@selesai/code 0.5.20 → 0.5.21
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/dist/extensions/handoff-new.test.ts +8 -9
- package/dist/extensions/handoff-new.ts +6 -8
- package/dist/extensions/pi-subagents/CHANGELOG.md +1367 -0
- package/dist/extensions/pi-subagents/README.md +602 -220
- package/dist/extensions/pi-subagents/banner.png +0 -0
- package/dist/extensions/pi-subagents/index.ts +1 -0
- package/dist/extensions/pi-subagents/install.mjs +3 -3
- package/dist/extensions/pi-subagents/package-lock.json +3405 -0
- package/dist/extensions/pi-subagents/package.json +26 -14
- package/dist/extensions/pi-subagents/prompts/gather-context-and-clarify.md +1 -1
- package/dist/extensions/pi-subagents/prompts/parallel-cleanup.md +9 -9
- package/dist/extensions/pi-subagents/prompts/parallel-context-build.md +3 -3
- package/dist/extensions/pi-subagents/prompts/parallel-handoff-plan.md +7 -7
- package/dist/extensions/pi-subagents/prompts/parallel-research.md +6 -6
- package/dist/extensions/pi-subagents/prompts/parallel-review.md +8 -8
- package/dist/extensions/pi-subagents/prompts/review-loop.md +13 -11
- package/dist/extensions/pi-subagents/skills/pi-subagents/SKILL.md +267 -176
- package/dist/extensions/pi-subagents/src/agents/agent-management.ts +89 -16
- package/dist/extensions/pi-subagents/src/agents/agent-serializer.ts +19 -0
- package/dist/extensions/pi-subagents/src/agents/agents.ts +218 -120
- package/dist/extensions/pi-subagents/src/agents/frontmatter.ts +67 -13
- package/dist/extensions/pi-subagents/src/agents/proactive-skills.ts +2 -2
- package/dist/extensions/pi-subagents/src/agents/skills.ts +25 -12
- package/dist/extensions/pi-subagents/src/api/background-work.ts +197 -0
- package/dist/extensions/pi-subagents/src/api/capability-ceiling.ts +17 -0
- package/dist/extensions/pi-subagents/src/api/delegation.ts +285 -0
- package/dist/extensions/pi-subagents/src/api/preflight.ts +399 -0
- package/dist/extensions/pi-subagents/src/extension/chain-validation.ts +165 -0
- package/dist/extensions/pi-subagents/src/extension/config.ts +7 -1
- package/dist/extensions/pi-subagents/src/extension/doctor.ts +15 -0
- package/dist/extensions/pi-subagents/src/extension/fanout-child.ts +3 -1
- package/dist/extensions/pi-subagents/src/extension/index.ts +113 -157
- package/dist/extensions/pi-subagents/src/extension/rpc.ts +41 -4
- package/dist/extensions/pi-subagents/src/extension/schemas.ts +45 -15
- package/dist/extensions/pi-subagents/src/extension/steering-notices.ts +35 -0
- package/dist/extensions/pi-subagents/src/extension/tool-description.ts +28 -15
- package/dist/extensions/pi-subagents/src/intercom/intercom-bridge.ts +4 -3
- package/dist/extensions/pi-subagents/src/intercom/native-supervisor-channel.ts +225 -29
- package/dist/extensions/pi-subagents/src/intercom/result-intercom.ts +11 -0
- package/dist/extensions/pi-subagents/src/profiles/profiles.ts +8 -10
- package/dist/extensions/pi-subagents/src/runs/background/async-execution.ts +452 -62
- package/dist/extensions/pi-subagents/src/runs/background/async-job-tracker.ts +60 -9
- package/dist/extensions/pi-subagents/src/runs/background/async-resume.ts +198 -52
- package/dist/extensions/pi-subagents/src/runs/background/async-status.ts +119 -21
- package/dist/extensions/pi-subagents/src/runs/background/auto-drain.ts +67 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-append.ts +2 -0
- package/dist/extensions/pi-subagents/src/runs/background/chain-root-attachment.ts +16 -8
- package/dist/extensions/pi-subagents/src/runs/background/completion-batcher.ts +6 -4
- package/dist/extensions/pi-subagents/src/runs/background/completion-dedupe.ts +2 -11
- package/dist/extensions/pi-subagents/src/runs/background/control-channel.ts +260 -13
- package/dist/extensions/pi-subagents/src/runs/background/fleet-view.ts +32 -6
- package/dist/extensions/pi-subagents/src/runs/background/notify.ts +171 -90
- package/dist/extensions/pi-subagents/src/runs/background/process-terminal.ts +280 -0
- package/dist/extensions/pi-subagents/src/runs/background/result-watcher.ts +149 -88
- package/dist/extensions/pi-subagents/src/runs/background/run-id-resolver.ts +14 -2
- package/dist/extensions/pi-subagents/src/runs/background/run-status.ts +33 -17
- package/dist/extensions/pi-subagents/src/runs/background/scheduled-runs.ts +9 -1
- package/dist/extensions/pi-subagents/src/runs/background/stale-run-reconciler.ts +38 -10
- package/dist/extensions/pi-subagents/src/runs/background/steering.ts +237 -0
- package/dist/extensions/pi-subagents/src/runs/background/subagent-runner.ts +1297 -307
- package/dist/extensions/pi-subagents/src/runs/background/subagent-wait.ts +610 -0
- package/dist/extensions/pi-subagents/src/runs/background/top-level-async.ts +2 -1
- package/dist/extensions/pi-subagents/src/runs/background/wait-config.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/background/wait-tool.ts +26 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/async-steering-action.ts +230 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-clarify.ts +22 -6
- package/dist/extensions/pi-subagents/src/runs/foreground/chain-execution.ts +228 -140
- package/dist/extensions/pi-subagents/src/runs/foreground/execution.ts +452 -138
- package/dist/extensions/pi-subagents/src/runs/foreground/foreground-control.ts +90 -0
- package/dist/extensions/pi-subagents/src/runs/foreground/subagent-executor.ts +1001 -416
- package/dist/extensions/pi-subagents/src/runs/shared/acceptance.ts +443 -132
- package/dist/extensions/pi-subagents/src/runs/shared/agent-contract.ts +38 -0
- package/dist/extensions/pi-subagents/src/runs/shared/capability-ceiling.ts +178 -0
- package/dist/extensions/pi-subagents/src/runs/shared/child-protocol.ts +121 -0
- package/dist/extensions/pi-subagents/src/runs/shared/completion-guard.ts +41 -93
- package/dist/extensions/pi-subagents/src/runs/shared/context-mode.ts +44 -0
- package/dist/extensions/pi-subagents/src/runs/shared/dynamic-fanout.ts +11 -9
- package/dist/extensions/pi-subagents/src/runs/shared/long-running-guard.ts +4 -0
- package/dist/extensions/pi-subagents/src/runs/shared/mcp-direct-tool-allowlist.ts +12 -6
- package/dist/extensions/pi-subagents/src/runs/shared/model-fallback.ts +36 -0
- package/dist/extensions/pi-subagents/src/runs/shared/nested-events.ts +44 -7
- package/dist/extensions/pi-subagents/src/runs/shared/nested-render.ts +4 -1
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-handoff.ts +154 -0
- package/dist/extensions/pi-subagents/src/runs/shared/parallel-utils.ts +18 -0
- package/dist/extensions/pi-subagents/src/runs/shared/pi-args.ts +174 -54
- package/dist/extensions/pi-subagents/src/runs/shared/pi-spawn.ts +38 -31
- package/dist/extensions/pi-subagents/src/runs/shared/run-history.ts +90 -5
- package/dist/extensions/pi-subagents/src/runs/shared/session-lease.ts +299 -0
- package/dist/extensions/pi-subagents/src/runs/shared/single-output.ts +61 -6
- package/dist/extensions/pi-subagents/src/runs/shared/spawn-budget.ts +128 -0
- package/dist/extensions/pi-subagents/src/runs/shared/structured-output.ts +112 -7
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-control.ts +14 -6
- package/dist/extensions/pi-subagents/src/runs/shared/subagent-prompt-runtime.ts +149 -36
- package/dist/extensions/pi-subagents/src/runs/shared/task-intent.ts +181 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-availability.ts +83 -0
- package/dist/extensions/pi-subagents/src/runs/shared/tool-budget.ts +11 -5
- package/dist/extensions/pi-subagents/src/runs/shared/turn-budget.ts +50 -4
- package/dist/extensions/pi-subagents/src/runs/shared/worktree.ts +63 -14
- package/dist/extensions/pi-subagents/src/shared/accessible-dir.ts +25 -0
- package/dist/extensions/pi-subagents/src/shared/artifacts.ts +37 -7
- package/dist/extensions/pi-subagents/src/shared/atomic-json.ts +18 -43
- package/dist/extensions/pi-subagents/src/shared/child-transcript.ts +52 -0
- package/dist/extensions/pi-subagents/src/shared/env.ts +16 -0
- package/dist/extensions/pi-subagents/src/shared/file-system-retry.ts +47 -0
- package/dist/extensions/pi-subagents/src/shared/fork-context.ts +28 -3
- package/dist/extensions/pi-subagents/src/shared/launch-contract.ts +123 -0
- package/dist/extensions/pi-subagents/src/shared/model-info.ts +8 -5
- package/dist/extensions/pi-subagents/src/shared/settings.ts +9 -1
- package/dist/extensions/pi-subagents/src/shared/status-format.ts +7 -1
- package/dist/extensions/pi-subagents/src/shared/types.ts +522 -51
- package/dist/extensions/pi-subagents/src/shared/utils.ts +59 -53
- package/dist/extensions/pi-subagents/src/slash/delegation-adapters.ts +604 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-json.ts +108 -0
- package/dist/extensions/pi-subagents/src/slash/delegation-request.ts +249 -0
- package/dist/extensions/pi-subagents/src/slash/prompt-template-bridge.ts +353 -345
- package/dist/extensions/pi-subagents/src/slash/prompt-workflows.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/selector.ts +147 -0
- package/dist/extensions/pi-subagents/src/slash/slash-commands.ts +265 -23
- package/dist/extensions/pi-subagents/src/slash/slash-live-state.ts +2 -2
- package/dist/extensions/pi-subagents/src/slash/subagents-admin.ts +428 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-status.ts +362 -0
- package/dist/extensions/pi-subagents/src/tui/fleet-transcript.ts +472 -0
- package/dist/extensions/pi-subagents/src/tui/fleet.ts +664 -0
- package/dist/extensions/pi-subagents/src/tui/render.ts +115 -31
- package/dist/extensions/pi-subagents/src/watchdog/change-signature.ts +220 -0
- package/dist/extensions/pi-subagents/src/watchdog/child-status.ts +205 -0
- package/dist/extensions/pi-subagents/src/watchdog/emission-guard.ts +123 -0
- package/dist/extensions/pi-subagents/src/watchdog/lsp-diagnostics.ts +532 -0
- package/dist/extensions/pi-subagents/src/watchdog/model-selection.ts +167 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-child.ts +117 -0
- package/dist/extensions/pi-subagents/src/watchdog/register-main.ts +433 -0
- package/dist/extensions/pi-subagents/src/watchdog/render.ts +54 -0
- package/dist/extensions/pi-subagents/src/watchdog/review.ts +298 -0
- package/dist/extensions/pi-subagents/src/watchdog/runtime.ts +714 -0
- package/dist/extensions/pi-subagents/src/watchdog/settings.ts +528 -0
- package/dist/extensions/pi-subagents/src/watchdog/tool-actions.ts +155 -0
- package/dist/extensions/pi-subagents/src/watchdog/turn-delta.ts +161 -0
- package/dist/extensions/pi-subagents/src/watchdog/types.ts +188 -0
- package/dist/extensions/pi-subagents/src/watchdog/warning-format.ts +73 -0
- package/dist/extensions/pi-subagents/test/e2e/real-session-subagent.test.ts +130 -2
- package/dist/extensions/pi-subagents/test/integration/acceptance-file-report.test.ts +439 -0
- package/dist/extensions/pi-subagents/test/integration/async-execution.test.ts +1632 -61
- package/dist/extensions/pi-subagents/test/integration/async-job-tracker.test.ts +54 -1
- package/dist/extensions/pi-subagents/test/integration/async-status.test.ts +112 -0
- package/dist/extensions/pi-subagents/test/integration/chain-clarify.test.ts +98 -1
- package/dist/extensions/pi-subagents/test/integration/chain-execution.test.ts +179 -9
- package/dist/extensions/pi-subagents/test/integration/detect-error.test.ts +16 -9
- package/dist/extensions/pi-subagents/test/integration/error-handling.test.ts +6 -5
- package/dist/extensions/pi-subagents/test/integration/fork-context-execution.test.ts +589 -9
- package/dist/extensions/pi-subagents/test/integration/intercom-result-delivery.test.ts +528 -21
- package/dist/extensions/pi-subagents/test/integration/parallel-execution.test.ts +227 -3
- package/dist/extensions/pi-subagents/test/integration/render-fork-badge.test.ts +235 -7
- package/dist/extensions/pi-subagents/test/integration/render-widget.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/result-watcher.test.ts +172 -2
- package/dist/extensions/pi-subagents/test/integration/single-execution.test.ts +1502 -18
- package/dist/extensions/pi-subagents/test/integration/slash-commands.test.ts +993 -4
- package/dist/extensions/pi-subagents/test/integration/slash-live-state.test.ts +27 -0
- package/dist/extensions/pi-subagents/test/integration/top-level-async.test.ts +7 -1
- package/dist/extensions/pi-subagents/test/support/helpers.ts +32 -0
- package/dist/extensions/pi-subagents/test/support/mock-pi-script.mjs +59 -2
- package/dist/extensions/pi-subagents/test/support/mock-pi.ts +32 -6
- package/dist/extensions/pi-subagents/test/support/real-session-child-cli.mjs +25 -24
- package/dist/extensions/pi-subagents/test/support/real-session-runner.ts +59 -35
- package/dist/extensions/pi-subagents/test/support/session-lease-child.mjs +42 -0
- package/dist/extensions/pi-subagents/test/unit/acceptance.test.ts +703 -69
- package/dist/extensions/pi-subagents/test/unit/accessible-dir.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/agent-disabled.test.ts +15 -15
- package/dist/extensions/pi-subagents/test/unit/agent-eject-disable.test.ts +66 -66
- package/dist/extensions/pi-subagents/test/unit/agent-frontmatter.test.ts +478 -19
- package/dist/extensions/pi-subagents/test/unit/agent-management.test.ts +228 -7
- package/dist/extensions/pi-subagents/test/unit/agent-memory.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/agent-overrides.test.ts +198 -78
- package/dist/extensions/pi-subagents/test/unit/async-execution.test.ts +15 -1
- package/dist/extensions/pi-subagents/test/unit/async-interrupt-action.test.ts +102 -7
- package/dist/extensions/pi-subagents/test/unit/async-resume.test.ts +439 -6
- package/dist/extensions/pi-subagents/test/unit/atomic-json.test.ts +41 -1
- package/dist/extensions/pi-subagents/test/unit/auto-drain.test.ts +79 -0
- package/dist/extensions/pi-subagents/test/unit/background-work.test.ts +285 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling-pi-args.test.ts +84 -0
- package/dist/extensions/pi-subagents/test/unit/capability-ceiling.test.ts +68 -0
- package/dist/extensions/pi-subagents/test/unit/chain-validation.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/child-protocol.test.ts +82 -0
- package/dist/extensions/pi-subagents/test/unit/child-transcript.test.ts +46 -4
- package/dist/extensions/pi-subagents/test/unit/completion-batcher.test.ts +3 -1
- package/dist/extensions/pi-subagents/test/unit/completion-dedupe.test.ts +9 -17
- package/dist/extensions/pi-subagents/test/unit/completion-guard.test.ts +175 -3
- package/dist/extensions/pi-subagents/test/unit/config-dir-runtime.test.ts +10 -5
- package/dist/extensions/pi-subagents/test/unit/control-channel.test.ts +126 -6
- package/dist/extensions/pi-subagents/test/unit/default-extensions.test.ts +219 -0
- package/dist/extensions/pi-subagents/test/unit/delegation-api.test.ts +913 -0
- package/dist/extensions/pi-subagents/test/unit/doctor.test.ts +13 -2
- package/dist/extensions/pi-subagents/test/unit/dynamic-fanout.test.ts +3 -3
- package/dist/extensions/pi-subagents/test/unit/fleet-status.test.ts +351 -0
- package/dist/extensions/pi-subagents/test/unit/fleet-transcript.test.ts +280 -0
- package/dist/extensions/pi-subagents/test/unit/fleet.test.ts +575 -0
- package/dist/extensions/pi-subagents/test/unit/foreground-control.test.ts +65 -0
- package/dist/extensions/pi-subagents/test/unit/fork-context.test.ts +94 -1
- package/dist/extensions/pi-subagents/test/unit/get-final-output.test.ts +23 -0
- package/dist/extensions/pi-subagents/test/unit/host-peer-runtime-imports.test.ts +157 -0
- package/dist/extensions/pi-subagents/test/unit/index-child-registration.test.ts +367 -5
- package/dist/extensions/pi-subagents/test/unit/intercom-bridge.test.ts +11 -0
- package/dist/extensions/pi-subagents/test/unit/model-fallback.test.ts +36 -0
- package/dist/extensions/pi-subagents/test/unit/model-info.test.ts +25 -3
- package/dist/extensions/pi-subagents/test/unit/model-scope.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/native-supervisor-channel.test.ts +341 -10
- package/dist/extensions/pi-subagents/test/unit/nested-control.test.ts +16 -0
- package/dist/extensions/pi-subagents/test/unit/nested-events.test.ts +52 -0
- package/dist/extensions/pi-subagents/test/unit/notify.test.ts +168 -7
- package/dist/extensions/pi-subagents/test/unit/package-manifest.test.ts +85 -7
- package/dist/extensions/pi-subagents/test/unit/parallel-handoff.test.ts +175 -0
- package/dist/extensions/pi-subagents/test/unit/path-resolution.test.ts +1 -1
- package/dist/extensions/pi-subagents/test/unit/pi-args.test.ts +243 -16
- package/dist/extensions/pi-subagents/test/unit/pi-coding-agent-dir.test.ts +79 -36
- package/dist/extensions/pi-subagents/test/unit/pi-spawn.test.ts +174 -56
- package/dist/extensions/pi-subagents/test/unit/preflight.test.ts +322 -0
- package/dist/extensions/pi-subagents/test/unit/process-terminal.test.ts +204 -0
- package/dist/extensions/pi-subagents/test/unit/recursion-guard.test.ts +20 -12
- package/dist/extensions/pi-subagents/test/unit/rpc.test.ts +117 -4
- package/dist/extensions/pi-subagents/test/unit/run-status.test.ts +40 -7
- package/dist/extensions/pi-subagents/test/unit/scheduled-runs.test.ts +48 -1
- package/dist/extensions/pi-subagents/test/unit/schemas.test.ts +21 -3
- package/dist/extensions/pi-subagents/test/unit/selector.test.ts +57 -0
- package/dist/extensions/pi-subagents/test/unit/session-lease.test.ts +326 -0
- package/dist/extensions/pi-subagents/test/unit/single-output.test.ts +101 -2
- package/dist/extensions/pi-subagents/test/unit/skills-fallback.test.ts +111 -1
- package/dist/extensions/pi-subagents/test/unit/spawn-budget.test.ts +124 -0
- package/dist/extensions/pi-subagents/test/unit/stale-run-reconciler.test.ts +6 -4
- package/dist/extensions/pi-subagents/test/unit/status-format.test.ts +7 -0
- package/dist/extensions/pi-subagents/test/unit/steering-action.test.ts +397 -0
- package/dist/extensions/pi-subagents/test/unit/steering-notices.test.ts +58 -0
- package/dist/extensions/pi-subagents/test/unit/steering.test.ts +173 -0
- package/dist/extensions/pi-subagents/test/unit/subagent-control.test.ts +25 -4
- package/dist/extensions/pi-subagents/test/unit/subagent-prompt-runtime.test.ts +390 -25
- package/dist/extensions/pi-subagents/test/unit/subagent-wait.test.ts +837 -0
- package/dist/extensions/pi-subagents/test/unit/task-intent.test.ts +86 -0
- package/dist/extensions/pi-subagents/test/unit/tool-budget.test.ts +15 -0
- package/dist/extensions/pi-subagents/test/unit/tool-description.test.ts +47 -1
- package/dist/extensions/pi-subagents/test/unit/turn-budget.test.ts +56 -10
- package/dist/extensions/pi-subagents/test/unit/watchdog-change-signature.test.ts +387 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-child-status.test.ts +110 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-emission-guard.test.ts +62 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-lsp-diagnostics.test.ts +144 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-model-selection.test.ts +121 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-render.test.ts +76 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-review.test.ts +327 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-runtime.test.ts +863 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-settings.test.ts +290 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-tool-actions.test.ts +91 -0
- package/dist/extensions/pi-subagents/test/unit/watchdog-turn-delta.test.ts +130 -0
- package/dist/extensions/pi-subagents/test/unit/widget-nested-render.test.ts +32 -4
- package/dist/extensions/pi-subagents/test/unit/worktree.test.ts +5 -1
- package/dist/extensions/pi-subagents/test/unit/writer-budget-guidance.test.ts +30 -0
- package/dist/extensions/question/batch.ts +39 -0
- package/dist/extensions/question/dialog-adapter.ts +23 -1
- package/dist/extensions/question/index.ts +237 -7
- package/dist/extensions/question/schemas.ts +28 -15
- package/dist/extensions/question/tests/batch.test.ts +26 -0
- package/dist/extensions/question/tests/ui-protocol.test.ts +23 -3
- package/dist/extensions/question/tui-adapter.ts +2 -3
- package/dist/extensions/question/types.ts +37 -0
- package/dist/extensions/question/ui-protocol.ts +3 -3
- package/dist/skills/batch-grill-me/SKILL.md +3 -1
- package/package.json +1 -1
|
@@ -0,0 +1,472 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { getLanguageFromPath, highlightCode, type ExtensionContext } from "@selesai/code";
|
|
4
|
+
import { Markdown, truncateToWidth, visibleWidth, wrapTextWithAnsi, type MarkdownTheme } from "@earendil-works/pi-tui";
|
|
5
|
+
|
|
6
|
+
const DEFAULT_MAX_RECORDS = 240;
|
|
7
|
+
const DEFAULT_MAX_BYTES = 2 * 1024 * 1024;
|
|
8
|
+
const MAX_MESSAGE_CHARS = 64 * 1024;
|
|
9
|
+
const TOOL_PREVIEW_LINES = 7;
|
|
10
|
+
|
|
11
|
+
type Theme = ExtensionContext["ui"]["theme"];
|
|
12
|
+
|
|
13
|
+
export type FleetTranscriptEvent =
|
|
14
|
+
| { kind: "assistant"; text: string; model?: string; timestamp?: number }
|
|
15
|
+
| { kind: "user"; text: string; timestamp?: number }
|
|
16
|
+
| { kind: "tool"; toolCallId?: string; name: string; args?: string; argsPayload?: string; output?: string; outputTruncated?: boolean; status: "running" | "complete" | "error"; error?: string; startedAt?: number; endedAt?: number; timestamp?: number }
|
|
17
|
+
| { kind: "notice"; text: string; tone: "muted" | "warning" | "error"; timestamp?: number };
|
|
18
|
+
|
|
19
|
+
export interface FleetTranscript {
|
|
20
|
+
path: string;
|
|
21
|
+
events: FleetTranscriptEvent[];
|
|
22
|
+
truncated: boolean;
|
|
23
|
+
warning?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface FleetTranscriptReadOptions {
|
|
27
|
+
trustedRoots: string[];
|
|
28
|
+
maxRecords?: number;
|
|
29
|
+
maxBytes?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface MutableToolEvent {
|
|
33
|
+
kind: "tool";
|
|
34
|
+
toolCallId?: string;
|
|
35
|
+
name: string;
|
|
36
|
+
args?: string;
|
|
37
|
+
argsPayload?: string;
|
|
38
|
+
output?: string;
|
|
39
|
+
outputTruncated?: boolean;
|
|
40
|
+
status: "running" | "complete" | "error";
|
|
41
|
+
error?: string;
|
|
42
|
+
startedAt?: number;
|
|
43
|
+
endedAt?: number;
|
|
44
|
+
timestamp?: number;
|
|
45
|
+
resultSeen?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function objectValue(value: unknown): Record<string, unknown> | undefined {
|
|
49
|
+
return value && typeof value === "object" && !Array.isArray(value)
|
|
50
|
+
? value as Record<string, unknown>
|
|
51
|
+
: undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function stringValue(value: unknown): string | undefined {
|
|
55
|
+
return typeof value === "string" && value.trim() ? value : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function numberValue(value: unknown): number | undefined {
|
|
59
|
+
return typeof value === "number" && Number.isFinite(value) ? value : undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function pathWithin(base: string, candidate: string): boolean {
|
|
63
|
+
const resolvedBase = path.resolve(base);
|
|
64
|
+
const resolvedCandidate = path.resolve(candidate);
|
|
65
|
+
return resolvedCandidate === resolvedBase || resolvedCandidate.startsWith(`${resolvedBase}${path.sep}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function errorMessage(error: unknown): string {
|
|
69
|
+
return error instanceof Error ? error.message : String(error);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function isNotFoundError(error: unknown): boolean {
|
|
73
|
+
return Boolean(objectValue(error)?.code === "ENOENT");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function validateTranscriptPath(filePath: string, trustedRoots: string[]): { resolvedPath?: string; warning?: string } {
|
|
77
|
+
if (trustedRoots.length === 0) return { warning: `Transcript preview has no trusted root: ${filePath}` };
|
|
78
|
+
const resolvedPath = path.resolve(filePath);
|
|
79
|
+
if (!trustedRoots.some((root) => pathWithin(root, resolvedPath))) {
|
|
80
|
+
return { warning: `Transcript is outside trusted roots: ${filePath}` };
|
|
81
|
+
}
|
|
82
|
+
let stat: fs.Stats;
|
|
83
|
+
try {
|
|
84
|
+
stat = fs.lstatSync(resolvedPath);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (isNotFoundError(error)) return {};
|
|
87
|
+
return { warning: `Transcript could not be inspected: ${errorMessage(error)}` };
|
|
88
|
+
}
|
|
89
|
+
if (stat.isSymbolicLink()) return { warning: `Transcript preview refused a symlink: ${filePath}` };
|
|
90
|
+
if (!stat.isFile()) return { warning: `Transcript path is not a file: ${filePath}` };
|
|
91
|
+
try {
|
|
92
|
+
const realPath = fs.realpathSync(resolvedPath);
|
|
93
|
+
const realRoots = trustedRoots
|
|
94
|
+
.filter((root) => fs.existsSync(root))
|
|
95
|
+
.map((root) => fs.realpathSync(root));
|
|
96
|
+
if (!realRoots.some((root) => pathWithin(root, realPath))) {
|
|
97
|
+
return { warning: `Transcript resolves outside trusted roots: ${filePath}` };
|
|
98
|
+
}
|
|
99
|
+
return { resolvedPath: realPath };
|
|
100
|
+
} catch (error) {
|
|
101
|
+
return { warning: `Transcript path could not be resolved: ${errorMessage(error)}` };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isCompleteRecord(line: string | undefined): boolean {
|
|
106
|
+
if (!line?.trim()) return false;
|
|
107
|
+
try {
|
|
108
|
+
return objectValue(JSON.parse(line)) !== undefined;
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function readTailLines(filePath: string, maxBytes: number): { lines: string[]; truncated: boolean; warning?: string } {
|
|
115
|
+
let fd: number | undefined;
|
|
116
|
+
try {
|
|
117
|
+
const noFollow = typeof fs.constants.O_NOFOLLOW === "number" ? fs.constants.O_NOFOLLOW : 0;
|
|
118
|
+
fd = fs.openSync(filePath, fs.constants.O_RDONLY | noFollow);
|
|
119
|
+
const stat = fs.fstatSync(fd);
|
|
120
|
+
if (!stat.isFile()) return { lines: [], truncated: false, warning: `Transcript path is not a file: ${filePath}` };
|
|
121
|
+
if (stat.size === 0) return { lines: [], truncated: false };
|
|
122
|
+
const bytesToRead = Math.min(stat.size, maxBytes);
|
|
123
|
+
const start = stat.size - bytesToRead;
|
|
124
|
+
const buffer = Buffer.alloc(bytesToRead);
|
|
125
|
+
const bytesRead = fs.readSync(fd, buffer, 0, bytesToRead, start);
|
|
126
|
+
const content = buffer.subarray(0, bytesRead).toString("utf-8");
|
|
127
|
+
const endsWithNewline = content.endsWith("\n");
|
|
128
|
+
let lines = content.split(/\r?\n/);
|
|
129
|
+
if (start > 0 && lines.length > 0) lines = lines.slice(1);
|
|
130
|
+
if (lines.at(-1) === "") lines = lines.slice(0, -1);
|
|
131
|
+
else if (!endsWithNewline && !isCompleteRecord(lines.at(-1))) lines = lines.slice(0, -1);
|
|
132
|
+
return { lines, truncated: start > 0 };
|
|
133
|
+
} catch (error) {
|
|
134
|
+
return { lines: [], truncated: false, warning: `Transcript could not be read: ${errorMessage(error)}` };
|
|
135
|
+
} finally {
|
|
136
|
+
if (fd !== undefined) fs.closeSync(fd);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function clipMessage(text: string): string {
|
|
141
|
+
if (text.length <= MAX_MESSAGE_CHARS) return text;
|
|
142
|
+
return `${text.slice(0, MAX_MESSAGE_CHARS)}\n\n… message truncated`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function findTool(
|
|
146
|
+
events: FleetTranscriptEvent[],
|
|
147
|
+
toolCallId: string | undefined,
|
|
148
|
+
name: string | undefined,
|
|
149
|
+
): MutableToolEvent | undefined {
|
|
150
|
+
if (toolCallId) {
|
|
151
|
+
for (let index = events.length - 1; index >= 0; index--) {
|
|
152
|
+
const event = events[index];
|
|
153
|
+
if (event?.kind === "tool" && event.toolCallId === toolCallId) return event as MutableToolEvent;
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
for (let index = events.length - 1; index >= 0; index--) {
|
|
158
|
+
const event = events[index];
|
|
159
|
+
if (event?.kind !== "tool") continue;
|
|
160
|
+
const tool = event as MutableToolEvent;
|
|
161
|
+
if ((!name || tool.name === name) && !tool.resultSeen) return tool;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function appendTextEvent(
|
|
167
|
+
events: FleetTranscriptEvent[],
|
|
168
|
+
kind: "assistant" | "user",
|
|
169
|
+
text: string,
|
|
170
|
+
metadata: { model?: string; timestamp?: number },
|
|
171
|
+
): void {
|
|
172
|
+
const clipped = clipMessage(text.trim());
|
|
173
|
+
if (!clipped) return;
|
|
174
|
+
const previous = events.at(-1);
|
|
175
|
+
if (previous?.kind === kind && previous.text === clipped) return;
|
|
176
|
+
events.push({ kind, text: clipped, ...metadata });
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function parseTranscriptLines(lines: string[], conversationStarted = false): { events: FleetTranscriptEvent[]; malformed: number; explicitTruncation: boolean } {
|
|
180
|
+
const events: FleetTranscriptEvent[] = [];
|
|
181
|
+
let malformed = 0;
|
|
182
|
+
let explicitTruncation = false;
|
|
183
|
+
let assistantSeen = conversationStarted;
|
|
184
|
+
|
|
185
|
+
for (const line of lines) {
|
|
186
|
+
if (!line.trim()) continue;
|
|
187
|
+
let record: Record<string, unknown> | undefined;
|
|
188
|
+
try {
|
|
189
|
+
record = objectValue(JSON.parse(line));
|
|
190
|
+
} catch {
|
|
191
|
+
malformed++;
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (!record) {
|
|
195
|
+
malformed++;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const recordType = stringValue(record.recordType);
|
|
200
|
+
const timestamp = numberValue(record.ts);
|
|
201
|
+
if (recordType === "truncated") {
|
|
202
|
+
explicitTruncation = true;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
if (recordType === "tool_start") {
|
|
206
|
+
const name = stringValue(record.toolName) ?? "tool";
|
|
207
|
+
events.push({
|
|
208
|
+
kind: "tool",
|
|
209
|
+
...(stringValue(record.toolCallId) ? { toolCallId: stringValue(record.toolCallId) } : {}),
|
|
210
|
+
name,
|
|
211
|
+
...(stringValue(record.argsPreview) ? { args: stringValue(record.argsPreview) } : {}),
|
|
212
|
+
...(stringValue(record.argsPayload) ? { argsPayload: stringValue(record.argsPayload) } : {}),
|
|
213
|
+
status: "running",
|
|
214
|
+
...(timestamp !== undefined ? { timestamp, startedAt: timestamp } : {}),
|
|
215
|
+
});
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
if (recordType === "tool_end") {
|
|
219
|
+
const tool = findTool(events, stringValue(record.toolCallId), stringValue(record.toolName));
|
|
220
|
+
if (tool && !tool.resultSeen) tool.status = record.isError === true ? "error" : "complete";
|
|
221
|
+
if (tool && timestamp !== undefined && tool.endedAt === undefined) tool.endedAt = timestamp;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
if (recordType === "stderr") {
|
|
225
|
+
const text = stringValue(record.text);
|
|
226
|
+
if (text) events.push({ kind: "notice", text: clipMessage(text), tone: "error", ...(timestamp !== undefined ? { timestamp } : {}) });
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (recordType !== "message") continue;
|
|
230
|
+
|
|
231
|
+
const message = objectValue(record.message);
|
|
232
|
+
const role = stringValue(record.role) ?? stringValue(message?.role);
|
|
233
|
+
const text = stringValue(record.text) ?? stringValue(message?.text) ?? stringValue(message?.content);
|
|
234
|
+
if (role === "toolResult" || role === "tool_result") {
|
|
235
|
+
const toolCallId = stringValue(record.toolCallId) ?? stringValue(message?.toolCallId);
|
|
236
|
+
const name = stringValue(record.toolName) ?? stringValue(message?.toolName) ?? "tool";
|
|
237
|
+
const failed = record.isError === true || message?.isError === true;
|
|
238
|
+
let tool = findTool(events, toolCallId, name);
|
|
239
|
+
if (!tool) {
|
|
240
|
+
tool = {
|
|
241
|
+
kind: "tool",
|
|
242
|
+
...(toolCallId ? { toolCallId } : {}),
|
|
243
|
+
name,
|
|
244
|
+
status: failed ? "error" : "complete",
|
|
245
|
+
...(timestamp !== undefined ? { timestamp } : {}),
|
|
246
|
+
};
|
|
247
|
+
events.push(tool);
|
|
248
|
+
}
|
|
249
|
+
if (!tool.resultSeen) {
|
|
250
|
+
tool.resultSeen = true;
|
|
251
|
+
tool.status = failed ? "error" : "complete";
|
|
252
|
+
if (timestamp !== undefined && tool.endedAt === undefined) tool.endedAt = timestamp;
|
|
253
|
+
if (text && (!failed || tool.output === undefined)) {
|
|
254
|
+
tool.output = clipMessage(text);
|
|
255
|
+
tool.outputTruncated = record.outputTruncated === true || text.includes("… payload truncated") || text.includes("[Showing lines");
|
|
256
|
+
}
|
|
257
|
+
if (failed && text) tool.error = clipMessage(text.split(/\r?\n/).find((candidate) => candidate.trim()) ?? text);
|
|
258
|
+
}
|
|
259
|
+
continue;
|
|
260
|
+
}
|
|
261
|
+
if (role === "assistant") {
|
|
262
|
+
assistantSeen = true;
|
|
263
|
+
if (text) appendTextEvent(events, "assistant", text, {
|
|
264
|
+
...(stringValue(record.model) ? { model: stringValue(record.model) } : {}),
|
|
265
|
+
...(timestamp !== undefined ? { timestamp } : {}),
|
|
266
|
+
});
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
if (role === "user" && assistantSeen && text) {
|
|
270
|
+
appendTextEvent(events, "user", text, timestamp !== undefined ? { timestamp } : {});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
for (const event of events) {
|
|
275
|
+
if (event.kind === "tool") delete (event as MutableToolEvent).resultSeen;
|
|
276
|
+
}
|
|
277
|
+
return { events, malformed, explicitTruncation };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function readFleetTranscript(filePath: string, options: FleetTranscriptReadOptions): FleetTranscript {
|
|
281
|
+
const validated = validateTranscriptPath(filePath, options.trustedRoots);
|
|
282
|
+
if (!validated.resolvedPath) {
|
|
283
|
+
return { path: filePath, events: [], truncated: false, ...(validated.warning ? { warning: validated.warning } : {}) };
|
|
284
|
+
}
|
|
285
|
+
const maxRecords = Math.max(1, options.maxRecords ?? DEFAULT_MAX_RECORDS);
|
|
286
|
+
const tail = readTailLines(validated.resolvedPath, Math.max(1024, options.maxBytes ?? DEFAULT_MAX_BYTES));
|
|
287
|
+
const recordsOmitted = tail.truncated || tail.lines.length > maxRecords;
|
|
288
|
+
const selectedLines = tail.lines.slice(-maxRecords);
|
|
289
|
+
const parsed = parseTranscriptLines(selectedLines, recordsOmitted);
|
|
290
|
+
const warnings = [
|
|
291
|
+
tail.warning,
|
|
292
|
+
parsed.malformed > 0 ? `Skipped ${parsed.malformed} malformed transcript record${parsed.malformed === 1 ? "" : "s"}.` : undefined,
|
|
293
|
+
].filter((value): value is string => Boolean(value));
|
|
294
|
+
return {
|
|
295
|
+
path: filePath,
|
|
296
|
+
events: parsed.events,
|
|
297
|
+
truncated: tail.truncated || tail.lines.length > maxRecords || parsed.explicitTruncation,
|
|
298
|
+
...(warnings.length ? { warning: warnings.join(" ") } : {}),
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function statusGlyph(event: Extract<FleetTranscriptEvent, { kind: "tool" }>, theme: Theme): string {
|
|
303
|
+
if (event.status === "running") return theme.fg("warning", "●");
|
|
304
|
+
if (event.status === "error") return theme.fg("error", "✗");
|
|
305
|
+
return theme.fg("success", "✓");
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function jsonScalar(value: unknown): string | undefined {
|
|
309
|
+
if (typeof value === "string" && value.trim()) return value;
|
|
310
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
311
|
+
return undefined;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function parseToolArgs(event: Extract<FleetTranscriptEvent, { kind: "tool" }>): Record<string, unknown> | undefined {
|
|
315
|
+
if (!event.argsPayload) return undefined;
|
|
316
|
+
try {
|
|
317
|
+
return objectValue(JSON.parse(event.argsPayload));
|
|
318
|
+
} catch {
|
|
319
|
+
return undefined;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
function toolDuration(event: Extract<FleetTranscriptEvent, { kind: "tool" }>): string | undefined {
|
|
324
|
+
if (event.startedAt === undefined || event.endedAt === undefined) return undefined;
|
|
325
|
+
return `${((event.endedAt - event.startedAt) / 1000).toFixed(1)}s`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function renderExpandedTool(
|
|
329
|
+
event: Extract<FleetTranscriptEvent, { kind: "tool" }>,
|
|
330
|
+
width: number,
|
|
331
|
+
theme: Theme,
|
|
332
|
+
): string[] {
|
|
333
|
+
const lines: string[] = [];
|
|
334
|
+
const args = parseToolArgs(event);
|
|
335
|
+
const glyph = statusGlyph(event, theme);
|
|
336
|
+
const output = event.output ?? event.error;
|
|
337
|
+
const outputColor = event.status === "error" ? "error" : "toolOutput";
|
|
338
|
+
if (event.name === "bash") {
|
|
339
|
+
const command = jsonScalar(args?.command) ?? event.args ?? "(unknown command)";
|
|
340
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`$ ${command}`))}`, width, theme));
|
|
341
|
+
if (output) {
|
|
342
|
+
for (const outputLine of output.replace(/\s+$/, "").split(/\r?\n/)) {
|
|
343
|
+
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) {
|
|
344
|
+
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
const duration = toolDuration(event);
|
|
349
|
+
if (duration) lines.push(railLine(theme.fg("dim", ` Took ${duration}`), width, theme));
|
|
350
|
+
return lines;
|
|
351
|
+
}
|
|
352
|
+
if (event.name === "read") {
|
|
353
|
+
const filePath = jsonScalar(args?.path ?? args?.file_path);
|
|
354
|
+
const language = filePath ? getLanguageFromPath(filePath) : undefined;
|
|
355
|
+
const rendered = !output
|
|
356
|
+
? []
|
|
357
|
+
: event.status === "error"
|
|
358
|
+
? output.split("\n").map((line) => theme.fg("error", line))
|
|
359
|
+
: language
|
|
360
|
+
? highlightCode(output, language)
|
|
361
|
+
: output.split("\n");
|
|
362
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(`read ${filePath ?? event.args ?? ""}`))}`, width, theme));
|
|
363
|
+
for (const line of rendered) {
|
|
364
|
+
for (const wrapped of renderWrapped(line, Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
365
|
+
}
|
|
366
|
+
return lines;
|
|
367
|
+
}
|
|
368
|
+
lines.push(railLine(`${glyph} ${theme.fg("toolTitle", theme.bold(event.name))}`, width, theme));
|
|
369
|
+
if (event.argsPayload) {
|
|
370
|
+
lines.push(railLine(theme.fg("dim", " args"), width, theme));
|
|
371
|
+
for (const argLine of event.argsPayload.split(/\r?\n/)) {
|
|
372
|
+
for (const wrapped of renderWrapped(theme.fg("muted", argLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (output) {
|
|
376
|
+
lines.push(railLine(theme.fg(event.status === "error" ? "error" : "dim", event.status === "error" ? " error" : " output"), width, theme));
|
|
377
|
+
for (const outputLine of output.split(/\r?\n/)) {
|
|
378
|
+
for (const wrapped of renderWrapped(theme.fg(outputColor, outputLine), Math.max(1, width - 4))) lines.push(railLine(` ${wrapped}`, width, theme));
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return lines;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function bounded(text: string, width: number): string {
|
|
385
|
+
return truncateToWidth(text, Math.max(0, width));
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function railLine(content: string, width: number, theme: Theme): string {
|
|
389
|
+
return bounded(`${theme.fg("borderMuted", "│")} ${content}`, width);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function renderWrapped(text: string, width: number): string[] {
|
|
393
|
+
return wrapTextWithAnsi(text, Math.max(1, width));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export function renderFleetTranscript(
|
|
397
|
+
transcript: FleetTranscript,
|
|
398
|
+
width: number,
|
|
399
|
+
theme: Theme,
|
|
400
|
+
markdownTheme: MarkdownTheme,
|
|
401
|
+
options: { expandedTools?: boolean } = {},
|
|
402
|
+
): string[] {
|
|
403
|
+
if (width <= 0) return [];
|
|
404
|
+
const lines: string[] = [];
|
|
405
|
+
if (transcript.truncated) lines.push(bounded(theme.fg("dim", "↑ Earlier activity omitted"), width));
|
|
406
|
+
if (transcript.warning) {
|
|
407
|
+
for (const line of renderWrapped(transcript.warning, Math.max(1, width - 2))) {
|
|
408
|
+
lines.push(bounded(`${theme.fg("warning", "!")} ${theme.fg("warning", line)}`, width));
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
for (const event of transcript.events) {
|
|
413
|
+
if (event.kind === "tool") {
|
|
414
|
+
if (options.expandedTools && (event.output || event.argsPayload || event.error)) {
|
|
415
|
+
lines.push(...renderExpandedTool(event, width, theme));
|
|
416
|
+
lines.push(railLine(theme.fg("dim", " x to collapse"), width, theme));
|
|
417
|
+
continue;
|
|
418
|
+
}
|
|
419
|
+
const title = theme.fg("toolTitle", theme.bold(event.name));
|
|
420
|
+
const args = event.args ? ` ${theme.fg("dim", event.args)}` : "";
|
|
421
|
+
const suffix = event.status === "running" ? theme.fg("warning", " running") : "";
|
|
422
|
+
lines.push(bounded(`${theme.fg("borderMuted", "├─")} ${statusGlyph(event, theme)} ${title}${args}${suffix}`, width));
|
|
423
|
+
if (event.output && event.status !== "error" && event.name === "bash") {
|
|
424
|
+
const outputLines = event.output.replace(/\s+$/, "").split(/\r?\n/);
|
|
425
|
+
const visible = outputLines.slice(-TOOL_PREVIEW_LINES);
|
|
426
|
+
const hidden = Math.max(0, outputLines.length - visible.length);
|
|
427
|
+
for (const outputLine of visible) {
|
|
428
|
+
for (const wrapped of renderWrapped(theme.fg("toolOutput", outputLine), Math.max(1, width - 4))) {
|
|
429
|
+
lines.push(railLine(` ${wrapped}`, width, theme));
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
if (hidden > 0) lines.push(railLine(theme.fg("dim", ` … ${hidden} earlier lines · x to expand`), width, theme));
|
|
433
|
+
const duration = toolDuration(event);
|
|
434
|
+
lines.push(railLine(theme.fg("dim", ` Took${duration ? ` ${duration}` : ""}`), width, theme));
|
|
435
|
+
} else if (event.output && event.status !== "error") {
|
|
436
|
+
const summary = truncateToWidth(event.output.replace(/\s+/g, " ").trim(), Math.max(1, width - 18), "…");
|
|
437
|
+
if (summary) lines.push(railLine(theme.fg("dim", ` ${summary} · x to expand`), width, theme));
|
|
438
|
+
}
|
|
439
|
+
if (event.error) {
|
|
440
|
+
for (const errorLine of renderWrapped(event.error, Math.max(1, width - 4))) {
|
|
441
|
+
lines.push(railLine(theme.fg("error", ` ${errorLine}`), width, theme));
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (event.kind === "notice") {
|
|
447
|
+
const color = event.tone === "error" ? "error" : event.tone === "warning" ? "warning" : "dim";
|
|
448
|
+
for (const noticeLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
449
|
+
lines.push(railLine(theme.fg(color, noticeLine), width, theme));
|
|
450
|
+
}
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
const assistant = event.kind === "assistant";
|
|
455
|
+
const label = assistant ? "Assistant" : "Supervisor";
|
|
456
|
+
const marker = assistant ? theme.fg("accent", "◆") : theme.fg("warning", "◇");
|
|
457
|
+
const model = assistant && event.model ? theme.fg("dim", ` · ${event.model}`) : "";
|
|
458
|
+
lines.push(bounded(`${marker} ${theme.bold(label)}${model}`, width));
|
|
459
|
+
if (assistant) {
|
|
460
|
+
const rendered = new Markdown(event.text, 0, 0, markdownTheme).render(Math.max(1, width - 2));
|
|
461
|
+
for (const markdownLine of rendered) lines.push(railLine(markdownLine, width, theme));
|
|
462
|
+
} else {
|
|
463
|
+
for (const userLine of renderWrapped(event.text, Math.max(1, width - 2))) {
|
|
464
|
+
lines.push(railLine(userLine, width, theme));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
lines.push(theme.fg("borderMuted", "│"));
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
while (lines.length > 0 && visibleWidth(lines.at(-1) ?? "") === 1) lines.pop();
|
|
471
|
+
return lines;
|
|
472
|
+
}
|