@yagni-app/code-staging 1.2.14-staging.2213.1 → 1.2.14-staging.2243.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@
16
16
  * lives (`packages/shared/src/attempts.ts`): the two meet only at this JSON.
17
17
  */
18
18
  import type { ContinuationStage } from "./continuation.js";
19
+ import { type PlanChange } from "./planChanges.js";
19
20
  import { type VerifyCheckRun, type VerifyOutcome } from "./verify.js";
20
21
  import type { WorktreeExec } from "./worktree.js";
21
22
  import type { Finding, PipelineLane, PipelineResult, StopReason } from "./types.js";
@@ -114,6 +115,12 @@ export interface AttemptResult extends CloudIdentity {
114
115
  costMillicents: number;
115
116
  }>;
116
117
  };
118
+ /**
119
+ * The steps the build did differently than `plan.md` says, or left out
120
+ * (`planChanges.ts`, spec 2026-11-02 §4); absent when there are none. The
121
+ * host writes each into the plan as Wright's decision.
122
+ */
123
+ planChanges?: PlanChange[];
117
124
  }
118
125
  /** The findings the result reports, blocking first. */
119
126
  export declare function openFindings(findings: readonly Finding[]): OpenFinding[];
@@ -204,6 +211,12 @@ export interface CloudCompletion {
204
211
  exec: WorktreeExec;
205
212
  writeFile: (path: string, text: string) => void;
206
213
  }
214
+ /**
215
+ * The changes to the plan the session's implement stage reported: the last
216
+ * implement summary that carries a plan-changes block. None when no implement
217
+ * stage ran, or none reported a change.
218
+ */
219
+ export declare function implementPlanChanges(stages: readonly Pick<PipelineResult["stages"][number], "stageId" | "finalOutput">[]): PlanChange[];
207
220
  /**
208
221
  * The cloud session's last act. A plan execution writes `plan.md` and
209
222
  * `plan.json`. Any other runs the secret and binary scan on what it added,
@@ -19,6 +19,7 @@ import { createHash } from "node:crypto";
19
19
  import { join } from "node:path";
20
20
  import { isBlockingFinding } from "./findings.js";
21
21
  import { planTitle, runFinish, verifyTrailerValue } from "./finish.js";
22
+ import { extractPlanChanges, planChangeNote } from "./planChanges.js";
22
23
  import { buildPlanFile, planMarkdown } from "./planOutput.js";
23
24
  import { cloudLane } from "./stages.js";
24
25
  import { applyStageTiers, parseStageTiers, STAGE_TIERS_ENV } from "./tierCap.js";
@@ -290,6 +291,22 @@ export function cannotRunNote(checks) {
290
291
  function findingKey(finding) {
291
292
  return `${finding.file ?? ""}:${finding.line ?? ""}:${finding.message}`;
292
293
  }
294
+ /**
295
+ * The changes to the plan the session's implement stage reported: the last
296
+ * implement summary that carries a plan-changes block. None when no implement
297
+ * stage ran, or none reported a change.
298
+ */
299
+ export function implementPlanChanges(stages) {
300
+ let found = [];
301
+ for (const stage of stages) {
302
+ if (stage.stageId !== "implement")
303
+ continue;
304
+ const changes = extractPlanChanges(stage.finalOutput ?? "");
305
+ if (changes.length > 0)
306
+ found = changes;
307
+ }
308
+ return found;
309
+ }
293
310
  /**
294
311
  * The cloud session's last act. A plan execution writes `plan.md` and
295
312
  * `plan.json`. Any other runs the secret and binary scan on what it added,
@@ -316,6 +333,11 @@ export async function completeCloudSession(c, ran) {
316
333
  }
317
334
  };
318
335
  const result = "result" in ran ? ran.result : undefined;
336
+ // What the implement stage did differently than the plan says, from the
337
+ // plan-changes block its summary ends with (`cloudLane`, spec 2026-11-02 §4).
338
+ const planChanges = c.stage === "plan"
339
+ ? []
340
+ : implementPlanChanges(result?.stages ?? ("partial" in ran ? ran.partial : []));
319
341
  let stop = result?.stopReason ?? "failed";
320
342
  if (stop === "partial")
321
343
  notes.push("A build stage stopped partway; its change is committed as it was left.");
@@ -398,6 +420,7 @@ export async function completeCloudSession(c, ran) {
398
420
  }
399
421
  const facts = await gitFacts(c.cwd, c.exec, c.baseSha);
400
422
  notes.push(...facts.notes);
423
+ notes.push(...planChanges.map(planChangeNote));
401
424
  let delivered = outputsWritten;
402
425
  if (c.stage !== "plan") {
403
426
  // A commit past the base is this execution's work, whoever wrote it.
@@ -435,6 +458,7 @@ export async function completeCloudSession(c, ran) {
435
458
  notes,
436
459
  blockingKey: blockingFindingsKey(findings),
437
460
  usage: resultUsage(result ?? { stages: "partial" in ran ? ran.partial : [], rounds: [] }),
461
+ ...(planChanges.length > 0 ? { planChanges } : {}),
438
462
  };
439
463
  const resultWritten = writeOut(RESULT_FILE_NAME, `${JSON.stringify(attempt, null, 2)}\n`);
440
464
  return { attempt, ok: resultWritten && attempt.stopReason === "clean" && delivered };
@@ -0,0 +1,42 @@
1
+ /**
2
+ * The steps a build session did differently than `plan.md` says, or left out
3
+ * (spec 2026-11-02 "The plan a person approves is the only contract", §4),
4
+ * as `result.json` carries them in `planChanges`. The host writes each into
5
+ * the plan as Wright's decision, in a version of the build's own, which
6
+ * Proctor checks. Without one, Proctor reads a step done another way as a
7
+ * step skipped.
8
+ *
9
+ * The session lane's model reports them in `session-report.json`; the
10
+ * one-attempt lane's implement stage ends its summary with a fenced
11
+ * `plan-changes` block. Both read through {@link parsePlanChanges}, the rule
12
+ * the host reads `result.json` with. This package does not depend on
13
+ * `@yagni/shared`, so the region between the markers below is a byte-for-byte
14
+ * copy of the same region of `packages/shared/src/attempts.ts`;
15
+ * `test/pipeline/planChanges.test.ts` fails when the two differ. Change the
16
+ * shared file and copy the region here.
17
+ */
18
+ /** One step done differently, or left out, in the session's own words. */
19
+ export interface AttemptPlanChange {
20
+ /** The step's number in `plan.md`, from 1; null for a change to the plan as a whole. */
21
+ step: number | null;
22
+ instead: string;
23
+ why: string;
24
+ }
25
+ /** The most plan changes a report carries, and the longest each one's words. */
26
+ export declare const MAX_PLAN_CHANGES = 20;
27
+ export declare const MAX_PLAN_CHANGE_CHARS = 600;
28
+ /** The report's plan changes: each with what was done instead, the rest dropped. */
29
+ export declare function parsePlanChanges(value: unknown): AttemptPlanChange[];
30
+ /** The extension's name for one change, as `cloud.ts` and the session lane use it. */
31
+ export type PlanChange = AttemptPlanChange;
32
+ /** What a build is told about reporting a change to the plan, in either lane. */
33
+ export declare const PLAN_CHANGES_RULE: string;
34
+ /**
35
+ * The changes an implement stage's summary ends with, in its ```plan-changes
36
+ * block: the last block that parses, or none. A summary with no block
37
+ * changed nothing in the plan.
38
+ */
39
+ export declare function extractPlanChanges(text: string): PlanChange[];
40
+ /** The line a change adds to the result's notes, which the stream shows. */
41
+ export declare function planChangeNote(change: PlanChange): string;
42
+ //# sourceMappingURL=planChanges.d.ts.map
@@ -0,0 +1,75 @@
1
+ /**
2
+ * The steps a build session did differently than `plan.md` says, or left out
3
+ * (spec 2026-11-02 "The plan a person approves is the only contract", §4),
4
+ * as `result.json` carries them in `planChanges`. The host writes each into
5
+ * the plan as Wright's decision, in a version of the build's own, which
6
+ * Proctor checks. Without one, Proctor reads a step done another way as a
7
+ * step skipped.
8
+ *
9
+ * The session lane's model reports them in `session-report.json`; the
10
+ * one-attempt lane's implement stage ends its summary with a fenced
11
+ * `plan-changes` block. Both read through {@link parsePlanChanges}, the rule
12
+ * the host reads `result.json` with. This package does not depend on
13
+ * `@yagni/shared`, so the region between the markers below is a byte-for-byte
14
+ * copy of the same region of `packages/shared/src/attempts.ts`;
15
+ * `test/pipeline/planChanges.test.ts` fails when the two differ. Change the
16
+ * shared file and copy the region here.
17
+ */
18
+ /** The most plan changes a report carries, and the longest each one's words. */
19
+ export const MAX_PLAN_CHANGES = 20;
20
+ export const MAX_PLAN_CHANGE_CHARS = 600;
21
+ /** A change's words on one line, clipped; null for none. */
22
+ function planChangeWords(value) {
23
+ if (typeof value !== "string")
24
+ return null;
25
+ const words = value.replace(/\s+/g, " ").trim();
26
+ return words ? words.slice(0, MAX_PLAN_CHANGE_CHARS) : null;
27
+ }
28
+ /** The report's plan changes: each with what was done instead, the rest dropped. */
29
+ export function parsePlanChanges(value) {
30
+ if (!Array.isArray(value))
31
+ return [];
32
+ const changes = [];
33
+ for (const entry of value) {
34
+ if (changes.length >= MAX_PLAN_CHANGES)
35
+ break;
36
+ if (!entry || typeof entry !== "object" || Array.isArray(entry))
37
+ continue;
38
+ const raw = entry;
39
+ const instead = planChangeWords(raw.instead);
40
+ const step = raw.step;
41
+ const numbered = typeof step === "number" && Number.isInteger(step) && step > 0;
42
+ if (!instead || !(numbered || step === null || step === undefined))
43
+ continue;
44
+ changes.push({ step: numbered ? step : null, instead, why: planChangeWords(raw.why) ?? "" });
45
+ }
46
+ return changes;
47
+ }
48
+ /** What a build is told about reporting a change to the plan, in either lane. */
49
+ export const PLAN_CHANGES_RULE = "The steps are guidance. When you do a step differently than plan.md says, or leave one out, " +
50
+ "add it to planChanges in your report: the step's number, what you did instead, and why. " +
51
+ "Leave out choices the plan left to you.";
52
+ const PLAN_CHANGES_BLOCK = /```plan-changes[^\n]*\n([\s\S]*?)```/gi;
53
+ /**
54
+ * The changes an implement stage's summary ends with, in its ```plan-changes
55
+ * block: the last block that parses, or none. A summary with no block
56
+ * changed nothing in the plan.
57
+ */
58
+ export function extractPlanChanges(text) {
59
+ let found = [];
60
+ for (const match of text.matchAll(PLAN_CHANGES_BLOCK)) {
61
+ try {
62
+ found = parsePlanChanges(JSON.parse(match[1] ?? ""));
63
+ }
64
+ catch {
65
+ // A block that does not parse is skipped; an earlier or later one may.
66
+ }
67
+ }
68
+ return found;
69
+ }
70
+ /** The line a change adds to the result's notes, which the stream shows. */
71
+ export function planChangeNote(change) {
72
+ const where = change.step ? `step ${change.step}` : "the plan";
73
+ return `Changed ${where}: ${change.instead}${change.why ? `, because ${change.why}` : ""}`;
74
+ }
75
+ //# sourceMappingURL=planChanges.js.map
@@ -29,7 +29,8 @@
29
29
  * process then runs what the cloud lane's finish runs (the secret and
30
30
  * binary scan, a commit of anything left, the git facts) and writes
31
31
  * `result.json` with the model's checks, what it could not verify and
32
- * where it departed from the plan folded in.
32
+ * where it departed from the plan folded in, each departure in
33
+ * `planChanges` for the host to write into the plan (`planChanges.ts`).
33
34
  *
34
35
  * Kept from the cloud lane: the run's clock (`YAGNI_PIPELINE_TIME_LEFT_MS`,
35
36
  * the turn's tools refused once it is nearly spent), the tool-failure health
@@ -39,6 +40,7 @@
39
40
  */
40
41
  import { type AttemptResult, type CloudIdentity, type CloudStage } from "./cloud.js";
41
42
  import type { ContinuationInputs } from "./continuation.js";
43
+ import { type PlanChange } from "./planChanges.js";
42
44
  import { type RunStageDeps } from "./runner.js";
43
45
  import { type ModelTier, type PipelineStage, type StageResult, type StopReason } from "./types.js";
44
46
  import { type VerifyCheckRun } from "./verify.js";
@@ -102,11 +104,8 @@ export interface SessionReport {
102
104
  summary: string | null;
103
105
  checks: VerifyCheckRun[];
104
106
  notVerified: string[];
105
- departures: Array<{
106
- from: string;
107
- what: string;
108
- why: string;
109
- }>;
107
+ /** The steps it did differently than plan.md says, or left out (spec 2026-11-02 §4). */
108
+ planChanges: PlanChange[];
110
109
  }
111
110
  /**
112
111
  * `session-report.json` as this process folds it, or null when it is missing
@@ -29,7 +29,8 @@
29
29
  * process then runs what the cloud lane's finish runs (the secret and
30
30
  * binary scan, a commit of anything left, the git facts) and writes
31
31
  * `result.json` with the model's checks, what it could not verify and
32
- * where it departed from the plan folded in.
32
+ * where it departed from the plan folded in, each departure in
33
+ * `planChanges` for the host to write into the plan (`planChanges.ts`).
33
34
  *
34
35
  * Kept from the cloud lane: the run's clock (`YAGNI_PIPELINE_TIME_LEFT_MS`,
35
36
  * the turn's tools refused once it is nearly spent), the tool-failure health
@@ -47,6 +48,7 @@ import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks
47
48
  import { creditExhaustionReason } from "./orchestrator.js";
48
49
  import { WORK_A_TICKET_SKILL } from "./personas.js";
49
50
  import { extractPlanJson } from "./planOutput.js";
51
+ import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
50
52
  import { runStage as defaultRunStage } from "./runner.js";
51
53
  import { scrubSecrets } from "./scrubSecrets.js";
52
54
  import { DECISIONS_READ_TOOL, PLAN_JSON_CONTRACT } from "./stages.js";
@@ -145,10 +147,12 @@ const REPORT_CONTRACT = (outDir) => `Last, write ${join(outDir, SESSION_REPORT_F
145
147
  '"checks": [{"name": "lint", "command": "pnpm lint", "cwd": ".", "exitCode": 0, "durationMs": 41000, ' +
146
148
  '"baseline": "runnable | fails_on_base | cannot_run"}], ' +
147
149
  '"notVerified": ["<what you could not verify, and why>"], ' +
148
- '"departures": [{"from": "<the plan step>", "what": "<what you did instead>", "why": "<why>"}]}. ' +
150
+ '"planChanges": [{"step": <the step\'s number in plan.md, or null for the plan as a whole>, ' +
151
+ '"instead": "<what you did instead>", "why": "<why>"}]}. ' +
149
152
  "List every check you ran on the final tree with its real exit code; a check you did not run is " +
150
153
  'not a pass, and goes in "notVerified". "baseline" is "fails_on_base" only when the check already ' +
151
- "failed on the unchanged code. Then end your turn.";
154
+ 'failed on the unchanged code. "planChanges" lists only a step you did differently than plan.md ' +
155
+ "says, or left out, never a choice the plan left to you. Then end your turn.";
152
156
  const BUILD_RULES = (outDir) => [
153
157
  "Write tools are on now. Work as your playbook says:",
154
158
  "- Prefer the smallest change that meets the ticket.",
@@ -205,7 +209,7 @@ export function turnMessage(facts) {
205
209
  parts.push(`The person approved your plan. The plan as approved is ${at("plan.md")}, and their answers are in ${at("plan-answers.json")}; ${at("ticket.md")} lists any answer that changes the plan.`);
206
210
  if (answers)
207
211
  parts.push(answers);
208
- parts.push(`The option they picked is binding. If it is not the one you recommended, re-plan in place first: write the plan you will build to ${join(facts.outDir, "plan.md")}, then build that. The steps are guidance; record every departure from them and why.`);
212
+ parts.push(`The option they picked is binding. If it is not the one you recommended, re-plan in place first: write the plan you will build to ${join(facts.outDir, "plan.md")}, then build that. ${PLAN_CHANGES_RULE}`);
209
213
  }
210
214
  else if (facts.stage === "fix" && facts.review) {
211
215
  parts.push(`A review or the CI on this attempt's pull request asks for changes. They are in ${at("ticket.md")}, under "Review on this attempt's pull request", each with its id; the branch may hold a person's commits since your last turn, so read the code as it is now. Address every item with the smallest change that does it, write the outcomes file that section names, and commit.`);
@@ -301,18 +305,22 @@ export function parseSessionReport(text, known = new Map()) {
301
305
  .map((entry) => line(entry))
302
306
  .filter((entry) => entry !== null)
303
307
  .slice(0, MAX_REPORT_LINES);
304
- const departures = list(data.departures)
305
- .flatMap((entry) => {
306
- if (!entry || typeof entry !== "object")
307
- return [];
308
- const record = entry;
309
- const what = line(record.what);
310
- if (!what)
311
- return [];
312
- return [{ from: line(record.from, 200) ?? "the plan", what, why: line(record.why) ?? "" }];
313
- })
314
- .slice(0, MAX_REPORT_LINES);
315
- return { summary: line(data.summary, 1_500), checks, notVerified, departures };
308
+ // A turn told the report's earlier shape (`departures`, its step named in
309
+ // words) in an earlier turn of the same session still counts: each is a
310
+ // change to the plan as a whole, its step named in what it did instead.
311
+ const planChanges = data.planChanges !== undefined
312
+ ? parsePlanChanges(data.planChanges)
313
+ : parsePlanChanges(list(data.departures).map((entry) => {
314
+ const record = (entry ?? {});
315
+ const what = line(record.what);
316
+ const from = line(record.from, 200);
317
+ return {
318
+ step: null,
319
+ instead: what && from ? `${from}: ${what}` : what,
320
+ why: record.why,
321
+ };
322
+ }));
323
+ return { summary: line(data.summary, 1_500), checks, notVerified, planChanges };
316
324
  }
317
325
  /** The checks the host named in `checks.json`, by their command, with how each stands on the base. */
318
326
  function knownBaselines(inputDir, readFile) {
@@ -334,12 +342,13 @@ export function withReport(attempt, report) {
334
342
  ...(report.summary ? [report.summary] : []),
335
343
  ...attempt.notes,
336
344
  ...report.notVerified.map((entry) => `Not verified: ${entry}`),
337
- ...report.departures.map((entry) => `Departed from ${entry.from}: ${entry.what}${entry.why ? `, because ${entry.why}` : ""}`),
345
+ ...report.planChanges.map(planChangeNote),
338
346
  ];
339
347
  return {
340
348
  ...attempt,
341
349
  checks: report.checks.length > 0 ? report.checks : attempt.checks,
342
350
  notes,
351
+ ...(report.planChanges.length > 0 ? { planChanges: report.planChanges } : {}),
343
352
  };
344
353
  }
345
354
  /** The most of a child's stderr a failed turn's note carries. */
@@ -98,6 +98,12 @@ export declare const PLAN_JSON_CONTRACT: string;
98
98
  * ends its own run: implement starts in a later run, on the approved plan.
99
99
  */
100
100
  export declare function cloudLane(inputDir: string): PipelineLane;
101
+ /**
102
+ * The cloud implement stage's report of what it did differently than the
103
+ * plan says (spec 2026-11-02 §4): a fenced block its summary ends with, which
104
+ * the session writes into `result.json` (`cloud.ts` `implementPlanChanges`).
105
+ */
106
+ export declare const CLOUD_PLAN_CHANGES_RULE: string;
101
107
  /**
102
108
  * The plan contract re-ask: the same cheap format-recovery pass the review
103
109
  * lenses get, pointed at the ```plan-json block. One attempt only.
@@ -291,6 +291,7 @@ export function cloudLane(inputDir) {
291
291
  const fix = PIPELINE_V1.find((s) => s.id === "fix");
292
292
  if (!fix)
293
293
  throw new Error("PIPELINE_V1 is missing the fix stage");
294
+ const implement = implementStage();
294
295
  return {
295
296
  stages: [
296
297
  {
@@ -301,7 +302,11 @@ export function cloudLane(inputDir) {
301
302
  taskTemplate: cloudPlanTask(inputDir),
302
303
  timeBudgetMs: CLOUD_PLAN_MINUTES * 60_000,
303
304
  },
304
- { ...implementStage(), model: "advanced" },
305
+ {
306
+ ...implement,
307
+ model: "advanced",
308
+ taskTemplate: withPlanChangesRule(implement.taskTemplate),
309
+ },
305
310
  reviewStage(),
306
311
  { ...fix, model: "advanced" },
307
312
  ],
@@ -312,6 +317,22 @@ export function cloudLane(inputDir) {
312
317
  skillsEveryStage: true,
313
318
  };
314
319
  }
320
+ /**
321
+ * The cloud implement stage's report of what it did differently than the
322
+ * plan says (spec 2026-11-02 §4): a fenced block its summary ends with, which
323
+ * the session writes into `result.json` (`cloud.ts` `implementPlanChanges`).
324
+ */
325
+ export const CLOUD_PLAN_CHANGES_RULE = "The steps are guidance. When you do a step differently than the plan says, or leave one out, " +
326
+ "end your summary with a ```plan-changes block: a JSON list with one entry per change, " +
327
+ '{"step": <the step\'s number in the plan, or null for the plan as a whole>, ' +
328
+ '"instead": "<what you did instead>", "why": "<why>"}. Leave out choices the plan left to you.';
329
+ /** The implement task with the rule just before the plan it builds. */
330
+ function withPlanChangesRule(taskTemplate) {
331
+ const at = taskTemplate.lastIndexOf("Plan:\n{previous}");
332
+ if (at < 0)
333
+ throw new Error("the implement stage's task no longer ends with its plan");
334
+ return `${taskTemplate.slice(0, at)}${CLOUD_PLAN_CHANGES_RULE}\n\n${taskTemplate.slice(at)}`;
335
+ }
315
336
  /**
316
337
  * The plan contract re-ask: the same cheap format-recovery pass the review
317
338
  * lenses get, pointed at the ```plan-json block. One attempt only.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2213.1",
3
+ "version": "1.2.14-staging.2243.1",
4
4
  "description": "YAGNI Code: a terminal coding agent that already knows your company. One YAGNI login routes the model and grounds the agent in your team's context.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "YAGNI, Inc. <jack@yagni.app> (https://yagni.app)",
@@ -58,5 +58,5 @@
58
58
  "turndown": "^7.2.4",
59
59
  "typebox": "^1.3.15"
60
60
  },
61
- "yagniSourceSha": "4cc9f6388171d4967fbf78689819f238baa1f5f8"
61
+ "yagniSourceSha": "250dab650145f8e7a80049cc227a6a69d24aac5b"
62
62
  }