cliewen-openspec 0.1.0-alpha.1 → 0.2.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 +87 -54
- package/README.md +106 -104
- package/adapters/node-test.mjs +21 -4
- package/dist/cli.js +7 -31
- package/dist/compatibility.d.ts +12 -0
- package/dist/compatibility.js +87 -0
- package/dist/core.d.ts +23 -4
- package/dist/core.js +107 -35
- package/dist/quality.d.ts +27 -0
- package/dist/quality.js +412 -0
- package/dist/release.d.ts +9 -0
- package/dist/release.js +23 -0
- package/dist/schema-source.js +1 -1
- package/docs/configuration.md +317 -265
- package/docs/testing/evidence.md +88 -86
- package/docs/testing/pilot-prompt.md +1 -1
- package/docs/testing/test-quality.md +84 -0
- package/package.json +9 -5
- package/schemas/all/templates/tasks.md +1 -5
- package/schemas/base/instructions/closure.md +33 -0
- package/schemas/base/instructions/humanizer.md +7 -0
- package/schemas/base/instructions/learnings.md +6 -0
- package/schemas/base/instructions/planning.md +31 -0
- package/schemas/base/instructions/product-context.md +31 -0
- package/schemas/base/instructions/prototyping.md +33 -0
- package/schemas/base/instructions/routing.md +1 -0
- package/schemas/base/instructions/testing-approach.md +14 -13
- package/schemas/base/instructions/work-scoping.md +12 -0
- package/schemas/base/instructions/writing.md +8 -0
- package/schemas/base/templates/learning.md +19 -0
- package/schemas/delivery/instructions/apply.md +2 -1
- package/schemas/delivery/instructions/tasks.md +3 -2
- package/schemas/delivery/templates/tasks.md +5 -7
- package/schemas/discovery/instructions/apply.md +1 -0
- package/schemas/discovery/instructions/investigation.md +1 -0
- package/dist/tdd.d.ts +0 -8
- package/dist/tdd.js +0 -276
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { execFileSync } from 'node:child_process';
|
|
5
|
+
import { requirements, meetsMinimum } from './release.js';
|
|
6
|
+
function npmCommand(root) {
|
|
7
|
+
let entry;
|
|
8
|
+
try {
|
|
9
|
+
entry = createRequire(path.join(path.resolve(root), 'package.json')).resolve('@fission-ai/openspec');
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
13
|
+
// A present but broken package must not be hidden by a global installation.
|
|
14
|
+
const locations = createRequire(path.join(path.resolve(root), 'package.json')).resolve.paths('@fission-ai/openspec') ?? [];
|
|
15
|
+
if (locations.some(p => fs.existsSync(path.join(p, '@fission-ai/openspec/package.json'))))
|
|
16
|
+
throw Error('Project OpenSpec package cannot be resolved; repair its installation before init/update.');
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
throw Error('Project OpenSpec package cannot be resolved; repair its installation before init/update.');
|
|
20
|
+
}
|
|
21
|
+
let cursor = path.dirname(entry);
|
|
22
|
+
while (true) {
|
|
23
|
+
const metadata = path.join(cursor, 'package.json');
|
|
24
|
+
if (fs.existsSync(metadata)) {
|
|
25
|
+
const pkg = JSON.parse(fs.readFileSync(metadata, 'utf8'));
|
|
26
|
+
if (pkg.name === '@fission-ai/openspec') {
|
|
27
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.openspec;
|
|
28
|
+
if (typeof bin !== 'string')
|
|
29
|
+
throw Error('Project OpenSpec package has no public CLI; repair its installation.');
|
|
30
|
+
const cli = path.resolve(cursor, bin), relative = path.relative(cursor, cli);
|
|
31
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative))
|
|
32
|
+
throw Error('Project OpenSpec CLI path is invalid; repair its installation.');
|
|
33
|
+
return { file: process.execPath, args: [cli], source: `project npm: ${cli}` };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const parent = path.dirname(cursor);
|
|
37
|
+
if (parent === cursor)
|
|
38
|
+
throw Error('Project OpenSpec package metadata cannot be located; repair its installation.');
|
|
39
|
+
cursor = parent;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function pathCommand() {
|
|
43
|
+
const extensions = process.platform === 'win32' ? ['.exe', '.cmd', '.bat', ''] : [''];
|
|
44
|
+
for (const directory of (process.env.PATH ?? '').split(path.delimiter).filter(Boolean)) {
|
|
45
|
+
for (const extension of extensions) {
|
|
46
|
+
const candidate = path.resolve(directory.replace(/^"|"$/g, ''), `openspec${extension}`);
|
|
47
|
+
if (!fs.existsSync(candidate) || !fs.statSync(candidate).isFile())
|
|
48
|
+
continue;
|
|
49
|
+
if (process.platform !== 'win32') {
|
|
50
|
+
try {
|
|
51
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (/\.(cmd|bat)$/i.test(candidate)) {
|
|
58
|
+
// npm/cmd-shim's public JS entry can be invoked without executing shell text.
|
|
59
|
+
const text = fs.readFileSync(candidate, 'utf8');
|
|
60
|
+
const entry = /"%dp0%[\\/]([^"\r\n]+\.(?:c|m)?js)"\s+%\*/i.exec(text)?.[1];
|
|
61
|
+
if (!entry)
|
|
62
|
+
throw Error(`Cannot safely resolve OpenSpec PATH shim: ${candidate}. Use a project-local npm installation or a standalone executable.`);
|
|
63
|
+
const cli = path.resolve(path.dirname(candidate), entry.replaceAll('\\', path.sep));
|
|
64
|
+
return { file: process.execPath, args: [cli], source: `PATH npm shim: ${candidate} -> ${cli}` };
|
|
65
|
+
}
|
|
66
|
+
return { file: candidate, args: [], source: `PATH: ${candidate}` };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function compatibility(root) {
|
|
71
|
+
const node = process.versions.node;
|
|
72
|
+
if (!meetsMinimum(node, requirements.node))
|
|
73
|
+
throw Error(`Node ${node} is unsupported; requires Node ${requirements.node}+. Install a compatible Node runtime and rerun init/update.`);
|
|
74
|
+
const command = npmCommand(root) ?? pathCommand();
|
|
75
|
+
if (!command)
|
|
76
|
+
throw Error(`OpenSpec not found; requires OpenSpec ${requirements.openspec}+ and Node ${requirements.node}+. Install a compatible project-local @fission-ai/openspec package or expose its standalone CLI on PATH, then rerun init/update.`);
|
|
77
|
+
let output;
|
|
78
|
+
try {
|
|
79
|
+
output = execFileSync(command.file, [...command.args, '--version'], { cwd: root, encoding: 'utf8', timeout: 5000, maxBuffer: 65536, windowsHide: true, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env, OPENSPEC_TELEMETRY: '0', CI: '1' } }).trim();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
throw Error(`OpenSpec version probe failed or exceeded 5 seconds (${command.source}); requires OpenSpec ${requirements.openspec}+ runnable on Node ${node}. Repair the selected installation or its Node runtime and rerun init/update.`);
|
|
83
|
+
}
|
|
84
|
+
if (!meetsMinimum(output, requirements.openspec))
|
|
85
|
+
throw Error(`OpenSpec version ${JSON.stringify(output)} is unsupported (${command.source}); requires stable OpenSpec ${requirements.openspec}+. Install a compatible version deliberately and rerun init/update; Cliewen does not upgrade OpenSpec.`);
|
|
86
|
+
return { node: { version: node, minimum: requirements.node }, openspec: { version: output, minimum: requirements.openspec, source: command.source } };
|
|
87
|
+
}
|
package/dist/core.d.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { type QualitySettings } from './quality.js';
|
|
1
2
|
export { nextId, renamePrefix, capabilityForPrefix } from './ac.js';
|
|
2
|
-
|
|
3
|
+
import { type Compatibility } from './compatibility.js';
|
|
4
|
+
export { version } from './release.js';
|
|
3
5
|
export type Config = {
|
|
4
6
|
docsRoot: string;
|
|
7
|
+
learnings: {
|
|
8
|
+
enabled: boolean;
|
|
9
|
+
directory: string;
|
|
10
|
+
};
|
|
11
|
+
writing: {
|
|
12
|
+
humanizer: 'auto' | 'on' | 'off';
|
|
13
|
+
};
|
|
5
14
|
features: Record<string, boolean>;
|
|
6
15
|
evidence: {
|
|
7
16
|
report: string;
|
|
@@ -10,9 +19,8 @@ export type Config = {
|
|
|
10
19
|
capabilities: Record<string, string>;
|
|
11
20
|
padding: number;
|
|
12
21
|
};
|
|
13
|
-
testing: {
|
|
22
|
+
testing: QualitySettings & {
|
|
14
23
|
placement: 'per-task' | 'end-of-change';
|
|
15
|
-
approach: 'flexible' | 'tdd';
|
|
16
24
|
types: Record<string, {
|
|
17
25
|
description: string;
|
|
18
26
|
}>;
|
|
@@ -32,11 +40,22 @@ export declare function uninstall(root: string, dryRun?: boolean, replacement?:
|
|
|
32
40
|
writes: string[];
|
|
33
41
|
deletes: string[];
|
|
34
42
|
};
|
|
35
|
-
export
|
|
43
|
+
export type LifecycleResult = {
|
|
36
44
|
writes: string[];
|
|
37
45
|
deletes: string[];
|
|
46
|
+
creates: string[];
|
|
47
|
+
replaces: string[];
|
|
48
|
+
installedVersion: string | null;
|
|
49
|
+
targetVersion: string;
|
|
50
|
+
compatibility: Compatibility;
|
|
51
|
+
recoveredTransaction: boolean;
|
|
38
52
|
};
|
|
53
|
+
export declare function lifecycle(root: string, operation: 'init' | 'update', dryRun?: boolean, makeDefault?: boolean): LifecycleResult;
|
|
39
54
|
export declare function init(root: string, dryRun: boolean, makeDefault: boolean): string[];
|
|
55
|
+
export declare function update(root: string, dryRun?: boolean): {
|
|
56
|
+
writes: string[];
|
|
57
|
+
deletes: string[];
|
|
58
|
+
};
|
|
40
59
|
export declare function markdowns(dir: string): string[];
|
|
41
60
|
export declare function scenarios(root: string, change?: string): {
|
|
42
61
|
id: string;
|
package/dist/core.js
CHANGED
|
@@ -8,10 +8,13 @@ import { parse, parseDocument, stringify, isMap } from 'yaml';
|
|
|
8
8
|
import { deliveryFiles } from './delivery.js';
|
|
9
9
|
import { discoveryFiles } from './discovery.js';
|
|
10
10
|
import { allFiles } from './all.js';
|
|
11
|
+
import { template } from './schema-source.js';
|
|
11
12
|
import { validateRegistry } from './ac.js';
|
|
12
|
-
import {
|
|
13
|
+
import { qualityDefaults, configureQuality, checkQuality } from './quality.js';
|
|
13
14
|
export { nextId, renamePrefix, capabilityForPrefix } from './ac.js';
|
|
14
|
-
|
|
15
|
+
import { version, supportedInstallations, supportsInstallation } from './release.js';
|
|
16
|
+
import { compatibility } from './compatibility.js';
|
|
17
|
+
export { version } from './release.js';
|
|
15
18
|
const state = '.cliewen-openspec';
|
|
16
19
|
const features = ['documentation', 'decisions', 'mermaid', 'planning', 'review', 'evidence'];
|
|
17
20
|
export function local(root, relative) {
|
|
@@ -42,7 +45,7 @@ const normalize = (s) => s.replace(/\r\n/g, '\n');
|
|
|
42
45
|
const hash = (s) => createHash('sha256').update(normalize(s)).digest('hex');
|
|
43
46
|
const read = (p) => fs.readFileSync(p, 'utf8');
|
|
44
47
|
export function defaults() {
|
|
45
|
-
return { docsRoot: 'docs', features: Object.fromEntries(features.map(f => [f, true])), evidence: { report: '.cliewen-openspec/evidence.json' }, ac: { capabilities: {}, padding: 3 }, testing: { placement: 'per-task',
|
|
48
|
+
return { docsRoot: 'docs', learnings: { enabled: false, directory: 'learnings' }, writing: { humanizer: 'auto' }, features: Object.fromEntries(features.map(f => [f, true])), evidence: { report: '.cliewen-openspec/evidence.json' }, ac: { capabilities: {}, padding: 3 }, testing: { ...qualityDefaults(), placement: 'per-task', types: {
|
|
46
49
|
Unit: { description: 'Isolated behavior without external dependencies' },
|
|
47
50
|
Integration: { description: 'Interaction between components or dependencies' },
|
|
48
51
|
E2E: { description: 'Complete user or system workflow' }
|
|
@@ -58,8 +61,32 @@ function keys(o, allowed, label) {
|
|
|
58
61
|
export function config(root) {
|
|
59
62
|
const p = local(root, `${state}/config.yaml`);
|
|
60
63
|
const raw = parse(read(p));
|
|
61
|
-
keys(raw, ['docsRoot', 'features', 'evidence', 'ac', 'testing'], 'config');
|
|
64
|
+
keys(raw, ['docsRoot', 'learnings', 'writing', 'features', 'evidence', 'ac', 'testing'], 'config');
|
|
62
65
|
const c = defaults();
|
|
66
|
+
if (raw.learnings !== undefined) {
|
|
67
|
+
keys(raw.learnings, ['enabled', 'directory'], 'learnings');
|
|
68
|
+
if (raw.learnings.enabled !== undefined) {
|
|
69
|
+
if (typeof raw.learnings.enabled !== 'boolean')
|
|
70
|
+
throw Error('learnings.enabled must be boolean');
|
|
71
|
+
c.learnings.enabled = raw.learnings.enabled;
|
|
72
|
+
}
|
|
73
|
+
if (raw.learnings.directory !== undefined) {
|
|
74
|
+
const directory = raw.learnings.directory;
|
|
75
|
+
if (typeof directory !== 'string' || !directory.trim() || directory !== directory.trim())
|
|
76
|
+
throw Error('learnings.directory must be a nonempty trimmed relative path');
|
|
77
|
+
if (path.isAbsolute(directory) || path.win32.parse(directory).root || directory.split(/[\\/]/).includes('..'))
|
|
78
|
+
throw Error('learnings.directory must stay within docsRoot');
|
|
79
|
+
c.learnings.directory = directory;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (raw.writing !== undefined) {
|
|
83
|
+
keys(raw.writing, ['humanizer'], 'writing');
|
|
84
|
+
if (raw.writing.humanizer !== undefined) {
|
|
85
|
+
if (!['auto', 'on', 'off'].includes(raw.writing.humanizer))
|
|
86
|
+
throw Error('writing.humanizer must be auto, on, or off');
|
|
87
|
+
c.writing.humanizer = raw.writing.humanizer;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
63
90
|
if (raw.ac !== undefined) {
|
|
64
91
|
keys(raw.ac, ['capabilities', 'padding'], 'ac');
|
|
65
92
|
if (raw.ac.capabilities !== undefined) {
|
|
@@ -82,7 +109,10 @@ export function config(root) {
|
|
|
82
109
|
}
|
|
83
110
|
}
|
|
84
111
|
if (raw.testing !== undefined) {
|
|
85
|
-
|
|
112
|
+
if (Object.hasOwn(raw.testing, 'approach'))
|
|
113
|
+
throw Error('testing.approach has been retired. Remove it from .cliewen-openspec/config.yaml; use evidence-first verification. See docs/configuration.md#evidence-first-verification.');
|
|
114
|
+
keys(raw.testing, ['placement', 'types', 'quality', 'lifecycle'], 'testing');
|
|
115
|
+
configureQuality(c.testing, raw.testing);
|
|
86
116
|
if (raw.testing.types !== undefined) {
|
|
87
117
|
const types = raw.testing.types;
|
|
88
118
|
if (!types || typeof types !== 'object' || Array.isArray(types) || !Object.keys(types).length)
|
|
@@ -101,14 +131,7 @@ export function config(root) {
|
|
|
101
131
|
throw Error('testing.placement must be per-task or end-of-change');
|
|
102
132
|
c.testing.placement = raw.testing.placement;
|
|
103
133
|
}
|
|
104
|
-
if (raw.testing.approach !== undefined) {
|
|
105
|
-
if (!['flexible', 'tdd'].includes(raw.testing.approach))
|
|
106
|
-
throw Error('testing.approach must be flexible or tdd');
|
|
107
|
-
c.testing.approach = raw.testing.approach;
|
|
108
|
-
}
|
|
109
134
|
}
|
|
110
|
-
if (c.testing.approach === 'tdd' && c.testing.placement !== 'per-task')
|
|
111
|
-
throw Error('testing.approach tdd requires testing.placement per-task');
|
|
112
135
|
if (raw.docsRoot !== undefined) {
|
|
113
136
|
if (typeof raw.docsRoot !== 'string')
|
|
114
137
|
throw Error('docsRoot must be a string');
|
|
@@ -128,7 +151,11 @@ export function config(root) {
|
|
|
128
151
|
throw Error('evidence.report must be a string');
|
|
129
152
|
c.evidence.report = raw.evidence.report;
|
|
130
153
|
}
|
|
154
|
+
if (!c.features.evidence && [c.testing.quality.coverage.mode, c.testing.quality.effectiveness.mode, c.testing.lifecycle.mode].includes('enforce'))
|
|
155
|
+
throw Error('Test policy enforcement requires features.evidence: true; enable evidence or use review/off mode.');
|
|
131
156
|
local(root, c.docsRoot);
|
|
157
|
+
if (c.learnings.enabled && c.features.documentation)
|
|
158
|
+
local(root, `${c.docsRoot}/${c.learnings.directory}`);
|
|
132
159
|
local(root, c.evidence.report);
|
|
133
160
|
return c;
|
|
134
161
|
}
|
|
@@ -189,7 +216,7 @@ export function recover(root) {
|
|
|
189
216
|
}
|
|
190
217
|
fs.unlinkSync(jp);
|
|
191
218
|
}
|
|
192
|
-
function bundledFiles() { return { ...deliveryFiles(), ...discoveryFiles(), ...allFiles() }; }
|
|
219
|
+
function bundledFiles() { return { ...deliveryFiles(), ...discoveryFiles(), ...allFiles(), [`${state}/templates/learning.md`]: template('base/templates/learning.md'), [`${state}/planning.md`]: template('base/instructions/planning.md') + '\n## Work scoping\n\n' + template('base/instructions/work-scoping.md'), [`${state}/closure.md`]: template('base/instructions/closure.md'), [`${state}/prototyping.md`]: template('base/instructions/prototyping.md'), [`${state}/product-context.md`]: template('base/instructions/product-context.md') }; }
|
|
193
220
|
function manifestText(files) {
|
|
194
221
|
return JSON.stringify({ version, files: Object.fromEntries(Object.entries(files).map(([file, content]) => [file, hash(content)])) }, null, 2) + '\n';
|
|
195
222
|
}
|
|
@@ -201,13 +228,13 @@ function ownedManifest(root, operation) {
|
|
|
201
228
|
: 'No Cliewen installation manifest; no files removed. Uninstall requires recorded ownership.');
|
|
202
229
|
const previous = JSON.parse(read(mp));
|
|
203
230
|
keys(previous, ['version', 'files'], 'manifest');
|
|
204
|
-
if (previous.version
|
|
205
|
-
throw Error(`Unsupported installed version: ${previous.version}; ${operation}
|
|
231
|
+
if (!supportsInstallation(previous.version))
|
|
232
|
+
throw Error(`Unsupported installed version: ${previous.version}; ${operation} supports ${supportedInstallations.join(', ')} manifests only. Install a compatible package; no automatic migration or downgrade is available.`);
|
|
206
233
|
if (!previous.files || typeof previous.files !== 'object' || Array.isArray(previous.files) || !Object.keys(previous.files).length)
|
|
207
234
|
throw Error('Manifest files must be a nonempty ownership mapping');
|
|
208
235
|
for (const [file, digest] of Object.entries(previous.files)) {
|
|
209
236
|
local(root, file);
|
|
210
|
-
const owned =
|
|
237
|
+
const owned = [`${state}/templates/decision.md`, `${state}/templates/learning.md`, `${state}/planning.md`, `${state}/closure.md`, `${state}/prototyping.md`, `${state}/product-context.md`].includes(file) || /^openspec\/schemas\/cliewen-(delivery|discovery|all)\/(schema\.yaml|templates\/[a-z0-9][a-z0-9-]*\.md)$/.test(file);
|
|
211
238
|
if (!owned || typeof digest !== 'string' || !/^[a-f0-9]{64}$/.test(digest))
|
|
212
239
|
throw Error(`Invalid owned-file entry in manifest: ${file}`);
|
|
213
240
|
}
|
|
@@ -334,11 +361,9 @@ export function uninstall(root, dryRun = false, replacement) {
|
|
|
334
361
|
transaction(root, changes, dryRun);
|
|
335
362
|
return { writes: Object.keys(changes).filter(file => changes[file] !== null), deletes: Object.keys(changes).filter(file => changes[file] === null) };
|
|
336
363
|
}
|
|
337
|
-
|
|
364
|
+
function planUpdate(root) {
|
|
338
365
|
if (!fs.existsSync(local(root, 'openspec/specs')) || !fs.existsSync(local(root, 'openspec/changes')))
|
|
339
366
|
throw Error('Run openspec init first (specs and changes directories are required).');
|
|
340
|
-
if (!dryRun)
|
|
341
|
-
recover(root);
|
|
342
367
|
const manifestPath = `${state}/manifest.json`;
|
|
343
368
|
const mp = local(root, manifestPath);
|
|
344
369
|
const previous = ownedManifest(root, 'update');
|
|
@@ -376,18 +401,15 @@ export function update(root, dryRun = false) {
|
|
|
376
401
|
const manifest = manifestText(files);
|
|
377
402
|
if (read(mp) !== manifest)
|
|
378
403
|
changes[manifestPath] = manifest;
|
|
379
|
-
|
|
380
|
-
return { writes: Object.keys(changes).filter(file => changes[file] !== null), deletes: Object.keys(changes).filter(file => changes[file] === null) };
|
|
404
|
+
return changes;
|
|
381
405
|
}
|
|
382
|
-
|
|
406
|
+
function planInit(root, makeDefault) {
|
|
383
407
|
if (!fs.existsSync(local(root, 'openspec/specs')) || !fs.existsSync(local(root, 'openspec/changes')))
|
|
384
408
|
throw Error('Run openspec init first (specs and changes directories are required).');
|
|
385
|
-
if (!dryRun)
|
|
386
|
-
recover(root);
|
|
387
409
|
const mp = local(root, `${state}/manifest.json`);
|
|
388
|
-
const previous = fs.existsSync(mp) ?
|
|
410
|
+
const previous = fs.existsSync(mp) ? ownedManifest(root, 'update') : undefined;
|
|
389
411
|
if (previous && previous.version !== version)
|
|
390
|
-
throw Error(
|
|
412
|
+
throw Error(`Installed version differs: ${previous.version}; run update to install ${version} resources. Init does not upgrade an existing installation.`);
|
|
391
413
|
const files = bundledFiles();
|
|
392
414
|
const writes = {};
|
|
393
415
|
for (const [p, content] of Object.entries(files)) {
|
|
@@ -411,14 +433,22 @@ export function init(root, dryRun, makeDefault) {
|
|
|
411
433
|
writes[entry] = '---\ntype: overview\n---\n# Project documentation\n\nKeep architecture/, design/, decisions/, testing/ and optional plans/ here as needed. Link to OpenSpec specs for behavior. Do not invent project intent.\n';
|
|
412
434
|
const ignore = `${state}/.gitignore`;
|
|
413
435
|
if (!fs.existsSync(local(root, ignore)))
|
|
414
|
-
writes[ignore] = 'evidence.json\ntransaction.json\
|
|
436
|
+
writes[ignore] = 'evidence.json\ntransaction.json\nreview-output/\n';
|
|
415
437
|
const cfgPath = 'openspec/config.yaml';
|
|
416
438
|
const original = fs.existsSync(local(root, cfgPath)) ? read(local(root, cfgPath)) : '';
|
|
417
439
|
if (makeDefault) {
|
|
418
440
|
const doc = parseDocument(original || '{}');
|
|
419
441
|
if (doc.errors.length)
|
|
420
442
|
throw Error(doc.errors[0].message);
|
|
443
|
+
if (doc.contents !== null && !isMap(doc.contents))
|
|
444
|
+
throw Error('OpenSpec config must be a YAML mapping');
|
|
445
|
+
const before = { ...doc.toJS() };
|
|
446
|
+
delete before.schema;
|
|
421
447
|
doc.set('schema', 'cliewen-delivery');
|
|
448
|
+
const after = { ...doc.toJS() };
|
|
449
|
+
delete after.schema;
|
|
450
|
+
if (!isDeepStrictEqual(before, after))
|
|
451
|
+
throw Error('Selecting the default would change other YAML values through shared anchors; resolve those aliases explicitly before init.');
|
|
422
452
|
const next = doc.toString();
|
|
423
453
|
if (next !== original)
|
|
424
454
|
writes[cfgPath] = next;
|
|
@@ -426,7 +456,36 @@ export function init(root, dryRun, makeDefault) {
|
|
|
426
456
|
const manifest = manifestText(files);
|
|
427
457
|
if (!fs.existsSync(mp) || read(mp) !== manifest)
|
|
428
458
|
writes[`${state}/manifest.json`] = manifest;
|
|
429
|
-
return
|
|
459
|
+
return writes;
|
|
460
|
+
}
|
|
461
|
+
export function lifecycle(root, operation, dryRun = false, makeDefault = false) {
|
|
462
|
+
const tools = compatibility(root);
|
|
463
|
+
const pending = fs.existsSync(local(root, `${state}/transaction.json`));
|
|
464
|
+
if (pending && dryRun)
|
|
465
|
+
throw Error('Interrupted transaction exists; run recover before preview. No preview files changed.');
|
|
466
|
+
if (pending)
|
|
467
|
+
recover(root);
|
|
468
|
+
try {
|
|
469
|
+
const mp = local(root, `${state}/manifest.json`);
|
|
470
|
+
const installedVersion = fs.existsSync(mp) ? ownedManifest(root, 'update').version : null;
|
|
471
|
+
const changes = operation === 'init' ? planInit(root, makeDefault) : planUpdate(root);
|
|
472
|
+
const writes = Object.keys(changes).filter(file => changes[file] !== null);
|
|
473
|
+
const result = { writes, deletes: Object.keys(changes).filter(file => changes[file] === null), creates: writes.filter(file => !fs.existsSync(local(root, file))), replaces: writes.filter(file => fs.existsSync(local(root, file))), installedVersion, targetVersion: version, compatibility: tools, recoveredTransaction: pending };
|
|
474
|
+
transaction(root, changes, dryRun);
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
477
|
+
catch (error) {
|
|
478
|
+
if (pending)
|
|
479
|
+
throw Error(`Recovered the preceding transaction; ${operation} did not complete: ${error instanceof Error ? error.message : String(error)}`);
|
|
480
|
+
throw error;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
export function init(root, dryRun, makeDefault) {
|
|
484
|
+
return lifecycle(root, 'init', dryRun, makeDefault).writes;
|
|
485
|
+
}
|
|
486
|
+
export function update(root, dryRun = false) {
|
|
487
|
+
const { writes, deletes } = lifecycle(root, 'update', dryRun);
|
|
488
|
+
return { writes, deletes };
|
|
430
489
|
}
|
|
431
490
|
export function markdowns(dir) {
|
|
432
491
|
if (!fs.existsSync(dir))
|
|
@@ -436,7 +495,13 @@ export function markdowns(dir) {
|
|
|
436
495
|
export function scenarios(root, change) {
|
|
437
496
|
if (change && !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(change))
|
|
438
497
|
throw Error('Change must be a kebab-case name');
|
|
439
|
-
|
|
498
|
+
let folder = change ? local(root, `openspec/changes/${change}/specs`) : local(root, 'openspec/specs');
|
|
499
|
+
const metadata = change ? local(root, `openspec/changes/${change}/.openspec.yaml`) : undefined;
|
|
500
|
+
if (metadata && fs.existsSync(metadata) && parse(read(metadata))?.skip_specs === true) {
|
|
501
|
+
if (markdowns(folder).length)
|
|
502
|
+
throw Error('skip_specs changes must not contain product spec deltas');
|
|
503
|
+
folder = local(root, 'openspec/specs');
|
|
504
|
+
}
|
|
440
505
|
if (change && !fs.existsSync(folder))
|
|
441
506
|
throw Error(`Change specs do not exist: ${change}`);
|
|
442
507
|
const out = [];
|
|
@@ -477,10 +542,16 @@ export function check(root, change, failPending = false) {
|
|
|
477
542
|
if (!fs.existsSync(mp))
|
|
478
543
|
add('not-installed', 'Run init');
|
|
479
544
|
else {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
545
|
+
try {
|
|
546
|
+
const m = ownedManifest(root, 'update');
|
|
547
|
+
for (const [p, h] of Object.entries(m.files))
|
|
548
|
+
if (!fs.existsSync(local(root, p)) || hash(read(local(root, p))) !== h)
|
|
549
|
+
add('owned-file-modified', p);
|
|
550
|
+
}
|
|
551
|
+
catch (error) {
|
|
552
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
553
|
+
add(message.startsWith('Unsupported installed version') ? 'unsupported-installed-version' : 'invalid-installation-manifest', message);
|
|
554
|
+
}
|
|
484
555
|
}
|
|
485
556
|
try {
|
|
486
557
|
validateRegistry(root, c);
|
|
@@ -524,10 +595,10 @@ export function check(root, change, failPending = false) {
|
|
|
524
595
|
}
|
|
525
596
|
}
|
|
526
597
|
}
|
|
527
|
-
if (c.testing.approach === 'tdd')
|
|
528
|
-
findings.push(...checkTdd(root, change));
|
|
529
598
|
if (!c.features.evidence) {
|
|
530
599
|
add('evidence-disabled', 'Evidence was explicitly disabled', 'info');
|
|
600
|
+
if ([c.testing.quality.coverage.mode, c.testing.quality.effectiveness.mode, c.testing.lifecycle.mode].includes('review'))
|
|
601
|
+
add('quality-evidence-unavailable', 'Test policy review remains advisory: enable evidence for execution-backed assessment.', 'warning');
|
|
531
602
|
return findings;
|
|
532
603
|
}
|
|
533
604
|
const specs = scenarios(root, change);
|
|
@@ -612,6 +683,7 @@ export function check(root, change, failPending = false) {
|
|
|
612
683
|
for (const id of ids)
|
|
613
684
|
if (!seen.has(id))
|
|
614
685
|
add('missing-evidence', id);
|
|
686
|
+
findings.push(...checkQuality(root, c, specs, report, change, local));
|
|
615
687
|
add('sufficiency-not-assessed', 'Execution and linkage do not prove assertion quality; review the assertions against the scenarios.', 'info');
|
|
616
688
|
return findings;
|
|
617
689
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Config, Finding } from './core.js';
|
|
2
|
+
type Mode = 'off' | 'review' | 'enforce';
|
|
3
|
+
type Category = 'positive' | 'negative' | 'boundary';
|
|
4
|
+
export type QualitySettings = {
|
|
5
|
+
quality: {
|
|
6
|
+
coverage: {
|
|
7
|
+
mode: Mode;
|
|
8
|
+
minimumCases: Record<Category, number>;
|
|
9
|
+
};
|
|
10
|
+
effectiveness: {
|
|
11
|
+
mode: Mode;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
lifecycle: {
|
|
15
|
+
mode: Mode;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export declare function qualityDefaults(): QualitySettings;
|
|
19
|
+
export declare function configureQuality(settings: QualitySettings, raw: Record<string, any>): void;
|
|
20
|
+
type Scenario = {
|
|
21
|
+
id: string;
|
|
22
|
+
file: string;
|
|
23
|
+
testTypes: string[];
|
|
24
|
+
};
|
|
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[];
|
|
27
|
+
export {};
|