pi-spine 2.11.0 → 2.12.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.mjs +1 -1
- package/package.json +2 -2
- package/skills/spine-orchestrate-waves/SKILL.md +2 -0
- package/skills/spine-release-operator/SKILL.md +2 -0
- package/src/batch/diagnosis.mjs +3 -3
- package/src/batch/engine-lanes/matrix-run.mjs +62 -0
- package/src/batch/engine-lanes/matrix.mjs +87 -1
- package/src/batch/engine-lanes.mjs +13 -3
- package/src/batch/reconcile-diagnosis.mjs +15 -0
- package/src/metrics/quota-cli.mjs +21 -3
- package/src/planner/lanes.mjs +10 -141
package/bin/spine.mjs
CHANGED
|
@@ -216,7 +216,7 @@ async function cmdMetrics(args) {
|
|
|
216
216
|
|
|
217
217
|
if (sub === "quota") {
|
|
218
218
|
const { runQuotaReport } = await import("../src/metrics/quota-cli.mjs");
|
|
219
|
-
const result = runQuotaReport({ projectRoot: process.cwd(), args: args.slice(1) });
|
|
219
|
+
const result = await runQuotaReport({ projectRoot: process.cwd(), args: args.slice(1) });
|
|
220
220
|
process.stdout.write(result.output);
|
|
221
221
|
if (result.exitCode !== 0) process.exit(result.exitCode);
|
|
222
222
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-spine",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.12.1",
|
|
4
4
|
"description": "Orchestration spine for long-running pi development",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"typecheck": "tsc --project tsconfig.json --noEmit && tsc --project tsconfig.batch.json --noEmit",
|
|
35
35
|
"verify:reconcile-fixtures": "node scripts/verify-reconcile-test-fixtures.mjs",
|
|
36
36
|
"pretest": "npm run verify:reconcile-fixtures",
|
|
37
|
-
"test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
|
|
37
|
+
"test": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/batch/*.test.mjs tests/metrics/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/init/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs tests/extensions/*.test.mjs",
|
|
38
38
|
"test:batch": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/batch/*.test.mjs",
|
|
39
39
|
"test:core": "SPINE_SUPPRESS_JOURNAL_ATTACH=1 node --experimental-strip-types --test tests/*.test.mjs tests/cli/*.test.mjs tests/compat/*.test.mjs tests/tasks/*.test.mjs tests/config/*.test.mjs tests/config/cursor-rules/*.test.mjs tests/planner/*.test.mjs tests/agents/*.test.mjs tests/adoption/*.test.mjs tests/dashboard/*.test.mjs tests/doctor/*.test.mjs tests/migrate/*.test.mjs tests/worker-tools/*.test.mjs tests/coverage/*.test.mjs",
|
|
40
40
|
"test:coverage": "node scripts/run-coverage.mjs --report-only",
|
|
@@ -117,6 +117,8 @@ git push origin <baseBranch> # when remote sync desired
|
|
|
117
117
|
|
|
118
118
|
Increment `WAVE` and repeat until `spine plan pending` shows no remaining waves.
|
|
119
119
|
|
|
120
|
+
> **Wait recipe note:** With SP-683, gate-pending land loops report the taxonomy diagnosis `needs_integrate`, so the default `--until` list above wakes on that diagnosis. The operator runbook documents optional land-loop pseudo-diagnoses (`gate_open`, `needs_approval`, `post_merge_limbo`) as belt-and-suspenders waits when you need finer-grained blocking inside the land loop itself.
|
|
121
|
+
|
|
120
122
|
**Optional script template:** `spine run sequence pending --attached --dry-run` — execute each printed block with judgment; do **not** chain `--auto-approve-gate` with real pi workers.
|
|
121
123
|
|
|
122
124
|
Full reference: [references/outer-loop.md](references/outer-loop.md).
|
|
@@ -294,6 +294,8 @@ spine wait --until completed,failed,needs_integrate,needs_retry,aborted --timeou
|
|
|
294
294
|
|
|
295
295
|
Optional pi watchdog: `LoopCreate` every 2m, `readOnly: true`, `maxFires: 50` — see pi-async-orchestration.
|
|
296
296
|
|
|
297
|
+
> **Wait recipe note:** With SP-683, gate-pending land loops report the taxonomy diagnosis `needs_integrate`, so the default `--until` lists above wake on that diagnosis. The operator runbook documents optional land-loop pseudo-diagnoses (`gate_open`, `needs_approval`, `post_merge_limbo`) as belt-and-suspenders waits when you need finer-grained blocking inside the land loop itself.
|
|
298
|
+
|
|
297
299
|
**Do not** start wave N+1 until wave N is integrated on `main`.
|
|
298
300
|
|
|
299
301
|
Wave sizing: prefer ≤4 M-sized tasks per wave; serialize hot shared files.
|
package/src/batch/diagnosis.mjs
CHANGED
|
@@ -232,10 +232,10 @@ export function buildSuggestedCommand(diagnosis, ctx = {}) {
|
|
|
232
232
|
case "needs_merge":
|
|
233
233
|
return "spine batch resume --force";
|
|
234
234
|
case "needs_integrate":
|
|
235
|
+
if (ctx.integrateGateOpen) {
|
|
236
|
+
return "spine gate approve";
|
|
237
|
+
}
|
|
235
238
|
if (ctx.postMergeLimbo && ctx.phase === "running") {
|
|
236
|
-
if (ctx.integrateGateOpen) {
|
|
237
|
-
return "spine gate approve";
|
|
238
|
-
}
|
|
239
239
|
if (ctx.stalePathSpine) {
|
|
240
240
|
return "node bin/spine.mjs batch resume --attached";
|
|
241
241
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
recordMatrixEvent,
|
|
14
14
|
removeMatrixSubLaneWorktree,
|
|
15
15
|
runConcurrent,
|
|
16
|
+
runMatrixSubLaneSetupHook,
|
|
16
17
|
runShellInDir,
|
|
17
18
|
substituteRowCommand,
|
|
18
19
|
} from "./matrix.mjs";
|
|
@@ -32,6 +33,32 @@ import { parseContract } from "../../tasks/packet/parse-prompt.mjs";
|
|
|
32
33
|
import { verifyContract } from "../contract-verify.mjs";
|
|
33
34
|
import { gitExec } from "../git-exec.mjs";
|
|
34
35
|
|
|
36
|
+
/**
|
|
37
|
+
* SP-690 / #227 — interim throttle for nested matrix row concurrency.
|
|
38
|
+
*
|
|
39
|
+
* A matrix task runs ON a lane the batch has already counted against
|
|
40
|
+
* `lanes.maxParallel`. While that parent lane is held, the rows it fans out
|
|
41
|
+
* must not reuse the parent's slot — otherwise global in-flight workers
|
|
42
|
+
* (sibling lane workers + matrix rows) can exceed `lanes.maxParallel`.
|
|
43
|
+
*
|
|
44
|
+
* Caps the rows to the remaining free slots: `max(1, globalMaxParallel -
|
|
45
|
+
* occupiedLaneSlots)`, never below 1 so a matrix task always makes forward
|
|
46
|
+
* progress. `occupiedLaneSlots` defaults to 1 (the parent matrix lane).
|
|
47
|
+
*
|
|
48
|
+
* This is an interim invariant. First-class row scheduling (#228) supersedes
|
|
49
|
+
* it by scheduling rows as real lane occupants instead of nested workers,
|
|
50
|
+
* which also closes the concurrent-sibling edge case for `maxParallel > 2`.
|
|
51
|
+
*
|
|
52
|
+
* @param {number} globalMaxParallel Configured `lanes.maxParallel`.
|
|
53
|
+
* @param {number} [occupiedLaneSlots] Lane slots already in use (≥ 1: the parent).
|
|
54
|
+
* @returns {number} Row concurrency limit, at least 1.
|
|
55
|
+
*/
|
|
56
|
+
export function matrixRowConcurrencyLimit(globalMaxParallel, occupiedLaneSlots = 1) {
|
|
57
|
+
const max = Math.max(1, Math.floor(Number(globalMaxParallel) || 1));
|
|
58
|
+
const occupied = Math.max(0, Math.floor(Number(occupiedLaneSlots) || 0));
|
|
59
|
+
return Math.max(1, max - occupied);
|
|
60
|
+
}
|
|
61
|
+
|
|
35
62
|
/**
|
|
36
63
|
* Read the `## Contract` table from a parent task folder (un-substituted).
|
|
37
64
|
*
|
|
@@ -103,6 +130,41 @@ export async function runMatrixSubLane({
|
|
|
103
130
|
worktreePath,
|
|
104
131
|
});
|
|
105
132
|
|
|
133
|
+
// Mirror the parent-lane provision→hook sequence: the row worktree is freshly
|
|
134
|
+
// provisioned off the lane branch, so gitignored toolchains/assets (e.g.
|
|
135
|
+
// `.venv`) that the row's runCommand depends on are absent until the hook
|
|
136
|
+
// links them in. Fail closed on hook failure so the row reports the missing
|
|
137
|
+
// setup rather than masking it as a runCommand failure (#224).
|
|
138
|
+
try {
|
|
139
|
+
runMatrixSubLaneSetupHook({
|
|
140
|
+
projectRoot,
|
|
141
|
+
worktreePath,
|
|
142
|
+
batchId,
|
|
143
|
+
laneNumber,
|
|
144
|
+
taskId,
|
|
145
|
+
rowId,
|
|
146
|
+
correlationId: laneCorrelationId,
|
|
147
|
+
config,
|
|
148
|
+
});
|
|
149
|
+
} catch (err) {
|
|
150
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
151
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.failed", {
|
|
152
|
+
taskId,
|
|
153
|
+
laneNumber,
|
|
154
|
+
rowId,
|
|
155
|
+
correlationId: laneCorrelationId,
|
|
156
|
+
error: `setup hook failed: ${message}`,
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
rowId,
|
|
160
|
+
ok: false,
|
|
161
|
+
exitCode: 1,
|
|
162
|
+
output: `worktree setup hook failed: ${message}`,
|
|
163
|
+
worktreePath,
|
|
164
|
+
branch,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
106
168
|
/** @type {{ rowId: string, ok: boolean, exitCode: number, output: string, worktreePath?: string, branch?: string }} */
|
|
107
169
|
let result;
|
|
108
170
|
|
|
@@ -23,7 +23,11 @@ import {
|
|
|
23
23
|
substituteMatrixVariables,
|
|
24
24
|
} from "../../planner/matrix.mjs";
|
|
25
25
|
import { gitExec } from "../git-exec.mjs";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
normalizeLaneWorktreeGitPaths,
|
|
28
|
+
runWorktreeSetupHook,
|
|
29
|
+
} from "../worktree.mjs";
|
|
30
|
+
import { resolveWorktreeSetupHook } from "../../config/worktree-setup-hook.mjs";
|
|
27
31
|
import { appendJournalEvent } from "../journal.mjs";
|
|
28
32
|
|
|
29
33
|
/**
|
|
@@ -147,6 +151,88 @@ export function provisionMatrixSubLaneWorktree({
|
|
|
147
151
|
return { worktreePath, branch };
|
|
148
152
|
}
|
|
149
153
|
|
|
154
|
+
/**
|
|
155
|
+
* Run the configured `worktreeSetupHook` for a matrix sub-lane worktree, mirroring
|
|
156
|
+
* the parent-lane provision→hook sequence (SP-688 / #224).
|
|
157
|
+
*
|
|
158
|
+
* Each matrix row runs in its own freshly-provisioned worktree, so gitignored
|
|
159
|
+
* toolchains (e.g. `.venv`) and symlinked assets that live on the main checkout
|
|
160
|
+
* would be absent there — the hook links them in before the row's runCommand /
|
|
161
|
+
* worker executes. Without this, rows that depend on those assets fail in ways
|
|
162
|
+
* that never reproduce on a parent lane, masking the missing setup.
|
|
163
|
+
*
|
|
164
|
+
* Journals `matrix.sub_lane.setup_hook.*` lifecycle events. When a hook is
|
|
165
|
+
* configured it runs with the same env (SPINE_PROJECT_ROOT / SPINE_WORKTREE /
|
|
166
|
+
* SPINE_BATCH_ID / SPINE_LANE_NUMBER) and JSON-stdout contract as parent lanes.
|
|
167
|
+
* On hook failure it rethrows so the caller surfaces the failure on the matrix
|
|
168
|
+
* row (fail closed — never silently continue into runCommand). When no hook is
|
|
169
|
+
* configured it is a no-op (skipped).
|
|
170
|
+
*
|
|
171
|
+
* @param {object} params
|
|
172
|
+
* @param {string} params.projectRoot
|
|
173
|
+
* @param {string} params.worktreePath
|
|
174
|
+
* @param {string} params.batchId
|
|
175
|
+
* @param {number} params.laneNumber
|
|
176
|
+
* @param {string} params.taskId
|
|
177
|
+
* @param {string} params.rowId
|
|
178
|
+
* @param {string} [params.correlationId]
|
|
179
|
+
* @param {object} [params.config]
|
|
180
|
+
* @returns {{ ok: boolean, skipped?: boolean, durationMs?: number }}
|
|
181
|
+
*/
|
|
182
|
+
export function runMatrixSubLaneSetupHook({
|
|
183
|
+
projectRoot,
|
|
184
|
+
worktreePath,
|
|
185
|
+
batchId,
|
|
186
|
+
laneNumber,
|
|
187
|
+
taskId,
|
|
188
|
+
rowId,
|
|
189
|
+
correlationId,
|
|
190
|
+
config = {},
|
|
191
|
+
}) {
|
|
192
|
+
const hookPath = resolveWorktreeSetupHook(projectRoot, config);
|
|
193
|
+
if (!hookPath) {
|
|
194
|
+
return { ok: true, skipped: true };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.started", {
|
|
198
|
+
taskId,
|
|
199
|
+
laneNumber,
|
|
200
|
+
rowId,
|
|
201
|
+
correlationId,
|
|
202
|
+
worktreePath,
|
|
203
|
+
hookPath,
|
|
204
|
+
});
|
|
205
|
+
try {
|
|
206
|
+
const hookResult = runWorktreeSetupHook({
|
|
207
|
+
projectRoot,
|
|
208
|
+
worktreePath,
|
|
209
|
+
batchId,
|
|
210
|
+
laneNumber,
|
|
211
|
+
config,
|
|
212
|
+
});
|
|
213
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.completed", {
|
|
214
|
+
taskId,
|
|
215
|
+
laneNumber,
|
|
216
|
+
rowId,
|
|
217
|
+
correlationId,
|
|
218
|
+
worktreePath,
|
|
219
|
+
durationMs: hookResult.durationMs,
|
|
220
|
+
});
|
|
221
|
+
return { ok: true, durationMs: hookResult.durationMs };
|
|
222
|
+
} catch (err) {
|
|
223
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
224
|
+
recordMatrixEvent(projectRoot, batchId, "matrix.sub_lane.setup_hook.failed", {
|
|
225
|
+
taskId,
|
|
226
|
+
laneNumber,
|
|
227
|
+
rowId,
|
|
228
|
+
correlationId,
|
|
229
|
+
worktreePath,
|
|
230
|
+
error: message,
|
|
231
|
+
});
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
150
236
|
/**
|
|
151
237
|
* Remove a matrix sub-lane worktree and its branch. Idempotent.
|
|
152
238
|
*
|
|
@@ -25,7 +25,7 @@ import { runCodeReviewPhase, runFinalReviewPhase } from "./engine-lanes/review.m
|
|
|
25
25
|
import { ensureLaneSyncedForSharedScopeDeps } from "./engine-lanes/orch-sync.mjs";
|
|
26
26
|
import { resolveWorktreeSetupIgnorePaths } from "../config/spine-config-load.mjs";
|
|
27
27
|
import { loadMatrixTaskRows } from "./engine-lanes/matrix.mjs";
|
|
28
|
-
import { runMatrixTaskOnLane } from "./engine-lanes/matrix-run.mjs";
|
|
28
|
+
import { runMatrixTaskOnLane, matrixRowConcurrencyLimit } from "./engine-lanes/matrix-run.mjs";
|
|
29
29
|
|
|
30
30
|
export {
|
|
31
31
|
buildTasksAndLanesFromPlan,
|
|
@@ -67,10 +67,11 @@ export {
|
|
|
67
67
|
removeAllMatrixSubLaneWorktrees,
|
|
68
68
|
removeMatrixSubLaneWorktree,
|
|
69
69
|
runConcurrent,
|
|
70
|
+
runMatrixSubLaneSetupHook,
|
|
70
71
|
runShellInDir,
|
|
71
72
|
} from "./engine-lanes/matrix.mjs";
|
|
72
73
|
|
|
73
|
-
export { runMatrixTaskOnLane, runMatrixSubLane } from "./engine-lanes/matrix-run.mjs";
|
|
74
|
+
export { runMatrixTaskOnLane, runMatrixSubLane, matrixRowConcurrencyLimit } from "./engine-lanes/matrix-run.mjs";
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
77
|
* @param {string} fromPhase
|
|
@@ -146,6 +147,15 @@ export async function runTaskOnLane({
|
|
|
146
147
|
// Non-matrix tasks fall through to the single-worker path below.
|
|
147
148
|
const matrixRows = loadMatrixTaskRows(path.join(projectRoot, taskFolderRel));
|
|
148
149
|
if (matrixRows) {
|
|
150
|
+
// SP-690 / #227: the parent matrix task already occupies this lane, so its
|
|
151
|
+
// nested rows must not reuse the parent's slot. Cap rows to the remaining
|
|
152
|
+
// free slots so global in-flight workers (siblings + rows) stay within
|
|
153
|
+
// `lanes.maxParallel`. Interim invariant — #228 first-class row scheduling
|
|
154
|
+
// supersedes it.
|
|
155
|
+
const matrixMaxParallel = matrixRowConcurrencyLimit(
|
|
156
|
+
config?.lanes?.maxParallel ?? 1,
|
|
157
|
+
1,
|
|
158
|
+
);
|
|
149
159
|
return runMatrixTaskOnLane({
|
|
150
160
|
projectRoot,
|
|
151
161
|
state,
|
|
@@ -158,7 +168,7 @@ export async function runTaskOnLane({
|
|
|
158
168
|
laneCorrelationId,
|
|
159
169
|
fileScopePaths,
|
|
160
170
|
matrix: matrixRows,
|
|
161
|
-
maxParallel:
|
|
171
|
+
maxParallel: matrixMaxParallel,
|
|
162
172
|
});
|
|
163
173
|
}
|
|
164
174
|
|
|
@@ -433,6 +433,21 @@ export function deriveDiagnosis(signals) {
|
|
|
433
433
|
return withFailureContext("paused", null, signals);
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
+
// Terminal-success land loop waiting for an integrate gate while the engine phase
|
|
437
|
+
// is still "running". Mark post-merge limbo so downstream suggestedCommand and
|
|
438
|
+
// macro-phase treat this as gate-ready rather than falling through to "running" (#221).
|
|
439
|
+
if (
|
|
440
|
+
RUNNING_PHASES.has(phase) &&
|
|
441
|
+
allTasksTerminalSuccess &&
|
|
442
|
+
git.orchBranchExists &&
|
|
443
|
+
!git.orchMergedToBase &&
|
|
444
|
+
!hasRunningTasks &&
|
|
445
|
+
!hasPendingTasks
|
|
446
|
+
) {
|
|
447
|
+
signals.postMergeLimbo = true;
|
|
448
|
+
return withFailureContext("needs_integrate", null, signals);
|
|
449
|
+
}
|
|
450
|
+
|
|
436
451
|
if (RUNNING_PHASES.has(phase) || hasRunningTasks || hasPendingTasks) {
|
|
437
452
|
return withFailureContext("running", null, signals);
|
|
438
453
|
}
|
|
@@ -15,6 +15,7 @@ import fs from "node:fs";
|
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
|
|
17
17
|
import { buildQuotaSnapshot } from "./quota-snapshot.mjs";
|
|
18
|
+
import { runQuotaProbes } from "./quota-probes.mjs";
|
|
18
19
|
import { renderQuotaHtml, writeHtmlBesideJson } from "./quota-html.mjs";
|
|
19
20
|
import { loadSpineConfig } from "../config/spine-config-load.mjs";
|
|
20
21
|
|
|
@@ -71,14 +72,23 @@ function formatHumanSummary(snapshot, reportPath) {
|
|
|
71
72
|
/**
|
|
72
73
|
* Run the `spine metrics quota` command.
|
|
73
74
|
*
|
|
75
|
+
* Optional provider probes are run before the snapshot is built so live usage
|
|
76
|
+
* can enrich a pool when credentials and the probe succeed. Probes fail closed
|
|
77
|
+
* to `absent` on missing credentials, network errors, or non-ok responses, so
|
|
78
|
+
* the snapshot degrades to estimate/absent rather than inventing limits or
|
|
79
|
+
* keys. The `authPath`/`fetch` params exist primarily for tests, which point
|
|
80
|
+
* `authPath` at a fixture and inject a mocked `fetch` instead of the network.
|
|
81
|
+
*
|
|
74
82
|
* @param {object} params
|
|
75
83
|
* @param {string} params.projectRoot
|
|
76
84
|
* @param {object} [params.config]
|
|
77
85
|
* @param {string[]} [params.args]
|
|
78
86
|
* @param {number | string | Date} [params.now]
|
|
79
|
-
* @
|
|
87
|
+
* @param {string} [params.authPath] Forwarded to `runQuotaProbes`.
|
|
88
|
+
* @param {typeof globalThis.fetch} [params.fetch] Forwarded to `runQuotaProbes`.
|
|
89
|
+
* @returns {Promise<{ output: string, exitCode: number, reportPath: string | null }>}
|
|
80
90
|
*/
|
|
81
|
-
export function runQuotaReport({ projectRoot, config, args = [], now = Date.now(), metricsLines }) {
|
|
91
|
+
export async function runQuotaReport({ projectRoot, config, args = [], now = Date.now(), metricsLines, authPath, fetch } = {}) {
|
|
82
92
|
const json = args.includes("--json");
|
|
83
93
|
const open = args.includes("--open");
|
|
84
94
|
|
|
@@ -95,7 +105,15 @@ export function runQuotaReport({ projectRoot, config, args = [], now = Date.now(
|
|
|
95
105
|
resolvedConfig = configResult.config;
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
// Production path: invoke provider probes so live usage can enrich pools.
|
|
109
|
+
// Adapters fail closed to "absent", so a missing/invalid auth file or network
|
|
110
|
+
// error leaves the snapshot at estimate/absent without inventing limits.
|
|
111
|
+
const probeOptions = {};
|
|
112
|
+
if (authPath !== undefined) probeOptions.authPath = authPath;
|
|
113
|
+
if (fetch !== undefined) probeOptions.fetch = fetch;
|
|
114
|
+
const probeResults = await runQuotaProbes(probeOptions);
|
|
115
|
+
|
|
116
|
+
const snapshot = buildQuotaSnapshot({ projectRoot, config: resolvedConfig, metricsLines, probeResults, now });
|
|
99
117
|
|
|
100
118
|
if (json) {
|
|
101
119
|
return {
|
package/src/planner/lanes.mjs
CHANGED
|
@@ -1,145 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* FR-SCHED-03/04: greedy lane assignment subject to file-scope disjointness.
|
|
3
|
+
*
|
|
4
|
+
* NOTE (SP-689 / issue #226): This module previously held a divergent copy of
|
|
5
|
+
* `assignLanesToWaves` whose overlap detection was directory-prefix only
|
|
6
|
+
* (normalizeFileScopePath + pathsOverlap). The production planner calls
|
|
7
|
+
* `planWaves` from `waves.mjs`, whose `assignLanesToWaves` uses the glob-aware
|
|
8
|
+
* `fileScopesOverlap` from `file-scope.mjs` — a strict superset of the logic
|
|
9
|
+
* that lived here. This module was imported only by tests, so the duplicate has
|
|
10
|
+
* been collapsed into a thin re-export of the canonical implementation to keep a
|
|
11
|
+
* single source of truth. Packing semantics are unchanged.
|
|
3
12
|
*/
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function normalizeFileScopePath(p) {
|
|
8
|
-
let s = String(p ?? '').trim();
|
|
9
|
-
if (!s) return null;
|
|
10
|
-
|
|
11
|
-
s = s.replace(/\\/g, '/');
|
|
12
|
-
if (s.startsWith('./')) s = s.slice(2);
|
|
13
|
-
s = s.replace(/\/+$/g, '');
|
|
14
|
-
|
|
15
|
-
// Common "globs" used in scopes are treated as directory prefixes.
|
|
16
|
-
if (s.endsWith('/*')) s = s.slice(0, -2);
|
|
17
|
-
if (s.endsWith('/**')) s = s.slice(0, -3);
|
|
18
|
-
|
|
19
|
-
return s || null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function pathsOverlap(a, b) {
|
|
23
|
-
if (a === b) return true;
|
|
24
|
-
// Only treat directory-prefix matches; a file prefix without a slash should not match.
|
|
25
|
-
return a.startsWith(b + '/') || b.startsWith(a + '/');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function taskOverlapsLane(taskPaths, lanePaths) {
|
|
29
|
-
for (const a of taskPaths) {
|
|
30
|
-
for (const b of lanePaths) {
|
|
31
|
-
if (pathsOverlap(a, b)) return true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @param {{ waves: string[][], tasksById: Record<string, { fileScope?: string[] }>, maxParallel: number, queueExcess?: boolean }} args
|
|
39
|
-
* @returns {Array<{ index: number, taskIds: string[], virtualLaneCount: number, ticks: Array<{ index: number, lanes: string[][] }>, laneAssignments: Record<string, { virtualLane: number, tick: number, laneInTick: number }> }>
|
|
40
|
-
*/
|
|
41
|
-
export function assignLanesToWaves({ waves, tasksById, maxParallel, queueExcess = true }) {
|
|
42
|
-
const planned = [];
|
|
43
|
-
|
|
44
|
-
for (let waveIndex = 0; waveIndex < waves.length; waveIndex++) {
|
|
45
|
-
const rawWaveTaskIds = waves[waveIndex];
|
|
46
|
-
const waveTaskIds = [];
|
|
47
|
-
|
|
48
|
-
// Expand matrix tasks
|
|
49
|
-
for (const taskId of rawWaveTaskIds) {
|
|
50
|
-
const task = tasksById[taskId];
|
|
51
|
-
if (!task) {
|
|
52
|
-
throw new Error(`Missing task packet for ${taskId} during lane assignment`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if (task.matrix && Array.isArray(task.matrix) && task.matrix.length > 0) {
|
|
56
|
-
for (const row of task.matrix) {
|
|
57
|
-
const rowId = deriveMatrixRowId(row, task.matrixColumns || []);
|
|
58
|
-
const subTaskId = `${taskId}[${rowId}]`;
|
|
59
|
-
waveTaskIds.push(subTaskId);
|
|
60
|
-
if (!tasksById[subTaskId]) {
|
|
61
|
-
tasksById[subTaskId] = {
|
|
62
|
-
...task,
|
|
63
|
-
taskId: subTaskId,
|
|
64
|
-
matrixRow: row,
|
|
65
|
-
parentTaskId: taskId
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
} else {
|
|
70
|
-
waveTaskIds.push(taskId);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** @type {{ lanePaths: string[], taskIds: string[] }} */
|
|
75
|
-
const virtualLanes = [];
|
|
76
|
-
|
|
77
|
-
/** @type {Record<string, { virtualLane: number, tick: number, laneInTick: number }>} */
|
|
78
|
-
const laneAssignments = {};
|
|
79
|
-
|
|
80
|
-
const virtualLaneForTask = {};
|
|
81
|
-
|
|
82
|
-
// Greedy packing into virtual lanes.
|
|
83
|
-
for (const taskId of waveTaskIds) {
|
|
84
|
-
const task = tasksById[taskId];
|
|
85
|
-
|
|
86
|
-
const taskPaths = (task.fileScope ?? [])
|
|
87
|
-
.map(normalizeFileScopePath)
|
|
88
|
-
.filter(Boolean);
|
|
89
|
-
|
|
90
|
-
let placed = false;
|
|
91
|
-
for (let i = 0; i < virtualLanes.length; i++) {
|
|
92
|
-
const lane = virtualLanes[i];
|
|
93
|
-
|
|
94
|
-
// Matrix sub-tasks of the same parent task do not conflict with each other
|
|
95
|
-
const hasSameParent = lane.taskIds.some(id => {
|
|
96
|
-
const other = tasksById[id];
|
|
97
|
-
return other && other.parentTaskId && other.parentTaskId === task.parentTaskId;
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
if (!hasSameParent && taskOverlapsLane(taskPaths, lane.lanePaths)) {
|
|
101
|
-
virtualLaneForTask[taskId] = i;
|
|
102
|
-
// Append to lane paths so future tasks are checked against everything already assigned.
|
|
103
|
-
lane.lanePaths.push(...taskPaths);
|
|
104
|
-
lane.taskIds.push(taskId);
|
|
105
|
-
placed = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (!placed) {
|
|
111
|
-
const i = virtualLanes.length;
|
|
112
|
-
virtualLanes.push({ lanePaths: [...taskPaths], taskIds: [taskId] });
|
|
113
|
-
virtualLaneForTask[taskId] = i;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const virtualLaneCount = virtualLanes.length;
|
|
118
|
-
const tickCount = queueExcess ? Math.ceil(virtualLaneCount / maxParallel) : 1;
|
|
119
|
-
|
|
120
|
-
const ticks = Array.from({ length: tickCount }, (_, t) => {
|
|
121
|
-
return {
|
|
122
|
-
index: t,
|
|
123
|
-
lanes: Array.from({ length: maxParallel }, () => []),
|
|
124
|
-
};
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
for (const taskId of waveTaskIds) {
|
|
128
|
-
const virtualLane = virtualLaneForTask[taskId];
|
|
129
|
-
const tick = queueExcess ? Math.floor(virtualLane / maxParallel) : 0;
|
|
130
|
-
const laneInTick = virtualLane % maxParallel;
|
|
131
|
-
laneAssignments[taskId] = { virtualLane, tick, laneInTick };
|
|
132
|
-
ticks[tick].lanes[laneInTick].push(taskId);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
planned.push({
|
|
136
|
-
index: waveIndex,
|
|
137
|
-
taskIds: waveTaskIds,
|
|
138
|
-
virtualLaneCount,
|
|
139
|
-
ticks,
|
|
140
|
-
laneAssignments,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return planned;
|
|
145
|
-
}
|
|
14
|
+
export { assignLanesToWaves } from './waves.mjs';
|