# Product Compiler

**Authority:** Product and engineering specification. **Maturity:** In development.

The Product Compiler turns a customer technical deep dive, connected source
metadata, and a measured goal into a saved Precise product composition. The
composition selects and combines existing Precise math and Harness workflows,
defines the customer answer, and packages the result as a cassette or portable
application.

The target experience is simple: a Precise builder provides the deep dive and
the connected facts. Within 30 seconds they can inspect a working product
preview, the smallest supported things the customer can change, the next useful
move, what will be recalculated, and the saved definition that produced it.

## One example

A Growth Owner says:

> Every Monday, show me why CPA is above $80, break it down as finely as our
> data supports, recommend one budget move, and size a holdout because the
> current report is observational. We can change budgets manually today.

The Compiler binds that request to the synchronized source release, accepted
field map, current goal, available controls, and exact Gateway catalog. It can
produce this composition:

- Primitive grain: creative × supply path × placement.
- Available control: budget, applied manually.
- Initial work: contribution, pair interactions, response, next-dollar, and
  holdout sizing.
- Continuing work: rerun the useful methods after a mature outcome arrives.
- Customer surface: current CPA, controllable rows, recommended move and
  bounds, why the answer changed, history, and grounded chat.
- Saved name: `weekly-cpa-move@1.0.0`.
- Package: portable application because the result includes a customer UI.

Audience stays absent when the connected facts cannot support it. The compiled
product says that once in the useful answer and keeps working at the supported
grain.

## The nine stages

### 1. Understand

Bind the technical conversation by reference and digest. Extract the named
user, their job, the desired result, timing, available actions, and facts that
would materially change the answer.

Inputs:

- technical deep-dive transcript reference;
- named user and job;
- desired business outcome;
- requested effect: read, recommend, or act.

Uses the existing Product Start and grounded-chat capabilities. Raw transcript
bytes stay in authorized customer or Precise custody. The composition carries
only references and the distilled requirements.

### 2. Connect

Resolve the exact synchronized source release, accepted mappings, measured
joins, and current goal. A warehouse, DSP, object store, API, or uploaded file
is a source connection. A campaign is a subject found inside those connected
facts, not the product's ingestion model.

### 3. Find the controls

Identify the finest supported inputs the customer can resize or change toward
the goal. Typical media controls include budget, pacing, targeting, bid,
creative, placement, supply path, and audience. A mapped field proves that the
product can observe it. The connected action adapter says whether Precise can
change it automatically.

### 4. Choose the work

Match available facts to the runtime schemas in the Gateway catalog. Compose
the smallest useful set of the default workflows:

- `understand-the-book`
- `find-the-next-move`
- `design-the-test`
- `measure-and-learn`
- a focused workflow for any smaller supported method set

The customer does not pick an analysis type. Technical names remain available
under the explanation and source views for the people who need them.

### 5. Show it

Generate one compact walkthrough:

1. What is happening.
2. What can change.
3. What the product expects to learn next.

The preview shows the current answer first, then the controllable primitive
rows, recommended move and supported bounds, history, and chat.

### 6. Try it

Read and calculation steps run against the exact bound source release. A step
that would change an external system is represented in the preview but is not
sent to that system. The preview shapes the product while external system state
stays untouched.

### 7. Save it

Save a content-addressed composition with a name, semantic version, predecessor,
source requirements, goal requirement, primitive contract, workflow program,
surface contract, and package shape. The name head points to the current saved
version. Earlier versions remain readable and runnable.

### 8. Ship it

Emit the Product API, UI or agent contract and one of two operating packages:

- Cassette: a repeatable API, agent, event, or scheduled job.
- Portable application: frontend, Product API, Harness, adapters, and Product
  state as one release.

### 9. Learn

Join the real action exposure and mature outcome to Decision Learning. Pass the
exact outcome into the continuing workflow, recompute the Product answer, and
save a successor composition only when the learned evidence changes the source
mapping, workflow choice, or customer projection.

## Saved composition

`precise.product-composition/v1` is the reusable definition. It contains no raw
customer rows and no transcript body.

```json
{
  "schema": "precise.product-composition/v1",
  "name": "weekly-cpa-move",
  "version": "1.0.0",
  "compiled_from": {
    "discovery_ref": "precise:product-discovery/sha256:…"
  },
  "source_requirements": [
    {
      "source_role": "media-delivery",
      "required_fields": ["spend", "conversions", "creative", "placement", "supply_path"],
      "required_grain": ["creative", "placement", "supply_path"],
      "time_requirement": "daily",
      "maturity_requirement": "conversion window closed"
    }
  ],
  "goal_requirement": {
    "measure": "cost_per_acquisition",
    "direction": "decrease",
    "window": "weekly"
  },
  "primitive_contract": {
    "dimensions": ["creative", "placement", "supply_path"],
    "controls": [
      { "field": "budget", "mode": "manual_action" }
    ],
    "measures": [
      "current_size",
      "measured_contribution",
      "uncertainty",
      "interactions",
      "marginal_value"
    ]
  },
  "workflow_program": [
    { "purpose": "understand", "workflow": "understand-the-book", "trigger": "first-run" },
    { "purpose": "move", "workflow": "find-the-next-move", "trigger": "source-change" },
    { "purpose": "test", "workflow": "design-the-test", "trigger": "first-run" },
    { "purpose": "learn", "workflow": "measure-and-learn", "trigger": "outcome" }
  ],
  "surface": "current-answer-with-history-and-chat",
  "package_shape": "application"
}
```

The tenant-bound Product instance adds exact release, result, goal, workflow,
and current-answer references. It returns the last complete answer while a new
run is active.

## Product interface

The emitted Product API is deliberately small:

```text
GET  /v1/products/:instance/current
POST /v1/products/:instance/run
POST /v1/products/:instance/outcomes
GET  /v1/products/:instance/history
POST /v1/products/:instance/ask
```

The current-answer record contains:

- a direct headline and current result;
- the recommended move and supported bounds;
- the smallest supported controllable primitives;
- measured contribution, uncertainty, interactions, current size, and marginal
  value for each primitive;
- the next recalculation trigger;
- exact evidence references.

Method names, workflow IDs, raw run records, and evidence references stay under
“Why this answer.” Grounded chat is pinned to the same current-answer digest so
its numbers and action claims can be checked against the page.

## Harness surface

The planned optional Harness child is `product-compiler`:

```text
start    deep dive + named user + outcome + sources + goal → discovery
compile  discovery reference → saved composition + walkthrough + preview
show     name or composition hash → exact composition
list     → names and versions
bind     composition + source and goal refs → tenant Product instance
run      Product instance + request ID → current answer
outcome  instance + exact outcome event → recomputed answer + learning record
revise   composition + learning refs + version → saved successor
package  composition → cassette spec or portable application bundle
```

The Compiler reuses current Precise parts: Product Start, source and mapping
records, Media Goals, the Gateway method catalog, continuing workflows, saved
workflow definitions, Decision Learning, Campaign projections, grounded chat,
application scaffolding, and deterministic bundling.

## Ownership

Precise owns transcript interpretation, source and goal requirements,
controllable-primitive logic, workflow choice, method-input compilation,
customer artifacts, Product API and UI meaning, learning, versioning, and the
policy that chooses a package shape. Precise also owns its differentiated math.

Boombox supplies reusable identity, tenancy, secrets, durable hosting, events,
lifecycle, receipts, metering, schedules, cassette operation, and portable
application operation. Its generic conversational authoring rail may help the
Compiler compose work, while the Precise Product Compiler remains the owner of
the customer result.

Another company can build its own compiler or Harness, combine its expertise
with Precise math, and distribute its own Product without transferring its data,
domain core, or customer relationship.

## In development

The current repository already contains the math, four continuing workflows,
saved workflow definitions, Product Start, source profiling and mapping,
synchronized releases, Media Goals, Campaign projections, Decision Learning,
grounded chat, application scaffolding, bundling, and Boombox cassette and
application contracts.

The Product Compiler implementation is organized as vertical slices:

1. Discovery record and technical-deep-dive source port.
2. Control detector and source/goal-to-method-input compiler.
3. Workflow selector and runnable preview.
4. Saved composition and tenant binding stores.
5. Current-answer projector with history and grounded chat.
6. Outcome join across continuing workflows and Decision Learning.
7. Cassette and portable-application package emitters.

Each slice ends in a user-visible behavior. A Precise builder can use the first
working slice while later slices deepen the same saved composition.
