forjajs 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +111 -7
- package/DOC-MAP.md +1 -0
- package/README.md +7 -2
- package/dist/apps/cli/src/index.d.ts +18 -1
- package/dist/apps/cli/src/index.js +161 -26
- package/dist/apps/cli/src/params.d.ts +44 -0
- package/dist/apps/cli/src/params.js +123 -0
- package/dist/bin/forja.js +234 -13
- package/dist/bin/init-project.js +11 -62
- package/dist/lib/cli-output.d.ts +29 -0
- package/dist/lib/cli-output.js +39 -0
- package/dist/lib/core/checks.d.ts +1 -1
- package/dist/lib/core/health.d.ts +9 -0
- package/dist/lib/core/health.js +9 -0
- package/dist/lib/core/project-smoke.d.ts +6 -2
- package/dist/lib/core/project-smoke.js +83 -7
- package/dist/lib/core/registry.d.ts +38 -571
- package/dist/lib/core/registry.js +174 -25
- package/dist/lib/core/release.d.ts +1 -571
- package/dist/lib/core/release.js +0 -3
- package/dist/lib/handoffs-index.d.ts +16 -0
- package/dist/lib/handoffs-index.js +29 -0
- package/dist/lib/llm/claude-output.d.ts +8 -0
- package/dist/lib/llm/claude-output.js +54 -0
- package/dist/lib/llm/context.d.ts +22 -0
- package/dist/lib/llm/context.js +39 -0
- package/dist/lib/llm/session.d.ts +6 -1
- package/dist/lib/llm/session.js +12 -2
- package/dist/lib/multi-ai-instructions.d.ts +28 -0
- package/dist/lib/multi-ai-instructions.js +83 -0
- package/dist/lib/orchestrate.d.ts +5 -0
- package/dist/lib/orchestrate.js +18 -0
- package/dist/lib/specs-index.d.ts +20 -0
- package/dist/lib/specs-index.js +51 -0
- package/dist/lib/sprint-index.d.ts +15 -0
- package/dist/lib/sprint-index.js +34 -0
- package/dist/lib/status-model.d.ts +64 -0
- package/dist/lib/status-model.js +180 -0
- package/dist/packages/evals/src/index.d.ts +2 -0
- package/dist/packages/evals/src/index.js +21 -0
- package/dist/packages/llm/src/index.d.ts +24 -3
- package/dist/packages/llm/src/index.js +51 -5
- package/dist/scripts/cost-economy.js +12 -10
- package/dist/scripts/drift-check.d.ts +2 -0
- package/dist/scripts/drift-check.js +57 -1
- package/dist/scripts/engineer.js +7 -4
- package/dist/scripts/forja-setup.d.ts +14 -0
- package/dist/scripts/forja-setup.js +58 -0
- package/dist/scripts/forja-status.d.ts +11 -0
- package/dist/scripts/forja-status.js +70 -0
- package/dist/scripts/hook-session-start.js +20 -46
- package/dist/scripts/llm-fit.js +113 -8
- package/dist/scripts/project-smoke.js +13 -3
- package/dist/scripts/simulate.js +18 -6
- package/dist/scripts/token-economy.js +34 -28
- package/dist/scripts/tools-doctor.js +14 -6
- package/docs/2x/CLI-CAPABILITIES.md +34 -10
- package/docs/agent-operating-contract.md +1 -1
- package/docs/cli-first-operacao.md +17 -0
- package/docs/contrato-saida-cli.md +79 -0
- package/docs/llm-evolution.md +2 -1
- package/docs/llm-fit-loop.md +74 -2
- package/docs/publishing.md +0 -11
- package/docs/quick-reference.md +13 -0
- package/docs/roadmap-v4.1.md +199 -0
- package/memory/90-decisions/0082-contrato-saida-cli.md +95 -0
- package/memory/90-decisions/0083-mcp-cobertura-declarativa.md +103 -0
- package/memory/90-decisions/0084-drift-sentinel-fecha.md +79 -0
- package/memory/90-decisions/0085-adaptador-claude-paridade.md +85 -0
- package/package.json +4 -1
- package/specs/cli-intuitiva-v1/plan.md +169 -0
- package/specs/cli-intuitiva-v1/spec.md +163 -0
- package/specs/cli-intuitiva-v1/tasks.md +224 -0
- package/specs/contrato-saida-cli/plan.md +162 -0
- package/specs/contrato-saida-cli/spec.md +157 -0
- package/specs/contrato-saida-cli/tasks.md +153 -0
- package/specs/drift-sentinel/spec.md +17 -8
- package/specs/forja-status-caminho-feliz/plan.md +149 -0
- package/specs/forja-status-caminho-feliz/spec.md +158 -0
- package/specs/forja-status-caminho-feliz/tasks.md +175 -0
- package/specs/llm-adaptador-claude/plan.md +117 -0
- package/specs/llm-adaptador-claude/spec.md +144 -0
- package/specs/llm-adaptador-claude/tasks.md +100 -0
- package/specs/llm-benchmark-recomendacao/plan.md +121 -0
- package/specs/llm-benchmark-recomendacao/spec.md +141 -0
- package/specs/llm-benchmark-recomendacao/tasks.md +88 -0
- package/specs/llm-contexto-e-sessoes/plan.md +143 -0
- package/specs/llm-contexto-e-sessoes/spec.md +139 -0
- package/specs/llm-contexto-e-sessoes/tasks.md +127 -0
- package/specs/mcp-cobertura-nucleo/plan.md +158 -0
- package/specs/mcp-cobertura-nucleo/spec.md +161 -0
- package/specs/mcp-cobertura-nucleo/tasks.md +169 -0
- package/specs/projeto-gerado-confiavel/plan.md +148 -0
- package/specs/projeto-gerado-confiavel/spec.md +142 -0
- package/specs/projeto-gerado-confiavel/tasks.md +139 -0
|
@@ -18,6 +18,7 @@ import path from 'node:path';
|
|
|
18
18
|
import { fileURLToPath } from 'node:url';
|
|
19
19
|
import { runChecks as run, worstStatus } from "./checks.js";
|
|
20
20
|
import { resolveScript } from "./registry.js";
|
|
21
|
+
import { writeAiInstructions, stripInstructionHeader, AI_LABELS } from "../multi-ai-instructions.js";
|
|
21
22
|
// @ts-ignore — validador legado sem tipos exportados; usado só pela forma { isValid, errors }.
|
|
22
23
|
import { validateProjectStructure } from "../validators/structure-validator.js";
|
|
23
24
|
export { worstStatus };
|
|
@@ -29,16 +30,25 @@ const PLACEHOLDER_RE = /\{\{[A-Z][A-Z0-9_]*\}\}/;
|
|
|
29
30
|
* Gera um projeto num diretório temporário isolado e entrega o caminho ao callback. Limpa o
|
|
30
31
|
* temporário **sempre**, inclusive quando o callback lança — o mesmo contrato do `withCleanInstall`.
|
|
31
32
|
*/
|
|
32
|
-
export async function withGeneratedProject(fn, { root = repoRoot, spawn }) {
|
|
33
|
+
export async function withGeneratedProject(fn, { root = repoRoot, spawn, ai }) {
|
|
33
34
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'forja-smoke-'));
|
|
34
35
|
const projectDir = path.join(dir, 'smoke-proj');
|
|
36
|
+
const aiMode = Array.isArray(ai) && ai.length > 0;
|
|
35
37
|
try {
|
|
36
38
|
// resolveScript acha .ts em dev e .js no dist — cravar .ts quebrava no pacote publicado.
|
|
37
39
|
const gen = resolveScript(root, 'bin/create-memory-nest-kit');
|
|
38
|
-
|
|
40
|
+
// Modo --ai (SPEC-047): só a memória — `create-memory-nest-kit` roda em dev, `init-project.ts`
|
|
41
|
+
// não (hardcoda `.js`) e trata o path como projeto de workspace. As instruções nativas vêm de
|
|
42
|
+
// lib/multi-ai-instructions.ts, a mesma fonte que o gerador usa. Sem rede, sem backend.
|
|
43
|
+
const genArgs = aiMode
|
|
44
|
+
? [gen, projectDir, '--only-memory', '--force']
|
|
45
|
+
: [gen, projectDir, '--force'];
|
|
46
|
+
const res = spawn(process.execPath, genArgs, { cwd: dir });
|
|
39
47
|
if (res.code !== 0) {
|
|
40
48
|
throw new Error(`o gerador saiu com código ${res.code}:\n${(res.stderr || res.stdout).slice(0, 800)}`);
|
|
41
49
|
}
|
|
50
|
+
if (aiMode)
|
|
51
|
+
writeAiInstructions(projectDir, ai, { kitRoot: root });
|
|
42
52
|
return await fn({ projectDir });
|
|
43
53
|
}
|
|
44
54
|
finally {
|
|
@@ -161,7 +171,9 @@ const structure = {
|
|
|
161
171
|
severity: 'critical',
|
|
162
172
|
dependsOn: 'generated',
|
|
163
173
|
probe(env) {
|
|
164
|
-
|
|
174
|
+
// Modo --ai (SPEC-047) é só-memória — não há backend NestJS para validar.
|
|
175
|
+
const includeNest = !(Array.isArray(env.ai) && env.ai.length > 0);
|
|
176
|
+
const report = validateProjectStructure(env.projectDir, { includeNest });
|
|
165
177
|
if (!report.isValid) {
|
|
166
178
|
return {
|
|
167
179
|
status: 'fail',
|
|
@@ -218,8 +230,71 @@ const builds = {
|
|
|
218
230
|
return { status: 'ok', detail: 'backend gerado instala e compila', fix: null };
|
|
219
231
|
},
|
|
220
232
|
};
|
|
233
|
+
/**
|
|
234
|
+
* SPEC-047: no modo `--ai`, as instruções nativas por IA têm que derivar da MESMA fonte. O check
|
|
235
|
+
* prova (a) que cada `<ai>.md` existe, (b) que o corpo — sem as linhas de cabeçalho que diferem
|
|
236
|
+
* entre IAs — é byte-idêntico entre todas, (c) que `models.json` bate com a lista pedida.
|
|
237
|
+
* Sem `--ai` → skipped. É o análogo do `agent-topology`, na saída do gerador.
|
|
238
|
+
*/
|
|
239
|
+
const aiInstructionsCoherent = {
|
|
240
|
+
id: 'ai-instructions',
|
|
241
|
+
title: 'as instruções nativas por IA derivam da mesma fonte (--ai)',
|
|
242
|
+
severity: 'critical',
|
|
243
|
+
dependsOn: 'generated',
|
|
244
|
+
probe(env) {
|
|
245
|
+
const ai = env.ai;
|
|
246
|
+
if (!Array.isArray(ai) || ai.length === 0) {
|
|
247
|
+
return { status: 'skipped', detail: 'sem --ai (o smoke completo não escreve .ia-instructions/)', fix: null };
|
|
248
|
+
}
|
|
249
|
+
const dir = path.join(env.projectDir, '.ia-instructions');
|
|
250
|
+
const bodies = new Map();
|
|
251
|
+
const missing = [];
|
|
252
|
+
for (const name of ai) {
|
|
253
|
+
const file = path.join(dir, `${name}.md`);
|
|
254
|
+
const src = readText(env, file);
|
|
255
|
+
if (src == null) {
|
|
256
|
+
missing.push(`${name}.md`);
|
|
257
|
+
continue;
|
|
258
|
+
}
|
|
259
|
+
bodies.set(name, stripInstructionHeader(src));
|
|
260
|
+
}
|
|
261
|
+
if (missing.length) {
|
|
262
|
+
return { status: 'fail', detail: `instrução ausente: ${missing.join(', ')}`, fix: 'confira writeAiInstructions / a lista --ai' };
|
|
263
|
+
}
|
|
264
|
+
const [first, ...rest] = [...bodies.entries()];
|
|
265
|
+
for (const [name, body] of rest) {
|
|
266
|
+
if (body !== first[1]) {
|
|
267
|
+
return {
|
|
268
|
+
status: 'fail',
|
|
269
|
+
detail: `o corpo de ${name}.md diverge de ${first[0]}.md — as instruções não são a mesma fonte`,
|
|
270
|
+
fix: 'toda IA parte de .gemini-instructions.md; só o cabeçalho muda (lib/multi-ai-instructions.ts)',
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
const modelsRaw = readText(env, path.join(dir, 'models.json'));
|
|
275
|
+
let models;
|
|
276
|
+
try {
|
|
277
|
+
models = JSON.parse(modelsRaw ?? '');
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
return { status: 'fail', detail: 'models.json ausente ou inválido', fix: 'writeAiInstructions deve gerá-lo' };
|
|
281
|
+
}
|
|
282
|
+
if (JSON.stringify(models.fallback_chain) !== JSON.stringify([...ai])) {
|
|
283
|
+
return { status: 'fail', detail: `models.json fallback_chain ${JSON.stringify(models.fallback_chain)} ≠ --ai ${JSON.stringify(ai)}`, fix: 'sincronize a lista' };
|
|
284
|
+
}
|
|
285
|
+
for (const name of ai) {
|
|
286
|
+
if (models.engines?.[name]?.instruction_file !== `.ia-instructions/${name}.md`) {
|
|
287
|
+
return { status: 'fail', detail: `models.json.engines.${name} sem instruction_file correto`, fix: 'writeAiInstructions' };
|
|
288
|
+
}
|
|
289
|
+
if (!(name in AI_LABELS)) {
|
|
290
|
+
return { status: 'fail', detail: `IA desconhecida na lista --ai: ${name} (conhecidas: ${Object.keys(AI_LABELS).join(', ')})`, fix: 'use uma IA suportada' };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return { status: 'ok', detail: `${ai.length} instruções coerentes (mesmo corpo, models.json em dia)`, fix: null };
|
|
294
|
+
},
|
|
295
|
+
};
|
|
221
296
|
/** @type {Check[]} */
|
|
222
|
-
export const SMOKE_CHECKS = [generated, noPlaceholders, jsonValid, structure, gateInherited, builds];
|
|
297
|
+
export const SMOKE_CHECKS = [generated, noPlaceholders, jsonValid, structure, gateInherited, aiInstructionsCoherent, builds];
|
|
223
298
|
export function defaultEnv(overrides = {}) {
|
|
224
299
|
return {
|
|
225
300
|
root: repoRoot,
|
|
@@ -244,7 +319,8 @@ export function defaultEnv(overrides = {}) {
|
|
|
244
319
|
};
|
|
245
320
|
}
|
|
246
321
|
/** Gera um projeto isolado, roda os checks, limpa. */
|
|
247
|
-
export async function runProjectSmoke({ full = false, env: overrides = {} } = {}) {
|
|
248
|
-
const
|
|
249
|
-
|
|
322
|
+
export async function runProjectSmoke({ full = false, ai, env: overrides = {} } = {}) {
|
|
323
|
+
const aiList = ai && ai.length > 0 ? ai : undefined;
|
|
324
|
+
const base = defaultEnv({ full, ...(aiList ? { ai: aiList } : {}), ...overrides });
|
|
325
|
+
return withGeneratedProject(({ projectDir }) => run({ checks: SMOKE_CHECKS, env: { ...base, projectDir } }), { root: base.root, spawn: base.spawn, ai: base.ai });
|
|
250
326
|
}
|