forjajs 1.7.2 → 2.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/CHANGELOG.md +49 -0
- package/README.md +223 -217
- package/README.pt-BR.md +323 -0
- package/dist/apps/dashboard/app/api/forja/[...path]/route.d.ts +10 -0
- package/dist/apps/dashboard/app/api/forja/[...path]/route.js +36 -0
- package/dist/apps/dashboard/app/api/forja/approval.d.ts +1 -0
- package/dist/apps/dashboard/app/api/forja/approval.js +8 -0
- package/dist/apps/dashboard/app/dashboard-client.d.ts +1 -0
- package/dist/apps/dashboard/app/dashboard-client.jsx +62 -0
- package/dist/apps/dashboard/app/layout.d.ts +9 -0
- package/dist/apps/dashboard/app/layout.jsx +7 -0
- package/dist/apps/dashboard/app/page.d.ts +1 -0
- package/dist/apps/dashboard/app/page.jsx +5 -0
- package/dist/apps/dashboard/app/providers.d.ts +4 -0
- package/dist/apps/dashboard/app/providers.jsx +7 -0
- package/dist/apps/dashboard/next.config.d.mts +6 -0
- package/dist/apps/dashboard/next.config.mjs +8 -0
- package/dist/apps/dashboard/src/index.d.ts +14 -0
- package/dist/apps/dashboard/src/index.js +16 -0
- package/dist/apps/server/src/app.module.d.ts +5 -0
- package/dist/apps/server/src/app.module.js +16 -0
- package/dist/apps/server/src/forja-nest.module.d.ts +59 -0
- package/dist/apps/server/src/forja-nest.module.js +316 -0
- package/dist/apps/server/src/index.d.ts +15 -0
- package/dist/apps/server/src/index.js +7 -0
- package/dist/apps/server/src/main.d.ts +12 -0
- package/dist/apps/server/src/main.js +105 -0
- package/dist/apps/worker/src/main.d.ts +12 -0
- package/dist/apps/worker/src/main.js +18 -0
- package/dist/lib/core/health.js +26 -4
- package/dist/packages/adapter-git/src/index.d.ts +27 -0
- package/dist/packages/adapter-git/src/index.js +53 -0
- package/dist/packages/adapter-nest/src/index.d.ts +71 -0
- package/dist/packages/adapter-nest/src/index.js +142 -0
- package/dist/packages/adapter-sqlite/src/index.d.ts +99 -0
- package/dist/packages/adapter-sqlite/src/index.js +108 -0
- package/dist/packages/context/src/index.d.ts +52 -0
- package/dist/packages/context/src/index.js +108 -0
- package/dist/packages/contracts/src/index.d.ts +368 -0
- package/dist/packages/contracts/src/index.js +27 -0
- package/dist/packages/core/src/index.d.ts +68 -0
- package/dist/packages/core/src/index.js +141 -0
- package/dist/packages/evals/src/index.d.ts +22 -0
- package/dist/packages/evals/src/index.js +65 -0
- package/dist/packages/events/src/index.d.ts +47 -0
- package/dist/packages/events/src/index.js +96 -0
- package/dist/packages/graph/src/index.d.ts +80 -0
- package/dist/packages/graph/src/index.js +163 -0
- package/dist/packages/mcp/src/index.d.ts +119 -0
- package/dist/packages/mcp/src/index.js +153 -0
- package/dist/packages/observability/src/index.d.ts +132 -0
- package/dist/packages/observability/src/index.js +86 -0
- package/dist/packages/orchestration/src/index.d.ts +122 -0
- package/dist/packages/orchestration/src/index.js +178 -0
- package/dist/packages/planner/src/index.d.ts +22 -0
- package/dist/packages/planner/src/index.js +70 -0
- package/dist/packages/plugin-sdk/src/index.d.ts +56 -0
- package/dist/packages/plugin-sdk/src/index.js +55 -0
- package/dist/packages/policy/src/index.d.ts +80 -0
- package/dist/packages/policy/src/index.js +136 -0
- package/dist/packages/runtime/src/index.d.ts +91 -0
- package/dist/packages/runtime/src/index.js +217 -0
- package/dist/packages/sandbox/src/index.d.ts +64 -0
- package/dist/packages/sandbox/src/index.js +108 -0
- package/dist/packages/scheduler/src/index.d.ts +56 -0
- package/dist/packages/scheduler/src/index.js +123 -0
- package/dist/packages/sdk/src/index.d.ts +122 -0
- package/dist/packages/sdk/src/index.js +40 -0
- package/dist/packages/validator/src/index.d.ts +36 -0
- package/dist/packages/validator/src/index.js +60 -0
- package/docs/architecture/FORJA-2.0-ARCHITECTURE.md +109 -0
- package/docs/architecture/FORJA-2.0-IMPACT-FOUNDATION.md +273 -0
- package/docs/security/FORJA-2.0-RELEASE-AUDIT-2026-08-01.md +95 -0
- package/docs/vision/FORJA-2.0-VISION.md +72 -0
- package/memory/50-orchestration/handoffs/2026-07-31_architect_foundation-contracts.md +15 -0
- package/memory/50-orchestration/handoffs/2026-07-31_backend-nest.md +22 -0
- package/memory/50-orchestration/handoffs/2026-07-31_context-engine.md +16 -0
- package/memory/50-orchestration/handoffs/2026-07-31_control-plane.md +28 -0
- package/memory/50-orchestration/handoffs/2026-07-31_core-capability-registry.md +15 -0
- package/memory/50-orchestration/handoffs/2026-07-31_evals-plugin-sdk.md +22 -0
- package/memory/50-orchestration/handoffs/2026-07-31_events-scheduler.md +16 -0
- package/memory/50-orchestration/handoffs/2026-07-31_graphloop.md +16 -0
- package/memory/50-orchestration/handoffs/2026-07-31_mcp.md +21 -0
- package/memory/50-orchestration/handoffs/2026-07-31_nest-bootstrap.md +28 -0
- package/memory/50-orchestration/handoffs/2026-07-31_next-dashboard.md +22 -0
- package/memory/50-orchestration/handoffs/2026-07-31_observability.md +27 -0
- package/memory/50-orchestration/handoffs/2026-07-31_orchestration.md +21 -0
- package/memory/50-orchestration/handoffs/2026-07-31_planner-validator.md +16 -0
- package/memory/50-orchestration/handoffs/2026-07-31_policy-engine.md +14 -0
- package/memory/50-orchestration/handoffs/2026-07-31_runtime-control-plane.md +23 -0
- package/memory/50-orchestration/handoffs/2026-07-31_runtime-controlado.md +15 -0
- package/memory/50-orchestration/handoffs/2026-07-31_sandbox.md +21 -0
- package/memory/50-orchestration/handoffs/2026-07-31_sdk.md +27 -0
- package/memory/50-orchestration/handoffs/2026-07-31_sqlite-adapter.md +21 -0
- package/memory/50-orchestration/handoffs/2026-07-31_worker-dashboard-boundary.md +23 -0
- package/memory/50-orchestration/handoffs/2026-08-01_approval-server-identity.md +23 -0
- package/memory/50-orchestration/handoffs/2026-08-01_dashboard-auth-query.md +24 -0
- package/memory/50-orchestration/handoffs/2026-08-01_graphloop-approvals.md +23 -0
- package/memory/90-decisions/0033-doctor-distingue-permissao-de-corrupcao.md +64 -0
- package/memory/90-decisions/0034-forja-2-core-e-contratos.md +29 -0
- package/memory/90-decisions/0035-forja-2-local-first-e-autonomia.md +23 -0
- package/memory/90-decisions/0036-forja-2-capability-registry.md +30 -0
- package/memory/90-decisions/0037-forja-2-policy-engine-obrigatorio.md +28 -0
- package/memory/90-decisions/0038-forja-2-runtime-controlado.md +28 -0
- package/memory/90-decisions/0039-forja-2-event-bus-scheduler-local-first.md +31 -0
- package/memory/90-decisions/0040-forja-2-context-engine-budget-cache.md +32 -0
- package/memory/90-decisions/0041-forja-2-graphloop-separado-codegraph.md +32 -0
- package/memory/90-decisions/0042-forja-2-planner-validator-independentes.md +29 -0
- package/memory/90-decisions/0043-forja-2-orchestration-entities.md +16 -0
- package/memory/90-decisions/0044-forja-2-sandbox-worktree.md +19 -0
- package/memory/90-decisions/0045-forja-2-sqlite-adapter.md +19 -0
- package/memory/90-decisions/0046-forja-2-mcp-adapter.md +18 -0
- package/memory/90-decisions/0047-forja-2-backend-nest-adapter.md +19 -0
- package/memory/90-decisions/0048-forja-2-sdk-transport.md +18 -0
- package/memory/90-decisions/0049-forja-2-observability-control-plane.md +18 -0
- package/memory/90-decisions/0050-forja-2-control-plane-application-ports.md +18 -0
- package/memory/90-decisions/0051-forja-2-runtime-control-plane-composition.md +18 -0
- package/memory/90-decisions/0052-forja-2-deterministic-evaluation.md +15 -0
- package/memory/90-decisions/0053-forja-2-plugin-sdk-permissionado.md +16 -0
- package/memory/90-decisions/0054-forja-2-worker-dashboard-boundary.md +15 -0
- package/memory/90-decisions/0055-forja-2-next-dashboard-distribution.md +16 -0
- package/memory/90-decisions/0056-forja-2-dashboard-proxy-auth-query.md +16 -0
- package/memory/90-decisions/0057-forja-2-graphloop-approvals-dashboard.md +15 -0
- package/memory/90-decisions/0058-forja-2-approval-server-identity.md +15 -0
- package/package.json +28 -3
- package/README.en.md +0 -329
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
11
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
12
|
+
};
|
|
13
|
+
var ForjaNestModule_1;
|
|
14
|
+
import { Controller, Get, Global, Inject, Injectable, Module, Optional, Post, Req, Res, Sse, UnauthorizedException, UseGuards } from '@nestjs/common';
|
|
15
|
+
import { Observable as RxObservable } from 'rxjs';
|
|
16
|
+
import { ForjaNestAdapter } from "../../../packages/adapter-nest/src/index.js";
|
|
17
|
+
export const FORJA_MCP = Symbol('FORJA_MCP');
|
|
18
|
+
export const FORJA_EVENT_STREAM = Symbol('FORJA_EVENT_STREAM');
|
|
19
|
+
export const FORJA_AUTHENTICATOR = Symbol('FORJA_AUTHENTICATOR');
|
|
20
|
+
export const FORJA_CONTROL_PLANE = Symbol('FORJA_CONTROL_PLANE');
|
|
21
|
+
function headers(request) {
|
|
22
|
+
return Object.fromEntries(Object.entries(request.headers).map(([key, value]) => [key, Array.isArray(value) ? value[0] : value]));
|
|
23
|
+
}
|
|
24
|
+
let ForjaLocalAuthGuard = class ForjaLocalAuthGuard {
|
|
25
|
+
authenticator;
|
|
26
|
+
constructor(authenticator) { this.authenticator = authenticator; }
|
|
27
|
+
async canActivate(context) {
|
|
28
|
+
if (this.authenticator === undefined)
|
|
29
|
+
return true;
|
|
30
|
+
const request = context.switchToHttp().getRequest();
|
|
31
|
+
if (await this.authenticator.authenticate(headers(request)))
|
|
32
|
+
return true;
|
|
33
|
+
throw new UnauthorizedException('Local authentication required');
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
ForjaLocalAuthGuard = __decorate([
|
|
37
|
+
Injectable(),
|
|
38
|
+
__param(0, Optional()),
|
|
39
|
+
__param(0, Inject(FORJA_AUTHENTICATOR)),
|
|
40
|
+
__metadata("design:paramtypes", [Object])
|
|
41
|
+
], ForjaLocalAuthGuard);
|
|
42
|
+
export { ForjaLocalAuthGuard };
|
|
43
|
+
let ForjaNestController = class ForjaNestController {
|
|
44
|
+
adapter;
|
|
45
|
+
constructor(adapter) { this.adapter = adapter; }
|
|
46
|
+
health(request, response) { return this.route(request, response, 'GET', '/health'); }
|
|
47
|
+
capabilities(request, response) { return this.route(request, response, 'GET', '/api/capabilities'); }
|
|
48
|
+
execute(request, response) { return this.route(request, response, 'POST', `/api/capabilities/${request.params.id}/execute`, request.body); }
|
|
49
|
+
context(request, response) { return this.route(request, response, 'POST', '/api/context/build', request.body); }
|
|
50
|
+
graphQuery(request, response) { return this.route(request, response, 'GET', '/api/graph/query'); }
|
|
51
|
+
graphImpact(request, response) { return this.route(request, response, 'GET', '/api/graph/impact'); }
|
|
52
|
+
taskNext(request, response) { return this.route(request, response, 'GET', '/api/tasks/next'); }
|
|
53
|
+
handoff(request, response) { return this.route(request, response, 'POST', '/api/handoffs', request.body); }
|
|
54
|
+
runtimeStart(request, response) { return this.route(request, response, 'POST', '/api/executions', request.body); }
|
|
55
|
+
runtimeGet(request, response) { return this.route(request, response, 'GET', `/api/executions/${request.params.id}`); }
|
|
56
|
+
runtimeExecute(request, response) { return this.route(request, response, 'POST', `/api/executions/${request.params.id}/execute`); }
|
|
57
|
+
runtimePause(request, response) { return this.route(request, response, 'POST', `/api/executions/${request.params.id}/pause`); }
|
|
58
|
+
runtimeResume(request, response) { return this.route(request, response, 'POST', `/api/executions/${request.params.id}/resume`); }
|
|
59
|
+
runtimeCancel(request, response) { return this.route(request, response, 'POST', `/api/executions/${request.params.id}/cancel`); }
|
|
60
|
+
sprintCreate(request, response) { return this.route(request, response, 'POST', '/api/sprints', request.body); }
|
|
61
|
+
sprintStart(request, response) { return this.route(request, response, 'POST', `/api/sprints/${request.params.id}/start`); }
|
|
62
|
+
sprintPause(request, response) { return this.route(request, response, 'POST', `/api/sprints/${request.params.id}/pause`); }
|
|
63
|
+
taskCreate(request, response) { return this.route(request, response, 'POST', '/api/tasks', request.body); }
|
|
64
|
+
taskStart(request, response) { return this.route(request, response, 'POST', `/api/tasks/${request.params.id}/start`); }
|
|
65
|
+
taskBlock(request, response) { return this.route(request, response, 'POST', `/api/tasks/${request.params.id}/block`); }
|
|
66
|
+
approvalGet(request, response) { return this.route(request, response, 'GET', `/api/approvals/${request.params.id}`); }
|
|
67
|
+
approvalDecide(request, response) { return this.route(request, response, 'POST', `/api/approvals/${request.params.id}/decide`, request.body); }
|
|
68
|
+
tools(request, response) { return this.route(request, response, 'GET', '/mcp/tools'); }
|
|
69
|
+
resources(request, response) { return this.route(request, response, 'GET', '/mcp/resources'); }
|
|
70
|
+
events() {
|
|
71
|
+
return new RxObservable((subscriber) => {
|
|
72
|
+
try {
|
|
73
|
+
const unsubscribe = this.adapter.subscribeSse((event) => subscriber.next({ id: event.id, type: event.event, data: event.data }));
|
|
74
|
+
return () => unsubscribe();
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
subscriber.error(error);
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async route(request, response, method, path, body) {
|
|
83
|
+
const result = await this.adapter.handle({ method, path, query: request.query, body, headers: headers(request), correlationId: this.correlation(request) });
|
|
84
|
+
response.status(result.status);
|
|
85
|
+
for (const [key, value] of Object.entries(result.headers))
|
|
86
|
+
response.setHeader(key, value);
|
|
87
|
+
return result.body;
|
|
88
|
+
}
|
|
89
|
+
correlation(request) { const value = request.headers['x-correlation-id']; return Array.isArray(value) ? value[0] : value; }
|
|
90
|
+
};
|
|
91
|
+
__decorate([
|
|
92
|
+
Get('health'),
|
|
93
|
+
__param(0, Req()),
|
|
94
|
+
__param(1, Res({ passthrough: true })),
|
|
95
|
+
__metadata("design:type", Function),
|
|
96
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
97
|
+
__metadata("design:returntype", Promise)
|
|
98
|
+
], ForjaNestController.prototype, "health", null);
|
|
99
|
+
__decorate([
|
|
100
|
+
Get('api/capabilities'),
|
|
101
|
+
__param(0, Req()),
|
|
102
|
+
__param(1, Res({ passthrough: true })),
|
|
103
|
+
__metadata("design:type", Function),
|
|
104
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
105
|
+
__metadata("design:returntype", Promise)
|
|
106
|
+
], ForjaNestController.prototype, "capabilities", null);
|
|
107
|
+
__decorate([
|
|
108
|
+
Post('api/capabilities/:id/execute'),
|
|
109
|
+
__param(0, Req()),
|
|
110
|
+
__param(1, Res({ passthrough: true })),
|
|
111
|
+
__metadata("design:type", Function),
|
|
112
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
113
|
+
__metadata("design:returntype", Promise)
|
|
114
|
+
], ForjaNestController.prototype, "execute", null);
|
|
115
|
+
__decorate([
|
|
116
|
+
Post('api/context/build'),
|
|
117
|
+
__param(0, Req()),
|
|
118
|
+
__param(1, Res({ passthrough: true })),
|
|
119
|
+
__metadata("design:type", Function),
|
|
120
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
121
|
+
__metadata("design:returntype", Promise)
|
|
122
|
+
], ForjaNestController.prototype, "context", null);
|
|
123
|
+
__decorate([
|
|
124
|
+
Get('api/graph/query'),
|
|
125
|
+
__param(0, Req()),
|
|
126
|
+
__param(1, Res({ passthrough: true })),
|
|
127
|
+
__metadata("design:type", Function),
|
|
128
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
129
|
+
__metadata("design:returntype", Promise)
|
|
130
|
+
], ForjaNestController.prototype, "graphQuery", null);
|
|
131
|
+
__decorate([
|
|
132
|
+
Get('api/graph/impact'),
|
|
133
|
+
__param(0, Req()),
|
|
134
|
+
__param(1, Res({ passthrough: true })),
|
|
135
|
+
__metadata("design:type", Function),
|
|
136
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
137
|
+
__metadata("design:returntype", Promise)
|
|
138
|
+
], ForjaNestController.prototype, "graphImpact", null);
|
|
139
|
+
__decorate([
|
|
140
|
+
Get('api/tasks/next'),
|
|
141
|
+
__param(0, Req()),
|
|
142
|
+
__param(1, Res({ passthrough: true })),
|
|
143
|
+
__metadata("design:type", Function),
|
|
144
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
145
|
+
__metadata("design:returntype", Promise)
|
|
146
|
+
], ForjaNestController.prototype, "taskNext", null);
|
|
147
|
+
__decorate([
|
|
148
|
+
Post('api/handoffs'),
|
|
149
|
+
__param(0, Req()),
|
|
150
|
+
__param(1, Res({ passthrough: true })),
|
|
151
|
+
__metadata("design:type", Function),
|
|
152
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
153
|
+
__metadata("design:returntype", Promise)
|
|
154
|
+
], ForjaNestController.prototype, "handoff", null);
|
|
155
|
+
__decorate([
|
|
156
|
+
Post('api/executions'),
|
|
157
|
+
__param(0, Req()),
|
|
158
|
+
__param(1, Res({ passthrough: true })),
|
|
159
|
+
__metadata("design:type", Function),
|
|
160
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
161
|
+
__metadata("design:returntype", Promise)
|
|
162
|
+
], ForjaNestController.prototype, "runtimeStart", null);
|
|
163
|
+
__decorate([
|
|
164
|
+
Get('api/executions/:id'),
|
|
165
|
+
__param(0, Req()),
|
|
166
|
+
__param(1, Res({ passthrough: true })),
|
|
167
|
+
__metadata("design:type", Function),
|
|
168
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
169
|
+
__metadata("design:returntype", Promise)
|
|
170
|
+
], ForjaNestController.prototype, "runtimeGet", null);
|
|
171
|
+
__decorate([
|
|
172
|
+
Post('api/executions/:id/execute'),
|
|
173
|
+
__param(0, Req()),
|
|
174
|
+
__param(1, Res({ passthrough: true })),
|
|
175
|
+
__metadata("design:type", Function),
|
|
176
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
177
|
+
__metadata("design:returntype", Promise)
|
|
178
|
+
], ForjaNestController.prototype, "runtimeExecute", null);
|
|
179
|
+
__decorate([
|
|
180
|
+
Post('api/executions/:id/pause'),
|
|
181
|
+
__param(0, Req()),
|
|
182
|
+
__param(1, Res({ passthrough: true })),
|
|
183
|
+
__metadata("design:type", Function),
|
|
184
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
185
|
+
__metadata("design:returntype", Promise)
|
|
186
|
+
], ForjaNestController.prototype, "runtimePause", null);
|
|
187
|
+
__decorate([
|
|
188
|
+
Post('api/executions/:id/resume'),
|
|
189
|
+
__param(0, Req()),
|
|
190
|
+
__param(1, Res({ passthrough: true })),
|
|
191
|
+
__metadata("design:type", Function),
|
|
192
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
193
|
+
__metadata("design:returntype", Promise)
|
|
194
|
+
], ForjaNestController.prototype, "runtimeResume", null);
|
|
195
|
+
__decorate([
|
|
196
|
+
Post('api/executions/:id/cancel'),
|
|
197
|
+
__param(0, Req()),
|
|
198
|
+
__param(1, Res({ passthrough: true })),
|
|
199
|
+
__metadata("design:type", Function),
|
|
200
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
201
|
+
__metadata("design:returntype", Promise)
|
|
202
|
+
], ForjaNestController.prototype, "runtimeCancel", null);
|
|
203
|
+
__decorate([
|
|
204
|
+
Post('api/sprints'),
|
|
205
|
+
__param(0, Req()),
|
|
206
|
+
__param(1, Res({ passthrough: true })),
|
|
207
|
+
__metadata("design:type", Function),
|
|
208
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
209
|
+
__metadata("design:returntype", Promise)
|
|
210
|
+
], ForjaNestController.prototype, "sprintCreate", null);
|
|
211
|
+
__decorate([
|
|
212
|
+
Post('api/sprints/:id/start'),
|
|
213
|
+
__param(0, Req()),
|
|
214
|
+
__param(1, Res({ passthrough: true })),
|
|
215
|
+
__metadata("design:type", Function),
|
|
216
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
217
|
+
__metadata("design:returntype", Promise)
|
|
218
|
+
], ForjaNestController.prototype, "sprintStart", null);
|
|
219
|
+
__decorate([
|
|
220
|
+
Post('api/sprints/:id/pause'),
|
|
221
|
+
__param(0, Req()),
|
|
222
|
+
__param(1, Res({ passthrough: true })),
|
|
223
|
+
__metadata("design:type", Function),
|
|
224
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
225
|
+
__metadata("design:returntype", Promise)
|
|
226
|
+
], ForjaNestController.prototype, "sprintPause", null);
|
|
227
|
+
__decorate([
|
|
228
|
+
Post('api/tasks'),
|
|
229
|
+
__param(0, Req()),
|
|
230
|
+
__param(1, Res({ passthrough: true })),
|
|
231
|
+
__metadata("design:type", Function),
|
|
232
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
233
|
+
__metadata("design:returntype", Promise)
|
|
234
|
+
], ForjaNestController.prototype, "taskCreate", null);
|
|
235
|
+
__decorate([
|
|
236
|
+
Post('api/tasks/:id/start'),
|
|
237
|
+
__param(0, Req()),
|
|
238
|
+
__param(1, Res({ passthrough: true })),
|
|
239
|
+
__metadata("design:type", Function),
|
|
240
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
241
|
+
__metadata("design:returntype", Promise)
|
|
242
|
+
], ForjaNestController.prototype, "taskStart", null);
|
|
243
|
+
__decorate([
|
|
244
|
+
Post('api/tasks/:id/block'),
|
|
245
|
+
__param(0, Req()),
|
|
246
|
+
__param(1, Res({ passthrough: true })),
|
|
247
|
+
__metadata("design:type", Function),
|
|
248
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
249
|
+
__metadata("design:returntype", Promise)
|
|
250
|
+
], ForjaNestController.prototype, "taskBlock", null);
|
|
251
|
+
__decorate([
|
|
252
|
+
Get('api/approvals/:id'),
|
|
253
|
+
__param(0, Req()),
|
|
254
|
+
__param(1, Res({ passthrough: true })),
|
|
255
|
+
__metadata("design:type", Function),
|
|
256
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
257
|
+
__metadata("design:returntype", Promise)
|
|
258
|
+
], ForjaNestController.prototype, "approvalGet", null);
|
|
259
|
+
__decorate([
|
|
260
|
+
Post('api/approvals/:id/decide'),
|
|
261
|
+
__param(0, Req()),
|
|
262
|
+
__param(1, Res({ passthrough: true })),
|
|
263
|
+
__metadata("design:type", Function),
|
|
264
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
265
|
+
__metadata("design:returntype", Promise)
|
|
266
|
+
], ForjaNestController.prototype, "approvalDecide", null);
|
|
267
|
+
__decorate([
|
|
268
|
+
Get('mcp/tools'),
|
|
269
|
+
__param(0, Req()),
|
|
270
|
+
__param(1, Res({ passthrough: true })),
|
|
271
|
+
__metadata("design:type", Function),
|
|
272
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
273
|
+
__metadata("design:returntype", Promise)
|
|
274
|
+
], ForjaNestController.prototype, "tools", null);
|
|
275
|
+
__decorate([
|
|
276
|
+
Get('mcp/resources'),
|
|
277
|
+
__param(0, Req()),
|
|
278
|
+
__param(1, Res({ passthrough: true })),
|
|
279
|
+
__metadata("design:type", Function),
|
|
280
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
281
|
+
__metadata("design:returntype", Promise)
|
|
282
|
+
], ForjaNestController.prototype, "resources", null);
|
|
283
|
+
__decorate([
|
|
284
|
+
Sse('api/events'),
|
|
285
|
+
__metadata("design:type", Function),
|
|
286
|
+
__metadata("design:paramtypes", []),
|
|
287
|
+
__metadata("design:returntype", Function)
|
|
288
|
+
], ForjaNestController.prototype, "events", null);
|
|
289
|
+
ForjaNestController = __decorate([
|
|
290
|
+
Controller(),
|
|
291
|
+
UseGuards(ForjaLocalAuthGuard),
|
|
292
|
+
__metadata("design:paramtypes", [ForjaNestAdapter])
|
|
293
|
+
], ForjaNestController);
|
|
294
|
+
export { ForjaNestController };
|
|
295
|
+
let ForjaNestModule = ForjaNestModule_1 = class ForjaNestModule {
|
|
296
|
+
static register(options) {
|
|
297
|
+
return {
|
|
298
|
+
module: ForjaNestModule_1,
|
|
299
|
+
controllers: [ForjaNestController],
|
|
300
|
+
providers: [
|
|
301
|
+
{ provide: FORJA_MCP, useValue: options.mcp },
|
|
302
|
+
{ provide: FORJA_EVENT_STREAM, useValue: options.eventStream },
|
|
303
|
+
{ provide: FORJA_AUTHENTICATOR, useValue: options.authenticator },
|
|
304
|
+
{ provide: FORJA_CONTROL_PLANE, useValue: options.controlPlane },
|
|
305
|
+
ForjaLocalAuthGuard,
|
|
306
|
+
{ provide: ForjaNestAdapter, useFactory: (mcp, stream, authenticator, controlPlane) => new ForjaNestAdapter(mcp, stream, authenticator, controlPlane), inject: [FORJA_MCP, FORJA_EVENT_STREAM, FORJA_AUTHENTICATOR, FORJA_CONTROL_PLANE] },
|
|
307
|
+
],
|
|
308
|
+
exports: [ForjaNestAdapter],
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
ForjaNestModule = ForjaNestModule_1 = __decorate([
|
|
313
|
+
Global(),
|
|
314
|
+
Module({})
|
|
315
|
+
], ForjaNestModule);
|
|
316
|
+
export { ForjaNestModule };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { McpServer } from '../../../packages/mcp/src/index.ts';
|
|
2
|
+
import { ForjaNestAdapter, type EventStream, type LocalAuthenticator, type NestModuleDefinition } from '../../../packages/adapter-nest/src/index.ts';
|
|
3
|
+
import type { ControlPlanePort } from '../../../packages/observability/src/index.ts';
|
|
4
|
+
export interface ForjaServerOptions {
|
|
5
|
+
readonly mcp: McpServer;
|
|
6
|
+
readonly eventStream?: EventStream;
|
|
7
|
+
readonly authenticator?: LocalAuthenticator;
|
|
8
|
+
readonly controlPlane?: ControlPlanePort;
|
|
9
|
+
}
|
|
10
|
+
export declare class ForjaServerApplication {
|
|
11
|
+
readonly http: ForjaNestAdapter;
|
|
12
|
+
constructor(options: ForjaServerOptions);
|
|
13
|
+
modules(): readonly NestModuleDefinition[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createForjaServer(options: ForjaServerOptions): ForjaServerApplication;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ForjaNestAdapter } from "../../../packages/adapter-nest/src/index.js";
|
|
2
|
+
export class ForjaServerApplication {
|
|
3
|
+
http;
|
|
4
|
+
constructor(options) { this.http = new ForjaNestAdapter(options.mcp, options.eventStream, options.authenticator, options.controlPlane); }
|
|
5
|
+
modules() { return this.http.modules(); }
|
|
6
|
+
}
|
|
7
|
+
export function createForjaServer(options) { return new ForjaServerApplication(options); }
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { CapabilityRegistry } from '../../../packages/core/src/index.ts';
|
|
3
|
+
import { PolicyEngine } from '../../../packages/policy/src/index.ts';
|
|
4
|
+
import { McpServer } from '../../../packages/mcp/src/index.ts';
|
|
5
|
+
import { ControlPlane } from '../../../packages/observability/src/index.ts';
|
|
6
|
+
import { InMemoryEventStream, type LocalAuthenticator } from '../../../packages/adapter-nest/src/index.ts';
|
|
7
|
+
import { GraphLoop } from '../../../packages/graph/src/index.ts';
|
|
8
|
+
export declare function createDefaultMcp(registry?: CapabilityRegistry, policy?: PolicyEngine, graph?: GraphLoop): McpServer;
|
|
9
|
+
export declare function createDefaultPolicy(): PolicyEngine;
|
|
10
|
+
export declare function createLocalAuthenticator(token?: string | undefined): LocalAuthenticator | undefined;
|
|
11
|
+
export declare function createDefaultControlPlane(eventStream: InMemoryEventStream, registry?: CapabilityRegistry, policy?: PolicyEngine): ControlPlane;
|
|
12
|
+
export declare function bootstrap(port?: number): Promise<import("@nestjs/common").INestApplication<any>>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { NestFactory } from '@nestjs/core';
|
|
3
|
+
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
4
|
+
import { CapabilityRegistry } from "../../../packages/core/src/index.js";
|
|
5
|
+
import { PolicyEngine } from "../../../packages/policy/src/index.js";
|
|
6
|
+
import { McpServer } from "../../../packages/mcp/src/index.js";
|
|
7
|
+
import { ControlPlane } from "../../../packages/observability/src/index.js";
|
|
8
|
+
import { ApprovalLedger } from "../../../packages/policy/src/index.js";
|
|
9
|
+
import { HandoffEngine, InMemoryOrchestrationStore, SprintEngine, TaskEngine } from "../../../packages/orchestration/src/index.js";
|
|
10
|
+
import { validateTokenBudget } from "../../../packages/contracts/src/index.js";
|
|
11
|
+
import { createBearerAuthenticator, InMemoryEventStream } from "../../../packages/adapter-nest/src/index.js";
|
|
12
|
+
import { AppModule } from "./app.module.js";
|
|
13
|
+
import { RuntimeEngine } from "../../../packages/runtime/src/index.js";
|
|
14
|
+
import { GraphLoop } from "../../../packages/graph/src/index.js";
|
|
15
|
+
export function createDefaultMcp(registry = new CapabilityRegistry(), policy = createDefaultPolicy(), graph = new GraphLoop()) {
|
|
16
|
+
return new McpServer({ registry, policy, graph, agent: { id: 'local-server', name: 'Forja local server', role: 'server', autonomy: 'supervised', permissions: [], capabilities: [] } });
|
|
17
|
+
}
|
|
18
|
+
export function createDefaultPolicy() {
|
|
19
|
+
const readOnlyRule = { id: 'local-read-only', priority: 10, effect: 'ALLOW', reason: 'Default local server permits read capabilities only', scope: { categories: ['read'], environments: ['local'] } };
|
|
20
|
+
return new PolicyEngine({ rules: [readOnlyRule] });
|
|
21
|
+
}
|
|
22
|
+
export function createLocalAuthenticator(token = process.env.FORJA_AUTH_TOKEN) {
|
|
23
|
+
if (token === undefined || token.length === 0)
|
|
24
|
+
return undefined;
|
|
25
|
+
return createBearerAuthenticator(token);
|
|
26
|
+
}
|
|
27
|
+
class DefaultRuntimeApplication {
|
|
28
|
+
contexts = new Map();
|
|
29
|
+
runtime;
|
|
30
|
+
policy;
|
|
31
|
+
constructor(registry, policy) {
|
|
32
|
+
this.policy = policy;
|
|
33
|
+
this.runtime = new RuntimeEngine({
|
|
34
|
+
registry,
|
|
35
|
+
planner: { plan: (_objective, context) => { if (!isRecord(context) || !Array.isArray(context.steps))
|
|
36
|
+
throw new Error('Runtime plan context is missing'); return context.steps; } },
|
|
37
|
+
contextBuilder: { build: async (objective) => this.contexts.get(objective) },
|
|
38
|
+
validator: { validate: (run, results) => this.validate(run, results) },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async start(input) {
|
|
42
|
+
const value = runtimeInput(input);
|
|
43
|
+
this.contexts.set(value.objective, { steps: value.steps });
|
|
44
|
+
try {
|
|
45
|
+
return await this.runtime.start({ objective: value.objective, agent: value.agent, budget: value.budget, policy: this.policy, sprintId: value.sprintId, taskId: value.taskId, correlationId: value.correlationId });
|
|
46
|
+
}
|
|
47
|
+
finally {
|
|
48
|
+
this.contexts.delete(value.objective);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
execute(id) { return this.runtime.execute(id); }
|
|
52
|
+
get(id) { return this.runtime.get(id); }
|
|
53
|
+
pause(id) { return this.runtime.pause(id); }
|
|
54
|
+
resume(id) { return this.runtime.resume(id); }
|
|
55
|
+
cancel(id) { return this.runtime.cancel(id); }
|
|
56
|
+
validate(run, results) {
|
|
57
|
+
const passed = results.length === run.steps && results.every((result) => result.status === 'succeeded' && result.evidence.length > 0);
|
|
58
|
+
const now = new Date().toISOString();
|
|
59
|
+
return { schemaVersion: '2.0', createdAt: now, updatedAt: now, correlationId: run.correlationId, status: passed ? 'accepted' : 'rejected', checks: [{ name: 'capabilities-succeeded-with-evidence', passed, evidenceIds: results.flatMap((result) => result.evidence.map((item) => item.id)) }], summary: passed ? 'All runtime steps succeeded with evidence' : 'Runtime step failed or lacked evidence' };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function runtimeInput(input) {
|
|
63
|
+
if (!isRecord(input) || typeof input.objective !== 'string' || typeof input.agent !== 'object' || input.agent === null || !isRecord(input.agent) || typeof input.budget !== 'object' || input.budget === null || !isRecord(input.budget) || !Array.isArray(input.steps))
|
|
64
|
+
throw new Error('Runtime requires objective, agent, budget and steps');
|
|
65
|
+
const agent = input.agent;
|
|
66
|
+
const budget = input.budget;
|
|
67
|
+
if (input.objective.trim().length === 0 || typeof agent.id !== 'string' || typeof agent.name !== 'string' || typeof agent.role !== 'string')
|
|
68
|
+
throw new Error('Runtime agent and objective are invalid');
|
|
69
|
+
validateTokenBudget(budget);
|
|
70
|
+
const steps = input.steps.map((step) => { if (!isRecord(step) || typeof step.capabilityId !== 'string' || typeof step.estimatedTokens !== 'number')
|
|
71
|
+
throw new Error('Runtime step requires capabilityId and estimatedTokens'); return step; });
|
|
72
|
+
if (steps.length === 0)
|
|
73
|
+
throw new Error('Runtime requires at least one capability step');
|
|
74
|
+
return { objective: input.objective, agent, budget, steps, sprintId: typeof input.sprintId === 'string' ? input.sprintId : undefined, taskId: typeof input.taskId === 'string' ? input.taskId : undefined, correlationId: typeof input.correlationId === 'string' ? input.correlationId : undefined };
|
|
75
|
+
}
|
|
76
|
+
function isRecord(value) { return typeof value === 'object' && value !== null; }
|
|
77
|
+
export function createDefaultControlPlane(eventStream, registry = new CapabilityRegistry(), policy = createDefaultPolicy()) {
|
|
78
|
+
const store = new InMemoryOrchestrationStore();
|
|
79
|
+
const sprintEngine = new SprintEngine(store);
|
|
80
|
+
const taskEngine = new TaskEngine(store, sprintEngine);
|
|
81
|
+
const handoffEngine = new HandoffEngine(store);
|
|
82
|
+
const approvals = new ApprovalLedger();
|
|
83
|
+
const runtime = new DefaultRuntimeApplication(registry, policy);
|
|
84
|
+
return new ControlPlane(undefined, {
|
|
85
|
+
runtime: { start: (input) => runtime.start(input), get: (input) => runtime.get(input), execute: (input) => runtime.execute(input), pause: (input) => runtime.pause(input), resume: (input) => runtime.resume(input), cancel: (input) => runtime.cancel(input) },
|
|
86
|
+
sprint: { create: (input) => sprintEngine.create(input), start: (id) => sprintEngine.start(id), pause: (id) => sprintEngine.pause(id) },
|
|
87
|
+
task: { create: (input) => taskEngine.create(input), start: (id) => taskEngine.start(id), block: (id) => taskEngine.block(id) },
|
|
88
|
+
handoff: { create: (input) => handoffEngine.create(input) },
|
|
89
|
+
approvals: { get: (id) => approvals.get(id), list: () => approvals.list(), decide: (input) => { const value = input; return approvals.decide(value.id, { decision: value.input.decision, approverId: value.input.approverId, decidedAt: value.input.decidedAt ?? new Date().toISOString() }); } },
|
|
90
|
+
events: { publish: (event) => eventStream.publish({ id: event.id, event: event.type, data: event.data, correlationId: event.correlationId }) },
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
export async function bootstrap(port = Number(process.env.FORJA_PORT ?? 3000)) {
|
|
94
|
+
const eventStream = new InMemoryEventStream();
|
|
95
|
+
const registry = new CapabilityRegistry();
|
|
96
|
+
const policy = createDefaultPolicy();
|
|
97
|
+
const mcp = createDefaultMcp(registry, policy, new GraphLoop());
|
|
98
|
+
const app = await NestFactory.create(AppModule.register({ mcp, eventStream, authenticator: createLocalAuthenticator(), controlPlane: createDefaultControlPlane(eventStream, registry, policy) }));
|
|
99
|
+
const config = new DocumentBuilder().setTitle('ForjaJS 2.0 API').setDescription('Local-first agent control plane').setVersion('2.0.0').build();
|
|
100
|
+
SwaggerModule.setup('docs', app, SwaggerModule.createDocument(app, config));
|
|
101
|
+
await app.listen(port, '127.0.0.1');
|
|
102
|
+
return app;
|
|
103
|
+
}
|
|
104
|
+
if (import.meta.url === `file://${process.argv[1]}`)
|
|
105
|
+
void bootstrap();
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { EvaluationEngine } from '../../../packages/evals/src/index.ts';
|
|
2
|
+
import { EventBus } from '../../../packages/events/src/index.ts';
|
|
3
|
+
import { Scheduler } from '../../../packages/scheduler/src/index.ts';
|
|
4
|
+
import { InMemoryObservationStore, ObservabilityRecorder } from '../../../packages/observability/src/index.ts';
|
|
5
|
+
export interface WorkerRuntime {
|
|
6
|
+
readonly events: EventBus;
|
|
7
|
+
readonly scheduler: Scheduler;
|
|
8
|
+
readonly observations: InMemoryObservationStore;
|
|
9
|
+
readonly evaluations: EvaluationEngine;
|
|
10
|
+
readonly recorder: ObservabilityRecorder;
|
|
11
|
+
}
|
|
12
|
+
export declare function createWorkerRuntime(): WorkerRuntime;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { EvaluationEngine } from "../../../packages/evals/src/index.js";
|
|
2
|
+
import { EventBus } from "../../../packages/events/src/index.js";
|
|
3
|
+
import { Scheduler } from "../../../packages/scheduler/src/index.js";
|
|
4
|
+
import { InMemoryObservationStore, ObservabilityRecorder } from "../../../packages/observability/src/index.js";
|
|
5
|
+
export function createWorkerRuntime() {
|
|
6
|
+
const observations = new InMemoryObservationStore();
|
|
7
|
+
const events = new EventBus();
|
|
8
|
+
const scheduler = new Scheduler(1);
|
|
9
|
+
const evaluations = new EvaluationEngine(observations);
|
|
10
|
+
const recorder = new ObservabilityRecorder(observations);
|
|
11
|
+
return { events, scheduler, observations, evaluations, recorder };
|
|
12
|
+
}
|
|
13
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
14
|
+
const worker = createWorkerRuntime();
|
|
15
|
+
worker.events.subscribe({ id: 'evaluation-worker', eventTypes: ['observation.recorded'], maxRetries: 2 }, async () => {
|
|
16
|
+
await worker.evaluations.evaluate({ scope: 'workspace' });
|
|
17
|
+
});
|
|
18
|
+
}
|
package/dist/lib/core/health.js
CHANGED
|
@@ -63,7 +63,7 @@ export function defaultEnv(overrides = {}) {
|
|
|
63
63
|
return {
|
|
64
64
|
root: repoRoot,
|
|
65
65
|
fs,
|
|
66
|
-
importModule: (specifier) => import(__rewriteRelativeImportExtension(specifier)),
|
|
66
|
+
importModule: (specifier) => import(__rewriteRelativeImportExtension(specifier, true)),
|
|
67
67
|
process: globalThis.process,
|
|
68
68
|
workspace: { dbPath: getWorkspaceDbPath, info: getWorkspaceInfo },
|
|
69
69
|
...overrides,
|
|
@@ -139,8 +139,9 @@ const memoryDb = {
|
|
|
139
139
|
fix: 'npm run sync:universal',
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
-
// Existir não é abrir: um banco corrompido
|
|
143
|
-
// banco saudável
|
|
142
|
+
// Existir não é abrir: um banco corrompido, sem permissão ou travado dá o mesmo `existsSync`
|
|
143
|
+
// de um banco saudável. Os três reprovam a abertura por motivos opostos e pedem correções
|
|
144
|
+
// opostas — o `catch` abaixo classifica por `err.code`, nunca colapsa num "corrompido" único.
|
|
144
145
|
const { default: Database } = await env.importModule('better-sqlite3');
|
|
145
146
|
try {
|
|
146
147
|
const db = new Database(dbPath, { readonly: true });
|
|
@@ -149,9 +150,30 @@ const memoryDb = {
|
|
|
149
150
|
return { status: 'ok', detail: `${n} nós indexados`, fix: null };
|
|
150
151
|
}
|
|
151
152
|
catch (err) {
|
|
153
|
+
const code = asErrno(err).code || '';
|
|
154
|
+
// CANTOPEN/EACCES: o arquivo está íntegro, o processo é que não o alcança — sandbox, FS
|
|
155
|
+
// read-only, diretório sem permissão. sync:universal *escreve* no banco: prescrito aqui,
|
|
156
|
+
// reencenaria o mesmo CANTOPEN sem curar nada. Colapsar isso em "corrompido" é o bug que
|
|
157
|
+
// este ramo fecha — a integridade nunca foi tocada.
|
|
158
|
+
if (code === 'SQLITE_CANTOPEN' || code === 'EACCES') {
|
|
159
|
+
return {
|
|
160
|
+
status: 'fail',
|
|
161
|
+
detail: `banco existe mas não abre (${code}) — sem permissão de acesso, não corrupção`,
|
|
162
|
+
fix: `garanta leitura em ${dbPath} (sandbox? FS read-only?) — NÃO rode sync:universal`,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
// BUSY: outro processo mantém o lock. O banco está são; esperar resolve.
|
|
166
|
+
if (code === 'SQLITE_BUSY') {
|
|
167
|
+
return {
|
|
168
|
+
status: 'warn',
|
|
169
|
+
detail: `banco ocupado (${code}) — outro processo o mantém travado`,
|
|
170
|
+
fix: 'aguarde o processo concorrente liberar o lock e rode de novo',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// Só o que sobra — SQLITE_CORRUPT, SQLITE_NOTADB, o resto — é integridade. Aí sim reindexar.
|
|
152
174
|
return {
|
|
153
175
|
status: 'fail',
|
|
154
|
-
detail: `banco existe mas não abre (${
|
|
176
|
+
detail: `banco existe mas não abre (${code || asErrno(err).message}) — provavelmente corrompido`,
|
|
155
177
|
fix: 'npm run sync:universal',
|
|
156
178
|
};
|
|
157
179
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SandboxBackend, SandboxCommandResult, SandboxDiffData, SandboxValidation } from '../../sandbox/src/index.ts';
|
|
2
|
+
import type { SandboxCommand, SandboxSession } from '../../contracts/src/index.ts';
|
|
3
|
+
export interface CommandRunner {
|
|
4
|
+
run(command: SandboxCommand): SandboxCommandResult | Promise<SandboxCommandResult>;
|
|
5
|
+
}
|
|
6
|
+
export interface PatchApplier {
|
|
7
|
+
apply(root: string, patch: string): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export interface GitWorktreeOptions {
|
|
10
|
+
readonly repositoryRoot: string;
|
|
11
|
+
readonly sourceRef: string;
|
|
12
|
+
readonly patchApplier: PatchApplier;
|
|
13
|
+
}
|
|
14
|
+
export declare class GitWorktreeBackend implements SandboxBackend {
|
|
15
|
+
private readonly runner;
|
|
16
|
+
private readonly options;
|
|
17
|
+
constructor(runner: CommandRunner, options: GitWorktreeOptions);
|
|
18
|
+
create(session: SandboxSession): Promise<void>;
|
|
19
|
+
prepare(session: SandboxSession): Promise<void>;
|
|
20
|
+
execute(session: SandboxSession, command: SandboxCommand): Promise<SandboxCommandResult>;
|
|
21
|
+
validate(session: SandboxSession): Promise<SandboxValidation>;
|
|
22
|
+
diff(session: SandboxSession): Promise<SandboxDiffData>;
|
|
23
|
+
promote(session: SandboxSession): Promise<void>;
|
|
24
|
+
reject(session: SandboxSession): Promise<void>;
|
|
25
|
+
destroy(session: SandboxSession): Promise<void>;
|
|
26
|
+
private runGit;
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export class GitWorktreeBackend {
|
|
2
|
+
runner;
|
|
3
|
+
options;
|
|
4
|
+
constructor(runner, options) { this.runner = runner; this.options = options; }
|
|
5
|
+
async create(session) {
|
|
6
|
+
await this.runGit(['-C', this.options.repositoryRoot, 'worktree', 'add', '--detach', session.root, this.options.sourceRef]);
|
|
7
|
+
}
|
|
8
|
+
async prepare(session) {
|
|
9
|
+
const result = await this.runGit(['-C', session.root, 'status', '--porcelain']);
|
|
10
|
+
if (result.exitCode !== 0)
|
|
11
|
+
throw new Error(`Git worktree preparation failed: ${result.stderr}`);
|
|
12
|
+
}
|
|
13
|
+
async execute(session, command) {
|
|
14
|
+
return this.runner.run({ ...command, cwd: session.root });
|
|
15
|
+
}
|
|
16
|
+
async validate(session) {
|
|
17
|
+
const result = await this.runGit(['-C', session.root, 'diff', '--check']);
|
|
18
|
+
return { status: result.exitCode === 0 ? 'accepted' : 'rejected', evidenceIds: [], summary: result.exitCode === 0 ? 'git diff --check passed' : `git diff --check failed: ${result.stderr}` };
|
|
19
|
+
}
|
|
20
|
+
async diff(session) {
|
|
21
|
+
const [names, stats] = await Promise.all([
|
|
22
|
+
this.runGit(['-C', session.root, 'diff', '--name-only']),
|
|
23
|
+
this.runGit(['-C', session.root, 'diff', '--numstat']),
|
|
24
|
+
]);
|
|
25
|
+
if (names.exitCode !== 0 || stats.exitCode !== 0)
|
|
26
|
+
throw new Error(`Git diff failed: ${names.stderr || stats.stderr}`);
|
|
27
|
+
let additions = 0;
|
|
28
|
+
let deletions = 0;
|
|
29
|
+
for (const line of stats.stdout.split('\n').map((item) => item.trim()).filter(Boolean)) {
|
|
30
|
+
const [added, removed] = line.split('\t');
|
|
31
|
+
if (added !== '-' && Number.isInteger(Number(added)))
|
|
32
|
+
additions += Number(added);
|
|
33
|
+
if (removed !== '-' && Number.isInteger(Number(removed)))
|
|
34
|
+
deletions += Number(removed);
|
|
35
|
+
}
|
|
36
|
+
return { files: names.stdout.split('\n').map((item) => item.trim()).filter(Boolean), additions, deletions, evidenceIds: [] };
|
|
37
|
+
}
|
|
38
|
+
async promote(session) {
|
|
39
|
+
const patch = await this.runGit(['-C', session.root, 'diff', '--binary']);
|
|
40
|
+
if (patch.exitCode !== 0)
|
|
41
|
+
throw new Error(`Git promotion diff failed: ${patch.stderr}`);
|
|
42
|
+
await this.options.patchApplier.apply(this.options.repositoryRoot, patch.stdout);
|
|
43
|
+
}
|
|
44
|
+
async reject(session) {
|
|
45
|
+
await this.runGit(['-C', this.options.repositoryRoot, 'worktree', 'remove', '--force', session.root]);
|
|
46
|
+
}
|
|
47
|
+
async destroy(session) {
|
|
48
|
+
await this.runGit(['-C', this.options.repositoryRoot, 'worktree', 'remove', '--force', session.root]);
|
|
49
|
+
}
|
|
50
|
+
async runGit(args) {
|
|
51
|
+
return this.runner.run({ executable: 'git', args });
|
|
52
|
+
}
|
|
53
|
+
}
|