Example

Assemble for the task, or report that you cannot

Run the compiler's fourteen synthetic cases at three budgets and see it separate a bundle it can build from a structured failure it cannot.

The chapter’s question is whether assembly is possible at all, before any question about which candidates are best. A packer that treats required constraints as soft preferences produces a plausible-looking bundle whose declared obligations have been violated. The compiler here answers feasibility first, and its answer can be “no”.

Run it

git clone https://github.com/ernanhughes/project-context-compiler.git
cd project-context-compiler
git checkout 8d8bd31a20788c4c3298dfdffac741c507211a58
npm ci
node src/cli.ts conformance

Node 22 or later. The command is offline and deterministic: no model, no network, no service.

Expected outcome

Fourteen fixtures at three budgets each, and a clean sweep:

Context Compiler conformance

fixtures: 14
budgets: 3
cases: 42

success cases: 34
expected failure cases: 8

semantic mismatches: 0
serialization mismatches: 0
budget violations: 0

PASS

The eight expected failures are the interesting half. A case with no legal representation reports a reason rather than a bundle:

no-legal-representation/tight: success=false
reason: NO_LEGAL_REPRESENTATION

And a case that fits reports what it admitted and what it cost:

qualification-trap/tight: success=true
admitted: ["instr-1","taskreq-1","claim-positive","exception-tenant"]
tokens: 319 hash: dd652304e84e50efe148f5505f6a71d86c86afee001bc9ef30fb3024fe81129a

Mandatory material is not a preference

The compiler’s own CLI documents the two questions a caller can ask, and the second is the one the chapter is about:

/**
 * context-compiler CLI. File IO lives here, never in src/core.
 * Usage:
 *   node src/cli.ts version
 *   node src/cli.ts conformance
 *   node src/cli.ts inspect <fixture> [--budget tight|medium|roomy]
 *   node src/cli.ts compile --request R --candidates C --policy P [--output O]
 *   node src/cli.ts validate --compilation M --request R --candidates C --policy P
 */

A case whose mandatory material does not fit gets a structured failure, with the blocking item named:

    "failure": {
      "schema_version": "project_context.compile_failure.v1",
      "request_id": "mandatory-overflow-req",
      "policy_version": "compiler-policy-v1",
      "reason": "INSUFFICIENT_BUDGET",
      "blocking_ids": [
        "mand-b"
      ],
      "budget_used": 2000,
      "budget_total": 4400,
      "diagnostic": "mandatory mand-b closure exceeds remaining budget"
    }

Mechanism and limitations

Documented: the fourteen fixtures, their three budgets and the expected outcomes are in conformance/compiler-v1/manifest.json; the failure schema is project_context.compile_failure.v1; the CLI contract is in src/cli.ts.

Observed: the run above. 42 cases, 34 successes and 8 expected failures, with zero semantic mismatches, zero serialization mismatches and zero budget violations. The conformance run compares every field of every case against a frozen golden set from the earlier Python implementation.

Not shown. The fixtures are synthetic and were written to exercise the compiler’s rules; passing them is a test of the implementation, not evidence that a real task’s context is assembled well. A budget is expressed in estimated tokens, and the estimate is an approximation. The conformance run proves the compiler agrees with the frozen reference on these cases, not that the reference was right. Nothing here measures whether a compiled bundle improved a model’s answer.

Canonical source and the compiler’s core .

Understand this example

Copy this prompt into your AI tool. No code runs here.

Apply this example

Copy this prompt into your AI tool. No code runs here.