@yagni-app/code-staging 1.2.14-staging.2283.1 → 1.2.14-staging.2312.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@
16
16
  * lives (`packages/shared/src/attempts.ts`): the two meet only at this JSON.
17
17
  */
18
18
  import type { ContinuationStage } from "./continuation.js";
19
+ import { type RunFinishOpts } from "./finish.js";
19
20
  import { type PlanChange } from "./planChanges.js";
20
21
  import { type VerifyCheckRun, type VerifyOutcome } from "./verify.js";
21
22
  import type { WorktreeExec } from "./worktree.js";
@@ -210,7 +211,36 @@ export interface CloudCompletion {
210
211
  planPaths: (planText: string) => string[];
211
212
  exec: WorktreeExec;
212
213
  writeFile: (path: string, text: string) => void;
214
+ /**
215
+ * The System's other repositories a yak's session may change in place
216
+ * (YAG-1211), each with its dirt from before the turn: each gets this
217
+ * repository's final commit over its own leftovers (YAG-1217). Absent on
218
+ * every other session.
219
+ */
220
+ others?: ReadonlyArray<OtherRepositoryFinish>;
221
+ /** The attempt's branch, for a detached checkout among `others` to take before its commit. */
222
+ othersBranch?: string | null;
223
+ }
224
+ /** Another repository of a yak's System, as the turn's final commit meets it (YAG-1217). */
225
+ export interface OtherRepositoryFinish {
226
+ /** `owner/name`. */
227
+ repository: string;
228
+ /** Its working copy. */
229
+ cwd: string;
230
+ /** Its dirt from before the turn, never committed. */
231
+ preRunDirt: readonly string[];
213
232
  }
233
+ /**
234
+ * The final commit in each of the System's other repositories a yak's
235
+ * session changed (YAG-1217): the ticket's own repository's commit, with its
236
+ * message and trailers, over that repository's own leftovers only (never its
237
+ * dirt from before the turn). One holding nothing of the turn's own is left
238
+ * alone, so no note is written for it. A detached checkout takes the
239
+ * attempt's branch first when that branch is not there yet, so the next
240
+ * wake knows the work as this attempt's. What could not be committed is a
241
+ * note naming the repository; the host names the repository in the thread.
242
+ */
243
+ export declare function finishOtherRepositories(others: ReadonlyArray<OtherRepositoryFinish>, finish: Omit<RunFinishOpts, "cwd" | "baselinePaths" | "baseSha" | "exec">, exec: WorktreeExec, branch: string | null): Promise<string[]>;
214
244
  /**
215
245
  * The changes to the plan the session's implement stage reported: the last
216
246
  * implement summary that carries a plan-changes block. None when no implement
@@ -23,7 +23,7 @@ import { extractPlanChanges, planChangeNote } from "./planChanges.js";
23
23
  import { buildPlanFile, planMarkdown } from "./planOutput.js";
24
24
  import { cloudLane } from "./stages.js";
25
25
  import { applyStageTiers, parseStageTiers, STAGE_TIERS_ENV } from "./tierCap.js";
26
- import { CHECK_NOT_RUN_NOTE } from "./verify.js";
26
+ import { CHECK_NOT_RUN_NOTE, parseChangedPaths, } from "./verify.js";
27
27
  /** Set on every stage child of a cloud session, so its prompt describes the cloud sandbox. */
28
28
  export const CLOUD_SESSION_ENV = "YAGNI_GO_CLOUD";
29
29
  /** Where the session writes `plan.md`, `plan.json` and `result.json`. */
@@ -291,6 +291,75 @@ export function cannotRunNote(checks) {
291
291
  function findingKey(finding) {
292
292
  return `${finding.file ?? ""}:${finding.line ?? ""}:${finding.message}`;
293
293
  }
294
+ const ATTEMPT_BRANCH = /^yagni\/[a-z0-9][a-z0-9._-]{0,120}$/;
295
+ /**
296
+ * Whether a checkout is on the attempt's branch, after a detached one takes
297
+ * it when that branch is not there yet: true, or why not, in words.
298
+ */
299
+ async function onAttemptBranch(run, branch) {
300
+ if (!branch || !ATTEMPT_BRANCH.test(branch))
301
+ return "the host named no branch for this ticket";
302
+ const on = await run(["git", "branch", "--show-current"]);
303
+ if (on.code !== 0)
304
+ return "its branch could not be read";
305
+ const current = on.output.trim();
306
+ if (current === branch)
307
+ return true;
308
+ if (current)
309
+ return `it is on ${current}, not this ticket's branch`;
310
+ const there = await run(["git", "rev-parse", "--verify", "--quiet", `refs/heads/${branch}`]);
311
+ if (there.code === 0)
312
+ return "it is detached away from this ticket's branch";
313
+ const made = await run(["git", "checkout", "--quiet", "-b", branch]);
314
+ return made.code === 0 ? true : "this ticket's branch could not be made there";
315
+ }
316
+ /**
317
+ * The final commit in each of the System's other repositories a yak's
318
+ * session changed (YAG-1217): the ticket's own repository's commit, with its
319
+ * message and trailers, over that repository's own leftovers only (never its
320
+ * dirt from before the turn). One holding nothing of the turn's own is left
321
+ * alone, so no note is written for it. A detached checkout takes the
322
+ * attempt's branch first when that branch is not there yet, so the next
323
+ * wake knows the work as this attempt's. What could not be committed is a
324
+ * note naming the repository; the host names the repository in the thread.
325
+ */
326
+ export async function finishOtherRepositories(others, finish, exec, branch) {
327
+ const notes = [];
328
+ for (const other of others) {
329
+ const run = (argv) => exec(argv, other.cwd).catch((err) => ({
330
+ code: -1,
331
+ output: err instanceof Error ? err.message : String(err),
332
+ }));
333
+ const status = await run(["git", "status", "--porcelain"]);
334
+ if (status.code !== 0) {
335
+ notes.push(`In ${other.repository}: what the turn left could not be read, so nothing there was committed.`);
336
+ continue;
337
+ }
338
+ const before = new Set(other.preRunDirt);
339
+ if (parseChangedPaths(status.output).every((path) => before.has(path)))
340
+ continue;
341
+ // The commit goes on the attempt's branch only, never on another
342
+ // ticket's: a detached checkout takes the branch when it is not there
343
+ // yet; any other is said and left (Codex round 2).
344
+ const owned = await onAttemptBranch(run, branch);
345
+ if (owned !== true) {
346
+ notes.push(`In ${other.repository}: ${owned}, so what the turn left there was not committed.`);
347
+ continue;
348
+ }
349
+ const done = await runFinish({
350
+ ...finish,
351
+ cwd: other.cwd,
352
+ // Dirt from before the turn stays out, staged or not (Codex round 1).
353
+ ...(other.preRunDirt.length > 0
354
+ ? { baselinePaths: [...other.preRunDirt], onlyRunOwned: true }
355
+ : {}),
356
+ exec,
357
+ });
358
+ if (!done.committed)
359
+ notes.push(...done.notes.map((note) => `In ${other.repository}: ${note}`));
360
+ }
361
+ return notes;
362
+ }
294
363
  /**
295
364
  * The changes to the plan the session's implement stage reported: the last
296
365
  * implement summary that carries a plan-changes block. None when no implement
@@ -395,8 +464,7 @@ export async function completeCloudSession(c, ran) {
395
464
  notes.push("The review loop stopped clean, but the final scan or checks found a blocker in what is committed.");
396
465
  }
397
466
  const title = c.plan ? planTitle(c.plan) : undefined;
398
- const finish = await runFinish({
399
- cwd: c.cwd,
467
+ const commit = {
400
468
  worktreeMode: true,
401
469
  hereBaseline: "unknown",
402
470
  ticket: ticketOfBranch(branch) ?? c.identity.attemptId,
@@ -411,12 +479,20 @@ export async function completeCloudSession(c, ran) {
411
479
  decisionsRecorded: result?.decisionsRecorded ?? 0,
412
480
  rounds: result?.rounds.length ?? 0,
413
481
  openPr: false,
482
+ };
483
+ const finish = await runFinish({
484
+ ...commit,
485
+ cwd: c.cwd,
414
486
  ...(c.preRunDirt.length > 0 ? { baselinePaths: c.preRunDirt } : {}),
415
487
  ...(c.baseSha ? { baseSha: c.baseSha } : {}),
416
488
  exec: c.exec,
417
489
  });
418
490
  committed = finish.committed;
419
491
  notes.push(...finish.notes);
492
+ // The System's other repositories get the same final commit (YAG-1217).
493
+ if (c.others?.length) {
494
+ notes.push(...(await finishOtherRepositories(c.others, commit, c.exec, c.othersBranch ?? null)));
495
+ }
420
496
  }
421
497
  const facts = await gitFacts(c.cwd, c.exec, c.baseSha);
422
498
  notes.push(...facts.notes);
@@ -80,6 +80,12 @@ export interface RunFinishOpts extends TrailerInputs {
80
80
  * commit on top, so the branch still carries the run's `YAGNI-Run` line.
81
81
  */
82
82
  baseSha?: string;
83
+ /**
84
+ * Commit only the run's own paths (`git commit -- <paths>`), never what was
85
+ * already staged among `baselinePaths` (a yak's System's other
86
+ * repositories, YAG-1217). Absent: the index is committed as staged.
87
+ */
88
+ onlyRunOwned?: boolean;
83
89
  signal?: AbortSignal;
84
90
  exec?: WorktreeExec;
85
91
  }
@@ -260,6 +260,36 @@ async function committedSince(run, baseSha) {
260
260
  .map((line) => line.trim())
261
261
  .filter(Boolean);
262
262
  }
263
+ /** Each rename in `git status --porcelain` (`R old -> new`), as its source and destination. */
264
+ function renamesIn(status) {
265
+ const renames = [];
266
+ for (const raw of status.split("\n")) {
267
+ if (raw.length < 4 || !raw.slice(0, 2).includes("R"))
268
+ continue;
269
+ const entry = raw[2] === " " ? raw.slice(3) : raw.slice(2);
270
+ const arrow = entry.indexOf(" -> ");
271
+ if (arrow < 0)
272
+ continue;
273
+ const from = entry.slice(0, arrow).trim();
274
+ const to = entry.slice(arrow + 4).trim();
275
+ if (from && to)
276
+ renames.push({ from, to });
277
+ }
278
+ return renames;
279
+ }
280
+ /** The source of each rename whose destination is one of `paths`: a commit limited to paths names both. */
281
+ function renameSources(status, paths) {
282
+ const wanted = new Set(paths);
283
+ return renamesIn(status)
284
+ .filter((rename) => wanted.has(rename.to) && !wanted.has(rename.from))
285
+ .map((rename) => rename.from);
286
+ }
287
+ /** The destination of each rename whose source is among `baseline`. */
288
+ function renamedFrom(status, baseline) {
289
+ return renamesIn(status)
290
+ .filter((rename) => baseline.has(rename.from))
291
+ .map((rename) => rename.to);
292
+ }
263
293
  /**
264
294
  * Run the FINISH stage. NEVER throws; every failure path returns an honest
265
295
  * {@link FinishResult} with notes. See the module docblock for the contract.
@@ -300,7 +330,12 @@ export async function runFinish(opts) {
300
330
  // commit only these, so the provenance commit never folds in non-run work.
301
331
  const changed = parseChangedPaths(status.output);
302
332
  const baseline = new Set(opts.baselinePaths ?? []);
303
- const runOwned = baseline.size === 0 ? changed : changed.filter((p) => !baseline.has(p));
333
+ // A path-limited commit leaves out a rename whose source was dirt from
334
+ // before the run too: its destination carries that dirt (Codex round 3).
335
+ const dirtyRenames = opts.onlyRunOwned === true ? renamedFrom(status.output, baseline) : [];
336
+ const runOwned = baseline.size === 0
337
+ ? changed
338
+ : changed.filter((p) => !baseline.has(p) && !dirtyRenames.includes(p));
304
339
  // Nothing of the run's own left in the tree, but its work may already be
305
340
  // committed past its base: the trailer then goes on an empty commit.
306
341
  const committed = runOwned.length === 0 ? await committedSince(run, opts.baseSha) : [];
@@ -329,7 +364,16 @@ export async function runFinish(opts) {
329
364
  return skipped(`FINISH could not stage the changes (git add failed: ${tail(add.output)}); nothing was committed.`);
330
365
  }
331
366
  }
332
- const commitArgs = [...(trailerOnly ? ["--allow-empty"] : []), "-m", message];
367
+ // Only the run's own paths, so dirt from before the run that was already
368
+ // staged is never committed with them.
369
+ const only = opts.onlyRunOwned === true && !trailerOnly && baseline.size > 0;
370
+ const commitArgs = [
371
+ ...(trailerOnly ? ["--allow-empty"] : []),
372
+ "-m",
373
+ message,
374
+ // A rename's source too, so its deletion goes with it (Codex round 2).
375
+ ...(only ? ["--", ...runOwned, ...renameSources(status.output, runOwned)] : []),
376
+ ];
333
377
  let commit = await run(["git", "commit", ...commitArgs]);
334
378
  if (commit.code !== 0) {
335
379
  // Most likely a missing git identity in a fresh environment (mirrors
@@ -27,7 +27,8 @@
27
27
  * verifies with a fresh `verification` subagent, commits and never
28
28
  * pushes, and writes its own account to `session-report.json`. This
29
29
  * process then runs what the cloud lane's finish runs (the secret and
30
- * binary scan, a commit of anything left, the git facts) and writes
30
+ * binary scan, a commit of anything left, in the ticket's repository
31
+ * and in each of a yak's System's other repositories, the git facts) and writes
31
32
  * `result.json` with the model's checks, what it could not verify and
32
33
  * where it departed from the plan folded in, each departure in
33
34
  * `planChanges` for the host to write into the plan (`planChanges.ts`).
@@ -27,7 +27,8 @@
27
27
  * verifies with a fresh `verification` subagent, commits and never
28
28
  * pushes, and writes its own account to `session-report.json`. This
29
29
  * process then runs what the cloud lane's finish runs (the secret and
30
- * binary scan, a commit of anything left, the git facts) and writes
30
+ * binary scan, a commit of anything left, in the ticket's repository
31
+ * and in each of a yak's System's other repositories, the git facts) and writes
31
32
  * `result.json` with the model's checks, what it could not verify and
32
33
  * where it departed from the plan folded in, each departure in
33
34
  * `planChanges` for the host to write into the plan (`planChanges.ts`).
@@ -517,9 +518,12 @@ async function runTurn(input, deps, pulse) {
517
518
  // A yak's System's other repositories, each as the turn found it, for the
518
519
  // read of a writing turn's change for a placed secret (YAG-1211).
519
520
  const others = [];
521
+ /** The attempt's branch the host named with them: a detached one takes it before its commit. */
522
+ let othersBranch = null;
520
523
  if (writes) {
521
524
  const listed = systemRepositoriesOf(readOrNull(join(input.inputDir, SYSTEM_REPOSITORIES_FILE_NAME)), input.cwd);
522
525
  for (const { repository, dir, pushedHead, branch } of listed) {
526
+ othersBranch ??= branch;
523
527
  const found = await snapshot(dir, input.signal);
524
528
  others.push({
525
529
  repository,
@@ -671,6 +675,18 @@ async function runTurn(input, deps, pulse) {
671
675
  planPaths: (text) => baselineDirs(input.cwd, planPaths(text), readFile).map((dir) => relative(input.cwd, dir) || "."),
672
676
  exec,
673
677
  writeFile,
678
+ // Each other repository of the System gets the same final commit,
679
+ // over what the turn left there (YAG-1217).
680
+ ...(others.length > 0
681
+ ? {
682
+ others: others.map((other) => ({
683
+ repository: other.repository,
684
+ cwd: other.cwd,
685
+ preRunDirt: other.skip ?? [],
686
+ })),
687
+ othersBranch,
688
+ }
689
+ : {}),
674
690
  }, ran);
675
691
  const noted = { ...done.attempt, notes: [...notes, ...done.attempt.notes] };
676
692
  const attempt = writes
@@ -62,13 +62,7 @@ export interface SubagentDef {
62
62
  /** The agent's system prompt (the markdown body). */
63
63
  body: string;
64
64
  source: SubagentSource;
65
- /** This agent's own wall clock, when shorter than {@link SUBAGENT_WALL_TIMEOUT_MS}. */
66
- wallTimeoutMs?: number;
67
65
  }
68
- /** How long one verification subagent may run: a review of a finished diff,
69
- * not a second build (on staging 2026-10-28, advanced-tier verifiers ran 34
70
- * minutes after an 11-minute build). */
71
- export declare const VERIFICATION_WALL_TIMEOUT_MS: number;
72
66
  /**
73
67
  * The tier the built-in verification agent asks for: `peak` in a session-lane
74
68
  * turn (`pipeline/sessionLane.ts`), the one place the proxy serves a verifier
@@ -169,7 +163,7 @@ export declare const SUBAGENT_WALL_TIMEOUT_MS: number;
169
163
  * Exported so a test can pin the composed policy the production path actually
170
164
  * runs (every unit test injects runStageImpl instead).
171
165
  */
172
- export declare function subagentRunPolicy(wallTimeoutMs?: number): ResiliencePolicy;
166
+ export declare function subagentRunPolicy(): ResiliencePolicy;
173
167
  /**
174
168
  * The per-attempt telemetry adapter: one content-free error-sink row per
175
169
  * resilience attempt (agent, taskIndex, outcome, timeoutKind, exit code,
@@ -213,10 +213,6 @@ What you could not check, and why.
213
213
 
214
214
  A HOLDS after real digging is valuable; a rubber stamp is not. If you found
215
215
  nothing, say exactly what you tried to break and how.`;
216
- /** How long one verification subagent may run: a review of a finished diff,
217
- * not a second build (on staging 2026-10-28, advanced-tier verifiers ran 34
218
- * minutes after an 11-minute build). */
219
- export const VERIFICATION_WALL_TIMEOUT_MS = 15 * 60_000;
220
216
  /**
221
217
  * The tier the built-in verification agent asks for: `peak` in a session-lane
222
218
  * turn (`pipeline/sessionLane.ts`), the one place the proxy serves a verifier
@@ -230,7 +226,8 @@ export function verificationTier(env = process.env) {
230
226
  }
231
227
  /** The diamond's reduce layer: refute-first review of completed work, on
232
228
  * {@link verificationTier} (judgment is the whole job, so the premium is worth
233
- * paying where the lane serves it). One by default, on a fifteen-minute clock.
229
+ * paying where the lane serves it). One by default, on the subagent lane's
230
+ * clock ({@link SUBAGENT_WALL_TIMEOUT_MS}), like every other subagent.
234
231
  * It has no edit/write tools; bash is included for `git diff`-style inspection
235
232
  * and is restricted to read-only USE by the persona, the same prompt-level
236
233
  * stance as /go's reviewer, not a technical guarantee. */
@@ -246,7 +243,6 @@ function verificationAgent(env) {
246
243
  tools: ["read", "grep", "find", "ls", "bash", "ask_yagni"],
247
244
  body: VERIFICATION_BODY,
248
245
  source: "builtin",
249
- wallTimeoutMs: VERIFICATION_WALL_TIMEOUT_MS,
250
246
  };
251
247
  }
252
248
  // Concrete tiers a subagent can actually run on. `balanced` is deliberately NOT
@@ -507,8 +503,12 @@ export const SUBAGENT_WALL_TIMEOUT_MS = 2 * 60 * 60_000;
507
503
  * Exported so a test can pin the composed policy the production path actually
508
504
  * runs (every unit test injects runStageImpl instead).
509
505
  */
510
- export function subagentRunPolicy(wallTimeoutMs = SUBAGENT_WALL_TIMEOUT_MS) {
511
- return { ...DEFAULT_RESILIENCE_POLICY, wallTimeoutMs, retryWallTimeout: false };
506
+ export function subagentRunPolicy() {
507
+ return {
508
+ ...DEFAULT_RESILIENCE_POLICY,
509
+ wallTimeoutMs: SUBAGENT_WALL_TIMEOUT_MS,
510
+ retryWallTimeout: false,
511
+ };
512
512
  }
513
513
  /**
514
514
  * The per-attempt telemetry adapter: one content-free error-sink row per
@@ -551,21 +551,16 @@ export function makeSubagentTool(deps = {}) {
551
551
  // text). The write-gate keys on the resolved agent's tools,
552
552
  // passed per task below — the synthetic stage id is "implement" and would
553
553
  // otherwise block retry of a read-only verifier forever.
554
- // One wrapped runner per wall clock: an agent with its own (verification)
555
- // gets a runner built on it, every other agent shares the lane's default.
556
- const runners = new Map();
557
- const runFor = (def) => {
554
+ // Every agent, the verifier included, runs on the lane's one wall clock,
555
+ // built once, when the first subagent runs.
556
+ let wrapped = null;
557
+ const run = () => {
558
558
  if (deps.runStageImpl)
559
559
  return deps.runStageImpl;
560
- const wall = def.wallTimeoutMs ?? SUBAGENT_WALL_TIMEOUT_MS;
561
- let runner = runners.get(wall);
562
- if (!runner) {
563
- runner = withResilience(runStage, subagentRunPolicy(wall), {
564
- telemetry: subagentTelemetry(deps.env ?? process.env),
565
- });
566
- runners.set(wall, runner);
567
- }
568
- return runner;
560
+ wrapped ??= withResilience(runStage, subagentRunPolicy(), {
561
+ telemetry: subagentTelemetry(deps.env ?? process.env),
562
+ });
563
+ return wrapped;
569
564
  };
570
565
  const discover = deps.discover ?? discoverSubagents;
571
566
  const grounded = deps.grounded !== false;
@@ -690,7 +685,7 @@ export function makeSubagentTool(deps = {}) {
690
685
  outcomes = await Promise.all(resolved.map(async ({ def, task }, index) => {
691
686
  const progress = progresses[index];
692
687
  const { stage, ctx: stageCtx } = buildSubagentStage(def, task, { grounded });
693
- const result = await runFor(def)(stage, stageCtx, {
688
+ const result = await run()(stage, stageCtx, {
694
689
  cwd,
695
690
  signal,
696
691
  // Write-gate input: whether the agent's DECLARED tool list has
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2283.1",
3
+ "version": "1.2.14-staging.2312.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": "070b30a13ecb2f930f932a574a84bc43a19f903b"
61
+ "yagniSourceSha": "22d5af00866101ff6dafd1281bf318bfada404f1"
62
62
  }