pi-spine 1.7.0 → 1.8.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.
- package/bin/spine-doctor.mjs +4 -0
- package/package.json +2 -2
- package/skills/create-spine-tasks/SKILL.md +1 -0
- package/skills/spine-autonomous-operator/SKILL.md +267 -0
- package/skills/spine-autonomous-operator/references/issue-template.md +45 -0
- package/skills/spine-orchestrate-waves/SKILL.md +1 -0
- package/skills/spine-release-operator/SKILL.md +44 -8
- package/skills/spine-release-operator/references/pi-async-orchestration.md +88 -0
- package/skills/spine-release-operator/scripts/collect-release-intake.sh +71 -0
- package/src/batch/abort.mjs +1 -0
- package/src/batch/agent-session-worker.mjs +1 -0
- package/src/batch/attached-engine-handoff.mjs +1 -0
- package/src/batch/attached-runner.mjs +100 -2
- package/src/batch/contract-prelanded.mjs +1 -0
- package/src/batch/contract-task-start.mjs +1 -0
- package/src/batch/contract-verify.mjs +1 -0
- package/src/batch/detached-start.mjs +1 -0
- package/src/batch/diagnosis-launch-failure.mjs +1 -0
- package/src/batch/diagnosis-merge-failure.mjs +1 -0
- package/src/batch/diagnosis-retry-limbo.mjs +1 -0
- package/src/batch/diagnosis-tail-state.mjs +6 -0
- package/src/batch/diagnosis-task-done.mjs +1 -0
- package/src/batch/diagnosis-worker-done-missing.mjs +1 -0
- package/src/batch/diagnosis.mjs +4 -2
- package/src/batch/engine-lanes/commit.mjs +1 -0
- package/src/batch/engine-lanes/merge.mjs +1 -0
- package/src/batch/engine-lanes/queue.mjs +1 -0
- package/src/batch/engine-lanes/review.mjs +1 -0
- package/src/batch/engine-lanes.mjs +1 -0
- package/src/batch/engine-scope.mjs +1 -0
- package/src/batch/engine.mjs +19 -9
- package/src/batch/evidence.mjs +1 -0
- package/src/batch/gate-evidence-collect.mjs +1 -0
- package/src/batch/gate-evidence-read.mjs +1 -0
- package/src/batch/gate.mjs +1 -0
- package/src/batch/git-helpers.mjs +1 -1
- package/src/batch/heartbeat-git-debounce.mjs +83 -0
- package/src/batch/heartbeat.mjs +17 -20
- package/src/batch/integrate-worktree.mjs +1 -0
- package/src/batch/integrate.mjs +1 -0
- package/src/batch/journal-rebuild.mjs +118 -0
- package/src/batch/journal.mjs +2 -1
- package/src/batch/lane-commit.mjs +1 -0
- package/src/batch/lane-dirty-check.mjs +1 -0
- package/src/batch/lifecycle.mjs +1 -0
- package/src/batch/limbo-detect.mjs +1 -0
- package/src/batch/macro-phase.mjs +41 -2
- package/src/batch/merge/adoption-doc-merge.mjs +1 -0
- package/src/batch/merge/wave-merge-state.mjs +1 -0
- package/src/batch/metrics.mjs +1 -0
- package/src/batch/orphan-detect.mjs +106 -2
- package/src/batch/pause.mjs +1 -0
- package/src/batch/post-merge-limbo.mjs +1 -0
- package/src/batch/postmortem.mjs +1 -0
- package/src/batch/readers/spine-state.mjs +1 -0
- package/src/batch/readers/taskplane-state.mjs +1 -0
- package/src/batch/reconcile.mjs +236 -18
- package/src/batch/resume-common.mjs +1 -0
- package/src/batch/resume-engine.mjs +1 -0
- package/src/batch/resume-multi-lanes.mjs +1 -0
- package/src/batch/resume-multi-validate.mjs +1 -0
- package/src/batch/resume-multi.mjs +1 -0
- package/src/batch/resume-validation.mjs +1 -0
- package/src/batch/resume.mjs +1 -0
- package/src/batch/retry.mjs +1 -0
- package/src/batch/review-shared.mjs +1 -0
- package/src/batch/review-spawn.mjs +1 -0
- package/src/batch/review.mjs +1 -0
- package/src/batch/rules-manifest-drift.mjs +1 -0
- package/src/batch/salvage.mjs +1 -0
- package/src/batch/sequence.mjs +5 -2
- package/src/batch/state.mjs +1 -0
- package/src/batch/supervisor-spawn.mjs +1 -0
- package/src/batch/task-stall-budget.mjs +3 -4
- package/src/batch/worker-host.mjs +31 -25
- package/src/batch/worker-output.mjs +1 -0
- package/src/batch/worker-prompt.mjs +1 -0
- package/src/cli/journal-follow.mjs +1 -1
- package/src/config/agent-model-resolve.mjs +1 -0
- package/src/config/contract.mjs +1 -0
- package/src/config/cursor-rules/discover.mjs +1 -0
- package/src/config/cursor-rules/match-globs.mjs +1 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +1 -0
- package/src/config/cursor-rules/profile.mjs +1 -0
- package/src/config/cursor-rules/select.mjs +1 -0
- package/src/config/env-overrides.mjs +1 -0
- package/src/config/pi-spine-root.mjs +1 -0
- package/src/config/preflight/discovery.mjs +333 -0
- package/src/config/preflight/git-batch.mjs +320 -0
- package/src/config/preflight/integrate-plan.mjs +460 -0
- package/src/config/reviewer-context.mjs +1 -0
- package/src/config/settings-fields.mjs +1 -0
- package/src/config/spine-config-schema.mjs +1 -0
- package/src/config/spine-init-constants.mjs +1 -0
- package/src/config/spine-preflight-lib.mjs +54 -1013
- package/src/config/worker-backend.mjs +1 -0
- package/src/config/worker-context.mjs +1 -0
- package/src/config/worker-launch-script.mjs +1 -0
- package/src/config/worktree-setup-hook.mjs +1 -0
- package/src/dashboard/public/dashboard.js +6 -1
- package/src/dashboard/running-tail-state.mjs +1 -0
- package/src/dashboard/server.mjs +136 -16
- package/src/dashboard/snapshot-lanes.mjs +479 -0
- package/src/dashboard/snapshot-waves.mjs +299 -0
- package/src/dashboard/snapshot.mjs +45 -863
- package/src/doctor/agent-model-inherit.mjs +1 -0
- package/src/doctor/agent-models.mjs +1 -0
- package/src/doctor/attached-orphan-risk.mjs +114 -0
- package/src/doctor/coexistence.mjs +1 -0
- package/src/doctor/run-doctor-checks.mjs +3 -0
- package/src/doctor/stale-path.mjs +1 -0
- package/src/doctor/stall-config.mjs +1 -0
- package/src/doctor/suggest-max-parallel.mjs +1 -0
- package/src/doctor/task-packet-size.mjs +3 -10
- package/src/doctor/worktree-health.mjs +1 -0
- package/src/planner/cycles.mjs +1 -0
- package/src/planner/file-scope.mjs +1 -0
- package/src/planner/format-plan.mjs +1 -0
- package/src/planner/graph.mjs +1 -0
- package/src/planner/scope.mjs +1 -0
- package/src/planner/wave-scope.mjs +1 -0
- package/src/planner/waves.mjs +1 -0
- package/src/tasks/packet/merge-deps.mjs +1 -0
- package/src/tasks/packet/parse-prompt.mjs +4 -3
- package/src/tasks/packet/parse-status.mjs +1 -0
- package/src/tasks/packet/size-line.mjs +12 -0
- package/src/tasks/packet/validate-contract.mjs +9 -1
- package/src/tasks/packet/validate-prompt.mjs +2 -0
- package/src/tasks/validate-contract-warn.mjs +50 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* Attached batch foreground runner — milestones, integrate handoff, CLI exit (SP-343, GitHub #34).
|
|
3
4
|
* Post-merge limbo resume fast path (SP-348, GitHub #39).
|
|
@@ -12,11 +13,25 @@ import { detectPostMergeLimboForResume } from "./resume-multi-validate.mjs";
|
|
|
12
13
|
import { isProcessAlive } from "../process/liveness.mjs";
|
|
13
14
|
import { terminateStaleDetachedEngine } from "./resume-engine.mjs";
|
|
14
15
|
import { reconcileBatch } from "./reconcile.mjs";
|
|
15
|
-
import { readJournalEventsCached } from "./journal.mjs";
|
|
16
|
+
import { readJournalEventsCached, readJournalEvents, appendJournalEvent } from "./journal.mjs";
|
|
16
17
|
import { enforceOperatorPauseOnDisk } from "./pause.mjs";
|
|
17
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
loadSpineBatchState,
|
|
20
|
+
readBatchEnginePid,
|
|
21
|
+
saveSpineBatchState,
|
|
22
|
+
updateSegmentForTask,
|
|
23
|
+
recomputeTaskCounters,
|
|
24
|
+
clearBatchEnginePid,
|
|
25
|
+
} from "./state.mjs";
|
|
18
26
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
19
27
|
import { resolveAttachedMilestonePollMs } from "../config/spine-config-schema.mjs";
|
|
28
|
+
import {
|
|
29
|
+
journalHasContractVerified,
|
|
30
|
+
journalIndicatesPausedForceResume,
|
|
31
|
+
} from "./orphan-detect.mjs";
|
|
32
|
+
import { classifyTaskDoneSemantics } from "./diagnosis-task-done.mjs";
|
|
33
|
+
import { resolveTasksRoot } from "../config/spine-preflight-lib.mjs";
|
|
34
|
+
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
20
35
|
|
|
21
36
|
export { DEFAULT_ATTACHED_MILESTONE_POLL_MS } from "../config/spine-config-schema.mjs";
|
|
22
37
|
|
|
@@ -214,6 +229,81 @@ export function enforceAttachedEngineSingleOwner({ projectRoot, force = false, o
|
|
|
214
229
|
};
|
|
215
230
|
}
|
|
216
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Promote running cache tasks with lane `.DONE` and contract verify after paused force resume (SP-513 / #184).
|
|
234
|
+
*
|
|
235
|
+
* @param {object} params
|
|
236
|
+
* @param {string} params.projectRoot
|
|
237
|
+
* @param {object} params.state
|
|
238
|
+
* @param {string} params.batchId
|
|
239
|
+
* @returns {{ reconciled: boolean, taskIds?: string[] }}
|
|
240
|
+
*/
|
|
241
|
+
export function reconcilePausedResumeDoneInLane({ projectRoot, state, batchId }) {
|
|
242
|
+
if (!state || typeof state !== "object" || !batchId) {
|
|
243
|
+
return { reconciled: false };
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const journalEvents = readJournalEvents(projectRoot, batchId);
|
|
247
|
+
if (!journalIndicatesPausedForceResume(journalEvents)) {
|
|
248
|
+
return { reconciled: false };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
252
|
+
const tasksRoot = resolveTasksRoot(projectRoot, configResult);
|
|
253
|
+
const lanes = state.lanes ?? [];
|
|
254
|
+
/** @type {string[]} */
|
|
255
|
+
const promotedTaskIds = [];
|
|
256
|
+
let changed = false;
|
|
257
|
+
|
|
258
|
+
for (const task of state.tasks ?? []) {
|
|
259
|
+
const status = String(task?.status ?? "").toLowerCase();
|
|
260
|
+
if (status !== "running" && status !== "pending") continue;
|
|
261
|
+
|
|
262
|
+
const classified = classifyTaskDoneSemantics(task, {
|
|
263
|
+
tasksRoot,
|
|
264
|
+
projectRoot,
|
|
265
|
+
batchId,
|
|
266
|
+
lanes,
|
|
267
|
+
});
|
|
268
|
+
if (classified.doneInLane !== true) continue;
|
|
269
|
+
if (!journalHasContractVerified(journalEvents, task.taskId)) continue;
|
|
270
|
+
|
|
271
|
+
task.status = "succeeded";
|
|
272
|
+
task.doneFileFound = true;
|
|
273
|
+
task.exitReason = task.exitReason ?? "done";
|
|
274
|
+
if (!task.endedAt) task.endedAt = Date.now();
|
|
275
|
+
updateSegmentForTask(state, task.taskId, "succeeded");
|
|
276
|
+
promotedTaskIds.push(task.taskId);
|
|
277
|
+
changed = true;
|
|
278
|
+
|
|
279
|
+
if (!journalHasTaskCompleted(journalEvents, task.taskId)) {
|
|
280
|
+
const laneNumber = Number(task.laneNumber ?? 1);
|
|
281
|
+
const lane = lanes.find((entry) => Number(entry?.laneNumber) === laneNumber);
|
|
282
|
+
appendJournalEvent(projectRoot, batchId, "task.completed", {
|
|
283
|
+
taskId: task.taskId,
|
|
284
|
+
laneNumber,
|
|
285
|
+
laneId: lane?.laneId ?? `lane-${laneNumber}`,
|
|
286
|
+
resumed: true,
|
|
287
|
+
skippedDoneOnDisk: true,
|
|
288
|
+
reconciled: true,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!changed) {
|
|
294
|
+
return { reconciled: false };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const enginePid = readBatchEnginePid(state);
|
|
298
|
+
if (enginePid != null && !isProcessAlive(enginePid)) {
|
|
299
|
+
clearBatchEnginePid(state);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
recomputeTaskCounters(state);
|
|
303
|
+
saveSpineBatchState(projectRoot, state);
|
|
304
|
+
return { reconciled: true, taskIds: promotedTaskIds };
|
|
305
|
+
}
|
|
306
|
+
|
|
217
307
|
/**
|
|
218
308
|
* Run an attached foreground engine while streaming land-loop journal milestones to stdout.
|
|
219
309
|
*
|
|
@@ -278,6 +368,14 @@ function resolveAttachedBatchExitCode(result, reconciliation) {
|
|
|
278
368
|
* @param {boolean} [params.json]
|
|
279
369
|
*/
|
|
280
370
|
export function formatAttachedBatchCliResult({ projectRoot, operation, result, json = false }) {
|
|
371
|
+
const loaded = loadSpineBatchState(projectRoot);
|
|
372
|
+
if (loaded.raw?.batchId) {
|
|
373
|
+
reconcilePausedResumeDoneInLane({
|
|
374
|
+
projectRoot,
|
|
375
|
+
state: loaded.raw,
|
|
376
|
+
batchId: String(loaded.raw.batchId),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
281
379
|
const reconciliation = reconcileBatch({ projectRoot });
|
|
282
380
|
const mergeBlocked = reconciliation.phase === "merge_blocked";
|
|
283
381
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* Running diagnosis headlines when batch phase is active but no workers are scheduled (GitHub #68).
|
|
3
4
|
*/
|
|
@@ -44,6 +45,11 @@ export function buildRunningTailHeadline(batchLabel, ctx = {}) {
|
|
|
44
45
|
return `${batchLabel} planning — no workers scheduled`;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
// Macro Failed must not surface in running tail — drift/orphan may still be recoverable (#165).
|
|
49
|
+
if (macroPhase === "failed") {
|
|
50
|
+
return `${batchLabel} finalizing batch — no active workers`;
|
|
51
|
+
}
|
|
52
|
+
|
|
47
53
|
if (macroPhase != null && macroPhase !== "executing") {
|
|
48
54
|
const label = macroPhaseLabel(macroPhase);
|
|
49
55
|
return `${batchLabel} ${label.toLowerCase()} — finalizing batch`;
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* FR-BATCH-13 diagnosis taxonomy and operator messaging (§18.3).
|
|
3
4
|
*/
|
|
@@ -168,8 +169,9 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
168
169
|
return "spine batch dismiss";
|
|
169
170
|
case "state_drift":
|
|
170
171
|
if (ctx.failedTaskId) {
|
|
171
|
-
|
|
172
|
-
|
|
172
|
+
const driftStatus = String(ctx.driftTaskStatus ?? "").toLowerCase();
|
|
173
|
+
if (driftStatus === "running" || ctx.phase === "running") {
|
|
174
|
+
return "spine batch resume --force";
|
|
173
175
|
}
|
|
174
176
|
return `spine batch retry ${ctx.failedTaskId}`;
|
|
175
177
|
}
|
package/src/batch/engine.mjs
CHANGED
|
@@ -72,6 +72,16 @@ export {
|
|
|
72
72
|
} from "./engine-scope.mjs";
|
|
73
73
|
export { loadTaskFileScopePaths, mergeLaneToOrch } from "./engine-lanes.mjs";
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Mutable batch-state fields are widened from createInitialBatchState literals so
|
|
77
|
+
* terminal transitions can assign endedAt/lastError without any casts.
|
|
78
|
+
*
|
|
79
|
+
* @typedef {Omit<ReturnType<typeof createInitialBatchState>, "endedAt" | "lastError"> & {
|
|
80
|
+
* endedAt: number | null;
|
|
81
|
+
* lastError: string | null;
|
|
82
|
+
* }} SpineBatchState
|
|
83
|
+
*/
|
|
84
|
+
|
|
75
85
|
const WORKTREE_SPINE_PATTERN = /[/\\]\.worktrees[/\\]spine-/;
|
|
76
86
|
|
|
77
87
|
/**
|
|
@@ -149,7 +159,7 @@ export async function startBatch({
|
|
|
149
159
|
ok: false,
|
|
150
160
|
exitCode: preflight.exitCode ?? 1,
|
|
151
161
|
error: "preflight_failed",
|
|
152
|
-
output: /** @type {
|
|
162
|
+
output: /** @type {{ output?: string }} */ (preflight).output,
|
|
153
163
|
};
|
|
154
164
|
}
|
|
155
165
|
}
|
|
@@ -241,8 +251,8 @@ export async function startBatch({
|
|
|
241
251
|
maxLaneNumber,
|
|
242
252
|
});
|
|
243
253
|
|
|
244
|
-
/** @type {
|
|
245
|
-
|
|
254
|
+
/** @type {SpineBatchState} */
|
|
255
|
+
const state = createInitialBatchState({
|
|
246
256
|
batchId,
|
|
247
257
|
baseBranch,
|
|
248
258
|
orchBranch,
|
|
@@ -425,8 +435,8 @@ export async function startBatch({
|
|
|
425
435
|
|
|
426
436
|
if (batchAborted) {
|
|
427
437
|
const abortedTask = state.tasks.find((/** @type {{ status: string }} */ task) => task.status === "aborted");
|
|
428
|
-
|
|
429
|
-
|
|
438
|
+
state.endedAt = Date.now();
|
|
439
|
+
state.lastError = "batch aborted";
|
|
430
440
|
transitionPhase(state, "aborted", {
|
|
431
441
|
projectRoot,
|
|
432
442
|
batchId,
|
|
@@ -444,8 +454,8 @@ export async function startBatch({
|
|
|
444
454
|
|
|
445
455
|
const mergeEligibility = assessWaveMergeEligibility(state, wave.index);
|
|
446
456
|
if (!mergeEligibility.ok) {
|
|
447
|
-
|
|
448
|
-
|
|
457
|
+
state.endedAt = Date.now();
|
|
458
|
+
state.lastError = mergeEligibility.message?.slice(0, 500) ?? "mixed_outcome";
|
|
449
459
|
transitionPhase(state, "failed", {
|
|
450
460
|
projectRoot,
|
|
451
461
|
batchId,
|
|
@@ -531,8 +541,8 @@ export async function startBatch({
|
|
|
531
541
|
});
|
|
532
542
|
} catch (err) {
|
|
533
543
|
const message = err instanceof Error ? err.message : String(err);
|
|
534
|
-
|
|
535
|
-
|
|
544
|
+
state.endedAt = Date.now();
|
|
545
|
+
state.lastError = message;
|
|
536
546
|
transitionPhase(state, "failed", {
|
|
537
547
|
projectRoot,
|
|
538
548
|
batchId,
|
package/src/batch/evidence.mjs
CHANGED
package/src/batch/gate.mjs
CHANGED
|
@@ -17,7 +17,7 @@ export function filterGitignoredPaths(projectRoot, paths) {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/** @type {Set<string>} */
|
|
20
|
-
|
|
20
|
+
const ignoredSet = new Set();
|
|
21
21
|
try {
|
|
22
22
|
const output = execFileSync("git", ["check-ignore", "--no-index", "--stdin"], {
|
|
23
23
|
cwd: projectRoot,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* Git porcelain debounce for lane heartbeat progress signals (issue #98 P1).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Per-lane file-scope mtime snapshot; reused when mtimes are unchanged.
|
|
11
|
+
* @type {Map<string, { fileScopeMtimeMs: number | null, dirtyPaths: string[] }>}
|
|
12
|
+
*/
|
|
13
|
+
const _gitPorcelainDebounceByLane = new Map();
|
|
14
|
+
|
|
15
|
+
let _gitPorcelainCallCount = 0;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {string} worktreePath
|
|
19
|
+
* @param {string[]} [fileScopePaths]
|
|
20
|
+
*/
|
|
21
|
+
function gitPorcelainDebounceKey(worktreePath, fileScopePaths) {
|
|
22
|
+
const scopeKey = Array.isArray(fileScopePaths) ? fileScopePaths.join("\0") : "";
|
|
23
|
+
return `${worktreePath}\0${scopeKey}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Clear git porcelain debounce cache. Useful for test isolation. */
|
|
27
|
+
export function clearGitPorcelainDebounceCache() {
|
|
28
|
+
_gitPorcelainDebounceByLane.clear();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Reset git porcelain invocation counter (tests only). */
|
|
32
|
+
export function resetGitPorcelainCallCount() {
|
|
33
|
+
_gitPorcelainCallCount = 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @returns {number} git status --porcelain invocations since last reset. */
|
|
37
|
+
export function getGitPorcelainCallCount() {
|
|
38
|
+
return _gitPorcelainCallCount;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Max mtime among existing file-scope paths (FR-WORK-10 activity signal).
|
|
43
|
+
* @param {string} worktreePath
|
|
44
|
+
* @param {string[]} [fileScopePaths]
|
|
45
|
+
*/
|
|
46
|
+
export function resolveFileScopeMtimeMs(worktreePath, fileScopePaths) {
|
|
47
|
+
if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return null;
|
|
48
|
+
let max = null;
|
|
49
|
+
for (const rel of fileScopePaths) {
|
|
50
|
+
if (!rel || typeof rel !== "string") continue;
|
|
51
|
+
const target = path.join(worktreePath, rel);
|
|
52
|
+
if (!fs.existsSync(target)) continue;
|
|
53
|
+
const stat = fs.statSync(target);
|
|
54
|
+
if (!stat.isFile()) continue;
|
|
55
|
+
max = max === null ? stat.mtimeMs : Math.max(max, stat.mtimeMs);
|
|
56
|
+
}
|
|
57
|
+
return max;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Debounced wrapper around fresh scoped porcelain resolution.
|
|
62
|
+
* @param {string} worktreePath
|
|
63
|
+
* @param {string[]} [fileScopePaths]
|
|
64
|
+
* @param {string} [taskFolder]
|
|
65
|
+
* @param {(worktreePath: string, fileScopePaths?: string[], taskFolder?: string) => string[]} resolveFresh
|
|
66
|
+
*/
|
|
67
|
+
export function resolveDebouncedScopedDirtyPaths(
|
|
68
|
+
worktreePath,
|
|
69
|
+
fileScopePaths,
|
|
70
|
+
taskFolder,
|
|
71
|
+
resolveFresh,
|
|
72
|
+
) {
|
|
73
|
+
const fileScopeMtimeMs = resolveFileScopeMtimeMs(worktreePath, fileScopePaths);
|
|
74
|
+
const debounceKey = gitPorcelainDebounceKey(worktreePath, fileScopePaths);
|
|
75
|
+
const debounced = _gitPorcelainDebounceByLane.get(debounceKey);
|
|
76
|
+
if (debounced && debounced.fileScopeMtimeMs === fileScopeMtimeMs) {
|
|
77
|
+
return debounced.dirtyPaths;
|
|
78
|
+
}
|
|
79
|
+
_gitPorcelainCallCount += 1;
|
|
80
|
+
const dirtyPaths = resolveFresh(worktreePath, fileScopePaths, taskFolder);
|
|
81
|
+
_gitPorcelainDebounceByLane.set(debounceKey, { fileScopeMtimeMs, dirtyPaths });
|
|
82
|
+
return dirtyPaths;
|
|
83
|
+
}
|
package/src/batch/heartbeat.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* Lane heartbeat and progress-aware stall helpers (FR-WORK-09, PRD §18.4, FR-STALL-02).
|
|
3
4
|
*/
|
|
@@ -6,6 +7,16 @@ import fs from "node:fs";
|
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
import { execFileSync } from "node:child_process";
|
|
8
9
|
import { appendJournalEvent, readJournalEventsCached } from "./journal.mjs";
|
|
10
|
+
import {
|
|
11
|
+
resolveDebouncedScopedDirtyPaths,
|
|
12
|
+
resolveFileScopeMtimeMs,
|
|
13
|
+
} from "./heartbeat-git-debounce.mjs";
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
clearGitPorcelainDebounceCache,
|
|
17
|
+
getGitPorcelainCallCount,
|
|
18
|
+
resetGitPorcelainCallCount,
|
|
19
|
+
} from "./heartbeat-git-debounce.mjs";
|
|
9
20
|
|
|
10
21
|
const DEFAULT_STALL_TIMEOUT_MIN = 60;
|
|
11
22
|
const DEFAULT_GRACE_AFTER_PROGRESS_MIN = 15;
|
|
@@ -76,25 +87,6 @@ function git(worktreePath, args) {
|
|
|
76
87
|
}
|
|
77
88
|
}
|
|
78
89
|
|
|
79
|
-
/**
|
|
80
|
-
* Max mtime among existing file-scope paths (FR-WORK-10 activity signal; warning only by default).
|
|
81
|
-
* @param {string} worktreePath
|
|
82
|
-
* @param {string[]} [fileScopePaths]
|
|
83
|
-
*/
|
|
84
|
-
function resolveFileScopeMtimeMs(worktreePath, fileScopePaths) {
|
|
85
|
-
if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return null;
|
|
86
|
-
let max = null;
|
|
87
|
-
for (const rel of fileScopePaths) {
|
|
88
|
-
if (!rel || typeof rel !== "string") continue;
|
|
89
|
-
const target = path.join(worktreePath, rel);
|
|
90
|
-
if (!fs.existsSync(target)) continue;
|
|
91
|
-
const stat = fs.statSync(target);
|
|
92
|
-
if (!stat.isFile()) continue;
|
|
93
|
-
max = max === null ? stat.mtimeMs : Math.max(max, stat.mtimeMs);
|
|
94
|
-
}
|
|
95
|
-
return max;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
90
|
/**
|
|
99
91
|
* Scoped git porcelain paths under File Scope or the task folder (FR-STALL-02 activity).
|
|
100
92
|
* @param {string} worktreePath
|
|
@@ -196,7 +188,12 @@ export function collectProgressSignals({
|
|
|
196
188
|
}
|
|
197
189
|
|
|
198
190
|
const fileScopeMtimeMs = resolveFileScopeMtimeMs(worktreePath, fileScopePaths);
|
|
199
|
-
const dirtyPaths =
|
|
191
|
+
const dirtyPaths = resolveDebouncedScopedDirtyPaths(
|
|
192
|
+
worktreePath,
|
|
193
|
+
fileScopePaths,
|
|
194
|
+
taskFolder,
|
|
195
|
+
resolveScopedDirtyPaths,
|
|
196
|
+
);
|
|
200
197
|
|
|
201
198
|
let stepCompletedAtMs = null;
|
|
202
199
|
if (journalContext?.projectRoot && journalContext?.batchId) {
|
package/src/batch/integrate.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* Rebuild batch task/segment status from append-only journal (FR-REL-01/02, PRD §11.4).
|
|
3
4
|
*/
|
|
@@ -5,10 +6,13 @@
|
|
|
5
6
|
import fs from "node:fs";
|
|
6
7
|
import { appendJournalEvent, readJournalEvents, STRUCTURAL_JOURNAL_EVENT_TYPES } from "./journal.mjs";
|
|
7
8
|
import { parseReviewVerdict } from "./review-shared.mjs";
|
|
9
|
+
import { journalHasTaskCompleted } from "./resume-common.mjs";
|
|
8
10
|
import {
|
|
9
11
|
clearTaskFailureMetadata,
|
|
10
12
|
createInitialBatchState,
|
|
13
|
+
recordTaskSucceeded,
|
|
11
14
|
recomputeTaskCounters,
|
|
15
|
+
saveSpineBatchState,
|
|
12
16
|
updateSegmentForTask,
|
|
13
17
|
} from "./state.mjs";
|
|
14
18
|
|
|
@@ -541,3 +545,117 @@ export function detectBatchStateDrift(cachedState, rebuiltState, events = [], cl
|
|
|
541
545
|
|
|
542
546
|
return { drifted: entries.length > 0, entries };
|
|
543
547
|
}
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Journal evidence that lane work finished and review/contract passed (FR-STA-01 / #170).
|
|
551
|
+
*
|
|
552
|
+
* @param {object[]} events
|
|
553
|
+
* @param {string} taskId
|
|
554
|
+
*/
|
|
555
|
+
export function journalShowsDoneInLaneTerminalArtifacts(events, taskId) {
|
|
556
|
+
let hasApprovedReview = false;
|
|
557
|
+
let hasLaneCompleted = false;
|
|
558
|
+
let hasContractVerified = false;
|
|
559
|
+
|
|
560
|
+
for (const event of events ?? []) {
|
|
561
|
+
const type = String(event?.type ?? "");
|
|
562
|
+
const payload = event.payload && typeof event.payload === "object" ? event.payload : {};
|
|
563
|
+
const eventTaskId = event.taskId ?? payload.taskId;
|
|
564
|
+
if (eventTaskId !== taskId) continue;
|
|
565
|
+
|
|
566
|
+
if (type === "review.completed" && APPROVED_VERDICTS.has(String(payload.verdict ?? ""))) {
|
|
567
|
+
hasApprovedReview = true;
|
|
568
|
+
}
|
|
569
|
+
if (type === "task.verdict_recorded" && APPROVED_VERDICTS.has(String(payload.verdict ?? ""))) {
|
|
570
|
+
hasApprovedReview = true;
|
|
571
|
+
}
|
|
572
|
+
if (type === "lane.completed") {
|
|
573
|
+
hasLaneCompleted = true;
|
|
574
|
+
}
|
|
575
|
+
if (type === "contract.verified" && payload.ok === true) {
|
|
576
|
+
hasContractVerified = true;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
return hasLaneCompleted && (hasApprovedReview || hasContractVerified);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Promote batch-state tasks when lane on-disk truth and journal show terminal success
|
|
585
|
+
* but cache still shows pending/running (idempotent; FR-STA-01 / SP-512).
|
|
586
|
+
*
|
|
587
|
+
* @param {object} params
|
|
588
|
+
* @param {string} params.projectRoot
|
|
589
|
+
* @param {object} params.state
|
|
590
|
+
* @param {object[]} [params.classifiedTasks]
|
|
591
|
+
* @param {object[]} [params.journalEvents]
|
|
592
|
+
* @param {{ drifted?: boolean, entries?: Array<{ taskId: string, field: string, rebuilt?: unknown }> }} [params.drift]
|
|
593
|
+
* @returns {{ reconciled: boolean, taskIds: string[] }}
|
|
594
|
+
*/
|
|
595
|
+
export function reconcileBatchStateDrift({
|
|
596
|
+
projectRoot,
|
|
597
|
+
state,
|
|
598
|
+
classifiedTasks = [],
|
|
599
|
+
journalEvents = [],
|
|
600
|
+
drift = null,
|
|
601
|
+
}) {
|
|
602
|
+
if (!state || typeof state !== "object" || !drift?.drifted || !Array.isArray(drift.entries)) {
|
|
603
|
+
return { reconciled: false, taskIds: [] };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
const batchId = String(state.batchId ?? "");
|
|
607
|
+
if (!batchId) {
|
|
608
|
+
return { reconciled: false, taskIds: [] };
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const classifiedById = new Map(
|
|
612
|
+
(classifiedTasks ?? []).map((task) => [String(task?.taskId ?? ""), task]),
|
|
613
|
+
);
|
|
614
|
+
/** @type {string[]} */
|
|
615
|
+
const reconciledTaskIds = [];
|
|
616
|
+
let changed = false;
|
|
617
|
+
|
|
618
|
+
for (const entry of drift.entries) {
|
|
619
|
+
const taskId = String(entry?.taskId ?? "");
|
|
620
|
+
if (!taskId || taskId === "*") continue;
|
|
621
|
+
|
|
622
|
+
const task = (state.tasks ?? []).find((row) => row?.taskId === taskId);
|
|
623
|
+
if (!task) continue;
|
|
624
|
+
|
|
625
|
+
if (entry.field === "status" && String(entry.rebuilt ?? "") === "succeeded") {
|
|
626
|
+
if (String(task.status ?? "") === "succeeded") continue;
|
|
627
|
+
if (!recordTaskSucceeded(state, taskId, { doneFileFound: true, exitReason: "done" })) continue;
|
|
628
|
+
reconciledTaskIds.push(taskId);
|
|
629
|
+
changed = true;
|
|
630
|
+
continue;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
if (entry.field !== "doneInLane") continue;
|
|
634
|
+
|
|
635
|
+
const classified = classifiedById.get(taskId);
|
|
636
|
+
if (!classifiedShowsDoneInLaneDrift(classified)) continue;
|
|
637
|
+
if (classified?.doneInLane !== true) continue;
|
|
638
|
+
if (journalHasTaskCompleted(journalEvents, taskId)) continue;
|
|
639
|
+
if (!journalShowsDoneInLaneTerminalArtifacts(journalEvents, taskId)) continue;
|
|
640
|
+
if (String(task.status ?? "") === "succeeded") continue;
|
|
641
|
+
|
|
642
|
+
if (!recordTaskSucceeded(state, taskId, { doneFileFound: true, exitReason: "done" })) continue;
|
|
643
|
+
|
|
644
|
+
appendJournalEvent(projectRoot, batchId, "task.completed", {
|
|
645
|
+
taskId,
|
|
646
|
+
laneNumber: task.laneNumber ?? null,
|
|
647
|
+
reconciled: true,
|
|
648
|
+
reconcileReason: "done_in_lane_terminal",
|
|
649
|
+
skippedDoneOnDisk: true,
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
reconciledTaskIds.push(taskId);
|
|
653
|
+
changed = true;
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (changed) {
|
|
657
|
+
saveSpineBatchState(projectRoot, state);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
return { reconciled: changed, taskIds: reconciledTaskIds };
|
|
661
|
+
}
|
package/src/batch/journal.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
/**
|
|
2
3
|
* Append-only orchestration journal (FR-JRN, PRD §11).
|
|
3
4
|
*/
|
|
@@ -83,7 +84,7 @@ export function redactSecrets(value) {
|
|
|
83
84
|
* @param {Record<string, unknown>} payload
|
|
84
85
|
*/
|
|
85
86
|
export function capPayloadSize(payload) {
|
|
86
|
-
|
|
87
|
+
const serialized = JSON.stringify(payload);
|
|
87
88
|
if (Buffer.byteLength(serialized, "utf-8") <= MAX_PAYLOAD_BYTES) {
|
|
88
89
|
return payload;
|
|
89
90
|
}
|