@covibes/zeroshot 5.3.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 (119) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +8 -385
  3. package/cli/index.js +108 -4615
  4. package/package.json +16 -125
  5. package/CHANGELOG.md +0 -537
  6. package/cli/commands/providers.js +0 -150
  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 -253
  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 -697
  14. package/cluster-templates/base-templates/single-worker.json +0 -63
  15. package/cluster-templates/base-templates/worker-validator.json +0 -152
  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 -212
  21. package/lib/id-detector.js +0 -53
  22. package/lib/provider-detection.js +0 -59
  23. package/lib/provider-names.js +0 -56
  24. package/lib/settings.js +0 -405
  25. package/lib/stream-json-parser.js +0 -10
  26. package/scripts/fix-node-pty-permissions.js +0 -75
  27. package/scripts/record-demo.sh +0 -279
  28. package/scripts/test-install.sh +0 -40
  29. package/scripts/validate-templates.js +0 -100
  30. package/src/agent/agent-config.js +0 -193
  31. package/src/agent/agent-context-builder.js +0 -335
  32. package/src/agent/agent-hook-executor.js +0 -402
  33. package/src/agent/agent-lifecycle.js +0 -683
  34. package/src/agent/agent-stuck-detector.js +0 -256
  35. package/src/agent/agent-task-executor.js +0 -1431
  36. package/src/agent/agent-trigger-evaluator.js +0 -67
  37. package/src/agent/output-extraction.js +0 -200
  38. package/src/agent/output-reformatter.js +0 -175
  39. package/src/agent/schema-utils.js +0 -111
  40. package/src/agent-wrapper.js +0 -570
  41. package/src/agents/git-pusher-agent.json +0 -20
  42. package/src/attach/attach-client.js +0 -438
  43. package/src/attach/attach-server.js +0 -543
  44. package/src/attach/index.js +0 -35
  45. package/src/attach/protocol.js +0 -220
  46. package/src/attach/ring-buffer.js +0 -121
  47. package/src/attach/socket-discovery.js +0 -267
  48. package/src/claude-task-runner.js +0 -523
  49. package/src/config-router.js +0 -80
  50. package/src/config-validator.js +0 -1660
  51. package/src/copy-worker.js +0 -43
  52. package/src/github.js +0 -139
  53. package/src/isolation-manager.js +0 -1381
  54. package/src/ledger.js +0 -614
  55. package/src/logic-engine.js +0 -223
  56. package/src/message-bus-bridge.js +0 -139
  57. package/src/message-bus.js +0 -249
  58. package/src/name-generator.js +0 -232
  59. package/src/orchestrator.js +0 -2519
  60. package/src/preflight.js +0 -485
  61. package/src/process-metrics.js +0 -566
  62. package/src/providers/anthropic/cli-builder.js +0 -45
  63. package/src/providers/anthropic/index.js +0 -134
  64. package/src/providers/anthropic/models.js +0 -23
  65. package/src/providers/anthropic/output-parser.js +0 -159
  66. package/src/providers/base-provider.js +0 -181
  67. package/src/providers/capabilities.js +0 -51
  68. package/src/providers/google/cli-builder.js +0 -55
  69. package/src/providers/google/index.js +0 -116
  70. package/src/providers/google/models.js +0 -24
  71. package/src/providers/google/output-parser.js +0 -92
  72. package/src/providers/index.js +0 -75
  73. package/src/providers/openai/cli-builder.js +0 -122
  74. package/src/providers/openai/index.js +0 -135
  75. package/src/providers/openai/models.js +0 -21
  76. package/src/providers/openai/output-parser.js +0 -129
  77. package/src/schemas/sub-cluster.js +0 -156
  78. package/src/status-footer.js +0 -980
  79. package/src/sub-cluster-wrapper.js +0 -560
  80. package/src/task-runner.js +0 -30
  81. package/src/template-resolver.js +0 -369
  82. package/src/tui/CHANGES.txt +0 -133
  83. package/src/tui/LAYOUT.md +0 -261
  84. package/src/tui/README.txt +0 -192
  85. package/src/tui/TWO-LEVEL-NAVIGATION.md +0 -186
  86. package/src/tui/data-poller.js +0 -325
  87. package/src/tui/demo.js +0 -208
  88. package/src/tui/formatters.js +0 -128
  89. package/src/tui/index.js +0 -193
  90. package/src/tui/keybindings.js +0 -383
  91. package/src/tui/layout.js +0 -334
  92. package/src/tui/renderer.js +0 -194
  93. package/task-lib/attachable-watcher.js +0 -272
  94. package/task-lib/claude-recovery.js +0 -119
  95. package/task-lib/commands/clean.js +0 -50
  96. package/task-lib/commands/get-log-path.js +0 -23
  97. package/task-lib/commands/kill.js +0 -32
  98. package/task-lib/commands/list.js +0 -105
  99. package/task-lib/commands/logs.js +0 -411
  100. package/task-lib/commands/resume.js +0 -42
  101. package/task-lib/commands/run.js +0 -57
  102. package/task-lib/commands/schedule.js +0 -105
  103. package/task-lib/commands/scheduler-cmd.js +0 -96
  104. package/task-lib/commands/schedules.js +0 -98
  105. package/task-lib/commands/status.js +0 -44
  106. package/task-lib/commands/unschedule.js +0 -16
  107. package/task-lib/completion.js +0 -9
  108. package/task-lib/config.js +0 -10
  109. package/task-lib/name-generator.js +0 -230
  110. package/task-lib/package.json +0 -3
  111. package/task-lib/runner.js +0 -144
  112. package/task-lib/scheduler.js +0 -252
  113. package/task-lib/store.js +0 -230
  114. package/task-lib/tui/formatters.js +0 -166
  115. package/task-lib/tui/index.js +0 -197
  116. package/task-lib/tui/layout.js +0 -111
  117. package/task-lib/tui/renderer.js +0 -119
  118. package/task-lib/tui.js +0 -384
  119. package/task-lib/watcher.js +0 -188
@@ -1,523 +0,0 @@
1
- /**
2
- * ClaudeTaskRunner - Production implementation of TaskRunner
3
- *
4
- * Executes provider tasks by spawning the `zeroshot task run` CLI command,
5
- * following logs, and assembling results.
6
- */
7
-
8
- const { spawn, exec, execSync } = require('child_process');
9
- const fs = require('fs');
10
- const TaskRunner = require('./task-runner');
11
- const { loadSettings } = require('../lib/settings');
12
- const { normalizeProviderName } = require('../lib/provider-names');
13
- const { getProvider } = require('./providers');
14
-
15
- class ClaudeTaskRunner extends TaskRunner {
16
- /**
17
- * @param {Object} options
18
- * @param {Object} [options.messageBus] - MessageBus for streaming output
19
- * @param {boolean} [options.quiet] - Suppress console logging
20
- * @param {number} [options.timeout] - Task timeout in ms (default: 1 hour)
21
- * @param {Function} [options.onOutput] - Callback for output lines
22
- */
23
- constructor(options = {}) {
24
- super();
25
- this.messageBus = options.messageBus || null;
26
- this.quiet = options.quiet || false;
27
- this.timeout = options.timeout || 60 * 60 * 1000;
28
- this.onOutput = options.onOutput || null;
29
- }
30
-
31
- /**
32
- * @param {...any} args
33
- */
34
- _log(...args) {
35
- if (!this.quiet) {
36
- console.log(...args);
37
- }
38
- }
39
-
40
- /**
41
- * Execute a task via zeroshot CLI
42
- *
43
- * @param {string} context - Full prompt/context
44
- * @param {{agentId?: string, model?: string, outputFormat?: string, jsonSchema?: any, strictSchema?: boolean, cwd?: string, isolation?: any}} options - Execution options
45
- * @returns {Promise<{success: boolean, output: string, error: string|null, taskId?: string}>}
46
- */
47
- async run(context, options = {}) {
48
- const {
49
- agentId = 'unknown',
50
- provider,
51
- model = null,
52
- modelLevel = null,
53
- modelSpec: explicitModelSpec = null,
54
- reasoningEffort = null,
55
- outputFormat = 'stream-json',
56
- jsonSchema = null,
57
- strictSchema = false, // false = live streaming (default), true = CLI schema enforcement (no streaming)
58
- cwd = process.cwd(),
59
- isolation = null,
60
- } = options;
61
-
62
- const settings = loadSettings();
63
- const providerName = normalizeProviderName(provider || settings.defaultProvider || 'claude');
64
- const providerModule = getProvider(providerName);
65
- const providerSettings = settings.providerSettings?.[providerName] || {};
66
- const levelOverrides = providerSettings.levelOverrides || {};
67
-
68
- let resolvedModelSpec = explicitModelSpec;
69
- if (!resolvedModelSpec) {
70
- if (model) {
71
- resolvedModelSpec = { model, reasoningEffort };
72
- } else {
73
- const level =
74
- modelLevel || providerSettings.defaultLevel || providerModule.getDefaultLevel();
75
- resolvedModelSpec = providerModule.resolveModelSpec(level, levelOverrides);
76
- if (reasoningEffort) {
77
- resolvedModelSpec = { ...resolvedModelSpec, reasoningEffort };
78
- }
79
- }
80
- }
81
-
82
- // Isolation mode delegates to separate method
83
- if (isolation?.enabled) {
84
- return this._runIsolated(context, {
85
- ...options,
86
- provider: providerName,
87
- modelSpec: resolvedModelSpec,
88
- });
89
- }
90
-
91
- const ctPath = 'zeroshot';
92
-
93
- // Build args.
94
- // json output does not stream; if a jsonSchema is configured we run stream-json
95
- // for live logs and validate/parse JSON after completion.
96
- // Set strictSchema=true to disable live streaming and use CLI's native schema enforcement.
97
- const desiredOutputFormat = outputFormat;
98
- const runOutputFormat =
99
- jsonSchema && desiredOutputFormat === 'json' && !strictSchema
100
- ? 'stream-json'
101
- : desiredOutputFormat;
102
- const args = ['task', 'run', '--output-format', runOutputFormat, '--provider', providerName];
103
-
104
- if (resolvedModelSpec?.model) {
105
- args.push('--model', resolvedModelSpec.model);
106
- }
107
-
108
- if (resolvedModelSpec?.reasoningEffort) {
109
- args.push('--reasoning-effort', resolvedModelSpec.reasoningEffort);
110
- }
111
-
112
- // Pass schema to CLI only when using json output (strictSchema=true or no conflict)
113
- if (jsonSchema && runOutputFormat === 'json') {
114
- args.push('--json-schema', JSON.stringify(jsonSchema));
115
- }
116
-
117
- args.push(context);
118
-
119
- // Spawn and get task ID
120
- const spawnEnv = {
121
- ...process.env,
122
- };
123
- if (providerName === 'claude' && resolvedModelSpec?.model) {
124
- spawnEnv.ANTHROPIC_MODEL = resolvedModelSpec.model;
125
- }
126
-
127
- const taskId = await this._spawnAndGetTaskId(ctPath, args, cwd, spawnEnv, agentId);
128
-
129
- this._log(`📋 [${agentId}]: Following zeroshot logs for ${taskId}`);
130
-
131
- // Wait for task registration
132
- await this._waitForTaskReady(ctPath, taskId);
133
-
134
- // Follow logs until completion
135
- return this._followLogs(ctPath, taskId, agentId);
136
- }
137
-
138
- /**
139
- * @param {string} ctPath
140
- * @param {string[]} args
141
- * @param {string} cwd
142
- * @param {Object} spawnEnv
143
- * @param {string} _agentId
144
- * @returns {Promise<string>}
145
- */
146
- _spawnAndGetTaskId(ctPath, args, cwd, spawnEnv, _agentId) {
147
- return new Promise((resolve, reject) => {
148
- const proc = spawn(ctPath, args, {
149
- cwd,
150
- stdio: ['ignore', 'pipe', 'pipe'],
151
- env: spawnEnv,
152
- });
153
-
154
- let stdout = '';
155
- let stderr = '';
156
-
157
- proc.stdout.on('data', (data) => {
158
- stdout += data.toString();
159
- });
160
-
161
- proc.stderr.on('data', (data) => {
162
- stderr += data.toString();
163
- });
164
-
165
- proc.on('close', (code) => {
166
- if (code === 0) {
167
- const match = stdout.match(/Task spawned: ((?:task-)?[a-z]+-[a-z]+-[a-z0-9]+)/);
168
- if (match) {
169
- resolve(match[1]);
170
- } else {
171
- reject(new Error(`Could not parse task ID from output: ${stdout}`));
172
- }
173
- } else {
174
- reject(new Error(`zeroshot task run failed with code ${code}: ${stderr}`));
175
- }
176
- });
177
-
178
- proc.on('error', (error) => {
179
- reject(error);
180
- });
181
- });
182
- }
183
-
184
- /**
185
- * @param {string} ctPath
186
- * @param {string} taskId
187
- * @param {number} maxRetries
188
- * @param {number} delayMs
189
- * @returns {Promise<void>}
190
- */
191
- async _waitForTaskReady(ctPath, taskId, maxRetries = 10, delayMs = 200) {
192
- for (let i = 0; i < maxRetries; i++) {
193
- const exists = await new Promise((resolve) => {
194
- exec(`${ctPath} status ${taskId}`, (error, stdout) => {
195
- resolve(!error && !stdout.includes('Task not found'));
196
- });
197
- });
198
-
199
- if (exists) return;
200
- await new Promise((r) => setTimeout(r, delayMs));
201
- }
202
- console.warn(
203
- `⚠️ Task ${taskId} not yet visible after ${maxRetries} retries, continuing anyway`
204
- );
205
- }
206
-
207
- /**
208
- * @param {string} ctPath
209
- * @param {string} taskId
210
- * @param {string} agentId
211
- * @returns {Promise<{success: boolean, output: string, error: string|null, taskId: string}>}
212
- */
213
- _followLogs(ctPath, taskId, agentId) {
214
- return new Promise((resolve, reject) => {
215
- let output = '';
216
- /** @type {string|null} */
217
- let logFilePath = null;
218
- let lastSize = 0;
219
- /** @type {NodeJS.Timeout|null} */
220
- let pollInterval = null;
221
- /** @type {NodeJS.Timeout|null} */
222
- let statusCheckInterval = null;
223
- let resolved = false;
224
- let lineBuffer = '';
225
-
226
- // Get log file path
227
- try {
228
- logFilePath = execSync(`${ctPath} get-log-path ${taskId}`, {
229
- encoding: 'utf-8',
230
- }).trim();
231
- } catch {
232
- this._log(`⏳ [${agentId}]: Waiting for log file...`);
233
- }
234
-
235
- /**
236
- * @param {string} line
237
- */
238
- const broadcastLine = (line) => {
239
- if (!line.trim()) return;
240
-
241
- let content = line;
242
- const timestampMatch = line.match(/^\[(\d{13})\](.*)$/);
243
- if (timestampMatch) {
244
- content = timestampMatch[2];
245
- }
246
-
247
- // Skip non-JSON patterns
248
- if (
249
- content.startsWith('===') ||
250
- content.startsWith('Finished:') ||
251
- content.startsWith('Exit code:') ||
252
- (content.includes('"type":"system"') && content.includes('"subtype":"init"'))
253
- ) {
254
- return;
255
- }
256
-
257
- if (!content.trim().startsWith('{')) return;
258
-
259
- try {
260
- JSON.parse(content);
261
- } catch {
262
- return;
263
- }
264
-
265
- output += content + '\n';
266
-
267
- // Callback for output streaming
268
- if (this.onOutput) {
269
- this.onOutput(content, agentId);
270
- }
271
- };
272
-
273
- /**
274
- * @param {string} content
275
- */
276
- const processNewContent = (content) => {
277
- lineBuffer += content;
278
- const lines = lineBuffer.split('\n');
279
-
280
- for (let i = 0; i < lines.length - 1; i++) {
281
- broadcastLine(lines[i]);
282
- }
283
- lineBuffer = lines[lines.length - 1];
284
- };
285
-
286
- const pollLogFile = () => {
287
- if (!logFilePath) {
288
- try {
289
- logFilePath = execSync(`${ctPath} get-log-path ${taskId}`, {
290
- encoding: 'utf-8',
291
- }).trim();
292
- } catch {
293
- return;
294
- }
295
- }
296
-
297
- if (!fs.existsSync(logFilePath)) return;
298
-
299
- try {
300
- const stats = fs.statSync(logFilePath);
301
- const currentSize = stats.size;
302
-
303
- if (currentSize > lastSize) {
304
- const fd = fs.openSync(logFilePath, 'r');
305
- const buffer = Buffer.alloc(currentSize - lastSize);
306
- fs.readSync(fd, buffer, 0, buffer.length, lastSize);
307
- fs.closeSync(fd);
308
-
309
- processNewContent(buffer.toString('utf-8'));
310
- lastSize = currentSize;
311
- }
312
- } catch (err) {
313
- const error = /** @type {Error} */ (err);
314
- console.warn(`⚠️ [${agentId}]: Error reading log: ${error.message}`);
315
- }
316
- };
317
-
318
- pollInterval = setInterval(pollLogFile, 300);
319
-
320
- /**
321
- * @param {boolean} success
322
- * @param {string} stdout
323
- * @returns {string|null}
324
- */
325
- const extractErrorContext = (success, stdout) => {
326
- if (success) return null;
327
-
328
- // Try to extract error from status output first
329
- const statusErrorMatch = stdout.match(/Error:\s*(.+)/);
330
- if (statusErrorMatch) {
331
- return statusErrorMatch[1].trim();
332
- }
333
-
334
- // Fall back to last 500 chars of output
335
- const lastOutput = output.slice(-500).trim();
336
- if (!lastOutput) {
337
- return 'Task failed with no output';
338
- }
339
-
340
- const errorPatterns = [
341
- /Error:\s*(.+)/i,
342
- /error:\s*(.+)/i,
343
- /failed:\s*(.+)/i,
344
- /Exception:\s*(.+)/i,
345
- ];
346
-
347
- for (const pattern of errorPatterns) {
348
- const match = lastOutput.match(pattern);
349
- if (match) {
350
- return match[1].slice(0, 200);
351
- }
352
- }
353
-
354
- return `Task failed. Last output: ${lastOutput.slice(-200)}`;
355
- };
356
-
357
- statusCheckInterval = setInterval(() => {
358
- exec(`${ctPath} status ${taskId}`, (error, stdout) => {
359
- if (resolved) return;
360
-
361
- if (
362
- !error &&
363
- (stdout.includes('Status: completed') || stdout.includes('Status: failed'))
364
- ) {
365
- const success = stdout.includes('Status: completed');
366
-
367
- pollLogFile();
368
-
369
- setTimeout(() => {
370
- if (resolved) return;
371
- resolved = true;
372
-
373
- if (pollInterval) clearInterval(pollInterval);
374
- if (statusCheckInterval) clearInterval(statusCheckInterval);
375
-
376
- const errorContext = extractErrorContext(success, stdout);
377
-
378
- resolve({
379
- success,
380
- output,
381
- error: errorContext,
382
- taskId,
383
- });
384
- }, 500);
385
- }
386
- });
387
- }, 1000);
388
-
389
- // Timeout
390
- setTimeout(() => {
391
- if (resolved) return;
392
- resolved = true;
393
-
394
- clearInterval(pollInterval);
395
- clearInterval(statusCheckInterval);
396
-
397
- const timeoutMinutes = Math.round(this.timeout / 60000);
398
- reject(new Error(`Task timed out after ${timeoutMinutes} minutes`));
399
- }, this.timeout);
400
- });
401
- }
402
-
403
- /**
404
- * Run task in isolated Docker container
405
- * @param {string} context
406
- * @param {{agentId?: string, model?: string, outputFormat?: string, jsonSchema?: any, strictSchema?: boolean, isolation?: any}} options
407
- * @returns {Promise<{success: boolean, output: string, error: string|null}>}
408
- */
409
- _runIsolated(context, options) {
410
- const {
411
- agentId = 'unknown',
412
- provider = 'claude',
413
- modelSpec = null,
414
- outputFormat = 'stream-json',
415
- jsonSchema = null,
416
- strictSchema = false,
417
- isolation,
418
- } = options;
419
- const { manager, clusterId } = isolation;
420
-
421
- this._log(`📦 [${agentId}]: Running task in isolated container...`);
422
-
423
- const desiredOutputFormat = outputFormat;
424
- const runOutputFormat =
425
- jsonSchema && desiredOutputFormat === 'json' && !strictSchema
426
- ? 'stream-json'
427
- : desiredOutputFormat;
428
-
429
- const command = [
430
- 'zeroshot',
431
- 'task',
432
- 'run',
433
- '--output-format',
434
- runOutputFormat,
435
- '--provider',
436
- provider,
437
- ];
438
-
439
- if (modelSpec?.model) {
440
- command.push('--model', modelSpec.model);
441
- }
442
-
443
- if (modelSpec?.reasoningEffort) {
444
- command.push('--reasoning-effort', modelSpec.reasoningEffort);
445
- }
446
-
447
- if (jsonSchema && runOutputFormat === 'json') {
448
- command.push('--json-schema', JSON.stringify(jsonSchema));
449
- }
450
-
451
- let finalContext = context;
452
- if (jsonSchema && desiredOutputFormat === 'json' && runOutputFormat === 'stream-json') {
453
- finalContext += `\n\n## Output Format (REQUIRED)\n\nReturn a JSON object that matches this schema exactly.\n\nSchema:\n\`\`\`json\n${JSON.stringify(
454
- jsonSchema,
455
- null,
456
- 2
457
- )}\n\`\`\`\n`;
458
- }
459
-
460
- command.push(finalContext);
461
-
462
- return new Promise((resolve, reject) => {
463
- let output = '';
464
- let resolved = false;
465
-
466
- const proc = manager.spawnInContainer(clusterId, command, {
467
- env:
468
- provider === 'claude' && modelSpec?.model
469
- ? { ANTHROPIC_MODEL: modelSpec.model, ZEROSHOT_BLOCK_ASK_USER: '1' }
470
- : {},
471
- });
472
-
473
- proc.stdout.on('data', (/** @type {Buffer} */ data) => {
474
- const chunk = data.toString();
475
- output += chunk;
476
-
477
- if (this.onOutput) {
478
- this.onOutput(chunk, agentId);
479
- }
480
- });
481
-
482
- proc.stderr.on('data', (/** @type {Buffer} */ data) => {
483
- const chunk = data.toString();
484
- if (!this.quiet) {
485
- console.error(`[${agentId}] stderr:`, chunk);
486
- }
487
- });
488
-
489
- proc.on('close', (/** @type {number|null} */ code) => {
490
- if (resolved) return;
491
- resolved = true;
492
-
493
- resolve({
494
- success: code === 0,
495
- output,
496
- error: code === 0 ? null : `Container exited with code ${code}`,
497
- });
498
- });
499
-
500
- proc.on('error', (/** @type {Error} */ error) => {
501
- if (resolved) return;
502
- resolved = true;
503
- reject(error);
504
- });
505
-
506
- setTimeout(() => {
507
- if (resolved) return;
508
- resolved = true;
509
-
510
- try {
511
- proc.kill('SIGKILL');
512
- } catch {
513
- // Ignore - process may already be dead
514
- }
515
-
516
- const timeoutMinutes = Math.round(this.timeout / 60000);
517
- reject(new Error(`Isolated task timed out after ${timeoutMinutes} minutes`));
518
- }, this.timeout);
519
- });
520
- }
521
- }
522
-
523
- module.exports = ClaudeTaskRunner;
@@ -1,80 +0,0 @@
1
- /**
2
- * Config Router - Maps 2D classification to parameterized templates
3
- *
4
- * Single source of truth for: Complexity × TaskType → { base, params }
5
- * Used by both logic-engine.js (trigger evaluation) and agent-wrapper.js (transform scripts)
6
- */
7
-
8
- const { DEFAULT_MAX_ITERATIONS } = require('./agent/agent-config');
9
-
10
- /**
11
- * Get cluster config based on complexity and task type
12
- * @param {string} complexity - TRIVIAL, SIMPLE, STANDARD, CRITICAL
13
- * @param {string} taskType - INQUIRY, TASK, DEBUG
14
- * @returns {{ base: string, params: object }}
15
- */
16
- function getConfig(complexity, taskType) {
17
- const getBase = () => {
18
- if (taskType === 'DEBUG' && complexity !== 'TRIVIAL') {
19
- return 'debug-workflow';
20
- }
21
- if (complexity === 'TRIVIAL') {
22
- return 'single-worker';
23
- }
24
- if (complexity === 'SIMPLE') {
25
- return 'worker-validator';
26
- }
27
- return 'full-workflow';
28
- };
29
-
30
- const getLevel = (role) => {
31
- if (complexity === 'CRITICAL' && role === 'planner') return 'level3';
32
- if (complexity === 'TRIVIAL') return 'level1';
33
- return 'level2';
34
- };
35
-
36
- const getValidatorCount = () => {
37
- if (complexity === 'TRIVIAL') return 0;
38
- if (complexity === 'SIMPLE') return 1;
39
- if (complexity === 'STANDARD') return 2;
40
- if (complexity === 'CRITICAL') return 4;
41
- return 1;
42
- };
43
-
44
- const getMaxTokens = () => {
45
- if (complexity === 'TRIVIAL') return 50000;
46
- if (complexity === 'SIMPLE') return 100000;
47
- if (complexity === 'STANDARD') return 100000;
48
- if (complexity === 'CRITICAL') return 150000;
49
- return 100000;
50
- };
51
-
52
- const base = getBase();
53
-
54
- const params = {
55
- task_type: taskType,
56
- complexity,
57
- max_tokens: getMaxTokens(),
58
- max_iterations: DEFAULT_MAX_ITERATIONS,
59
- };
60
-
61
- if (base === 'single-worker') {
62
- params.worker_level = getLevel('worker');
63
- } else if (base === 'worker-validator') {
64
- params.worker_level = getLevel('worker');
65
- params.validator_level = getLevel('validator');
66
- } else if (base === 'debug-workflow') {
67
- params.investigator_level = getLevel('planner');
68
- params.fixer_level = getLevel('worker');
69
- params.tester_level = getLevel('validator');
70
- } else if (base === 'full-workflow') {
71
- params.planner_level = getLevel('planner');
72
- params.worker_level = getLevel('worker');
73
- params.validator_level = getLevel('validator');
74
- params.validator_count = getValidatorCount();
75
- }
76
-
77
- return { base, params };
78
- }
79
-
80
- module.exports = { getConfig };