Cosmic Bull

Rendered from docs/APPLICATION_FACTORY.md at commit f191063fd89d in the project repository. The committed file is the source of truth; this page is a rendering of it.

The application factory

The longer-term objective of Cosmic Bull: accept an application objective and decide how to satisfy it, rather than defaulting to writing new code.

The goal is not maximum code generation. The goal is useful applications produced through maximum appropriate reuse and rigorous verification.


The four strategies

Given an objective, Cosmic Bull chooses among four, in this order of preference:

1. Reuse an existing primitive

A /p/ package already does this, correctly, and is already deployed. Import it.

This is the cheapest outcome by a wide margin: no new audit surface, and the imported code arrives with a track record. grants and market both reached production this way for their value handling — they import coinio and feeledger, which were already live and already audited by the time those realms were written.

2. Compose existing realms and packages

The capability exists, spread across two or more live components. Wire them together rather than reimplementing either.

Composition across /r/ boundaries is more expensive than /p/ reuse — it introduces cross-realm call semantics, and therefore caller-identity and readonly-taint questions — but it is still far cheaper than new infrastructure.

3. Adapt an existing implementation

Something close exists, but needs porting to current chain semantics, remediation of security findings, or a different asset/authority model.

Port it; do not redesign it. The discipline here is specific:

All five GitHub-pipeline applications are strategy 3. See catalog/applications.md.

4. Create genuinely new infrastructure

Only after 1–3 have been searched and recorded as insufficient — with the evidence committed in a DISCOVERY.md.

Strategy 4 is the expensive one and it is the last resort by design. Every new line is new audit surface, and on an immutable chain a mistake is permanent.

Cosmic Bull has used strategy 4 four times, each with recorded reasoning: feeledger, coinio, duebook and permbook. Reuse is what justifies having written them, and the chain-computed consumer lists in catalog/portfolio.json (proved by C7) are the authority: feeledger is imported by eight deployed realms (bounties, bounty_panel, coindemo, grants, market, service_market, subscriptions, vault); coinio by six (bounty_panel, coindemo, grants, market, service_market, subscriptions — the deployed bounties and vault v1s predate coinio and do not import it; only their undeployed local vNext trees do). (Corrected 2026-09-23 from a hand-grep "six for both" whose coinio membership wrongly included bounties/vault and which predated the two newest realms.) duebook and permbook each have exactly one consumer, so neither has earned that justification yet, and both records say so. A primitive written once and never reused is a cost, not an asset.

The first two were arrived at by extraction — the same code appeared in several realms first. The second two were arrived at objective-first, which is the riskier route, because there is no repetition to prove the abstraction was needed. permbook is the sharpest case: a live Cosmic Bull realm (permission_registry) already satisfied the literal objective and was recorded as doing so before any argument for building, so the new primitive exists only against one quoted, unworkaroundable property of that realm — caps that are global, shared and unraisable on immutable bytes.


How a strategy is chosen

The choice is an output of the discovery gate, not an input to it. The gate (docs/DISCOVERY_AND_REUSE.md) forces a search across the catalog, the existing sources, the chain, and the public ecosystem, and forces every hit to be classified:

ClassificationImplies strategy
EXACT DUPLICATEDo not build. Use it, or explain precisely why it cannot be used.
REUSABLE EXISTING PRIMITIVE1 — import it
RELATED IMPLEMENTATION2 or 3 — compose, or adapt, with the delta recorded
GENUINELY NEW4 — and the evidence for "new" is committed

A RELATED hit that is not reused must carry a concrete, specific reason. "Heavier surface than needed" and "marked v0 Unaudited" are concrete; "different style" is not.

Two worked examples from the retroactive review of this portfolio:


What "done" means

An application is not done when it compiles, and not done when it deploys. It is done when all of the following are true and written down:

  1. Discovery evidence is committed.
  2. All RED and material YELLOW findings are resolved — not downgraded.
  3. Tests pass against a chain-matched toolchain.
  4. The dependency closure the tests used is proven equivalent to the target chain's, by a matching digest pair, with the stdlib residual stated. A passing test alone does not satisfy this — see DEPENDENCY_CLOSURE.md.
  5. The deployed bytes byte-match the committed bytes of a named commit, proven before broadcast and re-proven after via vm/qfile.
  6. Live reads, live writes, and live attacks are recorded by transaction hash, with abort messages byte-matched to the audited source.
  7. Value invariants are checked against real bank state.
  8. Sibling live realms are proven untouched.
  9. Coverage that was not achieved is stated, with the reason, and correlated to the committed tests that do cover it.

Item 9 is the one that distinguishes a record from a press release.

Items 4 and 5 are deliberately separate, and conflating them was the factory's longest-standing blind spot. Item 5 proves the root is what was committed; item 4 proves the imports are what the chain will actually execute. A realm can satisfy 5 completely while item 4 fails, because the two verify different artifacts against different sources.


Open software, application economics, commercial services

Three layers the factory keeps distinct, because conflating them is how a software project turns into a fee-extraction platform:

The thesis stays what it was: build, compose, verify and deploy open on-chain software; let economics exist around useful applications and services, never by restricting reusable code.


What the factory is not yet

Stated plainly, so the roadmap is honest: