diff --git a/.agents/planner.md b/.agents/planner.md
index ae1db2d11..1e6de2646 100644
--- a/.agents/planner.md
+++ b/.agents/planner.md
@@ -113,6 +113,17 @@ Prefer a focused PR stack when independent invariants can be reviewed and
merged separately. Do not split work at a point that requires a temporary
architecture or leaves `main` contradicting its specifications.
+## Plan a repetitive migration
+
+Prepare the [parent migration program](../examples/adversarial-implementation/README.md#assess-a-repetitive-migration)
+before launching a migration batch. Count one comparable unit across the
+parent issue, including completed and planned batches. Name the query or
+inventory behind the estimate, the expected batch count and uncertainty.
+Refresh the shared record when new evidence changes those facts. If planning
+reveals a larger migration, return to launch preparation with the updated
+program before handing off implementation. Use the accepted design result and
+its representative dry run to settle the rollout in the plan.
+
## Validate the API before handoff
Implement the smallest API that removes the identified authoring friction.
diff --git a/examples/adversarial-implementation/README.md b/examples/adversarial-implementation/README.md
index eaf55140d..759888462 100644
--- a/examples/adversarial-implementation/README.md
+++ b/examples/adversarial-implementation/README.md
@@ -84,6 +84,7 @@ initial packet within 64000 characters; retain full logs as references.
| `implementation.ready`, `implementation.evidence` | Whether accepted scope and focused checks suffice for direct implementation through existing interfaces. A separate plan document is optional. |
| `sharedApi.needed`, `sharedApi.evidence` | Whether accepted behavior requires shared API work. Necessary API work excludes simple; it alone does not justify a migration split. |
| `migration` | `null` declares no worthwhile separate migration split. A record requires `evidence`, `representativeConsumers` and `remainingConsumers`: repeated production friction, representative validation and substantial identified conversion remaining. Both consumer lists are nonempty, distinct, disjoint repository-relative committed production paths. No file-count threshold applies. |
+| `migrationProgram` | Absolute path to the shared parent program for a repetitive migration. Every batch uses it, including batches that use the ordinary route. A non-null `migration` requires it. |
`assessment` is the existing ReviewPolicy impact assessment, independent of
scope. Its evidence and optional risk evidence also select `inputs`. Routing
@@ -97,6 +98,7 @@ The table is ordered. Missing or unknown facts never become false or null.
| --- | --- |
| Missing/invalid/unknown member, unavailable evidence/source, occupied fresh-work directory, conflicting identities or contradictory migration record | Actionable hold before paid roles; identify what to correct or which existing record to continue |
| Any `decisions.openQuestions` item | Hold before paid roles; show the unanswered question and evidence |
+| Parent migration meets the [design cutoff](#assess-a-repetitive-migration) | Obtain or verify the shared Problem Solver design. A held, uncertain or invalid assessment holds the batch before implementation. |
| Valid non-null migration record and `sharedApi.needed=true` | Existing Planner foundation and representative validation, then remaining consumer implementation, selected review and retirement |
| `migration=null`, `sharedApi.needed=false`, `implementation.ready=true` | Direct Implementor, then existing impact-selected independent review |
| `migration=null`, `sharedApi.needed=false`, `implementation.ready=false` | Ordinary Planner plan/evidence, with original Architect discovery when requested, then the same Planner handoff to Implementor and selected review |
@@ -114,6 +116,10 @@ Any unresolved material question?
| yes -----------------------> HOLD: show question and evidence
| no
v
+Parent migration meets design cutoff?
+ | yes -> obtain or verify shared Problem Solver design
+ | hold if the result cannot be verified
+ v
Justified migration record? (requires sharedApi.needed=true)
| yes -----------------------> MIGRATION
| Planner foundation + representatives
@@ -179,6 +185,71 @@ The roles use the normal agent permission policy. Running this example invokes
paid coding agents and permits the assigned implementation work. Publication,
issue/PR metadata and delivery remain with the Sidekick running Codex.
+## Assess a repetitive migration
+
+Use one parent program for all tickets, branches and PRs that make the same
+repetitive change. The Planner keeps the program and its supporting query or
+inventory outside individual batch checkouts and work directories. Set
+`scope.migrationProgram` to the same absolute program path for every batch.
+Count comparable sites across the full parent, including completed work.
+Count a batch once when it also has a PR. Update the parent record when a
+later ticket reveals more sites or changes the rollout.
+
+A program looks like this:
+
+```json
+{
+ "schema": "migration-program.v1",
+ "parent": "taras/executable.md#1171",
+ "unit": "one test owner that writes a failure journal",
+ "estimatedSites": 19,
+ "plannedBatches": 2,
+ "inventory": "journal-owners.md",
+ "uncertainty": {
+ "additionalSites": 2,
+ "additionalBatches": 0,
+ "reason": "Two candidates still need ownership checks."
+ },
+ "assumptions": "Each test owner belongs to one of the inventoried harnesses."
+}
+```
+
+The inventory is a text file beside the program. It records the source
+revision, query or counting method, and evidence behind the reported totals.
+Use zero for a dimension with no expected additions and `null` for an
+unbounded estimate. The workflow requires design at **20 sites or three
+batches**. It checks the upper end of both estimates, so the example requires
+a design for its 21 possible sites. An unbounded dimension takes the design
+path. Below both cutoffs, the workflow checks the two files and makes no
+Problem Solver call.
+
+Twenty sites gives a repeatable transformation enough applications to justify
+a representative dry run. Three batches catches the fixed planning and
+review work repeated on a rollout with fewer sites. These are initial
+thresholds. The observed rollout had ten open PRs, 75 commits, about 13,400
+non-whitespace changed lines, and 74 test owners pending or partial. A separate
+Fable assessment found that 17 rounds each left their own migration and audit
+scripts. It recommended consolidating them and backtesting the shared recipe
+before delegating routine cases. Token spend was unmeasured.
+[Journal attribution migration](https://github.com/taras/executable.md/issues/1171)
+
+The first batch that reaches a cutoff runs the existing Problem Solver design
+phase. It compares deterministic edits or a shared helper, batches a cheaper
+model can handle, a narrower rollout, and cases that need individual judgment.
+A hybrid XMD approach can inventory and preview deterministically, ask a model
+to classify ambiguous sites against approved recipes, and apply only the
+TypeScript edits whose AST preconditions pass. The assessment recommends a
+small dry run and gives distinct, measurable pass and fail outcomes.
+
+The workflow retains one attempt beside the parent record for the exact
+program and inventory contents. Further batches using those contents reuse
+the verified design and its native session receipt across checkout revisions.
+Changed contents require a new assessment when the cutoff applies. Keep the
+parent records stable while their assumptions hold. If a reserved attempt is still
+running or has no valid result, the batch holds and reports the saved
+attempt for reconciliation. Retrying the batch cannot repeat a reserved design turn.
+An admitted batch keeps its captured design with the existing Ticket inputs.
+
## Keep the original conversation
Every production role passes through `Phase.Session` inside its resolved Session,
diff --git a/examples/adversarial-implementation/components/Adversarial/Schema.md b/examples/adversarial-implementation/components/Adversarial/Schema.md
index ee81bb726..ab2655b2f 100644
--- a/examples/adversarial-implementation/components/Adversarial/Schema.md
+++ b/examples/adversarial-implementation/components/Adversarial/Schema.md
@@ -161,6 +161,7 @@ returns: {type: object}
],
"additionalProperties": false
},
+ "migrationProgram": {type:"string",pattern:"^/"},
"migration": {
"anyOf": [
{
diff --git a/examples/adversarial-implementation/components/Diagnosis/DesignMaterial.md b/examples/adversarial-implementation/components/Diagnosis/DesignMaterial.md
index 95f77448d..97c88671e 100644
--- a/examples/adversarial-implementation/components/Diagnosis/DesignMaterial.md
+++ b/examples/adversarial-implementation/components/Diagnosis/DesignMaterial.md
@@ -22,7 +22,9 @@ Connect your recommendation to those observations. In `whatWouldChange`, name
the evidence that would change your recommendation. Use `openQuestions` for
missing evidence or a decision the Architect must make. If a missing fact
prevents a choice, recommend the next step and explain what it would resolve.
-The Architect owns the implementation contract.
+The Architect owns the implementation contract. When the assignment asks for
+a dry run, fill in `dryRun` with its procedure and distinct, measurable pass
+and fail outcomes.
Return one JSON object. Keep any progress updates in plain prose.
diff --git a/examples/adversarial-implementation/components/Diagnosis/Schema.ts b/examples/adversarial-implementation/components/Diagnosis/Schema.ts
index 1c75f6bef..502904985 100644
--- a/examples/adversarial-implementation/components/Diagnosis/Schema.ts
+++ b/examples/adversarial-implementation/components/Diagnosis/Schema.ts
@@ -77,6 +77,7 @@ const designResult = z.strictObject({
recommendation: text,
whatWouldChange: text,
openQuestions: z.array(text).max(12),
+ dryRun: z.strictObject({ procedure: text, pass: text, fail: text }).optional(),
});
const evidence = z.array(
z.strictObject({
@@ -86,7 +87,7 @@ const evidence = z.array(
sha256: z.string().regex(/^[a-f0-9]{64}$/),
}),
);
-const designInputs = z.array(z.strictObject({ path: text, content: z.string() })).max(12);
+export const designInputs = z.array(z.strictObject({ path: text, content: z.string() })).max(12);
const inputs = designInputs.min(1);
const prior = z.strictObject({
schema: z.literal("diagnosis-attempt.v1"),
@@ -120,7 +121,7 @@ const receipt = z.strictObject({
identity,
result,
});
-const designReceipt = receipt.extend({
+export const designReceipt = receipt.extend({
assignment: prior.extend({ assignment: design }),
result: designResult,
});
diff --git a/examples/adversarial-implementation/components/Entry/Run.md b/examples/adversarial-implementation/components/Entry/Run.md
index 82236cd94..a4afd884b 100644
--- a/examples/adversarial-implementation/components/Entry/Run.md
+++ b/examples/adversarial-implementation/components/Entry/Run.md
@@ -79,12 +79,24 @@ test -f {referencePath} -a -r {referencePath}
+
documents[path])} />
{deliveryCheck.output}
+
+
+
+{designCheck.output}
+
+
+
+
+ documents[path])} />
+
+
diff --git a/examples/adversarial-implementation/components/Migration/Gate.md b/examples/adversarial-implementation/components/Migration/Gate.md
new file mode 100644
index 000000000..88f3081d3
--- /dev/null
+++ b/examples/adversarial-implementation/components/Migration/Gate.md
@@ -0,0 +1,40 @@
+---
+props:
+ type: object
+ properties:
+ batch:
+ type: object
+ properties:
+ path: {type: string, pattern: '^/'}
+ repository: {type: string, pattern: '^/'}
+ repositoryId: {type: string}
+ directory: {type: string, pattern: '^/'}
+ revision: {type: string, pattern: '^[a-f0-9]{40}$'}
+ required: [path, repository, repositoryId, directory, revision]
+ additionalProperties: false
+ required: [batch]
+ additionalProperties: false
+returns: {type: object}
+---
+
+
+
+
+
+
+ ({key,provider,models,effort}))}} />
+
+
+ input.path),assignment:{kind:"design",work:program.parent,repository:batch.repository,revision:batch.revision,question:program.question,constraints:program.constraints}}} />
+
+
+{assessment.output}
+
+
+
+
+
+
+
+
+
diff --git a/examples/adversarial-implementation/components/Migration/Program.ts b/examples/adversarial-implementation/components/Migration/Program.ts
new file mode 100644
index 000000000..454439548
--- /dev/null
+++ b/examples/adversarial-implementation/components/Migration/Program.ts
@@ -0,0 +1,107 @@
+import { realpath } from "@executablemd/runtime";
+import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path";
+import { z } from "zod";
+import { describe, read } from "../Ticket/text-storage.ts";
+
+const text = z.string().regex(/\S/).max(4_000);
+const count = z.number().int().min(0).max(1_000_000_000);
+const absolute = z.string().startsWith("/");
+const request = z.strictObject({
+ path: absolute,
+ repository: absolute,
+ repositoryId: text,
+ directory: absolute,
+});
+const program = z.strictObject({
+ schema: z.literal("migration-program.v1"),
+ parent: z.string().regex(/^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+#[1-9][0-9]*$/),
+ unit: text,
+ estimatedSites: count,
+ plannedBatches: count.min(1),
+ inventory: z.string().regex(/^[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/),
+ uncertainty: z.strictObject({
+ additionalSites: count.nullable(),
+ additionalBatches: count.nullable(),
+ reason: text,
+ }),
+ assumptions: text,
+});
+
+const sites = 20;
+const batches = 3;
+
+export const props = z.toJSONSchema(request, { target: "draft-7" });
+export const returns = { type: "object" };
+
+function inside(root: string, path: string): boolean {
+ const part = relative(root, path);
+ return !isAbsolute(part) && part !== ".." && !part.startsWith(".." + sep);
+}
+
+export default function* Program(value: unknown) {
+ const input = request.parse(value);
+ const path = yield* realpath(input.path);
+ const repository = yield* realpath(input.repository);
+ const directory = yield* realpath(dirname(input.directory));
+ if (
+ path === undefined ||
+ repository === undefined ||
+ directory === undefined ||
+ inside(repository, path) ||
+ inside(resolve(directory, basename(input.directory)), path)
+ ) {
+ throw new Error(
+ "Keep the shared parent migration program outside the checkout and batch directory.",
+ );
+ }
+
+ const content = yield* read(input.repository, path, 64_000);
+ const recorded = program.parse(JSON.parse(content));
+ if (recorded.parent.split("#")[0]?.toLowerCase() !== input.repositoryId.toLowerCase()) {
+ throw new Error("The parent migration issue must belong to the delivery repository.");
+ }
+
+ const inventoryPath = resolve(dirname(path), recorded.inventory);
+ if (inventoryPath === path || (yield* realpath(inventoryPath)) !== inventoryPath) {
+ throw new Error(
+ "Supply the parent migration inventory as a separate regular document beside the program.",
+ );
+ }
+ const inventory = yield* read(input.repository, inventoryPath, 64_000);
+ if (inventory.trim().length === 0) {
+ throw new Error("Record the query or inventory supporting the parent migration estimate.");
+ }
+
+ const inputs = [
+ { path, content },
+ { path: inventoryPath, content: inventory },
+ ];
+ const fingerprint = describe(
+ path,
+ JSON.stringify(inputs.map((entry) => describe(entry.path, entry.content).sha256)),
+ ).sha256;
+ const { additionalSites, additionalBatches } = recorded.uncertainty;
+ const required =
+ additionalSites === null ||
+ additionalBatches === null ||
+ recorded.estimatedSites + additionalSites >= sites ||
+ recorded.plannedBatches + additionalBatches >= batches;
+ return {
+ required,
+ parent: recorded.parent,
+ fingerprint,
+ inputs,
+ attempt: path + ".design-" + fingerprint,
+ session: "migration-design",
+ question:
+ "How can this parent migration deliver reliable results with fewer repeated implementation and review rounds?",
+ constraints: [
+ "Use the shared parent program and inventory. Account for completed and planned work and the stated uncertainty.",
+ "Group comparable units into mechanical edits, known patterns a cheaper model can handle in batches, and cases that need individual judgment.",
+ "Compare a codemod or shared helper, a cheaper model such as Codex Terra for routine work, a narrower rollout, and where higher judgment is needed.",
+ "Consider a hybrid XMD program with deterministic inventory and preview, model classification against approved recipes, and TypeScript edits guarded by AST preconditions and focused validation.",
+ "Recommend a small representative dry run before bulk rollout. Fill in dryRun.procedure, dryRun.pass and dryRun.fail with a measurable check and distinct outcomes.",
+ "Treat costs without measured token data as estimates. Identify the assumptions that would invalidate the recommendation.",
+ ],
+ };
+}
diff --git a/examples/adversarial-implementation/components/Migration/Result.ts b/examples/adversarial-implementation/components/Migration/Result.ts
new file mode 100644
index 000000000..b55813919
--- /dev/null
+++ b/examples/adversarial-implementation/components/Migration/Result.ts
@@ -0,0 +1,109 @@
+import { z } from "zod";
+import { designInputs, designReceipt } from "../Diagnosis/Schema.ts";
+import extract from "../Phase/Extract.ts";
+import fingerprint from "../Ticket/Fingerprint.ts";
+import { read, unused } from "../Ticket/text-storage.ts";
+
+const text = z.string().min(1);
+const request = z.strictObject({
+ repository: text,
+ parent: text,
+ directory: text,
+ identities: text,
+ session: text,
+ name: text,
+ question: text,
+ constraints: z.array(text),
+ inputs: designInputs,
+ candidates: z.array(
+ z.strictObject({
+ key: text,
+ provider: text,
+ models: z.array(text),
+ effort: text,
+ }),
+ ),
+});
+
+const completed = z.strictObject({
+ catalog: z.looseObject({ state: z.literal("selected"), model: text }),
+ turn: z.strictObject({ state: z.literal("reply"), reply: text }),
+});
+const extractedReply = z.object({ ok: z.literal(true), json: text });
+const options = z.strictObject({ input: request });
+
+export const props = z.toJSONSchema(options, { target: "draft-7" });
+
+export default function* Result(value: unknown) {
+ const { input } = options.parse(value);
+ const expectedEvidence = yield* fingerprint({ inputs: input.inputs });
+ for (const [position, candidate] of input.candidates.entries()) {
+ const attempt = input.directory + "/" + candidate.key;
+ const path = attempt + "/result.json";
+ if (yield* unused(input.repository, path)) {
+ continue;
+ }
+ const receipt = designReceipt.parse(JSON.parse(yield* read(input.repository, path)));
+ const record = receipt.assignment;
+ const assignment = record.assignment;
+ const session = input.name + "-" + candidate.key;
+ const savedAssignment = designReceipt.shape.assignment.parse(
+ JSON.parse(yield* read(input.repository, attempt + "/assignment.json", 1_048_576)),
+ );
+ const inputs = designInputs.parse(
+ JSON.parse(yield* read(input.repository, attempt + "/inputs.json")),
+ );
+ const savedIdentity = designReceipt.shape.identity.parse(
+ JSON.parse(
+ yield* read(
+ input.repository,
+ input.identities + "/" + encodeURIComponent(session) + ".json",
+ 1_048_576,
+ ),
+ ),
+ );
+ const execution = completed.parse(
+ JSON.parse(yield* read(input.repository, attempt + "/outcome.json")),
+ );
+ const raw = yield* read(input.repository, attempt + "/raw.txt");
+ const extracted = extractedReply.parse(yield* extract({ text: execution.turn.reply }));
+ const reply = designReceipt.shape.result.parse(JSON.parse(extracted.json));
+ const dryRun = receipt.result.dryRun;
+ if (
+ assignment.work !== input.parent ||
+ assignment.question !== input.question ||
+ JSON.stringify(assignment.constraints) !== JSON.stringify(input.constraints) ||
+ assignment.revision !== receipt.result.revision ||
+ record.primarySession !== input.session ||
+ record.previous !== null ||
+ record.position !== position ||
+ record.solverKey !== candidate.key ||
+ record.identities !== input.identities ||
+ record.solver.provider !== candidate.provider ||
+ record.solver.effort !== candidate.effort ||
+ record.solver.model !== candidate.models[0] ||
+ record.solver.session !== session ||
+ !candidate.models.includes(receipt.model) ||
+ execution.catalog.model !== receipt.model ||
+ raw !== execution.turn.reply ||
+ JSON.stringify(reply) !== JSON.stringify(receipt.result) ||
+ receipt.identity.agent !== candidate.provider ||
+ receipt.identity.name !== session ||
+ receipt.identity.cwd !== assignment.repository ||
+ JSON.stringify(savedAssignment) !== JSON.stringify(record) ||
+ JSON.stringify(savedIdentity) !== JSON.stringify(receipt.identity) ||
+ JSON.stringify(inputs) !== JSON.stringify(input.inputs) ||
+ JSON.stringify(record.evidence) !== JSON.stringify(expectedEvidence) ||
+ dryRun === undefined ||
+ dryRun.pass.trim() === dryRun.fail.trim()
+ ) {
+ throw new Error(
+ "The saved migration design at " +
+ path +
+ " differs from its scope, evidence, joined reply, session or required dry run.",
+ );
+ }
+ return path;
+ }
+ return null;
+}
diff --git a/examples/adversarial-implementation/tests/LaunchPolicy.test.md b/examples/adversarial-implementation/tests/LaunchPolicy.test.md
index c49644f6a..7813d38b3 100644
--- a/examples/adversarial-implementation/tests/LaunchPolicy.test.md
+++ b/examples/adversarial-implementation/tests/LaunchPolicy.test.md
@@ -27,8 +27,9 @@ git rev-parse HEAD
Accepted repeated production friction in wide and the difficult modal case; substantial remaining conversion in consumer.sh.
+
-
+
diff --git a/examples/adversarial-implementation/tests/implementation-holds.md b/examples/adversarial-implementation/tests/implementation-holds.md
index 01fa2983f..0fc7c9053 100644
--- a/examples/adversarial-implementation/tests/implementation-holds.md
+++ b/examples/adversarial-implementation/tests/implementation-holds.md
@@ -8,7 +8,7 @@ printf '%s' "$XMD_EXAMPLE_COMMAND"
-
+
@@ -23,7 +23,7 @@ git rev-parse HEAD
-
+
Uncommitted partial source.
Preserve this existing record.
@@ -36,7 +36,7 @@ git rev-parse HEAD
{child.stdout}
-
+
diff --git a/packages/cli/tests/adversarial-diagnosis.test.ts b/packages/cli/tests/adversarial-diagnosis.test.ts
index d966af123..58f6b1179 100644
--- a/packages/cli/tests/adversarial-diagnosis.test.ts
+++ b/packages/cli/tests/adversarial-diagnosis.test.ts
@@ -84,6 +84,7 @@ function* fixture() {
specs?: string[];
} = {},
solvers?: { primary: SolverProfile; fallback?: SolverProfile },
+ migration?: { path: string; directory: string },
) {
return scoped(function* () {
yield* useHostFiles();
@@ -163,7 +164,16 @@ function* fixture() {
solvers === undefined
? ``
: ``;
- const source = entry + "";
+ const gate =
+ migration === undefined
+ ? entry
+ : ``;
+ const source = gate + "";
yield* writeTextFile(doc, source);
const result = yield* collect(
yield* executeInstalled(
@@ -181,6 +191,27 @@ function* fixture() {
revision,
fake,
run,
+ gate(path: string, batch: string) {
+ return run(root, undefined, [], {}, undefined, { path, directory: join(root, batch) });
+ },
+ advanceRevision() {
+ git(
+ [
+ "-c",
+ "user.name=Fixture",
+ "-c",
+ "user.email=f@example.test",
+ "commit",
+ "--allow-empty",
+ "-qm",
+ "next batch",
+ ],
+ repository,
+ root,
+ );
+ expectedRevision = git(["rev-parse", "HEAD"], repository, root).trim();
+ return expectedRevision;
+ },
changeRevision() {
expectedRevision = "f".repeat(40);
},
@@ -196,6 +227,90 @@ function offer(fake: ReturnType, models: string[]) {
});
}
+describe("parent migration design gate", () => {
+ it("routes across the parent cutoff, reuses a joined design and invalidates changed evidence", function* () {
+ const test = yield* fixture();
+ offer(test.fake, ["fable", "gpt-6-astra"]);
+ const path = join(test.root, "program.json");
+ const program = {
+ schema: "migration-program.v1",
+ parent: "taras/executable.md#1171",
+ unit: "One journal-retaining test owner",
+ estimatedSites: 19,
+ plannedBatches: 2,
+ inventory: "first.log",
+ assumptions: "Each owner uses an existing test harness.",
+ uncertainty: { additionalSites: 0, additionalBatches: 0, reason: "Owners counted." },
+ };
+ const advice = {
+ outcome: "design",
+ revision: test.revision,
+ options: [
+ { option: "AST recipes", tradeoffs: "Mechanical edits use preview and validation." },
+ {
+ option: "Codex Terra batches",
+ tradeoffs: "Keep ambiguous owners for individual review.",
+ },
+ ],
+ observations: [{ source: test.evidence, observation: "Some owners share the same recipe." }],
+ recommendation: "Preview recipes and run two representative owners.",
+ whatWouldChange: "An owner needs a different journal lifecycle.",
+ openQuestions: [],
+ dryRun: {
+ procedure: "Preview and run two test owners.",
+ pass: "Both retain the expected journal and the diff contains only matched edits.",
+ fail: "Either loses a journal or applies an unmatched edit.",
+ },
+ };
+
+ yield* writeTextFile(path, JSON.stringify(program));
+ expect(JSON.parse(yield* test.gate(path, "batch-one"))).toEqual({ result: null });
+ expect(test.fake.prompts).toHaveLength(0);
+
+ yield* writeTextFile(path, JSON.stringify({ ...program, estimatedSites: 20 }));
+ test.fake.script({ reply: JSON.stringify(advice) });
+ const accepted = JSON.parse(yield* test.gate(path, "renamed-second-ticket"));
+ expect(accepted).toMatchObject({ parent: program.parent });
+ expect(accepted.result).toMatch(/\.design-[a-f0-9]{64}\/fable\/result\.json$/);
+ expect(test.fake.prompts[0]).toContain("TypeScript edits guarded by AST preconditions");
+ expect(test.fake.prompts[0]).toContain("Codex Terra");
+ const revised = { ...advice, revision: test.advanceRevision() };
+ expect(JSON.parse(yield* test.gate(path, "another-batch"))).toEqual(accepted);
+ expect(test.fake.prompts).toHaveLength(1);
+
+ const acceptedText = yield* readTextFile(accepted.result);
+ const amended = JSON.parse(acceptedText);
+ amended.result.recommendation = "Unverified modification.";
+ yield* writeTextFile(accepted.result, JSON.stringify(amended));
+ yield* expectRefusal(test.gate(path, "changed-receipt"), "joined reply");
+ expect(test.fake.prompts).toHaveLength(1);
+ yield* writeTextFile(accepted.result, acceptedText);
+
+ yield* writeTextFile(path, JSON.stringify({ ...program, plannedBatches: 3 }));
+ test.fake.script({ reply: JSON.stringify({ ...revised, dryRun: undefined }) });
+ yield* expectRefusal(test.gate(path, "third-batch"), "required dry run");
+ yield* expectRefusal(test.gate(path, "retried-third-batch"), "required dry run");
+ expect(test.fake.prompts).toHaveLength(2);
+
+ yield* writeTextFile(test.evidence, "Updated inventory excludes a false match.");
+ test.fake.script({ reply: JSON.stringify(revised) });
+ const updated = JSON.parse(yield* test.gate(path, "revised-program"));
+ expect(updated.result).not.toBe(accepted.result);
+ expect(test.fake.prompts).toHaveLength(3);
+
+ yield* writeTextFile(
+ path,
+ JSON.stringify({
+ ...program,
+ uncertainty: { ...program.uncertainty, additionalSites: 1 },
+ }),
+ );
+ test.fake.script({ reply: JSON.stringify(revised) });
+ expect(JSON.parse(yield* test.gate(path, "uncertain-inventory")).result).not.toBeNull();
+ expect(test.fake.prompts).toHaveLength(4);
+ });
+});
+
describe("adversarial problem-solver phase", () => {
it("records design advice with pinned spec sections and continues with captured evidence", function* () {
const test = yield* fixture();