zerg-ztc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +361 -0
- package/dist/App.d.ts +4 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +499 -0
- package/dist/App.js.map +1 -0
- package/dist/agent/agent.d.ts +54 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +347 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/backends/anthropic.d.ts +13 -0
- package/dist/agent/backends/anthropic.d.ts.map +1 -0
- package/dist/agent/backends/anthropic.js +54 -0
- package/dist/agent/backends/anthropic.js.map +1 -0
- package/dist/agent/backends/gemini.d.ts +13 -0
- package/dist/agent/backends/gemini.d.ts.map +1 -0
- package/dist/agent/backends/gemini.js +71 -0
- package/dist/agent/backends/gemini.js.map +1 -0
- package/dist/agent/backends/inception.d.ts +12 -0
- package/dist/agent/backends/inception.d.ts.map +1 -0
- package/dist/agent/backends/inception.js +15 -0
- package/dist/agent/backends/inception.js.map +1 -0
- package/dist/agent/backends/index.d.ts +7 -0
- package/dist/agent/backends/index.d.ts.map +1 -0
- package/dist/agent/backends/index.js +6 -0
- package/dist/agent/backends/index.js.map +1 -0
- package/dist/agent/backends/openai.d.ts +12 -0
- package/dist/agent/backends/openai.d.ts.map +1 -0
- package/dist/agent/backends/openai.js +15 -0
- package/dist/agent/backends/openai.js.map +1 -0
- package/dist/agent/backends/openai_compatible.d.ts +17 -0
- package/dist/agent/backends/openai_compatible.d.ts.map +1 -0
- package/dist/agent/backends/openai_compatible.js +95 -0
- package/dist/agent/backends/openai_compatible.js.map +1 -0
- package/dist/agent/backends/types.d.ts +49 -0
- package/dist/agent/backends/types.d.ts.map +1 -0
- package/dist/agent/backends/types.js +2 -0
- package/dist/agent/backends/types.js.map +1 -0
- package/dist/agent/commands/clipboard.d.ts +3 -0
- package/dist/agent/commands/clipboard.d.ts.map +1 -0
- package/dist/agent/commands/clipboard.js +72 -0
- package/dist/agent/commands/clipboard.js.map +1 -0
- package/dist/agent/commands/config.d.ts +3 -0
- package/dist/agent/commands/config.d.ts.map +1 -0
- package/dist/agent/commands/config.js +120 -0
- package/dist/agent/commands/config.js.map +1 -0
- package/dist/agent/commands/debug.d.ts +3 -0
- package/dist/agent/commands/debug.d.ts.map +1 -0
- package/dist/agent/commands/debug.js +23 -0
- package/dist/agent/commands/debug.js.map +1 -0
- package/dist/agent/commands/emulation.d.ts +3 -0
- package/dist/agent/commands/emulation.d.ts.map +1 -0
- package/dist/agent/commands/emulation.js +78 -0
- package/dist/agent/commands/emulation.js.map +1 -0
- package/dist/agent/commands/execution.d.ts +3 -0
- package/dist/agent/commands/execution.d.ts.map +1 -0
- package/dist/agent/commands/execution.js +8 -0
- package/dist/agent/commands/execution.js.map +1 -0
- package/dist/agent/commands/help.d.ts +3 -0
- package/dist/agent/commands/help.d.ts.map +1 -0
- package/dist/agent/commands/help.js +19 -0
- package/dist/agent/commands/help.js.map +1 -0
- package/dist/agent/commands/history.d.ts +3 -0
- package/dist/agent/commands/history.d.ts.map +1 -0
- package/dist/agent/commands/history.js +12 -0
- package/dist/agent/commands/history.js.map +1 -0
- package/dist/agent/commands/index.d.ts +4 -0
- package/dist/agent/commands/index.d.ts.map +1 -0
- package/dist/agent/commands/index.js +19 -0
- package/dist/agent/commands/index.js.map +1 -0
- package/dist/agent/commands/model.d.ts +3 -0
- package/dist/agent/commands/model.d.ts.map +1 -0
- package/dist/agent/commands/model.js +10 -0
- package/dist/agent/commands/model.js.map +1 -0
- package/dist/agent/commands/models.d.ts +3 -0
- package/dist/agent/commands/models.d.ts.map +1 -0
- package/dist/agent/commands/models.js +110 -0
- package/dist/agent/commands/models.js.map +1 -0
- package/dist/agent/commands/permissions.d.ts +3 -0
- package/dist/agent/commands/permissions.d.ts.map +1 -0
- package/dist/agent/commands/permissions.js +58 -0
- package/dist/agent/commands/permissions.js.map +1 -0
- package/dist/agent/commands/retry.d.ts +3 -0
- package/dist/agent/commands/retry.d.ts.map +1 -0
- package/dist/agent/commands/retry.js +8 -0
- package/dist/agent/commands/retry.js.map +1 -0
- package/dist/agent/commands/shell.d.ts +4 -0
- package/dist/agent/commands/shell.d.ts.map +1 -0
- package/dist/agent/commands/shell.js +66 -0
- package/dist/agent/commands/shell.js.map +1 -0
- package/dist/agent/commands/skills.d.ts +3 -0
- package/dist/agent/commands/skills.d.ts.map +1 -0
- package/dist/agent/commands/skills.js +50 -0
- package/dist/agent/commands/skills.js.map +1 -0
- package/dist/agent/commands/status.d.ts +3 -0
- package/dist/agent/commands/status.d.ts.map +1 -0
- package/dist/agent/commands/status.js +18 -0
- package/dist/agent/commands/status.js.map +1 -0
- package/dist/agent/commands/types.d.ts +70 -0
- package/dist/agent/commands/types.d.ts.map +1 -0
- package/dist/agent/commands/types.js +2 -0
- package/dist/agent/commands/types.js.map +1 -0
- package/dist/agent/factory.d.ts +13 -0
- package/dist/agent/factory.d.ts.map +1 -0
- package/dist/agent/factory.js +46 -0
- package/dist/agent/factory.js.map +1 -0
- package/dist/agent/index.d.ts +14 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +10 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/runtime/capabilities.d.ts +7 -0
- package/dist/agent/runtime/capabilities.d.ts.map +1 -0
- package/dist/agent/runtime/capabilities.js +8 -0
- package/dist/agent/runtime/capabilities.js.map +1 -0
- package/dist/agent/runtime/memory.d.ts +13 -0
- package/dist/agent/runtime/memory.d.ts.map +1 -0
- package/dist/agent/runtime/memory.js +13 -0
- package/dist/agent/runtime/memory.js.map +1 -0
- package/dist/agent/runtime/policy.d.ts +22 -0
- package/dist/agent/runtime/policy.d.ts.map +1 -0
- package/dist/agent/runtime/policy.js +29 -0
- package/dist/agent/runtime/policy.js.map +1 -0
- package/dist/agent/runtime/session.d.ts +11 -0
- package/dist/agent/runtime/session.d.ts.map +1 -0
- package/dist/agent/runtime/session.js +10 -0
- package/dist/agent/runtime/session.js.map +1 -0
- package/dist/agent/runtime/tracing.d.ts +13 -0
- package/dist/agent/runtime/tracing.d.ts.map +1 -0
- package/dist/agent/runtime/tracing.js +6 -0
- package/dist/agent/runtime/tracing.js.map +1 -0
- package/dist/agent/tools/file.d.ts +5 -0
- package/dist/agent/tools/file.d.ts.map +1 -0
- package/dist/agent/tools/file.js +162 -0
- package/dist/agent/tools/file.js.map +1 -0
- package/dist/agent/tools/index.d.ts +13 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +34 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/search.d.ts +3 -0
- package/dist/agent/tools/search.d.ts.map +1 -0
- package/dist/agent/tools/search.js +124 -0
- package/dist/agent/tools/search.js.map +1 -0
- package/dist/agent/tools/shell.d.ts +3 -0
- package/dist/agent/tools/shell.d.ts.map +1 -0
- package/dist/agent/tools/shell.js +60 -0
- package/dist/agent/tools/shell.js.map +1 -0
- package/dist/agent/tools/skills.d.ts +3 -0
- package/dist/agent/tools/skills.d.ts.map +1 -0
- package/dist/agent/tools/skills.js +27 -0
- package/dist/agent/tools/skills.js.map +1 -0
- package/dist/agent/tools/types.d.ts +8 -0
- package/dist/agent/tools/types.d.ts.map +1 -0
- package/dist/agent/tools/types.js +2 -0
- package/dist/agent/tools/types.js.map +1 -0
- package/dist/agent/tools/zerg.d.ts +3 -0
- package/dist/agent/tools/zerg.d.ts.map +1 -0
- package/dist/agent/tools/zerg.js +47 -0
- package/dist/agent/tools/zerg.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/components/FullScreen.d.ts +28 -0
- package/dist/components/FullScreen.d.ts.map +1 -0
- package/dist/components/FullScreen.js +40 -0
- package/dist/components/FullScreen.js.map +1 -0
- package/dist/components/Header.d.ts +10 -0
- package/dist/components/Header.d.ts.map +1 -0
- package/dist/components/Header.js +14 -0
- package/dist/components/Header.js.map +1 -0
- package/dist/components/InputArea.d.ts +24 -0
- package/dist/components/InputArea.d.ts.map +1 -0
- package/dist/components/InputArea.js +476 -0
- package/dist/components/InputArea.js.map +1 -0
- package/dist/components/MessageList.d.ts +12 -0
- package/dist/components/MessageList.d.ts.map +1 -0
- package/dist/components/MessageList.js +9 -0
- package/dist/components/MessageList.js.map +1 -0
- package/dist/components/StatusBar.d.ts +18 -0
- package/dist/components/StatusBar.d.ts.map +1 -0
- package/dist/components/StatusBar.js +21 -0
- package/dist/components/StatusBar.js.map +1 -0
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +7 -0
- package/dist/components/index.js.map +1 -0
- package/dist/config/types.d.ts +12 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config.d.ts +28 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +155 -0
- package/dist/config.js.map +1 -0
- package/dist/debug/logger.d.ts +2 -0
- package/dist/debug/logger.d.ts.map +1 -0
- package/dist/debug/logger.js +15 -0
- package/dist/debug/logger.js.map +1 -0
- package/dist/emulation/catalog.d.ts +4 -0
- package/dist/emulation/catalog.d.ts.map +1 -0
- package/dist/emulation/catalog.js +68 -0
- package/dist/emulation/catalog.js.map +1 -0
- package/dist/emulation/trace_style.d.ts +3 -0
- package/dist/emulation/trace_style.d.ts.map +1 -0
- package/dist/emulation/trace_style.js +10 -0
- package/dist/emulation/trace_style.js.map +1 -0
- package/dist/emulation/types.d.ts +8 -0
- package/dist/emulation/types.d.ts.map +1 -0
- package/dist/emulation/types.js +2 -0
- package/dist/emulation/types.js.map +1 -0
- package/dist/skills/index.d.ts +5 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +36 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/loader.d.ts +3 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +137 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/registry.d.ts +3 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +5 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +11 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +2 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/core/factory.d.ts +4 -0
- package/dist/ui/core/factory.d.ts.map +1 -0
- package/dist/ui/core/factory.js +7 -0
- package/dist/ui/core/factory.js.map +1 -0
- package/dist/ui/core/index.d.ts +5 -0
- package/dist/ui/core/index.d.ts.map +1 -0
- package/dist/ui/core/index.js +4 -0
- package/dist/ui/core/index.js.map +1 -0
- package/dist/ui/core/input.d.ts +22 -0
- package/dist/ui/core/input.d.ts.map +1 -0
- package/dist/ui/core/input.js +15 -0
- package/dist/ui/core/input.js.map +1 -0
- package/dist/ui/core/input_segments.d.ts +19 -0
- package/dist/ui/core/input_segments.d.ts.map +1 -0
- package/dist/ui/core/input_segments.js +367 -0
- package/dist/ui/core/input_segments.js.map +1 -0
- package/dist/ui/core/input_state.d.ts +24 -0
- package/dist/ui/core/input_state.d.ts.map +1 -0
- package/dist/ui/core/input_state.js +2 -0
- package/dist/ui/core/input_state.js.map +1 -0
- package/dist/ui/core/layout_yoga.d.ts +11 -0
- package/dist/ui/core/layout_yoga.d.ts.map +1 -0
- package/dist/ui/core/layout_yoga.js +102 -0
- package/dist/ui/core/layout_yoga.js.map +1 -0
- package/dist/ui/core/style.d.ts +3 -0
- package/dist/ui/core/style.d.ts.map +1 -0
- package/dist/ui/core/style.js +37 -0
- package/dist/ui/core/style.js.map +1 -0
- package/dist/ui/core/types.d.ts +50 -0
- package/dist/ui/core/types.d.ts.map +1 -0
- package/dist/ui/core/types.js +2 -0
- package/dist/ui/core/types.js.map +1 -0
- package/dist/ui/ink/index.d.ts +2 -0
- package/dist/ui/ink/index.d.ts.map +1 -0
- package/dist/ui/ink/index.js +2 -0
- package/dist/ui/ink/index.js.map +1 -0
- package/dist/ui/ink/render.d.ts +6 -0
- package/dist/ui/ink/render.d.ts.map +1 -0
- package/dist/ui/ink/render.js +14 -0
- package/dist/ui/ink/render.js.map +1 -0
- package/dist/ui/views/app.d.ts +28 -0
- package/dist/ui/views/app.d.ts.map +1 -0
- package/dist/ui/views/app.js +59 -0
- package/dist/ui/views/app.js.map +1 -0
- package/dist/ui/views/header.d.ts +11 -0
- package/dist/ui/views/header.d.ts.map +1 -0
- package/dist/ui/views/header.js +28 -0
- package/dist/ui/views/header.js.map +1 -0
- package/dist/ui/views/input_area.d.ts +45 -0
- package/dist/ui/views/input_area.d.ts.map +1 -0
- package/dist/ui/views/input_area.js +183 -0
- package/dist/ui/views/input_area.js.map +1 -0
- package/dist/ui/views/message_list.d.ts +12 -0
- package/dist/ui/views/message_list.d.ts.map +1 -0
- package/dist/ui/views/message_list.js +381 -0
- package/dist/ui/views/message_list.js.map +1 -0
- package/dist/ui/views/status_bar.d.ts +18 -0
- package/dist/ui/views/status_bar.d.ts.map +1 -0
- package/dist/ui/views/status_bar.js +72 -0
- package/dist/ui/views/status_bar.js.map +1 -0
- package/dist/ui/vue/index.d.ts +5 -0
- package/dist/ui/vue/index.d.ts.map +1 -0
- package/dist/ui/vue/index.js +50 -0
- package/dist/ui/vue/index.js.map +1 -0
- package/dist/utils/clipboard.d.ts +2 -0
- package/dist/utils/clipboard.d.ts.map +1 -0
- package/dist/utils/clipboard.js +39 -0
- package/dist/utils/clipboard.js.map +1 -0
- package/dist/utils/clipboard_image.d.ts +2 -0
- package/dist/utils/clipboard_image.d.ts.map +1 -0
- package/dist/utils/clipboard_image.js +37 -0
- package/dist/utils/clipboard_image.js.map +1 -0
- package/dist/utils/diff.d.ts +2 -0
- package/dist/utils/diff.d.ts.map +1 -0
- package/dist/utils/diff.js +49 -0
- package/dist/utils/diff.js.map +1 -0
- package/dist/utils/image_preview.d.ts +2 -0
- package/dist/utils/image_preview.d.ts.map +1 -0
- package/dist/utils/image_preview.js +37 -0
- package/dist/utils/image_preview.js.map +1 -0
- package/dist/utils/models.d.ts +8 -0
- package/dist/utils/models.d.ts.map +1 -0
- package/dist/utils/models.js +85 -0
- package/dist/utils/models.js.map +1 -0
- package/dist/utils/shell.d.ts +4 -0
- package/dist/utils/shell.d.ts.map +1 -0
- package/dist/utils/shell.js +57 -0
- package/dist/utils/shell.js.map +1 -0
- package/dist/utils/tool_summary.d.ts +3 -0
- package/dist/utils/tool_summary.d.ts.map +1 -0
- package/dist/utils/tool_summary.js +54 -0
- package/dist/utils/tool_summary.js.map +1 -0
- package/dist/utils/tool_trace.d.ts +9 -0
- package/dist/utils/tool_trace.d.ts.map +1 -0
- package/dist/utils/tool_trace.js +183 -0
- package/dist/utils/tool_trace.js.map +1 -0
- package/package.json +41 -0
- package/src/App.tsx +576 -0
- package/src/agent/agent.ts +407 -0
- package/src/agent/backends/anthropic.ts +76 -0
- package/src/agent/backends/gemini.ts +107 -0
- package/src/agent/backends/inception.ts +23 -0
- package/src/agent/backends/index.ts +16 -0
- package/src/agent/backends/openai.ts +23 -0
- package/src/agent/backends/openai_compatible.ts +131 -0
- package/src/agent/backends/types.ts +59 -0
- package/src/agent/commands/clipboard.ts +77 -0
- package/src/agent/commands/config.ts +130 -0
- package/src/agent/commands/debug.ts +23 -0
- package/src/agent/commands/emulation.ts +80 -0
- package/src/agent/commands/execution.ts +9 -0
- package/src/agent/commands/help.ts +20 -0
- package/src/agent/commands/history.ts +13 -0
- package/src/agent/commands/index.ts +40 -0
- package/src/agent/commands/model.ts +11 -0
- package/src/agent/commands/models.ts +116 -0
- package/src/agent/commands/permissions.ts +64 -0
- package/src/agent/commands/retry.ts +9 -0
- package/src/agent/commands/shell.ts +68 -0
- package/src/agent/commands/skills.ts +54 -0
- package/src/agent/commands/status.ts +19 -0
- package/src/agent/commands/types.ts +78 -0
- package/src/agent/factory.ts +60 -0
- package/src/agent/index.ts +20 -0
- package/src/agent/runtime/capabilities.ts +6 -0
- package/src/agent/runtime/memory.ts +23 -0
- package/src/agent/runtime/policy.ts +48 -0
- package/src/agent/runtime/session.ts +18 -0
- package/src/agent/runtime/tracing.ts +23 -0
- package/src/agent/tools/file.ts +173 -0
- package/src/agent/tools/index.ts +46 -0
- package/src/agent/tools/search.ts +137 -0
- package/src/agent/tools/shell.ts +65 -0
- package/src/agent/tools/skills.ts +28 -0
- package/src/agent/tools/types.ts +10 -0
- package/src/agent/tools/zerg.ts +50 -0
- package/src/cli.tsx +80 -0
- package/src/components/FullScreen.tsx +73 -0
- package/src/components/Header.tsx +27 -0
- package/src/components/InputArea.tsx +551 -0
- package/src/components/MessageList.tsx +25 -0
- package/src/components/StatusBar.tsx +49 -0
- package/src/components/index.tsx +6 -0
- package/src/config/types.ts +11 -0
- package/src/config.ts +178 -0
- package/src/debug/logger.ts +14 -0
- package/src/emulation/README.md +24 -0
- package/src/emulation/catalog.ts +82 -0
- package/src/emulation/trace_style.ts +8 -0
- package/src/emulation/types.ts +7 -0
- package/src/skills/index.ts +36 -0
- package/src/skills/loader.ts +135 -0
- package/src/skills/registry.ts +6 -0
- package/src/skills/types.ts +10 -0
- package/src/types.ts +83 -0
- package/src/ui/README.md +44 -0
- package/src/ui/core/factory.ts +9 -0
- package/src/ui/core/index.ts +4 -0
- package/src/ui/core/input.ts +38 -0
- package/src/ui/core/input_segments.ts +375 -0
- package/src/ui/core/input_state.ts +17 -0
- package/src/ui/core/layout_yoga.ts +122 -0
- package/src/ui/core/style.ts +38 -0
- package/src/ui/core/types.ts +53 -0
- package/src/ui/ink/index.tsx +1 -0
- package/src/ui/ink/render.tsx +49 -0
- package/src/ui/views/app.ts +99 -0
- package/src/ui/views/header.ts +42 -0
- package/src/ui/views/input_area.ts +244 -0
- package/src/ui/views/message_list.ts +427 -0
- package/src/ui/views/status_bar.ts +104 -0
- package/src/ui/vue/index.ts +53 -0
- package/src/utils/clipboard.ts +39 -0
- package/src/utils/clipboard_image.ts +40 -0
- package/src/utils/diff.ts +52 -0
- package/src/utils/image_preview.ts +36 -0
- package/src/utils/models.ts +98 -0
- package/src/utils/shell.ts +63 -0
- package/src/utils/tool_summary.ts +56 -0
- package/src/utils/tool_trace.ts +206 -0
- package/tsconfig.json +22 -0
- package/vite.config.ts +363 -0
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import { Message, MessageRole, ToolCall } from '../../types.js';
|
|
2
|
+
import { box, text, LayoutNode } from '../core/index.js';
|
|
3
|
+
|
|
4
|
+
function formatTime(date: Date): string {
|
|
5
|
+
return date.toLocaleTimeString('en-US', {
|
|
6
|
+
hour: '2-digit',
|
|
7
|
+
minute: '2-digit',
|
|
8
|
+
hour12: false
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function toDate(value?: Date | string): Date | null {
|
|
13
|
+
if (!value) return null;
|
|
14
|
+
if (value instanceof Date) return value;
|
|
15
|
+
const parsed = new Date(value);
|
|
16
|
+
if (Number.isNaN(parsed.getTime())) return null;
|
|
17
|
+
return parsed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function truncate(str: string, maxLen: number): string {
|
|
21
|
+
if (str.length <= maxLen) return str;
|
|
22
|
+
return str.slice(0, maxLen - 3) + '...';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
interface RoleConfig {
|
|
26
|
+
icon: string;
|
|
27
|
+
color: string;
|
|
28
|
+
label: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const roleConfigs: Record<MessageRole, RoleConfig> = {
|
|
32
|
+
user: { icon: '❯', color: 'blue', label: 'You' },
|
|
33
|
+
assistant: { icon: '◆', color: 'magenta', label: 'Zerg' },
|
|
34
|
+
tool: { icon: '⏺', color: 'yellow', label: 'Trace' },
|
|
35
|
+
system: { icon: '●', color: 'gray', label: 'System' }
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function toolCallView(tool: ToolCall): LayoutNode {
|
|
39
|
+
const statusIcons = {
|
|
40
|
+
pending: '○',
|
|
41
|
+
running: '◐',
|
|
42
|
+
complete: '●',
|
|
43
|
+
error: '✗'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const statusColors = {
|
|
47
|
+
pending: 'gray',
|
|
48
|
+
running: 'yellow',
|
|
49
|
+
complete: 'green',
|
|
50
|
+
error: 'red'
|
|
51
|
+
} as const;
|
|
52
|
+
|
|
53
|
+
const icon = statusIcons[tool.status];
|
|
54
|
+
const color = statusColors[tool.status];
|
|
55
|
+
|
|
56
|
+
let duration = '';
|
|
57
|
+
const started = toDate(tool.startedAt);
|
|
58
|
+
const completed = toDate(tool.completedAt);
|
|
59
|
+
if (started && completed) {
|
|
60
|
+
const ms = completed.getTime() - started.getTime();
|
|
61
|
+
duration = ms < 1000 ? `${ms}ms` : `${(ms / 1000).toFixed(1)}s`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const extra = tool.result ? renderToolResult(tool) : null;
|
|
65
|
+
|
|
66
|
+
return box([
|
|
67
|
+
box([
|
|
68
|
+
text(`${icon} `, { color }),
|
|
69
|
+
text(tool.name, { color: 'cyan', bold: true }),
|
|
70
|
+
text(` (${tool.id.slice(0, 8)})`, { color: 'gray', dimColor: true }),
|
|
71
|
+
duration ? text(` [${duration}]`, { color: 'gray', dimColor: true }) : text('', {})
|
|
72
|
+
], { flexDirection: 'row' }),
|
|
73
|
+
tool.result
|
|
74
|
+
? extra || box([
|
|
75
|
+
text('→ ', { color: 'green' }),
|
|
76
|
+
text(truncate(tool.result, 80))
|
|
77
|
+
], { flexDirection: 'row', marginLeft: 2 })
|
|
78
|
+
: box([], {}),
|
|
79
|
+
tool.error
|
|
80
|
+
? box([
|
|
81
|
+
text('✗ ', { color: 'red' }),
|
|
82
|
+
text(truncate(tool.error, 80), { color: 'red' })
|
|
83
|
+
], { flexDirection: 'row', marginLeft: 2 })
|
|
84
|
+
: box([], {})
|
|
85
|
+
], { flexDirection: 'column', marginLeft: 2 });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function parseJson(raw?: string): Record<string, unknown> | null {
|
|
89
|
+
if (!raw) return null;
|
|
90
|
+
try {
|
|
91
|
+
const data = JSON.parse(raw) as Record<string, unknown>;
|
|
92
|
+
if (data && typeof data === 'object') return data;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function renderDiffLines(diff: string, maxLines = 12): LayoutNode {
|
|
100
|
+
const lines = diff.split('\n').slice(0, maxLines);
|
|
101
|
+
return box(lines.map(line => {
|
|
102
|
+
if (line.startsWith('+')) {
|
|
103
|
+
return text(line, { color: 'green' });
|
|
104
|
+
}
|
|
105
|
+
if (line.startsWith('-')) {
|
|
106
|
+
return text(line, { color: 'red' });
|
|
107
|
+
}
|
|
108
|
+
return text(line, { color: 'gray', dimColor: true });
|
|
109
|
+
}), { flexDirection: 'column', marginLeft: 2 });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function renderToolResult(tool: ToolCall): LayoutNode | null {
|
|
113
|
+
const parsed = parseJson(tool.result);
|
|
114
|
+
if (!parsed) return null;
|
|
115
|
+
|
|
116
|
+
if (tool.name === 'read_file') {
|
|
117
|
+
const path = String(parsed.path || '');
|
|
118
|
+
const size = parsed.size ? `${parsed.size} bytes` : 'unknown size';
|
|
119
|
+
const content = String(parsed.content || '');
|
|
120
|
+
const truncatedFlag = parsed.truncated ? ' (truncated)' : '';
|
|
121
|
+
const previewLines = content.split('\n').slice(0, 6);
|
|
122
|
+
return box([
|
|
123
|
+
box([
|
|
124
|
+
text('→ ', { color: 'green' }),
|
|
125
|
+
text(`Read ${path} (${size})${truncatedFlag}`, { color: 'green' })
|
|
126
|
+
], { flexDirection: 'row', marginLeft: 2 }),
|
|
127
|
+
box(previewLines.map(line => text(line, { color: 'gray' })), { flexDirection: 'column', marginLeft: 4 })
|
|
128
|
+
], { flexDirection: 'column' });
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (tool.name === 'write_file') {
|
|
132
|
+
const path = String(parsed.path || '');
|
|
133
|
+
const action = String(parsed.action || 'written');
|
|
134
|
+
const diff = typeof parsed.diff === 'string' ? parsed.diff : '';
|
|
135
|
+
return box([
|
|
136
|
+
box([
|
|
137
|
+
text('→ ', { color: 'green' }),
|
|
138
|
+
text(`Wrote ${path} (${action})`, { color: 'green' })
|
|
139
|
+
], { flexDirection: 'row', marginLeft: 2 }),
|
|
140
|
+
diff ? renderDiffLines(diff) : box([text('(no diff)', { color: 'gray', dimColor: true })], { marginLeft: 4 })
|
|
141
|
+
], { flexDirection: 'column' });
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (tool.name === 'search') {
|
|
145
|
+
const path = String(parsed.path || '');
|
|
146
|
+
const count = Number(parsed.count || 0);
|
|
147
|
+
const matches = Array.isArray(parsed.matches) ? parsed.matches : [];
|
|
148
|
+
const preview = matches.slice(0, 6).map((entry: unknown) => {
|
|
149
|
+
if (entry && typeof entry === 'object') {
|
|
150
|
+
const row = entry as Record<string, unknown>;
|
|
151
|
+
const file = String(row.path || '');
|
|
152
|
+
const line = row.line ? `:${row.line}` : '';
|
|
153
|
+
const textValue = String(row.text || '');
|
|
154
|
+
return `${file}${line} ${textValue}`.trim();
|
|
155
|
+
}
|
|
156
|
+
return '';
|
|
157
|
+
}).filter(Boolean);
|
|
158
|
+
return box([
|
|
159
|
+
box([
|
|
160
|
+
text('→ ', { color: 'green' }),
|
|
161
|
+
text(`Found ${count} matches${path ? ` in ${path}` : ''}`, { color: 'green' })
|
|
162
|
+
], { flexDirection: 'row', marginLeft: 2 }),
|
|
163
|
+
box(preview.map(line => text(line, { color: 'gray' })), { flexDirection: 'column', marginLeft: 4 })
|
|
164
|
+
], { flexDirection: 'column' });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (tool.name === 'list_directory') {
|
|
168
|
+
const path = String(parsed.path || '');
|
|
169
|
+
const entries = Array.isArray(parsed.entries) ? parsed.entries : [];
|
|
170
|
+
const names = entries
|
|
171
|
+
.map(entry => entry && typeof entry === 'object' && 'name' in entry ? String((entry as Record<string, unknown>).name) : '')
|
|
172
|
+
.filter(Boolean)
|
|
173
|
+
.slice(0, 8);
|
|
174
|
+
return box([
|
|
175
|
+
box([
|
|
176
|
+
text('→ ', { color: 'green' }),
|
|
177
|
+
text(`Listed ${path} (${entries.length} items)`, { color: 'green' })
|
|
178
|
+
], { flexDirection: 'row', marginLeft: 2 }),
|
|
179
|
+
box(names.map(name => text(`- ${name}`, { color: 'gray' })), { flexDirection: 'column', marginLeft: 4 })
|
|
180
|
+
], { flexDirection: 'column' });
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function renderInlineMarkdown(line: string): LayoutNode {
|
|
187
|
+
const parts: Array<{ text: string; bold?: boolean; dim?: boolean }> = [];
|
|
188
|
+
let rest = line;
|
|
189
|
+
let matchedBold = false;
|
|
190
|
+
|
|
191
|
+
const pushPlain = (text: string) => {
|
|
192
|
+
if (text) parts.push({ text });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
while (rest.length > 0) {
|
|
196
|
+
const boldStart = rest.indexOf('**');
|
|
197
|
+
if (boldStart === -1) {
|
|
198
|
+
pushPlain(rest);
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
pushPlain(rest.slice(0, boldStart));
|
|
202
|
+
const afterStart = rest.slice(boldStart + 2);
|
|
203
|
+
const boldEnd = afterStart.indexOf('**');
|
|
204
|
+
if (boldEnd === -1) {
|
|
205
|
+
pushPlain(rest);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
const boldText = afterStart.slice(0, boldEnd);
|
|
209
|
+
if (boldText) {
|
|
210
|
+
matchedBold = true;
|
|
211
|
+
parts.push({ text: boldText, bold: true });
|
|
212
|
+
}
|
|
213
|
+
rest = afterStart.slice(boldEnd + 2);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (!matchedBold && line.includes('**')) {
|
|
217
|
+
return text(line.replace(/\*\*/g, ''), {});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return box(
|
|
221
|
+
parts.map(part => text(part.text, { bold: part.bold, dimColor: part.dim })),
|
|
222
|
+
{ flexDirection: 'row' }
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function renderMarkdownLine(line: string): LayoutNode {
|
|
227
|
+
const trimmed = line.trimStart();
|
|
228
|
+
if (trimmed.startsWith('### ')) {
|
|
229
|
+
return text(trimmed.slice(4), { bold: true, color: 'cyan' });
|
|
230
|
+
}
|
|
231
|
+
if (trimmed.startsWith('## ')) {
|
|
232
|
+
return text(trimmed.slice(3), { bold: true, color: 'cyan' });
|
|
233
|
+
}
|
|
234
|
+
if (trimmed.startsWith('# ')) {
|
|
235
|
+
return text(trimmed.slice(2), { bold: true, color: 'cyan' });
|
|
236
|
+
}
|
|
237
|
+
return renderInlineMarkdown(line);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function isTableSeparator(line: string): boolean {
|
|
241
|
+
const trimmed = line.trim();
|
|
242
|
+
return trimmed.startsWith('|') && trimmed.endsWith('|') && /^[|\-\s:]+$/.test(trimmed);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function splitTableRow(line: string): string[] {
|
|
246
|
+
const trimmed = line.trim();
|
|
247
|
+
const parts = trimmed.replace(/^\|/, '').replace(/\|$/, '').split('|');
|
|
248
|
+
return parts.map(part => part.replace(/\*\*/g, '').trim());
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function renderTable(lines: string[]): LayoutNode[] {
|
|
252
|
+
if (lines.length < 2) return [];
|
|
253
|
+
const header = splitTableRow(lines[0]);
|
|
254
|
+
const rows = lines.slice(2).map(splitTableRow);
|
|
255
|
+
const allRows = [header, ...rows];
|
|
256
|
+
const widths: number[] = [];
|
|
257
|
+
allRows.forEach(row => {
|
|
258
|
+
row.forEach((cell, idx) => {
|
|
259
|
+
const len = cell.length;
|
|
260
|
+
widths[idx] = Math.max(widths[idx] || 0, len);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const formatRow = (row: string[]) => {
|
|
265
|
+
const cells = row.map((cell, idx) => cell.padEnd(widths[idx] || 0));
|
|
266
|
+
return `| ${cells.join(' | ')} |`;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const rendered: LayoutNode[] = [];
|
|
270
|
+
rendered.push(text(formatRow(header), { bold: true }));
|
|
271
|
+
const sep = `| ${widths.map(w => '-'.repeat(Math.max(3, w))).join(' | ')} |`;
|
|
272
|
+
rendered.push(text(sep, { color: 'gray', dimColor: true }));
|
|
273
|
+
rows.forEach(row => {
|
|
274
|
+
rendered.push(text(formatRow(row), { color: 'gray' }));
|
|
275
|
+
});
|
|
276
|
+
return rendered;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function renderMarkdownLines(lines: string[]): LayoutNode[] {
|
|
280
|
+
const normalized: string[] = [];
|
|
281
|
+
lines.forEach(line => {
|
|
282
|
+
if (line.includes('||') && line.includes('|')) {
|
|
283
|
+
const segments = line.split('||').map(segment => segment.trim()).filter(Boolean);
|
|
284
|
+
segments.forEach(segment => {
|
|
285
|
+
let out = segment;
|
|
286
|
+
if (!out.startsWith('|')) out = `| ${out}`;
|
|
287
|
+
if (!out.endsWith('|')) out = `${out} |`;
|
|
288
|
+
normalized.push(out);
|
|
289
|
+
});
|
|
290
|
+
} else {
|
|
291
|
+
normalized.push(line);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
const nodes: LayoutNode[] = [];
|
|
296
|
+
let i = 0;
|
|
297
|
+
while (i < normalized.length) {
|
|
298
|
+
const line = normalized[i];
|
|
299
|
+
const next = normalized[i + 1];
|
|
300
|
+
if (line && next && line.includes('|') && isTableSeparator(next)) {
|
|
301
|
+
const tableLines: string[] = [line, next];
|
|
302
|
+
let j = i + 2;
|
|
303
|
+
while (j < normalized.length && normalized[j].includes('|')) {
|
|
304
|
+
tableLines.push(normalized[j]);
|
|
305
|
+
j += 1;
|
|
306
|
+
}
|
|
307
|
+
nodes.push(...renderTable(tableLines));
|
|
308
|
+
i = j;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
nodes.push(renderMarkdownLine(line));
|
|
312
|
+
i += 1;
|
|
313
|
+
}
|
|
314
|
+
return nodes;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function messageView(message: Message, expandToolOutputs = false): LayoutNode {
|
|
318
|
+
const config = roleConfigs[message.role];
|
|
319
|
+
const toolOutput = message.metadata && (message.metadata as Record<string, any>).toolOutput;
|
|
320
|
+
const content = toolOutput && expandToolOutputs && toolOutput.full
|
|
321
|
+
? toolOutput.full
|
|
322
|
+
: toolOutput && toolOutput.preview
|
|
323
|
+
? toolOutput.preview
|
|
324
|
+
: message.content;
|
|
325
|
+
const lines = content.split('\n');
|
|
326
|
+
|
|
327
|
+
return box([
|
|
328
|
+
box([
|
|
329
|
+
text(`${config.icon} ${config.label}`, { color: config.color, bold: true }),
|
|
330
|
+
text(` • ${formatTime(message.timestamp)}`, { color: 'gray', dimColor: true }),
|
|
331
|
+
message.isStreaming ? text(' ▌', { color: 'yellow', bold: true }) : text('', {})
|
|
332
|
+
], { flexDirection: 'row' }),
|
|
333
|
+
box(renderMarkdownLines(lines), { flexDirection: 'column', marginLeft: 2 }),
|
|
334
|
+
message.toolCalls && message.toolCalls.length > 0
|
|
335
|
+
? box(message.toolCalls.map(tool => toolCallView(tool)), { flexDirection: 'column' })
|
|
336
|
+
: box([], {})
|
|
337
|
+
], { flexDirection: 'column', marginY: 1 });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function estimateMessageLines(message: Message): number {
|
|
341
|
+
const toolOutput = message.metadata && (message.metadata as Record<string, any>).toolOutput;
|
|
342
|
+
const content = toolOutput && toolOutput.preview ? toolOutput.preview : message.content;
|
|
343
|
+
const contentLines = content.split('\n').length;
|
|
344
|
+
const toolLines = message.toolCalls ? message.toolCalls.length * 3 : 0;
|
|
345
|
+
const headerLines = 1;
|
|
346
|
+
const margins = 2;
|
|
347
|
+
return headerLines + contentLines + toolLines + margins;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function clipMessage(message: Message, available: number): Message | null {
|
|
351
|
+
if (available <= 0) return null;
|
|
352
|
+
const headerLines = 1;
|
|
353
|
+
const margins = 2;
|
|
354
|
+
const remaining = available - headerLines - margins;
|
|
355
|
+
if (remaining <= 0) return null;
|
|
356
|
+
|
|
357
|
+
const toolOutput = message.metadata && (message.metadata as Record<string, any>).toolOutput;
|
|
358
|
+
const content = toolOutput && toolOutput.preview ? toolOutput.preview : message.content;
|
|
359
|
+
const lines = content.split('\n');
|
|
360
|
+
if (lines.length <= remaining) {
|
|
361
|
+
return message;
|
|
362
|
+
}
|
|
363
|
+
const clippedLines = lines.slice(-remaining);
|
|
364
|
+
if (clippedLines.length > 0) {
|
|
365
|
+
clippedLines[0] = `... ${clippedLines[0]}`;
|
|
366
|
+
}
|
|
367
|
+
return {
|
|
368
|
+
...message,
|
|
369
|
+
content: clippedLines.join('\n'),
|
|
370
|
+
toolCalls: []
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
interface MessageListProps {
|
|
375
|
+
messages: Message[];
|
|
376
|
+
height: number;
|
|
377
|
+
maxMessages?: number;
|
|
378
|
+
debug?: boolean;
|
|
379
|
+
expandToolOutputs?: boolean;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function buildMessageListView({
|
|
383
|
+
messages,
|
|
384
|
+
height,
|
|
385
|
+
maxMessages = 50,
|
|
386
|
+
debug = false,
|
|
387
|
+
expandToolOutputs = false
|
|
388
|
+
}: MessageListProps): LayoutNode {
|
|
389
|
+
const recentMessages = messages.slice(-maxMessages);
|
|
390
|
+
const visibleMessages: Message[] = [];
|
|
391
|
+
let remaining = height;
|
|
392
|
+
for (let i = recentMessages.length - 1; i >= 0; i -= 1) {
|
|
393
|
+
const msg = recentMessages[i];
|
|
394
|
+
const estimate = estimateMessageLines(msg);
|
|
395
|
+
if (estimate <= remaining) {
|
|
396
|
+
visibleMessages.unshift(msg);
|
|
397
|
+
remaining -= estimate;
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (visibleMessages.length === 0) {
|
|
401
|
+
const clipped = clipMessage(msg, remaining);
|
|
402
|
+
if (clipped) {
|
|
403
|
+
visibleMessages.unshift(clipped);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
break;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
return box([
|
|
410
|
+
box([], { flexGrow: 1 }),
|
|
411
|
+
box(visibleMessages.map(msg => messageView(msg, expandToolOutputs)), { flexDirection: 'column' }),
|
|
412
|
+
messages.length === 0
|
|
413
|
+
? box([text('No messages yet. Type something to begin.', { color: 'gray', dimColor: true })], {
|
|
414
|
+
flexGrow: 1,
|
|
415
|
+
alignItems: 'center',
|
|
416
|
+
justifyContent: 'center'
|
|
417
|
+
})
|
|
418
|
+
: box([], {})
|
|
419
|
+
], {
|
|
420
|
+
flexDirection: 'column',
|
|
421
|
+
height,
|
|
422
|
+
paddingX: 1,
|
|
423
|
+
flexGrow: 1,
|
|
424
|
+
borderStyle: debug ? 'single' : undefined,
|
|
425
|
+
borderColor: debug ? 'gray' : undefined
|
|
426
|
+
});
|
|
427
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { AgentState, AgentStatus } from '../../types.js';
|
|
2
|
+
import { box, text, LayoutNode } from '../core/index.js';
|
|
3
|
+
|
|
4
|
+
interface StatusBarProps {
|
|
5
|
+
state: AgentState;
|
|
6
|
+
sessionId?: string;
|
|
7
|
+
version?: string;
|
|
8
|
+
connectionStatus?: 'connected' | 'disconnected' | 'connecting';
|
|
9
|
+
contextLength?: number;
|
|
10
|
+
contextEstimated?: boolean;
|
|
11
|
+
provider?: string;
|
|
12
|
+
model?: string;
|
|
13
|
+
emulationId?: string;
|
|
14
|
+
toast?: string | null;
|
|
15
|
+
debug?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getStatusConfig(state: AgentState) {
|
|
19
|
+
const configs: Record<AgentStatus, { icon: string; color: string; label: string }> = {
|
|
20
|
+
idle: { icon: '●', color: 'green', label: 'Ready' },
|
|
21
|
+
thinking: { icon: '◐', color: 'yellow', label: 'Thinking' },
|
|
22
|
+
tool_use: { icon: '⚙', color: 'cyan', label: `Tool: ${state.currentTool || 'unknown'}` },
|
|
23
|
+
streaming: { icon: '▸', color: 'magenta', label: 'Streaming' },
|
|
24
|
+
error: { icon: '✗', color: 'red', label: 'Error' }
|
|
25
|
+
};
|
|
26
|
+
return configs[state.status];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function buildStatusBarView({
|
|
30
|
+
state,
|
|
31
|
+
sessionId,
|
|
32
|
+
version = '0.1.0',
|
|
33
|
+
connectionStatus = 'connected',
|
|
34
|
+
contextLength,
|
|
35
|
+
contextEstimated,
|
|
36
|
+
provider,
|
|
37
|
+
model,
|
|
38
|
+
emulationId,
|
|
39
|
+
toast,
|
|
40
|
+
debug = false
|
|
41
|
+
}: StatusBarProps): LayoutNode {
|
|
42
|
+
const config = getStatusConfig(state);
|
|
43
|
+
const isActive = state.status !== 'idle' && state.status !== 'error';
|
|
44
|
+
|
|
45
|
+
const connectionColors = {
|
|
46
|
+
connected: 'green',
|
|
47
|
+
disconnected: 'red',
|
|
48
|
+
connecting: 'yellow'
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
const connectionIcons = {
|
|
52
|
+
connected: '◉',
|
|
53
|
+
disconnected: '◯',
|
|
54
|
+
connecting: '◐'
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const contextLabel = contextLength !== undefined
|
|
58
|
+
? `${contextEstimated ? '~' : ''}ctx ${contextLength.toLocaleString()}`
|
|
59
|
+
: '';
|
|
60
|
+
const toastLabel = toast ? (toast.length > 60 ? `${toast.slice(0, 59)}…` : toast) : '';
|
|
61
|
+
|
|
62
|
+
return box([
|
|
63
|
+
box([
|
|
64
|
+
text(isActive ? '⠋ ' : `${config.icon} `, { color: config.color }),
|
|
65
|
+
text(config.label, { color: config.color }),
|
|
66
|
+
state.error ? text(` - ${state.error}`, { color: 'red' }) : text('', {}),
|
|
67
|
+
toastLabel ? text(' • ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
68
|
+
toastLabel ? text(toastLabel, { color: 'yellow' }) : text('', {})
|
|
69
|
+
], { flexDirection: 'row' }),
|
|
70
|
+
box([
|
|
71
|
+
text(connectionIcons[connectionStatus], { color: connectionColors[connectionStatus] }),
|
|
72
|
+
text(' ', { color: 'gray', dimColor: true }),
|
|
73
|
+
state.authError ? text('auth error', { color: 'red' }) : text('', {}),
|
|
74
|
+
state.authError ? text(' • ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
75
|
+
provider ? text(provider, { color: 'gray', dimColor: true }) : text('', {}),
|
|
76
|
+
provider && model ? text(' / ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
77
|
+
model ? text(model, { color: 'gray', dimColor: true }) : text('', {}),
|
|
78
|
+
(provider || model) ? text(' • ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
79
|
+
emulationId ? text(`emu:${emulationId}`, { color: 'gray', dimColor: true }) : text('', {}),
|
|
80
|
+
emulationId ? text(' • ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
81
|
+
state.tokensUsed !== undefined && state.tokensUsed > 0
|
|
82
|
+
? text(`${state.tokensUsed.toLocaleString()} tok`, { color: 'gray', dimColor: true })
|
|
83
|
+
: text('', {}),
|
|
84
|
+
state.tokensUsed !== undefined && state.tokensUsed > 0
|
|
85
|
+
? text(' • ', { color: 'gray', dimColor: true })
|
|
86
|
+
: text('', {}),
|
|
87
|
+
contextLength !== undefined
|
|
88
|
+
? text(contextLabel, { color: 'gray', dimColor: true })
|
|
89
|
+
: text('', {}),
|
|
90
|
+
contextLength !== undefined
|
|
91
|
+
? text(' • ', { color: 'gray', dimColor: true })
|
|
92
|
+
: text('', {}),
|
|
93
|
+
text(`ZTC v${version}`, { color: 'gray', dimColor: true }),
|
|
94
|
+
sessionId ? text(' • ', { color: 'gray', dimColor: true }) : text('', {}),
|
|
95
|
+
sessionId ? text(sessionId.slice(0, 8), { color: 'gray', dimColor: true }) : text('', {})
|
|
96
|
+
], { flexDirection: 'row' })
|
|
97
|
+
], {
|
|
98
|
+
flexDirection: 'row',
|
|
99
|
+
justifyContent: 'space-between',
|
|
100
|
+
paddingX: 1,
|
|
101
|
+
borderStyle: debug ? 'single' : undefined,
|
|
102
|
+
borderColor: debug ? 'gray' : undefined
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { LayoutNode, TextNode } from '../core/types.js';
|
|
2
|
+
|
|
3
|
+
type VNodeFactory = (type: string, props: Record<string, unknown> | null, children?: unknown) => unknown;
|
|
4
|
+
|
|
5
|
+
function toVueStyle(style?: Record<string, unknown>): Record<string, unknown> {
|
|
6
|
+
return style ? { ...style } : {};
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function renderText(h: VNodeFactory, node: TextNode): unknown {
|
|
10
|
+
const style: Record<string, unknown> = {
|
|
11
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
12
|
+
fontSize: '14px',
|
|
13
|
+
lineHeight: '16px',
|
|
14
|
+
whiteSpace: 'pre'
|
|
15
|
+
};
|
|
16
|
+
if (node.style?.color) style.color = node.style.color;
|
|
17
|
+
if (node.style?.bold) style.fontWeight = 600;
|
|
18
|
+
if (node.style?.dimColor) style.opacity = 0.6;
|
|
19
|
+
if (node.style?.inverse) style.background = '#111';
|
|
20
|
+
|
|
21
|
+
return h('span', { style }, node.text);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function renderToVue(h: VNodeFactory, node: LayoutNode): unknown {
|
|
25
|
+
if (node.type === 'text') {
|
|
26
|
+
return renderText(h, node);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const style = toVueStyle({
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: node.style?.flexDirection || 'column',
|
|
32
|
+
flexGrow: node.style?.flexGrow ?? 0,
|
|
33
|
+
flexShrink: node.style?.flexShrink ?? 0,
|
|
34
|
+
paddingLeft: node.style?.paddingX ?? node.style?.padding ?? 0,
|
|
35
|
+
paddingRight: node.style?.paddingX ?? node.style?.padding ?? 0,
|
|
36
|
+
paddingTop: node.style?.paddingY ?? node.style?.padding ?? 0,
|
|
37
|
+
paddingBottom: node.style?.paddingY ?? node.style?.padding ?? 0,
|
|
38
|
+
marginLeft: node.style?.marginX ?? node.style?.margin ?? 0,
|
|
39
|
+
marginRight: node.style?.marginX ?? node.style?.margin ?? 0,
|
|
40
|
+
marginTop: node.style?.marginY ?? node.style?.margin ?? 0,
|
|
41
|
+
marginBottom: node.style?.marginY ?? node.style?.margin ?? 0
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (node.style?.width !== undefined) style.width = `${node.style.width}px`;
|
|
45
|
+
if (node.style?.height !== undefined) style.height = `${node.style.height}px`;
|
|
46
|
+
if (node.style?.borderStyle) {
|
|
47
|
+
style.borderStyle = node.style.borderStyle;
|
|
48
|
+
style.borderWidth = '1px';
|
|
49
|
+
style.borderColor = node.style.borderColor || 'currentColor';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return h('div', { style }, node.children.map(child => renderToVue(h, child)));
|
|
53
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
|
|
3
|
+
function runPipe(command: string, args: string[], input: string): Promise<void> {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const child = spawn(command, args, { stdio: ['pipe', 'ignore', 'pipe'] });
|
|
6
|
+
let err = '';
|
|
7
|
+
child.stderr.on('data', chunk => {
|
|
8
|
+
err += chunk.toString();
|
|
9
|
+
});
|
|
10
|
+
child.on('error', reject);
|
|
11
|
+
child.on('close', (code) => {
|
|
12
|
+
if (code === 0) resolve();
|
|
13
|
+
else reject(new Error(err || `Clipboard command failed (${command})`));
|
|
14
|
+
});
|
|
15
|
+
child.stdin.write(input);
|
|
16
|
+
child.stdin.end();
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function writeClipboard(text: string): Promise<void> {
|
|
21
|
+
const platform = process.platform;
|
|
22
|
+
if (platform === 'darwin') {
|
|
23
|
+
await runPipe('pbcopy', [], text);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (platform === 'win32') {
|
|
27
|
+
await runPipe('clip', [], text);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await runPipe('wl-copy', [], text);
|
|
33
|
+
return;
|
|
34
|
+
} catch {
|
|
35
|
+
// fall through
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
await runPipe('xclip', ['-selection', 'clipboard'], text);
|
|
39
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { execFile } from 'child_process';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import { mkdir } from 'fs/promises';
|
|
4
|
+
import { homedir } from 'os';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { randomUUID } from 'crypto';
|
|
7
|
+
|
|
8
|
+
const execFileAsync = promisify(execFile);
|
|
9
|
+
|
|
10
|
+
async function hasCommand(command: string): Promise<boolean> {
|
|
11
|
+
try {
|
|
12
|
+
await execFileAsync('which', [command]);
|
|
13
|
+
return true;
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function saveClipboardImage(): Promise<string | null> {
|
|
20
|
+
if (process.platform !== 'darwin') {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const hasPngPaste = await hasCommand('pngpaste');
|
|
25
|
+
if (!hasPngPaste) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const targetDir = join(homedir(), '.ztc', 'clipboard');
|
|
30
|
+
await mkdir(targetDir, { recursive: true });
|
|
31
|
+
const filename = `clipboard-${Date.now()}-${randomUUID().slice(0, 8)}.png`;
|
|
32
|
+
const targetPath = join(targetDir, filename);
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
await execFileAsync('pngpaste', [targetPath]);
|
|
36
|
+
return targetPath;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|