@yagni-app/code-staging 0.3.2-staging.1114.1 → 0.3.2-staging.1119.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.
Files changed (39) hide show
  1. package/dist/cli.js +13 -0
  2. package/dist/extension/index.d.ts +5 -0
  3. package/dist/extension/index.js +18 -1
  4. package/dist/extension/pipeline/activityFeed.js +19 -5
  5. package/dist/extension/pipeline/checker.d.ts +99 -0
  6. package/dist/extension/pipeline/checker.js +238 -0
  7. package/dist/extension/pipeline/fanout.d.ts +116 -0
  8. package/dist/extension/pipeline/fanout.js +248 -0
  9. package/dist/extension/pipeline/fanoutBeats.d.ts +31 -0
  10. package/dist/extension/pipeline/fanoutBeats.js +86 -0
  11. package/dist/extension/pipeline/goCommand.d.ts +14 -0
  12. package/dist/extension/pipeline/goCommand.js +38 -1
  13. package/dist/extension/pipeline/headlessGo.d.ts +163 -0
  14. package/dist/extension/pipeline/headlessGo.js +333 -0
  15. package/dist/extension/pipeline/invocation.d.ts +7 -1
  16. package/dist/extension/pipeline/invocation.js +7 -1
  17. package/dist/extension/pipeline/mission.d.ts +55 -0
  18. package/dist/extension/pipeline/mission.js +70 -0
  19. package/dist/extension/pipeline/orchestrator.d.ts +48 -3
  20. package/dist/extension/pipeline/orchestrator.js +450 -9
  21. package/dist/extension/pipeline/personas.d.ts +16 -1
  22. package/dist/extension/pipeline/personas.js +117 -6
  23. package/dist/extension/pipeline/runSession.d.ts +45 -1
  24. package/dist/extension/pipeline/runState.d.ts +57 -12
  25. package/dist/extension/pipeline/runState.js +60 -18
  26. package/dist/extension/pipeline/runner.js +10 -1
  27. package/dist/extension/pipeline/stages.d.ts +84 -7
  28. package/dist/extension/pipeline/stages.js +166 -0
  29. package/dist/extension/pipeline/tierCap.d.ts +32 -0
  30. package/dist/extension/pipeline/tierCap.js +57 -0
  31. package/dist/extension/pipeline/types.d.ts +130 -1
  32. package/dist/extension/pipeline/types.js +17 -0
  33. package/dist/extension/pipeline/verify.d.ts +86 -3
  34. package/dist/extension/pipeline/verify.js +175 -6
  35. package/dist/goHeadless.d.ts +75 -0
  36. package/dist/goHeadless.js +132 -0
  37. package/dist/paths.d.ts +9 -0
  38. package/dist/paths.js +12 -0
  39. package/package.json +2 -2
package/dist/cli.js CHANGED
@@ -22,6 +22,7 @@ import { claudeCompatArgs } from "./claudeCompat.js";
22
22
  import { agentDir, credentialsDir, piPackageDir } from "./credentials.js";
23
23
  import { DISTRIBUTION } from "./distribution.js";
24
24
  import { connectCommand } from "./connectClaudeCode.js";
25
+ import { goCommand } from "./goHeadless.js";
25
26
  import { login } from "./login.js";
26
27
  import { logout } from "./logout.js";
27
28
  import { tokenCommand } from "./token.js";
@@ -288,6 +289,10 @@ export const HELP_TEXT = [
288
289
  " yagni login Authorize the active environment (device-code flow).",
289
290
  " yagni logout Revoke and clear the active environment's token.",
290
291
  " yagni doctor Check that everything is ready (green/red checklist).",
292
+ " yagni go --headless Run the /go pipeline without a session, for scripts",
293
+ " and CI: --ticket-file <path> [--plan-file <path>]",
294
+ " [--memo-file <path>] [--run-id <id>] [--json].",
295
+ " Exits 0 only on a reviewed, verified candidate.",
291
296
  " yagni connect claude-code Route Claude Code through the YAGNI model proxy",
292
297
  " (--project scopes to this repo; --off disconnects).",
293
298
  " yagni connect codex Route Codex CLI through the YAGNI model proxy.",
@@ -313,6 +318,8 @@ export const HELP_TEXT = [
313
318
  "The active environment is sticky; `use` switches it (prod is the default).",
314
319
  "Set YAGNI_BASE_URL to override the base URL for a single run.",
315
320
  "Set YAGNI_DISABLE_UPDATE_CHECK=1 to silence the new-version notice.",
321
+ "Set YAGNI_GO_TIER_CAP=<tier> to cap every pipeline stage at that tier",
322
+ " (peak, advanced, standard, efficient). For eval and smoke lanes only.",
316
323
  "Set YAGNI_DISABLE_CLAUDE_COMPAT=1 to skip loading .claude assets.",
317
324
  "Set YAGNI_DISABLE_BRANDING=1 to pass the system prompt through unmodified.",
318
325
  "Set YAGNI_DISABLE_CRASH_REPORTS=1 to turn off sanitized crash reports.",
@@ -424,6 +431,12 @@ export async function main(argv) {
424
431
  if (command === "connect") {
425
432
  return connectCommand(rest);
426
433
  }
434
+ // The headless pipeline entry. `go` is a real subcommand, not passthrough:
435
+ // the interactive run stays `/go` inside a session, and a `yagni go` without
436
+ // --headless is refused with usage rather than launched as an agent prompt.
437
+ if (command === "go") {
438
+ return goCommand(rest, {}, cliVersion());
439
+ }
427
440
  if (command === "token") {
428
441
  return tokenCommand();
429
442
  }
@@ -149,6 +149,11 @@ export { registerGoCommand } from "./pipeline/goCommand.js";
149
149
  export type { RegisterGoDeps } from "./pipeline/goCommand.js";
150
150
  export { runPipeline } from "./pipeline/orchestrator.js";
151
151
  export type { RunPipelineDeps } from "./pipeline/orchestrator.js";
152
+ export { HEADLESS_GO_EXIT, HEADLESS_GO_USAGE, parseHeadlessGoArgs, runHeadlessGo, validateHeadlessGoArgs, } from "./pipeline/headlessGo.js";
153
+ export type { HeadlessGoArgs, HeadlessGoDeps, HeadlessGoOutcome, HeadlessGoResult, HeadlessStageRow, } from "./pipeline/headlessGo.js";
154
+ export { isMissionMode, missionSeed, missionSkippedStages, normalizeMission } from "./pipeline/mission.js";
155
+ export type { MissionInputs } from "./pipeline/mission.js";
156
+ export { clampTier, parseTierCap, resolveTierCap, TIER_CAP_ENV } from "./pipeline/tierCap.js";
152
157
  export { withResilience, classifyTransient, composeAbortSignal } from "./pipeline/resilience.js";
153
158
  export type { ResilienceAttemptRecord, ResilienceSeams, RunStageFn } from "./pipeline/resilience.js";
154
159
  export { DEFAULT_RESILIENCE_POLICY } from "./pipeline/types.js";
@@ -140,7 +140,12 @@ export async function registerYagni(pi, deps = {}) {
140
140
  // `yagni` provider, so /model and Ctrl+P show a single entry. Child
141
141
  // processes (/go, subagents, advisor) fetch their own catalog and register
142
142
  // their own provider, so they are unaffected by this filter.
143
- const catalog = fullCatalog.filter((m) => m.id === "advanced");
143
+ //
144
+ // Eval mode is exempt: a headless harness (scoping sessions, code evals)
145
+ // names its tier explicitly — the backend's scoping sessions run `--model
146
+ // standard` — and there is no /model picker to keep tidy. Filtering there
147
+ // turns a valid tier request into "no models match".
148
+ const catalog = evalMode ? fullCatalog : fullCatalog.filter((m) => m.id === "advanced");
144
149
  // YAG-471: the driver's own completions carry attribution headers read from
145
150
  // this process's env (YAGNI_SESSION_ID minted by the launcher; YAGNI_CALLER
146
151
  // defaults to "driver" when unset, i.e. every session that is not a /go
@@ -207,6 +212,10 @@ export async function registerYagni(pi, deps = {}) {
207
212
  // The grounded multi-agent pipeline entry point: /go <ticket> runs
208
213
  // map → plan → implement → review → fix, each child grounded by inheritance.
209
214
  registerGoCommand(pi, {
215
+ // /ultra is one dial for the whole session: the same holder the subagent
216
+ // tool reads widens the implement diamond's parallel ceiling (4 -> 8) for
217
+ // the fan and its fix turns. Read per run, so a toggle lands on the next /go.
218
+ isUltra: () => ultraHolder.get(),
210
219
  // Task 8: /go's end-of-run summary prefers the server-priced per-stage
211
220
  // breakdown for the ONE run that just finished (`?runId=`, aliasing the
212
221
  // spend endpoint's `sessionId` param — see the backend route), over
@@ -875,6 +884,14 @@ export { attributionHeaders, isDriverCaller, fetchCatalog, getToken, getWorkspac
875
884
  export { buildYagniProvider } from "./provider.js";
876
885
  export { registerGoCommand } from "./pipeline/goCommand.js";
877
886
  export { runPipeline } from "./pipeline/orchestrator.js";
887
+ // The headless front door (`yagni go --headless`): the same pipeline, driven by
888
+ // a script or the mission sandbox instead of a session.
889
+ export { HEADLESS_GO_EXIT, HEADLESS_GO_USAGE, parseHeadlessGoArgs, runHeadlessGo, validateHeadlessGoArgs, } from "./pipeline/headlessGo.js";
890
+ // Mission mode: the pure rules for entering the pipeline on an already-approved
891
+ // plan (map/plan skipped, memo as the stand-in repo brief, FINISH not ours).
892
+ export { isMissionMode, missionSeed, missionSkippedStages, normalizeMission } from "./pipeline/mission.js";
893
+ // The eval/smoke tier ceiling (YAGNI_GO_TIER_CAP), clamped centrally in runStage.
894
+ export { clampTier, parseTierCap, resolveTierCap, TIER_CAP_ENV } from "./pipeline/tierCap.js";
878
895
  // R1: the in-loop resilience HOF a dev can compose with (or replace at) the
879
896
  // `runStage` seam, plus its policy type and the default policy.
880
897
  export { withResilience, classifyTransient, composeAbortSignal } from "./pipeline/resilience.js";
@@ -92,9 +92,10 @@ export class ActivityFeed {
92
92
  }
93
93
  /** Fold a structured progress signal into stage transitions + the header tally. */
94
94
  applyProgress(p) {
95
- // A per-lens signal is a desktop concern: it must not steal the buffer from
96
- // the review stage that owns it, nor reset it mid fan-out.
97
- if (p.kind === "stage_start" && !p.lens && p.stageId !== this.bufferStageId) {
95
+ // A per-lens or per-workstream signal is a desktop concern: it must not steal
96
+ // the buffer from the stage that owns it, nor reset it mid fan-out. The
97
+ // implement diamond's builders get exactly the review lenses' treatment.
98
+ if (p.kind === "stage_start" && !p.lens && !p.workstream && p.stageId !== this.bufferStageId) {
98
99
  this.bufferStageId = p.stageId;
99
100
  this.actions = [];
100
101
  }
@@ -129,6 +130,10 @@ export class ActivityFeed {
129
130
  headerParts.push(elapsed);
130
131
  const header = theme.bold(clipRow(headerParts.join(" · "), ROW_MAX));
131
132
  const lines = [header];
133
+ // The implement diamond collapses to ONE row plus a compact summary, the same
134
+ // way the review fan-out collapses to one review row: per-child rows are the
135
+ // desktop's business and would break the 10-line cap here.
136
+ const fan = this.run.fanoutRow();
132
137
  // Only the lens-less stage rows: the review fan-out's per-lens children are
133
138
  // the desktop's business, and surfacing them here would break the 10-line cap.
134
139
  for (const s of this.run.stageAgents()) {
@@ -138,8 +143,17 @@ export class ActivityFeed {
138
143
  if (s.id === "finish" && s.status === "pending")
139
144
  continue;
140
145
  const glyph = glyphForStatus(s.status, spinnerFrame);
141
- const label = s.stageId.padEnd(9);
142
- const row = clipRow(`${glyph} ${label}${s.summary}`.trimEnd(), ROW_MAX);
146
+ // Padded past the longest stage name ("implement", 9) so every row keeps a
147
+ // separator between the label and its note; at 9 the implement row ran its
148
+ // name straight into its own summary.
149
+ const label = s.stageId.padEnd(10);
150
+ // While the fan is live the implement row's note IS the fan summary; once
151
+ // the stage settles its own narration takes the row back (and the summary
152
+ // stands in when there is no narration to show).
153
+ const fanNote = s.stageId === "implement" && fan?.mode === "fan" && (s.status === "active" || !s.summary)
154
+ ? `fanned ${fan.total} ways · ${fan.done}/${fan.total} done`
155
+ : undefined;
156
+ const row = clipRow(`${glyph} ${label}${fanNote ?? s.summary}`.trimEnd(), ROW_MAX);
143
157
  lines.push(theme.fg(themeColorForStatus[s.status], row));
144
158
  // The ring buffer renders under its OWNING stage (see RunState), so a
145
159
  // just-finished stage's resolved actions stay briefly visible beneath its ✔
@@ -0,0 +1,99 @@
1
+ /**
2
+ * PURE checker-side helpers for the implement diamond (spec decisions 5-7).
3
+ *
4
+ * The checker itself is deterministic and lives in `verify.ts` (the per-workstream
5
+ * scoped typecheck plus the one full `makeRunVerify` on the merged tree). What is
6
+ * left is the reading of its verdict, and that is all pure text math:
7
+ *
8
+ * - {@link checkerFindings} unions the scoped + full findings into one deduped list.
9
+ * - {@link composeSynthesizerInput} turns the fan handoff plus the checker's
10
+ * verdict into the synthesizer's `{previous}`.
11
+ * - {@link attributeFindings} routes each finding to the workstream whose claims
12
+ * cover its file; anything unattributable is the synthesizer's (or, on the
13
+ * single-writer path, the one builder's).
14
+ * - {@link parseOpenFindings} reads the synthesizer's own "## Open findings"
15
+ * section, because decision 7 lets the summary report defects the deterministic
16
+ * checker cannot see.
17
+ * - {@link composeResidue} names what is still open when the fix cap is reached,
18
+ * so `reviewInput` hands the review loop the truth rather than a clean-looking
19
+ * summary.
20
+ *
21
+ * No I/O, no model calls: the orchestrator owns the children, this module owns the
22
+ * reading, exactly the split `findings.ts` and `fanout.ts` already use.
23
+ */
24
+ import { type PartitionWorkstream } from "./fanout.js";
25
+ import type { Finding } from "./types.js";
26
+ import type { VerifyOutcome, WorkstreamCheckResult } from "./verify.js";
27
+ /** Everything the deterministic checker produced for one pass over the tree. */
28
+ export interface CheckerReport {
29
+ /** Per-workstream scoped typecheck verdicts (empty on the single-writer path). */
30
+ scoped: WorkstreamCheckResult[];
31
+ /** The one full verify on the merged tree; null when it could not be consulted. */
32
+ verify: VerifyOutcome | null;
33
+ }
34
+ /** Findings routed to one workstream's builder for a fix turn. */
35
+ export interface FindingAssignment {
36
+ workstream: PartitionWorkstream;
37
+ findings: Finding[];
38
+ }
39
+ /** How the fix loop splits a checker verdict across the children that can fix it. */
40
+ export interface FindingAttribution {
41
+ assigned: FindingAssignment[];
42
+ /** Findings no workstream's claims cover: the synthesizer's seam work. */
43
+ unassigned: Finding[];
44
+ }
45
+ /** Union findings in first-seen order, deduped by file + line + message. */
46
+ export declare function mergeFindings(...groups: Finding[][]): Finding[];
47
+ /** Every defect this checker pass found: the scoped typechecks plus the full verify. */
48
+ export declare function checkerFindings(report: CheckerReport): Finding[];
49
+ /** One finding as a line a builder can act on (mirrors the review loop's handoff shape). */
50
+ export declare function renderFindings(findings: Finding[]): string;
51
+ /**
52
+ * The synthesizer's `{previous}`: the fan's own handoff (which already names each
53
+ * workstream, its claims, and any out-of-claim edits) plus the checker's verdict,
54
+ * with a broken workstream attributed BY NAME so the reconciler knows where to look.
55
+ */
56
+ export declare function composeSynthesizerInput(handoff: string, report: CheckerReport): string;
57
+ /**
58
+ * Route findings to the builders that can fix them: a finding whose file sits under
59
+ * a workstream's claims goes to that workstream (at its original tier), and anything
60
+ * else - no file, a file outside every claim, a seam between two workstreams - is
61
+ * unattributable and belongs to the synthesizer. With no workstreams (the
62
+ * single-writer path) everything is unassigned, which is exactly right: there is one
63
+ * builder and it owns the whole tree.
64
+ */
65
+ export declare function attributeFindings(findings: Finding[], workstreams: PartitionWorkstream[]): FindingAttribution;
66
+ /**
67
+ * The synthesizer's own "## Open findings" section (its persona output contract),
68
+ * as findings the fix loop can act on. "none" is a real answer and returns nothing;
69
+ * an absent section returns nothing too, because a summary that never claimed a
70
+ * defect is not evidence of one. Deliberately forgiving about the prose: what the
71
+ * loop needs is the line and, where the synthesizer named one, the file.
72
+ */
73
+ export declare function parseOpenFindings(summary: string): Finding[];
74
+ /**
75
+ * The same "## Open findings" section {@link parseOpenFindings} reads, REMOVED
76
+ * from a summary (heading and body, up to the next heading of any depth).
77
+ *
78
+ * A fix turn that only re-engaged builders never re-runs the synthesizer, so its
79
+ * summary stays the handoff verbatim. Once those defects are answered and the
80
+ * re-check is clean, leaving the section in place would hand the review loop a
81
+ * document that names open defects in one paragraph and calls the final check
82
+ * clean in the next. Everything else the synthesizer wrote is untouched: this
83
+ * drops only the section the fix loop has since resolved.
84
+ */
85
+ export declare function stripOpenFindings(summary: string): string;
86
+ /**
87
+ * What `reviewInput` says when the fix loop ran and then came back clean: the
88
+ * reviewers should know the candidate was repaired inside the implement stage, not
89
+ * that it was right first time. Absent when no fix turn ran, which keeps a
90
+ * clean-on-the-first-check run byte-identical to today's handoff.
91
+ */
92
+ export declare function composeFixNote(turns: number): string;
93
+ /**
94
+ * What `reviewInput` says when the fix cap is reached with defects still open
95
+ * (spec decision 7): named, not hidden, so the review loop picks them up knowing
96
+ * the implement stage already spent its turns on them.
97
+ */
98
+ export declare function composeResidue(findings: Finding[], turns: number): string;
99
+ //# sourceMappingURL=checker.d.ts.map
@@ -0,0 +1,238 @@
1
+ /**
2
+ * PURE checker-side helpers for the implement diamond (spec decisions 5-7).
3
+ *
4
+ * The checker itself is deterministic and lives in `verify.ts` (the per-workstream
5
+ * scoped typecheck plus the one full `makeRunVerify` on the merged tree). What is
6
+ * left is the reading of its verdict, and that is all pure text math:
7
+ *
8
+ * - {@link checkerFindings} unions the scoped + full findings into one deduped list.
9
+ * - {@link composeSynthesizerInput} turns the fan handoff plus the checker's
10
+ * verdict into the synthesizer's `{previous}`.
11
+ * - {@link attributeFindings} routes each finding to the workstream whose claims
12
+ * cover its file; anything unattributable is the synthesizer's (or, on the
13
+ * single-writer path, the one builder's).
14
+ * - {@link parseOpenFindings} reads the synthesizer's own "## Open findings"
15
+ * section, because decision 7 lets the summary report defects the deterministic
16
+ * checker cannot see.
17
+ * - {@link composeResidue} names what is still open when the fix cap is reached,
18
+ * so `reviewInput` hands the review loop the truth rather than a clean-looking
19
+ * summary.
20
+ *
21
+ * No I/O, no model calls: the orchestrator owns the children, this module owns the
22
+ * reading, exactly the split `findings.ts` and `fanout.ts` already use.
23
+ */
24
+ import { claimCovers } from "./fanout.js";
25
+ /** Cap on how many open findings are ever carried into a prompt or the residue. */
26
+ const MAX_CARRIED_FINDINGS = 25;
27
+ const key = (f) => `${f.file ?? ""}:${f.line ?? ""}:${f.message}`;
28
+ /** Union findings in first-seen order, deduped by file + line + message. */
29
+ export function mergeFindings(...groups) {
30
+ const seen = new Set();
31
+ const out = [];
32
+ for (const group of groups) {
33
+ for (const f of group) {
34
+ const k = key(f);
35
+ if (seen.has(k))
36
+ continue;
37
+ seen.add(k);
38
+ out.push(f);
39
+ }
40
+ }
41
+ return out;
42
+ }
43
+ /** Every defect this checker pass found: the scoped typechecks plus the full verify. */
44
+ export function checkerFindings(report) {
45
+ return mergeFindings(report.scoped.flatMap((s) => s.findings), report.verify?.findings ?? []);
46
+ }
47
+ /** One finding as a line a builder can act on (mirrors the review loop's handoff shape). */
48
+ export function renderFindings(findings) {
49
+ return findings
50
+ .slice(0, MAX_CARRIED_FINDINGS)
51
+ .map((f) => {
52
+ const loc = f.file ? `${f.file}${f.line != null ? `:${f.line}` : ""}` : "";
53
+ return `${f.severity} | ${loc} | ${f.message}`;
54
+ })
55
+ .join("\n");
56
+ }
57
+ /** One workstream's scoped-typecheck line, stating honestly whether it ran. */
58
+ function scopedLine(s) {
59
+ if (!s.ran)
60
+ return `- ${s.name}: not checked (${s.reason ?? "no scoped build check"})`;
61
+ if (s.findings.length === 0)
62
+ return `- ${s.name}: clean (${s.command ?? "check"})`;
63
+ return `- ${s.name}: ${s.findings.length} finding${s.findings.length === 1 ? "" : "s"} (${s.command ?? "check"})`;
64
+ }
65
+ /** The full verify's one-line verdict, including the fail-open case. */
66
+ function verifyLine(verify) {
67
+ if (!verify)
68
+ return "The full verify did not run on this pass.";
69
+ if (!verify.ran)
70
+ return `The full verify did not produce a verdict: ${verify.reason ?? "it could not run"}.`;
71
+ const label = verify.command ? ` (${verify.command})` : "";
72
+ if (verify.ok)
73
+ return `The full verify passed${label}.`;
74
+ return `The full verify failed${label}: ${verify.findings.length} finding${verify.findings.length === 1 ? "" : "s"}.`;
75
+ }
76
+ /**
77
+ * The synthesizer's `{previous}`: the fan's own handoff (which already names each
78
+ * workstream, its claims, and any out-of-claim edits) plus the checker's verdict,
79
+ * with a broken workstream attributed BY NAME so the reconciler knows where to look.
80
+ */
81
+ export function composeSynthesizerInput(handoff, report) {
82
+ const parts = [handoff];
83
+ if (report.scoped.length > 0) {
84
+ parts.push(["## Checker: scoped typecheck per workstream", ...report.scoped.map(scopedLine)].join("\n"));
85
+ }
86
+ parts.push(`## Checker: full verify on the merged tree\n${verifyLine(report.verify)}`);
87
+ const findings = checkerFindings(report);
88
+ if (findings.length > 0) {
89
+ parts.push(`## Checker findings\n${renderFindings(findings)}`);
90
+ }
91
+ return parts.join("\n\n");
92
+ }
93
+ /** The workstream whose claims cover this finding's file, if exactly one does. */
94
+ function ownerOf(finding, workstreams) {
95
+ const file = finding.file?.trim();
96
+ if (!file)
97
+ return undefined;
98
+ return workstreams.find((w) => w.files.some((claim) => claimCovers(claim, file)));
99
+ }
100
+ /**
101
+ * Route findings to the builders that can fix them: a finding whose file sits under
102
+ * a workstream's claims goes to that workstream (at its original tier), and anything
103
+ * else - no file, a file outside every claim, a seam between two workstreams - is
104
+ * unattributable and belongs to the synthesizer. With no workstreams (the
105
+ * single-writer path) everything is unassigned, which is exactly right: there is one
106
+ * builder and it owns the whole tree.
107
+ */
108
+ export function attributeFindings(findings, workstreams) {
109
+ const assigned = [];
110
+ const unassigned = [];
111
+ for (const finding of findings) {
112
+ const owner = ownerOf(finding, workstreams);
113
+ if (!owner) {
114
+ unassigned.push(finding);
115
+ continue;
116
+ }
117
+ const existing = assigned.find((a) => a.workstream.name === owner.name);
118
+ if (existing)
119
+ existing.findings.push(finding);
120
+ else
121
+ assigned.push({ workstream: owner, findings: [finding] });
122
+ }
123
+ return { assigned, unassigned };
124
+ }
125
+ /** A heading line, at any depth: `## Open findings`. */
126
+ const HEADING = /^#{1,6}\s+(.*)$/;
127
+ /** `path/to/file.ts` or `path/to/file.ts:42` — a path token, not prose. */
128
+ const PATH_SHAPE = /^[\w./@-]+\.[A-Za-z]{1,5}(?::\d+)?$/;
129
+ /**
130
+ * The first path-shaped token in a synthesizer's finding line (backticked first,
131
+ * since that is how the persona writes paths), with any `:line` suffix dropped so
132
+ * it compares against claim prefixes. Undefined when the line names no file, which
133
+ * makes the finding unattributable and therefore the synthesizer's own.
134
+ */
135
+ function pathIn(line) {
136
+ const quoted = [...line.matchAll(/`([^`]+)`/g)].map((m) => m[1].trim());
137
+ for (const token of [...quoted, ...line.split(/[\s,;()[\]]+/)]) {
138
+ const clean = token.replace(/[.,;:]+$/, "");
139
+ if (clean.includes("/") && PATH_SHAPE.test(clean))
140
+ return clean.replace(/:\d+$/, "");
141
+ }
142
+ return undefined;
143
+ }
144
+ /**
145
+ * The synthesizer's own "## Open findings" section (its persona output contract),
146
+ * as findings the fix loop can act on. "none" is a real answer and returns nothing;
147
+ * an absent section returns nothing too, because a summary that never claimed a
148
+ * defect is not evidence of one. Deliberately forgiving about the prose: what the
149
+ * loop needs is the line and, where the synthesizer named one, the file.
150
+ */
151
+ export function parseOpenFindings(summary) {
152
+ const lines = summary.split("\n");
153
+ const start = lines.findIndex((l) => {
154
+ const m = l.trim().match(HEADING);
155
+ return m ? /^open findings\b/i.test(m[1].trim()) : false;
156
+ });
157
+ if (start < 0)
158
+ return [];
159
+ const body = [];
160
+ for (const raw of lines.slice(start + 1)) {
161
+ if (HEADING.test(raw.trim()))
162
+ break;
163
+ const line = raw.trim().replace(/^[-*]\s+/, "").trim();
164
+ if (line)
165
+ body.push(line);
166
+ }
167
+ if (body.length === 0)
168
+ return [];
169
+ if (body.length === 1 && /^none\b/i.test(body[0].replace(/[.*_`]/g, "")))
170
+ return [];
171
+ return body.slice(0, MAX_CARRIED_FINDINGS).map((line) => {
172
+ const file = pathIn(line);
173
+ const finding = {
174
+ severity: "critical",
175
+ lens: "does_it_hold",
176
+ message: `synthesizer: ${line}`,
177
+ };
178
+ if (file)
179
+ finding.file = file;
180
+ return finding;
181
+ });
182
+ }
183
+ /**
184
+ * The same "## Open findings" section {@link parseOpenFindings} reads, REMOVED
185
+ * from a summary (heading and body, up to the next heading of any depth).
186
+ *
187
+ * A fix turn that only re-engaged builders never re-runs the synthesizer, so its
188
+ * summary stays the handoff verbatim. Once those defects are answered and the
189
+ * re-check is clean, leaving the section in place would hand the review loop a
190
+ * document that names open defects in one paragraph and calls the final check
191
+ * clean in the next. Everything else the synthesizer wrote is untouched: this
192
+ * drops only the section the fix loop has since resolved.
193
+ */
194
+ export function stripOpenFindings(summary) {
195
+ const lines = summary.split("\n");
196
+ const start = lines.findIndex((l) => {
197
+ const m = l.trim().match(HEADING);
198
+ return m ? /^open findings\b/i.test(m[1].trim()) : false;
199
+ });
200
+ if (start < 0)
201
+ return summary;
202
+ let end = lines.length;
203
+ for (let i = start + 1; i < lines.length; i += 1) {
204
+ if (HEADING.test(lines[i].trim())) {
205
+ end = i;
206
+ break;
207
+ }
208
+ }
209
+ return [...lines.slice(0, start), ...lines.slice(end)].join("\n").replace(/\n{3,}/g, "\n\n").trimEnd();
210
+ }
211
+ /**
212
+ * What `reviewInput` says when the fix loop ran and then came back clean: the
213
+ * reviewers should know the candidate was repaired inside the implement stage, not
214
+ * that it was right first time. Absent when no fix turn ran, which keeps a
215
+ * clean-on-the-first-check run byte-identical to today's handoff.
216
+ */
217
+ export function composeFixNote(turns) {
218
+ return [
219
+ "## Verification",
220
+ `${turns} fix pass${turns === 1 ? "" : "es"} ran inside the implement stage. The final check came back clean.`,
221
+ ].join("\n");
222
+ }
223
+ /**
224
+ * What `reviewInput` says when the fix cap is reached with defects still open
225
+ * (spec decision 7): named, not hidden, so the review loop picks them up knowing
226
+ * the implement stage already spent its turns on them.
227
+ */
228
+ export function composeResidue(findings, turns) {
229
+ const header = turns === 0
230
+ ? "## Open findings from verification"
231
+ : `## Open findings after ${turns} fix pass${turns === 1 ? "" : "es"}`;
232
+ return [
233
+ header,
234
+ "Verification still reports these. They were not resolved inside the implement stage:",
235
+ renderFindings(findings),
236
+ ].join("\n");
237
+ }
238
+ //# sourceMappingURL=checker.js.map
@@ -0,0 +1,116 @@
1
+ /**
2
+ * PURE partition contract for the implement diamond — the analogue of
3
+ * `findings.ts` for the fan-out orchestrator's output.
4
+ *
5
+ * `parsePartition` reads the orchestrator child's fenced ```partition JSON block
6
+ * and validates it against the contract (spec "Partition contract"): mode legal,
7
+ * width in {2,4,8} with a matching workstream count, per-workstream tier legal
8
+ * (absent defaults to `standard`), every workstream named + tasked with at least
9
+ * one file claim, and claims pairwise DISJOINT across workstreams.
10
+ *
11
+ * Two failure kinds, deliberately distinct because the pipeline treats them
12
+ * differently:
13
+ * - SOFT (`hard: false`): malformed block, illegal field, missing reason. The
14
+ * caller gets one cheap-tier format re-ask and then degrades to single-writer.
15
+ * A partition is never guessed.
16
+ * - HARD (`hard: true`): overlapping claims. Two writers on one file is the one
17
+ * thing the design refuses to discover at merge time, so it fails the stage at
18
+ * partition time with the colliding paths and workstreams named. The caller
19
+ * (orchestrator) raises it as a `PipelineStageError`; keeping the throw out of
20
+ * here keeps this module pure and free of an import cycle.
21
+ *
22
+ * `auditClaims` is the post-fan check: claims are path PREFIXES (a directory
23
+ * claims its whole subtree), so a file a builder legitimately created inside its
24
+ * claimed directory is in-claim, and anything else is named as a violation for
25
+ * the synthesizer to reconcile.
26
+ */
27
+ import type { FanoutMode } from "./types.js";
28
+ /** The tiers a workstream may run on: load-bearing work standard, mechanical work efficient. */
29
+ export type WorkstreamTier = "standard" | "efficient";
30
+ /**
31
+ * The `go.fanout` knob's environment surface (spec decision 8), named the way
32
+ * `YAGNI_GO_TIER_CAP` is (see tierCap.ts): a run-wide /go setting an eval or
33
+ * benchmark lane pins from the outside. `always` forces the diamond attempt;
34
+ * unset (everywhere else) leaves the partitioner's own conservative verdict as
35
+ * the only thing that decides.
36
+ */
37
+ export declare const FANOUT_MODE_ENV = "YAGNI_GO_FANOUT";
38
+ /**
39
+ * Parse a raw env value into a mode. Unset, empty, or unrecognized all yield
40
+ * undefined so a caller can warn about a typo; {@link resolveFanoutMode} is what
41
+ * turns that into the safe `auto` default. A typo must never pin a lane.
42
+ */
43
+ export declare function parseFanoutMode(raw: string | undefined): FanoutMode | undefined;
44
+ /** The run's fan-out mode from an environment. Defaults to `auto`. */
45
+ export declare function resolveFanoutMode(env: NodeJS.ProcessEnv): FanoutMode;
46
+ /** The only legal fan widths (execution concurrency is capped separately by the session). */
47
+ export declare const PARTITION_WIDTHS: readonly [2, 4, 8];
48
+ export type PartitionWidth = (typeof PARTITION_WIDTHS)[number];
49
+ /** One workstream: a named, tasked builder with a disjoint set of prefix claims. */
50
+ export interface PartitionWorkstream {
51
+ name: string;
52
+ task: string;
53
+ /** Normalized, deduped path prefixes; a directory claim covers its subtree. */
54
+ files: string[];
55
+ tier: WorkstreamTier;
56
+ }
57
+ /** The orchestrator's verdict: fan into workstreams, or run today's single writer. */
58
+ export interface PartitionDecision {
59
+ mode: "fan" | "single";
60
+ /** Fan only; always equals `workstreams.length`. */
61
+ width?: PartitionWidth;
62
+ /** Always present: why this width, or why single-writer. */
63
+ reason: string;
64
+ /** Fan only. */
65
+ workstreams?: PartitionWorkstream[];
66
+ }
67
+ /** One pair of colliding claims across two workstreams. */
68
+ export interface ClaimCollision {
69
+ path: string;
70
+ otherPath: string;
71
+ workstreams: [string, string];
72
+ }
73
+ /**
74
+ * Parse outcome. `ok: false` splits into the re-askable soft rejection and the
75
+ * hard overlap error (see the module comment).
76
+ */
77
+ export type PartitionParse = {
78
+ ok: true;
79
+ decision: PartitionDecision;
80
+ } | {
81
+ ok: false;
82
+ hard: false;
83
+ reason: string;
84
+ } | {
85
+ ok: false;
86
+ hard: true;
87
+ reason: string;
88
+ collisions: ClaimCollision[];
89
+ };
90
+ /** Extract the inner text of a fenced ```partition block, if present. */
91
+ export declare function extractPartitionBlock(raw: string): string | null;
92
+ /**
93
+ * Normalize a claim or changed path for prefix comparison: trim, convert
94
+ * backslashes, collapse doubled slashes, drop interior `.` segments, a leading
95
+ * `./`, and trailing slashes. Purely lexical — no filesystem access. Without
96
+ * the collapse, `packages//backend` and `packages/./backend` pass disjointness
97
+ * against `packages/backend` while claiming the same directory — the exact
98
+ * two-writers-one-file outcome the partition-time hard error exists to prevent.
99
+ */
100
+ export declare function normalizeClaimPath(path: string): string;
101
+ /** True when `claim` is the path itself or a directory containing it. */
102
+ export declare function claimCovers(claim: string, path: string): boolean;
103
+ /**
104
+ * Parse the orchestrator's raw output into a {@link PartitionDecision}. Never
105
+ * throws: an unusable block is a soft rejection (re-ask, then single-writer) and
106
+ * overlapping claims are the hard rejection the caller turns into a stage error.
107
+ */
108
+ export declare function parsePartition(raw: string): PartitionParse;
109
+ /**
110
+ * Post-fan claim audit: the changed paths not covered by any workstream's claims,
111
+ * normalized, deduped, in first-seen order. Claims are prefixes, so a file created
112
+ * under a claimed directory is in-claim; anything else is a named violation the
113
+ * synthesizer reconciles.
114
+ */
115
+ export declare function auditClaims(changedPaths: string[], workstreams: PartitionWorkstream[]): string[];
116
+ //# sourceMappingURL=fanout.d.ts.map