@neurocode-ai/tui 1.18.8
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/bunfig.toml +4 -0
- package/package.json +72 -0
- package/src/app.tsx +1134 -0
- package/src/attention.ts +260 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +53 -0
- package/src/clipboard.ts +124 -0
- package/src/component/bg-pulse-render.ts +436 -0
- package/src/component/bg-pulse.tsx +99 -0
- package/src/component/command-palette.tsx +79 -0
- package/src/component/dialog-agent.tsx +31 -0
- package/src/component/dialog-console-org.tsx +135 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-mcp.tsx +85 -0
- package/src/component/dialog-model.tsx +197 -0
- package/src/component/dialog-move-session.tsx +353 -0
- package/src/component/dialog-provider.tsx +469 -0
- package/src/component/dialog-retry-action.tsx +160 -0
- package/src/component/dialog-session-delete-failed.tsx +99 -0
- package/src/component/dialog-session-list.tsx +364 -0
- package/src/component/dialog-session-rename.tsx +31 -0
- package/src/component/dialog-skill.tsx +70 -0
- package/src/component/dialog-stash.tsx +87 -0
- package/src/component/dialog-status.tsx +168 -0
- package/src/component/dialog-tag.tsx +47 -0
- package/src/component/dialog-theme-list.tsx +50 -0
- package/src/component/dialog-variant.tsx +39 -0
- package/src/component/dialog-workspace-create.tsx +308 -0
- package/src/component/dialog-workspace-file-changes.tsx +144 -0
- package/src/component/dialog-workspace-list.tsx +112 -0
- package/src/component/dialog-workspace-unavailable.tsx +69 -0
- package/src/component/error-component.tsx +240 -0
- package/src/component/logo.tsx +61 -0
- package/src/component/plugin-route-missing.tsx +14 -0
- package/src/component/prompt/autocomplete.tsx +781 -0
- package/src/component/prompt/cwd.ts +0 -0
- package/src/component/prompt/frecency.tsx +1 -0
- package/src/component/prompt/history.tsx +1 -0
- package/src/component/prompt/index.tsx +1713 -0
- package/src/component/prompt/local-attachment.ts +48 -0
- package/src/component/prompt/move.tsx +205 -0
- package/src/component/prompt/stash.tsx +1 -0
- package/src/component/prompt/workspace.tsx +137 -0
- package/src/component/register-spinner.ts +6 -0
- package/src/component/spinner.tsx +26 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/todo-item.tsx +32 -0
- package/src/component/use-connected.tsx +12 -0
- package/src/component/workspace-label.tsx +19 -0
- package/src/config/index.tsx +129 -0
- package/src/config/keybind.ts +471 -0
- package/src/context/args.tsx +16 -0
- package/src/context/clipboard.tsx +18 -0
- package/src/context/data.tsx +569 -0
- package/src/context/directory.ts +17 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +6 -0
- package/src/context/event.ts +36 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/kv.tsx +66 -0
- package/src/context/local.tsx +542 -0
- package/src/context/location.tsx +14 -0
- package/src/context/path-format.tsx +24 -0
- package/src/context/permission.tsx +26 -0
- package/src/context/project.tsx +115 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +60 -0
- package/src/context/runtime.tsx +62 -0
- package/src/context/sdk.tsx +151 -0
- package/src/context/sync.tsx +666 -0
- package/src/context/theme.tsx +332 -0
- package/src/context/thinking.ts +67 -0
- package/src/editor-zed.ts +286 -0
- package/src/editor.ts +101 -0
- package/src/feature-plugins/builtins.ts +36 -0
- package/src/feature-plugins/home/footer.tsx +100 -0
- package/src/feature-plugins/home/tips-view.tsx +287 -0
- package/src/feature-plugins/home/tips.tsx +59 -0
- package/src/feature-plugins/sidebar/context.tsx +65 -0
- package/src/feature-plugins/sidebar/files.tsx +70 -0
- package/src/feature-plugins/sidebar/footer.tsx +98 -0
- package/src/feature-plugins/sidebar/lsp.tsx +65 -0
- package/src/feature-plugins/sidebar/mcp.tsx +97 -0
- package/src/feature-plugins/sidebar/todo.tsx +49 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +232 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +162 -0
- package/src/feature-plugins/system/diff-viewer-ui.tsx +103 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1077 -0
- package/src/feature-plugins/system/notifications.ts +94 -0
- package/src/feature-plugins/system/plugins.tsx +269 -0
- package/src/feature-plugins/system/which-key.tsx +608 -0
- package/src/index.tsx +1 -0
- package/src/keymap.tsx +290 -0
- package/src/logo.ts +11 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/adapters.tsx +355 -0
- package/src/plugin/api.ts +52 -0
- package/src/plugin/command-shim.ts +109 -0
- package/src/plugin/runtime.tsx +81 -0
- package/src/plugin/slots.tsx +65 -0
- package/src/prompt/display.ts +48 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +111 -0
- package/src/prompt/part.ts +29 -0
- package/src/prompt/stash.tsx +89 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home/session-destination.tsx +41 -0
- package/src/routes/home.tsx +95 -0
- package/src/routes/session/dialog-fork-from-timeline.tsx +76 -0
- package/src/routes/session/dialog-message.tsx +109 -0
- package/src/routes/session/dialog-subagent.tsx +26 -0
- package/src/routes/session/dialog-timeline.tsx +47 -0
- package/src/routes/session/footer.tsx +91 -0
- package/src/routes/session/index.tsx +2710 -0
- package/src/routes/session/permission.tsx +718 -0
- package/src/routes/session/question.tsx +514 -0
- package/src/routes/session/sidebar.tsx +103 -0
- package/src/routes/session/subagent-footer.tsx +132 -0
- package/src/runtime.tsx +9 -0
- package/src/terminal-win32.ts +130 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/index.ts +1089 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +66 -0
- package/src/ui/dialog-confirm.tsx +108 -0
- package/src/ui/dialog-export-options.tsx +217 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +126 -0
- package/src/ui/dialog-select.tsx +790 -0
- package/src/ui/dialog.tsx +231 -0
- package/src/ui/link.tsx +34 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/toast.tsx +102 -0
- package/src/util/collapse-tool-output.ts +19 -0
- package/src/util/error.ts +182 -0
- package/src/util/filetype.ts +130 -0
- package/src/util/format.ts +20 -0
- package/src/util/layout.ts +25 -0
- package/src/util/locale.ts +86 -0
- package/src/util/model.ts +28 -0
- package/src/util/path.ts +12 -0
- package/src/util/persistence.ts +33 -0
- package/src/util/presentation.ts +38 -0
- package/src/util/provider-origin.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +7 -0
- package/src/util/revert-diff.ts +18 -0
- package/src/util/scroll.ts +27 -0
- package/src/util/selection.ts +79 -0
- package/src/util/session.ts +3 -0
- package/src/util/signal.ts +51 -0
- package/src/util/system.ts +20 -0
- package/src/util/tool-display.ts +13 -0
- package/src/util/transcript.ts +112 -0
- package/sst-env.d.ts +10 -0
- package/test/app-lifecycle.test.tsx +128 -0
- package/test/cli/cmd/tui/dialog-workspace-create.test.ts +28 -0
- package/test/cli/cmd/tui/model-options.test.ts +32 -0
- package/test/cli/cmd/tui/notifications.test.ts +267 -0
- package/test/cli/cmd/tui/provider-options.test.ts +41 -0
- package/test/cli/cmd/tui/sync-fixture.tsx +70 -0
- package/test/cli/cmd/tui/sync-live-hydration.test.tsx +262 -0
- package/test/cli/cmd/tui/sync-undefined-messages.test.tsx +43 -0
- package/test/cli/cmd/tui/sync.test.tsx +65 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +92 -0
- package/test/cli/tui/data.test.tsx +486 -0
- package/test/cli/tui/dialog-prompt.test.tsx +147 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +200 -0
- package/test/cli/tui/diff-viewer.test.tsx +268 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +351 -0
- package/test/cli/tui/prompt-submit-race.test.ts +98 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/use-event.test.tsx +148 -0
- package/test/clipboard.test.ts +19 -0
- package/test/component/dialog-session-list.test.ts +46 -0
- package/test/config.test.tsx +127 -0
- package/test/context/local.test.ts +22 -0
- package/test/editor.test.ts +32 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +323 -0
- package/test/fixture/fixture.ts +13 -0
- package/test/fixture/tui-environment.tsx +32 -0
- package/test/fixture/tui-plugin.ts +36 -0
- package/test/fixture/tui-runtime.ts +12 -0
- package/test/fixture/tui-sdk.ts +109 -0
- package/test/index.test.tsx +6 -0
- package/test/keymap.test.tsx +141 -0
- package/test/plugin/runtime.test.ts +50 -0
- package/test/plugin/slots.test.tsx +38 -0
- package/test/prompt/display.test.ts +33 -0
- package/test/prompt/history.test.ts +39 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +43 -0
- package/test/prompt/part.test.ts +53 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/runtime.test.tsx +37 -0
- package/test/theme.test.ts +81 -0
- package/test/util/error.test.ts +49 -0
- package/test/util/filetype.test.ts +16 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/model.test.ts +9 -0
- package/test/util/presentation.test.ts +8 -0
- package/test/util/renderer.test.ts +30 -0
- package/test/util/revert-diff.test.ts +35 -0
- package/test/util/session.test.ts +10 -0
- package/test/util/tool-display.test.ts +40 -0
- package/test/util/transcript.test.ts +421 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Message,
|
|
3
|
+
Agent,
|
|
4
|
+
Provider,
|
|
5
|
+
Session,
|
|
6
|
+
Part,
|
|
7
|
+
Config,
|
|
8
|
+
Todo,
|
|
9
|
+
Command,
|
|
10
|
+
PermissionRequest,
|
|
11
|
+
QuestionRequest,
|
|
12
|
+
LspStatus,
|
|
13
|
+
McpStatus,
|
|
14
|
+
McpResource,
|
|
15
|
+
FormatterStatus,
|
|
16
|
+
SessionStatus,
|
|
17
|
+
ProviderListResponse,
|
|
18
|
+
ProviderAuthMethod,
|
|
19
|
+
VcsInfo,
|
|
20
|
+
SnapshotFileDiff,
|
|
21
|
+
ConsoleState,
|
|
22
|
+
} from "@neurocode-ai/sdk/v2"
|
|
23
|
+
import { createStore, produce, reconcile } from "solid-js/store"
|
|
24
|
+
import { useProject } from "./project"
|
|
25
|
+
import { useEvent } from "./event"
|
|
26
|
+
import { useSDK } from "./sdk"
|
|
27
|
+
import { useTuiStartup } from "./runtime"
|
|
28
|
+
import { createSimpleContext } from "./helper"
|
|
29
|
+
import { useExit } from "./exit"
|
|
30
|
+
import { useArgs } from "./args"
|
|
31
|
+
import { batch, onMount } from "solid-js"
|
|
32
|
+
import path from "path"
|
|
33
|
+
import { useKV } from "./kv"
|
|
34
|
+
import { usePermission } from "./permission"
|
|
35
|
+
|
|
36
|
+
const emptyConsoleState: ConsoleState = {
|
|
37
|
+
consoleManagedProviders: [],
|
|
38
|
+
switchableOrgCount: 0,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function search<T>(items: T[], target: string, key: (item: T) => string) {
|
|
42
|
+
let left = 0
|
|
43
|
+
let right = items.length - 1
|
|
44
|
+
while (left <= right) {
|
|
45
|
+
const middle = Math.floor((left + right) / 2)
|
|
46
|
+
const value = key(items[middle])
|
|
47
|
+
if (value === target) return { found: true, index: middle }
|
|
48
|
+
if (value < target) left = middle + 1
|
|
49
|
+
else right = middle - 1
|
|
50
|
+
}
|
|
51
|
+
return { found: false, index: left }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const {
|
|
55
|
+
context: SyncContext,
|
|
56
|
+
use: useSync,
|
|
57
|
+
provider: SyncProvider,
|
|
58
|
+
} = createSimpleContext({
|
|
59
|
+
name: "Sync",
|
|
60
|
+
init: () => {
|
|
61
|
+
const startup = useTuiStartup()
|
|
62
|
+
const kv = useKV()
|
|
63
|
+
const permission = usePermission()
|
|
64
|
+
const [store, setStore] = createStore<{
|
|
65
|
+
status: "loading" | "partial" | "complete"
|
|
66
|
+
provider: Provider[]
|
|
67
|
+
provider_default: Record<string, string>
|
|
68
|
+
provider_next: ProviderListResponse
|
|
69
|
+
console_state: ConsoleState
|
|
70
|
+
capabilities: {
|
|
71
|
+
experimentalBackgroundSubagents: boolean
|
|
72
|
+
}
|
|
73
|
+
provider_auth: Record<string, ProviderAuthMethod[]>
|
|
74
|
+
agent: Agent[]
|
|
75
|
+
command: Command[]
|
|
76
|
+
permission: {
|
|
77
|
+
[sessionID: string]: PermissionRequest[]
|
|
78
|
+
}
|
|
79
|
+
question: {
|
|
80
|
+
[sessionID: string]: QuestionRequest[]
|
|
81
|
+
}
|
|
82
|
+
config: Config
|
|
83
|
+
session: Session[]
|
|
84
|
+
session_status: {
|
|
85
|
+
[sessionID: string]: SessionStatus
|
|
86
|
+
}
|
|
87
|
+
session_diff: {
|
|
88
|
+
[sessionID: string]: SnapshotFileDiff[]
|
|
89
|
+
}
|
|
90
|
+
todo: {
|
|
91
|
+
[sessionID: string]: Todo[]
|
|
92
|
+
}
|
|
93
|
+
message: {
|
|
94
|
+
[sessionID: string]: Message[]
|
|
95
|
+
}
|
|
96
|
+
part: {
|
|
97
|
+
[messageID: string]: Part[]
|
|
98
|
+
}
|
|
99
|
+
lsp: LspStatus[]
|
|
100
|
+
mcp: {
|
|
101
|
+
[key: string]: McpStatus
|
|
102
|
+
}
|
|
103
|
+
mcp_resource: {
|
|
104
|
+
[key: string]: McpResource
|
|
105
|
+
}
|
|
106
|
+
formatter: FormatterStatus[]
|
|
107
|
+
vcs: VcsInfo | undefined
|
|
108
|
+
}>({
|
|
109
|
+
provider_next: {
|
|
110
|
+
all: [],
|
|
111
|
+
default: {},
|
|
112
|
+
connected: [],
|
|
113
|
+
},
|
|
114
|
+
console_state: emptyConsoleState,
|
|
115
|
+
capabilities: {
|
|
116
|
+
experimentalBackgroundSubagents: false,
|
|
117
|
+
},
|
|
118
|
+
provider_auth: {},
|
|
119
|
+
config: {},
|
|
120
|
+
status: "loading",
|
|
121
|
+
agent: [],
|
|
122
|
+
permission: {},
|
|
123
|
+
question: {},
|
|
124
|
+
command: [],
|
|
125
|
+
provider: [],
|
|
126
|
+
provider_default: {},
|
|
127
|
+
session: [],
|
|
128
|
+
session_status: {},
|
|
129
|
+
session_diff: {},
|
|
130
|
+
todo: {},
|
|
131
|
+
message: {},
|
|
132
|
+
part: {},
|
|
133
|
+
lsp: [],
|
|
134
|
+
mcp: {},
|
|
135
|
+
mcp_resource: {},
|
|
136
|
+
formatter: [],
|
|
137
|
+
vcs: undefined,
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const event = useEvent()
|
|
141
|
+
const project = useProject()
|
|
142
|
+
const sdk = useSDK()
|
|
143
|
+
|
|
144
|
+
const fullSyncedSessions = new Set<string>()
|
|
145
|
+
const syncingSessions = new Map<string, Promise<void>>()
|
|
146
|
+
const hydratingSessions = new Map<string, { messages: Set<string>; parts: Set<string> }>()
|
|
147
|
+
const touchMessage = (sessionID: string, messageID: string) => {
|
|
148
|
+
hydratingSessions.get(sessionID)?.messages.add(messageID)
|
|
149
|
+
}
|
|
150
|
+
const touchPart = (sessionID: string, partID: string) => {
|
|
151
|
+
hydratingSessions.get(sessionID)?.parts.add(partID)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function sessionListQuery(): { scope?: "project"; path?: string } {
|
|
155
|
+
if (!kv.get("session_directory_filter_enabled", true)) return { scope: "project" }
|
|
156
|
+
if (!project.data.instance.path.worktree || !project.data.instance.path.directory) return { scope: "project" }
|
|
157
|
+
return {
|
|
158
|
+
path: path
|
|
159
|
+
.relative(path.resolve(project.data.instance.path.worktree), project.data.instance.path.directory)
|
|
160
|
+
.replaceAll("\\", "/"),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function listSessions() {
|
|
165
|
+
return sdk.client.session
|
|
166
|
+
.list({ start: Date.now() - 30 * 24 * 60 * 60 * 1000, ...sessionListQuery() })
|
|
167
|
+
.then((x) => (x.data ?? []).toSorted((a, b) => a.id.localeCompare(b.id)))
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
event.subscribe((event, { directory, workspace }) => {
|
|
171
|
+
switch (event.type) {
|
|
172
|
+
case "server.instance.disposed":
|
|
173
|
+
void bootstrap()
|
|
174
|
+
break
|
|
175
|
+
case "permission.replied": {
|
|
176
|
+
const requests = store.permission[event.properties.sessionID]
|
|
177
|
+
if (!requests) break
|
|
178
|
+
const match = search(requests, event.properties.requestID, (r) => r.id)
|
|
179
|
+
if (!match.found) break
|
|
180
|
+
setStore(
|
|
181
|
+
"permission",
|
|
182
|
+
event.properties.sessionID,
|
|
183
|
+
produce((draft) => {
|
|
184
|
+
draft.splice(match.index, 1)
|
|
185
|
+
}),
|
|
186
|
+
)
|
|
187
|
+
break
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
case "permission.asked": {
|
|
191
|
+
const request = event.properties
|
|
192
|
+
if (permission.mode === "auto") {
|
|
193
|
+
void sdk.client.permission.reply({
|
|
194
|
+
requestID: request.id,
|
|
195
|
+
reply: "once",
|
|
196
|
+
directory,
|
|
197
|
+
workspace,
|
|
198
|
+
})
|
|
199
|
+
break
|
|
200
|
+
}
|
|
201
|
+
const requests = store.permission[request.sessionID]
|
|
202
|
+
if (!requests) {
|
|
203
|
+
setStore("permission", request.sessionID, [request])
|
|
204
|
+
break
|
|
205
|
+
}
|
|
206
|
+
const match = search(requests, request.id, (r) => r.id)
|
|
207
|
+
if (match.found) {
|
|
208
|
+
setStore("permission", request.sessionID, match.index, reconcile(request))
|
|
209
|
+
break
|
|
210
|
+
}
|
|
211
|
+
setStore(
|
|
212
|
+
"permission",
|
|
213
|
+
request.sessionID,
|
|
214
|
+
produce((draft) => {
|
|
215
|
+
draft.splice(match.index, 0, request)
|
|
216
|
+
}),
|
|
217
|
+
)
|
|
218
|
+
break
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
case "question.replied":
|
|
222
|
+
case "question.rejected": {
|
|
223
|
+
const requests = store.question[event.properties.sessionID]
|
|
224
|
+
if (!requests) break
|
|
225
|
+
const match = search(requests, event.properties.requestID, (r) => r.id)
|
|
226
|
+
if (!match.found) break
|
|
227
|
+
setStore(
|
|
228
|
+
"question",
|
|
229
|
+
event.properties.sessionID,
|
|
230
|
+
produce((draft) => {
|
|
231
|
+
draft.splice(match.index, 1)
|
|
232
|
+
}),
|
|
233
|
+
)
|
|
234
|
+
break
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
case "question.asked": {
|
|
238
|
+
const request = event.properties
|
|
239
|
+
const requests = store.question[request.sessionID]
|
|
240
|
+
if (!requests) {
|
|
241
|
+
setStore("question", request.sessionID, [request])
|
|
242
|
+
break
|
|
243
|
+
}
|
|
244
|
+
const match = search(requests, request.id, (r) => r.id)
|
|
245
|
+
if (match.found) {
|
|
246
|
+
setStore("question", request.sessionID, match.index, reconcile(request))
|
|
247
|
+
break
|
|
248
|
+
}
|
|
249
|
+
setStore(
|
|
250
|
+
"question",
|
|
251
|
+
request.sessionID,
|
|
252
|
+
produce((draft) => {
|
|
253
|
+
draft.splice(match.index, 0, request)
|
|
254
|
+
}),
|
|
255
|
+
)
|
|
256
|
+
break
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
case "todo.updated":
|
|
260
|
+
setStore("todo", event.properties.sessionID, event.properties.todos)
|
|
261
|
+
break
|
|
262
|
+
|
|
263
|
+
case "session.diff":
|
|
264
|
+
setStore("session_diff", event.properties.sessionID, event.properties.diff)
|
|
265
|
+
break
|
|
266
|
+
|
|
267
|
+
case "session.deleted": {
|
|
268
|
+
const result = search(store.session, event.properties.info.id, (s) => s.id)
|
|
269
|
+
if (result.found) {
|
|
270
|
+
setStore(
|
|
271
|
+
"session",
|
|
272
|
+
produce((draft) => {
|
|
273
|
+
draft.splice(result.index, 1)
|
|
274
|
+
}),
|
|
275
|
+
)
|
|
276
|
+
}
|
|
277
|
+
break
|
|
278
|
+
}
|
|
279
|
+
case "session.updated": {
|
|
280
|
+
const result = search(store.session, event.properties.info.id, (s) => s.id)
|
|
281
|
+
if (result.found) {
|
|
282
|
+
setStore("session", result.index, reconcile(event.properties.info))
|
|
283
|
+
break
|
|
284
|
+
}
|
|
285
|
+
setStore(
|
|
286
|
+
"session",
|
|
287
|
+
produce((draft) => {
|
|
288
|
+
draft.splice(result.index, 0, event.properties.info)
|
|
289
|
+
}),
|
|
290
|
+
)
|
|
291
|
+
break
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
case "session.next.moved": {
|
|
295
|
+
const result = search(store.session, event.properties.sessionID, (s) => s.id)
|
|
296
|
+
if (!result.found) break
|
|
297
|
+
setStore(
|
|
298
|
+
"session",
|
|
299
|
+
result.index,
|
|
300
|
+
produce((session) => {
|
|
301
|
+
session.directory = event.properties.location.directory
|
|
302
|
+
session.path = event.properties.subdirectory
|
|
303
|
+
session.workspaceID = event.properties.location.workspaceID
|
|
304
|
+
session.time.updated = event.properties.timestamp
|
|
305
|
+
}),
|
|
306
|
+
)
|
|
307
|
+
break
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
case "session.status": {
|
|
311
|
+
setStore("session_status", event.properties.sessionID, event.properties.status)
|
|
312
|
+
break
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
case "message.updated": {
|
|
316
|
+
touchMessage(event.properties.info.sessionID, event.properties.info.id)
|
|
317
|
+
const messages = store.message[event.properties.info.sessionID]
|
|
318
|
+
if (!messages) {
|
|
319
|
+
setStore("message", event.properties.info.sessionID, [event.properties.info])
|
|
320
|
+
break
|
|
321
|
+
}
|
|
322
|
+
const result = search(messages, event.properties.info.id, (m) => m.id)
|
|
323
|
+
if (result.found) {
|
|
324
|
+
setStore("message", event.properties.info.sessionID, result.index, reconcile(event.properties.info))
|
|
325
|
+
break
|
|
326
|
+
}
|
|
327
|
+
setStore(
|
|
328
|
+
"message",
|
|
329
|
+
event.properties.info.sessionID,
|
|
330
|
+
produce((draft) => {
|
|
331
|
+
draft.splice(result.index, 0, event.properties.info)
|
|
332
|
+
}),
|
|
333
|
+
)
|
|
334
|
+
const updated = store.message[event.properties.info.sessionID]
|
|
335
|
+
if (updated.length > 100) {
|
|
336
|
+
const oldest = updated[0]
|
|
337
|
+
batch(() => {
|
|
338
|
+
setStore(
|
|
339
|
+
"message",
|
|
340
|
+
event.properties.info.sessionID,
|
|
341
|
+
produce((draft) => {
|
|
342
|
+
draft.shift()
|
|
343
|
+
}),
|
|
344
|
+
)
|
|
345
|
+
setStore(
|
|
346
|
+
"part",
|
|
347
|
+
produce((draft) => {
|
|
348
|
+
delete draft[oldest.id]
|
|
349
|
+
}),
|
|
350
|
+
)
|
|
351
|
+
})
|
|
352
|
+
}
|
|
353
|
+
break
|
|
354
|
+
}
|
|
355
|
+
case "message.removed": {
|
|
356
|
+
touchMessage(event.properties.sessionID, event.properties.messageID)
|
|
357
|
+
const messages = store.message[event.properties.sessionID]
|
|
358
|
+
const result = search(messages, event.properties.messageID, (m) => m.id)
|
|
359
|
+
if (result.found) {
|
|
360
|
+
setStore(
|
|
361
|
+
"message",
|
|
362
|
+
event.properties.sessionID,
|
|
363
|
+
produce((draft) => {
|
|
364
|
+
draft.splice(result.index, 1)
|
|
365
|
+
}),
|
|
366
|
+
)
|
|
367
|
+
}
|
|
368
|
+
break
|
|
369
|
+
}
|
|
370
|
+
case "message.part.updated": {
|
|
371
|
+
touchPart(event.properties.part.sessionID, event.properties.part.id)
|
|
372
|
+
const parts = store.part[event.properties.part.messageID]
|
|
373
|
+
if (!parts) {
|
|
374
|
+
setStore("part", event.properties.part.messageID, [event.properties.part])
|
|
375
|
+
break
|
|
376
|
+
}
|
|
377
|
+
const result = search(parts, event.properties.part.id, (p) => p.id)
|
|
378
|
+
if (result.found) {
|
|
379
|
+
setStore("part", event.properties.part.messageID, result.index, reconcile(event.properties.part))
|
|
380
|
+
break
|
|
381
|
+
}
|
|
382
|
+
setStore(
|
|
383
|
+
"part",
|
|
384
|
+
event.properties.part.messageID,
|
|
385
|
+
produce((draft) => {
|
|
386
|
+
draft.splice(result.index, 0, event.properties.part)
|
|
387
|
+
}),
|
|
388
|
+
)
|
|
389
|
+
break
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
case "message.part.delta": {
|
|
393
|
+
const parts = store.part[event.properties.messageID]
|
|
394
|
+
if (!parts) break
|
|
395
|
+
const result = search(parts, event.properties.partID, (p) => p.id)
|
|
396
|
+
if (!result.found) break
|
|
397
|
+
touchPart(event.properties.sessionID, event.properties.partID)
|
|
398
|
+
setStore(
|
|
399
|
+
"part",
|
|
400
|
+
event.properties.messageID,
|
|
401
|
+
produce((draft) => {
|
|
402
|
+
const part = draft[result.index]
|
|
403
|
+
const field = event.properties.field as keyof typeof part
|
|
404
|
+
const existing = part[field] as string | undefined
|
|
405
|
+
;(part[field] as string) = (existing ?? "") + event.properties.delta
|
|
406
|
+
}),
|
|
407
|
+
)
|
|
408
|
+
break
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
case "message.part.removed": {
|
|
412
|
+
touchPart(event.properties.sessionID, event.properties.partID)
|
|
413
|
+
const parts = store.part[event.properties.messageID]
|
|
414
|
+
const result = search(parts, event.properties.partID, (p) => p.id)
|
|
415
|
+
if (result.found) {
|
|
416
|
+
setStore(
|
|
417
|
+
"part",
|
|
418
|
+
event.properties.messageID,
|
|
419
|
+
produce((draft) => {
|
|
420
|
+
draft.splice(result.index, 1)
|
|
421
|
+
}),
|
|
422
|
+
)
|
|
423
|
+
}
|
|
424
|
+
break
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
case "lsp.updated": {
|
|
428
|
+
const workspace = project.workspace.current()
|
|
429
|
+
void sdk.client.lsp.status({ workspace }).then((x) => setStore("lsp", x.data ?? []))
|
|
430
|
+
break
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
case "vcs.branch.updated": {
|
|
434
|
+
if (workspace === project.workspace.current()) {
|
|
435
|
+
setStore("vcs", { branch: event.properties.branch })
|
|
436
|
+
}
|
|
437
|
+
break
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
const exit = useExit()
|
|
443
|
+
const args = useArgs()
|
|
444
|
+
|
|
445
|
+
async function bootstrap(input: { fatal?: boolean } = {}) {
|
|
446
|
+
const fatal = input.fatal ?? true
|
|
447
|
+
const workspace = project.workspace.current()
|
|
448
|
+
const projectPromise = project.sync()
|
|
449
|
+
const sessionListPromise = projectPromise.then(() => listSessions())
|
|
450
|
+
|
|
451
|
+
// blocking - include session.list when continuing a session
|
|
452
|
+
const providersPromise = sdk.client.config.providers({ workspace }, { throwOnError: true })
|
|
453
|
+
const providerListPromise = sdk.client.provider.list({ workspace }, { throwOnError: true })
|
|
454
|
+
const capabilitiesPromise = sdk.client.experimental.capabilities
|
|
455
|
+
.get({ workspace }, { throwOnError: true })
|
|
456
|
+
.then((x) => x.data)
|
|
457
|
+
.catch(() => undefined)
|
|
458
|
+
const consoleStatePromise = sdk.client.experimental.console
|
|
459
|
+
.get({ workspace }, { throwOnError: true })
|
|
460
|
+
.then((x) => x.data)
|
|
461
|
+
.catch(() => emptyConsoleState)
|
|
462
|
+
const agentsPromise = sdk.client.app.agents({ workspace }, { throwOnError: true })
|
|
463
|
+
const configPromise = sdk.client.config.get({ workspace }, { throwOnError: true })
|
|
464
|
+
await Promise.all([
|
|
465
|
+
providersPromise,
|
|
466
|
+
providerListPromise,
|
|
467
|
+
capabilitiesPromise,
|
|
468
|
+
agentsPromise,
|
|
469
|
+
configPromise,
|
|
470
|
+
projectPromise,
|
|
471
|
+
...(args.continue ? [sessionListPromise] : []),
|
|
472
|
+
])
|
|
473
|
+
.then(async () => {
|
|
474
|
+
const providersResponse = providersPromise.then((x) => x.data!)
|
|
475
|
+
const providerListResponse = providerListPromise.then((x) => x.data!)
|
|
476
|
+
const capabilitiesResponse = capabilitiesPromise
|
|
477
|
+
const consoleStateResponse = consoleStatePromise
|
|
478
|
+
const agentsResponse = agentsPromise.then((x) => x.data ?? [])
|
|
479
|
+
const configResponse = configPromise.then((x) => x.data!)
|
|
480
|
+
const sessionListResponse = args.continue ? sessionListPromise : undefined
|
|
481
|
+
|
|
482
|
+
return Promise.all([
|
|
483
|
+
providersResponse,
|
|
484
|
+
providerListResponse,
|
|
485
|
+
capabilitiesResponse,
|
|
486
|
+
consoleStateResponse,
|
|
487
|
+
agentsResponse,
|
|
488
|
+
configResponse,
|
|
489
|
+
...(sessionListResponse ? [sessionListResponse] : []),
|
|
490
|
+
]).then((responses) => {
|
|
491
|
+
const providers = responses[0]
|
|
492
|
+
const providerList = responses[1]
|
|
493
|
+
const capabilities = responses[2]
|
|
494
|
+
const consoleState = responses[3]
|
|
495
|
+
const agents = responses[4]
|
|
496
|
+
const config = responses[5]
|
|
497
|
+
const sessions = responses[6]
|
|
498
|
+
|
|
499
|
+
batch(() => {
|
|
500
|
+
setStore("provider", reconcile(providers.providers))
|
|
501
|
+
setStore("provider_default", reconcile(providers.default))
|
|
502
|
+
setStore("provider_next", reconcile(providerList))
|
|
503
|
+
setStore("capabilities", "experimentalBackgroundSubagents", capabilities?.backgroundSubagents === true)
|
|
504
|
+
setStore("console_state", reconcile(consoleState))
|
|
505
|
+
setStore("agent", reconcile(agents))
|
|
506
|
+
setStore("config", reconcile(config))
|
|
507
|
+
if (sessions !== undefined) setStore("session", reconcile(sessions))
|
|
508
|
+
})
|
|
509
|
+
})
|
|
510
|
+
})
|
|
511
|
+
.then(() => {
|
|
512
|
+
if (store.status !== "complete") setStore("status", "partial")
|
|
513
|
+
// non-blocking
|
|
514
|
+
void Promise.all([
|
|
515
|
+
...(args.continue ? [] : [sessionListPromise.then((sessions) => setStore("session", reconcile(sessions)))]),
|
|
516
|
+
consoleStatePromise.then((consoleState) => setStore("console_state", reconcile(consoleState))),
|
|
517
|
+
sdk.client.command.list({ workspace }).then((x) => setStore("command", reconcile(x.data ?? []))),
|
|
518
|
+
sdk.client.lsp.status({ workspace }).then((x) => setStore("lsp", reconcile(x.data ?? []))),
|
|
519
|
+
sdk.client.mcp.status({ workspace }).then((x) => setStore("mcp", reconcile(x.data ?? {}))),
|
|
520
|
+
sdk.client.experimental.resource
|
|
521
|
+
.list({ workspace })
|
|
522
|
+
.then((x) => setStore("mcp_resource", reconcile(x.data ?? {}))),
|
|
523
|
+
sdk.client.formatter.status({ workspace }).then((x) => setStore("formatter", reconcile(x.data ?? []))),
|
|
524
|
+
sdk.client.session.status({ workspace }).then((x) => {
|
|
525
|
+
setStore("session_status", reconcile(x.data ?? {}))
|
|
526
|
+
}),
|
|
527
|
+
sdk.client.provider.auth({ workspace }).then((x) => setStore("provider_auth", reconcile(x.data ?? {}))),
|
|
528
|
+
sdk.client.vcs.get({ workspace }).then((x) => setStore("vcs", reconcile(x.data))),
|
|
529
|
+
project.workspace.sync(),
|
|
530
|
+
]).then(() => {
|
|
531
|
+
setStore("status", "complete")
|
|
532
|
+
})
|
|
533
|
+
})
|
|
534
|
+
.catch(async (e) => {
|
|
535
|
+
console.error("tui bootstrap failed", {
|
|
536
|
+
error: e instanceof Error ? e.message : String(e),
|
|
537
|
+
name: e instanceof Error ? e.name : undefined,
|
|
538
|
+
stack: e instanceof Error ? e.stack : undefined,
|
|
539
|
+
})
|
|
540
|
+
if (fatal) {
|
|
541
|
+
exit(e)
|
|
542
|
+
} else {
|
|
543
|
+
throw e
|
|
544
|
+
}
|
|
545
|
+
})
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
onMount(() => {
|
|
549
|
+
void bootstrap()
|
|
550
|
+
})
|
|
551
|
+
|
|
552
|
+
const result = {
|
|
553
|
+
data: store,
|
|
554
|
+
set: setStore,
|
|
555
|
+
get status() {
|
|
556
|
+
return store.status
|
|
557
|
+
},
|
|
558
|
+
get ready() {
|
|
559
|
+
if (startup.skipInitialLoading) return true
|
|
560
|
+
return store.status !== "loading"
|
|
561
|
+
},
|
|
562
|
+
get path() {
|
|
563
|
+
return project.instance.path()
|
|
564
|
+
},
|
|
565
|
+
session: {
|
|
566
|
+
get(sessionID: string) {
|
|
567
|
+
const match = search(store.session, sessionID, (s) => s.id)
|
|
568
|
+
if (match.found) return store.session[match.index]
|
|
569
|
+
return undefined
|
|
570
|
+
},
|
|
571
|
+
query() {
|
|
572
|
+
return sessionListQuery()
|
|
573
|
+
},
|
|
574
|
+
async refresh() {
|
|
575
|
+
const list = await listSessions()
|
|
576
|
+
setStore("session", reconcile(list))
|
|
577
|
+
},
|
|
578
|
+
status(sessionID: string) {
|
|
579
|
+
const session = result.session.get(sessionID)
|
|
580
|
+
if (!session) return "idle"
|
|
581
|
+
if (session.time.compacting) return "compacting"
|
|
582
|
+
const messages = store.message[sessionID] ?? []
|
|
583
|
+
const last = messages.at(-1)
|
|
584
|
+
if (!last) return "idle"
|
|
585
|
+
if (last.role === "user") return "working"
|
|
586
|
+
return last.time.completed ? "idle" : "working"
|
|
587
|
+
},
|
|
588
|
+
async sync(sessionID: string) {
|
|
589
|
+
if (fullSyncedSessions.has(sessionID)) return
|
|
590
|
+
const syncing = syncingSessions.get(sessionID)
|
|
591
|
+
if (syncing) return syncing
|
|
592
|
+
const tracker = { messages: new Set<string>(), parts: new Set<string>() }
|
|
593
|
+
hydratingSessions.set(sessionID, tracker)
|
|
594
|
+
const task = (async () => {
|
|
595
|
+
const [session, messages, todo, diff] = await Promise.all([
|
|
596
|
+
sdk.client.session.get({ sessionID }, { throwOnError: true }),
|
|
597
|
+
sdk.client.session.messages({ sessionID, limit: 100 }),
|
|
598
|
+
sdk.client.session.todo({ sessionID }),
|
|
599
|
+
sdk.client.session.diff({ sessionID }),
|
|
600
|
+
])
|
|
601
|
+
setStore(
|
|
602
|
+
produce((draft) => {
|
|
603
|
+
const match = search(draft.session, sessionID, (s) => s.id)
|
|
604
|
+
if (match.found) draft.session[match.index] = session.data!
|
|
605
|
+
if (!match.found) draft.session.splice(match.index, 0, session.data!)
|
|
606
|
+
draft.todo[sessionID] = todo.data ?? []
|
|
607
|
+
const currentMessages = draft.message[sessionID] ?? []
|
|
608
|
+
const infos = (messages.data ?? []).flatMap((message) => {
|
|
609
|
+
if (!tracker.messages.has(message.info.id)) return [message.info]
|
|
610
|
+
const current = currentMessages.find((item) => item.id === message.info.id)
|
|
611
|
+
return current ? [current] : []
|
|
612
|
+
})
|
|
613
|
+
infos.push(
|
|
614
|
+
...currentMessages.filter(
|
|
615
|
+
(message) => tracker.messages.has(message.id) && !infos.some((item) => item.id === message.id),
|
|
616
|
+
),
|
|
617
|
+
)
|
|
618
|
+
const removed = infos.slice(0, -100)
|
|
619
|
+
const visible = infos.slice(-100)
|
|
620
|
+
const visibleIDs = new Set(visible.map((message) => message.id))
|
|
621
|
+
for (const message of messages.data ?? []) {
|
|
622
|
+
if (!visibleIDs.has(message.info.id)) {
|
|
623
|
+
delete draft.part[message.info.id]
|
|
624
|
+
continue
|
|
625
|
+
}
|
|
626
|
+
const currentParts = draft.part[message.info.id] ?? []
|
|
627
|
+
const parts = message.parts.flatMap((part) => {
|
|
628
|
+
const current = currentParts.find((item) => item.id === part.id)
|
|
629
|
+
if (tracker.parts.has(part.id)) return current ? [current] : []
|
|
630
|
+
if (
|
|
631
|
+
current &&
|
|
632
|
+
(part.type === "text" || part.type === "reasoning") &&
|
|
633
|
+
(current.type === "text" || current.type === "reasoning") &&
|
|
634
|
+
part.text.length === 0 &&
|
|
635
|
+
current.text.length > 0
|
|
636
|
+
) {
|
|
637
|
+
return [current]
|
|
638
|
+
}
|
|
639
|
+
return [part]
|
|
640
|
+
})
|
|
641
|
+
parts.push(
|
|
642
|
+
...currentParts.filter(
|
|
643
|
+
(part) => tracker.parts.has(part.id) && !parts.some((item) => item.id === part.id),
|
|
644
|
+
),
|
|
645
|
+
)
|
|
646
|
+
draft.part[message.info.id] = parts
|
|
647
|
+
}
|
|
648
|
+
for (const message of removed) delete draft.part[message.id]
|
|
649
|
+
draft.message[sessionID] = visible
|
|
650
|
+
draft.session_diff[sessionID] = diff.data ?? []
|
|
651
|
+
}),
|
|
652
|
+
)
|
|
653
|
+
fullSyncedSessions.add(sessionID)
|
|
654
|
+
})().finally(() => {
|
|
655
|
+
syncingSessions.delete(sessionID)
|
|
656
|
+
hydratingSessions.delete(sessionID)
|
|
657
|
+
})
|
|
658
|
+
syncingSessions.set(sessionID, task)
|
|
659
|
+
return task
|
|
660
|
+
},
|
|
661
|
+
},
|
|
662
|
+
bootstrap,
|
|
663
|
+
}
|
|
664
|
+
return result
|
|
665
|
+
},
|
|
666
|
+
})
|