@the-open-engine/zeroshot 5.4.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/CHANGELOG.md +539 -0
- package/LICENSE +21 -0
- package/README.md +508 -0
- package/cli/commands/inspect-render.js +135 -0
- package/cli/commands/inspect.js +294 -0
- package/cli/commands/providers.js +149 -0
- package/cli/index.js +5431 -0
- package/cli/lib/first-run.js +211 -0
- package/cli/lib/update-checker.js +281 -0
- package/cli/message-formatter-utils.js +75 -0
- package/cli/message-formatters-normal.js +275 -0
- package/cli/message-formatters-watch.js +185 -0
- package/cluster-templates/base-templates/debug-workflow.json +422 -0
- package/cluster-templates/base-templates/full-workflow.json +727 -0
- package/cluster-templates/base-templates/heavy-validation.json +272 -0
- package/cluster-templates/base-templates/quick-validation.json +285 -0
- package/cluster-templates/base-templates/single-worker.json +71 -0
- package/cluster-templates/base-templates/worker-validator.json +230 -0
- package/cluster-templates/conductor-bootstrap.json +130 -0
- package/docker/zeroshot-cluster/Dockerfile +153 -0
- package/docker/zeroshot-cluster/pre-baked-deps.json +28 -0
- package/lib/agent-cli-provider/adapters/claude-parser.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/claude-parser.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-parser.js +122 -0
- package/lib/agent-cli-provider/adapters/claude-parser.js.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.d.ts +15 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.js +165 -0
- package/lib/agent-cli-provider/adapters/claude-recovery.js.map +1 -0
- package/lib/agent-cli-provider/adapters/claude.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/claude.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/claude.js +181 -0
- package/lib/agent-cli-provider/adapters/claude.js.map +1 -0
- package/lib/agent-cli-provider/adapters/codex-parser.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/codex-parser.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/codex-parser.js +192 -0
- package/lib/agent-cli-provider/adapters/codex-parser.js.map +1 -0
- package/lib/agent-cli-provider/adapters/codex.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/codex.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/codex.js +151 -0
- package/lib/agent-cli-provider/adapters/codex.js.map +1 -0
- package/lib/agent-cli-provider/adapters/common.d.ts +28 -0
- package/lib/agent-cli-provider/adapters/common.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/common.js +71 -0
- package/lib/agent-cli-provider/adapters/common.js.map +1 -0
- package/lib/agent-cli-provider/adapters/gemini.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/gemini.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/gemini.js +176 -0
- package/lib/agent-cli-provider/adapters/gemini.js.map +1 -0
- package/lib/agent-cli-provider/adapters/index.d.ts +9 -0
- package/lib/agent-cli-provider/adapters/index.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/index.js +95 -0
- package/lib/agent-cli-provider/adapters/index.js.map +1 -0
- package/lib/agent-cli-provider/adapters/opencode.d.ts +3 -0
- package/lib/agent-cli-provider/adapters/opencode.d.ts.map +1 -0
- package/lib/agent-cli-provider/adapters/opencode.js +228 -0
- package/lib/agent-cli-provider/adapters/opencode.js.map +1 -0
- package/lib/agent-cli-provider/contract-actions.d.ts +5 -0
- package/lib/agent-cli-provider/contract-actions.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-actions.js +140 -0
- package/lib/agent-cli-provider/contract-actions.js.map +1 -0
- package/lib/agent-cli-provider/contract-env.d.ts +11 -0
- package/lib/agent-cli-provider/contract-env.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-env.js +113 -0
- package/lib/agent-cli-provider/contract-env.js.map +1 -0
- package/lib/agent-cli-provider/contract-envelope.d.ts +49 -0
- package/lib/agent-cli-provider/contract-envelope.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-envelope.js +52 -0
- package/lib/agent-cli-provider/contract-envelope.js.map +1 -0
- package/lib/agent-cli-provider/contract-errors.d.ts +22 -0
- package/lib/agent-cli-provider/contract-errors.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-errors.js +71 -0
- package/lib/agent-cli-provider/contract-errors.js.map +1 -0
- package/lib/agent-cli-provider/contract-fallback.d.ts +7 -0
- package/lib/agent-cli-provider/contract-fallback.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-fallback.js +102 -0
- package/lib/agent-cli-provider/contract-fallback.js.map +1 -0
- package/lib/agent-cli-provider/contract-invoke.d.ts +5 -0
- package/lib/agent-cli-provider/contract-invoke.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-invoke.js +89 -0
- package/lib/agent-cli-provider/contract-invoke.js.map +1 -0
- package/lib/agent-cli-provider/contract-options.d.ts +3 -0
- package/lib/agent-cli-provider/contract-options.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-options.js +140 -0
- package/lib/agent-cli-provider/contract-options.js.map +1 -0
- package/lib/agent-cli-provider/contract-parse.d.ts +15 -0
- package/lib/agent-cli-provider/contract-parse.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-parse.js +81 -0
- package/lib/agent-cli-provider/contract-parse.js.map +1 -0
- package/lib/agent-cli-provider/contract-support.d.ts +18 -0
- package/lib/agent-cli-provider/contract-support.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract-support.js +154 -0
- package/lib/agent-cli-provider/contract-support.js.map +1 -0
- package/lib/agent-cli-provider/contract.d.ts +13 -0
- package/lib/agent-cli-provider/contract.d.ts.map +1 -0
- package/lib/agent-cli-provider/contract.js +30 -0
- package/lib/agent-cli-provider/contract.js.map +1 -0
- package/lib/agent-cli-provider/env-safety.d.ts +11 -0
- package/lib/agent-cli-provider/env-safety.d.ts.map +1 -0
- package/lib/agent-cli-provider/env-safety.js +83 -0
- package/lib/agent-cli-provider/env-safety.js.map +1 -0
- package/lib/agent-cli-provider/errors.d.ts +5 -0
- package/lib/agent-cli-provider/errors.d.ts.map +1 -0
- package/lib/agent-cli-provider/errors.js +115 -0
- package/lib/agent-cli-provider/errors.js.map +1 -0
- package/lib/agent-cli-provider/executable.d.ts +3 -0
- package/lib/agent-cli-provider/executable.d.ts.map +1 -0
- package/lib/agent-cli-provider/executable.js +24 -0
- package/lib/agent-cli-provider/executable.js.map +1 -0
- package/lib/agent-cli-provider/index.d.ts +8 -0
- package/lib/agent-cli-provider/index.d.ts.map +1 -0
- package/lib/agent-cli-provider/index.js +31 -0
- package/lib/agent-cli-provider/index.js.map +1 -0
- package/lib/agent-cli-provider/invoke-evidence.d.ts +4 -0
- package/lib/agent-cli-provider/invoke-evidence.d.ts.map +1 -0
- package/lib/agent-cli-provider/invoke-evidence.js +17 -0
- package/lib/agent-cli-provider/invoke-evidence.js.map +1 -0
- package/lib/agent-cli-provider/json.d.ts +16 -0
- package/lib/agent-cli-provider/json.d.ts.map +1 -0
- package/lib/agent-cli-provider/json.js +110 -0
- package/lib/agent-cli-provider/json.js.map +1 -0
- package/lib/agent-cli-provider/log-prefix.d.ts +2 -0
- package/lib/agent-cli-provider/log-prefix.d.ts.map +1 -0
- package/lib/agent-cli-provider/log-prefix.js +22 -0
- package/lib/agent-cli-provider/log-prefix.js.map +1 -0
- package/lib/agent-cli-provider/process-runner.d.ts +17 -0
- package/lib/agent-cli-provider/process-runner.d.ts.map +1 -0
- package/lib/agent-cli-provider/process-runner.js +89 -0
- package/lib/agent-cli-provider/process-runner.js.map +1 -0
- package/lib/agent-cli-provider/redaction.d.ts +9 -0
- package/lib/agent-cli-provider/redaction.d.ts.map +1 -0
- package/lib/agent-cli-provider/redaction.js +227 -0
- package/lib/agent-cli-provider/redaction.js.map +1 -0
- package/lib/agent-cli-provider/schema.d.ts +5 -0
- package/lib/agent-cli-provider/schema.d.ts.map +1 -0
- package/lib/agent-cli-provider/schema.js +136 -0
- package/lib/agent-cli-provider/schema.js.map +1 -0
- package/lib/agent-cli-provider/single-agent-runtime.d.ts +15 -0
- package/lib/agent-cli-provider/single-agent-runtime.d.ts.map +1 -0
- package/lib/agent-cli-provider/single-agent-runtime.js +228 -0
- package/lib/agent-cli-provider/single-agent-runtime.js.map +1 -0
- package/lib/agent-cli-provider/types.d.ts +194 -0
- package/lib/agent-cli-provider/types.d.ts.map +1 -0
- package/lib/agent-cli-provider/types.js +12 -0
- package/lib/agent-cli-provider/types.js.map +1 -0
- package/lib/completion.js +174 -0
- package/lib/detached-startup.js +220 -0
- package/lib/docker-config.js +220 -0
- package/lib/git-remote-utils.js +165 -0
- package/lib/id-detector.js +55 -0
- package/lib/provider-defaults.js +62 -0
- package/lib/provider-detection.js +59 -0
- package/lib/provider-names.js +57 -0
- package/lib/repo-settings.js +69 -0
- package/lib/settings/claude-auth.js +78 -0
- package/lib/settings.js +542 -0
- package/lib/start-cluster.js +321 -0
- package/lib/stream-json-parser.js +67 -0
- package/package.json +162 -0
- package/scripts/fix-node-pty-permissions.js +75 -0
- package/scripts/record-demo.sh +279 -0
- package/scripts/setup-merge-queue.sh +170 -0
- package/scripts/test-install.sh +40 -0
- package/scripts/validate-templates.js +107 -0
- package/src/agent/agent-config.js +266 -0
- package/src/agent/agent-context-builder.js +189 -0
- package/src/agent/agent-context-sections.js +338 -0
- package/src/agent/agent-context-sources.js +147 -0
- package/src/agent/agent-hook-executor.js +721 -0
- package/src/agent/agent-input-injector.js +141 -0
- package/src/agent/agent-lifecycle.js +982 -0
- package/src/agent/agent-quality-gate-schema.js +93 -0
- package/src/agent/agent-quality-gates-context.js +51 -0
- package/src/agent/agent-stuck-detector.js +256 -0
- package/src/agent/agent-task-executor.js +2028 -0
- package/src/agent/agent-trigger-evaluator.js +67 -0
- package/src/agent/context-metrics.js +160 -0
- package/src/agent/context-pack-builder.js +367 -0
- package/src/agent/context-replay-policy.js +51 -0
- package/src/agent/guidance-queue.js +77 -0
- package/src/agent/output-extraction.js +367 -0
- package/src/agent/output-reformatter.js +175 -0
- package/src/agent/pr-verification.js +653 -0
- package/src/agent/rate-limit-backoff.js +82 -0
- package/src/agent/schema-utils.js +146 -0
- package/src/agent/validation-platform.js +35 -0
- package/src/agent-cli-provider/adapters/claude-parser.ts +133 -0
- package/src/agent-cli-provider/adapters/claude-recovery.ts +203 -0
- package/src/agent-cli-provider/adapters/claude.ts +247 -0
- package/src/agent-cli-provider/adapters/codex-parser.ts +211 -0
- package/src/agent-cli-provider/adapters/codex.ts +217 -0
- package/src/agent-cli-provider/adapters/common.ts +124 -0
- package/src/agent-cli-provider/adapters/gemini.ts +243 -0
- package/src/agent-cli-provider/adapters/index.ts +126 -0
- package/src/agent-cli-provider/adapters/opencode.ts +286 -0
- package/src/agent-cli-provider/contract-actions.ts +150 -0
- package/src/agent-cli-provider/contract-env.ts +111 -0
- package/src/agent-cli-provider/contract-envelope.ts +110 -0
- package/src/agent-cli-provider/contract-errors.ts +66 -0
- package/src/agent-cli-provider/contract-fallback.ts +121 -0
- package/src/agent-cli-provider/contract-invoke.ts +104 -0
- package/src/agent-cli-provider/contract-options.ts +173 -0
- package/src/agent-cli-provider/contract-parse.ts +94 -0
- package/src/agent-cli-provider/contract-support.ts +167 -0
- package/src/agent-cli-provider/contract.ts +56 -0
- package/src/agent-cli-provider/env-safety.ts +82 -0
- package/src/agent-cli-provider/errors.ts +122 -0
- package/src/agent-cli-provider/executable.ts +24 -0
- package/src/agent-cli-provider/index.ts +83 -0
- package/src/agent-cli-provider/invoke-evidence.ts +18 -0
- package/src/agent-cli-provider/json.ts +114 -0
- package/src/agent-cli-provider/log-prefix.ts +20 -0
- package/src/agent-cli-provider/process-runner.ts +145 -0
- package/src/agent-cli-provider/redaction.ts +282 -0
- package/src/agent-cli-provider/schema.ts +115 -0
- package/src/agent-cli-provider/single-agent-runtime.ts +311 -0
- package/src/agent-cli-provider/types.ts +237 -0
- package/src/agent-wrapper.js +615 -0
- package/src/agents/git-pusher-template.js +705 -0
- package/src/attach/attach-client.js +438 -0
- package/src/attach/attach-server.js +543 -0
- package/src/attach/index.js +37 -0
- package/src/attach/protocol.js +220 -0
- package/src/attach/ring-buffer.js +121 -0
- package/src/attach/send-input.js +88 -0
- package/src/attach/socket-discovery.js +267 -0
- package/src/claude-task-runner.js +661 -0
- package/src/config-router.js +89 -0
- package/src/config-validator.js +2202 -0
- package/src/copy-worker.js +43 -0
- package/src/guidance-topics.js +10 -0
- package/src/input-helpers.js +65 -0
- package/src/isolation-manager.js +1734 -0
- package/src/issue-providers/README.md +305 -0
- package/src/issue-providers/azure-devops-provider.js +307 -0
- package/src/issue-providers/base-provider.js +232 -0
- package/src/issue-providers/github-provider.js +210 -0
- package/src/issue-providers/gitlab-provider.js +262 -0
- package/src/issue-providers/index.js +196 -0
- package/src/issue-providers/jira-provider.js +260 -0
- package/src/ledger.js +692 -0
- package/src/lib/gc.js +232 -0
- package/src/lib/safe-exec.js +88 -0
- package/src/logic-engine.js +201 -0
- package/src/message-buffer.js +81 -0
- package/src/message-bus-bridge.js +144 -0
- package/src/message-bus.js +256 -0
- package/src/name-generator.js +232 -0
- package/src/orchestrator.js +3924 -0
- package/src/preflight.js +712 -0
- package/src/process-metrics.js +608 -0
- package/src/providers/anthropic/index.js +3 -0
- package/src/providers/base-provider.js +355 -0
- package/src/providers/capabilities.js +60 -0
- package/src/providers/google/index.js +3 -0
- package/src/providers/index.js +293 -0
- package/src/providers/openai/index.js +3 -0
- package/src/providers/opencode/index.js +3 -0
- package/src/quality-gates.js +143 -0
- package/src/schemas/sub-cluster.js +208 -0
- package/src/state-snapshot.js +398 -0
- package/src/state-snapshotter.js +142 -0
- package/src/status-footer.js +1026 -0
- package/src/sub-cluster-wrapper.js +693 -0
- package/src/task-runner.js +30 -0
- package/src/template-resolver.js +425 -0
- package/src/template-validation/index.js +338 -0
- package/src/template-validation/simulate-consensus-gates.js +324 -0
- package/src/template-validation/simulate-random-topology.js +541 -0
- package/src/template-validation/simulate-two-stage-validation.js +270 -0
- package/src/worktree-claude-config.js +135 -0
- package/src/worktree-tooling-env.js +150 -0
- package/task-lib/attachable-watcher.js +381 -0
- package/task-lib/commands/clean.js +50 -0
- package/task-lib/commands/episodes.js +105 -0
- package/task-lib/commands/get-log-path.js +23 -0
- package/task-lib/commands/kill.js +32 -0
- package/task-lib/commands/list.js +105 -0
- package/task-lib/commands/logs.js +439 -0
- package/task-lib/commands/resume.js +42 -0
- package/task-lib/commands/run.js +57 -0
- package/task-lib/commands/schedule.js +105 -0
- package/task-lib/commands/scheduler-cmd.js +96 -0
- package/task-lib/commands/schedules.js +148 -0
- package/task-lib/commands/status.js +44 -0
- package/task-lib/commands/unschedule.js +16 -0
- package/task-lib/completion.js +9 -0
- package/task-lib/config.js +11 -0
- package/task-lib/name-generator.js +230 -0
- package/task-lib/package.json +3 -0
- package/task-lib/provider-helper-runtime.js +29 -0
- package/task-lib/runner.js +190 -0
- package/task-lib/scheduler.js +252 -0
- package/task-lib/store.js +529 -0
- package/task-lib/watcher.js +305 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const Orchestrator = require('../../src/orchestrator');
|
|
3
|
+
const { detectIdType } = require('../../lib/id-detector');
|
|
4
|
+
const { getTask } = require('../../task-lib/store.js');
|
|
5
|
+
const { isProcessRunning } = require('../../task-lib/runner.js');
|
|
6
|
+
const {
|
|
7
|
+
getProcessMetrics,
|
|
8
|
+
isPlatformSupported: metricsPlatformSupported,
|
|
9
|
+
} = require('../../src/process-metrics');
|
|
10
|
+
const {
|
|
11
|
+
analyzeProcessHealth,
|
|
12
|
+
isPlatformSupported: stuckDetectorPlatformSupported,
|
|
13
|
+
} = require('../../src/agent/agent-stuck-detector');
|
|
14
|
+
const { printClusterInspectionHuman, printTaskInspectionHuman } = require('./inspect-render');
|
|
15
|
+
|
|
16
|
+
const DEFAULT_SAMPLE_MS = 1000;
|
|
17
|
+
const TASK_STALE_WARNING_MS = 5 * 60 * 1000;
|
|
18
|
+
|
|
19
|
+
function parseSampleMs(rawValue) {
|
|
20
|
+
const parsed = parseInt(rawValue ?? String(DEFAULT_SAMPLE_MS), 10);
|
|
21
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
22
|
+
throw new Error(`Invalid sample period: ${rawValue}`);
|
|
23
|
+
}
|
|
24
|
+
return parsed;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function safeDate(dateString) {
|
|
28
|
+
const date = new Date(dateString);
|
|
29
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function formatAgeMs(ageMs) {
|
|
33
|
+
if (!Number.isFinite(ageMs) || ageMs < 0) {
|
|
34
|
+
return 'unknown';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const totalSeconds = Math.floor(ageMs / 1000);
|
|
38
|
+
if (totalSeconds < 60) {
|
|
39
|
+
return `${totalSeconds}s`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const totalMinutes = Math.floor(totalSeconds / 60);
|
|
43
|
+
if (totalMinutes < 60) {
|
|
44
|
+
return `${totalMinutes}m`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
48
|
+
const minutes = totalMinutes % 60;
|
|
49
|
+
if (hours < 24) {
|
|
50
|
+
return `${hours}h ${minutes}m`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const days = Math.floor(hours / 24);
|
|
54
|
+
const remainingHours = hours % 24;
|
|
55
|
+
return `${days}d ${remainingHours}h`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function inferActivity(metrics, health) {
|
|
59
|
+
if (!metrics) {
|
|
60
|
+
return 'unknown';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!metrics.exists) {
|
|
64
|
+
return 'not-running';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (health?.isLikelyStuck) {
|
|
68
|
+
return 'likely-stuck';
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (metrics.cpuPercent >= 5) {
|
|
72
|
+
return 'cpu-active';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (metrics.network?.hasActivity) {
|
|
76
|
+
return 'network-active';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (metrics.childCount > 0) {
|
|
80
|
+
return 'child-active';
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (metrics.state === 'R') {
|
|
84
|
+
return 'running';
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return 'idle';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function buildTaskWarnings(task, details) {
|
|
91
|
+
const warnings = [];
|
|
92
|
+
|
|
93
|
+
if (task.status === 'running' && task.pid && !details.processRunning) {
|
|
94
|
+
warnings.push('task store says running but PID is not alive');
|
|
95
|
+
}
|
|
96
|
+
if (task.status === 'running' && task.logFile && !details.logFileExists) {
|
|
97
|
+
warnings.push('task log file missing');
|
|
98
|
+
}
|
|
99
|
+
if (
|
|
100
|
+
task.status === 'running' &&
|
|
101
|
+
details.updatedAgeMs !== null &&
|
|
102
|
+
details.updatedAgeMs > TASK_STALE_WARNING_MS
|
|
103
|
+
) {
|
|
104
|
+
warnings.push(`task record stale for ${formatAgeMs(details.updatedAgeMs)}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return warnings;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function getOptionalPathState(filePath, existsSync) {
|
|
111
|
+
return {
|
|
112
|
+
path: filePath || null,
|
|
113
|
+
exists: Boolean(filePath && existsSync(filePath)),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function buildTaskDetails(task, now, existsSync) {
|
|
118
|
+
const updatedAt = safeDate(task.updatedAt);
|
|
119
|
+
const logFile = getOptionalPathState(task.logFile, existsSync);
|
|
120
|
+
const socketPath = getOptionalPathState(task.socketPath, existsSync);
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
updatedAgeMs: updatedAt ? now - updatedAt.getTime() : null,
|
|
124
|
+
processRunning: task.pid ? isProcessRunning(task.pid) : false,
|
|
125
|
+
logFile,
|
|
126
|
+
socketPath,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function formatUpdatedAgeHuman(updatedAgeMs) {
|
|
131
|
+
return updatedAgeMs === null ? 'unknown' : formatAgeMs(updatedAgeMs);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function buildTaskSummary(task, details) {
|
|
135
|
+
return {
|
|
136
|
+
id: task.id,
|
|
137
|
+
status: task.status,
|
|
138
|
+
pid: task.pid || null,
|
|
139
|
+
exitCode: task.exitCode ?? null,
|
|
140
|
+
error: task.error || null,
|
|
141
|
+
cwd: task.cwd || null,
|
|
142
|
+
sessionId: task.sessionId || null,
|
|
143
|
+
attachable: Boolean(task.attachable),
|
|
144
|
+
socketPath: details.socketPath.path,
|
|
145
|
+
socketPathExists: details.socketPath.exists,
|
|
146
|
+
logFile: details.logFile.path,
|
|
147
|
+
logFileExists: details.logFile.exists,
|
|
148
|
+
createdAt: task.createdAt,
|
|
149
|
+
updatedAt: task.updatedAt,
|
|
150
|
+
updatedAgeMs: details.updatedAgeMs,
|
|
151
|
+
updatedAgeHuman: formatUpdatedAgeHuman(details.updatedAgeMs),
|
|
152
|
+
processRunning: details.processRunning,
|
|
153
|
+
warnings: buildTaskWarnings(task, {
|
|
154
|
+
...details,
|
|
155
|
+
logFileExists: details.logFile.exists,
|
|
156
|
+
socketPathExists: details.socketPath.exists,
|
|
157
|
+
}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function summarizeTaskRecord(task, now = Date.now(), existsSync = fs.existsSync) {
|
|
162
|
+
if (!task) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return buildTaskSummary(task, buildTaskDetails(task, now, existsSync));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async function inspectProcess(pid, sampleMs, options = {}) {
|
|
170
|
+
if (!pid) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const includeHealth = options.includeHealth !== false;
|
|
175
|
+
const metricsPromise = metricsPlatformSupported()
|
|
176
|
+
? getProcessMetrics(pid, { samplePeriodMs: sampleMs })
|
|
177
|
+
: Promise.resolve(null);
|
|
178
|
+
const healthPromise =
|
|
179
|
+
includeHealth && stuckDetectorPlatformSupported()
|
|
180
|
+
? analyzeProcessHealth(pid, sampleMs)
|
|
181
|
+
: Promise.resolve(null);
|
|
182
|
+
|
|
183
|
+
const [metrics, health] = await Promise.all([metricsPromise, healthPromise]);
|
|
184
|
+
return {
|
|
185
|
+
pid,
|
|
186
|
+
metrics,
|
|
187
|
+
health,
|
|
188
|
+
activity: inferActivity(metrics, health),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function inspectAgent(agent, options, deps = {}) {
|
|
193
|
+
const getTaskImpl = deps.getTask || getTask;
|
|
194
|
+
const existsSync = deps.existsSync || fs.existsSync;
|
|
195
|
+
|
|
196
|
+
const process = await inspectProcess(agent.pid, options.sampleMs);
|
|
197
|
+
const task = agent.currentTaskId
|
|
198
|
+
? summarizeTaskRecord(getTaskImpl(agent.currentTaskId), Date.now(), existsSync)
|
|
199
|
+
: null;
|
|
200
|
+
|
|
201
|
+
const warnings = [];
|
|
202
|
+
if (agent.currentTask && !agent.currentTaskId) {
|
|
203
|
+
warnings.push('agent reports running task but currentTaskId is missing');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return {
|
|
207
|
+
...agent,
|
|
208
|
+
process,
|
|
209
|
+
task,
|
|
210
|
+
warnings,
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function buildClusterInspection(clusterId, options = {}, deps = {}) {
|
|
215
|
+
const sampleMs = parseSampleMs(options.sampleMs);
|
|
216
|
+
const orchestrator =
|
|
217
|
+
deps.orchestrator ||
|
|
218
|
+
(deps.createOrchestrator
|
|
219
|
+
? await deps.createOrchestrator()
|
|
220
|
+
: await Orchestrator.create({ quiet: true }));
|
|
221
|
+
|
|
222
|
+
const status = deps.status || orchestrator.getStatus(clusterId);
|
|
223
|
+
const clusterProcess = await inspectProcess(status.pid, sampleMs, { includeHealth: false });
|
|
224
|
+
const agents = await Promise.all(
|
|
225
|
+
status.agents.map((agent) => inspectAgent(agent, { sampleMs }, deps))
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
return {
|
|
229
|
+
type: 'cluster',
|
|
230
|
+
id: clusterId,
|
|
231
|
+
sampleMs,
|
|
232
|
+
inspectedAt: new Date().toISOString(),
|
|
233
|
+
cluster: status,
|
|
234
|
+
process: clusterProcess,
|
|
235
|
+
agents,
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
async function buildTaskInspection(taskId, options = {}, deps = {}) {
|
|
240
|
+
const sampleMs = parseSampleMs(options.sampleMs);
|
|
241
|
+
const getTaskImpl = deps.getTask || getTask;
|
|
242
|
+
const existsSync = deps.existsSync || fs.existsSync;
|
|
243
|
+
const task = getTaskImpl(taskId);
|
|
244
|
+
|
|
245
|
+
if (!task) {
|
|
246
|
+
throw new Error(`Task ${taskId} not found`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
type: 'task',
|
|
251
|
+
id: taskId,
|
|
252
|
+
sampleMs,
|
|
253
|
+
inspectedAt: new Date().toISOString(),
|
|
254
|
+
task: summarizeTaskRecord(task, Date.now(), existsSync),
|
|
255
|
+
process: await inspectProcess(task.pid, sampleMs),
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async function runInspectCommand(id, options = {}, deps = {}) {
|
|
260
|
+
const type = deps.detectIdType ? deps.detectIdType(id) : detectIdType(id);
|
|
261
|
+
|
|
262
|
+
if (!type) {
|
|
263
|
+
throw new Error(`ID not found: ${id}`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const inspection =
|
|
267
|
+
type === 'cluster'
|
|
268
|
+
? await buildClusterInspection(id, options, deps)
|
|
269
|
+
: await buildTaskInspection(id, options, deps);
|
|
270
|
+
|
|
271
|
+
if (options.json) {
|
|
272
|
+
console.log(JSON.stringify(inspection, null, 2));
|
|
273
|
+
return inspection;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (inspection.type === 'cluster') {
|
|
277
|
+
printClusterInspectionHuman(inspection);
|
|
278
|
+
} else {
|
|
279
|
+
printTaskInspectionHuman(inspection);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return inspection;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
module.exports = {
|
|
286
|
+
DEFAULT_SAMPLE_MS,
|
|
287
|
+
TASK_STALE_WARNING_MS,
|
|
288
|
+
buildClusterInspection,
|
|
289
|
+
buildTaskInspection,
|
|
290
|
+
inferActivity,
|
|
291
|
+
parseSampleMs,
|
|
292
|
+
runInspectCommand,
|
|
293
|
+
summarizeTaskRecord,
|
|
294
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
const readline = require('readline');
|
|
2
|
+
const { loadSettings, saveSettings } = require('../../lib/settings');
|
|
3
|
+
const { VALID_PROVIDERS, normalizeProviderName } = require('../../lib/provider-names');
|
|
4
|
+
const { detectProviders, getProvider } = require('../../src/providers');
|
|
5
|
+
|
|
6
|
+
function question(rl, prompt) {
|
|
7
|
+
return new Promise((resolve) => {
|
|
8
|
+
rl.question(prompt, (answer) => resolve(answer.trim()));
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async function providersCommand() {
|
|
13
|
+
const detected = await detectProviders();
|
|
14
|
+
const settings = loadSettings();
|
|
15
|
+
|
|
16
|
+
console.log('\nProvider Status Default Level Model CLI Path');
|
|
17
|
+
console.log('─'.repeat(70));
|
|
18
|
+
|
|
19
|
+
for (const [name, status] of Object.entries(detected)) {
|
|
20
|
+
const provider = getProvider(name);
|
|
21
|
+
const statusIcon = status.available ? '✓ found' : '✗ not found';
|
|
22
|
+
const providerSettings = settings.providerSettings?.[name] || {};
|
|
23
|
+
const defaultLevel = providerSettings.defaultLevel || provider.getDefaultLevel();
|
|
24
|
+
const levelOverrides = providerSettings.levelOverrides || {};
|
|
25
|
+
const modelSpec = provider.resolveModelSpec(defaultLevel, levelOverrides);
|
|
26
|
+
const modelLabel = modelSpec?.model || '-';
|
|
27
|
+
const cliPath = status.available ? await provider.getCliPath() : '-';
|
|
28
|
+
const isDefault = settings.defaultProvider === name ? ' (default)' : '';
|
|
29
|
+
|
|
30
|
+
console.log(
|
|
31
|
+
`${provider.displayName.padEnd(12)} ${statusIcon.padEnd(12)} ${defaultLevel.padEnd(
|
|
32
|
+
14
|
|
33
|
+
)} ${modelLabel.padEnd(16)} ${cliPath}${isDefault}`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
console.log('\nCommands:');
|
|
38
|
+
console.log(' zeroshot providers set-default <provider> Set default provider');
|
|
39
|
+
console.log(' zeroshot providers setup <provider> Configure a provider');
|
|
40
|
+
console.log(
|
|
41
|
+
'\nNote: Authentication is managed by each CLI; zeroshot does not validate login or API keys.'
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function setDefaultCommand(args) {
|
|
46
|
+
const provider = normalizeProviderName(args[0]);
|
|
47
|
+
if (!VALID_PROVIDERS.includes(provider)) {
|
|
48
|
+
console.error(`Invalid provider: ${args[0]}`);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const settings = loadSettings();
|
|
53
|
+
settings.defaultProvider = provider;
|
|
54
|
+
saveSettings(settings);
|
|
55
|
+
|
|
56
|
+
console.log(`Default provider set to: ${provider}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async function setupCommand(args) {
|
|
60
|
+
const provider = normalizeProviderName(args[0]);
|
|
61
|
+
if (!provider) {
|
|
62
|
+
console.error('Provider is required (claude, codex, gemini, opencode)');
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const providerModule = getProvider(provider);
|
|
67
|
+
|
|
68
|
+
console.log(`\n${providerModule.displayName} Setup\n`);
|
|
69
|
+
|
|
70
|
+
const available = await providerModule.isAvailable();
|
|
71
|
+
if (!available) {
|
|
72
|
+
console.log(`✗ ${providerModule.cliCommand} CLI not found`);
|
|
73
|
+
console.log('\nInstall with:');
|
|
74
|
+
console.log(providerModule.getInstallInstructions());
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
console.log(`✓ ${providerModule.cliCommand} CLI found`);
|
|
78
|
+
|
|
79
|
+
console.log('\nAuth is user-managed; run the CLI login flow if needed:');
|
|
80
|
+
console.log(providerModule.getAuthInstructions());
|
|
81
|
+
|
|
82
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const levels = providerModule.getLevelMapping();
|
|
86
|
+
const levelKeys = Object.keys(levels).sort((a, b) => levels[a].rank - levels[b].rank);
|
|
87
|
+
|
|
88
|
+
console.log('\nAvailable levels (cheapest to most capable):');
|
|
89
|
+
levelKeys.forEach((level, i) => {
|
|
90
|
+
const spec = levels[level];
|
|
91
|
+
const reasoning = spec.reasoningEffort ? ` (reasoning: ${spec.reasoningEffort})` : '';
|
|
92
|
+
console.log(` ${i + 1}) ${level} -> ${spec.model}${reasoning}`);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const maxIdxRaw = await question(rl, `\nMax level (cost ceiling) [${levelKeys.length}]: `);
|
|
96
|
+
const minIdxRaw = await question(rl, 'Min level (floor) [1]: ');
|
|
97
|
+
const maxIdxNum = Math.min(
|
|
98
|
+
levelKeys.length,
|
|
99
|
+
Math.max(1, parseInt(maxIdxRaw) || levelKeys.length)
|
|
100
|
+
);
|
|
101
|
+
const minIdxNum = Math.min(levelKeys.length, Math.max(1, parseInt(minIdxRaw) || 1));
|
|
102
|
+
const minIdx = Math.min(minIdxNum, maxIdxNum);
|
|
103
|
+
const maxIdx = Math.max(minIdxNum, maxIdxNum);
|
|
104
|
+
|
|
105
|
+
const defaultIdxRaw = await question(
|
|
106
|
+
rl,
|
|
107
|
+
`Default level (between ${minIdx}-${maxIdx}) [${maxIdx}]: `
|
|
108
|
+
);
|
|
109
|
+
const defaultIdxNum = Math.min(maxIdx, Math.max(minIdx, parseInt(defaultIdxRaw) || maxIdx));
|
|
110
|
+
|
|
111
|
+
const levelOverrides = {};
|
|
112
|
+
const wantsOverrides = await question(rl, 'Override models per level? [y/N]: ');
|
|
113
|
+
if (wantsOverrides.toLowerCase() === 'y') {
|
|
114
|
+
const catalog = Object.keys(providerModule.getModelCatalog());
|
|
115
|
+
for (const level of levelKeys) {
|
|
116
|
+
const modelChoice = await question(rl, `Model for ${level} (${catalog.join(', ')}): `);
|
|
117
|
+
if (modelChoice) levelOverrides[level] = { model: modelChoice };
|
|
118
|
+
if (provider !== 'codex') continue;
|
|
119
|
+
const reasoning = await question(rl, `Reasoning for ${level} (low|medium|high|xhigh): `);
|
|
120
|
+
if (reasoning) {
|
|
121
|
+
levelOverrides[level] = {
|
|
122
|
+
...(levelOverrides[level] || {}),
|
|
123
|
+
reasoningEffort: reasoning,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const settings = loadSettings();
|
|
130
|
+
settings.providerSettings = settings.providerSettings || {};
|
|
131
|
+
settings.providerSettings[provider] = {
|
|
132
|
+
maxLevel: levelKeys[maxIdx - 1],
|
|
133
|
+
minLevel: levelKeys[minIdx - 1],
|
|
134
|
+
defaultLevel: levelKeys[defaultIdxNum - 1],
|
|
135
|
+
levelOverrides,
|
|
136
|
+
};
|
|
137
|
+
saveSettings(settings);
|
|
138
|
+
|
|
139
|
+
console.log(`\n✓ ${providerModule.displayName} configured successfully`);
|
|
140
|
+
} finally {
|
|
141
|
+
rl.close();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = {
|
|
146
|
+
providersCommand,
|
|
147
|
+
setDefaultCommand,
|
|
148
|
+
setupCommand,
|
|
149
|
+
};
|