@yagni-app/code-staging 1.2.14-staging.2347.1 → 1.2.14-staging.2351.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.
@@ -128,6 +128,12 @@ export interface AttemptResult extends CloudIdentity {
128
128
  * adds its own parts.
129
129
  */
130
130
  pullRequestText?: string;
131
+ /**
132
+ * How a plan turn asked for the plan's UI preview left it (`sessionLane.ts`):
133
+ * a whole page, its word that nothing on a screen changes, or neither.
134
+ * Absent on every other turn: the host then drafts the preview itself.
135
+ */
136
+ uiPreview?: "drawn" | "none" | "not_drawn";
131
137
  }
132
138
  /** The findings the result reports, blocking first. */
133
139
  export declare function openFindings(findings: readonly Finding[]): OpenFinding[];
@@ -78,6 +78,32 @@ export declare const MAX_PULL_REQUEST_TEXT_CHARS = 20000;
78
78
  export declare function pullRequestTextOf(text: string | null): string | null;
79
79
  /** What a plan turn may use: everything that reads or runs, nothing that edits. */
80
80
  export declare const PLAN_TURN_TOOLS: string[];
81
+ /**
82
+ * The brief the host writes beside the ticket when the plan turn draws the
83
+ * plan's UI preview itself (a yak's; `attempts/sessionPreview.ts`): the page's
84
+ * contract and how to work. Absent, the turn draws none and its result says
85
+ * nothing about one, so the host drafts the preview as it always did.
86
+ */
87
+ export declare const UI_PREVIEW_BRIEF_FILE_NAME = "ui-preview-brief.md";
88
+ /** The preview's page, in the output folder (the host's `SESSION_PREVIEW_FILE`). */
89
+ export declare const UI_PREVIEW_FILE_NAME = "preview.html";
90
+ /** What the turn writes instead of a page when the plan changes nothing on a screen. */
91
+ export declare const UI_PREVIEW_NONE_FILE_NAME = "ui-preview-none.md";
92
+ /** The most a preview's page may weigh (the host's `MAX_SESSION_PREVIEW_BYTES`). */
93
+ export declare const MAX_UI_PREVIEW_BYTES: number;
94
+ /** How a plan turn asked for its UI preview left it (`AttemptResult.uiPreview`). */
95
+ export type UiPreviewOutcome = "drawn" | "none" | "not_drawn";
96
+ /**
97
+ * What a plan turn that draws its preview may use: the plan turn's tools, and
98
+ * write and edit for the page. Anything they change in the repository is put
99
+ * back before the plan's gate, as a shell's change is ({@link putBackPlanTurn}).
100
+ */
101
+ export declare const PLAN_PREVIEW_TURN_TOOLS: string[];
102
+ /**
103
+ * Why a preview's page cannot stand, as the host's judge would refuse it
104
+ * (`parseDesignDocument`): empty when it is a whole page within size. Pure.
105
+ */
106
+ export declare function previewPageProblems(text: string | null): string[];
81
107
  /** What a turn that builds may use: the plan turn's tools and the writes. */
82
108
  export declare const BUILD_TURN_TOOLS: string[];
83
109
  /** The run's files under the run user's home: its one session, and the playbook it runs on. */
@@ -110,9 +136,21 @@ export interface TurnFacts {
110
136
  * (YAG-1162). Any stage, the plan's included.
111
137
  */
112
138
  newSinceLastTurn?: string | null;
139
+ /**
140
+ * The input folder has `ui-preview-brief.md`: this plan turn draws the
141
+ * plan's UI preview itself. Only ever on a plan turn.
142
+ */
143
+ preview?: boolean;
113
144
  /** Who writes the change, as the host said (`codeWriter.ts`); absent, the session. */
114
145
  codeWriter?: CodeWriter;
146
+ /**
147
+ * The input folder has `own-plans.md`: this yak approves its own plans, so
148
+ * no person answers the plan's questions. Only ever on a plan turn.
149
+ */
150
+ ownPlans?: boolean;
115
151
  }
152
+ /** The file the host writes when a yak approves its own plans (`attempts/inputs.ts`, `yaks/ownPlans.ts`). */
153
+ export declare const OWN_PLANS_FILE_NAME = "own-plans.md";
116
154
  /** The file the host writes a person's note for the next step to (`attempts/inputs.ts`). */
117
155
  export declare const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
118
156
  /** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
@@ -198,6 +236,8 @@ export interface SessionTurnDeps {
198
236
  writeFile?: (path: string, text: string) => void;
199
237
  exists?: (path: string) => boolean;
200
238
  mkdir?: (path: string) => void;
239
+ /** Removes a file, missing or not: the last turn's preview files. */
240
+ remove?: (path: string) => void;
201
241
  exec?: WorktreeExec;
202
242
  snapshot?: typeof snapshotWorkspace;
203
243
  /** The run user's home; the Machine's `/home/user`. */
@@ -43,7 +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 { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
46
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
47
47
  import { homedir } from "node:os";
48
48
  import { isAbsolute, join, relative } from "node:path";
49
49
  import { openPlacedValues } from "../placedValues.js";
@@ -105,6 +105,48 @@ export const PLAN_TURN_TOOLS = [
105
105
  "prototype_read",
106
106
  "subagent",
107
107
  ];
108
+ /**
109
+ * The brief the host writes beside the ticket when the plan turn draws the
110
+ * plan's UI preview itself (a yak's; `attempts/sessionPreview.ts`): the page's
111
+ * contract and how to work. Absent, the turn draws none and its result says
112
+ * nothing about one, so the host drafts the preview as it always did.
113
+ */
114
+ export const UI_PREVIEW_BRIEF_FILE_NAME = "ui-preview-brief.md";
115
+ /** The preview's page, in the output folder (the host's `SESSION_PREVIEW_FILE`). */
116
+ export const UI_PREVIEW_FILE_NAME = "preview.html";
117
+ /** What the turn writes instead of a page when the plan changes nothing on a screen. */
118
+ export const UI_PREVIEW_NONE_FILE_NAME = "ui-preview-none.md";
119
+ /** The most a preview's page may weigh (the host's `MAX_SESSION_PREVIEW_BYTES`). */
120
+ export const MAX_UI_PREVIEW_BYTES = 4 * 1024 * 1024;
121
+ /**
122
+ * What a plan turn that draws its preview may use: the plan turn's tools, and
123
+ * write and edit for the page. Anything they change in the repository is put
124
+ * back before the plan's gate, as a shell's change is ({@link putBackPlanTurn}).
125
+ */
126
+ export const PLAN_PREVIEW_TURN_TOOLS = [...PLAN_TURN_TOOLS, "write", "edit"];
127
+ const VIEW_MARKER = /\sdata-yagni-(?:view|state|choice)\s*=/i;
128
+ /**
129
+ * Why a preview's page cannot stand, as the host's judge would refuse it
130
+ * (`parseDesignDocument`): empty when it is a whole page within size. Pure.
131
+ */
132
+ export function previewPageProblems(text) {
133
+ const html = text?.trim() ?? "";
134
+ if (!html)
135
+ return ["the file is missing or empty"];
136
+ const problems = [];
137
+ if (!/^(?:<!doctype html[^>]*>\s*)?<html[\s>]/i.test(html) && !/^<!doctype html/i.test(html)) {
138
+ problems.push("it must be a whole HTML document that starts with <!doctype html> or <html>");
139
+ }
140
+ if (!/<\/html>\s*$/i.test(html))
141
+ problems.push("it must end with </html>; it looks cut off");
142
+ if (VIEW_MARKER.test(html)) {
143
+ problems.push("it must carry no data-yagni-view, data-yagni-state or data-yagni-choice attribute");
144
+ }
145
+ if (Buffer.byteLength(html, "utf8") > MAX_UI_PREVIEW_BYTES) {
146
+ problems.push(`it is over ${MAX_UI_PREVIEW_BYTES / (1024 * 1024)} MB`);
147
+ }
148
+ return problems;
149
+ }
108
150
  /** What a turn that builds may use: the plan turn's tools and the writes. */
109
151
  export const BUILD_TURN_TOOLS = [
110
152
  ...PLAN_TURN_TOOLS,
@@ -135,6 +177,8 @@ function feedStage(stage) {
135
177
  return "fix";
136
178
  return "implement";
137
179
  }
180
+ /** The file the host writes when a yak approves its own plans (`attempts/inputs.ts`, `yaks/ownPlans.ts`). */
181
+ export const OWN_PLANS_FILE_NAME = "own-plans.md";
138
182
  /** The file the host writes a person's note for the next step to (`attempts/inputs.ts`). */
139
183
  export const NEXT_STEP_NOTE_FILE_NAME = "next-step-note.md";
140
184
  /** The file the host writes a yak's new messages to (`attempts/inputs.ts`, `yaks/turns.ts`). */
@@ -178,8 +222,10 @@ const REPORT_CONTRACT = (outDir) => `Last, write ${join(outDir, SESSION_REPORT_F
178
222
  '"planChanges": [{"step": <the step\'s number in plan.md, or null for the plan as a whole>, ' +
179
223
  '"instead": "<what you did instead>", "why": "<why>"}]}. ' +
180
224
  "List every check you ran on the final tree with its real exit code; a check you did not run is " +
181
- 'not a pass, and goes in "notVerified". "baseline" is "fails_on_base" only when the check already ' +
182
- 'failed on the unchanged code. "planChanges" lists only a step you did differently than plan.md ' +
225
+ 'not a pass, and goes in "notVerified". "baseline" is "fails_on_base" only when the check failed on ' +
226
+ "the unchanged code in a run this attempt made, yours or one checks.json's baseMeasured names; a " +
227
+ 'record alone never makes it so. A check may carry "note": the new test that proves a behavior ' +
228
+ 'change says there what it showed failing without the change. "planChanges" lists only a step you did differently than plan.md ' +
183
229
  "says, or left out, never a choice the plan left to you. Then end your turn.";
184
230
  /** The build rule that says who writes the change: the host's value, in words. */
185
231
  const WRITER_RULE = (who) => who.writer === "helper"
@@ -193,9 +239,11 @@ const PULL_REQUEST_CONTRACT = (outDir) => `Before the report, write ${join(outDi
193
239
  "environment: everyone on the repository reads it. Write no title, checks table or plan version: YAGNI adds those.";
194
240
  const BUILD_RULES = (outDir, who) => [
195
241
  "Write tools are on now. Work as your playbook says:",
196
- "- Prefer the smallest change that meets the ticket.",
242
+ "- Prefer the smallest change that meets the ticket, and keep the diff to what the ticket needs.",
197
243
  WRITER_RULE(who),
198
- "- Run the checks that prove the change (checks.json, the plan's checks) and fix what your change breaks.",
244
+ "- Read the repository's CI workflows (.github/workflows, or the CI it uses) and run every check there your diff can trip, beside checks.json and the plan's checks; fix what your change breaks.",
245
+ "- Each behavior change gets a test. Run it once without the change and see it fail, then with it; in the report, that test's check says in its note what failed without the change.",
246
+ "- A check checks.json marks measureOnBase, or one you would call fails_on_base, is measured on the unchanged code during this attempt: before your first edit, or in a git worktree at the commit this branch started from. A red in the repository's record is not a measurement, however recent; a baseMeasured entry in checks.json is.",
199
247
  "- Before you finish, dispatch a fresh verification subagent on your diff with the ticket and the plan, and fix what it finds that is real.",
200
248
  "- Commit on the branch you are on. Never push and never open or edit a pull request: YAGNI pushes your commits and opens it.",
201
249
  `- ${PULL_REQUEST_CONTRACT(outDir)}`,
@@ -212,16 +260,55 @@ const INPUTS = (inputDir) => [
212
260
  ].join("\n");
213
261
  /** A close recommendation sent back is a person's call that the ticket needs work. */
214
262
  const PLANNED_ANYWAY = "If the plan sent back recommended closing the ticket, the person chose to plan it anyway: plan the change, and do not recommend closing it again.";
215
- const PLAN_RULES = [
216
- "This turn you have read, grep, find, ls, bash, ask_yagni, team_read, prototype_read and subagent, and no edit or write tool.",
217
- "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.",
218
- `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.`,
219
- "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.",
220
- "End the turn with the plan as your last message. Open it with ## Ticket check: a table of premise | checked, or not checkable | the command, file:line or query that shows it, one row per premise. Then ## Done when: the ticket's acceptance criteria, or yours when it has none, one line each. Then ## Goal (one sentence), ## Plan (numbered steps, each naming the file or function), ## Files to modify / create (say \"new\" beside a file the plan creates), ## Checks and ## Risks, then the plan-json block. Where there is a real choice of approach, ask it as a decision question with your recommendation and its alternatives; the plan's steps follow your recommendation.",
221
- '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.',
263
+ const PLAN_TOOLS = "read, grep, find, ls, bash, ask_yagni, team_read, prototype_read and subagent";
264
+ /**
265
+ * The plan turn's rules. With `preview` (the host's brief is in the input
266
+ * folder) the turn also draws the plan's UI preview: it gets write and edit
267
+ * for the preview's files, and the rule that says when to draw one.
268
+ */
269
+ const planRules = (preview, ownPlans) => [
270
+ preview
271
+ ? `This turn you have ${PLAN_TOOLS}, and write and edit for the UI preview's files in ${preview.outDir} only: never for a file in the repository.`
272
+ : `This turn you have ${PLAN_TOOLS}, and no edit or write tool.`,
273
+ ...PLAN_RULES_BEFORE_PREVIEW,
274
+ ...(preview ? [previewRule(preview.inputDir, preview.outDir)] : []),
275
+ `${PLAN_FORMAT_RULE} ${ownPlans ? DECIDE_RULE : QUESTION_RULE}`,
276
+ PLAN_CLOSE_RULE,
222
277
  PLAN_JSON_CONTRACT,
223
- "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.",
278
+ ownPlans ? OWN_PLANS_STOP : PLAN_STOP,
224
279
  ].join("\n\n");
280
+ /** When a plan turn draws the plan's UI preview, and what it writes when the plan has nothing to show. */
281
+ const previewRule = (inputDir, outDir) => `A person reads this plan beside its UI preview, and you draw it: read ${join(inputDir, UI_PREVIEW_BRIEF_FILE_NAME)} before you plan. ` +
282
+ `When the plan changes anything a person sees on a screen, write the preview to ${join(outDir, UI_PREVIEW_FILE_NAME)} as the brief says, before your plan message, ` +
283
+ "from what you read and ran this turn, and keep it in step with the plan whenever a review changes the plan. " +
284
+ `When the plan changes nothing on a screen, write ${join(outDir, UI_PREVIEW_NONE_FILE_NAME)} instead, with one line saying why, and draw nothing.`;
285
+ /** What a plan turn that left neither a page nor its none file is asked, once. */
286
+ const previewReask = (inputDir, outDir, problems) => `The plan has no UI preview yet: ${join(outDir, UI_PREVIEW_FILE_NAME)} cannot stand (${problems.join("; ")}), and ${join(outDir, UI_PREVIEW_NONE_FILE_NAME)} is not there. ` +
287
+ `If the plan changes anything a person sees on a screen, write the preview now as ${join(inputDir, UI_PREVIEW_BRIEF_FILE_NAME)} says. ` +
288
+ `If it changes nothing on a screen, write ${join(outDir, UI_PREVIEW_NONE_FILE_NAME)} with one line saying why. ` +
289
+ "Leave the plan as it is and do not send it again: answer in one line when the file is written.";
290
+ const PLAN_RULES_BEFORE_PREVIEW = [
291
+ "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.",
292
+ `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.`,
293
+ "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.",
294
+ ];
295
+ const PLAN_FORMAT_RULE = 'End the turn with the plan as your last message. Open it with ## Ticket check: a table of premise | checked, or not checkable | the command, file:line or query that shows it, one row per premise. Then ## Done when: the ticket\'s acceptance criteria, or yours when it has none, one line each. Then ## Goal (one sentence), ## Plan (numbered steps, each naming the file or function), ## Files to modify / create (say "new" beside a file the plan creates), ## Checks and ## Risks, then the plan-json block.';
296
+ /** Where a person answers the plan: a real choice is theirs to make. */
297
+ const QUESTION_RULE = "Where there is a real choice of approach, ask it as a decision question with your recommendation and its alternatives; the plan's steps follow your recommendation.";
298
+ /**
299
+ * Where the yak approves its own plans (`own-plans.md`): YAGNI takes every
300
+ * recommendation, so a question only records a change of direction.
301
+ */
302
+ 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.";
303
+ 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.';
304
+ 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.";
305
+ 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.";
306
+ /**
307
+ * How a turn treats a review's items. The host acknowledges each thread at
308
+ * take and posts the outcomes after its push (`attempts/review.ts`), with the
309
+ * marker Proctor reads, so a reply of the session's own is noise or worse.
310
+ */
311
+ const FIX_RULE = "For each item: check it against the pull request on GitHub as it is now (read it with gh, and only read), then fix it, with a test that fails without the fix where it changes behavior, or dispute it with evidence a reviewer can check. Never reply, comment, react or resolve on GitHub: YAGNI posts your outcomes on each thread after it pushes your commit.";
225
312
  /** The one message a turn sends the session. Pure. */
226
313
  export function turnMessage(facts) {
227
314
  const at = (file) => join(facts.inputDir, file);
@@ -238,14 +325,14 @@ export function turnMessage(facts) {
238
325
  parts.push(`Plan this ticket again from ${at("ticket.md")}.`);
239
326
  }
240
327
  else {
241
- parts.push("This is the plan turn of a YAGNI attempt. Work the ticket as your playbook says, up to the plan: nothing is built until a person approves it.", INPUTS(facts.inputDir));
328
+ parts.push("This is the plan turn of a YAGNI attempt. Work the ticket as your playbook says, up to the plan: nothing is built until the plan is approved.", INPUTS(facts.inputDir));
242
329
  if (facts.sentBack) {
243
330
  parts.push(`A person sent an earlier plan back: what they asked is in ${at("ticket.md")}, and that plan is ${at("sent-back-plan.md")}. ${PLANNED_ANYWAY}`);
244
331
  }
245
332
  }
246
333
  if (newSince)
247
334
  parts.push(newSince);
248
- parts.push(PLAN_RULES);
335
+ parts.push(planRules(facts.preview ? { inputDir: facts.inputDir, outDir: facts.outDir } : undefined, facts.ownPlans === true));
249
336
  return parts.join("\n\n");
250
337
  }
251
338
  if (facts.stage === "implement" && facts.resumed && !facts.continuation) {
@@ -254,7 +341,7 @@ export function turnMessage(facts) {
254
341
  parts.push(`The person approved the plan. The plan as approved is ${at("plan.md")}: their answers are already in it, under Decisions and Not doing, and it supersedes the draft you wrote earlier in this session. Build that plan. Leave out everything under Not doing. ${PLAN_CHANGES_RULE}`);
255
342
  }
256
343
  else if (facts.stage === "fix" && facts.review) {
257
- parts.push(`A review or the CI on this attempt's pull request asks for changes. They are in ${at("ticket.md")}, under "Review on this attempt's pull request", each with its id; the branch may hold a person's commits since your last turn, so read the code as it is now. Address every item with the smallest change that does it, write the outcomes file that section names, and commit.`);
344
+ parts.push(`A review or the CI on this attempt's pull request asks for changes. They are in ${at("ticket.md")}, under "Review on this attempt's pull request", each with its id; the branch may hold a person's commits since your last turn, so read the code as it is now. Address every item with the smallest change that does it, write the outcomes file that section names, and commit.`, FIX_RULE);
258
345
  }
259
346
  else {
260
347
  const why = facts.continuation?.priorStop
@@ -270,7 +357,7 @@ export function turnMessage(facts) {
270
357
  parts.push("Check the work on this branch against the plan: run the checks, fix only what this change broke, and commit any fix.");
271
358
  }
272
359
  if (facts.review) {
273
- parts.push(`A review or the CI on this attempt's pull request asks for changes: they are in ${at("ticket.md")}, under "Review on this attempt's pull request". Address every item and write the outcomes file that section names.`);
360
+ parts.push(`A review or the CI on this attempt's pull request asks for changes: they are in ${at("ticket.md")}, under "Review on this attempt's pull request". Address every item and write the outcomes file that section names.`, FIX_RULE);
274
361
  }
275
362
  }
276
363
  if (facts.handOffAnswer) {
@@ -353,7 +440,12 @@ export function parseSessionReport(text, known = new Map()) {
353
440
  /** The checks the host named in `checks.json`, by their command, with how each stands on the base. */
354
441
  function knownBaselines(inputDir, readFile) {
355
442
  const read = readMissionChecksFile(join(inputDir, MISSION_CHECKS_FILE_NAME), readFile);
356
- return new Map((read.file?.checks ?? []).map((check) => [check.command.replace(/\s+/g, " "), check.status]));
443
+ // A check the session was told to measure on the base takes no baseline
444
+ // from the record: only the session's own measurement may excuse it.
445
+ return new Map((read.file?.checks ?? []).map((check) => [
446
+ check.command.replace(/\s+/g, " "),
447
+ check.measureOnBase ? "runnable" : check.status,
448
+ ]));
357
449
  }
358
450
  /** The report's checks and its words on `result.json`: the model's own account, never the host's proof. */
359
451
  export function withReport(attempt, report) {
@@ -527,6 +619,7 @@ async function runTurn(input, deps, pulse) {
527
619
  const writeFile = deps.writeFile ?? ((path, text) => writeFileSync(path, text));
528
620
  const exists = deps.exists ?? existsSync;
529
621
  const mkdir = deps.mkdir ?? ((path) => void mkdirSync(path, { recursive: true }));
622
+ const remove = deps.remove ?? ((path) => rmSync(path, { force: true }));
530
623
  const exec = deps.exec ?? finishExec;
531
624
  const snapshot = deps.snapshot ?? snapshotWorkspace;
532
625
  const runStage = deps.runStage ?? defaultRunStage;
@@ -550,6 +643,21 @@ async function runTurn(input, deps, pulse) {
550
643
  const baseSha = start.head;
551
644
  const preRunDirt = parseChangedPaths(start.status);
552
645
  const writes = input.stage !== "plan";
646
+ // The host's brief is there: this plan turn draws the plan's UI preview
647
+ // itself, and whatever an earlier turn left in its place goes first.
648
+ const drawsPreview = input.stage === "plan" && exists(join(input.inputDir, UI_PREVIEW_BRIEF_FILE_NAME));
649
+ const previewFile = join(input.outDir, UI_PREVIEW_FILE_NAME);
650
+ const previewNoneFile = join(input.outDir, UI_PREVIEW_NONE_FILE_NAME);
651
+ if (drawsPreview) {
652
+ for (const path of [previewFile, previewNoneFile]) {
653
+ try {
654
+ remove(path);
655
+ }
656
+ catch {
657
+ // One that cannot be removed is read as this turn's: the host's judge still reads the page.
658
+ }
659
+ }
660
+ }
553
661
  // A yak's System's other repositories, each as the turn found it, for the
554
662
  // read of a writing turn's change for a placed secret (YAG-1211).
555
663
  const others = [];
@@ -583,7 +691,7 @@ async function runTurn(input, deps, pulse) {
583
691
  id: stageId,
584
692
  agent: "session",
585
693
  model: SESSION_TIER,
586
- tools: writes ? BUILD_TURN_TOOLS : PLAN_TURN_TOOLS,
694
+ tools: writes ? BUILD_TURN_TOOLS : drawsPreview ? PLAN_PREVIEW_TURN_TOOLS : PLAN_TURN_TOOLS,
587
695
  taskTemplate: "{ticket}",
588
696
  };
589
697
  let decisionsRecorded = 0;
@@ -672,6 +780,10 @@ async function runTurn(input, deps, pulse) {
672
780
  sentBack: exists(join(input.inputDir, "sent-back-plan.md")),
673
781
  nextStepNote: input.stage === "plan" ? null : readOrNull(join(input.inputDir, NEXT_STEP_NOTE_FILE_NAME)),
674
782
  newSinceLastTurn: readOrNull(join(input.inputDir, NEW_SINCE_LAST_TURN_FILE_NAME)),
783
+ ...(drawsPreview ? { preview: true } : {}),
784
+ ...(input.stage === "plan" && exists(join(input.inputDir, OWN_PLANS_FILE_NAME))
785
+ ? { ownPlans: true }
786
+ : {}),
675
787
  // The env the turn's child runs on, so the message and the agents the
676
788
  // child is offered (`builtinAgents`) read one value.
677
789
  codeWriter: resolveCodeWriter(input.childEnv),
@@ -679,6 +791,7 @@ async function runTurn(input, deps, pulse) {
679
791
  const notes = [];
680
792
  const stages = [];
681
793
  let planText = "";
794
+ let uiPreview = null;
682
795
  let ran;
683
796
  try {
684
797
  let run = await turn(message);
@@ -746,6 +859,28 @@ async function runTurn(input, deps, pulse) {
746
859
  sections.length > 0
747
860
  ? [run.finalOutput.trimEnd(), ...sections].join("\n\n")
748
861
  : run.finalOutput;
862
+ if (drawsPreview && planText.trim()) {
863
+ // The preview is settled on the final plan, from the files alone: the
864
+ // session's words are the yak's in its thread, never a signal here.
865
+ const left = () => {
866
+ const problems = previewPageProblems(readOrNull(previewFile));
867
+ if (problems.length === 0)
868
+ return "drawn";
869
+ return readOrNull(previewNoneFile)?.trim() ? "none" : problems;
870
+ };
871
+ let settled = left();
872
+ if (typeof settled !== "string" &&
873
+ turnStop(run, false, input.signal?.aborted === true).stop === "clean") {
874
+ stages.push(await turn(previewReask(input.inputDir, input.outDir, settled)));
875
+ settled = left();
876
+ }
877
+ uiPreview = typeof settled === "string" ? settled : "not_drawn";
878
+ if (typeof settled !== "string") {
879
+ const note = `The plan turn left no UI preview that can stand (${settled.join("; ")}); the plan's gate opens without one.`;
880
+ notes.push(note);
881
+ input.writeErr(note);
882
+ }
883
+ }
749
884
  notes.push(...(await putBackPlanTurn(input.cwd, start, exec, snapshot, input.signal)));
750
885
  }
751
886
  const stop = turnStop(run, writes, input.signal?.aborted === true);
@@ -806,10 +941,13 @@ async function runTurn(input, deps, pulse) {
806
941
  const noted = { ...done.attempt, notes: [...notes, ...done.attempt.notes] };
807
942
  const attempt = writes
808
943
  ? withSessionAccount(noted, parseSessionReport(readOrNull(join(input.outDir, SESSION_REPORT_FILE_NAME)), knownBaselines(input.inputDir, readFile)), pullRequestTextOf(readOrNull(join(input.outDir, PULL_REQUEST_FILE_NAME))))
809
- : noted;
944
+ : uiPreview
945
+ ? { ...noted, uiPreview }
946
+ : noted;
810
947
  // The cloud lane's finish wrote `result.json`; it is written again when
811
- // this turn adds to it (the model's account, the plan turn's put-back).
812
- if (writes || notes.length > 0)
948
+ // this turn adds to it (the model's account, the plan turn's put-back, how
949
+ // it left its UI preview).
950
+ if (writes || notes.length > 0 || uiPreview)
813
951
  rewriteResult(input.outDir, attempt, writeFile);
814
952
  input.emit({ type: "pipeline_result", ...attempt });
815
953
  const ok = writes ? done.ok && attempt.stopReason === "clean" : done.ok;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2347.1",
3
+ "version": "1.2.14-staging.2351.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": "a7e15e2da4a2f5b019b2b21df9208e4768fe5fb5"
61
+ "yagniSourceSha": "59922a7f75610bfa512989a2a60beb9921f016a8"
62
62
  }