forjajs 4.0.1 → 4.1.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +170 -7
  2. package/DOC-MAP.md +1 -0
  3. package/README.md +10 -2
  4. package/README.pt-BR.md +3 -0
  5. package/dist/apps/cli/src/index.d.ts +18 -1
  6. package/dist/apps/cli/src/index.js +161 -26
  7. package/dist/apps/cli/src/params.d.ts +44 -0
  8. package/dist/apps/cli/src/params.js +123 -0
  9. package/dist/bin/forja.js +234 -13
  10. package/dist/bin/init-project.js +11 -62
  11. package/dist/lib/cli-output.d.ts +29 -0
  12. package/dist/lib/cli-output.js +39 -0
  13. package/dist/lib/core/checks.d.ts +1 -1
  14. package/dist/lib/core/health.d.ts +9 -0
  15. package/dist/lib/core/health.js +9 -0
  16. package/dist/lib/core/project-smoke.d.ts +6 -2
  17. package/dist/lib/core/project-smoke.js +83 -7
  18. package/dist/lib/core/registry.d.ts +38 -571
  19. package/dist/lib/core/registry.js +174 -25
  20. package/dist/lib/core/release.d.ts +1 -571
  21. package/dist/lib/core/release.js +0 -3
  22. package/dist/lib/handoffs-index.d.ts +16 -0
  23. package/dist/lib/handoffs-index.js +29 -0
  24. package/dist/lib/llm/claude-output.d.ts +8 -0
  25. package/dist/lib/llm/claude-output.js +54 -0
  26. package/dist/lib/llm/context.d.ts +22 -0
  27. package/dist/lib/llm/context.js +39 -0
  28. package/dist/lib/llm/session.d.ts +6 -1
  29. package/dist/lib/llm/session.js +12 -2
  30. package/dist/lib/multi-ai-instructions.d.ts +28 -0
  31. package/dist/lib/multi-ai-instructions.js +83 -0
  32. package/dist/lib/orchestrate.d.ts +5 -0
  33. package/dist/lib/orchestrate.js +18 -0
  34. package/dist/lib/specs-index.d.ts +20 -0
  35. package/dist/lib/specs-index.js +51 -0
  36. package/dist/lib/sprint-index.d.ts +15 -0
  37. package/dist/lib/sprint-index.js +34 -0
  38. package/dist/lib/status-model.d.ts +64 -0
  39. package/dist/lib/status-model.js +180 -0
  40. package/dist/packages/evals/src/index.d.ts +2 -0
  41. package/dist/packages/evals/src/index.js +21 -0
  42. package/dist/packages/llm/src/index.d.ts +24 -3
  43. package/dist/packages/llm/src/index.js +51 -5
  44. package/dist/scripts/cost-economy.js +12 -10
  45. package/dist/scripts/drift-check.d.ts +2 -0
  46. package/dist/scripts/drift-check.js +57 -1
  47. package/dist/scripts/engineer.js +7 -4
  48. package/dist/scripts/forja-setup.d.ts +14 -0
  49. package/dist/scripts/forja-setup.js +58 -0
  50. package/dist/scripts/forja-status.d.ts +11 -0
  51. package/dist/scripts/forja-status.js +70 -0
  52. package/dist/scripts/hook-session-start.js +20 -46
  53. package/dist/scripts/llm-fit.js +113 -8
  54. package/dist/scripts/project-smoke.js +13 -3
  55. package/dist/scripts/simulate.js +18 -6
  56. package/dist/scripts/token-economy.js +34 -28
  57. package/dist/scripts/tools-doctor.js +14 -6
  58. package/docs/2x/CLI-CAPABILITIES.md +34 -10
  59. package/docs/agent-operating-contract.md +3 -1
  60. package/docs/cli-first-operacao.md +17 -0
  61. package/docs/contrato-saida-cli.md +79 -0
  62. package/docs/llm-evolution.md +2 -1
  63. package/docs/llm-fit-loop.md +74 -2
  64. package/docs/publishing.md +13 -16
  65. package/docs/quick-reference.md +13 -0
  66. package/docs/roadmap-v4.1.md +199 -0
  67. package/memory/90-decisions/0082-contrato-saida-cli.md +95 -0
  68. package/memory/90-decisions/0083-mcp-cobertura-declarativa.md +103 -0
  69. package/memory/90-decisions/0084-drift-sentinel-fecha.md +79 -0
  70. package/memory/90-decisions/0085-adaptador-claude-paridade.md +85 -0
  71. package/package.json +4 -1
  72. package/specs/cli-intuitiva-v1/plan.md +169 -0
  73. package/specs/cli-intuitiva-v1/spec.md +163 -0
  74. package/specs/cli-intuitiva-v1/tasks.md +224 -0
  75. package/specs/contrato-saida-cli/plan.md +162 -0
  76. package/specs/contrato-saida-cli/spec.md +157 -0
  77. package/specs/contrato-saida-cli/tasks.md +153 -0
  78. package/specs/drift-sentinel/spec.md +17 -8
  79. package/specs/forja-status-caminho-feliz/plan.md +149 -0
  80. package/specs/forja-status-caminho-feliz/spec.md +158 -0
  81. package/specs/forja-status-caminho-feliz/tasks.md +175 -0
  82. package/specs/llm-adaptador-claude/plan.md +117 -0
  83. package/specs/llm-adaptador-claude/spec.md +144 -0
  84. package/specs/llm-adaptador-claude/tasks.md +100 -0
  85. package/specs/llm-benchmark-recomendacao/plan.md +121 -0
  86. package/specs/llm-benchmark-recomendacao/spec.md +141 -0
  87. package/specs/llm-benchmark-recomendacao/tasks.md +88 -0
  88. package/specs/llm-contexto-e-sessoes/plan.md +143 -0
  89. package/specs/llm-contexto-e-sessoes/spec.md +139 -0
  90. package/specs/llm-contexto-e-sessoes/tasks.md +127 -0
  91. package/specs/mcp-cobertura-nucleo/plan.md +158 -0
  92. package/specs/mcp-cobertura-nucleo/spec.md +161 -0
  93. package/specs/mcp-cobertura-nucleo/tasks.md +169 -0
  94. package/specs/projeto-gerado-confiavel/plan.md +148 -0
  95. package/specs/projeto-gerado-confiavel/spec.md +142 -0
  96. 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
- const res = spawn(process.execPath, [gen, projectDir, '--force'], { cwd: dir });
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
- const report = validateProjectStructure(env.projectDir, { includeNest: true });
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 base = defaultEnv({ full, ...overrides });
249
- return withGeneratedProject(({ projectDir }) => run({ checks: SMOKE_CHECKS, env: { ...base, projectDir } }), { root: base.root, spawn: base.spawn });
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
  }