@kabmo-labs/kabmo 0.23.0 → 0.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +805 -736
- package/dist/client/static/js/index-bc9aa4mx.css +1 -0
- package/dist/client/static/js/{index-ph0q59rs.js → index-ga8cbpt4.js} +1071 -1171
- package/package.json +2 -4
- package/src/cli/lib/args.js +24 -1
- package/src/cli/lib/args.test.js +16 -0
- package/src/cli/lib/commands/session.js +233 -0
- package/src/cli/lib/commands/session.test.js +103 -0
- package/src/cli/main.js +1 -1
- package/src/client/components/common/ComposerPicker.tsx +3 -0
- package/src/client/components/common/Modal.tsx +2 -6
- package/src/client/components/common/code-surface/shiki.test.ts +82 -0
- package/src/client/components/common/code-surface/shiki.ts +28 -7
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +113 -0
- package/src/client/components/common/session-actions-menu/index.tsx +33 -2
- package/src/client/components/common/session-row/StatusSlot.tsx +4 -4
- package/src/client/components/common/session-row/index.tsx +27 -1
- package/src/client/components/layout/desktop-layout/WorkspacePanels.tsx +7 -1
- package/src/client/components/layout/desktop-layout/resizer/separator-drag.ts +3 -3
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +25 -12
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +66 -0
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +28 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.test.tsx +20 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +59 -12
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +94 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.test.tsx +130 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +120 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +47 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.test.tsx +122 -0
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +55 -46
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +18 -5
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +21 -4
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +27 -5
- package/src/client/components/settings/categories/harness-settings/EnvProviderForm.tsx +31 -0
- package/src/client/components/settings/categories/harness-settings/provider-panel.test.tsx +49 -0
- package/src/client/components/workspace/chat-timeline/ChatOverlays.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +64 -70
- package/src/client/components/workspace/chat-timeline/ComposerDockFrame.tsx +35 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +135 -118
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +22 -1
- package/src/client/components/workspace/chat-timeline/MessageList.test.ts +14 -0
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +4 -0
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +3 -0
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +4 -3
- package/src/client/components/workspace/chat-timeline/composer-dock-frame.test.tsx +155 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +5 -2
- package/src/client/components/workspace/chat-timeline/pending-harness.test.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/FrameControl.tsx +11 -20
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/GroupedAsk.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/QuestionBlock.tsx +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/drafts.ts +1 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/ask-panel/index.tsx +2 -1
- package/src/client/components/workspace/file-explorer/index.test.ts +25 -0
- package/src/client/components/workspace/file-explorer/index.tsx +9 -3
- package/src/client/components/workspace/model-dropdown/harness-models.test.ts +17 -0
- package/src/client/components/workspace/model-dropdown/harness-models.ts +33 -18
- package/src/client/components/workspace/model-dropdown/index.tsx +3 -3
- package/src/client/components/workspace/model-dropdown/popover-metrics.ts +4 -1
- package/src/client/components/workspace/terminal-panel/KeyBar.tsx +10 -8
- package/src/client/components/workspace/terminal-panel/{RealtimeXtermView.tsx → RealtimeTerminalView.tsx} +51 -58
- package/src/client/components/workspace/terminal-panel/fit.test.ts +37 -0
- package/src/client/components/workspace/terminal-panel/fit.ts +64 -0
- package/src/client/components/workspace/terminal-panel/fonts.test.ts +161 -0
- package/src/client/components/workspace/terminal-panel/fonts.ts +164 -0
- package/src/client/components/workspace/terminal-panel/grid.test.ts +52 -0
- package/src/client/components/workspace/terminal-panel/grid.ts +118 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +25 -21
- package/src/client/components/workspace/terminal-panel/mount.ts +247 -223
- package/src/client/components/workspace/terminal-panel/navigation.test.ts +54 -0
- package/src/client/components/workspace/terminal-panel/navigation.ts +47 -0
- package/src/client/data/settings/omp-schema.json +5 -5
- package/src/client/data/theme/terminal.test.ts +25 -0
- package/src/client/data/theme/terminal.ts +96 -79
- package/src/client/hooks/chat/composer/items.test.ts +12 -26
- package/src/client/hooks/chat/composer/pick-mapping.test.ts +42 -0
- package/src/client/hooks/chat/omp/prompt-send.test.ts +7 -7
- package/src/client/hooks/chat/omp/prompt-send.ts +26 -14
- package/src/client/hooks/chat/timeline/actions.ts +2 -2
- package/src/client/hooks/chat/timeline/ask-frames.ts +5 -4
- package/src/client/hooks/chat/timeline/new-chat-open.test.ts +86 -0
- package/src/client/hooks/chat/timeline/new-chat-open.ts +23 -5
- package/src/client/hooks/chat/timeline/new-chat.test.ts +32 -4
- package/src/client/hooks/chat/timeline/new-chat.ts +18 -6
- package/src/client/hooks/chat/timeline/prompt-text.test.ts +34 -1
- package/src/client/hooks/chat/timeline/prompt-text.ts +47 -20
- package/src/client/hooks/chat/timeline/rewind-actions.test.ts +24 -1
- package/src/client/hooks/chat/timeline/rewind-actions.ts +15 -11
- package/src/client/hooks/chat/timeline/run-identity.test.ts +52 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +23 -11
- package/src/client/hooks/chat/timeline/send-execute.test.ts +56 -0
- package/src/client/hooks/chat/timeline/send-helpers.ts +30 -1
- package/src/client/hooks/chat/timeline/send-props.ts +5 -3
- package/src/client/hooks/chat/timeline/send-steer.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.test-util.ts +8 -2
- package/src/client/hooks/chat/timeline/send.test.ts +4 -4
- package/src/client/hooks/chat/timeline/send.ts +59 -53
- package/src/client/hooks/chat/timeline/session-load.test-util.ts +6 -2
- package/src/client/hooks/chat/timeline/session-load.test.ts +31 -0
- package/src/client/hooks/chat/timeline/session-load.ts +6 -14
- package/src/client/hooks/chat/timeline/session-shapes.ts +32 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +49 -0
- package/src/client/hooks/models/harness-catalog.ts +114 -0
- package/src/client/hooks/models/provider-writes.test.ts +81 -0
- package/src/client/hooks/models/provider-writes.ts +10 -3
- package/src/client/hooks/models/use-harness-update.test.ts +193 -0
- package/src/client/hooks/models/use-harness-update.ts +202 -0
- package/src/client/hooks/models/use-harnesses-controller.ts +57 -0
- package/src/client/hooks/models/use-harnesses-signal.test.ts +128 -0
- package/src/client/hooks/models/use-harnesses.test.ts +2 -1
- package/src/client/hooks/models/use-harnesses.ts +48 -114
- package/src/client/hooks/workspace/child-expansion.ts +33 -0
- package/src/client/hooks/workspace/terminal/index.ts +17 -3
- package/src/client/hooks/workspace/terminal/socket.ts +9 -4
- package/src/client/lib/session-tree.test.ts +50 -0
- package/src/client/lib/session-tree.ts +59 -0
- package/src/client/tailwind.css +26 -12
- package/src/server/index.ts +2 -0
- package/src/server/lib/auth/guard.ts +10 -0
- package/src/server/lib/btw/session-copy.server.ts +6 -44
- package/src/server/lib/btw/session-copy.test.ts +2 -1
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/db/seed-terminal.test.ts +1 -1
- package/src/server/lib/db/seed.test.ts +1 -1
- package/src/server/lib/harness/acp/activation.test.ts +81 -0
- package/src/server/lib/harness/acp/activation.ts +72 -0
- package/src/server/lib/harness/acp/background-work.test.ts +262 -0
- package/src/server/lib/harness/acp/background-work.ts +320 -0
- package/src/server/lib/harness/acp/client.ts +2 -2
- package/src/server/lib/harness/acp/frames.test.ts +50 -1
- package/src/server/lib/harness/acp/frames.ts +17 -5
- package/src/server/lib/harness/acp/gateway-env.test.ts +64 -0
- package/src/server/lib/harness/acp/gateway-env.ts +70 -0
- package/src/server/lib/harness/acp/mapper.ts +6 -4
- package/src/server/lib/harness/acp/prompt.test.ts +20 -0
- package/src/server/lib/harness/acp/prompt.ts +19 -3
- package/src/server/lib/harness/acp/session-background.test.ts +129 -0
- package/src/server/lib/harness/acp/session-config.test.ts +73 -0
- package/src/server/lib/harness/acp/session-config.ts +87 -6
- package/src/server/lib/harness/acp/session-exit.ts +31 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +108 -0
- package/src/server/lib/harness/acp/session-handshake.ts +36 -3
- package/src/server/lib/harness/acp/session-idle.ts +51 -0
- package/src/server/lib/harness/acp/session-listeners.ts +31 -0
- package/src/server/lib/harness/acp/session-notifications.ts +19 -3
- package/src/server/lib/harness/acp/session-observers.test.ts +9 -0
- package/src/server/lib/harness/acp/session-options.ts +33 -0
- package/src/server/lib/harness/acp/session-reaper.test.ts +96 -0
- package/src/server/lib/harness/acp/session-requests.ts +47 -0
- package/src/server/lib/harness/acp/session-turns.ts +20 -5
- package/src/server/lib/harness/acp/session.test-util.ts +54 -3
- package/src/server/lib/harness/acp/session.test.ts +65 -3
- package/src/server/lib/harness/acp/session.ts +79 -79
- package/src/server/lib/harness/acp/turn.test.ts +81 -0
- package/src/server/lib/harness/acp/turn.ts +54 -13
- package/src/server/lib/harness/acp/verbs.ts +12 -2
- package/src/server/lib/harness/auto-probe.server.test.ts +121 -0
- package/src/server/lib/harness/auto-probe.server.ts +178 -0
- package/src/server/lib/harness/config.server.test.ts +1 -1
- package/src/server/lib/harness/config.server.ts +1 -1
- package/src/server/lib/harness/launch-table.ts +195 -0
- package/src/server/lib/harness/launch.test.ts +37 -0
- package/src/server/lib/harness/launch.ts +16 -116
- package/src/server/lib/harness/provider-entry.ts +32 -0
- package/src/server/lib/harness/provider-file.server.ts +3 -0
- package/src/server/lib/harness/provider-sources.server.test.ts +45 -0
- package/src/server/lib/harness/provider-sources.server.ts +26 -2
- package/src/server/lib/harness/provider-write.server.ts +21 -32
- package/src/server/lib/harness/provider-zcode.server.test.ts +270 -0
- package/src/server/lib/harness/provider-zcode.server.ts +324 -0
- package/src/server/lib/harness/spawn.server.ts +15 -2
- package/src/server/lib/harness/update-job-store.test.ts +126 -0
- package/src/server/lib/harness/update-job-store.ts +109 -0
- package/src/server/lib/harness/update-job.server.ts +203 -0
- package/src/server/lib/harness/update-state.server.ts +15 -20
- package/src/server/lib/harness/update-worker.test.ts +153 -0
- package/src/server/lib/harness/update-worker.ts +197 -0
- package/src/server/lib/lifecycle/after-listen.ts +7 -0
- package/src/server/lib/lifecycle/paths.ts +23 -0
- package/src/server/lib/models/registry-refresh.server.test.ts +87 -0
- package/src/server/lib/models/registry-refresh.server.ts +98 -0
- package/src/server/lib/omp/rpc/child-config.ts +5 -4
- package/src/server/lib/omp/rpc/constants.test.ts +2 -1
- package/src/server/lib/omp/rpc/forked-resume.test.ts +14 -3
- package/src/server/lib/omp/rpc/manager.ts +5 -5
- package/src/server/lib/omp/rpc/prewarm-pool.ts +12 -3
- package/src/server/lib/omp/rpc/session-registry.ts +14 -2
- package/src/server/lib/omp/rpc/terminal-settle.ts +53 -5
- package/src/server/lib/omp/session/delete-flow.server.ts +62 -8
- package/src/server/lib/omp/session/delete.server.ts +17 -0
- package/src/server/lib/omp/session/rewind-file.ts +39 -21
- package/src/server/lib/omp/session/sidebar-data.server.ts +6 -6
- package/src/server/lib/omp/session/transcript-copy.ts +123 -0
- package/src/server/lib/sessions/agent-token.server.test.ts +64 -0
- package/src/server/lib/sessions/agent-token.server.ts +134 -0
- package/src/server/lib/sessions/answers.server.test.ts +33 -0
- package/src/server/lib/sessions/answers.server.ts +37 -0
- package/src/server/lib/sessions/dispatch.server.test.ts +143 -0
- package/src/server/lib/sessions/dispatch.server.ts +128 -0
- package/src/server/lib/sessions/fork.server.test.ts +209 -0
- package/src/server/lib/sessions/fork.server.ts +304 -0
- package/src/server/lib/sessions/lifecycle.server.test.ts +75 -0
- package/src/server/lib/sessions/lifecycle.server.ts +71 -0
- package/src/server/lib/sessions/notify.server.test.ts +112 -0
- package/src/server/lib/sessions/notify.server.ts +212 -0
- package/src/server/lib/sessions/relation-types.ts +76 -0
- package/src/server/lib/sessions/relations.server.test.ts +207 -0
- package/src/server/lib/sessions/relations.server.ts +337 -0
- package/src/server/lib/sessions/resolve.server.ts +106 -0
- package/src/server/lib/sessions/schema.server.ts +82 -0
- package/src/server/lib/sessions/sidebar-relations.server.test.ts +61 -0
- package/src/server/lib/sessions/sidebar-relations.server.ts +47 -0
- package/src/server/lib/sessions/spawn.server.test.ts +196 -0
- package/src/server/lib/sessions/spawn.server.ts +310 -0
- package/src/server/lib/terminal/attach-replay.test.ts +2 -2
- package/src/server/lib/terminal/output.test.ts +2 -2
- package/src/server/lib/terminal/output.ts +1 -1
- package/src/server/lib/terminal/resize.test.ts +99 -0
- package/src/server/lib/terminal/runtime.server.ts +26 -6
- package/src/server/lib/terminal/send-result.test.ts +18 -1
- package/src/server/lib/terminal/send-result.ts +26 -2
- package/src/server/lib/terminal/session.server.ts +6 -6
- package/src/server/lib/usage/new-api.test.ts +92 -0
- package/src/server/lib/usage/new-api.ts +131 -0
- package/src/server/lib/usage/provider-endpoint.test.ts +106 -0
- package/src/server/lib/usage/provider-key.ts +33 -0
- package/src/server/lib/usage/providers.server.ts +10 -3
- package/src/server/lib/usage/vendor-balance.server.ts +4 -53
- package/src/server/lib/usage/vendor-http.ts +41 -0
- package/src/server/lib/usage/window.ts +55 -0
- package/src/server/routes/agent/command.ts +14 -1
- package/src/server/routes/agent/harness-command.ts +6 -0
- package/src/server/routes/agent/new.ts +15 -0
- package/src/server/routes/chat/rewind.test.ts +147 -0
- package/src/server/routes/chat/rewind.ts +29 -7
- package/src/server/routes/chat/session.test.ts +165 -10
- package/src/server/routes/chat/session.ts +60 -7
- package/src/server/routes/harness/add-provider.test.ts +9 -1
- package/src/server/routes/harness/import-action.ts +22 -4
- package/src/server/routes/harness/import.test.ts +1 -1
- package/src/server/routes/harness/index.ts +5 -1
- package/src/server/routes/harness/root.ts +8 -49
- package/src/server/routes/harness/toggle.test.ts +20 -0
- package/src/server/routes/harness/update-status.ts +26 -0
- package/src/server/routes/harness/update.test.ts +119 -0
- package/src/server/routes/harness/update.ts +67 -113
- package/src/server/routes/harness/versions.ts +5 -1
- package/src/server/routes/sessions/answer.ts +24 -0
- package/src/server/routes/sessions/batch-delete.ts +11 -5
- package/src/server/routes/sessions/delete-acp.test.ts +227 -0
- package/src/server/routes/sessions/delete.ts +4 -2
- package/src/server/routes/sessions/fork.ts +74 -0
- package/src/server/routes/sessions/index.ts +14 -0
- package/src/server/routes/sessions/relations.ts +85 -0
- package/src/server/routes/sessions/session.ts +4 -0
- package/src/server/routes/sessions/spawn.ts +134 -0
- package/src/server/routes/settings/model-override.ts +5 -2
- package/src/server/routes/settings/provider-entry.ts +2 -2
- package/src/server/routes/settings/provider-model.ts +2 -2
- package/src/server/routes/settings/provider-models.ts +2 -2
- package/src/server/routes/settings/provider-refresh.ts +6 -4
- package/src/server/routes/settings/providers.ts +3 -1
- package/src/server/routes/settings/settings-config-routes.test.ts +10 -2
- package/src/server/routes/terminal/ws.ts +3 -3
- package/src/shared/lib/chat/ask-form/fields.ts +76 -0
- package/src/shared/lib/chat/ask-form/index.ts +323 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +199 -0
- package/src/shared/lib/chat/ask-form/types.ts +43 -0
- package/src/shared/lib/chat/ask-form.test.ts +137 -0
- package/src/shared/lib/chat/ask-questions.test.ts +65 -1
- package/src/shared/lib/chat/ask-questions.ts +51 -145
- package/src/shared/lib/chat/ask-results.ts +198 -0
- package/src/shared/lib/chat/composer/client.ts +31 -2
- package/src/shared/lib/chat/composer/delegation.test.ts +93 -0
- package/src/shared/lib/chat/composer/delegation.ts +206 -0
- package/src/shared/lib/chat/notice-text.ts +1 -1
- package/src/shared/lib/chat/timeline/omp-callbacks.ts +13 -1
- package/src/shared/lib/chat/timeline/prompt-error.test.ts +146 -0
- package/src/shared/lib/chat/timeline/prompt-error.ts +88 -0
- package/src/shared/lib/chat/tool/summary-wait.test.ts +11 -0
- package/src/shared/lib/code/ansi.ts +1 -1
- package/src/shared/lib/fonts/nerd-symbols.css +4 -3
- package/src/shared/lib/fonts/nerd-symbols.test.ts +9 -9
- package/src/shared/lib/harness/catalog.test.ts +1 -1
- package/src/shared/lib/harness/config-fields.test.ts +4 -0
- package/src/shared/lib/harness/config-fields.ts +19 -4
- package/src/shared/lib/harness/dialects.test.ts +8 -0
- package/src/shared/lib/harness/dialects.ts +12 -0
- package/src/shared/lib/harness/provider-facts.test.ts +59 -8
- package/src/shared/lib/harness/provider-facts.ts +46 -11
- package/src/shared/lib/harness/providers.ts +44 -1
- package/src/shared/lib/harness/rewind.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +33 -0
- package/src/shared/lib/harness/update-plan.test.ts +69 -4
- package/src/shared/lib/harness/update-plan.ts +57 -9
- package/src/shared/lib/harness/updates.test.ts +22 -0
- package/src/shared/lib/harness/updates.ts +24 -1
- package/src/shared/lib/models/client.ts +10 -1
- package/src/shared/lib/omp/dialog-methods.ts +4 -3
- package/src/shared/lib/omp/session/wait-idle.test.ts +11 -0
- package/src/shared/lib/omp/session/wait-idle.ts +12 -2
- package/src/shared/lib/theme/catalog.test.ts +13 -9
- package/src/shared/lib/theme/color.test.ts +2 -2
- package/src/shared/lib/theme/color.ts +4 -4
- package/src/shared/lib/theme/css.ts +2 -0
- package/src/shared/lib/theme/ink-scale.ts +21 -1
- package/src/shared/lib/theme/theme.test.ts +26 -10
- package/src/shared/lib/ui/safe-area.test.ts +28 -0
- package/src/shared/lib/ui/safe-area.ts +42 -0
- package/src/shared/lib/workspace/terminal/input.test.ts +27 -0
- package/src/shared/lib/workspace/terminal/input.ts +33 -0
- package/src/shared/lib/workspace/terminal/keys.test.ts +1 -1
- package/src/shared/lib/workspace/terminal/keys.ts +7 -7
- package/src/shared/types/chat.ts +1 -1
- package/src/shared/types/harness-update.ts +65 -0
- package/src/shared/types/harness.ts +30 -4
- package/src/shared/types/omp/agent.ts +19 -2
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/fake-omp-fork.ts +16 -2
- package/src/test-support/file-explorer-render.test-util.ts +37 -0
- package/src/test-support/file-explorer.test-util.ts +20 -18
- package/src/test-support/harness-table.test-util.ts +21 -4
- package/dist/client/static/js/index-jhmg4w91.css +0 -1
- package/src/client/components/workspace/terminal-panel/webgl.test.ts +0 -75
- package/src/client/components/workspace/terminal-panel/webgl.ts +0 -108
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, expect, test } from 'bun:test';
|
|
7
|
+
import {
|
|
8
|
+
GRID_SETTLE_MS,
|
|
9
|
+
MIN_REPORT_COLS,
|
|
10
|
+
MIN_REPORT_ROWS,
|
|
11
|
+
gridDecision,
|
|
12
|
+
} from '@/client/components/workspace/terminal-panel/grid';
|
|
13
|
+
|
|
14
|
+
const UNATTACHED = { attached: false, committed: { cols: 0, rows: 0 } };
|
|
15
|
+
|
|
16
|
+
describe('gridDecision', () => {
|
|
17
|
+
test('announces the first real grid as the attach size', () => {
|
|
18
|
+
expect(gridDecision({ cols: 41, rows: 47, ...UNATTACHED })).toEqual({
|
|
19
|
+
kind: 'attach',
|
|
20
|
+
cols: 41,
|
|
21
|
+
rows: 47,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('ignores a squeezed panel instead of resizing the shell', () => {
|
|
26
|
+
// Measured: `resize 5x37` reached a real shell while the panel was opening
|
|
27
|
+
// its width transition, and the shell redrew its prompt hard-wrapped.
|
|
28
|
+
expect(gridDecision({ cols: 5, rows: 37, ...UNATTACHED })).toEqual({ kind: 'ignore' });
|
|
29
|
+
expect(gridDecision({ cols: MIN_REPORT_COLS - 1, rows: 47, ...UNATTACHED })).toEqual({
|
|
30
|
+
kind: 'ignore',
|
|
31
|
+
});
|
|
32
|
+
expect(gridDecision({ cols: 41, rows: MIN_REPORT_ROWS - 1, ...UNATTACHED })).toEqual({
|
|
33
|
+
kind: 'ignore',
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('maps a corrected grid onto a resize once attached', () => {
|
|
38
|
+
const attached = { attached: true, committed: { cols: 41, rows: 47 } };
|
|
39
|
+
expect(gridDecision({ cols: 41, rows: 47, ...attached })).toEqual({ kind: 'ignore' });
|
|
40
|
+
expect(gridDecision({ cols: 40, rows: 47, ...attached })).toEqual({
|
|
41
|
+
kind: 'change',
|
|
42
|
+
cols: 40,
|
|
43
|
+
rows: 47,
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('waits longer than a frame before announcing', () => {
|
|
48
|
+
// The panel's width transition outlives one animation frame; a gate shorter
|
|
49
|
+
// than ~100 ms measured the animating box again.
|
|
50
|
+
expect(GRID_SETTLE_MS).toBeGreaterThanOrEqual(100);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* When a terminal grid may be announced to the shell.
|
|
8
|
+
*
|
|
9
|
+
* A terminal's grid is a PTY size, and a PTY size is a `SIGWINCH`: the shell
|
|
10
|
+
* answers each one by redrawing its prompt, and those redraws are output that
|
|
11
|
+
* lives in the scrollback forever. The right panel opens with a width
|
|
12
|
+
* transition, so fits during it measure a squeezed box — announcing one sent
|
|
13
|
+
* `resize 5x37` to a real shell, which redrew its prompt hard-wrapped at five
|
|
14
|
+
* columns. Worse, before the first fit the terminal still holds ghostty's 80×24
|
|
15
|
+
* default, which looks like a plausible size: a reload announced `80x24` and the
|
|
16
|
+
* shell answered by rewrapping its prompt at 80 columns. Both left garbage in
|
|
17
|
+
* the history, and every later reload replayed one more block of it above the
|
|
18
|
+
* live prompt, which is why the prompt marched down the panel.
|
|
19
|
+
*
|
|
20
|
+
* Two rules follow, and they are this module:
|
|
21
|
+
*
|
|
22
|
+
* - **A grid is announced only after it has held still** (`GRID_SETTLE_MS`), so
|
|
23
|
+
* a value read mid-animation never leaves the client.
|
|
24
|
+
* - **A grid comes from a real fit**, never from the terminal's default: the
|
|
25
|
+
* caller's `fit()` reports whether the container was measurable, and the
|
|
26
|
+
* decision below is not even asked when it was not.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { Terminal } from 'ghostty-web';
|
|
30
|
+
|
|
31
|
+
/** A grid below this is a panel mid-transition, not a size someone chose. */
|
|
32
|
+
export const MIN_REPORT_COLS = 10;
|
|
33
|
+
export const MIN_REPORT_ROWS = 5;
|
|
34
|
+
/** How long a grid must hold still before it is announced to the shell. */
|
|
35
|
+
export const GRID_SETTLE_MS = 120;
|
|
36
|
+
|
|
37
|
+
export type GridEvent =
|
|
38
|
+
| { kind: 'ignore' }
|
|
39
|
+
| { kind: 'attach'; cols: number; rows: number }
|
|
40
|
+
| { kind: 'change'; cols: number; rows: number };
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Classify a measured grid against what has already been announced.
|
|
44
|
+
*
|
|
45
|
+
* Pure, so the rules can be pinned without a renderer, a timer or a socket.
|
|
46
|
+
*/
|
|
47
|
+
export function gridDecision(input: {
|
|
48
|
+
cols: number;
|
|
49
|
+
rows: number;
|
|
50
|
+
attached: boolean;
|
|
51
|
+
committed: { cols: number; rows: number };
|
|
52
|
+
}): GridEvent {
|
|
53
|
+
const { cols, rows, attached, committed } = input;
|
|
54
|
+
if (cols < MIN_REPORT_COLS || rows < MIN_REPORT_ROWS) return { kind: 'ignore' };
|
|
55
|
+
if (!attached) return { kind: 'attach', cols, rows };
|
|
56
|
+
if (cols === committed.cols && rows === committed.rows) return { kind: 'ignore' };
|
|
57
|
+
return { kind: 'change', cols, rows };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface GridAnnouncerOptions {
|
|
61
|
+
/** The live terminal; the announcer never holds it, a theme rebuild replaces it. */
|
|
62
|
+
current: () => Terminal | undefined;
|
|
63
|
+
/** Fit to the container. False when the panel is hidden or the cell unmeasured. */
|
|
64
|
+
fit: () => boolean;
|
|
65
|
+
onReady: (cols: number, rows: number) => void;
|
|
66
|
+
onGridChange: (cols: number, rows: number) => void;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GridAnnouncer {
|
|
70
|
+
/** Announce after the grid has held still for `GRID_SETTLE_MS`. */
|
|
71
|
+
schedule: () => void;
|
|
72
|
+
/** Forget what was announced, so the next commit states the grid again. */
|
|
73
|
+
restate: () => void;
|
|
74
|
+
/** True once the first real grid has been announced. */
|
|
75
|
+
isAttached: () => boolean;
|
|
76
|
+
dispose: () => void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function createGridAnnouncer(options: GridAnnouncerOptions): GridAnnouncer {
|
|
80
|
+
let committed = { cols: 0, rows: 0 };
|
|
81
|
+
let attached = false;
|
|
82
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
83
|
+
|
|
84
|
+
const commit = (): void => {
|
|
85
|
+
if (!options.fit()) return;
|
|
86
|
+
const term = options.current();
|
|
87
|
+
if (!term) return;
|
|
88
|
+
const event = gridDecision({
|
|
89
|
+
cols: term.cols,
|
|
90
|
+
rows: term.rows,
|
|
91
|
+
attached,
|
|
92
|
+
committed,
|
|
93
|
+
});
|
|
94
|
+
if (event.kind === 'ignore') return;
|
|
95
|
+
committed = { cols: event.cols, rows: event.rows };
|
|
96
|
+
if (event.kind === 'attach') {
|
|
97
|
+
attached = true;
|
|
98
|
+
options.onReady(event.cols, event.rows);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
options.onGridChange(event.cols, event.rows);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
schedule() {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
timer = setTimeout(commit, GRID_SETTLE_MS);
|
|
108
|
+
},
|
|
109
|
+
restate() {
|
|
110
|
+
committed = { cols: 0, rows: 0 };
|
|
111
|
+
},
|
|
112
|
+
isAttached: () => attached,
|
|
113
|
+
dispose() {
|
|
114
|
+
clearTimeout(timer);
|
|
115
|
+
timer = undefined;
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
}
|
|
@@ -8,7 +8,7 @@ import { copyToClipboard, readClipboardText } from '@/client/hooks/ui/clipboard'
|
|
|
8
8
|
import { TerminalHeader } from '@/client/components/workspace/terminal-panel/Header';
|
|
9
9
|
import { TerminalQuickActions } from '@/client/components/workspace/terminal-panel/QuickActions';
|
|
10
10
|
import { TerminalKeyBar } from '@/client/components/workspace/terminal-panel/KeyBar';
|
|
11
|
-
import {
|
|
11
|
+
import { RealtimeTerminalView, type RealtimeTerminalHandle } from '@/client/components/workspace/terminal-panel/RealtimeTerminalView';
|
|
12
12
|
import {
|
|
13
13
|
NO_MODIFIERS,
|
|
14
14
|
applyModifiers,
|
|
@@ -30,7 +30,7 @@ interface TerminalPanelProps {
|
|
|
30
30
|
const encoder = new TextEncoder();
|
|
31
31
|
|
|
32
32
|
export function TerminalPanel({ className = '', enabled = true, rootPath, showHeader = true, active = true }: TerminalPanelProps) {
|
|
33
|
-
const
|
|
33
|
+
const terminalRef = useRef<RealtimeTerminalHandle>(null);
|
|
34
34
|
const { isDark } = useTheme();
|
|
35
35
|
// Only a device without a physical keyboard gets the key bar: on a desktop
|
|
36
36
|
// every one of those keys is already under the user's fingers, and a strip of
|
|
@@ -44,21 +44,21 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
44
44
|
const { activeRepo, setActiveRepo } = useRepoScope(rootPath);
|
|
45
45
|
const { repos, scanning: reposScanning, rescan: rescanRepos } = useRepoList(rootPath, enabled);
|
|
46
46
|
const gridRef = useRef<{ cols: number; rows: number } | null>(null);
|
|
47
|
-
// The latch is read inside `handleInput`, which
|
|
47
|
+
// The latch is read inside `handleInput`, which the terminal calls outside React's
|
|
48
48
|
// render — a ref is what makes it the value at the keystroke, not at mount.
|
|
49
49
|
const modifiersRef = useRef(modifiers);
|
|
50
50
|
modifiersRef.current = modifiers;
|
|
51
51
|
|
|
52
52
|
const handleOutput = useCallback((bytes: Uint8Array) => {
|
|
53
|
-
|
|
53
|
+
terminalRef.current?.write(bytes);
|
|
54
54
|
}, []);
|
|
55
55
|
|
|
56
56
|
const handleReplay = useCallback((bytes: Uint8Array, frame: { replayCols: number; replayRows: number }) => {
|
|
57
|
-
|
|
57
|
+
terminalRef.current?.writeReplay(bytes, frame.replayCols, frame.replayRows);
|
|
58
58
|
}, []);
|
|
59
59
|
|
|
60
60
|
const handleRestart = useCallback(() => {
|
|
61
|
-
|
|
61
|
+
terminalRef.current?.reset();
|
|
62
62
|
}, []);
|
|
63
63
|
|
|
64
64
|
const {
|
|
@@ -70,6 +70,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
70
70
|
resize,
|
|
71
71
|
input,
|
|
72
72
|
restart,
|
|
73
|
+
reattach,
|
|
73
74
|
} = useTerminal({
|
|
74
75
|
root: enabled ? rootPath : undefined,
|
|
75
76
|
repo: activeRepo,
|
|
@@ -112,19 +113,19 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
112
113
|
|
|
113
114
|
const handleToggleModifier = useCallback((modifier: TerminalModifier) => {
|
|
114
115
|
setModifiers((previous) => ({ ...previous, [modifier]: !previous[modifier] }));
|
|
115
|
-
|
|
116
|
+
terminalRef.current?.focus();
|
|
116
117
|
}, []);
|
|
117
118
|
|
|
118
119
|
const handleKey = useCallback((id: TerminalKeyId) => {
|
|
119
120
|
const sequence = resolveKeySequence(id, {
|
|
120
|
-
applicationCursorKeys:
|
|
121
|
+
applicationCursorKeys: terminalRef.current?.applicationCursorKeys() ?? false,
|
|
121
122
|
modifiers: modifiersRef.current,
|
|
122
123
|
});
|
|
123
124
|
if (!sequence) return;
|
|
124
125
|
input(encoder.encode(sequence));
|
|
125
126
|
setModifiers(NO_MODIFIERS);
|
|
126
127
|
// Keep the OS keyboard where it was; a key bar tap must not dismiss it.
|
|
127
|
-
|
|
128
|
+
terminalRef.current?.focus();
|
|
128
129
|
}, [input]);
|
|
129
130
|
|
|
130
131
|
/**
|
|
@@ -134,7 +135,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
134
135
|
* instead of flashing success over an untouched clipboard.
|
|
135
136
|
*/
|
|
136
137
|
const handleCopy = useCallback(async () => {
|
|
137
|
-
const selection =
|
|
138
|
+
const selection = terminalRef.current?.getSelection() ?? '';
|
|
138
139
|
if (!selection) return false;
|
|
139
140
|
return copyToClipboard(selection);
|
|
140
141
|
}, []);
|
|
@@ -142,27 +143,29 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
142
143
|
const handlePaste = useCallback(async () => {
|
|
143
144
|
const text = await readClipboardText();
|
|
144
145
|
if (text === null || text.length === 0) return false;
|
|
145
|
-
// Through
|
|
146
|
-
|
|
147
|
-
|
|
146
|
+
// Through the terminal's own paste, so a bracketed-paste shell gets its markers.
|
|
147
|
+
terminalRef.current?.paste(text);
|
|
148
|
+
terminalRef.current?.focus();
|
|
148
149
|
return true;
|
|
149
150
|
}, []);
|
|
150
151
|
|
|
151
|
-
const handleBinaryInput = useCallback((
|
|
152
|
-
const bytes = new Uint8Array(data.length);
|
|
153
|
-
for (let i = 0; i < data.length; i += 1) bytes[i] = data.charCodeAt(i) & 0xff;
|
|
152
|
+
const handleBinaryInput = useCallback((bytes: Uint8Array) => {
|
|
154
153
|
input(bytes);
|
|
155
154
|
}, [input]);
|
|
156
155
|
|
|
157
156
|
const handleQuickAction = useCallback((command: string) => {
|
|
158
157
|
input(encoder.encode(`${command}\r`));
|
|
159
|
-
|
|
158
|
+
terminalRef.current?.focus();
|
|
160
159
|
}, [input]);
|
|
161
160
|
|
|
162
161
|
const handleRestartClick = useCallback(() => {
|
|
163
162
|
restart();
|
|
164
163
|
}, [restart]);
|
|
165
164
|
|
|
165
|
+
const handleReattach = useCallback(() => {
|
|
166
|
+
reattach();
|
|
167
|
+
}, [reattach]);
|
|
168
|
+
|
|
166
169
|
if (!enabled) {
|
|
167
170
|
return (
|
|
168
171
|
<div className={`flex flex-col h-full bg-paper items-center justify-center text-ink/40 ${className}`}>
|
|
@@ -175,6 +178,7 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
175
178
|
<div
|
|
176
179
|
ref={rootRef}
|
|
177
180
|
className={`flex flex-col h-full w-full bg-paper text-ink overflow-hidden ${className}`}
|
|
181
|
+
aria-hidden={!active}
|
|
178
182
|
// The soft keyboard covers the bottom of the visual viewport without
|
|
179
183
|
// shrinking the layout one, so the key bar would sit behind the keys the
|
|
180
184
|
// user is typing on. Lifting by the panel's actual overlap with the
|
|
@@ -207,15 +211,15 @@ export function TerminalPanel({ className = '', enabled = true, rootPath, showHe
|
|
|
207
211
|
</div>
|
|
208
212
|
)}
|
|
209
213
|
|
|
210
|
-
{/* Real-time
|
|
214
|
+
{/* Real-time terminal canvas, driven by the PTY socket */}
|
|
211
215
|
<div className="flex-1 w-full min-h-0 bg-canvas overflow-hidden">
|
|
212
|
-
<
|
|
213
|
-
ref={
|
|
216
|
+
<RealtimeTerminalView
|
|
217
|
+
ref={terminalRef}
|
|
214
218
|
onInput={handleInput}
|
|
215
219
|
onBinaryInput={handleBinaryInput}
|
|
216
220
|
onReady={handleReady}
|
|
217
221
|
onGridChange={handleGridChange}
|
|
218
|
-
|
|
222
|
+
onReattach={handleReattach}
|
|
219
223
|
/>
|
|
220
224
|
</div>
|
|
221
225
|
|