#!/usr/bin/env node // ═══════════════════════════════════════════════════════════════════════════ // Agent Runtime v3 — Med Policy Registry och Runtime Trace v2 // ═══════════════════════════════════════════════════════════════════════════ import { RuntimeTraceV2 } from './runtime-trace-v2.mjs'; import { getPolicy } from './policy-registry.mjs'; class AgentRuntimeV3 { constructor(task) { this.task = task; this.trace = new RuntimeTraceV2(); this.policies = []; } async execute() { // 1. PLANNER await this.runPlanner(); // 2. CONTEXT await this.runContext(); // 3. MEMORY await this.runMemory(); // 4. KNOWLEDGE await this.runKnowledge(); // 5. EOS — Policy checks const eosResult = await this.runEOSCheck(); if (!eosResult.passed) { return { status: 'blocked', reason: eosResult.reason, policy: eosResult.blockedBy, evidence: eosResult.evidence }; } // 6. DEVELOPER await this.runDeveloper(); // 7. REVIEWER await this.runReviewer(); // 8. COMMIT await this.runCommit(); // 9. OPERATOR await this.runOperator(); return { status: 'completed', trace: this.trace.toJSON() }; } async runPlanner() { const node = this.trace.addNode('PLANNER', { task: this.task.description }); // Simulera planering this.trace.completeNode(node.id, { plan: { steps: [], estimatedTime: null, dependencies: [] } }); } async runContext() { const node = this.trace.addNode('CONTEXT', { task: this.task.description }); // Simulera kontext this.trace.completeNode(node.id, { confidence: 0.8, git: { branch: null, uncommitted: null, remote: null } }); } async runMemory() { const node = this.trace.addNode('MEMORY', { queries: [] }); // Simulera minne this.trace.completeNode(node.id, { results: { relevantDecisions: [], similarTasks: [], lessonsLearned: [] } }); } async runKnowledge() { const node = this.trace.addNode('KNOWLEDGE', { queries: [] }); // Simulera kunskap this.trace.completeNode(node.id, { results: { relatedCapabilities: [], dependencies: [], impact: [] } }); } async runEOSCheck() { const node = this.trace.addNode('EOS', { rules: this.policies.length }); // Kör alla policyer for (const policy of this.policies) { const result = policy(this.task); if (!result.passed) { const policyInfo = getPolicy(result.policyId); this.trace.blockNode(node.id, result.reason, { policyId: result.policyId || 'UNKNOWN', policyName: policyInfo?.name || 'Unknown Policy', evidence: result.evidence || {}, riskClass: result.severity || 'CRITICAL', requiredAction: `Använd godkänd process: ${policyInfo?.description || 'Kontakta EOS Team'}` }); return { passed: false, blockedBy: result.rule, reason: result.reason, severity: result.severity, evidence: result.evidence }; } } this.trace.completeNode(node.id, { passed: this.policies.length, failed: 0 }); return { passed: true }; } 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; } } export { AgentRuntimeV3 };