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/bin/cli.js
CHANGED
|
@@ -1,437 +1,175 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
2
|
'use strict';
|
|
4
3
|
|
|
5
|
-
const fs
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
'
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
4
|
+
const fs = require('node:fs');
|
|
5
|
+
const { parseArgs } = require('node:util');
|
|
6
|
+
const io = require('../lib/io');
|
|
7
|
+
const project = require('../lib/project');
|
|
8
|
+
const validation = require('../lib/check');
|
|
9
|
+
const lifecycle = require('../lib/verification');
|
|
10
|
+
const installation = require('../lib/install');
|
|
11
|
+
const adapters = require('../lib/adapters');
|
|
12
|
+
|
|
13
|
+
const HELP = [
|
|
14
|
+
'sdd-flow ' + installation.VERSION + ' — portable, evidence-based spec-driven development',
|
|
15
|
+
'',
|
|
16
|
+
'sdd init [--mode light|standard|rigorous] [--harness claude-code|opencode] [--docs]',
|
|
17
|
+
'sdd docs [--types prd,roadmap,sd,ds,adr] [--dry-run]',
|
|
18
|
+
'sdd new <name> [--mode light|standard|rigorous]',
|
|
19
|
+
'sdd context <spec> [--phase implement] [--task T01] [--inspect] [--max-bytes N] [--json]',
|
|
20
|
+
'sdd skills list | show <name>',
|
|
21
|
+
'sdd check <spec> [--phase plan|implement|validate|close] [--final] [--json]',
|
|
22
|
+
'sdd approve <spec> --by <name>',
|
|
23
|
+
'sdd revise <spec> --by <name> --reason <reason> [--dry-run]',
|
|
24
|
+
'sdd evidence <spec> [--out path.json]',
|
|
25
|
+
'sdd handoff <spec>',
|
|
26
|
+
'sdd verify <spec> [--scope full|partial] [--evidence path.json] [--handoff path.json] [--run-external]',
|
|
27
|
+
'sdd close <spec> --by <name> [--note reason] [--archive]',
|
|
28
|
+
'sdd reopen <spec> --by <name> --reason <reason>',
|
|
29
|
+
'sdd cancel <spec> --by <name> --reason <reason>',
|
|
30
|
+
'sdd status [<spec>] [--json]',
|
|
31
|
+
'sdd doctor [--json]',
|
|
32
|
+
'sdd update [--dry-run] [--replace-managed]',
|
|
33
|
+
'sdd migrate <spec> [--dry-run]',
|
|
34
|
+
'sdd harness <claude-code|opencode> [--remove] [--dry-run]',
|
|
35
|
+
'sdd export <claude-code|opencode|agent-skills> --out <new-directory>',
|
|
36
|
+
'',
|
|
37
|
+
'All commands accept --json. Paths are relative to the project root.',
|
|
38
|
+
'Verification commands run with your account permissions. Use isolated test environments.',
|
|
39
|
+
'Approval records user authorization; it does not grant tool permissions.',
|
|
40
|
+
].join('\n');
|
|
41
|
+
|
|
42
|
+
const OPTIONS = {
|
|
43
|
+
json: { type: 'boolean' }, help: { type: 'boolean', short: 'h' }, version: { type: 'boolean', short: 'v' },
|
|
44
|
+
mode: { type: 'string' }, harness: { type: 'string' }, phase: { type: 'string' }, task: { type: 'string' },
|
|
45
|
+
'max-bytes': { type: 'string' }, final: { type: 'boolean' }, by: { type: 'string' },
|
|
46
|
+
out: { type: 'string' }, scope: { type: 'string' }, evidence: { type: 'string' },
|
|
47
|
+
note: { type: 'string' }, archive: { type: 'boolean' }, reason: { type: 'string' },
|
|
48
|
+
'dry-run': { type: 'boolean' }, 'replace-managed': { type: 'boolean' }, remove: { type: 'boolean' },
|
|
49
|
+
inspect: { type: 'boolean' },
|
|
50
|
+
handoff: { type: 'string' }, 'run-external': { type: 'boolean' },
|
|
51
|
+
docs: { type: 'boolean' }, types: { type: 'string' },
|
|
52
|
+
};
|
|
53
|
+
const ALLOWED = {
|
|
54
|
+
init: ['mode', 'harness', 'docs'], docs: ['types', 'dry-run'], new: ['mode'], context: ['phase', 'task', 'max-bytes', 'inspect'],
|
|
55
|
+
skills: [], check: ['phase', 'final'], approve: ['by'], evidence: ['out'], handoff: [], verify: ['scope', 'evidence', 'handoff', 'run-external'],
|
|
56
|
+
close: ['by', 'note', 'archive'], reopen: ['by', 'reason'], cancel: ['by', 'reason'],
|
|
57
|
+
status: [], doctor: [], update: ['dry-run', 'replace-managed'], migrate: ['dry-run'],
|
|
58
|
+
harness: ['remove', 'dry-run'], export: ['out'],
|
|
59
|
+
revise: ['by', 'reason', 'dry-run'],
|
|
58
60
|
};
|
|
59
61
|
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
fs.mkdirSync(path.dirname(excludePath), { recursive: true });
|
|
94
|
-
fs.writeFileSync(excludePath, content + '\n', 'utf8');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function init() {
|
|
98
|
-
log();
|
|
99
|
-
log(bold('sdd-cli') + dim(' — Spec Driven Development workflow'));
|
|
100
|
-
log();
|
|
101
|
-
|
|
102
|
-
const agentsDir = path.join(CWD, 'agents');
|
|
103
|
-
if (fs.existsSync(agentsDir)) {
|
|
104
|
-
warn('A pasta agents/ já existe neste projeto.');
|
|
105
|
-
const answer = await ask(' Deseja sobrescrever os arquivos do workflow? (s/N) ');
|
|
106
|
-
if (answer.toLowerCase() !== 's') {
|
|
107
|
-
info('Operação cancelada. Use ' + bold('sdd update') + ' para atualizar prompts e regras.');
|
|
108
|
-
log();
|
|
109
|
-
process.exit(0);
|
|
110
|
-
}
|
|
111
|
-
log();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
copy(path.join(TEMPLATES, 'AGENTS.md'), path.join(CWD, 'AGENTS.md'));
|
|
115
|
-
ok('AGENTS.md criado na raiz do projeto');
|
|
116
|
-
|
|
117
|
-
copy(path.join(TEMPLATES, 'QUICKSTART.md'), path.join(CWD, 'QUICKSTART.md'));
|
|
118
|
-
ok('QUICKSTART.md criado na raiz do projeto');
|
|
119
|
-
|
|
120
|
-
copyDir(path.join(TEMPLATES, 'agents'), agentsDir, ['harness']);
|
|
121
|
-
ok('Workflow instalado em agents/');
|
|
122
|
-
|
|
123
|
-
log();
|
|
124
|
-
info('O harness instala hooks de segurança e slash commands ' + dim('(opcional)'));
|
|
125
|
-
log(' 1) Pular esta etapa');
|
|
126
|
-
log(' 2) Claude Code');
|
|
127
|
-
log(' 3) OpenCode');
|
|
128
|
-
const choice = await ask(' Escolha [1]: ');
|
|
129
|
-
|
|
130
|
-
const harnessCfg = HARNESS_CONFIG[choice];
|
|
131
|
-
let harnessInstalled = false;
|
|
132
|
-
|
|
133
|
-
if (harnessCfg) {
|
|
134
|
-
const { name, commandsDest } = harnessCfg;
|
|
135
|
-
const harnessSrc = path.join(TEMPLATES, 'agents', 'harness', name);
|
|
136
|
-
|
|
137
|
-
if (fs.existsSync(harnessSrc)) {
|
|
138
|
-
copyDir(harnessSrc, path.join(agentsDir, 'harness', name), ['commands']);
|
|
139
|
-
ok(`Harness instalado: ${name}`);
|
|
140
|
-
|
|
141
|
-
const cmdSrc = path.join(harnessSrc, 'commands');
|
|
142
|
-
if (fs.existsSync(cmdSrc)) {
|
|
143
|
-
copyDir(cmdSrc, commandsDest);
|
|
144
|
-
ok(`Slash commands instalados em ${path.relative(CWD, commandsDest)}/`);
|
|
62
|
+
async function main(argv = process.argv.slice(2), root = process.cwd()) {
|
|
63
|
+
const { values, positionals } = parseArgs({ args: argv, options: OPTIONS, allowPositionals: true, strict: true });
|
|
64
|
+
if (values.version) { console.log(installation.VERSION); return 0; }
|
|
65
|
+
const [command = 'help', first, second] = positionals;
|
|
66
|
+
if (values.help || command === 'help') { console.log(HELP); return 0; }
|
|
67
|
+
if (!ALLOWED[command]) throw new Error('Unknown command: ' + command + '\nRun sdd help');
|
|
68
|
+
for (const key of Object.keys(values)) {
|
|
69
|
+
if (key !== 'json' && !ALLOWED[command].includes(key)) throw new Error('--' + key + ' is not supported by ' + command);
|
|
70
|
+
}
|
|
71
|
+
const maximum = command === 'skills' ? 3 : ['init', 'doctor', 'update', 'docs'].includes(command) ? 1 : 2;
|
|
72
|
+
if (positionals.length > maximum) throw new Error('Unexpected positional arguments');
|
|
73
|
+
const mutating = new Set(['init', 'docs', 'new', 'approve', 'revise', 'evidence', 'handoff', 'verify', 'close', 'reopen', 'cancel', 'update', 'migrate', 'harness', 'export']);
|
|
74
|
+
async function action() {
|
|
75
|
+
switch (command) {
|
|
76
|
+
case 'init': {
|
|
77
|
+
if (values.mode && !project.MODES.includes(values.mode)) throw new Error('Mode must be light, standard or rigorous');
|
|
78
|
+
if (values.harness && !adapters.NAMES.includes(values.harness)) throw new Error('Unsupported adapter');
|
|
79
|
+
if (values.docs) require('../lib/documents').scaffold(root, { dryRun: true });
|
|
80
|
+
const existed = io.exists(root, 'agents/config.yaml');
|
|
81
|
+
const result = installation.install(root);
|
|
82
|
+
if (values.mode && !existed) {
|
|
83
|
+
const YAML = require('yaml');
|
|
84
|
+
const cfg = project.config(root);
|
|
85
|
+
cfg.mode = values.mode;
|
|
86
|
+
io.write(root, 'agents/config.yaml', YAML.stringify(cfg));
|
|
87
|
+
}
|
|
88
|
+
if (values.harness) result.adapter = adapters.harness(root, values.harness);
|
|
89
|
+
if (values.docs) result.documents = require('../lib/documents').scaffold(root);
|
|
90
|
+
result.next = existed
|
|
91
|
+
? 'Existing project configuration was preserved. Run sdd doctor and review any reported maintenance needs; no new setup is required.'
|
|
92
|
+
: 'Complete agents/PROJECT.md, documentation language and checks in agents/config.yaml using agents/SETUP.md; then run sdd doctor.';
|
|
93
|
+
return result;
|
|
145
94
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (wantsDocs) {
|
|
160
|
-
const docsDir = path.join(CWD, 'docs');
|
|
161
|
-
if (fs.existsSync(docsDir)) {
|
|
162
|
-
info('docs/ já existe — preservado');
|
|
163
|
-
} else {
|
|
164
|
-
fs.mkdirSync(docsDir, { recursive: true });
|
|
165
|
-
for (const [name, header] of [['prd.md', '# PRD'], ['roadmap.md', '# Roadmap'], ['architecture.md', '# Architecture']]) {
|
|
166
|
-
fs.writeFileSync(path.join(docsDir, name), header + '\n', 'utf8');
|
|
95
|
+
case 'docs': return require('../lib/documents').scaffold(root, { types: values.types, dryRun: values['dry-run'] });
|
|
96
|
+
case 'new': return project.createSpec(root, first, values.mode);
|
|
97
|
+
case 'context': return require('../lib/context').context(root, first, { phase: values.phase, task: values.task, maxBytes: values['max-bytes'] ? Number(values['max-bytes']) : undefined, inspect: values.inspect });
|
|
98
|
+
case 'skills': {
|
|
99
|
+
const catalog = project.skills(root);
|
|
100
|
+
if (first === 'list') return catalog;
|
|
101
|
+
if (first === 'show' && second) {
|
|
102
|
+
const found = catalog.find(item => item.name === second);
|
|
103
|
+
if (!found) throw new Error('Unknown skill: ' + second);
|
|
104
|
+
return { ...found, content: io.read(root, found.path) };
|
|
105
|
+
}
|
|
106
|
+
throw new Error('Use sdd skills list or sdd skills show <name>');
|
|
167
107
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
log(dim(' Documentação: https://github.com/moisesuailab/spec-driven-workflow'));
|
|
207
|
-
log();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async function harness() {
|
|
211
|
-
log();
|
|
212
|
-
log(bold('sdd harness'));
|
|
213
|
-
log();
|
|
214
|
-
|
|
215
|
-
const agentsDir = path.join(CWD, 'agents');
|
|
216
|
-
if (!fs.existsSync(agentsDir)) {
|
|
217
|
-
error('Pasta agents/ não encontrada. Rode ' + bold('sdd init') + ' primeiro.');
|
|
218
|
-
log();
|
|
219
|
-
process.exit(1);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
info('O que deseja fazer?');
|
|
223
|
-
log(' 1) Remover harness atual');
|
|
224
|
-
log(' 2) Instalar / trocar para Claude Code');
|
|
225
|
-
log(' 3) Instalar / trocar para OpenCode');
|
|
226
|
-
const choice = await ask(' Escolha: ');
|
|
227
|
-
|
|
228
|
-
if (choice === '1') {
|
|
229
|
-
const harnessDir = path.join(agentsDir, 'harness');
|
|
230
|
-
if (fs.existsSync(harnessDir)) {
|
|
231
|
-
fs.rmSync(harnessDir, { recursive: true });
|
|
232
|
-
ok('Hooks removidos de agents/harness/');
|
|
233
|
-
}
|
|
234
|
-
for (const cfg of Object.values(HARNESS_CONFIG)) {
|
|
235
|
-
removeSddCommands(cfg.commandsDest);
|
|
236
|
-
if (fs.existsSync(cfg.commandsDest)) {
|
|
237
|
-
ok(`Slash commands removidos de ${path.relative(CWD, cfg.commandsDest)}/`);
|
|
108
|
+
case 'check': {
|
|
109
|
+
const result = validation.check(root, first, { phase: values.phase, final: values.final });
|
|
110
|
+
return { valid: result.valid, errors: result.errors, warnings: result.warnings };
|
|
111
|
+
}
|
|
112
|
+
case 'approve': return validation.approve(root, first, values.by);
|
|
113
|
+
case 'revise': return require('../lib/revisions').revise(root, first, { by: values.by, reason: values.reason, dryRun: values['dry-run'] });
|
|
114
|
+
case 'evidence': return lifecycle.evidenceTemplate(root, first, values.out);
|
|
115
|
+
case 'handoff': return require('../lib/handoff').template(root, first);
|
|
116
|
+
case 'verify': return lifecycle.verify(root, first, { scope: values.scope, evidence: values.evidence, handoff: values.handoff, runExternal: values['run-external'] });
|
|
117
|
+
case 'close': return lifecycle.close(root, first, { by: values.by, note: values.note, archive: values.archive });
|
|
118
|
+
case 'reopen':
|
|
119
|
+
case 'cancel': {
|
|
120
|
+
if (!values.by?.trim() || !values.reason?.trim()) throw new Error('Provide --by and --reason');
|
|
121
|
+
const spec = project.loadSpec(root, first);
|
|
122
|
+
if (spec.legacy) throw new Error('Migrate the spec before changing its lifecycle');
|
|
123
|
+
if (command === 'reopen') {
|
|
124
|
+
if (!['closed', 'cancelled'].includes(spec.change.status)) throw new Error('Only closed/cancelled changes can be reopened');
|
|
125
|
+
const target = 'agents/specs/' + spec.id;
|
|
126
|
+
if (spec.relative !== target) {
|
|
127
|
+
if (io.exists(root, target)) throw new Error('Active spec destination exists');
|
|
128
|
+
fs.renameSync(io.resolve(root, spec.relative), io.resolve(root, target));
|
|
129
|
+
spec.relative = target;
|
|
130
|
+
}
|
|
131
|
+
const receipt = spec.relative + '/verification.json';
|
|
132
|
+
if (io.exists(root, receipt)) {
|
|
133
|
+
fs.mkdirSync(io.resolve(root, spec.relative + '/runs'), { recursive: true });
|
|
134
|
+
fs.renameSync(io.resolve(root, receipt), io.resolve(root, spec.relative + '/runs/reopened-' + Date.now() + '.json'));
|
|
135
|
+
}
|
|
136
|
+
spec.change.status = 'implementing';
|
|
137
|
+
spec.change.reopened = { by: values.by, reason: values.reason, at: new Date().toISOString() };
|
|
138
|
+
} else {
|
|
139
|
+
if (spec.change.status === 'closed') throw new Error('Reopen a closed change before cancelling it');
|
|
140
|
+
spec.change.status = 'cancelled';
|
|
141
|
+
spec.change.cancellation = { by: values.by, reason: values.reason, at: new Date().toISOString() };
|
|
142
|
+
}
|
|
143
|
+
require('../lib/history').record(root, spec, command, { by: values.by, reason: values.reason, status: spec.change.status });
|
|
144
|
+
project.writeChange(root, spec);
|
|
145
|
+
return { id: spec.id, status: spec.change.status };
|
|
238
146
|
}
|
|
147
|
+
case 'status': return (first ? [project.locate(root, first)] : project.specDirectories(root)).map(item => {
|
|
148
|
+
const spec = project.loadSpec(root, item.id);
|
|
149
|
+
return { id: spec.id, path: spec.relative, status: spec.legacy ? 'legacy' : spec.change.status,
|
|
150
|
+
approval: spec.legacy ? 'legacy' : project.approvalValid(root, spec) ? 'current' : 'missing-or-stale',
|
|
151
|
+
closure: spec.change?.closure || null };
|
|
152
|
+
});
|
|
153
|
+
case 'doctor': return installation.doctor(root);
|
|
154
|
+
case 'update': return installation.install(root, { update: true, dryRun: values['dry-run'], replaceManaged: values['replace-managed'] });
|
|
155
|
+
case 'migrate': return installation.migrate(root, first, { dryRun: values['dry-run'] });
|
|
156
|
+
case 'harness': return adapters.harness(root, first, { remove: values.remove, dryRun: values['dry-run'] });
|
|
157
|
+
case 'export': return adapters.exportBundle(root, first, values.out);
|
|
239
158
|
}
|
|
240
|
-
log();
|
|
241
|
-
ok('Harness desinstalado.');
|
|
242
|
-
log();
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
const harnessCfg = HARNESS_CONFIG[choice];
|
|
247
|
-
if (!harnessCfg) {
|
|
248
|
-
info('Operação cancelada.');
|
|
249
|
-
log();
|
|
250
|
-
process.exit(0);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
const { name, commandsDest } = harnessCfg;
|
|
254
|
-
const harnessSrc = path.join(TEMPLATES, 'agents', 'harness', name);
|
|
255
|
-
|
|
256
|
-
if (!fs.existsSync(harnessSrc)) {
|
|
257
|
-
error(`Harness "${name}" não encontrado nos templates.`);
|
|
258
|
-
process.exit(1);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
for (const cfg of Object.values(HARNESS_CONFIG)) {
|
|
262
|
-
removeSddCommands(cfg.commandsDest);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
copyDir(harnessSrc, path.join(agentsDir, 'harness', name), ['commands']);
|
|
266
|
-
ok(`Harness instalado: ${name}`);
|
|
267
|
-
|
|
268
|
-
const cmdSrc = path.join(harnessSrc, 'commands');
|
|
269
|
-
if (fs.existsSync(cmdSrc)) {
|
|
270
|
-
copyDir(cmdSrc, commandsDest);
|
|
271
|
-
ok(`Slash commands instalados em ${path.relative(CWD, commandsDest)}/`);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
log();
|
|
275
|
-
showSlashCommands();
|
|
276
|
-
log();
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
async function update() {
|
|
280
|
-
log();
|
|
281
|
-
log(bold('sdd update'));
|
|
282
|
-
log();
|
|
283
|
-
|
|
284
|
-
const agentsDir = path.join(CWD, 'agents');
|
|
285
|
-
if (!fs.existsSync(agentsDir)) {
|
|
286
|
-
error('Pasta agents/ não encontrada. Rode ' + bold('sdd init') + ' primeiro.');
|
|
287
|
-
log();
|
|
288
|
-
process.exit(1);
|
|
289
159
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
if (
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
process.exit(0);
|
|
297
|
-
}
|
|
298
|
-
log();
|
|
299
|
-
|
|
300
|
-
const coreFiles = [
|
|
301
|
-
{ rel: ['AGENTS.md'], dest: path.join(CWD, 'AGENTS.md') },
|
|
302
|
-
{ rel: ['QUICKSTART.md'], dest: path.join(CWD, 'QUICKSTART.md') },
|
|
303
|
-
{ rel: ['agents', 'AGENTS.md'], dest: path.join(agentsDir, 'AGENTS.md') },
|
|
304
|
-
{ rel: ['agents', 'RULES.md'], dest: path.join(agentsDir, 'RULES.md') },
|
|
305
|
-
];
|
|
306
|
-
|
|
307
|
-
for (const { rel, dest } of coreFiles) {
|
|
308
|
-
copy(path.join(TEMPLATES, ...rel), dest);
|
|
309
|
-
ok(`Atualizado: ${rel.join('/')}`);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
copyDir(
|
|
313
|
-
path.join(TEMPLATES, 'agents', 'prompts'),
|
|
314
|
-
path.join(agentsDir, 'prompts')
|
|
315
|
-
);
|
|
316
|
-
ok('Atualizado: agents/prompts/');
|
|
317
|
-
|
|
318
|
-
log();
|
|
319
|
-
info('Preservados (dados do projeto):');
|
|
320
|
-
['agents/PROJECT.md', 'agents/DECISIONS.md', 'agents/skills/', 'agents/specs/', 'agents/harness/']
|
|
321
|
-
.forEach(f => log(` ${dim(f)}`));
|
|
322
|
-
log();
|
|
323
|
-
ok('Workflow atualizado com sucesso.');
|
|
324
|
-
log();
|
|
160
|
+
const result = await (mutating.has(command) && !values['dry-run'] ? io.locked(root, action) : action());
|
|
161
|
+
if (!values.json && typeof result.content === 'string') console.log(result.content);
|
|
162
|
+
else console.log(JSON.stringify(result, null, 2));
|
|
163
|
+
if (result.valid === false || result.verdict === 'failed' || result.conflicts?.length) return 1;
|
|
164
|
+
if (result.verdict === 'partial') return 2;
|
|
165
|
+
return 0;
|
|
325
166
|
}
|
|
326
167
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
.
|
|
331
|
-
.
|
|
332
|
-
|
|
333
|
-
const max = entries.length ? Math.max(...entries) : 0;
|
|
334
|
-
return String(max + 1).padStart(3, '0');
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
function newSpec(rawName) {
|
|
338
|
-
log();
|
|
339
|
-
log(bold('sdd new'));
|
|
340
|
-
log();
|
|
341
|
-
|
|
342
|
-
const agentsDir = path.join(CWD, 'agents');
|
|
343
|
-
if (!fs.existsSync(agentsDir)) {
|
|
344
|
-
error('Pasta agents/ não encontrada. Rode ' + bold('sdd init') + ' primeiro.');
|
|
345
|
-
log();
|
|
346
|
-
process.exit(1);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (!rawName) {
|
|
350
|
-
error('Informe o nome da feature: ' + bold('sdd new <nome-da-feature>'));
|
|
351
|
-
log(' Exemplo: ' + dim('sdd new user-authentication'));
|
|
352
|
-
log();
|
|
353
|
-
process.exit(1);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const name = rawName.toLowerCase().trim().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
|
|
357
|
-
if (!name) {
|
|
358
|
-
error('Nome inválido. Use apenas letras, números e hífens.');
|
|
359
|
-
log();
|
|
360
|
-
process.exit(1);
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const specsDir = path.join(agentsDir, 'specs');
|
|
364
|
-
const num = nextSpecNumber(specsDir);
|
|
365
|
-
const slug = num + '-' + name;
|
|
366
|
-
const specDir = path.join(specsDir, slug);
|
|
367
|
-
|
|
368
|
-
if (fs.existsSync(specDir)) {
|
|
369
|
-
error('Spec já existe: agents/specs/' + slug + '/');
|
|
370
|
-
log();
|
|
371
|
-
process.exit(1);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
fs.mkdirSync(specDir, { recursive: true });
|
|
375
|
-
fs.writeFileSync(
|
|
376
|
-
path.join(specDir, 'DECISIONS.md'),
|
|
377
|
-
'# DECISIONS — ' + name + '\n\n(decisões arquiteturais registradas durante o ciclo)\n'
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
ok('Spec criada: agents/specs/' + slug + '/');
|
|
381
|
-
log();
|
|
382
|
-
log(bold('Próximo passo — inicie a fase de Research:'));
|
|
383
|
-
log(' ' + c.cyan + '/sdd-research' + c.reset + ' ' + slug);
|
|
384
|
-
log(' ' + dim('"Leia e siga agents/prompts/rpi-research.md. Spec: ' + slug + '"'));
|
|
385
|
-
log();
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
function help() {
|
|
389
|
-
log();
|
|
390
|
-
log(bold('sdd-cli') + dim(' — Spec Driven Development workflow'));
|
|
391
|
-
log();
|
|
392
|
-
log('Uso:');
|
|
393
|
-
log(` sdd-cli ${c.cyan}init${c.reset} Instala o workflow no projeto atual`);
|
|
394
|
-
log(` sdd-cli ${c.cyan}new <nome>${c.reset} Cria pasta da spec com numeração automática`);
|
|
395
|
-
log(` sdd-cli ${c.cyan}harness${c.reset} Instala, troca ou remove o harness do agente`);
|
|
396
|
-
log(` sdd-cli ${c.cyan}update${c.reset} Atualiza prompts e regras, preserva dados do projeto`);
|
|
397
|
-
log(` sdd-cli ${c.cyan}help${c.reset} Exibe esta mensagem`);
|
|
398
|
-
log(` sdd-cli ${c.cyan}--version${c.reset} Exibe a versão instalada`);
|
|
399
|
-
log();
|
|
400
|
-
log(dim(' Alias: sdd init / sdd new / sdd harness / sdd update / sdd help / sdd --version'));
|
|
401
|
-
log();
|
|
402
|
-
log(dim(' Documentação: https://github.com/moisesuailab/spec-driven-workflow'));
|
|
403
|
-
log();
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
const cmd = process.argv[2];
|
|
407
|
-
|
|
408
|
-
switch (cmd) {
|
|
409
|
-
case 'init':
|
|
410
|
-
init().catch(e => { error(e.message); process.exit(1); });
|
|
411
|
-
break;
|
|
412
|
-
case 'new':
|
|
413
|
-
newSpec(process.argv[3]);
|
|
414
|
-
break;
|
|
415
|
-
case 'harness':
|
|
416
|
-
harness().catch(e => { error(e.message); process.exit(1); });
|
|
417
|
-
break;
|
|
418
|
-
case 'update':
|
|
419
|
-
update().catch(e => { error(e.message); process.exit(1); });
|
|
420
|
-
break;
|
|
421
|
-
case 'help':
|
|
422
|
-
case '--help':
|
|
423
|
-
case '-h':
|
|
424
|
-
help();
|
|
425
|
-
break;
|
|
426
|
-
case '--version':
|
|
427
|
-
case '-v':
|
|
428
|
-
log(VERSION);
|
|
429
|
-
break;
|
|
430
|
-
case undefined:
|
|
431
|
-
help();
|
|
432
|
-
break;
|
|
433
|
-
default:
|
|
434
|
-
error(`Comando desconhecido: "${cmd}"`);
|
|
435
|
-
help();
|
|
436
|
-
process.exit(1);
|
|
168
|
+
if (require.main === module) {
|
|
169
|
+
main().then(code => { process.exitCode = code; }).catch(error => {
|
|
170
|
+
if (process.argv.includes('--json')) console.log(JSON.stringify({ error: error.message, ...(error.code && { code: error.code }), ...(error.diagnostics && { diagnostics: error.diagnostics }) }));
|
|
171
|
+
else console.error('SDD: ' + error.message);
|
|
172
|
+
process.exitCode = 1;
|
|
173
|
+
});
|
|
437
174
|
}
|
|
175
|
+
module.exports = { main, HELP };
|