@yagni-app/code-staging 1.2.14-staging.2314.1 → 1.2.14-staging.2318.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.
@@ -10,7 +10,7 @@
10
10
  * `tool_execution_end`; the example's `tool_result_end` branch is dead/never
11
11
  * emitted, so `collectToolResults` reads the former and ignores the latter.
12
12
  */
13
- import type { JsonEvent, StageUsage } from "./types.js";
13
+ import { type JsonEvent, type StageUsage } from "./types.js";
14
14
  /**
15
15
  * The final assistant text handed forward as the next stage's `{previous}`.
16
16
  * Biased toward the model's GENUINE turn-end: prefer the last assistant message
@@ -38,12 +38,32 @@ export declare function collectToolResults(events: JsonEvent[]): Array<{
38
38
  toolName: string;
39
39
  isError: boolean;
40
40
  }>;
41
+ /**
42
+ * The pi tools that change files. A turn's edits land through these, so they are
43
+ * the only calls the write-stage health gate counts: `bash` errors on any
44
+ * non-zero exit, so a red test run or a `grep` with no match is an errored call
45
+ * that says nothing about whether the edits landed.
46
+ */
47
+ export declare const EDIT_TOOL_NAMES: readonly string[];
48
+ /**
49
+ * The write-stage health gate: true when a turn made enough `edit`/`write`
50
+ * calls (MIN_TOOL_CALLS_FOR_HEALTH) and most of them errored (above
51
+ * TOOL_ERROR_FAIL_RATE), so its edits likely did not land. Absent counts are a
52
+ * caller-injected seam that observed none, which never trips it.
53
+ */
54
+ export declare function editsMostlyFailed(r: {
55
+ editCalls?: number;
56
+ editErrors?: number;
57
+ }): boolean;
41
58
  export interface EventAccumulator {
42
59
  usage: StageUsage;
43
60
  stopReason?: string;
44
61
  errorMessage?: string;
45
62
  toolCalls: number;
46
63
  toolErrors: number;
64
+ /** The `edit` and `write` subset of the tool counts: what the write-stage health gate reads. */
65
+ editCalls: number;
66
+ editErrors: number;
47
67
  /** Last assistant text on a genuine "stop" turn, and on any turn — extractFinalOutput's two tiers. */
48
68
  lastStopText?: string;
49
69
  lastAnyText?: string;
@@ -10,6 +10,7 @@
10
10
  * `tool_execution_end`; the example's `tool_result_end` branch is dead/never
11
11
  * emitted, so `collectToolResults` reads the former and ignores the latter.
12
12
  */
13
+ import { MIN_TOOL_CALLS_FOR_HEALTH, TOOL_ERROR_FAIL_RATE, } from "./types.js";
13
14
  /** True for an assistant `message_end` event carrying a message. */
14
15
  function isAssistantMessage(ev) {
15
16
  return ev.type === "message_end" && ev.message?.role === "assistant";
@@ -92,11 +93,35 @@ export function collectToolResults(events) {
92
93
  }
93
94
  return out;
94
95
  }
96
+ /**
97
+ * The pi tools that change files. A turn's edits land through these, so they are
98
+ * the only calls the write-stage health gate counts: `bash` errors on any
99
+ * non-zero exit, so a red test run or a `grep` with no match is an errored call
100
+ * that says nothing about whether the edits landed.
101
+ */
102
+ export const EDIT_TOOL_NAMES = ["edit", "write"];
103
+ function isEditTool(toolName) {
104
+ return toolName !== undefined && EDIT_TOOL_NAMES.includes(toolName);
105
+ }
106
+ /**
107
+ * The write-stage health gate: true when a turn made enough `edit`/`write`
108
+ * calls (MIN_TOOL_CALLS_FOR_HEALTH) and most of them errored (above
109
+ * TOOL_ERROR_FAIL_RATE), so its edits likely did not land. Absent counts are a
110
+ * caller-injected seam that observed none, which never trips it.
111
+ */
112
+ export function editsMostlyFailed(r) {
113
+ const calls = r.editCalls ?? 0;
114
+ if (calls < MIN_TOOL_CALLS_FOR_HEALTH)
115
+ return false;
116
+ return (r.editErrors ?? 0) / calls > TOOL_ERROR_FAIL_RATE;
117
+ }
95
118
  export function newEventAccumulator() {
96
119
  return {
97
120
  usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, turns: 0 },
98
121
  toolCalls: 0,
99
122
  toolErrors: 0,
123
+ editCalls: 0,
124
+ editErrors: 0,
100
125
  };
101
126
  }
102
127
  /** The last text part of a single assistant message, or undefined. */
@@ -115,6 +140,11 @@ export function foldEvent(acc, ev) {
115
140
  acc.toolCalls += 1;
116
141
  if (ev.isError)
117
142
  acc.toolErrors += 1;
143
+ if (isEditTool(ev.toolName)) {
144
+ acc.editCalls += 1;
145
+ if (ev.isError)
146
+ acc.editErrors += 1;
147
+ }
118
148
  return;
119
149
  }
120
150
  if (!isAssistantMessage(ev))
@@ -26,6 +26,7 @@
26
26
  */
27
27
  import { addRunUsage, aggregateRunUsage, DEFAULT_RUN_BUDGET, DEFAULT_STAGE_ESTIMATE_MS, EMPTY_RUN_USAGE, exceedsBudget, stageWall, stageWontFit, } from "./budget.js";
28
28
  import { attributeFindings, checkerFindings, composeFixNote, composeResidue, composeSynthesizerInput, mergeFindings, parseOpenFindings, renderFindings, stripOpenFindings, } from "./checker.js";
29
+ import { editsMostlyFailed } from "./events.js";
29
30
  import { auditClaims, parsePartition, } from "./fanout.js";
30
31
  import { extractFindingsBlock, hasBlockingFindings, isBlockingFinding, parseFindings, shouldStop, unionFindings, } from "./findings.js";
31
32
  import { limitedMapFiles, readTouchedFiles } from "./fixRound.js";
@@ -36,7 +37,7 @@ import { makeRunVerify, makeWorkstreamCheck, parseChangedPaths, } from "./verify
36
37
  import { extractPlanJson } from "./planOutput.js";
37
38
  import { builderStage, fixerStage, fixRoundImplementStage, fixRoundMapStage, FULL_LANE, orchestratorStage, partitionReaskStage, PARTITION_CALLER_LABEL, planJsonReaskStage, REQUIRED_LENSES, reaskStage, reviewStage, synthesizerFixStage, synthesizerStage, SYNTHESIZER_CALLER_LABEL, workstreamCallerLabel, } from "./stages.js";
38
39
  import { snapshotWorkspace as defaultSnapshotWorkspace, workspaceChanged } from "./workspace.js";
39
- import { DEFAULT_RESILIENCE_POLICY, MAX_CONCURRENCY, MAX_FANOUT_CONCURRENCY, MAX_FANOUT_CONCURRENCY_ULTRA, MAX_FIX_TURNS, MIN_TOOL_CALLS_FOR_HEALTH, TOOL_ERROR_FAIL_RATE, } from "./types.js";
40
+ import { DEFAULT_RESILIENCE_POLICY, MAX_CONCURRENCY, MAX_FANOUT_CONCURRENCY, MAX_FANOUT_CONCURRENCY_ULTRA, MAX_FIX_TURNS, } from "./types.js";
40
41
  /** Each review round's findings as the host stores them: bounded, messages clipped. */
41
42
  export const MAX_ROUND_ITEMS = 20;
42
43
  const MAX_ROUND_ITEM_MESSAGE = 300;
@@ -64,31 +65,28 @@ export class PipelineStageError extends Error {
64
65
  }
65
66
  const BUILD_STAGE_IDS = ["map", "plan", "implement"];
66
67
  /**
67
- * Stages whose whole value is in landed edits, so a high tool-error rate there is
68
+ * Stages whose whole value is in landed edits, so a high edit-error rate there is
68
69
  * a real failure (R3-a). Read-only recon/review stages are intentionally exempt:
69
- * a grep/read that misses is normal navigation, not a broken stage.
70
+ * they make no edits to fail.
70
71
  */
71
72
  const WRITE_STAGE_IDS = ["implement", "fix"];
72
73
  /**
73
- * R3-a: true when a WRITE stage exited cleanly yet most of its tool calls errored
74
- * — the silent partial-implement landmine, where the model narrates a tidy
75
- * summary while its edits never landed. Conservative on purpose: only write
76
- * stages are gated, and BOTH a meaningful sample (MIN_TOOL_CALLS_FOR_HEALTH) and
77
- * a clear-majority error rate (above TOOL_ERROR_FAIL_RATE) must hold, so a couple
78
- * of expected errors never fail a stage.
74
+ * R3-a: true when a WRITE stage exited cleanly yet most of its edits and writes
75
+ * errored — the silent partial-implement landmine, where the model narrates a
76
+ * tidy summary while its edits never landed. Only write stages are gated, and
77
+ * only their `edit` / `write` calls count (`editsMostlyFailed`): a red test run
78
+ * or an empty search is an errored `bash` call, not a failed edit.
79
79
  */
80
80
  function toolFailureExceeded(r) {
81
81
  if (!WRITE_STAGE_IDS.includes(r.stageId))
82
82
  return false;
83
- if (r.toolCalls < MIN_TOOL_CALLS_FOR_HEALTH)
84
- return false;
85
- return r.toolErrors / r.toolCalls > TOOL_ERROR_FAIL_RATE;
83
+ return editsMostlyFailed(r);
86
84
  }
87
85
  /** The honest reason string for a tool-failure-flagged stage, else undefined. */
88
86
  function toolFailureReason(r) {
89
87
  if (!toolFailureExceeded(r))
90
88
  return undefined;
91
- return `tool failures: ${r.toolErrors} of ${r.toolCalls} tool calls errored, so its edits likely did not land despite a clean-looking summary. Re-run /go.`;
89
+ return `tool failures: ${r.editErrors ?? 0} of ${r.editCalls ?? 0} edits and writes errored, so its edits likely did not land despite a clean-looking summary. Re-run /go.`;
92
90
  }
93
91
  /**
94
92
  * A stage outcome counts as a failure on a non-zero exit, an error/abort stop, or
@@ -796,6 +794,8 @@ export async function runPipeline(ticket, deps) {
796
794
  .join("\n"),
797
795
  toolCalls: builders.reduce((n, r) => n + r.toolCalls, 0),
798
796
  toolErrors: builders.reduce((n, r) => n + r.toolErrors, 0),
797
+ editCalls: builders.reduce((n, r) => n + (r.editCalls ?? 0), 0),
798
+ editErrors: builders.reduce((n, r) => n + (r.editErrors ?? 0), 0),
799
799
  ...(failed.length > 0 ? { stopReason: "error", errorMessage: failureNote } : {}),
800
800
  };
801
801
  log("fanout_done", {
@@ -122,6 +122,8 @@ export async function runStage(stage, ctx, deps) {
122
122
  stderr: "",
123
123
  toolCalls: 0,
124
124
  toolErrors: 0,
125
+ editCalls: 0,
126
+ editErrors: 0,
125
127
  };
126
128
  try {
127
129
  const invocation = buildStageInvocation(stage, {
@@ -329,11 +331,13 @@ export async function runStage(stage, ctx, deps) {
329
331
  result.stderr = stderr;
330
332
  result.finalOutput = capOutput(finalOutputFrom(acc));
331
333
  result.usage = acc.usage;
332
- // R3-a: tap tool-result counts into stage health. The orchestrator turns
333
- // this ratio into a write-stage failure when most edits errored, so a
334
- // clean-looking summary can't mask a silent partial implement.
334
+ // R3-a: tap tool-result counts into stage health. The write-stage gate
335
+ // turns the edit / write ratio into a failure when most edits errored, so
336
+ // a clean-looking summary can't mask a silent partial implement.
335
337
  result.toolCalls = acc.toolCalls;
336
338
  result.toolErrors = acc.toolErrors;
339
+ result.editCalls = acc.editCalls;
340
+ result.editErrors = acc.editErrors;
337
341
  if (acc.stopReason)
338
342
  result.stopReason = acc.stopReason;
339
343
  if (acc.errorMessage)
@@ -47,7 +47,7 @@ import { type AttemptResult, type CloudIdentity, type CloudStage } from "./cloud
47
47
  import type { ContinuationInputs } from "./continuation.js";
48
48
  import { type PlanChange } from "./planChanges.js";
49
49
  import { type RunStageDeps } from "./runner.js";
50
- import { type JsonEvent, type ModelTier, type PipelineStage, type StageId, type StageResult, type StopReason } from "./types.js";
50
+ import type { JsonEvent, ModelTier, PipelineStage, StageId, StageResult, StopReason } from "./types.js";
51
51
  import { type VerifyCheckRun } from "./verify.js";
52
52
  import { snapshotWorkspace } from "./workspace.js";
53
53
  import type { WorktreeExec } from "./worktree.js";
@@ -145,7 +145,9 @@ export declare function childStderrTail(stderr: string): string;
145
145
  /**
146
146
  * The turn's stop as the result names it: aborted, its clock, a model proxy
147
147
  * that refused it for what the run may spend, a child that failed, a writing
148
- * turn whose tools mostly errored (the cloud lane's health gate), else clean.
148
+ * turn whose edits and writes mostly errored (the cloud lane's health gate),
149
+ * else clean. Red tests and empty searches are errored `bash` calls and never
150
+ * count: the gate asks whether the edits landed.
149
151
  */
150
152
  export declare function turnStop(run: StageResult, writes: boolean, aborted: boolean): {
151
153
  stop: StopReason;
@@ -60,7 +60,7 @@ import { runStage as defaultRunStage } from "./runner.js";
60
60
  import { scrubSecrets } from "./scrubSecrets.js";
61
61
  import { DECISIONS_READ_TOOL, PLAN_JSON_CONTRACT } from "./stages.js";
62
62
  import { STAGE_WRAP_UP_GRACE_MS } from "./stageClock.js";
63
- import { MIN_TOOL_CALLS_FOR_HEALTH, TOOL_ERROR_FAIL_RATE, } from "./types.js";
63
+ import { editsMostlyFailed } from "./events.js";
64
64
  import { baselineDirs, parseChangedPaths, planPaths } from "./verify.js";
65
65
  import { snapshotWorkspace } from "./workspace.js";
66
66
  /** The one tier the session's writer runs on; its subagents keep their own. */
@@ -371,7 +371,9 @@ export function childStderrTail(stderr) {
371
371
  /**
372
372
  * The turn's stop as the result names it: aborted, its clock, a model proxy
373
373
  * that refused it for what the run may spend, a child that failed, a writing
374
- * turn whose tools mostly errored (the cloud lane's health gate), else clean.
374
+ * turn whose edits and writes mostly errored (the cloud lane's health gate),
375
+ * else clean. Red tests and empty searches are errored `bash` calls and never
376
+ * count: the gate asks whether the edits landed.
375
377
  */
376
378
  export function turnStop(run, writes, aborted) {
377
379
  if (aborted || run.stopReason === "aborted")
@@ -394,12 +396,10 @@ export function turnStop(run, writes, aborted) {
394
396
  : ` (exit ${run.exitCode}, nothing on its stderr)`;
395
397
  return { stop: "failed", note: `The session's turn ended on an error${why}.` };
396
398
  }
397
- if (writes &&
398
- run.toolCalls >= MIN_TOOL_CALLS_FOR_HEALTH &&
399
- run.toolErrors / run.toolCalls > TOOL_ERROR_FAIL_RATE) {
399
+ if (writes && editsMostlyFailed(run)) {
400
400
  return {
401
401
  stop: "failed",
402
- note: `Tool failures: ${run.toolErrors} of ${run.toolCalls} tool calls errored, so its edits likely did not land.`,
402
+ note: `Tool failures: ${run.editErrors ?? 0} of ${run.editCalls ?? 0} edits and writes errored, so its edits likely did not land.`,
403
403
  };
404
404
  }
405
405
  return { stop: "clean" };
@@ -143,16 +143,22 @@ export interface StageResult {
143
143
  errorMessage?: string;
144
144
  stderr: string;
145
145
  /**
146
- * Tool-call health for this stage (R3-a). `toolCalls` is how many tools the
147
- * child actually executed (`tool_execution_end` events); `toolErrors` is how
148
- * many of those returned an error. The orchestrator folds the ratio into the
149
- * write-stage health check so an implement / fix stage that exits 0 with a
150
- * clean-looking summary while most of its edits failed is caught rather than
151
- * trusted. Both default to 0 (no tools observed), which is below
152
- * MIN_TOOL_CALLS_FOR_HEALTH and so never trips the guard.
146
+ * Tool-call counts for this stage. `toolCalls` is how many tools the child
147
+ * actually executed (`tool_execution_end` events); `toolErrors` is how many of
148
+ * those returned an error. Kept for logs and handoffs: a red test run or an
149
+ * empty search is an errored `bash` call, so these never feed a health gate.
153
150
  */
154
151
  toolCalls: number;
155
152
  toolErrors: number;
153
+ /**
154
+ * The `edit` / `write` subset of the counts above: the only calls the
155
+ * write-stage health gate (R3-a, `editsMostlyFailed`) reads, so an implement /
156
+ * fix stage that exits 0 with a clean-looking summary while most of its edits
157
+ * failed is caught rather than trusted. Absent means none observed (a
158
+ * caller-injected runStage seam), which never trips the gate.
159
+ */
160
+ editCalls?: number;
161
+ editErrors?: number;
156
162
  /**
157
163
  * How many stdout lines this stage discarded for exceeding the max line size
158
164
  * (`RunStageDeps.maxLineBytes`). A pathologically long single NDJSON line (a
@@ -613,14 +619,16 @@ export interface ResiliencePolicy {
613
619
  export declare const DEFAULT_RESILIENCE_POLICY: ResiliencePolicy;
614
620
  /**
615
621
  * R3-a tool-failure health gate. A WRITE stage (implement / fix) that exits 0 is
616
- * still a failure when most of its tool calls errored: the prose summary reads
617
- * fine while the edits never landed (the recorded silent-partial-implement
618
- * landmine). Conservative by design — BOTH guards must hold before a stage is
619
- * failed for tool errors, so a couple of expected misses never trip it:
620
- * - `TOOL_ERROR_FAIL_RATE`: the error rate must EXCEED this clear majority, so a
621
- * grep that finds nothing or one transient error among many calls is fine.
622
- * - `MIN_TOOL_CALLS_FOR_HEALTH`: require a meaningful sample first, so a stage
623
- * that made only one or two tool calls is never failed on a tiny ratio.
622
+ * still a failure when most of its `edit` / `write` calls errored: the prose
623
+ * summary reads fine while the edits never landed (the recorded
624
+ * silent-partial-implement landmine). Only those calls count: a red test run or
625
+ * a grep that finds nothing is a `bash` call that errored, not a failed edit.
626
+ * Conservative by design — BOTH guards must hold before a stage is failed:
627
+ * - `TOOL_ERROR_FAIL_RATE`: the edit error rate must EXCEED this clear
628
+ * majority, so one stale edit among many is fine.
629
+ * - `MIN_TOOL_CALLS_FOR_HEALTH`: require a meaningful sample of edits and
630
+ * writes first, so a stage that made only one or two is never failed on a
631
+ * tiny ratio.
624
632
  * Tunable per lane if a future stage needs a stricter or looser bar.
625
633
  */
626
634
  export declare const TOOL_ERROR_FAIL_RATE = 0.6;
@@ -54,14 +54,16 @@ export const DEFAULT_RESILIENCE_POLICY = {
54
54
  };
55
55
  /**
56
56
  * R3-a tool-failure health gate. A WRITE stage (implement / fix) that exits 0 is
57
- * still a failure when most of its tool calls errored: the prose summary reads
58
- * fine while the edits never landed (the recorded silent-partial-implement
59
- * landmine). Conservative by design — BOTH guards must hold before a stage is
60
- * failed for tool errors, so a couple of expected misses never trip it:
61
- * - `TOOL_ERROR_FAIL_RATE`: the error rate must EXCEED this clear majority, so a
62
- * grep that finds nothing or one transient error among many calls is fine.
63
- * - `MIN_TOOL_CALLS_FOR_HEALTH`: require a meaningful sample first, so a stage
64
- * that made only one or two tool calls is never failed on a tiny ratio.
57
+ * still a failure when most of its `edit` / `write` calls errored: the prose
58
+ * summary reads fine while the edits never landed (the recorded
59
+ * silent-partial-implement landmine). Only those calls count: a red test run or
60
+ * a grep that finds nothing is a `bash` call that errored, not a failed edit.
61
+ * Conservative by design — BOTH guards must hold before a stage is failed:
62
+ * - `TOOL_ERROR_FAIL_RATE`: the edit error rate must EXCEED this clear
63
+ * majority, so one stale edit among many is fine.
64
+ * - `MIN_TOOL_CALLS_FOR_HEALTH`: require a meaningful sample of edits and
65
+ * writes first, so a stage that made only one or two is never failed on a
66
+ * tiny ratio.
65
67
  * Tunable per lane if a future stage needs a stricter or looser bar.
66
68
  */
67
69
  export const TOOL_ERROR_FAIL_RATE = 0.6;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "1.2.14-staging.2314.1",
3
+ "version": "1.2.14-staging.2318.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": "c2e377750b3dd156d520b92af3d0ab8bfcd72e6d"
61
+ "yagniSourceSha": "6e6f47f73826b217af99de721a08c4b933ad7b50"
62
62
  }