@yagni-app/code-staging 1.2.14-staging.2204.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 };
@@ -238,6 +238,18 @@ export declare class PipelineStageError extends Error {
238
238
  readonly partial: StageResult[];
239
239
  constructor(stageId: string, message: string, partial: StageResult[]);
240
240
  }
241
+ /**
242
+ * The silent-402 landmine: when the workspace runs out of credits mid-run, the
243
+ * proxy 402s every model request, the child pi exits 0 with an EMPTY transcript,
244
+ * and the run otherwise dies as a confusing `no_changes` / empty-handoff / false
245
+ * "clean" stop with the real cause buried in stderr. Detect it and stop with an
246
+ * actionable message instead. Gated on the stage having produced no real output
247
+ * (or having failed outright) so a healthy stage whose stderr happens to contain
248
+ * a matching token can never trip it. A Run that spent its own budget stops the
249
+ * same way, with its own message. The session lane's turn reads it too
250
+ * (`sessionLane.ts` `turnStop`).
251
+ */
252
+ export declare function creditExhaustionReason(r: StageResult): string | undefined;
241
253
  /**
242
254
  * The resilience policy for a run's stages. With a deadline, a stage that
243
255
  * spent its wall clock spent the build's time: a retry would only get the
@@ -155,9 +155,10 @@ const RUN_REQUEST_LIMIT_RE = /run_request_limit_exhausted|This Run has used its
155
155
  * actionable message instead. Gated on the stage having produced no real output
156
156
  * (or having failed outright) so a healthy stage whose stderr happens to contain
157
157
  * a matching token can never trip it. A Run that spent its own budget stops the
158
- * same way, with its own message.
158
+ * same way, with its own message. The session lane's turn reads it too
159
+ * (`sessionLane.ts` `turnStop`).
159
160
  */
160
- function creditExhaustionReason(r) {
161
+ export function creditExhaustionReason(r) {
161
162
  if (r.finalOutput.trim().length > 0 && !isFailed(r))
162
163
  return undefined;
163
164
  const hay = `${r.errorMessage ?? ""}\n${r.stderr}`;
@@ -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
@@ -118,9 +117,16 @@ export declare function parseSessionReport(text: string | null, known?: Readonly
118
117
  /** The report's checks and its words on `result.json`: the model's own account, never the host's proof. */
119
118
  export declare function withReport(attempt: AttemptResult, report: SessionReport | null): AttemptResult;
120
119
  /**
121
- * The turn's stop as the result names it: aborted, its clock, a child that
122
- * failed, a writing turn whose tools mostly errored (the cloud lane's health
123
- * gate), else clean.
120
+ * The end of a turn's child's stderr as a note carries it: its last lines
121
+ * without the CLI's own `Skills:` line, secrets scrubbed, clipped; empty when
122
+ * nothing else is left. The child's stderr is the parent's alone, so without
123
+ * this a turn that died said nothing on the CLI's stderr either.
124
+ */
125
+ export declare function childStderrTail(stderr: string): string;
126
+ /**
127
+ * The turn's stop as the result names it: aborted, its clock, a model proxy
128
+ * that refused it for what the run may spend, a child that failed, a writing
129
+ * turn whose tools mostly errored (the cloud lane's health gate), else clean.
124
130
  */
125
131
  export declare function turnStop(run: StageResult, writes: boolean, aborted: boolean): {
126
132
  stop: StopReason;
@@ -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
@@ -44,9 +45,12 @@ import { scanChange } from "./changeScan.js";
44
45
  import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
45
46
  import { finishExec } from "./finish.js";
46
47
  import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
48
+ import { creditExhaustionReason } from "./orchestrator.js";
47
49
  import { WORK_A_TICKET_SKILL } from "./personas.js";
48
50
  import { extractPlanJson } from "./planOutput.js";
51
+ import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
49
52
  import { runStage as defaultRunStage } from "./runner.js";
53
+ import { scrubSecrets } from "./scrubSecrets.js";
50
54
  import { DECISIONS_READ_TOOL, PLAN_JSON_CONTRACT } from "./stages.js";
51
55
  import { STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
52
56
  import { MIN_TOOL_CALLS_FOR_HEALTH, TOOL_ERROR_FAIL_RATE, } from "./types.js";
@@ -143,10 +147,12 @@ const REPORT_CONTRACT = (outDir) => `Last, write ${join(outDir, SESSION_REPORT_F
143
147
  '"checks": [{"name": "lint", "command": "pnpm lint", "cwd": ".", "exitCode": 0, "durationMs": 41000, ' +
144
148
  '"baseline": "runnable | fails_on_base | cannot_run"}], ' +
145
149
  '"notVerified": ["<what you could not verify, and why>"], ' +
146
- '"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>"}]}. ' +
147
152
  "List every check you ran on the final tree with its real exit code; a check you did not run is " +
148
153
  'not a pass, and goes in "notVerified". "baseline" is "fails_on_base" only when the check already ' +
149
- "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.";
150
156
  const BUILD_RULES = (outDir) => [
151
157
  "Write tools are on now. Work as your playbook says:",
152
158
  "- Prefer the smallest change that meets the ticket.",
@@ -203,7 +209,7 @@ export function turnMessage(facts) {
203
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.`);
204
210
  if (answers)
205
211
  parts.push(answers);
206
- 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}`);
207
213
  }
208
214
  else if (facts.stage === "fix" && facts.review) {
209
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.`);
@@ -299,18 +305,22 @@ export function parseSessionReport(text, known = new Map()) {
299
305
  .map((entry) => line(entry))
300
306
  .filter((entry) => entry !== null)
301
307
  .slice(0, MAX_REPORT_LINES);
302
- const departures = list(data.departures)
303
- .flatMap((entry) => {
304
- if (!entry || typeof entry !== "object")
305
- return [];
306
- const record = entry;
307
- const what = line(record.what);
308
- if (!what)
309
- return [];
310
- return [{ from: line(record.from, 200) ?? "the plan", what, why: line(record.why) ?? "" }];
311
- })
312
- .slice(0, MAX_REPORT_LINES);
313
- 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 };
314
324
  }
315
325
  /** The checks the host named in `checks.json`, by their command, with how each stands on the base. */
316
326
  function knownBaselines(inputDir, readFile) {
@@ -332,18 +342,37 @@ export function withReport(attempt, report) {
332
342
  ...(report.summary ? [report.summary] : []),
333
343
  ...attempt.notes,
334
344
  ...report.notVerified.map((entry) => `Not verified: ${entry}`),
335
- ...report.departures.map((entry) => `Departed from ${entry.from}: ${entry.what}${entry.why ? `, because ${entry.why}` : ""}`),
345
+ ...report.planChanges.map(planChangeNote),
336
346
  ];
337
347
  return {
338
348
  ...attempt,
339
349
  checks: report.checks.length > 0 ? report.checks : attempt.checks,
340
350
  notes,
351
+ ...(report.planChanges.length > 0 ? { planChanges: report.planChanges } : {}),
341
352
  };
342
353
  }
354
+ /** The most of a child's stderr a failed turn's note carries. */
355
+ const STDERR_NOTE_LINES = 8;
356
+ const STDERR_NOTE_CHARS = 600;
357
+ /**
358
+ * The end of a turn's child's stderr as a note carries it: its last lines
359
+ * without the CLI's own `Skills:` line, secrets scrubbed, clipped; empty when
360
+ * nothing else is left. The child's stderr is the parent's alone, so without
361
+ * this a turn that died said nothing on the CLI's stderr either.
362
+ */
363
+ export function childStderrTail(stderr) {
364
+ const lines = scrubSecrets(stderr)
365
+ .split(/\r?\n/)
366
+ .map((line) => line.trim())
367
+ .filter((line) => line && !line.startsWith("Skills: "))
368
+ .slice(-STDERR_NOTE_LINES)
369
+ .join(" / ");
370
+ return lines.length > STDERR_NOTE_CHARS ? `...${lines.slice(-(STDERR_NOTE_CHARS - 3))}` : lines;
371
+ }
343
372
  /**
344
- * The turn's stop as the result names it: aborted, its clock, a child that
345
- * failed, a writing turn whose tools mostly errored (the cloud lane's health
346
- * gate), else clean.
373
+ * The turn's stop as the result names it: aborted, its clock, a model proxy
374
+ * that refused it for what the run may spend, a child that failed, a writing
375
+ * turn whose tools mostly errored (the cloud lane's health gate), else clean.
347
376
  */
348
377
  export function turnStop(run, writes, aborted) {
349
378
  if (aborted || run.stopReason === "aborted")
@@ -351,8 +380,19 @@ export function turnStop(run, writes, aborted) {
351
380
  if (run.timedOut) {
352
381
  return { stop: "budget_exceeded", note: "The turn ran out of the run's time and was stopped." };
353
382
  }
383
+ // The proxy's 402 or 429 for the workspace's credits or the run's own
384
+ // budget, in the pipeline's words, which the host reads as a spend stop
385
+ // (`spendStop.ts`) and hands to a person at once. Named only as an error,
386
+ // the host retried it twice into the same refusal and published the half
387
+ // build for review (staging NEARM-627, 2026-10-30).
388
+ const spent = creditExhaustionReason(run);
389
+ if (spent)
390
+ return { stop: "failed", note: `The session stopped: ${spent}` };
354
391
  if (run.exitCode !== 0 || run.stopReason === "error") {
355
- const why = run.errorMessage ? `: ${run.errorMessage.slice(0, 300)}` : "";
392
+ const said = scrubSecrets(run.errorMessage?.trim() ?? "") || childStderrTail(run.stderr);
393
+ const why = said
394
+ ? `: ${said.slice(0, STDERR_NOTE_CHARS)}`
395
+ : ` (exit ${run.exitCode}, nothing on its stderr)`;
356
396
  return { stop: "failed", note: `The session's turn ended on an error${why}.` };
357
397
  }
358
398
  if (writes &&
@@ -467,6 +507,10 @@ export async function runSessionTurn(input, deps = {}) {
467
507
  const stop = turnStop(run, writes, input.signal?.aborted === true);
468
508
  if (stop.note)
469
509
  notes.push(stop.note);
510
+ // On the CLI's own stderr too, whose tail the host logs with a session
511
+ // that ended without its work.
512
+ if (stop.stop === "failed" && stop.note)
513
+ input.writeErr(stop.note);
470
514
  const planned = input.stage !== "plan" || planText.trim().length > 0;
471
515
  ran = {
472
516
  result: {
@@ -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.2204.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": "481a9f9ced04d8756c322d0aa3edfe7420f6b957"
61
+ "yagniSourceSha": "250dab650145f8e7a80049cc227a6a69d24aac5b"
62
62
  }