@covibes/zeroshot 5.4.0 → 5.4.1

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 (136) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -465
  3. package/cli/index.js +101 -5231
  4. package/package.json +16 -130
  5. package/CHANGELOG.md +0 -537
  6. package/cli/commands/providers.js +0 -149
  7. package/cli/lib/first-run.js +0 -211
  8. package/cli/lib/update-checker.js +0 -281
  9. package/cli/message-formatter-utils.js +0 -75
  10. package/cli/message-formatters-normal.js +0 -275
  11. package/cli/message-formatters-watch.js +0 -181
  12. package/cluster-templates/base-templates/debug-workflow.json +0 -375
  13. package/cluster-templates/base-templates/full-workflow.json +0 -581
  14. package/cluster-templates/base-templates/single-worker.json +0 -63
  15. package/cluster-templates/base-templates/worker-validator.json +0 -208
  16. package/cluster-templates/conductor-bootstrap.json +0 -124
  17. package/docker/zeroshot-cluster/Dockerfile +0 -152
  18. package/docker/zeroshot-cluster/pre-baked-deps.json +0 -28
  19. package/lib/completion.js +0 -174
  20. package/lib/docker-config.js +0 -220
  21. package/lib/git-remote-utils.js +0 -165
  22. package/lib/id-detector.js +0 -56
  23. package/lib/provider-defaults.js +0 -62
  24. package/lib/provider-detection.js +0 -59
  25. package/lib/provider-names.js +0 -57
  26. package/lib/settings/claude-auth.js +0 -78
  27. package/lib/settings.js +0 -503
  28. package/lib/stream-json-parser.js +0 -10
  29. package/scripts/fix-node-pty-permissions.js +0 -75
  30. package/scripts/record-demo.sh +0 -279
  31. package/scripts/setup-merge-queue.sh +0 -170
  32. package/scripts/test-install.sh +0 -40
  33. package/scripts/validate-templates.js +0 -100
  34. package/src/agent/agent-config.js +0 -246
  35. package/src/agent/agent-context-builder.js +0 -444
  36. package/src/agent/agent-hook-executor.js +0 -599
  37. package/src/agent/agent-lifecycle.js +0 -743
  38. package/src/agent/agent-stuck-detector.js +0 -256
  39. package/src/agent/agent-task-executor.js +0 -1690
  40. package/src/agent/agent-trigger-evaluator.js +0 -67
  41. package/src/agent/output-extraction.js +0 -217
  42. package/src/agent/output-reformatter.js +0 -175
  43. package/src/agent/schema-utils.js +0 -146
  44. package/src/agent-wrapper.js +0 -579
  45. package/src/agents/git-pusher-template.js +0 -285
  46. package/src/attach/attach-client.js +0 -438
  47. package/src/attach/attach-server.js +0 -543
  48. package/src/attach/index.js +0 -35
  49. package/src/attach/protocol.js +0 -220
  50. package/src/attach/ring-buffer.js +0 -121
  51. package/src/attach/socket-discovery.js +0 -267
  52. package/src/claude-task-runner.js +0 -574
  53. package/src/config-router.js +0 -80
  54. package/src/config-validator.js +0 -1925
  55. package/src/copy-worker.js +0 -43
  56. package/src/input-helpers.js +0 -65
  57. package/src/isolation-manager.js +0 -1471
  58. package/src/issue-providers/README.md +0 -305
  59. package/src/issue-providers/azure-devops-provider.js +0 -273
  60. package/src/issue-providers/base-provider.js +0 -232
  61. package/src/issue-providers/github-provider.js +0 -179
  62. package/src/issue-providers/gitlab-provider.js +0 -241
  63. package/src/issue-providers/index.js +0 -196
  64. package/src/issue-providers/jira-provider.js +0 -239
  65. package/src/ledger.js +0 -631
  66. package/src/lib/safe-exec.js +0 -88
  67. package/src/logic-engine.js +0 -223
  68. package/src/message-bus-bridge.js +0 -139
  69. package/src/message-bus.js +0 -249
  70. package/src/name-generator.js +0 -232
  71. package/src/orchestrator.js +0 -2815
  72. package/src/preflight.js +0 -639
  73. package/src/process-metrics.js +0 -608
  74. package/src/providers/anthropic/cli-builder.js +0 -73
  75. package/src/providers/anthropic/index.js +0 -204
  76. package/src/providers/anthropic/models.js +0 -23
  77. package/src/providers/anthropic/output-parser.js +0 -177
  78. package/src/providers/base-provider.js +0 -251
  79. package/src/providers/capabilities.js +0 -60
  80. package/src/providers/google/cli-builder.js +0 -55
  81. package/src/providers/google/index.js +0 -116
  82. package/src/providers/google/models.js +0 -24
  83. package/src/providers/google/output-parser.js +0 -101
  84. package/src/providers/index.js +0 -91
  85. package/src/providers/openai/cli-builder.js +0 -133
  86. package/src/providers/openai/index.js +0 -136
  87. package/src/providers/openai/models.js +0 -21
  88. package/src/providers/openai/output-parser.js +0 -143
  89. package/src/providers/opencode/cli-builder.js +0 -42
  90. package/src/providers/opencode/index.js +0 -103
  91. package/src/providers/opencode/models.js +0 -55
  92. package/src/providers/opencode/output-parser.js +0 -122
  93. package/src/schemas/sub-cluster.js +0 -185
  94. package/src/status-footer.js +0 -1026
  95. package/src/sub-cluster-wrapper.js +0 -601
  96. package/src/task-runner.js +0 -30
  97. package/src/template-resolver.js +0 -372
  98. package/src/tui/CHANGES.txt +0 -133
  99. package/src/tui/LAYOUT.md +0 -261
  100. package/src/tui/README.txt +0 -192
  101. package/src/tui/TWO-LEVEL-NAVIGATION.md +0 -186
  102. package/src/tui/data-poller.js +0 -349
  103. package/src/tui/demo.js +0 -208
  104. package/src/tui/formatters.js +0 -129
  105. package/src/tui/index.js +0 -193
  106. package/src/tui/keybindings.js +0 -324
  107. package/src/tui/layout.js +0 -334
  108. package/src/tui/renderer.js +0 -184
  109. package/task-lib/attachable-watcher.js +0 -309
  110. package/task-lib/claude-recovery.js +0 -156
  111. package/task-lib/commands/clean.js +0 -50
  112. package/task-lib/commands/episodes.js +0 -105
  113. package/task-lib/commands/get-log-path.js +0 -23
  114. package/task-lib/commands/kill.js +0 -32
  115. package/task-lib/commands/list.js +0 -105
  116. package/task-lib/commands/logs.js +0 -453
  117. package/task-lib/commands/resume.js +0 -42
  118. package/task-lib/commands/run.js +0 -57
  119. package/task-lib/commands/schedule.js +0 -105
  120. package/task-lib/commands/scheduler-cmd.js +0 -96
  121. package/task-lib/commands/schedules.js +0 -148
  122. package/task-lib/commands/status.js +0 -44
  123. package/task-lib/commands/unschedule.js +0 -16
  124. package/task-lib/completion.js +0 -9
  125. package/task-lib/config.js +0 -8
  126. package/task-lib/name-generator.js +0 -230
  127. package/task-lib/package.json +0 -3
  128. package/task-lib/runner.js +0 -201
  129. package/task-lib/scheduler.js +0 -252
  130. package/task-lib/store.js +0 -529
  131. package/task-lib/tui/formatters.js +0 -215
  132. package/task-lib/tui/index.js +0 -197
  133. package/task-lib/tui/layout.js +0 -111
  134. package/task-lib/tui/renderer.js +0 -129
  135. package/task-lib/tui.js +0 -425
  136. package/task-lib/watcher.js +0 -226
@@ -1,579 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * AgentWrapper - Manages agent lifecycle and claude-zeroshots execution
4
- *
5
- * Provides:
6
- * - Agent state machine (idle -> evaluating -> building context -> executing -> idle)
7
- * - Trigger evaluation via LogicEngine
8
- * - Context building from ledger
9
- * - claude-zeroshots spawning and monitoring
10
- * - Hook execution (onStart, onComplete, onError)
11
- */
12
-
13
- const LogicEngine = require('./logic-engine');
14
- const { validateAgentConfig } = require('./agent/agent-config');
15
- const { loadSettings, validateModelAgainstMax } = require('../lib/settings');
16
- const { normalizeProviderName } = require('../lib/provider-names');
17
- const { getProvider } = require('./providers');
18
- const { buildContext } = require('./agent/agent-context-builder');
19
- const { findMatchingTrigger, evaluateTrigger } = require('./agent/agent-trigger-evaluator');
20
- const { executeHook } = require('./agent/agent-hook-executor');
21
- const {
22
- spawnClaudeTask,
23
- followClaudeTaskLogs,
24
- waitForTaskReady,
25
- spawnClaudeTaskIsolated,
26
- getClaudeTasksPath,
27
- parseResultOutput,
28
- killTask,
29
- } = require('./agent/agent-task-executor');
30
- const {
31
- start: lifecycleStart,
32
- stop: lifecycleStop,
33
- handleMessage: lifecycleHandleMessage,
34
- executeTriggerAction: lifecycleExecuteTriggerAction,
35
- executeTask: lifecycleExecuteTask,
36
- startLivenessCheck: lifecycleStartLivenessCheck,
37
- stopLivenessCheck: lifecycleStopLivenessCheck,
38
- } = require('./agent/agent-lifecycle');
39
-
40
- class AgentWrapper {
41
- /**
42
- * @param {any} config - Agent configuration
43
- * @param {any} messageBus - Message bus instance
44
- * @param {any} cluster - Cluster instance
45
- * @param {any} options - Options
46
- */
47
- constructor(config, messageBus, cluster, options = {}) {
48
- // Validate and normalize configuration
49
- const normalizedConfig = validateAgentConfig(config, options);
50
-
51
- this.id = normalizedConfig.id;
52
- this.role = normalizedConfig.role;
53
- this.modelConfig = normalizedConfig.modelConfig;
54
- this.config = normalizedConfig;
55
- this.messageBus = messageBus;
56
- this.cluster = cluster;
57
- this.logicEngine = new LogicEngine(messageBus, cluster);
58
-
59
- this.state = 'idle';
60
- this.iteration = 0;
61
- this.maxIterations = normalizedConfig.maxIterations;
62
- this.timeout = normalizedConfig.timeout;
63
- /** @type {any} */
64
- this.currentTask = null;
65
- /** @type {string | null} */
66
- this.currentTaskId = null; // Track spawned task ID for resume capability
67
- /** @type {number | null} */
68
- this.processPid = null; // Track process PID for resource monitoring
69
- this.running = false;
70
- /** @type {Function | null} */
71
- this.unsubscribe = null;
72
- /** @type {number | null} */
73
- this.lastTaskEndTime = null; // Track when last task completed (for context filtering)
74
- /** @type {number | null} */
75
- this.lastAgentStartTime = null; // Track when agent last began executing (for context filtering)
76
-
77
- // LIVENESS DETECTION - Track output freshness to detect stuck agents
78
- /** @type {number | null} */
79
- this.lastOutputTime = null; // Timestamp of last output received
80
- /** @type {NodeJS.Timeout | null} */
81
- this.livenessCheckInterval = null; // Interval for health checks
82
- this.staleDuration = normalizedConfig.staleDuration;
83
- this.enableLivenessCheck = normalizedConfig.enableLivenessCheck;
84
-
85
- // MOCK SUPPORT - Inject mock spawn function for testing
86
- // When set, _spawnClaudeTask uses this instead of real ct CLI
87
- // Priority: options.mockSpawnFn (legacy) > options.taskRunner (new DI pattern)
88
- if (options.mockSpawnFn) {
89
- this.mockSpawnFn = options.mockSpawnFn;
90
- } else if (options.taskRunner) {
91
- // TaskRunner DI - create mockSpawnFn wrapper
92
- const taskRunner = options.taskRunner;
93
- this.mockSpawnFn = (args, { context }) => {
94
- const spec = this._resolveModelSpec();
95
- return taskRunner.run(context, {
96
- agentId: this.id,
97
- model: this._selectModel(),
98
- modelSpec: spec,
99
- provider: this._resolveProvider(),
100
- });
101
- };
102
- } else {
103
- this.mockSpawnFn = null;
104
- }
105
-
106
- this.testMode = options.testMode || false;
107
- this.quiet = options.quiet || false;
108
-
109
- // ISOLATION SUPPORT - Run tasks inside Docker container
110
- this.isolation = options.isolation || null;
111
-
112
- // WORKTREE SUPPORT - Run tasks in git worktree (lightweight isolation without Docker)
113
- this.worktree = options.worktree || null;
114
- }
115
-
116
- /**
117
- * Log message (respects quiet mode)
118
- * @private
119
- */
120
- _log(...args) {
121
- if (!this.quiet) {
122
- console.log(...args);
123
- }
124
- }
125
-
126
- _resolveProvider() {
127
- const settings = loadSettings();
128
- const clusterConfig = this.cluster?.config || {};
129
-
130
- const resolved =
131
- clusterConfig.forceProvider ||
132
- this.config.provider ||
133
- clusterConfig.defaultProvider ||
134
- settings.defaultProvider ||
135
- 'claude';
136
-
137
- return normalizeProviderName(resolved) || 'claude';
138
- }
139
-
140
- _resolveModelSpec() {
141
- const settings = loadSettings();
142
- const providerName = this._resolveProvider();
143
- const provider = getProvider(providerName);
144
- const clusterConfig = this.cluster?.config || {};
145
- const providerSettings = settings.providerSettings?.[providerName] || {};
146
- const levelOverrides = providerSettings.levelOverrides || {};
147
- const minLevel = providerSettings.minLevel;
148
- const maxLevel = providerSettings.maxLevel;
149
- const forcedLevel =
150
- clusterConfig.forceProvider === providerName ? clusterConfig.forceLevel : null;
151
-
152
- const applyReasoningOverride = (spec, override) => {
153
- if (!override) return spec;
154
- return { ...spec, reasoningEffort: override };
155
- };
156
-
157
- if (this.modelConfig.type === 'rules') {
158
- for (const rule of this.modelConfig.rules) {
159
- if (this._matchesIterationRange(rule.iterations)) {
160
- if (rule.model) {
161
- return {
162
- level: 'custom',
163
- model: rule.model,
164
- reasoningEffort: rule.reasoningEffort || this.config.reasoningEffort,
165
- };
166
- }
167
- if (rule.modelLevel) {
168
- const level = provider.validateLevel(rule.modelLevel, minLevel, maxLevel);
169
- const spec = provider.resolveModelSpec(level, levelOverrides);
170
- return applyReasoningOverride(
171
- { ...spec, level },
172
- rule.reasoningEffort || this.config.reasoningEffort
173
- );
174
- }
175
- }
176
- }
177
-
178
- throw new Error(
179
- `Agent ${this.id}: No model rule matched iteration ${this.iteration}. ` +
180
- `Add a catch-all rule like { "iterations": "all", "modelLevel": "level2" }`
181
- );
182
- }
183
-
184
- if (this.modelConfig.model) {
185
- return {
186
- level: 'custom',
187
- model: this.modelConfig.model,
188
- reasoningEffort: this.config.reasoningEffort,
189
- };
190
- }
191
-
192
- if (forcedLevel) {
193
- const level = provider.validateLevel(forcedLevel, minLevel, maxLevel);
194
- const spec = provider.resolveModelSpec(level, levelOverrides);
195
- return applyReasoningOverride({ ...spec, level }, this.config.reasoningEffort);
196
- }
197
-
198
- if (this.modelConfig.modelLevel) {
199
- const level = provider.validateLevel(this.modelConfig.modelLevel, minLevel, maxLevel);
200
- const spec = provider.resolveModelSpec(level, levelOverrides);
201
- return applyReasoningOverride({ ...spec, level }, this.config.reasoningEffort);
202
- }
203
-
204
- const defaultLevel = providerSettings.defaultLevel || provider.getDefaultLevel();
205
- const level = provider.validateLevel(defaultLevel, minLevel, maxLevel);
206
- const spec = provider.resolveModelSpec(level, levelOverrides);
207
- return applyReasoningOverride({ ...spec, level }, this.config.reasoningEffort);
208
- }
209
-
210
- /**
211
- * Publish a message to the message bus, always including sender_model
212
- * @private
213
- */
214
- _publish(message) {
215
- this.messageBus.publish({
216
- ...message,
217
- cluster_id: this.cluster.id,
218
- sender: this.id,
219
- sender_model: this._selectModel(),
220
- sender_provider: this._resolveProvider(),
221
- });
222
- }
223
-
224
- /**
225
- * Publish agent lifecycle event to message bus (visible in zeroshot logs)
226
- * @private
227
- */
228
- _publishLifecycle(event, details = {}) {
229
- this._publish({
230
- topic: 'AGENT_LIFECYCLE',
231
- receiver: 'system',
232
- content: {
233
- text: `${this.id}: ${event}`,
234
- data: {
235
- event,
236
- agent: this.id,
237
- role: this.role,
238
- state: this.state,
239
- model: this._selectModel(),
240
- provider: this._resolveProvider(),
241
- ...details,
242
- },
243
- },
244
- });
245
- }
246
-
247
- /**
248
- * Select model based on current iteration and agent config
249
- * Enforces legacy maxModel/minModel for Claude's haiku/sonnet/opus
250
- * @returns {string|null}
251
- * @private
252
- */
253
- _selectModel() {
254
- const spec = this._resolveModelSpec();
255
- const settings = loadSettings();
256
- const maxModel = settings.maxModel || 'sonnet';
257
- const minModel = settings.minModel || null;
258
-
259
- if (spec.model && ['opus', 'sonnet', 'haiku'].includes(spec.model)) {
260
- return validateModelAgainstMax(spec.model, maxModel, minModel);
261
- }
262
-
263
- return spec.model || null;
264
- }
265
-
266
- /**
267
- * Check if current iteration matches the range pattern
268
- * @param {string} pattern - e.g., "1", "1-3", "5+", "all"
269
- * @returns {boolean}
270
- * @private
271
- */
272
- _matchesIterationRange(pattern) {
273
- if (pattern === 'all') return true;
274
-
275
- const current = this.iteration;
276
-
277
- // Exact match: "3"
278
- if (/^\d+$/.test(pattern)) {
279
- return current === parseInt(pattern);
280
- }
281
-
282
- // Range: "1-3"
283
- const rangeMatch = pattern.match(/^(\d+)-(\d+)$/);
284
- if (rangeMatch) {
285
- const [, start, end] = rangeMatch;
286
- return current >= parseInt(start) && current <= parseInt(end);
287
- }
288
-
289
- // Open-ended: "5+"
290
- const openMatch = pattern.match(/^(\d+)\+$/);
291
- if (openMatch) {
292
- const [, start] = openMatch;
293
- return current >= parseInt(start);
294
- }
295
-
296
- throw new Error(
297
- `Agent ${this.id}: Invalid iteration pattern '${pattern}'. ` +
298
- `Valid formats: "1", "1-3", "5+", "all"`
299
- );
300
- }
301
-
302
- /**
303
- * Select prompt based on current iteration and agent config
304
- * @returns {string|null} System prompt string, or null if no prompt configured
305
- * @private
306
- */
307
- _selectPrompt() {
308
- const promptConfig = this.config.promptConfig;
309
-
310
- // No prompt configured
311
- if (!promptConfig) {
312
- return null;
313
- }
314
-
315
- // Backward compatibility: static prompt
316
- if (promptConfig.type === 'static') {
317
- return promptConfig.system;
318
- }
319
-
320
- // Dynamic rules: evaluate based on iteration
321
- for (const rule of promptConfig.rules) {
322
- if (this._matchesIterationRange(rule.match)) {
323
- return rule.system;
324
- }
325
- }
326
-
327
- // No match: fail fast
328
- throw new Error(
329
- `Agent ${this.id}: No prompt rule matched iteration ${this.iteration}. ` +
330
- `Add a catch-all rule like { "match": "all", "system": "..." }`
331
- );
332
- }
333
-
334
- /**
335
- * Start the agent (begin listening for triggers)
336
- */
337
- start() {
338
- return lifecycleStart(this);
339
- }
340
-
341
- /**
342
- * Stop the agent
343
- */
344
- stop() {
345
- return lifecycleStop(this);
346
- }
347
-
348
- /**
349
- * Handle incoming message
350
- * @private
351
- */
352
- _handleMessage(message) {
353
- return lifecycleHandleMessage(this, message);
354
- }
355
-
356
- /**
357
- * Find trigger matching the message topic
358
- * @private
359
- */
360
- _findMatchingTrigger(message) {
361
- return findMatchingTrigger({
362
- triggers: this.config.triggers,
363
- message,
364
- });
365
- }
366
-
367
- /**
368
- * Evaluate trigger logic
369
- * @private
370
- */
371
- _evaluateTrigger(trigger, message) {
372
- const agent = {
373
- id: this.id,
374
- role: this.role,
375
- iteration: this.iteration,
376
- cluster_id: this.cluster.id,
377
- };
378
-
379
- return evaluateTrigger({
380
- trigger,
381
- message,
382
- agent,
383
- logicEngine: this.logicEngine,
384
- });
385
- }
386
-
387
- /**
388
- * Execute trigger action
389
- * @private
390
- */
391
- _executeTriggerAction(trigger, message) {
392
- return lifecycleExecuteTriggerAction(this, trigger, message);
393
- }
394
-
395
- /**
396
- * Execute claude-zeroshots with built context
397
- * Retries disabled by default. Set agent config `maxRetries` to enable (e.g., 3).
398
- * @private
399
- */
400
- _executeTask(triggeringMessage) {
401
- return lifecycleExecuteTask(this, triggeringMessage);
402
- }
403
-
404
- /**
405
- * Build context from ledger based on contextStrategy
406
- * @private
407
- */
408
- _buildContext(triggeringMessage) {
409
- const previousAgentStart = this.lastAgentStartTime;
410
- const context = buildContext({
411
- id: this.id,
412
- role: this.role,
413
- iteration: this.iteration,
414
- config: this.config,
415
- messageBus: this.messageBus,
416
- cluster: this.cluster,
417
- lastTaskEndTime: this.lastTaskEndTime,
418
- lastAgentStartTime: previousAgentStart,
419
- triggeringMessage,
420
- selectedPrompt: this._selectPrompt(),
421
- // Pass isolation state for conditional git restriction
422
- worktree: this.worktree,
423
- isolation: this.isolation,
424
- });
425
-
426
- // Record when this iteration started so future "since: last_agent_start" filters work
427
- this.lastAgentStartTime = Date.now();
428
-
429
- return context;
430
- }
431
-
432
- /**
433
- * Spawn claude-zeroshots process and stream output via message bus
434
- * @private
435
- */
436
- _spawnClaudeTask(context) {
437
- return spawnClaudeTask(this, context);
438
- }
439
-
440
- /**
441
- * Wait for task to be registered in ct storage
442
- * @private
443
- */
444
- _waitForTaskReady(taskId, maxRetries = 10, delayMs = 200) {
445
- return waitForTaskReady(this, taskId, maxRetries, delayMs);
446
- }
447
-
448
- /**
449
- * Follow claude-zeroshots logs until completion, streaming to message bus
450
- * Reads log file directly for reliable streaming
451
- * @private
452
- */
453
- _followClaudeTaskLogs(taskId) {
454
- return followClaudeTaskLogs(this, taskId);
455
- }
456
-
457
- /**
458
- * Get path to claude-zeroshots executable
459
- * @private
460
- */
461
- _getClaudeTasksPath() {
462
- return getClaudeTasksPath();
463
- }
464
-
465
- /**
466
- * Spawn claude-zeroshots inside Docker container (isolation mode)
467
- * Runs Claude CLI inside the container for full isolation
468
- * @private
469
- */
470
- _spawnClaudeTaskIsolated(context) {
471
- return spawnClaudeTaskIsolated(this, context);
472
- }
473
-
474
- /**
475
- * Kill current task
476
- * @private
477
- */
478
- _killTask() {
479
- return killTask(this);
480
- }
481
-
482
- /**
483
- * Execute a hook
484
- * THROWS on failure - no silent errors
485
- * @private
486
- */
487
- _executeHook(hookName, context) {
488
- const hook = this.config.hooks?.[hookName];
489
- return executeHook({
490
- hook,
491
- agent: this,
492
- message: context.triggeringMessage,
493
- result: context.result,
494
- messageBus: this.messageBus,
495
- cluster: this.cluster,
496
- orchestrator: this.orchestrator,
497
- });
498
- }
499
-
500
- /**
501
- * Parse agent output to extract structured result data
502
- * GENERIC - returns whatever structured output the agent provides
503
- * Works with any agent schema (planner, validator, worker, etc.)
504
- * Falls back to reformatting if extraction fails
505
- * @private
506
- */
507
- _parseResultOutput(output) {
508
- return parseResultOutput(this, output);
509
- }
510
-
511
- /**
512
- * Resume agent task with context from previous failure
513
- * Called by Orchestrator.resume() to continue where we left off
514
- * @param {String} resumeContext - Context describing what to resume
515
- */
516
- async resume(resumeContext) {
517
- if (!this.running) {
518
- throw new Error(`Agent ${this.id} is not running. Start it first.`);
519
- }
520
-
521
- if (this.state !== 'idle') {
522
- throw new Error(`Agent ${this.id} is busy (state: ${this.state}). Wait for current task.`);
523
- }
524
-
525
- this._log(`[${this.id}] Resuming task...`);
526
-
527
- // Create a synthetic triggering message for resume
528
- const triggeringMessage = {
529
- cluster_id: this.cluster.id,
530
- topic: 'AGENT_RESUME',
531
- sender: 'system',
532
- content: {
533
- text: resumeContext,
534
- },
535
- };
536
-
537
- // Execute the task with resume context
538
- await this._executeTask(triggeringMessage);
539
- }
540
-
541
- /**
542
- * Get current agent state
543
- */
544
- getState() {
545
- const modelSpec = this._resolveModelSpec();
546
- return {
547
- id: this.id,
548
- role: this.role,
549
- model: this._selectModel(),
550
- provider: this._resolveProvider(),
551
- modelSpec,
552
- state: this.state,
553
- iteration: this.iteration,
554
- maxIterations: this.maxIterations,
555
- currentTask: this.currentTask ? true : false,
556
- currentTaskId: this.currentTaskId,
557
- pid: this.processPid,
558
- };
559
- }
560
-
561
- /**
562
- * Start monitoring agent output liveness
563
- * Detects when agent produces no output for configured staleDuration
564
- * @private
565
- */
566
- _startLivenessCheck() {
567
- return lifecycleStartLivenessCheck(this);
568
- }
569
-
570
- /**
571
- * Stop liveness monitoring
572
- * @private
573
- */
574
- _stopLivenessCheck() {
575
- return lifecycleStopLivenessCheck(this);
576
- }
577
- }
578
-
579
- module.exports = AgentWrapper;