forjajs 5.1.0 → 5.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/CHANGELOG.md +76 -0
- package/README.md +37 -4
- package/README.pt-BR.md +39 -4
- package/dist/apps/cli/src/index.d.ts +0 -1
- package/dist/apps/cli/src/index.js +43 -32
- package/dist/apps/dashboard/app/api/forja/[...path]/route.js +34 -1
- package/dist/apps/dashboard/app/api/forja/capabilities.d.ts +26 -0
- package/dist/apps/dashboard/app/api/forja/capabilities.js +39 -0
- package/dist/apps/dashboard/app/dashboard-client.jsx +607 -42
- package/dist/apps/server/src/forja-nest.module.d.ts +6 -0
- package/dist/apps/server/src/forja-nest.module.js +55 -0
- package/dist/apps/server/src/main.d.ts +21 -4
- package/dist/apps/server/src/main.js +79 -57
- package/dist/apps/server/src/task-planning-service.d.ts +29 -0
- package/dist/apps/server/src/task-planning-service.js +195 -0
- package/dist/apps/server/src/task-runtime-coordinator.d.ts +57 -0
- package/dist/apps/server/src/task-runtime-coordinator.js +229 -0
- package/dist/bin/forja.js +3 -2
- package/dist/lib/agent-evals.d.ts +138 -0
- package/dist/lib/agent-evals.js +349 -0
- package/dist/lib/cli-output.js +14 -2
- package/dist/lib/code-context.d.ts +33 -5
- package/dist/lib/code-context.js +70 -5
- package/dist/lib/context-builder.d.ts +49 -4
- package/dist/lib/context-builder.js +114 -47
- package/dist/lib/core/coverage-gate.d.ts +59 -0
- package/dist/lib/core/coverage-gate.js +58 -0
- package/dist/lib/core/doc-graph.d.ts +38 -0
- package/dist/lib/core/doc-graph.js +83 -0
- package/dist/lib/core/health.js +286 -5
- package/dist/lib/core/journey.js +26 -0
- package/dist/lib/core/registry.js +81 -6
- package/dist/lib/docs-reference.d.ts +35 -0
- package/dist/lib/docs-reference.js +57 -0
- package/dist/lib/project-wiring.js +6 -2
- package/dist/lib/session-memory.d.ts +38 -0
- package/dist/lib/session-memory.js +206 -0
- package/dist/lib/spec-trace.d.ts +46 -0
- package/dist/lib/spec-trace.js +184 -0
- package/dist/packages/adapter-nest/src/index.d.ts +2 -1
- package/dist/packages/adapter-nest/src/index.js +59 -1
- package/dist/packages/adapter-sqlite/src/index.d.ts +15 -1
- package/dist/packages/adapter-sqlite/src/index.js +61 -1
- package/dist/packages/context/src/index.d.ts +2 -0
- package/dist/packages/context/src/index.js +36 -15
- package/dist/packages/contracts/src/index.d.ts +64 -0
- package/dist/packages/core/src/index.d.ts +9 -1
- package/dist/packages/core/src/index.js +28 -3
- package/dist/packages/graph/src/index.js +14 -5
- package/dist/packages/mcp/src/index.d.ts +8 -0
- package/dist/packages/mcp/src/index.js +12 -1
- package/dist/packages/observability/src/index.d.ts +11 -0
- package/dist/packages/observability/src/index.js +3 -0
- package/dist/packages/orchestration/src/index.d.ts +15 -1
- package/dist/packages/orchestration/src/index.js +127 -21
- package/dist/packages/planner/src/index.d.ts +7 -1
- package/dist/packages/planner/src/index.js +67 -10
- package/dist/packages/planner/src/proposal-store.d.ts +30 -0
- package/dist/packages/planner/src/proposal-store.js +109 -0
- package/dist/packages/policy/src/index.d.ts +9 -16
- package/dist/packages/policy/src/index.js +114 -31
- package/dist/packages/runtime/src/index.d.ts +16 -2
- package/dist/packages/runtime/src/index.js +176 -61
- package/dist/scripts/build-smart-context.d.ts +2 -0
- package/dist/scripts/build-smart-context.js +12 -3
- package/dist/scripts/code-context.d.ts +3 -1
- package/dist/scripts/code-context.js +13 -3
- package/dist/scripts/coverage-gate.d.ts +2 -0
- package/dist/scripts/coverage-gate.js +101 -0
- package/dist/scripts/eval-agents.d.ts +11 -0
- package/dist/scripts/eval-agents.js +96 -0
- package/dist/scripts/gen-commands-doc.d.ts +2 -0
- package/dist/scripts/gen-commands-doc.js +18 -0
- package/dist/scripts/hook-session-memory.d.ts +9 -0
- package/dist/scripts/hook-session-memory.js +20 -0
- package/dist/scripts/hook-session-start.js +34 -0
- package/dist/scripts/spec-trace.d.ts +10 -0
- package/dist/scripts/spec-trace.js +73 -0
- package/dist/scripts/sync-universal-memory.js +69 -4
- package/dist/scripts/token-benchmark.d.ts +33 -1
- package/dist/scripts/token-benchmark.js +179 -5
- package/dist/scripts/token-economy.js +3 -1
- package/dist/scripts/tools-doctor.d.ts +16 -1
- package/dist/scripts/tools-doctor.js +58 -17
- package/docs/commands.md +155 -0
- package/docs/fluxo.md +11 -7
- package/docs/init-project.md +3 -1
- package/docs/llm-fit-loop.md +20 -0
- package/docs/manual-operacional-cli-sdd-gsd.md +3 -2
- package/docs/produto/factsheet-marketing.md +7 -5
- package/docs/produto/roteiro-demo.md +14 -5
- package/docs/quick-reference.md +3 -3
- package/docs/token-optimization.md +10 -6
- package/memory/90-decisions/0091-memoria-de-sessao-por-hooks.md +40 -0
- package/memory/90-decisions/0092-criterios-de-aceite-ligados-a-testes.md +37 -0
- package/memory/90-decisions/0093-avaliacoes-com-agentes-reais.md +40 -0
- package/package.json +4 -2
- package/specs/avaliacoes-de-agentes/spec.md +52 -0
- package/specs/criterios-ligados-a-testes/spec.md +42 -0
- package/specs/memoria-de-sessao/spec.md +48 -0
- package/specs/v6-agent-runtime-portable/spec.md +83 -0
- package/specs/v6-core-consolidation/spec.md +70 -0
- package/specs/v6-docs-drift/spec.md +85 -0
- package/specs/v6-quality-gates/spec.md +99 -0
- package/specs/v6-token-economy/spec.md +84 -0
- package/templates/evals/agents/adr.json +25 -0
- package/templates/evals/agents/memoria.json +32 -0
- package/templates/evals/agents/proxima-acao.json +29 -0
- package/templates/evals/agents/spec-nova.json +26 -0
- package/templates/evals/agents/teste-do-criterio.json +29 -0
- package/templates/project/AGENTS.md +7 -0
- package/templates/project/CLAUDE.md +3 -2
- package/templates/project/skills/testing/SKILL.md +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AgentIdentity, type ApprovalRequest, type CapabilityDefinition, type EntityId, type ISO8601, type PolicyDecision, type RiskLevel, type TokenBudget } from '../../contracts/src/index.ts';
|
|
1
|
+
import { type AgentIdentity, type ApprovalRequest, type CapabilityDefinition, type CapabilityInput, type EntityId, type ISO8601, type PolicyDecision, type RiskLevel, type TokenBudget } from '../../contracts/src/index.ts';
|
|
2
2
|
export type PolicyCategory = 'read' | 'write' | 'execution' | 'network' | 'repository' | 'secrets' | 'database' | 'deployment' | 'destructive';
|
|
3
3
|
export interface PolicyScope {
|
|
4
4
|
readonly agentIds?: readonly EntityId[];
|
|
@@ -54,13 +54,10 @@ export interface ApprovalDetails {
|
|
|
54
54
|
export interface PolicyRequest {
|
|
55
55
|
readonly definition: CapabilityDefinition;
|
|
56
56
|
readonly agent: AgentIdentity;
|
|
57
|
-
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* fall back to `agent.id`, which only works correctly for an agent with a single in-flight
|
|
62
|
-
* approval at a time.
|
|
63
|
-
*/
|
|
57
|
+
/** Validated, canonical input supplied by the capability registry. Only its digest is persisted. */
|
|
58
|
+
readonly input?: CapabilityInput;
|
|
59
|
+
/** Stable action/step identity; falls back to correlationId, never to agent identity. */
|
|
60
|
+
readonly operationId?: string;
|
|
64
61
|
readonly correlationId?: string;
|
|
65
62
|
readonly projectId?: string;
|
|
66
63
|
readonly environment: string;
|
|
@@ -81,6 +78,8 @@ export interface ApprovalDecision {
|
|
|
81
78
|
}
|
|
82
79
|
export interface ApprovalInput extends ApprovalDetails {
|
|
83
80
|
readonly correlationId: string;
|
|
81
|
+
readonly operationId?: string;
|
|
82
|
+
readonly fingerprint?: string;
|
|
84
83
|
}
|
|
85
84
|
export interface ApprovalStore {
|
|
86
85
|
save(request: ApprovalRequest): void;
|
|
@@ -98,8 +97,8 @@ export declare class ApprovalLedger {
|
|
|
98
97
|
list(): readonly ApprovalRequest[];
|
|
99
98
|
decide(id: EntityId, decision: ApprovalDecision): ApprovalRequest;
|
|
100
99
|
expire(now: ISO8601): readonly ApprovalRequest[];
|
|
101
|
-
/**
|
|
102
|
-
|
|
100
|
+
/** Descriptive/historical records without both binding fields cannot authorize execution. */
|
|
101
|
+
findByOperation(operationId: string, fingerprint: string): ApprovalRequest | undefined;
|
|
103
102
|
get(id: EntityId): ApprovalRequest;
|
|
104
103
|
}
|
|
105
104
|
export declare class PolicyEngine {
|
|
@@ -113,12 +112,6 @@ export declare class PolicyEngine {
|
|
|
113
112
|
});
|
|
114
113
|
authorize(request: PolicyRequest): PolicyDecision;
|
|
115
114
|
get approvals(): ApprovalLedger;
|
|
116
|
-
/**
|
|
117
|
-
* Resolves approval state for `request` instead of unconditionally demanding a fresh one.
|
|
118
|
-
* Keyed by `request.correlationId` (falling back to the agent id) so that resuming/retrying
|
|
119
|
-
* the same run recognizes a decision a human already made, rather than re-issuing an
|
|
120
|
-
* unresolvable `REQUIRE_APPROVAL` on every attempt — see ADR/finding on approval resume.
|
|
121
|
-
*/
|
|
122
115
|
private withApproval;
|
|
123
116
|
private matches;
|
|
124
117
|
private validateRules;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { randomUUID } from 'node:crypto';
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { CONTRACT_VERSION, isPathWithinRoot, } from '../../contracts/src/index.js';
|
|
3
3
|
export class PolicyError extends Error {
|
|
4
4
|
constructor(message) {
|
|
@@ -6,6 +6,72 @@ export class PolicyError extends Error {
|
|
|
6
6
|
this.name = 'PolicyError';
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
// Round-trip the calendar to reject Date.parse's normalization of impossible dates.
|
|
10
|
+
function approvalInstant(value) {
|
|
11
|
+
const parts = typeof value === 'string' ? /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})(?:\.(\d{1,3}))?(Z|[+-](?:[01]\d|2[0-3]):[0-5]\d)$/.exec(value) : null;
|
|
12
|
+
if (parts === null)
|
|
13
|
+
throw new PolicyError('Approval date must be an unambiguous ISO timestamp');
|
|
14
|
+
const calendar = `${parts[1]}.${(parts[2] ?? '').padEnd(3, '0')}Z`;
|
|
15
|
+
const local = Date.parse(calendar);
|
|
16
|
+
const instant = Date.parse(value);
|
|
17
|
+
if (!Number.isFinite(local) || !Number.isFinite(instant) || new Date(local).toISOString() !== calendar) {
|
|
18
|
+
throw new PolicyError('Invalid approval date');
|
|
19
|
+
}
|
|
20
|
+
return instant;
|
|
21
|
+
}
|
|
22
|
+
// Tags distinguish absent/undefined/null; descriptors prevent executing getters or toJSON.
|
|
23
|
+
function canonicalApprovalValue(value, ancestors = new Set()) {
|
|
24
|
+
if (value === undefined)
|
|
25
|
+
return '["undefined"]';
|
|
26
|
+
if (value === null)
|
|
27
|
+
return '["null"]';
|
|
28
|
+
if (typeof value === 'string' || typeof value === 'boolean')
|
|
29
|
+
return JSON.stringify([typeof value, value]);
|
|
30
|
+
if (typeof value === 'number') {
|
|
31
|
+
if (!Number.isFinite(value))
|
|
32
|
+
throw new PolicyError('Non-finite approval value');
|
|
33
|
+
return JSON.stringify(['number', Object.is(value, -0) ? '-0' : value]);
|
|
34
|
+
}
|
|
35
|
+
if (typeof value !== 'object')
|
|
36
|
+
throw new PolicyError('Unsupported approval value');
|
|
37
|
+
if (ancestors.has(value))
|
|
38
|
+
throw new PolicyError('Cyclic approval value');
|
|
39
|
+
const array = Array.isArray(value);
|
|
40
|
+
const prototype = Object.getPrototypeOf(value);
|
|
41
|
+
if (array ? prototype !== Array.prototype : prototype !== Object.prototype && prototype !== null) {
|
|
42
|
+
throw new PolicyError('Approval values must be plain objects or arrays');
|
|
43
|
+
}
|
|
44
|
+
ancestors.add(value);
|
|
45
|
+
try {
|
|
46
|
+
const keys = Reflect.ownKeys(value);
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
49
|
+
if (typeof key !== 'string' || descriptor === undefined || !('value' in descriptor) || (!descriptor.enumerable && !(array && key === 'length'))) {
|
|
50
|
+
throw new PolicyError('Ambiguous approval property');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (array) {
|
|
54
|
+
if (keys.length !== value.length + 1)
|
|
55
|
+
throw new PolicyError('Sparse or extended approval array');
|
|
56
|
+
const entries = [];
|
|
57
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
58
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, String(index));
|
|
59
|
+
if (descriptor === undefined)
|
|
60
|
+
throw new PolicyError('Sparse approval array');
|
|
61
|
+
entries.push(canonicalApprovalValue(descriptor.value, ancestors));
|
|
62
|
+
}
|
|
63
|
+
return `["array",[${entries.join(',')}]]`;
|
|
64
|
+
}
|
|
65
|
+
const entries = Object.keys(value).sort().map((key) => {
|
|
66
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
67
|
+
return `[${JSON.stringify(key)},${canonicalApprovalValue(descriptor?.value, ancestors)}]`;
|
|
68
|
+
});
|
|
69
|
+
return `["object",[${entries.join(',')}]]`;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
ancestors.delete(value);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
9
75
|
export class ApprovalLedger {
|
|
10
76
|
requests = new Map();
|
|
11
77
|
store;
|
|
@@ -17,6 +83,8 @@ export class ApprovalLedger {
|
|
|
17
83
|
throw new PolicyError('Approval justification is required');
|
|
18
84
|
if (input.impact.trim().length === 0)
|
|
19
85
|
throw new PolicyError('Approval impact is required');
|
|
86
|
+
if (approvalInstant(input.expiresAt) <= approvalInstant(now))
|
|
87
|
+
throw new PolicyError('Approval expiry must be in the future');
|
|
20
88
|
const request = {
|
|
21
89
|
schemaVersion: CONTRACT_VERSION,
|
|
22
90
|
id: randomUUID(),
|
|
@@ -26,6 +94,8 @@ export class ApprovalLedger {
|
|
|
26
94
|
expectedDiff: input.expectedDiff,
|
|
27
95
|
expiresAt: input.expiresAt,
|
|
28
96
|
correlationId: input.correlationId,
|
|
97
|
+
operationId: input.operationId,
|
|
98
|
+
fingerprint: input.fingerprint,
|
|
29
99
|
createdAt: now,
|
|
30
100
|
updatedAt: now,
|
|
31
101
|
};
|
|
@@ -42,7 +112,7 @@ export class ApprovalLedger {
|
|
|
42
112
|
const current = this.get(id);
|
|
43
113
|
if (current.decision !== undefined)
|
|
44
114
|
throw new PolicyError(`Approval already decided: ${id}`);
|
|
45
|
-
if (current.expiresAt <= decision.decidedAt)
|
|
115
|
+
if (approvalInstant(current.expiresAt) <= approvalInstant(decision.decidedAt))
|
|
46
116
|
throw new PolicyError(`Approval expired: ${id}`);
|
|
47
117
|
const updated = { ...current, decision: decision.decision, approverId: decision.approverId, updatedAt: decision.decidedAt };
|
|
48
118
|
this.requests.set(id, updated);
|
|
@@ -50,9 +120,10 @@ export class ApprovalLedger {
|
|
|
50
120
|
return updated;
|
|
51
121
|
}
|
|
52
122
|
expire(now) {
|
|
123
|
+
const instant = approvalInstant(now);
|
|
53
124
|
const expired = [];
|
|
54
|
-
for (const current of this.
|
|
55
|
-
if (current.decision === undefined && current.expiresAt <=
|
|
125
|
+
for (const current of this.list()) {
|
|
126
|
+
if ((current.decision === undefined || current.decision === 'approved') && approvalInstant(current.expiresAt) <= instant) {
|
|
56
127
|
const updated = { ...current, decision: 'expired', updatedAt: now };
|
|
57
128
|
this.requests.set(current.id, updated);
|
|
58
129
|
void this.store?.save(updated);
|
|
@@ -61,20 +132,14 @@ export class ApprovalLedger {
|
|
|
61
132
|
}
|
|
62
133
|
return expired;
|
|
63
134
|
}
|
|
64
|
-
/**
|
|
65
|
-
|
|
66
|
-
const matches = this.list().filter((request) => request.
|
|
135
|
+
/** Descriptive/historical records without both binding fields cannot authorize execution. */
|
|
136
|
+
findByOperation(operationId, fingerprint) {
|
|
137
|
+
const matches = this.list().filter((request) => request.operationId === operationId && request.fingerprint === fingerprint && request.decision !== 'expired');
|
|
67
138
|
return matches.at(-1);
|
|
68
139
|
}
|
|
69
140
|
get(id) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const persisted = this.store.get(id);
|
|
73
|
-
if (persisted !== undefined) {
|
|
74
|
-
this.requests.set(id, persisted);
|
|
75
|
-
return persisted;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
141
|
+
// A persistent store is authoritative, including deletion and decisions by another ledger.
|
|
142
|
+
const request = this.store === undefined ? this.requests.get(id) : this.store.get(id);
|
|
78
143
|
if (request === undefined)
|
|
79
144
|
throw new PolicyError(`Approval not found: ${id}`);
|
|
80
145
|
return request;
|
|
@@ -99,25 +164,44 @@ export class PolicyEngine {
|
|
|
99
164
|
// approval just because a rule chose to bound it with limits instead of an unconditional ALLOW.
|
|
100
165
|
const isGranting = decision.effect === 'ALLOW' || decision.effect === 'ALLOW_WITH_LIMITS';
|
|
101
166
|
if (this.approvalRequiredRisks.includes(request.definition.risk) && isGranting) {
|
|
102
|
-
return this.withApproval(request, decision, 'Risk requires explicit approval');
|
|
167
|
+
return this.withApproval(request, decision, 'Risk requires explicit approval', match);
|
|
103
168
|
}
|
|
104
169
|
if (decision.effect === 'REQUIRE_APPROVAL')
|
|
105
|
-
return this.withApproval(request, decision, decision.reason);
|
|
170
|
+
return this.withApproval(request, decision, decision.reason, match);
|
|
106
171
|
return decision;
|
|
107
172
|
}
|
|
108
173
|
get approvals() {
|
|
109
174
|
return this.approvalLedger;
|
|
110
175
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
176
|
+
withApproval(request, decision, reason, rule) {
|
|
177
|
+
const now = approvalInstant(request.now);
|
|
178
|
+
if (request.approval !== undefined)
|
|
179
|
+
approvalInstant(request.approval.expiresAt);
|
|
180
|
+
const operationId = request.operationId ?? request.correlationId ?? randomUUID();
|
|
181
|
+
const correlationId = request.correlationId ?? operationId;
|
|
182
|
+
const { definition, agent, budget, approval } = request;
|
|
183
|
+
const fingerprint = `v1:${createHash('sha256').update(canonicalApprovalValue({
|
|
184
|
+
operationId,
|
|
185
|
+
agent: { id: agent.id, role: agent.role, autonomy: agent.autonomy },
|
|
186
|
+
capability: { id: definition.id, version: definition.version, risk: definition.risk, permissions: definition.permissions, sideEffects: definition.sideEffects },
|
|
187
|
+
payload: request.input?.payload,
|
|
188
|
+
projectId: request.projectId,
|
|
189
|
+
environment: request.environment,
|
|
190
|
+
files: [...new Set(request.files)].sort(),
|
|
191
|
+
categories: [...new Set(request.categories)].sort(),
|
|
192
|
+
approval: approval === undefined ? undefined : {
|
|
193
|
+
action: approval.action, justification: approval.justification, impact: approval.impact,
|
|
194
|
+
expectedDiff: approval.expectedDiff, expiresAt: approval.expiresAt,
|
|
195
|
+
},
|
|
196
|
+
decision,
|
|
197
|
+
rule,
|
|
198
|
+
approvalRequiredRisks: this.approvalRequiredRisks,
|
|
199
|
+
riskScore: request.riskScore,
|
|
200
|
+
anomalyScore: request.anomalyScore,
|
|
201
|
+
budget: budget === undefined ? undefined : { inputTokens: budget.inputTokens, outputTokens: budget.outputTokens, totalTokens: budget.totalTokens },
|
|
202
|
+
})).digest('hex')}`;
|
|
203
|
+
const existing = this.approvalLedger.findByOperation(operationId, fingerprint);
|
|
204
|
+
if (existing !== undefined && approvalInstant(existing.expiresAt) > now) {
|
|
121
205
|
if (existing.decision === 'approved') {
|
|
122
206
|
// `decision.effect` may already be ALLOW/ALLOW_WITH_LIMITS (gated only by the risk-level
|
|
123
207
|
// approval requirement) — keep it as-is. But when the *rule itself* is REQUIRE_APPROVAL,
|
|
@@ -130,12 +214,11 @@ export class PolicyEngine {
|
|
|
130
214
|
return { ...decision, effect: 'DENY', reason: `Approval rejected: ${existing.id}`, approvalRequestId: existing.id };
|
|
131
215
|
if (existing.decision === undefined)
|
|
132
216
|
return { ...decision, effect: 'REQUIRE_APPROVAL', reason, approvalRequestId: existing.id };
|
|
133
|
-
// existing.decision === 'expired': falls through to issue a fresh request below.
|
|
134
217
|
}
|
|
135
|
-
if (
|
|
218
|
+
if (approval === undefined)
|
|
136
219
|
return { ...decision, effect: 'REQUIRE_APPROVAL', reason };
|
|
137
|
-
const
|
|
138
|
-
return { ...decision, effect: 'REQUIRE_APPROVAL', reason, approvalRequestId:
|
|
220
|
+
const created = this.approvalLedger.create({ ...approval, correlationId, operationId, fingerprint }, request.now);
|
|
221
|
+
return { ...decision, effect: 'REQUIRE_APPROVAL', reason, approvalRequestId: created.id };
|
|
139
222
|
}
|
|
140
223
|
matches(scope, request) {
|
|
141
224
|
if (scope.agentIds !== undefined && !scope.agentIds.includes(request.agent.id))
|
|
@@ -51,6 +51,9 @@ export interface RuntimeMemory {
|
|
|
51
51
|
remember(run: RuntimeRun, result: ExecutionResult): void | Promise<void>;
|
|
52
52
|
}
|
|
53
53
|
export interface RuntimeStartRequest {
|
|
54
|
+
readonly runId?: RunId;
|
|
55
|
+
readonly handoffId?: EntityId;
|
|
56
|
+
readonly context?: unknown;
|
|
54
57
|
readonly objective: string;
|
|
55
58
|
readonly agent: AgentIdentity;
|
|
56
59
|
readonly budget: TokenBudget;
|
|
@@ -68,9 +71,11 @@ export interface RuntimeDependencies {
|
|
|
68
71
|
readonly checkpointStore?: CheckpointStore;
|
|
69
72
|
readonly persistence?: RuntimePersistence;
|
|
70
73
|
readonly memory?: RuntimeMemory;
|
|
74
|
+
readonly beforeExecution?: (run: RuntimeRun) => void | Promise<void>;
|
|
71
75
|
}
|
|
72
76
|
export declare class RuntimeError extends Error {
|
|
73
|
-
|
|
77
|
+
readonly code: string;
|
|
78
|
+
constructor(message: string, code?: string);
|
|
74
79
|
}
|
|
75
80
|
export declare class InMemoryCheckpointStore implements CheckpointStore {
|
|
76
81
|
private readonly checkpoints;
|
|
@@ -87,18 +92,27 @@ export declare class RuntimeEngine {
|
|
|
87
92
|
private readonly policies;
|
|
88
93
|
private readonly requestedPauses;
|
|
89
94
|
private readonly startedAt;
|
|
95
|
+
private readonly starts;
|
|
96
|
+
private readonly executions;
|
|
97
|
+
private readonly recoveries;
|
|
98
|
+
private readonly requestedCancels;
|
|
99
|
+
private readonly executionErrors;
|
|
90
100
|
constructor(dependencies: RuntimeDependencies, limits?: Partial<RuntimeLimits>);
|
|
91
101
|
start(request: RuntimeStartRequest): Promise<RuntimeRun>;
|
|
102
|
+
private prepare;
|
|
92
103
|
execute(runId: RunId): Promise<RuntimeRun>;
|
|
104
|
+
private singleFlight;
|
|
105
|
+
private executeRun;
|
|
93
106
|
recover(runId: RunId, policy: CapabilityExecutionRequest['policy']): Promise<RuntimeRun>;
|
|
107
|
+
private load;
|
|
94
108
|
resume(runId: RunId, policy?: CapabilityExecutionRequest['policy']): Promise<RuntimeRun>;
|
|
95
109
|
pause(runId: RunId): RuntimeRun;
|
|
96
110
|
cancel(runId: RunId): Promise<RuntimeRun>;
|
|
111
|
+
has(runId: RunId): boolean;
|
|
97
112
|
get(runId: RunId): RuntimeRun;
|
|
98
113
|
private validateAndFinish;
|
|
99
114
|
private stop;
|
|
100
115
|
private update;
|
|
101
|
-
private persist;
|
|
102
116
|
private saveCheckpoint;
|
|
103
117
|
private metrics;
|
|
104
118
|
private auditFields;
|