Files
boc/EOS/agent-runtime-v7.mjs
T

180 lines
5.5 KiB
JavaScript
Raw Normal View History

#!/usr/bin/env node
// ═══════════════════════════════════════════════════════════════════════════
// Agent Runtime v7 — Med Evidence Resolver
// Arkitektur: Text → Intent → Candidates → Evidence → Resolution → EOS
// ═══════════════════════════════════════════════════════════════════════════
import { RuntimeTraceV2 } from './runtime-trace-v2.mjs';
import { resolve } from './evidence-resolver-v2.mjs';
import { getPolicy } from './policy-registry.mjs';
import { DecisionReplay } from './decision-replay.mjs';
class AgentRuntimeV7 {
constructor(task) {
this.task = task;
this.trace = new RuntimeTraceV2();
this.decisionReplay = new DecisionReplay();
}
async execute() {
// 1. PLANNER
await this.runPlanner();
// 2. CONTEXT
await this.runContext();
// 3. MEMORY
await this.runMemory();
// 4. KNOWLEDGE
await this.runKnowledge();
// 5. INTENT EXTRACTION
const resolutionResult = await this.runIntentResolution();
// 6. EOS — Policy Check baserat på resolution
const eosResult = await this.runEOSCheck(resolutionResult);
// 7. RECORD DECISION
const decisionId = this.recordDecision(resolutionResult, eosResult);
if (!eosResult.passed) {
return {
status: 'blocked',
reason: eosResult.reason,
policy: eosResult.blockedBy,
evidence: eosResult.evidence,
decisionId
};
}
// 8. DEVELOPER
await this.runDeveloper();
// 9. REVIEWER
await this.runReviewer();
// 10. COMMIT
await this.runCommit();
// 11. OPERATOR
await this.runOperator();
return { status: 'completed', trace: this.trace.toJSON(), decisionId };
}
async runPlanner() {
const node = this.trace.addNode('PLANNER', { task: this.task.description });
this.trace.completeNode(node.id, { plan: { steps: [], estimatedTime: null, dependencies: [] } });
}
async runContext() {
const node = this.trace.addNode('CONTEXT', { task: this.task.description });
this.trace.completeNode(node.id, { confidence: 0.8, git: { branch: null, uncommitted: null, remote: null } });
}
async runMemory() {
const node = this.trace.addNode('MEMORY', { queries: [] });
this.trace.completeNode(node.id, { results: { relevantDecisions: [], similarTasks: [], lessonsLearned: [] } });
}
async runKnowledge() {
const node = this.trace.addNode('KNOWLEDGE', { queries: [] });
this.trace.completeNode(node.id, { results: { relatedCapabilities: [], dependencies: [], impact: [] } });
}
async runIntentResolution() {
const node = this.trace.addNode('INTENT', { task: this.task.description });
const result = resolve(this.task);
this.trace.completeNode(node.id, {
candidates: result.candidates.map(c => c.operation),
evidence: result.evidence,
resolution: result.resolution.operation.id,
confidence: result.resolution.confidence,
reasoning: result.resolution.reasoning
});
return result;
}
async runEOSCheck(resolutionResult) {
const node = this.trace.addNode('EOS', {
operation: resolutionResult.resolution.operation.id
});
const operation = resolutionResult.resolution.operation;
if (!operation.allowed) {
const policyInfo = getPolicy(operation.policy);
this.trace.blockNode(node.id, operation.description, {
policyId: operation.policy,
policyName: policyInfo?.name || 'Unknown Policy',
evidence: resolutionResult.resolution.evidence,
riskClass: operation.severity,
requiredAction: `Använd godkänd process: ${policyInfo?.description || 'Kontakta EOS Team'}`
});
return {
passed: false,
blockedBy: operation.id,
reason: `${operation.description} är förbjudet. Policy: ${operation.policy}`,
severity: operation.severity,
evidence: {
operation: operation.id,
confidence: resolutionResult.resolution.confidence,
matchedEvidence: resolutionResult.resolution.evidence
}
};
}
this.trace.completeNode(node.id, {
passed: true,
operation: operation.id
});
return { passed: true };
}
recordDecision(resolutionResult, eosResult) {
return this.decisionReplay.recordDecision(
this.task,
resolutionResult.resolution,
eosResult,
this.trace
);
}
async runDeveloper() {
const node = this.trace.addNode('DEVELOPER', { task: this.task.description });
this.trace.completeNode(node.id, { status: 'completed' });
}
async runReviewer() {
const node = this.trace.addNode('REVIEWER', { task: this.task.description });
this.trace.completeNode(node.id, { status: 'completed' });
}
async runCommit() {
const node = this.trace.addNode('COMMIT', { task: this.task.description });
this.trace.completeNode(node.id, { status: 'completed' });
}
async runOperator() {
const node = this.trace.addNode('OPERATOR', { task: this.task.description });
this.trace.completeNode(node.id, { status: 'completed' });
}
getTrace() {
return this.trace;
}
getDecisionReplay() {
return this.decisionReplay;
}
}
export { AgentRuntimeV7 };