forjajs 1.2.0 → 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 +25 -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
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Hook SessionStart — imprime status do framework no início da sessão.
|
|
4
|
-
*
|
|
5
|
-
* Roda uma vez por sessão. Lê specs em aberto + handoffs pendentes do universal.db.
|
|
6
|
-
* Output vai para additionalContext (carregado pelo Claude no system).
|
|
7
|
-
*
|
|
8
|
-
* Regra de ouro: este hook nunca pode derrubar a sessão. Todo acesso a SQLite é
|
|
9
|
-
* lazy e envolto em try/catch — sem `node_modules`, degrada para o modo só-specs
|
|
10
|
-
* em vez de abortar (ADR-0021).
|
|
11
|
-
*
|
|
12
|
-
* A saúde do núcleo vem de `lib/core/health.mjs` — zero heurística local (SPEC-009). O hook tinha
|
|
13
|
-
* a sua, e ela mentia: um `catch { return null }` colapsava "sem node_modules", "ABI incompatível"
|
|
14
|
-
* e "banco ausente" no mesmo `null`, e então prescrevia `npm install` — que não recompila binário
|
|
15
|
-
* nativo. Quem seguisse o conselho do próprio framework não consertava nada.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
import fs from 'node:fs';
|
|
19
|
-
import path from 'node:path';
|
|
20
|
-
import { fileURLToPath } from 'node:url';
|
|
21
|
-
|
|
22
|
-
import { runChecks } from '../lib/core/health.mjs';
|
|
23
|
-
|
|
24
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
25
|
-
const __dirname = path.dirname(__filename);
|
|
26
|
-
const root = path.resolve(__dirname, '..');
|
|
27
|
-
|
|
28
|
-
function safeReadDir(p) { try { return fs.readdirSync(p); } catch { return []; } }
|
|
29
|
-
|
|
30
|
-
function listSpecs() {
|
|
31
|
-
const specsDir = path.join(root, 'specs');
|
|
32
|
-
const out = [];
|
|
33
|
-
for (const slug of safeReadDir(specsDir)) {
|
|
34
|
-
if (slug.startsWith('_') || slug.startsWith('.')) continue;
|
|
35
|
-
const specPath = path.join(specsDir, slug, 'spec.md');
|
|
36
|
-
if (!fs.existsSync(specPath)) continue;
|
|
37
|
-
const c = fs.readFileSync(specPath, 'utf8');
|
|
38
|
-
const m = c.match(/-\s*\*\*Status\*\*:\s*([a-z]+)/i);
|
|
39
|
-
out.push({ slug, status: m ? m[1] : 'unknown' });
|
|
40
|
-
}
|
|
41
|
-
return out;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/** Handoffs só fazem sentido com a memória de pé — daí o `memoriaOk` do caller. */
|
|
45
|
-
async function openHandoffs() {
|
|
46
|
-
try {
|
|
47
|
-
const { getWorkspaceDbPath } = await import('../lib/workspace.mjs');
|
|
48
|
-
const { default: Database } = await import('better-sqlite3');
|
|
49
|
-
const db = new Database(getWorkspaceDbPath(), { readonly: true });
|
|
50
|
-
const rows = db.prepare(`SELECT id, from_agent, to_agent, intent, spec_slug FROM handoffs WHERE status='open' ORDER BY id DESC LIMIT 10`).all();
|
|
51
|
-
db.close();
|
|
52
|
-
return rows;
|
|
53
|
-
} catch { return []; }
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Nunca lança e nunca trava a sessão: o hook reporta, o `tools:doctor` é que é gate. Se a própria
|
|
58
|
-
* lib de health não carregar, seguimos com o resto do briefing em vez de abortar (ADR-0021).
|
|
59
|
-
*/
|
|
60
|
-
async function coreHealth() {
|
|
61
|
-
try {
|
|
62
|
-
return await runChecks({ scope: 'runtime' });
|
|
63
|
-
} catch { return []; }
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
(async function main() {
|
|
67
|
-
const specs = listSpecs();
|
|
68
|
-
const health = await coreHealth();
|
|
69
|
-
const problemas = health.filter((c) => c.status === 'fail' || c.status === 'warn');
|
|
70
|
-
const memoriaOk = !health.some((c) => c.status === 'fail');
|
|
71
|
-
const handoffs = memoriaOk ? await openHandoffs() : [];
|
|
72
|
-
|
|
73
|
-
const lines = ['<framework-status>'];
|
|
74
|
-
lines.push(`Framework: forja (SDD + orquestração)`);
|
|
75
|
-
|
|
76
|
-
if (problemas.length) {
|
|
77
|
-
lines.push('');
|
|
78
|
-
for (const p of problemas) {
|
|
79
|
-
const icone = p.status === 'fail' ? '✖' : '⚠';
|
|
80
|
-
lines.push(`${icone} ${p.title}: ${p.detail}`);
|
|
81
|
-
if (p.fix) lines.push(` corrigir: ${p.fix}`);
|
|
82
|
-
}
|
|
83
|
-
lines.push(' raio-x completo: `npm run tools:doctor`');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (specs.length) {
|
|
87
|
-
lines.push('\nSpecs ativas:');
|
|
88
|
-
for (const s of specs) lines.push(` - ${s.slug} [${s.status}]`);
|
|
89
|
-
}
|
|
90
|
-
if (handoffs.length) {
|
|
91
|
-
lines.push('\nHandoffs em aberto:');
|
|
92
|
-
for (const h of handoffs) lines.push(` - #${h.id} ${h.from_agent} → ${h.to_agent} (${h.intent}) ${h.spec_slug || ''}`);
|
|
93
|
-
}
|
|
94
|
-
lines.push('\nFluxo SDD: `npm run spec:new|plan|tasks|check`');
|
|
95
|
-
lines.push('Handoff: `node scripts/agent-router.mjs append <json>`');
|
|
96
|
-
lines.push('</framework-status>');
|
|
97
|
-
|
|
98
|
-
process.stdout.write(JSON.stringify({
|
|
99
|
-
hookSpecificOutput: {
|
|
100
|
-
hookEventName: 'SessionStart',
|
|
101
|
-
additionalContext: lines.join('\n'),
|
|
102
|
-
},
|
|
103
|
-
}));
|
|
104
|
-
})();
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* Hook UserPromptSubmit — injeção opcional de smart-context.
|
|
4
|
-
*
|
|
5
|
-
* Protocolo:
|
|
6
|
-
* - stdin: JSON com { prompt, session_id, ... }
|
|
7
|
-
* - stdout: JSON com { hookSpecificOutput: { hookEventName, additionalContext } } ou vazio
|
|
8
|
-
*
|
|
9
|
-
* Dois caminhos de injeção:
|
|
10
|
-
* 1. Slug de spec detectado no prompt (specs/<slug>/ existe) → injeta pack
|
|
11
|
-
* task-mode montado do filesystem (spec + plan + tasks + runbook GSD).
|
|
12
|
-
* Ligado por padrão; desligue com FRAMEWORK_HOOK_INJECT=0. A economia não
|
|
13
|
-
* depende da IA obedecer a instrução: o contexto certo chega sozinho.
|
|
14
|
-
* 2. TRIGGER_KEYWORDS genéricos → pack global (mission/standards/ADRs).
|
|
15
|
-
* Continua opt-in via FRAMEWORK_HOOK_INJECT=1.
|
|
16
|
-
*
|
|
17
|
-
* Defaults conservadores (não bloqueia, não atrasa):
|
|
18
|
-
* - Limite duro de bytes (configurável em .memoryrc.json -> hooks.userPromptCap)
|
|
19
|
-
* - Cache por hash do prompt em /tmp/framework-hook-cache/
|
|
20
|
-
* - Sem SQLite no hot path (o Context Engineer faz FTS5 quando convocado)
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
import fs from 'node:fs';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import process from 'node:process';
|
|
26
|
-
import crypto from 'node:crypto';
|
|
27
|
-
import { fileURLToPath } from 'node:url';
|
|
28
|
-
|
|
29
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
30
|
-
const __dirname = path.dirname(__filename);
|
|
31
|
-
const root = path.resolve(__dirname, '..');
|
|
32
|
-
|
|
33
|
-
const TRIGGER_KEYWORDS = [
|
|
34
|
-
'implement', 'implementa', 'implementar',
|
|
35
|
-
'refator', 'refactor',
|
|
36
|
-
'criar feature', 'nova feature',
|
|
37
|
-
'spec:', 'plan:', 'tasks:',
|
|
38
|
-
'arquitet', 'architect',
|
|
39
|
-
];
|
|
40
|
-
|
|
41
|
-
const DEFAULT_CAP_BYTES = 4000;
|
|
42
|
-
|
|
43
|
-
function exitSilent() {
|
|
44
|
-
process.exit(0);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function readStdin() {
|
|
48
|
-
try { return fs.readFileSync(0, 'utf8'); } catch { return ''; }
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function loadConfig() {
|
|
52
|
-
try {
|
|
53
|
-
const cfg = JSON.parse(fs.readFileSync(path.join(root, '.memoryrc.json'), 'utf8'));
|
|
54
|
-
return cfg.hooks || {};
|
|
55
|
-
} catch { return {}; }
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function keywordTriggered(prompt) {
|
|
59
|
-
if (process.env.FRAMEWORK_HOOK_INJECT !== '1') return false;
|
|
60
|
-
if (!prompt) return false;
|
|
61
|
-
const lower = prompt.toLowerCase();
|
|
62
|
-
return TRIGGER_KEYWORDS.some(kw => lower.includes(kw));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Slugs de spec do framework (specs/<slug>/spec.md). Slugs curtos (<4 chars)
|
|
66
|
-
// ficam de fora para evitar falso positivo em palavras comuns.
|
|
67
|
-
function listSpecSlugs() {
|
|
68
|
-
const dir = path.join(root, 'specs');
|
|
69
|
-
try {
|
|
70
|
-
return fs.readdirSync(dir, { withFileTypes: true })
|
|
71
|
-
.filter(e => e.isDirectory() && !e.name.startsWith('_') && e.name.length >= 4)
|
|
72
|
-
.filter(e => fs.existsSync(path.join(dir, e.name, 'spec.md')))
|
|
73
|
-
.map(e => e.name);
|
|
74
|
-
} catch { return []; }
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function detectSlug(prompt) {
|
|
78
|
-
if (!prompt || process.env.FRAMEWORK_HOOK_INJECT === '0') return null;
|
|
79
|
-
const lower = prompt.toLowerCase();
|
|
80
|
-
// Slug mais longo primeiro: "forja-core-v2" ganha de "forja-core".
|
|
81
|
-
const slugs = listSpecSlugs().sort((a, b) => b.length - a.length);
|
|
82
|
-
return slugs.find(s => lower.includes(s)) || null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function cacheKey(prompt) {
|
|
86
|
-
return crypto.createHash('sha1').update(prompt).digest('hex').slice(0, 16);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function getCached(key) {
|
|
90
|
-
const f = path.join('/tmp/framework-hook-cache', `${key}.txt`);
|
|
91
|
-
if (!fs.existsSync(f)) return null;
|
|
92
|
-
const stat = fs.statSync(f);
|
|
93
|
-
if (Date.now() - stat.mtimeMs > 30 * 60 * 1000) return null; // 30min TTL
|
|
94
|
-
return fs.readFileSync(f, 'utf8');
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function setCached(key, content) {
|
|
98
|
-
const dir = '/tmp/framework-hook-cache';
|
|
99
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
100
|
-
fs.writeFileSync(path.join(dir, `${key}.txt`), content);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Pack task-mode de uma spec: o contexto mínimo-suficiente para trabalhar
|
|
104
|
-
// naquela feature, sem carregar memory/ inteira.
|
|
105
|
-
function buildTaskContext(slug, capBytes) {
|
|
106
|
-
const pieces = [];
|
|
107
|
-
const candidates = [
|
|
108
|
-
[`specs/${slug}/spec.md`, 4000],
|
|
109
|
-
[`specs/${slug}/plan.md`, 2500],
|
|
110
|
-
[`specs/${slug}/tasks.md`, 2500],
|
|
111
|
-
[`.context/gsd-${slug}.md`, 1500],
|
|
112
|
-
];
|
|
113
|
-
for (const [rel, sliceCap] of /** @type {[string, number][]} */ (candidates)) {
|
|
114
|
-
try {
|
|
115
|
-
const c = fs.readFileSync(path.join(root, rel), 'utf8');
|
|
116
|
-
pieces.push(`### ${rel}\n\n${c.slice(0, sliceCap)}`);
|
|
117
|
-
} catch { /* arquivo ainda não existe nesta fase do pipeline */ }
|
|
118
|
-
}
|
|
119
|
-
if (!pieces.length) return null;
|
|
120
|
-
const header = `Spec detectada no prompt: **${slug}**. Pack task-mode injetado ` +
|
|
121
|
-
`(ADR-0009). Para mais contexto: \`npm run query:universal -- "<termo>"\`.`;
|
|
122
|
-
let out = `<forja-task-context slug="${slug}">\n${header}\n\n` +
|
|
123
|
-
pieces.join('\n\n---\n\n') + '\n</forja-task-context>';
|
|
124
|
-
if (out.length > capBytes) out = out.slice(0, capBytes) + '\n[…truncado…]';
|
|
125
|
-
return out;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function buildContext(prompt, capBytes) {
|
|
129
|
-
// Estratégia simples: cabeça das ADRs + index global. FTS5 dirigido por prompt seria ideal,
|
|
130
|
-
// mas evitamos abrir SQLite no hot path do hook. O Context Engineer faz isso quando convocado.
|
|
131
|
-
const pieces = [];
|
|
132
|
-
const candidates = [
|
|
133
|
-
'memory/00-global/mission.md',
|
|
134
|
-
'memory/00-global/standards.md',
|
|
135
|
-
'AGENTS.md',
|
|
136
|
-
'specs/README.md',
|
|
137
|
-
];
|
|
138
|
-
for (const rel of candidates) {
|
|
139
|
-
try {
|
|
140
|
-
const c = fs.readFileSync(path.join(root, rel), 'utf8');
|
|
141
|
-
pieces.push(`### ${rel}\n\n${c}`);
|
|
142
|
-
} catch { /* ignore */ }
|
|
143
|
-
}
|
|
144
|
-
// ADRs mais recentes
|
|
145
|
-
const adrDir = path.join(root, 'memory/90-decisions');
|
|
146
|
-
if (fs.existsSync(adrDir)) {
|
|
147
|
-
const adrs = fs.readdirSync(adrDir).filter(f => f.match(/^\d{4}-/)).sort().slice(-3);
|
|
148
|
-
for (const a of adrs) {
|
|
149
|
-
try {
|
|
150
|
-
const c = fs.readFileSync(path.join(adrDir, a), 'utf8');
|
|
151
|
-
pieces.push(`### memory/90-decisions/${a}\n\n${c.slice(0, 800)}`);
|
|
152
|
-
} catch { /* ignore */ }
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
let out = '<framework-context>\n' + pieces.join('\n\n---\n\n') + '\n</framework-context>';
|
|
156
|
-
if (out.length > capBytes) out = out.slice(0, capBytes) + '\n[…truncado…]';
|
|
157
|
-
return out;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
(function main() {
|
|
161
|
-
const raw = readStdin();
|
|
162
|
-
let payload = {};
|
|
163
|
-
try { payload = raw ? JSON.parse(raw) : {}; } catch { /* tolerância */ }
|
|
164
|
-
const prompt = payload.prompt || payload.user_prompt || '';
|
|
165
|
-
|
|
166
|
-
const slug = detectSlug(prompt);
|
|
167
|
-
if (!slug && !keywordTriggered(prompt)) exitSilent();
|
|
168
|
-
|
|
169
|
-
const cfg = loadConfig();
|
|
170
|
-
const cap = cfg.userPromptCap || DEFAULT_CAP_BYTES;
|
|
171
|
-
const key = cacheKey(`${slug || 'kw'}:${prompt}`);
|
|
172
|
-
let ctx = getCached(key);
|
|
173
|
-
if (!ctx) {
|
|
174
|
-
ctx = (slug && buildTaskContext(slug, cap)) || (keywordTriggered(prompt) ? buildContext(prompt, cap) : null);
|
|
175
|
-
if (!ctx) exitSilent();
|
|
176
|
-
setCached(key, ctx);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
process.stdout.write(JSON.stringify({
|
|
180
|
-
hookSpecificOutput: {
|
|
181
|
-
hookEventName: 'UserPromptSubmit',
|
|
182
|
-
additionalContext: ctx,
|
|
183
|
-
},
|
|
184
|
-
}));
|
|
185
|
-
})();
|
package/scripts/pre-commit.sh
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
##############################################################################
|
|
4
|
-
# Pre-Commit Hook #
|
|
5
|
-
# #
|
|
6
|
-
# Validação automática antes de commit: #
|
|
7
|
-
# - Lint (ESLint) #
|
|
8
|
-
# - Tests (Jest) #
|
|
9
|
-
# - Documentation validation #
|
|
10
|
-
# - No secrets check #
|
|
11
|
-
# #
|
|
12
|
-
# Instalação: #
|
|
13
|
-
# cp scripts/pre-commit.sh .git/hooks/pre-commit #
|
|
14
|
-
# chmod +x .git/hooks/pre-commit #
|
|
15
|
-
# #
|
|
16
|
-
##############################################################################
|
|
17
|
-
|
|
18
|
-
set -e
|
|
19
|
-
|
|
20
|
-
RED='\033[0;31m'
|
|
21
|
-
GREEN='\033[0;32m'
|
|
22
|
-
YELLOW='\033[1;33m'
|
|
23
|
-
NC='\033[0m' # No Color
|
|
24
|
-
|
|
25
|
-
echo -e "${YELLOW}🔍 Pre-commit validation...${NC}\n"
|
|
26
|
-
|
|
27
|
-
# 1. Check for secrets
|
|
28
|
-
echo -e "${YELLOW}1️⃣ Checking for secrets...${NC}"
|
|
29
|
-
if git grep -q -i -E '(password|api_key|token|secret|credential|auth)' -- ':!*.md' ':!*.lock' 2>/dev/null; then
|
|
30
|
-
echo -e "${RED}❌ Secrets detected! Remove before committing.${NC}"
|
|
31
|
-
git grep -i -E '(password|api_key|token|secret)' -- ':!*.md' ':!*.lock' || true
|
|
32
|
-
exit 1
|
|
33
|
-
fi
|
|
34
|
-
echo -e "${GREEN}✅ No secrets detected${NC}\n"
|
|
35
|
-
|
|
36
|
-
# 2. Check for console.log
|
|
37
|
-
echo -e "${YELLOW}2️⃣ Checking for console.log statements...${NC}"
|
|
38
|
-
if git diff --cached --name-only | grep -E '\.(js|ts)$' | xargs grep -l 'console\.(log|debug|info)' 2>/dev/null || [ $? -eq 1 ]; then
|
|
39
|
-
echo -e "${YELLOW}⚠️ Warning: console.log found. Consider using logger instead.${NC}"
|
|
40
|
-
fi
|
|
41
|
-
echo -e "${GREEN}✅ Check complete${NC}\n"
|
|
42
|
-
|
|
43
|
-
# 3. Lint staged files
|
|
44
|
-
echo -e "${YELLOW}3️⃣ Linting staged files...${NC}"
|
|
45
|
-
if command -v npm &> /dev/null; then
|
|
46
|
-
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts)$' || true)
|
|
47
|
-
if [ ! -z "$STAGED_FILES" ]; then
|
|
48
|
-
echo "$STAGED_FILES" | xargs npm run lint -- --fix --quiet 2>/dev/null || {
|
|
49
|
-
echo -e "${RED}❌ Lint failed. Fix errors and try again.${NC}"
|
|
50
|
-
exit 1
|
|
51
|
-
}
|
|
52
|
-
# Re-add fixed files
|
|
53
|
-
echo "$STAGED_FILES" | xargs git add
|
|
54
|
-
echo -e "${GREEN}✅ Lint passed (auto-fixed)${NC}\n"
|
|
55
|
-
else
|
|
56
|
-
echo -e "${GREEN}✅ No JS/TS files to lint${NC}\n"
|
|
57
|
-
fi
|
|
58
|
-
else
|
|
59
|
-
echo -e "${YELLOW}⚠️ npm not found. Skipping lint.${NC}\n"
|
|
60
|
-
fi
|
|
61
|
-
|
|
62
|
-
# 4. Run tests
|
|
63
|
-
echo -e "${YELLOW}4️⃣ Running tests...${NC}"
|
|
64
|
-
if [ -f "package.json" ] && npm run test --silent 2>/dev/null; then
|
|
65
|
-
echo -e "${GREEN}✅ Tests passed${NC}\n"
|
|
66
|
-
else
|
|
67
|
-
echo -e "${YELLOW}⚠️ Tests skipped or failed. Run: npm test${NC}\n"
|
|
68
|
-
fi
|
|
69
|
-
|
|
70
|
-
# 5. Check documentation
|
|
71
|
-
echo -e "${YELLOW}5️⃣ Checking documentation...${NC}"
|
|
72
|
-
README_FILES=$(git diff --cached --name-only | grep -E '(README|CHANGELOG|\.md)$' || true)
|
|
73
|
-
if [ ! -z "$README_FILES" ]; then
|
|
74
|
-
echo "📄 Updated docs:"
|
|
75
|
-
echo "$README_FILES" | sed 's/^/ - /'
|
|
76
|
-
fi
|
|
77
|
-
echo -e "${GREEN}✅ Documentation check complete${NC}\n"
|
|
78
|
-
|
|
79
|
-
# 6. SDD pipeline consistency
|
|
80
|
-
echo -e "${YELLOW}6️⃣ Validating SDD pipeline (spec:check)...${NC}"
|
|
81
|
-
if [ -f "scripts/spec-cli.mjs" ]; then
|
|
82
|
-
if node scripts/spec-cli.mjs check 2>&1; then
|
|
83
|
-
echo -e "${GREEN}✅ All specs consistent${NC}\n"
|
|
84
|
-
else
|
|
85
|
-
echo -e "${RED}❌ spec:check failed. Fix spec/plan/tasks status before committing.${NC}"
|
|
86
|
-
exit 1
|
|
87
|
-
fi
|
|
88
|
-
fi
|
|
89
|
-
|
|
90
|
-
# 7. Standards check
|
|
91
|
-
echo -e "${YELLOW}7️⃣ Project standards check...${NC}"
|
|
92
|
-
if [ -f "scripts/check-standards.js" ]; then
|
|
93
|
-
node scripts/check-standards.js 2>/dev/null || echo -e "${YELLOW}⚠️ standards check warnings${NC}"
|
|
94
|
-
fi
|
|
95
|
-
echo -e "${GREEN}✅ Standards check complete${NC}\n"
|
|
96
|
-
|
|
97
|
-
# 8. Summary
|
|
98
|
-
echo -e "${GREEN}════════════════════════════════════════════════════${NC}"
|
|
99
|
-
echo -e "${GREEN}✅ All pre-commit checks passed!${NC}"
|
|
100
|
-
echo -e "${GREEN}════════════════════════════════════════════════════${NC}\n"
|
|
101
|
-
|
|
102
|
-
exit 0
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import Database from 'better-sqlite3';
|
|
2
|
-
import { getDbPath, ensureSchema } from './memory-schema.mjs';
|
|
3
|
-
|
|
4
|
-
ensureSchema({ silent: true });
|
|
5
|
-
const dbPath = getDbPath();
|
|
6
|
-
|
|
7
|
-
const args = process.argv.slice(2);
|
|
8
|
-
const query = args[0] || '';
|
|
9
|
-
const limit = Number(args[1] || 5);
|
|
10
|
-
|
|
11
|
-
if (!query) {
|
|
12
|
-
console.log('Uso: node scripts/query-universal-memory.js "termo de busca" [limite]');
|
|
13
|
-
process.exit(0);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const db = new Database(dbPath, { readonly: true });
|
|
17
|
-
|
|
18
|
-
const search = db.prepare(`
|
|
19
|
-
SELECT
|
|
20
|
-
n.path,
|
|
21
|
-
n.kind,
|
|
22
|
-
n.title,
|
|
23
|
-
p.name as project,
|
|
24
|
-
snippet(search_idx, 2, '>', '<', '...', 20) as snippet
|
|
25
|
-
FROM search_idx
|
|
26
|
-
JOIN memory_nodes n ON n.id = search_idx.node_id
|
|
27
|
-
LEFT JOIN projects p ON p.id = n.project_id
|
|
28
|
-
WHERE search_idx MATCH ?
|
|
29
|
-
ORDER BY rank
|
|
30
|
-
LIMIT ?
|
|
31
|
-
`);
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
const results = search.all(query, limit);
|
|
35
|
-
|
|
36
|
-
if (results.length === 0) {
|
|
37
|
-
console.log(`Nenhum resultado encontrado para: "${query}"`);
|
|
38
|
-
} else {
|
|
39
|
-
console.log(`\nResultados para: "${query}"\n`);
|
|
40
|
-
results.forEach(r => {
|
|
41
|
-
const scope = r.project ? `[Projeto: ${r.project}]` : '[Global]';
|
|
42
|
-
console.log(`${scope} ${r.title} (${r.path})`);
|
|
43
|
-
console.log(` > ${r.snippet.replace(/\n/g, ' ')}\n`);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.error('Erro na busca:', e.message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
db.close();
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
/**
|
|
3
|
-
* release-check — o gate do tarball (SPEC-010, ADR-0024).
|
|
4
|
-
*
|
|
5
|
-
* Responde a uma pergunta com evidência: **o pacote funciona na máquina de quem instala?**
|
|
6
|
-
* Empacota, instala num diretório isolado, executa os comandos e reprova se algo só funcionava
|
|
7
|
-
* porque o repo estava por perto.
|
|
8
|
-
*
|
|
9
|
-
* npm run release:check árvore suja = aviso (smoke local)
|
|
10
|
-
* npm run release:check -- --publish árvore suja = falha (prepublishOnly, CI de release)
|
|
11
|
-
*
|
|
12
|
-
* Diagnostica e autoriza; nunca publica. `npm publish` continua sendo um ato humano.
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import { runReleaseChecks, worstStatus } from '../lib/core/release.mjs';
|
|
16
|
-
|
|
17
|
-
const TAG = { ok: 'OK ', warn: 'AVISO', fail: 'FALHA', skipped: '— ' };
|
|
18
|
-
|
|
19
|
-
async function main() {
|
|
20
|
-
const publish = process.argv.includes('--publish');
|
|
21
|
-
|
|
22
|
-
console.log(`\nForja release gate${publish ? ' (modo publish)' : ''}\n`);
|
|
23
|
-
console.log('Empacotando e instalando num diretório isolado — isto leva alguns instantes.\n');
|
|
24
|
-
|
|
25
|
-
const results = await runReleaseChecks({ publish });
|
|
26
|
-
|
|
27
|
-
for (const r of results) {
|
|
28
|
-
console.log(`${TAG[r.status]} ${r.id.padEnd(17)} ${r.detail}`);
|
|
29
|
-
if (r.fix) console.log(` corrigir: ${r.fix}`);
|
|
30
|
-
console.log('');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const verdict = worstStatus(results);
|
|
34
|
-
|
|
35
|
-
if (verdict === 'fail') {
|
|
36
|
-
const raiz = results.filter((r) => r.status === 'fail' && r.severity === 'critical');
|
|
37
|
-
console.log(`REPROVADO — ${raiz.length} falha(s) crítica(s). O pacote não deve ser publicado.`);
|
|
38
|
-
for (const r of raiz) console.log(` ${r.id}: ${r.fix || 'sem correção automática'}`);
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (verdict === 'warn') {
|
|
43
|
-
console.log('Aprovado com ressalvas. Nada impede o pacote de funcionar.');
|
|
44
|
-
if (!publish) console.log('Para o parecer de publicação, rode com --publish.');
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
console.log('APROVADO — instalação limpa funciona.');
|
|
49
|
-
console.log('O parecer é perecível: vale para este disco, neste instante. Qualquer npm install ou');
|
|
50
|
-
console.log('edição posterior o invalida.');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
main().catch((err) => {
|
|
54
|
-
console.error(`\nrelease-check falhou: ${err.message}`);
|
|
55
|
-
process.exit(1);
|
|
56
|
-
});
|