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,28 @@
|
|
|
1
|
+
export interface RunSpineReportProgressResult {
|
|
2
|
+
ok?: boolean;
|
|
3
|
+
eventId?: string;
|
|
4
|
+
error?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function runSpineReportProgress(options?: {
|
|
8
|
+
args?: string[];
|
|
9
|
+
worktreePath?: string;
|
|
10
|
+
projectRoot?: string;
|
|
11
|
+
batchId?: string;
|
|
12
|
+
taskId?: string;
|
|
13
|
+
laneId?: string;
|
|
14
|
+
laneNumber?: number;
|
|
15
|
+
correlationId?: string;
|
|
16
|
+
journal?: unknown;
|
|
17
|
+
}): {
|
|
18
|
+
exitCode: number;
|
|
19
|
+
output: string;
|
|
20
|
+
result: RunSpineReportProgressResult | null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function parseReportProgressArgs(argv: string[]): {
|
|
24
|
+
step: number | null;
|
|
25
|
+
checkboxesComplete?: number;
|
|
26
|
+
checkboxesTotal?: number;
|
|
27
|
+
json: boolean;
|
|
28
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Report worker step progress to the batch journal (FR-WORK-09, PRD §14.5).
|
|
4
|
+
* Usage: spine report progress --step N [--checkboxes-complete N] [--checkboxes-total N]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { resolveBatchJournalContext } from "../src/batch/review.mjs";
|
|
10
|
+
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
11
|
+
import { reportTaskProgress } from "../src/worker-tools/report-progress.mjs";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string[]} argv
|
|
15
|
+
*/
|
|
16
|
+
export function parseReportProgressArgs(argv) {
|
|
17
|
+
const args = {
|
|
18
|
+
step: null,
|
|
19
|
+
checkboxesComplete: undefined,
|
|
20
|
+
checkboxesTotal: undefined,
|
|
21
|
+
json: true,
|
|
22
|
+
};
|
|
23
|
+
for (let i = 0; i < argv.length; i++) {
|
|
24
|
+
const arg = argv[i];
|
|
25
|
+
if (arg === "--step") args.step = Number(argv[++i]);
|
|
26
|
+
else if (arg === "--checkboxes-complete") args.checkboxesComplete = Number(argv[++i]);
|
|
27
|
+
else if (arg === "--checkboxes-total") args.checkboxesTotal = Number(argv[++i]);
|
|
28
|
+
else if (arg === "--no-json") args.json = false;
|
|
29
|
+
}
|
|
30
|
+
return args;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @param {string} startPath
|
|
35
|
+
*/
|
|
36
|
+
function findProjectRoot(startPath) {
|
|
37
|
+
let current = startPath;
|
|
38
|
+
while (current !== path.dirname(current)) {
|
|
39
|
+
if (fs.existsSync(path.join(current, ".spine", "spine-config.json"))) {
|
|
40
|
+
return current;
|
|
41
|
+
}
|
|
42
|
+
current = path.dirname(current);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @param {number | undefined} value
|
|
49
|
+
*/
|
|
50
|
+
function parseLaneNumber(value) {
|
|
51
|
+
if (value == null || value === "") return undefined;
|
|
52
|
+
const parsed = Number(value);
|
|
53
|
+
return Number.isNaN(parsed) ? undefined : parsed;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {object} [options]
|
|
58
|
+
*/
|
|
59
|
+
export function runSpineReportProgress(options = {}) {
|
|
60
|
+
const args = parseReportProgressArgs(options.args ?? process.argv.slice(2));
|
|
61
|
+
if (args.step == null || Number.isNaN(args.step)) {
|
|
62
|
+
return {
|
|
63
|
+
exitCode: 1,
|
|
64
|
+
output:
|
|
65
|
+
"Usage: spine report progress --step N [--checkboxes-complete N] [--checkboxes-total N]\n",
|
|
66
|
+
result: null,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const worktreePath = options.worktreePath ?? process.env.SPINE_WORKTREE ?? process.cwd();
|
|
71
|
+
const attachCtx = options.journal ? null : resolveBatchJournalContext();
|
|
72
|
+
const projectRoot =
|
|
73
|
+
options.projectRoot ?? attachCtx?.projectRoot ?? findProjectRoot(worktreePath);
|
|
74
|
+
const batchId = options.batchId ?? attachCtx?.batchId ?? "";
|
|
75
|
+
const taskId = options.taskId ?? attachCtx?.taskId ?? process.env.SPINE_TASK_ID ?? "";
|
|
76
|
+
const laneId = options.laneId ?? process.env.SPINE_LANE_ID;
|
|
77
|
+
const laneNumber =
|
|
78
|
+
options.laneNumber ??
|
|
79
|
+
attachCtx?.laneNumber ??
|
|
80
|
+
parseLaneNumber(process.env.SPINE_LANE_NUMBER ?? process.env.SPINE_LANE_ID);
|
|
81
|
+
const correlationId =
|
|
82
|
+
options.correlationId ??
|
|
83
|
+
attachCtx?.correlationId ??
|
|
84
|
+
process.env.SPINE_LANE_CORRELATION_ID ??
|
|
85
|
+
undefined;
|
|
86
|
+
|
|
87
|
+
const result = reportTaskProgress({
|
|
88
|
+
projectRoot: projectRoot ?? "",
|
|
89
|
+
batchId,
|
|
90
|
+
taskId,
|
|
91
|
+
laneNumber,
|
|
92
|
+
laneId: laneId || undefined,
|
|
93
|
+
step: args.step,
|
|
94
|
+
checkboxesComplete: args.checkboxesComplete,
|
|
95
|
+
checkboxesTotal: args.checkboxesTotal,
|
|
96
|
+
correlationId,
|
|
97
|
+
journal: options.journal,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const payload = {
|
|
101
|
+
ok: result.ok,
|
|
102
|
+
eventId: result.eventId,
|
|
103
|
+
error: result.error,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
let output = "";
|
|
107
|
+
if (args.json) {
|
|
108
|
+
output = `${JSON.stringify(payload, null, 2)}\n`;
|
|
109
|
+
} else if (!result.ok) {
|
|
110
|
+
output = `ERROR: ${result.error}\n`;
|
|
111
|
+
} else {
|
|
112
|
+
output = `OK eventId=${result.eventId}\n`;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
exitCode: result.ok ? 0 : 1,
|
|
117
|
+
output,
|
|
118
|
+
result: payload,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
123
|
+
const { exitCode, output } = runSpineReportProgress({});
|
|
124
|
+
process.stdout.write(output ?? "");
|
|
125
|
+
process.exit(exitCode);
|
|
126
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface RunSpineReviewStepResult {
|
|
2
|
+
ok?: boolean;
|
|
3
|
+
verdict?: string | null;
|
|
4
|
+
feedback?: string;
|
|
5
|
+
artifactPath?: string;
|
|
6
|
+
reviewLevel?: number;
|
|
7
|
+
skipped?: boolean;
|
|
8
|
+
spawnFailed?: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
exitCode?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function runSpineReviewStep(options?: {
|
|
14
|
+
taskFolder?: string;
|
|
15
|
+
worktreePath?: string;
|
|
16
|
+
projectRoot?: string;
|
|
17
|
+
args?: string[];
|
|
18
|
+
config?: Record<string, unknown>;
|
|
19
|
+
journal?: unknown;
|
|
20
|
+
}): {
|
|
21
|
+
exitCode: number;
|
|
22
|
+
output: string;
|
|
23
|
+
result: RunSpineReviewStepResult | null;
|
|
24
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Spawn reviewer for a task step (FR-REV, spine_review_step).
|
|
4
|
+
* Usage: spine review step --step N [--type plan|code|final] [--baseline SHA]
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { loadSpineConfig } from "./spine-config.mjs";
|
|
11
|
+
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
12
|
+
import { resolveBatchJournalContext, runStepReview } from "../src/batch/review.mjs";
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string[]} argv
|
|
18
|
+
*/
|
|
19
|
+
export function parseReviewStepArgs(argv) {
|
|
20
|
+
const args = { step: null, type: "plan", baseline: undefined, stub: false, json: true };
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
const arg = argv[i];
|
|
23
|
+
if (arg === "--step") args.step = Number(argv[++i]);
|
|
24
|
+
else if (arg === "--type") args.type = argv[++i];
|
|
25
|
+
else if (arg === "--baseline") args.baseline = argv[++i];
|
|
26
|
+
else if (arg === "--stub") args.stub = true;
|
|
27
|
+
else if (arg === "--no-json") args.json = false;
|
|
28
|
+
}
|
|
29
|
+
return args;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {object} options
|
|
34
|
+
*/
|
|
35
|
+
export function runSpineReviewStep(options) {
|
|
36
|
+
const taskFolder = options.taskFolder ?? process.env.SPINE_TASK_FOLDER;
|
|
37
|
+
const worktreePath = options.worktreePath ?? process.env.SPINE_WORKTREE ?? process.cwd();
|
|
38
|
+
if (!taskFolder) {
|
|
39
|
+
return {
|
|
40
|
+
exitCode: 1,
|
|
41
|
+
output: "SPINE_TASK_FOLDER required\n",
|
|
42
|
+
result: null,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const args = parseReviewStepArgs(options.args ?? process.argv.slice(2));
|
|
47
|
+
if (args.step == null || Number.isNaN(args.step)) {
|
|
48
|
+
return {
|
|
49
|
+
exitCode: 1,
|
|
50
|
+
output: "Usage: spine review step --step N [--type plan|code|final] [--baseline SHA] [--stub]\n",
|
|
51
|
+
result: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const reviewType =
|
|
56
|
+
args.type === "final" ? "final" : args.type === "code" ? "code" : "plan";
|
|
57
|
+
const projectRoot = options.projectRoot ?? process.env.SPINE_PROJECT_ROOT ?? findProjectRoot(worktreePath);
|
|
58
|
+
let config = options.config ?? {};
|
|
59
|
+
if (projectRoot && !options.config) {
|
|
60
|
+
const loaded = loadSpineConfig(projectRoot);
|
|
61
|
+
if (loaded.config) config = loaded.config;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const journal = options.journal ?? resolveBatchJournalContext();
|
|
65
|
+
|
|
66
|
+
const result = runStepReview({
|
|
67
|
+
taskFolder,
|
|
68
|
+
worktreePath,
|
|
69
|
+
stepNumber: args.step,
|
|
70
|
+
reviewType,
|
|
71
|
+
baseline: args.baseline,
|
|
72
|
+
config,
|
|
73
|
+
journal,
|
|
74
|
+
stub: args.stub,
|
|
75
|
+
projectName: config?.project?.name,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const payload = {
|
|
79
|
+
verdict: result.verdict,
|
|
80
|
+
feedback: result.feedback,
|
|
81
|
+
artifactPath: result.artifactPath,
|
|
82
|
+
reviewLevel: result.reviewLevel,
|
|
83
|
+
skipped: result.skipped ?? false,
|
|
84
|
+
spawnFailed: result.spawnFailed ?? false,
|
|
85
|
+
error: result.error,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
let output = "";
|
|
89
|
+
if (args.json) {
|
|
90
|
+
output = `${JSON.stringify(payload, null, 2)}\n`;
|
|
91
|
+
} else if (result.spawnFailed) {
|
|
92
|
+
output = `REVIEW FAILED: ${result.error}\n`;
|
|
93
|
+
} else if (result.skipped) {
|
|
94
|
+
output = "SKIPPED (review level does not require this review type)\n";
|
|
95
|
+
} else {
|
|
96
|
+
output = `${result.verdict ?? "UNKNOWN"}: ${result.feedback || ""}\n`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
exitCode: result.exitCode ?? (result.ok ? 0 : 1),
|
|
101
|
+
output,
|
|
102
|
+
result,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @param {string} startPath
|
|
108
|
+
*/
|
|
109
|
+
function findProjectRoot(startPath) {
|
|
110
|
+
let current = startPath;
|
|
111
|
+
while (current !== path.dirname(current)) {
|
|
112
|
+
if (fs.existsSync(path.join(current, ".spine", "spine-config.json"))) {
|
|
113
|
+
return current;
|
|
114
|
+
}
|
|
115
|
+
current = path.dirname(current);
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
121
|
+
const { exitCode, output } = runSpineReviewStep({});
|
|
122
|
+
process.stdout.write(output ?? "");
|
|
123
|
+
process.exit(exitCode);
|
|
124
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* spine rules — discover, select, and sync Cursor rules manifest (SP-093).
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* spine rules discover [--json]
|
|
7
|
+
* spine rules select --task <task-id> [--role worker|reviewer] [--review-type plan|code|final] [--baseline <sha>] [--json]
|
|
8
|
+
* spine rules sync [--json]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
13
|
+
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
14
|
+
import { printRulesHelp, runSpineRules } from "../src/cli/rules.mjs";
|
|
15
|
+
|
|
16
|
+
export { printRulesHelp, runSpineRules } from "../src/cli/rules.mjs";
|
|
17
|
+
|
|
18
|
+
async function main() {
|
|
19
|
+
const argv = process.argv.slice(2);
|
|
20
|
+
|
|
21
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
22
|
+
process.stdout.write(printRulesHelp());
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const result = runSpineRules({ projectRoot: process.cwd(), args: argv });
|
|
27
|
+
process.stdout.write(result.output ?? "");
|
|
28
|
+
if (result.exitCode !== 0) {
|
|
29
|
+
process.exit(result.exitCode);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
34
|
+
main();
|
|
35
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* spine settings
|
|
4
|
+
*
|
|
5
|
+
* Read and write commands for editable spine-config fields (FR-CFG-03).
|
|
6
|
+
* Usage:
|
|
7
|
+
* spine settings show [path] [--json]
|
|
8
|
+
* spine settings set <path> <value> [--dry-run] [--json]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
|
|
13
|
+
import { isCliEntrypoint } from "./spine-cli/shared.mjs";
|
|
14
|
+
import { loadSpineConfig, loadSpineConfigFile } from "./spine-config.mjs";
|
|
15
|
+
import { formatSettingsShow } from "../src/cli/settings-show.mjs";
|
|
16
|
+
import {
|
|
17
|
+
runSettingsSetOperation,
|
|
18
|
+
writeSpineConfigAtomic,
|
|
19
|
+
} from "../src/cli/settings-set.mjs";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @param {object} options
|
|
23
|
+
* @param {string} options.projectRoot
|
|
24
|
+
* @param {string[]} options.args
|
|
25
|
+
*/
|
|
26
|
+
export function runSpineSettingsShow({ projectRoot, args }) {
|
|
27
|
+
const json = args.includes("--json");
|
|
28
|
+
const settingPath = args.find((arg) => !arg.startsWith("--")) ?? undefined;
|
|
29
|
+
|
|
30
|
+
const configResult = loadSpineConfig(projectRoot);
|
|
31
|
+
if (configResult.error) {
|
|
32
|
+
const message = configResult.error.message;
|
|
33
|
+
const suggestedCommand = configResult.error.suggestedCommand;
|
|
34
|
+
if (json) {
|
|
35
|
+
return {
|
|
36
|
+
exitCode: 1,
|
|
37
|
+
output: `${JSON.stringify({ error: message, suggestedCommand }, null, 2)}\n`,
|
|
38
|
+
suggestedCommand,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
exitCode: 1,
|
|
43
|
+
output: `Error: ${message}\nSuggested: ${suggestedCommand}\n`,
|
|
44
|
+
suggestedCommand,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return formatSettingsShow(configResult.config, {
|
|
49
|
+
path: settingPath,
|
|
50
|
+
json,
|
|
51
|
+
sources: configResult.sources,
|
|
52
|
+
envVars: configResult.envVars,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {object} options
|
|
58
|
+
* @param {string} options.projectRoot
|
|
59
|
+
* @param {string[]} options.args
|
|
60
|
+
*/
|
|
61
|
+
export function runSpineSettingsSet({ projectRoot, args }) {
|
|
62
|
+
const json = args.includes("--json");
|
|
63
|
+
const dryRun = args.includes("--dry-run");
|
|
64
|
+
const positional = args.filter((arg) => !arg.startsWith("--"));
|
|
65
|
+
|
|
66
|
+
if (positional.length < 2) {
|
|
67
|
+
const message = "Usage: spine settings set <path> <value> [--dry-run] [--json]";
|
|
68
|
+
if (json) {
|
|
69
|
+
return {
|
|
70
|
+
exitCode: 1,
|
|
71
|
+
output: `${JSON.stringify({ error: message }, null, 2)}\n`,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
exitCode: 1,
|
|
76
|
+
output: `Error: ${message}\n`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const [settingPath, ...valueParts] = positional;
|
|
81
|
+
const rawValue = valueParts.join(" ");
|
|
82
|
+
|
|
83
|
+
const configResult = loadSpineConfigFile(projectRoot);
|
|
84
|
+
if (configResult.error) {
|
|
85
|
+
const message = configResult.error.message;
|
|
86
|
+
const suggestedCommand = configResult.error.suggestedCommand;
|
|
87
|
+
if (json) {
|
|
88
|
+
return {
|
|
89
|
+
exitCode: 1,
|
|
90
|
+
output: `${JSON.stringify({ error: message, suggestedCommand }, null, 2)}\n`,
|
|
91
|
+
suggestedCommand,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
exitCode: 1,
|
|
96
|
+
output: `Error: ${message}\nSuggested: ${suggestedCommand}\n`,
|
|
97
|
+
suggestedCommand,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const result = runSettingsSetOperation(configResult.config, {
|
|
102
|
+
path: settingPath,
|
|
103
|
+
rawValue,
|
|
104
|
+
dryRun,
|
|
105
|
+
json,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if (result.exitCode !== 0) {
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!dryRun && result.config) {
|
|
113
|
+
try {
|
|
114
|
+
writeSpineConfigAtomic(projectRoot, result.config);
|
|
115
|
+
} catch (err) {
|
|
116
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
117
|
+
if (json) {
|
|
118
|
+
return {
|
|
119
|
+
exitCode: 1,
|
|
120
|
+
output: `${JSON.stringify({ error: `Failed to write spine config: ${message}` }, null, 2)}\n`,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
exitCode: 1,
|
|
125
|
+
output: `Error: Failed to write spine config: ${message}\n`,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {object} options
|
|
135
|
+
* @param {string} options.projectRoot
|
|
136
|
+
* @param {string[]} options.args
|
|
137
|
+
*/
|
|
138
|
+
export function runSpineSettings({ projectRoot, args }) {
|
|
139
|
+
const sub = args[0];
|
|
140
|
+
|
|
141
|
+
if (sub === "show" || sub === undefined) {
|
|
142
|
+
const showArgs = sub === "show" ? args.slice(1) : args;
|
|
143
|
+
return runSpineSettingsShow({ projectRoot, args: showArgs });
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (sub === "set") {
|
|
147
|
+
return runSpineSettingsSet({ projectRoot, args: args.slice(1) });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
exitCode: 1,
|
|
152
|
+
output: `Error: Unknown settings subcommand: ${sub}\nRun spine settings show [path] [--json] or spine settings set <path> <value> for usage.\n`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function printSettingsHelp() {
|
|
157
|
+
console.log(`
|
|
158
|
+
Usage:
|
|
159
|
+
spine settings show [path] [--json]
|
|
160
|
+
spine settings set <path> <value> [--dry-run] [--json]
|
|
161
|
+
|
|
162
|
+
Show editable spine-config fields and their current values.
|
|
163
|
+
With path, print a single registered setting value.
|
|
164
|
+
|
|
165
|
+
Set updates one registered field after validation; use --dry-run to preview without writing.
|
|
166
|
+
`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function main() {
|
|
170
|
+
const argv = process.argv.slice(2);
|
|
171
|
+
|
|
172
|
+
if (argv.includes("--help") || argv.includes("-h")) {
|
|
173
|
+
printSettingsHelp();
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const result = runSpineSettings({ projectRoot: process.cwd(), args: argv });
|
|
178
|
+
process.stdout.write(result.output);
|
|
179
|
+
if (result.exitCode !== 0) {
|
|
180
|
+
process.exit(result.exitCode);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (isCliEntrypoint(import.meta.url)) {
|
|
185
|
+
main();
|
|
186
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import {
|
|
3
|
+
loadSpineBatchState,
|
|
4
|
+
resolveBatchStateFileForValidation,
|
|
5
|
+
validateBatchState,
|
|
6
|
+
} from "../src/batch/state.mjs";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {object} options
|
|
10
|
+
* @param {string} options.projectRoot
|
|
11
|
+
* @param {string[]} options.args
|
|
12
|
+
*/
|
|
13
|
+
export function runSpineState(options) {
|
|
14
|
+
const { projectRoot, args } = options;
|
|
15
|
+
const subcommand = args[0];
|
|
16
|
+
|
|
17
|
+
if (subcommand !== "validate") {
|
|
18
|
+
return {
|
|
19
|
+
exitCode: 1,
|
|
20
|
+
output: "Usage: spine state validate [--batch ID] [--json] [--diagnose]\n",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const batchIdx = args.indexOf("--batch");
|
|
25
|
+
const batchId = batchIdx >= 0 ? args[batchIdx + 1] : null;
|
|
26
|
+
const json = args.includes("--json");
|
|
27
|
+
const diagnose = args.includes("--diagnose");
|
|
28
|
+
|
|
29
|
+
const resolved = resolveBatchStateFileForValidation(projectRoot, batchId);
|
|
30
|
+
if (!resolved.path) {
|
|
31
|
+
const message = resolved.error ?? "No batch-state file found";
|
|
32
|
+
if (json) {
|
|
33
|
+
return {
|
|
34
|
+
exitCode: 1,
|
|
35
|
+
output: `${JSON.stringify({ ok: false, error: message }, null, 2)}\n`,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
exitCode: 1,
|
|
40
|
+
output: `❌ ${message}\n → spine status --diagnose\n`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let raw;
|
|
45
|
+
try {
|
|
46
|
+
raw = JSON.parse(fs.readFileSync(resolved.path, "utf-8"));
|
|
47
|
+
} catch (err) {
|
|
48
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
49
|
+
if (json) {
|
|
50
|
+
return {
|
|
51
|
+
exitCode: 1,
|
|
52
|
+
output: `${JSON.stringify({ ok: false, path: resolved.path, parseError: message }, null, 2)}\n`,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
exitCode: 1,
|
|
57
|
+
output: `❌ Cannot parse batch state at ${resolved.path}: ${message}\n → spine state validate --diagnose\n`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const result = validateBatchState(raw);
|
|
62
|
+
const payload = {
|
|
63
|
+
ok: result.ok,
|
|
64
|
+
path: resolved.path,
|
|
65
|
+
source: resolved.source,
|
|
66
|
+
batchId: raw.batchId ?? batchId ?? null,
|
|
67
|
+
errors: result.ok ? [] : result.errors,
|
|
68
|
+
suggestedCommand: result.ok ? null : result.suggestedCommand,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
if (json) {
|
|
72
|
+
return {
|
|
73
|
+
exitCode: result.ok ? 0 : 1,
|
|
74
|
+
output: `${JSON.stringify(payload, null, 2)}\n`,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (result.ok) {
|
|
79
|
+
return {
|
|
80
|
+
exitCode: 0,
|
|
81
|
+
output: `✅ Batch state valid (${resolved.source}: ${resolved.path})\n`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const lines = [
|
|
86
|
+
`❌ Batch state validation failed (${resolved.path})`,
|
|
87
|
+
"",
|
|
88
|
+
...result.errors.map((error) => ` • ${error}`),
|
|
89
|
+
"",
|
|
90
|
+
` → ${result.suggestedCommand}`,
|
|
91
|
+
];
|
|
92
|
+
|
|
93
|
+
if (diagnose) {
|
|
94
|
+
const active = loadSpineBatchState(projectRoot);
|
|
95
|
+
lines.push("", " Active state snapshot:");
|
|
96
|
+
lines.push(` phase: ${String(raw.phase ?? "unknown")}`);
|
|
97
|
+
lines.push(` batchId: ${String(raw.batchId ?? "unknown")}`);
|
|
98
|
+
lines.push(` tasks: ${Array.isArray(raw.tasks) ? raw.tasks.length : 0}`);
|
|
99
|
+
lines.push(` lanes: ${Array.isArray(raw.lanes) ? raw.lanes.length : 0}`);
|
|
100
|
+
if (active.parseError) {
|
|
101
|
+
lines.push(` active parse error: ${active.parseError}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
lines.push("");
|
|
106
|
+
return {
|
|
107
|
+
exitCode: 1,
|
|
108
|
+
output: lines.join("\n"),
|
|
109
|
+
};
|
|
110
|
+
}
|