@yagni-app/code-staging 1.2.14-staging.2545.1 → 1.2.15-staging.2575.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.
@@ -36,7 +36,7 @@ import type { PipelineStage } from "./types.js";
36
36
  * each fix. Its words never name the harness (the branding scrub rewrites
37
37
  * that word) and open with no bullet.
38
38
  */
39
- export declare const WORK_A_TICKET_SKILL = "---\nname: work-a-ticket\ndescription: How YAGNI works a ticket in one session, from reading it to a committed, honestly reported change. Read, run and plan with options and a recommendation, stop for approval, build the smallest change yourself, run its checks, commit and report.\n---\n\n# How YAGNI works a ticket\n\nYou work one ticket for a Team, in its repository, checked out in your working directory on a machine that is yours for the whole run. Your plan is approved before anything is built. YAGNI pushes your commits, opens the pull request, waits for CI and the review, and brings you back with what they asked. Each time YAGNI resumes you, its message says which turn this is and what it needs back. This is a playbook, not a contract: use your judgement, and say what you did.\n\n## 1. Understand the ticket\n\nRead the ticket, its evidence and every image it names, the design, the memo, the checks, the Team's playbook and the Plan line's instructions. Read the code the ticket touches, and send searcher subagents for wide reads, in parallel. Settle facts by running things rather than guessing: the tests, a type check, the app, Docker, a query. Installing what a check needs is fine. Read the decision ledger (team_read with yagni_decisions_read_for_repository) and ask_yagni before you ask a person anything.\n\nCheck the ticket before you build on it. Each thing it states and your plan relies on (a bug, a file, a behaviour, a number) is a premise: check it against the code, the git history or the data, and keep the command, file or query that shows it. A premise you cannot check is marked so, never assumed. Take \"Done when\" from the ticket's acceptance criteria, or write it when the ticket has none. When the check shows the problem is already gone, your plan recommends closing the ticket, with the evidence, instead of a change.\n\n## 2. Plan, then stop\n\nOpen the plan with the ticket check and \"Done when\". Name the files and the steps. Where there is a real choice of approach, give the options, each with what it changes and what it costs, and recommend one. End the turn with the plan in the format the message gives, and stop. Then you review your own plan in this session, round by round, at most four: check it against the ticket and the code, fix what you find in place, and send the whole plan again with the round's verdict. You have no edit or write tool until the plan is approved, and anything you change in tracked files before then is put back.\n\n## 3. Build\n\nThe option the approved plan settled on is binding. The plan's steps are guidance: when the code shows a better step, take it, and record the departure and why. Prefer the smallest change that meets the ticket: no drive-by refactors and no files the ticket does not need. Write the change yourself, in this session, with the ticket, the plan and the code you read in mind. Only when this turn's message names a helper, hand it fully specified chunks of work (the files, the change, the check that proves it) and keep the judgement calls yourself. Run the checks that prove the change. A check that already failed on the unchanged code is not yours to fix; say so.\n\n## 4. Check your own work\n\nBefore you commit, run every check in the repository's CI that your diff can trip, and see each new test fail without your change before it passes with it. Fix what your change breaks. No helper reviews or judges your change: once YAGNI opens the pull request, its review reads the diff.\n\n## 5. Commit and report\n\nCommit on the branch you are on, with clear messages. Never push, never open or edit a pull request, and never change the git identity or config. Write the report the message asks for last, and honestly: each check you ran with its real exit code, what you could not verify and why, and every departure from the plan and why. A check you did not run is not a pass.\n\n## Rules that always hold\n\nNever fabricate a path, a result or a check: \"not found\" and \"not verified\" are answers. Never print, commit or send a token or a variable's value. If the disk fills (\"no space left on device\"), stop and say so; do not delete or prune to go on. Call record_decision only for a consequential product or architecture call the plan did not settle.\n";
39
+ export declare const WORK_A_TICKET_SKILL = "---\nname: work-a-ticket\ndescription: How YAGNI works a ticket in one session, from reading it to a committed, honestly reported change. Read, run and plan with options and a recommendation, stop for approval, build the smallest change yourself, run its checks, commit and report.\n---\n\n# How YAGNI works a ticket\n\nYou work one ticket for a Team, in its repository, checked out in your working directory on a machine that is yours for the whole run. Your plan is approved before anything is built. YAGNI pushes your commits, opens the pull request, waits for CI and the review, and brings you back with what they asked. Each time YAGNI resumes you, its message says which turn this is and what it needs back. This is a playbook, not a contract: use your judgement, and say what you did.\n\n## 1. Understand the ticket\n\nRead the ticket, its evidence and every image it names, the design, the memo, the checks, the Team's playbook and the Plan line's instructions. Read the code the ticket touches, and send searcher subagents for wide reads, in parallel. Settle facts by checking rather than guessing: read the code, and look at the running system (the app, its logs, its data, Docker) with one targeted command per fact, such as one test file or one query. The whole repository's lint, type check, test suite and build are the build's work, not the plan's: a fact that needs one goes in the plan's checks. Read the decision ledger (team_read with yagni_decisions_read_for_repository) and ask_yagni before you ask a person anything.\n\nCheck the ticket before you build on it. Each thing it states and your plan relies on (a bug, a file, a behaviour, a number) is a premise: check it against the code, the git history or the data, and keep the command, file or query that shows it. A premise you cannot check is marked so, never assumed. Take \"Done when\" from the ticket's acceptance criteria, or write it when the ticket has none. When the check shows the problem is already gone, your plan recommends closing the ticket, with the evidence, instead of a change.\n\n## 2. Plan, then stop\n\nOpen the plan with the ticket check and \"Done when\". Name the files and the steps. Where there is a real choice of approach, give the options, each with what it changes and what it costs, and recommend one. End the turn with the plan in the format the message gives, and stop. Then you review your own plan in this session, round by round, at most four: check it against the ticket and the code, fix what you find in place, and send the whole plan again with the round's verdict. You have no edit or write tool until the plan is approved, and anything you change in tracked files before then is put back.\n\n## 3. Build\n\nThe option the approved plan settled on is binding. The plan's steps are guidance: when the code shows a better step, take it, and record the departure and why. Prefer the smallest change that meets the ticket: no drive-by refactors and no files the ticket does not need. Write the change yourself, in this session, with the ticket, the plan and the code you read in mind. Only when this turn's message names a helper, hand it fully specified chunks of work (the files, the change, the check that proves it) and keep the judgement calls yourself. Run the checks that prove the change. A check that already failed on the unchanged code is not yours to fix; say so.\n\n## 4. Check your own work\n\nBefore you commit, run every check in the repository's CI that your diff can trip, and see each new test fail without your change before it passes with it. Installing what a check needs is fine. Fix what your change breaks. No helper reviews or judges your change: once YAGNI opens the pull request, its review reads the diff.\n\n## 5. Commit and report\n\nCommit on the branch you are on, with clear messages. Never push, never open or edit a pull request, and never change the git identity or config. Write the report the message asks for last, and honestly: each check you ran with its real exit code, what you could not verify and why, and every departure from the plan and why. A check you did not run is not a pass.\n\n## Rules that always hold\n\nNever fabricate a path, a result or a check: \"not found\" and \"not verified\" are answers. Never print, commit or send a token or a variable's value. If the disk fills (\"no space left on device\"), stop and say so; do not delete or prune to go on. Call record_decision only for a consequential product or architecture call the plan did not settle.\n";
40
40
  /** Persona body keyed by the agent name referenced in `stages.ts`. */
41
41
  export declare const PERSONA_BODIES: Record<string, string>;
42
42
  /**
@@ -91,7 +91,7 @@ You work one ticket for a Team, in its repository, checked out in your working d
91
91
 
92
92
  ## 1. Understand the ticket
93
93
 
94
- Read the ticket, its evidence and every image it names, the design, the memo, the checks, the Team's playbook and the Plan line's instructions. Read the code the ticket touches, and send searcher subagents for wide reads, in parallel. Settle facts by running things rather than guessing: the tests, a type check, the app, Docker, a query. Installing what a check needs is fine. Read the decision ledger (team_read with yagni_decisions_read_for_repository) and ask_yagni before you ask a person anything.
94
+ Read the ticket, its evidence and every image it names, the design, the memo, the checks, the Team's playbook and the Plan line's instructions. Read the code the ticket touches, and send searcher subagents for wide reads, in parallel. Settle facts by checking rather than guessing: read the code, and look at the running system (the app, its logs, its data, Docker) with one targeted command per fact, such as one test file or one query. The whole repository's lint, type check, test suite and build are the build's work, not the plan's: a fact that needs one goes in the plan's checks. Read the decision ledger (team_read with yagni_decisions_read_for_repository) and ask_yagni before you ask a person anything.
95
95
 
96
96
  Check the ticket before you build on it. Each thing it states and your plan relies on (a bug, a file, a behaviour, a number) is a premise: check it against the code, the git history or the data, and keep the command, file or query that shows it. A premise you cannot check is marked so, never assumed. Take "Done when" from the ticket's acceptance criteria, or write it when the ticket has none. When the check shows the problem is already gone, your plan recommends closing the ticket, with the evidence, instead of a change.
97
97
 
@@ -105,7 +105,7 @@ The option the approved plan settled on is binding. The plan's steps are guidanc
105
105
 
106
106
  ## 4. Check your own work
107
107
 
108
- Before you commit, run every check in the repository's CI that your diff can trip, and see each new test fail without your change before it passes with it. Fix what your change breaks. No helper reviews or judges your change: once YAGNI opens the pull request, its review reads the diff.
108
+ Before you commit, run every check in the repository's CI that your diff can trip, and see each new test fail without your change before it passes with it. Installing what a check needs is fine. Fix what your change breaks. No helper reviews or judges your change: once YAGNI opens the pull request, its review reads the diff.
109
109
 
110
110
  ## 5. Commit and report
111
111
 
@@ -55,7 +55,7 @@ export function reviewMessage(inputDir, planText, round, cap = MAX_PLAN_REVIEW_R
55
55
  ? "A person approves it next, and the build follows it."
56
56
  : "The build follows it.";
57
57
  return [
58
- `${REVIEW_MESSAGE_OPENING}, round ${round} of at most ${cap}, against the ticket in ${at("ticket.md")} and the code. ${next} Read again what you need and run what settles a fact; change no tracked file and commit nothing.`,
58
+ `${REVIEW_MESSAGE_OPENING}, round ${round} of at most ${cap}, against the ticket in ${at("ticket.md")} and the code. ${next} Read again what you need, and settle a fact with one targeted command as you did while planning, never the whole repository's lint, type check, test suite or build; change no tracked file and commit nothing.`,
59
59
  [
60
60
  "Answer each of these questions against the code, not from memory:",
61
61
  '1. Ticket check: is each premise the plan relies on checked, with the command, file:line or query that shows it, or marked as not checkable? Is a premise marked checked really true? Is "Done when" written? When the plan recommends closing the ticket, check that evidence again yourself.',
@@ -176,10 +176,19 @@ export async function runStage(stage, ctx, deps) {
176
176
  // to the session id alone.
177
177
  const callerLabel = deps.callerLabel ?? (ctx.lens ? `go:${stage.id}:${ctx.lens}` : `go:${stage.id}`);
178
178
  // A timed stage (`stageClock.ts`): the child refuses tools from
179
- // `wrapUpAt`, and is stopped a grace after it.
180
- const wrapUpAt = stage.timeBudgetMs !== undefined && stage.timeBudgetMs > 0
181
- ? (deps.now ?? Date.now)() + stage.timeBudgetMs
179
+ // `wrapUpAt`, and is stopped a grace after its `timeBudgetMs`. A soft
180
+ // clock (`wrapUpAfterMs`) only moves `wrapUpAt` sooner: it stops nothing.
181
+ // A stage with no clock of its own (a subagent the timed child starts)
182
+ // keeps the moment its env inherited, on purpose: a helper runs no tool
183
+ // past its parent's mark, and is never stopped for it.
184
+ const hardBudgetMs = stage.timeBudgetMs !== undefined && stage.timeBudgetMs > 0 ? stage.timeBudgetMs : undefined;
185
+ const softBudgetMs = stage.wrapUpAfterMs !== undefined && stage.wrapUpAfterMs > 0
186
+ ? stage.wrapUpAfterMs
182
187
  : undefined;
188
+ const wrapUpMs = hardBudgetMs !== undefined && softBudgetMs !== undefined
189
+ ? Math.min(hardBudgetMs, softBudgetMs)
190
+ : (hardBudgetMs ?? softBudgetMs);
191
+ const wrapUpAt = wrapUpMs !== undefined ? (deps.now ?? Date.now)() + wrapUpMs : undefined;
183
192
  let timedOut = false;
184
193
  const childEnv = {
185
194
  ...envForCap,
@@ -244,13 +253,13 @@ export async function runStage(stage, ctx, deps) {
244
253
  }, 5000);
245
254
  killTimer.unref?.();
246
255
  };
247
- const clock = wrapUpAt !== undefined && stage.timeBudgetMs !== undefined
256
+ const clock = hardBudgetMs !== undefined
248
257
  ? setTimeout(() => {
249
258
  if (closed)
250
259
  return;
251
260
  timedOut = true;
252
261
  onAbort();
253
- }, stage.timeBudgetMs + STAGE_WRAP_UP_GRACE_MS)
262
+ }, hardBudgetMs + STAGE_WRAP_UP_GRACE_MS)
254
263
  : undefined;
255
264
  clock?.unref?.();
256
265
  const finish = (code) => {
@@ -17,8 +17,11 @@
17
17
  * one conversation; a Machine the host had to replace has none, and the turn
18
18
  * starts a fresh session whose message points at everything on disk.
19
19
  *
20
- * - Plan turn: read, search, run anything (tests, Docker, the app), no edit
21
- * or write tool. Its last message is the plan with the plan-json block,
20
+ * - Plan turn: read, search, look at the running system with one targeted
21
+ * command per fact (never the whole repository's lint, type check, test
22
+ * suite or build: those are the build's, YAG-1483), no edit or write
23
+ * tool, on a soft clock of its own ({@link SESSION_PLAN_MINUTES} a
24
+ * message). Its last message is the plan with the plan-json block,
22
25
  * asked for once more when the block is missing. The session then
23
26
  * reviews its own plan, one turn per round, fixing what it finds in
24
27
  * place, until a round lists nothing major or four rounds have run, and
@@ -42,7 +45,7 @@
42
45
  * the turn's tools refused once it is nearly spent), the tool-failure health
43
46
  * gate on a turn that writes, and the report's contract with the host. Not
44
47
  * kept: the review loop and its round cap, the fixer, and the plan stage's
45
- * own clock.
48
+ * hard clock: the plan turn's own is soft, and stops nothing.
46
49
  */
47
50
  import { type PlacedValues } from "../placedValues.js";
48
51
  import { type CodeWriter } from "./codeWriter.js";
@@ -198,6 +201,18 @@ export declare function systemRepositoriesOf(text: string | null, cwd: string):
198
201
  pushedHead: string | null;
199
202
  branch: string | null;
200
203
  }>;
204
+ /**
205
+ * What a plan turn runs (YAG-1483): it settles facts, and leaves the build's
206
+ * work to the build. On staging (2026-11-19, NMT-104) a yak's plan turn ran
207
+ * 31 minutes and about 191 commands, the whole repository's lint, type check,
208
+ * unit tests and a build, while this rule said to run "the tests, a type
209
+ * check". The cloud lane's plan stage has said the opposite since 2026-10-23
210
+ * (`stages.ts`). A yak still looks at its running system: that is what its
211
+ * machine is for.
212
+ */
213
+ export declare const PLAN_RUN_RULE = "Planning reads and settles facts. The build does the build's work. Read the code, and look at the running system (the app, its logs, its data, Docker) as much as the plan needs. Settle each fact with one targeted command: one test file, one query, one request to the app. Never run the whole repository's lint, type check, test suite or build in this turn: when a fact needs one, put that command in the plan's checks, and the build runs it. Change no tracked file and commit nothing: anything this turn changes in the repository is put back before the plan's gate.";
214
+ /** The plan turn's own clock, said up front, as the cloud lane's plan stage says its own. */
215
+ export declare const PLAN_CLOCK_RULE = "You have about 25 minutes for the plan. Past them every tool call is refused and you write the plan from what you have: state what you could not check as an assumption, and put the check that settles it in the plan's checks.";
201
216
  /** The one message a turn sends the session. Pure. */
202
217
  export declare function turnMessage(facts: TurnFacts): string;
203
218
  /** The model's own account of a turn that builds (`session-report.json`). */
@@ -253,6 +268,42 @@ export declare const SILENT_STREAM_NOTE: string;
253
268
  * Only the idle timer is silence: the 24 hour wall is not, and writes nothing.
254
269
  */
255
270
  export declare function sessionSilenceTelemetry(sessionId: string | undefined): (rec: ResilienceAttemptRecord) => void;
271
+ /**
272
+ * What a plan turn spent (YAG-1483), as its one log line says it. The cost
273
+ * is the turn's own model calls as pi prices them from the catalog (the same
274
+ * sum `result.json`'s usage carries), not its subagents' calls. What the run
275
+ * was charged for the turn is the host's (`yak_turns.cost_millicents`, which
276
+ * the model proxy adds each settled call to).
277
+ */
278
+ export interface PlanTurnRecord {
279
+ /** From the turn's start to its result. */
280
+ durationMs: number;
281
+ /** The session's messages this turn: the plan, any re-ask, each review round. */
282
+ messages: number;
283
+ /** The messages that ran to the plan clock, and so were told to write their answer. */
284
+ clockReached: number;
285
+ /** Every tool call the turn's messages ran, and the shell commands among them. */
286
+ toolCalls: number;
287
+ commands: number;
288
+ tokens: number;
289
+ costUsd: number;
290
+ stop: string;
291
+ }
292
+ /**
293
+ * The plan turn's cost above which its line is a warning: about half of the
294
+ * most an earlier whole ticket cost on the yak where a plan ran the build's
295
+ * work (staging, NMT-104). A warning only: a spend stop would hand the
296
+ * ticket to a person at once.
297
+ */
298
+ export declare const PLAN_TURN_COST_WARN_USD = 3;
299
+ /** A plan turn's record from its messages' results and what the turn counted. Pure. */
300
+ export declare function planTurnRecord(stages: readonly StageResult[], counted: Pick<PlanTurnRecord, "durationMs" | "clockReached" | "commands" | "stop">): PlanTurnRecord;
301
+ /**
302
+ * The plan turn's one content-free line in the extension's log, which the
303
+ * host keeps with the session's transcript: what it took and spent, at
304
+ * `warn` when it cost more than {@link PLAN_TURN_COST_WARN_USD}.
305
+ */
306
+ export declare function planTurnLog(sessionId: string | undefined): (rec: PlanTurnRecord) => void;
256
307
  export declare function turnStop(run: StageResult, writes: boolean, aborted: boolean): {
257
308
  stop: StopReason;
258
309
  note?: string;
@@ -307,6 +358,8 @@ export interface SessionTurnDeps {
307
358
  silenceMs?: number;
308
359
  /** Where the silence watch's records go ({@link sessionSilenceTelemetry}); a test reads them. */
309
360
  telemetry?: (rec: ResilienceAttemptRecord) => void;
361
+ /** Where a plan turn's record goes ({@link planTurnLog}); a test reads it. */
362
+ planTurnLog?: (rec: PlanTurnRecord) => void;
310
363
  /** A yak's placed values (YAG-1209); absent, read from the machine, null on any other. */
311
364
  placedValues?: PlacedValues | null;
312
365
  }
@@ -17,8 +17,11 @@
17
17
  * one conversation; a Machine the host had to replace has none, and the turn
18
18
  * starts a fresh session whose message points at everything on disk.
19
19
  *
20
- * - Plan turn: read, search, run anything (tests, Docker, the app), no edit
21
- * or write tool. Its last message is the plan with the plan-json block,
20
+ * - Plan turn: read, search, look at the running system with one targeted
21
+ * command per fact (never the whole repository's lint, type check, test
22
+ * suite or build: those are the build's, YAG-1483), no edit or write
23
+ * tool, on a soft clock of its own ({@link SESSION_PLAN_MINUTES} a
24
+ * message). Its last message is the plan with the plan-json block,
22
25
  * asked for once more when the block is missing. The session then
23
26
  * reviews its own plan, one turn per round, fixing what it finds in
24
27
  * place, until a round lists nothing major or four rounds have run, and
@@ -42,7 +45,7 @@
42
45
  * the turn's tools refused once it is nearly spent), the tool-failure health
43
46
  * gate on a turn that writes, and the report's contract with the host. Not
44
47
  * kept: the review loop and its round cap, the fixer, and the plan stage's
45
- * own clock.
48
+ * hard clock: the plan turn's own is soft, and stops nothing.
46
49
  */
47
50
  import { createHash } from "node:crypto";
48
51
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
@@ -68,7 +71,7 @@ import { runStage as defaultRunStage } from "./runner.js";
68
71
  import { scrubSecrets } from "./scrubSecrets.js";
69
72
  import { DECISIONS_READ_TOOL, PIECES_RULE, YAK_FOLLOW_UPS_RULE, PLAN_JSON_CONTRACT, YAK_PLAN_JSON_CONTRACT, } from "./stages.js";
70
73
  import { planReviewRoundsFor, planSizeOf, sessionTicketPathOf, TICKET_PATH_FILE_NAME, } from "./ticketPath.js";
71
- import { STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
74
+ import { SESSION_PLAN_MINUTES, STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
72
75
  import { editsMostlyFailed } from "./events.js";
73
76
  import { DEFAULT_RESILIENCE_POLICY } from "./types.js";
74
77
  import { baselineDirs, parseChangedPaths, planPaths } from "./verify.js";
@@ -338,8 +341,21 @@ const previewReask = (inputDir, outDir, problems) => `The plan has no UI preview
338
341
  `If the plan changes anything a person sees on a screen, write the preview now as ${join(inputDir, UI_PREVIEW_BRIEF_FILE_NAME)} says. ` +
339
342
  `If it changes nothing on a screen, write ${join(outDir, UI_PREVIEW_NONE_FILE_NAME)} with one line saying why. ` +
340
343
  "Leave the plan as it is and do not send it again: answer in one line when the file is written.";
344
+ /**
345
+ * What a plan turn runs (YAG-1483): it settles facts, and leaves the build's
346
+ * work to the build. On staging (2026-11-19, NMT-104) a yak's plan turn ran
347
+ * 31 minutes and about 191 commands, the whole repository's lint, type check,
348
+ * unit tests and a build, while this rule said to run "the tests, a type
349
+ * check". The cloud lane's plan stage has said the opposite since 2026-10-23
350
+ * (`stages.ts`). A yak still looks at its running system: that is what its
351
+ * machine is for.
352
+ */
353
+ export const PLAN_RUN_RULE = "Planning reads and settles facts. The build does the build's work. Read the code, and look at the running system (the app, its logs, its data, Docker) as much as the plan needs. Settle each fact with one targeted command: one test file, one query, one request to the app. Never run the whole repository's lint, type check, test suite or build in this turn: when a fact needs one, put that command in the plan's checks, and the build runs it. Change no tracked file and commit nothing: anything this turn changes in the repository is put back before the plan's gate.";
354
+ /** The plan turn's own clock, said up front, as the cloud lane's plan stage says its own. */
355
+ export const PLAN_CLOCK_RULE = `You have about ${SESSION_PLAN_MINUTES} minutes for the plan. Past them every tool call is refused and you write the plan from what you have: state what you could not check as an assumption, and put the check that settles it in the plan's checks.`;
341
356
  const PLAN_RULES_BEFORE_PREVIEW = [
342
- "Run whatever settles a fact: the tests, a type check, the app, Docker, a query. Change no tracked file and commit nothing: anything this turn changes in the repository is put back before the plan's gate.",
357
+ PLAN_RUN_RULE,
358
+ PLAN_CLOCK_RULE,
343
359
  `Call team_read with tool "${DECISIONS_READ_TOOL}" before you ask a person anything: a question an earlier decision on this repository already answers is not a question.`,
344
360
  "Check the ticket before you plan on it: each premise it states that the plan relies on, against the code, the git history or the data. Read each one yourself, in this session: a searcher subagent's summary only says where to look.",
345
361
  ];
@@ -652,6 +668,51 @@ export function sessionSilenceTelemetry(sessionId) {
652
668
  });
653
669
  };
654
670
  }
671
+ /**
672
+ * The plan turn's cost above which its line is a warning: about half of the
673
+ * most an earlier whole ticket cost on the yak where a plan ran the build's
674
+ * work (staging, NMT-104). A warning only: a spend stop would hand the
675
+ * ticket to a person at once.
676
+ */
677
+ export const PLAN_TURN_COST_WARN_USD = 3;
678
+ /** A plan turn's record from its messages' results and what the turn counted. Pure. */
679
+ export function planTurnRecord(stages, counted) {
680
+ let tokens = 0;
681
+ let cost = 0;
682
+ let toolCalls = 0;
683
+ for (const stage of stages) {
684
+ const { input, output, cacheRead, cacheWrite } = stage.usage;
685
+ tokens += input + output + cacheRead + cacheWrite;
686
+ cost += stage.usage.cost;
687
+ toolCalls += stage.toolCalls;
688
+ }
689
+ return {
690
+ durationMs: counted.durationMs,
691
+ messages: stages.length,
692
+ clockReached: counted.clockReached,
693
+ toolCalls,
694
+ commands: counted.commands,
695
+ tokens,
696
+ costUsd: Math.round(cost * 10_000) / 10_000,
697
+ stop: counted.stop,
698
+ };
699
+ }
700
+ /**
701
+ * The plan turn's one content-free line in the extension's log, which the
702
+ * host keeps with the session's transcript: what it took and spent, at
703
+ * `warn` when it cost more than {@link PLAN_TURN_COST_WARN_USD}.
704
+ */
705
+ export function planTurnLog(sessionId) {
706
+ return (rec) => {
707
+ logEvent({
708
+ source: "session_lane",
709
+ level: rec.costUsd > PLAN_TURN_COST_WARN_USD ? "warn" : "info",
710
+ event: "plan_turn_ended",
711
+ sessionId,
712
+ fields: { ...rec },
713
+ });
714
+ };
715
+ }
655
716
  export function turnStop(run, writes, aborted) {
656
717
  if (aborted)
657
718
  return { stop: "aborted" };
@@ -792,14 +853,34 @@ export async function runSessionTurn(input, deps = {}) {
792
853
  // A beat that could not be written is a beat missed, never the turn's failure.
793
854
  }
794
855
  }, HEARTBEAT_EVERY_MS);
856
+ const startedAt = now();
857
+ const tally = { messages: [], commands: 0, clockReached: 0 };
858
+ // A plan turn's line is written however the turn ends, a throw included:
859
+ // that is the turn an operator most wants counted.
860
+ let stop = "failed";
795
861
  try {
796
- return await runTurn(input, deps, pulse);
862
+ const outcome = await runTurn(input, deps, pulse, tally);
863
+ stop = outcome.attempt.stopReason;
864
+ return outcome;
797
865
  }
798
866
  finally {
799
867
  beat.stop();
868
+ if (input.stage === "plan") {
869
+ try {
870
+ (deps.planTurnLog ?? planTurnLog(input.childEnv.YAGNI_SESSION_ID?.trim()))(planTurnRecord(tally.messages, {
871
+ durationMs: Math.max(0, now() - startedAt),
872
+ clockReached: tally.clockReached,
873
+ commands: tally.commands,
874
+ stop,
875
+ }));
876
+ }
877
+ catch {
878
+ // A line that could not be written is a line missed, never the turn's failure.
879
+ }
880
+ }
800
881
  }
801
882
  }
802
- async function runTurn(input, deps, pulse) {
883
+ async function runTurn(input, deps, pulse, tally) {
803
884
  const readFile = deps.readFile ?? ((path) => readFileSync(path, "utf8"));
804
885
  const writeFile = deps.writeFile ?? ((path, text) => writeFileSync(path, text));
805
886
  const exists = deps.exists ?? existsSync;
@@ -905,9 +986,23 @@ async function runTurn(input, deps, pulse) {
905
986
  const stageId = feedStage(input.stage);
906
987
  /** The run's time left before the turn's finish, read again for every child. */
907
988
  const timeLeftMs = () => input.deadlineMs === undefined ? undefined : input.deadlineMs - now() - TURN_FINISH_RESERVE_MS;
989
+ /**
990
+ * A plan turn's own clock, for each of its messages (YAG-1483): soft, so
991
+ * past it the child's tools are refused and the model writes its plan, and
992
+ * nothing ends the child, the session or the machine for it. The run's
993
+ * deadline stays the only clock that stops a child. None on a writing turn.
994
+ * It reaches the message's subagents too, on purpose: each inherits the
995
+ * child's `YAGNI_STAGE_WRAP_UP_AT`, as it does the deadline's, so a helper
996
+ * runs no tool past the message's mark either.
997
+ */
998
+ const planClockMs = writes ? undefined : SESSION_PLAN_MINUTES * 60_000;
908
999
  const withClock = (stage) => {
909
1000
  const left = timeLeftMs();
910
- return left === undefined ? stage : { ...stage, timeBudgetMs: Math.max(60_000, left) };
1001
+ return {
1002
+ ...stage,
1003
+ ...(left === undefined ? {} : { timeBudgetMs: Math.max(60_000, left) }),
1004
+ ...(planClockMs === undefined ? {} : { wrapUpAfterMs: planClockMs }),
1005
+ };
911
1006
  };
912
1007
  const turnStage = {
913
1008
  id: stageId,
@@ -949,6 +1044,8 @@ async function runTurn(input, deps, pulse) {
949
1044
  !event.isError) {
950
1045
  decisionsRecorded += 1;
951
1046
  }
1047
+ if (event.type === "tool_execution_end" && event.toolName === "bash")
1048
+ tally.commands += 1;
952
1049
  input.emit({ ...event, yagni: { stage: stageId } });
953
1050
  },
954
1051
  now,
@@ -974,11 +1071,17 @@ async function runTurn(input, deps, pulse) {
974
1071
  }
975
1072
  : {};
976
1073
  stageOpened = true;
977
- input.emit({ type: "pipeline_stage", stage: stageId, phase: "start", ...marks, at: now() });
1074
+ const began = now();
1075
+ input.emit({ type: "pipeline_stage", stage: stageId, phase: "start", ...marks, at: began });
978
1076
  try {
979
- return await runStage(withClock(turnStage), { ticket: message }, runDeps);
1077
+ const result = await runStage(withClock(turnStage), { ticket: message }, runDeps);
1078
+ // Counted as each message ends, so a turn that throws later still counts it.
1079
+ tally.messages.push(result);
1080
+ return result;
980
1081
  }
981
1082
  finally {
1083
+ if (planClockMs !== undefined && now() - began >= planClockMs)
1084
+ tally.clockReached += 1;
982
1085
  input.emit({ type: "pipeline_stage", stage: stageId, phase: "finish", ...marks, at: now() });
983
1086
  }
984
1087
  };
@@ -9,13 +9,24 @@
9
9
  * sandbox's own clock, which parent and child share), and the child's
10
10
  * extension refuses every tool call from then on with words that tell the
11
11
  * model to write its answer now. A grace later the runner stops the child
12
- * (`runner.ts`), and the orchestrator ends the run `budget_exceeded`.
12
+ * (`runner.ts`), and the orchestrator ends the run `budget_exceeded`. A soft
13
+ * clock (`PipelineStage.wrapUpAfterMs`, the session lane's plan turn) has the
14
+ * first half only: the runner never stops a child for it.
13
15
  */
14
16
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
15
17
  /** The child's env: the epoch millisecond its stage's time is up. */
16
18
  export declare const STAGE_WRAP_UP_AT_ENV = "YAGNI_STAGE_WRAP_UP_AT";
17
19
  /** The cloud plan stage's time, in minutes. Plans on staging took 8 to 16 minutes. */
18
20
  export declare const CLOUD_PLAN_MINUTES = 20;
21
+ /**
22
+ * The session lane's plan clock, in minutes, for each message of a plan turn
23
+ * (YAG-1483). Soft (`PipelineStage.wrapUpAfterMs`): past it the child refuses
24
+ * every tool call and the model writes its answer, and nothing stops the child
25
+ * for it. On staging (39 yak plan drafts, 2026-11-04 to 11-19) a draft took
26
+ * 5.9 minutes at the median and 26.3 at the 90th percentile, and a review
27
+ * round 1.8 and 5.5, while the plan's rules still said to run the tests.
28
+ */
29
+ export declare const SESSION_PLAN_MINUTES = 25;
19
30
  /** How long past its time a stage child may take to write its answer before it is stopped. */
20
31
  export declare const STAGE_WRAP_UP_GRACE_MS: number;
21
32
  /** The refusal a tool call gets once the stage's time is up. */
@@ -9,12 +9,23 @@
9
9
  * sandbox's own clock, which parent and child share), and the child's
10
10
  * extension refuses every tool call from then on with words that tell the
11
11
  * model to write its answer now. A grace later the runner stops the child
12
- * (`runner.ts`), and the orchestrator ends the run `budget_exceeded`.
12
+ * (`runner.ts`), and the orchestrator ends the run `budget_exceeded`. A soft
13
+ * clock (`PipelineStage.wrapUpAfterMs`, the session lane's plan turn) has the
14
+ * first half only: the runner never stops a child for it.
13
15
  */
14
16
  /** The child's env: the epoch millisecond its stage's time is up. */
15
17
  export const STAGE_WRAP_UP_AT_ENV = "YAGNI_STAGE_WRAP_UP_AT";
16
18
  /** The cloud plan stage's time, in minutes. Plans on staging took 8 to 16 minutes. */
17
19
  export const CLOUD_PLAN_MINUTES = 20;
20
+ /**
21
+ * The session lane's plan clock, in minutes, for each message of a plan turn
22
+ * (YAG-1483). Soft (`PipelineStage.wrapUpAfterMs`): past it the child refuses
23
+ * every tool call and the model writes its answer, and nothing stops the child
24
+ * for it. On staging (39 yak plan drafts, 2026-11-04 to 11-19) a draft took
25
+ * 5.9 minutes at the median and 26.3 at the 90th percentile, and a review
26
+ * round 1.8 and 5.5, while the plan's rules still said to run the tests.
27
+ */
28
+ export const SESSION_PLAN_MINUTES = 25;
18
29
  /** How long past its time a stage child may take to write its answer before it is stopped. */
19
30
  export const STAGE_WRAP_UP_GRACE_MS = 10 * 60_000;
20
31
  /** The refusal a tool call gets once the stage's time is up. */
@@ -85,6 +85,13 @@ export interface PipelineStage {
85
85
  * `timedOut`. Absent on every stage but the cloud plan stage.
86
86
  */
87
87
  timeBudgetMs?: number;
88
+ /**
89
+ * A soft clock, in milliseconds: past it (or past {@link timeBudgetMs},
90
+ * whichever comes first) the child refuses every tool call, as above, but
91
+ * the runner never stops the child for it. The session lane's plan turn
92
+ * (`SESSION_PLAN_MINUTES`, YAG-1483), whose only hard clock is the run's.
93
+ */
94
+ wrapUpAfterMs?: number;
88
95
  }
89
96
  /**
90
97
  * A stage list and the loop rules that go with it. The `full` lane is what
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2545.1",
3
+ "version": "1.2.15-staging.2575.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": "50548368b32099ab747418e6749a7f515ea15475"
61
+ "yagniSourceSha": "192dd4287a4a4b74fa6edfe4e393d41e58f231f4"
62
62
  }