pi-spine 1.0.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/LICENSE +21 -0
- package/README.md +563 -0
- package/bin/get-version.mjs +35 -0
- package/bin/spine-batch.mjs +425 -0
- package/bin/spine-cli/batch.mjs +47 -0
- package/bin/spine-cli/gate.mjs +10 -0
- package/bin/spine-cli/integrate.mjs +10 -0
- package/bin/spine-cli/plan.mjs +12 -0
- package/bin/spine-cli/shared.mjs +73 -0
- package/bin/spine-cli/status.mjs +18 -0
- package/bin/spine-cli/verify.mjs +199 -0
- package/bin/spine-config.mjs +212 -0
- package/bin/spine-dashboard.mjs +178 -0
- package/bin/spine-deps.mjs +69 -0
- package/bin/spine-doctor.mjs +468 -0
- package/bin/spine-gate.mjs +137 -0
- package/bin/spine-init.mjs +398 -0
- package/bin/spine-integrate.mjs +77 -0
- package/bin/spine-journal.mjs +198 -0
- package/bin/spine-migrate-from-taskplane.mjs +136 -0
- package/bin/spine-plan.mjs +83 -0
- package/bin/spine-preflight.mjs +700 -0
- package/bin/spine-report-progress.d.mts +28 -0
- package/bin/spine-report-progress.mjs +126 -0
- package/bin/spine-review-step.d.mts +24 -0
- package/bin/spine-review-step.mjs +124 -0
- package/bin/spine-rules.mjs +35 -0
- package/bin/spine-settings.mjs +186 -0
- package/bin/spine-state.mjs +110 -0
- package/bin/spine-status.mjs +79 -0
- package/bin/spine-tasks.mjs +293 -0
- package/bin/spine-worker-runner.mjs +314 -0
- package/bin/spine.mjs +404 -0
- package/extensions/spine/settings-slash.ts +20 -0
- package/extensions/spine/slash-commands.ts +806 -0
- package/extensions/spine/worker-tools.ts +279 -0
- package/extensions/spine-orchestrator.ts +12 -0
- package/package.json +72 -0
- package/skills/.gitkeep +0 -0
- package/skills/create-spine-tasks/SKILL.md +375 -0
- package/skills/create-spine-tasks/references/context-template.md +25 -0
- package/skills/create-spine-tasks/references/contract-template.md +98 -0
- package/skills/create-spine-tasks/references/explore-template.md +63 -0
- package/skills/create-spine-tasks/references/prompt-template.md +276 -0
- package/src/batch/abort.mjs +272 -0
- package/src/batch/agent-session-worker.mjs +297 -0
- package/src/batch/batch-state-io.mjs +53 -0
- package/src/batch/contract-verify.mjs +310 -0
- package/src/batch/detached-start.mjs +778 -0
- package/src/batch/diagnosis.mjs +378 -0
- package/src/batch/engine-lanes/merge.mjs +632 -0
- package/src/batch/engine-lanes/queue.mjs +208 -0
- package/src/batch/engine-lanes/review.mjs +970 -0
- package/src/batch/engine-lanes.mjs +388 -0
- package/src/batch/engine-scope.mjs +251 -0
- package/src/batch/engine.mjs +445 -0
- package/src/batch/evidence-command.mjs +157 -0
- package/src/batch/evidence.mjs +203 -0
- package/src/batch/gate.mjs +359 -0
- package/src/batch/git-commit-env.mjs +46 -0
- package/src/batch/git-exec.mjs +26 -0
- package/src/batch/heartbeat.mjs +430 -0
- package/src/batch/integrate.mjs +414 -0
- package/src/batch/journal-rebuild.mjs +388 -0
- package/src/batch/journal.mjs +373 -0
- package/src/batch/lane-commit.mjs +153 -0
- package/src/batch/lifecycle.mjs +364 -0
- package/src/batch/metrics.mjs +265 -0
- package/src/batch/orphan-detect.mjs +210 -0
- package/src/batch/post-merge-limbo.mjs +80 -0
- package/src/batch/postmortem.mjs +296 -0
- package/src/batch/readers/spine-state.mjs +95 -0
- package/src/batch/readers/taskplane-state.mjs +136 -0
- package/src/batch/reconcile.mjs +729 -0
- package/src/batch/resume-common.mjs +104 -0
- package/src/batch/resume-engine.mjs +66 -0
- package/src/batch/resume-multi-lanes.mjs +479 -0
- package/src/batch/resume-multi-validate.mjs +187 -0
- package/src/batch/resume-multi.mjs +254 -0
- package/src/batch/resume.mjs +475 -0
- package/src/batch/retry.mjs +257 -0
- package/src/batch/review-scope.mjs +136 -0
- package/src/batch/review.mjs +1045 -0
- package/src/batch/salvage.mjs +332 -0
- package/src/batch/state.mjs +680 -0
- package/src/batch/task-stall-budget.mjs +88 -0
- package/src/batch/worker-host.mjs +683 -0
- package/src/batch/worker-output.mjs +253 -0
- package/src/batch/worker-prompt.mjs +84 -0
- package/src/batch/worktree.mjs +290 -0
- package/src/cli/deps.mjs +141 -0
- package/src/cli/handoff.mjs +364 -0
- package/src/cli/rules.mjs +429 -0
- package/src/cli/settings-set.mjs +171 -0
- package/src/cli/settings-show.mjs +140 -0
- package/src/cli/settings-slash.mjs +107 -0
- package/src/config/contract.mjs +56 -0
- package/src/config/cursor-rules/discover.mjs +416 -0
- package/src/config/cursor-rules/index.mjs +39 -0
- package/src/config/cursor-rules/match-globs.mjs +132 -0
- package/src/config/cursor-rules/parse-frontmatter.mjs +222 -0
- package/src/config/cursor-rules/priority.mjs +26 -0
- package/src/config/cursor-rules/profile.mjs +403 -0
- package/src/config/cursor-rules/select.mjs +259 -0
- package/src/config/defaults.mjs +36 -0
- package/src/config/env-overrides.mjs +207 -0
- package/src/config/merge-defaults.mjs +47 -0
- package/src/config/pi-spine-root.mjs +93 -0
- package/src/config/reviewer-context.mjs +243 -0
- package/src/config/settings-fields.mjs +265 -0
- package/src/config/worker-backend.mjs +116 -0
- package/src/config/worker-context.mjs +402 -0
- package/src/config/worker-launch-script.mjs +130 -0
- package/src/config/worktree-setup-hook.mjs +122 -0
- package/src/dashboard/public/dashboard.css +77 -0
- package/src/dashboard/public/dashboard.js +349 -0
- package/src/dashboard/public/index.html +80 -0
- package/src/dashboard/server.mjs +155 -0
- package/src/dashboard/snapshot.mjs +414 -0
- package/src/dashboard/sse.mjs +15 -0
- package/src/dashboard/view.mjs +292 -0
- package/src/doctor/agent-model-inherit.mjs +101 -0
- package/src/doctor/batch-size-guidance.mjs +72 -0
- package/src/doctor/coexistence.mjs +312 -0
- package/src/doctor/rules-manifest.mjs +133 -0
- package/src/doctor/stale-path.mjs +156 -0
- package/src/doctor/stall-config.mjs +108 -0
- package/src/doctor/suggest-max-parallel.mjs +53 -0
- package/src/doctor/task-packet-size.mjs +110 -0
- package/src/doctor/worktree-health.mjs +71 -0
- package/src/migrate/taskplane-config.mjs +116 -0
- package/src/planner/cycles.mjs +63 -0
- package/src/planner/format-plan.mjs +132 -0
- package/src/planner/graph.mjs +99 -0
- package/src/planner/index.mjs +125 -0
- package/src/planner/lanes.mjs +111 -0
- package/src/planner/pending.mjs +39 -0
- package/src/planner/scope.mjs +142 -0
- package/src/process/liveness.mjs +21 -0
- package/src/tasks/packet/discover.mjs +40 -0
- package/src/tasks/packet/index.mjs +81 -0
- package/src/tasks/packet/merge-deps.mjs +79 -0
- package/src/tasks/packet/parse-prompt.mjs +445 -0
- package/src/tasks/packet/parse-status.mjs +118 -0
- package/src/tasks/packet/validate-contract.mjs +115 -0
- package/src/tasks/packet/validate-prompt.mjs +99 -0
- package/src/worker-tools/report-progress.d.mts +18 -0
- package/src/worker-tools/report-progress.mjs +59 -0
- package/src/worker-tools/request-gate.d.mts +17 -0
- package/src/worker-tools/request-gate.mjs +54 -0
- package/templates/agents/reviewer.md +123 -0
- package/templates/agents/supervisor.md +59 -0
- package/templates/agents/worker.md +122 -0
- package/templates/rules-profile.json +27 -0
- package/templates/spine-config.json +64 -0
- package/templates/tasks/CONTEXT.md +30 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reviewer context: auto-selected Cursor rules for review spawn (SP-250).
|
|
3
|
+
* Mirrors worker context path with 16 KiB cap and no referenceDocs injection.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { discoverCursorRules, loadRulesManifest } from "./cursor-rules/discover.mjs";
|
|
7
|
+
import { loadRulesProfile } from "./cursor-rules/profile.mjs";
|
|
8
|
+
import { selectRulesForReviewer } from "./cursor-rules/select.mjs";
|
|
9
|
+
import {
|
|
10
|
+
cursorRulesRootExists,
|
|
11
|
+
loadContextDocEntries,
|
|
12
|
+
normalizeContextPathList,
|
|
13
|
+
} from "./worker-context.mjs";
|
|
14
|
+
import { appendJournalEvent } from "../batch/journal.mjs";
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_REVIEWER_CONTEXT_BYTE_CAP = 16_384;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {object} ReviewerRulesJournalContext
|
|
20
|
+
* @property {string} projectRoot
|
|
21
|
+
* @property {string} batchId
|
|
22
|
+
* @property {string} [taskId]
|
|
23
|
+
* @property {number} [laneNumber]
|
|
24
|
+
* @property {string} [correlationId]
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {import("./cursor-rules/select.mjs").RulesSelectionResult} selection
|
|
29
|
+
* @returns {object[]}
|
|
30
|
+
*/
|
|
31
|
+
function journalEntriesFromSelection(selection) {
|
|
32
|
+
return selection.entries.map((entry) => ({
|
|
33
|
+
relPath: entry.relPath,
|
|
34
|
+
contextPath: entry.contextPath,
|
|
35
|
+
source: entry.source,
|
|
36
|
+
...(entry.spineClass ? { spineClass: entry.spineClass } : {}),
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @param {ReviewerRulesJournalContext | undefined} journal
|
|
42
|
+
* @param {Record<string, unknown>} payload
|
|
43
|
+
*/
|
|
44
|
+
export function emitReviewerRulesSelected(journal, payload) {
|
|
45
|
+
if (!journal?.projectRoot || !journal?.batchId) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
appendJournalEvent(journal.projectRoot, journal.batchId, "reviewer.rules_selected", {
|
|
49
|
+
taskId: journal.taskId,
|
|
50
|
+
laneNumber: journal.laneNumber,
|
|
51
|
+
correlationId: journal.correlationId,
|
|
52
|
+
...payload,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {object} params
|
|
58
|
+
* @param {string} [params.projectRoot]
|
|
59
|
+
* @param {object} [params.config]
|
|
60
|
+
* @param {"plan"|"code"|"final"} [params.reviewType]
|
|
61
|
+
* @param {string[]} [params.scopePaths]
|
|
62
|
+
* @param {ReviewerRulesJournalContext} [params.journal]
|
|
63
|
+
* @param {number} [params.byteCap]
|
|
64
|
+
*/
|
|
65
|
+
export function buildReviewerContext({
|
|
66
|
+
projectRoot = process.cwd(),
|
|
67
|
+
config = {},
|
|
68
|
+
reviewType = "plan",
|
|
69
|
+
scopePaths = [],
|
|
70
|
+
journal,
|
|
71
|
+
byteCap = DEFAULT_REVIEWER_CONTEXT_BYTE_CAP,
|
|
72
|
+
} = {}) {
|
|
73
|
+
const neverLoad = new Set(normalizeContextPathList(config.neverLoad) ?? []);
|
|
74
|
+
const standards = normalizeContextPathList(config.standards) ?? [];
|
|
75
|
+
|
|
76
|
+
if (!cursorRulesRootExists(projectRoot)) {
|
|
77
|
+
emitReviewerRulesSelected(journal, {
|
|
78
|
+
mode: "skipped",
|
|
79
|
+
reviewType,
|
|
80
|
+
scopePaths,
|
|
81
|
+
paths: [],
|
|
82
|
+
capped: false,
|
|
83
|
+
bytesUsed: 0,
|
|
84
|
+
manifestSource: "none",
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
text: "",
|
|
88
|
+
entries: [],
|
|
89
|
+
truncated: false,
|
|
90
|
+
skipped: [],
|
|
91
|
+
bytesUsed: 0,
|
|
92
|
+
byteCap,
|
|
93
|
+
selection: { mode: "skipped" },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const profileResult = loadRulesProfile(projectRoot);
|
|
98
|
+
if (!profileResult.ok) {
|
|
99
|
+
emitReviewerRulesSelected(journal, {
|
|
100
|
+
mode: "degraded",
|
|
101
|
+
reviewType,
|
|
102
|
+
scopePaths,
|
|
103
|
+
paths: [],
|
|
104
|
+
capped: false,
|
|
105
|
+
bytesUsed: 0,
|
|
106
|
+
profileError: profileResult.error,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
text: "",
|
|
110
|
+
entries: [],
|
|
111
|
+
truncated: false,
|
|
112
|
+
skipped: [],
|
|
113
|
+
bytesUsed: 0,
|
|
114
|
+
byteCap,
|
|
115
|
+
selection: {
|
|
116
|
+
mode: "degraded",
|
|
117
|
+
profileError: profileResult.error,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
let manifest = loadRulesManifest(projectRoot);
|
|
123
|
+
let manifestSource = "committed";
|
|
124
|
+
if (!manifest) {
|
|
125
|
+
const discovered = discoverCursorRules({
|
|
126
|
+
projectRoot,
|
|
127
|
+
profile: profileResult.profile,
|
|
128
|
+
writeManifest: false,
|
|
129
|
+
});
|
|
130
|
+
manifest = discovered.manifest;
|
|
131
|
+
manifestSource = "discovered";
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const selection = selectRulesForReviewer({
|
|
135
|
+
manifest,
|
|
136
|
+
profile: profileResult.profile,
|
|
137
|
+
scopePaths,
|
|
138
|
+
standards,
|
|
139
|
+
neverLoad: [...neverLoad],
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const orderedPaths = selection.paths;
|
|
143
|
+
|
|
144
|
+
if (orderedPaths.length === 0) {
|
|
145
|
+
emitReviewerRulesSelected(journal, {
|
|
146
|
+
mode: "auto",
|
|
147
|
+
reviewType,
|
|
148
|
+
scopePaths,
|
|
149
|
+
paths: [],
|
|
150
|
+
capped: selection.capped,
|
|
151
|
+
bytesUsed: 0,
|
|
152
|
+
manifestSource,
|
|
153
|
+
profileSource: profileResult.source,
|
|
154
|
+
entries: journalEntriesFromSelection(selection),
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
text: "",
|
|
158
|
+
entries: [],
|
|
159
|
+
truncated: false,
|
|
160
|
+
skipped: [],
|
|
161
|
+
bytesUsed: 0,
|
|
162
|
+
byteCap,
|
|
163
|
+
selection: {
|
|
164
|
+
mode: "auto",
|
|
165
|
+
manifestSource,
|
|
166
|
+
profileSource: profileResult.source,
|
|
167
|
+
...selection,
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const loaded = loadContextDocEntries({
|
|
173
|
+
projectRoot,
|
|
174
|
+
paths: orderedPaths,
|
|
175
|
+
neverLoad,
|
|
176
|
+
byteCap,
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
if (!loaded.ok) {
|
|
180
|
+
emitReviewerRulesSelected(journal, {
|
|
181
|
+
mode: "degraded",
|
|
182
|
+
reviewType,
|
|
183
|
+
scopePaths,
|
|
184
|
+
paths: orderedPaths,
|
|
185
|
+
capped: selection.capped,
|
|
186
|
+
bytesUsed: 0,
|
|
187
|
+
loadError: loaded.error,
|
|
188
|
+
blockedPath: loaded.relPath,
|
|
189
|
+
});
|
|
190
|
+
return {
|
|
191
|
+
text: "",
|
|
192
|
+
entries: [],
|
|
193
|
+
truncated: false,
|
|
194
|
+
skipped: [],
|
|
195
|
+
bytesUsed: 0,
|
|
196
|
+
byteCap,
|
|
197
|
+
error: loaded.error,
|
|
198
|
+
blockedPath: loaded.relPath,
|
|
199
|
+
selection: {
|
|
200
|
+
mode: "auto",
|
|
201
|
+
manifestSource,
|
|
202
|
+
profileSource: profileResult.source,
|
|
203
|
+
...selection,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const parts = loaded.entries.map(
|
|
209
|
+
(entry) => `--- ${entry.relPath} ---\n${entry.content.trim()}\n`,
|
|
210
|
+
);
|
|
211
|
+
const text =
|
|
212
|
+
parts.length > 0 ? `\n\n## Project standards for review\n\n${parts.join("\n")}` : "";
|
|
213
|
+
|
|
214
|
+
const capped = selection.capped || loaded.truncated;
|
|
215
|
+
|
|
216
|
+
emitReviewerRulesSelected(journal, {
|
|
217
|
+
mode: "auto",
|
|
218
|
+
reviewType,
|
|
219
|
+
scopePaths,
|
|
220
|
+
paths: orderedPaths,
|
|
221
|
+
capped,
|
|
222
|
+
bytesUsed: loaded.bytesUsed,
|
|
223
|
+
manifestSource,
|
|
224
|
+
profileSource: profileResult.source,
|
|
225
|
+
entries: journalEntriesFromSelection(selection),
|
|
226
|
+
truncated: loaded.truncated,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
text,
|
|
231
|
+
entries: loaded.entries,
|
|
232
|
+
truncated: loaded.truncated,
|
|
233
|
+
skipped: loaded.skipped,
|
|
234
|
+
bytesUsed: loaded.bytesUsed,
|
|
235
|
+
byteCap: loaded.byteCap,
|
|
236
|
+
selection: {
|
|
237
|
+
mode: "auto",
|
|
238
|
+
manifestSource,
|
|
239
|
+
profileSource: profileResult.source,
|
|
240
|
+
...selection,
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FR-CFG-03 editable spine-config field registry (TP-032).
|
|
3
|
+
* Pure validation — no filesystem writes.
|
|
4
|
+
*
|
|
5
|
+
* FR-CFG-04 (TP-046): `paths.tasksRoot` and `lanes.maxParallel` may be overridden at
|
|
6
|
+
* runtime by `SPINE_TASKS_ROOT` and `SPINE_MAX_LANES` (precedence: env > file).
|
|
7
|
+
* Only `lanes.maxParallel` is editable via `spine settings set`; tasks root is env/file only.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** @typedef {"boolean" | "number" | "string" | "enum"} SettingFieldType */
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {object} SettingField
|
|
14
|
+
* @property {string} path Dotted path into spine-config.json
|
|
15
|
+
* @property {string} label Human-readable label
|
|
16
|
+
* @property {SettingFieldType} type
|
|
17
|
+
* @property {number} [min]
|
|
18
|
+
* @property {number} [max]
|
|
19
|
+
* @property {string[]} [enum]
|
|
20
|
+
* @property {boolean} [caseSensitive] When true, enum values match exactly (no lowercasing)
|
|
21
|
+
* @property {boolean} [optional] When true, empty string is allowed for string fields
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/** @type {readonly SettingField[]} */
|
|
25
|
+
export const SETTINGS_FIELDS = Object.freeze([
|
|
26
|
+
{
|
|
27
|
+
path: "lanes.maxParallel",
|
|
28
|
+
label: "Max parallel lanes",
|
|
29
|
+
type: "number",
|
|
30
|
+
min: 1,
|
|
31
|
+
max: 32,
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
path: "lanes.workerBackend",
|
|
35
|
+
label: "Worker execution backend",
|
|
36
|
+
type: "enum",
|
|
37
|
+
enum: ["subprocess", "agentSession"],
|
|
38
|
+
caseSensitive: true,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
path: "lanes.autoIntegrateBetweenWaves",
|
|
42
|
+
label: "Auto integrate between waves",
|
|
43
|
+
type: "boolean",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
path: "gates.requireBeforeIntegrate",
|
|
47
|
+
label: "Require gate before integrate",
|
|
48
|
+
type: "boolean",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
path: "agents.worker.model",
|
|
52
|
+
label: "Worker model",
|
|
53
|
+
type: "string",
|
|
54
|
+
optional: true,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
path: "agents.worker.thinking",
|
|
58
|
+
label: "Worker thinking level",
|
|
59
|
+
type: "enum",
|
|
60
|
+
enum: ["off", "low", "medium", "high"],
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
path: "dashboard.port",
|
|
64
|
+
label: "Dashboard port",
|
|
65
|
+
type: "number",
|
|
66
|
+
min: 1024,
|
|
67
|
+
max: 65535,
|
|
68
|
+
},
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
const FIELD_BY_PATH = new Map(SETTINGS_FIELDS.map((field) => [field.path, field]));
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @returns {SettingField[]}
|
|
75
|
+
*/
|
|
76
|
+
export function listEditableFields() {
|
|
77
|
+
return SETTINGS_FIELDS.map((field) => ({ ...field }));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {unknown} path
|
|
82
|
+
* @returns {{ ok: true, path: string, field: SettingField } | { ok: false, error: string }}
|
|
83
|
+
*/
|
|
84
|
+
export function parseSettingPath(path) {
|
|
85
|
+
if (typeof path !== "string") {
|
|
86
|
+
return { ok: false, error: "Setting path must be a string" };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const trimmed = path.trim();
|
|
90
|
+
if (trimmed === "") {
|
|
91
|
+
return { ok: false, error: "Setting path must be non-empty" };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const field = FIELD_BY_PATH.get(trimmed);
|
|
95
|
+
if (!field) {
|
|
96
|
+
return { ok: false, error: `Unknown setting path: ${trimmed}` };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return { ok: true, path: trimmed, field };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {unknown} path
|
|
104
|
+
* @param {unknown} rawValue
|
|
105
|
+
* @returns {{ ok: true, normalizedValue: boolean | number | string } | { ok: false, error: string }}
|
|
106
|
+
*/
|
|
107
|
+
export function validateSettingValue(path, rawValue) {
|
|
108
|
+
const parsed = parseSettingPath(path);
|
|
109
|
+
if (!parsed.ok) {
|
|
110
|
+
return parsed;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return validateForField(parsed.field, rawValue);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* @param {SettingField} field
|
|
118
|
+
* @param {unknown} rawValue
|
|
119
|
+
*/
|
|
120
|
+
function validateForField(field, rawValue) {
|
|
121
|
+
switch (field.type) {
|
|
122
|
+
case "boolean":
|
|
123
|
+
return validateBoolean(rawValue);
|
|
124
|
+
case "number":
|
|
125
|
+
return validateNumber(rawValue, field);
|
|
126
|
+
case "string":
|
|
127
|
+
return validateString(rawValue, field);
|
|
128
|
+
case "enum":
|
|
129
|
+
return validateEnum(rawValue, field);
|
|
130
|
+
default:
|
|
131
|
+
return { ok: false, error: `Unsupported field type: ${field.type}` };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @param {unknown} rawValue
|
|
137
|
+
*/
|
|
138
|
+
function validateBoolean(rawValue) {
|
|
139
|
+
const coerced = coerceBoolean(rawValue);
|
|
140
|
+
if (coerced === undefined) {
|
|
141
|
+
return {
|
|
142
|
+
ok: false,
|
|
143
|
+
error: "Expected a boolean (true/false, 1/0, yes/no)",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return { ok: true, normalizedValue: coerced };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* @param {unknown} rawValue
|
|
151
|
+
* @param {SettingField} field
|
|
152
|
+
*/
|
|
153
|
+
function validateNumber(rawValue, field) {
|
|
154
|
+
const coerced = coerceNumber(rawValue);
|
|
155
|
+
if (coerced === undefined) {
|
|
156
|
+
return { ok: false, error: "Expected a number" };
|
|
157
|
+
}
|
|
158
|
+
if (!Number.isInteger(coerced)) {
|
|
159
|
+
return { ok: false, error: "Expected an integer" };
|
|
160
|
+
}
|
|
161
|
+
if (field.min != null && coerced < field.min) {
|
|
162
|
+
return { ok: false, error: `Value must be >= ${field.min}` };
|
|
163
|
+
}
|
|
164
|
+
if (field.max != null && coerced > field.max) {
|
|
165
|
+
return { ok: false, error: `Value must be <= ${field.max}` };
|
|
166
|
+
}
|
|
167
|
+
return { ok: true, normalizedValue: coerced };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @param {unknown} rawValue
|
|
172
|
+
* @param {SettingField} field
|
|
173
|
+
*/
|
|
174
|
+
function validateString(rawValue, field) {
|
|
175
|
+
if (rawValue == null) {
|
|
176
|
+
if (field.optional) {
|
|
177
|
+
return { ok: true, normalizedValue: "" };
|
|
178
|
+
}
|
|
179
|
+
return { ok: false, error: "Expected a non-empty string" };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (typeof rawValue !== "string" && typeof rawValue !== "number" && typeof rawValue !== "boolean") {
|
|
183
|
+
return { ok: false, error: "Expected a string" };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const normalized = String(rawValue).trim();
|
|
187
|
+
if (normalized === "" && !field.optional) {
|
|
188
|
+
return { ok: false, error: "Expected a non-empty string" };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return { ok: true, normalizedValue: normalized };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @param {unknown} rawValue
|
|
196
|
+
* @param {SettingField} field
|
|
197
|
+
*/
|
|
198
|
+
function validateEnum(rawValue, field) {
|
|
199
|
+
if (rawValue == null || (typeof rawValue === "string" && rawValue.trim() === "")) {
|
|
200
|
+
return { ok: false, error: "Expected one of: " + (field.enum ?? []).join(", ") };
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const normalized =
|
|
204
|
+
typeof rawValue === "string" ? rawValue.trim() : String(rawValue).trim();
|
|
205
|
+
const candidate = field.caseSensitive ? normalized : normalized.toLowerCase();
|
|
206
|
+
const allowed = field.caseSensitive
|
|
207
|
+
? (field.enum ?? [])
|
|
208
|
+
: (field.enum ?? []).map((value) => value.toLowerCase());
|
|
209
|
+
|
|
210
|
+
if (!allowed.includes(candidate)) {
|
|
211
|
+
return {
|
|
212
|
+
ok: false,
|
|
213
|
+
error: `Expected one of: ${field.enum?.join(", ") ?? "(none)"}`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return { ok: true, normalizedValue: candidate };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @param {unknown} rawValue
|
|
222
|
+
* @returns {boolean | undefined}
|
|
223
|
+
*/
|
|
224
|
+
function coerceBoolean(rawValue) {
|
|
225
|
+
if (typeof rawValue === "boolean") {
|
|
226
|
+
return rawValue;
|
|
227
|
+
}
|
|
228
|
+
if (typeof rawValue === "number") {
|
|
229
|
+
if (rawValue === 1) return true;
|
|
230
|
+
if (rawValue === 0) return false;
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
if (typeof rawValue !== "string") {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const normalized = rawValue.trim().toLowerCase();
|
|
238
|
+
if (["true", "1", "yes", "on"].includes(normalized)) return true;
|
|
239
|
+
if (["false", "0", "no", "off"].includes(normalized)) return false;
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {unknown} rawValue
|
|
245
|
+
* @returns {number | undefined}
|
|
246
|
+
*/
|
|
247
|
+
function coerceNumber(rawValue) {
|
|
248
|
+
if (typeof rawValue === "number" && Number.isFinite(rawValue)) {
|
|
249
|
+
return rawValue;
|
|
250
|
+
}
|
|
251
|
+
if (typeof rawValue !== "string") {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const trimmed = rawValue.trim();
|
|
256
|
+
if (trimmed === "") {
|
|
257
|
+
return undefined;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const parsed = Number(trimmed);
|
|
261
|
+
if (!Number.isFinite(parsed)) {
|
|
262
|
+
return undefined;
|
|
263
|
+
}
|
|
264
|
+
return parsed;
|
|
265
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lane worker execution backend (TP-050).
|
|
3
|
+
* @see docs/adoption/create-agent-session-spike.md
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
|
|
10
|
+
/** @typedef {"subprocess" | "agentSession"} WorkerBackend */
|
|
11
|
+
|
|
12
|
+
export const WORKER_BACKENDS = Object.freeze(["subprocess", "agentSession"]);
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_WORKER_BACKEND = /** @type {const} */ ("subprocess");
|
|
15
|
+
|
|
16
|
+
/** Doctor check label — subprocess is the production default (FR-SHIP-09 / SP-219). */
|
|
17
|
+
export const WORKER_BACKEND_DOCTOR_LABEL = "worker backend (lanes.workerBackend)";
|
|
18
|
+
|
|
19
|
+
const SUBPROCESS_DETAIL =
|
|
20
|
+
"subprocess — pi -p via spine-worker-runner (production default per FR-SHIP-09)";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {unknown} value
|
|
24
|
+
* @returns {value is WorkerBackend}
|
|
25
|
+
*/
|
|
26
|
+
export function isWorkerBackend(value) {
|
|
27
|
+
return typeof value === "string" && WORKER_BACKENDS.includes(value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve effective worker backend from spine config.
|
|
32
|
+
* Missing or invalid values fall back to subprocess (safe default).
|
|
33
|
+
*
|
|
34
|
+
* @param {object} [config]
|
|
35
|
+
* @returns {WorkerBackend}
|
|
36
|
+
*/
|
|
37
|
+
export function resolveWorkerBackend(config = {}) {
|
|
38
|
+
const raw = config.lanes?.workerBackend;
|
|
39
|
+
if (raw == null || raw === "") {
|
|
40
|
+
return DEFAULT_WORKER_BACKEND;
|
|
41
|
+
}
|
|
42
|
+
if (isWorkerBackend(raw)) {
|
|
43
|
+
return raw;
|
|
44
|
+
}
|
|
45
|
+
return DEFAULT_WORKER_BACKEND;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Doctor/preflight check for lanes.workerBackend.
|
|
50
|
+
* Subprocess is the default; agentSession is opt-in and requires the pi-coding-agent peer.
|
|
51
|
+
*
|
|
52
|
+
* @param {object} [config]
|
|
53
|
+
*/
|
|
54
|
+
export function buildWorkerBackendDoctorCheck(config = {}) {
|
|
55
|
+
const backend = resolveWorkerBackend(config);
|
|
56
|
+
const configuredRaw = config.lanes?.workerBackend;
|
|
57
|
+
|
|
58
|
+
if (backend !== "agentSession") {
|
|
59
|
+
const unset = configuredRaw == null || configuredRaw === "";
|
|
60
|
+
return {
|
|
61
|
+
label: WORKER_BACKEND_DOCTOR_LABEL,
|
|
62
|
+
ok: true,
|
|
63
|
+
detail: unset ? `${SUBPROCESS_DETAIL}; config unset (falls back to default)` : SUBPROCESS_DETAIL,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** @type {string[]} */
|
|
68
|
+
const issues = [];
|
|
69
|
+
try {
|
|
70
|
+
require.resolve("@earendil-works/pi-coding-agent");
|
|
71
|
+
} catch {
|
|
72
|
+
issues.push("@earendil-works/pi-coding-agent not installed");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (issues.length === 0) {
|
|
76
|
+
return {
|
|
77
|
+
label: WORKER_BACKEND_DOCTOR_LABEL,
|
|
78
|
+
ok: true,
|
|
79
|
+
warning: true,
|
|
80
|
+
detail:
|
|
81
|
+
"agentSession (opt-in) — pi-coding-agent peer available; subprocess remains default until land-loop dogfood passes",
|
|
82
|
+
suggestedCommand: "./scripts/stub-free-dogfood.sh --agent-session",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
label: WORKER_BACKEND_DOCTOR_LABEL,
|
|
88
|
+
ok: false,
|
|
89
|
+
detail: `agentSession (opt-in): ${issues.join("; ")}`,
|
|
90
|
+
suggestedCommand: "npm install @earendil-works/pi-coding-agent",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** @deprecated Use buildWorkerBackendDoctorCheck */
|
|
95
|
+
export const buildAgentSessionDoctorCheck = buildWorkerBackendDoctorCheck;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Validate optional lanes.workerBackend for spine-config schema.
|
|
99
|
+
*
|
|
100
|
+
* @param {object} config
|
|
101
|
+
* @returns {{ code: string, message: string, suggestedCommand: string } | null}
|
|
102
|
+
*/
|
|
103
|
+
export function validateWorkerBackendConfig(config) {
|
|
104
|
+
const raw = config.lanes?.workerBackend;
|
|
105
|
+
if (raw == null || raw === "") {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (isWorkerBackend(raw)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
code: "CONFIG_WORKER_BACKEND_INVALID",
|
|
113
|
+
message: `lanes.workerBackend must be one of: ${WORKER_BACKENDS.join(", ")}`,
|
|
114
|
+
suggestedCommand: "spine settings set lanes.workerBackend subprocess",
|
|
115
|
+
};
|
|
116
|
+
}
|