pi-spine 2.22.0 → 2.23.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-spine",
3
- "version": "2.22.0",
3
+ "version": "2.23.0",
4
4
  "description": "Orchestration spine for long-running pi development",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -35,8 +35,9 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
35
35
  4. `spine preflight` green; **`npm run release:check` green (blocking gate)** on current `main`
36
36
  5. **CI workflow green on release commit** (release-safe profile — parity with `ci.yml`) before tag push
37
37
  6. Operator explicitly approved publish; version bumped and tag pushed (if approved)
38
- 7. Every release-scoped `Closes #NNN` / `Closes: #NNN` issue is **CLOSED** on GitHub once its fix is on `main` (close after each land — do not wait for publish)
39
- 8. Final report with composition table, issues closed/deferred, verification output
38
+ 7. **npm stage completed via GitHub Actions** — `release.yml` Stage step green; then maintainer **approves** with 2FA; `npm view pi-spine version` matches the tag (stage alone is not publish)
39
+ 8. Every release-scoped `Closes #NNN` / `Closes: #NNN` issue is **CLOSED** on GitHub once its fix is on `main` (close after each land — do not wait for publish)
40
+ 9. Final report with composition table, issues closed/deferred, verification output
40
41
 
41
42
  ## Hard rules
42
43
 
@@ -46,6 +47,9 @@ Invoke explicitly: `/skill:spine-release-operator` or "run a spine release cycle
46
47
  - **Never** run `npm version` or `git push --tags` without explicit operator approval
47
48
  - **Never** run `npm version` or `git push --tags` when `npm run release:check` exits non-zero on current `main` ([#175](https://github.com/beettlle/pi-spine/issues/175))
48
49
  - **Never** run `npm version` or `git push --tags` when the **CI** workflow is not green on current `HEAD` — release-safe profile: typecheck + lint + tests + coverage (parity with `ci.yml`) ([#156](https://github.com/beettlle/pi-spine/issues/156))
50
+ - **Never** claim the package is on npm until the staged package is **approved** with 2FA and `npm view pi-spine version` matches the release — tag push and green `release.yml` stage alone are not publish
51
+ - **Never** re-run `npm version` / retag when `release.yml` failed after a correct `v*` tag already exists — fix Trusted Publisher / OIDC config or re-dispatch Release on the existing tag (see Phase 6 § Publish failure recovery)
52
+ - **Never** use local `npm publish` for routine releases — CI stages via OIDC (`npm stage publish`); emergency manual only after explicit operator approval (see `docs/release/npm-publish.md`)
49
53
  - **Always** parse target version / bump type **before** task selection (Phase 2)
50
54
  - **Always** record dependency drift in Phase 1 (`npm outdated` + `npm audit`) and apply include/defer thresholds — never auto-add a full “update all deps” task; see [issue-intake-checklist.md](references/issue-intake-checklist.md) § Dependency drift check
51
55
  - **Always** prioritize documentation issues over enhancements
@@ -519,15 +523,79 @@ npm version patch # or minor / major — must match Phase 2 profile
519
523
  git push && git push --tags
520
524
  ```
521
525
 
522
- Monitor Release workflow (tag publish):
526
+ ### CI stages to npm via OIDC (not the operator shell)
527
+
528
+ **Canonical publish path:** pushing `v*` triggers [`.github/workflows/release.yml`](../../.github/workflows/release.yml). That workflow:
529
+
530
+ 1. Checks out the tag
531
+ 2. Verifies CI green on the tagged commit (or runs the full gate if no green CI yet)
532
+ 3. Ensures npm ≥ 11.15 and runs `npm stage publish --access public --ignore-scripts --provenance` with **Trusted Publishing (OIDC)** — `permissions.id-token: write`; no `NPMSECRET`
533
+ 4. Creates the GitHub Release (`gh release create`)
534
+
535
+ **Not live yet:** Trusted Publisher is **stage-only**. A maintainer must approve with 2FA before the version is installable:
536
+
537
+ ```bash
538
+ npm stage list
539
+ npm stage view <stage-id>
540
+ npm stage approve <stage-id> # prompts for 2FA
541
+ # or: npmjs.com → package → Staged Packages → Approve
542
+ ```
543
+
544
+ Operator Phase 6 after approval is: **bump → push tag → watch `release.yml` (stage) → human approve → smoke**. Full mechanics: `docs/release/npm-publish.md`.
545
+
546
+ Monitor Release workflow until conclusion:
547
+
548
+ ```bash
549
+ gh run list --workflow release.yml --limit 3
550
+ # Prefer the run for this tag:
551
+ gh run list --workflow release.yml --branch v{VERSION} --limit 3
552
+ gh run watch --exit-status <run-id>
553
+ ```
554
+
555
+ **pi async:** `MonitorCreate` with `gh run watch --exit-status <run-id>`, `timeout: 1800000`, `onDone` to report conclusion; if green, remind operator to approve the staged package, then run smoke.
556
+
557
+ **Publish success criteria (all required):**
558
+
559
+ - `release.yml` conclusion `success` (stage + GitHub Release)
560
+ - Staged package **approved** (2FA) — `npm view pi-spine version` equals the released version
561
+ - GitHub Release exists for `v{VERSION}` (`gh release view v{VERSION}`)
562
+
563
+ Tag push + green **CI** (`ci.yml`) alone is **not** enough — `ci.yml` does not stage or publish. Green stage alone is **not** enough — approve is required.
564
+
565
+ ### Publish failure recovery (HARD STOP — do not retag)
566
+
567
+ When `release.yml` fails, diagnose with the failed job log before any recovery:
523
568
 
524
569
  ```bash
570
+ gh run view <run-id> --log-failed
571
+ ```
572
+
573
+ | Symptom | Meaning | Action |
574
+ |---------|---------|--------|
575
+ | OIDC / trusted publisher mismatch / `ENEEDAUTH` | Trusted Publisher config wrong (workflow name, Environment name set while job has none, stage permission missing) | Fix npm Trusted Publisher; re-dispatch same tag — do **not** `npm version` again |
576
+ | Legacy `E404` on PUT with `NPMSECRET` | Old token path still in use or secret bad | Prefer OIDC; emergency: rotate `NPMSECRET` only if workflow still uses token |
577
+ | Validation steps failed (typecheck / lint / coverage / CLI smoke) | Tagged commit not release-safe | Fix on `main`, create a **new** patch version + tag; do not force-publish a broken tag |
578
+ | CI gate failed for tagged commit | Pre-tag CI was red or missing | Fix `main` / re-run `ci.yml`; new tag if the old tag pointed at a bad commit |
579
+ | Stage green but install missing version | Not approved yet | Approve with 2FA; do not retag |
580
+ | GitHub Release step failed after stage succeeded | Notes/release page only | Create release manually; do not double-stage the same version without rejecting the prior stage first |
581
+
582
+ **Re-dispatch existing tag** (after Trusted Publisher / transient registry fix):
583
+
584
+ ```bash
585
+ # Tag must already exist; this re-runs checkout → gate → stage → gh release
586
+ # workflow_dispatch uses the workflow file from the branch you select (usually main)
587
+ gh workflow run release.yml -f tag=v{VERSION}
525
588
  gh run list --workflow release.yml --limit 3
589
+ gh run watch --exit-status <new-run-id>
526
590
  ```
527
591
 
528
- **pi async:** `MonitorCreate` with `gh run watch --exit-status <run-id>`, `timeout: 1800000`, `onDone` to report conclusion and run smoke tests if green.
592
+ UI equivalent: **Actions → Release → Run workflow** → enter `v{VERSION}`.
593
+
594
+ **Do not** delete/retag/`npm version` again when the only failure was auth/OIDC — package.json and the `v*` tag are already correct.
595
+
596
+ Distinguish **stage auth failures** (table above) from **post-approve install E404/ETARGET** (registry lag F9 — smoke section below) and from **pre-approve missing version** (approve pending).
529
597
 
530
- Post-publish smoke per `docs/release/npm-publish.md` — **retry on registry lag (F9, [#247](https://github.com/beettlle/pi-spine/issues/247)):** the first `npm install -g` right after a successful `release.yml` run can fail with `ETARGET` / "No matching version found" while the registry propagates, even when `npm view` already lists the version. Prefer the bounded wrapper:
598
+ Post-publish smoke per `docs/release/npm-publish.md` — **only after stage success and 2FA approve**. **Retry on registry lag (F9, [#247](https://github.com/beettlle/pi-spine/issues/247)):** the first `npm install -g` right after approve can fail with `ETARGET` / "No matching version found" while the registry propagates, even when `npm view` already lists the version. Prefer the bounded wrapper:
531
599
 
532
600
  ```bash
533
601
  scripts/post-publish-smoke.sh <version>
@@ -571,7 +639,7 @@ Include the published version/tag in the close comment when closing at Phase 6 (
571
639
  6. **Issues filed** — pi-spine GitHub links or "none"
572
640
  7. **Recovery actions** — aborts, retries, contract fixes
573
641
  8. **Verification** — paste `spine preflight` tail, **`npm run release:check` output** (or log path), test/coverage output
574
- 9. **Publish** — version bumped (Y/N), tag pushed (Y/N), workflow URL, or "awaiting operator approval"
642
+ 9. **Publish** — version bumped (Y/N), tag pushed (Y/N), `release.yml` URL + conclusion, stage approved (Y/N), `npm view pi-spine version`, or "awaiting operator approval" / "blocked on Trusted Publisher" / "awaiting stage approve"
575
643
  10. **Issue tracker hygiene** — confirm every release-scoped `Closes #NNN` is CLOSED (paste `gh issue view` states or list)
576
644
 
577
645
  ---
@@ -584,7 +652,8 @@ Include the published version/tag in the close comment when closing at Phase 6 (
584
652
  | Issues repo | `beettlle/pi-spine` |
585
653
  | Pre-publish gate | `npm run release:check` (typecheck → lint → tests → coverage; CI parity) |
586
654
  | Pre-tag CI gate | `ci.yml` green on `HEAD` via `gh run list` / `gh run watch` before `npm version` ([#156](https://github.com/beettlle/pi-spine/issues/156)) |
587
- | Publish | Tag-triggered `.github/workflows/release.yml` |
655
+ | Publish | **CI-only OIDC stage** — `.github/workflows/release.yml` runs `npm stage publish` (`id-token: write`). Trusted Publisher: stage-only. Human 2FA approve before installable |
656
+ | Re-publish | `gh workflow run release.yml -f tag=vX.Y.Z` after Trusted Publisher fix — never retag for auth-only failures |
588
657
  | Pending backlog | Run `spine plan pending` — release executes **subset only** |
589
658
 
590
659
  ## Short prompt (resume mid-release)
@@ -599,6 +668,7 @@ post-integrate release:check (exit 0 required; no tail-only verification) →
599
668
  git push origin main when remote publish is the goal (F8) →
600
669
  close Closes #NNN issues for tasks that just landed (§4.3c; do not wait for publish) →
601
670
  MonitorCreate release:check → HARD STOP if non-zero (fix on main, re-run) → only if exit 0: verify ci.yml green on HEAD (gh run list/watch) → HARD STOP if not green → only then: STOP for publish approval →
602
- after publish: Phase 6 issue sweep for any still-open Closes links → final report must list CLOSED issue numbers.
671
+ after approve: npm version + push tags → watch release.yml (OIDC `npm stage publish`) → on OIDC/auth failure fix Trusted Publisher and gh workflow run release.yml -f tag=v{TARGET} (do not retag) →
672
+ human 2FA approve staged package (npmjs.com or `npm stage approve`) → confirm npm view + gh release view → post-publish smoke → Phase 6 issue sweep → final report must list CLOSED issue numbers.
603
673
  resume --attached --force stays foreground. Post final report with composition table.
604
674
  ```
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Lane commit and post-commit dirty validation (SP-427 / #73).
4
3
  */
@@ -27,15 +26,15 @@ const DIRTY_AFTER_COMMIT_MESSAGE =
27
26
  * @param {string} params.taskId
28
27
  * @param {string} params.batchId
29
28
  * @param {string} params.taskFolder
30
- * @param {string} [params.projectRoot]
29
+ * @param {string} params.projectRoot
31
30
  * @param {string[]} [params.fileScopePaths]
32
31
  * @param {string[]} [params.ignorePatterns]
33
- * @param {object} params.task
34
- * @param {object} params.lane
32
+ * @param {Record<string, any>} params.task
33
+ * @param {Record<string, any>} params.lane
35
34
  * @param {number} params.laneNumber
36
35
  * @param {string} params.laneCorrelationId
37
- * @param {object} params.state
38
- * @param {object} params.config
36
+ * @param {Record<string, any>} params.state
37
+ * @param {Record<string, any>} params.config
39
38
  * @returns {{ ok: true, laneCommit: object } | { ok: false, error: string, output?: string }}
40
39
  */
41
40
  export function commitLaneAndValidateWorktree({
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Matrix task / sub-lane runners (SP-671 / #217).
4
3
  *
@@ -43,7 +42,7 @@ import { gitExec } from "../git-exec.mjs";
43
42
  * Read the `## Contract` table from a parent task folder (un-substituted).
44
43
  *
45
44
  * @param {string} parentTaskFolderAbs
46
- * @returns {object|null}
45
+ * @returns {ReturnType<typeof parseContract> | null}
47
46
  */
48
47
  export function readParentContract(parentTaskFolderAbs) {
49
48
  const promptPath = path.join(parentTaskFolderAbs, "PROMPT.md");
@@ -130,6 +129,18 @@ export function resolveMatrixRowConcurrency({ matrixMaxParallel, maxParallel = 1
130
129
  * worker child env (`buildMatrixRowEnv`).
131
130
  *
132
131
  * @param {object} params
132
+ * @param {string} params.projectRoot
133
+ * @param {string} params.batchId
134
+ * @param {number} params.laneNumber
135
+ * @param {string} params.taskId
136
+ * @param {string} params.laneBranch Lane task branch the row worktree branches from.
137
+ * @param {string} params.laneCorrelationId
138
+ * @param {{ rowId: string, values: Record<string, string> }} params.row
139
+ * @param {"execute" | "llm"} params.matrixType
140
+ * @param {string} params.parentTaskFolderAbs
141
+ * @param {string} params.taskFolderRel
142
+ * @param {Record<string, any>} [params.config]
143
+ * @param {string} [params.baseBranch]
133
144
  * @param {number} [params.rowIndex] 0-based index of this row in the matrix.
134
145
  * @param {number} [params.rowCount] Total matrix row count.
135
146
  * @returns {Promise<{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string, commitSha?: string, servedPrompt?: string }>}
@@ -223,7 +234,7 @@ export async function runMatrixSubLane({
223
234
  };
224
235
  }
225
236
 
226
- /** @type {{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string }} */
237
+ /** @type {{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string, commitSha?: string, servedPrompt?: string }} */
227
238
  let result;
228
239
 
229
240
  if (matrixType === "execute") {
@@ -333,7 +344,8 @@ export async function runMatrixSubLane({
333
344
  sha256,
334
345
  chars: servedPrompt.length,
335
346
  });
336
- const workerResult = await runWorker({
347
+ const workerResult = /** @type {{ ok?: boolean, exitCode?: number, output?: string, classification?: string }} */ (
348
+ await runWorker({
337
349
  worktreePath,
338
350
  taskFolder: path.join(worktreePath, taskFolderRel),
339
351
  projectRoot,
@@ -345,7 +357,7 @@ export async function runMatrixSubLane({
345
357
  fileScopePaths: [],
346
358
  config,
347
359
  ...(matrixEnv ? { extraEnv: matrixEnv } : {}),
348
- });
360
+ }));
349
361
  result = {
350
362
  rowId,
351
363
  ok: Boolean(workerResult.ok),
@@ -397,7 +409,7 @@ export async function runMatrixSubLane({
397
409
  { projectRoot },
398
410
  );
399
411
  }
400
- const sha = gitExec(worktreePath, ["rev-parse", "HEAD"], { projectRoot });
412
+ const sha = /** @type {string} */ (gitExec(worktreePath, ["rev-parse", "HEAD"], { projectRoot }));
401
413
  result.commitSha = sha;
402
414
  recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.completed", {
403
415
  taskId,
@@ -450,12 +462,12 @@ export async function runMatrixSubLane({
450
462
  *
451
463
  * @param {object} params
452
464
  * @param {string} params.projectRoot
453
- * @param {object} params.state Live batch state.
465
+ * @param {Record<string, any>} params.state Live batch state.
454
466
  * @param {string} params.batchId
455
467
  * @param {string} params.baseBranch
456
- * @param {object} params.config
457
- * @param {object} params.task
458
- * @param {object} params.lane
468
+ * @param {Record<string, any>} params.config
469
+ * @param {Record<string, any>} params.task
470
+ * @param {Record<string, any>} params.lane
459
471
  * @param {string} params.taskFolderRel
460
472
  * @param {string} params.laneCorrelationId
461
473
  * @param {string[]} params.fileScopePaths
@@ -536,8 +548,16 @@ export async function runMatrixTaskForResume({
536
548
  * branches (fresh and carried-over) are merged back into the lane worktree so
537
549
  * the normal lane-commit + wave-merge carry all rows' output.
538
550
  *
539
- * @param {object} params
540
- * @param {number} params.maxParallel Global `lanes.maxParallel` (pool size).
551
+ * Params bag keys: `projectRoot` (string), `state` (live batch state),
552
+ * `batchId` (string), `baseBranch` (string), `config` (spine config), `task`
553
+ * (parent matrix task, mutated in place), `lane` (lane identity with
554
+ * `laneNumber`/`branch`/`worktreePath`), `taskFolderRel` (string),
555
+ * `laneCorrelationId` (string), `fileScopePaths` (string[]), `matrix` (packet
556
+ * matrix rows from `loadMatrixTaskRows`), `maxParallel` (global
557
+ * `lanes.maxParallel`, pool size).
558
+ *
559
+ * @param {Record<string, any>} params
560
+ * @returns {Promise<{ ok: boolean, aborted?: boolean, error?: string, output?: string, laneCommit?: object, workerResult?: { ok: boolean, classification?: string, exitCode?: number, output?: string } }>}
541
561
  */
542
562
  export async function runMatrixTaskOnLane({
543
563
  projectRoot,
@@ -575,9 +595,9 @@ export async function runMatrixTaskOnLane({
575
595
  // rows keep their status + persisted worktree/branch for retry carry-over,
576
596
  // `canceled` rows stay excluded, and only failed/pending rows re-enter the
577
597
  // sweep. Fresh rows start `pending`.
578
- task.matrixRows = matrix.rows.map((row) => {
598
+ task.matrixRows = matrix.rows.map((/** @type {any} */ row) => {
579
599
  const existing = Array.isArray(task.matrixRows)
580
- ? task.matrixRows.find((entry) => entry && entry.rowId === row.rowId)
600
+ ? task.matrixRows.find((/** @type {any} */ entry) => entry && entry.rowId === row.rowId)
581
601
  : null;
582
602
  return existing ?? {
583
603
  rowId: row.rowId,
@@ -595,7 +615,7 @@ export async function runMatrixTaskOnLane({
595
615
  const runnableRows = [];
596
616
  const skippedRowIds = [];
597
617
  for (const row of matrix.rows) {
598
- const entry = task.matrixRows.find((m) => m.rowId === row.rowId);
618
+ const entry = task.matrixRows.find((/** @type {any} */ m) => m.rowId === row.rowId);
599
619
  if (entry.status === "succeeded") {
600
620
  const carryWorktree = typeof entry.worktreePath === "string" ? entry.worktreePath : null;
601
621
  const carryBranch = typeof entry.branch === "string" ? entry.branch : null;
@@ -641,13 +661,13 @@ export async function runMatrixTaskOnLane({
641
661
  laneNumber,
642
662
  laneId: lane.laneId,
643
663
  correlationId: laneCorrelationId,
644
- rowIds: matrix.rows.map((row) => row.rowId),
664
+ rowIds: matrix.rows.map((/** @type {any} */ row) => row.rowId),
645
665
  matrixType: matrix.type,
646
666
  maxParallel,
647
667
  matrixMaxParallel,
648
668
  rowConcurrency,
649
- runnableRowIds: runnableRows.map((row) => row.rowId),
650
- carriedOverRowIds: carryOverRows.map((carry) => carry.row.rowId),
669
+ runnableRowIds: runnableRows.map((/** @type {any} */ row) => row.rowId),
670
+ carriedOverRowIds: carryOverRows.map((/** @type {any} */ carry) => carry.row.rowId),
651
671
  skippedRowIds,
652
672
  });
653
673
 
@@ -659,7 +679,7 @@ export async function runMatrixTaskOnLane({
659
679
  const rowLaneNumber = await acquireLaneSlot(state, maxParallel);
660
680
  // Per-row live status (#230): flip to `running` only once the row actually
661
681
  // holds a slot, and persist so `spine status` sees it from another process.
662
- const runningEntry = task.matrixRows.find((m) => m.rowId === row.rowId);
682
+ const runningEntry = task.matrixRows.find((/** @type {any} */ m) => m.rowId === row.rowId);
663
683
  if (runningEntry) {
664
684
  runningEntry.status = "running";
665
685
  saveEngineBatchState(projectRoot, state);
@@ -697,6 +717,9 @@ export async function runMatrixTaskOnLane({
697
717
  ok: false,
698
718
  exitCode: 1,
699
719
  output: `sub-lane crashed: ${message}`,
720
+ worktreePath: undefined,
721
+ branch: undefined,
722
+ commitSha: undefined,
700
723
  };
701
724
  } finally {
702
725
  releaseLaneSlot(state, rowLaneNumber);
@@ -704,7 +727,7 @@ export async function runMatrixTaskOnLane({
704
727
  });
705
728
 
706
729
  for (const rowResult of results) {
707
- const entry = task.matrixRows.find((m) => m.rowId === rowResult.rowId);
730
+ const entry = task.matrixRows.find((/** @type {any} */ m) => m.rowId === rowResult.rowId);
708
731
  if (entry) {
709
732
  entry.status = rowResult.ok ? "succeeded" : "failed";
710
733
  entry.exitCode = rowResult.exitCode ?? null;
@@ -724,8 +747,8 @@ export async function runMatrixTaskOnLane({
724
747
  // scope).
725
748
  const { ok, failedRowIds } = aggregateMatrixOutcomes(
726
749
  task.matrixRows
727
- .filter((entry) => entry.status !== "canceled")
728
- .map((entry) => ({ rowId: entry.rowId, ok: entry.status === "succeeded" })),
750
+ .filter((/** @type {any} */ entry) => entry.status !== "canceled")
751
+ .map((/** @type {any} */ entry) => ({ rowId: entry.rowId, ok: entry.status === "succeeded" })),
729
752
  );
730
753
 
731
754
  if (!ok) {
@@ -735,7 +758,7 @@ export async function runMatrixTaskOnLane({
735
758
  // Failed rows' worktrees are cleaned up; succeeded rows keep theirs as
736
759
  // carry-over material for a row-scoped retry (#230).
737
760
  removeMatrixSubLaneWorktree(projectRoot, rowResult.worktreePath, rowResult.branch);
738
- const failedEntry = task.matrixRows.find((m) => m.rowId === rowResult.rowId);
761
+ const failedEntry = task.matrixRows.find((/** @type {any} */ m) => m.rowId === rowResult.rowId);
739
762
  if (failedEntry) {
740
763
  delete failedEntry.worktreePath;
741
764
  delete failedEntry.branch;
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Matrix sub-lane execution (SP-671 / #217).
4
3
  *
@@ -35,7 +34,7 @@ import { appendJournalEvent } from "../journal.mjs";
35
34
  * task is not a matrix task.
36
35
  *
37
36
  * @param {string} taskFolderPath Absolute path to the task folder (parent for matrix).
38
- * @returns {{ rows: Array<{ rowId: string, values: Record<string,string> }>, columns: string[], type: string } | null}
37
+ * @returns {{ rows: Array<{ rowId: string, values: Record<string,string> }>, columns: string[], type: "execute" | "llm" } | null}
39
38
  */
40
39
  export function loadMatrixTaskRows(taskFolderPath) {
41
40
  if (!taskFolderPath || !fs.existsSync(path.join(taskFolderPath, "PROMPT.md"))) {
@@ -48,7 +47,9 @@ export function loadMatrixTaskRows(taskFolderPath) {
48
47
  return null;
49
48
  }
50
49
  const prompt = packet?.prompt;
51
- const matrix = Array.isArray(prompt?.matrix) ? prompt.matrix : null;
50
+ const matrix = /** @type {Array<Record<string, string>> | null} */ (
51
+ Array.isArray(prompt?.matrix) ? prompt.matrix : null
52
+ );
52
53
  if (!matrix || matrix.length === 0) return null;
53
54
  const columns = Array.isArray(prompt.matrixColumns) ? prompt.matrixColumns : [];
54
55
  const rows = matrix.map((values) => ({
@@ -273,8 +274,8 @@ export function removeMatrixSubLaneWorktree(projectRoot, worktreePath, branch) {
273
274
  * @returns {Record<string, string> | null}
274
275
  */
275
276
  export function buildMatrixRowEnv({ taskId, rowId, rowIndex, rowCount }) {
276
- if (!Number.isInteger(rowIndex) || rowIndex < 0) return null;
277
- if (!Number.isInteger(rowCount) || rowCount < 0) return null;
277
+ if (typeof rowIndex !== "number" || !Number.isInteger(rowIndex) || rowIndex < 0) return null;
278
+ if (typeof rowCount !== "number" || !Number.isInteger(rowCount) || rowCount < 0) return null;
278
279
  return {
279
280
  SPINE_MATRIX_JOB_ID: String(taskId ?? ""),
280
281
  SPINE_MATRIX_TASK_ID: String(rowId ?? ""),
@@ -302,8 +303,9 @@ export function runShellInDir(cwd, command, extraEnv = null) {
302
303
  stdio: ["ignore", "pipe", "pipe"],
303
304
  });
304
305
  let output = "";
306
+ /** @type {(chunk: unknown) => void} */
305
307
  const append = (chunk) => {
306
- output += chunk.toString();
308
+ output += String(chunk);
307
309
  };
308
310
  child.stdout?.on("data", append);
309
311
  child.stderr?.on("data", append);
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane merge-phase wiring — lane→orch merges and rules-manifest conflict resolution.
4
3
  */
@@ -69,6 +68,7 @@ function listUnmergedPaths(projectRoot) {
69
68
  /**
70
69
  * @param {string} projectRoot
71
70
  * @param {string} ref
71
+ * @returns {{ ok: true, manifest: import("../../config/cursor-rules/discover.mjs").CursorRulesManifest } | { ok: false, error: string }}
72
72
  */
73
73
  function readRulesManifestFromRef(projectRoot, ref) {
74
74
  const output = git(projectRoot, ["show", `${ref}:${RULES_MANIFEST_REL_PATH}`], {
@@ -112,6 +112,7 @@ export { resolveRulesManifestIntegrateDrift } from "../rules-manifest-drift.mjs"
112
112
  /**
113
113
  * @param {string} projectRoot
114
114
  * @param {2 | 3} stage
115
+ * @returns {{ ok: true, manifest: import("../../config/cursor-rules/discover.mjs").CursorRulesManifest } | { ok: false, error: string }}
115
116
  */
116
117
  function readRulesManifestMergeStage(projectRoot, stage) {
117
118
  const output = git(projectRoot, ["show", `:${stage}:${RULES_MANIFEST_REL_PATH}`], {
@@ -161,7 +162,7 @@ function resolveRulesManifestMergeConflict(projectRoot) {
161
162
  const theirsResult = readRulesManifestMergeStage(projectRoot, 3);
162
163
  if (!oursResult.ok || !theirsResult.ok) {
163
164
  return {
164
- ok: false,
165
+ ok: /** @type {const} */ (false),
165
166
  error: "unable to read rules-manifest merge stages",
166
167
  };
167
168
  }
@@ -177,8 +178,8 @@ function resolveRulesManifestMergeConflict(projectRoot) {
177
178
  writeRulesManifestAtomic(projectRoot, resolved.manifest);
178
179
  gitAddFilteredPaths(projectRoot, [RULES_MANIFEST_REL_PATH], { projectRoot });
179
180
  return {
180
- ok: true,
181
- autoResolved: true,
181
+ ok: /** @type {const} */ (true),
182
+ autoResolved: /** @type {const} */ (true),
182
183
  generatedAt: resolved.manifest.generatedAt,
183
184
  };
184
185
  }
@@ -196,7 +197,7 @@ function tryAutoResolveOutOfScopeMergeConflict({
196
197
  projectRoot,
197
198
  filePath,
198
199
  laneFileScopePaths,
199
- _laneChangedFiles,
200
+ laneChangedFiles: _laneChangedFiles,
200
201
  }) {
201
202
  if (pathInLaneFileScope(filePath, laneFileScopePaths)) {
202
203
  return { ok: false, reason: "in_lane_file_scope" };
@@ -220,7 +221,7 @@ function tryAutoResolveOutOfScopeMergeConflict({
220
221
  }
221
222
 
222
223
  /**
223
- * @param {object} state
224
+ * @param {Record<string, any>} state
224
225
  * @param {number} laneNumber
225
226
  * @param {string[]} waveTaskIds
226
227
  */
@@ -228,7 +229,7 @@ function collectLaneWaveFileScope(state, laneNumber, waveTaskIds) {
228
229
  /** @type {Set<string>} */
229
230
  const patterns = new Set();
230
231
  for (const taskId of waveTaskIds) {
231
- const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
232
+ const task = (state.tasks ?? []).find((/** @type {any} */ entry) => entry?.taskId === taskId);
232
233
  if (!task || task.laneNumber !== laneNumber) continue;
233
234
  const folder = task.taskFolder;
234
235
  if (!folder) continue;
@@ -243,12 +244,15 @@ function collectLaneWaveFileScope(state, laneNumber, waveTaskIds) {
243
244
  }
244
245
 
245
246
  /**
247
+ * Auto-resolve lane→orch merge conflicts for known conflict classes.
248
+ *
246
249
  * @param {string} projectRoot
247
250
  * @param {object} [options]
248
251
  * @param {string[]} [options.laneFileScopePaths]
249
252
  * @param {string} [options.taskBranch]
250
253
  * @param {string} [options.orchBranch]
251
254
  * @param {number} [options.waveIndex]
255
+ * @returns {{ ok: true, autoResolved: true, generatedAt?: string, outOfScopePaths?: string[], adoptionDocPaths?: string[], skippedGitignoredPaths?: string[] } | { ok: false, error: string, failureClass?: string, outOfScopePaths?: string[], adoptionDocPaths?: string[], skippedGitignoredPaths?: string[] }}
252
256
  */
253
257
  export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
254
258
  const { laneFileScopePaths = [], taskBranch, orchBranch, waveIndex } = options;
@@ -274,11 +278,11 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
274
278
  /** @type {Set<string>} */
275
279
  let laneChangedFiles = new Set();
276
280
  if (canResolveOutOfScope) {
277
- const mergeBase = git(projectRoot, ["merge-base", orchBranch, taskBranch], {
281
+ const mergeBase = git(projectRoot, ["merge-base", /** @type {string} */ (orchBranch), /** @type {string} */ (taskBranch)], {
278
282
  throwOnError: false,
279
283
  });
280
284
  if (mergeBase) {
281
- laneChangedFiles = listBranchChangedFiles(projectRoot, mergeBase, taskBranch);
285
+ laneChangedFiles = listBranchChangedFiles(projectRoot, mergeBase, /** @type {string} */ (taskBranch));
282
286
  }
283
287
  }
284
288
 
@@ -411,7 +415,10 @@ export function tryAutoResolveMergeConflicts(projectRoot, options = {}) {
411
415
  };
412
416
  }
413
417
 
414
- /** @deprecated use tryAutoResolveMergeConflicts */
418
+ /**
419
+ * @deprecated use tryAutoResolveMergeConflicts
420
+ * @param {string} projectRoot
421
+ */
415
422
  export function tryAutoResolveRulesManifestMergeConflict(projectRoot) {
416
423
  return tryAutoResolveMergeConflicts(projectRoot, {});
417
424
  }
@@ -424,15 +431,12 @@ function gitStrict(projectRoot, args) {
424
431
  return git(projectRoot, args);
425
432
  }
426
433
 
427
- /**
428
- * @param {object} params
429
- * @param {boolean} [params.requireLaneCommits] When true, task branch must be ahead of orch before merge (post lane auto-commit).
430
- */
431
434
  /**
432
435
  * Clear generatedAt-only rules-manifest drift on the working tree before lane→orch merge.
433
436
  * Workers refresh the manifest during pi sessions; an uncommitted copy blocks `git merge`.
434
437
  *
435
438
  * @param {string} projectRoot
439
+ * @returns {{ ok: true, resolved: boolean, action?: string } | { ok: false, failureClass: string, error: string }}
436
440
  */
437
441
  function resolveRulesManifestPreMergeDrift(projectRoot) {
438
442
  const dirtyPaths = listDirtyPaths(projectRoot);
@@ -443,7 +447,7 @@ function resolveRulesManifestPreMergeDrift(projectRoot) {
443
447
  return { ok: true, resolved: false };
444
448
  }
445
449
 
446
- const headRef = gitStrict(projectRoot, ["rev-parse", "HEAD"]);
450
+ const headRef = /** @type {string} */ (gitStrict(projectRoot, ["rev-parse", "HEAD"]));
447
451
  const headResult = readRulesManifestFromRef(projectRoot, headRef);
448
452
  const working = loadRulesManifest(projectRoot);
449
453
  if (!working) {
@@ -478,6 +482,22 @@ function resolveRulesManifestPreMergeDrift(projectRoot) {
478
482
  return { ok: true, resolved: true, action: "restored_head_for_lane_merge" };
479
483
  }
480
484
 
485
+ /**
486
+ * Merge a lane task branch into the orch branch, auto-resolving known conflict
487
+ * classes (rules-manifest, adoption/PRD docs, out-of-scope dependency drift).
488
+ *
489
+ * @param {object} params
490
+ * @param {string} params.projectRoot
491
+ * @param {string} params.baseBranch
492
+ * @param {string} params.orchBranch
493
+ * @param {string} params.taskBranch
494
+ * @param {string} params.batchId
495
+ * @param {boolean} [params.requireLaneCommits] When true, task branch must be ahead of orch before merge (post lane auto-commit).
496
+ * @param {string[]} [params.laneFileScopePaths]
497
+ * @param {string[]} [params.laneTaskFolders]
498
+ * @param {number} [params.waveIndex]
499
+ * @returns {{ ok: true, mergeCommit: string, commitsAhead: number } | { ok: false, failureClass?: string, error: string, outOfScopePaths?: string[], skippedGitignoredPaths?: string[] }}
500
+ */
481
501
  export function mergeLaneToOrch({
482
502
  projectRoot,
483
503
  baseBranch,
@@ -501,7 +521,7 @@ export function mergeLaneToOrch({
501
521
  };
502
522
  }
503
523
 
504
- const orchHeadBefore = gitStrict(projectRoot, ["rev-parse", orchBranch]);
524
+ const orchHeadBefore = /** @type {string} */ (gitStrict(projectRoot, ["rev-parse", orchBranch]));
505
525
  const commitsAhead = countCommitsAhead(projectRoot, orchBranch, taskBranch);
506
526
 
507
527
  if (Array.isArray(laneTaskFolders) && laneTaskFolders.length > 0) {
@@ -567,7 +587,7 @@ export function mergeLaneToOrch({
567
587
  gitStrict(projectRoot, ["commit", "--no-edit"]);
568
588
  }
569
589
 
570
- const mergeCommit = gitStrict(projectRoot, ["rev-parse", "HEAD"]);
590
+ const mergeCommit = /** @type {string} */ (gitStrict(projectRoot, ["rev-parse", "HEAD"]));
571
591
 
572
592
  if (requireLaneCommits && mergeCommit === orchHeadBefore) {
573
593
  return {
@@ -605,9 +625,21 @@ export function mergeLaneToOrch({
605
625
  }
606
626
 
607
627
  /**
608
- * @param {object} params — includes optional `finalizeAfterWaveMerge(hookParams)` hook injected
609
- * by callers that own the limbo graph (`maybeFinalizeAfterWaveMerge` from post-merge-limbo.mjs,
610
- * SP-734). Omitted → skip post-wave-merge finalize.
628
+ * Merge every succeeded lane of a wave into the orch branch, then run the
629
+ * optional `finalizeAfterWaveMerge(hookParams)` hook injected by callers that
630
+ * own the limbo graph (`maybeFinalizeAfterWaveMerge` from post-merge-limbo.mjs,
631
+ * SP-734). Omitted → skip post-wave-merge finalize.
632
+ *
633
+ * @param {object} params
634
+ * @param {string} params.projectRoot
635
+ * @param {Record<string, any>} params.state
636
+ * @param {string} params.batchId
637
+ * @param {string} params.baseBranch
638
+ * @param {string} params.orchBranch
639
+ * @param {number} params.waveIndex
640
+ * @param {boolean} [params.resumed]
641
+ * @param {((params: object) => unknown) | null} [params.finalizeAfterWaveMerge]
642
+ * @returns {{ ok: true, mergeCommit: string | null, finalized: boolean, finalizeResult: unknown } | { ok: false, error: string, laneNumber?: number, failureClass?: string | null, blockedBy?: string, exitReason?: string }}
611
643
  */
612
644
  export function mergeWaveLanesToOrch({
613
645
  projectRoot,
@@ -621,7 +653,7 @@ export function mergeWaveLanesToOrch({
621
653
  }) {
622
654
  const waveTaskIds = state.wavePlan?.[waveIndex] ?? [];
623
655
  const needsReplanTask = (state.tasks ?? []).find(
624
- (entry) =>
656
+ (/** @type {any} */ entry) =>
625
657
  waveTaskIds.includes(entry?.taskId) && entry?.exitReason === "needs_replan",
626
658
  );
627
659
  if (needsReplanTask) {
@@ -639,8 +671,8 @@ export function mergeWaveLanesToOrch({
639
671
  for (const lane of lanes) {
640
672
  const laneNumber = lane.laneNumber;
641
673
  const waveTaskIds = state.wavePlan?.[waveIndex] ?? [];
642
- const laneSucceeded = waveTaskIds.some((taskId) => {
643
- const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
674
+ const laneSucceeded = waveTaskIds.some((/** @type {any} */ taskId) => {
675
+ const task = (state.tasks ?? []).find((/** @type {any} */ entry) => entry?.taskId === taskId);
644
676
  return task && task.laneNumber === laneNumber && task.status === "succeeded";
645
677
  });
646
678
  if (!laneSucceeded) continue;
@@ -648,8 +680,8 @@ export function mergeWaveLanesToOrch({
648
680
  const taskBranch = lane.branch ?? laneTaskBranch(batchId, laneNumber);
649
681
  const laneFileScopePaths = collectLaneWaveFileScope(state, laneNumber, waveTaskIds);
650
682
  const laneTaskFolders = waveTaskIds
651
- .map((taskId) => {
652
- const task = (state.tasks ?? []).find((entry) => entry?.taskId === taskId);
683
+ .map((/** @type {any} */ taskId) => {
684
+ const task = (state.tasks ?? []).find((/** @type {any} */ entry) => entry?.taskId === taskId);
653
685
  if (!task || task.laneNumber !== laneNumber || !task.taskFolder) return null;
654
686
  return task.taskFolder;
655
687
  })
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Orch→lane sync when satisfied deps share File Scope (FR-REL231-03 / #191).
4
3
  */
@@ -12,7 +11,7 @@ import { syncLaneWorktreeFromOrch } from "../worktree.mjs";
12
11
 
13
12
  /**
14
13
  * @param {string} projectRoot
15
- * @param {object} [config]
14
+ * @param {Record<string, any>} config
16
15
  */
17
16
  function resolveBatchTasksRoot(projectRoot, config) {
18
17
  return resolveTasksRootPath(projectRoot, config) ?? path.join(projectRoot, "spine-tasks");
@@ -21,7 +20,7 @@ function resolveBatchTasksRoot(projectRoot, config) {
21
20
  /**
22
21
  * @param {string} tasksRoot
23
22
  * @param {string} taskId
24
- * @param {object[]} [stateTasks]
23
+ * @param {Array<Record<string, any>>} [stateTasks]
25
24
  */
26
25
  function resolveTaskFolderPath(tasksRoot, taskId, stateTasks = []) {
27
26
  const fromState = stateTasks.find((entry) => entry?.taskId === taskId)?.taskFolder;
@@ -38,10 +37,10 @@ function resolveTaskFolderPath(tasksRoot, taskId, stateTasks = []) {
38
37
  *
39
38
  * @param {object} params
40
39
  * @param {string} params.projectRoot
41
- * @param {object} params.state
40
+ * @param {Record<string, any>} params.state
42
41
  * @param {string} params.taskId
43
42
  * @param {string[]} params.fileScopePaths
44
- * @param {object} [params.config]
43
+ * @param {Record<string, any>} [params.config]
45
44
  * @returns {Array<{ depId: string, overlap: string[] }>}
46
45
  */
47
46
  export function collectSharedScopeSatisfiedDeps({
@@ -54,7 +53,9 @@ export function collectSharedScopeSatisfiedDeps({
54
53
  if (!Array.isArray(fileScopePaths) || fileScopePaths.length === 0) return [];
55
54
 
56
55
  const tasksRoot = resolveBatchTasksRoot(projectRoot, config);
57
- const deps = loadDependenciesJson(tasksRoot).tasks?.[taskId] ?? [];
56
+ /** @type {{ tasks?: Record<string, string[]> }} */
57
+ const depsIndex = loadDependenciesJson(tasksRoot);
58
+ const deps = depsIndex.tasks?.[taskId] ?? [];
58
59
  if (!Array.isArray(deps) || deps.length === 0) return [];
59
60
 
60
61
  const scopeSet = new Set(fileScopePaths);
@@ -85,6 +86,12 @@ export function collectSharedScopeSatisfiedDeps({
85
86
 
86
87
  /**
87
88
  * @param {object} params
89
+ * @param {string} params.projectRoot
90
+ * @param {Record<string, any>} params.state
91
+ * @param {string} params.taskId
92
+ * @param {string[]} params.fileScopePaths
93
+ * @param {string} params.worktreePath
94
+ * @param {Record<string, any>} [params.config]
88
95
  * @returns {{ ok: true, synced: boolean, skipped?: boolean, sharedDeps: Array<{ depId: string, overlap: string[] }>, headSha?: string } | { ok: false, error: string, sharedDeps: Array<{ depId: string, overlap: string[] }> }}
89
96
  */
90
97
  export function ensureLaneSyncedForSharedScopeDeps({
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Batch phase transition helpers for the engine-lanes facade.
4
3
  * Leaf module: journals phase changes without importing resume/limbo/reconcile.
@@ -19,7 +18,7 @@ function phaseTransitionEventType(fromPhase, toPhase) {
19
18
  }
20
19
 
21
20
  /**
22
- * @param {object} params
21
+ * @param {{ projectRoot: string, batchId: string, fromPhase: string, toPhase: string, extra?: Record<string, unknown> }} params
23
22
  */
24
23
  function recordPhaseTransition({ projectRoot, batchId, fromPhase, toPhase, extra = {} }) {
25
24
  const type = phaseTransitionEventType(fromPhase, toPhase);
@@ -31,6 +30,13 @@ function recordPhaseTransition({ projectRoot, batchId, fromPhase, toPhase, extra
31
30
  });
32
31
  }
33
32
 
33
+ /**
34
+ * Mutate `state.phase` and journal the transition (SP-770).
35
+ *
36
+ * @param {Record<string, any>} state Batch state mutated in place.
37
+ * @param {string} newPhase
38
+ * @param {{ projectRoot: string, batchId: string, extra?: Record<string, unknown> }} ctx
39
+ */
34
40
  export function transitionPhase(state, newPhase, ctx) {
35
41
  const fromPhase = state.phase;
36
42
  if (fromPhase === newPhase) return;
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Lane queue and provisioning — build lane/task state from plan and handle
4
3
  * per-lane task prep (file scope) plus skip-when-done-on-disk queue behavior.
@@ -20,20 +19,28 @@ import { laneTaskBranch, laneWorktreePath } from "../worktree.mjs";
20
19
 
21
20
  /**
22
21
  * @param {object} params
22
+ * @param {string} params.projectRoot
23
+ * @param {string} params.batchId
24
+ * @param {Record<string, any>} params.task
25
+ * @param {Record<string, any>} [params.config]
26
+ * @param {string} [params.taskFolder]
27
+ * @param {{ laneNumber?: number }} [params.lane]
23
28
  */
24
29
  export function recordLaneTaskMetric({ projectRoot, batchId, task, config, taskFolder, lane }) {
25
- recordTaskTerminalMetric({
30
+ const metricParams = {
26
31
  projectRoot,
27
32
  batchId,
28
33
  task,
29
34
  config,
30
35
  taskFolder,
31
36
  laneNumber: lane?.laneNumber ?? task?.laneNumber,
32
- });
37
+ };
38
+ recordTaskTerminalMetric(metricParams);
33
39
  }
34
40
 
35
41
  /**
36
42
  * @param {string} taskFolderPath
43
+ * @returns {{ ok: true, fileScopePaths: string[] } | { ok: false, error: string, errors?: string[], promptPath: string }}
37
44
  */
38
45
  export function loadTaskFileScopePaths(taskFolderPath) {
39
46
  try {
@@ -58,6 +65,15 @@ export function loadTaskFileScopePaths(taskFolderPath) {
58
65
 
59
66
  /**
60
67
  * @param {object} params
68
+ * @param {string} params.projectRoot
69
+ * @param {Record<string, any>} params.state
70
+ * @param {string} params.batchId
71
+ * @param {Record<string, any>} params.task
72
+ * @param {{ laneNumber?: number, laneId?: string }} params.lane
73
+ * @param {string} [params.laneCorrelationId]
74
+ * @param {{ ok: false, error: string, errors?: string[], promptPath?: string }} params.scopeResult
75
+ * @param {Record<string, any>} [params.config]
76
+ * @param {string} [params.taskFolderPath]
61
77
  */
62
78
  export function recordPromptParseFailure({
63
79
  projectRoot,
@@ -122,9 +138,15 @@ export function recordPromptParseFailure({
122
138
 
123
139
  /**
124
140
  * @param {object} params
141
+ * @param {any} params.plan
142
+ * @param {Array<{ taskId: string, folderPath?: string }>} params.discovered
143
+ * @param {string} params.projectRoot
144
+ * @param {string} params.batchId
145
+ * @param {number} params.maxLaneNumber
125
146
  */
126
147
  export function buildTasksAndLanesFromPlan({ plan, discovered, projectRoot, batchId, maxLaneNumber }) {
127
148
  const assignments = buildTaskLaneAssignments(plan);
149
+ /** @type {string[]} */
128
150
  const taskIds = countPlanTasks(plan);
129
151
 
130
152
  /** @type {Record<number, string[]>} */
@@ -166,6 +188,14 @@ export function buildTasksAndLanesFromPlan({ plan, discovered, projectRoot, batc
166
188
 
167
189
  /**
168
190
  * @param {object} params
191
+ * @param {string} params.projectRoot
192
+ * @param {Record<string, any>} params.state
193
+ * @param {string} params.batchId
194
+ * @param {Record<string, any>} params.task
195
+ * @param {{ laneNumber?: number, laneId?: string }} params.lane
196
+ * @param {string} params.taskFolderPath
197
+ * @param {string} [params.laneCorrelationId]
198
+ * @param {Record<string, any>} [params.config]
169
199
  */
170
200
  export function skipTaskDoneOnDisk({
171
201
  projectRoot,
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane code review phase (SP-729 / #262).
4
3
  */
@@ -30,6 +29,13 @@ import {
30
29
 
31
30
  /**
32
31
  * @param {object} params
32
+ * @param {string} params.taskFolder
33
+ * @param {string} params.worktreePath
34
+ * @param {Record<string, any>} [params.config]
35
+ * @param {number} [params.attempt]
36
+ * @param {Record<string, any>} [params.journal]
37
+ * @param {{ next: () => string } | null} [params.stubVerdicts]
38
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
33
39
  */
34
40
  export async function runEngineCodeReview({
35
41
  taskFolder,
@@ -112,6 +118,17 @@ export async function runEngineCodeReview({
112
118
 
113
119
  /**
114
120
  * @param {object} params
121
+ * @param {string} params.projectRoot
122
+ * @param {Record<string, any>} params.state
123
+ * @param {string} params.batchId
124
+ * @param {Record<string, any>} params.task
125
+ * @param {Record<string, any>} params.lane
126
+ * @param {string} params.laneCorrelationId
127
+ * @param {string} params.exitReason
128
+ * @param {string|null} params.verdict
129
+ * @param {number} params.codeReviewAttempt
130
+ * @param {Record<string, any>} params.config
131
+ * @param {string} params.taskFolder
115
132
  */
116
133
  function recordCodeReviewTaskFailure({
117
134
  projectRoot,
@@ -154,7 +171,14 @@ function recordCodeReviewTaskFailure({
154
171
  }
155
172
 
156
173
  /**
157
- * @param {object} params
174
+ * Params: projectRoot, state, batchId, config, task, lane,
175
+ * taskFolderInWorktree, wt, taskBranch, laneCorrelationId, fileScopePaths.
176
+ * Loosely typed because callers may forward a shared params bag
177
+ * (resume-lane-reviews.mjs) — same `Record<string, any>` pattern as
178
+ * state-guards.mjs.
179
+ *
180
+ * @param {Record<string, any>} params
181
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
158
182
  */
159
183
  export async function runCodeReviewPhase({
160
184
  projectRoot,
@@ -205,7 +229,8 @@ export async function runCodeReviewPhase({
205
229
  attemptField: "codeReviewAttempts",
206
230
  attemptKey: "codeReviewAttempt",
207
231
  maxAttempts: maxCodeReviewAttempts,
208
- runEngineReview: (params) => runEngineCodeReview({ ...params, stubVerdicts }),
232
+ runEngineReview: (params) =>
233
+ runEngineCodeReview(/** @type {any} */ ({ ...params, stubVerdicts })),
209
234
  recordReviewTaskFailure: recordCodeReviewTaskFailure,
210
235
  invalidVerdictOutput: "code review artifact missing APPROVE or REVISE verdict",
211
236
  journalEvents,
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane final review phase (SP-729 / #262).
4
3
  */
@@ -39,6 +38,14 @@ import {
39
38
 
40
39
  /**
41
40
  * @param {object} params
41
+ * @param {string} params.taskFolder
42
+ * @param {string} params.worktreePath
43
+ * @param {Record<string, any>} [params.config]
44
+ * @param {number} [params.attempt]
45
+ * @param {any} [params.contractVerifyResult]
46
+ * @param {Record<string, any>} [params.journal]
47
+ * @param {{ next: () => string } | null} [params.stubVerdicts]
48
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
42
49
  */
43
50
  export async function runEngineFinalReview({
44
51
  taskFolder,
@@ -103,6 +110,15 @@ export async function runEngineFinalReview({
103
110
 
104
111
  /**
105
112
  * @param {object} params
113
+ * @param {string} params.projectRoot
114
+ * @param {Record<string, any>} params.state
115
+ * @param {string} params.batchId
116
+ * @param {Record<string, any>} params.task
117
+ * @param {Record<string, any>} params.lane
118
+ * @param {string} params.laneCorrelationId
119
+ * @param {any} params.contractVerifyResult
120
+ * @param {Record<string, any>} params.config
121
+ * @param {string} params.taskFolder
106
122
  */
107
123
  function recordContractVerifyTaskFailure({
108
124
  projectRoot,
@@ -153,6 +169,17 @@ function recordContractVerifyTaskFailure({
153
169
 
154
170
  /**
155
171
  * @param {object} params
172
+ * @param {string} params.projectRoot
173
+ * @param {Record<string, any>} params.state
174
+ * @param {string} params.batchId
175
+ * @param {Record<string, any>} params.task
176
+ * @param {Record<string, any>} params.lane
177
+ * @param {string} params.laneCorrelationId
178
+ * @param {string} params.exitReason
179
+ * @param {string|null} params.verdict
180
+ * @param {number} params.finalAttempt
181
+ * @param {Record<string, any>} params.config
182
+ * @param {string} params.taskFolder
156
183
  */
157
184
  function recordFinalReviewTaskFailure({
158
185
  projectRoot,
@@ -195,7 +222,15 @@ function recordFinalReviewTaskFailure({
195
222
  }
196
223
 
197
224
  /**
198
- * @param {object} params
225
+ * Params: projectRoot, state, batchId, config, task, lane,
226
+ * taskFolderInWorktree, wt, taskBranch, laneCorrelationId, fileScopePaths,
227
+ * baseBranch.
228
+ * Loosely typed because callers may forward a shared params bag
229
+ * (resume-lane-reviews.mjs) — same `Record<string, any>` pattern as
230
+ * state-guards.mjs.
231
+ *
232
+ * @param {Record<string, any>} params
233
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
199
234
  */
200
235
  export async function runFinalReviewPhase({
201
236
  projectRoot,
@@ -248,7 +283,8 @@ export async function runFinalReviewPhase({
248
283
  attemptField: "finalAttempts",
249
284
  attemptKey: "finalAttempt",
250
285
  maxAttempts: maxFinalAttempts,
251
- runEngineReview: (params) => runEngineFinalReview({ ...params, stubVerdicts }),
286
+ runEngineReview: (params) =>
287
+ runEngineFinalReview(/** @type {any} */ ({ ...params, stubVerdicts })),
252
288
  recordReviewTaskFailure: recordFinalReviewTaskFailure,
253
289
  invalidVerdictOutput: "final review artifact missing PASS, REVISE, or REPLAN verdict",
254
290
  allowReplan: true,
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane plan review phase (SP-730 / #262).
4
3
  */
@@ -57,7 +56,7 @@ function findPlanReviewStepNumber(taskFolder) {
57
56
  *
58
57
  * @param {object} params
59
58
  * @param {string} params.taskFolder
60
- * @param {object[]} [params.journalEvents]
59
+ * @param {Array<Record<string, any>>} [params.journalEvents]
61
60
  * @param {string} [params.taskId]
62
61
  * @returns {{ verdict: "APPROVE"|"REVISE", feedback: string, artifactPath: string, source: "journal"|"artifact" }|null}
63
62
  */
@@ -93,7 +92,9 @@ function findCompletedPlanReview({ taskFolder, journalEvents = [], taskId }) {
93
92
  const { verdict, feedback } = parseReviewVerdict(reviewContent, { reviewType: "plan" });
94
93
  if (verdict) {
95
94
  const artifactMatch = {
96
- verdict,
95
+ // Narrowed by the `if (verdict)` guard above; parseReviewVerdict's
96
+ // union spans code/final verdicts, so cast to the plan verdict set.
97
+ verdict: /** @type {"APPROVE"|"REVISE"} */ (verdict),
97
98
  feedback,
98
99
  artifactPath: latestArtifact.artifactPath,
99
100
  source: /** @type {"artifact"} */ ("artifact"),
@@ -113,6 +114,13 @@ function findCompletedPlanReview({ taskFolder, journalEvents = [], taskId }) {
113
114
  * Uses agents.reviewer.plan pins via runStepReview → buildReviewerPiArgs (SP-695 / #250).
114
115
  *
115
116
  * @param {object} params
117
+ * @param {string} params.taskFolder
118
+ * @param {string} params.worktreePath
119
+ * @param {Record<string, any>} [params.config]
120
+ * @param {number} [params.attempt]
121
+ * @param {Record<string, any>} [params.journal]
122
+ * @param {{ next: () => string } | null} [params.stubVerdicts]
123
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
116
124
  */
117
125
  export async function runEnginePlanReview({
118
126
  taskFolder,
@@ -195,6 +203,17 @@ export async function runEnginePlanReview({
195
203
 
196
204
  /**
197
205
  * @param {object} params
206
+ * @param {string} params.projectRoot
207
+ * @param {Record<string, any>} params.state
208
+ * @param {string} params.batchId
209
+ * @param {Record<string, any>} params.task
210
+ * @param {Record<string, any>} params.lane
211
+ * @param {string} params.laneCorrelationId
212
+ * @param {string} params.exitReason
213
+ * @param {string|null} params.verdict
214
+ * @param {number} params.planReviewAttempt
215
+ * @param {Record<string, any>} params.config
216
+ * @param {string} params.taskFolder
198
217
  */
199
218
  function recordPlanReviewTaskFailure({
200
219
  projectRoot,
@@ -242,7 +261,14 @@ function recordPlanReviewTaskFailure({
242
261
  * existing plan artifact/journal verdict, rework loop on REVISE, fail-closed
243
262
  * on exhaustion or invalid verdict.
244
263
  *
245
- * @param {object} params
264
+ * Params: projectRoot, state, batchId, config, task, lane,
265
+ * taskFolderInWorktree, wt, taskBranch, laneCorrelationId, fileScopePaths.
266
+ * Loosely typed because callers may forward a shared params bag
267
+ * (resume-lane-reviews.mjs) — same `Record<string, any>` pattern as
268
+ * state-guards.mjs.
269
+ *
270
+ * @param {Record<string, any>} params
271
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
246
272
  */
247
273
  export async function runPlanReviewPhase({
248
274
  projectRoot,
@@ -296,7 +322,8 @@ export async function runPlanReviewPhase({
296
322
  attemptField: "planReviewAttempts",
297
323
  attemptKey: "planReviewAttempt",
298
324
  maxAttempts: maxPlanReviewAttempts,
299
- runEngineReview: (params) => runEnginePlanReview({ ...params, stubVerdicts }),
325
+ runEngineReview: (params) =>
326
+ runEnginePlanReview(/** @type {any} */ ({ ...params, stubVerdicts })),
300
327
  recordReviewTaskFailure: recordPlanReviewTaskFailure,
301
328
  invalidVerdictOutput: "plan review artifact missing APPROVE or REVISE verdict",
302
329
  journalEvents,
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Shared review poll-loop mechanics for the engine lane review phases
4
3
  * (SP-727 / #262). Extracted from review.mjs so the plan, code, and final
@@ -38,12 +37,12 @@ export function removeDoneFile(taskFolder) {
38
37
  * @param {object} params
39
38
  * @param {string} params.projectRoot
40
39
  * @param {string} params.batchId
41
- * @param {object} params.task
42
- * @param {object} params.lane
40
+ * @param {Record<string, any>} params.task
41
+ * @param {Record<string, any>} params.lane
43
42
  * @param {string} params.laneCorrelationId
44
43
  * @param {"plan"|"code"|"final"} params.reviewType
45
44
  * @param {number} params.reviewAttempt
46
- * @param {object} params.honored
45
+ * @param {Record<string, any>} params.honored
47
46
  * @param {"review.crash_recovered"|"review.skipped_fresh_artifact"|null} params.honorJournalEvent
48
47
  */
49
48
  export function appendReviewHonorJournalEvents({
@@ -105,6 +104,15 @@ export function appendReviewHonorJournalEvents({
105
104
  * @param {string} params.attemptField Task state field, e.g. "codeReviewAttempts".
106
105
  * @param {string} params.attemptKey Journal payload key, e.g. "codeReviewAttempt".
107
106
  * @param {Function} params.findCompletedReview ({ taskFolder, journalEvents, taskId }) => honored|null
107
+ * @param {string} params.projectRoot
108
+ * @param {Record<string, any>} params.state
109
+ * @param {string} params.batchId
110
+ * @param {Record<string, any>} params.task
111
+ * @param {Record<string, any>} params.lane
112
+ * @param {string} params.laneCorrelationId
113
+ * @param {string} params.taskFolder
114
+ * @param {Array<Record<string, any>>} params.journalEvents
115
+ * @returns {{ ok: boolean, [key: string]: any } | null}
108
116
  */
109
117
  export function honorCompletedReview({
110
118
  reviewType,
@@ -130,7 +138,9 @@ export function honorCompletedReview({
130
138
  const honorJournalEvent = resolveReviewHonorJournalEvent({
131
139
  journalEvents,
132
140
  taskId,
133
- reviewType,
141
+ // review-artifacts.mjs predates the plan phase and still narrows the
142
+ // JSDoc to "code"|"final"; its body treats all three types alike.
143
+ reviewType: /** @type {"code"|"final"} */ (reviewType),
134
144
  honorSource: honored.source,
135
145
  reviewAttempt,
136
146
  });
@@ -178,12 +188,25 @@ export function honorCompletedReview({
178
188
  * @param {string} params.attemptField Task state field, e.g. "codeReviewAttempts".
179
189
  * @param {string} params.attemptKey Journal payload key, e.g. "codeReviewAttempt".
180
190
  * @param {number} params.maxAttempts
181
- * @param {Function} params.runEngineReview Async engine review fn (e.g. runEngineCodeReview).
191
+ * @param {(reviewParams: Record<string, any>) => any} params.runEngineReview Async engine review fn (e.g. runEngineCodeReview).
182
192
  * @param {Function} params.recordReviewTaskFailure Phase-specific failure recorder.
183
193
  * @param {string} params.invalidVerdictOutput Output message for the invalid-verdict failure.
184
194
  * @param {boolean} [params.allowReplan] Final phase only: handle REPLAN as needs_replan.
185
- * @param {Function} [params.beforeReview] Async hook per iteration; returns
195
+ * @param {((hookParams: { attempt: number }) => Promise<{ abort?: any, extraReviewParams?: Record<string, any> } | undefined>) | null} [params.beforeReview] Async hook per iteration; returns
186
196
  * { abort: result } to stop the loop or { extraReviewParams: object } to continue.
197
+ * @param {Array<Record<string, any>>} params.journalEvents
198
+ * @param {string} params.projectRoot
199
+ * @param {Record<string, any>} params.state
200
+ * @param {string} params.batchId
201
+ * @param {Record<string, any>} params.config
202
+ * @param {Record<string, any>} params.task
203
+ * @param {Record<string, any>} params.lane
204
+ * @param {string} params.taskFolderInWorktree
205
+ * @param {string} params.wt
206
+ * @param {string} params.taskBranch
207
+ * @param {string} params.laneCorrelationId
208
+ * @param {string[]} params.fileScopePaths
209
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
187
210
  */
188
211
  export async function runReviewPollLoop({
189
212
  reviewType,
@@ -355,7 +378,7 @@ export async function runReviewPollLoop({
355
378
  }
356
379
 
357
380
  removeDoneFile(taskFolderInWorktree);
358
- const reworkResult = await runWorker({
381
+ const reworkResult = /** @type {any} */ (await runWorker({
359
382
  worktreePath: wt,
360
383
  taskFolder: taskFolderInWorktree,
361
384
  projectRoot,
@@ -376,7 +399,7 @@ export async function runReviewPollLoop({
376
399
  saveSpineBatchState(projectRoot, state);
377
400
  }
378
401
  },
379
- });
402
+ }));
380
403
  if (!reworkResult.ok) {
381
404
  const aborted = reworkResult.classification === "aborted";
382
405
  task.status = aborted ? "aborted" : "failed";
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane review stub verdict queues (SP-728 / #262).
4
3
  *
@@ -69,7 +68,7 @@ export function createStubVerdictQueue({ queueValue, singleValue, normalize, def
69
68
  * @param {string} params.singleEnv Env var holding the single-verdict fallback.
70
69
  * @param {(raw: string) => string|null} params.normalize Verdict normalizer.
71
70
  * @param {string} params.defaultVerdict Fallback when nothing else resolves.
72
- * @param {NodeJS.ProcessEnv} [env]
71
+ * @param {NodeJS.ProcessEnv} [params.env]
73
72
  */
74
73
  export function createStubVerdictQueueFromEnv({
75
74
  queueEnv,
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Engine lane review-phase coordinator — re-exports phase modules (SP-729/730 / #262).
4
3
  */
@@ -1,4 +1,3 @@
1
- // @ts-nocheck
2
1
  /**
3
2
  * Lane task execution facade — re-exports split modules and phase transitions.
4
3
  *
@@ -90,6 +89,22 @@ export { runMatrixTaskOnLane, runMatrixSubLane } from "./engine-lanes/matrix-run
90
89
 
91
90
  export { transitionPhase } from "./engine-lanes/phase.mjs";
92
91
 
92
+ /**
93
+ * Run one task on its lane: file-scope load, matrix fan-out, or the single
94
+ * worker path (SP-770 typing).
95
+ *
96
+ * @param {object} params
97
+ * @param {string} params.projectRoot
98
+ * @param {Record<string, any>} params.state
99
+ * @param {string} params.batchId
100
+ * @param {string} [params.baseBranch]
101
+ * @param {Record<string, any>} params.config
102
+ * @param {Record<string, any>} params.task
103
+ * @param {Record<string, any>} params.lane
104
+ * @param {string} params.taskFolderRel
105
+ * @param {string} params.laneCorrelationId
106
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
107
+ */
93
108
  export async function runTaskOnLane({
94
109
  projectRoot,
95
110
  state,
@@ -125,7 +140,8 @@ export async function runTaskOnLane({
125
140
  // global in-flight workers never exceed `lanes.maxParallel`.
126
141
  const matrixRows = loadMatrixTaskRows(path.join(projectRoot, taskFolderRel));
127
142
  if (matrixRows) {
128
- return runMatrixTaskOnLane({
143
+ /** @type {{ maxParallel: number } & Record<string, any>} */
144
+ const matrixParams = {
129
145
  projectRoot,
130
146
  state,
131
147
  batchId,
@@ -138,7 +154,8 @@ export async function runTaskOnLane({
138
154
  fileScopePaths,
139
155
  matrix: matrixRows,
140
156
  maxParallel: config?.lanes?.maxParallel ?? 1,
141
- });
157
+ };
158
+ return runMatrixTaskOnLane(matrixParams);
142
159
  }
143
160
 
144
161
  const laneSlot = await acquireLaneSlot(state, config?.lanes?.maxParallel ?? 1);
@@ -165,6 +182,17 @@ export async function runTaskOnLane({
165
182
  * for the duration of this call.
166
183
  *
167
184
  * @param {object} params
185
+ * @param {string} params.projectRoot
186
+ * @param {Record<string, any>} params.state
187
+ * @param {string} params.batchId
188
+ * @param {string} [params.baseBranch]
189
+ * @param {Record<string, any>} params.config
190
+ * @param {Record<string, any>} params.task
191
+ * @param {Record<string, any>} params.lane
192
+ * @param {string} params.taskFolderRel
193
+ * @param {string} params.laneCorrelationId
194
+ * @param {string[]} params.fileScopePaths
195
+ * @returns {Promise<{ ok: boolean, [key: string]: any }>}
168
196
  */
169
197
  async function runNonMatrixTaskOnLane({
170
198
  projectRoot,
@@ -256,7 +284,7 @@ async function runNonMatrixTaskOnLane({
256
284
  correlationId: laneCorrelationId,
257
285
  });
258
286
 
259
- const workerResult = await runWorker({
287
+ const workerResult = /** @type {any} */ (await runWorker({
260
288
  worktreePath: wt,
261
289
  taskFolder: taskFolderInWorktree,
262
290
  projectRoot,
@@ -277,7 +305,7 @@ async function runNonMatrixTaskOnLane({
277
305
  saveEngineBatchState(projectRoot, state);
278
306
  }
279
307
  },
280
- });
308
+ }));
281
309
 
282
310
  if (!workerResult.ok) {
283
311
  const doneOnDisk = fs.existsSync(path.join(taskFolderInWorktree, ".DONE"));