@oevery/rsp 3.1.0-beta.0 → 3.1.0-beta.2
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/README.md +77 -74
- package/README.zh-CN.md +71 -53
- package/dist/chunk-4K53353L.mjs +322 -0
- package/dist/{chunk-QLXIDVKK.mjs → chunk-EALHA3ZS.mjs} +99 -1038
- package/dist/chunk-JOMFFQRG.mjs +99 -0
- package/dist/chunk-OTJFL6XH.mjs +1022 -0
- package/dist/cli.mjs +95 -264
- package/dist/{entry-LAPR3TNI.mjs → entry-N7WLWGTI.mjs} +8 -92
- package/dist/entry-UWUX3HM7.mjs +174 -0
- package/package.json +13 -11
- package/rules/rsp-rules.md +10 -12
- package/skills/rsp/SKILL.md +45 -172
- package/skills/rsp/references/conflict-handling.md +11 -0
- package/skills/rsp/references/durable-review.md +17 -0
- package/skills/rsp/references/groups-dependencies.md +11 -0
- package/skills/rsp/references/managed-routing.md +45 -0
- package/skills/rsp/references/setup-repair.md +11 -0
- package/skills/rsp-address-review/SKILL.md +5 -5
- package/skills/rsp-codebase-audit/SKILL.md +69 -0
- package/skills/rsp-codebase-audit/references/structural-lenses.md +35 -0
- package/skills/rsp-commit/SKILL.md +42 -0
- package/skills/rsp-design/SKILL.md +14 -9
- package/skills/rsp-manage/SKILL.md +24 -25
- package/skills/rsp-release-docs/SKILL.md +36 -81
- package/skills/rsp-release-docs/references/evidence-and-surfaces.md +21 -0
- package/skills/rsp-release-docs/references/output-contracts.md +0 -18
- package/skills/rsp-release-docs/references/publication-lifecycle.md +24 -0
- package/skills/rsp-shape/SKILL.md +19 -17
- package/skills/rsp-shape/references/complex-shaping.md +2 -2
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/core/config.ts
|
|
4
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
5
|
+
import { dirname as dirname3, join as join4 } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import pc from "picocolors";
|
|
8
|
+
|
|
9
|
+
// src/core/decisions.ts
|
|
10
|
+
import { existsSync } from "fs";
|
|
11
|
+
import { mkdir, readdir as readdir2, realpath, stat } from "fs/promises";
|
|
12
|
+
import { dirname, isAbsolute, join as join2, posix, relative, resolve, sep } from "path";
|
|
13
|
+
|
|
14
|
+
// src/core/managed-path.ts
|
|
15
|
+
import { lstatSync } from "fs";
|
|
16
|
+
import { readdir, writeFile } from "fs/promises";
|
|
17
|
+
import { join } from "path";
|
|
18
|
+
var ManagedPathError = class extends Error {
|
|
19
|
+
constructor(path, message) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.path = path;
|
|
22
|
+
this.name = "ManagedPathError";
|
|
23
|
+
}
|
|
24
|
+
path;
|
|
25
|
+
};
|
|
26
|
+
function inspectManagedDirectory(path, label, options = {}) {
|
|
27
|
+
try {
|
|
28
|
+
const stats = lstatSync(path);
|
|
29
|
+
if (stats.isDirectory())
|
|
30
|
+
return { exists: true, issue: null };
|
|
31
|
+
return {
|
|
32
|
+
exists: true,
|
|
33
|
+
issue: new ManagedPathError(path, `${label} must be a real directory: ${path}`)
|
|
34
|
+
};
|
|
35
|
+
} catch (error) {
|
|
36
|
+
if (error.code === "ENOENT") {
|
|
37
|
+
if (options.allowMissing)
|
|
38
|
+
return { exists: false, issue: null };
|
|
39
|
+
return {
|
|
40
|
+
exists: false,
|
|
41
|
+
issue: new ManagedPathError(path, `${label} must be a real directory: ${path}`)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
45
|
+
return {
|
|
46
|
+
exists: false,
|
|
47
|
+
issue: new ManagedPathError(path, `unable to inspect ${label} ${path}: ${message}`)
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function requireManagedDirectory(path, label, options = {}) {
|
|
52
|
+
const inspection = inspectManagedDirectory(path, label, options);
|
|
53
|
+
if (inspection.issue)
|
|
54
|
+
throw inspection.issue;
|
|
55
|
+
return inspection.exists;
|
|
56
|
+
}
|
|
57
|
+
function inspectManagedFile(path, label, options = {}) {
|
|
58
|
+
try {
|
|
59
|
+
const stats = lstatSync(path);
|
|
60
|
+
if (stats.isFile())
|
|
61
|
+
return { exists: true, issue: null };
|
|
62
|
+
return {
|
|
63
|
+
exists: true,
|
|
64
|
+
issue: new ManagedPathError(path, `${label} must be a regular file: ${path}`)
|
|
65
|
+
};
|
|
66
|
+
} catch (error) {
|
|
67
|
+
if (error.code === "ENOENT") {
|
|
68
|
+
if (options.allowMissing)
|
|
69
|
+
return { exists: false, issue: null };
|
|
70
|
+
return {
|
|
71
|
+
exists: false,
|
|
72
|
+
issue: new ManagedPathError(path, `${label} must be a regular file: ${path}`)
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
76
|
+
return {
|
|
77
|
+
exists: false,
|
|
78
|
+
issue: new ManagedPathError(path, `unable to inspect ${label} ${path}: ${message}`)
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function requireManagedFile(path, label, options = {}) {
|
|
83
|
+
const inspection = inspectManagedFile(path, label, options);
|
|
84
|
+
if (inspection.issue)
|
|
85
|
+
throw inspection.issue;
|
|
86
|
+
return inspection.exists;
|
|
87
|
+
}
|
|
88
|
+
async function ensureManagedFile(path, content, label) {
|
|
89
|
+
if (requireManagedFile(path, label, { allowMissing: true }))
|
|
90
|
+
return false;
|
|
91
|
+
await writeFile(path, content, { flag: "wx" });
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
async function writeManagedFile(path, content, label) {
|
|
95
|
+
const exists = requireManagedFile(path, label, { allowMissing: true });
|
|
96
|
+
if (exists)
|
|
97
|
+
await writeFile(path, content);
|
|
98
|
+
else
|
|
99
|
+
await writeFile(path, content, { flag: "wx" });
|
|
100
|
+
}
|
|
101
|
+
function resolveManagedDirectoryChain(root, segments, label) {
|
|
102
|
+
requireManagedDirectory(root, `${label} root`);
|
|
103
|
+
let current = root;
|
|
104
|
+
for (const segment of segments) {
|
|
105
|
+
if (!segment || segment === "." || segment === ".." || segment.includes("/") || segment.includes("\\"))
|
|
106
|
+
throw new ManagedPathError(current, `${label} contains an invalid directory segment: ${segment}`);
|
|
107
|
+
current = join(current, segment);
|
|
108
|
+
requireManagedDirectory(current, label, { allowMissing: true });
|
|
109
|
+
}
|
|
110
|
+
return current;
|
|
111
|
+
}
|
|
112
|
+
async function inspectManagedFileTree(root, label, options = {}) {
|
|
113
|
+
const result = { rootExists: false, files: [], issues: [] };
|
|
114
|
+
const rootInspection = inspectManagedDirectory(root, `${label} root`, options);
|
|
115
|
+
if (rootInspection.issue) {
|
|
116
|
+
result.issues.push(rootInspection.issue);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
if (!rootInspection.exists)
|
|
120
|
+
return result;
|
|
121
|
+
result.rootExists = true;
|
|
122
|
+
await collectManagedFiles(root, label, result);
|
|
123
|
+
result.files.sort();
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
async function collectManagedFiles(directory, label, result) {
|
|
127
|
+
let entries;
|
|
128
|
+
try {
|
|
129
|
+
entries = await readdir(directory, { withFileTypes: true });
|
|
130
|
+
} catch (error) {
|
|
131
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
132
|
+
result.issues.push(new ManagedPathError(directory, `unable to inspect the ${label} tree at ${directory}: ${message}`));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
136
|
+
if (entry.name.startsWith("."))
|
|
137
|
+
continue;
|
|
138
|
+
const path = join(directory, entry.name);
|
|
139
|
+
if (entry.isDirectory()) {
|
|
140
|
+
await collectManagedFiles(path, label, result);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (entry.isFile()) {
|
|
144
|
+
result.files.push(path);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
result.issues.push(new ManagedPathError(path, `unsupported entry in the ${label} tree: ${path}`));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/core/decisions.ts
|
|
152
|
+
var DEFAULT_DECISION_RECORDS_PATH = ".rsp/specs/decisions";
|
|
153
|
+
function normalizeDecisionRecordsPath(pathValue) {
|
|
154
|
+
return posix.normalize(pathValue.trim().replace(/\\/g, "/")).replace(/^\.\//, "").replace(/\/$/, "");
|
|
155
|
+
}
|
|
156
|
+
function validateDecisionRecordsPath(pathValue) {
|
|
157
|
+
if (typeof pathValue !== "string" || pathValue.trim() === "")
|
|
158
|
+
return 'config.yaml field "decisions.path" must be a non-empty string';
|
|
159
|
+
const raw = pathValue.trim();
|
|
160
|
+
const portable = raw.replace(/\\/g, "/");
|
|
161
|
+
if (isAbsolute(raw) || posix.isAbsolute(portable) || /^[a-z]:[\\/]/i.test(raw))
|
|
162
|
+
return 'config.yaml field "decisions.path" must be project-relative';
|
|
163
|
+
const normalized = normalizeDecisionRecordsPath(raw);
|
|
164
|
+
if (normalized === "." || normalized === ".." || normalized.startsWith("../"))
|
|
165
|
+
return 'config.yaml field "decisions.path" must stay inside the Host Project';
|
|
166
|
+
if ((normalized === ".rsp" || normalized.startsWith(".rsp/")) && normalized !== DEFAULT_DECISION_RECORDS_PATH)
|
|
167
|
+
return `config.yaml field "decisions.path" must use ${DEFAULT_DECISION_RECORDS_PATH} or a path outside .rsp/`;
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function getDecisionRecordsConfigIssue(config) {
|
|
171
|
+
if (!("decisions" in config))
|
|
172
|
+
return null;
|
|
173
|
+
const decisions = config.decisions;
|
|
174
|
+
if (!decisions || typeof decisions !== "object" || Array.isArray(decisions))
|
|
175
|
+
return 'config.yaml field "decisions" must be a mapping with one path';
|
|
176
|
+
const keys = Object.keys(decisions);
|
|
177
|
+
if (keys.length !== 1 || keys[0] !== "path")
|
|
178
|
+
return 'config.yaml field "decisions" supports only "path"';
|
|
179
|
+
return validateDecisionRecordsPath(decisions.path);
|
|
180
|
+
}
|
|
181
|
+
function resolveDecisionRecordsPath(config) {
|
|
182
|
+
const configured = config.decisions?.path;
|
|
183
|
+
return configured && validateDecisionRecordsPath(configured) === null ? normalizeDecisionRecordsPath(configured) : DEFAULT_DECISION_RECORDS_PATH;
|
|
184
|
+
}
|
|
185
|
+
async function ensureDecisionRecordsDirectory(pathValue) {
|
|
186
|
+
const filesystemError = await validateDecisionRecordsFilesystemPath(pathValue);
|
|
187
|
+
if (filesystemError)
|
|
188
|
+
throw new Error(filesystemError);
|
|
189
|
+
const existed = existsSync(pathValue);
|
|
190
|
+
await mkdir(pathValue, { recursive: true });
|
|
191
|
+
const entries = await readdir2(pathValue);
|
|
192
|
+
if (entries.length === 0) {
|
|
193
|
+
await ensureManagedFile(join2(pathValue, ".gitkeep"), "", "Decision Record placeholder");
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
if (entries.includes(".gitkeep"))
|
|
197
|
+
requireManagedFile(join2(pathValue, ".gitkeep"), "Decision Record placeholder");
|
|
198
|
+
return !existed;
|
|
199
|
+
}
|
|
200
|
+
async function validateDecisionRecordsFilesystemPath(pathValue) {
|
|
201
|
+
const projectRoot = await realpath(".");
|
|
202
|
+
let existingAncestor = resolve(pathValue);
|
|
203
|
+
while (!existsSync(existingAncestor)) {
|
|
204
|
+
const parent = dirname(existingAncestor);
|
|
205
|
+
if (parent === existingAncestor)
|
|
206
|
+
return `Decision Record path "${pathValue}" has no accessible Host Project ancestor`;
|
|
207
|
+
existingAncestor = parent;
|
|
208
|
+
}
|
|
209
|
+
const resolvedAncestor = await realpath(existingAncestor);
|
|
210
|
+
const rel = relative(projectRoot, resolvedAncestor);
|
|
211
|
+
if (rel === ".." || rel.startsWith(`..${sep}`) || isAbsolute(rel))
|
|
212
|
+
return `Decision Record path "${pathValue}" resolves outside the Host Project through ${existingAncestor}`;
|
|
213
|
+
if (existsSync(resolve(pathValue)) && !(await stat(resolve(pathValue))).isDirectory())
|
|
214
|
+
return `Decision Record path "${pathValue}" must be a directory`;
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// src/core/helpers.ts
|
|
219
|
+
import { existsSync as existsSync2 } from "fs";
|
|
220
|
+
import { readdir as readdir3, readFile, rmdir } from "fs/promises";
|
|
221
|
+
import { basename, dirname as dirname2, join as join3, relative as relative2, sep as sep2 } from "path";
|
|
222
|
+
import { parse } from "yaml";
|
|
223
|
+
var RSP_AGENTS_BEGIN = "<!-- rsp:begin -->";
|
|
224
|
+
var RSP_AGENTS_END = "<!-- rsp:end -->";
|
|
225
|
+
function parseYamlText(text) {
|
|
226
|
+
const parsed = parse(text);
|
|
227
|
+
if (parsed === null || parsed === void 0)
|
|
228
|
+
return {};
|
|
229
|
+
if (typeof parsed !== "object" || Array.isArray(parsed))
|
|
230
|
+
throw new Error("YAML document must be a mapping/object");
|
|
231
|
+
return parsed;
|
|
232
|
+
}
|
|
233
|
+
function parseFrontmatter(content) {
|
|
234
|
+
const m = content.match(/^---\r?\n([\s\S]*?)\r?\n(?:---|\.\.\.)\r?\n/);
|
|
235
|
+
if (!m)
|
|
236
|
+
return null;
|
|
237
|
+
return parseYamlText(m[1]);
|
|
238
|
+
}
|
|
239
|
+
function countCheckboxes(content) {
|
|
240
|
+
const todo = (content.match(/\[ \]/g) || []).length;
|
|
241
|
+
const progress = (content.match(/\[\/\]/g) || []).length;
|
|
242
|
+
const done = (content.match(/\[x\]/g) || []).length;
|
|
243
|
+
const dropped = (content.match(/\[-\]/g) || []).length;
|
|
244
|
+
return { todo, progress, done, dropped, total: todo + progress + done + dropped };
|
|
245
|
+
}
|
|
246
|
+
async function walkMarkdownFiles(dir, options = {}) {
|
|
247
|
+
const all = await walkFiles(dir, options);
|
|
248
|
+
return all.filter((f) => f.endsWith(".md"));
|
|
249
|
+
}
|
|
250
|
+
async function inspectUnsupportedRules() {
|
|
251
|
+
const rulesDir = join3(RSP_DIR, "rules");
|
|
252
|
+
const diagnostics = [];
|
|
253
|
+
const rawEntries = await walkAllEntries(rulesDir, diagnostics);
|
|
254
|
+
const entries = rawEntries.filter((entry) => entry.path !== OBSOLETE_RSP_RULES_PATH).map((entry) => ({
|
|
255
|
+
path: normalizeLogicalPath(relative2(rulesDir, entry.path)),
|
|
256
|
+
kind: entry.kind
|
|
257
|
+
}));
|
|
258
|
+
const obsoleteFallbackPresent = existsSync2(OBSOLETE_RSP_RULES_PATH);
|
|
259
|
+
return {
|
|
260
|
+
entries,
|
|
261
|
+
diagnostics,
|
|
262
|
+
directoryRemaining: existsSync2(rulesDir) && (!obsoleteFallbackPresent || entries.length > 0)
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
async function walkAllEntries(dir, diagnostics) {
|
|
266
|
+
const entries = [];
|
|
267
|
+
try {
|
|
268
|
+
const items = await readdir3(dir, { withFileTypes: true });
|
|
269
|
+
for (const item of items) {
|
|
270
|
+
const path = join3(dir, item.name);
|
|
271
|
+
const kind = item.isDirectory() ? "directory" : "file";
|
|
272
|
+
entries.push({ path, kind });
|
|
273
|
+
if (kind === "directory")
|
|
274
|
+
entries.push(...await walkAllEntries(path, diagnostics));
|
|
275
|
+
}
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error.code !== "ENOENT") {
|
|
278
|
+
diagnostics.push({
|
|
279
|
+
code: "walk_failed",
|
|
280
|
+
operation: "readdir",
|
|
281
|
+
path: dir,
|
|
282
|
+
message: toErrorMessage(error)
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return entries;
|
|
287
|
+
}
|
|
288
|
+
async function walkFiles(dir, options = {}) {
|
|
289
|
+
const files = [];
|
|
290
|
+
try {
|
|
291
|
+
const items = await readdir3(dir, { withFileTypes: true });
|
|
292
|
+
for (const item of items) {
|
|
293
|
+
if (item.name.startsWith("."))
|
|
294
|
+
continue;
|
|
295
|
+
const filePath = join3(dir, item.name);
|
|
296
|
+
if (item.isDirectory())
|
|
297
|
+
files.push(...await walkFiles(filePath, options));
|
|
298
|
+
else
|
|
299
|
+
files.push(filePath);
|
|
300
|
+
}
|
|
301
|
+
} catch (error) {
|
|
302
|
+
if (error.code !== "ENOENT") {
|
|
303
|
+
options.onError?.({
|
|
304
|
+
code: "walk_failed",
|
|
305
|
+
operation: "readdir",
|
|
306
|
+
path: dir,
|
|
307
|
+
message: toErrorMessage(error)
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return files;
|
|
312
|
+
}
|
|
313
|
+
function normalizeLogicalPath(pathValue) {
|
|
314
|
+
return pathValue.split(sep2).join("/").replace(/\\/g, "/");
|
|
315
|
+
}
|
|
316
|
+
function generateChangeContent(name, summary = "", kind, options = {}) {
|
|
317
|
+
const proposalSummary = summary || (name === "project-setup" ? "Capture the project model, boundaries, and stable local constraints" : "<one-line summary>");
|
|
318
|
+
if (name === "project-setup") {
|
|
319
|
+
return `---
|
|
320
|
+
kind: ops
|
|
321
|
+
---
|
|
322
|
+
|
|
323
|
+
# Change: project-setup
|
|
324
|
+
|
|
325
|
+
## Proposal
|
|
326
|
+
- Outcome: ${proposalSummary}
|
|
327
|
+
- Why:
|
|
328
|
+
- Establish a durable project model before normal implementation work starts
|
|
329
|
+
- Scope:
|
|
330
|
+
- Review the repository structure, entrypoints, and primary outputs
|
|
331
|
+
- Fill .rsp/specs/design.md with durable architecture facts
|
|
332
|
+
- Add stable navigation, context, instructions, or validation steps to project-owned CONTEXT.md or the nearest AGENTS.md when those conventions exist
|
|
333
|
+
- Non-goals:
|
|
334
|
+
- Do not duplicate durable project facts across this change, specs, and AGENTS.md
|
|
335
|
+
|
|
336
|
+
## Spec
|
|
337
|
+
### ADDED
|
|
338
|
+
- Requirement: project bootstrap capture
|
|
339
|
+
- The repository's purpose, scope, and structure are reflected in .rsp/specs/design.md
|
|
340
|
+
|
|
341
|
+
### MODIFIED
|
|
342
|
+
- Requirement: stable project-owned context and instructions
|
|
343
|
+
- Stable navigation and context are reflected in project-owned CONTEXT.md when that convention exists
|
|
344
|
+
- Stable agent instructions are reflected in the nearest project-owned AGENTS.md when needed
|
|
345
|
+
|
|
346
|
+
### Acceptance
|
|
347
|
+
#### Scenario: project model captured
|
|
348
|
+
- GIVEN an initialized RSP project
|
|
349
|
+
- WHEN project setup is completed
|
|
350
|
+
- THEN .rsp/specs/design.md reflects durable project facts
|
|
351
|
+
- AND project-owned CONTEXT.md and the nearest AGENTS.md contain only the stable context and instructions assigned to them by Host Project conventions
|
|
352
|
+
|
|
353
|
+
## Design
|
|
354
|
+
- Approach:
|
|
355
|
+
- Keep bootstrap work in this single Change while returning durable outcomes to their existing project owners
|
|
356
|
+
- Boundaries:
|
|
357
|
+
- Specs own stable current facts; project-owned CONTEXT.md and AGENTS.md retain their navigation, context, and instruction roles
|
|
358
|
+
- Affected areas:
|
|
359
|
+
- .rsp/specs/design.md
|
|
360
|
+
- Project-owned CONTEXT.md or AGENTS.md when applicable
|
|
361
|
+
- Durable outcome targets:
|
|
362
|
+
- Current facts: .rsp/specs/design.md, existing scoped Specs, CONTEXT.md, or AGENTS.md as applicable
|
|
363
|
+
- Lasting rationale: one Decision Record under the configured authoritative path, only when a hard-to-reverse tradeoff exists
|
|
364
|
+
- Constraints:
|
|
365
|
+
- Keep the setup lightweight and avoid duplicating durable project facts
|
|
366
|
+
|
|
367
|
+
## Tasks
|
|
368
|
+
- [ ] Review the repository structure, entrypoints, and primary outputs
|
|
369
|
+
- [ ] Review project-owned CONTEXT.md and AGENTS.md and confirm the RSP entry points to the right project files
|
|
370
|
+
- [ ] Fill .rsp/specs/design.md with durable architecture facts
|
|
371
|
+
- [ ] Add stable project-owned context, instructions, or validation steps only where the Host Project convention requires them
|
|
372
|
+
|
|
373
|
+
## Verify
|
|
374
|
+
- Automated:
|
|
375
|
+
- [ ] Run rsp doctor \u2014 proves: the initialized RSP workspace is structurally valid
|
|
376
|
+
- Manual or environment:
|
|
377
|
+
- [ ] Review .rsp/specs/design.md and project-owned context or instructions and confirm they match the repository
|
|
378
|
+
- Coverage:
|
|
379
|
+
- none
|
|
380
|
+
|
|
381
|
+
## Blockers
|
|
382
|
+
- none
|
|
383
|
+
`;
|
|
384
|
+
}
|
|
385
|
+
const frontmatterKind = kind ?? "<choose: feature | fix | refactor | docs | ops | research>";
|
|
386
|
+
if (options.lite)
|
|
387
|
+
return generateLiteChangeContent(name, proposalSummary, frontmatterKind);
|
|
388
|
+
const template = getChangeTemplateByKind(kind);
|
|
389
|
+
return `---
|
|
390
|
+
kind: "${frontmatterKind}"
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
# Change: ${name}
|
|
394
|
+
|
|
395
|
+
## Proposal
|
|
396
|
+
- Outcome: ${proposalSummary}
|
|
397
|
+
- Why:
|
|
398
|
+
- ${template.why}
|
|
399
|
+
- Scope:
|
|
400
|
+
- ${template.scope}
|
|
401
|
+
- Non-goals:
|
|
402
|
+
- ${template.nonGoals}
|
|
403
|
+
|
|
404
|
+
## Spec
|
|
405
|
+
${template.specSection}
|
|
406
|
+
|
|
407
|
+
### Acceptance
|
|
408
|
+
${template.acceptanceSection}
|
|
409
|
+
|
|
410
|
+
## Design
|
|
411
|
+
- Approach:
|
|
412
|
+
- ${template.approach}
|
|
413
|
+
- Boundaries:
|
|
414
|
+
- <module, interface, data, document, or ownership boundary affected>
|
|
415
|
+
- Affected areas:
|
|
416
|
+
- ${template.affectedArea1}
|
|
417
|
+
- ${template.affectedArea2}
|
|
418
|
+
- Constraints:
|
|
419
|
+
- ${template.constraints}
|
|
420
|
+
|
|
421
|
+
## Tasks
|
|
422
|
+
- [ ] ${template.task}
|
|
423
|
+
|
|
424
|
+
## Verify
|
|
425
|
+
- Automated:
|
|
426
|
+
- [ ] ${template.automatedVerify} \u2014 proves: <behavior or scope covered>
|
|
427
|
+
- Manual or environment:
|
|
428
|
+
- [ ] ${template.manualVerify}
|
|
429
|
+
- Coverage:
|
|
430
|
+
- <omitted or unavailable relevant coverage and reason, or none>
|
|
431
|
+
|
|
432
|
+
## Blockers
|
|
433
|
+
- none
|
|
434
|
+
`;
|
|
435
|
+
}
|
|
436
|
+
function generateLiteChangeContent(name, proposalSummary, frontmatterKind) {
|
|
437
|
+
return `---
|
|
438
|
+
kind: "${frontmatterKind}"
|
|
439
|
+
---
|
|
440
|
+
|
|
441
|
+
# Change: ${name}
|
|
442
|
+
|
|
443
|
+
## Proposal
|
|
444
|
+
- Outcome: ${proposalSummary}
|
|
445
|
+
- Why:
|
|
446
|
+
- <why this small change matters>
|
|
447
|
+
- Scope:
|
|
448
|
+
- <what will change>
|
|
449
|
+
- Non-goals:
|
|
450
|
+
- none
|
|
451
|
+
|
|
452
|
+
## Spec
|
|
453
|
+
### MODIFIED
|
|
454
|
+
- Requirement: <observable outcome>
|
|
455
|
+
- <what should be true after this change>
|
|
456
|
+
|
|
457
|
+
### Acceptance
|
|
458
|
+
#### Scenario: change is complete
|
|
459
|
+
- GIVEN <current context>
|
|
460
|
+
- WHEN <the change is applied>
|
|
461
|
+
- THEN <expected outcome>
|
|
462
|
+
|
|
463
|
+
## Design
|
|
464
|
+
- Approach:
|
|
465
|
+
- <minimal implementation approach>
|
|
466
|
+
- Boundaries:
|
|
467
|
+
- <primary ownership or interface boundary>
|
|
468
|
+
- Affected areas:
|
|
469
|
+
- <primary file, directory, or doc path>
|
|
470
|
+
- Constraints:
|
|
471
|
+
- <important constraint, or none>
|
|
472
|
+
|
|
473
|
+
## Tasks
|
|
474
|
+
- [ ] Implement the small change
|
|
475
|
+
|
|
476
|
+
## Verify
|
|
477
|
+
- Automated:
|
|
478
|
+
- [ ] <cheapest decisive check; retain a new test only when justified, or not applicable: reason> \u2014 proves: <behavior or scope covered>
|
|
479
|
+
- Manual or environment:
|
|
480
|
+
- [ ] <exact acceptance scenario, or unavailable/not applicable: owner and reason>
|
|
481
|
+
- Coverage:
|
|
482
|
+
- <omitted or unavailable relevant coverage and reason, or none>
|
|
483
|
+
|
|
484
|
+
## Blockers
|
|
485
|
+
- none
|
|
486
|
+
`;
|
|
487
|
+
}
|
|
488
|
+
function getChangeTemplateByKind(kind) {
|
|
489
|
+
const automatedVerify = "<cheapest decisive check; retain a new test only when justified, or not applicable: reason>";
|
|
490
|
+
switch (kind) {
|
|
491
|
+
case "feature":
|
|
492
|
+
return {
|
|
493
|
+
why: "<what user need or capability gap this addresses>",
|
|
494
|
+
scope: "<what new behavior or capability will be delivered>",
|
|
495
|
+
nonGoals: "<what related capabilities are explicitly out of scope>",
|
|
496
|
+
specSection: "<!-- Describe observable behavior and requirements. Implementation notes belong in ## Design. -->\n### ADDED\n- Requirement: <new user-facing behavior>\n - <verifiable requirement for the new capability>",
|
|
497
|
+
acceptanceSection: "#### Scenario: user exercises the new capability\n- GIVEN <context>\n- WHEN <user action>\n- THEN <expected new behavior>",
|
|
498
|
+
approach: "<how the new capability will be implemented>",
|
|
499
|
+
affectedArea1: "<concrete file path, directory, module, or subsystem 1>",
|
|
500
|
+
affectedArea2: "<concrete file path, directory, module, or subsystem 2 if needed>",
|
|
501
|
+
constraints: "<behavior, compatibility, performance, safety, or scope constraint that must hold>",
|
|
502
|
+
task: "<implement the new behavior and its acceptance scenario in the affected areas>",
|
|
503
|
+
automatedVerify,
|
|
504
|
+
manualVerify: "<exact end-to-end user scenario to validate the new capability, or unavailable/not applicable: owner and reason>"
|
|
505
|
+
};
|
|
506
|
+
case "fix":
|
|
507
|
+
return {
|
|
508
|
+
why: "<what current behavior is wrong or broken>",
|
|
509
|
+
scope: "<what specific defect is being corrected>",
|
|
510
|
+
nonGoals: "<what related but separate issues are out of scope>",
|
|
511
|
+
specSection: "<!-- Describe expected correct behavior. Implementation notes belong in ## Design. -->\n### MODIFIED\n- Requirement: correct behavior\n - <expected correct behavior after the fix>",
|
|
512
|
+
acceptanceSection: "#### Scenario: defect is resolved\n- GIVEN <conditions that trigger the defect>\n- WHEN <action that previously failed>\n- THEN <expected correct outcome>\n- AND the original broken outcome no longer occurs",
|
|
513
|
+
approach: "<confirmed cause and correction strategy, or exact evidence needed to establish the cause>",
|
|
514
|
+
affectedArea1: "<concrete file path, directory, module, or subsystem containing the defect>",
|
|
515
|
+
affectedArea2: "<secondary path, dependency, or test file if needed>",
|
|
516
|
+
constraints: "<regression, backward-compatibility, safety, or scope constraint that must hold>",
|
|
517
|
+
task: "<identify the root cause and apply the minimal fix>",
|
|
518
|
+
automatedVerify,
|
|
519
|
+
manualVerify: "<exact steps to reproduce the original issue and confirm it no longer occurs, or unavailable/not applicable: owner and reason>"
|
|
520
|
+
};
|
|
521
|
+
case "refactor":
|
|
522
|
+
return {
|
|
523
|
+
why: "<what maintainability, readability, or structural issue motivates this>",
|
|
524
|
+
scope: "<what code areas are being restructured>",
|
|
525
|
+
nonGoals: "<no behavior change is expected or intended>",
|
|
526
|
+
specSection: "<!-- Describe the desired structural outcome. Implementation notes belong in ## Design. -->\n### MODIFIED\n- Requirement: internal structure improvement\n - <desired structural outcome without observable behavior change>",
|
|
527
|
+
acceptanceSection: "#### Scenario: behavior is preserved after restructuring\n- GIVEN the existing codebase before the refactor\n- WHEN the refactored code runs against existing tests\n- THEN all existing tests pass unchanged",
|
|
528
|
+
approach: "<how the code will be restructured (rename, extract, move, etc.)>",
|
|
529
|
+
affectedArea1: "<concrete file path, directory, module, or subsystem being refactored>",
|
|
530
|
+
affectedArea2: "<secondary path, dependency, or test file if needed>",
|
|
531
|
+
constraints: "<observable behavior must remain unchanged; compatibility, performance, and safety constraints must still hold>",
|
|
532
|
+
task: "<restructure the code while keeping behavior identical>",
|
|
533
|
+
automatedVerify,
|
|
534
|
+
manualVerify: "<exact scenario to spot-check that behavior is unchanged after the refactor, or unavailable/not applicable: owner and reason>"
|
|
535
|
+
};
|
|
536
|
+
case "docs":
|
|
537
|
+
return {
|
|
538
|
+
why: "<why the documentation change matters>",
|
|
539
|
+
scope: "<which docs, readers, or workflows will be updated>",
|
|
540
|
+
nonGoals: "<what documentation behavior or audience is out of scope>",
|
|
541
|
+
specSection: "<!-- Describe what the reader should see or experience. Implementation notes belong in ## Design. -->\n### MODIFIED\n- Requirement: documentation accuracy\n - <what durable reader-facing behavior or explanation changes>",
|
|
542
|
+
acceptanceSection: "#### Scenario: reader follows the updated guidance\n- GIVEN the updated documentation\n- WHEN a reader follows the documented workflow\n- THEN the steps are accurate and sufficient",
|
|
543
|
+
approach: "<how the documentation will be updated and organized>",
|
|
544
|
+
affectedArea1: "<concrete doc path, directory, module doc, or documentation surface 1>",
|
|
545
|
+
affectedArea2: "<secondary doc path or reference file if needed>",
|
|
546
|
+
constraints: "<durable wording, consistency, scope, or audience constraint that must hold>",
|
|
547
|
+
task: "<update the target documentation and supporting references>",
|
|
548
|
+
automatedVerify,
|
|
549
|
+
manualVerify: "<exact reader or operator scenario to confirm the updated guidance is accurate, or unavailable/not applicable: owner and reason>"
|
|
550
|
+
};
|
|
551
|
+
case "research":
|
|
552
|
+
return {
|
|
553
|
+
why: "<what question or uncertainty this research resolves>",
|
|
554
|
+
scope: "<what system area, option set, or hypothesis is being examined>",
|
|
555
|
+
nonGoals: "<what implementation work is explicitly out of scope>",
|
|
556
|
+
specSection: "<!-- Describe what finding or decision must be captured. Implementation notes belong in ## Design. -->\n### ADDED\n- Requirement: research outcome recording\n - <what finding, option, or decision must be captured clearly>",
|
|
557
|
+
acceptanceSection: "#### Scenario: research question is resolved\n- GIVEN the current uncertainty or open question\n- WHEN the investigation is completed\n- THEN the result is recorded clearly enough to guide follow-up work",
|
|
558
|
+
approach: "<how the investigation will be performed and what evidence will be gathered>",
|
|
559
|
+
affectedArea1: "<concrete file path, directory, module, subsystem, or source under investigation>",
|
|
560
|
+
affectedArea2: "<secondary path, dependency, environment, or evidence source if needed>",
|
|
561
|
+
constraints: "<time, evidence, safety, or scope constraint for the investigation>",
|
|
562
|
+
task: "<gather evidence, record the recommendation or finding, and note any follow-up implementation work if needed>",
|
|
563
|
+
automatedVerify,
|
|
564
|
+
manualVerify: "<exact review of the findings to confirm they answer the original question and identify follow-up work if needed, or unavailable/not applicable: owner and reason>"
|
|
565
|
+
};
|
|
566
|
+
case "ops":
|
|
567
|
+
return {
|
|
568
|
+
why: "<why this operational or environment change matters>",
|
|
569
|
+
scope: "<what environment, workflow, or operational path changes>",
|
|
570
|
+
nonGoals: "<what product or feature behavior will not change>",
|
|
571
|
+
specSection: "<!-- Describe the reliable operational outcome. Implementation notes belong in ## Design. -->\n### MODIFIED\n- Requirement: operational behavior\n - <what reliable operational outcome should change or stay true>",
|
|
572
|
+
acceptanceSection: "#### Scenario: operational path succeeds\n- GIVEN the target environment or workflow\n- WHEN the operational change is applied\n- THEN the expected operational outcome is reliable",
|
|
573
|
+
approach: "<how the operational change will be applied safely>",
|
|
574
|
+
affectedArea1: "<concrete script, config path, workflow, environment path, or operational surface 1>",
|
|
575
|
+
affectedArea2: "<secondary script, config path, dependency, or environment surface if needed>",
|
|
576
|
+
constraints: "<rollback, safety, reliability, environment, or scope constraint that must hold>",
|
|
577
|
+
task: "<apply and verify the operational change>",
|
|
578
|
+
automatedVerify,
|
|
579
|
+
manualVerify: "<exact operator workflow or environment scenario to confirm the operational result, or unavailable/not applicable: owner and reason>"
|
|
580
|
+
};
|
|
581
|
+
default:
|
|
582
|
+
return {
|
|
583
|
+
why: "<why this change matters>",
|
|
584
|
+
scope: "<what this change will do>",
|
|
585
|
+
nonGoals: "<what this change will not do>",
|
|
586
|
+
specSection: "<!-- Describe observable behavior and requirements. Implementation notes belong in ## Design. -->\n### ADDED\n- Requirement: <new or updated behavior>\n - <verifiable requirement>",
|
|
587
|
+
acceptanceSection: "#### Scenario: <name>\n- GIVEN <context>\n- WHEN <action>\n- THEN <expected outcome>",
|
|
588
|
+
approach: "<how the change will be implemented>",
|
|
589
|
+
affectedArea1: "<concrete file path, directory, module, or subsystem 1>",
|
|
590
|
+
affectedArea2: "<concrete file path, directory, module, or subsystem 2 if needed>",
|
|
591
|
+
constraints: "<behavior, compatibility, performance, safety, or scope constraint that must hold>",
|
|
592
|
+
task: "<implement the core change in the affected areas>",
|
|
593
|
+
automatedVerify,
|
|
594
|
+
manualVerify: "<exact acceptance scenario, or unavailable/not applicable: owner and reason>"
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
function renderRspAgentsBlock() {
|
|
599
|
+
return `${RSP_AGENTS_BEGIN}
|
|
600
|
+
## RSP Entry
|
|
601
|
+
|
|
602
|
+
RSP tracks current work, stable specs, and archives under \`.rsp/\`.
|
|
603
|
+
|
|
604
|
+
Read in order:
|
|
605
|
+
1. Nearest \`AGENTS.md\` for project or module instructions.
|
|
606
|
+
2. Root \`CONTEXT-MAP.md\` if present, then the relevant nearest \`CONTEXT.md\`.
|
|
607
|
+
3. The \`rsp\` skill; if unavailable, read \`.rsp/rsp-rules.md\` as the fallback protocol.
|
|
608
|
+
4. \`.rsp/focus.d/\`; for grouped work read the sibling Group Brief, then the explicitly selected focused Change.
|
|
609
|
+
5. Only the relevant Specs and Decision Records under the configured authoritative path.
|
|
610
|
+
|
|
611
|
+
If \`.rsp/focus.d/\` is empty and the user has not provided a concrete task, ask what to work on or suggest \`npx -y @oevery/rsp create <name>\` for tracked work.
|
|
612
|
+
Do not treat \`.rsp/specs/\` or \`.rsp/changes/\` as replacements for nearest \`AGENTS.md\` or \`CONTEXT.md\`.
|
|
613
|
+
${RSP_AGENTS_END}`;
|
|
614
|
+
}
|
|
615
|
+
function upsertRspAgentsBlock(content) {
|
|
616
|
+
const block = renderRspAgentsBlock();
|
|
617
|
+
const managedRe = /<!-- rsp:begin -->[\s\S]*?<!-- rsp:end -->/;
|
|
618
|
+
if (managedRe.test(content)) {
|
|
619
|
+
const next2 = content.replace(managedRe, block);
|
|
620
|
+
return { content: next2, changed: next2 !== content };
|
|
621
|
+
}
|
|
622
|
+
const trimmed = content.trimStart();
|
|
623
|
+
const next = trimmed ? `${block}
|
|
624
|
+
|
|
625
|
+
${trimmed}` : `${block}
|
|
626
|
+
`;
|
|
627
|
+
return { content: next, changed: true };
|
|
628
|
+
}
|
|
629
|
+
function hasRspAgentsBlock(content) {
|
|
630
|
+
return content.includes(RSP_AGENTS_BEGIN) && content.includes(RSP_AGENTS_END);
|
|
631
|
+
}
|
|
632
|
+
var SPEC_NAME_RE = /^[a-z0-9-]+(?:\/[a-z0-9-]+)*$/;
|
|
633
|
+
function isValidSpecName(name) {
|
|
634
|
+
return SPEC_NAME_RE.test(name);
|
|
635
|
+
}
|
|
636
|
+
function guardRspInitialized() {
|
|
637
|
+
const designPath = join3(RSP_DIR, "specs", "design.md");
|
|
638
|
+
const rules = inspectManagedFile(RSP_RULES_PATH, "fallback protocol", { allowMissing: true });
|
|
639
|
+
const design = inspectManagedFile(designPath, "design Spec", { allowMissing: true });
|
|
640
|
+
if (rules.issue || design.issue || !rules.exists || !design.exists) {
|
|
641
|
+
const initialized = existsSync2(RSP_DIR);
|
|
642
|
+
console.error(` ${pc.red("Error:")} ${initialized ? "RSP project requires an update" : "RSP is not initialized in this project"}`);
|
|
643
|
+
console.error(` ${pc.dim(initialized ? "Run: rsp update" : "Run: rsp init")}`);
|
|
644
|
+
process.exit(1);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
function getOpenCheckboxes(sectionText) {
|
|
648
|
+
return sectionText.split("\n").map((line) => line.trim()).filter((line) => /^- \[[ /]\]/.test(line));
|
|
649
|
+
}
|
|
650
|
+
async function cleanupEmptyParentDirs(path, stopDir) {
|
|
651
|
+
let parent = dirname2(path);
|
|
652
|
+
while (parent !== stopDir) {
|
|
653
|
+
try {
|
|
654
|
+
const remaining = await readdir3(parent);
|
|
655
|
+
if (remaining.length === 0)
|
|
656
|
+
await rmdir(parent);
|
|
657
|
+
else
|
|
658
|
+
break;
|
|
659
|
+
} catch {
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
parent = dirname2(parent);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async function detectProjectName() {
|
|
666
|
+
try {
|
|
667
|
+
if (existsSync2("package.json")) {
|
|
668
|
+
const raw = await readFile("package.json", "utf-8");
|
|
669
|
+
const pkg = JSON.parse(raw);
|
|
670
|
+
if (pkg.name && pkg.name !== "")
|
|
671
|
+
return pkg.name;
|
|
672
|
+
}
|
|
673
|
+
} catch {
|
|
674
|
+
}
|
|
675
|
+
return basename(process.cwd());
|
|
676
|
+
}
|
|
677
|
+
function generateDesignContent(projectName) {
|
|
678
|
+
return `# Project Design: ${projectName}
|
|
679
|
+
|
|
680
|
+
## Purpose
|
|
681
|
+
- <what this project is responsible for>
|
|
682
|
+
- <who or what it serves>
|
|
683
|
+
|
|
684
|
+
## Stable Facts
|
|
685
|
+
- <durable fact that future agents or developers must know>
|
|
686
|
+
- <key architectural invariant>
|
|
687
|
+
|
|
688
|
+
## Boundaries
|
|
689
|
+
- In scope:
|
|
690
|
+
- <major capability or boundary>
|
|
691
|
+
- Out of scope:
|
|
692
|
+
- <intentional non-goal>
|
|
693
|
+
|
|
694
|
+
## Structure
|
|
695
|
+
- <important directory or subsystem> \u2014 <responsibility>
|
|
696
|
+
|
|
697
|
+
## Constraints
|
|
698
|
+
- <cross-cutting technical or operational constraint, when it affects architecture>
|
|
699
|
+
`;
|
|
700
|
+
}
|
|
701
|
+
function generateSpecContent(name) {
|
|
702
|
+
const title = toTitleCase(name);
|
|
703
|
+
return `# ${title}
|
|
704
|
+
|
|
705
|
+
## Purpose
|
|
706
|
+
- <why this project-level spec exists>
|
|
707
|
+
|
|
708
|
+
## Stable Facts
|
|
709
|
+
- <durable fact that future work must know>
|
|
710
|
+
|
|
711
|
+
## Boundaries
|
|
712
|
+
- In scope:
|
|
713
|
+
- <what this spec covers>
|
|
714
|
+
- Out of scope:
|
|
715
|
+
- <what this spec does not cover>
|
|
716
|
+
|
|
717
|
+
## Constraints
|
|
718
|
+
- <stable constraint, if any>
|
|
719
|
+
`;
|
|
720
|
+
}
|
|
721
|
+
function toTitleCase(value) {
|
|
722
|
+
return value.split(/[-/]/g).filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
723
|
+
}
|
|
724
|
+
function extractSection(content, heading) {
|
|
725
|
+
const lines = content.split("\n");
|
|
726
|
+
const start = lines.findIndex((line) => line.trim() === `## ${heading}`);
|
|
727
|
+
if (start === -1)
|
|
728
|
+
return "";
|
|
729
|
+
const body = [];
|
|
730
|
+
for (let index = start + 1; index < lines.length; index++) {
|
|
731
|
+
const line = lines[index];
|
|
732
|
+
if (line.startsWith("## "))
|
|
733
|
+
break;
|
|
734
|
+
body.push(line);
|
|
735
|
+
}
|
|
736
|
+
return body.join("\n").trim();
|
|
737
|
+
}
|
|
738
|
+
function extractBlockerLines(content) {
|
|
739
|
+
const uncommented = content.replace(/<!--[\s\S]*?-->/g, "");
|
|
740
|
+
return extractSection(uncommented, "Blockers").split("\n").map((line) => line.trim()).filter(Boolean);
|
|
741
|
+
}
|
|
742
|
+
function hasMeaningfulBlockers(content) {
|
|
743
|
+
const lines = extractBlockerLines(content);
|
|
744
|
+
if (lines.length === 0)
|
|
745
|
+
return false;
|
|
746
|
+
return lines.some((line) => !/^[-*]\s*(?:none)?$/i.test(line) && !/^none$/i.test(line));
|
|
747
|
+
}
|
|
748
|
+
function detectDeltaSections(content) {
|
|
749
|
+
const body = extractSection(content, "Spec");
|
|
750
|
+
return {
|
|
751
|
+
added: /^###\s*ADDED/im.test(body),
|
|
752
|
+
modified: /^###\s*MODIFIED/im.test(body),
|
|
753
|
+
removed: /^###\s*REMOVED/im.test(body)
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function collectArchiveReadiness(content, options = {}) {
|
|
757
|
+
const warnings = [];
|
|
758
|
+
const tasksSection = extractSection(content, "Tasks");
|
|
759
|
+
const verifySection = extractSection(content, "Verify");
|
|
760
|
+
const taskTodos = getOpenCheckboxes(tasksSection);
|
|
761
|
+
if (taskTodos.length > 0)
|
|
762
|
+
warnings.push(`${taskTodos.length} task item(s) still incomplete`);
|
|
763
|
+
const verifyTodos = getOpenCheckboxes(verifySection);
|
|
764
|
+
if (verifyTodos.length > 0)
|
|
765
|
+
warnings.push(`${verifyTodos.length} Verify checklist item(s) are still incomplete`);
|
|
766
|
+
const activeBlockers = options.activeBlockers ?? hasMeaningfulBlockers(content);
|
|
767
|
+
if (activeBlockers)
|
|
768
|
+
warnings.push("active blockers are present in the change file");
|
|
769
|
+
const scenarios = parseScenarios(content);
|
|
770
|
+
const missingScenarios = scenarios.length === 0;
|
|
771
|
+
if (missingScenarios)
|
|
772
|
+
warnings.push("no Scenario blocks found (some changes do not need them)");
|
|
773
|
+
const archiveReady = activeBlockers ? "no" : warnings.length === 0 ? "yes" : "judgment";
|
|
774
|
+
return {
|
|
775
|
+
taskTodos,
|
|
776
|
+
verifyTodos,
|
|
777
|
+
activeBlockers,
|
|
778
|
+
scenarioCount: scenarios.length,
|
|
779
|
+
missingScenarios,
|
|
780
|
+
deterministic: warnings.length === 0 ? "pass" : "warnings",
|
|
781
|
+
semantic: "needs-review",
|
|
782
|
+
archiveReady,
|
|
783
|
+
warnings
|
|
784
|
+
};
|
|
785
|
+
}
|
|
786
|
+
function buildDurableReviewGuidance(factCandidateTargets, decisionRecordsPath) {
|
|
787
|
+
return {
|
|
788
|
+
required: true,
|
|
789
|
+
factDecisions: [
|
|
790
|
+
"No current-fact update needed",
|
|
791
|
+
"Update existing spec or scoped instruction",
|
|
792
|
+
"Create a new durable spec"
|
|
793
|
+
],
|
|
794
|
+
rationaleDecisions: [
|
|
795
|
+
"No Decision Record needed",
|
|
796
|
+
"Create or update a Decision Record"
|
|
797
|
+
],
|
|
798
|
+
factCandidateTargets,
|
|
799
|
+
decisionRecordsPath,
|
|
800
|
+
note: "Semantic review decides current-fact and lasting-rationale updates independently. The CLI never infers scoped instruction or Decision Record filenames and never promotes Change content automatically."
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function getDurableReviewCandidateTargets() {
|
|
804
|
+
return [".rsp/specs/design.md"];
|
|
805
|
+
}
|
|
806
|
+
function collectArchiveChecklist(content, options = {}) {
|
|
807
|
+
return collectArchiveReadiness(content, options).warnings;
|
|
808
|
+
}
|
|
809
|
+
function parseScenarios(content) {
|
|
810
|
+
const scenarios = [];
|
|
811
|
+
const regex = /^#{3,4}\s*Scenario:\s*(.+)$/gim;
|
|
812
|
+
let match;
|
|
813
|
+
while ((match = regex.exec(content)) !== null) {
|
|
814
|
+
const heading = match[1].trim();
|
|
815
|
+
const startPos = match.index + match[0].length;
|
|
816
|
+
const restContent = content.slice(startPos);
|
|
817
|
+
const nextSection = restContent.match(/^#{3,4}\s/m);
|
|
818
|
+
const block = nextSection ? restContent.slice(0, nextSection.index) : restContent;
|
|
819
|
+
const steps = block.split("\n").map((s) => s.trim()).filter((s) => s.startsWith("-") && /GIVEN|WHEN|THEN|AND|BUT/i.test(s)).map((s) => s.replace(/^[-*]\s*/, ""));
|
|
820
|
+
if (steps.length > 0)
|
|
821
|
+
scenarios.push({ heading, steps });
|
|
822
|
+
}
|
|
823
|
+
return scenarios;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// src/core/config.ts
|
|
827
|
+
var __dirname = dirname3(fileURLToPath(import.meta.url));
|
|
828
|
+
var PKG_ROOT = join4(__dirname, "..");
|
|
829
|
+
var RSP_DIR = ".rsp";
|
|
830
|
+
var RSP_RULES_PATH = join4(RSP_DIR, "rsp-rules.md");
|
|
831
|
+
var OBSOLETE_RSP_RULES_PATH = join4(RSP_DIR, "rules", "rsp-rules.md");
|
|
832
|
+
var CHANGES_DIR = join4(RSP_DIR, "changes");
|
|
833
|
+
var FOCUS_DIR = join4(RSP_DIR, "focus.d");
|
|
834
|
+
var ARCHIVES_DIR = join4(RSP_DIR, "archives");
|
|
835
|
+
var LOCK_PATH = join4(RSP_DIR, ".lock");
|
|
836
|
+
var CONFIG_PATH = join4(RSP_DIR, "config.yaml");
|
|
837
|
+
var VALID_KINDS = ["feature", "fix", "refactor", "docs", "ops", "research"];
|
|
838
|
+
var DEFAULT_REQUIRED_SECTIONS = ["Proposal", "Spec", "Design", "Tasks", "Verify", "Blockers"];
|
|
839
|
+
var DEFAULT_MANAGE_POLICY = { activation: "explicit", closeout: "local" };
|
|
840
|
+
var FAILED_CLOSED_MANAGE_POLICY = { activation: "explicit", closeout: "manual" };
|
|
841
|
+
var MANAGE_ACTIVATIONS = ["explicit", "auto"];
|
|
842
|
+
var MANAGE_CLOSEOUTS = ["manual", "lifecycle", "local"];
|
|
843
|
+
var _configCache = null;
|
|
844
|
+
async function loadRspConfig() {
|
|
845
|
+
const inspection = await inspectRspConfig();
|
|
846
|
+
if (inspection.issues.length > 0)
|
|
847
|
+
throw new Error(inspection.issues.join("; "));
|
|
848
|
+
return inspection.config;
|
|
849
|
+
}
|
|
850
|
+
async function inspectRspConfig() {
|
|
851
|
+
const cwd = process.cwd();
|
|
852
|
+
if (_configCache?.cwd === cwd)
|
|
853
|
+
return _configCache.inspection;
|
|
854
|
+
const configFile = inspectManagedFile(CONFIG_PATH, "config file", { allowMissing: true });
|
|
855
|
+
if (configFile.issue)
|
|
856
|
+
throw configFile.issue;
|
|
857
|
+
if (!configFile.exists) {
|
|
858
|
+
const inspection2 = { config: {}, issues: [] };
|
|
859
|
+
_configCache = { cwd, inspection: inspection2 };
|
|
860
|
+
return inspection2;
|
|
861
|
+
}
|
|
862
|
+
const raw = await readFile2(CONFIG_PATH, "utf-8");
|
|
863
|
+
const parsed = parseYamlText(raw);
|
|
864
|
+
const issues = validateRspConfig(parsed);
|
|
865
|
+
const decisions = parsed.decisions && typeof parsed.decisions === "object" && !Array.isArray(parsed.decisions) ? parsed.decisions : void 0;
|
|
866
|
+
const decisionPath = decisions?.path;
|
|
867
|
+
const manageValue = parsed.manage && typeof parsed.manage === "object" && !Array.isArray(parsed.manage) ? parsed.manage : void 0;
|
|
868
|
+
const activation = MANAGE_ACTIVATIONS.includes(manageValue?.activation) ? manageValue?.activation : void 0;
|
|
869
|
+
const closeout = MANAGE_CLOSEOUTS.includes(manageValue?.closeout) ? manageValue?.closeout : void 0;
|
|
870
|
+
const kinds = Array.isArray(parsed.kinds) && parsed.kinds.every((value) => typeof value === "string" && value.trim() !== "") ? parsed.kinds.map((value) => value.trim()) : void 0;
|
|
871
|
+
const decisionRecordsIssue = getDecisionRecordsConfigIssue(parsed);
|
|
872
|
+
const inspection = {
|
|
873
|
+
config: {
|
|
874
|
+
kinds,
|
|
875
|
+
decisions: decisionRecordsIssue === null && validateDecisionRecordsPath(decisionPath) === null ? { path: normalizeDecisionRecordsPath(String(decisionPath)) } : void 0,
|
|
876
|
+
manage: manageValue ? { activation, closeout } : void 0
|
|
877
|
+
},
|
|
878
|
+
issues
|
|
879
|
+
};
|
|
880
|
+
_configCache = { cwd, inspection };
|
|
881
|
+
return inspection;
|
|
882
|
+
}
|
|
883
|
+
function validateRspConfig(parsed) {
|
|
884
|
+
const issues = [];
|
|
885
|
+
const supported = /* @__PURE__ */ new Set(["kinds", "decisions", "manage"]);
|
|
886
|
+
for (const key of Object.keys(parsed)) {
|
|
887
|
+
if (key === "required_sections") {
|
|
888
|
+
issues.push('config.yaml field "required_sections" is no longer supported');
|
|
889
|
+
} else if (!supported.has(key)) {
|
|
890
|
+
issues.push(`config.yaml field "${key}" is not supported`);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if ("kinds" in parsed) {
|
|
894
|
+
if (!Array.isArray(parsed.kinds)) {
|
|
895
|
+
issues.push('config.yaml field "kinds" must be a YAML list');
|
|
896
|
+
} else if (!parsed.kinds.every((value) => typeof value === "string" && value.trim() !== "")) {
|
|
897
|
+
issues.push('config.yaml field "kinds" must contain only non-empty strings');
|
|
898
|
+
} else {
|
|
899
|
+
const kinds = parsed.kinds.map((value) => value.trim());
|
|
900
|
+
const duplicates = [...new Set(kinds.filter((value, index) => kinds.indexOf(value) !== index))];
|
|
901
|
+
if (duplicates.length > 0)
|
|
902
|
+
issues.push(`config.yaml field "kinds" contains duplicate entries: ${duplicates.join(", ")}`);
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
const decisionRecordsIssue = getDecisionRecordsConfigIssue(parsed);
|
|
906
|
+
if (decisionRecordsIssue)
|
|
907
|
+
issues.push(decisionRecordsIssue);
|
|
908
|
+
if ("manage" in parsed) {
|
|
909
|
+
if (!parsed.manage || typeof parsed.manage !== "object" || Array.isArray(parsed.manage)) {
|
|
910
|
+
issues.push('config.yaml field "manage" must be a YAML mapping');
|
|
911
|
+
} else {
|
|
912
|
+
const manage = parsed.manage;
|
|
913
|
+
const supportedManageFields = /* @__PURE__ */ new Set(["activation", "closeout"]);
|
|
914
|
+
for (const key of Object.keys(manage)) {
|
|
915
|
+
if (!supportedManageFields.has(key))
|
|
916
|
+
issues.push(`config.yaml field "manage.${key}" is not supported`);
|
|
917
|
+
}
|
|
918
|
+
if ("activation" in manage && !MANAGE_ACTIVATIONS.includes(manage.activation))
|
|
919
|
+
issues.push('config.yaml field "manage.activation" must be one of: explicit, auto');
|
|
920
|
+
if ("closeout" in manage && !MANAGE_CLOSEOUTS.includes(manage.closeout))
|
|
921
|
+
issues.push('config.yaml field "manage.closeout" must be one of: manual, lifecycle, local');
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
return issues;
|
|
925
|
+
}
|
|
926
|
+
function clearConfigCache() {
|
|
927
|
+
_configCache = null;
|
|
928
|
+
}
|
|
929
|
+
function resolveKinds(config) {
|
|
930
|
+
return config.kinds && config.kinds.length > 0 ? config.kinds : [...VALID_KINDS];
|
|
931
|
+
}
|
|
932
|
+
function resolveRequiredSections(_config) {
|
|
933
|
+
return [...DEFAULT_REQUIRED_SECTIONS];
|
|
934
|
+
}
|
|
935
|
+
function resolveManagePolicy(config, options = {}) {
|
|
936
|
+
if (options.configValid === false)
|
|
937
|
+
return { ...FAILED_CLOSED_MANAGE_POLICY };
|
|
938
|
+
return {
|
|
939
|
+
activation: config.manage?.activation ?? DEFAULT_MANAGE_POLICY.activation,
|
|
940
|
+
closeout: config.manage?.closeout ?? DEFAULT_MANAGE_POLICY.closeout
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
async function getVersion() {
|
|
944
|
+
const { version } = JSON.parse(await readFile2(join4(PKG_ROOT, "package.json"), "utf-8"));
|
|
945
|
+
return version;
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/core/output.ts
|
|
949
|
+
function toErrorMessage(error) {
|
|
950
|
+
return error instanceof Error ? error.message : String(error);
|
|
951
|
+
}
|
|
952
|
+
function emitJson(data, options = {}) {
|
|
953
|
+
const indentation = options.compact ? void 0 : 2;
|
|
954
|
+
process.stdout.write(`${JSON.stringify(data, null, indentation)}
|
|
955
|
+
`);
|
|
956
|
+
}
|
|
957
|
+
function recordRuntimeDiagnostic(runtime, diagnostic, verbose = false) {
|
|
958
|
+
runtime.push(diagnostic);
|
|
959
|
+
if (verbose) {
|
|
960
|
+
console.error(` ${pc.dim(`[verbose] ${diagnostic.operation} ${diagnostic.path}: ${diagnostic.message}`)}`);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
export {
|
|
965
|
+
ManagedPathError,
|
|
966
|
+
inspectManagedDirectory,
|
|
967
|
+
requireManagedDirectory,
|
|
968
|
+
inspectManagedFile,
|
|
969
|
+
requireManagedFile,
|
|
970
|
+
ensureManagedFile,
|
|
971
|
+
writeManagedFile,
|
|
972
|
+
resolveManagedDirectoryChain,
|
|
973
|
+
inspectManagedFileTree,
|
|
974
|
+
DEFAULT_DECISION_RECORDS_PATH,
|
|
975
|
+
resolveDecisionRecordsPath,
|
|
976
|
+
ensureDecisionRecordsDirectory,
|
|
977
|
+
validateDecisionRecordsFilesystemPath,
|
|
978
|
+
toErrorMessage,
|
|
979
|
+
emitJson,
|
|
980
|
+
recordRuntimeDiagnostic,
|
|
981
|
+
parseFrontmatter,
|
|
982
|
+
countCheckboxes,
|
|
983
|
+
walkMarkdownFiles,
|
|
984
|
+
inspectUnsupportedRules,
|
|
985
|
+
normalizeLogicalPath,
|
|
986
|
+
generateChangeContent,
|
|
987
|
+
upsertRspAgentsBlock,
|
|
988
|
+
hasRspAgentsBlock,
|
|
989
|
+
isValidSpecName,
|
|
990
|
+
guardRspInitialized,
|
|
991
|
+
cleanupEmptyParentDirs,
|
|
992
|
+
detectProjectName,
|
|
993
|
+
generateDesignContent,
|
|
994
|
+
generateSpecContent,
|
|
995
|
+
extractSection,
|
|
996
|
+
extractBlockerLines,
|
|
997
|
+
hasMeaningfulBlockers,
|
|
998
|
+
detectDeltaSections,
|
|
999
|
+
collectArchiveReadiness,
|
|
1000
|
+
buildDurableReviewGuidance,
|
|
1001
|
+
getDurableReviewCandidateTargets,
|
|
1002
|
+
collectArchiveChecklist,
|
|
1003
|
+
parseScenarios,
|
|
1004
|
+
pc,
|
|
1005
|
+
PKG_ROOT,
|
|
1006
|
+
RSP_DIR,
|
|
1007
|
+
RSP_RULES_PATH,
|
|
1008
|
+
OBSOLETE_RSP_RULES_PATH,
|
|
1009
|
+
CHANGES_DIR,
|
|
1010
|
+
FOCUS_DIR,
|
|
1011
|
+
ARCHIVES_DIR,
|
|
1012
|
+
LOCK_PATH,
|
|
1013
|
+
CONFIG_PATH,
|
|
1014
|
+
VALID_KINDS,
|
|
1015
|
+
loadRspConfig,
|
|
1016
|
+
inspectRspConfig,
|
|
1017
|
+
clearConfigCache,
|
|
1018
|
+
resolveKinds,
|
|
1019
|
+
resolveRequiredSections,
|
|
1020
|
+
resolveManagePolicy,
|
|
1021
|
+
getVersion
|
|
1022
|
+
};
|