pi-spine 2.33.0 → 2.34.0

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.
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Flutter analyzer / build hygiene for lane worktrees (#78).
3
+ * Extracted from lane-dirty-check.mjs so that module stays under the LOC cap.
4
+ */
5
+
6
+ import fs from "node:fs";
7
+ import path from "node:path";
8
+
9
+ /** Flutter build output dir that can pollute unscoped `flutter analyze` (#78). */
10
+ export const FLUTTER_BUILD_DIR = "build";
11
+
12
+ /**
13
+ * @param {string} segment
14
+ * @returns {boolean}
15
+ */
16
+ export function isUnscopedFlutterAnalyzeSegment(segment) {
17
+ const trimmed = String(segment ?? "").trim().toLowerCase();
18
+ if (!/\bflutter\s+analyze\b/.test(trimmed)) {
19
+ return false;
20
+ }
21
+
22
+ const match = trimmed.match(/\bflutter\s+analyze\b(.*)$/);
23
+ if (!match) {
24
+ return false;
25
+ }
26
+
27
+ const remainder = (match[1] ?? "").trim();
28
+ if (!remainder) {
29
+ return true;
30
+ }
31
+
32
+ for (const token of remainder.split(/\s+/)) {
33
+ if (token.startsWith("-")) {
34
+ continue;
35
+ }
36
+ return false;
37
+ }
38
+
39
+ return true;
40
+ }
41
+
42
+ /**
43
+ * True when testCommand invokes unscoped `flutter analyze` (whole project tree).
44
+ * Scoped forms like `flutter analyze lib test` are excluded.
45
+ *
46
+ * @param {string} command
47
+ * @returns {boolean}
48
+ */
49
+ export function isUnscopedFlutterAnalyzeCommand(command) {
50
+ const trimmed = String(command ?? "").trim();
51
+ if (!trimmed) {
52
+ return false;
53
+ }
54
+
55
+ const segments = trimmed
56
+ .split(/&&|;/)
57
+ .map((segment) => segment.trim())
58
+ .filter(Boolean);
59
+ return segments.some((segment) => isUnscopedFlutterAnalyzeSegment(segment));
60
+ }
61
+
62
+ /**
63
+ * True when testCommand combines flutter analyze with flutter test.
64
+ *
65
+ * @param {string} command
66
+ * @returns {boolean}
67
+ */
68
+ export function isFlutterAnalyzeTestCompoundCommand(command) {
69
+ const trimmed = String(command ?? "").trim().toLowerCase();
70
+ return /\bflutter\s+analyze\b/.test(trimmed) && /\bflutter\s+test\b/.test(trimmed);
71
+ }
72
+
73
+ /**
74
+ * Whether contract verify should remove `build/` before running testCommand.
75
+ *
76
+ * @param {string} testCommand
77
+ * @param {{ contract?: { flutterAnalyzerHygiene?: boolean } }} [config]
78
+ * @returns {boolean}
79
+ */
80
+ export function shouldCleanFlutterBuildBeforeAnalyze(testCommand, config = {}) {
81
+ const enabled = config?.contract?.flutterAnalyzerHygiene ?? true;
82
+ if (!enabled) {
83
+ return false;
84
+ }
85
+ return isUnscopedFlutterAnalyzeCommand(testCommand);
86
+ }
87
+
88
+ /**
89
+ * Remove stale Flutter build artifacts so unscoped analyze does not scan SourcePackages (#78).
90
+ *
91
+ * @param {string} worktreePath
92
+ * @param {{ enabled?: boolean }} [options]
93
+ * @returns {{ cleaned: boolean, buildDir?: string, reason?: string }}
94
+ */
95
+ export function sanitizeFlutterBuildBeforeAnalyze(worktreePath, { enabled = true } = {}) {
96
+ if (!enabled) {
97
+ return { cleaned: false, reason: "disabled" };
98
+ }
99
+
100
+ const buildPath = path.join(worktreePath, FLUTTER_BUILD_DIR);
101
+ if (!fs.existsSync(buildPath)) {
102
+ return { cleaned: false, reason: "no_build_dir" };
103
+ }
104
+
105
+ fs.rmSync(buildPath, { recursive: true, force: true });
106
+ return { cleaned: true, buildDir: FLUTTER_BUILD_DIR };
107
+ }
@@ -17,6 +17,7 @@ import {
17
17
  buildHeartbeatPayloadFields,
18
18
  buildProgressSnapshotPayload,
19
19
  } from "./heartbeat-subprocess.mjs";
20
+ import { isWorkerUsageSidecarPath } from "./worker-usage-sidecar.mjs";
20
21
 
21
22
  export {
22
23
  clearGitPorcelainDebounceCache,
@@ -146,6 +147,8 @@ export function resolveScopedDirtyPaths(worktreePath, fileScopePaths, taskFolder
146
147
  let filePath = line.length > 2 && line[2] === " " ? line.slice(3) : line.slice(2);
147
148
  filePath = filePath.trim();
148
149
  const renamed = filePath.includes(" -> ") ? filePath.split(" -> ").pop()?.trim() : filePath;
150
+ // SP-881 / #380: engine-owned usage sidecar is never salvageable product dirt.
151
+ if (renamed && isWorkerUsageSidecarPath(renamed)) continue;
149
152
  if (renamed && inScope(renamed)) dirty.add(renamed);
150
153
  }
151
154
  return [...dirty].sort();
@@ -27,6 +27,7 @@ import { isLiveEngineInActivePhase } from "./lifecycle-archive.mjs";
27
27
  import { appendJournalEvent } from "./journal.mjs";
28
28
  import { countCommitsAhead } from "./lane-commit.mjs";
29
29
  import { inspectGitState, loadBatchStateFile, parseBatchState } from "./reconcile.mjs";
30
+ import { syncIssuesAfterIntegrate } from "../integrations/github/sync-on-land.mjs";
30
31
 
31
32
  /**
32
33
  * @param {string} projectRoot
@@ -99,6 +100,7 @@ function postMergeCompletionSuggestion(raw) {
99
100
  * @param {boolean} [ctx.dryRun]
100
101
  * @param {string|null} [ctx.batchId]
101
102
  * @param {string|null} [ctx.batchStatePath]
103
+ * @param {boolean} [ctx.noGithubSync] Skip the opt-in post-integrate GitHub issue sync (#383).
102
104
  */
103
105
  export function integrateOrchToBase(ctx) {
104
106
  const { projectRoot, dryRun = false } = ctx;
@@ -412,6 +414,18 @@ export function integrateOrchToBase(ctx) {
412
414
  baseCheckedOutAtStart,
413
415
  });
414
416
 
417
+ // Opt-in GitHub sync runs only on the fresh-success path — the
418
+ // `alreadyMerged` early-return above must not re-comment/close (#383).
419
+ // Best-effort: syncIssuesAfterIntegrate never throws into this path.
420
+ const githubSync = syncIssuesAfterIntegrate({
421
+ projectRoot,
422
+ batchId,
423
+ batch,
424
+ config,
425
+ mergeCommit,
426
+ noGithubSync: Boolean(ctx.noGithubSync),
427
+ });
428
+
415
429
  const waiting = postMergeCompletionSuggestion(loaded.raw);
416
430
  return {
417
431
  ok: true,
@@ -428,6 +442,7 @@ export function integrateOrchToBase(ctx) {
428
442
  alternatives: waiting
429
443
  ? ["spine batch complete", "spine status --diagnose"]
430
444
  : ["spine status --diagnose"],
445
+ ...(githubSync ? { githubSync } : {}),
431
446
  ...(dirtyOverlapWarning ? { warnings: [dirtyOverlapWarning] } : {}),
432
447
  };
433
448
  } catch (err) {
@@ -6,8 +6,6 @@
6
6
  */
7
7
 
8
8
  import { execFileSync } from "node:child_process";
9
- import fs from "node:fs";
10
- import path from "node:path";
11
9
  import { loadSpineConfig } from "../config/spine-config-load.mjs";
12
10
  import { resolveLaneCommitKeepPaths } from "../config/spine-config-schema.mjs";
13
11
  import { resolveWorktreeSetupHook } from "../config/worktree-setup-hook.mjs";
@@ -44,6 +42,21 @@ import {
44
42
  listTrackedPorcelainPaths,
45
43
  repairSetupHookSymlinkDrift,
46
44
  } from "./lane-dirty-check-git.mjs";
45
+ import { WORKER_USAGE_SIDECAR_FILENAME } from "./worker-usage-sidecar.mjs";
46
+
47
+ export {
48
+ WORKER_USAGE_SIDECAR_FILENAME,
49
+ isWorkerUsageSidecarPath,
50
+ } from "./worker-usage-sidecar.mjs";
51
+
52
+ export {
53
+ FLUTTER_BUILD_DIR,
54
+ isFlutterAnalyzeTestCompoundCommand,
55
+ isUnscopedFlutterAnalyzeCommand,
56
+ isUnscopedFlutterAnalyzeSegment,
57
+ sanitizeFlutterBuildBeforeAnalyze,
58
+ shouldCleanFlutterBuildBeforeAnalyze,
59
+ } from "./flutter-analyzer-hygiene.mjs";
47
60
 
48
61
  /**
49
62
  * Path segments for gitignored build artifacts that npm test and similar tools
@@ -64,108 +77,11 @@ export const GITIGNORED_ARTIFACT_MARKERS = [
64
77
  ".pi-smart-router/",
65
78
  "/.spine/runtime/",
66
79
  ".spine/runtime/",
80
+ // SP-881 / #380: engine-owned usage sidecar under task folders (must not salvage-thrash)
81
+ `/${WORKER_USAGE_SIDECAR_FILENAME}`,
82
+ WORKER_USAGE_SIDECAR_FILENAME,
67
83
  ];
68
84
 
69
- /** Flutter build output dir that can pollute unscoped `flutter analyze` (#78). */
70
- export const FLUTTER_BUILD_DIR = "build";
71
-
72
- /**
73
- * @param {string} segment
74
- * @returns {boolean}
75
- */
76
- export function isUnscopedFlutterAnalyzeSegment(segment) {
77
- const trimmed = String(segment ?? "").trim().toLowerCase();
78
- if (!/\bflutter\s+analyze\b/.test(trimmed)) {
79
- return false;
80
- }
81
-
82
- const match = trimmed.match(/\bflutter\s+analyze\b(.*)$/);
83
- if (!match) {
84
- return false;
85
- }
86
-
87
- const remainder = (match[1] ?? "").trim();
88
- if (!remainder) {
89
- return true;
90
- }
91
-
92
- for (const token of remainder.split(/\s+/)) {
93
- if (token.startsWith("-")) {
94
- continue;
95
- }
96
- return false;
97
- }
98
-
99
- return true;
100
- }
101
-
102
- /**
103
- * True when testCommand invokes unscoped `flutter analyze` (whole project tree).
104
- * Scoped forms like `flutter analyze lib test` are excluded.
105
- *
106
- * @param {string} command
107
- * @returns {boolean}
108
- */
109
- export function isUnscopedFlutterAnalyzeCommand(command) {
110
- const trimmed = String(command ?? "").trim();
111
- if (!trimmed) {
112
- return false;
113
- }
114
-
115
- const segments = trimmed
116
- .split(/&&|;/)
117
- .map((segment) => segment.trim())
118
- .filter(Boolean);
119
- return segments.some((segment) => isUnscopedFlutterAnalyzeSegment(segment));
120
- }
121
-
122
- /**
123
- * True when testCommand combines flutter analyze with flutter test.
124
- *
125
- * @param {string} command
126
- * @returns {boolean}
127
- */
128
- export function isFlutterAnalyzeTestCompoundCommand(command) {
129
- const trimmed = String(command ?? "").trim().toLowerCase();
130
- return /\bflutter\s+analyze\b/.test(trimmed) && /\bflutter\s+test\b/.test(trimmed);
131
- }
132
-
133
- /**
134
- * Whether contract verify should remove `build/` before running testCommand.
135
- *
136
- * @param {string} testCommand
137
- * @param {object} [config]
138
- * @returns {boolean}
139
- */
140
- export function shouldCleanFlutterBuildBeforeAnalyze(testCommand, config = {}) {
141
- const enabled = config?.contract?.flutterAnalyzerHygiene ?? true;
142
- if (!enabled) {
143
- return false;
144
- }
145
- return isUnscopedFlutterAnalyzeCommand(testCommand);
146
- }
147
-
148
- /**
149
- * Remove stale Flutter build artifacts so unscoped analyze does not scan SourcePackages (#78).
150
- *
151
- * @param {string} worktreePath
152
- * @param {{ enabled?: boolean }} [options]
153
- * @returns {{ cleaned: boolean, buildDir?: string, reason?: string }}
154
- */
155
- export function sanitizeFlutterBuildBeforeAnalyze(worktreePath, { enabled = true } = {}) {
156
- if (!enabled) {
157
- return { cleaned: false, reason: "disabled" };
158
- }
159
-
160
- const buildPath = path.join(worktreePath, FLUTTER_BUILD_DIR);
161
- if (!fs.existsSync(buildPath)) {
162
- return { cleaned: false, reason: "no_build_dir" };
163
- }
164
-
165
- fs.rmSync(buildPath, { recursive: true, force: true });
166
- return { cleaned: true, buildDir: FLUTTER_BUILD_DIR };
167
- }
168
-
169
85
  /**
170
86
  * Restore tracked and remove untracked out-of-scope coverage before lane commit.
171
87
  *
@@ -5,7 +5,7 @@
5
5
 
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
- import { appendJournalEvent } from "./journal.mjs";
8
+ import { appendJournalEvent, readJournalEvents } from "./journal.mjs";
9
9
  import {
10
10
  clearActiveBatchStateIfMatches,
11
11
  loadBatchStateFile,
@@ -46,6 +46,35 @@ export function isLiveEngineInActivePhase(raw, deps = {}) {
46
46
  return Boolean(isEngineAlive(raw));
47
47
  }
48
48
 
49
+ /**
50
+ * Journal signals that prove the batch is inside the land-loop finalize window
51
+ * (#379): the operator approved the integrate gate (`gate.approved`) or the
52
+ * orch branch already merged (`integrate.completed`). Past either point all
53
+ * tasks succeeded and merged, so an active-looking phase is finalize
54
+ * bookkeeping — resume can only take the post-merge limbo fast path — and not
55
+ * a batch that went active again for real work.
56
+ *
57
+ * @param {string} projectRoot
58
+ * @param {string} batchId
59
+ * @returns {boolean}
60
+ */
61
+ export function journalHasIntegrateProgressSignals(projectRoot, batchId) {
62
+ if (!batchId) return false;
63
+ try {
64
+ return readJournalEvents(projectRoot, batchId).some((event) => {
65
+ const type = String(
66
+ /** @type {{ type?: string }} */
67
+ (event)?.type ?? "",
68
+ );
69
+ return type === "gate.approved" || type === "integrate.completed";
70
+ });
71
+ } catch {
72
+ // Fail closed: an unreadable journal cannot prove finalize is in
73
+ // flight, so the caller keeps the generic mid-write refusal.
74
+ return false;
75
+ }
76
+ }
77
+
49
78
  /**
50
79
  * Re-read the active batch state inside the terminal lock section
51
80
  * (SP-792 / #301) so archive, history, and clear act on the freshest on-disk
@@ -57,6 +86,12 @@ export function isLiveEngineInActivePhase(raw, deps = {}) {
57
86
  * — with `requireTerminalPhase` — the batch became active again mid-write.
58
87
  * Abort passes `requireTerminalPhase: false` because aborting a running
59
88
  * batch is its normal use case.
89
+ * Exception (#371, #379): when the active phase is the engine finishing its
90
+ * land-loop finalize — a live engine PID, or the finalize window itself (no
91
+ * recorded PID with `gate.approved`/`integrate.completed` already journaled,
92
+ * since finalize clears the PID before writing the terminal phase, #198) —
93
+ * the refusal is a soft `pending` wait with a wait command, not a hard
94
+ * failure that implies corruption.
60
95
  *
61
96
  * @param {object} params
62
97
  * @param {string} params.projectRoot
@@ -68,6 +103,7 @@ export function isLiveEngineInActivePhase(raw, deps = {}) {
68
103
  * @param {string|null} [params.diagnosis] pre-lock diagnosis echoed on refusal
69
104
  * @param {object} [params.deps]
70
105
  * @param {(raw: object) => boolean} [params.deps.isEngineAlive] injectable engine liveness probe (#371)
106
+ * @param {(raw: object) => boolean} [params.deps.isFinalizeInFlight] injectable extra finalize-window probe (#379); OR-ed with `journalHasIntegrateProgressSignals` — a `false` return defers to the journal fallback
71
107
  * @returns {{ state: { path: string, raw: object }|null, refusal: object|null }}
72
108
  */
73
109
  export function reloadStateForTerminalWrite({
@@ -103,23 +139,40 @@ export function reloadStateForTerminalWrite({
103
139
  if (requireTerminalPhase && !force) {
104
140
  const phase = String(/** @type {{ phase?: string }} */ (reloaded.raw).phase ?? "");
105
141
  if (ACTIVE_RESUME_PHASES.has(phase)) {
142
+ // #371 / #379: the engine is finishing its land loop, not crashing —
143
+ // report a pending wait instead of the generic mid-write failure.
144
+ const landLoopPending = () => ({
145
+ state: null,
146
+ refusal: {
147
+ ok: false,
148
+ exitCode: 1,
149
+ pending: true,
150
+ error: "engine_finishing_land_loop",
151
+ headline: "Engine is finishing the land loop — wait for it to complete",
152
+ suggestedCommand: "spine wait --until completed --timeout 10m",
153
+ diagnosis: diagnosis ?? null,
154
+ batchId,
155
+ },
156
+ });
106
157
  // #371: a live engine turned the batch active again between the pre-lock
107
158
  // read and this reload — it is finishing its land loop, not crashing.
108
- // Report a pending wait instead of the generic mid-write failure.
109
159
  if (isLiveEngineInActivePhase(reloaded.raw, deps)) {
110
- return {
111
- state: null,
112
- refusal: {
113
- ok: false,
114
- exitCode: 1,
115
- pending: true,
116
- error: "engine_finishing_land_loop",
117
- headline: "Engine is finishing the land loop — wait for it to complete",
118
- suggestedCommand: "spine wait --until completed --timeout 10m",
119
- diagnosis: diagnosis ?? null,
120
- batchId,
121
- },
122
- };
160
+ return landLoopPending();
161
+ }
162
+ // #379: the finalize path clears the engine PID before writing the
163
+ // terminal phase (#198), so an active phase with no recorded PID is
164
+ // normal mid-finalize once the gate is approved / integrate completed.
165
+ // A recorded-but-dead PID stays a hard refusal: an engine died while the
166
+ // phase was active and the state needs diagnosis, not a blind wait.
167
+ const enginePidRecorded = readBatchEnginePid(reloaded.raw) != null;
168
+ // `||`, not `??`: a probe returning `false` ("not in flight") must
169
+ // still defer to the journal fallback instead of short-circuiting the
170
+ // whole expression to `false` and masking journaled approval signals.
171
+ const finalizeInFlight =
172
+ deps.isFinalizeInFlight?.(reloaded.raw) ||
173
+ journalHasIntegrateProgressSignals(projectRoot, batchId);
174
+ if (!enginePidRecorded && finalizeInFlight) {
175
+ return landLoopPending();
123
176
  }
124
177
  return { state: null, refusal: refuse() };
125
178
  }
@@ -4,6 +4,8 @@
4
4
  */
5
5
 
6
6
  import { loadSpineConfig } from "../config/spine-config-load.mjs";
7
+ import { refreshTaskPacketFromBase } from "./engine-lanes/orch-sync.mjs";
8
+ import { appendJournalEvent } from "./journal.mjs";
7
9
  import { reconcileOrphanRunningState } from "./reconcile.mjs";
8
10
  import { resolveRetryProfileOverride } from "./retry-profile.mjs";
9
11
  import {
@@ -263,9 +265,10 @@ export function retryTask({ projectRoot, taskId, profile = null, noEscalate = fa
263
265
  }
264
266
 
265
267
  // Classify before reset: `resetTaskForRetry` clears `exitReason` / `classification`.
268
+ const { config: spineConfig } = loadSpineConfig(projectRoot);
266
269
  const profileDecision = resolveRetryProfileOverride({
267
270
  task,
268
- config: loadSpineConfig(projectRoot).config,
271
+ config: spineConfig,
269
272
  profile,
270
273
  noEscalate,
271
274
  });
@@ -324,6 +327,28 @@ export function retryTask({ projectRoot, taskId, profile = null, noEscalate = fa
324
327
  },
325
328
  });
326
329
 
330
+ // Operator packet fixes on base must reach the next worker run (#378): the
331
+ // worker, contract verify, and final review all read PROMPT.md from the lane
332
+ // worktree copy, which still holds what the failed run saw.
333
+ const packetRefresh = refreshTaskPacketFromBase({
334
+ projectRoot,
335
+ state,
336
+ taskId,
337
+ task,
338
+ config: spineConfig,
339
+ });
340
+ if (state.batchId && packetRefresh.refreshed.length > 0) {
341
+ appendJournalEvent(projectRoot, state.batchId, "task.packet_refreshed", {
342
+ taskId,
343
+ files: packetRefresh.refreshed,
344
+ });
345
+ } else if (state.batchId && packetRefresh.ok === false) {
346
+ appendJournalEvent(projectRoot, state.batchId, "task.packet_refresh_failed", {
347
+ taskId,
348
+ error: packetRefresh.error,
349
+ });
350
+ }
351
+
327
352
  if (unblocked) {
328
353
  recordTaskTransition({
329
354
  projectRoot,
@@ -343,6 +368,18 @@ export function retryTask({ projectRoot, taskId, profile = null, noEscalate = fa
343
368
  if (retriedRowIds.length > 0) {
344
369
  output += `\n Matrix rows re-running: ${retriedRowIds.join(", ")} (succeeded rows carry over).`;
345
370
  }
371
+ if (packetRefresh.refreshed.length > 0) {
372
+ output += `\n Packet refreshed from base: ${packetRefresh.refreshed
373
+ .map((entry) =>
374
+ entry.committed
375
+ ? `${entry.file} (committed ${entry.commitSha.slice(0, 12)})`
376
+ : `${entry.file} (copied; lane commit failed)`,
377
+ )
378
+ .join(", ")}.`;
379
+ }
380
+ if (!packetRefresh.ok) {
381
+ output += `\n Packet refresh failed (retry proceeds with the lane packet): ${packetRefresh.error}.`;
382
+ }
346
383
  if (profileDecision.escalation) {
347
384
  output += `\n Profile override: ${profileDecision.profileOverride} (${profileDecision.escalation === "auto" ? "escalatePolicy" : "--profile"}).`;
348
385
  }
@@ -358,6 +395,7 @@ export function retryTask({ projectRoot, taskId, profile = null, noEscalate = fa
358
395
  profileOverride: profileDecision.profileOverride,
359
396
  escalation: profileDecision.escalation,
360
397
  ...(retriedRowIds.length > 0 ? { retriedRowIds } : {}),
398
+ ...(packetRefresh.refreshed.length > 0 ? { packetRefreshed: packetRefresh.refreshed } : {}),
361
399
  output,
362
400
  };
363
401
  }
@@ -246,7 +246,13 @@ export async function runStepReview({
246
246
  contractVerifyResult,
247
247
  };
248
248
  let spawnResult = await spawnReviewerPi(spawnParams);
249
-
249
+ // SP-884 (#377): forward spawnReviewerPi's provider-reported usage (SP-878
250
+ // parser, never invented) onto every post-spawn return; a closure so SP-814
251
+ // re-spawns attribute the terminal attempt's stream.
252
+ const usageFields = () => {
253
+ const u = /** @type {any} */ (spawnResult).usage;
254
+ return u !== null && typeof u === "object" && !Array.isArray(u) ? { usage: u } : {};
255
+ };
250
256
  /** @returns {ReturnType<typeof runStepReview>|null} */
251
257
  const completeIfHonored = () =>
252
258
  spawnResult.honored && spawnResult.honorReason === ARTIFACT_READY_HONOR_REASON
@@ -260,7 +266,7 @@ export async function runStepReview({
260
266
  : null;
261
267
 
262
268
  const honoredFirstAttempt = completeIfHonored();
263
- if (honoredFirstAttempt) return honoredFirstAttempt;
269
+ if (honoredFirstAttempt) return { ...usageFields(), ...honoredFirstAttempt };
264
270
 
265
271
  // One bounded re-spawn for transient no-artifact exits and non-timeout
266
272
  // spawn failures (SP-814 / #332): journal the retry with diagnostics, then
@@ -295,7 +301,7 @@ export async function runStepReview({
295
301
  spawnResult = await spawnReviewerPi(spawnParams);
296
302
  attempt += 1;
297
303
  const honoredRetry = completeIfHonored();
298
- if (honoredRetry) return honoredRetry;
304
+ if (honoredRetry) return { ...usageFields(), ...honoredRetry };
299
305
  }
300
306
 
301
307
  // SP-820 / #334: classify the terminal attempt once, after the SP-814
@@ -325,7 +331,7 @@ export async function runStepReview({
325
331
  reviewLevel,
326
332
  });
327
333
  if (honored) {
328
- return honored;
334
+ return { ...usageFields(), ...honored };
329
335
  }
330
336
 
331
337
  const log = persistReviewerLogForAttempt({
@@ -353,6 +359,7 @@ export async function runStepReview({
353
359
  ...diagnostics,
354
360
  });
355
361
  return {
362
+ ...usageFields(),
356
363
  ok: false,
357
364
  skipped: false,
358
365
  reviewLevel,
@@ -396,6 +403,7 @@ export async function runStepReview({
396
403
  ...diagnostics,
397
404
  });
398
405
  return {
406
+ ...usageFields(),
399
407
  ok: false,
400
408
  skipped: false,
401
409
  reviewLevel,
@@ -422,6 +430,7 @@ export async function runStepReview({
422
430
  artifactPath,
423
431
  });
424
432
  return {
433
+ ...usageFields(),
425
434
  ok: false,
426
435
  skipped: false,
427
436
  reviewLevel,
@@ -445,6 +454,7 @@ export async function runStepReview({
445
454
  });
446
455
 
447
456
  return {
457
+ ...usageFields(),
448
458
  ok,
449
459
  skipped: false,
450
460
  reviewLevel,