@kabmo-labs/kabmo 0.27.0 → 0.29.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/bunfig.toml +6 -0
- package/dist/client/index.html +2 -2
- package/dist/client/index.js +530 -493
- package/dist/client/static/js/{index-e3qh2yps.js → index-43z47ngg.js} +1178 -1034
- package/dist/client/static/js/index-naa91727.css +1 -0
- package/dist/client/static/{manifest-q6h8k9e0.webmanifest → manifest-vdvdqpre.webmanifest} +1 -0
- package/marketplace/plugins/command-runner/package.json +3 -17
- package/marketplace/plugins/command-runner/settings-schema.json +14 -0
- package/marketplace/plugins/git-forge/README.md +17 -7
- package/marketplace/plugins/git-forge/package.json +4 -30
- package/marketplace/plugins/git-forge/panel.css +16 -0
- package/marketplace/plugins/git-forge/settings-schema.json +27 -0
- package/marketplace/plugins/git-forge/src/panel/Badge.tsx +35 -22
- package/marketplace/plugins/git-forge/src/panel/Change.tsx +20 -24
- package/marketplace/plugins/git-forge/src/panel/CiBadge.tsx +16 -7
- package/marketplace/plugins/git-forge/src/panel/Credential.tsx +31 -26
- package/marketplace/plugins/git-forge/src/panel/Glyph.tsx +18 -2
- package/marketplace/plugins/git-forge/src/panel/Header.tsx +160 -96
- package/marketplace/plugins/git-forge/src/panel/ItemView.tsx +60 -44
- package/marketplace/plugins/git-forge/src/panel/List.tsx +150 -22
- package/marketplace/plugins/git-forge/src/panel/Row.tsx +11 -5
- package/marketplace/plugins/git-forge/src/panel/Sidebar.tsx +17 -15
- package/marketplace/plugins/git-forge/src/panel/Write.tsx +84 -61
- package/marketplace/plugins/git-forge/src/panel/format.test.ts +99 -0
- package/marketplace/plugins/git-forge/src/panel/format.ts +59 -16
- package/marketplace/plugins/git-forge/src/panel/index.test.tsx +109 -5
- package/marketplace/plugins/git-forge/src/panel/index.tsx +37 -4
- package/marketplace/plugins/git-forge/src/panel/use-forge.ts +17 -0
- package/marketplace/plugins/git-forge/src/panel/write.test.tsx +31 -0
- package/marketplace/plugins/session-info/package.json +2 -10
- package/marketplace/plugins/session-info/settings-schema.json +8 -0
- package/marketplace/plugins/stats/README.md +17 -5
- package/marketplace/plugins/stats/package.json +3 -23
- package/marketplace/plugins/stats/settings-schema.json +20 -0
- package/marketplace/plugins/stats/src/app.tsx +1 -1
- package/marketplace/plugins/stats/src/groups.test.ts +46 -1
- package/marketplace/plugins/stats/src/groups.ts +22 -11
- package/marketplace/plugins/stats/src/harness-leases.test.ts +84 -0
- package/marketplace/plugins/stats/src/harness-leases.ts +132 -0
- package/marketplace/plugins/stats/src/labels.test.ts +54 -1
- package/marketplace/plugins/stats/src/labels.ts +33 -7
- package/marketplace/plugins/stats/src/sampler.test.ts +61 -0
- package/marketplace/plugins/stats/src/sampler.ts +39 -5
- package/marketplace/plugins/stats/src/snapshot.ts +6 -0
- package/package.json +4 -3
- package/public/manifest.webmanifest +1 -0
- package/src/client/components/common/ComposerTextarea.test.tsx +109 -0
- package/src/client/components/common/ComposerTextarea.tsx +6 -0
- package/src/client/components/common/ReloadPageButton.test.tsx +14 -0
- package/src/client/components/common/ReloadPageButton.tsx +11 -2
- package/src/client/components/common/diagram-viewer/read-block.test.ts +71 -0
- package/src/client/components/common/diagram-viewer/read-block.ts +40 -16
- package/src/client/components/common/file-icon/index.tsx +7 -1
- package/src/client/components/common/harness-glyph/brands.ts +7 -1
- package/src/client/components/common/harness-glyph/index.tsx +18 -1
- package/src/client/components/common/image-viewer/index.tsx +37 -165
- package/src/client/components/common/picker-search/index.tsx +70 -0
- package/src/client/components/common/search-select/index.tsx +2 -7
- package/src/client/components/common/session-actions-menu/index.test.tsx +106 -0
- package/src/client/components/common/session-actions-menu/index.tsx +43 -1
- package/src/client/components/common/session-row/TrailingSlot.tsx +9 -4
- package/src/client/components/common/session-row/index.tsx +4 -0
- package/src/client/components/common/session-row/session-row.test.tsx +6 -0
- package/src/client/components/common/zoom-pan-stage/index.tsx +258 -0
- package/src/client/components/common/zoom-pan-stage/zoom-pan-stage.test.tsx +87 -0
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/ClassicView.tsx +1 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/SessionListNotice.tsx +7 -3
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +4 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +12 -1
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.test.tsx +82 -0
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +23 -3
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +1 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -1
- package/src/client/components/layout/session-sidebar/modern/index.tsx +1 -1
- package/src/client/components/layout/session-sidebar/scheduler-modal/ModelFields.tsx +202 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskForm.tsx +80 -19
- package/src/client/components/layout/session-sidebar/scheduler-modal/TaskList.tsx +29 -7
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
- package/src/client/components/layout/session-sidebar/session-list-states.test.tsx +8 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +181 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +1 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +6 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +9 -1
- package/src/client/components/settings/Modal.tsx +6 -2
- package/src/client/components/settings/Sidebar.tsx +32 -7
- package/src/client/components/settings/categories/HarnessSettings.tsx +15 -9
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +40 -15
- package/src/client/components/settings/categories/NotificationSettings.tsx +142 -64
- package/src/client/components/settings/categories/PanelPluginSettings.tsx +3 -3
- package/src/client/components/settings/categories/PluginSettings.tsx +1 -1
- package/src/client/components/settings/categories/harness-settings/ConfigForm.tsx +3 -6
- package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -0
- package/src/client/components/settings/categories/panel-plugins/GitFreshness.test.tsx +36 -0
- package/src/client/components/settings/categories/panel-plugins/InstalledList.tsx +11 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.test.tsx +1 -0
- package/src/client/components/settings/categories/panel-plugins/PluginCard.tsx +15 -1
- package/src/client/components/settings/categories/panel-plugins/Section.tsx +1 -3
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.test.tsx +165 -0
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
- package/src/client/components/settings/categories/panel-plugins/Toolbar.tsx +18 -4
- package/src/client/components/settings/categories/plugin-settings/MarketplacePane.tsx +64 -61
- package/src/client/components/settings/categories/plugin-settings/SidebarList.tsx +15 -4
- package/src/client/components/settings/groups.test.tsx +2 -2
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +24 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +8 -4
- package/src/client/components/workspace/chat-timeline/ComposerDock.tsx +34 -0
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +3 -2
- package/src/client/components/workspace/chat-timeline/IrcNotice.test.tsx +55 -0
- package/src/client/components/workspace/chat-timeline/IrcNotice.tsx +71 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.fork.test.ts +80 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +13 -4
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/TimelineBody.tsx +2 -1
- package/src/client/components/workspace/chat-timeline/chat-input/ComposerRows.tsx +8 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +9 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +4 -1
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.test.ts +19 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +32 -3
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.search.test.tsx +72 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +53 -33
- package/src/client/components/workspace/chat-timeline/chat-input/index.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/props.ts +5 -5
- package/src/client/components/workspace/chat-timeline/index.tsx +11 -5
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +1 -9
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.test.tsx +129 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +30 -12
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.test.tsx +47 -1
- package/src/client/components/workspace/chat-timeline/target-picker/WorkspacePicker.tsx +55 -5
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Wait.tsx +3 -2
- package/src/client/components/workspace/editor/FilePane.tsx +41 -4
- package/src/client/components/workspace/editor/Notices.tsx +2 -2
- package/src/client/components/workspace/editor/Pane.tsx +2 -2
- package/src/client/components/workspace/editor/Toolbar.tsx +20 -10
- package/src/client/components/workspace/editor/index.tsx +6 -10
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +5 -3
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +26 -14
- package/src/client/components/workspace/editor/viewers/CsvGrid.tsx +52 -5
- package/src/client/components/workspace/editor/viewers/DataGrid.tsx +227 -41
- package/src/client/components/workspace/editor/viewers/DrawioView.tsx +93 -0
- package/src/client/components/workspace/editor/viewers/GridRow.tsx +91 -0
- package/src/client/components/workspace/editor/viewers/GridToolbar.tsx +53 -0
- package/src/client/components/workspace/editor/viewers/SheetView.tsx +152 -57
- package/src/client/components/workspace/editor/viewers/dispatch.tsx +42 -9
- package/src/client/components/workspace/editor/viewers/drawio-pages.test.ts +80 -0
- package/src/client/components/workspace/editor/viewers/drawio-pages.ts +63 -0
- package/src/client/components/workspace/editor/viewers/grid.test.ts +296 -0
- package/src/client/components/workspace/editor/viewers/use-cell-edit.ts +64 -0
- package/src/client/components/workspace/editor/viewers/use-grid-interaction.ts +216 -0
- package/src/client/components/workspace/editor/viewers/viewers.test.ts +47 -2
- package/src/client/components/workspace/editor/viewers/workbook.ts +149 -0
- package/src/client/components/workspace/file-explorer/ArchiveModals.tsx +262 -0
- package/src/client/components/workspace/file-explorer/ContextMenu.tsx +30 -6
- package/src/client/components/workspace/file-explorer/Modals.tsx +8 -3
- package/src/client/components/workspace/file-explorer/RootOverlays.tsx +60 -0
- package/src/client/components/workspace/file-explorer/RowLabel.tsx +6 -2
- package/src/client/components/workspace/file-explorer/TreeItem.tsx +39 -49
- package/src/client/components/workspace/file-explorer/TreeItemModals.tsx +80 -0
- package/src/client/components/workspace/file-explorer/index.tsx +53 -29
- package/src/client/components/workspace/file-explorer/selection.test.tsx +109 -0
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +9 -1
- package/src/client/components/workspace/terminal-panel/focus.test.ts +70 -0
- package/src/client/components/workspace/terminal-panel/focus.ts +46 -0
- package/src/client/components/workspace/terminal-panel/index.tsx +14 -1
- package/src/client/components/workspace/terminal-panel/mount.ts +17 -9
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +158 -0
- package/src/client/components/workspace/terminal-panel/scroll-hold.ts +136 -0
- package/src/client/data/settings/omp-schema.json +169 -22
- package/src/client/glass.css +39 -14
- package/src/client/glass.test.ts +37 -0
- package/src/client/hooks/chat/composer/history.test.ts +267 -0
- package/src/client/hooks/chat/composer/history.ts +146 -0
- package/src/client/hooks/chat/composer/use-draft.ts +45 -1
- package/src/client/hooks/chat/omp/pending-sessions.waiting.test.ts +11 -10
- package/src/client/hooks/chat/omp/pending-waiting.ts +15 -7
- package/src/client/hooks/chat/omp/prompt-send.test.ts +11 -0
- package/src/client/hooks/chat/omp/prompt-send.ts +3 -0
- package/src/client/hooks/chat/timeline/actions.ts +4 -4
- package/src/client/hooks/chat/timeline/ask-frames.test.ts +54 -0
- package/src/client/hooks/chat/timeline/ask-frames.ts +29 -1
- package/src/client/hooks/chat/timeline/composer-modes.ts +13 -2
- package/src/client/hooks/chat/timeline/fork-open.ts +52 -0
- package/src/client/hooks/chat/timeline/index.ts +5 -2
- package/src/client/hooks/chat/timeline/mode-availability.ts +7 -0
- package/src/client/hooks/chat/timeline/modes-contract.ts +6 -0
- package/src/client/hooks/chat/timeline/modes-hydrate.ts +93 -0
- package/src/client/hooks/chat/timeline/modes.ts +32 -52
- package/src/client/hooks/chat/timeline/new-chat-open.ts +7 -6
- package/src/client/hooks/chat/timeline/new-chat.ts +10 -1
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +4 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.test.ts +136 -0
- package/src/client/hooks/chat/timeline/pending-session-mode.ts +69 -0
- package/src/client/hooks/chat/timeline/pending-warmup.test.ts +147 -0
- package/src/client/hooks/chat/timeline/pending-warmup.ts +62 -0
- package/src/client/hooks/chat/timeline/run-identity.test.ts +12 -0
- package/src/client/hooks/chat/timeline/run-identity.ts +4 -1
- package/src/client/hooks/chat/timeline/send-props.ts +2 -0
- package/src/client/hooks/chat/timeline/send-steer.test.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test-util.ts +1 -0
- package/src/client/hooks/chat/timeline/send.test.ts +1 -0
- package/src/client/hooks/chat/timeline/session-harness.ts +4 -0
- package/src/client/hooks/chat/timeline/timeline-rail.test.ts +34 -2
- package/src/client/hooks/chat/timeline/use-fork-session.ts +9 -22
- package/src/client/hooks/chat/timeline/user-turns.ts +31 -2
- package/src/client/hooks/chat/waiting/cancel.ts +13 -6
- package/src/client/hooks/chat/waiting/choice.ts +13 -16
- package/src/client/hooks/chat/waiting/composer-wait.ts +70 -0
- package/src/client/hooks/chat/waiting/dispatch.ts +48 -28
- package/src/client/hooks/chat/waiting/held.ts +37 -13
- package/src/client/hooks/chat/waiting/hold.test.ts +22 -0
- package/src/client/hooks/chat/waiting/hold.ts +20 -11
- package/src/client/hooks/chat/waiting/restore.test.ts +69 -0
- package/src/client/hooks/chat/waiting/restore.ts +34 -0
- package/src/client/hooks/chat/waiting/store.ts +9 -3
- package/src/client/hooks/editor/file-editor-types.ts +36 -12
- package/src/client/hooks/editor/save-bytes.ts +79 -0
- package/src/client/hooks/editor/save-file.test.ts +1 -1
- package/src/client/hooks/editor/save-file.ts +35 -8
- package/src/client/hooks/editor/target-key.ts +17 -0
- package/src/client/hooks/editor/use-disk-digest.test.ts +82 -0
- package/src/client/hooks/editor/use-disk-digest.ts +164 -0
- package/src/client/hooks/editor/use-disk-sync.ts +212 -0
- package/src/client/hooks/editor/use-file-cache.ts +113 -0
- package/src/client/hooks/editor/use-file-editor.test.ts +120 -0
- package/src/client/hooks/editor/use-file-editor.ts +143 -57
- package/src/client/hooks/editor/use-file-read.ts +45 -12
- package/src/client/hooks/editor/use-file-writes.ts +4 -4
- package/src/client/hooks/editor/use-grid-selection.ts +160 -0
- package/src/client/hooks/models/harness-catalog.ts +15 -0
- package/src/client/hooks/models/use-harness-update.test.ts +35 -2
- package/src/client/hooks/models/use-harness-update.ts +49 -10
- package/src/client/hooks/ui/notifications.ts +17 -8
- package/src/client/hooks/workspace/diff-file.test.ts +72 -0
- package/src/client/hooks/workspace/diff-file.ts +12 -6
- package/src/client/hooks/workspace/file-archive.ts +220 -0
- package/src/client/hooks/workspace/file-clipboard.test.ts +4 -4
- package/src/client/hooks/workspace/file-clipboard.ts +37 -26
- package/src/client/hooks/workspace/file-selection.test.ts +67 -0
- package/src/client/hooks/workspace/file-selection.ts +156 -0
- package/src/client/hooks/workspace/file-tree-actions-clipboard.test.ts +5 -5
- package/src/client/hooks/workspace/file-tree-actions.ts +36 -8
- package/src/client/hooks/workspace/panel-registry.ts +1 -1
- package/src/client/hooks/workspace/scheduled-tasks.ts +26 -11
- package/src/client/lib/editor/workbook-drafts.ts +42 -0
- package/src/client/lib/launch/file-handlers.ts +2 -2
- package/src/client/lib/notifications/os.test.ts +1 -30
- package/src/client/lib/notifications/os.ts +0 -15
- package/src/client/lib/notifications/platform.test.ts +68 -0
- package/src/client/lib/notifications/platform.ts +36 -0
- package/src/client/lib/scrollbar-activity.test.ts +21 -88
- package/src/client/lib/scrollbar-activity.ts +71 -73
- package/src/client/lib/scrollbar-events.ts +143 -0
- package/src/client/lib/scrollbar-input.test.ts +126 -0
- package/src/client/lib/scrollbar-probe.test-util.ts +107 -0
- package/src/client/tailwind.css +32 -1
- package/src/server/db.server.test.ts +50 -1
- package/src/server/db.server.ts +36 -3
- package/src/server/index.ts +7 -0
- package/src/server/lib/chat/prompt-history.server.test.ts +92 -0
- package/src/server/lib/chat/prompt-history.server.ts +65 -0
- package/src/server/lib/chat/schema.server.ts +35 -0
- package/src/server/lib/db/schema.ts +3 -0
- package/src/server/lib/fs/archive.test.ts +139 -0
- package/src/server/lib/fs/archive.ts +259 -0
- package/src/server/lib/fs/git-diff.test.ts +26 -1
- package/src/server/lib/fs/git-diff.ts +43 -15
- package/src/server/lib/harness/acp/client.ts +81 -87
- package/src/server/lib/harness/acp/prewarm.server.ts +237 -0
- package/src/server/lib/harness/acp/prewarm.test.ts +171 -0
- package/src/server/lib/harness/acp/prompt.test.ts +70 -1
- package/src/server/lib/harness/acp/prompt.ts +32 -1
- package/src/server/lib/harness/acp/protocol.ts +23 -0
- package/src/server/lib/harness/acp/session-handshake.test.ts +26 -0
- package/src/server/lib/harness/acp/session-handshake.ts +22 -20
- package/src/server/lib/harness/acp/session-options.ts +16 -0
- package/src/server/lib/harness/acp/session-process.ts +43 -0
- package/src/server/lib/harness/acp/session.ts +11 -12
- package/src/server/lib/harness/acp/stdio.ts +129 -0
- package/src/server/lib/harness/acp/verbs.test.ts +97 -0
- package/src/server/lib/harness/acp/verbs.ts +16 -6
- package/src/server/lib/harness/auto-probe.server.ts +4 -3
- package/src/server/lib/harness/capabilities.ts +8 -0
- package/src/server/lib/harness/config.server.ts +3 -2
- package/src/server/lib/harness/custom.server.ts +209 -0
- package/src/server/lib/harness/launch-table.ts +19 -0
- package/src/server/lib/harness/launch.ts +6 -1
- package/src/server/lib/harness/provider-entry.ts +1 -1
- package/src/server/lib/harness/provider-file.server.ts +1 -1
- package/src/server/lib/harness/provider-sources.server.ts +2 -1
- package/src/server/lib/harness/provider-write.server.ts +2 -1
- package/src/server/lib/harness/register.server.ts +8 -1
- package/src/server/lib/harness/schema.server.ts +21 -0
- package/src/server/lib/harness/session-lease.server.test.ts +99 -0
- package/src/server/lib/harness/session-lease.server.ts +193 -0
- package/src/server/lib/harness/session-store.server.test.ts +8 -8
- package/src/server/lib/harness/session-store.server.ts +25 -4
- package/src/server/lib/harness/session-title.server.ts +12 -2
- package/src/server/lib/harness/spawn.server.ts +123 -20
- package/src/server/lib/harness/update-job-store.ts +12 -0
- package/src/server/lib/harness/update-queue.server.ts +18 -13
- package/src/server/lib/lifecycle/after-listen.ts +12 -1
- package/src/server/lib/lifecycle/paths.ts +19 -1
- package/src/server/lib/mcp/registry.server.ts +155 -0
- package/src/server/lib/mcp/registry.test.ts +169 -0
- package/src/server/lib/mcp/store.server.ts +38 -0
- package/src/server/lib/omp/rpc/frame-fold-contract.ts +59 -0
- package/src/server/lib/omp/rpc/frame-fold-frames.test.ts +64 -1
- package/src/server/lib/omp/rpc/frame-fold-host.test-util.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold-signals.test.ts +5 -1
- package/src/server/lib/omp/rpc/frame-fold.test.ts +7 -2
- package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
- package/src/server/lib/omp/rpc/lifecycle.test.ts +4 -0
- package/src/server/lib/omp/rpc/prewarm-pool.ts +19 -5
- package/src/server/lib/omp/rpc/run-model.test.ts +116 -0
- package/src/server/lib/omp/rpc/run-model.ts +4 -2
- package/src/server/lib/omp/session/auto-title.server.test.ts +4 -0
- package/src/server/lib/omp/session/delete.server.ts +1 -0
- package/src/server/lib/omp/session/goal-driver.test.ts +5 -1
- package/src/server/lib/omp/session/goal-settings.test.ts +5 -1
- package/src/server/lib/omp/session/sidebar-data.harness.test.ts +6 -3
- package/src/server/lib/omp/session/standby.server.ts +13 -2
- package/src/server/lib/panels/auto-update.server.test.ts +5 -2
- package/src/server/lib/panels/git-update.server.test.ts +5 -2
- package/src/server/lib/panels/install.server.test.ts +5 -2
- package/src/server/lib/panels/manifest.test.ts +47 -1
- package/src/server/lib/panels/manifest.ts +19 -0
- package/src/server/lib/panels/registry.server.ts +19 -2
- package/src/server/lib/panels/remove.server.test.ts +5 -2
- package/src/server/lib/panels/scan.server.ts +26 -2
- package/src/server/lib/panels/settings-schema.server.ts +72 -0
- package/src/server/lib/plugins/background.server.ts +21 -3
- package/src/server/lib/plugins/background.test.ts +13 -0
- package/src/server/lib/plugins/loader.server.ts +35 -51
- package/src/server/lib/plugins/mcp.server.ts +100 -0
- package/src/server/lib/plugins/mcp.test.ts +75 -0
- package/src/server/lib/plugins/schedule-runner.server.ts +153 -0
- package/src/server/lib/plugins/schedule-runner.test.ts +186 -0
- package/src/server/lib/plugins/schedule-store.server.ts +107 -0
- package/src/server/lib/plugins/schema.server.ts +8 -0
- package/src/server/lib/plugins/settings.server.ts +56 -19
- package/src/server/lib/plugins/shutdown.server.ts +58 -0
- package/src/server/lib/plugins/shutdown.test.ts +28 -3
- package/src/server/lib/realtime/topics/global.server.ts +5 -1
- package/src/server/lib/schedule/rows.server.ts +9 -0
- package/src/server/lib/schedule/runtime.server.test.ts +91 -0
- package/src/server/lib/schedule/runtime.server.ts +101 -23
- package/src/server/lib/schedule/schema.server.ts +15 -0
- package/src/server/lib/schedule/store.server.test.ts +34 -0
- package/src/server/lib/schedule/store.server.ts +33 -9
- package/src/server/lib/sessions/fork.server.test.ts +47 -0
- package/src/server/lib/sessions/fork.server.ts +17 -1
- package/src/server/lib/sessions/spawn.server.ts +2 -2
- package/src/server/lib/waiting/runtime.server.test.ts +48 -0
- package/src/server/lib/waiting/runtime.server.ts +22 -0
- package/src/server/lib/waiting/schema.server.ts +8 -0
- package/src/server/lib/waiting/store.server.test.ts +14 -0
- package/src/server/lib/waiting/store.server.ts +6 -2
- package/src/server/routes/agent/command-resume.test.ts +9 -4
- package/src/server/routes/agent/command.ts +11 -0
- package/src/server/routes/agent/new-mode.test.ts +40 -0
- package/src/server/routes/agent/new.ts +36 -10
- package/src/server/routes/agent/prewarm.ts +48 -7
- package/src/server/routes/chat/index.ts +5 -0
- package/src/server/routes/chat/prompt-history.test.ts +67 -0
- package/src/server/routes/chat/prompt-history.ts +31 -0
- package/src/server/routes/chat/stream.test.ts +21 -0
- package/src/server/routes/chat/stream.ts +5 -0
- package/src/server/routes/fs/action-archive.test.ts +128 -0
- package/src/server/routes/fs/action-bulk.ts +106 -0
- package/src/server/routes/fs/action-save-bytes.test.ts +59 -0
- package/src/server/routes/fs/action-transfer.test.ts +26 -0
- package/src/server/routes/fs/action.ts +100 -12
- package/src/server/routes/fs/archive.ts +20 -0
- package/src/server/routes/fs/digest.test.ts +100 -0
- package/src/server/routes/fs/digest.ts +106 -0
- package/src/server/routes/fs/grant.test.ts +5 -2
- package/src/server/routes/fs/index.ts +4 -0
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/fs/scope.test.ts +6 -2
- package/src/server/routes/harness/custom.test.ts +131 -0
- package/src/server/routes/harness/import-action.ts +3 -3
- package/src/server/routes/harness/root.ts +47 -9
- package/src/server/routes/harness/summary.test.ts +50 -0
- package/src/server/routes/harness/update-status.ts +41 -2
- package/src/server/routes/harness/update.test.ts +56 -2
- package/src/server/routes/harness/update.ts +2 -2
- package/src/server/routes/panels/bindings.ts +2 -0
- package/src/server/routes/panels/settings.test.ts +165 -0
- package/src/server/routes/panels/settings.ts +106 -0
- package/src/server/routes/schedule/body.ts +14 -0
- package/src/server/routes/schedule/index.ts +28 -4
- package/src/server/routes/sessions/delete.test.ts +4 -0
- package/src/server/routes/settings/mcp.ts +9 -26
- package/src/server/routes/waiting/index.ts +21 -2
- package/src/server/routes/waiting/routes.test.ts +21 -0
- package/src/shared/lib/chat/ask-form/index.ts +39 -31
- package/src/shared/lib/chat/ask-form/labels.ts +46 -0
- package/src/shared/lib/chat/ask-form/tokens.ts +11 -2
- package/src/shared/lib/chat/ask-form.test.ts +57 -0
- package/src/shared/lib/chat/ask-questions.ts +31 -0
- package/src/shared/lib/chat/composer/delegation.ts +3 -3
- package/src/shared/lib/chat/composer/history.test.ts +67 -0
- package/src/shared/lib/chat/composer/history.ts +61 -0
- package/src/shared/lib/chat/irc-notice.ts +42 -0
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +99 -0
- package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
- package/src/shared/lib/chat/todo/parser.ts +6 -4
- package/src/shared/lib/fs/archive.test.ts +101 -0
- package/src/shared/lib/fs/archive.ts +191 -0
- package/src/shared/lib/fs/clipboard.test.ts +32 -7
- package/src/shared/lib/fs/clipboard.ts +59 -14
- package/src/shared/lib/fs/content-hash.ts +29 -0
- package/src/shared/lib/fs/csv.test.ts +50 -0
- package/src/shared/lib/fs/csv.ts +40 -0
- package/src/shared/lib/fs/document-kind.test.ts +13 -6
- package/src/shared/lib/fs/document-kind.ts +18 -6
- package/src/shared/lib/fs/file-kind-classify.test.ts +4 -0
- package/src/shared/lib/fs/file-kind.test.ts +2 -7
- package/src/shared/lib/fs/file-kind.ts +4 -2
- package/src/shared/lib/fs/grid-edit.test.ts +24 -0
- package/src/shared/lib/fs/grid-edit.ts +29 -0
- package/src/shared/lib/fs/grid-selection.test.ts +137 -0
- package/src/shared/lib/fs/grid-selection.ts +138 -0
- package/src/shared/lib/harness/brand-color.ts +5 -0
- package/src/shared/lib/harness/catalog.test.ts +22 -0
- package/src/shared/lib/harness/catalog.ts +60 -7
- package/src/shared/lib/harness/config-fields.test.ts +25 -0
- package/src/shared/lib/harness/config-fields.ts +33 -3
- package/src/shared/lib/harness/dialects.ts +1 -1
- package/src/shared/lib/harness/fork.ts +60 -0
- package/src/shared/lib/harness/mcp-facts.test.ts +30 -0
- package/src/shared/lib/harness/mcp-facts.ts +69 -0
- package/src/shared/lib/harness/menu.test.ts +16 -1
- package/src/shared/lib/harness/menu.ts +2 -2
- package/src/shared/lib/harness/provider-contracts.ts +109 -0
- package/src/shared/lib/harness/provider-facts.test.ts +2 -1
- package/src/shared/lib/harness/provider-facts.ts +24 -115
- package/src/shared/lib/harness/provider-lookup.ts +37 -0
- package/src/shared/lib/harness/providers.ts +2 -1
- package/src/shared/lib/harness/rewind.ts +6 -6
- package/src/shared/lib/harness/session-modes.ts +31 -0
- package/src/shared/lib/harness/transcript.test.ts +29 -0
- package/src/shared/lib/harness/transcript.ts +19 -0
- package/src/shared/lib/harness/updates.ts +10 -0
- package/src/shared/lib/notifications/settings.test.ts +21 -0
- package/src/shared/lib/notifications/settings.ts +24 -0
- package/src/shared/lib/omp/session/mapper.test.ts +31 -0
- package/src/shared/lib/omp/session/mapper.ts +17 -0
- package/src/shared/lib/omp/session/messages-map-notice.test.ts +68 -0
- package/src/shared/lib/omp/session/messages-map.test.ts +1 -35
- package/src/shared/lib/omp/session/messages-map.ts +17 -0
- package/src/shared/lib/omp/session/prewarm.test.ts +28 -4
- package/src/shared/lib/omp/session/prewarm.ts +25 -6
- package/src/shared/lib/omp/session/stream-state.server.test.ts +25 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +8 -4
- package/src/shared/lib/omp/session/wait.ts +10 -1
- package/src/shared/lib/panels/capabilities.test.ts +1 -1
- package/src/shared/lib/panels/capabilities.ts +3 -0
- package/src/shared/lib/plugins/settings.ts +22 -0
- package/src/shared/lib/schedule/parse.test.ts +48 -0
- package/src/shared/lib/schedule/parse.ts +69 -45
- package/src/shared/lib/schedule/timezone.ts +128 -0
- package/src/shared/lib/settings/defaults.ts +2 -0
- package/src/shared/lib/settings/sections.ts +8 -4
- package/src/shared/lib/ui/picker-filter.test.ts +23 -0
- package/src/shared/lib/ui/picker-filter.ts +20 -0
- package/src/shared/lib/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/types/chat.ts +4 -0
- package/src/shared/types/harness.ts +12 -1
- package/src/shared/types/omp/agent.ts +6 -0
- package/src/shared/types/omp/session.ts +18 -0
- package/src/shared/types/panels-registry.ts +3 -3
- package/src/shared/types/panels.ts +4 -2
- package/src/shared/types/schedule.ts +13 -0
- package/src/shared/types/settings/state.ts +18 -7
- package/src/shared/types/todo.ts +3 -1
- package/src/shared/types/waiting.ts +9 -0
- package/src/test-support/file-actions.test-util.ts +4 -0
- package/src/test-support/file-archive.test-util.ts +41 -0
- package/src/test-support/file-clipboard.test-util.ts +9 -6
- package/src/test-support/file-editor.test-util.ts +70 -5
- package/src/test-support/harness-table.test-util.ts +2 -0
- package/src/test-support/preload.ts +46 -0
- package/dist/client/static/js/index-32rpkj6b.css +0 -1
- package/src/client/hooks/editor/use-external-change-notice.ts +0 -71
- package/src/client/hooks/editor/use-external-change.test.ts +0 -88
- package/src/client/hooks/editor/use-external-change.ts +0 -146
|
@@ -94,7 +94,7 @@ describe('saveEditorFile — the request it builds', () => {
|
|
|
94
94
|
const writes = stubWrite({ ok: true, body: { success: true } });
|
|
95
95
|
const outcome = await saveEditorFile({ path: 'src/a.ts', root: '/repo' }, 'const a = 1;\n', 'lf', { interactive: false });
|
|
96
96
|
|
|
97
|
-
expect(outcome).toEqual({ status: 'written' });
|
|
97
|
+
expect(outcome).toEqual({ status: 'written', written: { mtimeMs: null, hash: null } });
|
|
98
98
|
expect(writes.length).toBe(1);
|
|
99
99
|
expect(writes[0].url).toBe('/api/fs/action');
|
|
100
100
|
expect(writes[0].method).toBe('POST');
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
import type { LineEnding } from '@/shared/lib/code/line-endings';
|
|
28
28
|
import { writeThroughHandle, type HandleWriteResult } from '@/client/lib/launch/file-handlers';
|
|
29
|
+
import { contentHash } from '@/shared/lib/fs/content-hash';
|
|
29
30
|
|
|
30
31
|
interface SavableFile {
|
|
31
32
|
path?: string;
|
|
@@ -34,9 +35,23 @@ interface SavableFile {
|
|
|
34
35
|
handleId?: string;
|
|
35
36
|
}
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* What the disk holds after a save landed.
|
|
40
|
+
*
|
|
41
|
+
* Both facts belong to the WRITTEN bytes, not to the buffer: the server rebuilt
|
|
42
|
+
* them from the buffer's LF text and the file's own ending, so it is the only
|
|
43
|
+
* place that can say what the disk now contains. The mtime is the next save's
|
|
44
|
+
* conflict base; the hash is the auto-refresh watcher's baseline, and without it
|
|
45
|
+
* the watcher would report the user's own save as an external change.
|
|
46
|
+
*/
|
|
47
|
+
export interface WrittenFile {
|
|
48
|
+
mtimeMs: number | null;
|
|
49
|
+
hash: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
/** What a save attempt answers. */
|
|
38
53
|
export type SaveOutcome =
|
|
39
|
-
| { status: 'written' }
|
|
54
|
+
| { status: 'written'; written: WrittenFile }
|
|
40
55
|
/** The buffer is behind the disk copy: `diskMtimeMs` is what is there now. */
|
|
41
56
|
| { status: 'conflict'; diskMtimeMs: number | null }
|
|
42
57
|
/** The write was refused for a reason that is not a conflict (a 4xx/5xx, a drop). */
|
|
@@ -50,6 +65,8 @@ interface SaveResponse {
|
|
|
50
65
|
error?: unknown;
|
|
51
66
|
/** Present on a `409`: the mtime the file holds now. */
|
|
52
67
|
mtimeMs?: unknown;
|
|
68
|
+
/** Present on success: the content hash of the bytes just written. */
|
|
69
|
+
hash?: unknown;
|
|
53
70
|
conflict?: unknown;
|
|
54
71
|
}
|
|
55
72
|
|
|
@@ -82,12 +99,14 @@ export async function saveEditorFile(
|
|
|
82
99
|
options: { interactive: boolean; baseMtimeMs?: number | null },
|
|
83
100
|
): Promise<SaveOutcome> {
|
|
84
101
|
if (file.handleId) {
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
102
|
+
const diskText = eol === 'crlf' ? lfText.replace(/\n/g, '\r\n') : lfText;
|
|
103
|
+
const result: HandleWriteResult = await writeThroughHandle(file.handleId, diskText, {
|
|
104
|
+
interactive: options.interactive,
|
|
105
|
+
});
|
|
106
|
+
// A handle write never reaches the server, so the digest is computed here from
|
|
107
|
+
// the exact bytes handed over — the same UTF-8 hash every other producer uses.
|
|
108
|
+
// No mtime: there is no server path to stat.
|
|
109
|
+
if (result === 'written') return { status: 'written', written: { mtimeMs: null, hash: await contentHash(diskText) } };
|
|
91
110
|
if (result === 'needs-permission') return { status: 'needs-permission' };
|
|
92
111
|
return { status: 'failed' };
|
|
93
112
|
}
|
|
@@ -111,7 +130,15 @@ export async function saveEditorFile(
|
|
|
111
130
|
const diskMtimeMs = typeof data?.mtimeMs === 'number' ? data.mtimeMs : null;
|
|
112
131
|
return { status: 'conflict', diskMtimeMs };
|
|
113
132
|
}
|
|
114
|
-
if (res.ok && data?.success)
|
|
133
|
+
if (res.ok && data?.success) {
|
|
134
|
+
return {
|
|
135
|
+
status: 'written',
|
|
136
|
+
written: {
|
|
137
|
+
mtimeMs: typeof data.mtimeMs === 'number' ? data.mtimeMs : null,
|
|
138
|
+
hash: typeof data.hash === 'string' ? data.hash : null,
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
115
142
|
return { status: 'failed' };
|
|
116
143
|
} catch {
|
|
117
144
|
return { status: 'failed' };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The key a target's buffer is cached under.
|
|
10
|
+
*
|
|
11
|
+
* One rule for every hook that caches by file: the read path, the write path, the
|
|
12
|
+
* conflict machine and the disk watcher all have to agree, or a reload clears a
|
|
13
|
+
* key the read never wrote.
|
|
14
|
+
*/
|
|
15
|
+
export function editorTargetKey(target: Pick<FileEditorTarget, 'id' | 'path' | 'name'>): string {
|
|
16
|
+
return String(target.id ?? target.path ?? target.name);
|
|
17
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The disk-digest probe the editor's auto-refresh runs.
|
|
8
|
+
*
|
|
9
|
+
* Three rules, and each is a silent failure if broken:
|
|
10
|
+
*
|
|
11
|
+
* - a REFUSED probe is not a verdict — a dropped request must never be read as
|
|
12
|
+
* "the disk changed" and replace a buffer;
|
|
13
|
+
* - a file that is GONE is the tab strip's strike-through, not a change;
|
|
14
|
+
* - a file with no hash (too large for the editor, unreadable) has nothing to
|
|
15
|
+
* compare, so it is no verdict either.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
19
|
+
|
|
20
|
+
import { probeDiskDigest } from '@/client/hooks/editor/use-disk-digest';
|
|
21
|
+
|
|
22
|
+
const nativeFetch = Bun.fetch;
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
globalThis.fetch = nativeFetch;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** Answer the probe with `body`, or refuse it. */
|
|
29
|
+
function stub(body: unknown, ok = true): void {
|
|
30
|
+
globalThis.fetch = (async () => ({
|
|
31
|
+
ok,
|
|
32
|
+
json: async () => body,
|
|
33
|
+
})) as unknown as typeof fetch;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
describe('probeDiskDigest', () => {
|
|
37
|
+
test('a file with a hash is a verdict carrying both facts', async () => {
|
|
38
|
+
stub({ exists: true, mtimeMs: 100, hash: 'abc' });
|
|
39
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toEqual({ hash: 'abc', mtimeMs: 100 });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('a missing file is not a change — the tab strip owns that fact', async () => {
|
|
43
|
+
stub({ exists: false, mtimeMs: null, hash: null });
|
|
44
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('gone');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('a file with no hash is no verdict', async () => {
|
|
48
|
+
stub({ exists: true, mtimeMs: 100, hash: null });
|
|
49
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('unknown');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('a refused probe is NO VERDICT, never a change', async () => {
|
|
53
|
+
stub({ exists: true, mtimeMs: 100, hash: 'abc' }, false);
|
|
54
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('unknown');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('a malformed body is no verdict', async () => {
|
|
58
|
+
stub({ exists: 'yes' });
|
|
59
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('unknown');
|
|
60
|
+
stub(null);
|
|
61
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('unknown');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a dropped connection is no verdict', async () => {
|
|
65
|
+
globalThis.fetch = (async () => {
|
|
66
|
+
throw new Error('offline');
|
|
67
|
+
}) as unknown as typeof fetch;
|
|
68
|
+
expect(await probeDiskDigest('/a.ts', null, null)).toBe('unknown');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('the scope travels with the probe, so a nested repo is read from its own tree', async () => {
|
|
72
|
+
const seen: string[] = [];
|
|
73
|
+
globalThis.fetch = (async (input: unknown) => {
|
|
74
|
+
seen.push(String(input));
|
|
75
|
+
return { ok: true, json: async () => ({ exists: true, mtimeMs: 100, hash: 'abc' }) };
|
|
76
|
+
}) as unknown as typeof fetch;
|
|
77
|
+
await probeDiskDigest('a.ts', '/repo', 'nested');
|
|
78
|
+
expect(seen[0]).toContain('/api/fs/digest');
|
|
79
|
+
expect(seen[0]).toContain('root=%2Frepo');
|
|
80
|
+
expect(seen[0]).toContain('repo=nested');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's disk watcher: the periodic question "are the bytes behind this
|
|
8
|
+
* tab still the ones the buffer holds?".
|
|
9
|
+
*
|
|
10
|
+
* It asks `/api/fs/digest`, which answers with the file's CONTENT hash, and it
|
|
11
|
+
* compares that against the hash the buffer was read at (and, for a write, the
|
|
12
|
+
* hash of the bytes that write landed). Two consequences, both deliberate:
|
|
13
|
+
*
|
|
14
|
+
* - a file rewritten with identical bytes (`git checkout` of the revision
|
|
15
|
+
* already open, a formatter that changes nothing, a `touch`) does NOT reach
|
|
16
|
+
* the buffer, because nothing about the document changed. The caller hears
|
|
17
|
+
* `onUnchanged` instead and may adopt the moved mtime — the save path's
|
|
18
|
+
* conflict base is still an mtime, so a touched file would otherwise refuse
|
|
19
|
+
* the next save over a change that never happened;
|
|
20
|
+
* - a file whose mtime did not move but whose bytes did (two writes inside one
|
|
21
|
+
* filesystem clock tick) is still seen, which an mtime poll cannot do.
|
|
22
|
+
*
|
|
23
|
+
* **Polling, not a filesystem watch**: the server has no watcher to subscribe
|
|
24
|
+
* to, and this app runs on the same machine as the tree, so one scoped request
|
|
25
|
+
* every few seconds is cheaper than a watch per open tab. The probe is skipped
|
|
26
|
+
* while the page is hidden and never overlaps itself. A workspace refresh (`revision`)
|
|
27
|
+
* and the window regaining focus both ask immediately, so the common case —
|
|
28
|
+
* the user alt-tabs back after an external edit — does not wait for the next tick.
|
|
29
|
+
*
|
|
30
|
+
* A `gone` or `unknown` verdict reports NOTHING: a deleted file belongs to
|
|
31
|
+
* `useMissingFiles` (which owns the struck-through tab), and a dropped request
|
|
32
|
+
* must not be read as "the disk changed".
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* How often an open tab asks whether its file moved.
|
|
39
|
+
*
|
|
40
|
+
* 3s is chosen against what the answer costs: the server hashes the file (cached
|
|
41
|
+
* against its stat, so an unchanged file costs one `stat`), and a text file the
|
|
42
|
+
* editor opens is at most 32 MiB. A shorter interval buys nothing — the user is
|
|
43
|
+
* coming back from another window, and focus asks immediately — while a longer
|
|
44
|
+
* one lets a tool call and the next keystroke race visibly.
|
|
45
|
+
*/
|
|
46
|
+
export const DISK_DIGEST_INTERVAL_MS = 3000;
|
|
47
|
+
|
|
48
|
+
/** What the disk says about the file behind a tab. */
|
|
49
|
+
export interface DiskDigest {
|
|
50
|
+
/** The file's content hash — the value every producer in the app agrees on. */
|
|
51
|
+
hash: string;
|
|
52
|
+
/** Rounded to a whole millisecond, exactly as the read route reports it. */
|
|
53
|
+
mtimeMs: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Ask the server for the digest of `path`, inside the tab's own scope.
|
|
58
|
+
*
|
|
59
|
+
* Exported because the three "no verdict" answers are the whole rule and are
|
|
60
|
+
* only testable without a mounted component.
|
|
61
|
+
*/
|
|
62
|
+
export async function probeDiskDigest(
|
|
63
|
+
path: string,
|
|
64
|
+
root: string | null,
|
|
65
|
+
repo: string | null,
|
|
66
|
+
): Promise<DiskDigest | 'gone' | 'unknown'> {
|
|
67
|
+
const params = new URLSearchParams({ path });
|
|
68
|
+
if (root) params.set('root', root);
|
|
69
|
+
if (repo && repo !== '.') params.set('repo', repo);
|
|
70
|
+
try {
|
|
71
|
+
const res = await fetch(`/api/fs/digest?${params.toString()}`);
|
|
72
|
+
const data = (await res.json().catch(() => null)) as
|
|
73
|
+
| { exists?: unknown; mtimeMs?: unknown; hash?: unknown }
|
|
74
|
+
| null;
|
|
75
|
+
if (!res.ok || !data || typeof data.exists !== 'boolean') return 'unknown';
|
|
76
|
+
if (data.exists === false) return 'gone';
|
|
77
|
+
// No hash is a file too large for the editor, or an unreadable one: there is
|
|
78
|
+
// nothing to compare, so there is no verdict.
|
|
79
|
+
if (typeof data.hash !== 'string' || typeof data.mtimeMs !== 'number') return 'unknown';
|
|
80
|
+
return { hash: data.hash, mtimeMs: data.mtimeMs };
|
|
81
|
+
} catch {
|
|
82
|
+
return 'unknown';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
interface UseDiskDigestOptions {
|
|
87
|
+
/** The file the tab names; `null` disables the watcher. */
|
|
88
|
+
path: string | null;
|
|
89
|
+
root?: string | null;
|
|
90
|
+
repo?: string | null;
|
|
91
|
+
/** The hash the buffer was read at (or the one its last save wrote). */
|
|
92
|
+
baseHash: string | null;
|
|
93
|
+
/** Bumped whenever something may have written the tree — asks immediately. */
|
|
94
|
+
revision: number;
|
|
95
|
+
/** The bytes on disk are the ones the buffer holds; only the clock moved. */
|
|
96
|
+
onUnchanged: (mtimeMs: number) => void;
|
|
97
|
+
/** The disk bytes differ from the buffer's fingerprint. */
|
|
98
|
+
onChanged: (digest: DiskDigest) => void;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function useDiskDigest({
|
|
102
|
+
path,
|
|
103
|
+
root = null,
|
|
104
|
+
repo = null,
|
|
105
|
+
baseHash,
|
|
106
|
+
revision,
|
|
107
|
+
onUnchanged,
|
|
108
|
+
onChanged,
|
|
109
|
+
}: UseDiskDigestOptions): void {
|
|
110
|
+
// The callbacks are rebuilt whenever the caller's state moves (and a new
|
|
111
|
+
// `baseHash` restarts this effect anyway), so they are read through refs: a
|
|
112
|
+
// dependency on their identity would tear the interval down on every keystroke.
|
|
113
|
+
const unchangedRef = useRef(onUnchanged);
|
|
114
|
+
unchangedRef.current = onUnchanged;
|
|
115
|
+
const changedRef = useRef(onChanged);
|
|
116
|
+
changedRef.current = onChanged;
|
|
117
|
+
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
// No baseline means no comparison: an inline attachment, a handle-backed
|
|
120
|
+
// tab, a byte viewer or a file the read refused all land here.
|
|
121
|
+
if (!path || baseHash === null) return;
|
|
122
|
+
|
|
123
|
+
let cancelled = false;
|
|
124
|
+
let inFlight = false;
|
|
125
|
+
/** The hash already reported, so one external write fires once. */
|
|
126
|
+
let reported: string | null = null;
|
|
127
|
+
|
|
128
|
+
const check = async () => {
|
|
129
|
+
if (cancelled || inFlight || document.hidden) return;
|
|
130
|
+
inFlight = true;
|
|
131
|
+
try {
|
|
132
|
+
const verdict = await probeDiskDigest(path, root, repo);
|
|
133
|
+
if (cancelled || verdict === 'unknown' || verdict === 'gone') return;
|
|
134
|
+
if (verdict.hash === baseHash) {
|
|
135
|
+
unchangedRef.current(verdict.mtimeMs);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (reported === verdict.hash) return;
|
|
139
|
+
reported = verdict.hash;
|
|
140
|
+
changedRef.current(verdict);
|
|
141
|
+
} finally {
|
|
142
|
+
inFlight = false;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const timer = window.setInterval(() => void check(), DISK_DIGEST_INTERVAL_MS);
|
|
147
|
+
// A workspace refresh is a write somewhere, and coming back to the window is
|
|
148
|
+
// the moment the user expects the tab to be current.
|
|
149
|
+
void check();
|
|
150
|
+
const onFocus = () => void check();
|
|
151
|
+
const onVisibility = () => {
|
|
152
|
+
if (!document.hidden) void check();
|
|
153
|
+
};
|
|
154
|
+
window.addEventListener('focus', onFocus);
|
|
155
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
cancelled = true;
|
|
159
|
+
window.clearInterval(timer);
|
|
160
|
+
window.removeEventListener('focus', onFocus);
|
|
161
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
162
|
+
};
|
|
163
|
+
}, [path, root, repo, baseHash, revision]);
|
|
164
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's disk SYNCHRONISATION: the watcher, the two answers it produces,
|
|
8
|
+
* and the manual Reload.
|
|
9
|
+
*
|
|
10
|
+
* Split from `useFileEditor` because it is a self-contained cluster — one poll,
|
|
11
|
+
* one verdict, one counter the panel renders — and it is the piece with a rule
|
|
12
|
+
* worth naming:
|
|
13
|
+
*
|
|
14
|
+
* - **A CLEAN buffer follows the disk.** Nothing of the user's is at stake, so a
|
|
15
|
+
* file changed by an agent, a `git checkout` or another editor is re-read
|
|
16
|
+
* without asking. The bytes stay on screen until the response lands.
|
|
17
|
+
* - **A DIRTY buffer never does.** Its edits are the user's, and only the user
|
|
18
|
+
* can say which side wins, so the hook reports a revision instead and the
|
|
19
|
+
* panel asks (the external-change strip).
|
|
20
|
+
* - **A file that still hashes the same is not a change.** Its mtime may have
|
|
21
|
+
* moved (`touch`, a no-op formatter, a checkout of the revision already open);
|
|
22
|
+
* that only means the save path's conflict base must move with it, or the next
|
|
23
|
+
* save would be refused over a change that never happened.
|
|
24
|
+
*
|
|
25
|
+
* Reload is the manual counterpart: it re-reads even a clean buffer (the answer
|
|
26
|
+
* to "read it again"), and it discards a dirty one — including the debounced
|
|
27
|
+
* write sitting behind those edits, which would otherwise land after the read
|
|
28
|
+
* and put the discarded text back on disk.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
32
|
+
import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
|
|
33
|
+
import type { PendingWrite } from '@/client/hooks/editor/use-file-writes';
|
|
34
|
+
import { useDiskDigest, type DiskDigest } from '@/client/hooks/editor/use-disk-digest';
|
|
35
|
+
import { editorTargetKey } from '@/client/hooks/editor/target-key';
|
|
36
|
+
import { isProbeableTab } from '@/client/hooks/workspace/missing-files';
|
|
37
|
+
|
|
38
|
+
/** A mutable ref, typed structurally — every ref here is read without a null check. */
|
|
39
|
+
interface LiveRef<T> {
|
|
40
|
+
current: T;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface DiskSyncDeps {
|
|
44
|
+
/** The active buffer's key, or `''` when nothing is open. */
|
|
45
|
+
key: string;
|
|
46
|
+
target: FileEditorTarget | null;
|
|
47
|
+
/** The hash the ACTIVE buffer was read at (or the one its last save wrote). */
|
|
48
|
+
baseHash: string | null;
|
|
49
|
+
/** Bumped by `reset()`/a save; also what makes the watcher ask immediately. */
|
|
50
|
+
revision: number;
|
|
51
|
+
hashesRef: LiveRef<Record<string, string | null>>;
|
|
52
|
+
mtimesRef: LiveRef<Record<string, number | null>>;
|
|
53
|
+
contentsRef: LiveRef<Record<string, string>>;
|
|
54
|
+
baselinesRef: LiveRef<Record<string, string>>;
|
|
55
|
+
pendingRef: LiveRef<PendingWrite | null>;
|
|
56
|
+
/** Reads on their way — a verdict must not queue a second one. */
|
|
57
|
+
readingRef: LiveRef<number>;
|
|
58
|
+
loadedRef: LiveRef<Set<string>>;
|
|
59
|
+
/** Forces the read effect to re-run for the active file. */
|
|
60
|
+
bumpRevision: () => void;
|
|
61
|
+
/** Take the disk's mtime as this buffer's base, writing nothing. */
|
|
62
|
+
adoptDiskMtime: (diskMtimeMs: number) => void;
|
|
63
|
+
/** Drop one buffer's conflict entry without resolving anything. */
|
|
64
|
+
clearConflict: (fileKey: string) => void;
|
|
65
|
+
/** Discard the active buffer and re-read it. */
|
|
66
|
+
reloadDiscardingEdits: () => void;
|
|
67
|
+
/** Drop the debounced write for a key. */
|
|
68
|
+
discardPendingWrite: (fileKey: string) => void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface DiskSync {
|
|
72
|
+
/**
|
|
73
|
+
* The disk bytes differ from a buffer that HAS edits, or null.
|
|
74
|
+
*
|
|
75
|
+
* Nothing was replaced: the panel renders this as the external-change strip, so
|
|
76
|
+
* the user chooses between the two copies. Cleared by itself as soon as the
|
|
77
|
+
* buffer and the disk agree again (a reload, a save, a "Keep mine" write).
|
|
78
|
+
*/
|
|
79
|
+
diskChange: DiskDigest | null;
|
|
80
|
+
reloadFromDisk: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Answer the strip with the user's buffer: adopt the disk's mtime and stop
|
|
83
|
+
* asking about THIS change.
|
|
84
|
+
*
|
|
85
|
+
* Nothing is written — the buffer stays dirty and the autosave owns the write —
|
|
86
|
+
* and the accepted hash is remembered, so the watcher does not raise the same
|
|
87
|
+
* strip again on its next poll. A LATER change is a new hash and asks again.
|
|
88
|
+
*/
|
|
89
|
+
keepMineAgainstDisk: () => void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function useDiskSync({
|
|
93
|
+
key,
|
|
94
|
+
target,
|
|
95
|
+
baseHash,
|
|
96
|
+
revision,
|
|
97
|
+
hashesRef,
|
|
98
|
+
mtimesRef,
|
|
99
|
+
contentsRef,
|
|
100
|
+
baselinesRef,
|
|
101
|
+
pendingRef,
|
|
102
|
+
readingRef,
|
|
103
|
+
loadedRef,
|
|
104
|
+
bumpRevision,
|
|
105
|
+
adoptDiskMtime,
|
|
106
|
+
clearConflict,
|
|
107
|
+
reloadDiscardingEdits,
|
|
108
|
+
discardPendingWrite,
|
|
109
|
+
}: DiskSyncDeps): DiskSync {
|
|
110
|
+
const [diskChange, setDiskChange] = useState<DiskDigest | null>(null);
|
|
111
|
+
/**
|
|
112
|
+
* The hash the user answered "Keep mine" about, so the same change is not
|
|
113
|
+
* reported again on the next poll.
|
|
114
|
+
*
|
|
115
|
+
* A ref rather than state: the watcher reads it from a callback that must stay
|
|
116
|
+
* stable, and dismissing a strip is not something the UI derives from.
|
|
117
|
+
*/
|
|
118
|
+
const dismissedRef = useRef<string | null>(null);
|
|
119
|
+
|
|
120
|
+
// The verdict describes the tab it was made for; switching tabs must not carry
|
|
121
|
+
// a stale "changed on disk" strip onto another file.
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
setDiskChange(null);
|
|
124
|
+
dismissedRef.current = null;
|
|
125
|
+
}, [key]);
|
|
126
|
+
|
|
127
|
+
const adoptUnchangedMtime = useCallback(
|
|
128
|
+
(diskMtimeMs: number) => {
|
|
129
|
+
if (!key) return;
|
|
130
|
+
// The bytes are the ones this buffer holds; only the clock moved. Adopting
|
|
131
|
+
// the mtime keeps the next save from being refused over nothing, and it is
|
|
132
|
+
// also the answer to a strip the user has already seen: the disk is not
|
|
133
|
+
// ahead of the buffer, so there is nothing left to ask.
|
|
134
|
+
if (mtimesRef.current[key] !== diskMtimeMs) adoptDiskMtime(diskMtimeMs);
|
|
135
|
+
setDiskChange(null);
|
|
136
|
+
// The bytes agree again, so a dismissal of an older change is spent.
|
|
137
|
+
dismissedRef.current = null;
|
|
138
|
+
},
|
|
139
|
+
[key, mtimesRef, adoptDiskMtime],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const adoptDiskChange = useCallback(
|
|
143
|
+
(digest: DiskDigest) => {
|
|
144
|
+
if (!key) return;
|
|
145
|
+
// A probe that started before the last read landed compares against a
|
|
146
|
+
// baseline that has since moved; the live hash is the truth, and the bytes
|
|
147
|
+
// it names are already on screen.
|
|
148
|
+
if (hashesRef.current[key] === digest.hash) {
|
|
149
|
+
setDiskChange(null);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (dismissedRef.current === digest.hash) return;
|
|
153
|
+
if (diskChange?.hash === digest.hash) return;
|
|
154
|
+
const typed = contentsRef.current[key];
|
|
155
|
+
const queued = pendingRef.current;
|
|
156
|
+
const dirty =
|
|
157
|
+
(typed !== undefined && typed !== baselinesRef.current[key]) ||
|
|
158
|
+
(queued !== null && editorTargetKey(queued.file) === key);
|
|
159
|
+
if (dirty) {
|
|
160
|
+
setDiskChange(digest);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
// A read already on its way (a workspace refresh, a manual Reload, an
|
|
164
|
+
// earlier verdict) will land these bytes; asking again would be one more
|
|
165
|
+
// request for the same answer.
|
|
166
|
+
if (readingRef.current > 0) return;
|
|
167
|
+
loadedRef.current.delete(key);
|
|
168
|
+
bumpRevision();
|
|
169
|
+
},
|
|
170
|
+
[key, hashesRef, contentsRef, baselinesRef, pendingRef, readingRef, loadedRef, bumpRevision, diskChange],
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
useDiskDigest({
|
|
174
|
+
// Same predicate the tab strip and the phone use for "this tab names a file
|
|
175
|
+
// on disk": a diff tab, an attachment chip and a handle/device file have no
|
|
176
|
+
// server path to ask about. The id only satisfies the predicate's shape.
|
|
177
|
+
path: target && isProbeableTab({ ...target, id: key }) ? target.path ?? null : null,
|
|
178
|
+
root: target?.root ?? null,
|
|
179
|
+
repo: target?.repo ?? null,
|
|
180
|
+
baseHash,
|
|
181
|
+
revision,
|
|
182
|
+
onUnchanged: adoptUnchangedMtime,
|
|
183
|
+
onChanged: adoptDiskChange,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const reloadFromDisk = useCallback(() => {
|
|
187
|
+
if (!target) return;
|
|
188
|
+
const fileKey = editorTargetKey(target);
|
|
189
|
+
const typed = contentsRef.current[fileKey];
|
|
190
|
+
const dirty = typed !== undefined && typed !== baselinesRef.current[fileKey];
|
|
191
|
+
if (dirty) {
|
|
192
|
+
discardPendingWrite(fileKey);
|
|
193
|
+
reloadDiscardingEdits();
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
clearConflict(fileKey);
|
|
197
|
+
loadedRef.current.delete(fileKey);
|
|
198
|
+
bumpRevision();
|
|
199
|
+
}, [target, contentsRef, baselinesRef, discardPendingWrite, reloadDiscardingEdits, clearConflict, loadedRef, bumpRevision]);
|
|
200
|
+
|
|
201
|
+
const keepMineAgainstDisk = useCallback(() => {
|
|
202
|
+
if (!diskChange) return;
|
|
203
|
+
// Remember the exact change that was dismissed: the disk still has those
|
|
204
|
+
// bytes until the buffer's own write lands, so the watcher would otherwise
|
|
205
|
+
// raise the strip again three seconds later.
|
|
206
|
+
dismissedRef.current = diskChange.hash;
|
|
207
|
+
adoptDiskMtime(diskChange.mtimeMs);
|
|
208
|
+
setDiskChange(null);
|
|
209
|
+
}, [diskChange, adoptDiskMtime]);
|
|
210
|
+
|
|
211
|
+
return { diskChange, reloadFromDisk, keepMineAgainstDisk };
|
|
212
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The editor's per-file CACHE lifecycle: throw every cached read away, keep only
|
|
8
|
+
* the files still open, and switch the ending a buffer saves in.
|
|
9
|
+
*
|
|
10
|
+
* These three belong together because they all answer "what does the cache hold
|
|
11
|
+
* right now", and they must touch EVERY cache — the bytes, the baselines, the
|
|
12
|
+
* line endings, the mtimes and the content hashes. A `retain` that forgot one of
|
|
13
|
+
* them left an entry a later tab could inherit under the same key; the hash list
|
|
14
|
+
* is part of that set, or a reopened tab would compare the disk against a
|
|
15
|
+
* fingerprint from the file it used to be.
|
|
16
|
+
*
|
|
17
|
+
* `reset` deliberately does NOT clear the bytes: they stay on screen until the
|
|
18
|
+
* fresh read lands, so a workspace refresh can never blank the editor.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { useCallback } from 'preact/hooks';
|
|
22
|
+
import { retainKeys } from '@/client/hooks/editor/save-file';
|
|
23
|
+
import { editorTargetKey } from '@/client/hooks/editor/target-key';
|
|
24
|
+
import type { FileEditorTarget } from '@/client/hooks/editor/file-editor-types';
|
|
25
|
+
import { detectLineEnding, toLf, type LineEnding } from '@/shared/lib/code/line-endings';
|
|
26
|
+
|
|
27
|
+
/** A mutable ref, typed structurally — every ref here is read without a null check. */
|
|
28
|
+
interface LiveRef<T> {
|
|
29
|
+
current: T;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FileCacheDeps {
|
|
33
|
+
target: FileEditorTarget | null;
|
|
34
|
+
loadedRef: LiveRef<Set<string>>;
|
|
35
|
+
bumpRevision: () => void;
|
|
36
|
+
setContents: (update: (previous: Record<string, string>) => Record<string, string>) => void;
|
|
37
|
+
setBaselines: (update: (previous: Record<string, string>) => Record<string, string>) => void;
|
|
38
|
+
setLineEndings: (update: (previous: Record<string, LineEnding>) => Record<string, LineEnding>) => void;
|
|
39
|
+
setMtimes: (update: (previous: Record<string, number | null>) => Record<string, number | null>) => void;
|
|
40
|
+
setHashes: (update: (previous: Record<string, string | null>) => Record<string, string | null>) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FileCache {
|
|
44
|
+
/**
|
|
45
|
+
* Store one read's bytes in EVERY cache: the LF buffer, its baseline, the
|
|
46
|
+
* ending it arrived with, the mtime it was read at, and the content hash the
|
|
47
|
+
* disk watcher compares against.
|
|
48
|
+
*/
|
|
49
|
+
remember: (fileKey: string, text: string, mtimeMs: number | null, hash: string | null) => void;
|
|
50
|
+
/** Re-read every cached file; a re-render cannot skip a key already marked read. */
|
|
51
|
+
reset: () => void;
|
|
52
|
+
/** Drop every cache entry for a tab that is no longer open. */
|
|
53
|
+
retain: (ids: Array<number | string>) => void;
|
|
54
|
+
/** Change the ending the NEXT save writes. */
|
|
55
|
+
setEol: (eol: LineEnding) => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function useFileCache({
|
|
59
|
+
target,
|
|
60
|
+
loadedRef,
|
|
61
|
+
bumpRevision,
|
|
62
|
+
setContents,
|
|
63
|
+
setBaselines,
|
|
64
|
+
setLineEndings,
|
|
65
|
+
setMtimes,
|
|
66
|
+
setHashes,
|
|
67
|
+
}: FileCacheDeps): FileCache {
|
|
68
|
+
const remember = useCallback(
|
|
69
|
+
(fileKey: string, text: string, mtimeMs: number | null, hash: string | null) => {
|
|
70
|
+
// The buffer holds LF only; the style the bytes arrived with is kept beside
|
|
71
|
+
// it so the write can put the file back the way it was found.
|
|
72
|
+
const ending = detectLineEnding(text);
|
|
73
|
+
const lf = toLf(text);
|
|
74
|
+
setContents((previous) => ({ ...previous, [fileKey]: lf }));
|
|
75
|
+
setBaselines((previous) => ({ ...previous, [fileKey]: lf }));
|
|
76
|
+
setLineEndings((previous) => ({ ...previous, [fileKey]: ending }));
|
|
77
|
+
setMtimes((previous) => ({ ...previous, [fileKey]: mtimeMs }));
|
|
78
|
+
setHashes((previous) => ({ ...previous, [fileKey]: hash }));
|
|
79
|
+
},
|
|
80
|
+
[setContents, setBaselines, setLineEndings, setMtimes, setHashes],
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const reset = useCallback(() => {
|
|
84
|
+
loadedRef.current.clear();
|
|
85
|
+
bumpRevision();
|
|
86
|
+
}, [loadedRef, bumpRevision]);
|
|
87
|
+
|
|
88
|
+
const retain = useCallback(
|
|
89
|
+
(ids: Array<number | string>) => {
|
|
90
|
+
const keep = new Set(ids.map(String));
|
|
91
|
+
for (const loaded of Array.from(loadedRef.current)) {
|
|
92
|
+
if (!keep.has(loaded)) loadedRef.current.delete(loaded);
|
|
93
|
+
}
|
|
94
|
+
setContents((previous) => retainKeys(previous, keep));
|
|
95
|
+
setLineEndings((previous) => retainKeys(previous, keep));
|
|
96
|
+
setMtimes((previous) => retainKeys(previous, keep));
|
|
97
|
+
setHashes((previous) => retainKeys(previous, keep));
|
|
98
|
+
},
|
|
99
|
+
[loadedRef, setContents, setLineEndings, setMtimes, setHashes],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// Only the ending moves: the BUFFER is LF-only either way, and the bytes are
|
|
103
|
+
// built at write time, so nothing on screen changes and no re-read is needed.
|
|
104
|
+
const setEol = useCallback(
|
|
105
|
+
(next: LineEnding) => {
|
|
106
|
+
if (!target) return;
|
|
107
|
+
setLineEndings((previous) => ({ ...previous, [editorTargetKey(target)]: next }));
|
|
108
|
+
},
|
|
109
|
+
[target, setLineEndings],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
return { remember, reset, retain, setEol };
|
|
113
|
+
}
|