forjajs 2.0.1 → 2.0.3
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 +15 -0
- package/README.md +22 -0
- package/README.pt-BR.md +22 -0
- package/dist/apps/cli/src/index.d.ts +44 -0
- package/dist/apps/cli/src/index.js +304 -0
- package/dist/apps/server/src/main.d.ts +9 -3
- package/dist/apps/server/src/main.js +70 -19
- package/dist/bin/forja.js +213 -0
- package/dist/lib/core/health.js +2 -1
- package/dist/lib/core/registry.d.ts +17 -0
- package/dist/lib/core/registry.js +17 -0
- package/dist/lib/core/release.d.ts +16 -0
- package/dist/packages/adapter-git/src/index.d.ts +14 -0
- package/dist/packages/adapter-git/src/index.js +66 -0
- package/dist/packages/adapter-sqlite/src/index.d.ts +59 -2
- package/dist/packages/adapter-sqlite/src/index.js +136 -0
- package/dist/packages/context/src/index.d.ts +8 -0
- package/dist/packages/context/src/index.js +7 -0
- package/dist/packages/contracts/src/index.d.ts +1 -1
- package/dist/packages/events/src/index.d.ts +2 -0
- package/dist/packages/events/src/index.js +16 -0
- package/dist/packages/graph/src/index.d.ts +59 -3
- package/dist/packages/graph/src/index.js +139 -21
- package/dist/packages/mcp/src/index.d.ts +14 -0
- package/dist/packages/mcp/src/index.js +39 -5
- package/dist/packages/plugin-docker/src/index.d.ts +3 -0
- package/dist/packages/plugin-docker/src/index.js +13 -0
- package/dist/packages/plugin-github/src/index.d.ts +3 -0
- package/dist/packages/plugin-github/src/index.js +13 -0
- package/dist/packages/policy/src/index.d.ts +7 -0
- package/dist/packages/policy/src/index.js +17 -1
- package/dist/packages/runtime/src/index.d.ts +20 -1
- package/dist/packages/runtime/src/index.js +34 -1
- package/dist/packages/sandbox/src/index.d.ts +2 -0
- package/dist/packages/sandbox/src/index.js +10 -0
- package/dist/scripts/context-benchmark.d.ts +2 -0
- package/dist/scripts/context-benchmark.js +39 -0
- package/dist/scripts/demo-autonomy.d.ts +15 -0
- package/dist/scripts/demo-autonomy.js +200 -0
- package/dist/scripts/server-persistence-probe.d.mts +1 -0
- package/dist/scripts/server-persistence-probe.d.ts +1 -0
- package/dist/scripts/server-persistence-probe.js +52 -0
- package/dist/scripts/server-persistence-probe.mjs +52 -0
- package/docs/2x/CLI-CAPABILITIES.md +35 -0
- package/docs/2x/IMPLEMENTATION-AUDIT.md +40 -0
- package/docs/2x/SPRINT-1-CLI-CAPABILITY-PLAN.md +53 -0
- package/docs/2x/SPRINT-10-GRAPH-SYNC-PLAN.md +54 -0
- package/docs/2x/SPRINT-11-GRAPH-SYNC-CLI-MCP-PLAN.md +38 -0
- package/docs/2x/SPRINT-12-REAL-AUTONOMY-PLAN.md +40 -0
- package/docs/2x/SPRINT-13-MCP-STDIO-PLAN.md +26 -0
- package/docs/2x/SPRINT-14-SERVER-RESTART-PLAN.md +28 -0
- package/docs/2x/SPRINT-15-CHAOS-SECURITY-PLAN.md +22 -0
- package/docs/2x/SPRINT-16-LAST-MILE-PLAN.md +25 -0
- package/docs/2x/SPRINT-2-CLI-CAPABILITY-PLAN.md +39 -0
- package/docs/2x/SPRINT-3-RUNTIME-PERSISTENCE-PLAN.md +42 -0
- package/docs/2x/SPRINT-4-MCP-REGISTRY-PLAN.md +35 -0
- package/docs/2x/SPRINT-5-SERVER-APPROVALS-AUDIT-PLAN.md +31 -0
- package/docs/2x/SPRINT-6-EVENTS-E2E-PLAN.md +55 -0
- package/docs/2x/SPRINT-7-GRAPHLOOP-PERSISTENCE-PLAN.md +60 -0
- package/docs/2x/SPRINT-8-CONTEXT-GRAPH-PLAN.md +64 -0
- package/docs/2x/SPRINT-9-DETERMINISTIC-EXTRACTORS-PLAN.md +51 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-1-cli-capabilities.md +41 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-10-graph-sync.md +23 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-11-graph-sync-cli-mcp.md +22 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-12-real-autonomy.md +16 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-2-cli-capabilities.md +30 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-3-runtime-persistence.md +29 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-4-mcp.md +29 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-5-server-approvals-audit.md +22 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-6-events-e2e.md +25 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-7-graphloop.md +23 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-8-context-graph.md +23 -0
- package/memory/50-orchestration/handoffs/2026-08-01_sprint-9-extractors.md +21 -0
- package/memory/50-orchestration/handoffs/2026-08-02_sprint-13-mcp-stdio.md +14 -0
- package/memory/50-orchestration/handoffs/2026-08-02_sprint-14-server-restart.md +15 -0
- package/memory/50-orchestration/handoffs/2026-08-02_sprint-15-chaos-security.md +13 -0
- package/memory/50-orchestration/handoffs/2026-08-02_sprint-16-last-mile.md +11 -0
- package/memory/90-decisions/0059-cli-adapter-capability-registry.md +17 -0
- package/memory/90-decisions/0060-runtime-persistence-port.md +17 -0
- package/memory/90-decisions/0061-mcp-dynamic-registry-stdio.md +16 -0
- package/memory/90-decisions/0062-server-catalog-approval-audit.md +17 -0
- package/memory/90-decisions/0063-events-persistent-e2e.md +19 -0
- package/memory/90-decisions/0064-graphloop-sqlite-store.md +20 -0
- package/memory/90-decisions/0065-context-graph-source-cache.md +20 -0
- package/memory/90-decisions/0066-graph-deterministic-extractors.md +16 -0
- package/memory/90-decisions/0067-graph-sync-capability.md +17 -0
- package/memory/90-decisions/0068-graph-sync-cli-mcp.md +17 -0
- package/memory/90-decisions/0069-real-autonomy-demo.md +16 -0
- package/memory/90-decisions/0070-mcp-stdio-real.md +11 -0
- package/memory/90-decisions/0071-server-persistence-composition.md +12 -0
- package/memory/90-decisions/0072-sandbox-security-boundaries.md +9 -0
- package/memory/90-decisions/0073-last-mile-rollback-benchmark-plugins.md +17 -0
- package/package.json +13 -3
package/dist/bin/forja.js
CHANGED
|
@@ -14,8 +14,15 @@ import fs from 'node:fs';
|
|
|
14
14
|
import path from 'node:path';
|
|
15
15
|
import { spawnSync } from 'node:child_process';
|
|
16
16
|
import { fileURLToPath } from 'node:url';
|
|
17
|
+
import Database from 'better-sqlite3';
|
|
17
18
|
import { COMMANDS, DOMAINS, resolveScript } from "../lib/core/registry.js";
|
|
18
19
|
import { getWorkspaceInfo, getWorkspaceContextDir } from "../lib/workspace.js";
|
|
20
|
+
import { capabilityIdForCommand, createCliCapabilityRuntime, executeCliCapability, parseLegacyCommandInput, } from "../apps/cli/src/index.js";
|
|
21
|
+
import { GitGraphDocumentSource, SpawnCommandRunner } from "../packages/adapter-git/src/index.js";
|
|
22
|
+
import { GraphLoop } from "../packages/graph/src/index.js";
|
|
23
|
+
import { SqliteGraphStore, SqliteMigrationRunner } from "../packages/adapter-sqlite/src/index.js";
|
|
24
|
+
import { getWorkspaceDbDir, getWorkspaceDbPath } from "../lib/workspace.js";
|
|
25
|
+
import { McpServer } from "../packages/mcp/src/index.js";
|
|
19
26
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
20
27
|
const root = path.resolve(__dirname, '..');
|
|
21
28
|
function printHelp() {
|
|
@@ -37,6 +44,11 @@ function printHelp() {
|
|
|
37
44
|
}
|
|
38
45
|
console.log('');
|
|
39
46
|
}
|
|
47
|
+
console.log('Capabilities:');
|
|
48
|
+
console.log(' capabilities:list Lista capabilities descobríveis');
|
|
49
|
+
console.log(' capabilities:describe Descreve uma capability');
|
|
50
|
+
console.log(' capability:execute Executa uma capability com input JSON');
|
|
51
|
+
console.log(' mcp:start Inicia o transporte MCP JSON-RPC por stdio');
|
|
40
52
|
console.log('Toda execução é auditada em .context/forja-runs.jsonl (workspace, se existir).');
|
|
41
53
|
}
|
|
42
54
|
function suggest(input) {
|
|
@@ -76,11 +88,209 @@ function audit(entry) {
|
|
|
76
88
|
console.error(`Aviso: auditoria indisponível (${error.message}).`);
|
|
77
89
|
}
|
|
78
90
|
}
|
|
91
|
+
function runLegacyCaptured(command, args) {
|
|
92
|
+
const cmd = COMMANDS[command];
|
|
93
|
+
if (!cmd)
|
|
94
|
+
return { exitCode: 127, stdout: '', stderr: `Comando legado não encontrado: ${command}` };
|
|
95
|
+
let result;
|
|
96
|
+
if (cmd.node) {
|
|
97
|
+
const script = resolveScript(root, cmd.node);
|
|
98
|
+
result = spawnSync('node', [script, ...(cmd.args || []), ...args], {
|
|
99
|
+
cwd: process.cwd(),
|
|
100
|
+
encoding: 'utf8',
|
|
101
|
+
stdio: 'pipe',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
result = spawnSync(cmd.bin, [...(cmd.args || []), ...args], {
|
|
106
|
+
cwd: process.cwd(),
|
|
107
|
+
encoding: 'utf8',
|
|
108
|
+
stdio: 'pipe',
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const error = result.error;
|
|
112
|
+
const stderr = [result.stderr || '', error ? error.message : ''].filter(Boolean).join('\n');
|
|
113
|
+
return {
|
|
114
|
+
exitCode: result.status ?? 1,
|
|
115
|
+
stdout: result.stdout || '',
|
|
116
|
+
stderr,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
function jsonFlag(args) {
|
|
120
|
+
return args.includes('--json');
|
|
121
|
+
}
|
|
122
|
+
function withoutFlag(args, flag) {
|
|
123
|
+
return args.filter((arg) => arg !== flag);
|
|
124
|
+
}
|
|
125
|
+
function printExecutionResult(result, json) {
|
|
126
|
+
if (json) {
|
|
127
|
+
console.log(JSON.stringify(result));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const execution = result;
|
|
131
|
+
const payload = execution.output?.payload;
|
|
132
|
+
if (payload?.stdout)
|
|
133
|
+
process.stdout.write(payload.stdout);
|
|
134
|
+
if (payload?.stderr)
|
|
135
|
+
process.stderr.write(payload.stderr);
|
|
136
|
+
if (payload && typeof payload.indexed === 'number' && typeof payload.skipped === 'number')
|
|
137
|
+
console.log(`Graph sync: ${payload.indexed} indexado(s), ${payload.skipped} ignorado(s), ${payload.edges ?? 0} aresta(s) em ${payload.durationMs ?? 0}ms.`);
|
|
138
|
+
if (execution.error?.message)
|
|
139
|
+
console.error(execution.error.message);
|
|
140
|
+
}
|
|
141
|
+
async function runCapabilityCommand(command, args) {
|
|
142
|
+
const needsGraph = command === 'graph:sync' || command === 'capability:execute' || command === 'capabilities:list' || command === 'capabilities:describe';
|
|
143
|
+
const runtime = createCliCapabilityRuntime(runLegacyCaptured, needsGraph ? createGraphSyncComposition() : undefined);
|
|
144
|
+
const started = Date.now();
|
|
145
|
+
const json = jsonFlag(args);
|
|
146
|
+
let result;
|
|
147
|
+
let capabilityId;
|
|
148
|
+
let commandSucceeded = true;
|
|
149
|
+
let inputArgs = withoutFlag(args, '--json');
|
|
150
|
+
if (command === 'capabilities:list') {
|
|
151
|
+
result = runtime.registry.list();
|
|
152
|
+
}
|
|
153
|
+
else if (command === 'capabilities:describe') {
|
|
154
|
+
const id = inputArgs[0];
|
|
155
|
+
if (!id) {
|
|
156
|
+
result = { error: 'Capability id is required' };
|
|
157
|
+
commandSucceeded = false;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
try {
|
|
161
|
+
result = runtime.registry.describe(id);
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
result = { error: error instanceof Error ? error.message : 'Capability not found' };
|
|
165
|
+
commandSucceeded = false;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
else if (command === 'capability:execute') {
|
|
170
|
+
capabilityId = inputArgs.shift();
|
|
171
|
+
const inputIndex = inputArgs.indexOf('--input');
|
|
172
|
+
if (!capabilityId || inputIndex < 0 || inputArgs[inputIndex + 1] === undefined) {
|
|
173
|
+
result = { error: 'Usage: capability:execute <id> --input \'{}\' [--json]' };
|
|
174
|
+
commandSucceeded = false;
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
try {
|
|
178
|
+
const payload = JSON.parse(inputArgs[inputIndex + 1]);
|
|
179
|
+
result = await executeCliCapability(runtime, capabilityId, payload);
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
result = { error: error instanceof Error ? error.message : 'Invalid capability input' };
|
|
183
|
+
commandSucceeded = false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
const migrated = capabilityIdForCommand(command);
|
|
189
|
+
if (!migrated)
|
|
190
|
+
return 1;
|
|
191
|
+
capabilityId = migrated;
|
|
192
|
+
try {
|
|
193
|
+
const parsed = parseLegacyCommandInput(command, inputArgs);
|
|
194
|
+
result = await executeCliCapability(runtime, parsed.capabilityId, parsed.payload);
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
result = { error: error instanceof Error ? error.message : 'Invalid command input' };
|
|
198
|
+
commandSucceeded = false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
printExecutionResult(result, json || command.startsWith('capabilit'));
|
|
202
|
+
const execution = result;
|
|
203
|
+
const payload = execution.output?.payload;
|
|
204
|
+
audit({
|
|
205
|
+
ts: new Date().toISOString(),
|
|
206
|
+
cmd: command,
|
|
207
|
+
args,
|
|
208
|
+
capabilityId,
|
|
209
|
+
runId: execution.runId,
|
|
210
|
+
correlationId: execution.correlationId,
|
|
211
|
+
status: execution.status,
|
|
212
|
+
exitCode: commandSucceeded && (execution.status === undefined || execution.status === 'succeeded') ? 0 : 1,
|
|
213
|
+
durationMs: Date.now() - started,
|
|
214
|
+
metrics: capabilityId === 'graph.sync' && payload === undefined ? undefined : capabilityId === 'graph.sync' ? { documents: payload?.documents, indexed: payload?.indexed, skipped: payload?.skipped, nodes: payload?.nodes, edges: payload?.edges, durationMs: payload?.durationMs, files: payload?.files } : undefined,
|
|
215
|
+
});
|
|
216
|
+
return commandSucceeded && (execution.status === undefined || execution.status === 'succeeded') ? 0 : 1;
|
|
217
|
+
}
|
|
218
|
+
async function runMcpStdio() {
|
|
219
|
+
const runtime = createCliCapabilityRuntime(runLegacyCaptured, createGraphSyncComposition());
|
|
220
|
+
const definitions = runtime.registry.list();
|
|
221
|
+
const mcp = new McpServer({
|
|
222
|
+
registry: runtime.registry,
|
|
223
|
+
policy: runtime.policy,
|
|
224
|
+
agent: {
|
|
225
|
+
...runtime.agent,
|
|
226
|
+
permissions: ['read', 'write', 'execution', 'database'],
|
|
227
|
+
capabilities: definitions.map((definition) => definition.id),
|
|
228
|
+
},
|
|
229
|
+
audit: {
|
|
230
|
+
append: (event) => audit({ ts: new Date().toISOString(), cmd: `mcp:${event.tool}`, args: [], capabilityId: event.tool, correlationId: event.correlationId, status: event.outcome === 'success' ? 'succeeded' : event.outcome === 'blocked' ? 'blocked' : 'failed', exitCode: event.outcome === 'success' ? 0 : 1, durationMs: 0 }),
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
process.stdin.setEncoding('utf8');
|
|
234
|
+
const handleLine = async (line) => {
|
|
235
|
+
if (line.trim().length === 0)
|
|
236
|
+
return;
|
|
237
|
+
let request;
|
|
238
|
+
let id = null;
|
|
239
|
+
try {
|
|
240
|
+
request = JSON.parse(line);
|
|
241
|
+
id = request.id ?? null;
|
|
242
|
+
if (request.method === 'notifications/initialized')
|
|
243
|
+
return;
|
|
244
|
+
if (request.method === 'notifications/cancelled')
|
|
245
|
+
return;
|
|
246
|
+
let result;
|
|
247
|
+
if (request.method === 'initialize')
|
|
248
|
+
result = { protocolVersion: '2025-06-18', capabilities: { tools: {}, resources: {} }, serverInfo: { name: 'forja', version: '2.0.3' } };
|
|
249
|
+
else if (request.method === 'tools/list')
|
|
250
|
+
result = { tools: mcp.listTools() };
|
|
251
|
+
else if (request.method === 'resources/list')
|
|
252
|
+
result = { resources: mcp.listResources() };
|
|
253
|
+
else if (request.method === 'tools/call')
|
|
254
|
+
result = await mcp.callTool(String(request.params?.name ?? ''), request.params?.arguments ?? {});
|
|
255
|
+
else if (request.method === 'resources/read')
|
|
256
|
+
result = await mcp.readResource(String(request.params?.uri ?? ''));
|
|
257
|
+
else
|
|
258
|
+
throw new Error(`Unsupported MCP method: ${request.method ?? 'missing'}`);
|
|
259
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, result })}\n`);
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, error: { code: -32000, message: error instanceof Error ? error.message : 'MCP request failed' } })}\n`);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
let buffer = '';
|
|
266
|
+
for await (const chunk of process.stdin) {
|
|
267
|
+
buffer += chunk;
|
|
268
|
+
const lines = buffer.split('\n');
|
|
269
|
+
buffer = lines.pop() ?? '';
|
|
270
|
+
for (const line of lines)
|
|
271
|
+
await handleLine(line);
|
|
272
|
+
}
|
|
273
|
+
await handleLine(buffer);
|
|
274
|
+
return 0;
|
|
275
|
+
}
|
|
276
|
+
function createGraphSyncComposition() {
|
|
277
|
+
fs.mkdirSync(getWorkspaceDbDir(), { recursive: true });
|
|
278
|
+
const database = new Database(process.env.FORJA_RUNTIME_DB ?? getWorkspaceDbPath());
|
|
279
|
+
new SqliteMigrationRunner(database).apply();
|
|
280
|
+
const graphRoot = process.env.FORJA_GRAPH_ROOT ?? process.cwd();
|
|
281
|
+
return { graph: new GraphLoop(new SqliteGraphStore(database)), source: new GitGraphDocumentSource(graphRoot, new SpawnCommandRunner()) };
|
|
282
|
+
}
|
|
79
283
|
const [name, ...rest] = process.argv.slice(2);
|
|
80
284
|
if (!name || name === 'help' || name === '--help' || name === '-h') {
|
|
81
285
|
printHelp();
|
|
82
286
|
process.exit(0);
|
|
83
287
|
}
|
|
288
|
+
if (name === 'capabilities:list' || name === 'capabilities:describe' || name === 'capability:execute') {
|
|
289
|
+
process.exit(await runCapabilityCommand(name, rest));
|
|
290
|
+
}
|
|
291
|
+
if (name === 'mcp:start') {
|
|
292
|
+
process.exit(await runMcpStdio());
|
|
293
|
+
}
|
|
84
294
|
const cmd = COMMANDS[name];
|
|
85
295
|
if (!cmd) {
|
|
86
296
|
console.error(`Comando desconhecido: ${name}`);
|
|
@@ -106,6 +316,9 @@ if (gateErrors.length) {
|
|
|
106
316
|
});
|
|
107
317
|
process.exit(1);
|
|
108
318
|
}
|
|
319
|
+
if (capabilityIdForCommand(name) !== undefined) {
|
|
320
|
+
process.exit(await runCapabilityCommand(name, rest));
|
|
321
|
+
}
|
|
109
322
|
const started = Date.now();
|
|
110
323
|
let result;
|
|
111
324
|
// Os filhos rodam ONDE O USUÁRIO INVOCOU, não na raiz do pacote. `cwd: root` funcionava por
|
package/dist/lib/core/health.js
CHANGED
|
@@ -40,6 +40,7 @@ import { runChecks as run, worstStatus, stripTemplateLiterals, asErrno } from ".
|
|
|
40
40
|
import { COMMANDS } from "./registry.js";
|
|
41
41
|
import { scanCommands, scanLinks, projectCommands, scanAdrRefs, adrNumbers, commandCited } from "./doc-graph.js";
|
|
42
42
|
import { topologyIssues } from "../agent-topology.js";
|
|
43
|
+
import { CLI_INTERFACE_COMMANDS } from "../../apps/cli/src/index.js";
|
|
43
44
|
/** @typedef {import('./checks.ts').Status} Status */
|
|
44
45
|
// O runner vive em checks.mjs e é compartilhado com o catálogo de release (SPEC-010). Re-exportado
|
|
45
46
|
// aqui para que `tools:doctor` e o hook SessionStart sigam importando de um lugar só.
|
|
@@ -458,7 +459,7 @@ const docsCommands = {
|
|
|
458
459
|
if (!isFrameworkRepo(env)) {
|
|
459
460
|
return { status: 'ok', detail: 'fora do repo do framework — não se aplica', fix: null };
|
|
460
461
|
}
|
|
461
|
-
const known = new Set([...Object.keys(COMMANDS), ...projectCommands(env)]);
|
|
462
|
+
const known = new Set([...Object.keys(COMMANDS), ...CLI_INTERFACE_COMMANDS, ...projectCommands(env)]);
|
|
462
463
|
const ghosts = scanCommands(env).filter((c) => !known.has(c.command));
|
|
463
464
|
if (ghosts.length) {
|
|
464
465
|
const amostra = ghosts.slice(0, 5).map((g) => `${g.command} (${g.file}:${g.line})`).join(', ');
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* Alvos:
|
|
8
8
|
* - node: script do repo executado com `node <script> [...args]`
|
|
9
9
|
* - bin: binário externo no PATH (ex.: codegraph)
|
|
10
|
+
* - capability: handler compartilhado do Capability Registry
|
|
10
11
|
*
|
|
11
12
|
* Gates (aplicados por bin/forja.mjs antes do alvo):
|
|
12
13
|
* - workspace bloqueia se o workspace (ADR-0019) não existir
|
|
@@ -179,6 +180,12 @@ export declare const COMMANDS: {
|
|
|
179
180
|
node: string;
|
|
180
181
|
args: string[];
|
|
181
182
|
};
|
|
183
|
+
'graph:sync': {
|
|
184
|
+
domain: string;
|
|
185
|
+
desc: string;
|
|
186
|
+
capability: string;
|
|
187
|
+
gates: string[];
|
|
188
|
+
};
|
|
182
189
|
'code:context': {
|
|
183
190
|
domain: string;
|
|
184
191
|
desc: string;
|
|
@@ -291,6 +298,11 @@ export declare const COMMANDS: {
|
|
|
291
298
|
desc: string;
|
|
292
299
|
node: string;
|
|
293
300
|
};
|
|
301
|
+
'benchmark:context': {
|
|
302
|
+
domain: string;
|
|
303
|
+
desc: string;
|
|
304
|
+
node: string;
|
|
305
|
+
};
|
|
294
306
|
'project:check': {
|
|
295
307
|
domain: string;
|
|
296
308
|
desc: string;
|
|
@@ -301,6 +313,11 @@ export declare const COMMANDS: {
|
|
|
301
313
|
desc: string;
|
|
302
314
|
node: string;
|
|
303
315
|
};
|
|
316
|
+
'demo:autonomy': {
|
|
317
|
+
domain: string;
|
|
318
|
+
desc: string;
|
|
319
|
+
node: string;
|
|
320
|
+
};
|
|
304
321
|
'release:check': {
|
|
305
322
|
domain: string;
|
|
306
323
|
desc: string;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* Alvos:
|
|
8
8
|
* - node: script do repo executado com `node <script> [...args]`
|
|
9
9
|
* - bin: binário externo no PATH (ex.: codegraph)
|
|
10
|
+
* - capability: handler compartilhado do Capability Registry
|
|
10
11
|
*
|
|
11
12
|
* Gates (aplicados por bin/forja.mjs antes do alvo):
|
|
12
13
|
* - workspace bloqueia se o workspace (ADR-0019) não existir
|
|
@@ -196,6 +197,12 @@ export const COMMANDS = {
|
|
|
196
197
|
node: 'scripts/agent-harness.ts',
|
|
197
198
|
args: ['code:impact'],
|
|
198
199
|
},
|
|
200
|
+
'graph:sync': {
|
|
201
|
+
domain: 'code',
|
|
202
|
+
desc: 'Indexa arquivos rastreáveis do workspace no GraphLoop por checksum',
|
|
203
|
+
capability: 'graph.sync',
|
|
204
|
+
gates: ['workspace-warn'],
|
|
205
|
+
},
|
|
199
206
|
'code:context': {
|
|
200
207
|
domain: 'code',
|
|
201
208
|
desc: 'Pacote de contexto mínimo de um domínio: o mapa (context.md), + código com --code (ADR-0009)',
|
|
@@ -310,6 +317,11 @@ export const COMMANDS = {
|
|
|
310
317
|
desc: 'Economia de token: eixos arquitetura + memória; --project mede seus domínios reais (ADR-0009/0027)',
|
|
311
318
|
node: 'scripts/token-economy.ts',
|
|
312
319
|
},
|
|
320
|
+
'benchmark:context': {
|
|
321
|
+
domain: 'contexto',
|
|
322
|
+
desc: 'Benchmark JSON determinístico de baseline, contexto mínimo, checksum e cache',
|
|
323
|
+
node: 'scripts/context-benchmark.ts',
|
|
324
|
+
},
|
|
313
325
|
// --- Governança & qualidade ---------------------------------------------------
|
|
314
326
|
'project:check': {
|
|
315
327
|
domain: 'governanca',
|
|
@@ -321,6 +333,11 @@ export const COMMANDS = {
|
|
|
321
333
|
desc: 'Raio-x do núcleo (gate, exit 1) + ferramentas de processo (ADR-0023, ADR-0018)',
|
|
322
334
|
node: 'scripts/tools-doctor.ts',
|
|
323
335
|
},
|
|
336
|
+
'demo:autonomy': {
|
|
337
|
+
domain: 'governanca',
|
|
338
|
+
desc: 'Executa a prova offline de autonomia supervisionada com Git worktree real',
|
|
339
|
+
node: 'scripts/demo-autonomy.ts',
|
|
340
|
+
},
|
|
324
341
|
'release:check': {
|
|
325
342
|
domain: 'governanca',
|
|
326
343
|
desc: 'Gate do tarball: instala limpo e prova que o pacote funciona (ADR-0024). --publish para o modo estrito',
|
|
@@ -187,6 +187,12 @@ export declare function defaultEnv(overrides?: {}): {
|
|
|
187
187
|
node: string;
|
|
188
188
|
args: string[];
|
|
189
189
|
};
|
|
190
|
+
'graph:sync': {
|
|
191
|
+
domain: string;
|
|
192
|
+
desc: string;
|
|
193
|
+
capability: string;
|
|
194
|
+
gates: string[];
|
|
195
|
+
};
|
|
190
196
|
'code:context': {
|
|
191
197
|
domain: string;
|
|
192
198
|
desc: string;
|
|
@@ -299,6 +305,11 @@ export declare function defaultEnv(overrides?: {}): {
|
|
|
299
305
|
desc: string;
|
|
300
306
|
node: string;
|
|
301
307
|
};
|
|
308
|
+
'benchmark:context': {
|
|
309
|
+
domain: string;
|
|
310
|
+
desc: string;
|
|
311
|
+
node: string;
|
|
312
|
+
};
|
|
302
313
|
'project:check': {
|
|
303
314
|
domain: string;
|
|
304
315
|
desc: string;
|
|
@@ -309,6 +320,11 @@ export declare function defaultEnv(overrides?: {}): {
|
|
|
309
320
|
desc: string;
|
|
310
321
|
node: string;
|
|
311
322
|
};
|
|
323
|
+
'demo:autonomy': {
|
|
324
|
+
domain: string;
|
|
325
|
+
desc: string;
|
|
326
|
+
node: string;
|
|
327
|
+
};
|
|
312
328
|
'release:check': {
|
|
313
329
|
domain: string;
|
|
314
330
|
desc: string;
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
import type { DeterministicDocument, GraphDocumentSource } from '../../graph/src/index.ts';
|
|
2
|
+
import type { ISO8601 } from '../../contracts/src/index.ts';
|
|
1
3
|
import type { SandboxBackend, SandboxCommandResult, SandboxDiffData, SandboxValidation } from '../../sandbox/src/index.ts';
|
|
2
4
|
import type { SandboxCommand, SandboxSession } from '../../contracts/src/index.ts';
|
|
3
5
|
export interface CommandRunner {
|
|
4
6
|
run(command: SandboxCommand): SandboxCommandResult | Promise<SandboxCommandResult>;
|
|
5
7
|
}
|
|
8
|
+
export declare class SpawnCommandRunner implements CommandRunner {
|
|
9
|
+
run(command: SandboxCommand): SandboxCommandResult;
|
|
10
|
+
}
|
|
11
|
+
export declare class GitGraphDocumentSource implements GraphDocumentSource {
|
|
12
|
+
private readonly root;
|
|
13
|
+
private readonly runner;
|
|
14
|
+
private readonly capturedAt;
|
|
15
|
+
constructor(root: string, runner: CommandRunner, capturedAt?: () => ISO8601);
|
|
16
|
+
listDocuments(): Promise<readonly DeterministicDocument[]>;
|
|
17
|
+
}
|
|
6
18
|
export interface PatchApplier {
|
|
7
19
|
apply(root: string, patch: string): void | Promise<void>;
|
|
20
|
+
revert(root: string, patch: string): void | Promise<void>;
|
|
8
21
|
}
|
|
9
22
|
export interface GitWorktreeOptions {
|
|
10
23
|
readonly repositoryRoot: string;
|
|
@@ -21,6 +34,7 @@ export declare class GitWorktreeBackend implements SandboxBackend {
|
|
|
21
34
|
validate(session: SandboxSession): Promise<SandboxValidation>;
|
|
22
35
|
diff(session: SandboxSession): Promise<SandboxDiffData>;
|
|
23
36
|
promote(session: SandboxSession): Promise<void>;
|
|
37
|
+
rollback(session: SandboxSession): Promise<void>;
|
|
24
38
|
reject(session: SandboxSession): Promise<void>;
|
|
25
39
|
destroy(session: SandboxSession): Promise<void>;
|
|
26
40
|
private runGit;
|
|
@@ -1,3 +1,63 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { graphDocumentId } from "../../graph/src/index.js";
|
|
5
|
+
export class SpawnCommandRunner {
|
|
6
|
+
run(command) {
|
|
7
|
+
const started = Date.now();
|
|
8
|
+
const result = spawnSync(command.executable, [...command.args], { cwd: command.cwd, env: sandboxEnvironment(command.env), encoding: 'utf8' });
|
|
9
|
+
return { exitCode: result.status ?? 1, stdout: result.stdout ?? '', stderr: [result.stderr ?? '', result.error?.message ?? ''].filter(Boolean).join('\n'), durationMs: Date.now() - started };
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class GitGraphDocumentSource {
|
|
13
|
+
root;
|
|
14
|
+
runner;
|
|
15
|
+
capturedAt;
|
|
16
|
+
constructor(root, runner, capturedAt = () => new Date().toISOString()) {
|
|
17
|
+
this.root = path.resolve(root);
|
|
18
|
+
this.runner = runner;
|
|
19
|
+
this.capturedAt = capturedAt;
|
|
20
|
+
}
|
|
21
|
+
async listDocuments() {
|
|
22
|
+
const result = await this.runner.run({ executable: 'git', args: ['-C', this.root, 'ls-files', '--cached', '--others', '--exclude-standard', '-z'] });
|
|
23
|
+
if (result.exitCode !== 0)
|
|
24
|
+
throw new Error(`Git file listing failed: ${result.stderr}`);
|
|
25
|
+
const documents = [];
|
|
26
|
+
for (const relative of result.stdout.split('\0').map((item) => item.trim()).filter(Boolean)) {
|
|
27
|
+
if (!isIndexable(relative))
|
|
28
|
+
continue;
|
|
29
|
+
const absolute = path.join(this.root, relative);
|
|
30
|
+
if (!isWithinRoot(this.root, absolute))
|
|
31
|
+
continue;
|
|
32
|
+
try {
|
|
33
|
+
const content = fs.readFileSync(absolute, 'utf8');
|
|
34
|
+
if (content.includes('\0') || Buffer.byteLength(content, 'utf8') > 1_000_000)
|
|
35
|
+
continue;
|
|
36
|
+
documents.push({ nodeId: graphDocumentId(relative), locator: relative, content, capturedAt: this.capturedAt() });
|
|
37
|
+
}
|
|
38
|
+
catch { /* unreadable/deleted files are skipped and remain auditable in Git status */ }
|
|
39
|
+
}
|
|
40
|
+
return documents;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function isIndexable(relative) {
|
|
44
|
+
if (relative.split('/').some((part) => part === 'node_modules' || part === '.git' || part === 'dist' || part === 'coverage'))
|
|
45
|
+
return false;
|
|
46
|
+
return /\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|yaml|yml)$/.test(relative);
|
|
47
|
+
}
|
|
48
|
+
function isWithinRoot(root, candidate) {
|
|
49
|
+
const relative = path.relative(root, candidate);
|
|
50
|
+
return relative.length === 0 || (!relative.startsWith(`..${path.sep}`) && relative !== '..' && !path.isAbsolute(relative));
|
|
51
|
+
}
|
|
52
|
+
function sandboxEnvironment(overrides) {
|
|
53
|
+
const inherited = {};
|
|
54
|
+
for (const key of ['PATH', 'NODE_PATH', 'SystemRoot', 'TMPDIR', 'TMP', 'TEMP']) {
|
|
55
|
+
const value = process.env[key];
|
|
56
|
+
if (value !== undefined)
|
|
57
|
+
inherited[key] = value;
|
|
58
|
+
}
|
|
59
|
+
return { ...inherited, ...(overrides ?? {}) };
|
|
60
|
+
}
|
|
1
61
|
export class GitWorktreeBackend {
|
|
2
62
|
runner;
|
|
3
63
|
options;
|
|
@@ -41,6 +101,12 @@ export class GitWorktreeBackend {
|
|
|
41
101
|
throw new Error(`Git promotion diff failed: ${patch.stderr}`);
|
|
42
102
|
await this.options.patchApplier.apply(this.options.repositoryRoot, patch.stdout);
|
|
43
103
|
}
|
|
104
|
+
async rollback(session) {
|
|
105
|
+
const patch = await this.runGit(['-C', session.root, 'diff', '--binary']);
|
|
106
|
+
if (patch.exitCode !== 0)
|
|
107
|
+
throw new Error(`Git rollback diff failed: ${patch.stderr}`);
|
|
108
|
+
await this.options.patchApplier.revert(this.options.repositoryRoot, patch.stdout);
|
|
109
|
+
}
|
|
44
110
|
async reject(session) {
|
|
45
111
|
await this.runGit(['-C', this.options.repositoryRoot, 'worktree', 'remove', '--force', session.root]);
|
|
46
112
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import type { AuditRecord, Checkpoint, DomainEvent, EntityId, Handoff, Observation, RuntimeRun, SandboxSession, Sprint, Task, RunId } from '../../contracts/src/index.ts';
|
|
1
|
+
import type { AuditRecord, Checkpoint, DomainEvent, EntityId, ExecutionResult, Handoff, Observation, RuntimeRun, SandboxSession, Sprint, Task, RunId } from '../../contracts/src/index.ts';
|
|
2
2
|
import type { EventStore } from '../../events/src/index.ts';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ApprovalStore } from '../../policy/src/index.ts';
|
|
4
|
+
import type { CheckpointStore, RuntimePersistence, RuntimePlanStep } from '../../runtime/src/index.ts';
|
|
5
|
+
import type { McpAuditEvent, McpAuditSink } from '../../mcp/src/index.ts';
|
|
4
6
|
import type { OrchestrationStore } from '../../orchestration/src/index.ts';
|
|
5
7
|
import type { SandboxStore } from '../../sandbox/src/index.ts';
|
|
6
8
|
import type { ObservationStore } from '../../observability/src/index.ts';
|
|
9
|
+
import type { GraphStore } from '../../graph/src/index.ts';
|
|
10
|
+
import type { Evidence, GraphEdge, GraphNode } from '../../contracts/src/index.ts';
|
|
11
|
+
import type { ContextCache } from '../../context/src/index.ts';
|
|
7
12
|
export interface SqliteStatement {
|
|
8
13
|
run(...parameters: readonly unknown[]): {
|
|
9
14
|
readonly changes?: number;
|
|
@@ -71,12 +76,64 @@ export declare class SqliteEventStore implements EventStore {
|
|
|
71
76
|
list(): readonly DomainEvent[];
|
|
72
77
|
private eventFrom;
|
|
73
78
|
}
|
|
79
|
+
export declare class SqliteGraphStore implements GraphStore {
|
|
80
|
+
private readonly db;
|
|
81
|
+
constructor(db: SqliteConnection);
|
|
82
|
+
getNode(id: EntityId): GraphNode | undefined;
|
|
83
|
+
listNodes(): readonly GraphNode[];
|
|
84
|
+
saveNode(node: GraphNode): void;
|
|
85
|
+
getEdge(key: string): GraphEdge | undefined;
|
|
86
|
+
listEdges(): readonly GraphEdge[];
|
|
87
|
+
saveEdge(key: string, edge: GraphEdge): void;
|
|
88
|
+
getEvidence(id: EntityId): Evidence | undefined;
|
|
89
|
+
saveEvidence(item: Evidence): void;
|
|
90
|
+
getSourceChecksum(sourceKey: string): string | undefined;
|
|
91
|
+
saveSourceChecksum(sourceKey: string, checksum: string): void;
|
|
92
|
+
private payload;
|
|
93
|
+
private listPayload;
|
|
94
|
+
}
|
|
95
|
+
export declare class SqliteContextCache implements ContextCache {
|
|
96
|
+
private readonly db;
|
|
97
|
+
constructor(db: SqliteConnection);
|
|
98
|
+
get(checksum: string): string | undefined;
|
|
99
|
+
set(checksum: string, content: string): void;
|
|
100
|
+
}
|
|
74
101
|
export declare class SqliteRuntimeRunStore {
|
|
75
102
|
private readonly repository;
|
|
76
103
|
constructor(db: SqliteConnection);
|
|
77
104
|
save(value: RuntimeRun): void;
|
|
78
105
|
get(runId: RunId): RuntimeRun | undefined;
|
|
79
106
|
}
|
|
107
|
+
export declare class SqliteRuntimePersistence implements RuntimePersistence {
|
|
108
|
+
private readonly db;
|
|
109
|
+
constructor(db: SqliteConnection);
|
|
110
|
+
saveRun(value: RuntimeRun): void;
|
|
111
|
+
getRun(runId: RunId): RuntimeRun | undefined;
|
|
112
|
+
savePlan(runId: RunId, plan: readonly RuntimePlanStep[]): void;
|
|
113
|
+
getPlan(runId: RunId): readonly RuntimePlanStep[] | undefined;
|
|
114
|
+
saveResults(runId: RunId, results: readonly ExecutionResult[]): void;
|
|
115
|
+
getResults(runId: RunId): readonly ExecutionResult[] | undefined;
|
|
116
|
+
saveCursor(runId: RunId, nextStep: number, startedAt: number): void;
|
|
117
|
+
getCursor(runId: RunId): {
|
|
118
|
+
readonly nextStep: number;
|
|
119
|
+
readonly startedAt: number;
|
|
120
|
+
} | undefined;
|
|
121
|
+
private put;
|
|
122
|
+
private payload;
|
|
123
|
+
}
|
|
124
|
+
export declare class SqliteApprovalStore implements ApprovalStore {
|
|
125
|
+
private readonly db;
|
|
126
|
+
constructor(db: SqliteConnection);
|
|
127
|
+
save(value: import('../../contracts/src/index.ts').ApprovalRequest): void;
|
|
128
|
+
get(id: EntityId): import('../../contracts/src/index.ts').ApprovalRequest | undefined;
|
|
129
|
+
list(): readonly import('../../contracts/src/index.ts').ApprovalRequest[];
|
|
130
|
+
private payload;
|
|
131
|
+
}
|
|
132
|
+
export declare class SqliteMcpAuditSink implements McpAuditSink {
|
|
133
|
+
private readonly audit;
|
|
134
|
+
constructor(db: SqliteConnection);
|
|
135
|
+
append(event: McpAuditEvent): void;
|
|
136
|
+
}
|
|
80
137
|
export declare class SqliteObservationStore implements ObservationStore {
|
|
81
138
|
private readonly repository;
|
|
82
139
|
constructor(db: SqliteConnection);
|