@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.
Files changed (227) hide show
  1. package/README.md +3 -1234
  2. package/README.zh.md +3 -1191
  3. package/dist/acp.js +1 -1
  4. package/dist/api.js +1 -404
  5. package/dist/benchmark/checkpoint-resume-cost-benchmark.js +1 -55
  6. package/dist/benchmark/deepagent-local-model-benchmark.js +2 -35
  7. package/dist/benchmark/upstream-runtime-ab-benchmark.js +1 -179
  8. package/dist/cli/chat-interactive.js +25 -244
  9. package/dist/cli/chat-rendering.js +6 -100
  10. package/dist/cli/chat-stream.js +23 -512
  11. package/dist/cli/chat-ui.js +21 -199
  12. package/dist/cli/chat-workspace.js +2 -210
  13. package/dist/cli/main.js +21 -428
  14. package/dist/cli/managed-service-commands.js +9 -63
  15. package/dist/cli/managed-service.js +2 -137
  16. package/dist/cli/options-init-chat.js +1 -108
  17. package/dist/cli/options-runtime.js +1 -158
  18. package/dist/cli/options-serve.js +1 -282
  19. package/dist/cli/options.js +2 -19
  20. package/dist/cli/process-guards.js +1 -139
  21. package/dist/cli/request-tree.js +7 -296
  22. package/dist/cli/runtime-commands.js +12 -258
  23. package/dist/cli/runtime-output.js +16 -155
  24. package/dist/cli/server-commands.js +16 -270
  25. package/dist/cli/workspace.js +1 -67
  26. package/dist/cli.js +1 -7
  27. package/dist/client/acp.js +1 -1
  28. package/dist/client/in-process.js +1 -67
  29. package/dist/client/index.js +1 -2
  30. package/dist/client/types.js +0 -1
  31. package/dist/client.js +1 -1
  32. package/dist/contracts/core.js +1 -1
  33. package/dist/contracts/runtime-evaluation.js +0 -1
  34. package/dist/contracts/runtime-memory.js +0 -1
  35. package/dist/contracts/runtime-observability.js +0 -1
  36. package/dist/contracts/runtime-requests.js +0 -1
  37. package/dist/contracts/runtime-scheduling.js +0 -1
  38. package/dist/contracts/runtime.js +1 -27
  39. package/dist/contracts/types.js +1 -3
  40. package/dist/contracts/workspace.js +0 -1
  41. package/dist/flow/build-flow-graph.js +1 -50
  42. package/dist/flow/export-mermaid.js +2 -464
  43. package/dist/flow/export-sequence-mermaid.js +2 -325
  44. package/dist/flow/flow-graph-normalization.js +1 -214
  45. package/dist/flow/flow-graph-runtime.js +1 -107
  46. package/dist/flow/flow-graph-upstream.js +1 -494
  47. package/dist/flow/index.js +1 -3
  48. package/dist/flow/types.js +0 -1
  49. package/dist/index.js +1 -5
  50. package/dist/init-project.js +1 -1
  51. package/dist/knowledge/config.js +1 -32
  52. package/dist/knowledge/contracts.js +0 -1
  53. package/dist/knowledge/index.js +1 -2
  54. package/dist/knowledge/module.js +12 -909
  55. package/dist/knowledge/procedural/config.js +1 -125
  56. package/dist/knowledge/procedural/index.js +1 -2
  57. package/dist/knowledge/procedural/manager.js +9 -345
  58. package/dist/mcp.js +1 -2
  59. package/dist/package-version.d.ts +1 -1
  60. package/dist/package-version.js +1 -2
  61. package/dist/persistence/file-store.js +3 -758
  62. package/dist/persistence/sqlite-request-context-store.js +5 -54
  63. package/dist/persistence/sqlite-request-queue-store.js +10 -108
  64. package/dist/persistence/sqlite-runtime.js +1 -86
  65. package/dist/persistence/sqlite-store.js +62 -810
  66. package/dist/persistence/types.js +0 -1
  67. package/dist/projections/presentation.js +37 -206
  68. package/dist/projections/request-events.js +2 -502
  69. package/dist/projections/upstream-events.js +1 -201
  70. package/dist/protocol/a2a/http-discovery.js +1 -178
  71. package/dist/protocol/a2a/http-rpc.js +6 -622
  72. package/dist/protocol/a2a/http.js +1 -138
  73. package/dist/protocol/a2a/task-state.js +3 -317
  74. package/dist/protocol/acp/client.js +8 -294
  75. package/dist/protocol/acp/harness-client.js +1 -218
  76. package/dist/protocol/acp/http.js +5 -130
  77. package/dist/protocol/acp/server.js +1 -310
  78. package/dist/protocol/acp/stdio.js +2 -69
  79. package/dist/protocol/ag-ui/http.js +3 -378
  80. package/dist/protocol/mcp/server.js +1 -428
  81. package/dist/resource/backend/workspace-scoped-backend.js +1 -319
  82. package/dist/resource/isolation.js +1 -237
  83. package/dist/resource/mcp/tool-support.js +3 -296
  84. package/dist/resource/mcp-tool-support.js +1 -2
  85. package/dist/resource/providers/resource-provider.js +1 -215
  86. package/dist/resource/resource-impl.js +1 -3
  87. package/dist/resource/resource-types.js +0 -1
  88. package/dist/resource/resource.js +1 -1
  89. package/dist/resource/sources.js +1 -247
  90. package/dist/resource/tools/function-tool-resolver.js +2 -272
  91. package/dist/runtime/adapter/compat/deepagent-compat.js +1 -29
  92. package/dist/runtime/adapter/compat/openai-compatible.js +1 -55
  93. package/dist/runtime/adapter/direct-builtin-utility.js +2 -90
  94. package/dist/runtime/adapter/flow/execution-context.js +1 -71
  95. package/dist/runtime/adapter/flow/invocation-flow.js +8 -425
  96. package/dist/runtime/adapter/flow/invoke-runtime.js +1 -20
  97. package/dist/runtime/adapter/flow/stream-runtime.js +11 -1395
  98. package/dist/runtime/adapter/invocation-result.js +2 -473
  99. package/dist/runtime/adapter/local-tool-invocation.js +6 -638
  100. package/dist/runtime/adapter/middleware/context-hygiene.js +1 -83
  101. package/dist/runtime/adapter/middleware-assembly.js +5 -477
  102. package/dist/runtime/adapter/model/invocation-request.js +3 -183
  103. package/dist/runtime/adapter/model/message-assembly.js +1 -28
  104. package/dist/runtime/adapter/model/model-providers.js +23 -1115
  105. package/dist/runtime/adapter/model/prompted-json-tool-call-capture.js +1 -40
  106. package/dist/runtime/adapter/model/prompted-json-tool-policy.js +1 -22
  107. package/dist/runtime/adapter/resilience.js +1 -104
  108. package/dist/runtime/adapter/runtime-adapter-support.js +3 -141
  109. package/dist/runtime/adapter/runtime-shell.js +5 -166
  110. package/dist/runtime/adapter/stream-event-projection.js +2 -622
  111. package/dist/runtime/adapter/stream-text-consumption.js +1 -18
  112. package/dist/runtime/adapter/terminal-status.js +2 -67
  113. package/dist/runtime/adapter/tool/builtin-middleware-tools.js +6 -627
  114. package/dist/runtime/adapter/tool/declared-middleware.js +1 -154
  115. package/dist/runtime/adapter/tool/interrupt-policy.js +1 -34
  116. package/dist/runtime/adapter/tool/provider-tool.js +1 -25
  117. package/dist/runtime/adapter/tool/resolved-tool.js +1 -225
  118. package/dist/runtime/adapter/tool/tool-arguments.js +3 -486
  119. package/dist/runtime/adapter/tool/tool-hitl.js +1 -346
  120. package/dist/runtime/adapter/tool/tool-name-mapping.js +1 -128
  121. package/dist/runtime/adapter/tool/tool-output-artifacts.js +2 -88
  122. package/dist/runtime/adapter/tool/tool-replay.js +1 -37
  123. package/dist/runtime/adapter/tool-resolution.js +1 -86
  124. package/dist/runtime/adapter/upstream-configurable-keys.js +1 -2
  125. package/dist/runtime/agent-runtime-adapter.js +60 -2338
  126. package/dist/runtime/agent-runtime-assembly.js +7 -249
  127. package/dist/runtime/env/runtime-env.js +1 -62
  128. package/dist/runtime/harness/background-runtime.js +1 -8
  129. package/dist/runtime/harness/bindings.js +1 -58
  130. package/dist/runtime/harness/events/event-bus.js +1 -16
  131. package/dist/runtime/harness/events/event-sink.js +1 -61
  132. package/dist/runtime/harness/events/events.js +1 -80
  133. package/dist/runtime/harness/events/listener-runtime.js +1 -13
  134. package/dist/runtime/harness/events/runtime-event-operations.js +1 -9
  135. package/dist/runtime/harness/events/streaming.js +1 -100
  136. package/dist/runtime/harness/events/timeline.js +1 -52
  137. package/dist/runtime/harness/public-shapes.js +1 -186
  138. package/dist/runtime/harness/run/artifact-paths.js +1 -15
  139. package/dist/runtime/harness/run/governance.js +1 -295
  140. package/dist/runtime/harness/run/helpers.js +1 -71
  141. package/dist/runtime/harness/run/inspection.js +1 -409
  142. package/dist/runtime/harness/run/operator-overview.js +1 -80
  143. package/dist/runtime/harness/run/queue-diagnostics.js +1 -15
  144. package/dist/runtime/harness/run/recovery.js +1 -162
  145. package/dist/runtime/harness/run/resources.js +1 -60
  146. package/dist/runtime/harness/run/resume.js +1 -56
  147. package/dist/runtime/harness/run/routing.js +1 -48
  148. package/dist/runtime/harness/run/run-lifecycle.js +1 -66
  149. package/dist/runtime/harness/run/run-operations.js +1 -217
  150. package/dist/runtime/harness/run/run-queue.js +1 -43
  151. package/dist/runtime/harness/run/run-slot-acquisition.js +1 -157
  152. package/dist/runtime/harness/run/session-records.js +1 -97
  153. package/dist/runtime/harness/run/start-run.js +1 -120
  154. package/dist/runtime/harness/run/startup-runtime.js +1 -69
  155. package/dist/runtime/harness/run/stream-run.js +8 -1418
  156. package/dist/runtime/harness/run/surface-semantics.js +1 -79
  157. package/dist/runtime/harness/runtime-defaults.js +1 -39
  158. package/dist/runtime/harness/system/boundary-analysis.js +1 -234
  159. package/dist/runtime/harness/system/health-monitor.js +1 -258
  160. package/dist/runtime/harness/system/inventory.js +1 -129
  161. package/dist/runtime/harness/system/mem0-ingestion-sync.js +5 -345
  162. package/dist/runtime/harness/system/policy-engine.js +1 -175
  163. package/dist/runtime/harness/system/runtime-memory-candidates.js +4 -110
  164. package/dist/runtime/harness/system/runtime-memory-consolidation.js +1 -51
  165. package/dist/runtime/harness/system/runtime-memory-manager.js +10 -693
  166. package/dist/runtime/harness/system/runtime-memory-policy.js +1 -155
  167. package/dist/runtime/harness/system/runtime-memory-records.js +11 -577
  168. package/dist/runtime/harness/system/runtime-memory-sync.js +5 -206
  169. package/dist/runtime/harness/system/session-memory-sync.js +3 -113
  170. package/dist/runtime/harness/system/skill-requirements.js +1 -112
  171. package/dist/runtime/harness/system/store.js +9 -365
  172. package/dist/runtime/harness/tool-gateway/index.js +1 -2
  173. package/dist/runtime/harness/tool-gateway/policy.js +1 -45
  174. package/dist/runtime/harness/tool-gateway/validation.js +1 -176
  175. package/dist/runtime/harness/tool-schema.js +1 -3
  176. package/dist/runtime/harness.js +3 -1490
  177. package/dist/runtime/index.js +1 -3
  178. package/dist/runtime/layout/runtime-layout.js +1 -31
  179. package/dist/runtime/maintenance/checkpoint-maintenance.js +2 -178
  180. package/dist/runtime/maintenance/file-checkpoint-saver.js +1 -106
  181. package/dist/runtime/maintenance/runtime-record-maintenance.js +2 -169
  182. package/dist/runtime/maintenance/sqlite-checkpoint-saver.js +4 -289
  183. package/dist/runtime/parsing/output-content.js +10 -550
  184. package/dist/runtime/parsing/output-parsing.js +1 -4
  185. package/dist/runtime/parsing/output-recovery.js +3 -213
  186. package/dist/runtime/parsing/output-tool-args.js +7 -663
  187. package/dist/runtime/parsing/stream-event-parsing.js +3 -362
  188. package/dist/runtime/prompts/runtime-prompts.js +4 -73
  189. package/dist/runtime/scheduling/system-schedule-manager.js +11 -532
  190. package/dist/runtime/skills/skill-metadata.js +1 -197
  191. package/dist/runtime/startup-tracing.js +2 -37
  192. package/dist/runtime/support/compiled-binding.js +1 -290
  193. package/dist/runtime/support/embedding-models.js +1 -118
  194. package/dist/runtime/support/harness-support.js +5 -137
  195. package/dist/runtime/support/llamaindex.js +1 -108
  196. package/dist/runtime/support/runtime-adapter-options.js +1 -29
  197. package/dist/runtime/support/runtime-factories.js +1 -51
  198. package/dist/runtime/support/vector-stores.js +9 -270
  199. package/dist/scaffold/init-project.js +54 -233
  200. package/dist/tooling/extensions.js +1 -311
  201. package/dist/tooling/module-loader.js +1 -55
  202. package/dist/tools.js +1 -176
  203. package/dist/utils/agent-display.js +1 -18
  204. package/dist/utils/bundled-text.js +4 -39
  205. package/dist/utils/compiled-binding.js +1 -33
  206. package/dist/utils/fs.js +2 -45
  207. package/dist/utils/id.js +1 -9
  208. package/dist/utils/message-content.js +1 -30
  209. package/dist/utils/object.js +1 -6
  210. package/dist/workspace/agent-binding-compiler.js +3 -613
  211. package/dist/workspace/compile.js +1 -472
  212. package/dist/workspace/framework-contract-validation.js +2 -322
  213. package/dist/workspace/index.js +1 -1
  214. package/dist/workspace/object-loader-paths.js +1 -71
  215. package/dist/workspace/object-loader-readers.js +1 -187
  216. package/dist/workspace/object-loader.js +1 -754
  217. package/dist/workspace/resource-compilers.js +1 -374
  218. package/dist/workspace/support/agent-capabilities.js +1 -37
  219. package/dist/workspace/support/agent-execution-config.js +1 -44
  220. package/dist/workspace/support/discovery.js +1 -147
  221. package/dist/workspace/support/source-collectors.js +1 -30
  222. package/dist/workspace/support/source-protocols.js +2 -192
  223. package/dist/workspace/support/workspace-ref-utils.js +1 -362
  224. package/dist/workspace/tool-hydration.js +1 -280
  225. package/dist/workspace/validate.js +1 -99
  226. package/dist/workspace/yaml-object-reader.js +1 -285
  227. package/package.json +7 -3
@@ -1,296 +1,7 @@
1
- const STEP_KIND_ICON = {
2
- llm: "◆",
3
- tool: "",
4
- skill: "★",
5
- agent: "",
6
- memory: "◈",
7
- approval: "",
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 { renderApprovalList, renderBoundaryAnalysis, renderHealthSnapshot, renderJson, renderOperatorOverview, renderRequestList, } from "./runtime-output.js";
2
- import { parseRuntimeExportOptions, parseRuntimeInspectOptions, parseScheduledRunOptions, renderUsage } from "./options.js";
3
- import { resolveCliWorkspaceRoot, validateCliWorkspaceRoot } from "./workspace.js";
4
- function resolveValidatedWorkspace(cwd, workspaceRoot, stderr) {
5
- const workspacePath = resolveCliWorkspaceRoot(cwd, workspaceRoot);
6
- const workspaceError = validateCliWorkspaceRoot(workspacePath, workspaceRoot);
7
- if (workspaceError) {
8
- stderr(`${workspaceError}\n`);
9
- return undefined;
10
- }
11
- return workspacePath;
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};