forjajs 4.1.1 → 5.0.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 +2 -2
- package/.gemini-instructions.md +1 -1
- package/.github/copilot-instructions.md +1 -1
- package/.openai-instructions.md +1 -1
- package/CHANGELOG.md +125 -0
- package/DOC-MAP.md +2 -2
- package/README.md +62 -10
- package/README.pt-BR.md +46 -7
- package/boilerplates/01-api-rest/README.md +1 -1
- package/boilerplates/06-clean-arch/README.md +5 -3
- package/boilerplates/06-clean-arch/backend/.oxlintrc.json +10 -0
- package/boilerplates/06-clean-arch/backend/nest-cli.json +8 -0
- package/boilerplates/06-clean-arch/backend/package.json +22 -24
- package/boilerplates/06-clean-arch/backend/src/app.module.ts +4 -4
- package/boilerplates/06-clean-arch/backend/src/main.ts +2 -2
- package/boilerplates/06-clean-arch/backend/src/modules/orders/application/place-order.usecase.ts +4 -4
- package/boilerplates/06-clean-arch/backend/src/modules/orders/application/ship-order.usecase.ts +2 -2
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/order.entity.ts +3 -3
- package/boilerplates/06-clean-arch/backend/src/modules/orders/domain/order.repository.ts +1 -1
- package/boilerplates/06-clean-arch/backend/src/modules/orders/infrastructure/typeorm-order.repository.ts +5 -5
- package/boilerplates/06-clean-arch/backend/src/modules/orders/orders.module.ts +6 -6
- package/boilerplates/06-clean-arch/backend/src/modules/orders/presentation/orders.controller.ts +3 -3
- package/boilerplates/06-clean-arch/backend/src/modules/products/products.controller.ts +1 -1
- package/boilerplates/06-clean-arch/backend/src/modules/products/products.module.ts +2 -2
- package/boilerplates/06-clean-arch/backend/test/orders/place-order.spec.ts +2 -2
- package/boilerplates/06-clean-arch/backend/tsconfig.build.json +15 -0
- package/boilerplates/06-clean-arch/backend/tsconfig.json +24 -10
- package/boilerplates/06-clean-arch/backend/vitest.config.ts +11 -0
- package/boilerplates/06-clean-arch/boilerplate.manifest.json +6 -5
- package/boilerplates/README.md +24 -44
- package/dist/apps/cli/src/index.js +6 -6
- package/dist/apps/dashboard/next.config.d.mts +5 -5
- package/dist/apps/server/src/app.module.js +1 -1
- package/dist/apps/server/src/forja-nest.module.js +1 -1
- package/dist/apps/server/src/index.js +1 -1
- package/dist/apps/server/src/main.js +20 -20
- package/dist/apps/worker/src/main.js +4 -4
- package/dist/bin/create-memory-nest-kit.js +5 -5
- package/dist/bin/forja.js +28 -14
- package/dist/bin/init-project.d.ts +4 -9
- package/dist/bin/init-project.js +126 -182
- package/dist/lib/audit.js +1 -1
- package/dist/lib/context-builder.d.ts +6 -1
- package/dist/lib/context-builder.js +21 -12
- package/dist/lib/core/architecture-gate.js +2 -4
- package/dist/lib/core/checks.d.ts +1 -1
- package/dist/lib/core/drift-gate.js +2 -4
- package/dist/lib/core/gates.js +5 -5
- package/dist/lib/core/health.d.ts +0 -1
- package/dist/lib/core/health.js +33 -7
- package/dist/lib/core/journey.d.ts +30 -0
- package/dist/lib/core/journey.js +142 -0
- package/dist/lib/core/model-pricing.js +3 -5
- package/dist/lib/core/project-smoke.d.ts +6 -2
- package/dist/lib/core/project-smoke.js +60 -61
- package/dist/lib/core/registry.d.ts +1 -12
- package/dist/lib/core/registry.js +42 -32
- package/dist/lib/core/release.d.ts +1 -1
- package/dist/lib/core/release.js +31 -3
- package/dist/lib/core/risk-collect.js +4 -4
- package/dist/lib/drift-sentinel.js +1 -1
- package/dist/lib/generators/memory-generator.d.ts +30 -30
- package/dist/lib/generators/memory-generator.js +19 -8
- package/dist/lib/generators/nest-generator.js +192 -275
- package/dist/lib/generators/readme-generator.js +1 -1
- package/dist/lib/governance-report.js +4 -4
- package/dist/lib/handoffs-index.d.ts +16 -2
- package/dist/lib/handoffs-index.js +32 -5
- package/dist/lib/llm/session.js +1 -1
- package/dist/lib/llm/validation.js +1 -1
- package/dist/lib/memory-audit.js +1 -1
- package/dist/lib/paths.d.ts +39 -0
- package/dist/lib/paths.js +73 -0
- package/dist/lib/project-wiring.d.ts +54 -0
- package/dist/lib/project-wiring.js +391 -0
- package/dist/lib/specs-index.d.ts +1 -0
- package/dist/lib/specs-index.js +22 -3
- package/dist/lib/status-model.js +24 -8
- package/dist/lib/templates.d.ts +24 -0
- package/dist/lib/templates.js +77 -0
- package/dist/lib/validators/structure-validator.js +0 -1
- package/dist/lib/workspace.d.ts +7 -0
- package/dist/lib/workspace.js +33 -3
- package/dist/packages/adapter-git/src/index.js +2 -2
- package/dist/packages/context/src/index.js +1 -1
- package/dist/packages/core/src/index.js +1 -1
- package/dist/packages/evals/src/index.js +1 -1
- package/dist/packages/events/src/index.js +1 -1
- package/dist/packages/graph/src/index.js +1 -1
- package/dist/packages/mcp/src/index.d.ts +1 -1
- package/dist/packages/observability/src/index.js +1 -1
- package/dist/packages/orchestration/src/index.js +1 -1
- package/dist/packages/planner/src/index.js +1 -1
- package/dist/packages/policy/src/index.js +1 -1
- package/dist/packages/runtime/src/index.js +1 -1
- package/dist/packages/sandbox/src/index.js +1 -1
- package/dist/packages/validator/src/index.js +1 -1
- package/dist/scripts/adr.js +4 -4
- package/dist/scripts/agent-harness.js +30 -23
- package/dist/scripts/agent-router.js +22 -5
- package/dist/scripts/agent.js +5 -5
- package/dist/scripts/architecture.js +6 -6
- package/dist/scripts/audit-query.js +1 -1
- package/dist/scripts/audit-sync.js +1 -1
- package/dist/scripts/build-smart-context.d.ts +19 -1
- package/dist/scripts/build-smart-context.js +84 -68
- package/dist/scripts/check-standards.js +8 -3
- package/dist/scripts/code-context.js +1 -1
- package/dist/scripts/compress-memory.js +3 -2
- package/dist/scripts/compress-project-memory.js +2 -2
- package/dist/scripts/context-ops.js +13 -5
- package/dist/scripts/cost-economy.js +4 -4
- package/dist/scripts/demo-autonomy.js +11 -11
- package/dist/scripts/demo-workspace.js +12 -4
- package/dist/scripts/dev.js +8 -7
- package/dist/scripts/drift-check.js +5 -5
- package/dist/scripts/engineer.js +11 -11
- package/dist/scripts/evidence.js +4 -4
- package/dist/scripts/extract-global-knowledge.js +6 -4
- package/dist/scripts/forja-setup.js +2 -1
- package/dist/scripts/forja-status.d.ts +1 -1
- package/dist/scripts/forja-status.js +31 -3
- package/dist/scripts/gates.js +1 -1
- package/dist/scripts/generate-dashboard.js +6 -4
- package/dist/scripts/governance-dashboard.js +2 -2
- package/dist/scripts/hook-session-start.js +18 -9
- package/dist/scripts/hook-user-prompt.js +3 -2
- package/dist/scripts/incident.js +4 -4
- package/dist/scripts/llm-fit.js +11 -11
- package/dist/scripts/memory-audit.js +1 -1
- package/dist/scripts/memory-schema.js +3 -2
- package/dist/scripts/orchestrate.js +4 -5
- package/dist/scripts/project-smoke.js +13 -2
- package/dist/scripts/project-templates.d.ts +1 -0
- package/dist/scripts/project-templates.js +20 -0
- package/dist/scripts/project-upgrade.d.ts +13 -0
- package/dist/scripts/project-upgrade.js +107 -40
- package/dist/scripts/project-wire.d.ts +8 -0
- package/dist/scripts/project-wire.js +55 -0
- package/dist/scripts/provenance.js +3 -3
- package/dist/scripts/query-universal-memory.js +7 -4
- package/dist/scripts/release-check.js +1 -1
- package/dist/scripts/risk.js +4 -4
- package/dist/scripts/simulate.js +9 -9
- package/dist/scripts/spec-cli.d.ts +1 -0
- package/dist/scripts/spec-cli.js +25 -5
- package/dist/scripts/sprint-manager.js +21 -8
- package/dist/scripts/sync-universal-memory.js +50 -27
- package/dist/scripts/token-benchmark.js +4 -3
- package/dist/scripts/token-economy.js +4 -3
- package/dist/scripts/tools-doctor.d.ts +1 -1
- package/dist/scripts/tools-doctor.js +25 -3
- package/docs/GUIA-ONBOARDING-EXECUTIVO.md +1 -2
- package/docs/GUIA-ONBOARDING-OPERACIONAL-PAPEIS.md +5 -6
- package/docs/GUIA-ONBOARDING-PROJETO.md +7 -9
- package/docs/glossary.md +4 -4
- package/docs/init-project.md +88 -444
- package/docs/manual-operacional-cli-sdd-gsd.md +1 -1
- package/docs/modos-de-operacao.md +1 -1
- package/docs/processo-projeto.md +14 -11
- package/docs/produto/roteiro-demo.md +15 -18
- package/docs/publishing.md +5 -0
- package/docs/quick-reference.md +15 -23
- package/docs/structure.md +16 -30
- package/lib/core/model-pricing.json +19 -0
- package/memory/30-projects/README.md +1 -1
- package/memory/90-decisions/0022-congelar-dashboard-web.md +1 -1
- package/memory/90-decisions/0086-projeto-conectado-e-jornada-como-gate.md +95 -0
- package/memory/90-decisions/0087-remover-dashboard-legado.md +35 -0
- package/memory/90-decisions/0088-templates-validados.md +55 -0
- package/package.json +25 -25
- package/templates/project/AGENTS.md +75 -0
- package/templates/project/CLAUDE.md +9 -0
- package/templates/project/agents/context-engineer.md +15 -0
- package/templates/project/agents/governance.md +15 -0
- package/templates/project/agents/marketing.md +15 -0
- package/templates/project/agents/orchestrator.md +15 -0
- package/templates/project/agents/product.md +15 -0
- package/templates/project/agents/sdd-architect.md +15 -0
- package/dist/lib/multi-ai-instructions.d.ts +0 -28
- package/dist/lib/multi-ai-instructions.js +0 -83
package/dist/scripts/simulate.js
CHANGED
|
@@ -22,15 +22,15 @@ import os from 'node:os';
|
|
|
22
22
|
import path from 'node:path';
|
|
23
23
|
import { randomUUID } from 'node:crypto';
|
|
24
24
|
import Database from 'better-sqlite3';
|
|
25
|
-
import { checkConstitution } from
|
|
26
|
-
import { assessRisk } from
|
|
27
|
-
import { SandboxEngine, InMemorySandboxStore } from
|
|
28
|
-
import { GitWorktreeBackend, SpawnCommandRunner } from
|
|
29
|
-
import { GitGraphDocumentSource } from
|
|
30
|
-
import { GraphIndexer, GraphLoop } from
|
|
31
|
-
import { SqliteGraphStore, SqliteMigrationRunner } from
|
|
32
|
-
import { buildRiskInput, changedFiles } from
|
|
33
|
-
import { emitOk, emitError, emitRejected } from
|
|
25
|
+
import { checkConstitution } from '../packages/engineering/architecture/src/index.js';
|
|
26
|
+
import { assessRisk } from '../packages/engineering/risk/src/index.js';
|
|
27
|
+
import { SandboxEngine, InMemorySandboxStore } from '../packages/sandbox/src/index.js';
|
|
28
|
+
import { GitWorktreeBackend, SpawnCommandRunner } from '../packages/adapter-git/src/index.js';
|
|
29
|
+
import { GitGraphDocumentSource } from '../packages/adapter-git/src/index.js';
|
|
30
|
+
import { GraphIndexer, GraphLoop } from '../packages/graph/src/index.js';
|
|
31
|
+
import { SqliteGraphStore, SqliteMigrationRunner } from '../packages/adapter-sqlite/src/index.js';
|
|
32
|
+
import { buildRiskInput, changedFiles } from '../lib/core/risk-collect.js';
|
|
33
|
+
import { emitOk, emitError, emitRejected } from '../lib/cli-output.js';
|
|
34
34
|
const CONSTITUTION_PATH = '.context/architecture/constitution.json';
|
|
35
35
|
function repoRoot() {
|
|
36
36
|
return process.env.FORJA_GRAPH_ROOT ?? process.cwd();
|
package/dist/scripts/spec-cli.js
CHANGED
|
@@ -71,7 +71,10 @@ function fillTemplate(tpl, vars) {
|
|
|
71
71
|
.replace(/{{FEATURE}}/g, vars.feature)
|
|
72
72
|
.replace(/{{ID}}/g, vars.id)
|
|
73
73
|
.replace(/{{OWNER}}/g, vars.owner || '—')
|
|
74
|
-
.replace(/{{DATE}}/g, vars.date)
|
|
74
|
+
.replace(/{{DATE}}/g, vars.date)
|
|
75
|
+
// O template lista os status possíveis; o artefato nasce `draft` (antes nascia com a lista
|
|
76
|
+
// inteira, e o índice da memória e o painel ops a exibiam como se fosse o status).
|
|
77
|
+
.replace(/^(-\s*\*\*Status\*\*:\s*)draft(\s*\|[^\n]*)$/m, '$1draft');
|
|
75
78
|
}
|
|
76
79
|
function readStatus(filePath) {
|
|
77
80
|
if (!fs.existsSync(filePath))
|
|
@@ -147,18 +150,35 @@ function ensureSpecVersioned(slug) {
|
|
|
147
150
|
out(` ⚠ não foi possível escrever .gitignore — adicione "!/specs/${slug}" manualmente.`);
|
|
148
151
|
}
|
|
149
152
|
}
|
|
153
|
+
export function nextSpecId(dir = specsDir) {
|
|
154
|
+
let max = 0;
|
|
155
|
+
if (fs.existsSync(dir)) {
|
|
156
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
157
|
+
if (!entry.isDirectory())
|
|
158
|
+
continue;
|
|
159
|
+
const spec = path.join(dir, entry.name, 'spec.md');
|
|
160
|
+
const m = fs.existsSync(spec) ? fs.readFileSync(spec, 'utf8').match(/\*\*ID\*\*:\s*SPEC-(\d+)/) : null;
|
|
161
|
+
if (m)
|
|
162
|
+
max = Math.max(max, Number(m[1]));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return `SPEC-${String(max + 1).padStart(3, '0')}`;
|
|
166
|
+
}
|
|
150
167
|
function cmdNew(feature) {
|
|
151
168
|
if (!feature)
|
|
152
|
-
fail('uso: spec:new <feature>');
|
|
169
|
+
fail('uso: forja spec:new <feature>');
|
|
153
170
|
const slug = slugify(feature);
|
|
154
171
|
const dir = path.join(specsDir, slug);
|
|
155
172
|
if (fs.existsSync(dir))
|
|
156
173
|
fail(`spec ${slug} já existe em ${dir}`);
|
|
174
|
+
// Maior ID existente + 1, calculado ANTES do mkdir: contar pastas depois de criá-la fazia a
|
|
175
|
+
// primeira spec de um projeto nascer SPEC-002, e remover uma spec gerava IDs repetidos.
|
|
176
|
+
const id = nextSpecId();
|
|
157
177
|
fs.mkdirSync(dir, { recursive: true });
|
|
158
178
|
const tpl = readTemplate('spec');
|
|
159
179
|
const content = fillTemplate(tpl, {
|
|
160
180
|
feature: slug,
|
|
161
|
-
id
|
|
181
|
+
id,
|
|
162
182
|
owner: process.env.USER || '—',
|
|
163
183
|
date: todayISO(),
|
|
164
184
|
});
|
|
@@ -169,7 +189,7 @@ function cmdNew(feature) {
|
|
|
169
189
|
}
|
|
170
190
|
function cmdNextStage(stage, feature) {
|
|
171
191
|
if (!feature)
|
|
172
|
-
fail(`uso: spec:${stage} <feature>`);
|
|
192
|
+
fail(`uso: forja spec:${stage} <feature>`);
|
|
173
193
|
const slug = slugify(feature);
|
|
174
194
|
const dir = path.join(specsDir, slug);
|
|
175
195
|
if (!fs.existsSync(dir))
|
|
@@ -237,7 +257,7 @@ function cmdCheck(feature) {
|
|
|
237
257
|
}
|
|
238
258
|
function cmdSetStatus(feature, stage, status) {
|
|
239
259
|
if (!feature || !stage || !status)
|
|
240
|
-
fail('uso: spec:set-status <feature> <spec|plan|tasks> <status>');
|
|
260
|
+
fail('uso: forja spec:set-status <feature> <spec|plan|tasks> <status>');
|
|
241
261
|
if (!STAGES.includes(stage))
|
|
242
262
|
fail(`stage inválido: ${stage}. Use: ${STAGES.join('|')}`);
|
|
243
263
|
if (!VALID_STATUSES.includes(status))
|
|
@@ -1,26 +1,39 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { resolveProject, initWorkspace } from
|
|
4
|
+
import { resolveProject, initWorkspace, isInsideFrameworkRepo } from '../lib/workspace.js';
|
|
5
|
+
import { pkgRoot } from '../lib/paths.js';
|
|
5
6
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
7
|
const __dirname = path.dirname(__filename);
|
|
7
|
-
const
|
|
8
|
+
const frameworkRoot = pkgRoot;
|
|
9
|
+
const cwd = path.resolve(process.cwd());
|
|
8
10
|
const [cmd, projectArg, ...args] = process.argv.slice(2);
|
|
9
11
|
if (!cmd) {
|
|
10
|
-
console.log('Uso:
|
|
12
|
+
console.log('Uso: forja sprint:<start|status|complete> [projeto|.|root] [args]');
|
|
11
13
|
console.log(' . ou root = framework raiz; outro nome = projeto no workspace');
|
|
12
14
|
process.exit(0);
|
|
13
15
|
}
|
|
14
16
|
const project = projectArg || '.';
|
|
15
17
|
let projectDir;
|
|
16
|
-
if (project === '
|
|
17
|
-
projectDir =
|
|
18
|
+
if (project === 'root') {
|
|
19
|
+
projectDir = frameworkRoot;
|
|
20
|
+
}
|
|
21
|
+
else if (project === '.') {
|
|
22
|
+
if (isInsideFrameworkRepo(cwd)) {
|
|
23
|
+
projectDir = frameworkRoot;
|
|
24
|
+
}
|
|
25
|
+
else if (fs.existsSync(path.join(cwd, 'memory/40-delivery')) || fs.existsSync(path.join(cwd, 'package.json'))) {
|
|
26
|
+
projectDir = cwd;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
projectDir = frameworkRoot;
|
|
30
|
+
}
|
|
18
31
|
}
|
|
19
32
|
else {
|
|
20
33
|
initWorkspace();
|
|
21
34
|
projectDir = resolveProject(project);
|
|
22
35
|
}
|
|
23
|
-
const projectLabel = projectDir ===
|
|
36
|
+
const projectLabel = projectDir === frameworkRoot ? 'framework-root' : (project === '.' ? path.basename(projectDir) : project);
|
|
24
37
|
if (!fs.existsSync(projectDir)) {
|
|
25
38
|
console.error(`Projeto nao encontrado: ${project}`);
|
|
26
39
|
process.exit(1);
|
|
@@ -164,11 +177,11 @@ ${pending.length ? pending.map((item) => `- ${item}`).join('\n') : '- Nenhuma'}
|
|
|
164
177
|
- Nova sprint ainda não iniciada.
|
|
165
178
|
|
|
166
179
|
## Próximo passo
|
|
167
|
-
- Execute: node scripts/sprint-manager.js start ${projectDir ===
|
|
180
|
+
- Execute: node scripts/sprint-manager.js start ${projectDir === frameworkRoot ? '' : project}
|
|
168
181
|
`;
|
|
169
182
|
fs.writeFileSync(sprintFile, resetSprint, 'utf8');
|
|
170
183
|
console.log(`Sprint encerrada para ${projectLabel}.`);
|
|
171
|
-
console.log(`Relatorio: ${path.relative(
|
|
184
|
+
console.log(`Relatorio: ${path.relative(projectDir, reportFile)}`);
|
|
172
185
|
if (pending.length > 0) {
|
|
173
186
|
console.log(`${pending.length} pendencia(s) devolvida(s) para Alta Prioridade no backlog.`);
|
|
174
187
|
}
|
|
@@ -3,14 +3,18 @@ import path from 'node:path';
|
|
|
3
3
|
import crypto from 'node:crypto';
|
|
4
4
|
import Database from 'better-sqlite3';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { ensureSchema, getDbPath } from
|
|
7
|
-
import { initWorkspace, getForjaMode, getWorkspaceRoot, getProjectsDir, getWorkspaceSpecsDir, getWorkspaceProjectsMemoryDir, } from
|
|
6
|
+
import { ensureSchema, getDbPath } from './memory-schema.js';
|
|
7
|
+
import { initWorkspace, getForjaMode, getWorkspaceRoot, getProjectsDir, getWorkspaceSpecsDir, getWorkspaceProjectsMemoryDir, listProjects, } from '../lib/workspace.js';
|
|
8
|
+
import { pkgRoot } from '../lib/paths.js';
|
|
8
9
|
const __filename = fileURLToPath(import.meta.url);
|
|
9
10
|
const __dirname = path.dirname(__filename);
|
|
10
|
-
const root =
|
|
11
|
+
const root = pkgRoot;
|
|
11
12
|
initWorkspace();
|
|
12
13
|
const mode = getForjaMode();
|
|
13
14
|
const operationRoot = getWorkspaceRoot();
|
|
15
|
+
// Fonte do conteúdo indexado: no modo embedded é o PROJETO, nunca o pacote. Ler specs/, boilerplates/
|
|
16
|
+
// e design-md/ de `root` (o pacote) vazava as specs do framework para a memória do produto.
|
|
17
|
+
const contentRoot = mode === 'embedded' ? operationRoot : root;
|
|
14
18
|
const dbPath = getDbPath();
|
|
15
19
|
const args = process.argv.slice(2);
|
|
16
20
|
const projectArgIndex = args.indexOf('--project');
|
|
@@ -60,9 +64,21 @@ function walk(dir, out = []) {
|
|
|
60
64
|
if (entry.name === 'node_modules' || entry.name === '.git' || entry.name === '.memory')
|
|
61
65
|
continue;
|
|
62
66
|
const abs = path.join(dir, entry.name);
|
|
63
|
-
|
|
67
|
+
let isDir = entry.isDirectory();
|
|
68
|
+
let isFile = entry.isFile();
|
|
69
|
+
if (entry.isSymbolicLink()) {
|
|
70
|
+
try {
|
|
71
|
+
const stat = fs.statSync(abs);
|
|
72
|
+
isDir = stat.isDirectory();
|
|
73
|
+
isFile = stat.isFile();
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (isDir)
|
|
64
80
|
walk(abs, out);
|
|
65
|
-
else if (
|
|
81
|
+
else if (isFile && entry.name.endsWith('.md'))
|
|
66
82
|
out.push(abs);
|
|
67
83
|
}
|
|
68
84
|
return out;
|
|
@@ -77,7 +93,7 @@ const upsertProject = db.prepare('INSERT INTO projects (name, path, created_at)
|
|
|
77
93
|
// Sem ele restaria `lastInsertRowid`, que num upsert-que-atualizou guarda o id do
|
|
78
94
|
// último INSERT da conexão — um id alheio, e o FTS acabava indexando o conteúdo de
|
|
79
95
|
// um documento sob o node_id de outro (ADR-0021).
|
|
80
|
-
const upsertNode = db.prepare('INSERT INTO memory_nodes (project_id, path, kind, title, content, content_hash, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(path) DO UPDATE SET title=excluded.title, content=excluded.content, content_hash=excluded.content_hash, updated_at=excluded.updated_at RETURNING id');
|
|
96
|
+
const upsertNode = db.prepare('INSERT INTO memory_nodes (project_id, path, kind, title, content, content_hash, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(path) DO UPDATE SET project_id=excluded.project_id, kind=excluded.kind, title=excluded.title, content=excluded.content, content_hash=excluded.content_hash, updated_at=excluded.updated_at RETURNING id');
|
|
81
97
|
const getProjectId = db.prepare('SELECT id FROM projects WHERE name = ?');
|
|
82
98
|
const deleteFts = db.prepare('DELETE FROM search_idx WHERE node_id = ?');
|
|
83
99
|
const insertFts = db.prepare('INSERT INTO search_idx (node_id, title, content) VALUES (?, ?, ?)');
|
|
@@ -131,7 +147,7 @@ function extractSection(content, heading, maxChars = 1200) {
|
|
|
131
147
|
return match ? match[1].trim().slice(0, maxChars) : '';
|
|
132
148
|
}
|
|
133
149
|
function summarizeReadme(relPath) {
|
|
134
|
-
const full = path.join(
|
|
150
|
+
const full = path.join(contentRoot, relPath);
|
|
135
151
|
if (!fs.existsSync(full))
|
|
136
152
|
return null;
|
|
137
153
|
const content = fs.readFileSync(full, 'utf8');
|
|
@@ -143,7 +159,7 @@ function summarizeReadme(relPath) {
|
|
|
143
159
|
.slice(0, 450);
|
|
144
160
|
}
|
|
145
161
|
function readJson(relPath) {
|
|
146
|
-
const full = path.join(
|
|
162
|
+
const full = path.join(contentRoot, relPath);
|
|
147
163
|
if (!fs.existsSync(full))
|
|
148
164
|
return null;
|
|
149
165
|
try {
|
|
@@ -154,7 +170,7 @@ function readJson(relPath) {
|
|
|
154
170
|
}
|
|
155
171
|
}
|
|
156
172
|
function syncSpecSummaries() {
|
|
157
|
-
const specsDir = path.join(
|
|
173
|
+
const specsDir = path.join(contentRoot, 'specs');
|
|
158
174
|
if (!fs.existsSync(specsDir))
|
|
159
175
|
return;
|
|
160
176
|
let count = 0;
|
|
@@ -163,7 +179,7 @@ function syncSpecSummaries() {
|
|
|
163
179
|
continue;
|
|
164
180
|
const slug = entry.name;
|
|
165
181
|
const rel = path.join('specs', slug, 'spec.md');
|
|
166
|
-
const full = path.join(
|
|
182
|
+
const full = path.join(contentRoot, rel);
|
|
167
183
|
if (!fs.existsSync(full))
|
|
168
184
|
continue;
|
|
169
185
|
const content = fs.readFileSync(full, 'utf8');
|
|
@@ -181,7 +197,7 @@ function syncSpecSummaries() {
|
|
|
181
197
|
}
|
|
182
198
|
function syncAssetCatalog() {
|
|
183
199
|
const assets = [];
|
|
184
|
-
const boilerRoot = path.join(
|
|
200
|
+
const boilerRoot = path.join(contentRoot, 'boilerplates');
|
|
185
201
|
if (fs.existsSync(boilerRoot)) {
|
|
186
202
|
for (const entry of fs.readdirSync(boilerRoot, { withFileTypes: true })) {
|
|
187
203
|
if (!entry.isDirectory())
|
|
@@ -195,7 +211,7 @@ function syncAssetCatalog() {
|
|
|
195
211
|
assets.push({ type: 'boilerplate', name: entry.name, path: rel, summary, tags });
|
|
196
212
|
}
|
|
197
213
|
}
|
|
198
|
-
const designRoot = path.join(
|
|
214
|
+
const designRoot = path.join(contentRoot, 'design-md');
|
|
199
215
|
if (fs.existsSync(designRoot)) {
|
|
200
216
|
for (const entry of fs.readdirSync(designRoot, { withFileTypes: true })) {
|
|
201
217
|
if (!entry.isDirectory())
|
|
@@ -216,7 +232,10 @@ function syncAssetCatalog() {
|
|
|
216
232
|
}
|
|
217
233
|
function syncFiles(files, projectId = null) {
|
|
218
234
|
for (const abs of files) {
|
|
219
|
-
|
|
235
|
+
let rel = path.relative(contentRoot, abs);
|
|
236
|
+
if (rel.startsWith('..')) {
|
|
237
|
+
rel = path.relative(operationRoot, abs);
|
|
238
|
+
}
|
|
220
239
|
const raw = fs.readFileSync(abs, 'utf8');
|
|
221
240
|
const hash = crypto.createHash('sha256').update(raw).digest('hex');
|
|
222
241
|
const titleMatch = raw.match(/^#\s+(.+)$/m);
|
|
@@ -234,10 +253,12 @@ function syncFiles(files, projectId = null) {
|
|
|
234
253
|
// 1. Sincronizar Memória/Docs/Prompts Globais
|
|
235
254
|
if (syncGlobal) {
|
|
236
255
|
log('Sincronizando Memória Global...', 'info');
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
...walk(path.join(
|
|
256
|
+
// Embedded: memória/docs/prompts SÃO do projeto — indexados no passo 2 com o project_id. Indexá-los
|
|
257
|
+
// aqui também (como globais, project_id NULL) fazia o modo domain/task do context:smart não achar nada.
|
|
258
|
+
const globalFiles = mode === 'embedded' ? [] : [
|
|
259
|
+
...walk(path.join(contentRoot, 'memory')),
|
|
260
|
+
...walk(path.join(contentRoot, 'docs')),
|
|
261
|
+
...walk(path.join(contentRoot, 'prompts')),
|
|
241
262
|
];
|
|
242
263
|
syncFiles(globalFiles);
|
|
243
264
|
syncSpecSummaries();
|
|
@@ -252,26 +273,28 @@ if (syncProjects && mode === 'embedded') {
|
|
|
252
273
|
syncFiles([
|
|
253
274
|
...walk(path.join(operationRoot, 'memory')),
|
|
254
275
|
...walk(path.join(operationRoot, 'docs')),
|
|
276
|
+
...walk(path.join(operationRoot, 'prompts')),
|
|
255
277
|
...walk(path.join(operationRoot, 'specs')),
|
|
256
278
|
...walk(path.join(operationRoot, 'design-md')),
|
|
257
279
|
], pid);
|
|
258
280
|
}
|
|
259
281
|
else if (syncProjects && fs.existsSync(projectsDir)) {
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
.filter(e => !onlyProject || e.name === onlyProject);
|
|
263
|
-
if (onlyProject && projects.length === 0) {
|
|
282
|
+
const projectNames = listProjects().filter((name) => !onlyProject || name === onlyProject);
|
|
283
|
+
if (onlyProject && projectNames.length === 0) {
|
|
264
284
|
log(`Projeto nao encontrado para sync: ${onlyProject}`, 'warn');
|
|
265
285
|
}
|
|
266
|
-
for (const
|
|
267
|
-
log(`Sincronizando Projeto: ${
|
|
268
|
-
const projectPath = path.join(projectsDir,
|
|
269
|
-
upsertProject.run(
|
|
270
|
-
const pid = getProjectId.get(
|
|
286
|
+
for (const name of projectNames) {
|
|
287
|
+
log(`Sincronizando Projeto: ${name}...`, 'info');
|
|
288
|
+
const projectPath = path.join(projectsDir, name);
|
|
289
|
+
upsertProject.run(name, projectPath, now);
|
|
290
|
+
const pid = getProjectId.get(name).id;
|
|
271
291
|
// Indexa memória, documentação, spec SDD e referências de design do projeto (somente .md)
|
|
272
292
|
const projectMemFiles = walk(path.join(projectPath, 'memory'));
|
|
273
293
|
const projectDocsFiles = walk(path.join(projectPath, 'docs'));
|
|
274
|
-
const projectSpecFiles =
|
|
294
|
+
const projectSpecFiles = [
|
|
295
|
+
...walk(path.join(projectPath, 'specs')),
|
|
296
|
+
...walk(path.join(getWorkspaceSpecsDir(), name)),
|
|
297
|
+
];
|
|
275
298
|
const projectDesignFiles = walk(path.join(projectPath, 'design-md'));
|
|
276
299
|
syncFiles([...projectMemFiles, ...projectDocsFiles, ...projectSpecFiles, ...projectDesignFiles], pid);
|
|
277
300
|
}
|
|
@@ -11,11 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import fs from 'node:fs';
|
|
13
13
|
import path from 'node:path';
|
|
14
|
-
import ContextBuilder from
|
|
14
|
+
import ContextBuilder from '../lib/context-builder.js';
|
|
15
15
|
import { fileURLToPath } from 'node:url';
|
|
16
|
-
import { getDbPath, ensureSchema } from
|
|
16
|
+
import { getDbPath, ensureSchema } from './memory-schema.js';
|
|
17
|
+
import { pkgRoot } from '../lib/paths.js';
|
|
17
18
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
18
|
-
const root =
|
|
19
|
+
const root = pkgRoot;
|
|
19
20
|
/**
|
|
20
21
|
* Estimar tokens (1KB ≈ 250 tokens, aproximação)
|
|
21
22
|
*/
|
|
@@ -20,14 +20,15 @@
|
|
|
20
20
|
import fs from 'node:fs';
|
|
21
21
|
import path from 'node:path';
|
|
22
22
|
import { fileURLToPath } from 'node:url';
|
|
23
|
-
import { domainsOf, buildContextPack } from
|
|
24
|
-
import { emitOk } from
|
|
23
|
+
import { domainsOf, buildContextPack } from '../lib/code-context.js';
|
|
24
|
+
import { emitOk } from '../lib/cli-output.js';
|
|
25
|
+
import { pkgRoot } from '../lib/paths.js';
|
|
25
26
|
const JSON_MODE = process.argv.includes('--json');
|
|
26
27
|
/** No modo `--json` o stdout é só o objeto final (ADR-0082); o texto de análise é suprimido. */
|
|
27
28
|
const say = (line = '') => { if (!JSON_MODE)
|
|
28
29
|
console.log(line); };
|
|
29
30
|
const __filename = fileURLToPath(import.meta.url);
|
|
30
|
-
const root =
|
|
31
|
+
const root = pkgRoot;
|
|
31
32
|
/**
|
|
32
33
|
* Modo `--project <path>`: mede o eixo memória nos domínios REAIS do usuário, não na fixture. Para
|
|
33
34
|
* cada domínio, o mapa (`context.md`) vs ler todo o código da fatia — o número fica dele.
|
|
@@ -15,17 +15,22 @@
|
|
|
15
15
|
* Diagnostica e prescreve; não conserta. Rodar `npm rebuild` sem consentimento é a classe de
|
|
16
16
|
* risco oposta à que este comando existe para fechar.
|
|
17
17
|
*
|
|
18
|
-
* Uso:
|
|
18
|
+
* Uso: forja tools:doctor
|
|
19
19
|
*/
|
|
20
20
|
import { spawnSync } from 'node:child_process';
|
|
21
|
-
import
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { runChecks, worstStatus, bucketFor, BUCKET_LABEL } from '../lib/core/health.js';
|
|
24
|
+
import { COMMANDS } from '../lib/core/registry.js';
|
|
25
|
+
import { checkProjectWiring } from '../lib/project-wiring.js';
|
|
26
|
+
import { isInsideFrameworkRepo } from '../lib/workspace.js';
|
|
22
27
|
const TOOLS = [
|
|
23
28
|
{
|
|
24
29
|
name: 'codegraph',
|
|
25
30
|
probe: ['codegraph', ['--version']],
|
|
26
31
|
role: 'Code intelligence: chamadores, blast radius, mapa de impacto (ADR-0017).',
|
|
27
32
|
install: 'npm i -g @codegraph/cli',
|
|
28
|
-
gate: '
|
|
33
|
+
gate: 'forja code:check / code:impact',
|
|
29
34
|
},
|
|
30
35
|
{
|
|
31
36
|
name: 'gitleaks',
|
|
@@ -104,11 +109,28 @@ function printTools() {
|
|
|
104
109
|
console.log(`${installed}/${TOOLS.length} ferramentas disponíveis.`);
|
|
105
110
|
console.log('Ferramentas ausentes apenas desativam seus gates — o fluxo nunca trava por elas.\n');
|
|
106
111
|
}
|
|
112
|
+
/** Num projeto (fora do repo do framework): a IA, os hooks e o MCP estão ligados a ele? */
|
|
113
|
+
function printProject() {
|
|
114
|
+
const cwd = process.cwd();
|
|
115
|
+
if (isInsideFrameworkRepo(cwd) || !fs.existsSync(path.join(cwd, 'AGENTS.md')))
|
|
116
|
+
return null;
|
|
117
|
+
console.log('Projeto — a IA enxerga o Forja aqui? (forja project:wire --check)\n');
|
|
118
|
+
const checks = checkProjectWiring(cwd, { commands: COMMANDS });
|
|
119
|
+
for (const c of checks)
|
|
120
|
+
console.log(`${TAG[c.status]} ${c.id.padEnd(13)} ${c.detail}`);
|
|
121
|
+
console.log('');
|
|
122
|
+
return checks.some((c) => c.status === 'fail') ? 'fail' : checks.some((c) => c.status === 'warn') ? 'warn' : 'ok';
|
|
123
|
+
}
|
|
107
124
|
async function main() {
|
|
108
125
|
console.log('\nForja doctor\n');
|
|
109
126
|
const core = await runChecks();
|
|
110
127
|
printCore(core);
|
|
128
|
+
const project = printProject();
|
|
111
129
|
printTools();
|
|
130
|
+
if (project === 'fail') {
|
|
131
|
+
console.log('Projeto desconectado da IA — corrija com: forja project:wire');
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
112
134
|
// Só o núcleo decide o exit code. Ferramenta ausente nunca reprova — o contrato do ADR-0018
|
|
113
135
|
// é preservado à risca.
|
|
114
136
|
const verdict = worstStatus(core);
|
|
@@ -16,7 +16,7 @@ Implementar com qualidade, manter contexto atualizado e reduzir retrabalho.
|
|
|
16
16
|
- Rodar sync da memória operacional:
|
|
17
17
|
```bash
|
|
18
18
|
cd backend
|
|
19
|
-
|
|
19
|
+
forja sync:universal
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
### Critério de Pronto (DEV)
|
|
@@ -99,15 +99,14 @@ Se qualquer item for “não”: refinar step antes da execução.
|
|
|
99
99
|
```bash
|
|
100
100
|
cd backend
|
|
101
101
|
npm install
|
|
102
|
-
|
|
103
|
-
npm run memory:db:sync
|
|
102
|
+
forja sync:universal
|
|
104
103
|
```
|
|
105
104
|
|
|
106
105
|
### Consulta de contexto
|
|
107
106
|
```bash
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
forja query:universal "auth" 10
|
|
108
|
+
forja agent:route list
|
|
109
|
+
forja adr:list
|
|
111
110
|
```
|
|
112
111
|
|
|
113
112
|
### Registrar handoff
|
|
@@ -83,9 +83,8 @@ Checagem esperada:
|
|
|
83
83
|
Ainda dentro de `backend/`:
|
|
84
84
|
|
|
85
85
|
```bash
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
npm run memory:db:query -- "search" "contexto" 10
|
|
86
|
+
forja sync:universal
|
|
87
|
+
forja query:universal "contexto" 10
|
|
89
88
|
```
|
|
90
89
|
|
|
91
90
|
O que isso faz:
|
|
@@ -224,12 +223,12 @@ Próximos passos:
|
|
|
224
223
|
1. Sincronizar memória:
|
|
225
224
|
```bash
|
|
226
225
|
cd backend
|
|
227
|
-
|
|
226
|
+
forja sync:universal
|
|
228
227
|
```
|
|
229
228
|
|
|
230
229
|
2. Buscar contexto da tarefa:
|
|
231
230
|
```bash
|
|
232
|
-
|
|
231
|
+
forja query:universal "tema da tarefa" 10
|
|
233
232
|
```
|
|
234
233
|
|
|
235
234
|
3. Executar step
|
|
@@ -242,7 +241,7 @@ npm run memory:db:query -- "search" "tema da tarefa" 10
|
|
|
242
241
|
- Evitar: aplicar seção 7 (questionamento obrigatório).
|
|
243
242
|
|
|
244
243
|
- Erro: esquecer atualização de memória.
|
|
245
|
-
- Evitar: sempre rodar `
|
|
244
|
+
- Evitar: sempre rodar `forja sync:universal` após mudanças relevantes.
|
|
246
245
|
|
|
247
246
|
- Erro: deploy sem rollback claro.
|
|
248
247
|
- Evitar: incluir rollback como item obrigatório no DoD.
|
|
@@ -259,12 +258,11 @@ npx github:SEU_USUARIO/create-memory-nest-kit nome-do-projeto
|
|
|
259
258
|
# setup inicial
|
|
260
259
|
cd nome-do-projeto/backend
|
|
261
260
|
npm install
|
|
262
|
-
|
|
263
|
-
npm run memory:db:sync
|
|
261
|
+
forja sync:universal
|
|
264
262
|
npm run start:dev
|
|
265
263
|
|
|
266
264
|
# consultar contexto
|
|
267
|
-
|
|
265
|
+
forja query:universal "auth" 10
|
|
268
266
|
|
|
269
267
|
# registrar handoff (na raiz do projeto)
|
|
270
268
|
cd ..
|
package/docs/glossary.md
CHANGED
|
@@ -128,7 +128,7 @@ No kit: Busca em memory/ via SQLite
|
|
|
128
128
|
CLI que cria novo projeto com toda estrutura. Os projetos vão para o workspace Forja (`~/forja-workspace/projects/<nome>`).
|
|
129
129
|
```
|
|
130
130
|
Comando: npm run project:new meu-projeto
|
|
131
|
-
Arquivos: bin/init-project.
|
|
131
|
+
Arquivos: bin/init-project.ts, bin/create-memory-nest-kit.ts, lib/project-wiring.ts
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
---
|
|
@@ -158,7 +158,7 @@ Esperado: { "status": "ok" }
|
|
|
158
158
|
Estrutura que acelera buscas (SQLite FTS5).
|
|
159
159
|
```
|
|
160
160
|
No kit: memory/ → .memory/sqlite/context.db
|
|
161
|
-
Sync:
|
|
161
|
+
Sync: forja sync:universal
|
|
162
162
|
```
|
|
163
163
|
|
|
164
164
|
---
|
|
@@ -315,8 +315,8 @@ Gerenciar: npm run sprint:start
|
|
|
315
315
|
### SQLite
|
|
316
316
|
Banco de dados leve, em-arquivo.
|
|
317
317
|
```
|
|
318
|
-
No
|
|
319
|
-
|
|
318
|
+
No projeto: memory/sqlite/universal.db (FTS5, fora do git)
|
|
319
|
+
Indexar: forja sync:universal
|
|
320
320
|
```
|
|
321
321
|
|
|
322
322
|
---
|