@zyro-sec/tui 0.0.0-stage → 1.0.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/AGENTS.md +6 -0
- package/bunfig.toml +4 -0
- package/package.json +79 -4
- package/src/app.tsx +1632 -0
- package/src/assets/backgrounds/anime.png +0 -0
- package/src/assets/backgrounds/circuit.jpg +0 -0
- package/src/assets/backgrounds/cyber-grid.jpg +0 -0
- package/src/assets/backgrounds/datacenter.jpg +0 -0
- package/src/assets/backgrounds/hacker-desk.jpg +0 -0
- package/src/assets/backgrounds/matrix-code.jpg +0 -0
- package/src/attention-sounds.bun.ts +8 -0
- package/src/attention-sounds.node.ts +16 -0
- package/src/attention.ts +189 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +49 -0
- package/src/clipboard.ts +68 -0
- package/src/component/background-image.tsx +26 -0
- package/src/component/command-palette.tsx +74 -0
- package/src/component/devtools-bar.tsx +611 -0
- package/src/component/dialog-agent.tsx +33 -0
- package/src/component/dialog-background.tsx +102 -0
- package/src/component/dialog-config.tsx +494 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-error-details.tsx +130 -0
- package/src/component/dialog-experiments.tsx +101 -0
- package/src/component/dialog-go-upsell.tsx +448 -0
- package/src/component/dialog-highlights.tsx +88 -0
- package/src/component/dialog-image-preview.tsx +85 -0
- package/src/component/dialog-install-mcp.tsx +67 -0
- package/src/component/dialog-integration.tsx +1332 -0
- package/src/component/dialog-mcp.tsx +184 -0
- package/src/component/dialog-model-free.tsx +79 -0
- package/src/component/dialog-model.tsx +238 -0
- package/src/component/dialog-open.tsx +509 -0
- package/src/component/dialog-pair.tsx +123 -0
- package/src/component/dialog-session-list.tsx +328 -0
- package/src/component/dialog-session-rename.tsx +37 -0
- package/src/component/dialog-shell-output.tsx +194 -0
- package/src/component/dialog-skill.tsx +93 -0
- package/src/component/dialog-speed.tsx +48 -0
- package/src/component/dialog-stash.tsx +90 -0
- package/src/component/dialog-status.tsx +50 -0
- package/src/component/dialog-theme-list.tsx +56 -0
- package/src/component/dialog-update.tsx +144 -0
- package/src/component/dialog-variant.tsx +43 -0
- package/src/component/dialog-workspace-file-changes.tsx +187 -0
- package/src/component/dialog-workspaces.tsx +413 -0
- package/src/component/dialog-worktree-name.tsx +40 -0
- package/src/component/error-component.tsx +258 -0
- package/src/component/fade-in-text.tsx +113 -0
- package/src/component/go-upsell-art.ts +338 -0
- package/src/component/logo.tsx +79 -0
- package/src/component/masked-text.ts +59 -0
- package/src/component/media-source.ts +43 -0
- package/src/component/migration-overlay.tsx +73 -0
- package/src/component/model-options.tsx +121 -0
- package/src/component/one-cell-spinner.tsx +75 -0
- package/src/component/panel-host.tsx +64 -0
- package/src/component/patch-diff.tsx +211 -0
- package/src/component/plugin-route-missing.tsx +21 -0
- package/src/component/prompt/autocomplete.tsx +1005 -0
- package/src/component/prompt/draft-stash.ts +47 -0
- package/src/component/prompt/index.tsx +2080 -0
- package/src/component/prompt/local-attachment.ts +188 -0
- package/src/component/prompt/metadata.tsx +193 -0
- package/src/component/prompt/move.tsx +181 -0
- package/src/component/reconnecting.tsx +40 -0
- package/src/component/retry-provider.tsx +202 -0
- package/src/component/session-frame.tsx +408 -0
- package/src/component/session-tabs-rail.tsx +94 -0
- package/src/component/session-tabs.tsx +1789 -0
- package/src/component/shimmer-text.tsx +64 -0
- package/src/component/spinner-frames.ts +1 -0
- package/src/component/spinner-renderable.ts +126 -0
- package/src/component/spinner.tsx +50 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/tab-pulse.tsx +819 -0
- package/src/component/terminal-pane.tsx +377 -0
- package/src/component/theme-error-toast.tsx +20 -0
- package/src/component/title-shimmer.tsx +272 -0
- package/src/component/todo-item.tsx +27 -0
- package/src/component/usage.tsx +329 -0
- package/src/component/use-connected.tsx +14 -0
- package/src/config/index.tsx +438 -0
- package/src/config/keybind.ts +367 -0
- package/src/config/new-session-location.ts +16 -0
- package/src/config/v1/index.tsx +149 -0
- package/src/config/v1/keybind.ts +463 -0
- package/src/context/args.tsx +31 -0
- package/src/context/attention.tsx +23 -0
- package/src/context/client-mcp.tsx +119 -0
- package/src/context/client.tsx +76 -0
- package/src/context/clipboard.tsx +19 -0
- package/src/context/data.tsx +69 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +14 -0
- package/src/context/event.ts +32 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/interactivity.tsx +20 -0
- package/src/context/keymap.tsx +515 -0
- package/src/context/local.tsx +723 -0
- package/src/context/location.tsx +80 -0
- package/src/context/log.tsx +24 -0
- package/src/context/panel.tsx +59 -0
- package/src/context/path-format.tsx +12 -0
- package/src/context/permission.tsx +18 -0
- package/src/context/program-status.ts +94 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +73 -0
- package/src/context/runtime.tsx +98 -0
- package/src/context/session-tabs-model.ts +263 -0
- package/src/context/session-tabs.tsx +508 -0
- package/src/context/session-terminals.tsx +136 -0
- package/src/context/storage.tsx +150 -0
- package/src/context/theme.tsx +447 -0
- package/src/context/thinking.ts +20 -0
- package/src/context/update-notification.tsx +158 -0
- package/src/devtools/index.ts +41 -0
- package/src/editor-zed-sqlite.bun.ts +1 -0
- package/src/editor-zed-sqlite.node.ts +21 -0
- package/src/editor-zed.ts +277 -0
- package/src/editor.ts +86 -0
- package/src/feature-plugins/home/footer.tsx +116 -0
- package/src/feature-plugins/prompt/btw.tsx +190 -0
- package/src/feature-plugins/prompt/footer.tsx +163 -0
- package/src/feature-plugins/prompt/goal.tsx +211 -0
- package/src/feature-plugins/sidebar/context.tsx +52 -0
- package/src/feature-plugins/sidebar/footer.tsx +126 -0
- package/src/feature-plugins/sidebar/limit.tsx +47 -0
- package/src/feature-plugins/sidebar/mcp.tsx +103 -0
- package/src/feature-plugins/sidebar/todo.tsx +58 -0
- package/src/feature-plugins/system/diff-viewer-file-menu.tsx +87 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +174 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +274 -0
- package/src/feature-plugins/system/diff-viewer-image.tsx +96 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1380 -0
- package/src/feature-plugins/system/notifications.ts +102 -0
- package/src/feature-plugins/system/plugins.tsx +356 -0
- package/src/feature-plugins/system/stats-data.ts +18 -0
- package/src/feature-plugins/system/stats.tsx +217 -0
- package/src/feature-plugins/system/storybook/footer.tsx +51 -0
- package/src/feature-plugins/system/storybook/highlights.tsx +71 -0
- package/src/feature-plugins/system/storybook/index.tsx +153 -0
- package/src/feature-plugins/system/storybook/link-clicks.tsx +125 -0
- package/src/feature-plugins/system/storybook/merman-layouts.tsx +200 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.fixtures.ts +144 -0
- package/src/feature-plugins/system/storybook/one-cell-spinner.tsx +293 -0
- package/src/feature-plugins/system/storybook/session-location-missing.tsx +80 -0
- package/src/feature-plugins/system/storybook/session-tabs.tsx +571 -0
- package/src/feature-plugins/system/storybook/subcell-spinner.fixtures.ts +115 -0
- package/src/feature-plugins/system/storybook/todo.tsx +166 -0
- package/src/index.tsx +2 -0
- package/src/logo.ts +21 -0
- package/src/mini/catalog.shared.ts +116 -0
- package/src/mini/demo.ts +1086 -0
- package/src/mini/entry.body.ts +244 -0
- package/src/mini/footer.command.tsx +1205 -0
- package/src/mini/footer.form.tsx +647 -0
- package/src/mini/footer.menu.tsx +313 -0
- package/src/mini/footer.permission.tsx +562 -0
- package/src/mini/footer.prompt.tsx +1533 -0
- package/src/mini/footer.subagent.tsx +268 -0
- package/src/mini/footer.ts +1193 -0
- package/src/mini/footer.view.tsx +1022 -0
- package/src/mini/footer.width.ts +118 -0
- package/src/mini/form.shared.ts +241 -0
- package/src/mini/index.ts +7 -0
- package/src/mini/mono.ts +277 -0
- package/src/mini/permission.shared.ts +199 -0
- package/src/mini/prompt.editor.ts +74 -0
- package/src/mini/prompt.shared.ts +192 -0
- package/src/mini/runtime.boot.ts +98 -0
- package/src/mini/runtime.lifecycle.ts +393 -0
- package/src/mini/runtime.queue.ts +320 -0
- package/src/mini/runtime.ts +1117 -0
- package/src/mini/scrollback.shared.ts +82 -0
- package/src/mini/scrollback.surface.ts +548 -0
- package/src/mini/scrollback.writer.tsx +380 -0
- package/src/mini/session-data.ts +13 -0
- package/src/mini/session.shared.ts +113 -0
- package/src/mini/splash.ts +307 -0
- package/src/mini/stream-v2.fragment.ts +83 -0
- package/src/mini/stream-v2.image.ts +38 -0
- package/src/mini/stream-v2.subagent.ts +1130 -0
- package/src/mini/stream-v2.transport.ts +1916 -0
- package/src/mini/stream.ts +152 -0
- package/src/mini/theme.ts +328 -0
- package/src/mini/tool.public.ts +3 -0
- package/src/mini/tool.ts +1394 -0
- package/src/mini/turn-summary.ts +21 -0
- package/src/mini/types.ts +482 -0
- package/src/mini/variant.shared.ts +58 -0
- package/src/mini/verbosity.ts +84 -0
- package/src/model-preference.ts +206 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/api.tsx +486 -0
- package/src/plugin/builtins.ts +35 -0
- package/src/plugin/context.tsx +757 -0
- package/src/plugin/discovery.ts +67 -0
- package/src/plugin/markdown.ts +18 -0
- package/src/plugin/render.tsx +116 -0
- package/src/plugin/runtime-plugin-support.bun.ts +11 -0
- package/src/plugin/runtime-plugin-support.node.ts +1 -0
- package/src/plugin/source.ts +1 -0
- package/src/plugin/structure.ts +159 -0
- package/src/plugin/watch.ts +113 -0
- package/src/prompt/attachment.ts +97 -0
- package/src/prompt/codec.ts +61 -0
- package/src/prompt/content.ts +22 -0
- package/src/prompt/directory-completion.ts +97 -0
- package/src/prompt/directory-recents.ts +36 -0
- package/src/prompt/display.ts +41 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +175 -0
- package/src/prompt/mention.ts +173 -0
- package/src/prompt/parse.ts +25 -0
- package/src/prompt/part.ts +35 -0
- package/src/prompt/restore.ts +39 -0
- package/src/prompt/stash.tsx +93 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home.tsx +180 -0
- package/src/routes/session/activity-summary.ts +101 -0
- package/src/routes/session/anchor-view.tsx +53 -0
- package/src/routes/session/anchors.ts +85 -0
- package/src/routes/session/composer/context.ts +24 -0
- package/src/routes/session/composer/index.tsx +143 -0
- package/src/routes/session/composer/scripts-tab.tsx +166 -0
- package/src/routes/session/composer/shell-tab.tsx +149 -0
- package/src/routes/session/composer/subagents-tab.tsx +264 -0
- package/src/routes/session/composer/tabs.ts +91 -0
- package/src/routes/session/composer/terminals-tab.tsx +114 -0
- package/src/routes/session/dialog-execute.tsx +276 -0
- package/src/routes/session/dialog-fork.tsx +87 -0
- package/src/routes/session/dialog-message.tsx +89 -0
- package/src/routes/session/dialog-timeline.tsx +43 -0
- package/src/routes/session/form.tsx +1177 -0
- package/src/routes/session/group-view.tsx +407 -0
- package/src/routes/session/grouping/session.ts +184 -0
- package/src/routes/session/grouping/tree.ts +111 -0
- package/src/routes/session/history.ts +59 -0
- package/src/routes/session/index.tsx +3922 -0
- package/src/routes/session/location-missing.tsx +81 -0
- package/src/routes/session/message-navigation.ts +48 -0
- package/src/routes/session/message-parts.tsx +322 -0
- package/src/routes/session/mount-budget.ts +38 -0
- package/src/routes/session/permission.tsx +622 -0
- package/src/routes/session/render-context.tsx +44 -0
- package/src/routes/session/rows.ts +493 -0
- package/src/routes/session/sidebar.tsx +80 -0
- package/src/routes/session/thinking-syntax.ts +8 -0
- package/src/runtime.tsx +1 -0
- package/src/simulation/semantics.ts +12 -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/v2/opencode-classic.json +387 -0
- package/src/theme/assets/v2/opencode.json +395 -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/color.ts +48 -0
- package/src/theme/component.ts +51 -0
- package/src/theme/discovery.ts +21 -0
- package/src/theme/index.ts +109 -0
- package/src/theme/resolve.ts +53 -0
- package/src/theme/system.ts +144 -0
- package/src/theme/v1.ts +70 -0
- package/src/ui/animation.ts +235 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +51 -0
- package/src/ui/dialog-confirm.tsx +62 -0
- package/src/ui/dialog-export-options.tsx +316 -0
- package/src/ui/dialog-export-result.tsx +84 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +180 -0
- package/src/ui/dialog-select.tsx +1006 -0
- package/src/ui/dialog.tsx +560 -0
- package/src/ui/file-path.tsx +112 -0
- package/src/ui/layout.ts +26 -0
- package/src/ui/link.tsx +51 -0
- package/src/ui/one-cell-motion.ts +111 -0
- package/src/ui/pane-resize-handle.tsx +33 -0
- package/src/ui/pane-resize.ts +76 -0
- package/src/ui/select-controller.ts +45 -0
- package/src/ui/session-link.ts +92 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/subcell.ts +37 -0
- package/src/ui/toast.tsx +222 -0
- package/src/ui/working-directory-actions.tsx +66 -0
- package/src/util/collapse-tool-output.ts +95 -0
- package/src/util/config-directories.ts +53 -0
- package/src/util/connected-provider.ts +15 -0
- package/src/util/delayed-presence.ts +34 -0
- package/src/util/diff.ts +84 -0
- package/src/util/error-details.ts +21 -0
- package/src/util/error.ts +141 -0
- package/src/util/filetype.ts +135 -0
- package/src/util/form.ts +146 -0
- package/src/util/highlights.ts +51 -0
- package/src/util/locale.ts +81 -0
- package/src/util/marquee.ts +51 -0
- package/src/util/media.ts +43 -0
- package/src/util/model.ts +33 -0
- package/src/util/path-format.ts +37 -0
- package/src/util/path.ts +12 -0
- package/src/util/permission.ts +188 -0
- package/src/util/persistence.ts +42 -0
- package/src/util/presentation.ts +42 -0
- package/src/util/project.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +15 -0
- package/src/util/scroll.ts +29 -0
- package/src/util/selection.ts +103 -0
- package/src/util/session.ts +103 -0
- package/src/util/signal.ts +49 -0
- package/src/util/single-flight.ts +12 -0
- package/src/util/string-width.bun.ts +1 -0
- package/src/util/string-width.node.ts +26 -0
- package/src/util/string-width.ts +1 -0
- package/src/util/system.ts +23 -0
- package/src/util/todo.ts +43 -0
- package/src/util/tool-display.ts +70 -0
- package/src/util/usage-limits.ts +152 -0
- package/src/util/watch.ts +24 -0
- package/test/app-lifecycle.test.tsx +2962 -0
- package/test/clear-session.test.tsx +67 -0
- package/test/cli/cmd/tui/integration-options.test.ts +98 -0
- package/test/cli/cmd/tui/model-options.test.ts +105 -0
- package/test/cli/cmd/tui/notifications.test.ts +356 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +22 -0
- package/test/cli/tui/anchors.test.ts +77 -0
- package/test/cli/tui/collapse-tool-output.test.ts +14 -0
- package/test/cli/tui/command-palette.test.tsx +86 -0
- package/test/cli/tui/composer-keymap.test.tsx +346 -0
- package/test/cli/tui/data.test.tsx +3669 -0
- package/test/cli/tui/dialog-integration.test.tsx +588 -0
- package/test/cli/tui/dialog-mcp.test.tsx +197 -0
- package/test/cli/tui/dialog-open.test.tsx +1037 -0
- package/test/cli/tui/dialog-prompt.test.tsx +253 -0
- package/test/cli/tui/dialog-select.test.tsx +740 -0
- package/test/cli/tui/dialog-session-list.test.tsx +130 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +256 -0
- package/test/cli/tui/diff-viewer-image.test.tsx +172 -0
- package/test/cli/tui/diff-viewer.test.tsx +2510 -0
- package/test/cli/tui/form.test.tsx +950 -0
- package/test/cli/tui/group-boundary.test.ts +63 -0
- package/test/cli/tui/group-view.test.tsx +352 -0
- package/test/cli/tui/grouping-tree.test.ts +82 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +248 -0
- package/test/cli/tui/input-scope.test.tsx +282 -0
- package/test/cli/tui/keymap-arguments.test.tsx +45 -0
- package/test/cli/tui/message-navigation.test.ts +164 -0
- package/test/cli/tui/mount-budget.test.ts +74 -0
- package/test/cli/tui/permission.test.ts +7 -0
- package/test/cli/tui/plugins-dialog.test.tsx +217 -0
- package/test/cli/tui/prompt-interrupt-status.test.tsx +25 -0
- package/test/cli/tui/prompt-move.test.tsx +446 -0
- package/test/cli/tui/reasoning-body.test.tsx +80 -0
- package/test/cli/tui/script-changes.test.ts +41 -0
- package/test/cli/tui/session-grouping.test.ts +21 -0
- package/test/cli/tui/session-history.test.ts +124 -0
- package/test/cli/tui/session-rows.test.ts +616 -0
- package/test/cli/tui/session-verbosity.test.ts +307 -0
- package/test/cli/tui/theme-mode.test.tsx +179 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/toast.test.tsx +117 -0
- package/test/cli/tui/use-event.test.tsx +295 -0
- package/test/client-mcp.test.tsx +226 -0
- package/test/clipboard.test.ts +148 -0
- package/test/command-selection.test.tsx +123 -0
- package/test/compact-admission.test.tsx +251 -0
- package/test/completion-notices.test.tsx +197 -0
- package/test/component/animation-ticks.test.tsx +212 -0
- package/test/component/dialog-error-details.test.tsx +110 -0
- package/test/component/dialog-export-options.test.tsx +68 -0
- package/test/component/dialog-highlights.test.tsx +73 -0
- package/test/component/dialog-model.test.tsx +145 -0
- package/test/component/dialog-shell-output.test.tsx +255 -0
- package/test/component/dialog-speed.test.tsx +114 -0
- package/test/component/dialog-update.test.tsx +111 -0
- package/test/component/dialog-variant.test.tsx +24 -0
- package/test/component/go-upsell-art.test.tsx +110 -0
- package/test/component/retry-provider.test.tsx +288 -0
- package/test/component/session-tabs-marquee.test.tsx +100 -0
- package/test/component/session-tabs-mouse.test.tsx +216 -0
- package/test/component/session-tabs-rail.test.tsx +120 -0
- package/test/component/session-tabs-status.test.tsx +345 -0
- package/test/component/shimmer-text.test.tsx +37 -0
- package/test/component/spinner-renderable.test.tsx +133 -0
- package/test/component/tab-pulse.test.tsx +196 -0
- package/test/component/terminal-pane-theme.test.ts +68 -0
- package/test/config-v2.test.tsx +335 -0
- package/test/config.test.tsx +184 -0
- package/test/context/local-selection.test.tsx +204 -0
- package/test/context/local.test.ts +15 -0
- package/test/context/program-status.test.ts +73 -0
- package/test/context/session-retention.test.ts +234 -0
- package/test/context/session-tabs-model.test.ts +341 -0
- package/test/context/session-tabs.test.tsx +864 -0
- package/test/context/storage.test.ts +37 -0
- package/test/context/theme.test.tsx +183 -0
- package/test/copy-session-id.test.tsx +79 -0
- package/test/editor.test.ts +69 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +234 -0
- package/test/feature-plugins/goal.test.tsx +126 -0
- package/test/feature-plugins/home-footer.test.ts +13 -0
- package/test/feature-plugins/prompt-footer.test.tsx +303 -0
- package/test/feature-plugins/sidebar-context.test.tsx +70 -0
- package/test/feature-plugins/sidebar-footer.test.tsx +139 -0
- package/test/fixture/animation-ticks.ts +19 -0
- package/test/fixture/app.ts +95 -0
- package/test/fixture/diff-image.ts +7 -0
- package/test/fixture/fixture.ts +27 -0
- package/test/fixture/frame.ts +25 -0
- package/test/fixture/local.tsx +158 -0
- package/test/fixture/plugin/client-reads/tui.tsx +9 -0
- package/test/fixture/plugin/dialog-throw/tui.tsx +11 -0
- package/test/fixture/plugin/native-resources/tui.tsx +26 -0
- package/test/fixture/plugin/setup-keymap/tui.tsx +72 -0
- package/test/fixture/plugin/slot-string/tui.tsx +10 -0
- package/test/fixture/tui-client.ts +186 -0
- package/test/fixture/tui-environment.tsx +47 -0
- package/test/fixture/tui-runtime.ts +21 -0
- package/test/highlights.test.ts +43 -0
- package/test/interactivity.test.tsx +46 -0
- package/test/keybind.test.ts +7 -0
- package/test/keymap-scope.test.tsx +271 -0
- package/test/keymap.test.tsx +244 -0
- package/test/markdown-streaming.test.tsx +49 -0
- package/test/mini/blocker.responsive.test.tsx +732 -0
- package/test/mini/catalog.shared.test.ts +76 -0
- package/test/mini/entry.body.test.ts +622 -0
- package/test/mini/fixture/catalog.ts +63 -0
- package/test/mini/fixture/footer-api.ts +69 -0
- package/test/mini/fixture/tool-part.ts +20 -0
- package/test/mini/footer-keymap.test.tsx +141 -0
- package/test/mini/footer.menu.test.ts +43 -0
- package/test/mini/footer.responsive.test.tsx +438 -0
- package/test/mini/footer.test.ts +446 -0
- package/test/mini/footer.view.test.tsx +2627 -0
- package/test/mini/footer.width.test.ts +120 -0
- package/test/mini/form.shared.test.ts +66 -0
- package/test/mini/permission.shared.test.ts +195 -0
- package/test/mini/prompt.editor.test.ts +118 -0
- package/test/mini/prompt.shared.test.ts +104 -0
- package/test/mini/runtime.boot.test.ts +118 -0
- package/test/mini/runtime.queue.test.ts +443 -0
- package/test/mini/runtime.test.ts +591 -0
- package/test/mini/scrollback.image.test.ts +213 -0
- package/test/mini/scrollback.surface.test.ts +1078 -0
- package/test/mini/session.shared.test.ts +267 -0
- package/test/mini/splash.test.ts +196 -0
- package/test/mini/stream-v2.transport.test.ts +4705 -0
- package/test/mini/stream.test.ts +52 -0
- package/test/mini/theme.test.ts +438 -0
- package/test/mini/tool.test.ts +134 -0
- package/test/mini/variant.shared.test.ts +58 -0
- package/test/mini/verbosity.test.ts +53 -0
- package/test/model-preference.test.ts +70 -0
- package/test/new-session-id.test.tsx +102 -0
- package/test/new-session-location.test.ts +30 -0
- package/test/panel.test.ts +71 -0
- package/test/plugin-discovery.test.ts +18 -0
- package/test/plugin-keymap.test.tsx +143 -0
- package/test/plugin-markdown.test.tsx +120 -0
- package/test/plugin-model.test.tsx +46 -0
- package/test/plugin-native-resources.test.tsx +11 -0
- package/test/plugin-select.test.tsx +391 -0
- package/test/plugin-slot-output.test.tsx +23 -0
- package/test/plugin-source.test.ts +871 -0
- package/test/plugin-toast.test.tsx +62 -0
- package/test/preload.ts +17 -0
- package/test/prompt/attachment.test.ts +138 -0
- package/test/prompt/autocomplete.test.ts +218 -0
- package/test/prompt/codec.test.ts +136 -0
- package/test/prompt/display.test.ts +72 -0
- package/test/prompt/draft-stash.test.ts +42 -0
- package/test/prompt/history-composer.test.tsx +52 -0
- package/test/prompt/history-provider.test.tsx +108 -0
- package/test/prompt/history.test.ts +94 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +244 -0
- package/test/prompt/mention.test.ts +119 -0
- package/test/prompt/parse.test.ts +46 -0
- package/test/prompt/part.test.ts +40 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/prompt-cursor.test.tsx +27 -0
- package/test/prompt-offset.test.tsx +58 -0
- package/test/prompt-paste.test.tsx +127 -0
- package/test/prompt-shell-failure.test.tsx +76 -0
- package/test/routes/composer-tabs.test.tsx +97 -0
- package/test/runtime.test.tsx +37 -0
- package/test/session-activity-anchor.test.tsx +180 -0
- package/test/session-backfill-disclosure.test.tsx +89 -0
- package/test/session-dialog-resync.test.tsx +122 -0
- package/test/session-fork-pending.test.tsx +60 -0
- package/test/session-group-navigation.test.tsx +252 -0
- package/test/session-history-interactions.test.tsx +305 -0
- package/test/session-history-reveal.test.tsx +108 -0
- package/test/session-home.test.tsx +401 -0
- package/test/session-interrupt-undo.test.tsx +98 -0
- package/test/session-media-refs.test.tsx +360 -0
- package/test/session-mount-budget.test.tsx +137 -0
- package/test/session-panel.test.tsx +721 -0
- package/test/session-shell-output.test.tsx +114 -0
- package/test/session-shell-stopped.test.tsx +107 -0
- package/test/session-subagent-navigation.test.tsx +44 -0
- package/test/session-submit-scroll.test.tsx +85 -0
- package/test/session-terminal-availability.test.tsx +80 -0
- package/test/session-wheel-focus.test.tsx +176 -0
- package/test/simulation/semantics.test.ts +23 -0
- package/test/stats.test.ts +33 -0
- package/test/stats.view.test.tsx +94 -0
- package/test/theme/v2/component.test.ts +87 -0
- package/test/theme/v2/resolve.test.ts +424 -0
- package/test/theme/v2/select.test.ts +25 -0
- package/test/theme/v2/types.typecheck.ts +57 -0
- package/test/theme/v2/v1-migrate.test.ts +397 -0
- package/test/theme.test.ts +150 -0
- package/test/ui/dialog-layout.test.tsx +56 -0
- package/test/ui/file-path.test.ts +61 -0
- package/test/ui/layout.test.ts +31 -0
- package/test/ui/link.test.tsx +60 -0
- package/test/ui/pane-resize-handle.test.tsx +134 -0
- package/test/ui/pane-resize.test.ts +258 -0
- package/test/ui/select-controller.test.ts +44 -0
- package/test/ui/session-link.test.tsx +325 -0
- package/test/usage-limits.test.tsx +162 -0
- package/test/util/added-patch.test.ts +44 -0
- package/test/util/connected-provider.test.ts +59 -0
- package/test/util/delayed-presence.test.ts +114 -0
- package/test/util/error-details.test.ts +26 -0
- package/test/util/error.test.ts +36 -0
- package/test/util/filetype.test.ts +23 -0
- package/test/util/form.test.ts +110 -0
- package/test/util/locale.test.ts +32 -0
- package/test/util/marquee.test.ts +45 -0
- package/test/util/media.test.ts +54 -0
- package/test/util/model.test.ts +70 -0
- package/test/util/path-format.test.ts +15 -0
- package/test/util/permission.test.ts +23 -0
- package/test/util/presentation.test.ts +30 -0
- package/test/util/renderer.test.ts +42 -0
- package/test/util/selection-copy-on-select.test.tsx +64 -0
- package/test/util/selection-keys.test.ts +172 -0
- package/test/util/selection.test.ts +115 -0
- package/test/util/session.test.ts +70 -0
- package/test/util/tool-display.test.ts +65 -0
- package/test/util/usage-limits.test.ts +154 -0
- package/tsconfig.json +13 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2080 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BoxRenderable,
|
|
3
|
+
RGBA,
|
|
4
|
+
TextareaRenderable,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
PasteEvent,
|
|
7
|
+
decodePasteBytes,
|
|
8
|
+
measureEditText,
|
|
9
|
+
stripAnsiSequences,
|
|
10
|
+
type KeyEvent,
|
|
11
|
+
} from "@opentui/core"
|
|
12
|
+
import { createEffect, createMemo, onMount, createSignal, onCleanup, on, Show, Switch, Match, For } from "solid-js"
|
|
13
|
+
import path from "path"
|
|
14
|
+
import { useLocal } from "../../context/local"
|
|
15
|
+
import { useTheme, useThemes } from "../../context/theme"
|
|
16
|
+
import { tint } from "../../theme/color"
|
|
17
|
+
import { createAnimatable, tween } from "../../ui/animation"
|
|
18
|
+
import { EmptyBorder, SplitBorder } from "../../ui/border"
|
|
19
|
+
import { useTuiPaths, useTuiTerminalEnvironment } from "../../context/runtime"
|
|
20
|
+
import { useClipboard } from "../../context/clipboard"
|
|
21
|
+
import { Spinner } from "../spinner"
|
|
22
|
+
import { useClient } from "../../context/client"
|
|
23
|
+
import { useRoute } from "../../context/route"
|
|
24
|
+
import { usePromptRef } from "../../context/prompt"
|
|
25
|
+
import { useSessionTabs } from "../../context/session-tabs"
|
|
26
|
+
import { useEvent } from "../../context/event"
|
|
27
|
+
import { editorSelectionKey, useEditorContext, type EditorSelection } from "../../context/editor"
|
|
28
|
+
import { normalizePromptContent, openEditor } from "../../editor"
|
|
29
|
+
import { useExit } from "../../context/exit"
|
|
30
|
+
import { expandPromptInputPastedText, realignPromptInputMentions } from "../../prompt/mention"
|
|
31
|
+
import { parseSlashHead } from "../../prompt/parse"
|
|
32
|
+
import { createStore, produce, unwrap } from "solid-js/store"
|
|
33
|
+
import { emptyPrompt, usePromptHistory, type ChipData, type PromptInfo, type PromptPartRef } from "../../prompt/history"
|
|
34
|
+
import { appendToSessionPrompt, registerComposer, saveDraft, takeDraft } from "./draft-stash"
|
|
35
|
+
import { usePromptRestore } from "../../prompt/restore"
|
|
36
|
+
import { Skill } from "@zyro-sec/schema/skill"
|
|
37
|
+
import { computePromptTraits } from "../../prompt/traits"
|
|
38
|
+
import { expandPastedTextPlaceholders, expandTrackedPastedText } from "../../prompt/part"
|
|
39
|
+
import { usePromptStash } from "../../prompt/stash"
|
|
40
|
+
import { DialogStash } from "../dialog-stash"
|
|
41
|
+
import { type AutocompleteOption, type AutocompleteRef, Autocomplete } from "./autocomplete"
|
|
42
|
+
import { useRenderer, useTerminalDimensions } from "@opentui/solid"
|
|
43
|
+
import { Locale } from "../../util/locale"
|
|
44
|
+
import { errorMessage } from "../../util/error"
|
|
45
|
+
import { createColors, createFrames } from "../../ui/spinner"
|
|
46
|
+
import { useDialog } from "../../ui/dialog"
|
|
47
|
+
import { DialogIntegration } from "../dialog-integration"
|
|
48
|
+
import { useConnected } from "../use-connected"
|
|
49
|
+
import { useToast } from "../../ui/toast"
|
|
50
|
+
import { createFadeIn } from "../../util/signal"
|
|
51
|
+
import { DialogSkill } from "../dialog-skill"
|
|
52
|
+
import { useConfig, useCursorStyle, useNewDesigns } from "../../config"
|
|
53
|
+
import { usePromptMove } from "./move"
|
|
54
|
+
import { promptFilesForServer, resolvePastedAttachments } from "./local-attachment"
|
|
55
|
+
import { locationKey, useData } from "../../context/data"
|
|
56
|
+
import { useLocation } from "../../context/location"
|
|
57
|
+
import { useArgs } from "../../context/args"
|
|
58
|
+
import { Keymap, type KeymapCommand } from "../../context/keymap"
|
|
59
|
+
import { useInteractivity } from "../../context/interactivity"
|
|
60
|
+
import { abbreviateHome } from "../../runtime"
|
|
61
|
+
import { Slot } from "../../plugin/render"
|
|
62
|
+
import type { SessionInbox } from "@zyro-sec/schema/session-inbox"
|
|
63
|
+
import {
|
|
64
|
+
deduplicatePromptImages,
|
|
65
|
+
preserveMentionlessPromptAttachments,
|
|
66
|
+
promptAttachmentLabel,
|
|
67
|
+
} from "../../prompt/attachment"
|
|
68
|
+
import { DialogImagePreview } from "../dialog-image-preview"
|
|
69
|
+
import { useDirectoryRecents } from "../../prompt/directory-recents"
|
|
70
|
+
import { directoryRecentValue } from "../../prompt/directory-completion"
|
|
71
|
+
import { useWorkingDirectoryActions } from "../../ui/working-directory-actions"
|
|
72
|
+
import { truncateFilePath } from "../../ui/file-path"
|
|
73
|
+
import { PromptMetadataRow } from "./metadata"
|
|
74
|
+
import { limitLabel, useUsageLimits } from "../usage"
|
|
75
|
+
|
|
76
|
+
export type PromptProps = {
|
|
77
|
+
sessionID?: string
|
|
78
|
+
visible?: boolean
|
|
79
|
+
disabled?: boolean
|
|
80
|
+
muted?: boolean
|
|
81
|
+
onSubmit?: () => void
|
|
82
|
+
onEmptySubmit?: () => boolean | Promise<boolean>
|
|
83
|
+
ref?: (ref: PromptRef | undefined) => void
|
|
84
|
+
placeholders?: {
|
|
85
|
+
normal?: string[]
|
|
86
|
+
shell?: string[]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export type PromptRef = {
|
|
91
|
+
focused: boolean
|
|
92
|
+
current: PromptInfo
|
|
93
|
+
mode: "normal" | "shell"
|
|
94
|
+
setMode(mode: "normal" | "shell"): void
|
|
95
|
+
set(prompt: PromptInfo): void
|
|
96
|
+
reset(): void
|
|
97
|
+
blur(): void
|
|
98
|
+
focus(): void
|
|
99
|
+
submit(): void
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const DRAFT_RETENTION_MIN_CHARS = 20
|
|
103
|
+
const revealedPromptMetadata = new WeakSet<object>()
|
|
104
|
+
|
|
105
|
+
function randomIndex(count: number) {
|
|
106
|
+
if (count <= 0) return 0
|
|
107
|
+
return Math.floor(Math.random() * count)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function PromptInterruptStatus(props: {
|
|
111
|
+
armed: boolean
|
|
112
|
+
animations?: boolean
|
|
113
|
+
text: RGBA
|
|
114
|
+
subdued: RGBA
|
|
115
|
+
warning: RGBA
|
|
116
|
+
flash?: RGBA
|
|
117
|
+
}) {
|
|
118
|
+
const ignition = createAnimatable(
|
|
119
|
+
{ level: 0 },
|
|
120
|
+
{ enabled: () => props.animations ?? false, transition: tween({ duration: 0.22 }) },
|
|
121
|
+
)
|
|
122
|
+
createEffect(
|
|
123
|
+
on(
|
|
124
|
+
() => props.armed,
|
|
125
|
+
(armed) => {
|
|
126
|
+
if (!armed || !props.animations) return ignition.jump({ level: 0 })
|
|
127
|
+
ignition.jump({ level: 0.75 })
|
|
128
|
+
ignition.animate({ level: 0 })
|
|
129
|
+
},
|
|
130
|
+
{ defer: true },
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
const armedColor = createMemo(() => {
|
|
134
|
+
const level = ignition.value().level
|
|
135
|
+
if (level === 0 || !props.flash) return props.warning
|
|
136
|
+
return tint(props.warning, props.flash, level)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
return (
|
|
140
|
+
<text fg={props.armed ? armedColor() : props.text} wrapMode="none" truncate flexShrink={1}>
|
|
141
|
+
esc{" "}
|
|
142
|
+
<span style={{ fg: props.armed ? armedColor() : props.subdued }}>
|
|
143
|
+
{props.armed ? "again to interrupt" : "interrupt"}
|
|
144
|
+
</span>
|
|
145
|
+
</text>
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function hasEditorRangeSelection(selection: EditorSelection["ranges"][number]) {
|
|
150
|
+
return (
|
|
151
|
+
selection.selection.start.line !== selection.selection.end.line ||
|
|
152
|
+
selection.selection.start.character !== selection.selection.end.character
|
|
153
|
+
)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function getEditorRangeLabel(selection: EditorSelection["ranges"][number]) {
|
|
157
|
+
if (!hasEditorRangeSelection(selection)) return
|
|
158
|
+
if (selection.selection.start.line === selection.selection.end.line) return `#${selection.selection.start.line}`
|
|
159
|
+
return `#${selection.selection.start.line}-${selection.selection.end.line}`
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function formatEditorContext(selection: EditorSelection) {
|
|
163
|
+
const selected = selection.ranges.filter(hasEditorRangeSelection)
|
|
164
|
+
if (selected.length === 0)
|
|
165
|
+
return `<system-update>Note: The user opened the file "${selection.filePath}". This may or may not be relevant to the current task.</system-update>\n`
|
|
166
|
+
|
|
167
|
+
const ranges = selected.map((range, index) => {
|
|
168
|
+
const prefix = selected.length > 1 ? `Selection ${index + 1}: ` : ""
|
|
169
|
+
return `Note: The user selected ${prefix}${getEditorRangeLabel(range)} from "${selection.filePath}". \`\`\`${range.text}\`\`\`\n\n`
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
return `<system-update>${ranges.join("\n")} This may or may not be relevant to the current task.</system-update>\n`
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function argumentSlash(input: string, commands: readonly KeymapCommand[]) {
|
|
176
|
+
const head = parseSlashHead(input, /\s/)
|
|
177
|
+
if (!head) return
|
|
178
|
+
const command = commands.find(
|
|
179
|
+
(command) =>
|
|
180
|
+
command.slash?.arguments &&
|
|
181
|
+
(command.slash.name === head.name || command.slash.aliases?.includes(head.name) === true),
|
|
182
|
+
)
|
|
183
|
+
if (!command) return
|
|
184
|
+
return { command, input: head.arguments }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function Prompt(props: PromptProps) {
|
|
188
|
+
let input: TextareaRenderable
|
|
189
|
+
let anchor: BoxRenderable
|
|
190
|
+
const [inputTarget, setInputTarget] = createSignal<TextareaRenderable | undefined>()
|
|
191
|
+
|
|
192
|
+
const enabled = useInteractivity()
|
|
193
|
+
const disabled = () => props.disabled || !enabled()
|
|
194
|
+
const leader = Keymap.useLeaderActive()
|
|
195
|
+
const muted = () => leader() || props.muted
|
|
196
|
+
const local = useLocal()
|
|
197
|
+
const paths = useTuiPaths()
|
|
198
|
+
const terminalEnvironment = useTuiTerminalEnvironment()
|
|
199
|
+
const clipboard = useClipboard()
|
|
200
|
+
const client = useClient()
|
|
201
|
+
const editor = useEditorContext()
|
|
202
|
+
const route = useRoute()
|
|
203
|
+
const promptRef = usePromptRef()
|
|
204
|
+
const sessionTabs = useSessionTabs()
|
|
205
|
+
const data = useData()
|
|
206
|
+
const directoryRecents = useDirectoryRecents()
|
|
207
|
+
const keymapCommands = Keymap.useCommands()
|
|
208
|
+
const currentLocation = useLocation()
|
|
209
|
+
const args = useArgs()
|
|
210
|
+
const config = useConfig().data
|
|
211
|
+
const cursorStyle = useCursorStyle()
|
|
212
|
+
const dialog = useDialog()
|
|
213
|
+
const toast = useToast()
|
|
214
|
+
const status = createMemo(() => data.session.status(props.sessionID ?? ""))
|
|
215
|
+
const stash = usePromptStash()
|
|
216
|
+
const keymap = Keymap.use()
|
|
217
|
+
const renderer = useRenderer()
|
|
218
|
+
const measure = (text: string) => measureEditText(text, { widthMethod: renderer.widthMethod })
|
|
219
|
+
const exit = useExit()
|
|
220
|
+
const dimensions = useTerminalDimensions()
|
|
221
|
+
const theme = useTheme()
|
|
222
|
+
const newDesigns = useNewDesigns()
|
|
223
|
+
const { currentSyntax: syntax } = useThemes()
|
|
224
|
+
const animationsEnabled = createMemo(() => config.animations ?? true)
|
|
225
|
+
const list = createMemo(() => props.placeholders?.normal ?? [])
|
|
226
|
+
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
|
227
|
+
const fileContextEnabled = createMemo(() => config.prompt?.editor ?? true)
|
|
228
|
+
const [dismissedEditorSelectionKey, setDismissedEditorSelectionKey] = createSignal<string>()
|
|
229
|
+
const editorContext = createMemo(() => {
|
|
230
|
+
const selection = fileContextEnabled() ? editor.selection() : undefined
|
|
231
|
+
if (!selection) return
|
|
232
|
+
return editorSelectionKey(selection) === dismissedEditorSelectionKey() ? undefined : selection
|
|
233
|
+
})
|
|
234
|
+
const editorPath = createMemo(() => editorContext()?.filePath)
|
|
235
|
+
const editorSelectionLabel = createMemo(() => {
|
|
236
|
+
const ranges = editorContext()?.ranges
|
|
237
|
+
if (!ranges) return
|
|
238
|
+
const first = ranges.find(hasEditorRangeSelection) ?? ranges[0]
|
|
239
|
+
if (!first) return
|
|
240
|
+
return [getEditorRangeLabel(first), ranges.length > 1 ? `+${ranges.length - 1}` : undefined]
|
|
241
|
+
.filter(Boolean)
|
|
242
|
+
.join(" ")
|
|
243
|
+
})
|
|
244
|
+
const editorFileLabel = createMemo(() => {
|
|
245
|
+
const value = editorPath()
|
|
246
|
+
if (!value) return
|
|
247
|
+
const filename = path.basename(value)
|
|
248
|
+
const file = /^index\.[^./]+$/.test(filename)
|
|
249
|
+
? [path.basename(path.dirname(value)), filename].filter(Boolean).join("/")
|
|
250
|
+
: filename
|
|
251
|
+
return `${file.split(path.sep).join("/")}${editorSelectionLabel() ?? ""}`
|
|
252
|
+
})
|
|
253
|
+
const editorFileLabelDisplay = createMemo(() => {
|
|
254
|
+
const file = editorFileLabel()
|
|
255
|
+
if (!file) return
|
|
256
|
+
return Locale.truncateMiddle(file, Math.max(12, Math.min(48, Math.floor(dimensions().width / 3))))
|
|
257
|
+
})
|
|
258
|
+
const editorContextLabelState = createMemo(() => editor.labelState())
|
|
259
|
+
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
|
260
|
+
const move = usePromptMove({
|
|
261
|
+
projectID: () =>
|
|
262
|
+
(props.sessionID ? data.session.get(props.sessionID)?.projectID : undefined) ?? data.location.info()?.project.id,
|
|
263
|
+
sessionID: () => props.sessionID,
|
|
264
|
+
})
|
|
265
|
+
const [pendingDirectory, setPendingDirectory] = createSignal<string>()
|
|
266
|
+
Keymap.createLayer(() => ({
|
|
267
|
+
mode: "global",
|
|
268
|
+
enabled: !disabled(),
|
|
269
|
+
commands: [
|
|
270
|
+
{
|
|
271
|
+
id: "session.cd",
|
|
272
|
+
title: "Change working directory",
|
|
273
|
+
slash: { name: "cd", arguments: true },
|
|
274
|
+
run: async (input) => {
|
|
275
|
+
if (!input?.trim()) {
|
|
276
|
+
toast.show({ message: "Directory is required", variant: "error" })
|
|
277
|
+
return
|
|
278
|
+
}
|
|
279
|
+
const sessionID = props.sessionID
|
|
280
|
+
const session = sessionID ? data.session.get(sessionID) : undefined
|
|
281
|
+
const sourceProjectID = session?.projectID ?? data.location.info()?.project.id
|
|
282
|
+
const value = input.trim()
|
|
283
|
+
const expanded =
|
|
284
|
+
value === "~" ? paths.home : value.startsWith("~/") ? path.join(paths.home, value.slice(2)) : value
|
|
285
|
+
const directory = path.resolve(
|
|
286
|
+
session?.location.directory ?? currentLocation.current?.directory ?? data.location.default().directory,
|
|
287
|
+
expanded,
|
|
288
|
+
)
|
|
289
|
+
if (!sessionID) {
|
|
290
|
+
setPendingDirectory(directory)
|
|
291
|
+
const location = await client.api.location.get({ location: { directory } }).catch((error) => {
|
|
292
|
+
toast.show({ title: "Failed to change directory", message: errorMessage(error), variant: "error" })
|
|
293
|
+
return undefined
|
|
294
|
+
})
|
|
295
|
+
if (!location) {
|
|
296
|
+
setPendingDirectory(undefined)
|
|
297
|
+
return
|
|
298
|
+
}
|
|
299
|
+
if (sourceProjectID) directoryRecents.touch(sourceProjectID, location.directory)
|
|
300
|
+
currentLocation.set(location)
|
|
301
|
+
setPendingDirectory(undefined)
|
|
302
|
+
return
|
|
303
|
+
}
|
|
304
|
+
const error = await client.api.session.move({ sessionID, directory: input }).then(
|
|
305
|
+
() => undefined,
|
|
306
|
+
(error) => error,
|
|
307
|
+
)
|
|
308
|
+
if (error) {
|
|
309
|
+
toast.show({ title: "Failed to change directory", message: errorMessage(error), variant: "error" })
|
|
310
|
+
return
|
|
311
|
+
}
|
|
312
|
+
if (sourceProjectID) directoryRecents.touch(sourceProjectID, directory)
|
|
313
|
+
},
|
|
314
|
+
},
|
|
315
|
+
],
|
|
316
|
+
}))
|
|
317
|
+
const [cursorVersion, setCursorVersion] = createSignal(0)
|
|
318
|
+
const connected = useConnected()
|
|
319
|
+
|
|
320
|
+
function promptModelWarning() {
|
|
321
|
+
toast.show({
|
|
322
|
+
variant: "warning",
|
|
323
|
+
message: "Connect an integration to send prompts",
|
|
324
|
+
duration: 3000,
|
|
325
|
+
})
|
|
326
|
+
if (!connected()) {
|
|
327
|
+
dialog.replace(() => <DialogIntegration />)
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function dismissEditorContext() {
|
|
332
|
+
setDismissedEditorSelectionKey(editorSelectionKey(editorContext()))
|
|
333
|
+
editor.clearSelection()
|
|
334
|
+
}
|
|
335
|
+
const fileStyleId = syntax().getStyleId("extmark.file")!
|
|
336
|
+
const agentStyleId = syntax().getStyleId("extmark.agent")!
|
|
337
|
+
const skillStyleId = syntax().getStyleId("extmark.skill")!
|
|
338
|
+
const pasteStyleId = syntax().getStyleId("extmark.paste")!
|
|
339
|
+
let promptPartTypeId = 0
|
|
340
|
+
const event = useEvent()
|
|
341
|
+
|
|
342
|
+
event.on("tui.prompt.append", (evt, { directory }) => {
|
|
343
|
+
if (directory !== (currentLocation.current?.directory ?? data.location.default().directory)) return
|
|
344
|
+
if (!input || input.isDestroyed) return
|
|
345
|
+
input.insertText(evt.data.text)
|
|
346
|
+
input.gotoBufferEnd()
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
createEffect(() => {
|
|
350
|
+
if (!input || input.isDestroyed) return
|
|
351
|
+
input.cursorColor = disabled() ? theme.background.raised.base : theme.text.base
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
const [store, setStore] = createStore<{
|
|
355
|
+
prompt: PromptInfo
|
|
356
|
+
mode: "normal" | "shell"
|
|
357
|
+
extmarkToPart: Map<number, PromptPartRef>
|
|
358
|
+
interrupt: number
|
|
359
|
+
placeholder: number
|
|
360
|
+
}>({
|
|
361
|
+
placeholder: randomIndex(list().length),
|
|
362
|
+
prompt: emptyPrompt(),
|
|
363
|
+
mode: "normal",
|
|
364
|
+
extmarkToPart: new Map(),
|
|
365
|
+
interrupt: 0,
|
|
366
|
+
})
|
|
367
|
+
const history = usePromptHistory(() => ({ ...unwrap(store.prompt), mode: store.mode }))
|
|
368
|
+
let disposed = false
|
|
369
|
+
let pasteQueue = Promise.resolve()
|
|
370
|
+
|
|
371
|
+
function enqueuePaste(run: (changed: () => boolean) => Promise<void>) {
|
|
372
|
+
pasteQueue = pasteQueue
|
|
373
|
+
.then(async () => {
|
|
374
|
+
if (disposed || input.isDestroyed || disabled()) return
|
|
375
|
+
const before = { sessionID: props.sessionID, mode: store.mode, text: input.plainText }
|
|
376
|
+
await run(
|
|
377
|
+
() =>
|
|
378
|
+
disposed ||
|
|
379
|
+
input.isDestroyed ||
|
|
380
|
+
disabled() ||
|
|
381
|
+
props.sessionID !== before.sessionID ||
|
|
382
|
+
store.mode !== before.mode ||
|
|
383
|
+
input.plainText !== before.text,
|
|
384
|
+
)
|
|
385
|
+
})
|
|
386
|
+
.catch((error) => {
|
|
387
|
+
if (!disposed) toast.error(error)
|
|
388
|
+
})
|
|
389
|
+
return pasteQueue
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
const restorePrompt = usePromptRestore()
|
|
393
|
+
// Interrupting before the model has answered with text or a tool call takes the prompt back, as /undo does: the
|
|
394
|
+
// likeliest reason to stop that early is to reword what was just sent. A draft or a pending prompt means the user
|
|
395
|
+
// has moved on to something else, so those keep the plain interrupt.
|
|
396
|
+
async function interrupt(sessionID: string) {
|
|
397
|
+
const takeBack = !store.prompt.text.trim() && data.session.pending.list(sessionID).length === 0
|
|
398
|
+
const result = await client.api.session.interrupt({ sessionID, resume: true })
|
|
399
|
+
// A repeated press finds the execution already stopping and reports nothing interrupted.
|
|
400
|
+
if (!takeBack || !result.interrupted) return
|
|
401
|
+
await client.api.experimental.session.wait({ sessionID })
|
|
402
|
+
const messages = data.session.message.list(sessionID)
|
|
403
|
+
const index = messages.findLastIndex((message) => message.type === "user")
|
|
404
|
+
const message = messages[index]
|
|
405
|
+
if (message?.type !== "user") return
|
|
406
|
+
// A shell command, a compaction and a synthetic prompt each start a run of their own, so the one just stopped
|
|
407
|
+
// wasn't this prompt's.
|
|
408
|
+
const answered = messages.slice(index + 1).some((item) => {
|
|
409
|
+
if (item.type === "shell" || item.type === "compaction" || item.type === "synthetic") return true
|
|
410
|
+
return (
|
|
411
|
+
item.type === "assistant" &&
|
|
412
|
+
item.content.some((part) => part.type === "tool" || (part.type === "text" && part.text.trim()))
|
|
413
|
+
)
|
|
414
|
+
})
|
|
415
|
+
if (answered) return
|
|
416
|
+
const restored = await restorePrompt(message)
|
|
417
|
+
// The model called no tool, so any file that changed meanwhile is the user's own edit.
|
|
418
|
+
await client.api.session.revert.stage({ sessionID, messageID: message.id, files: false })
|
|
419
|
+
// Nothing of an answer is lost and the prompt is back in the composer, so drop it for good instead of leaving a
|
|
420
|
+
// "reverted" notice to redo from.
|
|
421
|
+
await client.api.session.revert.commit({ sessionID })
|
|
422
|
+
appendToSessionPrompt(sessionID, restored, renderer.widthMethod)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
const imageAttachments = createMemo(() =>
|
|
426
|
+
(deduplicatePromptImages(store.prompt.files) ?? []).filter((file) => file.uri.startsWith("data:image/")),
|
|
427
|
+
)
|
|
428
|
+
const imagePreviewHeight = createMemo(() => Math.max(4, Math.min(8, Math.floor(dimensions().height / 4))))
|
|
429
|
+
const imagePreviewWidth = createMemo(() => imagePreviewHeight() * 2)
|
|
430
|
+
const visibleImageAttachments = createMemo(() => imageAttachments().slice(0, 3))
|
|
431
|
+
|
|
432
|
+
function openImagePreview(initial: number) {
|
|
433
|
+
const images = imageAttachments()
|
|
434
|
+
if (images.length === 0) return
|
|
435
|
+
dialog.replace(() => <DialogImagePreview images={images} initial={initial} />)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
createEffect(
|
|
439
|
+
on(
|
|
440
|
+
() => props.sessionID,
|
|
441
|
+
() => {
|
|
442
|
+
setStore("placeholder", randomIndex(list().length))
|
|
443
|
+
},
|
|
444
|
+
{ defer: true },
|
|
445
|
+
),
|
|
446
|
+
)
|
|
447
|
+
|
|
448
|
+
const promptCommands = createMemo(() =>
|
|
449
|
+
[
|
|
450
|
+
{
|
|
451
|
+
title: "Clear prompt",
|
|
452
|
+
name: "prompt.clear",
|
|
453
|
+
category: "Prompt",
|
|
454
|
+
palette: undefined,
|
|
455
|
+
run: () => {
|
|
456
|
+
clearPrompt()
|
|
457
|
+
dialog.clear()
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
title: "Submit prompt",
|
|
462
|
+
name: "prompt.submit",
|
|
463
|
+
category: "Prompt",
|
|
464
|
+
palette: undefined,
|
|
465
|
+
run: async (_input: string | undefined, event?: KeyEvent) => {
|
|
466
|
+
event?.preventDefault()
|
|
467
|
+
event?.stopPropagation()
|
|
468
|
+
if (!input.focused) return
|
|
469
|
+
const handled = await submit()
|
|
470
|
+
if (!handled) return
|
|
471
|
+
|
|
472
|
+
dialog.clear()
|
|
473
|
+
},
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
title: "Queue prompt",
|
|
477
|
+
name: "prompt.queue",
|
|
478
|
+
category: "Prompt",
|
|
479
|
+
run: async (_input: string | undefined, event?: KeyEvent) => {
|
|
480
|
+
event?.preventDefault()
|
|
481
|
+
event?.stopPropagation()
|
|
482
|
+
if (!input.focused) return
|
|
483
|
+
if (auto()?.visible && !auto()?.completeQueueableCommand()) return
|
|
484
|
+
const handled = await submit("queue")
|
|
485
|
+
if (!handled) return
|
|
486
|
+
dialog.clear()
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
title: "Remove editor context",
|
|
491
|
+
name: "prompt.editor_context.clear",
|
|
492
|
+
category: "Prompt",
|
|
493
|
+
enabled: Boolean(editorContext()),
|
|
494
|
+
run: () => {
|
|
495
|
+
dismissEditorContext()
|
|
496
|
+
dialog.clear()
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
title: "Paste",
|
|
501
|
+
name: "prompt.paste",
|
|
502
|
+
category: "Prompt",
|
|
503
|
+
palette: undefined,
|
|
504
|
+
run: (_input: string | undefined, event?: KeyEvent) => {
|
|
505
|
+
event?.preventDefault()
|
|
506
|
+
event?.stopPropagation()
|
|
507
|
+
return enqueuePaste(async (changed) => {
|
|
508
|
+
const content = await clipboard.read()
|
|
509
|
+
if (changed()) return
|
|
510
|
+
if (content?.mime.startsWith("image/")) {
|
|
511
|
+
pasteAttachment({
|
|
512
|
+
filename: "clipboard",
|
|
513
|
+
uri: `data:${content.mime};base64,${content.data}`,
|
|
514
|
+
})
|
|
515
|
+
return
|
|
516
|
+
}
|
|
517
|
+
if (content?.mime === "text/plain") {
|
|
518
|
+
await pasteInputText(content.data, changed)
|
|
519
|
+
}
|
|
520
|
+
})
|
|
521
|
+
},
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
title: "View image attachments",
|
|
525
|
+
name: "prompt.images.view",
|
|
526
|
+
category: "Prompt",
|
|
527
|
+
enabled: imageAttachments().length > 0,
|
|
528
|
+
run: () => openImagePreview(0),
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
title: "Interrupt session",
|
|
532
|
+
name: "session.interrupt",
|
|
533
|
+
category: "Session",
|
|
534
|
+
palette: undefined,
|
|
535
|
+
enabled: status() === "running",
|
|
536
|
+
run: () => {
|
|
537
|
+
if (auto()?.visible) return
|
|
538
|
+
if (!input.focused) return
|
|
539
|
+
// TODO: this should be its own command
|
|
540
|
+
if (store.mode === "shell") {
|
|
541
|
+
setStore("mode", "normal")
|
|
542
|
+
return
|
|
543
|
+
}
|
|
544
|
+
if (!props.sessionID) return
|
|
545
|
+
|
|
546
|
+
setStore("interrupt", store.interrupt + 1)
|
|
547
|
+
|
|
548
|
+
setTimeout(() => {
|
|
549
|
+
setStore("interrupt", 0)
|
|
550
|
+
}, 5000)
|
|
551
|
+
|
|
552
|
+
if (store.interrupt >= 2) {
|
|
553
|
+
void interrupt(props.sessionID).catch((error) =>
|
|
554
|
+
toast.show({ message: errorMessage(error), variant: "error", duration: 5000 }),
|
|
555
|
+
)
|
|
556
|
+
setStore("interrupt", 0)
|
|
557
|
+
}
|
|
558
|
+
dialog.clear()
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
title: "Background blocking tools",
|
|
563
|
+
name: "session.background",
|
|
564
|
+
category: "Session",
|
|
565
|
+
palette: undefined,
|
|
566
|
+
enabled: status() === "running",
|
|
567
|
+
run: () => {
|
|
568
|
+
if (auto()?.visible) return
|
|
569
|
+
if (!input.focused) return
|
|
570
|
+
if (!props.sessionID) return
|
|
571
|
+
|
|
572
|
+
void client.api.session.background({
|
|
573
|
+
sessionID: props.sessionID,
|
|
574
|
+
})
|
|
575
|
+
dialog.clear()
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
{
|
|
579
|
+
title: "Open editor",
|
|
580
|
+
category: "Session",
|
|
581
|
+
name: "prompt.editor",
|
|
582
|
+
slash: { name: "editor" },
|
|
583
|
+
run: async () => {
|
|
584
|
+
dialog.clear()
|
|
585
|
+
|
|
586
|
+
const editorPrompt = expandPromptInputPastedText(store.prompt, store.prompt.pasted, renderer.widthMethod)
|
|
587
|
+
const value = editorPrompt.text
|
|
588
|
+
const content = await openEditor({
|
|
589
|
+
renderer,
|
|
590
|
+
value,
|
|
591
|
+
cwd:
|
|
592
|
+
(data.location.info()?.project.directory === "/" ? undefined : data.location.info()?.project.directory) ||
|
|
593
|
+
data.location.default().directory ||
|
|
594
|
+
paths.cwd,
|
|
595
|
+
}).catch((error) => {
|
|
596
|
+
toast.show({ title: "Failed to open editor", message: errorMessage(error), variant: "error" })
|
|
597
|
+
})
|
|
598
|
+
if (!content) return
|
|
599
|
+
const normalized = normalizePromptContent(content)
|
|
600
|
+
|
|
601
|
+
input.setText(normalized)
|
|
602
|
+
|
|
603
|
+
setStore("prompt", {
|
|
604
|
+
...realignPromptInputMentions(normalized, editorPrompt, renderer.widthMethod),
|
|
605
|
+
pasted: [],
|
|
606
|
+
})
|
|
607
|
+
restoreExtmarksFromPrompt(store.prompt)
|
|
608
|
+
input.cursorOffset = measure(normalized)
|
|
609
|
+
},
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
title: "Skills",
|
|
613
|
+
name: "prompt.skills",
|
|
614
|
+
category: "Prompt",
|
|
615
|
+
slash: { name: "skills" },
|
|
616
|
+
run: () => {
|
|
617
|
+
dialog.replace(() => (
|
|
618
|
+
<DialogSkill
|
|
619
|
+
location={currentLocation.ref}
|
|
620
|
+
onSelect={(skill) => {
|
|
621
|
+
if (store.prompt.skills?.some((item) => item.id === skill)) return
|
|
622
|
+
const text = `@${skill}`
|
|
623
|
+
const start = input.cursorOffset
|
|
624
|
+
const end = start + measure(text)
|
|
625
|
+
input.insertText(text + " ")
|
|
626
|
+
const part = { id: Skill.ID.make(skill), mention: { start, end, text } }
|
|
627
|
+
const extmarkId = input.extmarks.create({
|
|
628
|
+
start,
|
|
629
|
+
end,
|
|
630
|
+
virtual: true,
|
|
631
|
+
styleId: skillStyleId,
|
|
632
|
+
typeId: promptPartTypeId,
|
|
633
|
+
data: { skill: part } satisfies ChipData,
|
|
634
|
+
})
|
|
635
|
+
setStore(
|
|
636
|
+
produce((draft) => {
|
|
637
|
+
draft.prompt.text = input.plainText
|
|
638
|
+
const skills = (draft.prompt.skills ??= [])
|
|
639
|
+
const index = skills.length
|
|
640
|
+
skills.push(part)
|
|
641
|
+
draft.extmarkToPart.set(extmarkId, { type: "skill", index })
|
|
642
|
+
}),
|
|
643
|
+
)
|
|
644
|
+
}}
|
|
645
|
+
/>
|
|
646
|
+
))
|
|
647
|
+
},
|
|
648
|
+
},
|
|
649
|
+
{
|
|
650
|
+
title: "Manage workspaces",
|
|
651
|
+
desc: "Manage workspaces",
|
|
652
|
+
name: "session.move",
|
|
653
|
+
category: "Session",
|
|
654
|
+
slash: { name: "worktrees" },
|
|
655
|
+
run: () => {
|
|
656
|
+
move.open()
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
].map(
|
|
660
|
+
({ name, category, ...command }) =>
|
|
661
|
+
({
|
|
662
|
+
id: name,
|
|
663
|
+
group: category,
|
|
664
|
+
bind: false,
|
|
665
|
+
palette: true as const,
|
|
666
|
+
...command,
|
|
667
|
+
}) satisfies KeymapCommand,
|
|
668
|
+
),
|
|
669
|
+
)
|
|
670
|
+
|
|
671
|
+
Keymap.createLayer(() => ({
|
|
672
|
+
mode: "global",
|
|
673
|
+
enabled: !disabled(),
|
|
674
|
+
commands: promptCommands(),
|
|
675
|
+
}))
|
|
676
|
+
|
|
677
|
+
Keymap.createLayer(() => ({
|
|
678
|
+
priority: 1,
|
|
679
|
+
enabled: !disabled(),
|
|
680
|
+
bindings: ["prompt.queue"],
|
|
681
|
+
}))
|
|
682
|
+
|
|
683
|
+
Keymap.createLayer(() => ({
|
|
684
|
+
enabled: !disabled(),
|
|
685
|
+
bindings: [
|
|
686
|
+
"prompt.submit",
|
|
687
|
+
"prompt.editor",
|
|
688
|
+
"prompt.editor_context.clear",
|
|
689
|
+
"prompt.images.view",
|
|
690
|
+
"prompt.stash",
|
|
691
|
+
"prompt.stash.pop",
|
|
692
|
+
"prompt.stash.list",
|
|
693
|
+
"prompt.skills",
|
|
694
|
+
"session.interrupt",
|
|
695
|
+
"session.background",
|
|
696
|
+
"session.move",
|
|
697
|
+
],
|
|
698
|
+
}))
|
|
699
|
+
|
|
700
|
+
const ref: PromptRef = {
|
|
701
|
+
get focused() {
|
|
702
|
+
return !disabled() && input.focused
|
|
703
|
+
},
|
|
704
|
+
get current() {
|
|
705
|
+
return store.prompt
|
|
706
|
+
},
|
|
707
|
+
get mode() {
|
|
708
|
+
return store.mode
|
|
709
|
+
},
|
|
710
|
+
focus() {
|
|
711
|
+
if (disabled()) return
|
|
712
|
+
input.focus()
|
|
713
|
+
},
|
|
714
|
+
blur() {
|
|
715
|
+
input.blur()
|
|
716
|
+
},
|
|
717
|
+
setMode(mode) {
|
|
718
|
+
setStore("mode", mode)
|
|
719
|
+
},
|
|
720
|
+
set(prompt) {
|
|
721
|
+
history.reset()
|
|
722
|
+
input.setText(prompt.text)
|
|
723
|
+
setStore("prompt", prompt)
|
|
724
|
+
restoreExtmarksFromPrompt(prompt)
|
|
725
|
+
input.gotoBufferEnd()
|
|
726
|
+
},
|
|
727
|
+
reset() {
|
|
728
|
+
resetComposer()
|
|
729
|
+
},
|
|
730
|
+
submit() {
|
|
731
|
+
void submit()
|
|
732
|
+
},
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function resetComposer() {
|
|
736
|
+
history.reset()
|
|
737
|
+
input.extmarks.clear()
|
|
738
|
+
setStore("prompt", emptyPrompt())
|
|
739
|
+
setStore("extmarkToPart", new Map())
|
|
740
|
+
input.clear()
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// Captured once: the session route is keyed by sessionID, so this Prompt
|
|
744
|
+
// instance belongs to exactly one tab. Reading props.sessionID lazily would
|
|
745
|
+
// observe the *next* route during onCleanup and stash under the wrong tab.
|
|
746
|
+
const stashSessionID = props.sessionID
|
|
747
|
+
|
|
748
|
+
onMount(() => {
|
|
749
|
+
onCleanup(registerComposer(stashSessionID, ref))
|
|
750
|
+
const saved = takeDraft(stashSessionID)
|
|
751
|
+
if (store.prompt.text) return
|
|
752
|
+
if (saved && saved.prompt.text) {
|
|
753
|
+
input.setText(saved.prompt.text)
|
|
754
|
+
setStore("prompt", saved.prompt)
|
|
755
|
+
restoreExtmarksFromPrompt(saved.prompt)
|
|
756
|
+
input.cursorOffset = Math.min(saved.cursor, measure(saved.prompt.text))
|
|
757
|
+
}
|
|
758
|
+
})
|
|
759
|
+
|
|
760
|
+
onCleanup(() => {
|
|
761
|
+
disposed = true
|
|
762
|
+
if (store.prompt.text) {
|
|
763
|
+
saveDraft(stashSessionID, { prompt: unwrap(store.prompt), cursor: input.cursorOffset })
|
|
764
|
+
}
|
|
765
|
+
setInputTarget(undefined)
|
|
766
|
+
props.ref?.(undefined)
|
|
767
|
+
})
|
|
768
|
+
|
|
769
|
+
createEffect(() => {
|
|
770
|
+
if (!input || input.isDestroyed) return
|
|
771
|
+
if (props.visible === false || disabled() || dialog.stack.length > 0) {
|
|
772
|
+
if (input.focused) input.blur()
|
|
773
|
+
input.focusable = false
|
|
774
|
+
return
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
input.focusable = true
|
|
778
|
+
// Slot/plugin updates can remount the background prompt while a dialog is open.
|
|
779
|
+
// Keep focus with the dialog and let the prompt reclaim it after the dialog closes.
|
|
780
|
+
if (!input.focused) input.focus()
|
|
781
|
+
})
|
|
782
|
+
|
|
783
|
+
createEffect(() => {
|
|
784
|
+
if (!input || input.isDestroyed) return
|
|
785
|
+
input.traits = {
|
|
786
|
+
...input.traits,
|
|
787
|
+
...computePromptTraits({
|
|
788
|
+
mode: store.mode,
|
|
789
|
+
autocompleteVisible: !!auto()?.visible,
|
|
790
|
+
}),
|
|
791
|
+
}
|
|
792
|
+
})
|
|
793
|
+
|
|
794
|
+
function restoreExtmarksFromPrompt(prompt: PromptInfo) {
|
|
795
|
+
input.extmarks.clear()
|
|
796
|
+
setStore("extmarkToPart", new Map())
|
|
797
|
+
|
|
798
|
+
const parts = [
|
|
799
|
+
...(prompt.files ?? []).map((part, index) => ({
|
|
800
|
+
mention: part.mention,
|
|
801
|
+
ref: { type: "file" as const, index },
|
|
802
|
+
styleId: fileStyleId,
|
|
803
|
+
data: { file: unwrap(part) },
|
|
804
|
+
})),
|
|
805
|
+
...(prompt.agents ?? []).map((part, index) => ({
|
|
806
|
+
mention: part.mention,
|
|
807
|
+
ref: { type: "agent" as const, index },
|
|
808
|
+
styleId: agentStyleId,
|
|
809
|
+
data: { agent: unwrap(part) },
|
|
810
|
+
})),
|
|
811
|
+
...(prompt.skills ?? []).map((part, index) => ({
|
|
812
|
+
mention: part.mention,
|
|
813
|
+
ref: { type: "skill" as const, index },
|
|
814
|
+
styleId: skillStyleId,
|
|
815
|
+
data: { skill: unwrap(part) },
|
|
816
|
+
})),
|
|
817
|
+
...prompt.pasted.map((part, index) => ({
|
|
818
|
+
mention: part.source,
|
|
819
|
+
ref: { type: "pasted" as const, index },
|
|
820
|
+
styleId: pasteStyleId,
|
|
821
|
+
data: { pasted: part.text, label: part.source.text },
|
|
822
|
+
})),
|
|
823
|
+
]
|
|
824
|
+
|
|
825
|
+
parts.forEach(({ mention, ref, styleId, data }) => {
|
|
826
|
+
if (mention?.text) {
|
|
827
|
+
const extmarkId = input.extmarks.create({
|
|
828
|
+
start: mention.start,
|
|
829
|
+
end: mention.end,
|
|
830
|
+
virtual: true,
|
|
831
|
+
styleId,
|
|
832
|
+
typeId: promptPartTypeId,
|
|
833
|
+
data,
|
|
834
|
+
})
|
|
835
|
+
setStore("extmarkToPart", (map: Map<number, PromptPartRef>) => {
|
|
836
|
+
const newMap = new Map(map)
|
|
837
|
+
newMap.set(extmarkId, ref)
|
|
838
|
+
return newMap
|
|
839
|
+
})
|
|
840
|
+
}
|
|
841
|
+
})
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Undo restores a deleted chip's mark, with its data, after its part left the prompt.
|
|
845
|
+
function rebindChip(prompt: PromptInfo, data: ChipData | undefined): PromptPartRef | undefined {
|
|
846
|
+
const copy = <T extends { mention?: object }>(part: T) => ({
|
|
847
|
+
...part,
|
|
848
|
+
mention: part.mention && { ...part.mention },
|
|
849
|
+
})
|
|
850
|
+
// A second chip for an attached file moves the first part's mention instead of adding one.
|
|
851
|
+
if (data?.file && !prompt.files?.some((file) => file.uri === data.file?.uri))
|
|
852
|
+
return { type: "file", index: (prompt.files ??= []).push(copy(data.file)) - 1 }
|
|
853
|
+
if (data?.agent) return { type: "agent", index: (prompt.agents ??= []).push(copy(data.agent)) - 1 }
|
|
854
|
+
if (data?.skill) return { type: "skill", index: (prompt.skills ??= []).push(copy(data.skill)) - 1 }
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function syncExtmarksWithPromptParts() {
|
|
858
|
+
const allExtmarks = input.extmarks.getAllForTypeId(promptPartTypeId)
|
|
859
|
+
setStore(
|
|
860
|
+
produce((draft) => {
|
|
861
|
+
const newMap = new Map<number, PromptPartRef>()
|
|
862
|
+
const fileExtmarks = new Map<number, NonNullable<PromptInfo["files"]>[number]>()
|
|
863
|
+
const files: NonNullable<PromptInfo["files"]> = []
|
|
864
|
+
const agents: NonNullable<PromptInfo["agents"]> = []
|
|
865
|
+
const skills: NonNullable<PromptInfo["skills"]> = []
|
|
866
|
+
const pasted: PromptInfo["pasted"] = []
|
|
867
|
+
|
|
868
|
+
for (const extmark of allExtmarks) {
|
|
869
|
+
// Undo restores the extmark after its entry in the live prompt has been removed.
|
|
870
|
+
if (typeof extmark.data?.pasted === "string" && typeof extmark.data?.label === "string") {
|
|
871
|
+
if (input.getTextRange(extmark.start, extmark.end) !== extmark.data.label) {
|
|
872
|
+
input.extmarks.delete(extmark.id)
|
|
873
|
+
continue
|
|
874
|
+
}
|
|
875
|
+
newMap.set(extmark.id, { type: "pasted", index: pasted.length })
|
|
876
|
+
pasted.push({
|
|
877
|
+
text: extmark.data.pasted,
|
|
878
|
+
source: { start: extmark.start, end: extmark.end, text: extmark.data.label },
|
|
879
|
+
})
|
|
880
|
+
continue
|
|
881
|
+
}
|
|
882
|
+
const ref = draft.extmarkToPart.get(extmark.id) ?? rebindChip(draft.prompt, extmark.data)
|
|
883
|
+
if (!ref) continue
|
|
884
|
+
if (ref.type === "file") {
|
|
885
|
+
const part = draft.prompt.files?.[ref.index]
|
|
886
|
+
if (!part?.mention) continue
|
|
887
|
+
part.mention.start = extmark.start
|
|
888
|
+
part.mention.end = extmark.end
|
|
889
|
+
files.push(part)
|
|
890
|
+
fileExtmarks.set(extmark.id, part)
|
|
891
|
+
continue
|
|
892
|
+
}
|
|
893
|
+
if (ref.type === "agent") {
|
|
894
|
+
const part = draft.prompt.agents?.[ref.index]
|
|
895
|
+
if (!part?.mention) continue
|
|
896
|
+
part.mention.start = extmark.start
|
|
897
|
+
part.mention.end = extmark.end
|
|
898
|
+
const index = agents.length
|
|
899
|
+
agents.push(part)
|
|
900
|
+
newMap.set(extmark.id, { type: "agent", index })
|
|
901
|
+
continue
|
|
902
|
+
}
|
|
903
|
+
if (ref.type === "skill") {
|
|
904
|
+
const part = draft.prompt.skills?.[ref.index]
|
|
905
|
+
if (!part?.mention) continue
|
|
906
|
+
part.mention.start = extmark.start
|
|
907
|
+
part.mention.end = extmark.end
|
|
908
|
+
const index = skills.length
|
|
909
|
+
skills.push(part)
|
|
910
|
+
newMap.set(extmark.id, { type: "skill", index })
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
const nextFiles = preserveMentionlessPromptAttachments(draft.prompt.files, files)
|
|
915
|
+
const fileIndices = new Map(nextFiles.map((file, index) => [file, index]))
|
|
916
|
+
for (const [extmark, file] of fileExtmarks) {
|
|
917
|
+
const index = fileIndices.get(file)
|
|
918
|
+
if (index !== undefined) newMap.set(extmark, { type: "file", index })
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
// Each content change syncs; replace a list only when its parts changed, so typing notifies no reader.
|
|
922
|
+
const same = <T,>(next: T[], prev: T[] | undefined) =>
|
|
923
|
+
next.length === (prev?.length ?? 0) && next.every((part, index) => part === prev?.[index])
|
|
924
|
+
draft.extmarkToPart = newMap
|
|
925
|
+
if (!same(nextFiles, draft.prompt.files)) draft.prompt.files = nextFiles
|
|
926
|
+
if (!same(agents, draft.prompt.agents)) draft.prompt.agents = agents
|
|
927
|
+
if (!same(skills, draft.prompt.skills)) draft.prompt.skills = skills
|
|
928
|
+
if (!same(pasted, draft.prompt.pasted)) draft.prompt.pasted = pasted
|
|
929
|
+
}),
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const stashCommands = createMemo(() =>
|
|
934
|
+
[
|
|
935
|
+
{
|
|
936
|
+
title: "Stash prompt",
|
|
937
|
+
name: "prompt.stash",
|
|
938
|
+
category: "Prompt",
|
|
939
|
+
enabled: !!store.prompt.text,
|
|
940
|
+
run: () => {
|
|
941
|
+
if (!store.prompt.text) return
|
|
942
|
+
stash.push({ prompt: store.prompt })
|
|
943
|
+
resetComposer()
|
|
944
|
+
dialog.clear()
|
|
945
|
+
},
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
title: "Stash pop",
|
|
949
|
+
name: "prompt.stash.pop",
|
|
950
|
+
category: "Prompt",
|
|
951
|
+
enabled: stash.list().length > 0,
|
|
952
|
+
run: () => {
|
|
953
|
+
const entry = stash.pop()
|
|
954
|
+
if (entry) ref.set(entry.prompt)
|
|
955
|
+
dialog.clear()
|
|
956
|
+
},
|
|
957
|
+
},
|
|
958
|
+
{
|
|
959
|
+
title: "Stash list",
|
|
960
|
+
name: "prompt.stash.list",
|
|
961
|
+
category: "Prompt",
|
|
962
|
+
enabled: stash.list().length > 0,
|
|
963
|
+
run: () => {
|
|
964
|
+
dialog.replace(() => <DialogStash onSelect={(entry) => ref.set(entry.prompt)} />)
|
|
965
|
+
},
|
|
966
|
+
},
|
|
967
|
+
].map(
|
|
968
|
+
({ name, category, ...command }) =>
|
|
969
|
+
({
|
|
970
|
+
id: name,
|
|
971
|
+
group: category,
|
|
972
|
+
bind: false,
|
|
973
|
+
palette: true as const,
|
|
974
|
+
...command,
|
|
975
|
+
}) satisfies KeymapCommand,
|
|
976
|
+
),
|
|
977
|
+
)
|
|
978
|
+
|
|
979
|
+
Keymap.createLayer(() => ({
|
|
980
|
+
mode: "global",
|
|
981
|
+
enabled: !disabled(),
|
|
982
|
+
commands: stashCommands(),
|
|
983
|
+
}))
|
|
984
|
+
|
|
985
|
+
Keymap.createLayer(() => {
|
|
986
|
+
return {
|
|
987
|
+
target: inputTarget,
|
|
988
|
+
enabled: inputTarget() !== undefined && !disabled(),
|
|
989
|
+
bindings: ["prompt.paste"],
|
|
990
|
+
}
|
|
991
|
+
})
|
|
992
|
+
|
|
993
|
+
Keymap.createLayer(() => {
|
|
994
|
+
return {
|
|
995
|
+
target: inputTarget,
|
|
996
|
+
enabled: inputTarget() !== undefined && !disabled() && store.prompt.text !== "",
|
|
997
|
+
bindings: ["prompt.clear"],
|
|
998
|
+
}
|
|
999
|
+
})
|
|
1000
|
+
|
|
1001
|
+
Keymap.createLayer(() => {
|
|
1002
|
+
return {
|
|
1003
|
+
target: inputTarget,
|
|
1004
|
+
enabled: (() => {
|
|
1005
|
+
cursorVersion()
|
|
1006
|
+
return (
|
|
1007
|
+
inputTarget() !== undefined &&
|
|
1008
|
+
!disabled() &&
|
|
1009
|
+
store.mode === "normal" &&
|
|
1010
|
+
!auto()?.visible &&
|
|
1011
|
+
input?.visualCursor.offset === 0
|
|
1012
|
+
)
|
|
1013
|
+
})(),
|
|
1014
|
+
commands: [
|
|
1015
|
+
{
|
|
1016
|
+
bind: "!",
|
|
1017
|
+
title: "Shell mode",
|
|
1018
|
+
group: "Prompt",
|
|
1019
|
+
run: () => {
|
|
1020
|
+
setStore("placeholder", randomIndex(shell().length))
|
|
1021
|
+
setStore("mode", "shell")
|
|
1022
|
+
},
|
|
1023
|
+
},
|
|
1024
|
+
],
|
|
1025
|
+
}
|
|
1026
|
+
})
|
|
1027
|
+
|
|
1028
|
+
Keymap.createLayer(() => {
|
|
1029
|
+
return {
|
|
1030
|
+
priority: 1,
|
|
1031
|
+
target: inputTarget,
|
|
1032
|
+
enabled: inputTarget() !== undefined && !disabled() && store.mode === "shell",
|
|
1033
|
+
commands: [
|
|
1034
|
+
{ bind: "escape", title: "Exit shell mode", group: "Prompt", run: () => setStore("mode", "normal") },
|
|
1035
|
+
{
|
|
1036
|
+
bind: "ctrl+c",
|
|
1037
|
+
title: "Exit shell mode",
|
|
1038
|
+
group: "Prompt",
|
|
1039
|
+
enabled: () => store.prompt.text === "",
|
|
1040
|
+
run: () => setStore("mode", "normal"),
|
|
1041
|
+
},
|
|
1042
|
+
],
|
|
1043
|
+
}
|
|
1044
|
+
})
|
|
1045
|
+
|
|
1046
|
+
Keymap.createLayer(() => {
|
|
1047
|
+
return {
|
|
1048
|
+
target: inputTarget,
|
|
1049
|
+
enabled: (() => {
|
|
1050
|
+
cursorVersion()
|
|
1051
|
+
return inputTarget() !== undefined && !disabled() && store.mode === "shell" && input?.visualCursor.offset === 0
|
|
1052
|
+
})(),
|
|
1053
|
+
commands: [
|
|
1054
|
+
{ bind: "backspace", title: "Exit shell mode", group: "Prompt", run: () => setStore("mode", "normal") },
|
|
1055
|
+
],
|
|
1056
|
+
}
|
|
1057
|
+
})
|
|
1058
|
+
|
|
1059
|
+
Keymap.createLayer(() => {
|
|
1060
|
+
return {
|
|
1061
|
+
priority: 1,
|
|
1062
|
+
target: inputTarget,
|
|
1063
|
+
enabled: (() => {
|
|
1064
|
+
cursorVersion()
|
|
1065
|
+
return inputTarget() !== undefined && !disabled() && !auto()?.visible && input !== undefined
|
|
1066
|
+
})(),
|
|
1067
|
+
commands: [
|
|
1068
|
+
{
|
|
1069
|
+
id: "prompt.history.previous",
|
|
1070
|
+
title: "Previous prompt history",
|
|
1071
|
+
group: "Prompt",
|
|
1072
|
+
run() {
|
|
1073
|
+
if (input.cursorOffset !== 0) {
|
|
1074
|
+
if (input.scrollY + input.visualCursor.visualRow === 0) {
|
|
1075
|
+
input.cursorOffset = 0
|
|
1076
|
+
return
|
|
1077
|
+
}
|
|
1078
|
+
input.moveCursorUp()
|
|
1079
|
+
return
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
const item = history.move(-1, input.plainText)
|
|
1083
|
+
if (!item) return false
|
|
1084
|
+
input.setText(item.text)
|
|
1085
|
+
setStore("prompt", item)
|
|
1086
|
+
setStore("mode", item.mode ?? "normal")
|
|
1087
|
+
restoreExtmarksFromPrompt(item)
|
|
1088
|
+
input.cursorOffset = 0
|
|
1089
|
+
},
|
|
1090
|
+
},
|
|
1091
|
+
],
|
|
1092
|
+
}
|
|
1093
|
+
})
|
|
1094
|
+
|
|
1095
|
+
Keymap.createLayer(() => {
|
|
1096
|
+
return {
|
|
1097
|
+
priority: 1,
|
|
1098
|
+
target: inputTarget,
|
|
1099
|
+
enabled: (() => {
|
|
1100
|
+
cursorVersion()
|
|
1101
|
+
return inputTarget() !== undefined && !disabled() && !auto()?.visible && input !== undefined
|
|
1102
|
+
})(),
|
|
1103
|
+
commands: [
|
|
1104
|
+
{
|
|
1105
|
+
id: "prompt.history.next",
|
|
1106
|
+
title: "Next prompt history",
|
|
1107
|
+
group: "Prompt",
|
|
1108
|
+
run() {
|
|
1109
|
+
const end = measure(input.plainText)
|
|
1110
|
+
if (input.cursorOffset !== end) {
|
|
1111
|
+
if (
|
|
1112
|
+
input.scrollY + input.visualCursor.visualRow ===
|
|
1113
|
+
Math.max(0, input.editorView.getTotalVirtualLineCount() - 1)
|
|
1114
|
+
) {
|
|
1115
|
+
input.cursorOffset = end
|
|
1116
|
+
return
|
|
1117
|
+
}
|
|
1118
|
+
input.moveCursorDown()
|
|
1119
|
+
return
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
const item = history.move(1, input.plainText)
|
|
1123
|
+
if (!item) return false
|
|
1124
|
+
input.setText(item.text)
|
|
1125
|
+
setStore("prompt", item)
|
|
1126
|
+
setStore("mode", item.mode ?? "normal")
|
|
1127
|
+
restoreExtmarksFromPrompt(item)
|
|
1128
|
+
input.cursorOffset = measure(item.text)
|
|
1129
|
+
},
|
|
1130
|
+
},
|
|
1131
|
+
],
|
|
1132
|
+
}
|
|
1133
|
+
})
|
|
1134
|
+
|
|
1135
|
+
let submitting = false
|
|
1136
|
+
async function submit(delivery: SessionInbox.Delivery = "steer") {
|
|
1137
|
+
if (disabled()) return false
|
|
1138
|
+
// Prevent overlapping invocations (e.g. a double-pressed Enter, or the
|
|
1139
|
+
// input's native onSubmit racing another dispatch). Without this guard,
|
|
1140
|
+
// a second call slips past the empty-input check before the first call
|
|
1141
|
+
// clears `store.prompt.text`, then awaits its own `session.create` and
|
|
1142
|
+
// ultimately reads the now-empty store — sending a phantom empty prompt
|
|
1143
|
+
// to a freshly created session.
|
|
1144
|
+
if (submitting) return false
|
|
1145
|
+
submitting = true
|
|
1146
|
+
try {
|
|
1147
|
+
return await submitInner(delivery)
|
|
1148
|
+
} finally {
|
|
1149
|
+
submitting = false
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
async function submitInner(delivery: SessionInbox.Delivery) {
|
|
1154
|
+
// IME: double-defer may fire before onContentChange flushes the last
|
|
1155
|
+
// composed character (e.g. Korean hangul) to the store, so read
|
|
1156
|
+
// plainText directly and sync before any downstream reads.
|
|
1157
|
+
if (input && !input.isDestroyed && input.plainText !== store.prompt.text) {
|
|
1158
|
+
setStore("prompt", "text", input.plainText)
|
|
1159
|
+
syncExtmarksWithPromptParts()
|
|
1160
|
+
}
|
|
1161
|
+
if (move.creating()) return false
|
|
1162
|
+
if (auto()?.visible) return false
|
|
1163
|
+
const trimmed = store.prompt.text.trim()
|
|
1164
|
+
if (!trimmed && (!props.sessionID || store.mode === "shell" || delivery === "queue"))
|
|
1165
|
+
return delivery === "steer" ? (await props.onEmptySubmit?.()) === true : false
|
|
1166
|
+
const exitWord = trimmed === "exit" || trimmed === "quit" || trimmed === ":q"
|
|
1167
|
+
const inputText = expandTrackedPastedText(
|
|
1168
|
+
store.prompt.text,
|
|
1169
|
+
input.extmarks.getAllForTypeId(promptPartTypeId).flatMap((extmark) => {
|
|
1170
|
+
const ref = store.extmarkToPart.get(extmark.id)
|
|
1171
|
+
if (ref?.type !== "pasted") return []
|
|
1172
|
+
const part = store.prompt.pasted[ref.index]
|
|
1173
|
+
if (!part) return []
|
|
1174
|
+
return [{ start: extmark.start, end: extmark.end, text: part.text }]
|
|
1175
|
+
}),
|
|
1176
|
+
renderer.widthMethod,
|
|
1177
|
+
)
|
|
1178
|
+
const slash = argumentSlash(inputText, keymapCommands())
|
|
1179
|
+
if (delivery === "queue" && (store.mode === "shell" || exitWord || slash)) {
|
|
1180
|
+
toast.show({ message: "This prompt cannot be queued", variant: "warning" })
|
|
1181
|
+
return false
|
|
1182
|
+
}
|
|
1183
|
+
if (exitWord) {
|
|
1184
|
+
void exit()
|
|
1185
|
+
return true
|
|
1186
|
+
}
|
|
1187
|
+
if (slash) {
|
|
1188
|
+
clearPrompt()
|
|
1189
|
+
await slash.command.run(slash.input)
|
|
1190
|
+
return true
|
|
1191
|
+
}
|
|
1192
|
+
const slashHead = parseSlashHead(inputText, /\s/)
|
|
1193
|
+
const isCommand =
|
|
1194
|
+
slashHead !== undefined &&
|
|
1195
|
+
(data.location.command.list(currentLocation.ref) ?? []).some((command) => command.name === slashHead.name)
|
|
1196
|
+
const editorSelection = editorContext()
|
|
1197
|
+
const pendingEditorSelection = editorSelection && editor.labelState() === "pending" ? editorSelection : undefined
|
|
1198
|
+
if (delivery === "queue" && pendingEditorSelection) {
|
|
1199
|
+
toast.show({ message: "Editor context cannot be queued", variant: "warning" })
|
|
1200
|
+
return false
|
|
1201
|
+
}
|
|
1202
|
+
const agent = local.agent.current()
|
|
1203
|
+
if (!agent) return false
|
|
1204
|
+
const selection = local.model.selection()
|
|
1205
|
+
if (!selection) {
|
|
1206
|
+
void promptModelWarning()
|
|
1207
|
+
return false
|
|
1208
|
+
}
|
|
1209
|
+
const usesModel = !props.sessionID || store.mode !== "shell"
|
|
1210
|
+
if (usesModel && !local.model.available(selection)) {
|
|
1211
|
+
toast.show({
|
|
1212
|
+
title: "Model unavailable",
|
|
1213
|
+
message: `${selection.providerID}/${selection.modelID} is not available in this session's location`,
|
|
1214
|
+
variant: "warning",
|
|
1215
|
+
})
|
|
1216
|
+
return false
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
// Snapshot the composer and clear it synchronously, before the first await.
|
|
1220
|
+
// Everything below reads the snapshot: text typed while a request is in
|
|
1221
|
+
// flight lands in the already-empty composer and survives, and prompt
|
|
1222
|
+
// history records exactly what was submitted instead of the live store
|
|
1223
|
+
// (which may have absorbed mid-flight typing). Failure paths restore the
|
|
1224
|
+
// snapshot unless the user has started typing something new.
|
|
1225
|
+
const currentMode = store.mode
|
|
1226
|
+
const entry = { ...store.prompt, mode: currentMode }
|
|
1227
|
+
if (trimmed) {
|
|
1228
|
+
resetComposer()
|
|
1229
|
+
props.onSubmit?.()
|
|
1230
|
+
}
|
|
1231
|
+
const restoreEntry = () => {
|
|
1232
|
+
if (disposed || input.isDestroyed || input.plainText !== "") return
|
|
1233
|
+
input.setText(entry.text)
|
|
1234
|
+
setStore("prompt", entry)
|
|
1235
|
+
setStore("mode", entry.mode ?? "normal")
|
|
1236
|
+
restoreExtmarksFromPrompt(entry)
|
|
1237
|
+
input.cursorOffset = measure(entry.text)
|
|
1238
|
+
}
|
|
1239
|
+
const fail = (title: string, error: unknown) => {
|
|
1240
|
+
toast.show({ title, message: errorMessage(error), variant: "error" })
|
|
1241
|
+
restoreEntry()
|
|
1242
|
+
}
|
|
1243
|
+
const attempt = async (title: string, run: () => Promise<unknown>) => {
|
|
1244
|
+
return run().then(
|
|
1245
|
+
() => true,
|
|
1246
|
+
(error: unknown) => {
|
|
1247
|
+
fail(title, error)
|
|
1248
|
+
return false
|
|
1249
|
+
},
|
|
1250
|
+
)
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
const variant = selection.variant
|
|
1254
|
+
let sessionID = props.sessionID
|
|
1255
|
+
let session = sessionID ? data.session.get(sessionID) : undefined
|
|
1256
|
+
let finishMoveProgress = false
|
|
1257
|
+
// New-session sends wait for creation and environment setup.
|
|
1258
|
+
let newSession: { gate: Promise<unknown>; recover: (error: unknown) => void } | undefined
|
|
1259
|
+
if (sessionID == null) {
|
|
1260
|
+
const directory = await move.getDirectory()
|
|
1261
|
+
if (move.pending() && !directory) {
|
|
1262
|
+
restoreEntry()
|
|
1263
|
+
return false
|
|
1264
|
+
}
|
|
1265
|
+
finishMoveProgress = Boolean(move.progress())
|
|
1266
|
+
// The location context is where the next session is created: seeded by the home
|
|
1267
|
+
// route (launch cwd, inherited session location, or picked project) and updated
|
|
1268
|
+
// by /cd before a session exists.
|
|
1269
|
+
const location = currentLocation.ref ?? data.location.default()
|
|
1270
|
+
|
|
1271
|
+
// Optimistic create: the data layer mints the ID client-side and admits
|
|
1272
|
+
// a local session record synchronously, so the navigation below happens
|
|
1273
|
+
// immediately — enter feels sent even while the create round-trip is in
|
|
1274
|
+
// flight. Sends against the new session gate on the request.
|
|
1275
|
+
const newSessionID = args.takeNewSessionID()
|
|
1276
|
+
const created = data.session.create({
|
|
1277
|
+
id: newSessionID,
|
|
1278
|
+
location: directory ? { directory } : location,
|
|
1279
|
+
agent: agent.id,
|
|
1280
|
+
model: {
|
|
1281
|
+
providerID: selection.providerID,
|
|
1282
|
+
id: selection.modelID,
|
|
1283
|
+
variant,
|
|
1284
|
+
},
|
|
1285
|
+
})
|
|
1286
|
+
if (newSessionID !== undefined) created.request.catch(() => args.restoreNewSessionID(newSessionID))
|
|
1287
|
+
sessionID = created.id
|
|
1288
|
+
session = data.session.get(created.id)
|
|
1289
|
+
newSession = {
|
|
1290
|
+
gate: created.request.then(async (info) => {
|
|
1291
|
+
if (terminalEnvironment.variables !== undefined) {
|
|
1292
|
+
await client.api.session.environment({ sessionID: created.id, variables: terminalEnvironment.variables })
|
|
1293
|
+
}
|
|
1294
|
+
}),
|
|
1295
|
+
recover: (error) => {
|
|
1296
|
+
toast.show({
|
|
1297
|
+
title: data.session.get(created.id) ? "Failed to set up session" : "Creating a session failed",
|
|
1298
|
+
message: errorMessage(error),
|
|
1299
|
+
variant: "error",
|
|
1300
|
+
})
|
|
1301
|
+
const active =
|
|
1302
|
+
route.data.type === "session" && route.data.sessionID === created.id ? promptRef.current : undefined
|
|
1303
|
+
const current = active?.current
|
|
1304
|
+
const draft = current?.text
|
|
1305
|
+
? { prompt: { ...unwrap(current) }, cursor: Infinity }
|
|
1306
|
+
: (takeDraft(created.id) ?? { prompt: entry, cursor: Infinity })
|
|
1307
|
+
saveDraft(undefined, draft)
|
|
1308
|
+
active?.reset()
|
|
1309
|
+
if (sessionTabs.enabled()) {
|
|
1310
|
+
sessionTabs.close(created.id)
|
|
1311
|
+
} else if (route.data.type === "session" && route.data.sessionID === created.id) {
|
|
1312
|
+
route.navigate({ type: "home" })
|
|
1313
|
+
}
|
|
1314
|
+
},
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
const target = sessionID
|
|
1319
|
+
const prepareAgent = async () => {
|
|
1320
|
+
if (!session) {
|
|
1321
|
+
await data.session.sync(target)
|
|
1322
|
+
session = data.session.get(target)
|
|
1323
|
+
}
|
|
1324
|
+
if (session?.agent !== agent.id) {
|
|
1325
|
+
await client.api.session.switchAgent({ sessionID: target, agent: agent.id })
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
const commitModel = () => {
|
|
1329
|
+
const model = { providerID: selection.providerID, id: selection.modelID, variant }
|
|
1330
|
+
const cancelCommit = local.model.trackSessionCommit(target, model, agent.id)
|
|
1331
|
+
return client.api.session.switchModel({ sessionID: target, model }).catch((error) => {
|
|
1332
|
+
cancelCommit()
|
|
1333
|
+
throw new Error(`Failed to switch model: ${errorMessage(error)}`, { cause: error })
|
|
1334
|
+
})
|
|
1335
|
+
}
|
|
1336
|
+
const commitSelection = async () => {
|
|
1337
|
+
await prepareAgent()
|
|
1338
|
+
await commitModel()
|
|
1339
|
+
}
|
|
1340
|
+
if (!trimmed) {
|
|
1341
|
+
// Blank Enter in an existing session commits the composer's agent and
|
|
1342
|
+
// model selection, then hands off to the route (queued prompt promotion).
|
|
1343
|
+
await attempt("Failed to prepare session", async () => {
|
|
1344
|
+
await commitSelection()
|
|
1345
|
+
await props.onEmptySubmit?.()
|
|
1346
|
+
})
|
|
1347
|
+
return true
|
|
1348
|
+
}
|
|
1349
|
+
history.append(entry)
|
|
1350
|
+
if (currentMode === "shell") {
|
|
1351
|
+
move.startSubmit()
|
|
1352
|
+
const send = () => client.api.session.shell({ sessionID: target, command: inputText })
|
|
1353
|
+
void (newSession ? newSession.gate.then(send) : send()).catch((error) =>
|
|
1354
|
+
newSession ? newSession.recover(error) : fail("Failed to run shell command", error),
|
|
1355
|
+
)
|
|
1356
|
+
setStore("mode", "normal")
|
|
1357
|
+
} else if (slashHead && isCommand) {
|
|
1358
|
+
const send = async () => {
|
|
1359
|
+
// Commands inherit the composer selection; command-specific overrides
|
|
1360
|
+
// remain server-owned and run after this preparation.
|
|
1361
|
+
await commitSelection()
|
|
1362
|
+
return client.api.session.command({
|
|
1363
|
+
sessionID: target,
|
|
1364
|
+
name: slashHead.name,
|
|
1365
|
+
text: slashHead.arguments,
|
|
1366
|
+
files: promptFilesForServer(entry.files, terminalEnvironment.localServer === true),
|
|
1367
|
+
agents: entry.agents,
|
|
1368
|
+
skills: entry.skills?.length ? entry.skills : undefined,
|
|
1369
|
+
delivery,
|
|
1370
|
+
})
|
|
1371
|
+
}
|
|
1372
|
+
void (newSession ? newSession.gate.then(send) : send()).catch((error) =>
|
|
1373
|
+
newSession ? newSession.recover(error) : fail("Failed to run command", error),
|
|
1374
|
+
)
|
|
1375
|
+
} else {
|
|
1376
|
+
move.startSubmit()
|
|
1377
|
+
if (!(await attempt("Failed to prepare session", prepareAgent))) return true
|
|
1378
|
+
// Revert must settle before optimistic admission: its committed echo
|
|
1379
|
+
// splices every local row at or after the boundary, which would include
|
|
1380
|
+
// a freshly admitted prompt.
|
|
1381
|
+
if (
|
|
1382
|
+
session?.revert &&
|
|
1383
|
+
!(await attempt("Failed to commit revert", () => client.api.session.revert.commit({ sessionID: target })))
|
|
1384
|
+
)
|
|
1385
|
+
return false
|
|
1386
|
+
if (pendingEditorSelection) {
|
|
1387
|
+
// Keep editor context hidden while admitting it before the corresponding user prompt.
|
|
1388
|
+
const send = () =>
|
|
1389
|
+
client.api.session.synthetic({
|
|
1390
|
+
sessionID: target,
|
|
1391
|
+
text: formatEditorContext(pendingEditorSelection),
|
|
1392
|
+
resume: false,
|
|
1393
|
+
})
|
|
1394
|
+
// Fold into the setup gate so the context still admits before the
|
|
1395
|
+
// user prompt once the session exists.
|
|
1396
|
+
if (newSession) newSession.gate = newSession.gate.then(send)
|
|
1397
|
+
else if (!(await attempt("Failed to send editor context", send))) return false
|
|
1398
|
+
}
|
|
1399
|
+
// The data layer admits optimistically: the prompt renders immediately
|
|
1400
|
+
// and rolls back if the server rejects it, so submission does not wait
|
|
1401
|
+
// on the network. On rejection the row is already rolled back; restore
|
|
1402
|
+
// the composer unless the user has started typing something new.
|
|
1403
|
+
data.session
|
|
1404
|
+
.prompt({
|
|
1405
|
+
sessionID: target,
|
|
1406
|
+
text: inputText,
|
|
1407
|
+
files: promptFilesForServer(entry.files, terminalEnvironment.localServer === true),
|
|
1408
|
+
agents: entry.agents,
|
|
1409
|
+
skills: entry.skills?.length ? entry.skills : undefined,
|
|
1410
|
+
delivery,
|
|
1411
|
+
gate: newSession?.gate,
|
|
1412
|
+
// Commit the captured selection after earlier admissions, including
|
|
1413
|
+
// compaction setup. Cached state may still precede their SSE echoes;
|
|
1414
|
+
// the server makes an unchanged selection a no-op.
|
|
1415
|
+
prepare: commitModel,
|
|
1416
|
+
})
|
|
1417
|
+
.catch((error) => (newSession ? newSession.recover(error) : fail("Failed to send prompt", error)))
|
|
1418
|
+
if (pendingEditorSelection) editor.markSelectionSent()
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
// Optimistic admission puts the message in the store synchronously, so
|
|
1422
|
+
// the session view renders it on arrival.
|
|
1423
|
+
if (!props.sessionID) {
|
|
1424
|
+
if (pendingEditorSelection) editor.preserveSelectionFromNewSession()
|
|
1425
|
+
// Text typed while session creation was in flight lives in this (home)
|
|
1426
|
+
// prompt, which unmounts on navigation and would stash it under the
|
|
1427
|
+
// home key. Re-stash it under the new session so that composer restores
|
|
1428
|
+
// it, and clear it here so onCleanup does not also stash it for home.
|
|
1429
|
+
if (!disposed && !input.isDestroyed && store.prompt.text) {
|
|
1430
|
+
// Copy before clearing: unwrap returns the live store target, and the
|
|
1431
|
+
// resetComposer store write merges into that same object.
|
|
1432
|
+
saveDraft(sessionID, { prompt: { ...unwrap(store.prompt) }, cursor: input.cursorOffset })
|
|
1433
|
+
resetComposer()
|
|
1434
|
+
}
|
|
1435
|
+
route.navigate({
|
|
1436
|
+
type: "session",
|
|
1437
|
+
sessionID,
|
|
1438
|
+
})
|
|
1439
|
+
}
|
|
1440
|
+
if (finishMoveProgress) move.finishSubmit()
|
|
1441
|
+
return true
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function pasteText(text: string, virtualText: string) {
|
|
1445
|
+
const currentOffset = input.cursorOffset
|
|
1446
|
+
const extmarkStart = currentOffset
|
|
1447
|
+
const extmarkEnd = extmarkStart + measure(virtualText)
|
|
1448
|
+
|
|
1449
|
+
input.insertText(virtualText + " ")
|
|
1450
|
+
|
|
1451
|
+
const extmarkId = input.extmarks.create({
|
|
1452
|
+
start: extmarkStart,
|
|
1453
|
+
end: extmarkEnd,
|
|
1454
|
+
virtual: true,
|
|
1455
|
+
styleId: pasteStyleId,
|
|
1456
|
+
typeId: promptPartTypeId,
|
|
1457
|
+
data: { pasted: text, label: virtualText },
|
|
1458
|
+
})
|
|
1459
|
+
|
|
1460
|
+
setStore(
|
|
1461
|
+
produce((draft) => {
|
|
1462
|
+
const index = draft.prompt.pasted.length
|
|
1463
|
+
draft.prompt.pasted.push({
|
|
1464
|
+
text,
|
|
1465
|
+
source: { start: extmarkStart, end: extmarkEnd, text: virtualText },
|
|
1466
|
+
})
|
|
1467
|
+
draft.extmarkToPart.set(extmarkId, { type: "pasted", index })
|
|
1468
|
+
}),
|
|
1469
|
+
)
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
function expandPastedText(extmarkId: number) {
|
|
1473
|
+
const extmark = input.extmarks.get(extmarkId)
|
|
1474
|
+
const ref = store.extmarkToPart.get(extmarkId)
|
|
1475
|
+
if (!extmark || ref?.type !== "pasted") return false
|
|
1476
|
+
const part = store.prompt.pasted[ref.index]
|
|
1477
|
+
if (!part) return false
|
|
1478
|
+
|
|
1479
|
+
input.setSelection(extmark.start, extmark.end)
|
|
1480
|
+
input.insertText(part.text)
|
|
1481
|
+
return true
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
async function pasteInputText(text: string, changed: () => boolean) {
|
|
1485
|
+
const normalizedText = stripAnsiSequences(text).replace(/\r\n?/g, "\n")
|
|
1486
|
+
const pastedContent = normalizedText.trim()
|
|
1487
|
+
const attachments = await resolvePastedAttachments(pastedContent, terminalEnvironment.platform)
|
|
1488
|
+
if (changed()) return
|
|
1489
|
+
if (attachments) {
|
|
1490
|
+
attachments.forEach((attachment) => {
|
|
1491
|
+
if (attachment.type === "text") {
|
|
1492
|
+
pasteText(attachment.content, `[SVG: ${attachment.filename || "image"}]`)
|
|
1493
|
+
return
|
|
1494
|
+
}
|
|
1495
|
+
pasteAttachment(attachment)
|
|
1496
|
+
})
|
|
1497
|
+
return
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const lineCount = (pastedContent.match(/\n/g)?.length ?? 0) + 1
|
|
1501
|
+
if ((lineCount >= 3 || pastedContent.length > 150) && config.prompt?.paste !== "full") {
|
|
1502
|
+
const extmark = input.extmarks.getAllForTypeId(promptPartTypeId).find((extmark) => {
|
|
1503
|
+
const ref = store.extmarkToPart.get(extmark.id)
|
|
1504
|
+
return (
|
|
1505
|
+
(extmark.end === input.cursorOffset || extmark.end + 1 === input.cursorOffset) &&
|
|
1506
|
+
ref?.type === "pasted" &&
|
|
1507
|
+
store.prompt.pasted[ref.index]?.text === pastedContent
|
|
1508
|
+
)
|
|
1509
|
+
})
|
|
1510
|
+
if (extmark && expandPastedText(extmark.id)) return
|
|
1511
|
+
pasteText(pastedContent, `[Pasted ~${lineCount} lines]`)
|
|
1512
|
+
return
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
|
+
input.insertText(normalizedText)
|
|
1516
|
+
}
|
|
1517
|
+
|
|
1518
|
+
function pasteAttachment(file: { filename?: string; uri: string; path?: string }) {
|
|
1519
|
+
const currentOffset = input.cursorOffset
|
|
1520
|
+
const extmarkStart = currentOffset
|
|
1521
|
+
const virtualText = promptAttachmentLabel(store.prompt.files, { uri: file.uri, name: file.filename })
|
|
1522
|
+
const extmarkEnd = extmarkStart + measure(virtualText)
|
|
1523
|
+
const textToInsert = virtualText + " "
|
|
1524
|
+
|
|
1525
|
+
input.insertText(textToInsert)
|
|
1526
|
+
|
|
1527
|
+
const part: NonNullable<PromptInfo["files"]>[number] = {
|
|
1528
|
+
uri: file.uri,
|
|
1529
|
+
name: file.filename,
|
|
1530
|
+
path: file.path,
|
|
1531
|
+
mention: {
|
|
1532
|
+
start: extmarkStart,
|
|
1533
|
+
end: extmarkEnd,
|
|
1534
|
+
text: virtualText,
|
|
1535
|
+
},
|
|
1536
|
+
}
|
|
1537
|
+
const extmarkId = input.extmarks.create({
|
|
1538
|
+
start: extmarkStart,
|
|
1539
|
+
end: extmarkEnd,
|
|
1540
|
+
virtual: true,
|
|
1541
|
+
styleId: pasteStyleId,
|
|
1542
|
+
typeId: promptPartTypeId,
|
|
1543
|
+
data: { file: part } satisfies ChipData,
|
|
1544
|
+
})
|
|
1545
|
+
|
|
1546
|
+
setStore(
|
|
1547
|
+
produce((draft) => {
|
|
1548
|
+
const files = (draft.prompt.files ??= [])
|
|
1549
|
+
const index = files.length
|
|
1550
|
+
files.push(part)
|
|
1551
|
+
draft.extmarkToPart.set(extmarkId, { type: "file", index })
|
|
1552
|
+
}),
|
|
1553
|
+
)
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
function clearPrompt() {
|
|
1557
|
+
if (
|
|
1558
|
+
store.prompt.text.trim().length >= DRAFT_RETENTION_MIN_CHARS ||
|
|
1559
|
+
store.prompt.pasted.length > 0 ||
|
|
1560
|
+
(store.prompt.files?.length ?? 0) > 0 ||
|
|
1561
|
+
(store.prompt.agents?.length ?? 0) > 0
|
|
1562
|
+
) {
|
|
1563
|
+
history.append({
|
|
1564
|
+
...store.prompt,
|
|
1565
|
+
mode: store.mode,
|
|
1566
|
+
})
|
|
1567
|
+
}
|
|
1568
|
+
resetComposer()
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
// Keep the last resolved prompt display visible while destination catalogs load;
|
|
1572
|
+
// availability and submission still use the live location-scoped catalog.
|
|
1573
|
+
const promptDisplay = createMemo<{
|
|
1574
|
+
agentLabel: string | undefined
|
|
1575
|
+
agentColor: RGBA | undefined
|
|
1576
|
+
modelLabel: string
|
|
1577
|
+
providerLabel: string
|
|
1578
|
+
variant: string | undefined
|
|
1579
|
+
speed: string | undefined
|
|
1580
|
+
}>(
|
|
1581
|
+
(previous) => {
|
|
1582
|
+
const location = currentLocation.ref ?? data.location.default()
|
|
1583
|
+
const sessionLocation = props.sessionID ? data.session.get(props.sessionID)?.location : location
|
|
1584
|
+
if (!sessionLocation || locationKey(sessionLocation) !== locationKey(location)) return previous
|
|
1585
|
+
|
|
1586
|
+
const loading = data.location.agent.list(location) === undefined || !local.model.catalogReady
|
|
1587
|
+
const error = currentLocation.error
|
|
1588
|
+
const failed = error && locationKey(error.location) === locationKey(location)
|
|
1589
|
+
if (loading && !failed) return previous
|
|
1590
|
+
|
|
1591
|
+
const agent = local.agent.current()
|
|
1592
|
+
const model = local.model.parsed()
|
|
1593
|
+
return {
|
|
1594
|
+
agentLabel: agent ? Locale.titlecase(agent.id) : undefined,
|
|
1595
|
+
agentColor: agent ? local.agent.color(agent.id) : undefined,
|
|
1596
|
+
modelLabel: model.model,
|
|
1597
|
+
providerLabel: model.provider,
|
|
1598
|
+
variant: local.model.variant.current(),
|
|
1599
|
+
speed: local.model.speed.current(),
|
|
1600
|
+
}
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
agentLabel: undefined,
|
|
1604
|
+
agentColor: undefined,
|
|
1605
|
+
modelLabel: local.model.parsed().model,
|
|
1606
|
+
providerLabel: local.model.parsed().provider,
|
|
1607
|
+
variant: undefined,
|
|
1608
|
+
speed: undefined,
|
|
1609
|
+
},
|
|
1610
|
+
)
|
|
1611
|
+
// What the workspace's limits leave for the selected model, once it is running low. Only OpenCode Console limits
|
|
1612
|
+
// models, so only a model it serves loads them.
|
|
1613
|
+
const limits = useUsageLimits()
|
|
1614
|
+
createEffect(() => {
|
|
1615
|
+
const selected = local.model.current()
|
|
1616
|
+
if (selected && limits.served(selected.providerID) && limits.info() === undefined) limits.load()
|
|
1617
|
+
})
|
|
1618
|
+
const limit = createMemo(() => {
|
|
1619
|
+
const selected = local.model.current()
|
|
1620
|
+
const model = limits
|
|
1621
|
+
.models()
|
|
1622
|
+
.find((item) => item.providerID === selected?.providerID && item.id === selected?.modelID)
|
|
1623
|
+
return model ? limitLabel(limits.usage(model), model) : undefined
|
|
1624
|
+
})
|
|
1625
|
+
const highlight = createMemo(() => {
|
|
1626
|
+
if (muted()) return theme.border.base
|
|
1627
|
+
if (store.mode === "shell")
|
|
1628
|
+
// The new designs' interactive color matches the first agent's, so shell takes the second categorical color.
|
|
1629
|
+
return newDesigns() ? (theme.categorical[1] ?? theme.categorical[0])[400] : theme.text.action.primary.selected
|
|
1630
|
+
return promptDisplay().agentColor ?? theme.border.base
|
|
1631
|
+
})
|
|
1632
|
+
const agentLabel = createMemo(() => (store.mode === "shell" ? "Shell" : promptDisplay().agentLabel))
|
|
1633
|
+
const animateMetadata = !revealedPromptMetadata.has(local)
|
|
1634
|
+
const metadataAnimationsEnabled = () => animationsEnabled() && animateMetadata
|
|
1635
|
+
const agentMetaAlpha = createFadeIn(() => !!agentLabel(), metadataAnimationsEnabled)
|
|
1636
|
+
const modelMetaAlpha = createFadeIn(
|
|
1637
|
+
() => !!promptDisplay().agentLabel && store.mode === "normal",
|
|
1638
|
+
metadataAnimationsEnabled,
|
|
1639
|
+
)
|
|
1640
|
+
const variantMetaAlpha = createFadeIn(
|
|
1641
|
+
() => !!promptDisplay().agentLabel && store.mode === "normal" && !!promptDisplay().variant,
|
|
1642
|
+
metadataAnimationsEnabled,
|
|
1643
|
+
)
|
|
1644
|
+
createEffect(() => {
|
|
1645
|
+
if (agentLabel()) revealedPromptMetadata.add(local)
|
|
1646
|
+
})
|
|
1647
|
+
const borderHighlight = createMemo(() => tint(theme.border.base, highlight(), agentMetaAlpha()))
|
|
1648
|
+
const footerInput = () => ({
|
|
1649
|
+
sessionID: props.sessionID,
|
|
1650
|
+
mode: store.mode,
|
|
1651
|
+
showDetails: store.interrupt === 0 || dimensions().width >= 80,
|
|
1652
|
+
})
|
|
1653
|
+
|
|
1654
|
+
const placeholderText = createMemo(() => {
|
|
1655
|
+
const value = (() => {
|
|
1656
|
+
if (store.mode === "shell") {
|
|
1657
|
+
if (!shell().length) return undefined
|
|
1658
|
+
return `Run a command… "${shell()[store.placeholder % shell().length]}"`
|
|
1659
|
+
}
|
|
1660
|
+
if (!list().length) return undefined
|
|
1661
|
+
return `Ask anything… "${list()[store.placeholder % list().length]}"`
|
|
1662
|
+
})()
|
|
1663
|
+
if (!value) return undefined
|
|
1664
|
+
const width = dimensions().width < 44 ? dimensions().width - 5 : Math.min(75, dimensions().width - 4) - 5
|
|
1665
|
+
return Locale.takeWidth(value, Math.max(1, width)).trimEnd()
|
|
1666
|
+
})
|
|
1667
|
+
const footerLocation = createMemo(() => {
|
|
1668
|
+
if (!props.sessionID) {
|
|
1669
|
+
// No session yet: show where the next session will be created.
|
|
1670
|
+
return currentLocation.ref ?? data.location.default()
|
|
1671
|
+
}
|
|
1672
|
+
if (status() !== "idle") return
|
|
1673
|
+
return data.session.get(props.sessionID)?.location
|
|
1674
|
+
})
|
|
1675
|
+
const locationLabel = createMemo(() => {
|
|
1676
|
+
const pending = pendingDirectory()
|
|
1677
|
+
const location = pending ? { directory: pending } : footerLocation()
|
|
1678
|
+
if (!location) return
|
|
1679
|
+
const directory = abbreviateHome(location.directory, paths.home)
|
|
1680
|
+
const branch = data.location.vcs.info(location)?.branch.current
|
|
1681
|
+
return branch ? `${directory}:${branch}` : directory
|
|
1682
|
+
})
|
|
1683
|
+
const [locationWidth, setLocationWidth] = createSignal(dimensions().width)
|
|
1684
|
+
const locationLabelDisplay = createMemo(() => {
|
|
1685
|
+
const label = locationLabel()
|
|
1686
|
+
if (!label) return
|
|
1687
|
+
return truncateFilePath(label, locationWidth())
|
|
1688
|
+
})
|
|
1689
|
+
const locationActions = useWorkingDirectoryActions({
|
|
1690
|
+
directory: () => footerLocation()?.directory,
|
|
1691
|
+
onMove: () => void move.open(),
|
|
1692
|
+
})
|
|
1693
|
+
|
|
1694
|
+
const spinnerDef = createMemo(() => {
|
|
1695
|
+
const color = promptDisplay().agentColor ?? theme.border.base
|
|
1696
|
+
return {
|
|
1697
|
+
frames: createFrames({
|
|
1698
|
+
color,
|
|
1699
|
+
style: "blocks",
|
|
1700
|
+
inactiveFactor: 0.6,
|
|
1701
|
+
// enableFading: false,
|
|
1702
|
+
minAlpha: 0.3,
|
|
1703
|
+
}),
|
|
1704
|
+
color: createColors({
|
|
1705
|
+
color,
|
|
1706
|
+
style: "blocks",
|
|
1707
|
+
inactiveFactor: 0.6,
|
|
1708
|
+
// enableFading: false,
|
|
1709
|
+
minAlpha: 0.3,
|
|
1710
|
+
}),
|
|
1711
|
+
}
|
|
1712
|
+
})
|
|
1713
|
+
const maxHeight = createMemo(() => Math.max(6, Math.floor(dimensions().height / 3)))
|
|
1714
|
+
|
|
1715
|
+
const promptBg = createMemo(() => theme.decrease(theme.background.raised.base))
|
|
1716
|
+
|
|
1717
|
+
return (
|
|
1718
|
+
<>
|
|
1719
|
+
<box ref={(r: BoxRenderable) => (anchor = r)} visible={props.visible !== false} width="100%">
|
|
1720
|
+
<box
|
|
1721
|
+
width="100%"
|
|
1722
|
+
border={["left"]}
|
|
1723
|
+
borderColor={borderHighlight()}
|
|
1724
|
+
customBorderChars={{
|
|
1725
|
+
...SplitBorder.customBorderChars,
|
|
1726
|
+
bottomLeft: "╹",
|
|
1727
|
+
}}
|
|
1728
|
+
>
|
|
1729
|
+
<box
|
|
1730
|
+
paddingLeft={dimensions().width < 44 ? 1 : 2}
|
|
1731
|
+
paddingRight={dimensions().width < 44 ? 1 : 2}
|
|
1732
|
+
paddingTop={1}
|
|
1733
|
+
flexShrink={0}
|
|
1734
|
+
backgroundColor={promptBg()}
|
|
1735
|
+
flexGrow={1}
|
|
1736
|
+
width="100%"
|
|
1737
|
+
>
|
|
1738
|
+
<Show when={config.prompt?.image_preview && visibleImageAttachments().length > 0}>
|
|
1739
|
+
<box
|
|
1740
|
+
width="100%"
|
|
1741
|
+
height={imagePreviewHeight() + 1}
|
|
1742
|
+
flexDirection="row"
|
|
1743
|
+
flexShrink={0}
|
|
1744
|
+
justifyContent="flex-start"
|
|
1745
|
+
gap={1}
|
|
1746
|
+
paddingBottom={1}
|
|
1747
|
+
>
|
|
1748
|
+
<For each={visibleImageAttachments()}>
|
|
1749
|
+
{(file, index) => {
|
|
1750
|
+
const [failed, setFailed] = createSignal(false)
|
|
1751
|
+
return (
|
|
1752
|
+
<box
|
|
1753
|
+
width={imagePreviewWidth()}
|
|
1754
|
+
height={imagePreviewHeight()}
|
|
1755
|
+
flexBasis={imagePreviewWidth()}
|
|
1756
|
+
flexShrink={1}
|
|
1757
|
+
onMouseUp={(event: MouseEvent) => {
|
|
1758
|
+
if (event.button !== 0) return
|
|
1759
|
+
event.stopPropagation()
|
|
1760
|
+
openImagePreview(index())
|
|
1761
|
+
}}
|
|
1762
|
+
>
|
|
1763
|
+
<Show
|
|
1764
|
+
when={!failed()}
|
|
1765
|
+
fallback={
|
|
1766
|
+
<box width="100%" height="100%" alignItems="center" justifyContent="center">
|
|
1767
|
+
<text fg={theme.text.muted}>No preview</text>
|
|
1768
|
+
</box>
|
|
1769
|
+
}
|
|
1770
|
+
>
|
|
1771
|
+
<image
|
|
1772
|
+
id={`prompt-image-preview-${index()}`}
|
|
1773
|
+
source={file.uri}
|
|
1774
|
+
fit="cover"
|
|
1775
|
+
protocol="auto"
|
|
1776
|
+
width="100%"
|
|
1777
|
+
height="100%"
|
|
1778
|
+
onError={() => setFailed(true)}
|
|
1779
|
+
/>
|
|
1780
|
+
</Show>
|
|
1781
|
+
</box>
|
|
1782
|
+
)
|
|
1783
|
+
}}
|
|
1784
|
+
</For>
|
|
1785
|
+
<Show when={imageAttachments().length > visibleImageAttachments().length}>
|
|
1786
|
+
<box
|
|
1787
|
+
width={8}
|
|
1788
|
+
height={imagePreviewHeight()}
|
|
1789
|
+
flexBasis={8}
|
|
1790
|
+
flexShrink={1}
|
|
1791
|
+
alignItems="center"
|
|
1792
|
+
justifyContent="center"
|
|
1793
|
+
onMouseUp={(event: MouseEvent) => {
|
|
1794
|
+
if (event.button !== 0) return
|
|
1795
|
+
event.stopPropagation()
|
|
1796
|
+
openImagePreview(visibleImageAttachments().length)
|
|
1797
|
+
}}
|
|
1798
|
+
>
|
|
1799
|
+
<text fg={theme.text.muted} wrapMode="none" truncate>
|
|
1800
|
+
+{imageAttachments().length - visibleImageAttachments().length} more
|
|
1801
|
+
</text>
|
|
1802
|
+
</box>
|
|
1803
|
+
</Show>
|
|
1804
|
+
</box>
|
|
1805
|
+
</Show>
|
|
1806
|
+
<textarea
|
|
1807
|
+
width="100%"
|
|
1808
|
+
placeholder={placeholderText()}
|
|
1809
|
+
placeholderColor={theme.text.muted}
|
|
1810
|
+
textColor={muted() ? theme.text.muted : theme.text.base}
|
|
1811
|
+
focusedTextColor={muted() ? theme.text.muted : theme.text.base}
|
|
1812
|
+
minHeight={1}
|
|
1813
|
+
maxHeight={maxHeight()}
|
|
1814
|
+
cursorStyle={cursorStyle()}
|
|
1815
|
+
onContentChange={() => {
|
|
1816
|
+
const value = input.plainText
|
|
1817
|
+
setStore("prompt", "text", value)
|
|
1818
|
+
auto()?.onInput(value)
|
|
1819
|
+
syncExtmarksWithPromptParts()
|
|
1820
|
+
setCursorVersion((value) => value + 1)
|
|
1821
|
+
}}
|
|
1822
|
+
onCursorChange={() => setCursorVersion((value) => value + 1)}
|
|
1823
|
+
onKeyDown={(e: { preventDefault(): void }) => {
|
|
1824
|
+
if (disabled()) {
|
|
1825
|
+
e.preventDefault()
|
|
1826
|
+
return
|
|
1827
|
+
}
|
|
1828
|
+
}}
|
|
1829
|
+
onSubmit={() => {
|
|
1830
|
+
if (disabled()) return
|
|
1831
|
+
// IME: double-defer so the last composed character (e.g. Korean
|
|
1832
|
+
// hangul) is flushed to plainText before we read it for submission.
|
|
1833
|
+
setTimeout(() => setTimeout(() => submit(), 0), 0)
|
|
1834
|
+
}}
|
|
1835
|
+
onPaste={(event: PasteEvent) => {
|
|
1836
|
+
if (disabled()) {
|
|
1837
|
+
event.preventDefault()
|
|
1838
|
+
return
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
// Normalize line endings at the boundary
|
|
1842
|
+
// Windows ConPTY/Terminal often sends CR-only newlines in bracketed paste
|
|
1843
|
+
// Replace CRLF first, then any remaining CR
|
|
1844
|
+
const normalizedText = decodePasteBytes(event.bytes).replace(/\r\n/g, "\n").replace(/\r/g, "\n")
|
|
1845
|
+
|
|
1846
|
+
// Windows Terminal <1.25 can surface image-only clipboard as an
|
|
1847
|
+
// empty bracketed paste. Windows Terminal 1.25+ does not.
|
|
1848
|
+
if (event.bytes.byteLength === 0) {
|
|
1849
|
+
keymap.dispatch("prompt.paste")
|
|
1850
|
+
return
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
// Once we cross an async boundary below, the terminal may perform its
|
|
1854
|
+
// default paste unless we suppress it first and handle insertion ourselves.
|
|
1855
|
+
event.preventDefault()
|
|
1856
|
+
|
|
1857
|
+
void enqueuePaste((changed) => pasteInputText(normalizedText, changed))
|
|
1858
|
+
}}
|
|
1859
|
+
ref={(r: TextareaRenderable) => {
|
|
1860
|
+
input = r
|
|
1861
|
+
Object.assign(r, {
|
|
1862
|
+
getClipboardText: (text: string) => {
|
|
1863
|
+
const range = r.getSelection()
|
|
1864
|
+
// A selection spanning other renderables is not indexed relative to this textarea.
|
|
1865
|
+
if (!range || text !== r.getSelectedText()) {
|
|
1866
|
+
return expandPastedTextPlaceholders(text, store.prompt.pasted)
|
|
1867
|
+
}
|
|
1868
|
+
const parts = store.prompt.pasted.flatMap(({ source, text }) => {
|
|
1869
|
+
if (source.start < range.start || source.end > range.end) return []
|
|
1870
|
+
return [{ start: source.start - range.start, end: source.end - range.start, text }]
|
|
1871
|
+
})
|
|
1872
|
+
return expandTrackedPastedText(text, parts, renderer.widthMethod)
|
|
1873
|
+
},
|
|
1874
|
+
})
|
|
1875
|
+
setInputTarget(r)
|
|
1876
|
+
if (promptPartTypeId === 0) {
|
|
1877
|
+
promptPartTypeId = input.extmarks.registerType("prompt-part")
|
|
1878
|
+
}
|
|
1879
|
+
props.ref?.(ref)
|
|
1880
|
+
}}
|
|
1881
|
+
onMouseDown={(r: MouseEvent) => {
|
|
1882
|
+
if (disabled()) {
|
|
1883
|
+
r.preventDefault()
|
|
1884
|
+
return
|
|
1885
|
+
}
|
|
1886
|
+
if (r.button !== 0) return
|
|
1887
|
+
r.target?.focus()
|
|
1888
|
+
const extmark = input.extmarks
|
|
1889
|
+
.getAtOffset(input.cursorOffset)
|
|
1890
|
+
.find((item) => store.extmarkToPart.get(item.id)?.type === "pasted")
|
|
1891
|
+
if (!extmark || !expandPastedText(extmark.id)) return
|
|
1892
|
+
r.preventDefault()
|
|
1893
|
+
r.stopPropagation()
|
|
1894
|
+
}}
|
|
1895
|
+
focusedBackgroundColor="transparent"
|
|
1896
|
+
cursorColor={disabled() ? theme.background.raised.base : theme.text.base}
|
|
1897
|
+
syntaxStyle={syntax()}
|
|
1898
|
+
/>
|
|
1899
|
+
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between">
|
|
1900
|
+
<PromptMetadataRow
|
|
1901
|
+
mode={store.mode}
|
|
1902
|
+
agent={agentLabel()}
|
|
1903
|
+
auto={local.permission.mode === "autoaccept"}
|
|
1904
|
+
model={promptDisplay().modelLabel}
|
|
1905
|
+
provider={promptDisplay().providerLabel}
|
|
1906
|
+
variant={promptDisplay().variant}
|
|
1907
|
+
speed={promptDisplay().speed}
|
|
1908
|
+
limit={limit()}
|
|
1909
|
+
muted={!!muted()}
|
|
1910
|
+
highlight={highlight()}
|
|
1911
|
+
agentAlpha={agentMetaAlpha()}
|
|
1912
|
+
modelAlpha={modelMetaAlpha()}
|
|
1913
|
+
variantAlpha={variantMetaAlpha()}
|
|
1914
|
+
/>
|
|
1915
|
+
</box>
|
|
1916
|
+
</box>
|
|
1917
|
+
</box>
|
|
1918
|
+
<box
|
|
1919
|
+
height={1}
|
|
1920
|
+
border={["left"]}
|
|
1921
|
+
borderColor={borderHighlight()}
|
|
1922
|
+
customBorderChars={{
|
|
1923
|
+
...EmptyBorder,
|
|
1924
|
+
vertical: promptBg().a !== 0 ? "╹" : " ",
|
|
1925
|
+
}}
|
|
1926
|
+
>
|
|
1927
|
+
<box
|
|
1928
|
+
height={1}
|
|
1929
|
+
border={["bottom"]}
|
|
1930
|
+
borderColor={promptBg()}
|
|
1931
|
+
customBorderChars={
|
|
1932
|
+
promptBg().a !== 0
|
|
1933
|
+
? {
|
|
1934
|
+
...EmptyBorder,
|
|
1935
|
+
horizontal: "▀",
|
|
1936
|
+
}
|
|
1937
|
+
: {
|
|
1938
|
+
...EmptyBorder,
|
|
1939
|
+
horizontal: " ",
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
/>
|
|
1943
|
+
</box>
|
|
1944
|
+
<box width="100%" flexDirection="row" justifyContent="space-between" gap={2}>
|
|
1945
|
+
<Slot path="prompt.footer" input={footerInput()}>
|
|
1946
|
+
<Slot path="prompt.footer.status" input={footerInput()}>
|
|
1947
|
+
<box
|
|
1948
|
+
flexGrow={1}
|
|
1949
|
+
flexShrink={1}
|
|
1950
|
+
minWidth={0}
|
|
1951
|
+
onSizeChange={function (this: BoxRenderable) {
|
|
1952
|
+
const width = this.width
|
|
1953
|
+
queueMicrotask(() => setLocationWidth(width))
|
|
1954
|
+
}}
|
|
1955
|
+
>
|
|
1956
|
+
<Switch>
|
|
1957
|
+
<Match when={status() === "running"}>
|
|
1958
|
+
<box flexDirection="row" gap={1} flexGrow={1} justifyContent="flex-start">
|
|
1959
|
+
<box marginLeft={1}>
|
|
1960
|
+
<Show when={config.animations ?? true} fallback={<text fg={theme.text.muted}>[⋯]</text>}>
|
|
1961
|
+
<spinner color={spinnerDef().color} frames={spinnerDef().frames} interval={40} />
|
|
1962
|
+
</Show>
|
|
1963
|
+
</box>
|
|
1964
|
+
<PromptInterruptStatus
|
|
1965
|
+
armed={store.interrupt > 0}
|
|
1966
|
+
animations={animationsEnabled()}
|
|
1967
|
+
text={theme.text.base}
|
|
1968
|
+
subdued={theme.text.muted}
|
|
1969
|
+
warning={theme.text.feedback.warning.base}
|
|
1970
|
+
flash={theme.decrease(theme.text.feedback.warning.base, 2)}
|
|
1971
|
+
/>
|
|
1972
|
+
</box>
|
|
1973
|
+
</Match>
|
|
1974
|
+
<Match when={move.progress()}>
|
|
1975
|
+
{(progress) => (
|
|
1976
|
+
<box paddingLeft={3} height={1} minHeight={0} flexShrink={1}>
|
|
1977
|
+
<Spinner color={theme.hue.accent[500]}>
|
|
1978
|
+
{progress()}
|
|
1979
|
+
<span style={{ fg: theme.text.muted }}>{".".repeat(move.creatingDots())}</span>
|
|
1980
|
+
</Spinner>
|
|
1981
|
+
</box>
|
|
1982
|
+
)}
|
|
1983
|
+
</Match>
|
|
1984
|
+
<Match when={move.pendingNew()}>
|
|
1985
|
+
<box paddingLeft={3} height={1} minHeight={0} flexShrink={1}>
|
|
1986
|
+
<text fg={theme.hue.accent[500]} wrapMode="none" truncate>
|
|
1987
|
+
(new worktree)
|
|
1988
|
+
</text>
|
|
1989
|
+
</box>
|
|
1990
|
+
</Match>
|
|
1991
|
+
<Match when={true}>
|
|
1992
|
+
<Show when={locationLabelDisplay()} fallback={<text />}>
|
|
1993
|
+
{(location) => (
|
|
1994
|
+
<text
|
|
1995
|
+
id="prompt.footer.location"
|
|
1996
|
+
fg={locationActions.hovered() ? theme.text.base : theme.text.muted}
|
|
1997
|
+
wrapMode="none"
|
|
1998
|
+
truncate
|
|
1999
|
+
flexGrow={1}
|
|
2000
|
+
flexShrink={1}
|
|
2001
|
+
onMouseOver={locationActions.onMouseOver}
|
|
2002
|
+
onMouseOut={locationActions.onMouseOut}
|
|
2003
|
+
onMouseUp={locationActions.onMouseUp}
|
|
2004
|
+
>
|
|
2005
|
+
{location()}
|
|
2006
|
+
</text>
|
|
2007
|
+
)}
|
|
2008
|
+
</Show>
|
|
2009
|
+
</Match>
|
|
2010
|
+
</Switch>
|
|
2011
|
+
</box>
|
|
2012
|
+
</Slot>
|
|
2013
|
+
<Slot path="prompt.footer.file" input={footerInput()}>
|
|
2014
|
+
<Show when={editorContextLabelState() !== "none" ? editorFileLabelDisplay() : undefined}>
|
|
2015
|
+
{(file) => (
|
|
2016
|
+
<text
|
|
2017
|
+
wrapMode="none"
|
|
2018
|
+
truncate
|
|
2019
|
+
flexShrink={1}
|
|
2020
|
+
fg={editorContextLabelState() === "pending" ? theme.hue.accent[500] : theme.text.muted}
|
|
2021
|
+
>
|
|
2022
|
+
{file()}
|
|
2023
|
+
</text>
|
|
2024
|
+
)}
|
|
2025
|
+
</Show>
|
|
2026
|
+
</Slot>
|
|
2027
|
+
</Slot>
|
|
2028
|
+
</box>
|
|
2029
|
+
</box>
|
|
2030
|
+
<Autocomplete
|
|
2031
|
+
sessionID={props.sessionID}
|
|
2032
|
+
argumentAutocomplete={(command) => (command.id === "session.cd" ? "directory" : undefined)}
|
|
2033
|
+
directoryOptions={(query): AutocompleteOption[] => {
|
|
2034
|
+
if (query !== "") return []
|
|
2035
|
+
const projectID =
|
|
2036
|
+
(props.sessionID ? data.session.get(props.sessionID)?.projectID : undefined) ??
|
|
2037
|
+
data.location.info()?.project.id
|
|
2038
|
+
if (!projectID) return []
|
|
2039
|
+
return directoryRecents.list(projectID).map((item) => {
|
|
2040
|
+
const value = directoryRecentValue(item.directory, paths.home)
|
|
2041
|
+
return {
|
|
2042
|
+
display: value,
|
|
2043
|
+
value,
|
|
2044
|
+
description: "recent",
|
|
2045
|
+
isDirectory: true,
|
|
2046
|
+
path: value,
|
|
2047
|
+
absolute: item.directory,
|
|
2048
|
+
destructive: {
|
|
2049
|
+
id: item.directory,
|
|
2050
|
+
confirm: "Press ctrl+d to confirm",
|
|
2051
|
+
run: () => directoryRecents.remove(projectID, item.directory),
|
|
2052
|
+
},
|
|
2053
|
+
}
|
|
2054
|
+
})
|
|
2055
|
+
}}
|
|
2056
|
+
ref={(r) => {
|
|
2057
|
+
setAuto(() => r)
|
|
2058
|
+
}}
|
|
2059
|
+
anchor={() => anchor}
|
|
2060
|
+
input={() => input}
|
|
2061
|
+
setPrompt={(cb) => {
|
|
2062
|
+
setStore("prompt", produce(cb))
|
|
2063
|
+
}}
|
|
2064
|
+
setExtmark={(part, extmarkId) => {
|
|
2065
|
+
setStore("extmarkToPart", (map: Map<number, PromptPartRef>) => {
|
|
2066
|
+
const newMap = new Map(map)
|
|
2067
|
+
newMap.set(extmarkId, part)
|
|
2068
|
+
return newMap
|
|
2069
|
+
})
|
|
2070
|
+
}}
|
|
2071
|
+
value={store.prompt.text}
|
|
2072
|
+
fileStyleId={fileStyleId}
|
|
2073
|
+
agentStyleId={agentStyleId}
|
|
2074
|
+
skillStyleId={skillStyleId}
|
|
2075
|
+
hasSkill={(id) => store.prompt.skills?.some((skill) => skill.id === id) ?? false}
|
|
2076
|
+
promptPartTypeId={() => promptPartTypeId}
|
|
2077
|
+
/>
|
|
2078
|
+
</>
|
|
2079
|
+
)
|
|
2080
|
+
}
|