@botbotgo/agent-harness 0.0.475 → 0.0.476
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/README.md +3 -1234
- package/README.zh.md +3 -1191
- package/dist/acp.js +1 -1
- package/dist/api.js +1 -404
- package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
- package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
- package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
- package/dist/cli/chat-interactive.js +25 -244
- package/dist/cli/chat-rendering.js +6 -100
- package/dist/cli/chat-stream.js +23 -512
- package/dist/cli/chat-ui.js +21 -199
- package/dist/cli/chat-workspace.js +2 -210
- package/dist/cli/main.js +21 -428
- package/dist/cli/managed-service-commands.js +9 -63
- package/dist/cli/managed-service.js +2 -137
- package/dist/cli/options-init-chat.js +1 -108
- package/dist/cli/options-runtime.js +1 -158
- package/dist/cli/options-serve.js +1 -282
- package/dist/cli/options.js +2 -19
- package/dist/cli/process-guards.js +1 -139
- package/dist/cli/request-tree.js +7 -296
- package/dist/cli/runtime-commands.js +12 -258
- package/dist/cli/runtime-output.js +16 -155
- package/dist/cli/server-commands.js +16 -270
- package/dist/cli/workspace.js +1 -67
- package/dist/cli.js +1 -7
- package/dist/client/acp.js +1 -1
- package/dist/client/in-process.js +1 -67
- package/dist/client/index.js +1 -2
- package/dist/client/types.js +0 -1
- package/dist/client.js +1 -1
- package/dist/contracts/core.js +1 -1
- package/dist/contracts/runtime-evaluation.js +0 -1
- package/dist/contracts/runtime-memory.js +0 -1
- package/dist/contracts/runtime-observability.js +0 -1
- package/dist/contracts/runtime-requests.js +0 -1
- package/dist/contracts/runtime-scheduling.js +0 -1
- package/dist/contracts/runtime.js +1 -27
- package/dist/contracts/types.js +1 -3
- package/dist/contracts/workspace.js +0 -1
- package/dist/flow/build-flow-graph.js +1 -50
- package/dist/flow/export-mermaid.js +2 -464
- package/dist/flow/export-sequence-mermaid.js +2 -325
- package/dist/flow/flow-graph-normalization.js +1 -214
- package/dist/flow/flow-graph-runtime.js +1 -107
- package/dist/flow/flow-graph-upstream.js +1 -494
- package/dist/flow/index.js +1 -3
- package/dist/flow/types.js +0 -1
- package/dist/index.js +1 -5
- package/dist/init-project.js +1 -1
- package/dist/knowledge/config.js +1 -32
- package/dist/knowledge/contracts.js +0 -1
- package/dist/knowledge/index.js +1 -2
- package/dist/knowledge/module.js +12 -909
- package/dist/knowledge/procedural/config.js +1 -125
- package/dist/knowledge/procedural/index.js +1 -2
- package/dist/knowledge/procedural/manager.js +9 -345
- package/dist/mcp.js +1 -2
- package/dist/package-version.d.ts +1 -1
- package/dist/package-version.js +1 -2
- package/dist/persistence/file-store.js +3 -758
- package/dist/persistence/sqlite-request-context-store.js +5 -54
- package/dist/persistence/sqlite-request-queue-store.js +10 -108
- package/dist/persistence/sqlite-runtime.js +1 -86
- package/dist/persistence/sqlite-store.js +62 -810
- package/dist/persistence/types.js +0 -1
- package/dist/projections/presentation.js +37 -206
- package/dist/projections/request-events.js +2 -502
- package/dist/projections/upstream-events.js +1 -201
- package/dist/protocol/a2a/http-discovery.js +1 -178
- package/dist/protocol/a2a/http-rpc.js +6 -622
- package/dist/protocol/a2a/http.js +1 -138
- package/dist/protocol/a2a/task-state.js +3 -317
- package/dist/protocol/acp/client.js +8 -294
- package/dist/protocol/acp/harness-client.js +1 -218
- package/dist/protocol/acp/http.js +5 -130
- package/dist/protocol/acp/server.js +1 -310
- package/dist/protocol/acp/stdio.js +2 -69
- package/dist/protocol/ag-ui/http.js +3 -378
- package/dist/protocol/mcp/server.js +1 -428
- package/dist/resource/backend/workspace-scoped-backend.js +1 -319
- package/dist/resource/isolation.js +1 -237
- package/dist/resource/mcp/tool-support.js +3 -296
- package/dist/resource/mcp-tool-support.js +1 -2
- package/dist/resource/providers/resource-provider.js +1 -215
- package/dist/resource/resource-impl.js +1 -3
- package/dist/resource/resource-types.js +0 -1
- package/dist/resource/resource.js +1 -1
- package/dist/resource/sources.js +1 -247
- package/dist/resource/tools/function-tool-resolver.js +2 -272
- package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
- package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
- package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
- package/dist/runtime/adapter/flow/execution-context.js +1 -71
- package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
- package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
- package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
- package/dist/runtime/adapter/invocation-result.js +2 -473
- package/dist/runtime/adapter/local-tool-invocation.js +6 -638
- package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
- package/dist/runtime/adapter/middleware-assembly.js +5 -477
- package/dist/runtime/adapter/model/invocation-request.js +3 -183
- package/dist/runtime/adapter/model/message-assembly.js +1 -28
- package/dist/runtime/adapter/model/model-providers.js +23 -1115
- package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
- package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
- package/dist/runtime/adapter/resilience.js +1 -104
- package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
- package/dist/runtime/adapter/runtime-shell.js +5 -166
- package/dist/runtime/adapter/stream-event-projection.js +2 -622
- package/dist/runtime/adapter/stream-text-consumption.js +1 -18
- package/dist/runtime/adapter/terminal-status.js +2 -67
- package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
- package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
- package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
- package/dist/runtime/adapter/tool/provider-tool.js +1 -25
- package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
- package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
- package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
- package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
- package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
- package/dist/runtime/adapter/tool/tool-replay.js +1 -37
- package/dist/runtime/adapter/tool-resolution.js +1 -86
- package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
- package/dist/runtime/agent-runtime-adapter.js +60 -2338
- package/dist/runtime/agent-runtime-assembly.js +7 -249
- package/dist/runtime/env/runtime-env.js +1 -62
- package/dist/runtime/harness/background-runtime.js +1 -8
- package/dist/runtime/harness/bindings.js +1 -58
- package/dist/runtime/harness/events/event-bus.js +1 -16
- package/dist/runtime/harness/events/event-sink.js +1 -61
- package/dist/runtime/harness/events/events.js +1 -80
- package/dist/runtime/harness/events/listener-runtime.js +1 -13
- package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
- package/dist/runtime/harness/events/streaming.js +1 -100
- package/dist/runtime/harness/events/timeline.js +1 -52
- package/dist/runtime/harness/public-shapes.js +1 -186
- package/dist/runtime/harness/run/artifact-paths.js +1 -15
- package/dist/runtime/harness/run/governance.js +1 -295
- package/dist/runtime/harness/run/helpers.js +1 -71
- package/dist/runtime/harness/run/inspection.js +1 -409
- package/dist/runtime/harness/run/operator-overview.js +1 -80
- package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
- package/dist/runtime/harness/run/recovery.js +1 -162
- package/dist/runtime/harness/run/resources.js +1 -60
- package/dist/runtime/harness/run/resume.js +1 -56
- package/dist/runtime/harness/run/routing.js +1 -48
- package/dist/runtime/harness/run/run-lifecycle.js +1 -66
- package/dist/runtime/harness/run/run-operations.js +1 -217
- package/dist/runtime/harness/run/run-queue.js +1 -43
- package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
- package/dist/runtime/harness/run/session-records.js +1 -97
- package/dist/runtime/harness/run/start-run.js +1 -120
- package/dist/runtime/harness/run/startup-runtime.js +1 -69
- package/dist/runtime/harness/run/stream-run.js +8 -1418
- package/dist/runtime/harness/run/surface-semantics.js +1 -79
- package/dist/runtime/harness/runtime-defaults.js +1 -39
- package/dist/runtime/harness/system/boundary-analysis.js +1 -234
- package/dist/runtime/harness/system/health-monitor.js +1 -258
- package/dist/runtime/harness/system/inventory.js +1 -129
- package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
- package/dist/runtime/harness/system/policy-engine.js +1 -175
- package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
- package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
- package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
- package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
- package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
- package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
- package/dist/runtime/harness/system/session-memory-sync.js +3 -113
- package/dist/runtime/harness/system/skill-requirements.js +1 -112
- package/dist/runtime/harness/system/store.js +9 -365
- package/dist/runtime/harness/tool-gateway/index.js +1 -2
- package/dist/runtime/harness/tool-gateway/policy.js +1 -45
- package/dist/runtime/harness/tool-gateway/validation.js +1 -176
- package/dist/runtime/harness/tool-schema.js +1 -3
- package/dist/runtime/harness.js +3 -1490
- package/dist/runtime/index.js +1 -3
- package/dist/runtime/layout/runtime-layout.js +1 -31
- package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
- package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
- package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
- package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
- package/dist/runtime/parsing/output-content.js +10 -550
- package/dist/runtime/parsing/output-parsing.js +1 -4
- package/dist/runtime/parsing/output-recovery.js +3 -213
- package/dist/runtime/parsing/output-tool-args.js +7 -663
- package/dist/runtime/parsing/stream-event-parsing.js +3 -362
- package/dist/runtime/prompts/runtime-prompts.js +4 -73
- package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
- package/dist/runtime/skills/skill-metadata.js +1 -197
- package/dist/runtime/startup-tracing.js +2 -37
- package/dist/runtime/support/compiled-binding.js +1 -290
- package/dist/runtime/support/embedding-models.js +1 -118
- package/dist/runtime/support/harness-support.js +5 -137
- package/dist/runtime/support/llamaindex.js +1 -108
- package/dist/runtime/support/runtime-adapter-options.js +1 -29
- package/dist/runtime/support/runtime-factories.js +1 -51
- package/dist/runtime/support/vector-stores.js +9 -270
- package/dist/scaffold/init-project.js +54 -233
- package/dist/tooling/extensions.js +1 -311
- package/dist/tooling/module-loader.js +1 -55
- package/dist/tools.js +1 -176
- package/dist/utils/agent-display.js +1 -18
- package/dist/utils/bundled-text.js +4 -39
- package/dist/utils/compiled-binding.js +1 -33
- package/dist/utils/fs.js +2 -45
- package/dist/utils/id.js +1 -9
- package/dist/utils/message-content.js +1 -30
- package/dist/utils/object.js +1 -6
- package/dist/workspace/agent-binding-compiler.js +3 -613
- package/dist/workspace/compile.js +1 -472
- package/dist/workspace/framework-contract-validation.js +2 -322
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/object-loader-paths.js +1 -71
- package/dist/workspace/object-loader-readers.js +1 -187
- package/dist/workspace/object-loader.js +1 -754
- package/dist/workspace/resource-compilers.js +1 -374
- package/dist/workspace/support/agent-capabilities.js +1 -37
- package/dist/workspace/support/agent-execution-config.js +1 -44
- package/dist/workspace/support/discovery.js +1 -147
- package/dist/workspace/support/source-collectors.js +1 -30
- package/dist/workspace/support/source-protocols.js +2 -192
- package/dist/workspace/support/workspace-ref-utils.js +1 -362
- package/dist/workspace/tool-hydration.js +1 -280
- package/dist/workspace/validate.js +1 -99
- package/dist/workspace/yaml-object-reader.js +1 -285
- package/package.json +7 -3
package/dist/cli/request-tree.js
CHANGED
|
@@ -1,296 +1,7 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
function ellipsizeChatId(value, maxChars) {
|
|
10
|
-
if (value.length <= maxChars) {
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
if (maxChars <= 1) {
|
|
14
|
-
return "…";
|
|
15
|
-
}
|
|
16
|
-
return `${value.slice(0, maxChars - 1)}…`;
|
|
17
|
-
}
|
|
18
|
-
function formatTreeBranch(isLast) {
|
|
19
|
-
return isLast ? "└─" : "├─";
|
|
20
|
-
}
|
|
21
|
-
function formatTreeIndent(ancestorLast) {
|
|
22
|
-
return ancestorLast ? " " : "│ ";
|
|
23
|
-
}
|
|
24
|
-
function applyAnsi(text, code, enabled) {
|
|
25
|
-
if (!enabled) {
|
|
26
|
-
return text;
|
|
27
|
-
}
|
|
28
|
-
return `\x1b[${code}m${text}\x1b[0m`;
|
|
29
|
-
}
|
|
30
|
-
function renderRequestStateBadge(state, color) {
|
|
31
|
-
if (state === "completed") {
|
|
32
|
-
return color ? `\x1b[32;1m✔ DONE\x1b[0m` : "✔ DONE";
|
|
33
|
-
}
|
|
34
|
-
if (state === "running") {
|
|
35
|
-
return color ? `\x1b[36;1m▶ RUNNING\x1b[0m` : "▶ RUNNING";
|
|
36
|
-
}
|
|
37
|
-
if (state === "waiting" || state === "waiting_for_approval") {
|
|
38
|
-
return color ? `\x1b[33;1m⚠ WAITING\x1b[0m` : "⚠ WAITING";
|
|
39
|
-
}
|
|
40
|
-
if (state === "failed") {
|
|
41
|
-
return color ? `\x1b[31;1m✘ FAILED\x1b[0m` : "✘ FAILED";
|
|
42
|
-
}
|
|
43
|
-
if (state === "cancelled") {
|
|
44
|
-
return color ? `\x1b[31m○ CANCELLED\x1b[0m` : "○ CANCELLED";
|
|
45
|
-
}
|
|
46
|
-
if (state === "queued") {
|
|
47
|
-
return color ? `\x1b[38;5;242m· QUEUED\x1b[0m` : "· QUEUED";
|
|
48
|
-
}
|
|
49
|
-
return color ? `\x1b[37m${state.toUpperCase()}\x1b[0m` : state.toUpperCase();
|
|
50
|
-
}
|
|
51
|
-
function summarizeRequestPlan(snapshot) {
|
|
52
|
-
const summary = snapshot.plan.summary;
|
|
53
|
-
const eventCount = flattenRequestExecutionSteps(snapshot).length;
|
|
54
|
-
const parts = [
|
|
55
|
-
`${summary.total} todo${summary.total === 1 ? "" : "s"}`,
|
|
56
|
-
summary.inProgress > 0 ? `${summary.inProgress} active` : undefined,
|
|
57
|
-
summary.completed > 0 ? `${summary.completed} done` : undefined,
|
|
58
|
-
summary.failed > 0 ? `${summary.failed} failed` : undefined,
|
|
59
|
-
eventCount > 0 ? `${eventCount} event${eventCount === 1 ? "" : "s"}` : undefined,
|
|
60
|
-
].filter((part) => typeof part === "string");
|
|
61
|
-
return parts.join(" · ");
|
|
62
|
-
}
|
|
63
|
-
function formatCompactClockTime(value) {
|
|
64
|
-
const date = new Date(value);
|
|
65
|
-
if (Number.isNaN(date.getTime())) {
|
|
66
|
-
return value;
|
|
67
|
-
}
|
|
68
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
69
|
-
hour12: false,
|
|
70
|
-
hour: "2-digit",
|
|
71
|
-
minute: "2-digit",
|
|
72
|
-
second: "2-digit",
|
|
73
|
-
}).format(date);
|
|
74
|
-
}
|
|
75
|
-
function renderTimeRange(startedAt, endedAt, detail, color) {
|
|
76
|
-
if (!startedAt && !endedAt) {
|
|
77
|
-
return "";
|
|
78
|
-
}
|
|
79
|
-
const from = startedAt ? formatCompactClockTime(startedAt) : "?";
|
|
80
|
-
const to = endedAt ? formatCompactClockTime(endedAt) : "now";
|
|
81
|
-
const durationMs = typeof detail?.durationMs === "number" ? detail.durationMs : undefined;
|
|
82
|
-
const durationLabel = durationMs !== undefined
|
|
83
|
-
? ` · ${(durationMs / 1000).toFixed(durationMs >= 10_000 ? 0 : durationMs >= 1_000 ? 1 : 3)}s`
|
|
84
|
-
: "";
|
|
85
|
-
return ` ${applyAnsi(`[${from} -> ${to}${durationLabel}]`, "2", color)}`;
|
|
86
|
-
}
|
|
87
|
-
function readStepSkillNames(step) {
|
|
88
|
-
const value = step.detail?.skillNames;
|
|
89
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === "string" && item.trim().length > 0) : [];
|
|
90
|
-
}
|
|
91
|
-
function buildRequestStepEventKey(step) {
|
|
92
|
-
return `${step.kind}:${step.id}`;
|
|
93
|
-
}
|
|
94
|
-
function resolveEventTimestamp(step) {
|
|
95
|
-
return step.occurredAt ?? step.endedAt ?? step.startedAt;
|
|
96
|
-
}
|
|
97
|
-
function summarizeRequestStepDetail(step, displayName, color) {
|
|
98
|
-
if (step.kind === "memory" && step.detail?.source === "runtime-durable-memory") {
|
|
99
|
-
const count = typeof step.detail.count === "number" ? step.detail.count : undefined;
|
|
100
|
-
const scopes = Array.isArray(step.detail.scopes)
|
|
101
|
-
? step.detail.scopes.filter((item) => typeof item === "string" && item.trim().length > 0)
|
|
102
|
-
: [];
|
|
103
|
-
const countLabel = count !== undefined ? `${count} record${count === 1 ? "" : "s"}` : undefined;
|
|
104
|
-
const scopeLabel = scopes.length > 0 ? scopes.join(", ") : undefined;
|
|
105
|
-
const summary = typeof step.detail.summary === "string" ? step.detail.summary.trim() : "";
|
|
106
|
-
const detailLabel = [countLabel, scopeLabel].filter((value) => Boolean(value)).join(" · ");
|
|
107
|
-
if (detailLabel) {
|
|
108
|
-
return ` ${applyAnsi(`(${detailLabel})`, "2", color)}`;
|
|
109
|
-
}
|
|
110
|
-
if (summary && !summary.toLowerCase().includes(displayName.toLowerCase())) {
|
|
111
|
-
const preview = summary.length > 48 ? `${summary.slice(0, 45)}...` : summary;
|
|
112
|
-
return ` ${applyAnsi(`(${preview})`, "2", color)}`;
|
|
113
|
-
}
|
|
114
|
-
return "";
|
|
115
|
-
}
|
|
116
|
-
if (step.ownerAgentId && step.ownerAgentId !== step.agentId) {
|
|
117
|
-
return ` ${applyAnsi(`(from ${step.ownerAgentId})`, "2", color)}`;
|
|
118
|
-
}
|
|
119
|
-
return "";
|
|
120
|
-
}
|
|
121
|
-
function statusIcon(status, color) {
|
|
122
|
-
if (status === "completed" || status === "done")
|
|
123
|
-
return applyAnsi("✔", "32", color);
|
|
124
|
-
if (status === "in_progress" || status === "started")
|
|
125
|
-
return applyAnsi("▶", "36", color);
|
|
126
|
-
if (status === "failed")
|
|
127
|
-
return applyAnsi("✘", "31", color);
|
|
128
|
-
if (status === "cancelled")
|
|
129
|
-
return applyAnsi("○", "31", color);
|
|
130
|
-
if (status === "pending" || status === "queued")
|
|
131
|
-
return applyAnsi("·", "238", color);
|
|
132
|
-
return applyAnsi("?", "37", color);
|
|
133
|
-
}
|
|
134
|
-
function renderRequestStepLine(step, prefix, isLast, _activeEventId, color = false) {
|
|
135
|
-
const skillNames = step.kind === "skill" ? readStepSkillNames(step) : [];
|
|
136
|
-
const profileDisplayName = step.id.startsWith("profile:") && step.kind === "agent"
|
|
137
|
-
? `${step.name} ${step.action ?? ""}`.trim()
|
|
138
|
-
: undefined;
|
|
139
|
-
const displayName = profileDisplayName
|
|
140
|
-
? profileDisplayName
|
|
141
|
-
: step.kind === "skill" && skillNames.length === 1
|
|
142
|
-
? skillNames[0]
|
|
143
|
-
: step.kind === "skill" && skillNames.length > 1
|
|
144
|
-
? skillNames.join(", ")
|
|
145
|
-
: step.name;
|
|
146
|
-
const icon = STEP_KIND_ICON[step.kind] ?? "·";
|
|
147
|
-
const kindLabel = color
|
|
148
|
-
? `\x1b[38;5;242m${icon} ${step.kind}\x1b[0m`
|
|
149
|
-
: `${icon} ${step.kind}`;
|
|
150
|
-
const stIcon = statusIcon(step.status === "started" ? "in_progress" : step.status, color);
|
|
151
|
-
const nameFormatted = color ? `\x1b[38;5;252m${displayName}\x1b[0m` : displayName;
|
|
152
|
-
const eventTime = resolveEventTimestamp(step);
|
|
153
|
-
const timeLabel = eventTime ? applyAnsi(`[${formatCompactClockTime(eventTime)}]`, "2", color) : applyAnsi("[time?]", "2", color);
|
|
154
|
-
const detailSuffix = summarizeRequestStepDetail(step, displayName, color);
|
|
155
|
-
return `${prefix}${formatTreeBranch(isLast)} ${timeLabel} ${stIcon} ${kindLabel} ${nameFormatted}${detailSuffix}`;
|
|
156
|
-
}
|
|
157
|
-
function isInternalAgentLifecycleStep(step) {
|
|
158
|
-
return step.kind === "agent" && step.id.startsWith("profile:agent:");
|
|
159
|
-
}
|
|
160
|
-
function isVisibleRequestTreeStep(step) {
|
|
161
|
-
if (step.kind === "skill") {
|
|
162
|
-
return false;
|
|
163
|
-
}
|
|
164
|
-
return !isInternalAgentLifecycleStep(step);
|
|
165
|
-
}
|
|
166
|
-
function getVisibleTodoEvents(todo) {
|
|
167
|
-
return todo.events.filter(isVisibleRequestTreeStep);
|
|
168
|
-
}
|
|
169
|
-
function getVisibleRootEvents(snapshot) {
|
|
170
|
-
return snapshot.events.filter(isVisibleRequestTreeStep);
|
|
171
|
-
}
|
|
172
|
-
export function flattenRequestExecutionSteps(snapshot) {
|
|
173
|
-
return [
|
|
174
|
-
...snapshot.plan.items.flatMap((item) => getVisibleTodoEvents(item)),
|
|
175
|
-
...getVisibleRootEvents(snapshot),
|
|
176
|
-
];
|
|
177
|
-
}
|
|
178
|
-
function buildExecutionStepEventKey(step) {
|
|
179
|
-
return [
|
|
180
|
-
buildRequestStepEventKey(step),
|
|
181
|
-
step.status,
|
|
182
|
-
step.startedAt ?? "",
|
|
183
|
-
step.endedAt ?? "",
|
|
184
|
-
].join("|");
|
|
185
|
-
}
|
|
186
|
-
export function renderRequestSnapshotTree(snapshot, color = false, timingSummary) {
|
|
187
|
-
const lines = [];
|
|
188
|
-
const rootEvents = getVisibleRootEvents(snapshot);
|
|
189
|
-
const badge = renderRequestStateBadge(snapshot.state, color);
|
|
190
|
-
const agentLabel = snapshot.agentId
|
|
191
|
-
? (color ? `\x1b[38;5;33m${snapshot.agentId}\x1b[0m` : snapshot.agentId)
|
|
192
|
-
: applyAnsi("unknown", "2", color);
|
|
193
|
-
const headerLabel = color ? `\x1b[1;37mREQUEST\x1b[0m` : "REQUEST";
|
|
194
|
-
lines.push(`${headerLabel} ${badge} ${applyAnsi("agent:", "2", color)}${agentLabel}`);
|
|
195
|
-
const muted = (s) => applyAnsi(s, "2", color);
|
|
196
|
-
lines.push(`├─ ${muted("session")} ${applyAnsi(ellipsizeChatId(snapshot.sessionId, 24), "2", color)}`);
|
|
197
|
-
lines.push(`├─ ${muted("request")} ${applyAnsi(ellipsizeChatId(snapshot.requestId, 24), "2", color)}`);
|
|
198
|
-
const planSummary = summarizeRequestPlan(snapshot);
|
|
199
|
-
const timing = timingSummary ?? "collecting";
|
|
200
|
-
lines.push(`├─ ${muted("plan")} ${applyAnsi(`v${snapshot.plan.version}`, "2", color)} ${muted("·")} ${planSummary ? applyAnsi(planSummary, "2", color) : muted("no tracked work yet")}`);
|
|
201
|
-
lines.push(`├─ ${muted("timing")} ${applyAnsi(timing, "2", color)}`);
|
|
202
|
-
lines.push(`├─ ${muted("todos")}`);
|
|
203
|
-
const planPrefix = `${formatTreeIndent(false)}`;
|
|
204
|
-
if (snapshot.plan.items.length === 0) {
|
|
205
|
-
lines.push(`${planPrefix}└─ ${muted("none yet")}`);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
snapshot.plan.items.forEach((todo, todoIndex) => {
|
|
209
|
-
const todoEvents = getVisibleTodoEvents(todo);
|
|
210
|
-
const todoIsLast = todoIndex === snapshot.plan.items.length - 1 && rootEvents.length === 0 && !snapshot.approval;
|
|
211
|
-
const todoActive = todo.key === snapshot.activeTodoKey ? (color ? ` \x1b[36m●\x1b[0m` : " ●") : "";
|
|
212
|
-
const tIcon = statusIcon(todo.status, color);
|
|
213
|
-
const todoTimeRange = renderTimeRange(todo.startedAt, todo.endedAt, undefined, color);
|
|
214
|
-
const todoContent = color ? `\x1b[38;5;253m${todo.content}\x1b[0m` : todo.content;
|
|
215
|
-
lines.push(`${planPrefix}${formatTreeBranch(todoIsLast)} ${tIcon} ${todoContent}${todoTimeRange}${todoActive}`);
|
|
216
|
-
if (todoEvents.length > 0) {
|
|
217
|
-
const todoEventPrefix = `${planPrefix}${formatTreeIndent(todoIsLast)}`;
|
|
218
|
-
todoEvents.forEach((step, eventIndex) => {
|
|
219
|
-
lines.push(renderRequestStepLine(step, todoEventPrefix, eventIndex === todoEvents.length - 1, snapshot.activeEventId, color));
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
if (rootEvents.length > 0) {
|
|
225
|
-
lines.push(`├─ ${muted("events")}`);
|
|
226
|
-
rootEvents.forEach((step, index) => {
|
|
227
|
-
lines.push(renderRequestStepLine(step, `${formatTreeIndent(false)}`, index === rootEvents.length - 1 && !snapshot.approval, snapshot.activeEventId, color));
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
if (snapshot.approval) {
|
|
231
|
-
const approvalStatus = snapshot.approval.status ?? "pending";
|
|
232
|
-
const approvalColor = approvalStatus === "approved" ? "32" : approvalStatus === "rejected" ? "31" : "33";
|
|
233
|
-
lines.push(`└─ ${color ? `\x1b[33m⚠ approval\x1b[0m` : "⚠ approval"} ${muted("·")} ${snapshot.approval.toolName ?? "unknown-tool"} ${applyAnsi(`(${approvalStatus})`, approvalColor, color)}`);
|
|
234
|
-
}
|
|
235
|
-
return `${lines.join("\n")}\n`;
|
|
236
|
-
}
|
|
237
|
-
export function renderRequestEventContinuation(snapshot, fromIndex, color = false) {
|
|
238
|
-
const eventSteps = flattenRequestExecutionSteps(snapshot).slice(fromIndex);
|
|
239
|
-
if (eventSteps.length === 0) {
|
|
240
|
-
return "";
|
|
241
|
-
}
|
|
242
|
-
const muted = (s) => applyAnsi(s, "2", color);
|
|
243
|
-
const lines = [`${muted("events (continued)")}`];
|
|
244
|
-
eventSteps.forEach((step, index) => {
|
|
245
|
-
lines.push(renderRequestStepLine(step, "", index === eventSteps.length - 1, snapshot.activeEventId, color));
|
|
246
|
-
});
|
|
247
|
-
return `${lines.join("\n")}\n`;
|
|
248
|
-
}
|
|
249
|
-
export function buildTodoContinuationSignature(snapshot) {
|
|
250
|
-
return snapshot.plan.items
|
|
251
|
-
.map((item) => [
|
|
252
|
-
item.id ?? "",
|
|
253
|
-
item.content,
|
|
254
|
-
item.status,
|
|
255
|
-
item.ownerAgentId ?? "",
|
|
256
|
-
item.startedAt ?? "",
|
|
257
|
-
item.endedAt ?? "",
|
|
258
|
-
].join("|"))
|
|
259
|
-
.join(";");
|
|
260
|
-
}
|
|
261
|
-
export function renderRequestTodoContinuation(snapshot, previousSignature, color = false) {
|
|
262
|
-
const nextSignature = buildTodoContinuationSignature(snapshot);
|
|
263
|
-
if (!nextSignature || nextSignature === previousSignature || snapshot.plan.items.length === 0) {
|
|
264
|
-
return "";
|
|
265
|
-
}
|
|
266
|
-
const muted = (s) => applyAnsi(s, "2", color);
|
|
267
|
-
const lines = [`${muted("todos (continued)")}`];
|
|
268
|
-
snapshot.plan.items.forEach((todo, index) => {
|
|
269
|
-
const tIcon = statusIcon(todo.status, color);
|
|
270
|
-
const todoTimeRange = renderTimeRange(todo.startedAt, todo.endedAt, undefined, color);
|
|
271
|
-
const todoContent = color ? `\x1b[38;5;253m${todo.content}\x1b[0m` : todo.content;
|
|
272
|
-
lines.push(`${formatTreeBranch(index === snapshot.plan.items.length - 1)} ${tIcon} ${todoContent}${todoTimeRange}`);
|
|
273
|
-
});
|
|
274
|
-
return `${lines.join("\n")}\n`;
|
|
275
|
-
}
|
|
276
|
-
export function buildTerminalRequestSnapshot(snapshot, result) {
|
|
277
|
-
return {
|
|
278
|
-
...snapshot,
|
|
279
|
-
state: result.state,
|
|
280
|
-
updatedAt: new Date().toISOString(),
|
|
281
|
-
output: result.output,
|
|
282
|
-
activeEventId: undefined,
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
export function summarizeRequestOutput(output, color) {
|
|
286
|
-
const trimmed = output.trim();
|
|
287
|
-
if (!trimmed) {
|
|
288
|
-
return applyAnsi("empty", "2", color);
|
|
289
|
-
}
|
|
290
|
-
const normalized = trimmed.replace(/\s+/g, " ");
|
|
291
|
-
const preview = normalized.length > 72 ? `${normalized.slice(0, 69)}...` : normalized;
|
|
292
|
-
return applyAnsi(preview, "2", color);
|
|
293
|
-
}
|
|
294
|
-
export function buildExecutionStepContinuationKey(step) {
|
|
295
|
-
return buildExecutionStepEventKey(step);
|
|
296
|
-
}
|
|
1
|
+
const j={llm:"\u25C6",tool:"\u2699",skill:"\u2605",agent:"\u25C9",memory:"\u25C8",approval:"\u26A0"};function y(e,n){return e.length<=n?e:n<=1?"\u2026":`${e.slice(0,n-1)}\u2026`}function p(e){return e?"\u2514\u2500":"\u251C\u2500"}function b(e){return e?" ":"\u2502 "}function r(e,n,i){return i?`\x1B[${n}m${e}\x1B[0m`:e}function U(e,n){return e==="completed"?n?"\x1B[32;1m\u2714 DONE\x1B[0m":"\u2714 DONE":e==="running"?n?"\x1B[36;1m\u25B6 RUNNING\x1B[0m":"\u25B6 RUNNING":e==="waiting"||e==="waiting_for_approval"?n?"\x1B[33;1m\u26A0 WAITING\x1B[0m":"\u26A0 WAITING":e==="failed"?n?"\x1B[31;1m\u2718 FAILED\x1B[0m":"\u2718 FAILED":e==="cancelled"?n?"\x1B[31m\u25CB CANCELLED\x1B[0m":"\u25CB CANCELLED":e==="queued"?n?"\x1B[38;5;242m\xB7 QUEUED\x1B[0m":"\xB7 QUEUED":n?`\x1B[37m${e.toUpperCase()}\x1B[0m`:e.toUpperCase()}function _(e){const n=e.plan.summary,i=T(e).length;return[`${n.total} todo${n.total===1?"":"s"}`,n.inProgress>0?`${n.inProgress} active`:void 0,n.completed>0?`${n.completed} done`:void 0,n.failed>0?`${n.failed} failed`:void 0,i>0?`${i} event${i===1?"":"s"}`:void 0].filter(a=>typeof a=="string").join(" \xB7 ")}function v(e){const n=new Date(e);return Number.isNaN(n.getTime())?e:new Intl.DateTimeFormat("en-US",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(n)}function k(e,n,i,t){if(!e&&!n)return"";const a=e?v(e):"?",f=n?v(n):"now",u=typeof i?.durationMs=="number"?i.durationMs:void 0,s=u!==void 0?` \xB7 ${(u/1e3).toFixed(u>=1e4?0:u>=1e3?1:3)}s`:"";return` ${r(`[${a} -> ${f}${s}]`,"2",t)}`}function P(e){const n=e.detail?.skillNames;return Array.isArray(n)?n.filter(i=>typeof i=="string"&&i.trim().length>0):[]}function z(e){return`${e.kind}:${e.id}`}function F(e){return e.occurredAt??e.endedAt??e.startedAt}function K(e,n,i){if(e.kind==="memory"&&e.detail?.source==="runtime-durable-memory"){const t=typeof e.detail.count=="number"?e.detail.count:void 0,a=Array.isArray(e.detail.scopes)?e.detail.scopes.filter(m=>typeof m=="string"&&m.trim().length>0):[],f=t!==void 0?`${t} record${t===1?"":"s"}`:void 0,u=a.length>0?a.join(", "):void 0,s=typeof e.detail.summary=="string"?e.detail.summary.trim():"",d=[f,u].filter(m=>!!m).join(" \xB7 ");if(d)return` ${r(`(${d})`,"2",i)}`;if(s&&!s.toLowerCase().includes(n.toLowerCase())){const m=s.length>48?`${s.slice(0,45)}...`:s;return` ${r(`(${m})`,"2",i)}`}return""}return e.ownerAgentId&&e.ownerAgentId!==e.agentId?` ${r(`(from ${e.ownerAgentId})`,"2",i)}`:""}function x(e,n){return e==="completed"||e==="done"?r("\u2714","32",n):e==="in_progress"||e==="started"?r("\u25B6","36",n):e==="failed"?r("\u2718","31",n):e==="cancelled"?r("\u25CB","31",n):e==="pending"||e==="queued"?r("\xB7","238",n):r("?","37",n)}function E(e,n,i,t,a=!1){const f=e.kind==="skill"?P(e):[],u=e.id.startsWith("profile:")&&e.kind==="agent"?`${e.name} ${e.action??""}`.trim():void 0,s=u||(e.kind==="skill"&&f.length===1?f[0]:e.kind==="skill"&&f.length>1?f.join(", "):e.name),d=j[e.kind]??"\xB7",m=a?`\x1B[38;5;242m${d} ${e.kind}\x1B[0m`:`${d} ${e.kind}`,c=x(e.status==="started"?"in_progress":e.status,a),$=a?`\x1B[38;5;252m${s}\x1B[0m`:s,o=F(e),l=r(o?`[${v(o)}]`:"[time?]","2",a),g=K(e,s,a);return`${n}${p(i)} ${l} ${c} ${m} ${$}${g}`}function O(e){return e.kind==="agent"&&e.id.startsWith("profile:agent:")}function A(e){return e.kind==="skill"?!1:!O(e)}function S(e){return e.events.filter(A)}function N(e){return e.events.filter(A)}function T(e){return[...e.plan.items.flatMap(n=>S(n)),...N(e)]}function G(e){return[z(e),e.status,e.startedAt??"",e.endedAt??""].join("|")}function Q(e,n=!1,i){const t=[],a=N(e),f=U(e.state,n),u=e.agentId?n?`\x1B[38;5;33m${e.agentId}\x1B[0m`:e.agentId:r("unknown","2",n),s=n?"\x1B[1;37mREQUEST\x1B[0m":"REQUEST";t.push(`${s} ${f} ${r("agent:","2",n)}${u}`);const d=o=>r(o,"2",n);t.push(`\u251C\u2500 ${d("session")} ${r(y(e.sessionId,24),"2",n)}`),t.push(`\u251C\u2500 ${d("request")} ${r(y(e.requestId,24),"2",n)}`);const m=_(e),c=i??"collecting";t.push(`\u251C\u2500 ${d("plan")} ${r(`v${e.plan.version}`,"2",n)} ${d("\xB7")} ${m?r(m,"2",n):d("no tracked work yet")}`),t.push(`\u251C\u2500 ${d("timing")} ${r(c,"2",n)}`),t.push(`\u251C\u2500 ${d("todos")}`);const $=`${b(!1)}`;if(e.plan.items.length===0?t.push(`${$}\u2514\u2500 ${d("none yet")}`):e.plan.items.forEach((o,l)=>{const g=S(o),I=l===e.plan.items.length-1&&a.length===0&&!e.approval,h=o.key===e.activeTodoKey?n?" \x1B[36m\u25CF\x1B[0m":" \u25CF":"",R=x(o.status,n),L=k(o.startedAt,o.endedAt,void 0,n),C=n?`\x1B[38;5;253m${o.content}\x1B[0m`:o.content;if(t.push(`${$}${p(I)} ${R} ${C}${L}${h}`),g.length>0){const w=`${$}${b(I)}`;g.forEach((q,D)=>{t.push(E(q,w,D===g.length-1,e.activeEventId,n))})}}),a.length>0&&(t.push(`\u251C\u2500 ${d("events")}`),a.forEach((o,l)=>{t.push(E(o,`${b(!1)}`,l===a.length-1&&!e.approval,e.activeEventId,n))})),e.approval){const o=e.approval.status??"pending",l=o==="approved"?"32":o==="rejected"?"31":"33";t.push(`\u2514\u2500 ${n?"\x1B[33m\u26A0 approval\x1B[0m":"\u26A0 approval"} ${d("\xB7")} ${e.approval.toolName??"unknown-tool"} ${r(`(${o})`,l,n)}`)}return`${t.join(`
|
|
2
|
+
`)}
|
|
3
|
+
`}function W(e,n,i=!1){const t=T(e).slice(n);if(t.length===0)return"";const f=[`${(u=>r(u,"2",i))("events (continued)")}`];return t.forEach((u,s)=>{f.push(E(u,"",s===t.length-1,e.activeEventId,i))}),`${f.join(`
|
|
4
|
+
`)}
|
|
5
|
+
`}function M(e){return e.plan.items.map(n=>[n.id??"",n.content,n.status,n.ownerAgentId??"",n.startedAt??"",n.endedAt??""].join("|")).join(";")}function B(e,n,i=!1){const t=M(e);if(!t||t===n||e.plan.items.length===0)return"";const f=[`${(u=>r(u,"2",i))("todos (continued)")}`];return e.plan.items.forEach((u,s)=>{const d=x(u.status,i),m=k(u.startedAt,u.endedAt,void 0,i),c=i?`\x1B[38;5;253m${u.content}\x1B[0m`:u.content;f.push(`${p(s===e.plan.items.length-1)} ${d} ${c}${m}`)}),`${f.join(`
|
|
6
|
+
`)}
|
|
7
|
+
`}function V(e,n){return{...e,state:n.state,updatedAt:new Date().toISOString(),output:n.output,activeEventId:void 0}}function H(e,n){const i=e.trim();if(!i)return r("empty","2",n);const t=i.replace(/\s+/g," "),a=t.length>72?`${t.slice(0,69)}...`:t;return r(a,"2",n)}function J(e){return G(e)}export{J as buildExecutionStepContinuationKey,V as buildTerminalRequestSnapshot,M as buildTodoContinuationSignature,T as flattenRequestExecutionSteps,W as renderRequestEventContinuation,Q as renderRequestSnapshotTree,B as renderRequestTodoContinuation,H as summarizeRequestOutput};
|
|
@@ -1,258 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
export async function handleRuntimeCommand(subcommandAndArgs, io, deps) {
|
|
14
|
-
const { cwd, stdout, stderr } = io;
|
|
15
|
-
const { createHarness, createClient } = deps;
|
|
16
|
-
const [subcommand, possibleNestedCommand, possibleThirdCommand, ...remainingArgs] = subcommandAndArgs;
|
|
17
|
-
if (!subcommand) {
|
|
18
|
-
stderr(renderUsage());
|
|
19
|
-
return 1;
|
|
20
|
-
}
|
|
21
|
-
if (subcommand === "scheduled-run") {
|
|
22
|
-
const parsed = parseScheduledRunOptions([possibleNestedCommand, possibleThirdCommand, ...remainingArgs].filter((item) => typeof item === "string"));
|
|
23
|
-
if (parsed.error) {
|
|
24
|
-
stderr(`${parsed.error}\n`);
|
|
25
|
-
stderr(renderUsage());
|
|
26
|
-
return 1;
|
|
27
|
-
}
|
|
28
|
-
if (!parsed.scheduleId) {
|
|
29
|
-
stderr("Missing value for --schedule\n");
|
|
30
|
-
stderr(renderUsage());
|
|
31
|
-
return 1;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const workspacePath = resolveValidatedWorkspace(cwd, parsed.workspaceRoot, stderr);
|
|
35
|
-
if (!workspacePath) {
|
|
36
|
-
return 1;
|
|
37
|
-
}
|
|
38
|
-
const runtime = await createHarness(workspacePath);
|
|
39
|
-
try {
|
|
40
|
-
const result = await runtime.runScheduledTask(parsed.scheduleId);
|
|
41
|
-
stdout(`${String(result.output ?? "").trim()}\n`);
|
|
42
|
-
}
|
|
43
|
-
finally {
|
|
44
|
-
await runtime.stop();
|
|
45
|
-
}
|
|
46
|
-
return 0;
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
-
stderr(`${message}\n`);
|
|
51
|
-
return 1;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (subcommand === "export") {
|
|
55
|
-
const exportTarget = possibleNestedCommand;
|
|
56
|
-
const parsed = parseRuntimeExportOptions([possibleThirdCommand, ...remainingArgs].filter((item) => typeof item === "string"));
|
|
57
|
-
if (parsed.error) {
|
|
58
|
-
stderr(`${parsed.error}\n`);
|
|
59
|
-
stderr(renderUsage());
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
if (!parsed.sessionId) {
|
|
63
|
-
stderr("Missing value for --session\n");
|
|
64
|
-
stderr(renderUsage());
|
|
65
|
-
return 1;
|
|
66
|
-
}
|
|
67
|
-
if (exportTarget !== "request" && exportTarget !== "session") {
|
|
68
|
-
stderr(renderUsage());
|
|
69
|
-
return 1;
|
|
70
|
-
}
|
|
71
|
-
if (exportTarget === "request" && !parsed.requestId) {
|
|
72
|
-
stderr("Missing value for --request\n");
|
|
73
|
-
stderr(renderUsage());
|
|
74
|
-
return 1;
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
const workspacePath = resolveValidatedWorkspace(cwd, parsed.workspaceRoot, stderr);
|
|
78
|
-
if (!workspacePath) {
|
|
79
|
-
return 1;
|
|
80
|
-
}
|
|
81
|
-
const runtime = await createHarness(workspacePath);
|
|
82
|
-
try {
|
|
83
|
-
if (exportTarget === "request") {
|
|
84
|
-
const pkg = await runtime.exportRequestPackage({
|
|
85
|
-
sessionId: parsed.sessionId,
|
|
86
|
-
requestId: parsed.requestId,
|
|
87
|
-
includeArtifacts: parsed.includeArtifacts,
|
|
88
|
-
includeArtifactContents: parsed.includeArtifactContents,
|
|
89
|
-
includeRuntimeHealth: parsed.includeRuntimeHealth,
|
|
90
|
-
});
|
|
91
|
-
stdout(renderJson(pkg));
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
const pkg = await runtime.exportSessionPackage({
|
|
95
|
-
sessionId: parsed.sessionId,
|
|
96
|
-
includeArtifacts: parsed.includeArtifacts,
|
|
97
|
-
includeArtifactContents: parsed.includeArtifactContents,
|
|
98
|
-
includeRuntimeHealth: parsed.includeRuntimeHealth,
|
|
99
|
-
});
|
|
100
|
-
stdout(renderJson(pkg));
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
finally {
|
|
104
|
-
await runtime.stop();
|
|
105
|
-
}
|
|
106
|
-
return 0;
|
|
107
|
-
}
|
|
108
|
-
catch (error) {
|
|
109
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
110
|
-
stderr(`${message}\n`);
|
|
111
|
-
return 1;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
const nestedCommand = (subcommand === "approvals" || subcommand === "requests") && possibleNestedCommand
|
|
115
|
-
? possibleNestedCommand
|
|
116
|
-
: undefined;
|
|
117
|
-
const subcommandArgs = nestedCommand
|
|
118
|
-
? [possibleThirdCommand, ...remainingArgs].filter((item) => typeof item === "string")
|
|
119
|
-
: [possibleNestedCommand, possibleThirdCommand, ...remainingArgs].filter((item) => typeof item === "string");
|
|
120
|
-
const parsed = parseRuntimeInspectOptions(subcommandArgs);
|
|
121
|
-
if (parsed.error) {
|
|
122
|
-
stderr(`${parsed.error}\n`);
|
|
123
|
-
stderr(renderUsage());
|
|
124
|
-
return 1;
|
|
125
|
-
}
|
|
126
|
-
try {
|
|
127
|
-
const workspacePath = resolveValidatedWorkspace(cwd, parsed.workspaceRoot, stderr);
|
|
128
|
-
if (!workspacePath) {
|
|
129
|
-
return 1;
|
|
130
|
-
}
|
|
131
|
-
if (subcommand === "boundaries") {
|
|
132
|
-
const runtime = await createHarness(workspacePath);
|
|
133
|
-
try {
|
|
134
|
-
const analysis = runtime.analyzeWorkspaceBoundaries();
|
|
135
|
-
stdout(parsed.json ? renderJson(analysis) : renderBoundaryAnalysis(analysis, workspacePath));
|
|
136
|
-
return analysis.summary.errorCount > 0 ? 2 : 0;
|
|
137
|
-
}
|
|
138
|
-
finally {
|
|
139
|
-
await runtime.stop();
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
const shouldUseClient = subcommand === "health"
|
|
143
|
-
|| subcommand === "overview"
|
|
144
|
-
|| (subcommand === "approvals" && (nestedCommand === "list" || nestedCommand === "watch"))
|
|
145
|
-
|| (subcommand === "requests" && (nestedCommand === "list" || nestedCommand === "tail"));
|
|
146
|
-
if (shouldUseClient && createClient) {
|
|
147
|
-
const client = await createClient(workspacePath);
|
|
148
|
-
try {
|
|
149
|
-
if (subcommand === "health") {
|
|
150
|
-
const snapshot = await client.getHealth();
|
|
151
|
-
stdout(parsed.json ? renderJson(snapshot) : renderHealthSnapshot(snapshot, workspacePath));
|
|
152
|
-
return 0;
|
|
153
|
-
}
|
|
154
|
-
if (subcommand === "overview") {
|
|
155
|
-
const overview = await client.getOperatorOverview({ limit: parsed.limit });
|
|
156
|
-
stdout(parsed.json ? renderJson(overview) : renderOperatorOverview(overview, workspacePath));
|
|
157
|
-
return 0;
|
|
158
|
-
}
|
|
159
|
-
if (subcommand === "approvals" && (nestedCommand === "list" || nestedCommand === "watch")) {
|
|
160
|
-
const renderApprovals = async () => {
|
|
161
|
-
const approvals = await client.listApprovals(parsed.status ? { status: parsed.status } : undefined);
|
|
162
|
-
stdout(parsed.json ? renderJson(approvals) : renderApprovalList(approvals));
|
|
163
|
-
};
|
|
164
|
-
await renderApprovals();
|
|
165
|
-
if (nestedCommand === "watch" && !parsed.once) {
|
|
166
|
-
for (;;) {
|
|
167
|
-
await deps.sleep(parsed.pollMs);
|
|
168
|
-
await renderApprovals();
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
return 0;
|
|
172
|
-
}
|
|
173
|
-
if (subcommand === "requests" && (nestedCommand === "list" || nestedCommand === "tail")) {
|
|
174
|
-
const renderRequests = async () => {
|
|
175
|
-
const requests = await client.listRequests({
|
|
176
|
-
...(parsed.agentId ? { agentId: parsed.agentId } : {}),
|
|
177
|
-
...(parsed.sessionId ? { sessionId: parsed.sessionId } : {}),
|
|
178
|
-
...(parsed.state ? { state: parsed.state } : {}),
|
|
179
|
-
});
|
|
180
|
-
stdout(parsed.json ? renderJson(requests) : renderRequestList(requests));
|
|
181
|
-
};
|
|
182
|
-
await renderRequests();
|
|
183
|
-
if (nestedCommand === "tail" && !parsed.once) {
|
|
184
|
-
for (;;) {
|
|
185
|
-
await deps.sleep(parsed.pollMs);
|
|
186
|
-
await renderRequests();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
return 0;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
finally {
|
|
193
|
-
await client.stop();
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
if (shouldUseClient) {
|
|
197
|
-
const runtime = await createHarness(workspacePath);
|
|
198
|
-
try {
|
|
199
|
-
if (subcommand === "health") {
|
|
200
|
-
const snapshot = await runtime.getHealth();
|
|
201
|
-
stdout(parsed.json ? renderJson(snapshot) : renderHealthSnapshot(snapshot, workspacePath));
|
|
202
|
-
return 0;
|
|
203
|
-
}
|
|
204
|
-
if (subcommand === "overview") {
|
|
205
|
-
const overview = await runtime.getOperatorOverview({ limit: parsed.limit });
|
|
206
|
-
stdout(parsed.json ? renderJson(overview) : renderOperatorOverview(overview, workspacePath));
|
|
207
|
-
return 0;
|
|
208
|
-
}
|
|
209
|
-
if (subcommand === "approvals" && (nestedCommand === "list" || nestedCommand === "watch")) {
|
|
210
|
-
const renderApprovals = async () => {
|
|
211
|
-
const approvals = await runtime.listApprovals(parsed.status ? { status: parsed.status } : undefined);
|
|
212
|
-
stdout(parsed.json ? renderJson(approvals) : renderApprovalList(approvals));
|
|
213
|
-
};
|
|
214
|
-
await renderApprovals();
|
|
215
|
-
if (nestedCommand === "watch" && !parsed.once) {
|
|
216
|
-
for (;;) {
|
|
217
|
-
await deps.sleep(parsed.pollMs);
|
|
218
|
-
await renderApprovals();
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
return 0;
|
|
222
|
-
}
|
|
223
|
-
if (subcommand === "requests" && (nestedCommand === "list" || nestedCommand === "tail")) {
|
|
224
|
-
const renderRequests = async () => {
|
|
225
|
-
const listRequests = runtime.listRequests?.bind(runtime);
|
|
226
|
-
if (!listRequests) {
|
|
227
|
-
throw new Error("Runtime does not support request listing");
|
|
228
|
-
}
|
|
229
|
-
const requests = await listRequests({
|
|
230
|
-
...(parsed.agentId ? { agentId: parsed.agentId } : {}),
|
|
231
|
-
...(parsed.sessionId ? { sessionId: parsed.sessionId } : {}),
|
|
232
|
-
...(parsed.state ? { state: parsed.state } : {}),
|
|
233
|
-
});
|
|
234
|
-
stdout(parsed.json ? renderJson(requests) : renderRequestList(requests));
|
|
235
|
-
};
|
|
236
|
-
await renderRequests();
|
|
237
|
-
if (nestedCommand === "tail" && !parsed.once) {
|
|
238
|
-
for (;;) {
|
|
239
|
-
await deps.sleep(parsed.pollMs);
|
|
240
|
-
await renderRequests();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return 0;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
finally {
|
|
247
|
-
await runtime.stop();
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
stderr(renderUsage());
|
|
251
|
-
return 1;
|
|
252
|
-
}
|
|
253
|
-
catch (error) {
|
|
254
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
255
|
-
stderr(`${message}\n`);
|
|
256
|
-
return 1;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
1
|
+
import{renderApprovalList as k,renderBoundaryAnalysis as H,renderHealthSnapshot as A,renderJson as l,renderOperatorOverview as C,renderRequestList as j}from"./runtime-output.js";import{parseRuntimeExportOptions as S,parseRuntimeInspectOptions as $,parseScheduledRunOptions as M,renderUsage as d}from"./options.js";import{resolveCliWorkspaceRoot as b,validateCliWorkspaceRoot as x}from"./workspace.js";function I(y,m,p){const f=b(y,m),c=x(f,m);if(c){p(`${c}
|
|
2
|
+
`);return}return f}async function T(y,m,p){const{cwd:f,stdout:c,stderr:a}=m,{createHarness:h,createClient:q}=p,[i,w,g,...v]=y;if(!i)return a(d()),1;if(i==="scheduled-run"){const r=M([w,g,...v].filter(n=>typeof n=="string"));if(r.error)return a(`${r.error}
|
|
3
|
+
`),a(d()),1;if(!r.scheduleId)return a(`Missing value for --schedule
|
|
4
|
+
`),a(d()),1;try{const n=I(f,r.workspaceRoot,a);if(!n)return 1;const s=await h(n);try{const e=await s.runScheduledTask(r.scheduleId);c(`${String(e.output??"").trim()}
|
|
5
|
+
`)}finally{await s.stop()}return 0}catch(n){const s=n instanceof Error?n.message:String(n);return a(`${s}
|
|
6
|
+
`),1}}if(i==="export"){const r=w,n=S([g,...v].filter(s=>typeof s=="string"));if(n.error)return a(`${n.error}
|
|
7
|
+
`),a(d()),1;if(!n.sessionId)return a(`Missing value for --session
|
|
8
|
+
`),a(d()),1;if(r!=="request"&&r!=="session")return a(d()),1;if(r==="request"&&!n.requestId)return a(`Missing value for --request
|
|
9
|
+
`),a(d()),1;try{const s=I(f,n.workspaceRoot,a);if(!s)return 1;const e=await h(s);try{if(r==="request"){const u=await e.exportRequestPackage({sessionId:n.sessionId,requestId:n.requestId,includeArtifacts:n.includeArtifacts,includeArtifactContents:n.includeArtifactContents,includeRuntimeHealth:n.includeRuntimeHealth});c(l(u))}else{const u=await e.exportSessionPackage({sessionId:n.sessionId,includeArtifacts:n.includeArtifacts,includeArtifactContents:n.includeArtifactContents,includeRuntimeHealth:n.includeRuntimeHealth});c(l(u))}}finally{await e.stop()}return 0}catch(s){const e=s instanceof Error?s.message:String(s);return a(`${e}
|
|
10
|
+
`),1}}const o=(i==="approvals"||i==="requests")&&w?w:void 0,O=o?[g,...v].filter(r=>typeof r=="string"):[w,g,...v].filter(r=>typeof r=="string"),t=$(O);if(t.error)return a(`${t.error}
|
|
11
|
+
`),a(d()),1;try{const r=I(f,t.workspaceRoot,a);if(!r)return 1;if(i==="boundaries"){const s=await h(r);try{const e=s.analyzeWorkspaceBoundaries();return c(t.json?l(e):H(e,r)),e.summary.errorCount>0?2:0}finally{await s.stop()}}const n=i==="health"||i==="overview"||i==="approvals"&&(o==="list"||o==="watch")||i==="requests"&&(o==="list"||o==="tail");if(n&&q){const s=await q(r);try{if(i==="health"){const e=await s.getHealth();return c(t.json?l(e):A(e,r)),0}if(i==="overview"){const e=await s.getOperatorOverview({limit:t.limit});return c(t.json?l(e):C(e,r)),0}if(i==="approvals"&&(o==="list"||o==="watch")){const e=async()=>{const u=await s.listApprovals(t.status?{status:t.status}:void 0);c(t.json?l(u):k(u))};if(await e(),o==="watch"&&!t.once)for(;;)await p.sleep(t.pollMs),await e();return 0}if(i==="requests"&&(o==="list"||o==="tail")){const e=async()=>{const u=await s.listRequests({...t.agentId?{agentId:t.agentId}:{},...t.sessionId?{sessionId:t.sessionId}:{},...t.state?{state:t.state}:{}});c(t.json?l(u):j(u))};if(await e(),o==="tail"&&!t.once)for(;;)await p.sleep(t.pollMs),await e();return 0}}finally{await s.stop()}}if(n){const s=await h(r);try{if(i==="health"){const e=await s.getHealth();return c(t.json?l(e):A(e,r)),0}if(i==="overview"){const e=await s.getOperatorOverview({limit:t.limit});return c(t.json?l(e):C(e,r)),0}if(i==="approvals"&&(o==="list"||o==="watch")){const e=async()=>{const u=await s.listApprovals(t.status?{status:t.status}:void 0);c(t.json?l(u):k(u))};if(await e(),o==="watch"&&!t.once)for(;;)await p.sleep(t.pollMs),await e();return 0}if(i==="requests"&&(o==="list"||o==="tail")){const e=async()=>{const u=s.listRequests?.bind(s);if(!u)throw new Error("Runtime does not support request listing");const R=await u({...t.agentId?{agentId:t.agentId}:{},...t.sessionId?{sessionId:t.sessionId}:{},...t.state?{state:t.state}:{}});c(t.json?l(R):j(R))};if(await e(),o==="tail"&&!t.once)for(;;)await p.sleep(t.pollMs),await e();return 0}}finally{await s.stop()}}return a(d()),1}catch(r){const n=r instanceof Error?r.message:String(r);return a(`${n}
|
|
12
|
+
`),1}}export{T as handleRuntimeCommand};
|