tryassay 0.3.0 → 0.11.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/dist/api/pricing-enforcer.d.ts +45 -0
- package/dist/api/pricing-enforcer.js +144 -0
- package/dist/api/pricing-enforcer.js.map +1 -0
- package/dist/api/server.d.ts +28 -0
- package/dist/api/server.js +265 -0
- package/dist/api/server.js.map +1 -0
- package/dist/api/team-session.d.ts +59 -0
- package/dist/api/team-session.js +240 -0
- package/dist/api/team-session.js.map +1 -0
- package/dist/cli.js +142 -2
- package/dist/cli.js.map +1 -1
- package/dist/commands/api.d.ts +4 -0
- package/dist/commands/api.js +50 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/runtime.d.ts +69 -0
- package/dist/commands/runtime.js +673 -0
- package/dist/commands/runtime.js.map +1 -1
- package/dist/runtime/agent-loop.d.ts +6 -0
- package/dist/runtime/agent-loop.js +87 -5
- package/dist/runtime/agent-loop.js.map +1 -1
- package/dist/runtime/agent-spawner.d.ts +56 -0
- package/dist/runtime/agent-spawner.js +217 -0
- package/dist/runtime/agent-spawner.js.map +1 -0
- package/dist/runtime/agents/code-agent.d.ts +11 -0
- package/dist/runtime/agents/code-agent.js +90 -0
- package/dist/runtime/agents/code-agent.js.map +1 -0
- package/dist/runtime/agents/coordinator-agent.d.ts +20 -0
- package/dist/runtime/agents/coordinator-agent.js +182 -0
- package/dist/runtime/agents/coordinator-agent.js.map +1 -0
- package/dist/runtime/agents/ops-agent.d.ts +11 -0
- package/dist/runtime/agents/ops-agent.js +113 -0
- package/dist/runtime/agents/ops-agent.js.map +1 -0
- package/dist/runtime/agents/research-agent.d.ts +11 -0
- package/dist/runtime/agents/research-agent.js +114 -0
- package/dist/runtime/agents/research-agent.js.map +1 -0
- package/dist/runtime/agents/review-agent.d.ts +11 -0
- package/dist/runtime/agents/review-agent.js +96 -0
- package/dist/runtime/agents/review-agent.js.map +1 -0
- package/dist/runtime/agents/test-agent.d.ts +11 -0
- package/dist/runtime/agents/test-agent.js +114 -0
- package/dist/runtime/agents/test-agent.js.map +1 -0
- package/dist/runtime/capability-registry.d.ts +62 -0
- package/dist/runtime/capability-registry.js +191 -0
- package/dist/runtime/capability-registry.js.map +1 -0
- package/dist/runtime/collusion-detector.d.ts +35 -0
- package/dist/runtime/collusion-detector.js +97 -0
- package/dist/runtime/collusion-detector.js.map +1 -0
- package/dist/runtime/composition-verifier.d.ts +22 -0
- package/dist/runtime/composition-verifier.js +265 -0
- package/dist/runtime/composition-verifier.js.map +1 -0
- package/dist/runtime/confidence-calibrator.d.ts +10 -0
- package/dist/runtime/confidence-calibrator.js +95 -0
- package/dist/runtime/confidence-calibrator.js.map +1 -0
- package/dist/runtime/domain-coverage-analyzer.d.ts +24 -0
- package/dist/runtime/domain-coverage-analyzer.js +178 -0
- package/dist/runtime/domain-coverage-analyzer.js.map +1 -0
- package/dist/runtime/enriched-prompt-builder.d.ts +25 -0
- package/dist/runtime/enriched-prompt-builder.js +173 -0
- package/dist/runtime/enriched-prompt-builder.js.map +1 -0
- package/dist/runtime/gap-detector.d.ts +6 -0
- package/dist/runtime/gap-detector.js +111 -0
- package/dist/runtime/gap-detector.js.map +1 -0
- package/dist/runtime/human-escalation.d.ts +41 -0
- package/dist/runtime/human-escalation.js +122 -0
- package/dist/runtime/human-escalation.js.map +1 -0
- package/dist/runtime/kill-switch.d.ts +51 -0
- package/dist/runtime/kill-switch.js +185 -0
- package/dist/runtime/kill-switch.js.map +1 -0
- package/dist/runtime/layer2-guardian.d.ts +81 -0
- package/dist/runtime/layer2-guardian.js +263 -0
- package/dist/runtime/layer2-guardian.js.map +1 -0
- package/dist/runtime/message-bus.d.ts +57 -0
- package/dist/runtime/message-bus.js +115 -0
- package/dist/runtime/message-bus.js.map +1 -0
- package/dist/runtime/multi-agent-loop.d.ts +37 -0
- package/dist/runtime/multi-agent-loop.js +411 -0
- package/dist/runtime/multi-agent-loop.js.map +1 -0
- package/dist/runtime/pattern-extractor.d.ts +20 -0
- package/dist/runtime/pattern-extractor.js +257 -0
- package/dist/runtime/pattern-extractor.js.map +1 -0
- package/dist/runtime/planner.d.ts +2 -2
- package/dist/runtime/planner.js +10 -7
- package/dist/runtime/planner.js.map +1 -1
- package/dist/runtime/prompt-safety-analyzer.d.ts +17 -0
- package/dist/runtime/prompt-safety-analyzer.js +230 -0
- package/dist/runtime/prompt-safety-analyzer.js.map +1 -0
- package/dist/runtime/reasoner.d.ts +2 -2
- package/dist/runtime/reasoner.js +9 -5
- package/dist/runtime/reasoner.js.map +1 -1
- package/dist/runtime/reflector.d.ts +7 -1
- package/dist/runtime/reflector.js.map +1 -1
- package/dist/runtime/rollback-manager.d.ts +50 -0
- package/dist/runtime/rollback-manager.js +157 -0
- package/dist/runtime/rollback-manager.js.map +1 -0
- package/dist/runtime/rule-canary-deployer.d.ts +69 -0
- package/dist/runtime/rule-canary-deployer.js +289 -0
- package/dist/runtime/rule-canary-deployer.js.map +1 -0
- package/dist/runtime/rule-conflict-detector.d.ts +48 -0
- package/dist/runtime/rule-conflict-detector.js +214 -0
- package/dist/runtime/rule-conflict-detector.js.map +1 -0
- package/dist/runtime/rule-meta-verifier.d.ts +18 -0
- package/dist/runtime/rule-meta-verifier.js +275 -0
- package/dist/runtime/rule-meta-verifier.js.map +1 -0
- package/dist/runtime/rule-proposal-manager.d.ts +95 -0
- package/dist/runtime/rule-proposal-manager.js +190 -0
- package/dist/runtime/rule-proposal-manager.js.map +1 -0
- package/dist/runtime/safety-enforcer.d.ts +35 -0
- package/dist/runtime/safety-enforcer.js +165 -0
- package/dist/runtime/safety-enforcer.js.map +1 -0
- package/dist/runtime/safety-status.d.ts +48 -0
- package/dist/runtime/safety-status.js +119 -0
- package/dist/runtime/safety-status.js.map +1 -0
- package/dist/runtime/shadow-runner.d.ts +14 -0
- package/dist/runtime/shadow-runner.js +190 -0
- package/dist/runtime/shadow-runner.js.map +1 -0
- package/dist/runtime/shared-memory.d.ts +47 -0
- package/dist/runtime/shared-memory.js +151 -0
- package/dist/runtime/shared-memory.js.map +1 -0
- package/dist/runtime/specialized-agent.d.ts +72 -0
- package/dist/runtime/specialized-agent.js +123 -0
- package/dist/runtime/specialized-agent.js.map +1 -0
- package/dist/runtime/stall-detector.d.ts +13 -0
- package/dist/runtime/stall-detector.js +121 -0
- package/dist/runtime/stall-detector.js.map +1 -0
- package/dist/runtime/strategy-library.d.ts +11 -0
- package/dist/runtime/strategy-library.js +142 -0
- package/dist/runtime/strategy-library.js.map +1 -0
- package/dist/runtime/supabase-experience-store.d.ts +19 -0
- package/dist/runtime/supabase-experience-store.js +215 -0
- package/dist/runtime/supabase-experience-store.js.map +1 -0
- package/dist/runtime/tool-approval.d.ts +51 -0
- package/dist/runtime/tool-approval.js +148 -0
- package/dist/runtime/tool-approval.js.map +1 -0
- package/dist/runtime/tool-sandbox.d.ts +43 -0
- package/dist/runtime/tool-sandbox.js +394 -0
- package/dist/runtime/tool-sandbox.js.map +1 -0
- package/dist/runtime/tool-verifier.d.ts +18 -0
- package/dist/runtime/tool-verifier.js +323 -0
- package/dist/runtime/tool-verifier.js.map +1 -0
- package/dist/runtime/trust-manager.d.ts +63 -0
- package/dist/runtime/trust-manager.js +212 -0
- package/dist/runtime/trust-manager.js.map +1 -0
- package/dist/runtime/two-agent-loop.d.ts +35 -0
- package/dist/runtime/two-agent-loop.js +208 -0
- package/dist/runtime/two-agent-loop.js.map +1 -0
- package/dist/runtime/types.d.ts +939 -1
- package/dist/runtime/verification-intensity.d.ts +34 -0
- package/dist/runtime/verification-intensity.js +104 -0
- package/dist/runtime/verification-intensity.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Assay Verified Agent Runtime — Agent Spawner
|
|
3
|
+
// Orchestrates: propose → verify → approve → spawn into
|
|
4
|
+
// the Phase 3 coordination framework.
|
|
5
|
+
// Trust inheritance: child cannot exceed parent trust.
|
|
6
|
+
// ============================================================
|
|
7
|
+
import { randomUUID } from 'node:crypto';
|
|
8
|
+
import { PromptSafetyAnalyzer } from './prompt-safety-analyzer.js';
|
|
9
|
+
import { DomainCoverageAnalyzer } from './domain-coverage-analyzer.js';
|
|
10
|
+
// ── Trust Level Hierarchy ──────────────────────────────────
|
|
11
|
+
const TRUST_HIERARCHY = {
|
|
12
|
+
sandboxed: 0,
|
|
13
|
+
standard: 1,
|
|
14
|
+
elevated: 2,
|
|
15
|
+
coordinator: 3,
|
|
16
|
+
};
|
|
17
|
+
const TRUST_FROM_PHASE3 = {
|
|
18
|
+
untrusted: 'sandboxed',
|
|
19
|
+
provisional: 'standard',
|
|
20
|
+
trusted: 'elevated',
|
|
21
|
+
formal: 'coordinator',
|
|
22
|
+
};
|
|
23
|
+
// ── Agent Spawner ──────────────────────────────────────────
|
|
24
|
+
export class AgentSpawner {
|
|
25
|
+
promptAnalyzer;
|
|
26
|
+
coverageAnalyzer;
|
|
27
|
+
registry;
|
|
28
|
+
pendingApprovals = new Map();
|
|
29
|
+
constructor(registry) {
|
|
30
|
+
this.promptAnalyzer = new PromptSafetyAnalyzer();
|
|
31
|
+
this.coverageAnalyzer = new DomainCoverageAnalyzer();
|
|
32
|
+
this.registry = registry;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Propose a new agent. Runs full verification:
|
|
36
|
+
* 1. Prompt safety analysis
|
|
37
|
+
* 2. Domain coverage analysis
|
|
38
|
+
* 3. Trust inheritance validation
|
|
39
|
+
* 4. Tool access analysis
|
|
40
|
+
*
|
|
41
|
+
* Returns the verification result and queues for human approval.
|
|
42
|
+
*/
|
|
43
|
+
async propose(agent, parentTrust, justification, opts) {
|
|
44
|
+
const proposalId = `mod_agent_${Date.now()}_${randomUUID().slice(0, 8)}`;
|
|
45
|
+
const verificationId = randomUUID();
|
|
46
|
+
// Step 1: Prompt safety analysis
|
|
47
|
+
const promptSafety = await this.promptAnalyzer.analyze(agent.system_prompt, { useLLM: opts?.useLLMAnalysis });
|
|
48
|
+
// Step 2: Domain coverage analysis
|
|
49
|
+
const availableTools = this.registry.listActiveTools();
|
|
50
|
+
const coverage = this.coverageAnalyzer.analyze(agent, availableTools);
|
|
51
|
+
// Step 3: Trust inheritance validation
|
|
52
|
+
const trustInheritance = this.validateTrustInheritance(agent, parentTrust);
|
|
53
|
+
// Step 4: Tool access analysis (from coverage analyzer)
|
|
54
|
+
const toolAccess = coverage.tool_access;
|
|
55
|
+
// Build verification report
|
|
56
|
+
const blockers = [];
|
|
57
|
+
if (promptSafety.contains_verification_bypass) {
|
|
58
|
+
blockers.push('CRITICAL: System prompt contains verification bypass instructions');
|
|
59
|
+
}
|
|
60
|
+
if (promptSafety.contains_privilege_escalation) {
|
|
61
|
+
blockers.push('CRITICAL: System prompt contains privilege escalation attempts');
|
|
62
|
+
}
|
|
63
|
+
if (!trustInheritance.valid) {
|
|
64
|
+
blockers.push(`Trust inheritance violation: ${trustInheritance.reason}`);
|
|
65
|
+
}
|
|
66
|
+
if (coverage.overreach.length > 3) {
|
|
67
|
+
blockers.push(`Significant overreach: ${coverage.overreach.length} overreach findings`);
|
|
68
|
+
}
|
|
69
|
+
// Critical prompt findings are blockers
|
|
70
|
+
const criticalFindings = promptSafety.findings.filter(f => f.severity === 'critical');
|
|
71
|
+
for (const finding of criticalFindings) {
|
|
72
|
+
blockers.push(`Critical prompt finding: ${finding.description}`);
|
|
73
|
+
}
|
|
74
|
+
const verdict = blockers.length > 0 ? 'reject'
|
|
75
|
+
: promptSafety.findings.some(f => f.severity === 'high') ? 'needs_review'
|
|
76
|
+
: coverage.gaps.length > 5 ? 'needs_review'
|
|
77
|
+
: 'approve';
|
|
78
|
+
const verification = {
|
|
79
|
+
agent_id: agent.id,
|
|
80
|
+
verification_id: verificationId,
|
|
81
|
+
timestamp: new Date().toISOString(),
|
|
82
|
+
domain_coverage: coverage,
|
|
83
|
+
prompt_safety: promptSafety,
|
|
84
|
+
tool_access: toolAccess,
|
|
85
|
+
trust_inheritance: trustInheritance,
|
|
86
|
+
verdict,
|
|
87
|
+
blockers,
|
|
88
|
+
};
|
|
89
|
+
// Create proposal
|
|
90
|
+
const proposal = {
|
|
91
|
+
id: proposalId,
|
|
92
|
+
type: 'agent',
|
|
93
|
+
timestamp: new Date().toISOString(),
|
|
94
|
+
title: `New agent: ${agent.name}`,
|
|
95
|
+
description: agent.domain.description,
|
|
96
|
+
payload: agent,
|
|
97
|
+
justification,
|
|
98
|
+
safety: {
|
|
99
|
+
modifies_layer2: false,
|
|
100
|
+
modifies_approval_framework: false,
|
|
101
|
+
trust_level_required: 'elevated',
|
|
102
|
+
rollback_plan: `Retire agent ${agent.id} and remove from coordination framework`,
|
|
103
|
+
},
|
|
104
|
+
proposed_by: agent.created_by,
|
|
105
|
+
status: verdict === 'reject' ? 'rejected' : 'pending_approval',
|
|
106
|
+
verification_id: verificationId,
|
|
107
|
+
};
|
|
108
|
+
if (verdict !== 'reject') {
|
|
109
|
+
this.pendingApprovals.set(proposalId, {
|
|
110
|
+
proposal,
|
|
111
|
+
verification,
|
|
112
|
+
agentDefinition: agent,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
proposalId,
|
|
117
|
+
verification,
|
|
118
|
+
status: proposal.status,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* List all pending agent approvals.
|
|
123
|
+
*/
|
|
124
|
+
listPending() {
|
|
125
|
+
return Array.from(this.pendingApprovals.values());
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Get a specific pending approval.
|
|
129
|
+
*/
|
|
130
|
+
getPending(proposalId) {
|
|
131
|
+
return this.pendingApprovals.get(proposalId);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Approve a pending agent proposal.
|
|
135
|
+
* Returns the approved agent definition ready for spawning.
|
|
136
|
+
*/
|
|
137
|
+
approve(proposalId, approvedBy, reasoning) {
|
|
138
|
+
const pending = this.pendingApprovals.get(proposalId);
|
|
139
|
+
if (!pending) {
|
|
140
|
+
throw new Error(`No pending approval found for "${proposalId}"`);
|
|
141
|
+
}
|
|
142
|
+
const approval = {
|
|
143
|
+
proposal_id: proposalId,
|
|
144
|
+
decision: 'approved',
|
|
145
|
+
decided_by: approvedBy,
|
|
146
|
+
decided_at: new Date().toISOString(),
|
|
147
|
+
reasoning,
|
|
148
|
+
};
|
|
149
|
+
const approvedAgent = {
|
|
150
|
+
...pending.agentDefinition,
|
|
151
|
+
approved_by: approvedBy,
|
|
152
|
+
approved_at: new Date().toISOString(),
|
|
153
|
+
status: 'approved',
|
|
154
|
+
};
|
|
155
|
+
this.pendingApprovals.delete(proposalId);
|
|
156
|
+
return { approval, agent: approvedAgent };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Reject a pending agent proposal.
|
|
160
|
+
*/
|
|
161
|
+
reject(proposalId, rejectedBy, reasoning) {
|
|
162
|
+
const pending = this.pendingApprovals.get(proposalId);
|
|
163
|
+
if (!pending) {
|
|
164
|
+
throw new Error(`No pending approval found for "${proposalId}"`);
|
|
165
|
+
}
|
|
166
|
+
this.pendingApprovals.delete(proposalId);
|
|
167
|
+
return {
|
|
168
|
+
proposal_id: proposalId,
|
|
169
|
+
decision: 'rejected',
|
|
170
|
+
decided_by: rejectedBy,
|
|
171
|
+
decided_at: new Date().toISOString(),
|
|
172
|
+
reasoning,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
// ── Private: Trust Inheritance ────────────────────────────
|
|
176
|
+
validateTrustInheritance(agent, parentTrust) {
|
|
177
|
+
// Human can create any trust level
|
|
178
|
+
if (parentTrust === 'human') {
|
|
179
|
+
return {
|
|
180
|
+
parent_trust: 'human',
|
|
181
|
+
requested_trust: agent.trust_level,
|
|
182
|
+
valid: true,
|
|
183
|
+
reason: 'Human-created agent: any trust level permitted',
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
const parentLevel = TRUST_HIERARCHY[parentTrust];
|
|
187
|
+
const childLevel = TRUST_HIERARCHY[agent.trust_level];
|
|
188
|
+
// Child cannot exceed parent trust level - 1
|
|
189
|
+
// (parent elevated can spawn at most standard)
|
|
190
|
+
const maxChildLevel = Math.max(0, parentLevel - 1);
|
|
191
|
+
if (childLevel > maxChildLevel) {
|
|
192
|
+
const maxTrust = Object.entries(TRUST_HIERARCHY).find(([, v]) => v === maxChildLevel)?.[0] ?? 'sandboxed';
|
|
193
|
+
return {
|
|
194
|
+
parent_trust: parentTrust,
|
|
195
|
+
requested_trust: agent.trust_level,
|
|
196
|
+
valid: false,
|
|
197
|
+
reason: `Parent trust "${parentTrust}" (level ${parentLevel}) can spawn at most "${maxTrust}" (level ${maxChildLevel}). Requested "${agent.trust_level}" (level ${childLevel}) exceeds limit.`,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
// Spawning agents requires elevated+ trust
|
|
201
|
+
if (parentLevel < TRUST_HIERARCHY['elevated']) {
|
|
202
|
+
return {
|
|
203
|
+
parent_trust: parentTrust,
|
|
204
|
+
requested_trust: agent.trust_level,
|
|
205
|
+
valid: false,
|
|
206
|
+
reason: `Only elevated+ agents can spawn agents. Parent has "${parentTrust}" trust.`,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
parent_trust: parentTrust,
|
|
211
|
+
requested_trust: agent.trust_level,
|
|
212
|
+
valid: true,
|
|
213
|
+
reason: `Trust inheritance valid: parent "${parentTrust}" -> child "${agent.trust_level}"`,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
//# sourceMappingURL=agent-spawner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-spawner.js","sourceRoot":"","sources":["../../src/runtime/agent-spawner.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,+CAA+C;AAC/C,wDAAwD;AACxD,sCAAsC;AACtC,uDAAuD;AACvD,+DAA+D;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,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,KAAK;gBACZ,MAAM,EAAE,iBAAiB,WAAW,YAAY,WAAW,wBAAwB,QAAQ,YAAY,aAAa,iBAAiB,KAAK,CAAC,WAAW,YAAY,UAAU,kBAAkB;aAC/L,CAAC;QACJ,CAAC;QAED,2CAA2C;QAC3C,IAAI,WAAW,GAAG,eAAe,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,OAAO;gBACL,YAAY,EAAE,WAAW;gBACzB,eAAe,EAAE,KAAK,CAAC,WAAW;gBAClC,KAAK,EAAE,KAAK;gBACZ,MAAM,EAAE,uDAAuD,WAAW,UAAU;aACrF,CAAC;QACJ,CAAC;QAED,OAAO;YACL,YAAY,EAAE,WAAW;YACzB,eAAe,EAAE,KAAK,CAAC,WAAW;YAClC,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,oCAAoC,WAAW,eAAe,KAAK,CAAC,WAAW,GAAG;SAC3F,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpecializedAgent, type TaskAssignmentPayload, type TaskResultPayload } from '../specialized-agent.js';
|
|
2
|
+
import type { AgentMessage } from '../types.js';
|
|
3
|
+
import type { MessageBus } from '../message-bus.js';
|
|
4
|
+
export declare class CodeAgent extends SpecializedAgent {
|
|
5
|
+
constructor(messageBus: MessageBus, opts?: {
|
|
6
|
+
model?: string;
|
|
7
|
+
});
|
|
8
|
+
protected onMessage(_message: AgentMessage): void;
|
|
9
|
+
executeTask(task: TaskAssignmentPayload): Promise<TaskResultPayload>;
|
|
10
|
+
private parseCodeResponse;
|
|
11
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Code Agent — Writes and modifies source code
|
|
3
|
+
// ============================================================
|
|
4
|
+
import { SpecializedAgent, } from '../specialized-agent.js';
|
|
5
|
+
export class CodeAgent extends SpecializedAgent {
|
|
6
|
+
constructor(messageBus, opts) {
|
|
7
|
+
super('code-agent', 'code', [
|
|
8
|
+
{ name: 'write_code', description: 'Write new source code files', tools: ['file_write'] },
|
|
9
|
+
{ name: 'edit_code', description: 'Edit existing source code', tools: ['file_read', 'file_write'] },
|
|
10
|
+
{ name: 'run_commands', description: 'Run build/test commands', tools: ['shell'] },
|
|
11
|
+
], messageBus, { model: opts?.model, initialTrust: 'untrusted' });
|
|
12
|
+
}
|
|
13
|
+
onMessage(_message) {
|
|
14
|
+
// Handle incoming findings from review agent
|
|
15
|
+
// Store for context in next task execution
|
|
16
|
+
}
|
|
17
|
+
async executeTask(task) {
|
|
18
|
+
const contextSnippets = task.contextRefs
|
|
19
|
+
.map(ref => `Context: ${ref.summary}\n${ref.content ?? ''}`)
|
|
20
|
+
.join('\n\n');
|
|
21
|
+
const systemPrompt = `You are a Code Agent — a specialized AI that writes and modifies source code.
|
|
22
|
+
|
|
23
|
+
Your job: Given a task description and context, produce code patches.
|
|
24
|
+
|
|
25
|
+
Rules:
|
|
26
|
+
1. Write clean, type-safe code.
|
|
27
|
+
2. Include error handling for all failure paths.
|
|
28
|
+
3. Do not use TODO, Coming Soon, or placeholder implementations.
|
|
29
|
+
4. State explicit claims about what your code does (these will be verified).
|
|
30
|
+
5. Respond with JSON: { "files": [{ "path": "...", "content": "...", "language": "..." }], "summary": "...", "claims": ["..."] }`;
|
|
31
|
+
const userPrompt = `TASK: ${task.goal}
|
|
32
|
+
|
|
33
|
+
CONSTRAINTS:
|
|
34
|
+
${task.constraints.map(c => `- ${c}`).join('\n')}
|
|
35
|
+
|
|
36
|
+
CONTEXT:
|
|
37
|
+
${contextSnippets || 'No additional context provided.'}
|
|
38
|
+
|
|
39
|
+
Produce the code now. Remember to state your claims explicitly.`;
|
|
40
|
+
try {
|
|
41
|
+
const { content } = await this.callClaude(systemPrompt, userPrompt);
|
|
42
|
+
// Parse the response
|
|
43
|
+
const parsed = this.parseCodeResponse(content);
|
|
44
|
+
const artifacts = parsed.files.map(f => this.makeArtifact('code_patch', f.content, {
|
|
45
|
+
path: f.path,
|
|
46
|
+
language: f.language,
|
|
47
|
+
}));
|
|
48
|
+
return {
|
|
49
|
+
taskId: task.taskId,
|
|
50
|
+
status: 'completed',
|
|
51
|
+
artifacts,
|
|
52
|
+
summary: parsed.summary,
|
|
53
|
+
claimsAboutArtifacts: parsed.claims,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
return {
|
|
58
|
+
taskId: task.taskId,
|
|
59
|
+
status: 'failed',
|
|
60
|
+
artifacts: [],
|
|
61
|
+
summary: `Code generation failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
62
|
+
claimsAboutArtifacts: [],
|
|
63
|
+
blockers: [err instanceof Error ? err.message : String(err)],
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
parseCodeResponse(raw) {
|
|
68
|
+
let cleaned = raw.trim();
|
|
69
|
+
if (cleaned.startsWith('```')) {
|
|
70
|
+
cleaned = cleaned.replace(/^```(?:json)?\s*/, '').replace(/\s*```$/, '');
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(cleaned);
|
|
74
|
+
return {
|
|
75
|
+
files: Array.isArray(parsed.files) ? parsed.files : [],
|
|
76
|
+
summary: typeof parsed.summary === 'string' ? parsed.summary : 'No summary',
|
|
77
|
+
claims: Array.isArray(parsed.claims) ? parsed.claims : [],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Fallback: treat entire response as a single code file
|
|
82
|
+
return {
|
|
83
|
+
files: [{ path: 'output.ts', content: raw, language: 'typescript' }],
|
|
84
|
+
summary: 'Raw code output (failed to parse structured response)',
|
|
85
|
+
claims: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=code-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-agent.js","sourceRoot":"","sources":["../../../src/runtime/agents/code-agent.ts"],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,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAC3E,CAAC;QAED,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO;gBACL,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE;gBACtD,OAAO,EAAE,OAAO,MAAM,CAAC,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY;gBAC3E,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;aAC1D,CAAC;QACJ,CAAC;QAAC,MAAM,CAAC;YACP,wDAAwD;YACxD,OAAO;gBACL,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;gBACpE,OAAO,EAAE,uDAAuD;gBAChE,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SpecializedAgent, type TaskAssignmentPayload, type TaskResultPayload } from '../specialized-agent.js';
|
|
2
|
+
import type { AgentMessage } from '../types.js';
|
|
3
|
+
import type { MessageBus } from '../message-bus.js';
|
|
4
|
+
export declare class CoordinatorAgent extends SpecializedAgent {
|
|
5
|
+
constructor(messageBus: MessageBus, opts?: {
|
|
6
|
+
model?: string;
|
|
7
|
+
});
|
|
8
|
+
protected onMessage(_message: AgentMessage): void;
|
|
9
|
+
/**
|
|
10
|
+
* Coordinator's executeTask decomposes the goal into a TaskDecomposition.
|
|
11
|
+
* The multi-agent loop uses this to build the TaskGraph.
|
|
12
|
+
*/
|
|
13
|
+
executeTask(task: TaskAssignmentPayload): Promise<TaskResultPayload>;
|
|
14
|
+
/**
|
|
15
|
+
* Parse the decomposition response and build a TaskDecomposition.
|
|
16
|
+
*/
|
|
17
|
+
private parseDecomposition;
|
|
18
|
+
private validateSpecialization;
|
|
19
|
+
private validateComplexity;
|
|
20
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
// ============================================================
|
|
2
|
+
// Coordinator Agent — Decomposes goals into task graphs,
|
|
3
|
+
// assigns tasks to specialized agents, manages dependencies,
|
|
4
|
+
// detects stalls, and drives the multi-agent loop.
|
|
5
|
+
// ============================================================
|
|
6
|
+
import { randomUUID } from 'node:crypto';
|
|
7
|
+
import { SpecializedAgent, } from '../specialized-agent.js';
|
|
8
|
+
export class CoordinatorAgent extends SpecializedAgent {
|
|
9
|
+
constructor(messageBus, opts) {
|
|
10
|
+
super('coordinator', 'coordinator', [
|
|
11
|
+
{ name: 'decompose', description: 'Decompose goals into subtasks', tools: [] },
|
|
12
|
+
{ name: 'assign', description: 'Assign tasks to specialized agents', tools: [] },
|
|
13
|
+
{ name: 'monitor', description: 'Monitor task graph progress', tools: [] },
|
|
14
|
+
], messageBus, { model: opts?.model, initialTrust: 'untrusted' });
|
|
15
|
+
}
|
|
16
|
+
onMessage(_message) {
|
|
17
|
+
// Coordinator processes task results and escalations via executeTask
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Coordinator's executeTask decomposes the goal into a TaskDecomposition.
|
|
21
|
+
* The multi-agent loop uses this to build the TaskGraph.
|
|
22
|
+
*/
|
|
23
|
+
async executeTask(task) {
|
|
24
|
+
const contextSnippets = task.contextRefs
|
|
25
|
+
.map(ref => `Context: ${ref.summary}\n${ref.content ?? ''}`)
|
|
26
|
+
.join('\n\n');
|
|
27
|
+
const systemPrompt = `You are a Coordinator Agent — you decompose complex goals into subtasks for a team of specialized agents.
|
|
28
|
+
|
|
29
|
+
Available agent roles:
|
|
30
|
+
- code: Writes and modifies source code
|
|
31
|
+
- review: Reviews code for bugs, security issues, and quality
|
|
32
|
+
- test: Writes and runs tests, reports coverage
|
|
33
|
+
- research: Investigates problems, reads docs, provides sourced findings
|
|
34
|
+
- ops: Handles deployment verification and infrastructure
|
|
35
|
+
|
|
36
|
+
Your job: Given a goal, produce a task decomposition with:
|
|
37
|
+
1. Subtasks — each assigned to the most appropriate agent role
|
|
38
|
+
2. Dependencies — which tasks must complete before others can start
|
|
39
|
+
3. Gap analysis — what requirements are covered, what might be missed
|
|
40
|
+
|
|
41
|
+
Rules:
|
|
42
|
+
1. Every requirement in the original goal must map to at least one subtask.
|
|
43
|
+
2. Dependencies must be acyclic (no circular dependencies).
|
|
44
|
+
3. Assign each subtask to the agent role with the best-matching capability.
|
|
45
|
+
4. Estimate complexity for each subtask.
|
|
46
|
+
5. State your claims about completeness — they will be verified.
|
|
47
|
+
|
|
48
|
+
Respond with JSON:
|
|
49
|
+
{
|
|
50
|
+
"subtasks": [
|
|
51
|
+
{
|
|
52
|
+
"id": "task-1",
|
|
53
|
+
"goal": "...",
|
|
54
|
+
"assignedTo": "code" | "review" | "test" | "research" | "ops",
|
|
55
|
+
"estimatedComplexity": "trivial" | "small" | "medium" | "large",
|
|
56
|
+
"requiredCapabilities": ["..."]
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"dependencies": [
|
|
60
|
+
{
|
|
61
|
+
"from": "task-1",
|
|
62
|
+
"to": "task-2",
|
|
63
|
+
"type": "blocks" | "informs",
|
|
64
|
+
"reason": "..."
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
"gapAnalysis": {
|
|
68
|
+
"coveredRequirements": ["..."],
|
|
69
|
+
"uncoveredRequirements": ["..."],
|
|
70
|
+
"redundantTasks": ["..."]
|
|
71
|
+
},
|
|
72
|
+
"summary": "...",
|
|
73
|
+
"claims": ["..."]
|
|
74
|
+
}`;
|
|
75
|
+
const userPrompt = `GOAL: ${task.goal}
|
|
76
|
+
|
|
77
|
+
CONSTRAINTS:
|
|
78
|
+
${task.constraints.map(c => `- ${c}`).join('\n')}
|
|
79
|
+
|
|
80
|
+
CONTEXT:
|
|
81
|
+
${contextSnippets || 'No additional context provided.'}
|
|
82
|
+
|
|
83
|
+
Decompose this goal into subtasks now. Ensure every requirement is covered.`;
|
|
84
|
+
try {
|
|
85
|
+
const { content } = await this.callClaude(systemPrompt, userPrompt);
|
|
86
|
+
const parsed = this.parseDecomposition(content);
|
|
87
|
+
const artifact = this.makeArtifact('review_report', JSON.stringify(parsed.decomposition, null, 2), {
|
|
88
|
+
metadata: {
|
|
89
|
+
subtaskCount: parsed.decomposition.subtasks.length,
|
|
90
|
+
dependencyCount: parsed.decomposition.dependencies.length,
|
|
91
|
+
uncoveredCount: parsed.decomposition.gapAnalysis.uncoveredRequirements.length,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
return {
|
|
95
|
+
taskId: task.taskId,
|
|
96
|
+
status: 'completed',
|
|
97
|
+
artifacts: [artifact],
|
|
98
|
+
summary: parsed.summary,
|
|
99
|
+
claimsAboutArtifacts: parsed.claims,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
return {
|
|
104
|
+
taskId: task.taskId,
|
|
105
|
+
status: 'failed',
|
|
106
|
+
artifacts: [],
|
|
107
|
+
summary: `Decomposition failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
108
|
+
claimsAboutArtifacts: [],
|
|
109
|
+
blockers: [err instanceof Error ? err.message : String(err)],
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Parse the decomposition response and build a TaskDecomposition.
|
|
115
|
+
*/
|
|
116
|
+
parseDecomposition(raw) {
|
|
117
|
+
let cleaned = raw.trim();
|
|
118
|
+
if (cleaned.startsWith('```')) {
|
|
119
|
+
cleaned = cleaned.replace(/^```(?:json)?\s*/, '').replace(/\s*```$/, '');
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const parsed = JSON.parse(cleaned);
|
|
123
|
+
const subtasks = (Array.isArray(parsed.subtasks) ? parsed.subtasks : []).map((s) => ({
|
|
124
|
+
id: typeof s.id === 'string' ? s.id : randomUUID(),
|
|
125
|
+
goal: typeof s.goal === 'string' ? s.goal : '',
|
|
126
|
+
assignedTo: this.validateSpecialization(s.assignedTo),
|
|
127
|
+
estimatedComplexity: this.validateComplexity(s.estimatedComplexity),
|
|
128
|
+
requiredCapabilities: Array.isArray(s.requiredCapabilities) ? s.requiredCapabilities : [],
|
|
129
|
+
contextRefs: [],
|
|
130
|
+
}));
|
|
131
|
+
const dependencies = (Array.isArray(parsed.dependencies) ? parsed.dependencies : []).map((d) => ({
|
|
132
|
+
from: typeof d.from === 'string' ? d.from : '',
|
|
133
|
+
to: typeof d.to === 'string' ? d.to : '',
|
|
134
|
+
type: d.type === 'informs' ? 'informs' : 'blocks',
|
|
135
|
+
reason: typeof d.reason === 'string' ? d.reason : '',
|
|
136
|
+
}));
|
|
137
|
+
const gap = parsed.gapAnalysis ?? {};
|
|
138
|
+
const decomposition = {
|
|
139
|
+
originalGoal: '',
|
|
140
|
+
subtasks,
|
|
141
|
+
dependencies,
|
|
142
|
+
gapAnalysis: {
|
|
143
|
+
coveredRequirements: Array.isArray(gap.coveredRequirements) ? gap.coveredRequirements : [],
|
|
144
|
+
uncoveredRequirements: Array.isArray(gap.uncoveredRequirements) ? gap.uncoveredRequirements : [],
|
|
145
|
+
redundantTasks: Array.isArray(gap.redundantTasks) ? gap.redundantTasks : [],
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
return {
|
|
149
|
+
decomposition,
|
|
150
|
+
summary: typeof parsed.summary === 'string' ? parsed.summary : 'No summary',
|
|
151
|
+
claims: Array.isArray(parsed.claims) ? parsed.claims : [],
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
return {
|
|
156
|
+
decomposition: {
|
|
157
|
+
originalGoal: '',
|
|
158
|
+
subtasks: [],
|
|
159
|
+
dependencies: [],
|
|
160
|
+
gapAnalysis: { coveredRequirements: [], uncoveredRequirements: [], redundantTasks: [] },
|
|
161
|
+
},
|
|
162
|
+
summary: 'Failed to parse decomposition response',
|
|
163
|
+
claims: [],
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
validateSpecialization(val) {
|
|
168
|
+
const valid = ['coordinator', 'code', 'review', 'test', 'ops', 'research'];
|
|
169
|
+
if (typeof val === 'string' && valid.includes(val)) {
|
|
170
|
+
return val;
|
|
171
|
+
}
|
|
172
|
+
return 'code'; // Default to code agent for unrecognized specializations
|
|
173
|
+
}
|
|
174
|
+
validateComplexity(val) {
|
|
175
|
+
const valid = ['trivial', 'small', 'medium', 'large'];
|
|
176
|
+
if (typeof val === 'string' && valid.includes(val)) {
|
|
177
|
+
return val;
|
|
178
|
+
}
|
|
179
|
+
return 'medium';
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//# sourceMappingURL=coordinator-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordinator-agent.js","sourceRoot":"","sources":["../../../src/runtime/agents/coordinator-agent.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,yDAAyD;AACzD,6DAA6D;AAC7D,mDAAmD;AACnD,+DAA+D;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,GAGjB,MAAM,yBAAyB,CAAC;AAcjC,MAAM,OAAO,gBAAiB,SAAQ,gBAAgB;IACpD,YAAY,UAAsB,EAAE,IAAyB;QAC3D,KAAK,CACH,aAAa,EACb,aAAa,EACb;YACE,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,+BAA+B,EAAE,KAAK,EAAE,EAAE,EAAE;YAC9E,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oCAAoC,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AqB,EAAE,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE;iBACxF;gBACD,OAAO,EAAE,wCAAwC;gBACjD,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;IACH,CAAC;IAEO,sBAAsB,CAAC,GAAY;QACzC,MAAM,KAAK,GAA0B,CAAC,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC;QAClG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAA0B,CAAC,EAAE,CAAC;YAC1E,OAAO,GAA0B,CAAC;QACpC,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,yDAAyD;IAC1E,CAAC;IAEO,kBAAkB,CAAC,GAAY;QACrC,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACnD,OAAO,GAA+C,CAAC;QACzD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SpecializedAgent, type TaskAssignmentPayload, type TaskResultPayload } from '../specialized-agent.js';
|
|
2
|
+
import type { AgentMessage } from '../types.js';
|
|
3
|
+
import type { MessageBus } from '../message-bus.js';
|
|
4
|
+
export declare class OpsAgent extends SpecializedAgent {
|
|
5
|
+
constructor(messageBus: MessageBus, opts?: {
|
|
6
|
+
model?: string;
|
|
7
|
+
});
|
|
8
|
+
protected onMessage(_message: AgentMessage): void;
|
|
9
|
+
executeTask(task: TaskAssignmentPayload): Promise<TaskResultPayload>;
|
|
10
|
+
private parseOpsResponse;
|
|
11
|
+
}
|