pi-spine 2.34.0 → 2.36.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/bin/spine-dashboard.mjs +87 -4
- package/bin/spine-integrate.mjs +5 -5
- package/bin/spine-plan.mjs +14 -1
- package/package.json +1 -1
- package/skills/create-spine-tasks/SKILL.md +7 -7
- package/skills/spine-orchestrate-waves/SKILL.md +1 -1
- package/skills/spine-release-operator/SKILL.md +2 -2
- package/src/batch/engine-lanes/queue.mjs +5 -0
- package/src/batch/engine-lanes/vl-slot-dispatch.mjs +227 -0
- package/src/batch/engine-lanes/vl-wave-dispatch.mjs +325 -0
- package/src/batch/engine-scope.mjs +116 -0
- package/src/batch/engine.mjs +28 -95
- package/src/batch/integrate.mjs +3 -3
- package/src/batch/resume-multi-queue.mjs +276 -75
- package/src/cli/board-select.mjs +26 -10
- package/src/config/defaults.mjs +8 -5
- package/src/config/spine-config-schema.mjs +28 -12
- package/src/dashboard/snapshot-lanes.mjs +97 -2
- package/src/integrations/issues/providers/github.mjs +47 -0
- package/src/integrations/{github → issues}/sync-on-land.mjs +32 -59
- /package/src/integrations/{github → issues}/mission-issue-links.mjs +0 -0
package/bin/spine-dashboard.mjs
CHANGED
|
@@ -63,9 +63,11 @@ export function resolveDashboardPort(projectRoot, cliPort) {
|
|
|
63
63
|
* @param {object} options
|
|
64
64
|
* @param {string} options.url
|
|
65
65
|
* @param {string} options.host
|
|
66
|
-
* @param {number} options.port
|
|
66
|
+
* @param {number} options.port Bound (listen) port — must match `url` (#388).
|
|
67
67
|
* @param {string} [options.projectRoot]
|
|
68
68
|
* @param {"cli"|"config"|"default"} [options.portSource]
|
|
69
|
+
* @param {number} [options.fallbackFromPort] Preferred port that was busy; when
|
|
70
|
+
* set, a busy→bound note is printed so the ephemeral move is never silent.
|
|
69
71
|
* @returns {string}
|
|
70
72
|
*/
|
|
71
73
|
export function formatDashboardStartupMessage({
|
|
@@ -73,6 +75,7 @@ export function formatDashboardStartupMessage({
|
|
|
73
75
|
host,
|
|
74
76
|
port,
|
|
75
77
|
portSource = "default",
|
|
78
|
+
fallbackFromPort,
|
|
76
79
|
}) {
|
|
77
80
|
const base = url.endsWith("/") ? url.slice(0, -1) : url;
|
|
78
81
|
const portNote = formatPortSourceNote(portSource);
|
|
@@ -84,6 +87,15 @@ export function formatDashboardStartupMessage({
|
|
|
84
87
|
"",
|
|
85
88
|
` Open in browser: ${browserUrl}`,
|
|
86
89
|
` Listen: ${host}:${port}${portNote}`,
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
if (fallbackFromPort != null) {
|
|
93
|
+
lines.push(
|
|
94
|
+
` Note: preferred port ${fallbackFromPort} busy — bound ephemeral port ${port}`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
lines.push(
|
|
87
99
|
"",
|
|
88
100
|
" While running: keep this terminal open; dashboard updates via SSE (~2s)",
|
|
89
101
|
"",
|
|
@@ -98,7 +110,7 @@ export function formatDashboardStartupMessage({
|
|
|
98
110
|
"",
|
|
99
111
|
" Stop: Ctrl+C",
|
|
100
112
|
"",
|
|
101
|
-
|
|
113
|
+
);
|
|
102
114
|
|
|
103
115
|
return lines.join("\n");
|
|
104
116
|
}
|
|
@@ -126,6 +138,50 @@ Open in browser: ${browserUrl}
|
|
|
126
138
|
CLI: \`spine dashboard\`${portHint}.`;
|
|
127
139
|
}
|
|
128
140
|
|
|
141
|
+
/**
|
|
142
|
+
* Listen on the preferred port; on `EADDRINUSE` either fail with an
|
|
143
|
+
* operator-readable error (strict, for explicit `--port N > 0`) or retry on an
|
|
144
|
+
* OS-assigned ephemeral port (`port: 0`) and report the fallback (#388).
|
|
145
|
+
*
|
|
146
|
+
* The same server instance is reused for the retry: after a failed
|
|
147
|
+
* `listen()` the socket handle is released, so re-listening is safe.
|
|
148
|
+
*
|
|
149
|
+
* @param {object} options
|
|
150
|
+
* @param {import("node:http").Server} options.server
|
|
151
|
+
* @param {string} options.host
|
|
152
|
+
* @param {number} options.preferredPort
|
|
153
|
+
* @param {boolean} [options.strict]
|
|
154
|
+
* @returns {Promise<{ url: string, host: string, port: number, fallbackFromPort?: number }>}
|
|
155
|
+
* `fallbackFromPort` is set only when the preferred port was busy and the
|
|
156
|
+
* bind moved to an ephemeral port.
|
|
157
|
+
*/
|
|
158
|
+
export async function listenDashboardWithFallback({
|
|
159
|
+
server,
|
|
160
|
+
host,
|
|
161
|
+
preferredPort,
|
|
162
|
+
strict = false,
|
|
163
|
+
}) {
|
|
164
|
+
try {
|
|
165
|
+
return await listenDashboardServer({ server, host, port: preferredPort });
|
|
166
|
+
} catch (err) {
|
|
167
|
+
if (err?.code !== "EADDRINUSE") throw err;
|
|
168
|
+
|
|
169
|
+
if (strict) {
|
|
170
|
+
const strictError = new Error(
|
|
171
|
+
`Dashboard port ${preferredPort} is already in use (--port ${preferredPort}). Free the port or run \`spine dashboard --port 0\` to bind an ephemeral port.`,
|
|
172
|
+
);
|
|
173
|
+
strictError.code = "EADDRINUSE";
|
|
174
|
+
strictError.cause = err;
|
|
175
|
+
throw strictError;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const bound = await listenDashboardServer({ server, host, port: 0 });
|
|
179
|
+
// A port-0 bind is already ephemeral; never print a nonsensical
|
|
180
|
+
// "preferred port 0 busy" note.
|
|
181
|
+
return preferredPort > 0 ? { ...bound, fallbackFromPort: preferredPort } : bound;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
129
185
|
/**
|
|
130
186
|
* @param {object} options
|
|
131
187
|
* @param {string} options.projectRoot
|
|
@@ -160,10 +216,37 @@ export async function runSpineDashboard({ projectRoot, args = [] }) {
|
|
|
160
216
|
}
|
|
161
217
|
|
|
162
218
|
const server = createDashboardServer({ projectRoot, host, port });
|
|
163
|
-
|
|
219
|
+
// Strict (no fallback) only when the operator pinned an explicit nonzero
|
|
220
|
+
// port: `--port N` with N > 0 (#388). Config/default preferred ports and
|
|
221
|
+
// `--port 0` may move to an ephemeral bind.
|
|
222
|
+
const strictPort = portSource === "cli" && port > 0;
|
|
223
|
+
|
|
224
|
+
let listenResult;
|
|
225
|
+
try {
|
|
226
|
+
listenResult = await listenDashboardWithFallback({
|
|
227
|
+
server,
|
|
228
|
+
host,
|
|
229
|
+
preferredPort: port,
|
|
230
|
+
strict: strictPort,
|
|
231
|
+
});
|
|
232
|
+
} catch (err) {
|
|
233
|
+
return {
|
|
234
|
+
exitCode: 1,
|
|
235
|
+
output: `${err instanceof Error ? err.message : String(err)}\n`,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const { url, port: boundPort, fallbackFromPort } = listenResult;
|
|
164
240
|
|
|
165
241
|
process.stdout.write(
|
|
166
|
-
`${formatDashboardStartupMessage({
|
|
242
|
+
`${formatDashboardStartupMessage({
|
|
243
|
+
url,
|
|
244
|
+
host,
|
|
245
|
+
port: boundPort,
|
|
246
|
+
projectRoot,
|
|
247
|
+
portSource,
|
|
248
|
+
fallbackFromPort,
|
|
249
|
+
})}\n`,
|
|
167
250
|
);
|
|
168
251
|
|
|
169
252
|
await new Promise((resolve) => {
|
package/bin/spine-integrate.mjs
CHANGED
|
@@ -11,7 +11,7 @@ Options:
|
|
|
11
11
|
--batch ID Target batch (default: active batch)
|
|
12
12
|
--dry-run Show the merge plan without changing anything
|
|
13
13
|
--force-integrate Bypass the gate (requires SPINE_ALLOW_FORCE=1)
|
|
14
|
-
--no-
|
|
14
|
+
--no-issue-sync Skip the opt-in post-integrate GitHub issue sync (#383)
|
|
15
15
|
--json Machine-readable output
|
|
16
16
|
--help, -h Show this help without changing state
|
|
17
17
|
`;
|
|
@@ -25,8 +25,8 @@ Options:
|
|
|
25
25
|
*/
|
|
26
26
|
function appendGithubSyncLines(lines, sync) {
|
|
27
27
|
if (sync.skipped) {
|
|
28
|
-
if (sync.reason === "
|
|
29
|
-
lines.push("", " GitHub: sync skipped (--no-
|
|
28
|
+
if (sync.reason === "no_issue_sync_flag") {
|
|
29
|
+
lines.push("", " GitHub: sync skipped (--no-issue-sync)");
|
|
30
30
|
}
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
@@ -110,7 +110,7 @@ export function runSpineIntegrate(options) {
|
|
|
110
110
|
const { projectRoot, args } = options;
|
|
111
111
|
const parsed = parseStrictArgs(args, {
|
|
112
112
|
valued: ["--batch"],
|
|
113
|
-
boolean: ["--dry-run", "--force-integrate", "--json", "--no-
|
|
113
|
+
boolean: ["--dry-run", "--force-integrate", "--json", "--no-issue-sync"],
|
|
114
114
|
});
|
|
115
115
|
const flags = parsed.flags;
|
|
116
116
|
if (parsed.help) {
|
|
@@ -143,7 +143,7 @@ export function runSpineIntegrate(options) {
|
|
|
143
143
|
dryRun: flags.has("--dry-run"),
|
|
144
144
|
batchId: parsed.values.get("--batch") ?? null,
|
|
145
145
|
forceIntegrate: flags.has("--force-integrate"),
|
|
146
|
-
|
|
146
|
+
noIssueSync: flags.has("--no-issue-sync"),
|
|
147
147
|
});
|
|
148
148
|
|
|
149
149
|
return {
|
package/bin/spine-plan.mjs
CHANGED
|
@@ -124,7 +124,20 @@ async function main() {
|
|
|
124
124
|
const json = argv.includes('--json');
|
|
125
125
|
|
|
126
126
|
// SP-889 (#386): board selection — GitHub label/milestone → pending task IDs.
|
|
127
|
-
|
|
127
|
+
// SP-894 (#387): parseBoardSelectArgs throws fail-closed on the retired
|
|
128
|
+
// --github-label spelling; surface it with the standard error style.
|
|
129
|
+
let board;
|
|
130
|
+
try {
|
|
131
|
+
board = parseBoardSelectArgs(argv);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
const msg = err?.message ?? String(err);
|
|
134
|
+
if (err?.suggestedCommand) {
|
|
135
|
+
console.error(`Error: ${msg}\nSuggested: ${err.suggestedCommand}`);
|
|
136
|
+
} else {
|
|
137
|
+
console.error(`Error: ${msg}`);
|
|
138
|
+
}
|
|
139
|
+
process.exit(1);
|
|
140
|
+
}
|
|
128
141
|
if (board.labels.length > 0 || (board.milestone !== null && board.milestone !== '')) {
|
|
129
142
|
try {
|
|
130
143
|
const { output } = await runBoardSelect({
|
package/package.json
CHANGED
|
@@ -546,11 +546,11 @@ Packet shape decides most of a batch's token spend. Each choice below removes LL
|
|
|
546
546
|
|
|
547
547
|
## Thin packets (issue narrative vs packet Contract) — #385 / #382
|
|
548
548
|
|
|
549
|
-
**Dual-layer seam:** GitHub
|
|
549
|
+
**Dual-layer seam:** the issue tracker (GitHub provider by default) holds goals and discussion (human/intake SoR). Packets under `paths.tasksRoot` hold Contract, File Scope, Steps, Do NOT, and STATUS (agent/engine SoR). Do **not** paste full issue threads into worker context.
|
|
550
550
|
|
|
551
551
|
| Layer | Keep here | Do not dump here |
|
|
552
552
|
|-------|-----------|------------------|
|
|
553
|
-
| GitHub
|
|
553
|
+
| Issue tracker entry (GitHub by default) | Narrative, ACs discussion, comments, board labels | Machine Contract / File Scope as the only source of truth |
|
|
554
554
|
| Packet `## Mission` | One short paragraph + `Closes #N` / `Partial #N` pointing at the issue | Multi-page issue body or all comment history |
|
|
555
555
|
| Packet Contract / File Scope / Steps / Do NOT | Complete, local, authoritative for the batch | “See issue for File Scope” without listing paths |
|
|
556
556
|
| Context to Read First | Few high-signal paths the worker needs | Unbounded “read all comments on #N” or pasted mega-dumps |
|
|
@@ -560,16 +560,16 @@ Packet shape decides most of a batch's token spend. Each choice below removes LL
|
|
|
560
560
|
```markdown
|
|
561
561
|
## Mission
|
|
562
562
|
|
|
563
|
-
Closes #384 — Scaffold SP-* packets from
|
|
563
|
+
Closes #384 — Scaffold SP-* packets from an issue-tracker issue via `spine tasks from-issue`. Keep Contract stubs incomplete until the operator fills File Scope.
|
|
564
564
|
```
|
|
565
565
|
|
|
566
566
|
**Fat-context anti-pattern:** Pasting the entire issue body plus comment thread into Context to Read First or Mission. Prefer the `#N` link and a one-line pointer; use `neverLoad` for docs that must stay out of worker context.
|
|
567
567
|
|
|
568
568
|
**Advisory validate (deferred):** A warn-only `spine tasks validate` heuristic for mega Context dumps is **deferred** — hard to distinguish legitimate multi-doc Context from dumps without false positives, and hard-fail on any issue link is explicitly out of scope for #385. Authors rely on this DoR item until a later advisory lands.
|
|
569
569
|
|
|
570
|
-
## Hydrate from a
|
|
570
|
+
## Hydrate from a tracker issue — `spine tasks from-issue` (#384 / #382)
|
|
571
571
|
|
|
572
|
-
Thin CLI path from an open issue to a stub packet. Fetches the issue title via `gh issue view --json`, scaffolds `{tasksRoot}/SP-###-<slug>/`, and stops before inventing Contract content:
|
|
572
|
+
Thin CLI path from an open issue-tracker issue (GitHub provider by default) to a stub packet. Fetches the issue title via `gh issue view --json`, scaffolds `{tasksRoot}/SP-###-<slug>/`, and stops before inventing Contract content:
|
|
573
573
|
|
|
574
574
|
```bash
|
|
575
575
|
spine tasks from-issue 384 # Mission "Closes #384" (default)
|
|
@@ -622,9 +622,9 @@ Before reporting launch commands:
|
|
|
622
622
|
- [ ] No LLM step waits on a long-running command — split authoring (`llm`) from running (`execute`) ([#276](https://github.com/beettlle/pi-spine/issues/276))
|
|
623
623
|
- [ ] Size S/M/L — split if XL
|
|
624
624
|
- [ ] PROMPT.md from template: Mission, Dependencies, Context, File Scope, Contract (SP-\*), Steps, Do NOT, Git Commit Convention, Amendments
|
|
625
|
-
- [ ] Mission uses `Closes #N` or `Partial #N` on first line when tracking
|
|
625
|
+
- [ ] Mission uses `Closes #N` or `Partial #N` on first line when tracking issue-tracker issues (GitHub by default) ([#147](https://github.com/beettlle/pi-spine/issues/147))
|
|
626
626
|
- [ ] Thin packet: short Mission + `#N` pointer; Contract/File Scope/Steps/Do NOT complete locally — no pasted issue-thread mega-dumps in Context ([#385](https://github.com/beettlle/pi-spine/issues/385) / [Thin packets](#thin-packets-issue-narrative-vs-packet-contract--385--382))
|
|
627
|
-
- [ ] Issue intake via `spine tasks from-issue`: Contract / File Scope / Steps filled and `spine tasks validate <id>` passing before plan/batch ([#384](https://github.com/beettlle/pi-spine/issues/384) / [Hydrate](#hydrate-from-a-
|
|
627
|
+
- [ ] Issue intake via `spine tasks from-issue`: Contract / File Scope / Steps filled and `spine tasks validate <id>` passing before plan/batch ([#384](https://github.com/beettlle/pi-spine/issues/384) / [Hydrate](#hydrate-from-a-tracker-issue--spine-tasks-from-issue-384--382))
|
|
628
628
|
- [ ] Split-successor tasks include `Parent split: SP-###` in Context to Read First ([#146](https://github.com/beettlle/pi-spine/issues/146))
|
|
629
629
|
- [ ] `## Do NOT` bans `.spine/`, `AGENTS.md`, `CLAUDE.md`, `.gitnexus/` ([#149](https://github.com/beettlle/pi-spine/issues/149))
|
|
630
630
|
- [ ] Level 2+ only when operator environment supports cross-model review ([#150](https://github.com/beettlle/pi-spine/issues/150))
|
|
@@ -79,7 +79,7 @@ START
|
|
|
79
79
|
## Wave picker algorithm
|
|
80
80
|
|
|
81
81
|
1. Run `spine plan pending` (or `spine plan all` / explicit task scope).
|
|
82
|
-
- **Board-driven alternative (SP-889 / #386):** when the operator names
|
|
82
|
+
- **Board-driven alternative (SP-889 / #386):** when the operator names an issue-tracker label or milestone (GitHub provider by default), resolve the scope first — `node bin/spine-plan.mjs --issue-label <label> --print-ids` (Mission `Closes`/`Partial` links → pending task IDs, selection only, no auto-start) — then plan that ID list to confirm wave structure.
|
|
83
83
|
2. Parse wave index and task list:
|
|
84
84
|
- **JSON:** `spine plan pending --json` → `waveCount`, per-wave `tasks[]`
|
|
85
85
|
- **Text:** read wave headers from CLI output
|
|
@@ -407,9 +407,9 @@ git push origin main
|
|
|
407
407
|
|
|
408
408
|
Do not let `main` drift far ahead of `origin` between waves — v2.12.1 ran **24 commits ahead** of `origin` at Phase 5 (F8, [#249](https://github.com/beettlle/pi-spine/issues/249)). Local-only releases may defer this push; record the deferral in the manifest publish checklist.
|
|
409
409
|
|
|
410
|
-
### 4.3c Close
|
|
410
|
+
### 4.3c Close tracker issues for landed tasks (blocking hygiene)
|
|
411
411
|
|
|
412
|
-
> **Automated sync (SP-887 / #383):** repos with `integrations.
|
|
412
|
+
> **Automated sync (SP-887 / #383):** repos with `integrations.issues.syncOnLand: true` get the `Closes #N` / `Partial #N` actions below applied automatically by `spine integrate` (close = comment + close; partial = comment only; journal `issues.synced` / `issues.sync_failed`; escape hatch `spine integrate --no-issue-sync`). The default is **off** — when disabled or soft-failed (missing `gh`/auth), perform this §4.3c sweep manually.
|
|
413
413
|
|
|
414
414
|
After §4.3a is green (and §4.3b push when remote publish is the goal), **close every open issue fully resolved by tasks that just landed** — same wave, same land loop. Do not wait for Phase 6 or npm publish.
|
|
415
415
|
|
|
@@ -205,6 +205,11 @@ export function recordPromptParseFailure({
|
|
|
205
205
|
* @param {number} params.maxLaneNumber
|
|
206
206
|
*/
|
|
207
207
|
export function buildTasksAndLanesFromPlan({ plan, discovered, projectRoot, batchId, maxLaneNumber }) {
|
|
208
|
+
// Plan-time stamping is advisory (#358): `buildTaskLaneAssignments` maps
|
|
209
|
+
// the planner's tick layout, which stays preview-only under slot-pool
|
|
210
|
+
// dispatch. These values are provisional until the first VL→slot bind —
|
|
211
|
+
// `applyVlSlotLaneBinding` (engine-scope.mjs) rewrites task.laneNumber,
|
|
212
|
+
// lane.taskIds, the journal, and saved state at dispatch time.
|
|
208
213
|
const assignments = buildTaskLaneAssignments(plan);
|
|
209
214
|
/** @type {string[]} */
|
|
210
215
|
const taskIds = countPlanTasks(plan);
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VL slot-pool dispatch helper (SP-897 / #358 partial).
|
|
3
|
+
*
|
|
4
|
+
* Selects the next ready virtual lane (VL) for a free physical slot in
|
|
5
|
+
* `1..lanes.maxParallel` so the engine can replace tick barriers with
|
|
6
|
+
* slot-pool dispatch (wire step is SP-903 — this module does not touch the
|
|
7
|
+
* engine tick loop).
|
|
8
|
+
*
|
|
9
|
+
* Invariants locked here:
|
|
10
|
+
*
|
|
11
|
+
* 1. `lanes.maxParallel` caps in-flight VLs (physical slot pool).
|
|
12
|
+
* 2. A ready VL whose scopes overlap any currently running VL's scopes is
|
|
13
|
+
* never dispatched while that work runs — never two overlapping VLs
|
|
14
|
+
* concurrent.
|
|
15
|
+
* 3. Same-VL serial queue semantics: a VL holds at most one slot at a time;
|
|
16
|
+
* its remaining tasks wait behind the running task on that VL. Mid-run
|
|
17
|
+
* steal across the same-VL serial queue is out of scope (#358).
|
|
18
|
+
* 4. Slot free but no dispatchable VL is distinguishable from true idle via
|
|
19
|
+
* a journalable conflict-wait payload (event `lane.slot_conflict_wait`).
|
|
20
|
+
*
|
|
21
|
+
* Slot mechanics mirror the matrix sub-lane pool
|
|
22
|
+
* (`acquireLaneSlot` / `releaseLaneSlot` in `matrix.mjs`): lowest free slot,
|
|
23
|
+
* FIFO wake on release, `maxParallel` clamped to at least 1. This module owns
|
|
24
|
+
* its pool instance (created by the caller) instead of a state-keyed WeakMap
|
|
25
|
+
* so matrix row scheduling stays untouched.
|
|
26
|
+
*
|
|
27
|
+
* Scope overlap delegates to the planner's glob-aware
|
|
28
|
+
* `fileScopesOverlap` (`src/planner/file-scope.mjs`) — the exact predicate the
|
|
29
|
+
* planner used to pack VLs — so dispatch can never run two VLs concurrently
|
|
30
|
+
* that packing would have serialized onto one lane.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import { fileScopesOverlap } from "../../planner/file-scope.mjs";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Journal event name for "slot free but every remaining ready VL conflicts".
|
|
37
|
+
* Emitted by the wire step (SP-903) via
|
|
38
|
+
* `appendJournalEvent(projectRoot, batchId, VL_SLOT_CONFLICT_WAIT_EVENT, buildConflictWaitPayload(...))`.
|
|
39
|
+
*
|
|
40
|
+
* @type {"lane.slot_conflict_wait"}
|
|
41
|
+
*/
|
|
42
|
+
export const VL_SLOT_CONFLICT_WAIT_EVENT = "lane.slot_conflict_wait";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* A dispatch-ready virtual lane entry.
|
|
46
|
+
*
|
|
47
|
+
* @typedef {Object} VlDispatchEntry
|
|
48
|
+
* @property {string | number | null} [vlId] Stable VL identity.
|
|
49
|
+
* @property {string[]} [scopes] Accumulated file scopes for the VL.
|
|
50
|
+
* @property {string[]} [taskIds] Ordered task queue for the VL (serial).
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Selection result for `selectReadyVl`.
|
|
55
|
+
*
|
|
56
|
+
* @typedef {Object} VlSelection
|
|
57
|
+
* @property {"dispatch" | "conflict-wait" | "idle"} status
|
|
58
|
+
* - `dispatch`: `vl` is the ready VL to bind to a free slot.
|
|
59
|
+
* - `conflict-wait`: slot would be free but nothing dispatchable — every
|
|
60
|
+
* remaining ready VL either overlaps running scopes (`blocked`) or is
|
|
61
|
+
* already running its own serial queue (`waitingOn`).
|
|
62
|
+
* - `idle`: no ready VLs at all.
|
|
63
|
+
* @property {VlDispatchEntry | null} vl Selected VL when `status` is `dispatch`.
|
|
64
|
+
* @property {Array<{ vlId: string | number | null, overlapsWith: string | number | null }>} blocked
|
|
65
|
+
* Ready VLs skipped because their scopes overlap running work (in ready order).
|
|
66
|
+
* @property {Array<string | number | null>} waitingOn
|
|
67
|
+
* Ready VL ids already running — their remaining tasks stay serial-queued.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Whether two scope lists overlap, using the planner's glob-aware overlap
|
|
72
|
+
* predicate (directory prefixes, `*`/`**` globs, brace expansion). Empty or
|
|
73
|
+
* missing scope lists never overlap anything.
|
|
74
|
+
*
|
|
75
|
+
* @param {unknown} scopesA First scope list.
|
|
76
|
+
* @param {unknown} scopesB Second scope list.
|
|
77
|
+
* @returns {boolean}
|
|
78
|
+
*/
|
|
79
|
+
export function scopesOverlap(scopesA, scopesB) {
|
|
80
|
+
const left = Array.isArray(scopesA) ? scopesA : [];
|
|
81
|
+
const right = Array.isArray(scopesB) ? scopesB : [];
|
|
82
|
+
if (left.length === 0 || right.length === 0) return false;
|
|
83
|
+
return fileScopesOverlap(left, right);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Select the next ready VL to bind to a free physical slot.
|
|
88
|
+
*
|
|
89
|
+
* Scans `readyVls` in queue order and returns the first VL that (a) is not
|
|
90
|
+
* already running (same-VL serial queue) and (b) does not overlap any
|
|
91
|
+
* currently running VL's scopes. VLs skipped along the way are reported in
|
|
92
|
+
* `blocked` / `waitingOn` so callers can journal exactly why a free slot
|
|
93
|
+
* could not take work.
|
|
94
|
+
*
|
|
95
|
+
* @param {VlDispatchEntry[]} readyVls Ready VLs in dispatch-priority order.
|
|
96
|
+
* @param {VlDispatchEntry[]} [runningVls] VLs currently holding slots.
|
|
97
|
+
* @returns {VlSelection}
|
|
98
|
+
*/
|
|
99
|
+
export function selectReadyVl(readyVls, runningVls = []) {
|
|
100
|
+
const ready = Array.isArray(readyVls) ? readyVls.filter(Boolean) : [];
|
|
101
|
+
const running = Array.isArray(runningVls) ? runningVls.filter(Boolean) : [];
|
|
102
|
+
if (ready.length === 0) {
|
|
103
|
+
return { status: "idle", vl: null, blocked: [], waitingOn: [] };
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const runningIds = new Set(running.map((vl) => vl?.vlId));
|
|
107
|
+
/** @type {Array<{ vlId: string | number | null, overlapsWith: string | number | null }>} */
|
|
108
|
+
const blocked = [];
|
|
109
|
+
/** @type {Array<string | number | null>} */
|
|
110
|
+
const waitingOn = [];
|
|
111
|
+
|
|
112
|
+
for (const vl of ready) {
|
|
113
|
+
const vlId = vl?.vlId ?? null;
|
|
114
|
+
if (runningIds.has(vlId)) {
|
|
115
|
+
waitingOn.push(vlId);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const conflicting = running.find((runVl) => scopesOverlap(vl?.scopes, runVl?.scopes));
|
|
119
|
+
if (conflicting) {
|
|
120
|
+
blocked.push({ vlId, overlapsWith: conflicting.vlId ?? null });
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
return { status: "dispatch", vl, blocked, waitingOn };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { status: "conflict-wait", vl: null, blocked, waitingOn };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Physical slot pool sized `1..maxParallel` (matrix pool semantics, owned
|
|
131
|
+
* instance). `acquire` waits FIFO when the pool is full; `release` hands the
|
|
132
|
+
* freed slot to the oldest waiter.
|
|
133
|
+
*
|
|
134
|
+
* @typedef {Object} VlSlotPool
|
|
135
|
+
* @property {number} max Configured pool size (clamped to ≥ 1).
|
|
136
|
+
* @property {() => number | null} tryAcquire Take the lowest free slot now, or null.
|
|
137
|
+
* @property {() => Promise<number>} acquire Take the lowest free slot, waiting FIFO until one frees.
|
|
138
|
+
* @property {(slot: number) => void} release Return a slot; wakes the oldest waiter (FIFO).
|
|
139
|
+
* @property {() => number} runningCount Slots currently in use.
|
|
140
|
+
* @property {() => number} freeSlotCount Slots currently free.
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Create a VL slot pool. Missing/zero/negative `maxParallel` clamps to a
|
|
145
|
+
* single slot (mirrors the matrix pool).
|
|
146
|
+
*
|
|
147
|
+
* @param {number} maxParallel Configured `lanes.maxParallel`.
|
|
148
|
+
* @returns {VlSlotPool}
|
|
149
|
+
*/
|
|
150
|
+
export function createVlSlotPool(maxParallel) {
|
|
151
|
+
const max = Math.max(1, Math.floor(Number(maxParallel) || 1));
|
|
152
|
+
/** @type {Set<number>} */
|
|
153
|
+
const inUse = new Set();
|
|
154
|
+
/** @type {Array<(slot: number) => void>} */
|
|
155
|
+
const waiters = [];
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
get max() {
|
|
159
|
+
return max;
|
|
160
|
+
},
|
|
161
|
+
tryAcquire() {
|
|
162
|
+
for (let slot = 1; slot <= max; slot++) {
|
|
163
|
+
if (!inUse.has(slot)) {
|
|
164
|
+
inUse.add(slot);
|
|
165
|
+
return slot;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
},
|
|
170
|
+
acquire() {
|
|
171
|
+
const slot = this.tryAcquire();
|
|
172
|
+
if (slot !== null) return Promise.resolve(slot);
|
|
173
|
+
return new Promise((resolve) => {
|
|
174
|
+
waiters.push(resolve);
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
release(slot) {
|
|
178
|
+
const slotNumber = Number(slot);
|
|
179
|
+
if (!Number.isInteger(slotNumber) || slotNumber < 1 || !inUse.has(slotNumber)) return;
|
|
180
|
+
inUse.delete(slotNumber);
|
|
181
|
+
const next = waiters.shift();
|
|
182
|
+
if (next) {
|
|
183
|
+
inUse.add(slotNumber);
|
|
184
|
+
next(slotNumber);
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
runningCount() {
|
|
188
|
+
return inUse.size;
|
|
189
|
+
},
|
|
190
|
+
freeSlotCount() {
|
|
191
|
+
return max - inUse.size;
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Journalable payload for a conflict-wait: a physical slot is free but no
|
|
198
|
+
* ready VL can take it. Data only — pass alongside
|
|
199
|
+
* `VL_SLOT_CONFLICT_WAIT_EVENT` to `appendJournalEvent`.
|
|
200
|
+
*
|
|
201
|
+
* @param {object} [params]
|
|
202
|
+
* @param {number | null} [params.slot] Free slot number, when known.
|
|
203
|
+
* @param {Array<{ vlId: string | number | null, overlapsWith: string | number | null }>} [params.blocked]
|
|
204
|
+
* Ready VLs skipped for scope overlap (from `selectReadyVl`).
|
|
205
|
+
* @param {Array<string | number | null>} [params.waitingOn]
|
|
206
|
+
* Ready VL ids serial-queued behind their own running task.
|
|
207
|
+
* @param {Array<string | number | null>} [params.runningVlIds] VL ids holding slots.
|
|
208
|
+
* @param {number} [params.readyCount] Ready VLs remaining (dispatchable + blocked).
|
|
209
|
+
* @returns {{ event: typeof VL_SLOT_CONFLICT_WAIT_EVENT, slot: number | null, reason: "scope_conflict", blockedByOverlap: Array<{ vlId: string | number | null, overlapsWith: string | number | null }>, queuedBehindRunning: Array<string | number | null>, runningVlIds: Array<string | number | null>, readyCount: number }}
|
|
210
|
+
*/
|
|
211
|
+
export function buildConflictWaitPayload({
|
|
212
|
+
slot = null,
|
|
213
|
+
blocked = [],
|
|
214
|
+
waitingOn = [],
|
|
215
|
+
runningVlIds = [],
|
|
216
|
+
readyCount = 0,
|
|
217
|
+
} = {}) {
|
|
218
|
+
return {
|
|
219
|
+
event: VL_SLOT_CONFLICT_WAIT_EVENT,
|
|
220
|
+
slot,
|
|
221
|
+
reason: "scope_conflict",
|
|
222
|
+
blockedByOverlap: Array.isArray(blocked) ? blocked : [],
|
|
223
|
+
queuedBehindRunning: Array.isArray(waitingOn) ? waitingOn : [],
|
|
224
|
+
runningVlIds: Array.isArray(runningVlIds) ? runningVlIds : [],
|
|
225
|
+
readyCount: Math.max(0, Math.floor(Number(readyCount) || 0)),
|
|
226
|
+
};
|
|
227
|
+
}
|