chad-code 1.3.1 → 1.3.2
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 +55 -6
- package/package.json +36 -98
- package/AGENTS.md +0 -27
- package/Dockerfile +0 -18
- package/README.npm.md +0 -64
- package/bunfig.toml +0 -7
- package/eslint.config.js +0 -29
- package/parsers-config.ts +0 -253
- package/script/build.ts +0 -167
- package/script/publish-registries.ts +0 -187
- package/script/publish.ts +0 -93
- package/script/schema.ts +0 -47
- package/src/acp/README.md +0 -164
- package/src/acp/agent.ts +0 -1086
- package/src/acp/session.ts +0 -101
- package/src/acp/types.ts +0 -22
- package/src/agent/agent.ts +0 -253
- package/src/agent/generate.txt +0 -75
- package/src/agent/prompt/compaction.txt +0 -12
- package/src/agent/prompt/explore.txt +0 -18
- package/src/agent/prompt/summary.txt +0 -11
- package/src/agent/prompt/title.txt +0 -36
- package/src/auth/index.ts +0 -70
- package/src/bun/index.ts +0 -130
- package/src/bus/bus-event.ts +0 -43
- package/src/bus/global.ts +0 -10
- package/src/bus/index.ts +0 -105
- package/src/cli/bootstrap.ts +0 -17
- package/src/cli/cmd/acp.ts +0 -69
- package/src/cli/cmd/agent.ts +0 -257
- package/src/cli/cmd/auth.ts +0 -132
- package/src/cli/cmd/cmd.ts +0 -7
- package/src/cli/cmd/debug/agent.ts +0 -28
- package/src/cli/cmd/debug/config.ts +0 -15
- package/src/cli/cmd/debug/file.ts +0 -91
- package/src/cli/cmd/debug/index.ts +0 -45
- package/src/cli/cmd/debug/lsp.ts +0 -48
- package/src/cli/cmd/debug/ripgrep.ts +0 -83
- package/src/cli/cmd/debug/scrap.ts +0 -15
- package/src/cli/cmd/debug/skill.ts +0 -15
- package/src/cli/cmd/debug/snapshot.ts +0 -48
- package/src/cli/cmd/export.ts +0 -88
- package/src/cli/cmd/generate.ts +0 -38
- package/src/cli/cmd/github.ts +0 -32
- package/src/cli/cmd/import.ts +0 -98
- package/src/cli/cmd/mcp.ts +0 -670
- package/src/cli/cmd/models.ts +0 -42
- package/src/cli/cmd/pr.ts +0 -112
- package/src/cli/cmd/run.ts +0 -374
- package/src/cli/cmd/serve.ts +0 -16
- package/src/cli/cmd/session.ts +0 -135
- package/src/cli/cmd/stats.ts +0 -402
- package/src/cli/cmd/tui/app.tsx +0 -705
- package/src/cli/cmd/tui/attach.ts +0 -32
- package/src/cli/cmd/tui/component/border.tsx +0 -21
- package/src/cli/cmd/tui/component/dialog-agent.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-command.tsx +0 -124
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-model.tsx +0 -232
- package/src/cli/cmd/tui/component/dialog-provider.tsx +0 -228
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +0 -115
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +0 -31
- package/src/cli/cmd/tui/component/dialog-stash.tsx +0 -86
- package/src/cli/cmd/tui/component/dialog-status.tsx +0 -162
- package/src/cli/cmd/tui/component/dialog-tag.tsx +0 -44
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +0 -50
- package/src/cli/cmd/tui/component/did-you-know.tsx +0 -85
- package/src/cli/cmd/tui/component/logo.tsx +0 -43
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +0 -654
- package/src/cli/cmd/tui/component/prompt/history.tsx +0 -108
- package/src/cli/cmd/tui/component/prompt/index.tsx +0 -1078
- package/src/cli/cmd/tui/component/prompt/stash.tsx +0 -101
- package/src/cli/cmd/tui/component/textarea-keybindings.ts +0 -73
- package/src/cli/cmd/tui/component/tips.ts +0 -92
- package/src/cli/cmd/tui/component/todo-item.tsx +0 -32
- package/src/cli/cmd/tui/context/args.tsx +0 -14
- package/src/cli/cmd/tui/context/directory.ts +0 -13
- package/src/cli/cmd/tui/context/exit.tsx +0 -23
- package/src/cli/cmd/tui/context/helper.tsx +0 -25
- package/src/cli/cmd/tui/context/keybind.tsx +0 -101
- package/src/cli/cmd/tui/context/kv.tsx +0 -49
- package/src/cli/cmd/tui/context/local.tsx +0 -392
- package/src/cli/cmd/tui/context/prompt.tsx +0 -18
- package/src/cli/cmd/tui/context/route.tsx +0 -46
- package/src/cli/cmd/tui/context/sdk.tsx +0 -75
- package/src/cli/cmd/tui/context/sync.tsx +0 -384
- package/src/cli/cmd/tui/context/theme/aura.json +0 -69
- package/src/cli/cmd/tui/context/theme/ayu.json +0 -80
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +0 -233
- package/src/cli/cmd/tui/context/theme/catppuccin.json +0 -112
- package/src/cli/cmd/tui/context/theme/chad.json +0 -245
- package/src/cli/cmd/tui/context/theme/cobalt2.json +0 -228
- package/src/cli/cmd/tui/context/theme/cursor.json +0 -249
- package/src/cli/cmd/tui/context/theme/dracula.json +0 -219
- package/src/cli/cmd/tui/context/theme/everforest.json +0 -241
- package/src/cli/cmd/tui/context/theme/flexoki.json +0 -237
- package/src/cli/cmd/tui/context/theme/github.json +0 -233
- package/src/cli/cmd/tui/context/theme/gruvbox.json +0 -95
- package/src/cli/cmd/tui/context/theme/kanagawa.json +0 -77
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +0 -227
- package/src/cli/cmd/tui/context/theme/material.json +0 -235
- package/src/cli/cmd/tui/context/theme/matrix.json +0 -77
- package/src/cli/cmd/tui/context/theme/mercury.json +0 -252
- package/src/cli/cmd/tui/context/theme/monokai.json +0 -221
- package/src/cli/cmd/tui/context/theme/nightowl.json +0 -221
- package/src/cli/cmd/tui/context/theme/nord.json +0 -223
- package/src/cli/cmd/tui/context/theme/one-dark.json +0 -84
- package/src/cli/cmd/tui/context/theme/orng.json +0 -245
- package/src/cli/cmd/tui/context/theme/osaka-jade.json +0 -93
- package/src/cli/cmd/tui/context/theme/palenight.json +0 -222
- package/src/cli/cmd/tui/context/theme/rosepine.json +0 -234
- package/src/cli/cmd/tui/context/theme/solarized.json +0 -223
- package/src/cli/cmd/tui/context/theme/synthwave84.json +0 -226
- package/src/cli/cmd/tui/context/theme/tokyonight.json +0 -243
- package/src/cli/cmd/tui/context/theme/vercel.json +0 -245
- package/src/cli/cmd/tui/context/theme/vesper.json +0 -218
- package/src/cli/cmd/tui/context/theme/zenburn.json +0 -223
- package/src/cli/cmd/tui/context/theme.tsx +0 -1137
- package/src/cli/cmd/tui/event.ts +0 -46
- package/src/cli/cmd/tui/routes/home.tsx +0 -138
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +0 -64
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +0 -109
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +0 -26
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +0 -47
- package/src/cli/cmd/tui/routes/session/footer.tsx +0 -88
- package/src/cli/cmd/tui/routes/session/header.tsx +0 -125
- package/src/cli/cmd/tui/routes/session/index.tsx +0 -1814
- package/src/cli/cmd/tui/routes/session/permission.tsx +0 -416
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +0 -318
- package/src/cli/cmd/tui/spawn.ts +0 -48
- package/src/cli/cmd/tui/thread.ts +0 -111
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +0 -57
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +0 -83
- package/src/cli/cmd/tui/ui/dialog-export-options.tsx +0 -204
- package/src/cli/cmd/tui/ui/dialog-help.tsx +0 -38
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +0 -77
- package/src/cli/cmd/tui/ui/dialog-select.tsx +0 -345
- package/src/cli/cmd/tui/ui/dialog.tsx +0 -171
- package/src/cli/cmd/tui/ui/link.tsx +0 -28
- package/src/cli/cmd/tui/ui/spinner.ts +0 -368
- package/src/cli/cmd/tui/ui/toast.tsx +0 -100
- package/src/cli/cmd/tui/util/clipboard.ts +0 -127
- package/src/cli/cmd/tui/util/editor.ts +0 -32
- package/src/cli/cmd/tui/util/signal.ts +0 -7
- package/src/cli/cmd/tui/util/terminal.ts +0 -114
- package/src/cli/cmd/tui/util/transcript.ts +0 -98
- package/src/cli/cmd/tui/worker.ts +0 -68
- package/src/cli/cmd/uninstall.ts +0 -344
- package/src/cli/cmd/upgrade.ts +0 -67
- package/src/cli/cmd/web.ts +0 -73
- package/src/cli/error.ts +0 -56
- package/src/cli/network.ts +0 -53
- package/src/cli/ui.ts +0 -87
- package/src/cli/upgrade.ts +0 -25
- package/src/command/index.ts +0 -131
- package/src/command/template/initialize.txt +0 -10
- package/src/command/template/review.txt +0 -97
- package/src/config/config.ts +0 -1124
- package/src/config/markdown.ts +0 -41
- package/src/env/index.ts +0 -26
- package/src/file/ignore.ts +0 -83
- package/src/file/index.ts +0 -411
- package/src/file/ripgrep.ts +0 -402
- package/src/file/time.ts +0 -64
- package/src/file/watcher.ts +0 -117
- package/src/flag/flag.ts +0 -52
- package/src/format/formatter.ts +0 -359
- package/src/format/index.ts +0 -137
- package/src/global/index.ts +0 -55
- package/src/id/id.ts +0 -73
- package/src/ide/index.ts +0 -77
- package/src/index.ts +0 -159
- package/src/installation/index.ts +0 -198
- package/src/lsp/client.ts +0 -252
- package/src/lsp/index.ts +0 -485
- package/src/lsp/language.ts +0 -119
- package/src/lsp/server.ts +0 -2023
- package/src/mcp/auth.ts +0 -135
- package/src/mcp/index.ts +0 -874
- package/src/mcp/oauth-callback.ts +0 -200
- package/src/mcp/oauth-provider.ts +0 -154
- package/src/patch/index.ts +0 -622
- package/src/permission/arity.ts +0 -163
- package/src/permission/index.ts +0 -210
- package/src/permission/next.ts +0 -268
- package/src/plugin/index.ts +0 -106
- package/src/project/bootstrap.ts +0 -31
- package/src/project/instance.ts +0 -78
- package/src/project/project.ts +0 -263
- package/src/project/state.ts +0 -65
- package/src/project/vcs.ts +0 -76
- package/src/provider/auth.ts +0 -143
- package/src/provider/models-macro.ts +0 -4
- package/src/provider/models.ts +0 -77
- package/src/provider/provider.ts +0 -516
- package/src/provider/transform.ts +0 -114
- package/src/pty/index.ts +0 -212
- package/src/server/error.ts +0 -36
- package/src/server/mdns.ts +0 -57
- package/src/server/project.ts +0 -79
- package/src/server/server.ts +0 -2866
- package/src/server/tui.ts +0 -71
- package/src/session/compaction.ts +0 -225
- package/src/session/index.ts +0 -469
- package/src/session/llm.ts +0 -213
- package/src/session/message-v2.ts +0 -742
- package/src/session/message.ts +0 -189
- package/src/session/processor.ts +0 -402
- package/src/session/prompt/anthropic-20250930.txt +0 -166
- package/src/session/prompt/anthropic.txt +0 -105
- package/src/session/prompt/anthropic_spoof.txt +0 -1
- package/src/session/prompt/beast.txt +0 -147
- package/src/session/prompt/build-switch.txt +0 -5
- package/src/session/prompt/codex.txt +0 -318
- package/src/session/prompt/copilot-gpt-5.txt +0 -143
- package/src/session/prompt/gemini.txt +0 -155
- package/src/session/prompt/max-steps.txt +0 -16
- package/src/session/prompt/plan-reminder-anthropic.txt +0 -67
- package/src/session/prompt/plan.txt +0 -26
- package/src/session/prompt/qwen.txt +0 -109
- package/src/session/prompt.ts +0 -1621
- package/src/session/retry.ts +0 -90
- package/src/session/revert.ts +0 -108
- package/src/session/status.ts +0 -76
- package/src/session/summary.ts +0 -194
- package/src/session/system.ts +0 -108
- package/src/session/todo.ts +0 -37
- package/src/share/share-next.ts +0 -194
- package/src/share/share.ts +0 -23
- package/src/shell/shell.ts +0 -67
- package/src/skill/index.ts +0 -1
- package/src/skill/skill.ts +0 -124
- package/src/snapshot/index.ts +0 -197
- package/src/storage/storage.ts +0 -226
- package/src/tool/bash.ts +0 -262
- package/src/tool/bash.txt +0 -116
- package/src/tool/batch.ts +0 -175
- package/src/tool/batch.txt +0 -24
- package/src/tool/codesearch.ts +0 -132
- package/src/tool/codesearch.txt +0 -12
- package/src/tool/edit.ts +0 -655
- package/src/tool/edit.txt +0 -10
- package/src/tool/glob.ts +0 -75
- package/src/tool/glob.txt +0 -6
- package/src/tool/grep.ts +0 -132
- package/src/tool/grep.txt +0 -8
- package/src/tool/invalid.ts +0 -17
- package/src/tool/ls.ts +0 -119
- package/src/tool/ls.txt +0 -1
- package/src/tool/lsp.ts +0 -94
- package/src/tool/lsp.txt +0 -19
- package/src/tool/multiedit.ts +0 -46
- package/src/tool/multiedit.txt +0 -41
- package/src/tool/patch.ts +0 -210
- package/src/tool/patch.txt +0 -1
- package/src/tool/read.ts +0 -191
- package/src/tool/read.txt +0 -12
- package/src/tool/registry.ts +0 -137
- package/src/tool/skill.ts +0 -77
- package/src/tool/task.ts +0 -167
- package/src/tool/task.txt +0 -60
- package/src/tool/todo.ts +0 -53
- package/src/tool/todoread.txt +0 -14
- package/src/tool/todowrite.txt +0 -167
- package/src/tool/tool.ts +0 -73
- package/src/tool/webfetch.ts +0 -182
- package/src/tool/webfetch.txt +0 -13
- package/src/tool/websearch.ts +0 -144
- package/src/tool/websearch.txt +0 -11
- package/src/tool/write.ts +0 -84
- package/src/tool/write.txt +0 -8
- package/src/util/archive.ts +0 -16
- package/src/util/color.ts +0 -19
- package/src/util/context.ts +0 -25
- package/src/util/defer.ts +0 -12
- package/src/util/eventloop.ts +0 -20
- package/src/util/filesystem.ts +0 -83
- package/src/util/fn.ts +0 -11
- package/src/util/iife.ts +0 -3
- package/src/util/keybind.ts +0 -102
- package/src/util/lazy.ts +0 -18
- package/src/util/locale.ts +0 -81
- package/src/util/lock.ts +0 -98
- package/src/util/log.ts +0 -180
- package/src/util/queue.ts +0 -32
- package/src/util/rpc.ts +0 -42
- package/src/util/scrap.ts +0 -10
- package/src/util/signal.ts +0 -12
- package/src/util/timeout.ts +0 -14
- package/src/util/token.ts +0 -7
- package/src/util/wildcard.ts +0 -54
- package/src/worktree/index.ts +0 -217
- package/sst-env.d.ts +0 -9
- package/test/agent/agent.test.ts +0 -448
- package/test/bun.test.ts +0 -53
- package/test/cli/github-action.test.ts +0 -129
- package/test/cli/github-remote.test.ts +0 -80
- package/test/cli/tui/transcript.test.ts +0 -297
- package/test/config/agent-color.test.ts +0 -66
- package/test/config/config.test.ts +0 -870
- package/test/config/markdown.test.ts +0 -89
- package/test/file/ignore.test.ts +0 -10
- package/test/file/path-traversal.test.ts +0 -115
- package/test/fixture/fixture.ts +0 -45
- package/test/fixture/lsp/fake-lsp-server.js +0 -77
- package/test/ide/ide.test.ts +0 -82
- package/test/keybind.test.ts +0 -421
- package/test/lsp/client.test.ts +0 -95
- package/test/mcp/headers.test.ts +0 -153
- package/test/patch/patch.test.ts +0 -348
- package/test/permission/arity.test.ts +0 -33
- package/test/permission/next.test.ts +0 -652
- package/test/preload.ts +0 -63
- package/test/project/project.test.ts +0 -120
- package/test/provider/amazon-bedrock.test.ts +0 -236
- package/test/provider/provider.test.ts +0 -2127
- package/test/provider/transform.test.ts +0 -980
- package/test/server/session-select.test.ts +0 -78
- package/test/session/compaction.test.ts +0 -251
- package/test/session/message-v2.test.ts +0 -570
- package/test/session/retry.test.ts +0 -131
- package/test/session/revert-compact.test.ts +0 -285
- package/test/session/session.test.ts +0 -71
- package/test/skill/skill.test.ts +0 -185
- package/test/snapshot/snapshot.test.ts +0 -939
- package/test/tool/__snapshots__/tool.test.ts.snap +0 -9
- package/test/tool/bash.test.ts +0 -232
- package/test/tool/grep.test.ts +0 -109
- package/test/tool/patch.test.ts +0 -261
- package/test/tool/read.test.ts +0 -167
- package/test/util/iife.test.ts +0 -36
- package/test/util/lazy.test.ts +0 -50
- package/test/util/timeout.test.ts +0 -21
- package/test/util/wildcard.test.ts +0 -55
- package/tsconfig.json +0 -16
- /package/{script/postinstall.mjs → postinstall.mjs} +0 -0
|
@@ -1,1078 +0,0 @@
|
|
|
1
|
-
import { BoxRenderable, TextareaRenderable, MouseEvent, PasteEvent, t, dim, fg } from "@opentui/core"
|
|
2
|
-
import { createEffect, createMemo, type JSX, onMount, createSignal, onCleanup, Show, Switch, Match } from "solid-js"
|
|
3
|
-
import "opentui-spinner/solid"
|
|
4
|
-
import { useLocal } from "@tui/context/local"
|
|
5
|
-
import { useTheme } from "@tui/context/theme"
|
|
6
|
-
import { EmptyBorder } from "@tui/component/border"
|
|
7
|
-
import { useSDK } from "@tui/context/sdk"
|
|
8
|
-
import { useRoute } from "@tui/context/route"
|
|
9
|
-
import { useSync } from "@tui/context/sync"
|
|
10
|
-
import { Identifier } from "@/id/id"
|
|
11
|
-
import { createStore, produce } from "solid-js/store"
|
|
12
|
-
import { useKeybind } from "@tui/context/keybind"
|
|
13
|
-
import { usePromptHistory, type PromptInfo } from "./history"
|
|
14
|
-
import { usePromptStash } from "./stash"
|
|
15
|
-
import { DialogStash } from "../dialog-stash"
|
|
16
|
-
import { type AutocompleteRef, Autocomplete } from "./autocomplete"
|
|
17
|
-
import { useCommandDialog } from "../dialog-command"
|
|
18
|
-
import { useRenderer } from "@opentui/solid"
|
|
19
|
-
import { Editor } from "@tui/util/editor"
|
|
20
|
-
import { useExit } from "../../context/exit"
|
|
21
|
-
import { Clipboard } from "../../util/clipboard"
|
|
22
|
-
import type { FilePart } from "@opencode-ai/sdk/v2"
|
|
23
|
-
import { TuiEvent } from "../../event"
|
|
24
|
-
import { iife } from "@/util/iife"
|
|
25
|
-
import { Locale } from "@/util/locale"
|
|
26
|
-
import { createColors, createFrames } from "../../ui/spinner.ts"
|
|
27
|
-
import { useDialog } from "@tui/ui/dialog"
|
|
28
|
-
import { DialogProvider as DialogProviderConnect } from "../dialog-provider"
|
|
29
|
-
import { DialogAlert } from "../../ui/dialog-alert"
|
|
30
|
-
import { useToast } from "../../ui/toast"
|
|
31
|
-
import { useKV } from "../../context/kv"
|
|
32
|
-
import { useTextareaKeybindings } from "../textarea-keybindings"
|
|
33
|
-
|
|
34
|
-
export type PromptProps = {
|
|
35
|
-
sessionID?: string
|
|
36
|
-
visible?: boolean
|
|
37
|
-
disabled?: boolean
|
|
38
|
-
onSubmit?: () => void
|
|
39
|
-
ref?: (ref: PromptRef) => void
|
|
40
|
-
hint?: JSX.Element
|
|
41
|
-
showPlaceholder?: boolean
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export type PromptRef = {
|
|
45
|
-
focused: boolean
|
|
46
|
-
current: PromptInfo
|
|
47
|
-
set(prompt: PromptInfo): void
|
|
48
|
-
reset(): void
|
|
49
|
-
blur(): void
|
|
50
|
-
focus(): void
|
|
51
|
-
submit(): void
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const PLACEHOLDERS = ["Fix a TODO in the codebase", "What is the tech stack of this project?", "Fix broken tests"]
|
|
55
|
-
|
|
56
|
-
export function Prompt(props: PromptProps) {
|
|
57
|
-
let input: TextareaRenderable
|
|
58
|
-
let anchor: BoxRenderable
|
|
59
|
-
let autocomplete: AutocompleteRef
|
|
60
|
-
|
|
61
|
-
const keybind = useKeybind()
|
|
62
|
-
const local = useLocal()
|
|
63
|
-
const sdk = useSDK()
|
|
64
|
-
const route = useRoute()
|
|
65
|
-
const sync = useSync()
|
|
66
|
-
const dialog = useDialog()
|
|
67
|
-
const toast = useToast()
|
|
68
|
-
const status = createMemo(() => sync.data.session_status?.[props.sessionID ?? ""] ?? { type: "idle" })
|
|
69
|
-
const history = usePromptHistory()
|
|
70
|
-
const stash = usePromptStash()
|
|
71
|
-
const command = useCommandDialog()
|
|
72
|
-
const renderer = useRenderer()
|
|
73
|
-
const { theme, syntax } = useTheme()
|
|
74
|
-
const kv = useKV()
|
|
75
|
-
|
|
76
|
-
function promptModelWarning() {
|
|
77
|
-
toast.show({
|
|
78
|
-
variant: "warning",
|
|
79
|
-
message: "Enter your Chadcode API key to send prompts",
|
|
80
|
-
duration: 3000,
|
|
81
|
-
})
|
|
82
|
-
if (sync.data.provider.length === 0) {
|
|
83
|
-
dialog.replace(() => <DialogProviderConnect />)
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const textareaKeybindings = useTextareaKeybindings()
|
|
88
|
-
|
|
89
|
-
const fileStyleId = syntax().getStyleId("extmark.file")!
|
|
90
|
-
const agentStyleId = syntax().getStyleId("extmark.agent")!
|
|
91
|
-
const pasteStyleId = syntax().getStyleId("extmark.paste")!
|
|
92
|
-
let promptPartTypeId: number
|
|
93
|
-
|
|
94
|
-
sdk.event.on(TuiEvent.PromptAppend.type, (evt) => {
|
|
95
|
-
input.insertText(evt.properties.text)
|
|
96
|
-
setTimeout(() => {
|
|
97
|
-
input.getLayoutNode().markDirty()
|
|
98
|
-
input.gotoBufferEnd()
|
|
99
|
-
renderer.requestRender()
|
|
100
|
-
}, 0)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
createEffect(() => {
|
|
104
|
-
if (props.disabled) input.cursorColor = theme.backgroundElement
|
|
105
|
-
if (!props.disabled) input.cursorColor = theme.text
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
const lastUserMessage = createMemo(() => {
|
|
109
|
-
if (!props.sessionID) return undefined
|
|
110
|
-
const messages = sync.data.message[props.sessionID]
|
|
111
|
-
if (!messages) return undefined
|
|
112
|
-
return messages.findLast((m) => m.role === "user")
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
const [store, setStore] = createStore<{
|
|
116
|
-
prompt: PromptInfo
|
|
117
|
-
mode: "normal" | "shell"
|
|
118
|
-
extmarkToPartIndex: Map<number, number>
|
|
119
|
-
interrupt: number
|
|
120
|
-
placeholder: number
|
|
121
|
-
}>({
|
|
122
|
-
placeholder: Math.floor(Math.random() * PLACEHOLDERS.length),
|
|
123
|
-
prompt: {
|
|
124
|
-
input: "",
|
|
125
|
-
parts: [],
|
|
126
|
-
},
|
|
127
|
-
mode: "normal",
|
|
128
|
-
extmarkToPartIndex: new Map(),
|
|
129
|
-
interrupt: 0,
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
// Initialize agent/model/variant from last user message when session changes
|
|
133
|
-
let syncedSessionID: string | undefined
|
|
134
|
-
createEffect(() => {
|
|
135
|
-
const sessionID = props.sessionID
|
|
136
|
-
const msg = lastUserMessage()
|
|
137
|
-
|
|
138
|
-
if (sessionID !== syncedSessionID) {
|
|
139
|
-
if (!sessionID || !msg) return
|
|
140
|
-
|
|
141
|
-
syncedSessionID = sessionID
|
|
142
|
-
|
|
143
|
-
// Only set agent if it's a primary agent (not a subagent)
|
|
144
|
-
const isPrimaryAgent = local.agent.list().some((x) => x.name === msg.agent)
|
|
145
|
-
if (msg.agent && isPrimaryAgent) {
|
|
146
|
-
local.agent.set(msg.agent)
|
|
147
|
-
}
|
|
148
|
-
if (msg.model) local.model.set(msg.model)
|
|
149
|
-
if (msg.variant) local.model.variant.set(msg.variant)
|
|
150
|
-
}
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
command.register(() => {
|
|
154
|
-
return [
|
|
155
|
-
{
|
|
156
|
-
title: "Clear prompt",
|
|
157
|
-
value: "prompt.clear",
|
|
158
|
-
category: "Prompt",
|
|
159
|
-
disabled: true,
|
|
160
|
-
onSelect: (dialog) => {
|
|
161
|
-
input.extmarks.clear()
|
|
162
|
-
input.clear()
|
|
163
|
-
dialog.clear()
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
title: "Submit prompt",
|
|
168
|
-
value: "prompt.submit",
|
|
169
|
-
disabled: true,
|
|
170
|
-
keybind: "input_submit",
|
|
171
|
-
category: "Prompt",
|
|
172
|
-
onSelect: (dialog) => {
|
|
173
|
-
if (!input.focused) return
|
|
174
|
-
submit()
|
|
175
|
-
dialog.clear()
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
title: "Paste",
|
|
180
|
-
value: "prompt.paste",
|
|
181
|
-
disabled: true,
|
|
182
|
-
keybind: "input_paste",
|
|
183
|
-
category: "Prompt",
|
|
184
|
-
onSelect: async () => {
|
|
185
|
-
const content = await Clipboard.read()
|
|
186
|
-
if (content?.mime.startsWith("image/")) {
|
|
187
|
-
await pasteImage({
|
|
188
|
-
filename: "clipboard",
|
|
189
|
-
mime: content.mime,
|
|
190
|
-
content: content.data,
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
title: "Interrupt session",
|
|
197
|
-
value: "session.interrupt",
|
|
198
|
-
keybind: "session_interrupt",
|
|
199
|
-
disabled: status().type === "idle",
|
|
200
|
-
category: "Session",
|
|
201
|
-
onSelect: (dialog) => {
|
|
202
|
-
if (autocomplete.visible) return
|
|
203
|
-
if (!input.focused) return
|
|
204
|
-
// TODO: this should be its own command
|
|
205
|
-
if (store.mode === "shell") {
|
|
206
|
-
setStore("mode", "normal")
|
|
207
|
-
return
|
|
208
|
-
}
|
|
209
|
-
if (!props.sessionID) return
|
|
210
|
-
|
|
211
|
-
setStore("interrupt", store.interrupt + 1)
|
|
212
|
-
|
|
213
|
-
setTimeout(() => {
|
|
214
|
-
setStore("interrupt", 0)
|
|
215
|
-
}, 5000)
|
|
216
|
-
|
|
217
|
-
if (store.interrupt >= 2) {
|
|
218
|
-
sdk.client.session.abort({
|
|
219
|
-
sessionID: props.sessionID,
|
|
220
|
-
})
|
|
221
|
-
setStore("interrupt", 0)
|
|
222
|
-
}
|
|
223
|
-
dialog.clear()
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
title: "Open editor",
|
|
228
|
-
category: "Session",
|
|
229
|
-
keybind: "editor_open",
|
|
230
|
-
value: "prompt.editor",
|
|
231
|
-
onSelect: async (dialog, trigger) => {
|
|
232
|
-
dialog.clear()
|
|
233
|
-
|
|
234
|
-
// replace summarized text parts with the actual text
|
|
235
|
-
const text = store.prompt.parts
|
|
236
|
-
.filter((p) => p.type === "text")
|
|
237
|
-
.reduce((acc, p) => {
|
|
238
|
-
if (!p.source) return acc
|
|
239
|
-
return acc.replace(p.source.text.value, p.text)
|
|
240
|
-
}, store.prompt.input)
|
|
241
|
-
|
|
242
|
-
const nonTextParts = store.prompt.parts.filter((p) => p.type !== "text")
|
|
243
|
-
|
|
244
|
-
const value = trigger === "prompt" ? "" : text
|
|
245
|
-
const content = await Editor.open({ value, renderer })
|
|
246
|
-
if (!content) return
|
|
247
|
-
|
|
248
|
-
input.setText(content)
|
|
249
|
-
|
|
250
|
-
// Update positions for nonTextParts based on their location in new content
|
|
251
|
-
// Filter out parts whose virtual text was deleted
|
|
252
|
-
// this handles a case where the user edits the text in the editor
|
|
253
|
-
// such that the virtual text moves around or is deleted
|
|
254
|
-
const updatedNonTextParts = nonTextParts
|
|
255
|
-
.map((part) => {
|
|
256
|
-
let virtualText = ""
|
|
257
|
-
if (part.type === "file" && part.source?.text) {
|
|
258
|
-
virtualText = part.source.text.value
|
|
259
|
-
} else if (part.type === "agent" && part.source) {
|
|
260
|
-
virtualText = part.source.value
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
if (!virtualText) return part
|
|
264
|
-
|
|
265
|
-
const newStart = content.indexOf(virtualText)
|
|
266
|
-
// if the virtual text is deleted, remove the part
|
|
267
|
-
if (newStart === -1) return null
|
|
268
|
-
|
|
269
|
-
const newEnd = newStart + virtualText.length
|
|
270
|
-
|
|
271
|
-
if (part.type === "file" && part.source?.text) {
|
|
272
|
-
return {
|
|
273
|
-
...part,
|
|
274
|
-
source: {
|
|
275
|
-
...part.source,
|
|
276
|
-
text: {
|
|
277
|
-
...part.source.text,
|
|
278
|
-
start: newStart,
|
|
279
|
-
end: newEnd,
|
|
280
|
-
},
|
|
281
|
-
},
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (part.type === "agent" && part.source) {
|
|
286
|
-
return {
|
|
287
|
-
...part,
|
|
288
|
-
source: {
|
|
289
|
-
...part.source,
|
|
290
|
-
start: newStart,
|
|
291
|
-
end: newEnd,
|
|
292
|
-
},
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return part
|
|
297
|
-
})
|
|
298
|
-
.filter((part) => part !== null)
|
|
299
|
-
|
|
300
|
-
setStore("prompt", {
|
|
301
|
-
input: content,
|
|
302
|
-
// keep only the non-text parts because the text parts were
|
|
303
|
-
// already expanded inline
|
|
304
|
-
parts: updatedNonTextParts,
|
|
305
|
-
})
|
|
306
|
-
restoreExtmarksFromParts(updatedNonTextParts)
|
|
307
|
-
input.cursorOffset = Bun.stringWidth(content)
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
]
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
createEffect(() => {
|
|
314
|
-
if (props.visible !== false) input?.focus()
|
|
315
|
-
if (props.visible === false) input?.blur()
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
onMount(() => {
|
|
319
|
-
promptPartTypeId = input.extmarks.registerType("prompt-part")
|
|
320
|
-
})
|
|
321
|
-
|
|
322
|
-
function restoreExtmarksFromParts(parts: PromptInfo["parts"]) {
|
|
323
|
-
input.extmarks.clear()
|
|
324
|
-
setStore("extmarkToPartIndex", new Map())
|
|
325
|
-
|
|
326
|
-
parts.forEach((part, partIndex) => {
|
|
327
|
-
let start = 0
|
|
328
|
-
let end = 0
|
|
329
|
-
let virtualText = ""
|
|
330
|
-
let styleId: number | undefined
|
|
331
|
-
|
|
332
|
-
if (part.type === "file" && part.source?.text) {
|
|
333
|
-
start = part.source.text.start
|
|
334
|
-
end = part.source.text.end
|
|
335
|
-
virtualText = part.source.text.value
|
|
336
|
-
styleId = fileStyleId
|
|
337
|
-
} else if (part.type === "agent" && part.source) {
|
|
338
|
-
start = part.source.start
|
|
339
|
-
end = part.source.end
|
|
340
|
-
virtualText = part.source.value
|
|
341
|
-
styleId = agentStyleId
|
|
342
|
-
} else if (part.type === "text" && part.source?.text) {
|
|
343
|
-
start = part.source.text.start
|
|
344
|
-
end = part.source.text.end
|
|
345
|
-
virtualText = part.source.text.value
|
|
346
|
-
styleId = pasteStyleId
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
if (virtualText) {
|
|
350
|
-
const extmarkId = input.extmarks.create({
|
|
351
|
-
start,
|
|
352
|
-
end,
|
|
353
|
-
virtual: true,
|
|
354
|
-
styleId,
|
|
355
|
-
typeId: promptPartTypeId,
|
|
356
|
-
})
|
|
357
|
-
setStore("extmarkToPartIndex", (map: Map<number, number>) => {
|
|
358
|
-
const newMap = new Map(map)
|
|
359
|
-
newMap.set(extmarkId, partIndex)
|
|
360
|
-
return newMap
|
|
361
|
-
})
|
|
362
|
-
}
|
|
363
|
-
})
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
function syncExtmarksWithPromptParts() {
|
|
367
|
-
const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
|
|
368
|
-
setStore(
|
|
369
|
-
produce((draft) => {
|
|
370
|
-
const newMap = new Map<number, number>()
|
|
371
|
-
const newParts: typeof draft.prompt.parts = []
|
|
372
|
-
|
|
373
|
-
for (const extmark of allExtmarks) {
|
|
374
|
-
const partIndex = draft.extmarkToPartIndex.get(extmark.id)
|
|
375
|
-
if (partIndex !== undefined) {
|
|
376
|
-
const part = draft.prompt.parts[partIndex]
|
|
377
|
-
if (part) {
|
|
378
|
-
if (part.type === "agent" && part.source) {
|
|
379
|
-
part.source.start = extmark.start
|
|
380
|
-
part.source.end = extmark.end
|
|
381
|
-
} else if (part.type === "file" && part.source?.text) {
|
|
382
|
-
part.source.text.start = extmark.start
|
|
383
|
-
part.source.text.end = extmark.end
|
|
384
|
-
} else if (part.type === "text" && part.source?.text) {
|
|
385
|
-
part.source.text.start = extmark.start
|
|
386
|
-
part.source.text.end = extmark.end
|
|
387
|
-
}
|
|
388
|
-
newMap.set(extmark.id, newParts.length)
|
|
389
|
-
newParts.push(part)
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
draft.extmarkToPartIndex = newMap
|
|
395
|
-
draft.prompt.parts = newParts
|
|
396
|
-
}),
|
|
397
|
-
)
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
command.register(() => [
|
|
401
|
-
{
|
|
402
|
-
title: "Stash prompt",
|
|
403
|
-
value: "prompt.stash",
|
|
404
|
-
category: "Prompt",
|
|
405
|
-
disabled: !store.prompt.input,
|
|
406
|
-
onSelect: (dialog) => {
|
|
407
|
-
if (!store.prompt.input) return
|
|
408
|
-
stash.push({
|
|
409
|
-
input: store.prompt.input,
|
|
410
|
-
parts: store.prompt.parts,
|
|
411
|
-
})
|
|
412
|
-
input.extmarks.clear()
|
|
413
|
-
input.clear()
|
|
414
|
-
setStore("prompt", { input: "", parts: [] })
|
|
415
|
-
setStore("extmarkToPartIndex", new Map())
|
|
416
|
-
dialog.clear()
|
|
417
|
-
},
|
|
418
|
-
},
|
|
419
|
-
{
|
|
420
|
-
title: "Stash pop",
|
|
421
|
-
value: "prompt.stash.pop",
|
|
422
|
-
category: "Prompt",
|
|
423
|
-
disabled: stash.list().length === 0,
|
|
424
|
-
onSelect: (dialog) => {
|
|
425
|
-
const entry = stash.pop()
|
|
426
|
-
if (entry) {
|
|
427
|
-
input.setText(entry.input)
|
|
428
|
-
setStore("prompt", { input: entry.input, parts: entry.parts })
|
|
429
|
-
restoreExtmarksFromParts(entry.parts)
|
|
430
|
-
input.gotoBufferEnd()
|
|
431
|
-
}
|
|
432
|
-
dialog.clear()
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
{
|
|
436
|
-
title: "Stash list",
|
|
437
|
-
value: "prompt.stash.list",
|
|
438
|
-
category: "Prompt",
|
|
439
|
-
disabled: stash.list().length === 0,
|
|
440
|
-
onSelect: (dialog) => {
|
|
441
|
-
dialog.replace(() => (
|
|
442
|
-
<DialogStash
|
|
443
|
-
onSelect={(entry) => {
|
|
444
|
-
input.setText(entry.input)
|
|
445
|
-
setStore("prompt", { input: entry.input, parts: entry.parts })
|
|
446
|
-
restoreExtmarksFromParts(entry.parts)
|
|
447
|
-
input.gotoBufferEnd()
|
|
448
|
-
}}
|
|
449
|
-
/>
|
|
450
|
-
))
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
])
|
|
454
|
-
|
|
455
|
-
props.ref?.({
|
|
456
|
-
get focused() {
|
|
457
|
-
return input.focused
|
|
458
|
-
},
|
|
459
|
-
get current() {
|
|
460
|
-
return store.prompt
|
|
461
|
-
},
|
|
462
|
-
focus() {
|
|
463
|
-
input.focus()
|
|
464
|
-
},
|
|
465
|
-
blur() {
|
|
466
|
-
input.blur()
|
|
467
|
-
},
|
|
468
|
-
set(prompt) {
|
|
469
|
-
input.setText(prompt.input)
|
|
470
|
-
setStore("prompt", prompt)
|
|
471
|
-
restoreExtmarksFromParts(prompt.parts)
|
|
472
|
-
input.gotoBufferEnd()
|
|
473
|
-
},
|
|
474
|
-
reset() {
|
|
475
|
-
input.clear()
|
|
476
|
-
input.extmarks.clear()
|
|
477
|
-
setStore("prompt", {
|
|
478
|
-
input: "",
|
|
479
|
-
parts: [],
|
|
480
|
-
})
|
|
481
|
-
setStore("extmarkToPartIndex", new Map())
|
|
482
|
-
},
|
|
483
|
-
submit() {
|
|
484
|
-
submit()
|
|
485
|
-
},
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
async function submit() {
|
|
489
|
-
if (props.disabled) return
|
|
490
|
-
if (autocomplete?.visible) return
|
|
491
|
-
if (!store.prompt.input) return
|
|
492
|
-
const trimmed = store.prompt.input.trim()
|
|
493
|
-
if (trimmed === "exit" || trimmed === "quit" || trimmed === ":q") {
|
|
494
|
-
exit()
|
|
495
|
-
return
|
|
496
|
-
}
|
|
497
|
-
const selectedModel = local.model.current()
|
|
498
|
-
if (!selectedModel) {
|
|
499
|
-
promptModelWarning()
|
|
500
|
-
return
|
|
501
|
-
}
|
|
502
|
-
const sessionID = props.sessionID
|
|
503
|
-
? props.sessionID
|
|
504
|
-
: await (async () => {
|
|
505
|
-
const sessionID = await sdk.client.session.create({}).then((x) => x.data!.id)
|
|
506
|
-
return sessionID
|
|
507
|
-
})()
|
|
508
|
-
const messageID = Identifier.ascending("message")
|
|
509
|
-
let inputText = store.prompt.input
|
|
510
|
-
|
|
511
|
-
// Expand pasted text inline before submitting
|
|
512
|
-
const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
|
|
513
|
-
const sortedExtmarks = allExtmarks.sort((a: { start: number }, b: { start: number }) => b.start - a.start)
|
|
514
|
-
|
|
515
|
-
for (const extmark of sortedExtmarks) {
|
|
516
|
-
const partIndex = store.extmarkToPartIndex.get(extmark.id)
|
|
517
|
-
if (partIndex !== undefined) {
|
|
518
|
-
const part = store.prompt.parts[partIndex]
|
|
519
|
-
if (part?.type === "text" && part.text) {
|
|
520
|
-
const before = inputText.slice(0, extmark.start)
|
|
521
|
-
const after = inputText.slice(extmark.end)
|
|
522
|
-
inputText = before + part.text + after
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
// Filter out text parts (pasted content) since they're now expanded inline
|
|
528
|
-
const nonTextParts = store.prompt.parts.filter((part) => part.type !== "text")
|
|
529
|
-
|
|
530
|
-
// Capture mode before it gets reset
|
|
531
|
-
const currentMode = store.mode
|
|
532
|
-
const variant = local.model.variant.current()
|
|
533
|
-
|
|
534
|
-
if (store.mode === "shell") {
|
|
535
|
-
sdk.client.session.shell({
|
|
536
|
-
sessionID,
|
|
537
|
-
agent: local.agent.current().name,
|
|
538
|
-
model: {
|
|
539
|
-
providerID: selectedModel.providerID,
|
|
540
|
-
modelID: selectedModel.modelID,
|
|
541
|
-
},
|
|
542
|
-
command: inputText,
|
|
543
|
-
})
|
|
544
|
-
setStore("mode", "normal")
|
|
545
|
-
} else if (
|
|
546
|
-
inputText.startsWith("/") &&
|
|
547
|
-
iife(() => {
|
|
548
|
-
const command = inputText.split(" ")[0].slice(1)
|
|
549
|
-
console.log(command)
|
|
550
|
-
return sync.data.command.some((x) => x.name === command)
|
|
551
|
-
})
|
|
552
|
-
) {
|
|
553
|
-
let [command, ...args] = inputText.split(" ")
|
|
554
|
-
sdk.client.session.command({
|
|
555
|
-
sessionID,
|
|
556
|
-
command: command.slice(1),
|
|
557
|
-
arguments: args.join(" "),
|
|
558
|
-
agent: local.agent.current().name,
|
|
559
|
-
model: `${selectedModel.providerID}/${selectedModel.modelID}`,
|
|
560
|
-
messageID,
|
|
561
|
-
variant,
|
|
562
|
-
})
|
|
563
|
-
} else {
|
|
564
|
-
sdk.client.session.prompt({
|
|
565
|
-
sessionID,
|
|
566
|
-
...selectedModel,
|
|
567
|
-
messageID,
|
|
568
|
-
agent: local.agent.current().name,
|
|
569
|
-
model: selectedModel,
|
|
570
|
-
variant,
|
|
571
|
-
parts: [
|
|
572
|
-
{
|
|
573
|
-
id: Identifier.ascending("part"),
|
|
574
|
-
type: "text",
|
|
575
|
-
text: inputText,
|
|
576
|
-
},
|
|
577
|
-
...nonTextParts.map((x) => ({
|
|
578
|
-
id: Identifier.ascending("part"),
|
|
579
|
-
...x,
|
|
580
|
-
})),
|
|
581
|
-
],
|
|
582
|
-
})
|
|
583
|
-
}
|
|
584
|
-
history.append({
|
|
585
|
-
...store.prompt,
|
|
586
|
-
mode: currentMode,
|
|
587
|
-
})
|
|
588
|
-
input.extmarks.clear()
|
|
589
|
-
setStore("prompt", {
|
|
590
|
-
input: "",
|
|
591
|
-
parts: [],
|
|
592
|
-
})
|
|
593
|
-
setStore("extmarkToPartIndex", new Map())
|
|
594
|
-
props.onSubmit?.()
|
|
595
|
-
|
|
596
|
-
// temporary hack to make sure the message is sent
|
|
597
|
-
if (!props.sessionID)
|
|
598
|
-
setTimeout(() => {
|
|
599
|
-
route.navigate({
|
|
600
|
-
type: "session",
|
|
601
|
-
sessionID,
|
|
602
|
-
})
|
|
603
|
-
}, 50)
|
|
604
|
-
input.clear()
|
|
605
|
-
}
|
|
606
|
-
const exit = useExit()
|
|
607
|
-
|
|
608
|
-
function pasteText(text: string, virtualText: string) {
|
|
609
|
-
const currentOffset = input.visualCursor.offset
|
|
610
|
-
const extmarkStart = currentOffset
|
|
611
|
-
const extmarkEnd = extmarkStart + virtualText.length
|
|
612
|
-
|
|
613
|
-
input.insertText(virtualText + " ")
|
|
614
|
-
|
|
615
|
-
const extmarkId = input.extmarks.create({
|
|
616
|
-
start: extmarkStart,
|
|
617
|
-
end: extmarkEnd,
|
|
618
|
-
virtual: true,
|
|
619
|
-
styleId: pasteStyleId,
|
|
620
|
-
typeId: promptPartTypeId,
|
|
621
|
-
})
|
|
622
|
-
|
|
623
|
-
setStore(
|
|
624
|
-
produce((draft) => {
|
|
625
|
-
const partIndex = draft.prompt.parts.length
|
|
626
|
-
draft.prompt.parts.push({
|
|
627
|
-
type: "text" as const,
|
|
628
|
-
text,
|
|
629
|
-
source: {
|
|
630
|
-
text: {
|
|
631
|
-
start: extmarkStart,
|
|
632
|
-
end: extmarkEnd,
|
|
633
|
-
value: virtualText,
|
|
634
|
-
},
|
|
635
|
-
},
|
|
636
|
-
})
|
|
637
|
-
draft.extmarkToPartIndex.set(extmarkId, partIndex)
|
|
638
|
-
}),
|
|
639
|
-
)
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
async function pasteImage(file: { filename?: string; content: string; mime: string }) {
|
|
643
|
-
const currentOffset = input.visualCursor.offset
|
|
644
|
-
const extmarkStart = currentOffset
|
|
645
|
-
const count = store.prompt.parts.filter((x) => x.type === "file").length
|
|
646
|
-
const virtualText = `[Image ${count + 1}]`
|
|
647
|
-
const extmarkEnd = extmarkStart + virtualText.length
|
|
648
|
-
const textToInsert = virtualText + " "
|
|
649
|
-
|
|
650
|
-
input.insertText(textToInsert)
|
|
651
|
-
|
|
652
|
-
const extmarkId = input.extmarks.create({
|
|
653
|
-
start: extmarkStart,
|
|
654
|
-
end: extmarkEnd,
|
|
655
|
-
virtual: true,
|
|
656
|
-
styleId: pasteStyleId,
|
|
657
|
-
typeId: promptPartTypeId,
|
|
658
|
-
})
|
|
659
|
-
|
|
660
|
-
const part: Omit<FilePart, "id" | "messageID" | "sessionID"> = {
|
|
661
|
-
type: "file" as const,
|
|
662
|
-
mime: file.mime,
|
|
663
|
-
filename: file.filename,
|
|
664
|
-
url: `data:${file.mime};base64,${file.content}`,
|
|
665
|
-
source: {
|
|
666
|
-
type: "file",
|
|
667
|
-
path: file.filename ?? "",
|
|
668
|
-
text: {
|
|
669
|
-
start: extmarkStart,
|
|
670
|
-
end: extmarkEnd,
|
|
671
|
-
value: virtualText,
|
|
672
|
-
},
|
|
673
|
-
},
|
|
674
|
-
}
|
|
675
|
-
setStore(
|
|
676
|
-
produce((draft) => {
|
|
677
|
-
const partIndex = draft.prompt.parts.length
|
|
678
|
-
draft.prompt.parts.push(part)
|
|
679
|
-
draft.extmarkToPartIndex.set(extmarkId, partIndex)
|
|
680
|
-
}),
|
|
681
|
-
)
|
|
682
|
-
return
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
const highlight = createMemo(() => {
|
|
686
|
-
if (keybind.leader) return theme.border
|
|
687
|
-
if (store.mode === "shell") return theme.primary
|
|
688
|
-
return local.agent.color(local.agent.current().name)
|
|
689
|
-
})
|
|
690
|
-
|
|
691
|
-
const showVariant = createMemo(() => {
|
|
692
|
-
const variants = local.model.variant.list()
|
|
693
|
-
if (variants.length === 0) return false
|
|
694
|
-
const current = local.model.variant.current()
|
|
695
|
-
return !!current
|
|
696
|
-
})
|
|
697
|
-
|
|
698
|
-
const spinnerDef = createMemo(() => {
|
|
699
|
-
const color = local.agent.color(local.agent.current().name)
|
|
700
|
-
return {
|
|
701
|
-
frames: createFrames({
|
|
702
|
-
color,
|
|
703
|
-
style: "blocks",
|
|
704
|
-
inactiveFactor: 0.6,
|
|
705
|
-
// enableFading: false,
|
|
706
|
-
minAlpha: 0.3,
|
|
707
|
-
}),
|
|
708
|
-
color: createColors({
|
|
709
|
-
color,
|
|
710
|
-
style: "blocks",
|
|
711
|
-
inactiveFactor: 0.6,
|
|
712
|
-
// enableFading: false,
|
|
713
|
-
minAlpha: 0.3,
|
|
714
|
-
}),
|
|
715
|
-
}
|
|
716
|
-
})
|
|
717
|
-
|
|
718
|
-
return (
|
|
719
|
-
<>
|
|
720
|
-
<Autocomplete
|
|
721
|
-
sessionID={props.sessionID}
|
|
722
|
-
ref={(r) => (autocomplete = r)}
|
|
723
|
-
anchor={() => anchor}
|
|
724
|
-
input={() => input}
|
|
725
|
-
setPrompt={(cb) => {
|
|
726
|
-
setStore("prompt", produce(cb))
|
|
727
|
-
}}
|
|
728
|
-
setExtmark={(partIndex, extmarkId) => {
|
|
729
|
-
setStore("extmarkToPartIndex", (map: Map<number, number>) => {
|
|
730
|
-
const newMap = new Map(map)
|
|
731
|
-
newMap.set(extmarkId, partIndex)
|
|
732
|
-
return newMap
|
|
733
|
-
})
|
|
734
|
-
}}
|
|
735
|
-
value={store.prompt.input}
|
|
736
|
-
fileStyleId={fileStyleId}
|
|
737
|
-
agentStyleId={agentStyleId}
|
|
738
|
-
promptPartTypeId={() => promptPartTypeId}
|
|
739
|
-
/>
|
|
740
|
-
<box ref={(r) => (anchor = r)} visible={props.visible !== false}>
|
|
741
|
-
<box
|
|
742
|
-
border={["left"]}
|
|
743
|
-
borderColor={highlight()}
|
|
744
|
-
customBorderChars={{
|
|
745
|
-
...EmptyBorder,
|
|
746
|
-
vertical: "┃",
|
|
747
|
-
bottomLeft: "╹",
|
|
748
|
-
}}
|
|
749
|
-
>
|
|
750
|
-
<box
|
|
751
|
-
paddingLeft={2}
|
|
752
|
-
paddingRight={2}
|
|
753
|
-
paddingTop={1}
|
|
754
|
-
flexShrink={0}
|
|
755
|
-
backgroundColor={theme.backgroundElement}
|
|
756
|
-
flexGrow={1}
|
|
757
|
-
>
|
|
758
|
-
<textarea
|
|
759
|
-
placeholder={props.sessionID ? undefined : `Ask anything... "${PLACEHOLDERS[store.placeholder]}"`}
|
|
760
|
-
textColor={keybind.leader ? theme.textMuted : theme.text}
|
|
761
|
-
focusedTextColor={keybind.leader ? theme.textMuted : theme.text}
|
|
762
|
-
minHeight={1}
|
|
763
|
-
maxHeight={6}
|
|
764
|
-
onContentChange={() => {
|
|
765
|
-
const value = input.plainText
|
|
766
|
-
setStore("prompt", "input", value)
|
|
767
|
-
autocomplete.onInput(value)
|
|
768
|
-
syncExtmarksWithPromptParts()
|
|
769
|
-
}}
|
|
770
|
-
keyBindings={textareaKeybindings()}
|
|
771
|
-
onKeyDown={async (e) => {
|
|
772
|
-
if (props.disabled) {
|
|
773
|
-
e.preventDefault()
|
|
774
|
-
return
|
|
775
|
-
}
|
|
776
|
-
// Handle clipboard paste (Ctrl+V) - check for images first on Windows
|
|
777
|
-
// This is needed because Windows terminal doesn't properly send image data
|
|
778
|
-
// through bracketed paste, so we need to intercept the keypress and
|
|
779
|
-
// directly read from clipboard before the terminal handles it
|
|
780
|
-
if (keybind.match("input_paste", e)) {
|
|
781
|
-
const content = await Clipboard.read()
|
|
782
|
-
if (content?.mime.startsWith("image/")) {
|
|
783
|
-
e.preventDefault()
|
|
784
|
-
await pasteImage({
|
|
785
|
-
filename: "clipboard",
|
|
786
|
-
mime: content.mime,
|
|
787
|
-
content: content.data,
|
|
788
|
-
})
|
|
789
|
-
return
|
|
790
|
-
}
|
|
791
|
-
// If no image, let the default paste behavior continue
|
|
792
|
-
}
|
|
793
|
-
if (keybind.match("input_clear", e) && store.prompt.input !== "") {
|
|
794
|
-
input.clear()
|
|
795
|
-
input.extmarks.clear()
|
|
796
|
-
setStore("prompt", {
|
|
797
|
-
input: "",
|
|
798
|
-
parts: [],
|
|
799
|
-
})
|
|
800
|
-
setStore("extmarkToPartIndex", new Map())
|
|
801
|
-
return
|
|
802
|
-
}
|
|
803
|
-
if (keybind.match("app_exit", e)) {
|
|
804
|
-
if (store.prompt.input === "") {
|
|
805
|
-
await exit()
|
|
806
|
-
// Don't preventDefault - let textarea potentially handle the event
|
|
807
|
-
e.preventDefault()
|
|
808
|
-
return
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
if (e.name === "!" && input.visualCursor.offset === 0) {
|
|
812
|
-
setStore("mode", "shell")
|
|
813
|
-
e.preventDefault()
|
|
814
|
-
return
|
|
815
|
-
}
|
|
816
|
-
if (store.mode === "shell") {
|
|
817
|
-
if ((e.name === "backspace" && input.visualCursor.offset === 0) || e.name === "escape") {
|
|
818
|
-
setStore("mode", "normal")
|
|
819
|
-
e.preventDefault()
|
|
820
|
-
return
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
if (store.mode === "normal") autocomplete.onKeyDown(e)
|
|
824
|
-
if (!autocomplete.visible) {
|
|
825
|
-
if (
|
|
826
|
-
(keybind.match("history_previous", e) && input.cursorOffset === 0) ||
|
|
827
|
-
(keybind.match("history_next", e) && input.cursorOffset === input.plainText.length)
|
|
828
|
-
) {
|
|
829
|
-
const direction = keybind.match("history_previous", e) ? -1 : 1
|
|
830
|
-
const item = history.move(direction, input.plainText)
|
|
831
|
-
|
|
832
|
-
if (item) {
|
|
833
|
-
input.setText(item.input)
|
|
834
|
-
setStore("prompt", item)
|
|
835
|
-
setStore("mode", item.mode ?? "normal")
|
|
836
|
-
restoreExtmarksFromParts(item.parts)
|
|
837
|
-
e.preventDefault()
|
|
838
|
-
if (direction === -1) input.cursorOffset = 0
|
|
839
|
-
if (direction === 1) input.cursorOffset = input.plainText.length
|
|
840
|
-
}
|
|
841
|
-
return
|
|
842
|
-
}
|
|
843
|
-
|
|
844
|
-
if (keybind.match("history_previous", e) && input.visualCursor.visualRow === 0) input.cursorOffset = 0
|
|
845
|
-
if (keybind.match("history_next", e) && input.visualCursor.visualRow === input.height - 1)
|
|
846
|
-
input.cursorOffset = input.plainText.length
|
|
847
|
-
}
|
|
848
|
-
}}
|
|
849
|
-
onSubmit={submit}
|
|
850
|
-
onPaste={async (event: PasteEvent) => {
|
|
851
|
-
if (props.disabled) {
|
|
852
|
-
event.preventDefault()
|
|
853
|
-
return
|
|
854
|
-
}
|
|
855
|
-
|
|
856
|
-
// Normalize line endings at the boundary
|
|
857
|
-
// Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste
|
|
858
|
-
// Replace CRLF first, then any remaining CR
|
|
859
|
-
const normalizedText = event.text.replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
|
860
|
-
const pastedContent = normalizedText.trim()
|
|
861
|
-
if (!pastedContent) {
|
|
862
|
-
command.trigger("prompt.paste")
|
|
863
|
-
return
|
|
864
|
-
}
|
|
865
|
-
|
|
866
|
-
// trim ' from the beginning and end of the pasted content. just
|
|
867
|
-
// ' and nothing else
|
|
868
|
-
const filepath = pastedContent.replace(/^'+|'+$/g, "").replace(/\\ /g, " ")
|
|
869
|
-
const isUrl = /^(https?):\/\//.test(filepath)
|
|
870
|
-
if (!isUrl) {
|
|
871
|
-
try {
|
|
872
|
-
const file = Bun.file(filepath)
|
|
873
|
-
// Handle SVG as raw text content, not as base64 image
|
|
874
|
-
if (file.type === "image/svg+xml") {
|
|
875
|
-
event.preventDefault()
|
|
876
|
-
const content = await file.text().catch(() => {})
|
|
877
|
-
if (content) {
|
|
878
|
-
pasteText(content, `[SVG: ${file.name ?? "image"}]`)
|
|
879
|
-
return
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
if (file.type.startsWith("image/")) {
|
|
883
|
-
event.preventDefault()
|
|
884
|
-
const content = await file
|
|
885
|
-
.arrayBuffer()
|
|
886
|
-
.then((buffer) => Buffer.from(buffer).toString("base64"))
|
|
887
|
-
.catch(() => {})
|
|
888
|
-
if (content) {
|
|
889
|
-
await pasteImage({
|
|
890
|
-
filename: file.name,
|
|
891
|
-
mime: file.type,
|
|
892
|
-
content,
|
|
893
|
-
})
|
|
894
|
-
return
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
} catch {}
|
|
898
|
-
}
|
|
899
|
-
|
|
900
|
-
const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
|
|
901
|
-
if (
|
|
902
|
-
(lineCount >= 3 || pastedContent.length > 150) &&
|
|
903
|
-
!sync.data.config.experimental?.disable_paste_summary
|
|
904
|
-
) {
|
|
905
|
-
event.preventDefault()
|
|
906
|
-
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
|
907
|
-
return
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
// Force layout update and render for the pasted content
|
|
911
|
-
setTimeout(() => {
|
|
912
|
-
input.getLayoutNode().markDirty()
|
|
913
|
-
input.gotoBufferEnd()
|
|
914
|
-
renderer.requestRender()
|
|
915
|
-
}, 0)
|
|
916
|
-
}}
|
|
917
|
-
ref={(r: TextareaRenderable) => {
|
|
918
|
-
input = r
|
|
919
|
-
setTimeout(() => {
|
|
920
|
-
input.cursorColor = theme.text
|
|
921
|
-
}, 0)
|
|
922
|
-
}}
|
|
923
|
-
onMouseDown={(r: MouseEvent) => r.target?.focus()}
|
|
924
|
-
focusedBackgroundColor={theme.backgroundElement}
|
|
925
|
-
cursorColor={theme.text}
|
|
926
|
-
syntaxStyle={syntax()}
|
|
927
|
-
/>
|
|
928
|
-
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1}>
|
|
929
|
-
<text fg={highlight()}>
|
|
930
|
-
{store.mode === "shell" ? "Shell" : Locale.titlecase(local.agent.current().name)}{" "}
|
|
931
|
-
</text>
|
|
932
|
-
<Show when={store.mode === "normal"}>
|
|
933
|
-
<box flexDirection="row" gap={1}>
|
|
934
|
-
<text flexShrink={0} fg={keybind.leader ? theme.textMuted : theme.text}>
|
|
935
|
-
{local.model.parsed().model}
|
|
936
|
-
</text>
|
|
937
|
-
<text fg={theme.textMuted}>{local.model.parsed().provider}</text>
|
|
938
|
-
<Show when={showVariant()}>
|
|
939
|
-
<text fg={theme.textMuted}>·</text>
|
|
940
|
-
<text>
|
|
941
|
-
<span style={{ fg: theme.warning, bold: true }}>{local.model.variant.current()}</span>
|
|
942
|
-
</text>
|
|
943
|
-
</Show>
|
|
944
|
-
</box>
|
|
945
|
-
</Show>
|
|
946
|
-
</box>
|
|
947
|
-
</box>
|
|
948
|
-
</box>
|
|
949
|
-
<box
|
|
950
|
-
height={1}
|
|
951
|
-
border={["left"]}
|
|
952
|
-
borderColor={highlight()}
|
|
953
|
-
customBorderChars={{
|
|
954
|
-
...EmptyBorder,
|
|
955
|
-
vertical: theme.backgroundElement.a !== 0 ? "╹" : " ",
|
|
956
|
-
}}
|
|
957
|
-
>
|
|
958
|
-
<box
|
|
959
|
-
height={1}
|
|
960
|
-
border={["bottom"]}
|
|
961
|
-
borderColor={theme.backgroundElement}
|
|
962
|
-
customBorderChars={
|
|
963
|
-
theme.backgroundElement.a !== 0
|
|
964
|
-
? {
|
|
965
|
-
...EmptyBorder,
|
|
966
|
-
horizontal: "▀",
|
|
967
|
-
}
|
|
968
|
-
: {
|
|
969
|
-
...EmptyBorder,
|
|
970
|
-
horizontal: " ",
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
/>
|
|
974
|
-
</box>
|
|
975
|
-
<box flexDirection="row" justifyContent="space-between">
|
|
976
|
-
<Show when={status().type !== "idle"} fallback={<text />}>
|
|
977
|
-
<box
|
|
978
|
-
flexDirection="row"
|
|
979
|
-
gap={1}
|
|
980
|
-
flexGrow={1}
|
|
981
|
-
justifyContent={status().type === "retry" ? "space-between" : "flex-start"}
|
|
982
|
-
>
|
|
983
|
-
<box flexShrink={0} flexDirection="row" gap={1}>
|
|
984
|
-
<box marginLeft={1}>
|
|
985
|
-
<Show when={kv.get("animations_enabled", true)} fallback={<text fg={theme.textMuted}>[⋯]</text>}>
|
|
986
|
-
<spinner color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
|
|
987
|
-
</Show>
|
|
988
|
-
</box>
|
|
989
|
-
<box flexDirection="row" gap={1} flexShrink={0}>
|
|
990
|
-
{(() => {
|
|
991
|
-
const retry = createMemo(() => {
|
|
992
|
-
const s = status()
|
|
993
|
-
if (s.type !== "retry") return
|
|
994
|
-
return s
|
|
995
|
-
})
|
|
996
|
-
const message = createMemo(() => {
|
|
997
|
-
const r = retry()
|
|
998
|
-
if (!r) return
|
|
999
|
-
if (r.message.includes("exceeded your current quota") && r.message.includes("gemini"))
|
|
1000
|
-
return "gemini is way too hot right now"
|
|
1001
|
-
if (r.message.length > 80) return r.message.slice(0, 80) + "..."
|
|
1002
|
-
return r.message
|
|
1003
|
-
})
|
|
1004
|
-
const isTruncated = createMemo(() => {
|
|
1005
|
-
const r = retry()
|
|
1006
|
-
if (!r) return false
|
|
1007
|
-
return r.message.length > 120
|
|
1008
|
-
})
|
|
1009
|
-
const [seconds, setSeconds] = createSignal(0)
|
|
1010
|
-
onMount(() => {
|
|
1011
|
-
const timer = setInterval(() => {
|
|
1012
|
-
const next = retry()?.next
|
|
1013
|
-
if (next) setSeconds(Math.round((next - Date.now()) / 1000))
|
|
1014
|
-
}, 1000)
|
|
1015
|
-
|
|
1016
|
-
onCleanup(() => {
|
|
1017
|
-
clearInterval(timer)
|
|
1018
|
-
})
|
|
1019
|
-
})
|
|
1020
|
-
const handleMessageClick = () => {
|
|
1021
|
-
const r = retry()
|
|
1022
|
-
if (!r) return
|
|
1023
|
-
if (isTruncated()) {
|
|
1024
|
-
DialogAlert.show(dialog, "Retry Error", r.message)
|
|
1025
|
-
}
|
|
1026
|
-
}
|
|
1027
|
-
|
|
1028
|
-
const retryText = () => {
|
|
1029
|
-
const r = retry()
|
|
1030
|
-
if (!r) return ""
|
|
1031
|
-
const baseMessage = message()
|
|
1032
|
-
const truncatedHint = isTruncated() ? " (click to expand)" : ""
|
|
1033
|
-
const retryInfo = ` [retrying ${seconds() > 0 ? `in ${seconds()}s ` : ""}attempt #${r.attempt}]`
|
|
1034
|
-
return baseMessage + truncatedHint + retryInfo
|
|
1035
|
-
}
|
|
1036
|
-
|
|
1037
|
-
return (
|
|
1038
|
-
<Show when={retry()}>
|
|
1039
|
-
<box onMouseUp={handleMessageClick}>
|
|
1040
|
-
<text fg={theme.error}>{retryText()}</text>
|
|
1041
|
-
</box>
|
|
1042
|
-
</Show>
|
|
1043
|
-
)
|
|
1044
|
-
})()}
|
|
1045
|
-
</box>
|
|
1046
|
-
</box>
|
|
1047
|
-
<text fg={store.interrupt > 0 ? theme.primary : theme.text}>
|
|
1048
|
-
esc{" "}
|
|
1049
|
-
<span style={{ fg: store.interrupt > 0 ? theme.primary : theme.textMuted }}>
|
|
1050
|
-
{store.interrupt > 0 ? "again to interrupt" : "interrupt"}
|
|
1051
|
-
</span>
|
|
1052
|
-
</text>
|
|
1053
|
-
</box>
|
|
1054
|
-
</Show>
|
|
1055
|
-
<Show when={status().type !== "retry"}>
|
|
1056
|
-
<box gap={2} flexDirection="row">
|
|
1057
|
-
<Switch>
|
|
1058
|
-
<Match when={store.mode === "normal"}>
|
|
1059
|
-
<text fg={theme.text}>
|
|
1060
|
-
{keybind.print("agent_cycle")} <span style={{ fg: theme.textMuted }}>switch agent</span>
|
|
1061
|
-
</text>
|
|
1062
|
-
<text fg={theme.text}>
|
|
1063
|
-
{keybind.print("command_list")} <span style={{ fg: theme.textMuted }}>commands</span>
|
|
1064
|
-
</text>
|
|
1065
|
-
</Match>
|
|
1066
|
-
<Match when={store.mode === "shell"}>
|
|
1067
|
-
<text fg={theme.text}>
|
|
1068
|
-
esc <span style={{ fg: theme.textMuted }}>exit shell mode</span>
|
|
1069
|
-
</text>
|
|
1070
|
-
</Match>
|
|
1071
|
-
</Switch>
|
|
1072
|
-
</box>
|
|
1073
|
-
</Show>
|
|
1074
|
-
</box>
|
|
1075
|
-
</box>
|
|
1076
|
-
</>
|
|
1077
|
-
)
|
|
1078
|
-
}
|