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,257 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Atomic task retry and skip (TP-017, PRD §18.5, FR-BATCH-09/10).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
countPendingSegments,
|
|
7
|
+
loadSpineBatchState,
|
|
8
|
+
recomputeTaskCounters,
|
|
9
|
+
recordTaskTransition,
|
|
10
|
+
resetTaskForRetry,
|
|
11
|
+
updateSegmentForTask,
|
|
12
|
+
validateBatchState,
|
|
13
|
+
} from "./state.mjs";
|
|
14
|
+
|
|
15
|
+
const RETRY_ALLOWED_PHASES = new Set(["paused", "failed"]);
|
|
16
|
+
const RETRY_BLOCKED_PHASES = new Set(["running", "planning"]);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {object} state
|
|
20
|
+
* @param {string} taskId
|
|
21
|
+
*/
|
|
22
|
+
function findTask(state, taskId) {
|
|
23
|
+
return (state.tasks ?? []).find(
|
|
24
|
+
(task) => task && typeof task === "object" && task.taskId === taskId,
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {object} state
|
|
30
|
+
*/
|
|
31
|
+
export function detectSegmentDrift(state) {
|
|
32
|
+
return (state.tasks ?? []).some((task) => {
|
|
33
|
+
if (!task || task.status !== "pending") return false;
|
|
34
|
+
return (state.segments ?? []).some(
|
|
35
|
+
(segment) =>
|
|
36
|
+
segment &&
|
|
37
|
+
segment.taskId === task.taskId &&
|
|
38
|
+
(segment.status === "failed" || segment.status === "succeeded"),
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {object} params
|
|
45
|
+
* @param {string} params.projectRoot
|
|
46
|
+
* @param {string} params.taskId
|
|
47
|
+
*/
|
|
48
|
+
export function retryTask({ projectRoot, taskId }) {
|
|
49
|
+
const loaded = loadSpineBatchState(projectRoot);
|
|
50
|
+
if (!loaded.raw) {
|
|
51
|
+
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const state = loaded.raw;
|
|
55
|
+
const phase = String(state.phase ?? "");
|
|
56
|
+
|
|
57
|
+
if (RETRY_BLOCKED_PHASES.has(phase)) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
exitCode: 1,
|
|
61
|
+
error: "cannot_retry",
|
|
62
|
+
output: `Cannot retry task while batch phase is ${phase}. Pause the batch first.\n`,
|
|
63
|
+
batchId: state.batchId,
|
|
64
|
+
phase,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!RETRY_ALLOWED_PHASES.has(phase)) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
exitCode: 1,
|
|
72
|
+
error: "cannot_retry",
|
|
73
|
+
output: `Cannot retry task in batch phase ${phase}. Retry is allowed in paused or failed batches.\n`,
|
|
74
|
+
batchId: state.batchId,
|
|
75
|
+
phase,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const validation = validateBatchState(state);
|
|
80
|
+
if (!validation.ok) {
|
|
81
|
+
return {
|
|
82
|
+
ok: false,
|
|
83
|
+
exitCode: 1,
|
|
84
|
+
error: "invalid_batch_state",
|
|
85
|
+
output: `Batch state validation failed:\n ${validation.errors.join("\n ")}\n`,
|
|
86
|
+
batchId: state.batchId,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const task = findTask(state, taskId);
|
|
91
|
+
if (!task) {
|
|
92
|
+
return {
|
|
93
|
+
ok: false,
|
|
94
|
+
exitCode: 1,
|
|
95
|
+
error: "task_not_found",
|
|
96
|
+
output: `Task ${taskId} not found in batch ${state.batchId}.\n`,
|
|
97
|
+
batchId: state.batchId,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const taskStatus = String(task.status ?? "");
|
|
102
|
+
const segmentFailed = (state.segments ?? []).some(
|
|
103
|
+
(segment) => segment?.taskId === taskId && segment.status === "failed",
|
|
104
|
+
);
|
|
105
|
+
if (taskStatus !== "failed" && !(taskStatus === "pending" && segmentFailed)) {
|
|
106
|
+
return {
|
|
107
|
+
ok: false,
|
|
108
|
+
exitCode: 1,
|
|
109
|
+
error: "task_not_retryable",
|
|
110
|
+
output: `Task ${taskId} is ${taskStatus} — only failed tasks (or pending with failed segments) can be retried.\n`,
|
|
111
|
+
batchId: state.batchId,
|
|
112
|
+
taskId,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const reset = resetTaskForRetry(state, taskId);
|
|
117
|
+
if (!reset) {
|
|
118
|
+
return {
|
|
119
|
+
ok: false,
|
|
120
|
+
exitCode: 1,
|
|
121
|
+
error: "task_not_found",
|
|
122
|
+
output: `Task ${taskId} not found.\n`,
|
|
123
|
+
batchId: state.batchId,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
state.phase = "failed";
|
|
128
|
+
state.endedAt = null;
|
|
129
|
+
state.lastError = null;
|
|
130
|
+
state.resilience = state.resilience ?? {};
|
|
131
|
+
state.resilience.retryCountByScope = state.resilience.retryCountByScope ?? {};
|
|
132
|
+
state.resilience.retryCountByScope[taskId] = (state.resilience.retryCountByScope[taskId] ?? 0) + 1;
|
|
133
|
+
|
|
134
|
+
const pendingSegments = countPendingSegments(state, taskId);
|
|
135
|
+
recordTaskTransition({
|
|
136
|
+
projectRoot,
|
|
137
|
+
state,
|
|
138
|
+
journalType: "task.retry_requested",
|
|
139
|
+
journalPayload: {
|
|
140
|
+
taskId,
|
|
141
|
+
previousClassification: reset.previousClassification,
|
|
142
|
+
pendingSegments,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
ok: true,
|
|
148
|
+
exitCode: 0,
|
|
149
|
+
batchId: state.batchId,
|
|
150
|
+
taskId,
|
|
151
|
+
pendingSegments,
|
|
152
|
+
output: `Task ${taskId} reset for retry (pendingSegments=${pendingSegments}).\n → spine batch resume --force\n`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {object} params
|
|
158
|
+
* @param {string} params.projectRoot
|
|
159
|
+
* @param {string} params.taskId
|
|
160
|
+
*/
|
|
161
|
+
export function skipTask({ projectRoot, taskId }) {
|
|
162
|
+
const loaded = loadSpineBatchState(projectRoot);
|
|
163
|
+
if (!loaded.raw) {
|
|
164
|
+
return { ok: false, exitCode: 1, error: "no_active_batch", output: "No active pi-spine batch.\n" };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const state = loaded.raw;
|
|
168
|
+
const phase = String(state.phase ?? "");
|
|
169
|
+
|
|
170
|
+
if (RETRY_BLOCKED_PHASES.has(phase)) {
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
exitCode: 1,
|
|
174
|
+
error: "cannot_skip",
|
|
175
|
+
output: `Cannot skip task while batch phase is ${phase}. Pause the batch first.\n`,
|
|
176
|
+
batchId: state.batchId,
|
|
177
|
+
phase,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const validation = validateBatchState(state);
|
|
182
|
+
if (!validation.ok) {
|
|
183
|
+
return {
|
|
184
|
+
ok: false,
|
|
185
|
+
exitCode: 1,
|
|
186
|
+
error: "invalid_batch_state",
|
|
187
|
+
output: `Batch state validation failed:\n ${validation.errors.join("\n ")}\n`,
|
|
188
|
+
batchId: state.batchId,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const task = findTask(state, taskId);
|
|
193
|
+
if (!task) {
|
|
194
|
+
return {
|
|
195
|
+
ok: false,
|
|
196
|
+
exitCode: 1,
|
|
197
|
+
error: "task_not_found",
|
|
198
|
+
output: `Task ${taskId} not found in batch ${state.batchId}.\n`,
|
|
199
|
+
batchId: state.batchId,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const taskStatus = String(task.status ?? "");
|
|
204
|
+
if (taskStatus === "succeeded" || taskStatus === "skipped") {
|
|
205
|
+
return {
|
|
206
|
+
ok: false,
|
|
207
|
+
exitCode: 1,
|
|
208
|
+
error: "task_not_skippable",
|
|
209
|
+
output: `Task ${taskId} is already ${taskStatus}.\n`,
|
|
210
|
+
batchId: state.batchId,
|
|
211
|
+
taskId,
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
task.status = "skipped";
|
|
216
|
+
task.endedAt = Date.now();
|
|
217
|
+
task.exitReason = "skipped_by_operator";
|
|
218
|
+
updateSegmentForTask(state, taskId, "skipped");
|
|
219
|
+
|
|
220
|
+
state.blockedTaskIds = (state.blockedTaskIds ?? []).filter((id) => id !== taskId);
|
|
221
|
+
recomputeTaskCounters(state);
|
|
222
|
+
|
|
223
|
+
const allTerminal = (state.tasks ?? []).every((entry) => {
|
|
224
|
+
const status = String(entry?.status ?? "");
|
|
225
|
+
return status === "succeeded" || status === "skipped";
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
if (allTerminal && state.mergeResults.length === 0) {
|
|
229
|
+
state.phase = "failed";
|
|
230
|
+
state.lastError = null;
|
|
231
|
+
} else if (allTerminal) {
|
|
232
|
+
state.phase = "completed";
|
|
233
|
+
state.endedAt = Date.now();
|
|
234
|
+
} else {
|
|
235
|
+
state.phase = phase === "paused" ? "paused" : "failed";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
recordTaskTransition({
|
|
239
|
+
projectRoot,
|
|
240
|
+
state,
|
|
241
|
+
journalType: "task.skipped",
|
|
242
|
+
journalPayload: {
|
|
243
|
+
taskId,
|
|
244
|
+
previousStatus: taskStatus,
|
|
245
|
+
},
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
return {
|
|
249
|
+
ok: true,
|
|
250
|
+
exitCode: 0,
|
|
251
|
+
batchId: state.batchId,
|
|
252
|
+
taskId,
|
|
253
|
+
output: allTerminal
|
|
254
|
+
? `Task ${taskId} skipped. All batch tasks are terminal — resume or merge as needed.\n → spine batch resume --force\n`
|
|
255
|
+
: `Task ${taskId} skipped.\n → spine batch resume --force\n`,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review-type-specific scope paths for reviewer Cursor rule glob matching (SP-249).
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { execFileSync } from "node:child_process";
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import path from "node:path";
|
|
8
|
+
import { parsePrompt } from "../tasks/packet/parse-prompt.mjs";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Paths excluded from reviewer glob scope (runtime artifacts, not product code).
|
|
12
|
+
* @param {string} filePath
|
|
13
|
+
*/
|
|
14
|
+
export function isNoiseReviewScopePath(filePath) {
|
|
15
|
+
const normalized = String(filePath ?? "")
|
|
16
|
+
.replace(/\\/g, "/")
|
|
17
|
+
.replace(/^\.\/+/, "");
|
|
18
|
+
|
|
19
|
+
if (normalized === ".DONE" || normalized.endsWith("/.DONE")) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (normalized.includes("/.reviews/") || normalized.startsWith(".reviews/")) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (normalized.includes("/.spine/runtime/") || normalized.startsWith(".spine/runtime/")) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {string[]} paths
|
|
33
|
+
* @returns {string[]}
|
|
34
|
+
*/
|
|
35
|
+
export function filterReviewScopeNoise(paths) {
|
|
36
|
+
if (!Array.isArray(paths)) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
const filtered = [];
|
|
40
|
+
const seen = new Set();
|
|
41
|
+
for (const raw of paths) {
|
|
42
|
+
const trimmed = String(raw ?? "").trim();
|
|
43
|
+
if (!trimmed || isNoiseReviewScopePath(trimmed)) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (seen.has(trimmed)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
seen.add(trimmed);
|
|
50
|
+
filtered.push(trimmed);
|
|
51
|
+
}
|
|
52
|
+
return filtered;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param {string} taskFolder
|
|
57
|
+
* @returns {string[]}
|
|
58
|
+
*/
|
|
59
|
+
export function resolvePlanReviewScopePaths(taskFolder) {
|
|
60
|
+
const promptPath = path.join(taskFolder, "PROMPT.md");
|
|
61
|
+
if (!fs.existsSync(promptPath)) {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
const markdown = fs.readFileSync(promptPath, "utf-8");
|
|
65
|
+
const parsed = parsePrompt(markdown);
|
|
66
|
+
return filterReviewScopeNoise(parsed.fileScope ?? []);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {string} worktreePath
|
|
71
|
+
* @param {string} [baseline]
|
|
72
|
+
* @param {(command: string, args: string[], cwd: string) => string} [runGit]
|
|
73
|
+
* @returns {string[]}
|
|
74
|
+
*/
|
|
75
|
+
export function resolveCodeReviewScopePaths(worktreePath, baseline, runGit = defaultRunGit) {
|
|
76
|
+
const args = baseline ? ["diff", "--name-only", `${baseline}..HEAD`] : ["diff", "--name-only"];
|
|
77
|
+
try {
|
|
78
|
+
const output = runGit("git", args, worktreePath);
|
|
79
|
+
const paths = output
|
|
80
|
+
.split(/\r?\n/)
|
|
81
|
+
.map((line) => line.trim())
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
return filterReviewScopeNoise(paths);
|
|
84
|
+
} catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {string} command
|
|
91
|
+
* @param {string[]} args
|
|
92
|
+
* @param {string} cwd
|
|
93
|
+
*/
|
|
94
|
+
function defaultRunGit(command, args, cwd) {
|
|
95
|
+
return execFileSync(command, args, {
|
|
96
|
+
cwd,
|
|
97
|
+
encoding: "utf-8",
|
|
98
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolve scope paths for reviewer rule glob matching by review phase.
|
|
104
|
+
*
|
|
105
|
+
* @param {object} params
|
|
106
|
+
* @param {string} params.worktreePath Git worktree root for code reviews
|
|
107
|
+
* @param {string} [params.baseline] Baseline commit for code review diff (optional)
|
|
108
|
+
* @param {"plan"|"code"|"final"} params.reviewType Review phase
|
|
109
|
+
* @param {string} params.taskFolder Absolute path to task packet folder
|
|
110
|
+
* @param {(command: string, args: string[], cwd: string) => string} [params.runGit] Injectable git runner for tests
|
|
111
|
+
* @returns {{ scopePaths: string[] }}
|
|
112
|
+
*/
|
|
113
|
+
export function resolveReviewScopePaths({
|
|
114
|
+
worktreePath,
|
|
115
|
+
baseline,
|
|
116
|
+
reviewType,
|
|
117
|
+
taskFolder,
|
|
118
|
+
runGit,
|
|
119
|
+
}) {
|
|
120
|
+
/** @type {string[]} */
|
|
121
|
+
let scopePaths;
|
|
122
|
+
switch (reviewType) {
|
|
123
|
+
case "plan":
|
|
124
|
+
scopePaths = resolvePlanReviewScopePaths(taskFolder);
|
|
125
|
+
break;
|
|
126
|
+
case "code":
|
|
127
|
+
scopePaths = resolveCodeReviewScopePaths(worktreePath, baseline, runGit);
|
|
128
|
+
break;
|
|
129
|
+
case "final":
|
|
130
|
+
scopePaths = [];
|
|
131
|
+
break;
|
|
132
|
+
default:
|
|
133
|
+
scopePaths = [];
|
|
134
|
+
}
|
|
135
|
+
return { scopePaths };
|
|
136
|
+
}
|