cliewen-openspec 0.2.0 → 0.4.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/CHANGELOG.md +28 -0
- package/README.md +16 -12
- package/adapters/node-test.mjs +9 -4
- package/dist/ac-coordination.d.ts +33 -0
- package/dist/ac-coordination.js +318 -0
- package/dist/ac.d.ts +4 -3
- package/dist/ac.js +20 -1
- package/dist/ci-github.d.ts +19 -0
- package/dist/ci-github.js +70 -0
- package/dist/ci-inspection.d.ts +48 -0
- package/dist/ci-inspection.js +246 -0
- package/dist/ci-settings.d.ts +15 -0
- package/dist/ci-settings.js +50 -0
- package/dist/cli.js +73 -12
- package/dist/core.d.ts +32 -3
- package/dist/core.js +167 -15
- package/dist/documentation-settings.d.ts +16 -0
- package/dist/documentation-settings.js +65 -0
- package/dist/documentation.d.ts +47 -0
- package/dist/documentation.js +337 -0
- package/dist/mermaid-check.d.ts +10 -0
- package/dist/mermaid-check.js +40 -0
- package/dist/mermaid-worker.d.ts +1 -0
- package/dist/mermaid-worker.js +24 -0
- package/dist/quality.d.ts +1 -1
- package/dist/quality.js +22 -7
- package/dist/release.d.ts +2 -2
- package/dist/release.js +3 -3
- package/dist/schema-source.js +1 -1
- package/dist/setup-profile.d.ts +31 -0
- package/dist/setup-profile.js +59 -0
- package/dist/state-lock.d.ts +2 -0
- package/dist/state-lock.js +92 -0
- package/docs/configuration.md +170 -10
- package/docs/testing/evidence.md +14 -1
- package/docs/testing/test-quality.md +3 -1
- package/package.json +67 -65
- package/schemas/base/instructions/ci-inspection.md +9 -0
- package/schemas/base/instructions/closure.md +4 -2
- package/schemas/base/instructions/context-entry.md +1 -0
- package/schemas/base/instructions/context-selection.md +33 -0
- package/schemas/base/instructions/documentation-checks.md +2 -0
- package/schemas/base/instructions/humanizer.md +12 -5
- package/schemas/base/instructions/planning.md +60 -27
- package/schemas/delivery/instructions/apply.md +2 -0
|
@@ -0,0 +1,337 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import MarkdownIt from 'markdown-it';
|
|
4
|
+
import GithubSlugger from 'github-slugger';
|
|
5
|
+
import { parseDocument, isMap, LineCounter } from 'yaml';
|
|
6
|
+
import { config, local } from './core.js';
|
|
7
|
+
import { requirements, meetsMinimum } from './release.js';
|
|
8
|
+
import { documentationCategories } from './documentation-settings.js';
|
|
9
|
+
import { checkDiagrams } from './mermaid-check.js';
|
|
10
|
+
export const documentationLimits = { files: 1000, fileBytes: 1048576, diagramBytes: 262144, directoryEntries: 10000, diagramMilliseconds: 5000 };
|
|
11
|
+
const markdown = new MarkdownIt({ html: true });
|
|
12
|
+
const normalizeLink = markdown.normalizeLink;
|
|
13
|
+
markdown.normalizeLink = value => /%(?![\da-f]{2})/i.test(value) && !/^[a-z][a-z\d+.-]*:/i.test(value) ? value : normalizeLink(value);
|
|
14
|
+
// An inline rule sees real reference syntax after escape/code handling.
|
|
15
|
+
markdown.inline.ruler.before('link', 'docs-reference', (state, silent) => {
|
|
16
|
+
if (state.src[state.pos] !== '[')
|
|
17
|
+
return false;
|
|
18
|
+
const end = state.md.helpers.parseLinkLabel(state, state.pos, true);
|
|
19
|
+
if (end < 0 || state.src[end + 1] !== '[')
|
|
20
|
+
return false;
|
|
21
|
+
const referenceEnd = state.md.helpers.parseLinkLabel(state, end + 1, false);
|
|
22
|
+
if (referenceEnd < 0)
|
|
23
|
+
return false;
|
|
24
|
+
const label = state.md.utils.normalizeReference(state.src.slice(end + 2, referenceEnd) || state.src.slice(state.pos + 1, end));
|
|
25
|
+
if (Object.hasOwn(state.env.references ?? {}, label))
|
|
26
|
+
return false;
|
|
27
|
+
if (!silent)
|
|
28
|
+
state.push('docs_reference_missing', '', 0).content = state.src.slice(state.pos, referenceEnd + 1);
|
|
29
|
+
state.pos = referenceEnd + 1;
|
|
30
|
+
return true;
|
|
31
|
+
});
|
|
32
|
+
const slash = (value) => value.replaceAll('\\', '/');
|
|
33
|
+
const pathKey = (file) => process.platform === 'win32' ? file.toLowerCase() : file;
|
|
34
|
+
const matches = (file, root) => root === '.' || pathKey(file) === pathKey(root) || pathKey(file).startsWith(pathKey(root) + '/');
|
|
35
|
+
const isMarkdown = (file) => /\.(?:md|markdown)$/i.test(file);
|
|
36
|
+
const reserved = (file) => file.split('/').some(part => pathKey(part) === '.git' || pathKey(part) === 'node_modules');
|
|
37
|
+
const fileIdentity = (stat) => `${stat.dev}:${stat.ino}`;
|
|
38
|
+
function entryIdentity(full, stat, directories, collect = false) {
|
|
39
|
+
const parent = path.dirname(full), parentStat = fs.statSync(parent, { bigint: true });
|
|
40
|
+
if (stat.ino === 0n || parentStat.ino === 0n)
|
|
41
|
+
return;
|
|
42
|
+
const parentID = fileIdentity(parentStat);
|
|
43
|
+
let names = directories.get(parentID);
|
|
44
|
+
if (!names && collect) {
|
|
45
|
+
names = [];
|
|
46
|
+
const dir = fs.opendirSync(parent);
|
|
47
|
+
try {
|
|
48
|
+
let entry;
|
|
49
|
+
while ((entry = dir.readSync())) {
|
|
50
|
+
if (names.length === documentationLimits.directoryEntries)
|
|
51
|
+
return;
|
|
52
|
+
names.push(entry.name);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
finally {
|
|
56
|
+
dir.closeSync();
|
|
57
|
+
}
|
|
58
|
+
directories.set(parentID, names);
|
|
59
|
+
}
|
|
60
|
+
if (!names)
|
|
61
|
+
return;
|
|
62
|
+
let name = path.basename(full);
|
|
63
|
+
if (!names.includes(name)) {
|
|
64
|
+
// Successful stat proves the alias exists; stored entry names preserve scope
|
|
65
|
+
// even when this volume ignores case or normalizes Unicode differently.
|
|
66
|
+
const folded = name.normalize('NFC').toLowerCase();
|
|
67
|
+
const similar = names.filter(candidate => candidate.normalize('NFC').toLowerCase() === folded);
|
|
68
|
+
const candidates = (similar.length ? similar : names).filter(candidate => {
|
|
69
|
+
try {
|
|
70
|
+
const found = fs.lstatSync(path.join(parent, candidate), { bigint: true });
|
|
71
|
+
return found.isFile() && fileIdentity(found) === fileIdentity(stat);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (candidates.length !== 1)
|
|
78
|
+
return;
|
|
79
|
+
name = candidates[0];
|
|
80
|
+
}
|
|
81
|
+
// Separate directory entries can be hard links to the same file. An excluded
|
|
82
|
+
// or unselected entry must not inherit another entry's selected scope.
|
|
83
|
+
return `${parentID}:${fileIdentity(stat)}:${name}`;
|
|
84
|
+
}
|
|
85
|
+
function document(file, source) {
|
|
86
|
+
const text = source.replace(/^\uFEFF/, '').replaceAll('\r\n', '\n');
|
|
87
|
+
let body = text, metadata, offset = 0, metadataClosed = true;
|
|
88
|
+
if (text.startsWith('---\n')) {
|
|
89
|
+
const lines = text.split('\n');
|
|
90
|
+
const end = lines.findIndex((line, i) => i > 0 && /^(?:---|\.\.\.)\s*$/.test(line));
|
|
91
|
+
metadataClosed = end >= 0;
|
|
92
|
+
metadata = lines.slice(1, end < 0 ? undefined : end).join('\n');
|
|
93
|
+
offset = end < 0 ? lines.length : end + 1;
|
|
94
|
+
body = end < 0 ? '' : lines.slice(end + 1).join('\n');
|
|
95
|
+
}
|
|
96
|
+
const tokens = markdown.parse(body, {});
|
|
97
|
+
const slugger = new GithubSlugger(), headings = new Set();
|
|
98
|
+
for (let i = 0; i < tokens.length; i++)
|
|
99
|
+
if (tokens[i].type === 'heading_open') {
|
|
100
|
+
const children = tokens[i + 1]?.children ?? [];
|
|
101
|
+
const text = children.map(t => ['text', 'code_inline', 'image', 'docs_reference_missing'].includes(t.type) ? t.content : ['softbreak', 'hardbreak'].includes(t.type) ? ' ' : '').join('');
|
|
102
|
+
headings.add(slugger.slug(text));
|
|
103
|
+
}
|
|
104
|
+
const customAnchors = tokens.some(t => (t.type === 'html_block' && /\b(?:id|name)\s*=/i.test(t.content)) || t.children?.some(c => c.type === 'html_inline' && /\b(?:id|name)\s*=/i.test(c.content))) || tokens.some((t, i) => tokens[i - 1]?.type === 'heading_open' && (t.children ?? []).some(c => c.type === 'text' && /\{#[^}]+\}/.test(c.content)));
|
|
105
|
+
return { path: file, body, offset, metadata, metadataClosed, tokens, headings, customAnchors };
|
|
106
|
+
}
|
|
107
|
+
export async function checkDocumentation(root) {
|
|
108
|
+
if (!meetsMinimum(process.versions.node, requirements.node))
|
|
109
|
+
throw Error(`Node ${process.versions.node} is unsupported; requires Node ${requirements.node}+. Install a compatible Node runtime.`);
|
|
110
|
+
root = path.resolve(root);
|
|
111
|
+
const c = config(root), settings = c.documentationChecks;
|
|
112
|
+
const roots = settings.roots.length ? settings.roots : [slash(path.posix.normalize(slash(c.docsRoot)))];
|
|
113
|
+
const findings = [];
|
|
114
|
+
const categories = Object.fromEntries(documentationCategories.map(category => [category, { mode: settings[category], status: settings[category] === 'off' ? 'off' : 'not-applicable', checked: 0 }]));
|
|
115
|
+
const scope = { roots, exclude: settings.exclude, selectedFiles: 0, readFiles: 0, excludedPaths: 0, reservedPaths: 0, nonLocalReferences: 0 };
|
|
116
|
+
const add = (category, code, file, message, line, incomplete = false) => {
|
|
117
|
+
if (settings[category] === 'off')
|
|
118
|
+
return;
|
|
119
|
+
findings.push({ category, code, path: file, line, message, incomplete, severity: settings[category] === 'enforce' ? 'error' : 'warning' });
|
|
120
|
+
};
|
|
121
|
+
const unavailable = (file, code, message) => { for (const category of documentationCategories)
|
|
122
|
+
add(category, code, file, message, undefined, true); };
|
|
123
|
+
const result = (parserVersion = null) => {
|
|
124
|
+
for (const category of documentationCategories)
|
|
125
|
+
if (settings[category] !== 'off') {
|
|
126
|
+
const own = findings.filter(f => f.category === category);
|
|
127
|
+
categories[category].status = own.some(f => f.incomplete) ? 'incomplete' : own.length ? 'issues' : categories[category].checked ? 'passed' : 'not-applicable';
|
|
128
|
+
}
|
|
129
|
+
const exitCode = findings.some(f => f.severity === 'error') ? 1 : 0;
|
|
130
|
+
return { ok: exitCode === 0, exitCode, scope, limits: documentationLimits, categories, anchorDialect: 'github-slugger', mermaidParserVersion: parserVersion, findings };
|
|
131
|
+
};
|
|
132
|
+
if (documentationCategories.every(category => settings[category] === 'off'))
|
|
133
|
+
return result();
|
|
134
|
+
const selected = new Set(), visited = new Set();
|
|
135
|
+
const pending = [...roots].sort().reverse();
|
|
136
|
+
let entries = 0, stopped = false;
|
|
137
|
+
while (pending.length && !stopped) {
|
|
138
|
+
const file = pending.pop();
|
|
139
|
+
if (settings.exclude.some(exclude => matches(file, exclude))) {
|
|
140
|
+
scope.excludedPaths++;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
if (reserved(file)) {
|
|
144
|
+
scope.reservedPaths++;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
if (visited.has(file))
|
|
148
|
+
continue;
|
|
149
|
+
visited.add(file);
|
|
150
|
+
try {
|
|
151
|
+
const full = local(root, file), stat = fs.lstatSync(full);
|
|
152
|
+
if (stat.isDirectory()) {
|
|
153
|
+
const names = [];
|
|
154
|
+
const dir = fs.opendirSync(full);
|
|
155
|
+
try {
|
|
156
|
+
let entry;
|
|
157
|
+
while ((entry = dir.readSync())) {
|
|
158
|
+
if (++entries > documentationLimits.directoryEntries) {
|
|
159
|
+
unavailable(file, 'docs-entry-limit', 'Directory entry limit reached; remaining scope is unchecked.');
|
|
160
|
+
stopped = true;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
names.push(entry.name);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
finally {
|
|
167
|
+
dir.closeSync();
|
|
168
|
+
}
|
|
169
|
+
for (const name of names.sort().reverse())
|
|
170
|
+
pending.push(file === '.' ? name : `${file}/${name}`);
|
|
171
|
+
}
|
|
172
|
+
else if (stat.isFile() && isMarkdown(file)) {
|
|
173
|
+
if (selected.size === documentationLimits.files) {
|
|
174
|
+
unavailable(file, 'docs-file-limit', 'Markdown file limit reached; remaining scope is unchecked.');
|
|
175
|
+
stopped = true;
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
selected.add(file);
|
|
179
|
+
}
|
|
180
|
+
else if (roots.includes(file))
|
|
181
|
+
unavailable(file, 'docs-unsupported-root', 'Select a Markdown file or directory.');
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
unavailable(file, 'docs-unreadable-path', 'Path is missing, unreadable, or resolves through a symbolic link; content was not read.');
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
scope.selectedFiles = selected.size;
|
|
188
|
+
const documents = new Map();
|
|
189
|
+
const identities = new Map(), directories = new Map();
|
|
190
|
+
for (const file of [...selected].sort()) {
|
|
191
|
+
try {
|
|
192
|
+
const full = local(root, file);
|
|
193
|
+
const stat = fs.statSync(full, { bigint: true });
|
|
194
|
+
if (stat.size > BigInt(documentationLimits.fileBytes)) {
|
|
195
|
+
unavailable(file, 'docs-file-size', 'File exceeds the byte limit; content is unchecked.');
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const content = fs.readFileSync(full);
|
|
199
|
+
if (content.length > documentationLimits.fileBytes) {
|
|
200
|
+
unavailable(file, 'docs-file-size', 'File exceeds the byte limit; content is unchecked.');
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const doc = document(file, content.toString('utf8'));
|
|
204
|
+
documents.set(file, doc);
|
|
205
|
+
scope.readFiles++;
|
|
206
|
+
if (settings.links !== 'off') {
|
|
207
|
+
let identity;
|
|
208
|
+
try {
|
|
209
|
+
identity = entryIdentity(full, stat, directories, true);
|
|
210
|
+
}
|
|
211
|
+
catch { /* Report incomplete identity without discarding other checks. */ }
|
|
212
|
+
if (identity)
|
|
213
|
+
identities.set(identity, doc);
|
|
214
|
+
else
|
|
215
|
+
add('links', 'docs-identity-unchecked', file, 'Selected document identity could not be established for fragment checks.', undefined, true);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
unavailable(file, 'docs-read-failed', 'Selected file could not be read or parsed.');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
const diagrams = [];
|
|
223
|
+
for (const doc of documents.values()) {
|
|
224
|
+
if (!doc.metadataClosed)
|
|
225
|
+
for (const category of ['links', 'mermaid'])
|
|
226
|
+
add(category, 'docs-body-unchecked', doc.path, 'Unclosed frontmatter leaves the Markdown body boundary unknown.', 1, true);
|
|
227
|
+
if (settings.metadata !== 'off') {
|
|
228
|
+
categories.metadata.checked++;
|
|
229
|
+
const lineCounter = new LineCounter();
|
|
230
|
+
const parsed = doc.metadata === undefined ? undefined : parseDocument(doc.metadata, { lineCounter });
|
|
231
|
+
if (!doc.metadataClosed)
|
|
232
|
+
add('metadata', 'docs-frontmatter-unclosed', doc.path, 'Close the YAML frontmatter block.', 1);
|
|
233
|
+
else if (parsed && (parsed.errors.length || !isMap(parsed.contents))) {
|
|
234
|
+
if (!parsed.errors.length)
|
|
235
|
+
add('metadata', 'docs-frontmatter-mapping', doc.path, 'Frontmatter must be a YAML mapping.', 1);
|
|
236
|
+
for (const error of parsed.errors)
|
|
237
|
+
add('metadata', 'docs-frontmatter-yaml', doc.path, `Invalid frontmatter (${error.code}).`, lineCounter.linePos(error.pos[0]).line + 1);
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
let values;
|
|
241
|
+
try {
|
|
242
|
+
values = parsed?.toJS({ maxAliasCount: 100 }) ?? {};
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
add('metadata', 'docs-frontmatter-alias', doc.path, 'Frontmatter cannot be resolved within the YAML alias limit.', 1);
|
|
246
|
+
}
|
|
247
|
+
for (const rule of values === undefined ? [] : settings.metadataRules.filter(r => matches(doc.path, r.path))) {
|
|
248
|
+
for (const field of rule.required)
|
|
249
|
+
if (!Object.hasOwn(values, field))
|
|
250
|
+
add('metadata', 'docs-metadata-required', doc.path, `Required field ${field} is absent (rule ${rule.path}).`, 1);
|
|
251
|
+
for (const [field, allowed] of Object.entries(rule.values))
|
|
252
|
+
if (Object.hasOwn(values, field) && !allowed.includes(values[field]))
|
|
253
|
+
add('metadata', 'docs-metadata-value', doc.path, `Field ${field} has a disallowed value (rule ${rule.path}).`, 1);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (settings.links !== 'off')
|
|
258
|
+
checkLinks(doc, root, identities, directories, categories.links, scope, add);
|
|
259
|
+
if (settings.mermaid !== 'off')
|
|
260
|
+
for (const token of doc.tokens)
|
|
261
|
+
if (token.type === 'fence' && token.info.trim() === 'mermaid') {
|
|
262
|
+
categories.mermaid.checked++;
|
|
263
|
+
const line = (token.map?.[0] ?? 0) + doc.offset + 1;
|
|
264
|
+
if (Buffer.byteLength(token.content) > documentationLimits.diagramBytes)
|
|
265
|
+
add('mermaid', 'docs-mermaid-size', doc.path, 'Mermaid block exceeds the byte limit; syntax is unchecked.', line, true);
|
|
266
|
+
else
|
|
267
|
+
diagrams.push({ path: doc.path, line, text: token.content });
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const parsed = await checkDiagrams(diagrams);
|
|
271
|
+
parsed.outcomes.forEach((outcome, i) => {
|
|
272
|
+
const diagram = diagrams[i];
|
|
273
|
+
if (outcome === 'invalid')
|
|
274
|
+
add('mermaid', 'docs-mermaid-syntax', diagram.path, 'Mermaid syntax is invalid for the included parser.', diagram.line);
|
|
275
|
+
if (outcome === 'incomplete')
|
|
276
|
+
add('mermaid', 'docs-mermaid-unavailable', diagram.path, 'Mermaid parsing did not complete; check the installation or the documented limits.', diagram.line, true);
|
|
277
|
+
});
|
|
278
|
+
return result(parsed.version);
|
|
279
|
+
}
|
|
280
|
+
function checkLinks(doc, root, identities, directories, category, scope, add) {
|
|
281
|
+
category.checked++;
|
|
282
|
+
for (const token of doc.tokens)
|
|
283
|
+
for (const child of token.children ?? []) {
|
|
284
|
+
if (child.type === 'docs_reference_missing') {
|
|
285
|
+
add('links', 'docs-reference-undefined', doc.path, 'Explicit Markdown reference has no definition.', (token.map?.[0] ?? 0) + doc.offset + 1);
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (!['link_open', 'image'].includes(child.type))
|
|
289
|
+
continue;
|
|
290
|
+
const href = String(child.attrGet(child.type === 'image' ? 'src' : 'href') ?? '');
|
|
291
|
+
const line = (token.map?.[0] ?? 0) + doc.offset + 1;
|
|
292
|
+
if (/^(?:[a-z][a-z\d+.-]*:|\/)/i.test(href)) {
|
|
293
|
+
scope.nonLocalReferences++;
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
const hash = href.indexOf('#'), query = href.indexOf('?');
|
|
297
|
+
const end = Math.min(...[hash, query, href.length].filter(n => n >= 0));
|
|
298
|
+
let filename, fragment;
|
|
299
|
+
try {
|
|
300
|
+
filename = decodeURIComponent(href.slice(0, end));
|
|
301
|
+
fragment = hash < 0 ? '' : decodeURIComponent(href.slice(hash + 1));
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
add('links', 'docs-link-encoding', doc.path, 'Local reference has invalid URI encoding.', line);
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const target = filename ? path.resolve(root, path.dirname(doc.path), slash(filename)) : path.resolve(root, doc.path);
|
|
308
|
+
const relative = slash(path.relative(root, target));
|
|
309
|
+
let stat, full;
|
|
310
|
+
try {
|
|
311
|
+
if (path.isAbsolute(relative) || relative === '..' || relative.startsWith('../') || reserved(relative))
|
|
312
|
+
throw Error();
|
|
313
|
+
full = local(root, relative || '.');
|
|
314
|
+
stat = fs.statSync(full, { bigint: true });
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
const missing = error?.code === 'ENOENT';
|
|
318
|
+
add('links', missing ? 'docs-link-missing' : 'docs-link-unchecked', doc.path, missing ? `Local reference target ${JSON.stringify(relative)} does not exist.` : 'Local reference target is outside safe readable scope.', line, !missing);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
if (!fragment)
|
|
322
|
+
continue;
|
|
323
|
+
let identity;
|
|
324
|
+
try {
|
|
325
|
+
if (stat.isFile())
|
|
326
|
+
identity = entryIdentity(full, stat, directories);
|
|
327
|
+
}
|
|
328
|
+
catch { /* Unknown identity remains an unchecked fragment. */ }
|
|
329
|
+
const targetDoc = identity ? identities.get(identity) : undefined;
|
|
330
|
+
if (!stat.isFile() || !isMarkdown(relative) || !targetDoc) {
|
|
331
|
+
add('links', 'docs-fragment-unchecked', doc.path, 'Fragment requires a selected readable Markdown target; it was not checked.', line, true);
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
if (!targetDoc.headings.has(fragment))
|
|
335
|
+
add('links', targetDoc.customAnchors ? 'docs-fragment-unsupported' : 'docs-fragment-missing', doc.path, targetDoc.customAnchors ? 'Target has custom anchors; this fragment is outside the supported heading convention.' : `Heading fragment ${JSON.stringify(fragment)} does not exist in ${JSON.stringify(relative)} under the supported convention.`, line, targetDoc.customAnchors);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type DiagramInput = {
|
|
2
|
+
path: string;
|
|
3
|
+
line: number;
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
export type DiagramResult = {
|
|
7
|
+
version: string | null;
|
|
8
|
+
outcomes: ('passed' | 'invalid' | 'incomplete')[];
|
|
9
|
+
};
|
|
10
|
+
export declare function checkDiagrams(diagrams: DiagramInput[]): Promise<DiagramResult>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { fork } from 'node:child_process';
|
|
2
|
+
export async function checkDiagrams(diagrams) {
|
|
3
|
+
const result = { version: null, outcomes: diagrams.map(() => 'incomplete') };
|
|
4
|
+
if (!diagrams.length)
|
|
5
|
+
return result;
|
|
6
|
+
return new Promise(resolve => {
|
|
7
|
+
const child = fork(new URL('./mermaid-worker.js', import.meta.url), [], { silent: true, windowsHide: true, execArgv: [], env: { ...process.env, NODE_OPTIONS: '' } });
|
|
8
|
+
let index = 0, bytes = 0, finished = false;
|
|
9
|
+
const finish = () => { if (finished)
|
|
10
|
+
return; finished = true; clearTimeout(timer); child.kill(); resolve(result); };
|
|
11
|
+
let timer = setTimeout(finish, 5000);
|
|
12
|
+
const deadline = () => { clearTimeout(timer); timer = setTimeout(finish, 5000); };
|
|
13
|
+
for (const stream of [child.stdout, child.stderr])
|
|
14
|
+
stream?.on('data', data => { bytes += data.length; if (bytes > 65536)
|
|
15
|
+
finish(); });
|
|
16
|
+
child.on('error', finish);
|
|
17
|
+
child.on('exit', finish);
|
|
18
|
+
child.on('message', message => {
|
|
19
|
+
if (finished || !message || typeof message !== 'object')
|
|
20
|
+
return;
|
|
21
|
+
const response = message;
|
|
22
|
+
if (response.ready && typeof response.version === 'string')
|
|
23
|
+
result.version = response.version;
|
|
24
|
+
else if (typeof response.valid === 'boolean' && result.version) {
|
|
25
|
+
result.outcomes[index++] = response.valid ? 'passed' : 'invalid';
|
|
26
|
+
if (index === diagrams.length) {
|
|
27
|
+
finish();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
finish();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
deadline();
|
|
36
|
+
child.send(diagrams[index].text, error => { if (error)
|
|
37
|
+
finish(); });
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
// Do not enable scripts or resource loading in this parsing-only DOM.
|
|
5
|
+
const { window } = new JSDOM('');
|
|
6
|
+
Object.assign(globalThis, { window, document: window.document });
|
|
7
|
+
const { default: mermaid } = await import('mermaid');
|
|
8
|
+
mermaid.initialize({ startOnLoad: false, securityLevel: 'strict', secure: ['securityLevel', 'startOnLoad', 'maxTextSize', 'suppressErrorRendering'], maxTextSize: 262144, suppressErrorRendering: true });
|
|
9
|
+
process.send?.({ ready: true, version: require('mermaid/package.json').version });
|
|
10
|
+
process.on('message', async (value) => {
|
|
11
|
+
if (typeof value !== 'string' || Buffer.byteLength(value) > 262144) {
|
|
12
|
+
process.exitCode = 1;
|
|
13
|
+
process.disconnect?.();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
await mermaid.parse(value);
|
|
18
|
+
process.send?.({ valid: true });
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// Parser errors can contain whole source lines; report location in the parent.
|
|
22
|
+
process.send?.({ valid: false });
|
|
23
|
+
}
|
|
24
|
+
});
|
package/dist/quality.d.ts
CHANGED
|
@@ -23,5 +23,5 @@ type Scenario = {
|
|
|
23
23
|
testTypes: string[];
|
|
24
24
|
};
|
|
25
25
|
type Resolve = (root: string, relative: string) => string;
|
|
26
|
-
export declare function checkQuality(root: string, config: Config, specs: Scenario[], report: any, change: string | undefined, resolve: Resolve): Finding[];
|
|
26
|
+
export declare function checkQuality(root: string, config: Config, specs: Scenario[], report: any, change: string | undefined, resolve: Resolve, capability?: string): Finding[];
|
|
27
27
|
export {};
|
package/dist/quality.js
CHANGED
|
@@ -47,7 +47,7 @@ export function configureQuality(settings, raw) {
|
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
const git = (root, ...args) => execFileSync('git', ['-C', root, ...args], { stdio: ['ignore', 'pipe', 'pipe'], maxBuffer: 32 * 1024 * 1024 });
|
|
50
|
-
export function checkQuality(root, config, specs, report, change, resolve) {
|
|
50
|
+
export function checkQuality(root, config, specs, report, change, resolve, capability) {
|
|
51
51
|
const findings = [];
|
|
52
52
|
const modes = { coverage: config.testing.quality.coverage.mode, effectiveness: config.testing.quality.effectiveness.mode, lifecycle: config.testing.lifecycle.mode };
|
|
53
53
|
const add = (policy, code, message) => {
|
|
@@ -57,7 +57,8 @@ export function checkQuality(root, config, specs, report, change, resolve) {
|
|
|
57
57
|
if (Object.values(modes).every(value => value === 'off'))
|
|
58
58
|
return findings;
|
|
59
59
|
const ids = new Set(specs.map(s => s.id));
|
|
60
|
-
const
|
|
60
|
+
const recordName = capability !== undefined ? `capability-${capability}` : change ? `change-${change}` : 'specs';
|
|
61
|
+
const recordPath = `.cliewen-openspec/reviews/${recordName}.yaml`;
|
|
61
62
|
let review;
|
|
62
63
|
let usable = false;
|
|
63
64
|
try {
|
|
@@ -75,7 +76,9 @@ export function checkQuality(root, config, specs, report, change, resolve) {
|
|
|
75
76
|
only(review, ['version', 'scope', 'baseline', 'inputs', 'effectiveness', 'lifecycle', 'exceptions'], 'test review');
|
|
76
77
|
if (review.version !== 1 || !object(review.inputs) || !Object.keys(review.inputs).length || ![review.effectiveness, review.lifecycle, review.exceptions].every(Array.isArray))
|
|
77
78
|
throw Error('Expected version 1, nonempty inputs, and effectiveness/lifecycle/exceptions lists');
|
|
78
|
-
|
|
79
|
+
const scopeMatches = object(review.scope) && Object.keys(review.scope).length === 1 &&
|
|
80
|
+
(capability !== undefined ? review.scope.capability === capability : change ? review.scope.change === change : review.scope.specs === true);
|
|
81
|
+
if (!scopeMatches)
|
|
79
82
|
throw Error('test-review-scope-mismatch');
|
|
80
83
|
if (typeof review.baseline !== 'string' || !/^[a-f0-9]{40,64}$/.test(review.baseline))
|
|
81
84
|
throw Error('baseline must be a full Git commit ID');
|
|
@@ -219,14 +222,14 @@ export function checkQuality(root, config, specs, report, change, resolve) {
|
|
|
219
222
|
return;
|
|
220
223
|
// Scenario projection and baseline comparison are performed without changing OpenSpec files.
|
|
221
224
|
try {
|
|
222
|
-
lifecycleReview(root, review, change, ids, report, add, waived, resolve);
|
|
225
|
+
lifecycleReview(root, review, change, ids, report, add, waived, resolve, capability);
|
|
223
226
|
}
|
|
224
227
|
catch (error) {
|
|
225
228
|
add('lifecycle', 'lifecycle-unresolved', String(error));
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
231
|
}
|
|
229
|
-
function lifecycleReview(root, review, change, ids, report, add, waived, resolve) {
|
|
232
|
+
function lifecycleReview(root, review, change, ids, report, add, waived, resolve, capability) {
|
|
230
233
|
const requirements = (source) => {
|
|
231
234
|
const result = new Map();
|
|
232
235
|
let operation = 'permanent', current, scenario, fence = '';
|
|
@@ -313,7 +316,8 @@ function lifecycleReview(root, review, change, ids, report, add, waived, resolve
|
|
|
313
316
|
}
|
|
314
317
|
return result;
|
|
315
318
|
};
|
|
316
|
-
const
|
|
319
|
+
const baselineTree = tree(review.baseline);
|
|
320
|
+
const baseline = flatten(baselineTree);
|
|
317
321
|
const targetTree = tree('HEAD');
|
|
318
322
|
if (change) {
|
|
319
323
|
const folder = `openspec/changes/${change}/specs`;
|
|
@@ -344,7 +348,14 @@ function lifecycleReview(root, review, change, ids, report, add, waived, resolve
|
|
|
344
348
|
}
|
|
345
349
|
}
|
|
346
350
|
const target = flatten(targetTree);
|
|
347
|
-
const
|
|
351
|
+
const selected = new Set(ids);
|
|
352
|
+
if (capability !== undefined) {
|
|
353
|
+
for (const requirement of baselineTree.get(`${capability}/spec.md`)?.values() ?? []) {
|
|
354
|
+
for (const id of requirement.scenarios.keys())
|
|
355
|
+
selected.add(id);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const required = new Set([...baseline.keys()].filter(id => (capability === undefined || selected.has(id)) && (!target.has(id) || baseline.get(id) !== target.get(id))));
|
|
348
359
|
const dispositions = new Set();
|
|
349
360
|
for (const entry of review.lifecycle) {
|
|
350
361
|
try {
|
|
@@ -352,6 +363,8 @@ function lifecycleReview(root, review, change, ids, report, add, waived, resolve
|
|
|
352
363
|
if (!text(entry.scenario) || dispositions.has(entry.scenario) || !['unchanged', 'modified', 'retired'].includes(entry.change) || !text(entry.reason) || !['proposed', 'reviewed'].includes(entry.status) || !Array.isArray(entry.tests))
|
|
353
364
|
throw Error('Invalid or duplicate lifecycle disposition');
|
|
354
365
|
dispositions.add(entry.scenario);
|
|
366
|
+
if (capability !== undefined && !selected.has(entry.scenario))
|
|
367
|
+
throw Error('Lifecycle disposition is outside the selected capability');
|
|
355
368
|
if (!baseline.has(entry.scenario))
|
|
356
369
|
throw Error('Lifecycle scenario must exist at baseline');
|
|
357
370
|
const isRetired = !target.has(entry.scenario);
|
|
@@ -392,6 +405,8 @@ function lifecycleReview(root, review, change, ids, report, add, waived, resolve
|
|
|
392
405
|
throw Error('Remapping needs replacement scenarios');
|
|
393
406
|
if (test.action !== 'remap' && test.replacementScenarios !== undefined)
|
|
394
407
|
throw Error('Replacement scenarios require remap');
|
|
408
|
+
if (capability !== undefined && test.action === 'remap' && replacements.some((id) => !ids.has(id)))
|
|
409
|
+
throw Error('Use a whole-project check for cross-capability remapping');
|
|
395
410
|
for (const id of replacements ?? [])
|
|
396
411
|
if (!target.has(id) || ((test.action === 'remap' || ids.has(id)) && !report.results.some((row) => row.scenario === id && row.outcome === 'passed')))
|
|
397
412
|
throw Error('Remapped or in-scope obligations require target scenarios and passing evidence');
|
package/dist/release.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export declare const version = "0.
|
|
1
|
+
export declare const version = "0.4.0";
|
|
2
2
|
export declare const requirements: {
|
|
3
|
-
readonly node: '
|
|
3
|
+
readonly node: '22.12.0';
|
|
4
4
|
readonly openspec: '1.15.0';
|
|
5
5
|
};
|
|
6
6
|
export declare const supportedInstallations: string[];
|
package/dist/release.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export const version = '0.
|
|
2
|
-
export const requirements = { node: '
|
|
3
|
-
export const supportedInstallations = [
|
|
1
|
+
export const version = '0.4.0';
|
|
2
|
+
export const requirements = { node: '22.12.0', openspec: '1.15.0' };
|
|
3
|
+
export const supportedInstallations = ['0.1.0', '0.2.0', '0.3.0', version];
|
|
4
4
|
export function stableVersion(value) {
|
|
5
5
|
const match = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/.exec(value);
|
|
6
6
|
if (!match)
|
package/dist/schema-source.js
CHANGED
|
@@ -6,4 +6,4 @@ export function template(relative) {
|
|
|
6
6
|
export function instruction(relative) {
|
|
7
7
|
return template(relative).trim().split(/\n/).map(line => line.trim()).join(' ');
|
|
8
8
|
}
|
|
9
|
-
export const routing = ['routing', 'writing', 'humanizer', 'learnings', 'diagrams', 'work-scoping'].map(name => instruction(`base/instructions/${name}.md`)).join(' ') + ' Read .cliewen-openspec/planning.md for optional planning guidance; features.planning controls its planning-specific requests.';
|
|
9
|
+
export const routing = ['routing', 'writing', 'humanizer', 'learnings', 'diagrams', 'documentation-checks', 'work-scoping', 'context-entry'].map(name => instruction(`base/instructions/${name}.md`)).join(' ') + ' Read .cliewen-openspec/planning.md for optional planning guidance; features.planning controls its planning-specific requests. For relevant integration/review work with ciInspection configured and enabled, read .cliewen-openspec/ci-inspection.md for advisory host inspection; this adds no integration authorization.';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type SetupProfile } from './core.js';
|
|
2
|
+
export declare function selectSetupProfile(root: string, selected: string | undefined, options: {
|
|
3
|
+
interactive: boolean;
|
|
4
|
+
concurrent: boolean;
|
|
5
|
+
sharedReview: boolean;
|
|
6
|
+
enableReview: boolean;
|
|
7
|
+
existingOnly?: boolean;
|
|
8
|
+
}): Promise<{
|
|
9
|
+
selection: {
|
|
10
|
+
profile: "solo" | "team";
|
|
11
|
+
enableReview: boolean;
|
|
12
|
+
basis: {
|
|
13
|
+
settings: string | undefined;
|
|
14
|
+
stored: string | undefined;
|
|
15
|
+
current: SetupProfile | undefined;
|
|
16
|
+
review: boolean;
|
|
17
|
+
coordinated: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
summary: {
|
|
21
|
+
current: SetupProfile | null;
|
|
22
|
+
proposed: "solo" | "team";
|
|
23
|
+
recommendations: string[];
|
|
24
|
+
settings: {
|
|
25
|
+
key: string;
|
|
26
|
+
current: boolean;
|
|
27
|
+
proposed: boolean;
|
|
28
|
+
selected: boolean;
|
|
29
|
+
}[];
|
|
30
|
+
};
|
|
31
|
+
} | undefined>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
import { profileSnapshot, setupProfile } from './core.js';
|
|
3
|
+
export async function selectSetupProfile(root, selected, options) {
|
|
4
|
+
const { interactive, existingOnly } = options;
|
|
5
|
+
let { concurrent, sharedReview, enableReview } = options;
|
|
6
|
+
let profile = selected === undefined ? undefined : setupProfile(selected);
|
|
7
|
+
if (!profile && !interactive)
|
|
8
|
+
return;
|
|
9
|
+
const basis = profileSnapshot(root, existingOnly);
|
|
10
|
+
const terminal = interactive ? createInterface({ input: process.stdin, output: process.stderr }) : undefined;
|
|
11
|
+
const abort = new AbortController();
|
|
12
|
+
terminal?.once('SIGINT', () => terminal.close());
|
|
13
|
+
terminal?.once('close', () => abort.abort());
|
|
14
|
+
const ask = (question) => terminal.question(question, { signal: abort.signal });
|
|
15
|
+
const yes = async (question) => /^y(?:es)?$/i.test((await ask(question)).trim());
|
|
16
|
+
try {
|
|
17
|
+
if (!profile) {
|
|
18
|
+
const explanation = basis.settings === undefined
|
|
19
|
+
? 'Assign acceptance IDs locally. Agents are asked to test each implementation task and collect evidence. Test quality and lifecycle findings are advisory. Set up CI separately if you use it.'
|
|
20
|
+
: 'Keep your current settings if you choose a profile later.';
|
|
21
|
+
process.stderr.write(`${explanation}\nSee all settings at https://cliewen-openspec.github.io/guide/configuration.html#full-defaults\n`);
|
|
22
|
+
const choice = (await ask('How do you work on this project? Solo / Team / Choose later [later]: ')).trim().toLowerCase();
|
|
23
|
+
if (!choice || choice === 'later' || choice === 'choose later')
|
|
24
|
+
return;
|
|
25
|
+
profile = setupProfile(choice);
|
|
26
|
+
}
|
|
27
|
+
if (terminal) {
|
|
28
|
+
process.stderr.write(`Setup profile: ${basis.current ?? 'none'} → ${profile}\n`);
|
|
29
|
+
if (!concurrent && !basis.coordinated)
|
|
30
|
+
concurrent = await yes('Can separate clones or worktrees allocate IDs concurrently? [y/N] ');
|
|
31
|
+
if (profile === 'team' && !sharedReview && !basis.review)
|
|
32
|
+
sharedReview = await yes('Does the team review changes together? [y/N] ');
|
|
33
|
+
}
|
|
34
|
+
if (enableReview && (profile !== 'team' || !sharedReview))
|
|
35
|
+
throw Error('Use --enable-review with a team profile and --shared-review.');
|
|
36
|
+
const reviewRecommended = profile === 'team' && sharedReview && !basis.review;
|
|
37
|
+
const recommendations = [];
|
|
38
|
+
if (concurrent && !basis.coordinated) {
|
|
39
|
+
recommendations.push('Preview Git coordination with cliewen-openspec ac coordinate REMOTE. Concurrent allocation needs a shared authority.');
|
|
40
|
+
}
|
|
41
|
+
if (profile === 'team')
|
|
42
|
+
recommendations.push('Use the project’s existing integration policy for review and CI.');
|
|
43
|
+
if (reviewRecommended)
|
|
44
|
+
recommendations.push('Enable features.review for agents to prepare changes for team review (false → true).');
|
|
45
|
+
if (terminal) {
|
|
46
|
+
for (const recommendation of recommendations)
|
|
47
|
+
process.stderr.write(`${recommendation}\n`);
|
|
48
|
+
if (reviewRecommended && !enableReview)
|
|
49
|
+
enableReview = await yes('Enable features.review? [y/N] ');
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
selection: { profile, enableReview, basis },
|
|
53
|
+
summary: { current: basis.current ?? null, proposed: profile, recommendations, settings: reviewRecommended ? [{ key: 'features.review', current: false, proposed: true, selected: enableReview }] : [] }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
terminal?.close();
|
|
58
|
+
}
|
|
59
|
+
}
|