sdd-flow 1.3.3 → 2.0.1
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 +39 -0
- package/CONTRIBUTING.md +25 -0
- package/LICENSE +21 -21
- package/README.md +402 -168
- package/README.pt-BR.md +387 -0
- package/bin/cli.js +162 -424
- package/docs/architecture.md +91 -0
- package/docs/distribution.md +64 -0
- package/docs/formats.md +215 -0
- package/docs/local-testing.pt-BR.md +196 -0
- package/docs/methodology.pt-BR.md +139 -0
- package/docs/migration.md +76 -0
- package/docs/quality-gates.pt-BR.md +160 -0
- package/docs/quality.md +56 -0
- package/docs/releases.pt-BR.md +105 -0
- package/docs/setup-documents.pt-BR.md +120 -0
- package/docs/usage.pt-BR.md +310 -0
- package/docs/validation.md +101 -0
- package/lib/adapters.js +115 -0
- package/lib/check.js +221 -0
- package/lib/context.js +117 -0
- package/lib/documents.js +71 -0
- package/lib/handoff.js +81 -0
- package/lib/history.js +16 -0
- package/lib/install.js +181 -0
- package/lib/io.js +119 -0
- package/lib/legacy-hashes.json +31 -0
- package/lib/markdown.js +71 -0
- package/lib/project.js +200 -0
- package/lib/quality.js +24 -0
- package/lib/revisions.js +79 -0
- package/lib/verification.js +267 -0
- package/package.json +55 -32
- package/templates/AGENTS.md +12 -50
- package/templates/QUICKSTART.md +16 -70
- package/templates/agents/AGENTS.md +58 -92
- package/templates/agents/DECISIONS.md +5 -21
- package/templates/agents/POLICIES.md +14 -0
- package/templates/agents/PROJECT.md +35 -145
- package/templates/agents/QUALITY.md +19 -0
- package/templates/agents/RULES.md +24 -132
- package/templates/agents/SETUP.md +38 -224
- package/templates/agents/config.yaml +13 -0
- package/templates/agents/current/_template.md +19 -0
- package/templates/agents/decisions/_template.md +22 -0
- package/templates/agents/prompts/conventional-commit.md +11 -51
- package/templates/agents/prompts/intake.md +23 -0
- package/templates/agents/prompts/pr-template.md +12 -21
- package/templates/agents/prompts/quality.md +57 -0
- package/templates/agents/prompts/rpi-close.md +23 -0
- package/templates/agents/prompts/rpi-implement.md +35 -68
- package/templates/agents/prompts/rpi-plan.md +87 -117
- package/templates/agents/prompts/rpi-research.md +21 -67
- package/templates/agents/prompts/rpi-validate.md +40 -103
- package/templates/agents/prompts/skill-call.md +11 -29
- package/templates/agents/prompts/task-create.md +13 -42
- package/templates/agents/skills/_template/SKILL.md +11 -37
- package/templates/agents/harness/claude-code/.hooks/guard-delete.sh +0 -22
- package/templates/agents/harness/claude-code/.hooks/guard-deps.sh +0 -25
- package/templates/agents/harness/claude-code/.hooks/guard-git.sh +0 -24
- package/templates/agents/harness/claude-code/commands/sdd-implement.md +0 -3
- package/templates/agents/harness/claude-code/commands/sdd-plan.md +0 -3
- package/templates/agents/harness/claude-code/commands/sdd-research.md +0 -3
- package/templates/agents/harness/claude-code/commands/sdd-validate.md +0 -3
- package/templates/agents/harness/claude-code/settings.json +0 -34
- package/templates/agents/harness/opencode/commands/sdd-implement.md +0 -3
- package/templates/agents/harness/opencode/commands/sdd-plan.md +0 -3
- package/templates/agents/harness/opencode/commands/sdd-research.md +0 -3
- package/templates/agents/harness/opencode/commands/sdd-validate.md +0 -3
- package/templates/agents/harness/opencode/opencode.json +0 -18
package/lib/install.js
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
const io = require('./io');
|
|
7
|
+
const md = require('./markdown');
|
|
8
|
+
const project = require('./project');
|
|
9
|
+
const { check } = require('./check');
|
|
10
|
+
|
|
11
|
+
const TEMPLATES = path.join(__dirname, '..', 'templates');
|
|
12
|
+
const VERSION = require('../package.json').version;
|
|
13
|
+
const LEGACY = require('./legacy-hashes.json');
|
|
14
|
+
const START = '<!-- sdd-flow:start -->';
|
|
15
|
+
const END = '<!-- sdd-flow:end -->';
|
|
16
|
+
|
|
17
|
+
function block(content) {
|
|
18
|
+
const start = content.indexOf(START);
|
|
19
|
+
const end = content.indexOf(END);
|
|
20
|
+
if (start < 0 && end < 0) return null;
|
|
21
|
+
if (start < 0 || end < start || content.indexOf(START, start + START.length) >= 0 || content.indexOf(END, end + END.length) >= 0) {
|
|
22
|
+
throw new Error('Malformed SDD managed block; restore its markers before updating');
|
|
23
|
+
}
|
|
24
|
+
return { start, end: end + END.length, content: content.slice(start, end + END.length) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function mergeEntry(existing, incoming) {
|
|
28
|
+
const replacement = block(incoming);
|
|
29
|
+
if (!replacement) throw new Error('Distributed entry point has no managed block');
|
|
30
|
+
const old = block(existing);
|
|
31
|
+
if (old) return existing.slice(0, old.start) + replacement.content + existing.slice(old.end);
|
|
32
|
+
return existing.trimEnd() + (existing.trim() ? '\n\n' : '') + replacement.content + '\n';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function install(root, { update = false, dryRun = false, replaceManaged = false } = {}) {
|
|
36
|
+
const stateFile = 'agents/.sdd/installed.json';
|
|
37
|
+
const state = io.exists(root, stateFile) ? io.json(root, stateFile) : { schema_version: 2, files: {} };
|
|
38
|
+
if (state.schema_version !== 2 || !state.files || typeof state.files !== 'object') throw new Error('Invalid installation inventory');
|
|
39
|
+
const userFiles = new Set(['agents/config.yaml', 'agents/PROJECT.md', 'agents/POLICIES.md', 'agents/QUALITY.md', 'agents/DECISIONS.md', 'agents/.gitignore']);
|
|
40
|
+
const plan = [];
|
|
41
|
+
const conflicts = [];
|
|
42
|
+
for (const relative of io.walk(TEMPLATES)) {
|
|
43
|
+
const incoming = io.read(TEMPLATES, relative);
|
|
44
|
+
const present = io.exists(root, relative);
|
|
45
|
+
const previous = present ? io.read(root, relative) : '';
|
|
46
|
+
let content = incoming;
|
|
47
|
+
let action = present ? 'unchanged' : 'create';
|
|
48
|
+
let managed = !userFiles.has(relative);
|
|
49
|
+
if (relative === 'agents/SETUP.md' && !present && (state.files[relative] || update)) {
|
|
50
|
+
action = 'preserve';
|
|
51
|
+
managed = false;
|
|
52
|
+
content = '';
|
|
53
|
+
} else if (!managed && present) {
|
|
54
|
+
action = 'preserve';
|
|
55
|
+
content = previous;
|
|
56
|
+
} else if (relative === 'AGENTS.md') {
|
|
57
|
+
const oldBlock = present ? block(previous) : null;
|
|
58
|
+
const oldHash = oldBlock ? io.hash(oldBlock.content) : io.hash(previous);
|
|
59
|
+
const expected = state.files[relative]?.hash;
|
|
60
|
+
const knownLegacy = present && io.hash(previous) === LEGACY[relative];
|
|
61
|
+
content = knownLegacy ? incoming : mergeEntry(previous, incoming);
|
|
62
|
+
if (present && expected && oldHash !== expected && previous !== content && !replaceManaged) {
|
|
63
|
+
action = 'conflict';
|
|
64
|
+
} else if (previous !== content) action = knownLegacy ? 'migrate-legacy' : present ? 'merge-entry' : 'create';
|
|
65
|
+
} else if (present && previous !== incoming && managed) {
|
|
66
|
+
const owned = state.files[relative]?.hash === io.hash(previous);
|
|
67
|
+
const legacy = LEGACY[relative] === io.hash(previous);
|
|
68
|
+
action = owned || legacy || replaceManaged ? 'update' : 'conflict';
|
|
69
|
+
}
|
|
70
|
+
if (action === 'conflict') conflicts.push(relative);
|
|
71
|
+
plan.push({ path: relative, action, content, previous, managed });
|
|
72
|
+
}
|
|
73
|
+
if (dryRun) return { version: VERSION, dry_run: true, conflicts, files: plan.map(({ path, action }) => ({ path, action })) };
|
|
74
|
+
if (conflicts.length) throw new Error('Customized/unowned workflow files were preserved. Review sdd update --dry-run; use --replace-managed only after review (backups are created):\n' + conflicts.join('\n'));
|
|
75
|
+
const backupId = new Date().toISOString().replace(/[:.]/g, '-') + '-' + crypto.randomUUID().slice(0, 8);
|
|
76
|
+
for (const item of plan) {
|
|
77
|
+
if (!['unchanged', 'preserve'].includes(item.action)) {
|
|
78
|
+
if (io.exists(root, item.path)) io.write(root, 'agents/.sdd/backups/' + backupId + '/' + item.path, item.previous);
|
|
79
|
+
io.write(root, item.path, item.content);
|
|
80
|
+
}
|
|
81
|
+
if (item.managed) {
|
|
82
|
+
state.files[item.path] = { hash: io.hash(item.path === 'AGENTS.md' ? block(item.content).content : item.content) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
for (const directory of ['agents/specs', 'agents/archive', 'agents/current', 'agents/decisions', 'agents/skills']) {
|
|
86
|
+
fs.mkdirSync(io.resolve(root, directory), { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
state.version = VERSION;
|
|
89
|
+
io.writeJson(root, stateFile, state);
|
|
90
|
+
return { version: VERSION, update, backup: 'agents/.sdd/backups/' + backupId, files: plan.map(({ path, action }) => ({ path, action })) };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function doctor(root) {
|
|
94
|
+
const errors = [];
|
|
95
|
+
const warnings = [];
|
|
96
|
+
const details = {};
|
|
97
|
+
try {
|
|
98
|
+
details.config = project.config(root);
|
|
99
|
+
for (const file of ['AGENTS.md', 'agents/AGENTS.md', 'agents/RULES.md', 'agents/PROJECT.md']) {
|
|
100
|
+
if (!io.exists(root, file)) errors.push('Missing ' + file);
|
|
101
|
+
}
|
|
102
|
+
if (io.exists(root, 'agents/PROJECT.md') && /\[FILL:|\[TODO:/.test(io.read(root, 'agents/PROJECT.md'))) errors.push('Complete agents/PROJECT.md setup');
|
|
103
|
+
if (io.exists(root, 'agents/SETUP.md')) warnings.push('SETUP.md remains available; remove it after completing project setup');
|
|
104
|
+
details.skills = project.skills(root);
|
|
105
|
+
const specs = project.specDirectories(root);
|
|
106
|
+
const identifiers = new Set();
|
|
107
|
+
details.specs = [];
|
|
108
|
+
for (const spec of specs) {
|
|
109
|
+
if (identifiers.has(spec.id)) errors.push('Duplicate active/archive spec ID: ' + spec.id);
|
|
110
|
+
identifiers.add(spec.id);
|
|
111
|
+
const loaded = project.loadSpec(root, spec.id);
|
|
112
|
+
if (loaded.legacy) warnings.push('Legacy spec requires migration: ' + spec.id);
|
|
113
|
+
else {
|
|
114
|
+
const result = check(root, spec.id);
|
|
115
|
+
details.specs.push({ id: spec.id, status: loaded.change.status, valid: result.valid });
|
|
116
|
+
if (!result.valid) warnings.push(spec.id + ': ' + result.errors.join('; '));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (io.exists(root, 'agents/.sdd/installed.json')) {
|
|
120
|
+
const state = io.json(root, 'agents/.sdd/installed.json');
|
|
121
|
+
for (const [file, record] of Object.entries(state.files)) {
|
|
122
|
+
if (file === 'agents/SETUP.md' && !io.exists(root, file)) continue;
|
|
123
|
+
if (!io.exists(root, file)) { errors.push('Managed file is missing: ' + file); continue; }
|
|
124
|
+
const source = io.read(root, file);
|
|
125
|
+
const content = file === 'AGENTS.md' ? block(source)?.content : source;
|
|
126
|
+
if (!content || io.hash(content) !== record.hash) warnings.push('Managed file has local edits: ' + file);
|
|
127
|
+
}
|
|
128
|
+
} else warnings.push('Installation inventory missing; use sdd update --dry-run');
|
|
129
|
+
if (io.exists(root, 'agents/.sdd/adapters.json')) {
|
|
130
|
+
const adapters = io.json(root, 'agents/.sdd/adapters.json');
|
|
131
|
+
for (const [name, files] of Object.entries(adapters)) {
|
|
132
|
+
for (const [file, record] of Object.entries(files)) {
|
|
133
|
+
if (!io.exists(root, file)) { errors.push(name + ': missing active adapter file ' + file); continue; }
|
|
134
|
+
const text = io.read(root, file);
|
|
135
|
+
const actual = record.block ? block(text)?.content : text;
|
|
136
|
+
if (!actual || io.hash(actual) !== record.hash) warnings.push(name + ': adapter file has local edits: ' + file);
|
|
137
|
+
const canonical = file.endsWith('/references/rules.md') ? 'agents/RULES.md'
|
|
138
|
+
: file.endsWith('/references/workflow.md') ? 'agents/AGENTS.md' : null;
|
|
139
|
+
if (canonical && io.hash(text) !== io.hash(io.read(root, canonical))) warnings.push(name + ': rerun sdd harness to refresh ' + file);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (io.exists(root, 'agents/harness')) warnings.push('Legacy harness templates remain. Review old active settings/hooks manually; v2 does not silently remove existing permission controls.');
|
|
144
|
+
} catch (error) { errors.push(error.message); }
|
|
145
|
+
return { valid: !errors.length, errors, warnings, details };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function migrate(root, id, { dryRun = false } = {}) {
|
|
149
|
+
const spec = project.loadSpec(root, id);
|
|
150
|
+
if (!spec.legacy) return { id: spec.id, migrated: false, reason: 'Already uses schema 2' };
|
|
151
|
+
const files = [];
|
|
152
|
+
for (const [name, artifact] of [['SPEC.md', 'spec'], ['TASK.md', 'tasks'], ['RESEARCH.md', 'research']]) {
|
|
153
|
+
const file = spec.relative + '/' + name;
|
|
154
|
+
if (!io.exists(root, file)) continue;
|
|
155
|
+
const original = io.read(root, file);
|
|
156
|
+
const document = md.parseMarkdown(original, file, false);
|
|
157
|
+
if (!document.legacy) continue;
|
|
158
|
+
const data = { schema_version: 2, artifact, id: spec.id, legacy: true };
|
|
159
|
+
if (artifact === 'spec') { data.requirements = []; data.acceptance = []; }
|
|
160
|
+
if (artifact === 'tasks') {
|
|
161
|
+
data.tasks = [...document.body.matchAll(/^- \[([ x-])\]\s+(T\d+)\s*[—–-]\s*(.+)$/gm)].map(match => ({
|
|
162
|
+
id: match[2], title: match[3], status: match[1] === 'x' ? 'done' : match[1] === '-' ? 'cancelled' : 'pending',
|
|
163
|
+
covers: [], depends_on: [], verify: '',
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
files.push({ path: file, previous: original, content: md.markdown(data, document.body) });
|
|
167
|
+
}
|
|
168
|
+
const change = { schema_version: 2, id: spec.id, title: spec.id.replace(/^\d+-/, ''), mode: 'standard', status: 'draft',
|
|
169
|
+
capabilities: [], decisions: [], skills: [], depends_on: [], context: [], sources: [], approval: null };
|
|
170
|
+
if (dryRun) return { id: spec.id, dry_run: true, files: files.map(f => f.path), review_required: true };
|
|
171
|
+
const backup = 'agents/.sdd/backups/migrate-' + crypto.randomUUID();
|
|
172
|
+
for (const file of files) {
|
|
173
|
+
io.write(root, backup + '/' + file.path, file.previous);
|
|
174
|
+
io.write(root, file.path, file.content);
|
|
175
|
+
}
|
|
176
|
+
project.writeChange(root, { ...spec, change });
|
|
177
|
+
return { id: spec.id, migrated: true, backup, review_required: true,
|
|
178
|
+
next: 'Preserved legacy bodies. Review requirements/acceptance/covers/verify, remove legacy: true after normalization, then run sdd check. No approval or test evidence was fabricated.' };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
module.exports = { TEMPLATES, VERSION, START, END, block, mergeEntry, install, doctor, migrate };
|
package/lib/io.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const crypto = require('node:crypto');
|
|
6
|
+
|
|
7
|
+
function hash(value) {
|
|
8
|
+
return crypto.createHash('sha256').update(value).digest('hex');
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function stable(value) {
|
|
12
|
+
if (Array.isArray(value)) return value.map(stable);
|
|
13
|
+
if (value && typeof value === 'object') {
|
|
14
|
+
return Object.fromEntries(Object.keys(value).sort().map(k => [k, stable(value[k])]));
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function digest(value) {
|
|
20
|
+
return hash(JSON.stringify(stable(value)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function resolve(root, relative) {
|
|
24
|
+
if (typeof relative !== 'string' || !relative || relative.includes('\0') ||
|
|
25
|
+
path.isAbsolute(relative) || /^[a-z]:/i.test(relative) || relative.includes('\\')) {
|
|
26
|
+
throw new Error('Expected a relative project path: ' + relative);
|
|
27
|
+
}
|
|
28
|
+
const parts = relative.split('/');
|
|
29
|
+
if (parts.some(p => p === '..' || p === '.git' || p === 'node_modules')) {
|
|
30
|
+
throw new Error('Path is outside the allowed project scope: ' + relative);
|
|
31
|
+
}
|
|
32
|
+
const base = path.resolve(root);
|
|
33
|
+
const target = path.resolve(base, relative);
|
|
34
|
+
if (target === base || !target.startsWith(base + path.sep)) throw new Error('Unsafe path: ' + relative);
|
|
35
|
+
let cursor = base;
|
|
36
|
+
for (const part of path.relative(base, target).split(path.sep)) {
|
|
37
|
+
cursor = path.join(cursor, part);
|
|
38
|
+
if (fs.existsSync(cursor) && fs.lstatSync(cursor).isSymbolicLink()) {
|
|
39
|
+
throw new Error('Symbolic links are not followed: ' + relative);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function exists(root, relative) {
|
|
46
|
+
return fs.existsSync(resolve(root, relative));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function read(root, relative) {
|
|
50
|
+
const file = resolve(root, relative);
|
|
51
|
+
if (!fs.statSync(file).isFile()) throw new Error('Expected a regular file: ' + relative);
|
|
52
|
+
if (fs.statSync(file).size > 2 * 1024 * 1024) throw new Error('File exceeds 2 MiB: ' + relative);
|
|
53
|
+
return fs.readFileSync(file, 'utf8');
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function write(root, relative, content, { exclusive = false } = {}) {
|
|
57
|
+
const file = resolve(root, relative);
|
|
58
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
59
|
+
if (exclusive) {
|
|
60
|
+
fs.writeFileSync(file, content, { flag: 'wx' });
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const temporary = file + '.sdd-' + crypto.randomUUID() + '.tmp';
|
|
64
|
+
try {
|
|
65
|
+
fs.writeFileSync(temporary, content, { flag: 'wx' });
|
|
66
|
+
fs.renameSync(temporary, file);
|
|
67
|
+
} finally {
|
|
68
|
+
if (fs.existsSync(temporary)) fs.unlinkSync(temporary);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function json(root, relative) {
|
|
73
|
+
return JSON.parse(read(root, relative));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function writeJson(root, relative, value, options) {
|
|
77
|
+
write(root, relative, JSON.stringify(value, null, 2) + '\n', options);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function walk(root, relative = '', skip = () => false) {
|
|
81
|
+
const directory = relative ? resolve(root, relative) : root;
|
|
82
|
+
if (!fs.existsSync(directory)) return [];
|
|
83
|
+
const files = [];
|
|
84
|
+
for (const item of fs.readdirSync(directory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
85
|
+
const rel = relative ? relative + '/' + item.name : item.name;
|
|
86
|
+
if (skip(rel, item)) continue;
|
|
87
|
+
if (item.isSymbolicLink()) throw new Error('Symbolic links are not followed: ' + rel);
|
|
88
|
+
if (item.isDirectory()) files.push(...walk(root, rel, skip));
|
|
89
|
+
else if (item.isFile()) files.push(rel);
|
|
90
|
+
if (files.length > 20000) throw new Error('Project scan exceeds 20,000 files; configure verification.exclude.');
|
|
91
|
+
}
|
|
92
|
+
return files;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function locked(root, action) {
|
|
96
|
+
const relative = 'agents/.sdd/lock';
|
|
97
|
+
const file = resolve(root, relative);
|
|
98
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
99
|
+
let descriptor;
|
|
100
|
+
try {
|
|
101
|
+
descriptor = fs.openSync(file, 'wx');
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error.code === 'EEXIST') throw new Error('Another SDD mutation holds agents/.sdd/lock. If interrupted, confirm no SDD process is running before removing it.');
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
fs.writeFileSync(descriptor, JSON.stringify({ pid: process.pid, started: new Date().toISOString() }));
|
|
107
|
+
const release = () => { fs.closeSync(descriptor); fs.unlinkSync(file); };
|
|
108
|
+
try {
|
|
109
|
+
const result = action();
|
|
110
|
+
if (result && typeof result.then === 'function') return result.finally(release);
|
|
111
|
+
release();
|
|
112
|
+
return result;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
release();
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = { hash, digest, stable, resolve, exists, read, write, json, writeJson, walk, locked };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"QUICKSTART.md": "a4e939542f765fc2e9b0692ec5cffc7fd0b793c7230ee4b2acd0b77148b0561c",
|
|
3
|
+
"AGENTS.md": "e81fdb84bb37d8b89dc89fe86da874dcd4b22fea7c47324d36468cbfe6a29a8b",
|
|
4
|
+
"agents/SETUP.md": "df27808ae8800651b08b6bc75910b7b362f3a40f6a724dd346f83bc6ce0d014d",
|
|
5
|
+
"agents/AGENTS.md": "8f6d098ab54edeb10e9d8c7e3f928005781086d09464a7630a5c691d7eef4c2f",
|
|
6
|
+
"agents/PROJECT.md": "e5c095a3e08d791abc96940d0337abd544a55ff5653019cda8a5759a68c6a155",
|
|
7
|
+
"agents/RULES.md": "d05bfa1b6123d72f9ac287d265ae49c00f6d1f14eda9969ba8986c82fbe94287",
|
|
8
|
+
"agents/DECISIONS.md": "14f7013b6d4a03c8298a2b96a4e68e0a081d9106a68cb84cdeba4ad29e68ee6b",
|
|
9
|
+
"agents/prompts/task-create.md": "8d89960122588f09ed9d2435e710b83f0d4720e69a213f34048849d13954130a",
|
|
10
|
+
"agents/prompts/skill-call.md": "ea5b76fd751f75d92c98c0fee62e5951229b41ce24dfd57754305d05f5f6a07a",
|
|
11
|
+
"agents/prompts/rpi-implement.md": "d4d0c17705d710130d8ef95493d9232d77a5413daf6f9c352a401e498f3f0894",
|
|
12
|
+
"agents/prompts/conventional-commit.md": "d92c21c1df44d00b76daf09191de442e6540b46ed0257d372a9fd7dfaabee98a",
|
|
13
|
+
"agents/prompts/rpi-validate.md": "e4898b16e04d26067741a4c5f5c2420a0b742fd174bd53b5d0e305af35de18f8",
|
|
14
|
+
"agents/prompts/rpi-research.md": "dbc4d2ca99fb7b8eb34846c27e5922088c24f031d07d3f0f7209fb68c5fca64f",
|
|
15
|
+
"agents/prompts/pr-template.md": "a8e7c0f7f7ffa3ee34bce29df6495187c1f4a90c0cc50790f035762a46de7d6c",
|
|
16
|
+
"agents/prompts/rpi-plan.md": "c3993157cf32cc05f35d14765c2d3b390011a63d9450102b4f75d5dfa66c4ec2",
|
|
17
|
+
"agents/harness/opencode/opencode.json": "8222b73042b45f9ee3e821700ea1576659b5188e2f45b7616010bda7a0202f11",
|
|
18
|
+
"agents/harness/claude-code/settings.json": "3b1cdf8e82c615a9b2e86d7c241be168aeb36d96258e6f4605b3a03b5cc08986",
|
|
19
|
+
"agents/harness/opencode/commands/sdd-research.md": "6e737ca418936b7ac29b8b1df3a66bb323b9542f44f271d3d30944d865532228",
|
|
20
|
+
"agents/harness/opencode/commands/sdd-plan.md": "90daff4a0816532bab5ce1a93f3e2dce8832a92f5fe5e18b2f84530404baa530",
|
|
21
|
+
"agents/harness/opencode/commands/sdd-implement.md": "f87f39f5b22687117c95dceee813b8e4508088945977702c0a8d73160ca19c8d",
|
|
22
|
+
"agents/harness/opencode/commands/sdd-validate.md": "0462aad9ce86356a8c47a2e9c5c03187d06732da8708695db3149d3eb565ea97",
|
|
23
|
+
"agents/harness/claude-code/.hooks/guard-git.sh": "cd7787b0e83e7400d2f1fa4d86c1abcfb527204a78ce263a66821498ecd335fe",
|
|
24
|
+
"agents/harness/claude-code/.hooks/guard-deps.sh": "f0ba202ab6d2f1b288336436bad2714254b271136dd6c4f961156a19ad702496",
|
|
25
|
+
"agents/harness/claude-code/.hooks/guard-delete.sh": "cf2d4b2cc6c16ed719417838ea67bbeaf2c8c7990d064528efe85afabcd671aa",
|
|
26
|
+
"agents/harness/claude-code/commands/sdd-research.md": "6e737ca418936b7ac29b8b1df3a66bb323b9542f44f271d3d30944d865532228",
|
|
27
|
+
"agents/harness/claude-code/commands/sdd-plan.md": "90daff4a0816532bab5ce1a93f3e2dce8832a92f5fe5e18b2f84530404baa530",
|
|
28
|
+
"agents/harness/claude-code/commands/sdd-implement.md": "f87f39f5b22687117c95dceee813b8e4508088945977702c0a8d73160ca19c8d",
|
|
29
|
+
"agents/harness/claude-code/commands/sdd-validate.md": "0462aad9ce86356a8c47a2e9c5c03187d06732da8708695db3149d3eb565ea97",
|
|
30
|
+
"agents/skills/_template/SKILL.md": "6045bb68ddcd19416317459d136f509b7c27b82139f93e5631e0bc93cc3ba965"
|
|
31
|
+
}
|
package/lib/markdown.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const YAML = require('yaml');
|
|
4
|
+
const io = require('./io');
|
|
5
|
+
|
|
6
|
+
function parseYaml(source, label = 'YAML') {
|
|
7
|
+
const document = YAML.parseDocument(source, { uniqueKeys: true, strict: true, schema: 'core' });
|
|
8
|
+
if (document.errors.length || document.warnings.length) {
|
|
9
|
+
throw new Error(label + ': ' + [...document.errors, ...document.warnings].map(e => e.message).join('; '));
|
|
10
|
+
}
|
|
11
|
+
let result;
|
|
12
|
+
try { result = document.toJS({ maxAliasCount: 0 }); }
|
|
13
|
+
catch (error) { throw new Error(label + ': ' + error.message); }
|
|
14
|
+
if (!result || typeof result !== 'object' || Array.isArray(result)) throw new Error(label + ': expected a mapping');
|
|
15
|
+
function inspect(value) {
|
|
16
|
+
if (!value || typeof value !== 'object') return;
|
|
17
|
+
for (const [key, child] of Object.entries(value)) {
|
|
18
|
+
if (['__proto__', 'constructor', 'prototype'].includes(key)) throw new Error(label + ': reserved key ' + key);
|
|
19
|
+
inspect(child);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
inspect(result);
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function parseMarkdown(source, label = 'Markdown', required = true) {
|
|
27
|
+
const normalized = source.replace(/^\uFEFF/, '').replace(/\r\n/g, '\n');
|
|
28
|
+
if (!normalized.startsWith('---\n')) {
|
|
29
|
+
if (required) throw new Error(label + ': missing YAML front matter; run sdd migrate for legacy specs');
|
|
30
|
+
return { data: {}, body: normalized, legacy: true };
|
|
31
|
+
}
|
|
32
|
+
let end = normalized.indexOf('\n---\n', 4);
|
|
33
|
+
if (end < 0 && normalized.endsWith('\n---')) end = normalized.length - 4;
|
|
34
|
+
if (end < 0) throw new Error(label + ': unclosed front matter');
|
|
35
|
+
if (end > 65536) throw new Error(label + ': front matter exceeds 64 KiB');
|
|
36
|
+
return { data: parseYaml(normalized.slice(4, end), label), body: normalized.slice(end + 5).replace(/^\n/, ''), legacy: false };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function markdown(data, body) {
|
|
40
|
+
return '---\n' + YAML.stringify(data, { lineWidth: 0, aliasDuplicateObjects: false }).trimEnd() + '\n---\n\n' + body.trim() + '\n';
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function load(root, relative, required = true) {
|
|
44
|
+
return parseMarkdown(io.read(root, relative), relative, required);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function section(body, heading, label) {
|
|
48
|
+
const lines = body.split('\n');
|
|
49
|
+
let start = -1;
|
|
50
|
+
let level = 0;
|
|
51
|
+
let fenced = false;
|
|
52
|
+
let fenceCharacter;
|
|
53
|
+
let fenceLength;
|
|
54
|
+
for (let index = 0; index < lines.length; index++) {
|
|
55
|
+
const fence = lines[index].match(/^\s*(`{3,}|~{3,})/);
|
|
56
|
+
if (fence) {
|
|
57
|
+
if (!fenced) { fenced = true; fenceCharacter = fence[1][0]; fenceLength = fence[1].length; }
|
|
58
|
+
else if (fence[1][0] === fenceCharacter && fence[1].length >= fenceLength) fenced = false;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (fenced) continue;
|
|
62
|
+
const match = lines[index].match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);
|
|
63
|
+
if (!match) continue;
|
|
64
|
+
if (start >= 0 && match[1].length <= level) return lines.slice(start, index).join('\n').trim();
|
|
65
|
+
if (match[2] === heading) { start = index; level = match[1].length; }
|
|
66
|
+
}
|
|
67
|
+
if (start < 0) throw new Error(label + ': heading not found: ' + heading);
|
|
68
|
+
return lines.slice(start).join('\n').trim();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
module.exports = { parseYaml, parseMarkdown, markdown, load, section };
|
package/lib/project.js
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const fs = require('node:fs');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const YAML = require('yaml');
|
|
6
|
+
const io = require('./io');
|
|
7
|
+
const md = require('./markdown');
|
|
8
|
+
const quality = require('./quality');
|
|
9
|
+
|
|
10
|
+
const MODES = ['light', 'standard', 'rigorous'];
|
|
11
|
+
const PHASES = ['research', 'plan', 'implement', 'validate', 'close'];
|
|
12
|
+
const CONFIG = 'agents/config.yaml';
|
|
13
|
+
|
|
14
|
+
function documentationSettings(cfg) {
|
|
15
|
+
const settings = cfg.documentation;
|
|
16
|
+
if (settings !== undefined && (!settings || typeof settings !== 'object' || Array.isArray(settings))) throw new Error('documentation must be a mapping');
|
|
17
|
+
const language = settings?.language ?? 'auto';
|
|
18
|
+
if (typeof language !== 'string' || !language.trim()) throw new Error('documentation.language must be auto or a language tag such as pt-BR');
|
|
19
|
+
try {
|
|
20
|
+
return { language: language === 'auto' ? language : Intl.getCanonicalLocales(language)[0], encoding: 'UTF-8' };
|
|
21
|
+
} catch {
|
|
22
|
+
throw new Error('documentation.language must be auto or a valid language tag such as pt-BR');
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function config(root) {
|
|
27
|
+
if (!io.exists(root, CONFIG)) throw new Error('Missing agents/config.yaml. Run sdd init, or sdd update for a v1 project.');
|
|
28
|
+
const value = md.parseYaml(io.read(root, CONFIG), CONFIG);
|
|
29
|
+
if (value.schema_version !== 2) throw new Error('Unsupported config schema_version; expected 2');
|
|
30
|
+
if (!MODES.includes(value.mode)) throw new Error('Invalid project mode');
|
|
31
|
+
if (!['batch', 'step'].includes(value.autonomy)) throw new Error('Invalid autonomy; expected batch or step');
|
|
32
|
+
if (!['required', 'optional'].includes(value.approval)) throw new Error('Invalid approval policy');
|
|
33
|
+
documentationSettings(value);
|
|
34
|
+
quality.settings(value);
|
|
35
|
+
if (!Number.isSafeInteger(value.context?.max_bytes) || value.context.max_bytes < 1024) throw new Error('context.max_bytes must be an integer >= 1024');
|
|
36
|
+
if (!Array.isArray(value.checks) || !Array.isArray(value.verification?.exclude)) throw new Error('checks and verification.exclude must be arrays');
|
|
37
|
+
const names = new Set();
|
|
38
|
+
for (const check of value.checks) {
|
|
39
|
+
if (!/^[a-z][a-z0-9-]*$/.test(check.name) || names.has(check.name)) throw new Error('Invalid or duplicate check name');
|
|
40
|
+
if (typeof check.command !== 'string' || !check.command.trim()) throw new Error('Check command must be a nonempty string');
|
|
41
|
+
if (!Number.isSafeInteger(check.timeout_ms) || check.timeout_ms < 1 || check.timeout_ms > 3600000) throw new Error('Check timeout_ms must be between 1 and 3600000');
|
|
42
|
+
names.add(check.name);
|
|
43
|
+
quality.checkSettings(check);
|
|
44
|
+
}
|
|
45
|
+
for (const exclude of value.verification.exclude) {
|
|
46
|
+
io.resolve(root, exclude);
|
|
47
|
+
if (exclude === 'agents' || exclude === 'src' || exclude === 'tests' || exclude === 'package.json') {
|
|
48
|
+
throw new Error('Do not exclude source or dependency manifests: ' + exclude);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function specDirectories(root) {
|
|
55
|
+
const result = [];
|
|
56
|
+
for (const parent of ['agents/specs', 'agents/archive']) {
|
|
57
|
+
if (!io.exists(root, parent)) continue;
|
|
58
|
+
for (const item of fs.readdirSync(io.resolve(root, parent), { withFileTypes: true })) {
|
|
59
|
+
if (!item.isDirectory() || !/^\d+-[a-z0-9]+(?:-[a-z0-9]+)*$/.test(item.name)) continue;
|
|
60
|
+
result.push({ id: item.name, relative: parent + '/' + item.name });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function locate(root, id) {
|
|
67
|
+
if (typeof id !== 'string' || !/^\d+(?:-[a-z0-9]+(?:-[a-z0-9]+)*)?$/.test(id)) throw new Error('Expected a spec ID such as 001-export');
|
|
68
|
+
const matches = specDirectories(root).filter(s => s.id === id || s.id.split('-')[0] === id);
|
|
69
|
+
if (matches.length !== 1) throw new Error(matches.length ? 'Ambiguous spec ID: ' + id : 'Spec not found: ' + id);
|
|
70
|
+
return matches[0];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function loadSpec(root, id) {
|
|
74
|
+
const location = locate(root, id);
|
|
75
|
+
const manifestPath = location.relative + '/change.yaml';
|
|
76
|
+
if (!io.exists(root, manifestPath)) return { ...location, legacy: true };
|
|
77
|
+
const change = md.parseYaml(io.read(root, manifestPath), manifestPath);
|
|
78
|
+
if (change.schema_version !== 2 || change.id !== location.id) throw new Error(manifestPath + ': invalid schema_version or id');
|
|
79
|
+
return { ...location, change, legacy: false };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function writeChange(root, spec) {
|
|
83
|
+
io.write(root, spec.relative + '/change.yaml', YAML.stringify(spec.change, { lineWidth: 0 }));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function skills(root) {
|
|
87
|
+
const records = [];
|
|
88
|
+
for (const file of io.walk(root, 'agents/skills', rel => rel.split('/').some(s => s.startsWith('_')))) {
|
|
89
|
+
if (!file.endsWith('/SKILL.md')) continue;
|
|
90
|
+
const { data } = md.load(root, file);
|
|
91
|
+
const expected = path.posix.basename(path.posix.dirname(file));
|
|
92
|
+
if (typeof data.name !== 'string' || !/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(data.name) || data.name.length > 64 || data.name !== expected) {
|
|
93
|
+
throw new Error(file + ': name must match its directory and Agent Skills naming rules');
|
|
94
|
+
}
|
|
95
|
+
if (typeof data.description !== 'string' || !data.description.trim() || data.description.length > 1024) throw new Error(file + ': description must contain 1–1024 characters');
|
|
96
|
+
if (records.some(s => s.name === data.name)) throw new Error('Duplicate skill name: ' + data.name);
|
|
97
|
+
records.push({ name: data.name, description: data.description, path: file });
|
|
98
|
+
}
|
|
99
|
+
return records;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function scopeDocument(root, spec) {
|
|
103
|
+
const change = spec.change;
|
|
104
|
+
const fields = ['schema_version', 'id', 'title', 'mode', 'capabilities', 'decisions', 'skills', 'depends_on', 'context', 'sources'];
|
|
105
|
+
const normative = Object.fromEntries(fields.map(k => [k, change[k] ?? null]));
|
|
106
|
+
const specification = md.load(root, spec.relative + '/SPEC.md');
|
|
107
|
+
let tasks = null;
|
|
108
|
+
if (io.exists(root, spec.relative + '/TASK.md')) {
|
|
109
|
+
const source = md.load(root, spec.relative + '/TASK.md');
|
|
110
|
+
tasks = {
|
|
111
|
+
body: source.body,
|
|
112
|
+
data: { ...source.data, tasks: (source.data.tasks || []).map(t => {
|
|
113
|
+
const { status, cancellation, evidence, deferral, ...plan } = t;
|
|
114
|
+
return plan;
|
|
115
|
+
}) },
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
const policy = config(root);
|
|
119
|
+
return { change: normative, specification, tasks, policy: {
|
|
120
|
+
approval: policy.approval, autonomy: policy.autonomy, checks: policy.checks, verification: policy.verification,
|
|
121
|
+
quality: quality.settings(policy),
|
|
122
|
+
project_policies: io.exists(root, 'agents/POLICIES.md') ? io.read(root, 'agents/POLICIES.md') : '',
|
|
123
|
+
project_quality: io.exists(root, 'agents/QUALITY.md') ? io.read(root, 'agents/QUALITY.md') : '',
|
|
124
|
+
} };
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function scopeDigest(root, spec) {
|
|
128
|
+
return io.digest(scopeDocument(root, spec));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function approvalValid(root, spec) {
|
|
132
|
+
return Boolean(spec.change.approval?.by && spec.change.approval?.at && spec.change.approval?.digest === scopeDigest(root, spec));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function sourceSnapshot(root) {
|
|
136
|
+
const cfg = config(root);
|
|
137
|
+
const excluded = ['.git', 'node_modules', 'agents', ...cfg.verification.exclude];
|
|
138
|
+
const files = io.walk(root, '', (rel, entry) => {
|
|
139
|
+
if (excluded.some(prefix => rel === prefix || rel.startsWith(prefix + '/'))) return true;
|
|
140
|
+
if (entry.isDirectory() && ['node_modules', '.git', '__pycache__', '.pytest_cache'].includes(entry.name)) return true;
|
|
141
|
+
return false;
|
|
142
|
+
});
|
|
143
|
+
return Object.fromEntries(files.map(file => [file, io.hash(fs.readFileSync(io.resolve(root, file)))]));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function inputDigest(root, spec) {
|
|
147
|
+
const references = [...spec.change.capabilities, ...spec.change.decisions,
|
|
148
|
+
...spec.change.sources.map(x => typeof x === 'string' ? x : x.path),
|
|
149
|
+
...spec.change.context.map(x => typeof x === 'string' ? x : x.path)];
|
|
150
|
+
for (const name of spec.change.skills) {
|
|
151
|
+
const found = skills(root).find(s => s.name === name);
|
|
152
|
+
if (!found) throw new Error('Unknown skill: ' + name);
|
|
153
|
+
references.push(...io.walk(root, path.posix.dirname(found.path)));
|
|
154
|
+
}
|
|
155
|
+
const docs = Object.fromEntries([...new Set(references)].sort().map(file => [file, io.hash(io.read(root, file))]));
|
|
156
|
+
const tasks = io.exists(root, spec.relative + '/TASK.md') ? md.load(root, spec.relative + '/TASK.md').data.tasks : [];
|
|
157
|
+
return { digest: io.digest({ scope: scopeDigest(root, spec), config: config(root), files: sourceSnapshot(root), docs, tasks }), docs };
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function createSpec(root, title, mode) {
|
|
161
|
+
const cfg = config(root);
|
|
162
|
+
mode = mode || cfg.mode;
|
|
163
|
+
if (!MODES.includes(mode)) throw new Error('Mode must be light, standard or rigorous');
|
|
164
|
+
if (typeof title !== 'string' || !title.trim()) throw new Error('Provide a feature name');
|
|
165
|
+
const name = title.normalize('NFKD').replace(/[\u0300-\u036f]/g, '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '');
|
|
166
|
+
if (!name || name.length > 96) throw new Error('Feature name must produce a slug of 1–96 characters');
|
|
167
|
+
const registryPath = 'agents/.sdd/registry.json';
|
|
168
|
+
const registry = io.exists(root, registryPath) ? io.json(root, registryPath) : { ids: [] };
|
|
169
|
+
if (!Array.isArray(registry.ids) || registry.ids.some(id => typeof id !== 'string' || !/^\d+-/.test(id))) throw new Error('Invalid SDD registry');
|
|
170
|
+
const all = [...registry.ids, ...specDirectories(root).map(s => s.id)];
|
|
171
|
+
const numbers = all.map(id => Number(id.split('-')[0]));
|
|
172
|
+
if (numbers.some(n => !Number.isSafeInteger(n) || n < 0)) throw new Error('Invalid spec number in registry');
|
|
173
|
+
const next = Math.max(0, ...numbers) + 1;
|
|
174
|
+
if (!Number.isSafeInteger(next)) throw new Error('Spec numbering exceeded the safe integer range');
|
|
175
|
+
const id = String(next).padStart(3, '0') + '-' + name;
|
|
176
|
+
const relative = 'agents/specs/' + id;
|
|
177
|
+
fs.mkdirSync(io.resolve(root, relative), { recursive: false });
|
|
178
|
+
registry.ids = [...new Set([...all, id])].sort();
|
|
179
|
+
io.writeJson(root, registryPath, registry);
|
|
180
|
+
const spec = { id, relative, change: {
|
|
181
|
+
schema_version: 2, id, title, mode, status: 'draft',
|
|
182
|
+
capabilities: [], decisions: [], skills: [], depends_on: [], context: [], sources: [], approval: null,
|
|
183
|
+
} };
|
|
184
|
+
writeChange(root, spec);
|
|
185
|
+
const portuguese = documentationSettings(cfg).language.toLowerCase().split('-')[0] === 'pt';
|
|
186
|
+
io.write(root, relative + '/SPEC.md', md.markdown({
|
|
187
|
+
schema_version: 2, artifact: 'spec', id, requirements: [], acceptance: [],
|
|
188
|
+
}, '# ' + title + (portuguese
|
|
189
|
+
? '\n\n## Objetivo\n\nDescreva o resultado observável.\n\n## Escopo\n\nIndique o que muda e o que fica fora desta alteração.'
|
|
190
|
+
: '\n\n## Goal\n\nDescribe the observable outcome.\n\n## Scope\n\nState what changes and what remains outside this change.')));
|
|
191
|
+
if (mode !== 'light') {
|
|
192
|
+
io.write(root, relative + '/TASK.md', md.markdown({ schema_version: 2, artifact: 'tasks', id, tasks: [] },
|
|
193
|
+
portuguese
|
|
194
|
+
? '# Tarefas\n\nMantenha o estado das tarefas no front matter. Planeje resultados coesos e verificáveis, incluindo os testes.'
|
|
195
|
+
: '# Tasks\n\nKeep task state in the front matter. Plan cohesive, independently verifiable outcomes, including their tests.'));
|
|
196
|
+
}
|
|
197
|
+
return spec;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
module.exports = { MODES, PHASES, CONFIG, documentationSettings, config, specDirectories, locate, loadSpec, writeChange, skills, scopeDocument, scopeDigest, approvalValid, sourceSnapshot, inputDigest, createSpec };
|
package/lib/quality.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function settings(cfg) {
|
|
4
|
+
const value = cfg.quality;
|
|
5
|
+
if (value !== undefined && (!value || typeof value !== 'object' || Array.isArray(value))) throw new Error('quality must be a mapping');
|
|
6
|
+
const tdd = value?.tdd ?? 'preferred';
|
|
7
|
+
if (!['optional', 'preferred', 'required'].includes(tdd)) throw new Error('quality.tdd must be optional, preferred or required');
|
|
8
|
+
return { tdd };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function checkSettings(definition) {
|
|
12
|
+
const level = definition.level ?? 'required';
|
|
13
|
+
const environment = definition.environment ?? 'local';
|
|
14
|
+
if (!['required', 'advisory'].includes(level)) throw new Error('Check level must be required or advisory: ' + definition.name);
|
|
15
|
+
if (!['local', 'external'].includes(environment)) throw new Error('Check environment must be local or external: ' + definition.name);
|
|
16
|
+
return { level, environment };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function externalCriterion(criterion, cfg) {
|
|
20
|
+
if (criterion.method !== 'automated') return criterion.environment === 'external';
|
|
21
|
+
return criterion.checks?.some(name => cfg.checks.some(def => def.name === name && checkSettings(def).environment === 'external'));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = { settings, checkSettings, externalCriterion };
|