@kabmo-labs/kabmo 0.27.0 → 0.28.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 +495 -467
- package/dist/client/static/js/index-81f7berm.css +1 -0
- package/dist/client/static/js/{index-e3qh2yps.js → index-xzvyrxya.js} +795 -795
- 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 +2 -2
- package/src/client/components/common/harness-glyph/index.tsx +18 -1
- 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/layout/session-sidebar/CategoryItem.tsx +2 -1
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +9 -1
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +2 -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 +23 -3
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +3 -0
- package/src/client/components/mobile/mobile-right-sidebar/EditorSurface.tsx +156 -0
- package/src/client/components/mobile/mobile-right-sidebar/FullEditor.tsx +41 -86
- 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 +30 -3
- package/src/client/components/settings/categories/HarnessSettings.tsx +11 -7
- 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 +1 -1
- package/src/client/components/settings/categories/harness-settings/CustomHarnessForm.tsx +186 -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/SettingsModal.test.tsx +165 -0
- package/src/client/components/settings/categories/panel-plugins/SettingsModal.tsx +260 -0
- 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/MessageItem.fork.test.ts +80 -0
- package/src/client/components/workspace/chat-timeline/MessageItem.tsx +9 -3
- 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.tsx +24 -0
- package/src/client/components/workspace/chat-timeline/chat-input/WaitingDependencyPicker.tsx +13 -20
- 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 +101 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +2 -2
- package/src/client/components/workspace/editor/FilePane.tsx +9 -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 +16 -10
- package/src/client/components/workspace/editor/index.tsx +6 -10
- package/src/client/components/workspace/editor/toolbar-clusters.test.ts +4 -3
- package/src/client/components/workspace/editor/toolbar-clusters.tsx +23 -14
- 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/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/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/use-fork-session.ts +9 -22
- 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 +21 -12
- 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 +90 -0
- package/src/client/hooks/editor/use-file-editor.ts +90 -52
- package/src/client/hooks/editor/use-file-read.ts +24 -10
- package/src/client/hooks/editor/use-file-writes.ts +4 -4
- package/src/client/hooks/models/harness-catalog.ts +15 -0
- package/src/client/hooks/ui/notifications.ts +17 -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/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/server/index.ts +7 -0
- 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.ts +6 -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-queue.server.ts +3 -3
- 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.test.ts +2 -1
- package/src/server/lib/omp/rpc/frame-fold.ts +6 -45
- 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/sidebar-data.harness.test.ts +6 -3
- package/src/server/lib/omp/session/standby.server.ts +13 -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/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/new-mode.test.ts +40 -0
- package/src/server/routes/agent/new.ts +31 -10
- package/src/server/routes/agent/prewarm.ts +48 -7
- package/src/server/routes/fs/action.ts +9 -1
- package/src/server/routes/fs/digest.test.ts +100 -0
- package/src/server/routes/fs/digest.ts +106 -0
- package/src/server/routes/fs/index.ts +2 -0
- package/src/server/routes/fs/read.ts +6 -1
- package/src/server/routes/harness/custom.test.ts +131 -0
- package/src/server/routes/harness/import-action.ts +2 -2
- package/src/server/routes/harness/root.ts +41 -8
- 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/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/composer/delegation.ts +3 -3
- package/src/shared/lib/chat/timeline/fork-anchor.test.ts +97 -0
- package/src/shared/lib/chat/timeline/fork-anchor.ts +47 -0
- package/src/shared/lib/fs/content-hash.ts +29 -0
- package/src/shared/lib/harness/catalog.ts +48 -6
- 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 +65 -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/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/notifications/settings.test.ts +21 -0
- package/src/shared/lib/notifications/settings.ts +24 -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/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/workspace/refresh-cadence.test.ts +25 -1
- package/src/shared/lib/workspace/relative-time.ts +16 -0
- package/src/shared/types/harness.ts +7 -0
- package/src/shared/types/omp/agent.ts +6 -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 +12 -1
- package/src/shared/types/waiting.ts +9 -0
- package/src/test-support/file-editor.test-util.ts +70 -5
- 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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Put a held prompt's text and attachments back into the composer it came from.
|
|
8
|
+
*
|
|
9
|
+
* The row is the ONLY copy while the prompt waits: the send path clears the
|
|
10
|
+
* draft when it creates the wait. A cancel or a failed dispatch therefore has
|
|
11
|
+
* to write that copy back, or the user's text is gone — it was reachable only
|
|
12
|
+
* through a database row with no UI.
|
|
13
|
+
*
|
|
14
|
+
* The write goes through the session-state store rather than a component setter
|
|
15
|
+
* because the cancel may start from the sidebar for a chat that is not mounted.
|
|
16
|
+
* A mounted composer follows the slot (`useComposerDraft` subscribes), and an
|
|
17
|
+
* unmounted one reads it on the next open.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { CHAT_DRAFT_ATTACHMENTS_KEY, CHAT_DRAFT_KEY } from '@/shared/lib/chat/composer/draft';
|
|
21
|
+
import { setSessionKey } from '@/shared/lib/workspace/session-state/store';
|
|
22
|
+
import type { WaitingPrompt } from '@/shared/types/waiting';
|
|
23
|
+
|
|
24
|
+
/** The chat a prompt belongs to: the pending slot, else the session it targets. */
|
|
25
|
+
export function waitingDraftSessionId(prompt: WaitingPrompt): string | null {
|
|
26
|
+
return prompt.pendingId ?? prompt.targetSessionId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function restoreHeldDraft(prompt: WaitingPrompt): void {
|
|
30
|
+
const sessionId = waitingDraftSessionId(prompt);
|
|
31
|
+
if (!sessionId) return;
|
|
32
|
+
setSessionKey(sessionId, CHAT_DRAFT_KEY, prompt.prompt);
|
|
33
|
+
setSessionKey(sessionId, CHAT_DRAFT_ATTACHMENTS_KEY, prompt.attachments);
|
|
34
|
+
}
|
|
@@ -70,6 +70,7 @@ export function useWaitingPrompts(): WaitingPromptsState {
|
|
|
70
70
|
/** Create a held prompt. Throws the server's own reason on a refusal. */
|
|
71
71
|
export async function createWaitingPromptRequest(input: {
|
|
72
72
|
pendingId: string | null;
|
|
73
|
+
targetSessionId: string | null;
|
|
73
74
|
dependsOn: string;
|
|
74
75
|
dependsOnTitle: string | null;
|
|
75
76
|
prompt: string;
|
|
@@ -91,10 +92,15 @@ export async function createWaitingPromptRequest(input: {
|
|
|
91
92
|
return data.prompt as WaitingPrompt;
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
/** Cancel a held prompt. Returns the server's refusal rather than swallowing it
|
|
95
|
-
|
|
95
|
+
/** Cancel a held prompt. Returns the server's refusal rather than swallowing it,
|
|
96
|
+
* and the cancelled row so the caller can restore its draft. */
|
|
97
|
+
export async function cancelWaitingPromptRequest(
|
|
98
|
+
id: string,
|
|
99
|
+
): Promise<{ ok: boolean; error?: string; prompt?: WaitingPrompt }> {
|
|
96
100
|
const response = await fetch(`/api/waiting?id=${encodeURIComponent(id)}`, { method: 'DELETE' });
|
|
97
|
-
if (response.ok) return { ok: true };
|
|
98
101
|
const data = await response.json().catch(() => null);
|
|
102
|
+
if (response.ok) {
|
|
103
|
+
return { ok: true, ...(data?.prompt ? { prompt: data.prompt as WaitingPrompt } : {}) };
|
|
104
|
+
}
|
|
99
105
|
return { ok: false, error: typeof data?.error === 'string' ? data.error : `HTTP ${response.status}` };
|
|
100
106
|
}
|
|
@@ -17,6 +17,7 @@ export type FileEditorSaveStatus = 'idle' | 'saving' | 'saved' | 'error' | 'need
|
|
|
17
17
|
import type { ViewerKind } from '@/shared/lib/fs/document-kind';
|
|
18
18
|
import type { LineEnding } from '@/shared/lib/code/line-endings';
|
|
19
19
|
import type { ByteSource } from '@/client/components/workspace/editor/viewers/bytes';
|
|
20
|
+
import type { DiskDigest } from '@/client/hooks/editor/use-disk-digest';
|
|
20
21
|
|
|
21
22
|
/** The single file a code surface is editing; `id` keys the in-memory cache. */
|
|
22
23
|
export interface FileEditorTarget {
|
|
@@ -203,21 +204,29 @@ export interface UseFileEditorResult {
|
|
|
203
204
|
*/
|
|
204
205
|
resolveConflictByKeepingMine: () => void;
|
|
205
206
|
/**
|
|
206
|
-
*
|
|
207
|
+
* Re-read the active file from disk, discarding the buffer's edits.
|
|
207
208
|
*
|
|
208
|
-
* The user-facing
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
209
|
+
* The user-facing Reload, offered even for a clean buffer: it is the manual
|
|
210
|
+
* counterpart of the automatic refresh, and it is the only way to force a read
|
|
211
|
+
* of a file whose digest the watcher has not compared yet. Distinct from
|
|
212
|
+
* `reset()` (a workspace refresh, which deliberately KEEPS a dirty buffer).
|
|
212
213
|
*/
|
|
213
|
-
|
|
214
|
+
reloadFromDisk: () => void;
|
|
214
215
|
/**
|
|
215
|
-
*
|
|
216
|
+
* The disk bytes differ from a buffer that HAS edits, or null.
|
|
216
217
|
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
* dirty and the autosave owns the write.
|
|
218
|
+
* Nothing is replaced: the panel renders this as the external-change strip so
|
|
219
|
+
* the user chooses between the two copies. A clean buffer never reports here —
|
|
220
|
+
* it is re-read, because there is nothing of the user's to lose.
|
|
221
221
|
*/
|
|
222
|
-
|
|
222
|
+
diskChange: DiskDigest | null;
|
|
223
|
+
/**
|
|
224
|
+
* Answer an external-change notice with the user's buffer.
|
|
225
|
+
*
|
|
226
|
+
* Adopts the disk's mtime as the buffer's base WITHOUT writing anything — the
|
|
227
|
+
* buffer stays dirty and the autosave owns the write — and dismisses the notice,
|
|
228
|
+
* so the same change is not reported again. A later change is a new hash and
|
|
229
|
+
* asks again.
|
|
230
|
+
*/
|
|
231
|
+
keepMineAgainstDisk: () => void;
|
|
223
232
|
}
|
|
@@ -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
|
+
}
|