pi-spine 2.2.0 → 2.3.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 (56) hide show
  1. package/bin/spine-cli/verify.mjs +15 -46
  2. package/package.json +1 -1
  3. package/src/batch/attached-runner-promote.mjs +370 -0
  4. package/src/batch/attached-runner-reconcile.mjs +291 -0
  5. package/src/batch/attached-runner.mjs +24 -645
  6. package/src/batch/batch-guards.mjs +69 -0
  7. package/src/batch/contract-exec.mjs +483 -0
  8. package/src/batch/contract-parse.mjs +243 -0
  9. package/src/batch/contract-verify.mjs +32 -707
  10. package/src/batch/detached-diagnostics.mjs +255 -0
  11. package/src/batch/detached-run.mjs +326 -0
  12. package/src/batch/detached-start.mjs +18 -894
  13. package/src/batch/detached-wait.mjs +346 -0
  14. package/src/batch/diagnosis.mjs +35 -4
  15. package/src/batch/engine-lanes/orch-sync.mjs +126 -0
  16. package/src/batch/engine-lanes.mjs +69 -0
  17. package/src/batch/engine.mjs +8 -67
  18. package/src/batch/integrate-git.mjs +21 -0
  19. package/src/batch/integrate.mjs +5 -15
  20. package/src/batch/journal-rebuild-structural.mjs +352 -0
  21. package/src/batch/journal-rebuild.mjs +16 -348
  22. package/src/batch/lane-dirty-check-commit.mjs +361 -0
  23. package/src/batch/lane-dirty-check-git.mjs +298 -0
  24. package/src/batch/lane-dirty-check.mjs +31 -297
  25. package/src/batch/reconcile-batch.mjs +495 -0
  26. package/src/batch/reconcile-classify.mjs +433 -0
  27. package/src/batch/reconcile-diagnosis.mjs +459 -0
  28. package/src/batch/reconcile-light-cache.mjs +61 -0
  29. package/src/batch/reconcile-orphan.mjs +198 -0
  30. package/src/batch/reconcile.mjs +19 -1693
  31. package/src/batch/resume-multi-lanes.mjs +6 -148
  32. package/src/batch/resume-multi-queue.mjs +159 -0
  33. package/src/batch/resume-single-validate.mjs +25 -0
  34. package/src/batch/resume.mjs +3 -20
  35. package/src/batch/review-artifacts.mjs +419 -0
  36. package/src/batch/review-step-run.mjs +383 -0
  37. package/src/batch/review-step.mjs +451 -0
  38. package/src/batch/review.mjs +32 -1199
  39. package/src/batch/salvage-batch-list.mjs +291 -0
  40. package/src/batch/salvage-batch.mjs +10 -284
  41. package/src/batch/sequence-plan.mjs +234 -0
  42. package/src/batch/sequence-run.mjs +418 -0
  43. package/src/batch/sequence-wait.mjs +167 -0
  44. package/src/batch/sequence.mjs +22 -783
  45. package/src/batch/state-guards.mjs +284 -0
  46. package/src/batch/state-io.mjs +135 -0
  47. package/src/batch/state.mjs +27 -396
  48. package/src/batch/worker-heartbeat.mjs +382 -0
  49. package/src/batch/worker-host.mjs +56 -548
  50. package/src/batch/worker-spawn.mjs +326 -0
  51. package/src/batch/worktree.mjs +68 -0
  52. package/src/config/preflight/integrate-plan.mjs +6 -1
  53. package/src/config/preflight/loc-capstone.mjs +274 -0
  54. package/src/config/spine-preflight-lib.mjs +14 -0
  55. package/src/planner/index.mjs +14 -3
  56. package/src/process/terminate-tree.mjs +154 -0
@@ -1,18 +1,15 @@
1
1
  // @ts-nocheck
2
2
  /**
3
- * Per-lane task execution and wave queue wiring for multi-task resume (extracted from resume-multi.mjs).
3
+ * Per-lane task execution for multi-task resume (extracted from resume-multi.mjs).
4
+ * Queue wiring lives in resume-multi-queue.mjs (SP-590); re-exported below.
4
5
  */
5
6
 
6
7
  import path from "node:path";
7
- import crypto from "node:crypto";
8
8
  import fs from "node:fs";
9
9
  import {
10
10
  journalHasTaskCompleted,
11
11
  loadResumeFileScopePaths,
12
12
  recomputeTaskCounters,
13
- resolveTaskFolderInWorktree,
14
- taskAlreadyComplete,
15
- taskTerminalSuccessInBatch,
16
13
  } from "./resume-common.mjs";
17
14
  import { appendJournalEvent, readJournalEvents } from "./journal.mjs";
18
15
  import { commitLaneWorktree, filterPorcelain, gitPorcelain } from "./lane-commit.mjs";
@@ -21,9 +18,10 @@ import { saveSpineBatchState, updateSegmentForTask } from "./state.mjs";
21
18
  import { laneTaskBranch } from "./worktree.mjs";
22
19
  import { laneDoneMarkerCommittedOnBranch } from "./journal-rebuild.mjs";
23
20
  import { runWorker } from "./worker-host.mjs";
24
- import { isTaskResumable } from "./resume-multi-validate.mjs";
25
21
  import { runLaneReviewPhasesBeforeCommit } from "./resume-lane-reviews.mjs";
26
22
 
23
+ export { executeResumeWave } from "./resume-multi-queue.mjs";
24
+
27
25
  /**
28
26
  * @param {object} params
29
27
  */
@@ -46,7 +44,7 @@ export function resetFailedTasksForForceResume({ state, pendingTasks }) {
46
44
  /**
47
45
  * @param {object} params
48
46
  */
49
- async function markTaskCompleteFromDisk({
47
+ export async function markTaskCompleteFromDisk({
50
48
  projectRoot,
51
49
  state,
52
50
  batchId,
@@ -224,7 +222,7 @@ async function markTaskCompleteFromDisk({
224
222
  /**
225
223
  * @param {object} params
226
224
  */
227
- async function runResumedTaskOnLane({
225
+ export async function runResumedTaskOnLane({
228
226
  projectRoot,
229
227
  state,
230
228
  batchId,
@@ -441,143 +439,3 @@ async function runResumedTaskOnLane({
441
439
 
442
440
  return { ok: true, taskId, laneNumber };
443
441
  }
444
-
445
- /**
446
- * Build lane queues and run all tasks in a resume wave.
447
- *
448
- * @param {object} params
449
- * @returns {Promise<{ ok: true, waveResults: object[], batchAborted: boolean } | { ok: false, result: object }>}
450
- */
451
- export async function executeResumeWave({
452
- projectRoot,
453
- state,
454
- batchId,
455
- config,
456
- tasksRootRel,
457
- waveIndex,
458
- waveTaskIds,
459
- events,
460
- }) {
461
- /** @type {Map<number, { lane: object, runs: Array<{ taskId: string, run: () => Promise<object> }> }>} */
462
- const runsByLane = new Map();
463
- let batchAborted = false;
464
-
465
- for (const taskId of waveTaskIds) {
466
- const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
467
- if (!task) continue;
468
-
469
- const laneNumber = task.laneNumber;
470
- const lane = (state.lanes ?? []).find((entry) => entry.laneNumber === laneNumber);
471
- if (!lane) {
472
- return {
473
- ok: false,
474
- result: {
475
- ok: false,
476
- exitCode: 1,
477
- batchId,
478
- taskId,
479
- error: "lane_not_found",
480
- output: `No lane assigned for task ${taskId} (lane ${laneNumber}).\n`,
481
- },
482
- };
483
- }
484
-
485
- const taskFolderRel = task.taskFolder
486
- ? path.isAbsolute(task.taskFolder)
487
- ? path.relative(projectRoot, task.taskFolder)
488
- : task.taskFolder
489
- : path.join(tasksRootRel, `${taskId}-smoke`);
490
- const taskFolderInWorktree = resolveTaskFolderInWorktree({
491
- projectRoot,
492
- task,
493
- lane,
494
- tasksRootRel,
495
- batchId,
496
- });
497
- const laneCorrelationId = lane.correlationId ?? crypto.randomUUID();
498
- lane.correlationId = laneCorrelationId;
499
-
500
- if (!runsByLane.has(laneNumber)) {
501
- runsByLane.set(laneNumber, { lane, runs: [] });
502
- }
503
- const laneQueue = runsByLane.get(laneNumber);
504
-
505
- if (
506
- taskTerminalSuccessInBatch({
507
- events,
508
- task,
509
- taskFolder: taskFolderInWorktree,
510
- })
511
- ) {
512
- continue;
513
- }
514
-
515
- if (taskAlreadyComplete({ taskFolder: taskFolderInWorktree, events, task })) {
516
- laneQueue.runs.push({
517
- taskId,
518
- run: () =>
519
- markTaskCompleteFromDisk({
520
- projectRoot,
521
- state,
522
- batchId,
523
- config,
524
- task,
525
- lane,
526
- taskBranch: lane.branch ?? laneTaskBranch(batchId, laneNumber),
527
- taskFolderInWorktree,
528
- laneCorrelationId,
529
- }),
530
- });
531
- continue;
532
- }
533
-
534
- if (!isTaskResumable(state, task)) {
535
- continue;
536
- }
537
-
538
- laneQueue.runs.push({
539
- taskId,
540
- run: () =>
541
- runResumedTaskOnLane({
542
- projectRoot,
543
- state,
544
- batchId,
545
- config,
546
- task,
547
- lane,
548
- taskFolderRel,
549
- laneCorrelationId,
550
- }).then((result) => {
551
- if (result.aborted) batchAborted = true;
552
- return result;
553
- }),
554
- });
555
- }
556
-
557
- const laneExecutions = [...runsByLane.entries()].map(async ([laneNumber, { lane, runs }]) => {
558
- if (runs.length > 1) {
559
- appendJournalEvent(projectRoot, batchId, "lane.tasks_serialized", {
560
- laneNumber,
561
- laneId: lane.laneId,
562
- waveIndex,
563
- taskIds: runs.map((entry) => entry.taskId),
564
- correlationId: lane.correlationId ?? null,
565
- });
566
- }
567
-
568
- /** @type {object[]} */
569
- const laneResults = [];
570
- for (const { run } of runs) {
571
- const result = await run();
572
- laneResults.push(result);
573
- if (result.aborted) {
574
- batchAborted = true;
575
- return laneResults;
576
- }
577
- }
578
- return laneResults;
579
- });
580
-
581
- const waveResults = (await Promise.all(laneExecutions)).flat();
582
- return { ok: true, waveResults, batchAborted };
583
- }
@@ -0,0 +1,159 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Per-lane queue wiring for multi-task resume waves (extracted from resume-multi-lanes.mjs).
4
+ */
5
+
6
+ import path from "node:path";
7
+ import crypto from "node:crypto";
8
+ import {
9
+ resolveTaskFolderInWorktree,
10
+ taskAlreadyComplete,
11
+ taskTerminalSuccessInBatch,
12
+ } from "./resume-common.mjs";
13
+ import { appendJournalEvent } from "./journal.mjs";
14
+ import { laneTaskBranch } from "./worktree.mjs";
15
+ import { isTaskResumable } from "./resume-multi-validate.mjs";
16
+ import {
17
+ markTaskCompleteFromDisk,
18
+ runResumedTaskOnLane,
19
+ } from "./resume-multi-lanes.mjs";
20
+
21
+ /**
22
+ * Build lane queues and run all tasks in a resume wave.
23
+ *
24
+ * @param {object} params
25
+ * @returns {Promise<{ ok: true, waveResults: object[], batchAborted: boolean } | { ok: false, result: object }>}
26
+ */
27
+ export async function executeResumeWave({
28
+ projectRoot,
29
+ state,
30
+ batchId,
31
+ config,
32
+ tasksRootRel,
33
+ waveIndex,
34
+ waveTaskIds,
35
+ events,
36
+ }) {
37
+ /** @type {Map<number, { lane: object, runs: Array<{ taskId: string, run: () => Promise<object> }> }>} */
38
+ const runsByLane = new Map();
39
+ let batchAborted = false;
40
+
41
+ for (const taskId of waveTaskIds) {
42
+ const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
43
+ if (!task) continue;
44
+
45
+ const laneNumber = task.laneNumber;
46
+ const lane = (state.lanes ?? []).find((entry) => entry.laneNumber === laneNumber);
47
+ if (!lane) {
48
+ return {
49
+ ok: false,
50
+ result: {
51
+ ok: false,
52
+ exitCode: 1,
53
+ batchId,
54
+ taskId,
55
+ error: "lane_not_found",
56
+ output: `No lane assigned for task ${taskId} (lane ${laneNumber}).\n`,
57
+ },
58
+ };
59
+ }
60
+
61
+ const taskFolderRel = task.taskFolder
62
+ ? path.isAbsolute(task.taskFolder)
63
+ ? path.relative(projectRoot, task.taskFolder)
64
+ : task.taskFolder
65
+ : path.join(tasksRootRel, `${taskId}-smoke`);
66
+ const taskFolderInWorktree = resolveTaskFolderInWorktree({
67
+ projectRoot,
68
+ task,
69
+ lane,
70
+ tasksRootRel,
71
+ batchId,
72
+ });
73
+ const laneCorrelationId = lane.correlationId ?? crypto.randomUUID();
74
+ lane.correlationId = laneCorrelationId;
75
+
76
+ if (!runsByLane.has(laneNumber)) {
77
+ runsByLane.set(laneNumber, { lane, runs: [] });
78
+ }
79
+ const laneQueue = runsByLane.get(laneNumber);
80
+
81
+ if (
82
+ taskTerminalSuccessInBatch({
83
+ events,
84
+ task,
85
+ taskFolder: taskFolderInWorktree,
86
+ })
87
+ ) {
88
+ continue;
89
+ }
90
+
91
+ if (taskAlreadyComplete({ taskFolder: taskFolderInWorktree, events, task })) {
92
+ laneQueue.runs.push({
93
+ taskId,
94
+ run: () =>
95
+ markTaskCompleteFromDisk({
96
+ projectRoot,
97
+ state,
98
+ batchId,
99
+ config,
100
+ task,
101
+ lane,
102
+ taskBranch: lane.branch ?? laneTaskBranch(batchId, laneNumber),
103
+ taskFolderInWorktree,
104
+ laneCorrelationId,
105
+ }),
106
+ });
107
+ continue;
108
+ }
109
+
110
+ if (!isTaskResumable(state, task)) {
111
+ continue;
112
+ }
113
+
114
+ laneQueue.runs.push({
115
+ taskId,
116
+ run: () =>
117
+ runResumedTaskOnLane({
118
+ projectRoot,
119
+ state,
120
+ batchId,
121
+ config,
122
+ task,
123
+ lane,
124
+ taskFolderRel,
125
+ laneCorrelationId,
126
+ }).then((result) => {
127
+ if (result.aborted) batchAborted = true;
128
+ return result;
129
+ }),
130
+ });
131
+ }
132
+
133
+ const laneExecutions = [...runsByLane.entries()].map(async ([laneNumber, { lane, runs }]) => {
134
+ if (runs.length > 1) {
135
+ appendJournalEvent(projectRoot, batchId, "lane.tasks_serialized", {
136
+ laneNumber,
137
+ laneId: lane.laneId,
138
+ waveIndex,
139
+ taskIds: runs.map((entry) => entry.taskId),
140
+ correlationId: lane.correlationId ?? null,
141
+ });
142
+ }
143
+
144
+ /** @type {object[]} */
145
+ const laneResults = [];
146
+ for (const { run } of runs) {
147
+ const result = await run();
148
+ laneResults.push(result);
149
+ if (result.aborted) {
150
+ batchAborted = true;
151
+ return laneResults;
152
+ }
153
+ }
154
+ return laneResults;
155
+ });
156
+
157
+ const waveResults = (await Promise.all(laneExecutions)).flat();
158
+ return { ok: true, waveResults, batchAborted };
159
+ }
@@ -0,0 +1,25 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Single-batch resume validation wrapper (extracted from resume.mjs for LOC policy).
4
+ */
5
+
6
+ import { validateMultiTaskResume } from "./resume-multi.mjs";
7
+
8
+ /**
9
+ * @param {object} params
10
+ * @param {string} params.projectRoot
11
+ * @param {boolean} [params.force]
12
+ */
13
+ export function validateResumeBatch({ projectRoot, force = false }) {
14
+ const result = validateMultiTaskResume({ projectRoot, force });
15
+ if (!result.ok) {
16
+ return result;
17
+ }
18
+
19
+ const taskId = result.pendingTasks.length === 1 ? result.pendingTasks[0].taskId : undefined;
20
+
21
+ return {
22
+ ...result,
23
+ taskId,
24
+ };
25
+ }
@@ -31,31 +31,14 @@ import {
31
31
  updateSegmentForTask,
32
32
  } from "./state.mjs";
33
33
  import { laneTaskBranch, laneWorktreePath } from "./worktree.mjs";
34
- import { validateMultiTaskResume, resumeMultiTaskBatch } from "./resume-multi.mjs";
34
+ import { resumeMultiTaskBatch } from "./resume-multi.mjs";
35
35
  import { runLaneReviewPhasesBeforeCommit } from "./resume-lane-reviews.mjs";
36
+ import { validateResumeBatch } from "./resume-single-validate.mjs";
36
37
  import { runWorker } from "./worker-host.mjs";
37
38
  import { recordTaskFailureSalvage } from "./salvage.mjs";
38
39
 
39
40
  export { pauseBatch } from "./pause.mjs";
40
-
41
- /**
42
- * @param {object} params
43
- * @param {string} params.projectRoot
44
- * @param {boolean} [params.force]
45
- */
46
- export function validateResumeBatch({ projectRoot, force = false }) {
47
- const result = validateMultiTaskResume({ projectRoot, force });
48
- if (!result.ok) {
49
- return result;
50
- }
51
-
52
- const taskId = result.pendingTasks.length === 1 ? result.pendingTasks[0].taskId : undefined;
53
-
54
- return {
55
- ...result,
56
- taskId,
57
- };
58
- }
41
+ export { validateResumeBatch } from "./resume-single-validate.mjs";
59
42
 
60
43
  /**
61
44
  * @param {object} params