rird 1.0.200
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/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/opencode +336 -0
- package/bin/pty-wrapper.js +285 -0
- package/bunfig.toml +4 -0
- package/facebook_ads_library.png +0 -0
- package/nul`nif +0 -0
- package/package.json +111 -0
- package/parsers-config.ts +239 -0
- package/rird-1.0.199.tgz +0 -0
- package/script/build-windows.ts +54 -0
- package/script/build.ts +167 -0
- package/script/postinstall.mjs +544 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +72 -0
- package/script/schema.ts +47 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1063 -0
- package/src/acp/session.ts +101 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +367 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +10 -0
- package/src/agent/prompt/title.txt +36 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +114 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +88 -0
- package/src/cli/cmd/agent.ts +256 -0
- package/src/cli/cmd/auth.ts +391 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/config.ts +15 -0
- package/src/cli/cmd/debug/file.ts +91 -0
- package/src/cli/cmd/debug/index.ts +43 -0
- package/src/cli/cmd/debug/lsp.ts +48 -0
- package/src/cli/cmd/debug/ripgrep.ts +83 -0
- package/src/cli/cmd/debug/scrap.ts +15 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +48 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1400 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +654 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +368 -0
- package/src/cli/cmd/serve.ts +31 -0
- package/src/cli/cmd/session.ts +106 -0
- package/src/cli/cmd/stats.ts +298 -0
- package/src/cli/cmd/tui/app.tsx +696 -0
- package/src/cli/cmd/tui/attach.ts +30 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +245 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/did-you-know.tsx +85 -0
- package/src/cli/cmd/tui/component/logo.tsx +35 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1090 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/tips.ts +27 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +49 -0
- package/src/cli/cmd/tui/context/local.tsx +354 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +74 -0
- package/src/cli/cmd/tui/context/sync.tsx +372 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +245 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rird.json +245 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1109 -0
- package/src/cli/cmd/tui/event.ts +40 -0
- package/src/cli/cmd/tui/routes/home.tsx +138 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +1864 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +318 -0
- package/src/cli/cmd/tui/spawn.ts +60 -0
- package/src/cli/cmd/tui/thread.ts +142 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +332 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +127 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/worker.ts +63 -0
- package/src/cli/cmd/uninstall.ts +344 -0
- package/src/cli/cmd/upgrade.ts +100 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/error.ts +56 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +80 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +97 -0
- package/src/config/config.ts +995 -0
- package/src/config/markdown.ts +41 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +328 -0
- package/src/file/ripgrep.ts +393 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +103 -0
- package/src/flag/flag.ts +46 -0
- package/src/format/formatter.ts +315 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +52 -0
- package/src/id/id.ts +73 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +240 -0
- package/src/installation/index.ts +239 -0
- package/src/lsp/client.ts +229 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +116 -0
- package/src/lsp/server.ts +1895 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +690 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +622 -0
- package/src/permission/index.ts +199 -0
- package/src/plugin/index.ts +91 -0
- package/src/project/bootstrap.ts +31 -0
- package/src/project/instance.ts +78 -0
- package/src/project/project.ts +221 -0
- package/src/project/state.ts +65 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +143 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +106 -0
- package/src/provider/provider.ts +1071 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +455 -0
- package/src/pty/index.ts +231 -0
- package/src/security/guardrails.test.ts +341 -0
- package/src/security/guardrails.ts +558 -0
- package/src/security/index.ts +19 -0
- package/src/server/error.ts +36 -0
- package/src/server/project.ts +79 -0
- package/src/server/server.ts +2642 -0
- package/src/server/tui.ts +71 -0
- package/src/session/compaction.ts +223 -0
- package/src/session/index.ts +461 -0
- package/src/session/llm.ts +201 -0
- package/src/session/message-v2.ts +690 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +409 -0
- package/src/session/prompt/act-switch.txt +5 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +85 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +103 -0
- package/src/session/prompt/codex.txt +304 -0
- package/src/session/prompt/copilot-gpt-5.txt +138 -0
- package/src/session/prompt/gemini.txt +85 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
- package/src/session/prompt/plan.txt +24 -0
- package/src/session/prompt/polaris.txt +84 -0
- package/src/session/prompt/qwen.txt +106 -0
- package/src/session/prompt.ts +1509 -0
- package/src/session/retry.ts +86 -0
- package/src/session/revert.ts +108 -0
- package/src/session/sensitive-filter.test.ts +327 -0
- package/src/session/sensitive-filter.ts +466 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +194 -0
- package/src/session/system.ts +120 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +194 -0
- package/src/share/share.ts +87 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +83 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tests/agent.test.ts +308 -0
- package/src/tests/build-guards.test.ts +267 -0
- package/src/tests/config.test.ts +664 -0
- package/src/tests/tool-registry.test.ts +589 -0
- package/src/tool/bash.ts +317 -0
- package/src/tool/bash.txt +158 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +168 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +675 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +121 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp-diagnostics.ts +26 -0
- package/src/tool/lsp-diagnostics.txt +1 -0
- package/src/tool/lsp-hover.ts +31 -0
- package/src/tool/lsp-hover.txt +1 -0
- package/src/tool/lsp.ts +87 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/patch.ts +233 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +219 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +162 -0
- package/src/tool/skill.ts +100 -0
- package/src/tool/task.ts +136 -0
- package/src/tool/task.txt +51 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +71 -0
- package/src/tool/webfetch.ts +198 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +180 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +110 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +83 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +102 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/license.ts +325 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +42 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +54 -0
- package/sst-env.d.ts +9 -0
- package/test/agent/agent.test.ts +146 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +535 -0
- package/test/config/markdown.test.ts +89 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/fixture/fixture.ts +36 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/preload.ts +57 -0
- package/test/project/project.test.ts +72 -0
- package/test/provider/provider.test.ts +1809 -0
- package/test/provider/transform.test.ts +411 -0
- package/test/session/retry.test.ts +111 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +131 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/bash.test.ts +434 -0
- package/test/tool/grep.test.ts +108 -0
- package/test/tool/patch.test.ts +259 -0
- package/test/tool/read.test.ts +42 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +55 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,1864 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
createEffect,
|
|
4
|
+
createMemo,
|
|
5
|
+
createSignal,
|
|
6
|
+
For,
|
|
7
|
+
Match,
|
|
8
|
+
on,
|
|
9
|
+
Show,
|
|
10
|
+
Switch,
|
|
11
|
+
useContext,
|
|
12
|
+
type Component,
|
|
13
|
+
} from "solid-js"
|
|
14
|
+
import { Dynamic } from "solid-js/web"
|
|
15
|
+
import path from "path"
|
|
16
|
+
import { useRoute, useRouteData } from "@tui/context/route"
|
|
17
|
+
import { useSync } from "@tui/context/sync"
|
|
18
|
+
import { SplitBorder } from "@tui/component/border"
|
|
19
|
+
import { useTheme } from "@tui/context/theme"
|
|
20
|
+
import {
|
|
21
|
+
BoxRenderable,
|
|
22
|
+
ScrollBoxRenderable,
|
|
23
|
+
addDefaultParsers,
|
|
24
|
+
MacOSScrollAccel,
|
|
25
|
+
type ScrollAcceleration,
|
|
26
|
+
} from "@opentui/core"
|
|
27
|
+
import { Prompt, type PromptRef } from "@tui/component/prompt"
|
|
28
|
+
import type { AssistantMessage, Part, ToolPart, UserMessage, TextPart, ReasoningPart } from "@opencode-ai/sdk/v2"
|
|
29
|
+
import { useLocal } from "@tui/context/local"
|
|
30
|
+
import { Locale } from "@/util/locale"
|
|
31
|
+
import type { Tool } from "@/tool/tool"
|
|
32
|
+
import type { ReadTool } from "@/tool/read"
|
|
33
|
+
import type { WriteTool } from "@/tool/write"
|
|
34
|
+
import { BashTool } from "@/tool/bash"
|
|
35
|
+
import type { GlobTool } from "@/tool/glob"
|
|
36
|
+
import { TodoWriteTool } from "@/tool/todo"
|
|
37
|
+
import type { GrepTool } from "@/tool/grep"
|
|
38
|
+
import type { ListTool } from "@/tool/ls"
|
|
39
|
+
import type { EditTool } from "@/tool/edit"
|
|
40
|
+
import type { PatchTool } from "@/tool/patch"
|
|
41
|
+
import type { WebFetchTool } from "@/tool/webfetch"
|
|
42
|
+
import type { TaskTool } from "@/tool/task"
|
|
43
|
+
import { useKeyboard, useRenderer, useTerminalDimensions, type BoxProps, type JSX } from "@opentui/solid"
|
|
44
|
+
import { useSDK } from "@tui/context/sdk"
|
|
45
|
+
import { useCommandDialog } from "@tui/component/dialog-command"
|
|
46
|
+
import { useKeybind } from "@tui/context/keybind"
|
|
47
|
+
import { Header } from "./header"
|
|
48
|
+
import { parsePatch } from "diff"
|
|
49
|
+
import { useDialog } from "../../ui/dialog"
|
|
50
|
+
import { TodoItem } from "../../component/todo-item"
|
|
51
|
+
import { DialogMessage } from "./dialog-message"
|
|
52
|
+
import type { PromptInfo } from "../../component/prompt/history"
|
|
53
|
+
import { iife } from "@/util/iife"
|
|
54
|
+
import { DialogConfirm } from "@tui/ui/dialog-confirm"
|
|
55
|
+
import { DialogPrompt } from "@tui/ui/dialog-prompt"
|
|
56
|
+
import { DialogTimeline } from "./dialog-timeline"
|
|
57
|
+
import { DialogForkFromTimeline } from "./dialog-fork-from-timeline"
|
|
58
|
+
import { DialogSessionRename } from "../../component/dialog-session-rename"
|
|
59
|
+
import { Sidebar } from "./sidebar"
|
|
60
|
+
import { LANGUAGE_EXTENSIONS } from "@/lsp/language"
|
|
61
|
+
import parsers from "../../../../../../parsers-config.ts"
|
|
62
|
+
import { Clipboard } from "../../util/clipboard"
|
|
63
|
+
import { Toast, useToast } from "../../ui/toast"
|
|
64
|
+
import { useKV } from "../../context/kv.tsx"
|
|
65
|
+
import { Editor } from "../../util/editor"
|
|
66
|
+
import stripAnsi from "strip-ansi"
|
|
67
|
+
import { Footer } from "./footer.tsx"
|
|
68
|
+
import { usePromptRef } from "../../context/prompt"
|
|
69
|
+
import { Filesystem } from "@/util/filesystem"
|
|
70
|
+
import { DialogSubagent } from "./dialog-subagent.tsx"
|
|
71
|
+
|
|
72
|
+
addDefaultParsers(parsers.parsers)
|
|
73
|
+
|
|
74
|
+
class CustomSpeedScroll implements ScrollAcceleration {
|
|
75
|
+
constructor(private speed: number) {}
|
|
76
|
+
|
|
77
|
+
tick(_now?: number): number {
|
|
78
|
+
return this.speed
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
reset(): void {}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const context = createContext<{
|
|
85
|
+
width: number
|
|
86
|
+
conceal: () => boolean
|
|
87
|
+
showThinking: () => boolean
|
|
88
|
+
showTimestamps: () => boolean
|
|
89
|
+
usernameVisible: () => boolean
|
|
90
|
+
showDetails: () => boolean
|
|
91
|
+
userMessageMarkdown: () => boolean
|
|
92
|
+
diffWrapMode: () => "word" | "none"
|
|
93
|
+
sync: ReturnType<typeof useSync>
|
|
94
|
+
}>()
|
|
95
|
+
|
|
96
|
+
function use() {
|
|
97
|
+
const ctx = useContext(context)
|
|
98
|
+
if (!ctx) throw new Error("useContext must be used within a Session component")
|
|
99
|
+
return ctx
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function Session() {
|
|
103
|
+
const route = useRouteData("session")
|
|
104
|
+
const { navigate } = useRoute()
|
|
105
|
+
const sync = useSync()
|
|
106
|
+
const kv = useKV()
|
|
107
|
+
const { theme } = useTheme()
|
|
108
|
+
const promptRef = usePromptRef()
|
|
109
|
+
const session = createMemo(() => sync.session.get(route.sessionID)!)
|
|
110
|
+
const messages = createMemo(() => sync.data.message[route.sessionID] ?? [])
|
|
111
|
+
const permissions = createMemo(() => sync.data.permission[route.sessionID] ?? [])
|
|
112
|
+
|
|
113
|
+
const pending = createMemo(() => {
|
|
114
|
+
return messages().findLast((x) => x.role === "assistant" && !x.time.completed)?.id
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const lastAssistant = createMemo(() => {
|
|
118
|
+
return messages().findLast((x) => x.role === "assistant")
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
const dimensions = useTerminalDimensions()
|
|
122
|
+
const [sidebar, setSidebar] = createSignal<"show" | "hide" | "auto">(kv.get("sidebar", "auto"))
|
|
123
|
+
const [conceal, setConceal] = createSignal(true)
|
|
124
|
+
const [showThinking, setShowThinking] = createSignal(kv.get("thinking_visibility", true))
|
|
125
|
+
const [showTimestamps, setShowTimestamps] = createSignal(kv.get("timestamps", "hide") === "show")
|
|
126
|
+
const [usernameVisible, setUsernameVisible] = createSignal(kv.get("username_visible", true))
|
|
127
|
+
const [showDetails, setShowDetails] = createSignal(kv.get("tool_details_visibility", true))
|
|
128
|
+
const [showScrollbar, setShowScrollbar] = createSignal(kv.get("scrollbar_visible", false))
|
|
129
|
+
const [userMessageMarkdown, setUserMessageMarkdown] = createSignal(kv.get("user_message_markdown", true))
|
|
130
|
+
const [diffWrapMode, setDiffWrapMode] = createSignal<"word" | "none">("word")
|
|
131
|
+
|
|
132
|
+
const wide = createMemo(() => dimensions().width > 120)
|
|
133
|
+
const sidebarVisible = createMemo(() => {
|
|
134
|
+
if (session()?.parentID) return false
|
|
135
|
+
if (sidebar() === "show") return true
|
|
136
|
+
if (sidebar() === "auto" && wide()) return true
|
|
137
|
+
return false
|
|
138
|
+
})
|
|
139
|
+
const contentWidth = createMemo(() => dimensions().width - (sidebarVisible() ? 42 : 0) - 4)
|
|
140
|
+
|
|
141
|
+
const scrollAcceleration = createMemo(() => {
|
|
142
|
+
const tui = sync.data.config.tui
|
|
143
|
+
if (tui?.scroll_acceleration?.enabled) {
|
|
144
|
+
return new MacOSScrollAccel()
|
|
145
|
+
}
|
|
146
|
+
if (tui?.scroll_speed) {
|
|
147
|
+
return new CustomSpeedScroll(tui.scroll_speed)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return new CustomSpeedScroll(3)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
createEffect(async () => {
|
|
154
|
+
await sync.session
|
|
155
|
+
.sync(route.sessionID)
|
|
156
|
+
.then(() => {
|
|
157
|
+
if (scroll) scroll.scrollBy(100_000)
|
|
158
|
+
})
|
|
159
|
+
.catch((e) => {
|
|
160
|
+
console.error(e)
|
|
161
|
+
toast.show({
|
|
162
|
+
message: `Session not found: ${route.sessionID}`,
|
|
163
|
+
variant: "error",
|
|
164
|
+
})
|
|
165
|
+
return navigate({ type: "home" })
|
|
166
|
+
})
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const toast = useToast()
|
|
170
|
+
const sdk = useSDK()
|
|
171
|
+
|
|
172
|
+
// Handle initial prompt from fork
|
|
173
|
+
createEffect(() => {
|
|
174
|
+
if (route.initialPrompt && prompt) {
|
|
175
|
+
prompt.set(route.initialPrompt)
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
// Auto-navigate to whichever session currently needs permission input
|
|
180
|
+
createEffect(() => {
|
|
181
|
+
const currentSession = session()
|
|
182
|
+
if (!currentSession) return
|
|
183
|
+
const currentPermissions = permissions()
|
|
184
|
+
let targetID = currentPermissions.length > 0 ? currentSession.id : undefined
|
|
185
|
+
|
|
186
|
+
if (!targetID) {
|
|
187
|
+
const child = sync.data.session.find(
|
|
188
|
+
(x) => x.parentID === currentSession.id && (sync.data.permission[x.id]?.length ?? 0) > 0,
|
|
189
|
+
)
|
|
190
|
+
if (child) targetID = child.id
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (targetID && targetID !== currentSession.id) {
|
|
194
|
+
navigate({
|
|
195
|
+
type: "session",
|
|
196
|
+
sessionID: targetID,
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
let scroll: ScrollBoxRenderable
|
|
202
|
+
let prompt: PromptRef
|
|
203
|
+
const keybind = useKeybind()
|
|
204
|
+
|
|
205
|
+
// Helper: Find next visible message boundary in direction
|
|
206
|
+
const findNextVisibleMessage = (direction: "next" | "prev"): string | null => {
|
|
207
|
+
const children = scroll.getChildren()
|
|
208
|
+
const messagesList = messages()
|
|
209
|
+
const scrollTop = scroll.y
|
|
210
|
+
|
|
211
|
+
// Get visible messages sorted by position, filtering for valid non-synthetic, non-ignored content
|
|
212
|
+
const visibleMessages = children
|
|
213
|
+
.filter((c) => {
|
|
214
|
+
if (!c.id) return false
|
|
215
|
+
const message = messagesList.find((m) => m.id === c.id)
|
|
216
|
+
if (!message) return false
|
|
217
|
+
|
|
218
|
+
// Check if message has valid non-synthetic, non-ignored text parts
|
|
219
|
+
const parts = sync.data.part[message.id]
|
|
220
|
+
if (!parts || !Array.isArray(parts)) return false
|
|
221
|
+
|
|
222
|
+
return parts.some((part) => part && part.type === "text" && !part.synthetic && !part.ignored)
|
|
223
|
+
})
|
|
224
|
+
.sort((a, b) => a.y - b.y)
|
|
225
|
+
|
|
226
|
+
if (visibleMessages.length === 0) return null
|
|
227
|
+
|
|
228
|
+
if (direction === "next") {
|
|
229
|
+
// Find first message below current position
|
|
230
|
+
return visibleMessages.find((c) => c.y > scrollTop + 10)?.id ?? null
|
|
231
|
+
}
|
|
232
|
+
// Find last message above current position
|
|
233
|
+
return [...visibleMessages].reverse().find((c) => c.y < scrollTop - 10)?.id ?? null
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Helper: Scroll to message in direction or fallback to page scroll
|
|
237
|
+
const scrollToMessage = (direction: "next" | "prev", dialog: ReturnType<typeof useDialog>) => {
|
|
238
|
+
const targetID = findNextVisibleMessage(direction)
|
|
239
|
+
|
|
240
|
+
if (!targetID) {
|
|
241
|
+
scroll.scrollBy(direction === "next" ? scroll.height : -scroll.height)
|
|
242
|
+
dialog.clear()
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const child = scroll.getChildren().find((c) => c.id === targetID)
|
|
247
|
+
if (child) scroll.scrollBy(child.y - scroll.y - 1)
|
|
248
|
+
dialog.clear()
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
useKeyboard((evt) => {
|
|
252
|
+
if (dialog.stack.length > 0) return
|
|
253
|
+
|
|
254
|
+
const first = permissions()[0]
|
|
255
|
+
if (first) {
|
|
256
|
+
const response = iife(() => {
|
|
257
|
+
if (evt.ctrl || evt.meta) return
|
|
258
|
+
if (evt.name === "return") return "once"
|
|
259
|
+
if (evt.name === "a") return "always"
|
|
260
|
+
if (evt.name === "d") return "reject"
|
|
261
|
+
if (evt.name === "escape") return "reject"
|
|
262
|
+
return
|
|
263
|
+
})
|
|
264
|
+
if (response) {
|
|
265
|
+
sdk.client.permission.respond({
|
|
266
|
+
permissionID: first.id,
|
|
267
|
+
sessionID: route.sessionID,
|
|
268
|
+
response: response,
|
|
269
|
+
})
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
function toBottom() {
|
|
275
|
+
setTimeout(() => {
|
|
276
|
+
if (scroll) scroll.scrollTo(scroll.scrollHeight)
|
|
277
|
+
}, 50)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const local = useLocal()
|
|
281
|
+
|
|
282
|
+
function moveChild(direction: number) {
|
|
283
|
+
const parentID = session()?.parentID ?? session()?.id
|
|
284
|
+
let children = sync.data.session
|
|
285
|
+
.filter((x) => x.parentID === parentID || x.id === parentID)
|
|
286
|
+
.toSorted((a, b) => (a.id < b.id ? -1 : a.id > b.id ? 1 : 0))
|
|
287
|
+
if (children.length === 1) return
|
|
288
|
+
let next = children.findIndex((x) => x.id === session()?.id) + direction
|
|
289
|
+
if (next >= children.length) next = 0
|
|
290
|
+
if (next < 0) next = children.length - 1
|
|
291
|
+
if (children[next]) {
|
|
292
|
+
navigate({
|
|
293
|
+
type: "session",
|
|
294
|
+
sessionID: children[next].id,
|
|
295
|
+
})
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const command = useCommandDialog()
|
|
300
|
+
command.register(() => [
|
|
301
|
+
...(sync.data.config.share !== "disabled"
|
|
302
|
+
? [
|
|
303
|
+
{
|
|
304
|
+
title: "Share session",
|
|
305
|
+
value: "session.share",
|
|
306
|
+
suggested: route.type === "session",
|
|
307
|
+
keybind: "session_share" as const,
|
|
308
|
+
disabled: !!session()?.share?.url,
|
|
309
|
+
category: "Session",
|
|
310
|
+
onSelect: async (dialog: any) => {
|
|
311
|
+
await sdk.client.session
|
|
312
|
+
.share({
|
|
313
|
+
sessionID: route.sessionID,
|
|
314
|
+
})
|
|
315
|
+
.then((res) =>
|
|
316
|
+
Clipboard.copy(res.data!.share!.url).catch(() =>
|
|
317
|
+
toast.show({ message: "Failed to copy URL to clipboard", variant: "error" }),
|
|
318
|
+
),
|
|
319
|
+
)
|
|
320
|
+
.then(() => toast.show({ message: "Share URL copied to clipboard!", variant: "success" }))
|
|
321
|
+
.catch(() => toast.show({ message: "Failed to share session", variant: "error" }))
|
|
322
|
+
dialog.clear()
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
]
|
|
326
|
+
: []),
|
|
327
|
+
{
|
|
328
|
+
title: "Rename session",
|
|
329
|
+
value: "session.rename",
|
|
330
|
+
keybind: "session_rename",
|
|
331
|
+
category: "Session",
|
|
332
|
+
onSelect: (dialog) => {
|
|
333
|
+
dialog.replace(() => <DialogSessionRename session={route.sessionID} />)
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
{
|
|
337
|
+
title: "Jump to message",
|
|
338
|
+
value: "session.timeline",
|
|
339
|
+
keybind: "session_timeline",
|
|
340
|
+
category: "Session",
|
|
341
|
+
onSelect: (dialog) => {
|
|
342
|
+
dialog.replace(() => (
|
|
343
|
+
<DialogTimeline
|
|
344
|
+
onMove={(messageID) => {
|
|
345
|
+
const child = scroll.getChildren().find((child) => {
|
|
346
|
+
return child.id === messageID
|
|
347
|
+
})
|
|
348
|
+
if (child) scroll.scrollBy(child.y - scroll.y - 1)
|
|
349
|
+
}}
|
|
350
|
+
sessionID={route.sessionID}
|
|
351
|
+
setPrompt={(promptInfo) => prompt.set(promptInfo)}
|
|
352
|
+
/>
|
|
353
|
+
))
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
title: "Fork from message",
|
|
358
|
+
value: "session.fork",
|
|
359
|
+
keybind: "session_fork",
|
|
360
|
+
category: "Session",
|
|
361
|
+
onSelect: (dialog) => {
|
|
362
|
+
dialog.replace(() => (
|
|
363
|
+
<DialogForkFromTimeline
|
|
364
|
+
onMove={(messageID) => {
|
|
365
|
+
const child = scroll.getChildren().find((child) => {
|
|
366
|
+
return child.id === messageID
|
|
367
|
+
})
|
|
368
|
+
if (child) scroll.scrollBy(child.y - scroll.y - 1)
|
|
369
|
+
}}
|
|
370
|
+
sessionID={route.sessionID}
|
|
371
|
+
/>
|
|
372
|
+
))
|
|
373
|
+
},
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
title: "Compact session",
|
|
377
|
+
value: "session.compact",
|
|
378
|
+
keybind: "session_compact",
|
|
379
|
+
category: "Session",
|
|
380
|
+
onSelect: (dialog) => {
|
|
381
|
+
const selectedModel = local.model.current()
|
|
382
|
+
if (!selectedModel) {
|
|
383
|
+
toast.show({
|
|
384
|
+
variant: "warning",
|
|
385
|
+
message: "Connect a provider to summarize this session",
|
|
386
|
+
duration: 3000,
|
|
387
|
+
})
|
|
388
|
+
return
|
|
389
|
+
}
|
|
390
|
+
sdk.client.session.summarize({
|
|
391
|
+
sessionID: route.sessionID,
|
|
392
|
+
modelID: selectedModel.modelID,
|
|
393
|
+
providerID: selectedModel.providerID,
|
|
394
|
+
})
|
|
395
|
+
dialog.clear()
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
title: "Unshare session",
|
|
400
|
+
value: "session.unshare",
|
|
401
|
+
keybind: "session_unshare",
|
|
402
|
+
disabled: !session()?.share?.url,
|
|
403
|
+
category: "Session",
|
|
404
|
+
onSelect: async (dialog) => {
|
|
405
|
+
await sdk.client.session
|
|
406
|
+
.unshare({
|
|
407
|
+
sessionID: route.sessionID,
|
|
408
|
+
})
|
|
409
|
+
.then(() => toast.show({ message: "Session unshared successfully", variant: "success" }))
|
|
410
|
+
.catch(() => toast.show({ message: "Failed to unshare session", variant: "error" }))
|
|
411
|
+
dialog.clear()
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
title: "Undo previous message",
|
|
416
|
+
value: "session.undo",
|
|
417
|
+
keybind: "messages_undo",
|
|
418
|
+
category: "Session",
|
|
419
|
+
onSelect: async (dialog) => {
|
|
420
|
+
const status = sync.data.session_status?.[route.sessionID]
|
|
421
|
+
if (status?.type !== "idle") await sdk.client.session.abort({ sessionID: route.sessionID }).catch(() => {})
|
|
422
|
+
const revert = session().revert?.messageID
|
|
423
|
+
const message = messages().findLast((x) => (!revert || x.id < revert) && x.role === "user")
|
|
424
|
+
if (!message) return
|
|
425
|
+
sdk.client.session
|
|
426
|
+
.revert({
|
|
427
|
+
sessionID: route.sessionID,
|
|
428
|
+
messageID: message.id,
|
|
429
|
+
})
|
|
430
|
+
.then(() => {
|
|
431
|
+
toBottom()
|
|
432
|
+
})
|
|
433
|
+
const parts = sync.data.part[message.id]
|
|
434
|
+
prompt.set(
|
|
435
|
+
parts.reduce(
|
|
436
|
+
(agg, part) => {
|
|
437
|
+
if (part.type === "text") {
|
|
438
|
+
if (!part.synthetic) agg.input += part.text
|
|
439
|
+
}
|
|
440
|
+
if (part.type === "file") agg.parts.push(part)
|
|
441
|
+
return agg
|
|
442
|
+
},
|
|
443
|
+
{ input: "", parts: [] as PromptInfo["parts"] },
|
|
444
|
+
),
|
|
445
|
+
)
|
|
446
|
+
dialog.clear()
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
title: "Redo",
|
|
451
|
+
value: "session.redo",
|
|
452
|
+
keybind: "messages_redo",
|
|
453
|
+
disabled: !session()?.revert?.messageID,
|
|
454
|
+
category: "Session",
|
|
455
|
+
onSelect: (dialog) => {
|
|
456
|
+
dialog.clear()
|
|
457
|
+
const messageID = session().revert?.messageID
|
|
458
|
+
if (!messageID) return
|
|
459
|
+
const message = messages().find((x) => x.role === "user" && x.id > messageID)
|
|
460
|
+
if (!message) {
|
|
461
|
+
sdk.client.session.unrevert({
|
|
462
|
+
sessionID: route.sessionID,
|
|
463
|
+
})
|
|
464
|
+
prompt.set({ input: "", parts: [] })
|
|
465
|
+
return
|
|
466
|
+
}
|
|
467
|
+
sdk.client.session.revert({
|
|
468
|
+
sessionID: route.sessionID,
|
|
469
|
+
messageID: message.id,
|
|
470
|
+
})
|
|
471
|
+
},
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
title: sidebarVisible() ? "Hide sidebar" : "Show sidebar",
|
|
475
|
+
value: "session.sidebar.toggle",
|
|
476
|
+
keybind: "sidebar_toggle",
|
|
477
|
+
category: "Session",
|
|
478
|
+
onSelect: (dialog) => {
|
|
479
|
+
setSidebar((prev) => {
|
|
480
|
+
if (prev === "auto") return sidebarVisible() ? "hide" : "show"
|
|
481
|
+
if (prev === "show") return "hide"
|
|
482
|
+
return "show"
|
|
483
|
+
})
|
|
484
|
+
if (sidebar() === "show") kv.set("sidebar", "auto")
|
|
485
|
+
if (sidebar() === "hide") kv.set("sidebar", "hide")
|
|
486
|
+
dialog.clear()
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
title: usernameVisible() ? "Hide username" : "Show username",
|
|
491
|
+
value: "session.username_visible.toggle",
|
|
492
|
+
keybind: "username_toggle",
|
|
493
|
+
category: "Session",
|
|
494
|
+
onSelect: (dialog) => {
|
|
495
|
+
setUsernameVisible((prev) => {
|
|
496
|
+
const next = !prev
|
|
497
|
+
kv.set("username_visible", next)
|
|
498
|
+
return next
|
|
499
|
+
})
|
|
500
|
+
dialog.clear()
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
title: "Toggle code concealment",
|
|
505
|
+
value: "session.toggle.conceal",
|
|
506
|
+
keybind: "messages_toggle_conceal" as any,
|
|
507
|
+
category: "Session",
|
|
508
|
+
onSelect: (dialog) => {
|
|
509
|
+
setConceal((prev) => !prev)
|
|
510
|
+
dialog.clear()
|
|
511
|
+
},
|
|
512
|
+
},
|
|
513
|
+
{
|
|
514
|
+
title: showTimestamps() ? "Hide timestamps" : "Show timestamps",
|
|
515
|
+
value: "session.toggle.timestamps",
|
|
516
|
+
category: "Session",
|
|
517
|
+
onSelect: (dialog) => {
|
|
518
|
+
setShowTimestamps((prev) => {
|
|
519
|
+
const next = !prev
|
|
520
|
+
kv.set("timestamps", next ? "show" : "hide")
|
|
521
|
+
return next
|
|
522
|
+
})
|
|
523
|
+
dialog.clear()
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
title: showThinking() ? "Hide thinking" : "Show thinking",
|
|
528
|
+
value: "session.toggle.thinking",
|
|
529
|
+
category: "Session",
|
|
530
|
+
onSelect: (dialog) => {
|
|
531
|
+
setShowThinking((prev) => {
|
|
532
|
+
const next = !prev
|
|
533
|
+
kv.set("thinking_visibility", next)
|
|
534
|
+
return next
|
|
535
|
+
})
|
|
536
|
+
dialog.clear()
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
title: "Toggle diff wrapping",
|
|
541
|
+
value: "session.toggle.diffwrap",
|
|
542
|
+
category: "Session",
|
|
543
|
+
onSelect: (dialog) => {
|
|
544
|
+
setDiffWrapMode((prev) => (prev === "word" ? "none" : "word"))
|
|
545
|
+
dialog.clear()
|
|
546
|
+
},
|
|
547
|
+
},
|
|
548
|
+
{
|
|
549
|
+
title: showDetails() ? "Hide tool details" : "Show tool details",
|
|
550
|
+
value: "session.toggle.actions",
|
|
551
|
+
keybind: "tool_details",
|
|
552
|
+
category: "Session",
|
|
553
|
+
onSelect: (dialog) => {
|
|
554
|
+
const newValue = !showDetails()
|
|
555
|
+
setShowDetails(newValue)
|
|
556
|
+
kv.set("tool_details_visibility", newValue)
|
|
557
|
+
dialog.clear()
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
{
|
|
561
|
+
title: "Toggle session scrollbar",
|
|
562
|
+
value: "session.toggle.scrollbar",
|
|
563
|
+
keybind: "scrollbar_toggle",
|
|
564
|
+
category: "Session",
|
|
565
|
+
onSelect: (dialog) => {
|
|
566
|
+
setShowScrollbar((prev) => {
|
|
567
|
+
const next = !prev
|
|
568
|
+
kv.set("scrollbar_visible", next)
|
|
569
|
+
return next
|
|
570
|
+
})
|
|
571
|
+
dialog.clear()
|
|
572
|
+
},
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
title: userMessageMarkdown() ? "Disable user message markdown" : "Enable user message markdown",
|
|
576
|
+
value: "session.toggle.user_message_markdown",
|
|
577
|
+
category: "Session",
|
|
578
|
+
onSelect: (dialog) => {
|
|
579
|
+
setUserMessageMarkdown((prev) => {
|
|
580
|
+
const next = !prev
|
|
581
|
+
kv.set("user_message_markdown", next)
|
|
582
|
+
return next
|
|
583
|
+
})
|
|
584
|
+
dialog.clear()
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
title: "Page up",
|
|
589
|
+
value: "session.page.up",
|
|
590
|
+
keybind: "messages_page_up",
|
|
591
|
+
category: "Session",
|
|
592
|
+
disabled: true,
|
|
593
|
+
onSelect: (dialog) => {
|
|
594
|
+
scroll.scrollBy(-scroll.height / 2)
|
|
595
|
+
dialog.clear()
|
|
596
|
+
},
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
title: "Page down",
|
|
600
|
+
value: "session.page.down",
|
|
601
|
+
keybind: "messages_page_down",
|
|
602
|
+
category: "Session",
|
|
603
|
+
disabled: true,
|
|
604
|
+
onSelect: (dialog) => {
|
|
605
|
+
scroll.scrollBy(scroll.height / 2)
|
|
606
|
+
dialog.clear()
|
|
607
|
+
},
|
|
608
|
+
},
|
|
609
|
+
{
|
|
610
|
+
title: "Half page up",
|
|
611
|
+
value: "session.half.page.up",
|
|
612
|
+
keybind: "messages_half_page_up",
|
|
613
|
+
category: "Session",
|
|
614
|
+
disabled: true,
|
|
615
|
+
onSelect: (dialog) => {
|
|
616
|
+
scroll.scrollBy(-scroll.height / 4)
|
|
617
|
+
dialog.clear()
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
title: "Half page down",
|
|
622
|
+
value: "session.half.page.down",
|
|
623
|
+
keybind: "messages_half_page_down",
|
|
624
|
+
category: "Session",
|
|
625
|
+
disabled: true,
|
|
626
|
+
onSelect: (dialog) => {
|
|
627
|
+
scroll.scrollBy(scroll.height / 4)
|
|
628
|
+
dialog.clear()
|
|
629
|
+
},
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
title: "First message",
|
|
633
|
+
value: "session.first",
|
|
634
|
+
keybind: "messages_first",
|
|
635
|
+
category: "Session",
|
|
636
|
+
disabled: true,
|
|
637
|
+
onSelect: (dialog) => {
|
|
638
|
+
scroll.scrollTo(0)
|
|
639
|
+
dialog.clear()
|
|
640
|
+
},
|
|
641
|
+
},
|
|
642
|
+
{
|
|
643
|
+
title: "Last message",
|
|
644
|
+
value: "session.last",
|
|
645
|
+
keybind: "messages_last",
|
|
646
|
+
category: "Session",
|
|
647
|
+
disabled: true,
|
|
648
|
+
onSelect: (dialog) => {
|
|
649
|
+
scroll.scrollTo(scroll.scrollHeight)
|
|
650
|
+
dialog.clear()
|
|
651
|
+
},
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
title: "Jump to last user message",
|
|
655
|
+
value: "session.messages_last_user",
|
|
656
|
+
keybind: "messages_last_user",
|
|
657
|
+
category: "Session",
|
|
658
|
+
onSelect: () => {
|
|
659
|
+
const messages = sync.data.message[route.sessionID]
|
|
660
|
+
if (!messages || !messages.length) return
|
|
661
|
+
|
|
662
|
+
// Find the most recent user message with non-ignored, non-synthetic text parts
|
|
663
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
664
|
+
const message = messages[i]
|
|
665
|
+
if (!message || message.role !== "user") continue
|
|
666
|
+
|
|
667
|
+
const parts = sync.data.part[message.id]
|
|
668
|
+
if (!parts || !Array.isArray(parts)) continue
|
|
669
|
+
|
|
670
|
+
const hasValidTextPart = parts.some(
|
|
671
|
+
(part) => part && part.type === "text" && !part.synthetic && !part.ignored,
|
|
672
|
+
)
|
|
673
|
+
|
|
674
|
+
if (hasValidTextPart) {
|
|
675
|
+
const child = scroll.getChildren().find((child) => {
|
|
676
|
+
return child.id === message.id
|
|
677
|
+
})
|
|
678
|
+
if (child) scroll.scrollBy(child.y - scroll.y - 1)
|
|
679
|
+
break
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
},
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
title: "Next message",
|
|
686
|
+
value: "session.message.next",
|
|
687
|
+
keybind: "messages_next",
|
|
688
|
+
category: "Session",
|
|
689
|
+
disabled: true,
|
|
690
|
+
onSelect: (dialog) => scrollToMessage("next", dialog),
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
title: "Previous message",
|
|
694
|
+
value: "session.message.previous",
|
|
695
|
+
keybind: "messages_previous",
|
|
696
|
+
category: "Session",
|
|
697
|
+
disabled: true,
|
|
698
|
+
onSelect: (dialog) => scrollToMessage("prev", dialog),
|
|
699
|
+
},
|
|
700
|
+
{
|
|
701
|
+
title: "Copy last assistant message",
|
|
702
|
+
value: "messages.copy",
|
|
703
|
+
keybind: "messages_copy",
|
|
704
|
+
category: "Session",
|
|
705
|
+
onSelect: (dialog) => {
|
|
706
|
+
const revertID = session()?.revert?.messageID
|
|
707
|
+
const lastAssistantMessage = messages().findLast(
|
|
708
|
+
(msg) => msg.role === "assistant" && (!revertID || msg.id < revertID),
|
|
709
|
+
)
|
|
710
|
+
if (!lastAssistantMessage) {
|
|
711
|
+
toast.show({ message: "No assistant messages found", variant: "error" })
|
|
712
|
+
dialog.clear()
|
|
713
|
+
return
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
const parts = sync.data.part[lastAssistantMessage.id] ?? []
|
|
717
|
+
const textParts = parts.filter((part) => part.type === "text")
|
|
718
|
+
if (textParts.length === 0) {
|
|
719
|
+
toast.show({ message: "No text parts found in last assistant message", variant: "error" })
|
|
720
|
+
dialog.clear()
|
|
721
|
+
return
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
const text = textParts
|
|
725
|
+
.map((part) => part.text)
|
|
726
|
+
.join("\n")
|
|
727
|
+
.trim()
|
|
728
|
+
if (!text) {
|
|
729
|
+
toast.show({
|
|
730
|
+
message: "No text content found in last assistant message",
|
|
731
|
+
variant: "error",
|
|
732
|
+
})
|
|
733
|
+
dialog.clear()
|
|
734
|
+
return
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
const base64 = Buffer.from(text).toString("base64")
|
|
738
|
+
const osc52 = `\x1b]52;c;${base64}\x07`
|
|
739
|
+
const finalOsc52 = process.env["TMUX"] ? `\x1bPtmux;\x1b${osc52}\x1b\\` : osc52
|
|
740
|
+
/* @ts-expect-error */
|
|
741
|
+
renderer.writeOut(finalOsc52)
|
|
742
|
+
Clipboard.copy(text)
|
|
743
|
+
.then(() => toast.show({ message: "Message copied to clipboard!", variant: "success" }))
|
|
744
|
+
.catch(() => toast.show({ message: "Failed to copy to clipboard", variant: "error" }))
|
|
745
|
+
dialog.clear()
|
|
746
|
+
},
|
|
747
|
+
},
|
|
748
|
+
{
|
|
749
|
+
title: "Copy session transcript",
|
|
750
|
+
value: "session.copy",
|
|
751
|
+
keybind: "session_copy",
|
|
752
|
+
category: "Session",
|
|
753
|
+
onSelect: async (dialog) => {
|
|
754
|
+
try {
|
|
755
|
+
// Format session transcript as markdown
|
|
756
|
+
const sessionData = session()
|
|
757
|
+
const sessionMessages = messages()
|
|
758
|
+
|
|
759
|
+
let transcript = `# ${sessionData.title}\n\n`
|
|
760
|
+
transcript += `**Session ID:** ${sessionData.id}\n`
|
|
761
|
+
transcript += `**Created:** ${new Date(sessionData.time.created).toLocaleString()}\n`
|
|
762
|
+
transcript += `**Updated:** ${new Date(sessionData.time.updated).toLocaleString()}\n\n`
|
|
763
|
+
transcript += `---\n\n`
|
|
764
|
+
|
|
765
|
+
for (const msg of sessionMessages) {
|
|
766
|
+
const parts = sync.data.part[msg.id] ?? []
|
|
767
|
+
const role = msg.role === "user" ? "User" : "Assistant"
|
|
768
|
+
transcript += `## ${role}\n\n`
|
|
769
|
+
|
|
770
|
+
for (const part of parts) {
|
|
771
|
+
if (part.type === "text" && !part.synthetic) {
|
|
772
|
+
transcript += `${part.text}\n\n`
|
|
773
|
+
} else if (part.type === "tool") {
|
|
774
|
+
transcript += `\`\`\`\nTool: ${part.tool}\n\`\`\`\n\n`
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
transcript += `---\n\n`
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
// Copy to clipboard
|
|
782
|
+
await Clipboard.copy(transcript)
|
|
783
|
+
toast.show({ message: "Session transcript copied to clipboard!", variant: "success" })
|
|
784
|
+
} catch (error) {
|
|
785
|
+
toast.show({ message: "Failed to copy session transcript", variant: "error" })
|
|
786
|
+
}
|
|
787
|
+
dialog.clear()
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
title: "Export session transcript to file",
|
|
792
|
+
value: "session.export",
|
|
793
|
+
keybind: "session_export",
|
|
794
|
+
category: "Session",
|
|
795
|
+
onSelect: async (dialog) => {
|
|
796
|
+
try {
|
|
797
|
+
// Format session transcript as markdown
|
|
798
|
+
const sessionData = session()
|
|
799
|
+
const sessionMessages = messages()
|
|
800
|
+
|
|
801
|
+
let transcript = `# ${sessionData.title}\n\n`
|
|
802
|
+
transcript += `**Session ID:** ${sessionData.id}\n`
|
|
803
|
+
transcript += `**Created:** ${new Date(sessionData.time.created).toLocaleString()}\n`
|
|
804
|
+
transcript += `**Updated:** ${new Date(sessionData.time.updated).toLocaleString()}\n\n`
|
|
805
|
+
transcript += `---\n\n`
|
|
806
|
+
|
|
807
|
+
for (const msg of sessionMessages) {
|
|
808
|
+
const parts = sync.data.part[msg.id] ?? []
|
|
809
|
+
const role = msg.role === "user" ? "User" : "Assistant"
|
|
810
|
+
transcript += `## ${role}\n\n`
|
|
811
|
+
|
|
812
|
+
for (const part of parts) {
|
|
813
|
+
if (part.type === "text" && !part.synthetic) {
|
|
814
|
+
transcript += `${part.text}\n\n`
|
|
815
|
+
} else if (part.type === "tool") {
|
|
816
|
+
transcript += `\`\`\`\nTool: ${part.tool}\n\`\`\`\n\n`
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
transcript += `---\n\n`
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// Prompt for optional filename
|
|
824
|
+
const customFilename = await DialogPrompt.show(dialog, "Export filename", {
|
|
825
|
+
value: `session-${sessionData.id.slice(0, 8)}.md`,
|
|
826
|
+
})
|
|
827
|
+
|
|
828
|
+
// Cancel if user pressed escape
|
|
829
|
+
if (customFilename === null) return
|
|
830
|
+
|
|
831
|
+
// Save to file in current working directory
|
|
832
|
+
const exportDir = process.cwd()
|
|
833
|
+
const filename = customFilename.trim()
|
|
834
|
+
const filepath = path.join(exportDir, filename)
|
|
835
|
+
|
|
836
|
+
await Bun.write(filepath, transcript)
|
|
837
|
+
|
|
838
|
+
// Open with EDITOR if available
|
|
839
|
+
const result = await Editor.open({ value: transcript, renderer })
|
|
840
|
+
if (result !== undefined) {
|
|
841
|
+
// User edited the file, save the changes
|
|
842
|
+
await Bun.write(filepath, result)
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
toast.show({ message: `Session exported to ${filename}`, variant: "success" })
|
|
846
|
+
} catch (error) {
|
|
847
|
+
toast.show({ message: "Failed to export session", variant: "error" })
|
|
848
|
+
}
|
|
849
|
+
dialog.clear()
|
|
850
|
+
},
|
|
851
|
+
},
|
|
852
|
+
{
|
|
853
|
+
title: "Next child session",
|
|
854
|
+
value: "session.child.next",
|
|
855
|
+
keybind: "session_child_cycle",
|
|
856
|
+
category: "Session",
|
|
857
|
+
disabled: true,
|
|
858
|
+
onSelect: (dialog) => {
|
|
859
|
+
moveChild(1)
|
|
860
|
+
dialog.clear()
|
|
861
|
+
},
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
title: "Previous child session",
|
|
865
|
+
value: "session.child.previous",
|
|
866
|
+
keybind: "session_child_cycle_reverse",
|
|
867
|
+
category: "Session",
|
|
868
|
+
disabled: true,
|
|
869
|
+
onSelect: (dialog) => {
|
|
870
|
+
moveChild(-1)
|
|
871
|
+
dialog.clear()
|
|
872
|
+
},
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
title: "Go to parent session",
|
|
876
|
+
value: "session.parent",
|
|
877
|
+
keybind: "session_parent",
|
|
878
|
+
category: "Session",
|
|
879
|
+
disabled: true,
|
|
880
|
+
onSelect: (dialog) => {
|
|
881
|
+
const parentID = session()?.parentID
|
|
882
|
+
if (parentID) {
|
|
883
|
+
navigate({
|
|
884
|
+
type: "session",
|
|
885
|
+
sessionID: parentID,
|
|
886
|
+
})
|
|
887
|
+
}
|
|
888
|
+
dialog.clear()
|
|
889
|
+
},
|
|
890
|
+
},
|
|
891
|
+
])
|
|
892
|
+
|
|
893
|
+
const revertInfo = createMemo(() => session()?.revert)
|
|
894
|
+
const revertMessageID = createMemo(() => revertInfo()?.messageID)
|
|
895
|
+
|
|
896
|
+
const revertDiffFiles = createMemo(() => {
|
|
897
|
+
const diffText = revertInfo()?.diff ?? ""
|
|
898
|
+
if (!diffText) return []
|
|
899
|
+
|
|
900
|
+
try {
|
|
901
|
+
const patches = parsePatch(diffText)
|
|
902
|
+
return patches.map((patch) => {
|
|
903
|
+
const filename = patch.newFileName || patch.oldFileName || "unknown"
|
|
904
|
+
const cleanFilename = filename.replace(/^[ab]\//, "")
|
|
905
|
+
return {
|
|
906
|
+
filename: cleanFilename,
|
|
907
|
+
additions: patch.hunks.reduce(
|
|
908
|
+
(sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("+")).length,
|
|
909
|
+
0,
|
|
910
|
+
),
|
|
911
|
+
deletions: patch.hunks.reduce(
|
|
912
|
+
(sum, hunk) => sum + hunk.lines.filter((line) => line.startsWith("-")).length,
|
|
913
|
+
0,
|
|
914
|
+
),
|
|
915
|
+
}
|
|
916
|
+
})
|
|
917
|
+
} catch (error) {
|
|
918
|
+
return []
|
|
919
|
+
}
|
|
920
|
+
})
|
|
921
|
+
|
|
922
|
+
const revertRevertedMessages = createMemo(() => {
|
|
923
|
+
const messageID = revertMessageID()
|
|
924
|
+
if (!messageID) return []
|
|
925
|
+
return messages().filter((x) => x.id >= messageID && x.role === "user")
|
|
926
|
+
})
|
|
927
|
+
|
|
928
|
+
const revert = createMemo(() => {
|
|
929
|
+
const info = revertInfo()
|
|
930
|
+
if (!info) return
|
|
931
|
+
if (!info.messageID) return
|
|
932
|
+
return {
|
|
933
|
+
messageID: info.messageID,
|
|
934
|
+
reverted: revertRevertedMessages(),
|
|
935
|
+
diff: info.diff,
|
|
936
|
+
diffFiles: revertDiffFiles(),
|
|
937
|
+
}
|
|
938
|
+
})
|
|
939
|
+
|
|
940
|
+
const dialog = useDialog()
|
|
941
|
+
const renderer = useRenderer()
|
|
942
|
+
|
|
943
|
+
// snap to bottom when session changes
|
|
944
|
+
createEffect(on(() => route.sessionID, toBottom))
|
|
945
|
+
|
|
946
|
+
return (
|
|
947
|
+
<context.Provider
|
|
948
|
+
value={{
|
|
949
|
+
get width() {
|
|
950
|
+
return contentWidth()
|
|
951
|
+
},
|
|
952
|
+
conceal,
|
|
953
|
+
showThinking,
|
|
954
|
+
showTimestamps,
|
|
955
|
+
usernameVisible,
|
|
956
|
+
showDetails,
|
|
957
|
+
userMessageMarkdown,
|
|
958
|
+
diffWrapMode,
|
|
959
|
+
sync,
|
|
960
|
+
}}
|
|
961
|
+
>
|
|
962
|
+
<box flexDirection="row">
|
|
963
|
+
<box flexGrow={1} paddingBottom={1} paddingTop={1} paddingLeft={2} paddingRight={2} gap={1}>
|
|
964
|
+
<Show when={session()}>
|
|
965
|
+
<Show when={!sidebarVisible()}>
|
|
966
|
+
<Header />
|
|
967
|
+
</Show>
|
|
968
|
+
<scrollbox
|
|
969
|
+
ref={(r) => (scroll = r)}
|
|
970
|
+
viewportOptions={{
|
|
971
|
+
paddingRight: showScrollbar() ? 1 : 0,
|
|
972
|
+
}}
|
|
973
|
+
verticalScrollbarOptions={{
|
|
974
|
+
paddingLeft: 1,
|
|
975
|
+
visible: showScrollbar(),
|
|
976
|
+
trackOptions: {
|
|
977
|
+
backgroundColor: theme.backgroundElement,
|
|
978
|
+
foregroundColor: theme.border,
|
|
979
|
+
},
|
|
980
|
+
}}
|
|
981
|
+
stickyScroll={true}
|
|
982
|
+
stickyStart="bottom"
|
|
983
|
+
flexGrow={1}
|
|
984
|
+
scrollAcceleration={scrollAcceleration()}
|
|
985
|
+
>
|
|
986
|
+
<For each={messages()}>
|
|
987
|
+
{(message, index) => (
|
|
988
|
+
<Switch>
|
|
989
|
+
<Match when={message.id === revert()?.messageID}>
|
|
990
|
+
{(function () {
|
|
991
|
+
const command = useCommandDialog()
|
|
992
|
+
const [hover, setHover] = createSignal(false)
|
|
993
|
+
const dialog = useDialog()
|
|
994
|
+
|
|
995
|
+
const handleUnrevert = async () => {
|
|
996
|
+
const confirmed = await DialogConfirm.show(
|
|
997
|
+
dialog,
|
|
998
|
+
"Confirm Redo",
|
|
999
|
+
"Are you sure you want to restore the reverted messages?",
|
|
1000
|
+
)
|
|
1001
|
+
if (confirmed) {
|
|
1002
|
+
command.trigger("session.redo")
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
return (
|
|
1007
|
+
<box
|
|
1008
|
+
onMouseOver={() => setHover(true)}
|
|
1009
|
+
onMouseOut={() => setHover(false)}
|
|
1010
|
+
onMouseUp={handleUnrevert}
|
|
1011
|
+
marginTop={1}
|
|
1012
|
+
flexShrink={0}
|
|
1013
|
+
border={["left"]}
|
|
1014
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
1015
|
+
borderColor={theme.backgroundPanel}
|
|
1016
|
+
>
|
|
1017
|
+
<box
|
|
1018
|
+
paddingTop={1}
|
|
1019
|
+
paddingBottom={1}
|
|
1020
|
+
paddingLeft={2}
|
|
1021
|
+
backgroundColor={hover() ? theme.backgroundElement : theme.backgroundPanel}
|
|
1022
|
+
>
|
|
1023
|
+
<text fg={theme.textMuted}>{revert()!.reverted.length} message reverted</text>
|
|
1024
|
+
<text fg={theme.textMuted}>
|
|
1025
|
+
<span style={{ fg: theme.text }}>{keybind.print("messages_redo")}</span> or /redo to
|
|
1026
|
+
restore
|
|
1027
|
+
</text>
|
|
1028
|
+
<Show when={revert()!.diffFiles?.length}>
|
|
1029
|
+
<box marginTop={1}>
|
|
1030
|
+
<For each={revert()!.diffFiles}>
|
|
1031
|
+
{(file) => (
|
|
1032
|
+
<text fg={theme.text}>
|
|
1033
|
+
{file.filename}
|
|
1034
|
+
<Show when={file.additions > 0}>
|
|
1035
|
+
<span style={{ fg: theme.diffAdded }}> +{file.additions}</span>
|
|
1036
|
+
</Show>
|
|
1037
|
+
<Show when={file.deletions > 0}>
|
|
1038
|
+
<span style={{ fg: theme.diffRemoved }}> -{file.deletions}</span>
|
|
1039
|
+
</Show>
|
|
1040
|
+
</text>
|
|
1041
|
+
)}
|
|
1042
|
+
</For>
|
|
1043
|
+
</box>
|
|
1044
|
+
</Show>
|
|
1045
|
+
</box>
|
|
1046
|
+
</box>
|
|
1047
|
+
)
|
|
1048
|
+
})()}
|
|
1049
|
+
</Match>
|
|
1050
|
+
<Match when={revert()?.messageID && message.id >= revert()!.messageID}>
|
|
1051
|
+
<></>
|
|
1052
|
+
</Match>
|
|
1053
|
+
<Match when={message.role === "user"}>
|
|
1054
|
+
<UserMessage
|
|
1055
|
+
index={index()}
|
|
1056
|
+
onMouseUp={() => {
|
|
1057
|
+
if (renderer.getSelection()?.getSelectedText()) return
|
|
1058
|
+
dialog.replace(() => (
|
|
1059
|
+
<DialogMessage
|
|
1060
|
+
messageID={message.id}
|
|
1061
|
+
sessionID={route.sessionID}
|
|
1062
|
+
setPrompt={(promptInfo) => prompt.set(promptInfo)}
|
|
1063
|
+
/>
|
|
1064
|
+
))
|
|
1065
|
+
}}
|
|
1066
|
+
message={message as UserMessage}
|
|
1067
|
+
parts={sync.data.part[message.id] ?? []}
|
|
1068
|
+
pending={pending()}
|
|
1069
|
+
/>
|
|
1070
|
+
</Match>
|
|
1071
|
+
<Match when={message.role === "assistant"}>
|
|
1072
|
+
<AssistantMessage
|
|
1073
|
+
last={lastAssistant()?.id === message.id}
|
|
1074
|
+
message={message as AssistantMessage}
|
|
1075
|
+
parts={sync.data.part[message.id] ?? []}
|
|
1076
|
+
/>
|
|
1077
|
+
</Match>
|
|
1078
|
+
</Switch>
|
|
1079
|
+
)}
|
|
1080
|
+
</For>
|
|
1081
|
+
</scrollbox>
|
|
1082
|
+
<box flexShrink={0}>
|
|
1083
|
+
<Prompt
|
|
1084
|
+
ref={(r) => {
|
|
1085
|
+
prompt = r
|
|
1086
|
+
promptRef.set(r)
|
|
1087
|
+
}}
|
|
1088
|
+
disabled={permissions().length > 0}
|
|
1089
|
+
onSubmit={() => {
|
|
1090
|
+
toBottom()
|
|
1091
|
+
}}
|
|
1092
|
+
sessionID={route.sessionID}
|
|
1093
|
+
/>
|
|
1094
|
+
</box>
|
|
1095
|
+
<Show when={!sidebarVisible()}>
|
|
1096
|
+
<Footer />
|
|
1097
|
+
</Show>
|
|
1098
|
+
</Show>
|
|
1099
|
+
<Toast />
|
|
1100
|
+
</box>
|
|
1101
|
+
<Show when={sidebarVisible()}>
|
|
1102
|
+
<Sidebar sessionID={route.sessionID} />
|
|
1103
|
+
</Show>
|
|
1104
|
+
</box>
|
|
1105
|
+
</context.Provider>
|
|
1106
|
+
)
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
const MIME_BADGE: Record<string, string> = {
|
|
1110
|
+
"text/plain": "txt",
|
|
1111
|
+
"image/png": "img",
|
|
1112
|
+
"image/jpeg": "img",
|
|
1113
|
+
"image/gif": "img",
|
|
1114
|
+
"image/webp": "img",
|
|
1115
|
+
"application/pdf": "pdf",
|
|
1116
|
+
"application/x-directory": "dir",
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
function UserMessage(props: {
|
|
1120
|
+
message: UserMessage
|
|
1121
|
+
parts: Part[]
|
|
1122
|
+
onMouseUp: () => void
|
|
1123
|
+
index: number
|
|
1124
|
+
pending?: string
|
|
1125
|
+
}) {
|
|
1126
|
+
const ctx = use()
|
|
1127
|
+
const local = useLocal()
|
|
1128
|
+
const text = createMemo(() => props.parts.flatMap((x) => (x.type === "text" && !x.synthetic ? [x] : []))[0])
|
|
1129
|
+
const files = createMemo(() => props.parts.flatMap((x) => (x.type === "file" ? [x] : [])))
|
|
1130
|
+
const sync = useSync()
|
|
1131
|
+
const { theme, syntax } = useTheme()
|
|
1132
|
+
const [hover, setHover] = createSignal(false)
|
|
1133
|
+
const queued = createMemo(() => props.pending && props.message.id > props.pending)
|
|
1134
|
+
const color = createMemo(() => (queued() ? theme.accent : local.agent.color(props.message.agent)))
|
|
1135
|
+
|
|
1136
|
+
const compaction = createMemo(() => props.parts.find((x) => x.type === "compaction"))
|
|
1137
|
+
|
|
1138
|
+
return (
|
|
1139
|
+
<>
|
|
1140
|
+
<Show when={text()}>
|
|
1141
|
+
<box
|
|
1142
|
+
id={props.message.id}
|
|
1143
|
+
border={["left"]}
|
|
1144
|
+
borderColor={color()}
|
|
1145
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
1146
|
+
marginTop={props.index === 0 ? 0 : 1}
|
|
1147
|
+
>
|
|
1148
|
+
<box
|
|
1149
|
+
onMouseOver={() => {
|
|
1150
|
+
setHover(true)
|
|
1151
|
+
}}
|
|
1152
|
+
onMouseOut={() => {
|
|
1153
|
+
setHover(false)
|
|
1154
|
+
}}
|
|
1155
|
+
onMouseUp={props.onMouseUp}
|
|
1156
|
+
paddingTop={1}
|
|
1157
|
+
paddingBottom={1}
|
|
1158
|
+
paddingLeft={2}
|
|
1159
|
+
backgroundColor={hover() ? theme.backgroundElement : theme.backgroundPanel}
|
|
1160
|
+
flexShrink={0}
|
|
1161
|
+
>
|
|
1162
|
+
<Switch>
|
|
1163
|
+
<Match when={ctx.userMessageMarkdown()}>
|
|
1164
|
+
<code
|
|
1165
|
+
filetype="markdown"
|
|
1166
|
+
drawUnstyledText={false}
|
|
1167
|
+
streaming={false}
|
|
1168
|
+
syntaxStyle={syntax()}
|
|
1169
|
+
content={text()?.text ?? ""}
|
|
1170
|
+
conceal={ctx.conceal()}
|
|
1171
|
+
fg={theme.text}
|
|
1172
|
+
/>
|
|
1173
|
+
</Match>
|
|
1174
|
+
<Match when={!ctx.userMessageMarkdown()}>
|
|
1175
|
+
<text fg={theme.text}>{text()?.text}</text>
|
|
1176
|
+
</Match>
|
|
1177
|
+
</Switch>
|
|
1178
|
+
<Show when={files().length}>
|
|
1179
|
+
<box flexDirection="row" paddingBottom={1} paddingTop={1} gap={1} flexWrap="wrap">
|
|
1180
|
+
<For each={files()}>
|
|
1181
|
+
{(file) => {
|
|
1182
|
+
const bg = createMemo(() => {
|
|
1183
|
+
if (file.mime.startsWith("image/")) return theme.accent
|
|
1184
|
+
if (file.mime === "application/pdf") return theme.primary
|
|
1185
|
+
return theme.secondary
|
|
1186
|
+
})
|
|
1187
|
+
return (
|
|
1188
|
+
<text fg={theme.text}>
|
|
1189
|
+
<span style={{ bg: bg(), fg: theme.background }}> {MIME_BADGE[file.mime] ?? file.mime} </span>
|
|
1190
|
+
<span style={{ bg: theme.backgroundElement, fg: theme.textMuted }}> {file.filename} </span>
|
|
1191
|
+
</text>
|
|
1192
|
+
)
|
|
1193
|
+
}}
|
|
1194
|
+
</For>
|
|
1195
|
+
</box>
|
|
1196
|
+
</Show>
|
|
1197
|
+
<text fg={theme.textMuted}>
|
|
1198
|
+
{ctx.usernameVisible() ? `${sync.data.config.username ?? "You "}` : "You "}
|
|
1199
|
+
<Show
|
|
1200
|
+
when={queued()}
|
|
1201
|
+
fallback={
|
|
1202
|
+
<Show when={ctx.showTimestamps()}>
|
|
1203
|
+
<span style={{ fg: theme.textMuted }}>
|
|
1204
|
+
{ctx.usernameVisible() ? " · " : " "}
|
|
1205
|
+
{Locale.todayTimeOrDateTime(props.message.time.created)}
|
|
1206
|
+
</span>
|
|
1207
|
+
</Show>
|
|
1208
|
+
}
|
|
1209
|
+
>
|
|
1210
|
+
<span> </span>
|
|
1211
|
+
<span style={{ bg: theme.accent, fg: theme.backgroundPanel, bold: true }}> QUEUED </span>
|
|
1212
|
+
</Show>
|
|
1213
|
+
</text>
|
|
1214
|
+
</box>
|
|
1215
|
+
</box>
|
|
1216
|
+
</Show>
|
|
1217
|
+
<Show when={compaction()}>
|
|
1218
|
+
<box
|
|
1219
|
+
marginTop={1}
|
|
1220
|
+
border={["top"]}
|
|
1221
|
+
title=" Compaction "
|
|
1222
|
+
titleAlignment="center"
|
|
1223
|
+
borderColor={theme.borderActive}
|
|
1224
|
+
/>
|
|
1225
|
+
</Show>
|
|
1226
|
+
</>
|
|
1227
|
+
)
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function AssistantMessage(props: { message: AssistantMessage; parts: Part[]; last: boolean }) {
|
|
1231
|
+
const local = useLocal()
|
|
1232
|
+
const { theme } = useTheme()
|
|
1233
|
+
const sync = useSync()
|
|
1234
|
+
const messages = createMemo(() => sync.data.message[props.message.sessionID] ?? [])
|
|
1235
|
+
|
|
1236
|
+
const final = createMemo(() => {
|
|
1237
|
+
return props.message.finish && !["tool-calls", "unknown"].includes(props.message.finish)
|
|
1238
|
+
})
|
|
1239
|
+
|
|
1240
|
+
const duration = createMemo(() => {
|
|
1241
|
+
if (!final()) return 0
|
|
1242
|
+
if (!props.message.time.completed) return 0
|
|
1243
|
+
const user = messages().find((x) => x.role === "user" && x.id === props.message.parentID)
|
|
1244
|
+
if (!user || !user.time) return 0
|
|
1245
|
+
return props.message.time.completed - user.time.created
|
|
1246
|
+
})
|
|
1247
|
+
|
|
1248
|
+
return (
|
|
1249
|
+
<>
|
|
1250
|
+
<For each={props.parts}>
|
|
1251
|
+
{(part, index) => {
|
|
1252
|
+
const component = createMemo(() => PART_MAPPING[part.type as keyof typeof PART_MAPPING])
|
|
1253
|
+
return (
|
|
1254
|
+
<Show when={component()}>
|
|
1255
|
+
<Dynamic
|
|
1256
|
+
last={index() === props.parts.length - 1}
|
|
1257
|
+
component={component()}
|
|
1258
|
+
part={part as any}
|
|
1259
|
+
message={props.message}
|
|
1260
|
+
/>
|
|
1261
|
+
</Show>
|
|
1262
|
+
)
|
|
1263
|
+
}}
|
|
1264
|
+
</For>
|
|
1265
|
+
<Show when={props.message.error}>
|
|
1266
|
+
<box
|
|
1267
|
+
border={["left"]}
|
|
1268
|
+
paddingTop={1}
|
|
1269
|
+
paddingBottom={1}
|
|
1270
|
+
paddingLeft={2}
|
|
1271
|
+
marginTop={1}
|
|
1272
|
+
backgroundColor={theme.backgroundPanel}
|
|
1273
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
1274
|
+
borderColor={theme.error}
|
|
1275
|
+
>
|
|
1276
|
+
<text fg={theme.textMuted}>{props.message.error?.data.message}</text>
|
|
1277
|
+
</box>
|
|
1278
|
+
</Show>
|
|
1279
|
+
<Switch>
|
|
1280
|
+
<Match when={props.last || final()}>
|
|
1281
|
+
<box paddingLeft={3}>
|
|
1282
|
+
<text marginTop={1}>
|
|
1283
|
+
<span style={{ fg: local.agent.color(props.message.mode) }}>▣ </span>{" "}
|
|
1284
|
+
<span style={{ fg: theme.text }}>{Locale.titlecase(props.message.mode)}</span>
|
|
1285
|
+
<span style={{ fg: theme.textMuted }}> · {props.message.modelID}</span>
|
|
1286
|
+
<Show when={duration()}>
|
|
1287
|
+
<span style={{ fg: theme.textMuted }}> · {Locale.duration(duration())}</span>
|
|
1288
|
+
</Show>
|
|
1289
|
+
</text>
|
|
1290
|
+
</box>
|
|
1291
|
+
</Match>
|
|
1292
|
+
</Switch>
|
|
1293
|
+
</>
|
|
1294
|
+
)
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
const PART_MAPPING = {
|
|
1298
|
+
text: TextPart,
|
|
1299
|
+
tool: ToolPart,
|
|
1300
|
+
reasoning: ReasoningPart,
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function ReasoningPart(props: { last: boolean; part: ReasoningPart; message: AssistantMessage }) {
|
|
1304
|
+
const { theme, subtleSyntax } = useTheme()
|
|
1305
|
+
const ctx = use()
|
|
1306
|
+
const content = createMemo(() => {
|
|
1307
|
+
// Filter out redacted reasoning chunks from OpenRouter
|
|
1308
|
+
// OpenRouter sends encrypted reasoning data that appears as [REDACTED]
|
|
1309
|
+
return props.part.text.replace("[REDACTED]", "").trim()
|
|
1310
|
+
})
|
|
1311
|
+
return (
|
|
1312
|
+
<Show when={content() && ctx.showThinking()}>
|
|
1313
|
+
<box
|
|
1314
|
+
id={"text-" + props.part.id}
|
|
1315
|
+
paddingLeft={2}
|
|
1316
|
+
marginTop={1}
|
|
1317
|
+
flexDirection="column"
|
|
1318
|
+
border={["left"]}
|
|
1319
|
+
customBorderChars={SplitBorder.customBorderChars}
|
|
1320
|
+
borderColor={theme.backgroundElement}
|
|
1321
|
+
>
|
|
1322
|
+
<code
|
|
1323
|
+
filetype="markdown"
|
|
1324
|
+
drawUnstyledText={false}
|
|
1325
|
+
streaming={true}
|
|
1326
|
+
syntaxStyle={subtleSyntax()}
|
|
1327
|
+
content={"_Thinking:_ " + content()}
|
|
1328
|
+
conceal={ctx.conceal()}
|
|
1329
|
+
fg={theme.textMuted}
|
|
1330
|
+
/>
|
|
1331
|
+
</box>
|
|
1332
|
+
</Show>
|
|
1333
|
+
)
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function TextPart(props: { last: boolean; part: TextPart; message: AssistantMessage }) {
|
|
1337
|
+
const ctx = use()
|
|
1338
|
+
const { theme, syntax } = useTheme()
|
|
1339
|
+
return (
|
|
1340
|
+
<Show when={props.part.text.trim()}>
|
|
1341
|
+
<box id={"text-" + props.part.id} paddingLeft={3} marginTop={1} flexShrink={0}>
|
|
1342
|
+
<code
|
|
1343
|
+
filetype="markdown"
|
|
1344
|
+
drawUnstyledText={false}
|
|
1345
|
+
streaming={true}
|
|
1346
|
+
syntaxStyle={syntax()}
|
|
1347
|
+
content={props.part.text.trim()}
|
|
1348
|
+
conceal={ctx.conceal()}
|
|
1349
|
+
fg={theme.text}
|
|
1350
|
+
/>
|
|
1351
|
+
</box>
|
|
1352
|
+
</Show>
|
|
1353
|
+
)
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
// Pending messages moved to individual tool pending functions
|
|
1357
|
+
|
|
1358
|
+
function ToolPart(props: { last: boolean; part: ToolPart; message: AssistantMessage }) {
|
|
1359
|
+
const { theme } = useTheme()
|
|
1360
|
+
const { showDetails } = use()
|
|
1361
|
+
const sync = useSync()
|
|
1362
|
+
const [margin, setMargin] = createSignal(0)
|
|
1363
|
+
const component = createMemo(() => {
|
|
1364
|
+
// Hide tool if showDetails is false and tool completed successfully
|
|
1365
|
+
// But always show if there's an error or permission is required
|
|
1366
|
+
const shouldHide =
|
|
1367
|
+
!showDetails() &&
|
|
1368
|
+
props.part.state.status === "completed" &&
|
|
1369
|
+
!sync.data.permission[props.message.sessionID]?.some((x) => x.callID === props.part.callID)
|
|
1370
|
+
|
|
1371
|
+
if (shouldHide) {
|
|
1372
|
+
return undefined
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
const render = ToolRegistry.render(props.part.tool) ?? GenericTool
|
|
1376
|
+
|
|
1377
|
+
const metadata = props.part.state.status === "pending" ? {} : (props.part.state.metadata ?? {})
|
|
1378
|
+
const input = props.part.state.input ?? {}
|
|
1379
|
+
const container = ToolRegistry.container(props.part.tool)
|
|
1380
|
+
const permissions = sync.data.permission[props.message.sessionID] ?? []
|
|
1381
|
+
const permissionIndex = permissions.findIndex((x) => x.callID === props.part.callID)
|
|
1382
|
+
const permission = permissions[permissionIndex]
|
|
1383
|
+
|
|
1384
|
+
const style: BoxProps =
|
|
1385
|
+
container === "block" || permission
|
|
1386
|
+
? {
|
|
1387
|
+
border: permissionIndex === 0 ? (["left", "right"] as const) : (["left"] as const),
|
|
1388
|
+
paddingTop: 1,
|
|
1389
|
+
paddingBottom: 1,
|
|
1390
|
+
paddingLeft: 2,
|
|
1391
|
+
marginTop: 1,
|
|
1392
|
+
gap: 1,
|
|
1393
|
+
backgroundColor: theme.backgroundPanel,
|
|
1394
|
+
customBorderChars: SplitBorder.customBorderChars,
|
|
1395
|
+
borderColor: permissionIndex === 0 ? theme.warning : theme.background,
|
|
1396
|
+
}
|
|
1397
|
+
: {
|
|
1398
|
+
paddingLeft: 3,
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
return (
|
|
1402
|
+
<box
|
|
1403
|
+
marginTop={margin()}
|
|
1404
|
+
{...style}
|
|
1405
|
+
renderBefore={function () {
|
|
1406
|
+
const el = this as BoxRenderable
|
|
1407
|
+
const parent = el.parent
|
|
1408
|
+
if (!parent) {
|
|
1409
|
+
return
|
|
1410
|
+
}
|
|
1411
|
+
if (el.height > 1) {
|
|
1412
|
+
setMargin(1)
|
|
1413
|
+
return
|
|
1414
|
+
}
|
|
1415
|
+
const children = parent.getChildren()
|
|
1416
|
+
const index = children.indexOf(el)
|
|
1417
|
+
const previous = children[index - 1]
|
|
1418
|
+
if (!previous) {
|
|
1419
|
+
setMargin(0)
|
|
1420
|
+
return
|
|
1421
|
+
}
|
|
1422
|
+
if (previous.height > 1 || previous.id.startsWith("text-")) {
|
|
1423
|
+
setMargin(1)
|
|
1424
|
+
return
|
|
1425
|
+
}
|
|
1426
|
+
}}
|
|
1427
|
+
>
|
|
1428
|
+
<Dynamic
|
|
1429
|
+
component={render}
|
|
1430
|
+
input={input}
|
|
1431
|
+
tool={props.part.tool}
|
|
1432
|
+
metadata={metadata}
|
|
1433
|
+
permission={permission?.metadata ?? {}}
|
|
1434
|
+
output={props.part.state.status === "completed" ? props.part.state.output : undefined}
|
|
1435
|
+
/>
|
|
1436
|
+
{props.part.state.status === "error" && (
|
|
1437
|
+
<box paddingLeft={2}>
|
|
1438
|
+
<text fg={theme.error}>{props.part.state.error.replace("Error: ", "")}</text>
|
|
1439
|
+
</box>
|
|
1440
|
+
)}
|
|
1441
|
+
{permission && (
|
|
1442
|
+
<box gap={1}>
|
|
1443
|
+
<text fg={theme.text}>Permission required to run this tool:</text>
|
|
1444
|
+
<box flexDirection="row" gap={2}>
|
|
1445
|
+
<text fg={theme.text}>
|
|
1446
|
+
<b>enter</b>
|
|
1447
|
+
<span style={{ fg: theme.textMuted }}> accept</span>
|
|
1448
|
+
</text>
|
|
1449
|
+
<text fg={theme.text}>
|
|
1450
|
+
<b>a</b>
|
|
1451
|
+
<span style={{ fg: theme.textMuted }}> accept always</span>
|
|
1452
|
+
</text>
|
|
1453
|
+
<text fg={theme.text}>
|
|
1454
|
+
<b>d</b>
|
|
1455
|
+
<span style={{ fg: theme.textMuted }}> deny</span>
|
|
1456
|
+
</text>
|
|
1457
|
+
</box>
|
|
1458
|
+
</box>
|
|
1459
|
+
)}
|
|
1460
|
+
</box>
|
|
1461
|
+
)
|
|
1462
|
+
})
|
|
1463
|
+
|
|
1464
|
+
return <Show when={component()}>{component()}</Show>
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1467
|
+
type ToolProps<T extends Tool.Info> = {
|
|
1468
|
+
input: Partial<Tool.InferParameters<T>>
|
|
1469
|
+
metadata: Partial<Tool.InferMetadata<T>>
|
|
1470
|
+
permission: Record<string, any>
|
|
1471
|
+
tool: string
|
|
1472
|
+
output?: string
|
|
1473
|
+
}
|
|
1474
|
+
function GenericTool(props: ToolProps<any>) {
|
|
1475
|
+
return (
|
|
1476
|
+
<ToolTitle icon="⚙" fallback="Writing command..." when={true}>
|
|
1477
|
+
{props.tool} {input(props.input)}
|
|
1478
|
+
</ToolTitle>
|
|
1479
|
+
)
|
|
1480
|
+
}
|
|
1481
|
+
|
|
1482
|
+
type ToolRegistration<T extends Tool.Info = any> = {
|
|
1483
|
+
name: string
|
|
1484
|
+
container: "inline" | "block"
|
|
1485
|
+
render?: Component<ToolProps<T>>
|
|
1486
|
+
}
|
|
1487
|
+
const ToolRegistry = (() => {
|
|
1488
|
+
const state: Record<string, ToolRegistration> = {}
|
|
1489
|
+
function register<T extends Tool.Info>(input: ToolRegistration<T>) {
|
|
1490
|
+
state[input.name] = input
|
|
1491
|
+
return input
|
|
1492
|
+
}
|
|
1493
|
+
return {
|
|
1494
|
+
register,
|
|
1495
|
+
container(name: string) {
|
|
1496
|
+
return state[name]?.container
|
|
1497
|
+
},
|
|
1498
|
+
render(name: string) {
|
|
1499
|
+
return state[name]?.render
|
|
1500
|
+
},
|
|
1501
|
+
}
|
|
1502
|
+
})()
|
|
1503
|
+
|
|
1504
|
+
function ToolTitle(props: { fallback: string; when: any; icon: string; children: JSX.Element }) {
|
|
1505
|
+
const { theme } = useTheme()
|
|
1506
|
+
return (
|
|
1507
|
+
<text paddingLeft={3} fg={props.when ? theme.textMuted : theme.text}>
|
|
1508
|
+
<Show fallback={<>~ {props.fallback}</>} when={props.when}>
|
|
1509
|
+
<span style={{ bold: true }}>{props.icon}</span> {props.children}
|
|
1510
|
+
</Show>
|
|
1511
|
+
</text>
|
|
1512
|
+
)
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
ToolRegistry.register<typeof BashTool>({
|
|
1516
|
+
name: "bash",
|
|
1517
|
+
container: "block",
|
|
1518
|
+
render(props) {
|
|
1519
|
+
const output = createMemo(() => stripAnsi(props.metadata.output?.trim() ?? ""))
|
|
1520
|
+
const { theme } = useTheme()
|
|
1521
|
+
return (
|
|
1522
|
+
<>
|
|
1523
|
+
<ToolTitle icon="#" fallback="Writing command..." when={props.input.command}>
|
|
1524
|
+
{props.input.description || "Shell"}
|
|
1525
|
+
</ToolTitle>
|
|
1526
|
+
<Show when={props.input.command}>
|
|
1527
|
+
<text fg={theme.text}>$ {props.input.command}</text>
|
|
1528
|
+
</Show>
|
|
1529
|
+
<Show when={output()}>
|
|
1530
|
+
<box>
|
|
1531
|
+
<text fg={theme.text}>{output()}</text>
|
|
1532
|
+
</box>
|
|
1533
|
+
</Show>
|
|
1534
|
+
</>
|
|
1535
|
+
)
|
|
1536
|
+
},
|
|
1537
|
+
})
|
|
1538
|
+
|
|
1539
|
+
ToolRegistry.register<typeof ReadTool>({
|
|
1540
|
+
name: "read",
|
|
1541
|
+
container: "inline",
|
|
1542
|
+
render(props) {
|
|
1543
|
+
return (
|
|
1544
|
+
<>
|
|
1545
|
+
<ToolTitle icon="→" fallback="Reading file..." when={props.input.filePath}>
|
|
1546
|
+
Read {normalizePath(props.input.filePath!)} {input(props.input, ["filePath"])}
|
|
1547
|
+
</ToolTitle>
|
|
1548
|
+
</>
|
|
1549
|
+
)
|
|
1550
|
+
},
|
|
1551
|
+
})
|
|
1552
|
+
|
|
1553
|
+
ToolRegistry.register<typeof WriteTool>({
|
|
1554
|
+
name: "write",
|
|
1555
|
+
container: "block",
|
|
1556
|
+
render(props) {
|
|
1557
|
+
const { theme, syntax } = useTheme()
|
|
1558
|
+
const code = createMemo(() => {
|
|
1559
|
+
if (!props.input.content) return ""
|
|
1560
|
+
return props.input.content
|
|
1561
|
+
})
|
|
1562
|
+
|
|
1563
|
+
const diagnostics = createMemo(() => {
|
|
1564
|
+
const filePath = Filesystem.normalizePath(props.input.filePath ?? "")
|
|
1565
|
+
return props.metadata.diagnostics?.[filePath] ?? []
|
|
1566
|
+
})
|
|
1567
|
+
|
|
1568
|
+
const done = !!props.input.filePath
|
|
1569
|
+
|
|
1570
|
+
return (
|
|
1571
|
+
<>
|
|
1572
|
+
<ToolTitle icon="←" fallback="Preparing write..." when={done}>
|
|
1573
|
+
Wrote {props.input.filePath}
|
|
1574
|
+
</ToolTitle>
|
|
1575
|
+
<Show when={done}>
|
|
1576
|
+
<line_number fg={theme.textMuted} minWidth={3} paddingRight={1}>
|
|
1577
|
+
<code
|
|
1578
|
+
conceal={false}
|
|
1579
|
+
fg={theme.text}
|
|
1580
|
+
filetype={filetype(props.input.filePath!)}
|
|
1581
|
+
syntaxStyle={syntax()}
|
|
1582
|
+
content={code()}
|
|
1583
|
+
/>
|
|
1584
|
+
</line_number>
|
|
1585
|
+
</Show>
|
|
1586
|
+
<Show when={diagnostics().length}>
|
|
1587
|
+
<For each={diagnostics()}>
|
|
1588
|
+
{(diagnostic) => (
|
|
1589
|
+
<text fg={theme.error}>
|
|
1590
|
+
Error [{diagnostic.range.start.line}:{diagnostic.range.start.character}]: {diagnostic.message}
|
|
1591
|
+
</text>
|
|
1592
|
+
)}
|
|
1593
|
+
</For>
|
|
1594
|
+
</Show>
|
|
1595
|
+
</>
|
|
1596
|
+
)
|
|
1597
|
+
},
|
|
1598
|
+
})
|
|
1599
|
+
|
|
1600
|
+
ToolRegistry.register<typeof GlobTool>({
|
|
1601
|
+
name: "glob",
|
|
1602
|
+
container: "inline",
|
|
1603
|
+
render(props) {
|
|
1604
|
+
return (
|
|
1605
|
+
<>
|
|
1606
|
+
<ToolTitle icon="✱" fallback="Finding files..." when={props.input.pattern}>
|
|
1607
|
+
Glob "{props.input.pattern}" <Show when={props.input.path}>in {normalizePath(props.input.path)} </Show>
|
|
1608
|
+
<Show when={props.metadata.count}>({props.metadata.count} matches)</Show>
|
|
1609
|
+
</ToolTitle>
|
|
1610
|
+
</>
|
|
1611
|
+
)
|
|
1612
|
+
},
|
|
1613
|
+
})
|
|
1614
|
+
|
|
1615
|
+
ToolRegistry.register<typeof GrepTool>({
|
|
1616
|
+
name: "grep",
|
|
1617
|
+
container: "inline",
|
|
1618
|
+
render(props) {
|
|
1619
|
+
return (
|
|
1620
|
+
<ToolTitle icon="✱" fallback="Searching content..." when={props.input.pattern}>
|
|
1621
|
+
Grep "{props.input.pattern}" <Show when={props.input.path}>in {normalizePath(props.input.path)} </Show>
|
|
1622
|
+
<Show when={props.metadata.matches}>({props.metadata.matches} matches)</Show>
|
|
1623
|
+
</ToolTitle>
|
|
1624
|
+
)
|
|
1625
|
+
},
|
|
1626
|
+
})
|
|
1627
|
+
|
|
1628
|
+
ToolRegistry.register<typeof ListTool>({
|
|
1629
|
+
name: "list",
|
|
1630
|
+
container: "inline",
|
|
1631
|
+
render(props) {
|
|
1632
|
+
const dir = createMemo(() => {
|
|
1633
|
+
if (props.input.path) {
|
|
1634
|
+
return normalizePath(props.input.path)
|
|
1635
|
+
}
|
|
1636
|
+
return ""
|
|
1637
|
+
})
|
|
1638
|
+
return (
|
|
1639
|
+
<>
|
|
1640
|
+
<ToolTitle icon="→" fallback="Listing directory..." when={props.input.path !== undefined}>
|
|
1641
|
+
List {dir()}
|
|
1642
|
+
</ToolTitle>
|
|
1643
|
+
</>
|
|
1644
|
+
)
|
|
1645
|
+
},
|
|
1646
|
+
})
|
|
1647
|
+
|
|
1648
|
+
ToolRegistry.register<typeof TaskTool>({
|
|
1649
|
+
name: "task",
|
|
1650
|
+
container: "block",
|
|
1651
|
+
render(props) {
|
|
1652
|
+
const { theme } = useTheme()
|
|
1653
|
+
const keybind = useKeybind()
|
|
1654
|
+
const dialog = useDialog()
|
|
1655
|
+
const renderer = useRenderer()
|
|
1656
|
+
|
|
1657
|
+
return (
|
|
1658
|
+
<>
|
|
1659
|
+
<ToolTitle icon="◉" fallback="Delegating..." when={props.input.subagent_type ?? props.input.description}>
|
|
1660
|
+
{Locale.titlecase(props.input.subagent_type ?? "unknown")} Task "{props.input.description}"
|
|
1661
|
+
</ToolTitle>
|
|
1662
|
+
<Show when={props.metadata.summary?.length}>
|
|
1663
|
+
<box>
|
|
1664
|
+
<For each={props.metadata.summary ?? []}>
|
|
1665
|
+
{(task, index) => {
|
|
1666
|
+
const summary = props.metadata.summary ?? []
|
|
1667
|
+
return (
|
|
1668
|
+
<text style={{ fg: task.state.status === "error" ? theme.error : theme.textMuted }}>
|
|
1669
|
+
{index() === summary.length - 1 ? "└" : "├"} {Locale.titlecase(task.tool)}{" "}
|
|
1670
|
+
{task.state.status === "completed" ? task.state.title : ""}
|
|
1671
|
+
</text>
|
|
1672
|
+
)
|
|
1673
|
+
}}
|
|
1674
|
+
</For>
|
|
1675
|
+
</box>
|
|
1676
|
+
</Show>
|
|
1677
|
+
<text fg={theme.text}>
|
|
1678
|
+
{keybind.print("session_child_cycle")}, {keybind.print("session_child_cycle_reverse")}
|
|
1679
|
+
<span style={{ fg: theme.textMuted }}> to navigate between subagent sessions</span>
|
|
1680
|
+
</text>
|
|
1681
|
+
</>
|
|
1682
|
+
)
|
|
1683
|
+
},
|
|
1684
|
+
})
|
|
1685
|
+
|
|
1686
|
+
ToolRegistry.register<typeof WebFetchTool>({
|
|
1687
|
+
name: "webfetch",
|
|
1688
|
+
container: "inline",
|
|
1689
|
+
render(props) {
|
|
1690
|
+
return (
|
|
1691
|
+
<ToolTitle icon="%" fallback="Fetching from the web..." when={(props.input as any).url}>
|
|
1692
|
+
WebFetch {(props.input as any).url}
|
|
1693
|
+
</ToolTitle>
|
|
1694
|
+
)
|
|
1695
|
+
},
|
|
1696
|
+
})
|
|
1697
|
+
|
|
1698
|
+
ToolRegistry.register({
|
|
1699
|
+
name: "codesearch",
|
|
1700
|
+
container: "inline",
|
|
1701
|
+
render(props: ToolProps<any>) {
|
|
1702
|
+
const input = props.input as any
|
|
1703
|
+
const metadata = props.metadata as any
|
|
1704
|
+
return (
|
|
1705
|
+
<ToolTitle icon="◇" fallback="Searching code..." when={input.query}>
|
|
1706
|
+
Exa Code Search "{input.query}" <Show when={metadata.results}>({metadata.results} results)</Show>
|
|
1707
|
+
</ToolTitle>
|
|
1708
|
+
)
|
|
1709
|
+
},
|
|
1710
|
+
})
|
|
1711
|
+
|
|
1712
|
+
ToolRegistry.register({
|
|
1713
|
+
name: "websearch",
|
|
1714
|
+
container: "inline",
|
|
1715
|
+
render(props: ToolProps<any>) {
|
|
1716
|
+
const input = props.input as any
|
|
1717
|
+
const metadata = props.metadata as any
|
|
1718
|
+
return (
|
|
1719
|
+
<ToolTitle icon="◈" fallback="Searching web..." when={input.query}>
|
|
1720
|
+
Exa Web Search "{input.query}" <Show when={metadata.numResults}>({metadata.numResults} results)</Show>
|
|
1721
|
+
</ToolTitle>
|
|
1722
|
+
)
|
|
1723
|
+
},
|
|
1724
|
+
})
|
|
1725
|
+
|
|
1726
|
+
ToolRegistry.register<typeof EditTool>({
|
|
1727
|
+
name: "edit",
|
|
1728
|
+
container: "block",
|
|
1729
|
+
render(props) {
|
|
1730
|
+
const ctx = use()
|
|
1731
|
+
const { theme, syntax } = useTheme()
|
|
1732
|
+
|
|
1733
|
+
const view = createMemo(() => {
|
|
1734
|
+
const diffStyle = ctx.sync.data.config.tui?.diff_style
|
|
1735
|
+
if (diffStyle === "stacked") return "unified"
|
|
1736
|
+
// Default to "auto" behavior
|
|
1737
|
+
return ctx.width > 120 ? "split" : "unified"
|
|
1738
|
+
})
|
|
1739
|
+
|
|
1740
|
+
const ft = createMemo(() => filetype(props.input.filePath))
|
|
1741
|
+
|
|
1742
|
+
const diffContent = createMemo(() => props.metadata.diff ?? props.permission["diff"])
|
|
1743
|
+
|
|
1744
|
+
const diagnostics = createMemo(() => {
|
|
1745
|
+
const filePath = Filesystem.normalizePath(props.input.filePath ?? "")
|
|
1746
|
+
const arr = props.metadata.diagnostics?.[filePath] ?? []
|
|
1747
|
+
return arr.filter((x) => x.severity === 1).slice(0, 3)
|
|
1748
|
+
})
|
|
1749
|
+
|
|
1750
|
+
return (
|
|
1751
|
+
<>
|
|
1752
|
+
<ToolTitle icon="←" fallback="Preparing edit..." when={props.input.filePath}>
|
|
1753
|
+
Edit {normalizePath(props.input.filePath!)}{" "}
|
|
1754
|
+
{input({
|
|
1755
|
+
replaceAll: props.input.replaceAll,
|
|
1756
|
+
})}
|
|
1757
|
+
</ToolTitle>
|
|
1758
|
+
<Show when={diffContent()}>
|
|
1759
|
+
<box paddingLeft={1}>
|
|
1760
|
+
<diff
|
|
1761
|
+
diff={diffContent()}
|
|
1762
|
+
view={view()}
|
|
1763
|
+
filetype={ft()}
|
|
1764
|
+
syntaxStyle={syntax()}
|
|
1765
|
+
showLineNumbers={true}
|
|
1766
|
+
width="100%"
|
|
1767
|
+
wrapMode={ctx.diffWrapMode()}
|
|
1768
|
+
fg={theme.text}
|
|
1769
|
+
addedBg={theme.diffAddedBg}
|
|
1770
|
+
removedBg={theme.diffRemovedBg}
|
|
1771
|
+
contextBg={theme.diffContextBg}
|
|
1772
|
+
addedSignColor={theme.diffHighlightAdded}
|
|
1773
|
+
removedSignColor={theme.diffHighlightRemoved}
|
|
1774
|
+
lineNumberFg={theme.diffLineNumber}
|
|
1775
|
+
lineNumberBg={theme.diffContextBg}
|
|
1776
|
+
addedLineNumberBg={theme.diffAddedLineNumberBg}
|
|
1777
|
+
removedLineNumberBg={theme.diffRemovedLineNumberBg}
|
|
1778
|
+
/>
|
|
1779
|
+
</box>
|
|
1780
|
+
</Show>
|
|
1781
|
+
<Show when={diagnostics().length}>
|
|
1782
|
+
<box>
|
|
1783
|
+
<For each={diagnostics()}>
|
|
1784
|
+
{(diagnostic) => (
|
|
1785
|
+
<text fg={theme.error}>
|
|
1786
|
+
Error [{diagnostic.range.start.line + 1}:{diagnostic.range.start.character + 1}] {diagnostic.message}
|
|
1787
|
+
</text>
|
|
1788
|
+
)}
|
|
1789
|
+
</For>
|
|
1790
|
+
</box>
|
|
1791
|
+
</Show>
|
|
1792
|
+
</>
|
|
1793
|
+
)
|
|
1794
|
+
},
|
|
1795
|
+
})
|
|
1796
|
+
|
|
1797
|
+
ToolRegistry.register<typeof PatchTool>({
|
|
1798
|
+
name: "patch",
|
|
1799
|
+
container: "block",
|
|
1800
|
+
render(props) {
|
|
1801
|
+
const { theme } = useTheme()
|
|
1802
|
+
return (
|
|
1803
|
+
<>
|
|
1804
|
+
<ToolTitle icon="%" fallback="Preparing patch..." when={true}>
|
|
1805
|
+
Patch
|
|
1806
|
+
</ToolTitle>
|
|
1807
|
+
<Show when={props.output}>
|
|
1808
|
+
<box>
|
|
1809
|
+
<text fg={theme.text}>{props.output?.trim()}</text>
|
|
1810
|
+
</box>
|
|
1811
|
+
</Show>
|
|
1812
|
+
</>
|
|
1813
|
+
)
|
|
1814
|
+
},
|
|
1815
|
+
})
|
|
1816
|
+
|
|
1817
|
+
ToolRegistry.register<typeof TodoWriteTool>({
|
|
1818
|
+
name: "todowrite",
|
|
1819
|
+
container: "block",
|
|
1820
|
+
render(props) {
|
|
1821
|
+
const { theme } = useTheme()
|
|
1822
|
+
return (
|
|
1823
|
+
<>
|
|
1824
|
+
<Show when={!props.input.todos?.length}>
|
|
1825
|
+
<ToolTitle icon="⚙" fallback="Updating todos..." when={true}>
|
|
1826
|
+
Updating todos...
|
|
1827
|
+
</ToolTitle>
|
|
1828
|
+
</Show>
|
|
1829
|
+
<Show when={props.metadata.todos?.length}>
|
|
1830
|
+
<box>
|
|
1831
|
+
<For each={props.input.todos ?? []}>
|
|
1832
|
+
{(todo) => <TodoItem status={todo.status} content={todo.content} />}
|
|
1833
|
+
</For>
|
|
1834
|
+
</box>
|
|
1835
|
+
</Show>
|
|
1836
|
+
</>
|
|
1837
|
+
)
|
|
1838
|
+
},
|
|
1839
|
+
})
|
|
1840
|
+
|
|
1841
|
+
function normalizePath(input?: string) {
|
|
1842
|
+
if (!input) return ""
|
|
1843
|
+
if (path.isAbsolute(input)) {
|
|
1844
|
+
return path.relative(process.cwd(), input) || "."
|
|
1845
|
+
}
|
|
1846
|
+
return input
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
function input(input: Record<string, any>, omit?: string[]): string {
|
|
1850
|
+
const primitives = Object.entries(input).filter(([key, value]) => {
|
|
1851
|
+
if (omit?.includes(key)) return false
|
|
1852
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean"
|
|
1853
|
+
})
|
|
1854
|
+
if (primitives.length === 0) return ""
|
|
1855
|
+
return `[${primitives.map(([key, value]) => `${key}=${value}`).join(", ")}]`
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
function filetype(input?: string) {
|
|
1859
|
+
if (!input) return "none"
|
|
1860
|
+
const ext = path.extname(input)
|
|
1861
|
+
const language = LANGUAGE_EXTENSIONS[ext]
|
|
1862
|
+
if (["typescriptreact", "javascriptreact", "javascript"].includes(language)) return "typescript"
|
|
1863
|
+
return language
|
|
1864
|
+
}
|