tryassay 0.6.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.
Files changed (103) hide show
  1. package/dist/api/pricing-enforcer.d.ts +45 -0
  2. package/dist/api/pricing-enforcer.js +144 -0
  3. package/dist/api/pricing-enforcer.js.map +1 -0
  4. package/dist/api/server.d.ts +28 -0
  5. package/dist/api/server.js +265 -0
  6. package/dist/api/server.js.map +1 -0
  7. package/dist/api/team-session.d.ts +59 -0
  8. package/dist/api/team-session.js +240 -0
  9. package/dist/api/team-session.js.map +1 -0
  10. package/dist/cli.js +123 -2
  11. package/dist/cli.js.map +1 -1
  12. package/dist/commands/api.d.ts +4 -0
  13. package/dist/commands/api.js +50 -0
  14. package/dist/commands/api.js.map +1 -0
  15. package/dist/commands/runtime.d.ts +61 -0
  16. package/dist/commands/runtime.js +554 -0
  17. package/dist/commands/runtime.js.map +1 -1
  18. package/dist/runtime/agent-spawner.d.ts +56 -0
  19. package/dist/runtime/agent-spawner.js +217 -0
  20. package/dist/runtime/agent-spawner.js.map +1 -0
  21. package/dist/runtime/agents/coordinator-agent.d.ts +20 -0
  22. package/dist/runtime/agents/coordinator-agent.js +182 -0
  23. package/dist/runtime/agents/coordinator-agent.js.map +1 -0
  24. package/dist/runtime/agents/ops-agent.d.ts +11 -0
  25. package/dist/runtime/agents/ops-agent.js +113 -0
  26. package/dist/runtime/agents/ops-agent.js.map +1 -0
  27. package/dist/runtime/agents/research-agent.d.ts +11 -0
  28. package/dist/runtime/agents/research-agent.js +114 -0
  29. package/dist/runtime/agents/research-agent.js.map +1 -0
  30. package/dist/runtime/agents/test-agent.d.ts +11 -0
  31. package/dist/runtime/agents/test-agent.js +114 -0
  32. package/dist/runtime/agents/test-agent.js.map +1 -0
  33. package/dist/runtime/capability-registry.d.ts +62 -0
  34. package/dist/runtime/capability-registry.js +191 -0
  35. package/dist/runtime/capability-registry.js.map +1 -0
  36. package/dist/runtime/collusion-detector.d.ts +35 -0
  37. package/dist/runtime/collusion-detector.js +97 -0
  38. package/dist/runtime/collusion-detector.js.map +1 -0
  39. package/dist/runtime/domain-coverage-analyzer.d.ts +24 -0
  40. package/dist/runtime/domain-coverage-analyzer.js +178 -0
  41. package/dist/runtime/domain-coverage-analyzer.js.map +1 -0
  42. package/dist/runtime/human-escalation.d.ts +41 -0
  43. package/dist/runtime/human-escalation.js +122 -0
  44. package/dist/runtime/human-escalation.js.map +1 -0
  45. package/dist/runtime/kill-switch.d.ts +51 -0
  46. package/dist/runtime/kill-switch.js +185 -0
  47. package/dist/runtime/kill-switch.js.map +1 -0
  48. package/dist/runtime/layer2-guardian.d.ts +81 -0
  49. package/dist/runtime/layer2-guardian.js +263 -0
  50. package/dist/runtime/layer2-guardian.js.map +1 -0
  51. package/dist/runtime/multi-agent-loop.d.ts +37 -0
  52. package/dist/runtime/multi-agent-loop.js +411 -0
  53. package/dist/runtime/multi-agent-loop.js.map +1 -0
  54. package/dist/runtime/prompt-safety-analyzer.d.ts +17 -0
  55. package/dist/runtime/prompt-safety-analyzer.js +230 -0
  56. package/dist/runtime/prompt-safety-analyzer.js.map +1 -0
  57. package/dist/runtime/rollback-manager.d.ts +50 -0
  58. package/dist/runtime/rollback-manager.js +157 -0
  59. package/dist/runtime/rollback-manager.js.map +1 -0
  60. package/dist/runtime/rule-canary-deployer.d.ts +69 -0
  61. package/dist/runtime/rule-canary-deployer.js +289 -0
  62. package/dist/runtime/rule-canary-deployer.js.map +1 -0
  63. package/dist/runtime/rule-conflict-detector.d.ts +48 -0
  64. package/dist/runtime/rule-conflict-detector.js +214 -0
  65. package/dist/runtime/rule-conflict-detector.js.map +1 -0
  66. package/dist/runtime/rule-meta-verifier.d.ts +18 -0
  67. package/dist/runtime/rule-meta-verifier.js +275 -0
  68. package/dist/runtime/rule-meta-verifier.js.map +1 -0
  69. package/dist/runtime/rule-proposal-manager.d.ts +95 -0
  70. package/dist/runtime/rule-proposal-manager.js +190 -0
  71. package/dist/runtime/rule-proposal-manager.js.map +1 -0
  72. package/dist/runtime/safety-enforcer.d.ts +35 -0
  73. package/dist/runtime/safety-enforcer.js +165 -0
  74. package/dist/runtime/safety-enforcer.js.map +1 -0
  75. package/dist/runtime/safety-status.d.ts +48 -0
  76. package/dist/runtime/safety-status.js +119 -0
  77. package/dist/runtime/safety-status.js.map +1 -0
  78. package/dist/runtime/shared-memory.d.ts +47 -0
  79. package/dist/runtime/shared-memory.js +151 -0
  80. package/dist/runtime/shared-memory.js.map +1 -0
  81. package/dist/runtime/specialized-agent.d.ts +5 -0
  82. package/dist/runtime/specialized-agent.js +37 -0
  83. package/dist/runtime/specialized-agent.js.map +1 -1
  84. package/dist/runtime/stall-detector.d.ts +13 -0
  85. package/dist/runtime/stall-detector.js +121 -0
  86. package/dist/runtime/stall-detector.js.map +1 -0
  87. package/dist/runtime/tool-approval.d.ts +51 -0
  88. package/dist/runtime/tool-approval.js +148 -0
  89. package/dist/runtime/tool-approval.js.map +1 -0
  90. package/dist/runtime/tool-sandbox.d.ts +43 -0
  91. package/dist/runtime/tool-sandbox.js +394 -0
  92. package/dist/runtime/tool-sandbox.js.map +1 -0
  93. package/dist/runtime/tool-verifier.d.ts +18 -0
  94. package/dist/runtime/tool-verifier.js +323 -0
  95. package/dist/runtime/tool-verifier.js.map +1 -0
  96. package/dist/runtime/trust-manager.d.ts +33 -3
  97. package/dist/runtime/trust-manager.js +128 -26
  98. package/dist/runtime/trust-manager.js.map +1 -1
  99. package/dist/runtime/types.d.ts +652 -0
  100. package/dist/runtime/verification-intensity.d.ts +34 -0
  101. package/dist/runtime/verification-intensity.js +104 -0
  102. package/dist/runtime/verification-intensity.js.map +1 -0
  103. package/package.json +1 -1
@@ -0,0 +1,411 @@
1
+ // ============================================================
2
+ // Assay Verified Agent Runtime — Multi-Agent Loop
3
+ // Full team orchestration: Coordinator decomposes, agents execute,
4
+ // Assay verifies at every boundary, stall detector monitors.
5
+ // ============================================================
6
+ import { randomUUID } from 'node:crypto';
7
+ import { EventEmitter } from 'node:events';
8
+ import { MessageBus } from './message-bus.js';
9
+ import { CompositionVerifier } from './composition-verifier.js';
10
+ import { TrustManager } from './trust-manager.js';
11
+ import { SharedMemoryStore } from './shared-memory.js';
12
+ import { StallDetector } from './stall-detector.js';
13
+ import { CoordinatorAgent } from './agents/coordinator-agent.js';
14
+ import { CodeAgent } from './agents/code-agent.js';
15
+ import { ReviewAgent } from './agents/review-agent.js';
16
+ import { TestAgent } from './agents/test-agent.js';
17
+ import { ResearchAgent } from './agents/research-agent.js';
18
+ import { OpsAgent } from './agents/ops-agent.js';
19
+ // ── Default safety policy ───────────────────────────────────
20
+ const DEFAULT_SAFETY = {
21
+ formalOverridesConsensus: true,
22
+ noSelfVerification: true,
23
+ criticalClaimsRequireFormal: true,
24
+ escalationRules: {
25
+ maxFormalOverridesBeforeHalt: 3,
26
+ maxTrustDemotions: 2,
27
+ maxRejectCyclesPerTask: 3,
28
+ },
29
+ preferModelDiversity: false,
30
+ };
31
+ // ── Agent Factory ──────────────────────────────────────────
32
+ function createAgent(spec, messageBus, model) {
33
+ switch (spec) {
34
+ case 'coordinator': return new CoordinatorAgent(messageBus, { model });
35
+ case 'code': return new CodeAgent(messageBus, { model });
36
+ case 'review': return new ReviewAgent(messageBus, { model });
37
+ case 'test': return new TestAgent(messageBus, { model });
38
+ case 'research': return new ResearchAgent(messageBus, { model });
39
+ case 'ops': return new OpsAgent(messageBus, { model });
40
+ }
41
+ }
42
+ // ── Multi-Agent Loop ───────────────────────────────────────
43
+ export class MultiAgentLoop extends EventEmitter {
44
+ messageBus;
45
+ compositionVerifier;
46
+ trustManager;
47
+ sharedMemory;
48
+ stallDetector;
49
+ agents = new Map();
50
+ auditTrail = [];
51
+ config;
52
+ codebaseRoot;
53
+ constructor(codebaseRoot, config) {
54
+ super();
55
+ this.codebaseRoot = codebaseRoot;
56
+ this.config = config;
57
+ this.messageBus = new MessageBus();
58
+ this.compositionVerifier = new CompositionVerifier(codebaseRoot);
59
+ this.trustManager = new TrustManager(config.safetyPolicy);
60
+ this.sharedMemory = new SharedMemoryStore();
61
+ this.stallDetector = new StallDetector();
62
+ // Spawn requested agents
63
+ for (const spec of config.agents) {
64
+ const model = config.models?.[spec];
65
+ const agent = createAgent(spec, this.messageBus, model);
66
+ this.agents.set(spec, agent);
67
+ this.trustManager.register(agent.getIdentity());
68
+ }
69
+ // Ensure coordinator exists
70
+ if (!this.agents.has('coordinator')) {
71
+ const coordinator = createAgent('coordinator', this.messageBus, config.models?.coordinator);
72
+ this.agents.set('coordinator', coordinator);
73
+ this.trustManager.register(coordinator.getIdentity());
74
+ }
75
+ }
76
+ /**
77
+ * Run the full multi-agent loop on a goal.
78
+ * 1. Coordinator decomposes goal into task graph
79
+ * 2. Ready tasks are assigned to agents
80
+ * 3. Each agent output passes through boundary verification
81
+ * 4. Completed tasks unlock dependent tasks
82
+ * 5. Stall detector monitors for problems
83
+ * 6. Loop until all tasks complete, fail, or escalate
84
+ */
85
+ async run() {
86
+ const startTime = Date.now();
87
+ const goalId = randomUUID();
88
+ this.audit('task_status_change', { goalId, status: 'planning', goal: this.config.goal });
89
+ // Step 1: Coordinator decomposes the goal
90
+ const coordinator = this.agents.get('coordinator');
91
+ const decompositionResult = await coordinator.executeTask({
92
+ taskId: `${goalId}-decompose`,
93
+ goal: this.config.goal,
94
+ constraints: [],
95
+ dependencies: [],
96
+ contextRefs: [],
97
+ });
98
+ if (decompositionResult.status === 'failed') {
99
+ this.audit('task_status_change', { goalId, status: 'failed', reason: 'decomposition_failed' });
100
+ return this.makeResult(goalId, 'failed', this.makeEmptyGraph(goalId), [], startTime);
101
+ }
102
+ // Parse the decomposition from the coordinator's artifact
103
+ const decomposition = this.parseDecomposition(decompositionResult);
104
+ if (decomposition.subtasks.length === 0) {
105
+ this.audit('task_status_change', { goalId, status: 'failed', reason: 'no_subtasks' });
106
+ return this.makeResult(goalId, 'failed', this.makeEmptyGraph(goalId), [], startTime);
107
+ }
108
+ this.audit('task_status_change', {
109
+ goalId,
110
+ status: 'executing',
111
+ subtaskCount: decomposition.subtasks.length,
112
+ uncovered: decomposition.gapAnalysis.uncoveredRequirements.length,
113
+ });
114
+ // Store decomposition in shared memory
115
+ this.sharedMemory.add('decision', `Decomposed goal into ${decomposition.subtasks.length} subtasks`, coordinator.getIdentity().id, {
116
+ tags: ['decomposition', goalId],
117
+ confidence: 0.8,
118
+ });
119
+ // Log uncovered requirements as assumptions
120
+ for (const uncovered of decomposition.gapAnalysis.uncoveredRequirements) {
121
+ this.sharedMemory.add('assumption', `Uncovered requirement: ${uncovered}`, coordinator.getIdentity().id, {
122
+ tags: ['gap', goalId],
123
+ confidence: 0.3,
124
+ });
125
+ }
126
+ // Build mutable task nodes from decomposition
127
+ const taskNodes = decomposition.subtasks.map(sub => ({
128
+ id: sub.id,
129
+ goal: sub.goal,
130
+ assignedTo: null,
131
+ specialization: sub.assignedTo,
132
+ status: 'pending',
133
+ dependencies: decomposition.dependencies.filter(d => d.to === sub.id),
134
+ artifacts: [],
135
+ attempts: 0,
136
+ maxAttempts: this.config.safetyPolicy.escalationRules.maxRejectCyclesPerTask,
137
+ threadId: randomUUID(),
138
+ createdAt: new Date().toISOString(),
139
+ }));
140
+ const allHandoffs = [];
141
+ const allStalls = [];
142
+ // Step 2: Execute tasks in dependency order
143
+ let maxIterations = this.config.maxTotalAttempts;
144
+ let iterations = 0;
145
+ while (iterations < maxIterations) {
146
+ iterations++;
147
+ // Mark tasks as ready if all blocking dependencies are complete
148
+ this.updateReadyTasks(taskNodes);
149
+ // Get next ready tasks (up to concurrency limit)
150
+ const readyTasks = taskNodes
151
+ .filter(t => t.status === 'ready')
152
+ .slice(0, this.config.maxConcurrentTasks);
153
+ if (readyTasks.length === 0) {
154
+ // Check if everything is done
155
+ const allDone = taskNodes.every(t => t.status === 'completed' || t.status === 'failed');
156
+ if (allDone)
157
+ break;
158
+ // Check for stalls
159
+ const graph = this.buildGraph(goalId, taskNodes, decomposition);
160
+ const stalls = this.stallDetector.detectStalls(graph, this.config.stallTimeoutMs);
161
+ if (stalls.length > 0) {
162
+ allStalls.push(...stalls);
163
+ this.audit('escalation', { reason: 'stall_detected', stalls: stalls.map(s => ({ taskId: s.taskId, type: s.type })) });
164
+ // Handle stalls: abort deadlocked tasks, escalate stuck ones
165
+ for (const stall of stalls) {
166
+ const task = taskNodes.find(t => t.id === stall.taskId);
167
+ if (task && stall.suggestedAction === 'abort') {
168
+ task.status = 'failed';
169
+ }
170
+ else if (task && stall.suggestedAction === 'escalate') {
171
+ task.status = 'failed';
172
+ }
173
+ }
174
+ continue;
175
+ }
176
+ // No ready tasks and nothing in progress and not all done = stall
177
+ const inProgress = taskNodes.some(t => t.status === 'in_progress' || t.status === 'in_review');
178
+ if (!inProgress) {
179
+ this.audit('task_status_change', { goalId, status: 'stalled' });
180
+ const graph2 = this.buildGraph(goalId, taskNodes, decomposition);
181
+ return this.makeResult(goalId, 'stalled', graph2, allHandoffs, startTime, allStalls);
182
+ }
183
+ // Tasks are in progress, wait a bit (in real system this would be event-driven)
184
+ break;
185
+ }
186
+ // Execute ready tasks
187
+ for (const task of readyTasks) {
188
+ task.status = 'in_progress';
189
+ task.attempts++;
190
+ const agent = this.agents.get(task.specialization);
191
+ if (!agent) {
192
+ this.audit('task_status_change', { taskId: task.id, status: 'failed', reason: `no_agent_for_${task.specialization}` });
193
+ task.status = 'failed';
194
+ continue;
195
+ }
196
+ task.assignedTo = agent.getIdentity().id;
197
+ this.audit('task_status_change', { taskId: task.id, status: 'in_progress', agent: agent.getIdentity().name, attempt: task.attempts });
198
+ // Build context refs from completed dependency artifacts
199
+ const contextRefs = this.buildContextRefs(task, taskNodes);
200
+ // Execute the task
201
+ const taskPayload = {
202
+ taskId: task.id,
203
+ goal: task.goal,
204
+ constraints: [],
205
+ dependencies: task.dependencies.filter(d => d.type === 'blocks').map(d => d.from),
206
+ contextRefs,
207
+ };
208
+ const result = await agent.executeTask(taskPayload);
209
+ if (result.status === 'failed') {
210
+ task.status = task.attempts >= task.maxAttempts ? 'failed' : 'rejected';
211
+ this.audit('task_status_change', { taskId: task.id, status: task.status, reason: result.summary });
212
+ continue;
213
+ }
214
+ // Boundary verification: verify agent output before accepting
215
+ task.status = 'in_review';
216
+ let allPassed = true;
217
+ for (const artifact of result.artifacts) {
218
+ // Determine the target agent for this handoff (usually coordinator)
219
+ const targetSpec = this.getReviewTarget(task.specialization);
220
+ const targetAgent = this.agents.get(targetSpec) ?? this.agents.get('coordinator');
221
+ const handoff = await this.compositionVerifier.verifyHandoff(agent.getIdentity(), targetAgent.getIdentity(), artifact);
222
+ allHandoffs.push(handoff);
223
+ task.artifacts.push(handoff);
224
+ this.audit('verification_run', {
225
+ boundary: `${agent.getIdentity().name} -> ${targetAgent.getIdentity().name}`,
226
+ verdict: handoff.verificationResult.verdict,
227
+ claims: handoff.verificationResult.total,
228
+ passed: handoff.verificationResult.passed,
229
+ failed: handoff.verificationResult.failed,
230
+ });
231
+ // Update trust
232
+ const trustResult = this.trustManager.updateTrust(agent.getIdentity().id, handoff.verificationResult);
233
+ if (trustResult.demoted) {
234
+ this.audit('trust_change', { agent: agent.getIdentity().name, newTrust: trustResult.newTrust });
235
+ }
236
+ if (trustResult.shouldHalt) {
237
+ this.audit('escalation', { reason: 'trust_threshold_exceeded', agent: agent.getIdentity().name });
238
+ const graph = this.buildGraph(goalId, taskNodes, decomposition);
239
+ return this.makeResult(goalId, 'escalated', graph, allHandoffs, startTime, allStalls);
240
+ }
241
+ if (handoff.decision.action === 'reject') {
242
+ allPassed = false;
243
+ this.audit('handoff_decision', { decision: 'reject', taskId: task.id });
244
+ }
245
+ }
246
+ if (allPassed) {
247
+ task.status = 'completed';
248
+ task.completedAt = new Date().toISOString();
249
+ this.audit('task_status_change', { taskId: task.id, status: 'completed' });
250
+ // Store result summary in shared memory
251
+ this.sharedMemory.add('fact', result.summary, agent.getIdentity().id, {
252
+ tags: [task.id, task.specialization],
253
+ confidence: 0.8,
254
+ });
255
+ }
256
+ else {
257
+ task.status = task.attempts >= task.maxAttempts ? 'failed' : 'rejected';
258
+ this.audit('task_status_change', { taskId: task.id, status: task.status, reason: 'boundary_rejection' });
259
+ }
260
+ }
261
+ }
262
+ // Determine final status
263
+ const allCompleted = taskNodes.every(t => t.status === 'completed');
264
+ const anyFailed = taskNodes.some(t => t.status === 'failed');
265
+ const finalStatus = allCompleted ? 'completed' : anyFailed ? 'failed' : 'stalled';
266
+ this.audit('task_status_change', { goalId, status: finalStatus });
267
+ const graph = this.buildGraph(goalId, taskNodes, decomposition);
268
+ return this.makeResult(goalId, finalStatus, graph, allHandoffs, startTime, allStalls);
269
+ }
270
+ /** Get the current audit trail. */
271
+ getAuditTrail() {
272
+ return this.auditTrail;
273
+ }
274
+ /** Get the shared memory store. */
275
+ getSharedMemory() {
276
+ return this.sharedMemory;
277
+ }
278
+ // ── Private helpers ─────────────────────────────────────
279
+ updateReadyTasks(tasks) {
280
+ for (const task of tasks) {
281
+ if (task.status !== 'pending')
282
+ continue;
283
+ // A task is ready if all its blocking dependencies are completed
284
+ const blockingDeps = task.dependencies.filter(d => d.type === 'blocks');
285
+ const allBlockersComplete = blockingDeps.every(dep => {
286
+ const depTask = tasks.find(t => t.id === dep.from);
287
+ return depTask?.status === 'completed';
288
+ });
289
+ if (allBlockersComplete) {
290
+ task.status = 'ready';
291
+ }
292
+ }
293
+ }
294
+ getReviewTarget(sourceSpec) {
295
+ // noSelfVerification: route to a different agent type for review
296
+ switch (sourceSpec) {
297
+ case 'code': return 'review';
298
+ case 'review': return 'code';
299
+ case 'test': return 'review';
300
+ case 'research': return 'review';
301
+ case 'ops': return 'review';
302
+ case 'coordinator': return 'review';
303
+ }
304
+ }
305
+ buildContextRefs(task, allTasks) {
306
+ const refs = [];
307
+ // Collect artifacts from completed dependencies
308
+ for (const dep of task.dependencies) {
309
+ const depTask = allTasks.find(t => t.id === dep.from);
310
+ if (depTask && depTask.status === 'completed') {
311
+ for (const handoff of depTask.artifacts) {
312
+ refs.push({
313
+ summary: `Output from ${depTask.specialization} agent (task: ${depTask.goal})`,
314
+ content: handoff.artifact.content,
315
+ });
316
+ }
317
+ }
318
+ }
319
+ // Add relevant shared memory entries
320
+ const relevantMemory = this.sharedMemory.getByTag(task.id);
321
+ for (const entry of relevantMemory) {
322
+ refs.push({
323
+ summary: `Shared memory [${entry.type}]: ${entry.content.slice(0, 100)}`,
324
+ content: entry.content,
325
+ });
326
+ }
327
+ return refs;
328
+ }
329
+ parseDecomposition(result) {
330
+ if (result.artifacts.length === 0) {
331
+ return { originalGoal: this.config.goal, subtasks: [], dependencies: [], gapAnalysis: { coveredRequirements: [], uncoveredRequirements: [], redundantTasks: [] } };
332
+ }
333
+ const content = result.artifacts[0].content;
334
+ try {
335
+ const parsed = JSON.parse(content);
336
+ return {
337
+ originalGoal: this.config.goal,
338
+ subtasks: parsed.subtasks ?? [],
339
+ dependencies: parsed.dependencies ?? [],
340
+ gapAnalysis: parsed.gapAnalysis ?? { coveredRequirements: [], uncoveredRequirements: [], redundantTasks: [] },
341
+ };
342
+ }
343
+ catch {
344
+ return { originalGoal: this.config.goal, subtasks: [], dependencies: [], gapAnalysis: { coveredRequirements: [], uncoveredRequirements: [], redundantTasks: [] } };
345
+ }
346
+ }
347
+ buildGraph(goalId, tasks, decomposition) {
348
+ const frozenTasks = tasks.map(t => ({
349
+ id: t.id,
350
+ goal: t.goal,
351
+ assignedTo: t.assignedTo,
352
+ specialization: t.specialization,
353
+ status: t.status,
354
+ dependencies: t.dependencies,
355
+ artifacts: t.artifacts,
356
+ attempts: t.attempts,
357
+ maxAttempts: t.maxAttempts,
358
+ threadId: t.threadId,
359
+ createdAt: t.createdAt,
360
+ completedAt: t.completedAt,
361
+ }));
362
+ const allCompleted = tasks.every(t => t.status === 'completed');
363
+ const anyFailed = tasks.some(t => t.status === 'failed');
364
+ const graphStatus = allCompleted ? 'completed' :
365
+ anyFailed ? 'failed' : 'executing';
366
+ return {
367
+ goalId,
368
+ originalGoal: this.config.goal,
369
+ tasks: frozenTasks,
370
+ edges: decomposition.dependencies,
371
+ status: graphStatus,
372
+ createdAt: tasks[0]?.createdAt ?? new Date().toISOString(),
373
+ completedAt: allCompleted ? new Date().toISOString() : undefined,
374
+ };
375
+ }
376
+ makeEmptyGraph(goalId) {
377
+ return {
378
+ goalId,
379
+ originalGoal: this.config.goal,
380
+ tasks: [],
381
+ edges: [],
382
+ status: 'failed',
383
+ createdAt: new Date().toISOString(),
384
+ };
385
+ }
386
+ makeResult(goalId, status, graph, handoffs, startTime, stalls = []) {
387
+ return {
388
+ goalId,
389
+ status,
390
+ taskGraph: graph,
391
+ artifacts: handoffs,
392
+ sharedMemorySnapshot: this.sharedMemory.getAllEntries(),
393
+ auditTrail: this.auditTrail,
394
+ totalDurationMs: Date.now() - startTime,
395
+ stalls,
396
+ };
397
+ }
398
+ audit(eventType, details) {
399
+ const entry = {
400
+ id: randomUUID(),
401
+ eventType: eventType,
402
+ agentName: 'multi-agent-loop',
403
+ timestamp: new Date().toISOString(),
404
+ details,
405
+ relatedIds: {},
406
+ };
407
+ this.auditTrail.push(entry);
408
+ this.emit('audit', entry);
409
+ }
410
+ }
411
+ //# sourceMappingURL=multi-agent-loop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multi-agent-loop.js","sourceRoot":"","sources":["../../src/runtime/multi-agent-loop.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,kDAAkD;AAClD,mEAAmE;AACnE,6DAA6D;AAC7D,+DAA+D;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,aAAa,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D,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,eAAe,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;YACvC,MAAM;SACP,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,SAAkC,EAAE,OAAgC;QAChF,MAAM,KAAK,GAAe;YACxB,EAAE,EAAE,UAAU,EAAE;YAChB,SAAS,EAAE,SAA2B;YACtC,SAAS,EAAE,kBAAkB;YAC7B,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;YACnC,OAAO;YACP,UAAU,EAAE,EAAE;SACf,CAAC;QACF,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import type { PromptSafetyFinding } from './types.js';
2
+ export declare class PromptSafetyAnalyzer {
3
+ /**
4
+ * Analyze an agent system prompt for safety issues.
5
+ * Uses both deterministic pattern matching (formal) and
6
+ * optional LLM-based semantic analysis.
7
+ */
8
+ analyze(systemPrompt: string, opts?: {
9
+ useLLM?: boolean;
10
+ }): Promise<{
11
+ contains_verification_bypass: boolean;
12
+ contains_privilege_escalation: boolean;
13
+ contains_self_reference: boolean;
14
+ findings: PromptSafetyFinding[];
15
+ }>;
16
+ private llmAnalysis;
17
+ }