forjajs 1.1.6 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.json +7 -7
- package/CHANGELOG.md +62 -0
- package/README.en.md +33 -5
- package/README.md +35 -4
- package/boilerplates/06-clean-arch/README.md +48 -0
- package/boilerplates/06-clean-arch/WHEN-CLEAN-WHEN-LEAN.md +42 -0
- package/boilerplates/06-clean-arch/backend/package.json +43 -0
- package/boilerplates/06-clean-arch/backend/src/app.module.ts +20 -0
- package/boilerplates/06-clean-arch/backend/src/main.ts +10 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/application/place-order.usecase.ts +47 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/application/ship-order.usecase.ts +28 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/money.vo.ts +30 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/order-status.vo.ts +36 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/order.entity.ts +85 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/order.repository.ts +17 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/infrastructure/order.orm-entity.ts +24 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/infrastructure/typeorm-order.repository.ts +57 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/orders.module.ts +28 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/presentation/orders.controller.ts +31 -0
- package/boilerplates/06-clean-arch/backend/src/modules/orders/presentation/orders.http.dto.ts +30 -0
- package/boilerplates/06-clean-arch/backend/src/modules/products/product.entity.ts +20 -0
- package/boilerplates/06-clean-arch/backend/src/modules/products/products.controller.ts +43 -0
- package/boilerplates/06-clean-arch/backend/src/modules/products/products.module.ts +11 -0
- package/boilerplates/06-clean-arch/backend/src/shared/result.ts +32 -0
- package/boilerplates/06-clean-arch/backend/test/orders/place-order.spec.ts +46 -0
- package/boilerplates/06-clean-arch/backend/tsconfig.json +16 -0
- package/boilerplates/06-clean-arch/boilerplate.manifest.json +43 -0
- package/boilerplates/06-clean-arch/memory/30-domains/orders/context.md +39 -0
- package/boilerplates/06-clean-arch/memory/30-domains/products/context.md +23 -0
- package/boilerplates/README.md +20 -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/docs/personas/architect/README.md +4 -4
- package/docs/personas/developer/README.md +3 -3
- package/docs/personas/qa/README.md +3 -3
- package/docs/quick-reference.md +9 -9
- package/docs/structure.md +3 -3
- package/memory/90-decisions/0025-coerencia-da-documentacao.md +95 -0
- package/memory/90-decisions/0027-clean-arch-calibrada.md +96 -0
- package/memory/90-decisions/0028-governanca-visivel.md +84 -0
- package/package.json +60 -56
- package/specs/clean-arch-boilerplate/plan.md +137 -0
- package/specs/clean-arch-boilerplate/spec.md +121 -0
- package/specs/clean-arch-boilerplate/tasks.md +70 -0
- package/specs/coerencia-do-sistema/plan.md +155 -0
- package/specs/coerencia-do-sistema/spec.md +15 -14
- package/specs/coerencia-do-sistema/tasks.md +115 -0
- 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 +199 -0
- package/specs/ts-migration/spec.md +119 -0
- package/specs/ts-migration/tasks.md +110 -0
- 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 -138
- package/lib/core/health.mjs +0 -475
- package/lib/core/registry.mjs +0 -289
- package/lib/core/release.mjs +0 -452
- 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 -578
- 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 -463
- 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 -75
- 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 -260
- 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/context-ops.mjs
DELETED
|
@@ -1,463 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import Database from 'better-sqlite3';
|
|
6
|
-
import { fileURLToPath } from 'node:url';
|
|
7
|
-
import { ensureSchema, dbPath } from './memory-schema.mjs';
|
|
8
|
-
|
|
9
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const root = path.resolve(__dirname, '..');
|
|
11
|
-
const outDir = path.join(root, '.context');
|
|
12
|
-
const defaultLimit = readTokenLimit();
|
|
13
|
-
|
|
14
|
-
function estimateTokens(content) {
|
|
15
|
-
return Math.ceil(content.length / 4);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function readTokenLimit() {
|
|
19
|
-
const configPath = path.join(root, '.memoryrc.json');
|
|
20
|
-
if (!fs.existsSync(configPath)) return 8000;
|
|
21
|
-
try {
|
|
22
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
23
|
-
return Number(config?.tokenLimits?.task) || 8000;
|
|
24
|
-
} catch {
|
|
25
|
-
return 8000;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function ensureOutDir() {
|
|
30
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function readIfExists(relPath, maxChars = 12000) {
|
|
34
|
-
const full = path.join(root, relPath);
|
|
35
|
-
if (!fs.existsSync(full)) return '';
|
|
36
|
-
return fs.readFileSync(full, 'utf8').slice(0, maxChars);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function firstHeading(content, fallback) {
|
|
40
|
-
const match = content.match(/^#\s+(.+)$/m);
|
|
41
|
-
return match ? match[1].trim() : fallback;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function specStatus(content) {
|
|
45
|
-
const match = content.match(/-\s+\*\*Status\*\*:\s+([^\n]+)/);
|
|
46
|
-
return match ? match[1].trim() : 'unknown';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function extractSection(content, heading, maxChars = 2200) {
|
|
50
|
-
const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
51
|
-
const re = new RegExp(`^##\\s+${escaped}\\s*\\n([\\s\\S]*?)(?=^##\\s+|$)`, 'm');
|
|
52
|
-
const match = content.match(re);
|
|
53
|
-
return match ? match[1].trim().slice(0, maxChars) : '';
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function listSpecs() {
|
|
57
|
-
const specsDir = path.join(root, 'specs');
|
|
58
|
-
if (!fs.existsSync(specsDir)) return [];
|
|
59
|
-
return fs.readdirSync(specsDir, { withFileTypes: true })
|
|
60
|
-
.filter((entry) => entry.isDirectory() && !entry.name.startsWith('_'))
|
|
61
|
-
.map((entry) => {
|
|
62
|
-
const slug = entry.name;
|
|
63
|
-
const specPath = path.join(specsDir, slug, 'spec.md');
|
|
64
|
-
const planPath = path.join(specsDir, slug, 'plan.md');
|
|
65
|
-
const tasksPath = path.join(specsDir, slug, 'tasks.md');
|
|
66
|
-
const spec = fs.existsSync(specPath) ? fs.readFileSync(specPath, 'utf8') : '';
|
|
67
|
-
return {
|
|
68
|
-
slug,
|
|
69
|
-
title: spec ? firstHeading(spec, slug) : slug,
|
|
70
|
-
status: spec ? specStatus(spec) : 'missing',
|
|
71
|
-
hasPlan: fs.existsSync(planPath),
|
|
72
|
-
hasTasks: fs.existsSync(tasksPath),
|
|
73
|
-
path: path.relative(root, specPath),
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function openDb() {
|
|
79
|
-
ensureSchema({ silent: true });
|
|
80
|
-
return new Database(dbPath, { timeout: 5000 });
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function recordContextRun(kind, slug, filePath, content, limitTokens = null) {
|
|
84
|
-
const db = openDb();
|
|
85
|
-
const tokens = estimateTokens(content);
|
|
86
|
-
const status = limitTokens && tokens > limitTokens ? 'over_budget' : 'ok';
|
|
87
|
-
db.prepare(`
|
|
88
|
-
INSERT INTO context_runs (created_at, kind, slug, path, bytes, estimated_tokens, limit_tokens, status)
|
|
89
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
90
|
-
`).run(new Date().toISOString(), kind, slug || null, path.relative(root, filePath), content.length, tokens, limitTokens, status);
|
|
91
|
-
db.close();
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function upsertSpecSummary(slug, content) {
|
|
95
|
-
const db = openDb();
|
|
96
|
-
const title = firstHeading(content, slug);
|
|
97
|
-
const status = specStatus(content);
|
|
98
|
-
const problem = extractSection(content, '1. Problema', 900);
|
|
99
|
-
const value = extractSection(content, '2. Proposta de valor', 700);
|
|
100
|
-
const ac = extractSection(content, '4. Criterios de aceite', 1200) || extractSection(content, '4. Critérios de aceite', 1200);
|
|
101
|
-
const summary = [`## Problema\n${problem}`, `## Valor\n${value}`, `## AC\n${ac}`]
|
|
102
|
-
.filter((part) => !part.endsWith('\n'))
|
|
103
|
-
.join('\n\n')
|
|
104
|
-
.slice(0, 3500);
|
|
105
|
-
db.prepare(`
|
|
106
|
-
INSERT INTO spec_summaries (slug, status, title, summary, source_path, updated_at)
|
|
107
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
108
|
-
ON CONFLICT(slug) DO UPDATE SET
|
|
109
|
-
status=excluded.status,
|
|
110
|
-
title=excluded.title,
|
|
111
|
-
summary=excluded.summary,
|
|
112
|
-
source_path=excluded.source_path,
|
|
113
|
-
updated_at=excluded.updated_at
|
|
114
|
-
`).run(slug, status, title, summary, `specs/${slug}/spec.md`, new Date().toISOString());
|
|
115
|
-
db.close();
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function getOpenHandoffs(slug = null) {
|
|
119
|
-
if (!fs.existsSync(dbPath)) return [];
|
|
120
|
-
const db = openDb();
|
|
121
|
-
let rows;
|
|
122
|
-
try {
|
|
123
|
-
rows = slug
|
|
124
|
-
? db.prepare("SELECT id, created_at, from_agent, to_agent, intent, status, context, acceptance FROM handoffs WHERE spec_slug = ? AND status != 'archived' ORDER BY id DESC LIMIT 10").all(slug)
|
|
125
|
-
: db.prepare("SELECT id, created_at, from_agent, to_agent, intent, status, spec_slug, context, acceptance FROM handoffs WHERE status = 'open' ORDER BY id DESC LIMIT 20").all();
|
|
126
|
-
} catch {
|
|
127
|
-
rows = [];
|
|
128
|
-
}
|
|
129
|
-
db.close();
|
|
130
|
-
return rows;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function latestAdrs() {
|
|
134
|
-
const dir = path.join(root, 'memory', '90-decisions');
|
|
135
|
-
if (!fs.existsSync(dir)) return [];
|
|
136
|
-
return fs.readdirSync(dir)
|
|
137
|
-
.filter((file) => file.endsWith('.md') && file !== '_template.md')
|
|
138
|
-
.sort()
|
|
139
|
-
.slice(-6)
|
|
140
|
-
.map((file) => {
|
|
141
|
-
const rel = path.join('memory/90-decisions', file);
|
|
142
|
-
const content = readIfExists(rel, 1500);
|
|
143
|
-
return { rel, title: firstHeading(content, file) };
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function cmdBudget([target, limitArg]) {
|
|
148
|
-
if (!target) {
|
|
149
|
-
console.error('Uso: context-ops budget <slug|arquivo> [limite_tokens]');
|
|
150
|
-
process.exit(1);
|
|
151
|
-
}
|
|
152
|
-
const limit = Number(limitArg) || defaultLimit;
|
|
153
|
-
const candidates = [
|
|
154
|
-
target,
|
|
155
|
-
`.context/gsd-${target}.md`,
|
|
156
|
-
`.context/agent-brief-${target}.md`,
|
|
157
|
-
`.context/context-task.md`,
|
|
158
|
-
];
|
|
159
|
-
const file = candidates.map((candidate) => path.resolve(root, candidate)).find((candidate) => fs.existsSync(candidate));
|
|
160
|
-
if (!file || !file.startsWith(root)) {
|
|
161
|
-
console.error(`Arquivo ou slug nao encontrado: ${target}`);
|
|
162
|
-
process.exit(1);
|
|
163
|
-
}
|
|
164
|
-
const content = fs.readFileSync(file, 'utf8');
|
|
165
|
-
const tokens = estimateTokens(content);
|
|
166
|
-
const status = tokens <= limit ? 'OK' : 'FAIL';
|
|
167
|
-
recordContextRun('budget', path.basename(target), file, content, limit);
|
|
168
|
-
console.log(`${status} ${path.relative(root, file)}: ${tokens} tokens estimados / limite ${limit}`);
|
|
169
|
-
if (tokens > limit) process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function cmdSprintPack() {
|
|
173
|
-
ensureOutDir();
|
|
174
|
-
const sprint = readIfExists('memory/40-delivery/current-sprint.md', 6000) || 'Nenhuma sprint ativa.';
|
|
175
|
-
const activeSpecs = listSpecs()
|
|
176
|
-
.filter((spec) => ['approved', 'implementing', 'review'].includes(spec.status))
|
|
177
|
-
.slice(0, 12);
|
|
178
|
-
const handoffs = getOpenHandoffs();
|
|
179
|
-
const adrs = latestAdrs();
|
|
180
|
-
|
|
181
|
-
let md = `# Sprint Pack\n\n`;
|
|
182
|
-
md += `- **Gerado em**: ${new Date().toISOString()}\n`;
|
|
183
|
-
md += `- **Budget alvo**: ${defaultLimit} tokens\n\n`;
|
|
184
|
-
md += `## Sprint Atual\n\n${sprint}\n\n`;
|
|
185
|
-
md += `## Specs Ativas\n\n`;
|
|
186
|
-
md += activeSpecs.length
|
|
187
|
-
? activeSpecs.map((spec) => `- ${spec.slug}: ${spec.status}; plan=${spec.hasPlan ? 'sim' : 'nao'}; tasks=${spec.hasTasks ? 'sim' : 'nao'}; ${spec.path}`).join('\n')
|
|
188
|
-
: '- Nenhuma spec ativa encontrada.';
|
|
189
|
-
md += `\n\n## Handoffs Abertos\n\n`;
|
|
190
|
-
md += handoffs.length
|
|
191
|
-
? handoffs.map((h) => `- #${h.id} ${h.from_agent} -> ${h.to_agent} (${h.intent}) ${h.spec_slug || ''}: ${String(h.context).slice(0, 180)}`).join('\n')
|
|
192
|
-
: '- Nenhum handoff aberto.';
|
|
193
|
-
md += `\n\n## ADRs Recentes\n\n`;
|
|
194
|
-
md += adrs.length ? adrs.map((adr) => `- ${adr.rel}: ${adr.title}`).join('\n') : '- Nenhuma ADR encontrada.';
|
|
195
|
-
md += `\n\n## Proximo Uso\n\n`;
|
|
196
|
-
md += `- Para tarefa especifica: \`npm run agent:brief -- <role> <slug>\`\n`;
|
|
197
|
-
md += `- Para budget: \`npm run context:budget -- .context/sprint-pack.md\`\n`;
|
|
198
|
-
|
|
199
|
-
const outFile = path.join(outDir, 'sprint-pack.md');
|
|
200
|
-
fs.writeFileSync(outFile, md, 'utf8');
|
|
201
|
-
recordContextRun('sprint-pack', null, outFile, md, defaultLimit);
|
|
202
|
-
console.log(`Sprint pack gerado: ${path.relative(root, outFile)} (${estimateTokens(md)} tokens estimados)`);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function cmdAgentBrief([role, slug]) {
|
|
206
|
-
if (!role || !slug) {
|
|
207
|
-
console.error('Uso: context-ops agent-brief <role> <slug>');
|
|
208
|
-
process.exit(1);
|
|
209
|
-
}
|
|
210
|
-
ensureOutDir();
|
|
211
|
-
const spec = readIfExists(`specs/${slug}/spec.md`, 12000);
|
|
212
|
-
if (!spec) {
|
|
213
|
-
console.error(`Spec nao encontrada: specs/${slug}/spec.md`);
|
|
214
|
-
process.exit(1);
|
|
215
|
-
}
|
|
216
|
-
upsertSpecSummary(slug, spec);
|
|
217
|
-
const plan = readIfExists(`specs/${slug}/plan.md`, 7000);
|
|
218
|
-
const tasks = readIfExists(`specs/${slug}/tasks.md`, 7000);
|
|
219
|
-
const gsd = readIfExists(`.context/gsd-${slug}.md`, 5000);
|
|
220
|
-
const handoffs = getOpenHandoffs(slug);
|
|
221
|
-
|
|
222
|
-
const sections = [
|
|
223
|
-
['Problema', extractSection(spec, '1. Problema', 1200)],
|
|
224
|
-
['Valor', extractSection(spec, '2. Proposta de valor', 900)],
|
|
225
|
-
['Aceite', extractSection(spec, '4. Criterios de aceite', 1600) || extractSection(spec, '4. Critérios de aceite', 1600)],
|
|
226
|
-
['Plano tecnico', extractSection(plan, '1. Abordagem tecnica', 1400) || extractSection(plan, '1. Abordagem técnica', 1400)],
|
|
227
|
-
['Contratos', extractSection(plan, '4. Contratos', 1200)],
|
|
228
|
-
['Tasks', tasks.split('\n').filter((line) => /^## T\d+/.test(line) || line.includes('- **Paths**') || line.includes('- **Done quando**')).slice(0, 40).join('\n')],
|
|
229
|
-
['GSD', gsd.split('\n').filter((line) => line.includes('- [ ]') || line.includes('- [x]') || line.includes('Objetivo')).slice(0, 30).join('\n')],
|
|
230
|
-
];
|
|
231
|
-
|
|
232
|
-
let md = `# Agent Brief: ${role} / ${slug}\n\n`;
|
|
233
|
-
md += `- **Role**: ${role}\n`;
|
|
234
|
-
md += `- **Spec status**: ${specStatus(spec)}\n`;
|
|
235
|
-
md += `- **Gerado em**: ${new Date().toISOString()}\n`;
|
|
236
|
-
md += `- **Fonte primaria**: specs/${slug}/spec.md\n\n`;
|
|
237
|
-
for (const [title, body] of sections) {
|
|
238
|
-
if (body) md += `## ${title}\n\n${body}\n\n`;
|
|
239
|
-
}
|
|
240
|
-
md += `## Handoffs Relevantes\n\n`;
|
|
241
|
-
md += handoffs.length
|
|
242
|
-
? handoffs.map((h) => `- #${h.id} [${h.status}] ${h.from_agent} -> ${h.to_agent} (${h.intent}); aceite: ${String(h.acceptance).slice(0, 220)}`).join('\n')
|
|
243
|
-
: '- Nenhum handoff registrado para este slug.';
|
|
244
|
-
md += `\n\n## Comandos de Validacao\n\n`;
|
|
245
|
-
md += `\`\`\`bash\nnpm run gsd:check -- ${slug}\nnpm run spec:check -- ${slug}\nnpm run project:check\n\`\`\`\n`;
|
|
246
|
-
|
|
247
|
-
const outFile = path.join(outDir, `agent-brief-${role}-${slug}.md`);
|
|
248
|
-
fs.writeFileSync(outFile, md, 'utf8');
|
|
249
|
-
recordContextRun('agent-brief', slug, outFile, md, defaultLimit);
|
|
250
|
-
console.log(`Agent brief gerado: ${path.relative(root, outFile)} (${estimateTokens(md)} tokens estimados)`);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function summarizeReadme(relPath) {
|
|
254
|
-
const content = readIfExists(relPath, 2500);
|
|
255
|
-
const title = firstHeading(content, path.basename(path.dirname(relPath)));
|
|
256
|
-
const lines = content.split('\n')
|
|
257
|
-
.filter((line) => line.trim() && !line.startsWith('```'))
|
|
258
|
-
.slice(0, 10)
|
|
259
|
-
.join(' ')
|
|
260
|
-
.replace(/\s+/g, ' ')
|
|
261
|
-
.slice(0, 450);
|
|
262
|
-
return { title, summary: lines };
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function keywordTags(text, candidates) {
|
|
266
|
-
const lower = text.toLowerCase();
|
|
267
|
-
return candidates.filter((tag) => lower.includes(tag.toLowerCase()));
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function inferBoilerplateManifest(name, relPath) {
|
|
271
|
-
const readme = readIfExists(relPath, 8000);
|
|
272
|
-
const lower = `${name} ${readme}`.toLowerCase();
|
|
273
|
-
const stack = keywordTags(lower, ['NestJS', 'Next.js', 'React', 'Docker', 'Turborepo', 'RabbitMQ', 'JWT', 'SQLite', 'Postgres']);
|
|
274
|
-
const useCases = keywordTags(lower, ['API REST', 'SaaS', 'E-Commerce', 'Microserviços', 'Monorepo', 'Dashboard', 'Admin', 'Billing', 'Auth']);
|
|
275
|
-
const commands = ['npm install'];
|
|
276
|
-
if (lower.includes('start:dev')) commands.push('npm run start:dev');
|
|
277
|
-
if (lower.includes('docker-compose') || lower.includes('docker compose')) commands.push('docker compose up -d');
|
|
278
|
-
if (lower.includes('test')) commands.push('npm test');
|
|
279
|
-
|
|
280
|
-
return {
|
|
281
|
-
schemaVersion: '1.0',
|
|
282
|
-
type: 'boilerplate',
|
|
283
|
-
name,
|
|
284
|
-
title: firstHeading(readme, name),
|
|
285
|
-
path: path.dirname(relPath),
|
|
286
|
-
readme: relPath,
|
|
287
|
-
stack,
|
|
288
|
-
useCases,
|
|
289
|
-
commands,
|
|
290
|
-
gates: ['npm run spec:check', 'npm test', 'npm run project:check'],
|
|
291
|
-
tokenPolicy: {
|
|
292
|
-
firstRead: ['boilerplate.manifest.json', 'README.md'],
|
|
293
|
-
avoidLoadingByDefault: ['node_modules', 'dist', 'coverage'],
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
function inferDesignManifest(name, relPath) {
|
|
299
|
-
const readme = readIfExists(relPath, 8000);
|
|
300
|
-
const lower = `${name} ${readme}`.toLowerCase();
|
|
301
|
-
const surfaces = [];
|
|
302
|
-
if (['linear.app', 'cursor', 'raycast', 'sentry', 'posthog', 'claude'].includes(name)) surfaces.push('agent-console', 'ops');
|
|
303
|
-
if (['stripe', 'linear.app', 'posthog', 'sentry', 'supabase'].includes(name)) surfaces.push('dashboard');
|
|
304
|
-
if (['mintlify', 'stripe', 'vercel', 'resend', 'hashicorp'].includes(name)) surfaces.push('docs');
|
|
305
|
-
if (['figma', 'miro', 'notion', 'raycast'].includes(name)) surfaces.push('tool');
|
|
306
|
-
if (['wise', 'revolut', 'coinbase', 'kraken'].includes(name)) surfaces.push('fintech');
|
|
307
|
-
if (['apple', 'bmw', 'ferrari', 'tesla', 'lamborghini'].includes(name)) surfaces.push('premium');
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
schemaVersion: '1.0',
|
|
311
|
-
type: 'design-reference',
|
|
312
|
-
name,
|
|
313
|
-
title: firstHeading(readme, name),
|
|
314
|
-
path: path.dirname(relPath),
|
|
315
|
-
readme: relPath,
|
|
316
|
-
surfaces: [...new Set(surfaces)],
|
|
317
|
-
traits: keywordTags(lower, ['dashboard', 'docs', 'developer', 'ai', 'agent', 'collaboration', 'fintech', 'observability', 'premium', 'crm']),
|
|
318
|
-
tokenHints: {
|
|
319
|
-
density: lower.includes('dashboard') || lower.includes('ops') ? 'high' : 'medium',
|
|
320
|
-
useWhen: 'Escolha quando a superficie e o tom baterem com MATRIX.md.',
|
|
321
|
-
avoidWhen: 'Evite copiar identidade proprietaria ou carregar README inteiro sem necessidade.',
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function readJsonIfExists(relPath) {
|
|
327
|
-
const full = path.join(root, relPath);
|
|
328
|
-
if (!fs.existsSync(full)) return null;
|
|
329
|
-
try {
|
|
330
|
-
return JSON.parse(fs.readFileSync(full, 'utf8'));
|
|
331
|
-
} catch {
|
|
332
|
-
return null;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function cmdGenerateManifests() {
|
|
337
|
-
let written = 0;
|
|
338
|
-
const boilerRoot = path.join(root, 'boilerplates');
|
|
339
|
-
if (fs.existsSync(boilerRoot)) {
|
|
340
|
-
for (const entry of fs.readdirSync(boilerRoot, { withFileTypes: true })) {
|
|
341
|
-
if (!entry.isDirectory()) continue;
|
|
342
|
-
const rel = path.join('boilerplates', entry.name, 'README.md');
|
|
343
|
-
if (!fs.existsSync(path.join(root, rel))) continue;
|
|
344
|
-
const manifest = inferBoilerplateManifest(entry.name, rel);
|
|
345
|
-
const outFile = path.join(root, 'boilerplates', entry.name, 'boilerplate.manifest.json');
|
|
346
|
-
fs.writeFileSync(outFile, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
347
|
-
written++;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
const designRoot = path.join(root, 'design-md');
|
|
352
|
-
if (fs.existsSync(designRoot)) {
|
|
353
|
-
for (const entry of fs.readdirSync(designRoot, { withFileTypes: true })) {
|
|
354
|
-
if (!entry.isDirectory()) continue;
|
|
355
|
-
const rel = path.join('design-md', entry.name, 'README.md');
|
|
356
|
-
if (!fs.existsSync(path.join(root, rel))) continue;
|
|
357
|
-
const manifest = inferDesignManifest(entry.name, rel);
|
|
358
|
-
const outFile = path.join(root, 'design-md', entry.name, 'design.manifest.json');
|
|
359
|
-
fs.writeFileSync(outFile, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
|
|
360
|
-
written++;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
console.log(`Manifests gerados: ${written}`);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
function cmdAssetCatalog() {
|
|
368
|
-
ensureOutDir();
|
|
369
|
-
const assets = [];
|
|
370
|
-
const boilerRoot = path.join(root, 'boilerplates');
|
|
371
|
-
if (fs.existsSync(boilerRoot)) {
|
|
372
|
-
for (const entry of fs.readdirSync(boilerRoot, { withFileTypes: true })) {
|
|
373
|
-
if (!entry.isDirectory()) continue;
|
|
374
|
-
const rel = path.join('boilerplates', entry.name, 'README.md');
|
|
375
|
-
if (fs.existsSync(path.join(root, rel))) {
|
|
376
|
-
const data = summarizeReadme(rel);
|
|
377
|
-
const manifest = readJsonIfExists(path.join('boilerplates', entry.name, 'boilerplate.manifest.json'));
|
|
378
|
-
assets.push({
|
|
379
|
-
type: 'boilerplate',
|
|
380
|
-
name: entry.name,
|
|
381
|
-
path: rel,
|
|
382
|
-
...data,
|
|
383
|
-
tags: manifest ? [...(manifest.stack || []), ...(manifest.useCases || [])].join(',') : data.title,
|
|
384
|
-
manifest,
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
const designRoot = path.join(root, 'design-md');
|
|
390
|
-
if (fs.existsSync(designRoot)) {
|
|
391
|
-
for (const entry of fs.readdirSync(designRoot, { withFileTypes: true })) {
|
|
392
|
-
if (!entry.isDirectory()) continue;
|
|
393
|
-
const rel = path.join('design-md', entry.name, 'README.md');
|
|
394
|
-
if (fs.existsSync(path.join(root, rel))) {
|
|
395
|
-
const data = summarizeReadme(rel);
|
|
396
|
-
const manifest = readJsonIfExists(path.join('design-md', entry.name, 'design.manifest.json'));
|
|
397
|
-
assets.push({
|
|
398
|
-
type: 'design-reference',
|
|
399
|
-
name: entry.name,
|
|
400
|
-
path: rel,
|
|
401
|
-
...data,
|
|
402
|
-
tags: manifest ? [...(manifest.surfaces || []), ...(manifest.traits || [])].join(',') : data.title,
|
|
403
|
-
manifest,
|
|
404
|
-
});
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const db = openDb();
|
|
410
|
-
const now = new Date().toISOString();
|
|
411
|
-
const stmt = db.prepare(`
|
|
412
|
-
INSERT INTO asset_catalog (type, name, path, summary, tags, updated_at)
|
|
413
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
414
|
-
ON CONFLICT(path) DO UPDATE SET
|
|
415
|
-
type=excluded.type,
|
|
416
|
-
name=excluded.name,
|
|
417
|
-
summary=excluded.summary,
|
|
418
|
-
tags=excluded.tags,
|
|
419
|
-
updated_at=excluded.updated_at
|
|
420
|
-
`);
|
|
421
|
-
for (const asset of assets) {
|
|
422
|
-
stmt.run(asset.type, asset.name, asset.path, asset.summary, asset.tags || asset.title, now);
|
|
423
|
-
}
|
|
424
|
-
db.close();
|
|
425
|
-
|
|
426
|
-
let md = `# Asset Catalog\n\n- **Gerado em**: ${now}\n- **Total**: ${assets.length}\n\n`;
|
|
427
|
-
for (const type of ['boilerplate', 'design-reference']) {
|
|
428
|
-
md += `## ${type}\n\n`;
|
|
429
|
-
for (const asset of assets.filter((item) => item.type === type)) {
|
|
430
|
-
const tags = asset.tags ? ` [${asset.tags}]` : '';
|
|
431
|
-
md += `- **${asset.name}**${tags}: ${asset.path} — ${asset.summary}\n`;
|
|
432
|
-
}
|
|
433
|
-
md += '\n';
|
|
434
|
-
}
|
|
435
|
-
const outFile = path.join(outDir, 'asset-catalog.md');
|
|
436
|
-
fs.writeFileSync(outFile, md, 'utf8');
|
|
437
|
-
recordContextRun('asset-catalog', null, outFile, md, defaultLimit);
|
|
438
|
-
console.log(`Asset catalog gerado: ${path.relative(root, outFile)} (${assets.length} assets)`);
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
function help() {
|
|
442
|
-
console.log(`Uso: node scripts/context-ops.mjs <command> [args]
|
|
443
|
-
|
|
444
|
-
Comandos:
|
|
445
|
-
budget <slug|arquivo> [limite] Mede tokens e falha se passar do limite
|
|
446
|
-
sprint-pack Gera .context/sprint-pack.md
|
|
447
|
-
agent-brief <role> <slug> Gera brief compacto por papel/feature
|
|
448
|
-
asset-catalog Cataloga boilerplates e design-md
|
|
449
|
-
manifests Gera manifests JSON para boilerplates/design-md
|
|
450
|
-
`);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
const [cmd, ...args] = process.argv.slice(2);
|
|
454
|
-
switch (cmd) {
|
|
455
|
-
case 'budget': cmdBudget(args); break;
|
|
456
|
-
case 'sprint-pack': cmdSprintPack(); break;
|
|
457
|
-
case 'agent-brief': cmdAgentBrief(args); break;
|
|
458
|
-
case 'asset-catalog': cmdAssetCatalog(); break;
|
|
459
|
-
case 'manifests': cmdGenerateManifests(); break;
|
|
460
|
-
default:
|
|
461
|
-
help();
|
|
462
|
-
process.exit(cmd ? 1 : 0);
|
|
463
|
-
}
|