forjajs 1.2.0 → 1.3.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/.claude/settings.json +7 -7
- package/CHANGELOG.md +41 -0
- package/README.en.md +5 -0
- package/README.md +5 -0
- package/dist/bin/create-memory-nest-kit.d.ts +2 -0
- package/dist/bin/create-memory-nest-kit.js +110 -0
- package/dist/bin/forja.d.ts +13 -0
- package/dist/bin/forja.js +136 -0
- package/dist/bin/init-project.d.ts +2 -0
- package/dist/bin/init-project.js +516 -0
- package/dist/lib/audit.d.ts +67 -0
- package/dist/lib/audit.js +143 -0
- package/dist/lib/context-builder.d.ts +58 -0
- package/dist/lib/context-builder.js +233 -0
- package/dist/lib/core/checks.d.ts +91 -0
- package/dist/lib/core/checks.js +119 -0
- package/dist/lib/core/doc-graph.d.ts +60 -0
- package/dist/lib/core/doc-graph.js +235 -0
- package/dist/lib/core/health.d.ts +103 -0
- package/dist/lib/core/health.js +538 -0
- package/dist/lib/core/registry.d.ts +296 -0
- package/dist/lib/core/registry.js +317 -0
- package/dist/lib/core/release.d.ts +334 -0
- package/dist/lib/core/release.js +465 -0
- package/dist/lib/generators/memory-generator.d.ts +83 -0
- package/{lib → dist/lib}/generators/memory-generator.js +107 -178
- package/dist/lib/generators/nest-generator.d.ts +15 -0
- package/{lib → dist/lib}/generators/nest-generator.js +47 -71
- package/dist/lib/generators/readme-generator.d.ts +15 -0
- package/{lib → dist/lib}/generators/readme-generator.js +9 -14
- package/dist/lib/governance-report.d.ts +49 -0
- package/dist/lib/governance-report.js +170 -0
- package/dist/lib/templates/harness/code-intel.d.mts +2 -0
- package/dist/lib/templates/harness/code-intel.mjs +126 -0
- package/dist/lib/utils/file-helpers.d.ts +9 -0
- package/dist/lib/utils/file-helpers.js +34 -0
- package/dist/lib/validators/structure-validator.d.ts +48 -0
- package/dist/lib/validators/structure-validator.js +232 -0
- package/dist/lib/workspace.d.ts +40 -0
- package/dist/lib/workspace.js +174 -0
- package/dist/scripts/agent-harness.d.ts +2 -0
- package/dist/scripts/agent-harness.js +556 -0
- package/dist/scripts/agent-router.d.ts +30 -0
- package/dist/scripts/agent-router.js +208 -0
- package/dist/scripts/audit-query.d.ts +2 -0
- package/dist/scripts/audit-query.js +43 -0
- package/dist/scripts/audit-sync.d.ts +2 -0
- package/dist/scripts/audit-sync.js +19 -0
- package/dist/scripts/build-smart-context.d.ts +1 -0
- package/dist/scripts/build-smart-context.js +75 -0
- package/dist/scripts/check-standards.d.ts +1 -0
- package/dist/scripts/check-standards.js +87 -0
- package/dist/scripts/compress-memory.d.ts +16 -0
- package/dist/scripts/compress-memory.js +157 -0
- package/dist/scripts/compress-project-memory.d.ts +1 -0
- package/dist/scripts/compress-project-memory.js +48 -0
- package/dist/scripts/context-ops.d.ts +2 -0
- package/dist/scripts/context-ops.js +464 -0
- package/dist/scripts/dev.d.ts +96 -0
- package/dist/scripts/dev.js +312 -0
- package/dist/scripts/extract-global-knowledge.d.ts +1 -0
- package/dist/scripts/extract-global-knowledge.js +43 -0
- package/dist/scripts/generate-dashboard.d.ts +1 -0
- package/dist/scripts/generate-dashboard.js +48 -0
- package/dist/scripts/governance-dashboard.d.ts +2 -0
- package/dist/scripts/governance-dashboard.js +36 -0
- package/dist/scripts/hook-guard-paths.d.ts +17 -0
- package/dist/scripts/hook-guard-paths.js +68 -0
- package/dist/scripts/hook-post-edit.d.ts +20 -0
- package/dist/scripts/hook-post-edit.js +70 -0
- package/dist/scripts/hook-session-start.d.ts +17 -0
- package/dist/scripts/hook-session-start.js +108 -0
- package/dist/scripts/hook-user-prompt.d.ts +22 -0
- package/dist/scripts/hook-user-prompt.js +193 -0
- package/dist/scripts/memory-schema.d.ts +6 -0
- package/{scripts/memory-schema.mjs → dist/scripts/memory-schema.js} +27 -20
- package/dist/scripts/query-universal-memory.d.ts +1 -0
- package/dist/scripts/query-universal-memory.js +44 -0
- package/dist/scripts/release-check.d.ts +14 -0
- package/dist/scripts/release-check.js +48 -0
- package/dist/scripts/spec-cli.d.ts +29 -0
- package/dist/scripts/spec-cli.js +261 -0
- package/dist/scripts/sprint-manager.d.ts +1 -0
- package/dist/scripts/sprint-manager.js +187 -0
- package/dist/scripts/sync-universal-memory.d.ts +1 -0
- package/dist/scripts/sync-universal-memory.js +277 -0
- package/dist/scripts/token-benchmark.d.ts +20 -0
- package/dist/scripts/token-benchmark.js +181 -0
- package/dist/scripts/tools-doctor.d.ts +20 -0
- package/dist/scripts/tools-doctor.js +120 -0
- package/memory/90-decisions/0028-governanca-visivel.md +84 -0
- package/package.json +54 -56
- package/specs/governanca-visivel/plan.md +122 -0
- package/specs/governanca-visivel/spec.md +112 -0
- package/specs/governanca-visivel/tasks.md +60 -0
- package/specs/ts-migration/plan.md +24 -13
- package/bin/create-memory-nest-kit.js +0 -125
- package/bin/forja.mjs +0 -143
- package/bin/init-project.js +0 -612
- package/lib/context-builder.js +0 -257
- package/lib/core/checks.mjs +0 -155
- package/lib/core/doc-graph.mjs +0 -231
- package/lib/core/health.mjs +0 -577
- package/lib/core/registry.mjs +0 -312
- package/lib/core/release.mjs +0 -492
- package/lib/templates/harness/code-intel.mjs +0 -119
- package/lib/templates/harness/mcp.json +0 -10
- package/lib/utils/file-helpers.js +0 -40
- package/lib/validators/structure-validator.js +0 -253
- package/lib/workspace.mjs +0 -213
- package/scripts/agent-harness.mjs +0 -580
- package/scripts/agent-router.mjs +0 -189
- package/scripts/build-smart-context.js +0 -87
- package/scripts/check-standards.js +0 -98
- package/scripts/compress-memory.mjs +0 -198
- package/scripts/compress-project-memory.js +0 -58
- package/scripts/context-ops.mjs +0 -466
- package/scripts/dev.mjs +0 -349
- package/scripts/extract-global-knowledge.js +0 -52
- package/scripts/generate-dashboard.js +0 -59
- package/scripts/hook-guard-paths.mjs +0 -76
- package/scripts/hook-post-edit.mjs +0 -79
- package/scripts/hook-session-start.mjs +0 -104
- package/scripts/hook-user-prompt.mjs +0 -185
- package/scripts/pre-commit.sh +0 -102
- package/scripts/query-universal-memory.js +0 -50
- package/scripts/release-check.mjs +0 -56
- package/scripts/spec-cli.mjs +0 -261
- package/scripts/sprint-manager.js +0 -200
- package/scripts/sync-universal-memory.js +0 -286
- package/scripts/token-benchmark.mjs +0 -203
- package/scripts/tools-doctor.mjs +0 -132
package/scripts/spec-cli.mjs
DELETED
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* spec-cli — pipeline SDD
|
|
4
|
-
*
|
|
5
|
-
* Comandos:
|
|
6
|
-
* spec:new <feature> cria specs/<feature>/spec.md a partir do template
|
|
7
|
-
* spec:plan <feature> cria plan.md (exige spec.md aprovada)
|
|
8
|
-
* spec:tasks <feature> cria tasks.md (exige plan.md aprovado)
|
|
9
|
-
* spec:check [feature] valida 1 feature ou todas
|
|
10
|
-
*
|
|
11
|
-
* Convenções:
|
|
12
|
-
* - feature-slug em kebab-case
|
|
13
|
-
* - status na frontmatter-like "- **Status**: ..." linha 3
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import fs from 'node:fs';
|
|
17
|
-
import path from 'node:path';
|
|
18
|
-
import process from 'node:process';
|
|
19
|
-
import { fileURLToPath } from 'node:url';
|
|
20
|
-
|
|
21
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
-
const __dirname = path.dirname(__filename);
|
|
23
|
-
const repoRoot = path.resolve(__dirname, '..');
|
|
24
|
-
const specsDir = path.join(repoRoot, 'specs');
|
|
25
|
-
const templatesDir = path.join(specsDir, '_templates');
|
|
26
|
-
|
|
27
|
-
const STAGES = ['spec', 'plan', 'tasks'];
|
|
28
|
-
const STATUS_RE = /-\s*\*\*Status\*\*:\s*([a-z]+)[^\n]*/i;
|
|
29
|
-
const VALID_STATUSES = ['draft', 'review', 'approved', 'implementing', 'done', 'abandoned'];
|
|
30
|
-
|
|
31
|
-
/** @returns {never} */
|
|
32
|
-
function fail(msg) {
|
|
33
|
-
fs.writeSync(2, `[spec-cli] ${msg}\n`);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function out(msg = '') {
|
|
38
|
-
fs.writeSync(1, `${msg}\n`);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function slugify(name) {
|
|
42
|
-
return name
|
|
43
|
-
.toLowerCase()
|
|
44
|
-
.normalize('NFD').replace(/[̀-ͯ]/g, '')
|
|
45
|
-
.replace(/[^a-z0-9]+/g, '-')
|
|
46
|
-
.replace(/^-+|-+$/g, '');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function todayISO() {
|
|
50
|
-
return new Date().toISOString().slice(0, 10);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function readTemplate(stage) {
|
|
54
|
-
const p = path.join(templatesDir, `${stage}.md`);
|
|
55
|
-
if (!fs.existsSync(p)) fail(`template ${stage}.md ausente em ${templatesDir}`);
|
|
56
|
-
return fs.readFileSync(p, 'utf8');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function fillTemplate(tpl, vars) {
|
|
60
|
-
return tpl
|
|
61
|
-
.replace(/{{FEATURE}}/g, vars.feature)
|
|
62
|
-
.replace(/{{ID}}/g, vars.id)
|
|
63
|
-
.replace(/{{OWNER}}/g, vars.owner || '—')
|
|
64
|
-
.replace(/{{DATE}}/g, vars.date);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function readStatus(filePath) {
|
|
68
|
-
if (!fs.existsSync(filePath)) return null;
|
|
69
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
70
|
-
const m = content.match(STATUS_RE);
|
|
71
|
-
return m ? m[1].toLowerCase() : 'unknown';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function listFeatures() {
|
|
75
|
-
if (!fs.existsSync(specsDir)) return [];
|
|
76
|
-
return fs.readdirSync(specsDir)
|
|
77
|
-
.filter(name => !name.startsWith('_') && !name.startsWith('.'))
|
|
78
|
-
.filter(name => fs.statSync(path.join(specsDir, name)).isDirectory());
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* `.gitignore` ignora `/specs/*` e libera as specs do framework por allow-list. Uma spec nova
|
|
83
|
-
* nascia invisível ao git: criada, aprovada pelo check, e descartada em silêncio. A regra existia
|
|
84
|
-
* só como convenção — e convenção que depende de memória não é regra. Passa a viver no harness
|
|
85
|
-
* (ADR-0021).
|
|
86
|
-
*
|
|
87
|
-
* Puro de propósito: recebe e devolve conteúdo, para ser testável sem tocar no .gitignore real.
|
|
88
|
-
*
|
|
89
|
-
* @returns {{ changed: boolean, content: string, reason: 'added'|'already-present'|'no-block' }}
|
|
90
|
-
*/
|
|
91
|
-
export function addSpecToAllowlist(content, slug) {
|
|
92
|
-
const line = `!/specs/${slug}`;
|
|
93
|
-
const lines = content.split('\n');
|
|
94
|
-
|
|
95
|
-
if (lines.some((l) => l.trim() === line)) {
|
|
96
|
-
return { changed: false, content, reason: 'already-present' };
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Insere após a última entrada do bloco, não no fim do arquivo: as regras seguintes do
|
|
100
|
-
// .gitignore dependem da ordem.
|
|
101
|
-
let anchor = -1;
|
|
102
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
103
|
-
if (lines[i].trim().startsWith('!/specs/')) anchor = i;
|
|
104
|
-
}
|
|
105
|
-
if (anchor === -1) return { changed: false, content, reason: 'no-block' };
|
|
106
|
-
|
|
107
|
-
lines.splice(anchor + 1, 0, line);
|
|
108
|
-
return { changed: true, content: lines.join('\n'), reason: 'added' };
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function gitignorePath() {
|
|
112
|
-
return process.env.FORJA_GITIGNORE || path.join(repoRoot, '.gitignore');
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** Efeito colateral de `spec:new`. Nunca derruba a criação da spec — criar a spec é o trabalho. */
|
|
116
|
-
function ensureSpecVersioned(slug) {
|
|
117
|
-
const file = gitignorePath();
|
|
118
|
-
let raw;
|
|
119
|
-
try {
|
|
120
|
-
raw = fs.readFileSync(file, 'utf8');
|
|
121
|
-
} catch {
|
|
122
|
-
out(' ⚠ .gitignore não encontrado — confira se a spec será versionada.');
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const result = addSpecToAllowlist(raw, slug);
|
|
127
|
-
if (result.reason === 'no-block') {
|
|
128
|
-
out(' ⚠ bloco allow-list de specs ausente no .gitignore — versione a spec manualmente.');
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (!result.changed) return;
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
fs.writeFileSync(file, result.content);
|
|
135
|
-
out(` + .gitignore: !/specs/${slug}`);
|
|
136
|
-
} catch {
|
|
137
|
-
out(` ⚠ não foi possível escrever .gitignore — adicione "!/specs/${slug}" manualmente.`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function cmdNew(feature) {
|
|
142
|
-
if (!feature) fail('uso: spec:new <feature>');
|
|
143
|
-
const slug = slugify(feature);
|
|
144
|
-
const dir = path.join(specsDir, slug);
|
|
145
|
-
if (fs.existsSync(dir)) fail(`spec ${slug} já existe em ${dir}`);
|
|
146
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
147
|
-
const tpl = readTemplate('spec');
|
|
148
|
-
const content = fillTemplate(tpl, {
|
|
149
|
-
feature: slug,
|
|
150
|
-
id: `SPEC-${String(listFeatures().length + 1).padStart(3, '0')}`,
|
|
151
|
-
owner: process.env.USER || '—',
|
|
152
|
-
date: todayISO(),
|
|
153
|
-
});
|
|
154
|
-
fs.writeFileSync(path.join(dir, 'spec.md'), content);
|
|
155
|
-
out(`✓ criada: specs/${slug}/spec.md`);
|
|
156
|
-
ensureSpecVersioned(slug);
|
|
157
|
-
out(' edite, mude status para "review", peça revisão.');
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function cmdNextStage(stage, feature) {
|
|
161
|
-
if (!feature) fail(`uso: spec:${stage} <feature>`);
|
|
162
|
-
const slug = slugify(feature);
|
|
163
|
-
const dir = path.join(specsDir, slug);
|
|
164
|
-
if (!fs.existsSync(dir)) fail(`feature ${slug} não existe — rode spec:new primeiro`);
|
|
165
|
-
|
|
166
|
-
const prevStage = STAGES[STAGES.indexOf(stage) - 1];
|
|
167
|
-
const prevStatus = readStatus(path.join(dir, `${prevStage}.md`));
|
|
168
|
-
if (!prevStatus) fail(`${prevStage}.md não existe em ${dir}`);
|
|
169
|
-
if (!['approved', 'implementing', 'done'].includes(prevStatus)) {
|
|
170
|
-
fail(`${prevStage}.md está em status "${prevStatus}". Precisa de "approved" para gerar ${stage}.md`);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const outputPath = path.join(dir, `${stage}.md`);
|
|
174
|
-
if (fs.existsSync(outputPath)) fail(`${stage}.md já existe`);
|
|
175
|
-
const tpl = readTemplate(stage);
|
|
176
|
-
fs.writeFileSync(outputPath, fillTemplate(tpl, { feature: slug, id: '', owner: '—', date: todayISO() }));
|
|
177
|
-
out(`✓ criada: specs/${slug}/${stage}.md`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
function checkFeature(slug) {
|
|
181
|
-
const dir = path.join(specsDir, slug);
|
|
182
|
-
const result = { slug, stages: /** @type {Record<string,string|null>} */ ({}), ok: true, errors: /** @type {string[]} */ ([]) };
|
|
183
|
-
for (const stage of STAGES) {
|
|
184
|
-
const status = readStatus(path.join(dir, `${stage}.md`));
|
|
185
|
-
result.stages[stage] = status;
|
|
186
|
-
}
|
|
187
|
-
// Regras
|
|
188
|
-
// `abandoned` é terminal: uma feature pode ter avançado até plan/tasks antes de parar,
|
|
189
|
-
// e isso não é incoerência — é história. Ver ADR-0022.
|
|
190
|
-
const ALLOWS_NEXT_STAGE = ['approved', 'implementing', 'done', 'abandoned'];
|
|
191
|
-
if (!result.stages.spec) {
|
|
192
|
-
result.ok = false;
|
|
193
|
-
result.errors.push('spec.md ausente');
|
|
194
|
-
}
|
|
195
|
-
if (result.stages.plan && !ALLOWS_NEXT_STAGE.includes(result.stages.spec ?? '')) {
|
|
196
|
-
result.ok = false;
|
|
197
|
-
result.errors.push(`plan.md existe mas spec status = ${result.stages.spec}`);
|
|
198
|
-
}
|
|
199
|
-
if (result.stages.tasks && !ALLOWS_NEXT_STAGE.includes(result.stages.plan ?? '')) {
|
|
200
|
-
result.ok = false;
|
|
201
|
-
result.errors.push(`tasks.md existe mas plan status = ${result.stages.plan}`);
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function cmdCheck(feature) {
|
|
207
|
-
const features = feature ? [slugify(feature)] : listFeatures();
|
|
208
|
-
if (!features.length) {
|
|
209
|
-
out('Nenhuma spec encontrada em specs/');
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
let failed = 0;
|
|
213
|
-
for (const slug of features) {
|
|
214
|
-
const r = checkFeature(slug);
|
|
215
|
-
const tag = r.ok ? '✓' : '✗';
|
|
216
|
-
const stages = STAGES.map(s => `${s}:${r.stages[s] || '—'}`).join(' ');
|
|
217
|
-
out(`${tag} ${slug.padEnd(30)} ${stages}`);
|
|
218
|
-
if (!r.ok) {
|
|
219
|
-
r.errors.forEach(e => out(` ↳ ${e}`));
|
|
220
|
-
failed++;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (failed) {
|
|
224
|
-
out(`\n${failed} feature(s) com problema.`);
|
|
225
|
-
process.exit(1);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function cmdSetStatus(feature, stage, status) {
|
|
230
|
-
if (!feature || !stage || !status) fail('uso: spec:set-status <feature> <spec|plan|tasks> <status>');
|
|
231
|
-
if (!STAGES.includes(stage)) fail(`stage inválido: ${stage}. Use: ${STAGES.join('|')}`);
|
|
232
|
-
if (!VALID_STATUSES.includes(status)) fail(`status inválido: ${status}. Use: ${VALID_STATUSES.join('|')}`);
|
|
233
|
-
const slug = slugify(feature);
|
|
234
|
-
const file = path.join(specsDir, slug, `${stage}.md`);
|
|
235
|
-
if (!fs.existsSync(file)) fail(`${stage}.md não existe em specs/${slug}/`);
|
|
236
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
237
|
-
const m = content.match(STATUS_RE);
|
|
238
|
-
const previous = m ? m[1].toLowerCase() : 'unknown';
|
|
239
|
-
const updated = m
|
|
240
|
-
? content.replace(STATUS_RE, `- **Status**: ${status}`)
|
|
241
|
-
: content.replace(/^# .+\n/, match => `${match}\n- **Status**: ${status}\n`);
|
|
242
|
-
fs.writeFileSync(file, updated);
|
|
243
|
-
out(`✓ ${slug}/${stage}.md: ${previous} → ${status}`);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Só despacha quando executado como CLI. Importado (pelos testes), expõe as funções sem rodar nada.
|
|
247
|
-
if (process.argv[1] && path.resolve(process.argv[1]) === __filename) {
|
|
248
|
-
const [, , subcmd, ...rest] = process.argv;
|
|
249
|
-
const arg = rest[0];
|
|
250
|
-
|
|
251
|
-
switch (subcmd) {
|
|
252
|
-
case 'new': cmdNew(arg); break;
|
|
253
|
-
case 'plan': cmdNextStage('plan', arg); break;
|
|
254
|
-
case 'tasks': cmdNextStage('tasks', arg); break;
|
|
255
|
-
case 'check': cmdCheck(arg); break;
|
|
256
|
-
case 'set-status': cmdSetStatus(rest[0], rest[1], rest[2]); break;
|
|
257
|
-
default:
|
|
258
|
-
out('Uso: spec-cli <new|plan|tasks|check|set-status> [args]');
|
|
259
|
-
process.exit(1);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { resolveProject, initWorkspace, getWorkspaceRoot } from '../lib/workspace.mjs';
|
|
5
|
-
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
const root = path.resolve(__dirname, '..');
|
|
9
|
-
|
|
10
|
-
const [cmd, projectArg, ...args] = process.argv.slice(2);
|
|
11
|
-
|
|
12
|
-
if (!cmd) {
|
|
13
|
-
console.log('Uso: node scripts/sprint-manager.js <start|status|complete> [projeto|.|root] [args]');
|
|
14
|
-
console.log(' . ou root = framework raiz; outro nome = projeto no workspace');
|
|
15
|
-
process.exit(0);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const project = projectArg || '.';
|
|
19
|
-
let projectDir;
|
|
20
|
-
if (project === '.' || project === 'root') {
|
|
21
|
-
projectDir = root;
|
|
22
|
-
} else {
|
|
23
|
-
initWorkspace();
|
|
24
|
-
projectDir = resolveProject(project);
|
|
25
|
-
}
|
|
26
|
-
const projectLabel = projectDir === root ? 'framework-root' : project;
|
|
27
|
-
|
|
28
|
-
if (!fs.existsSync(projectDir)) {
|
|
29
|
-
console.error(`Projeto nao encontrado: ${project}`);
|
|
30
|
-
process.exit(1);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const backlogFile = path.join(projectDir, 'memory/40-delivery/backlog.md');
|
|
34
|
-
const sprintFile = path.join(projectDir, 'memory/40-delivery/current-sprint.md');
|
|
35
|
-
const runsDir = path.join(projectDir, 'memory/60-runs');
|
|
36
|
-
|
|
37
|
-
function startSprint() {
|
|
38
|
-
if (!fs.existsSync(backlogFile)) return console.error('Backlog nao encontrado.');
|
|
39
|
-
|
|
40
|
-
const backlog = fs.readFileSync(backlogFile, 'utf8');
|
|
41
|
-
const lines = backlog.split('\n');
|
|
42
|
-
|
|
43
|
-
const toSprint = [];
|
|
44
|
-
const remaining = [];
|
|
45
|
-
|
|
46
|
-
let inPriority = false;
|
|
47
|
-
let hasChecklistPriority = false;
|
|
48
|
-
for (const line of lines) {
|
|
49
|
-
if (line.includes('## Alta Prioridade')) inPriority = true;
|
|
50
|
-
else if (line.startsWith('## ')) inPriority = false;
|
|
51
|
-
|
|
52
|
-
if (inPriority && line.match(/^[-*]\s+\[\s\]\s+(.+)$/)) {
|
|
53
|
-
toSprint.push(line);
|
|
54
|
-
hasChecklistPriority = true;
|
|
55
|
-
} else {
|
|
56
|
-
remaining.push(line);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (toSprint.length === 0) {
|
|
61
|
-
const riceRows = parseRiceBacklog(backlog)
|
|
62
|
-
.filter((item) => ['P0', 'P1'].includes(item.priority))
|
|
63
|
-
.slice(0, Number(args[0]) || 5);
|
|
64
|
-
|
|
65
|
-
toSprint.push(...riceRows.map((item) => `- [ ] ${item.priority}: ${item.item} (RICE ${item.rice})`));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (toSprint.length === 0) return console.log('Nada para mover para a sprint.');
|
|
69
|
-
|
|
70
|
-
const sprintContent = `# Sprint Atual
|
|
71
|
-
|
|
72
|
-
## Projeto
|
|
73
|
-
${projectLabel}
|
|
74
|
-
|
|
75
|
-
## Objetivos
|
|
76
|
-
- Completar itens P0/P1 do backlog com handoffs GSD registrados.
|
|
77
|
-
|
|
78
|
-
## Itens da Sprint
|
|
79
|
-
${toSprint.join('\n')}
|
|
80
|
-
|
|
81
|
-
## Ritual CLI
|
|
82
|
-
- Planejar: npm run gsd:plan -- <slug> "<objetivo>"
|
|
83
|
-
- Handoff spec: npm run gsd:handoff -- spec <slug>
|
|
84
|
-
- Handoff plan: npm run gsd:handoff -- plan <slug>
|
|
85
|
-
- Handoff implement: npm run gsd:handoff -- implement <slug>
|
|
86
|
-
- Validar: npm run gsd:check -- <slug>
|
|
87
|
-
- Governanca: npm run project:check
|
|
88
|
-
`;
|
|
89
|
-
|
|
90
|
-
fs.writeFileSync(sprintFile, sprintContent, 'utf8');
|
|
91
|
-
if (hasChecklistPriority) fs.writeFileSync(backlogFile, remaining.join('\n'), 'utf8');
|
|
92
|
-
|
|
93
|
-
console.log(`Sprint iniciada para ${projectLabel} com ${toSprint.length} itens.`);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function showStatus() {
|
|
97
|
-
if (!fs.existsSync(sprintFile)) return console.log('Nenhuma sprint ativa.');
|
|
98
|
-
const content = fs.readFileSync(sprintFile, 'utf8');
|
|
99
|
-
console.log(`\n--- Status da Sprint: ${projectLabel} ---\n`);
|
|
100
|
-
console.log(content);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function parseRiceBacklog(content) {
|
|
104
|
-
return content
|
|
105
|
-
.split('\n')
|
|
106
|
-
.filter((line) => line.startsWith('| P'))
|
|
107
|
-
.map((line) => line.split('|').map((cell) => cell.trim()))
|
|
108
|
-
.filter((cells) => cells.length >= 8)
|
|
109
|
-
.map((cells) => ({
|
|
110
|
-
priority: cells[1],
|
|
111
|
-
item: cells[2],
|
|
112
|
-
rice: cells[7],
|
|
113
|
-
}))
|
|
114
|
-
.filter((item) => item.priority && item.item && item.rice);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function parseChecklistItems(content) {
|
|
118
|
-
const done = [];
|
|
119
|
-
const pending = [];
|
|
120
|
-
const lines = content.split('\n');
|
|
121
|
-
|
|
122
|
-
for (const line of lines) {
|
|
123
|
-
const doneMatch = line.match(/^[-*]\s+\[x\]\s+(.+)$/i);
|
|
124
|
-
const pendingMatch = line.match(/^[-*]\s+\[\s\]\s+(.+)$/);
|
|
125
|
-
if (doneMatch) done.push(doneMatch[1]);
|
|
126
|
-
if (pendingMatch) pending.push(pendingMatch[1]);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return { done, pending };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function appendToHighPriorityBacklog(items) {
|
|
133
|
-
if (items.length === 0 || !fs.existsSync(backlogFile)) return;
|
|
134
|
-
const backlog = fs.readFileSync(backlogFile, 'utf8');
|
|
135
|
-
const lines = backlog.split('\n');
|
|
136
|
-
const output = [];
|
|
137
|
-
let inserted = false;
|
|
138
|
-
|
|
139
|
-
for (let i = 0; i < lines.length; i += 1) {
|
|
140
|
-
output.push(lines[i]);
|
|
141
|
-
if (!inserted && lines[i].includes('## Alta Prioridade')) {
|
|
142
|
-
output.push(...items.map((item) => `- [ ] ${item}`));
|
|
143
|
-
inserted = true;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
fs.writeFileSync(backlogFile, output.join('\n'), 'utf8');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function completeSprint() {
|
|
151
|
-
if (!fs.existsSync(sprintFile)) return console.log('Nenhuma sprint ativa para encerrar.');
|
|
152
|
-
const content = fs.readFileSync(sprintFile, 'utf8');
|
|
153
|
-
const { done, pending } = parseChecklistItems(content);
|
|
154
|
-
|
|
155
|
-
appendToHighPriorityBacklog(pending);
|
|
156
|
-
fs.mkdirSync(runsDir, { recursive: true });
|
|
157
|
-
|
|
158
|
-
const now = new Date();
|
|
159
|
-
const stamp = now.toISOString().replace(/[:]/g, '-');
|
|
160
|
-
const reportFile = path.join(runsDir, `sprint-close-${stamp}.md`);
|
|
161
|
-
const report = `# Fechamento de Sprint
|
|
162
|
-
|
|
163
|
-
## Projeto
|
|
164
|
-
${projectLabel}
|
|
165
|
-
|
|
166
|
-
## Data
|
|
167
|
-
${now.toISOString()}
|
|
168
|
-
|
|
169
|
-
## Entregas concluídas (${done.length})
|
|
170
|
-
${done.length ? done.map((item) => `- ${item}`).join('\n') : '- Nenhuma'}
|
|
171
|
-
|
|
172
|
-
## Pendências realocadas para backlog (${pending.length})
|
|
173
|
-
${pending.length ? pending.map((item) => `- ${item}`).join('\n') : '- Nenhuma'}
|
|
174
|
-
`;
|
|
175
|
-
fs.writeFileSync(reportFile, report, 'utf8');
|
|
176
|
-
|
|
177
|
-
const resetSprint = `# Sprint Atual
|
|
178
|
-
|
|
179
|
-
## Status
|
|
180
|
-
- Encerrada em ${now.toISOString()}
|
|
181
|
-
- Nova sprint ainda não iniciada.
|
|
182
|
-
|
|
183
|
-
## Próximo passo
|
|
184
|
-
- Execute: node scripts/sprint-manager.js start ${projectDir === root ? '' : project}
|
|
185
|
-
`;
|
|
186
|
-
fs.writeFileSync(sprintFile, resetSprint, 'utf8');
|
|
187
|
-
|
|
188
|
-
console.log(`Sprint encerrada para ${projectLabel}.`);
|
|
189
|
-
console.log(`Relatorio: ${path.relative(root, reportFile)}`);
|
|
190
|
-
if (pending.length > 0) {
|
|
191
|
-
console.log(`${pending.length} pendencia(s) devolvida(s) para Alta Prioridade no backlog.`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
switch (cmd) {
|
|
196
|
-
case 'start': startSprint(); break;
|
|
197
|
-
case 'status': showStatus(); break;
|
|
198
|
-
case 'complete': completeSprint(); break;
|
|
199
|
-
default: console.log('Comando desconhecido.');
|
|
200
|
-
}
|