@kabmo-labs/kabmo 0.25.0 → 0.27.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 +448 -444
- package/dist/client/static/js/index-32rpkj6b.css +1 -0
- package/dist/client/static/js/{index-ga8cbpt4.js → index-e3qh2yps.js} +950 -950
- package/package.json +1 -1
- package/src/client/components/common/Toast.test.tsx +28 -2
- package/src/client/components/common/Toast.tsx +21 -9
- package/src/client/components/common/session-actions-menu/index.tsx +38 -12
- package/src/client/components/common/session-branch/BranchGuides.tsx +93 -0
- package/src/client/components/common/session-branch/SubagentRow.tsx +77 -0
- package/src/client/components/common/session-branch/index.tsx +169 -0
- package/src/client/components/common/session-branch/session-branch.test.tsx +240 -0
- package/src/client/components/common/session-branch/style.ts +29 -0
- package/src/client/components/common/session-row/StatusSlot.tsx +15 -3
- package/src/client/components/common/session-row/index.tsx +24 -25
- package/src/client/components/common/session-row/session-row.test.tsx +11 -0
- package/src/client/components/common/session-state-provider/index.tsx +1 -1
- package/src/client/components/layout/desktop-layout/LeftColumn.tsx +2 -1
- package/src/client/components/layout/session-sidebar/CategoryItem.tsx +66 -69
- package/src/client/components/layout/session-sidebar/SessionItem.batch.test.ts +3 -3
- package/src/client/components/layout/session-sidebar/SessionItem.test.ts +25 -2
- package/src/client/components/layout/session-sidebar/SessionItem.tsx +33 -30
- package/src/client/components/layout/session-sidebar/SessionList.tsx +2 -1
- package/src/client/components/layout/session-sidebar/about-modal/HarnessRow.tsx +261 -0
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTable.tsx +35 -225
- package/src/client/components/layout/session-sidebar/about-modal/HarnessTableLog.test.tsx +36 -16
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogDialog.tsx +11 -3
- package/src/client/components/layout/session-sidebar/about-modal/UpdateLogLine.tsx +13 -4
- package/src/client/components/layout/session-sidebar/about-modal/UpdateSection.tsx +3 -2
- package/src/client/components/layout/session-sidebar/about-modal/index.tsx +30 -14
- package/src/client/components/layout/session-sidebar/modern/RevealRow.tsx +56 -0
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +69 -85
- package/src/client/components/layout/session-sidebar/modern/reveal-row.test.tsx +104 -0
- package/src/client/components/layout/session-sidebar/scheduler-modal/index.tsx +2 -1
- package/src/client/components/layout/session-sidebar/variant-props.ts +2 -1
- package/src/client/components/mobile/SessionSidebar.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/ClassicDrawer.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +59 -62
- package/src/client/components/mobile/mobile-session-sidebar/List.tsx +2 -1
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.test.ts +5 -0
- package/src/client/components/mobile/mobile-session-sidebar/SessionRow.tsx +33 -30
- package/src/client/components/settings/Modal.tsx +1 -1
- package/src/client/components/settings/Sidebar.tsx +1 -1
- package/src/client/components/settings/categories/NotificationSettings.test.tsx +92 -0
- package/src/client/components/settings/categories/NotificationSettings.tsx +112 -2
- package/src/client/components/settings/categories/harness-settings/HarnessCard.tsx +1 -1
- package/src/client/components/settings/categories/project-settings/WorktreeSettings.tsx +2 -1
- package/src/client/components/settings/categories/usage-settings/LimitsSection.tsx +39 -19
- package/src/client/components/settings/categories/usage-settings/ProviderDetail.tsx +1 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.test.ts +94 -0
- package/src/client/components/settings/categories/usage-settings/limit-groups.ts +118 -0
- package/src/client/components/settings/categories/usage-settings/limits-section.test.tsx +118 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.fork.test.ts +94 -0
- package/src/client/components/workspace/chat-timeline/AiMessageFooter.tsx +31 -5
- package/src/client/components/workspace/chat-timeline/EmptyWorkspacePrompt.tsx +86 -93
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +21 -1
- package/src/client/components/workspace/chat-timeline/PendingTranscript.tsx +130 -0
- package/src/client/components/workspace/chat-timeline/RunFooter.tsx +12 -3
- package/src/client/components/workspace/chat-timeline/chat-input/AttachmentToolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/ModeToggles.tsx +15 -1
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.test.tsx +85 -0
- package/src/client/components/workspace/chat-timeline/chat-input/SessionModeDropdown.tsx +84 -0
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +2 -0
- package/src/client/components/workspace/chat-timeline/chat-input/modes-props.ts +5 -0
- package/src/client/components/workspace/chat-timeline/fork-preview.test.tsx +141 -0
- package/src/client/components/workspace/chat-timeline/index.tsx +16 -22
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +116 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/WorktreePicker.tsx +5 -4
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -0
- package/src/client/components/workspace/git-panel/index.tsx +2 -2
- package/src/client/components/workspace/terminal-panel/RealtimeTerminalView.tsx +8 -5
- package/src/client/components/workspace/terminal-panel/index.tsx +3 -0
- package/src/client/hooks/chat/composer/items.test.ts +19 -0
- package/src/client/hooks/chat/omp/folder-auto-expand.ts +1 -1
- package/src/client/hooks/chat/omp/pending-adoption.ts +51 -0
- package/src/client/hooks/chat/omp/pending-child.test.ts +73 -0
- package/src/client/hooks/chat/omp/pending-entry.ts +59 -0
- package/src/client/hooks/chat/omp/pending-rows.ts +6 -2
- package/src/client/hooks/chat/omp/pending-sessions.test.ts +1 -2
- package/src/client/hooks/chat/omp/pending-sessions.ts +45 -69
- package/src/client/hooks/chat/omp/pending-waiting.ts +1 -1
- package/src/client/hooks/chat/omp/run-switch.ts +1 -1
- package/src/client/hooks/chat/omp/session-list.tsx +9 -0
- package/src/client/hooks/chat/omp/sidebar-reload.test.ts +85 -0
- package/src/client/hooks/chat/omp/sidebar-reload.ts +30 -0
- package/src/client/hooks/chat/subagents/roster.ts +122 -0
- package/src/client/hooks/chat/timeline/child-spawn.test.ts +55 -0
- package/src/client/hooks/chat/timeline/child-spawn.ts +45 -0
- package/src/client/hooks/chat/timeline/fork-preview.test.ts +148 -0
- package/src/client/hooks/chat/timeline/fork-preview.ts +104 -0
- package/src/client/hooks/chat/timeline/fork-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -0
- package/src/client/hooks/chat/timeline/fork-send.test.ts +139 -0
- package/src/client/hooks/chat/timeline/mode-availability.test.ts +1 -1
- package/src/client/hooks/chat/timeline/mode-availability.ts +33 -0
- package/src/client/hooks/chat/timeline/mode-markers.ts +7 -1
- package/src/client/hooks/chat/timeline/mode-post.ts +15 -3
- package/src/client/hooks/chat/timeline/modes-contract.ts +9 -4
- package/src/client/hooks/chat/timeline/modes.test.ts +56 -18
- package/src/client/hooks/chat/timeline/modes.ts +42 -29
- package/src/client/hooks/chat/timeline/pending-branch.ts +214 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +302 -0
- package/src/client/hooks/chat/timeline/send.ts +17 -103
- package/src/client/hooks/chat/timeline/session-harness.ts +6 -0
- package/src/client/hooks/chat/timeline/stop-with-queue.ts +42 -0
- package/src/client/hooks/chat/timeline/use-fork-session.ts +40 -31
- package/src/client/hooks/chat/waiting/cancel.ts +2 -1
- package/src/client/hooks/chat/waiting/dispatch.ts +5 -4
- package/src/client/hooks/chat/waiting/held.ts +2 -1
- package/src/client/hooks/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- package/src/client/hooks/settings/providers/actions.ts +3 -2
- package/src/client/hooks/settings/providers/messages.ts +9 -7
- package/src/client/hooks/settings/providers/model-actions.ts +2 -1
- package/src/client/hooks/ui/editor-error-toast.ts +2 -1
- package/src/client/hooks/ui/input-required-alert.ts +12 -5
- package/src/client/hooks/ui/notifications.ts +45 -0
- package/src/client/hooks/ui/run-outcome-alert.ts +48 -0
- package/src/client/hooks/workspace/batch-archive.test.ts +2 -2
- package/src/client/hooks/workspace/batch-archive.ts +4 -2
- package/src/client/hooks/workspace/expanded-sessions.ts +36 -7
- package/src/client/hooks/workspace/git-action-outcome.ts +4 -3
- package/src/client/hooks/workspace/navbar-session-actions.ts +2 -1
- package/src/client/hooks/workspace/session-actions.test.ts +2 -1
- package/src/client/hooks/workspace/session-actions.ts +2 -1
- package/src/client/hooks/workspace/terminal/connection.test.ts +63 -0
- package/src/client/hooks/workspace/terminal/connection.ts +47 -0
- package/src/client/hooks/workspace/terminal/index.ts +35 -4
- package/src/client/hooks/workspace/workspace-folder-actions.ts +2 -1
- package/src/client/lib/native/open-session.ts +33 -0
- package/src/client/lib/notifications/os.test.ts +125 -0
- package/src/client/lib/notifications/os.ts +130 -0
- package/src/client/lib/plugins/sidebar-bridge.ts +2 -20
- package/src/client/lib/router/open-session.test.ts +75 -0
- package/src/client/lib/router/open-session.ts +34 -0
- package/src/client/lib/signals.ts +5 -1
- package/src/client/main.tsx +6 -0
- package/src/server/lib/db/schema.ts +1 -0
- package/src/server/lib/harness/acp/calls.ts +15 -1
- package/src/server/lib/harness/acp/client-capabilities.test.ts +55 -0
- package/src/server/lib/harness/acp/client-capabilities.ts +61 -0
- package/src/server/lib/harness/acp/client-fs.test.ts +135 -0
- package/src/server/lib/harness/acp/client-fs.ts +131 -0
- package/src/server/lib/harness/acp/client-initialize.test.ts +70 -0
- package/src/server/lib/harness/acp/client-initialize.ts +84 -0
- package/src/server/lib/harness/acp/client.ts +31 -21
- package/src/server/lib/harness/acp/commands.test.ts +5 -5
- package/src/server/lib/harness/acp/commands.ts +14 -2
- package/src/server/lib/harness/acp/frames-timing.test.ts +68 -0
- package/src/server/lib/harness/acp/frames-v2.test.ts +85 -0
- package/src/server/lib/harness/acp/frames.ts +71 -158
- package/src/server/lib/harness/acp/mapper.test.ts +40 -0
- package/src/server/lib/harness/acp/mapper.ts +12 -0
- package/src/server/lib/harness/acp/permissions.ts +6 -0
- package/src/server/lib/harness/acp/protocol.ts +41 -2
- package/src/server/lib/harness/acp/session-facts.ts +1 -1
- package/src/server/lib/harness/acp/session-handshake.test.ts +90 -1
- package/src/server/lib/harness/acp/session-handshake.ts +83 -6
- package/src/server/lib/harness/acp/session-idle.ts +7 -6
- package/src/server/lib/harness/acp/session-notifications.ts +41 -2
- package/src/server/lib/harness/acp/session-observers.test.ts +63 -0
- package/src/server/lib/harness/acp/session-permissions.test.ts +29 -0
- package/src/server/lib/harness/acp/session-permissions.ts +36 -0
- package/src/server/lib/harness/acp/session-requests.test.ts +92 -0
- package/src/server/lib/harness/acp/session-requests.ts +48 -6
- package/src/server/lib/harness/acp/session-turns.ts +8 -3
- package/src/server/lib/harness/acp/session-usage.ts +4 -0
- package/src/server/lib/harness/acp/session-web-state.ts +30 -2
- package/src/server/lib/harness/acp/session.test-util.ts +19 -1
- package/src/server/lib/harness/acp/session.ts +60 -60
- package/src/server/lib/harness/acp/tool-calls.ts +223 -0
- package/src/server/lib/harness/acp/turn.test.ts +102 -0
- package/src/server/lib/harness/acp/turn.ts +81 -6
- package/src/server/lib/harness/acp/v2.test.ts +144 -0
- package/src/server/lib/harness/acp/v2.ts +220 -0
- package/src/server/lib/harness/acp/verbs.ts +46 -6
- package/src/server/lib/harness/launch.test.ts +25 -0
- package/src/server/lib/harness/launch.ts +21 -9
- package/src/server/lib/harness/session.ts +3 -0
- package/src/server/lib/harness/update-job-store.test.ts +37 -12
- package/src/server/lib/harness/update-job-store.ts +22 -16
- package/src/server/lib/harness/update-job.server.ts +66 -175
- package/src/server/lib/harness/update-queue.server.ts +292 -0
- package/src/server/lib/harness/update-queue.test.ts +265 -0
- package/src/server/lib/harness/update-spawn.server.ts +96 -0
- package/src/server/lib/harness/update-worker.ts +8 -3
- package/src/server/lib/lifecycle/after-listen.ts +9 -0
- package/src/server/lib/lifecycle/paths.ts +14 -9
- package/src/server/lib/omp/rpc/run-settle.server.ts +10 -1
- package/src/server/lib/omp/rpc/subagent-liveness.ts +5 -5
- package/src/server/lib/omp/rpc/terminal-settle.ts +5 -1
- package/src/server/lib/omp/session/delete-flow.server.ts +1 -0
- package/src/server/lib/omp/session/sidebar-data.server.ts +10 -12
- package/src/server/lib/sessions/fork.server.test.ts +68 -0
- package/src/server/lib/sessions/fork.server.ts +31 -6
- package/src/server/lib/sessions/spawn.server.test.ts +41 -0
- package/src/server/lib/sessions/spawn.server.ts +27 -2
- package/src/server/lib/usage/report.server.ts +57 -0
- package/src/server/routes/agent/harness-command.ts +6 -5
- package/src/server/routes/chat/stream.ts +7 -2
- package/src/server/routes/harness/update-status.ts +18 -12
- package/src/server/routes/harness/update.test.ts +53 -16
- package/src/server/routes/harness/update.ts +13 -8
- package/src/server/routes/sessions/body-readers.ts +43 -0
- package/src/server/routes/sessions/fork.ts +19 -4
- package/src/server/routes/sessions/routes.test.ts +1 -2
- package/src/server/routes/sessions/session.ts +19 -0
- package/src/server/routes/sessions/spawn.ts +16 -13
- package/src/shared/lib/chat/omp/agent-events.ts +11 -0
- package/src/shared/lib/chat/omp/session-modes-signal.test.ts +41 -0
- package/src/shared/lib/chat/timeline/fork-preview.test.ts +62 -0
- package/src/shared/lib/chat/timeline/fork-preview.ts +36 -0
- package/src/shared/lib/harness/mode-signal.ts +20 -0
- package/src/shared/lib/harness/session-modes.ts +24 -0
- package/src/shared/lib/harness/update-job.ts +53 -6
- package/src/shared/lib/icons/tint-hues.generated.ts +34 -34
- package/src/shared/lib/notifications/outcomes.test.ts +96 -0
- package/src/shared/lib/notifications/outcomes.ts +64 -0
- package/src/shared/lib/notifications/settings.test.ts +49 -0
- package/src/shared/lib/notifications/settings.ts +34 -0
- package/src/shared/lib/omp/session/default-title.ts +5 -4
- package/src/shared/lib/omp/session/prewarm-misc.test.ts +3 -2
- package/src/shared/lib/omp/session/schema-migrations.ts +4 -0
- package/src/shared/lib/omp/session/stream-state.server.test.ts +19 -0
- package/src/shared/lib/omp/session/stream-state.server.ts +24 -4
- package/src/shared/lib/settings/defaults.ts +3 -0
- package/src/shared/lib/ui/toast-duration.test.ts +25 -1
- package/src/shared/lib/ui/toast-duration.ts +22 -4
- package/src/shared/lib/workspace/session-state/store.ts +4 -0
- package/src/shared/types/harness-update.ts +24 -0
- package/src/shared/types/realtime.ts +2 -0
- package/src/shared/types/settings/state.ts +10 -0
- package/src/shared/types/workspace.ts +4 -0
- package/src/test-support/harness-table.test-util.ts +25 -9
- package/dist/client/static/js/index-bc9aa4mx.css +0 -1
- package/src/client/components/common/session-actions-menu/NewChildSessionDialog.tsx +0 -113
- package/src/client/components/common/subagent-list/index.tsx +0 -165
- package/src/client/components/layout/session-sidebar/ChildSessionList.tsx +0 -66
- package/src/client/hooks/workspace/child-expansion.ts +0 -33
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import type { ProviderItem } from '@/shared/types';
|
|
17
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
17
18
|
|
|
18
19
|
/** The success/failure line for an Add Provider submission. */
|
|
19
20
|
export function addProviderMessage(
|
|
20
21
|
provider: ProviderItem,
|
|
21
22
|
options: { fetchedCount: number; ompNote?: string },
|
|
22
|
-
): { text: string; tone:
|
|
23
|
+
): { text: string; tone: ToastTone } {
|
|
23
24
|
if (provider.modelSource === 'discovery') {
|
|
24
25
|
return { text: `${provider.name} registered — omp discovers its models on each run.`, tone: 'success' };
|
|
25
26
|
}
|
|
@@ -37,12 +38,13 @@ export function addProviderMessage(
|
|
|
37
38
|
}
|
|
38
39
|
if (options.fetchedCount === -1) {
|
|
39
40
|
// The listing failed. When omp reported a reason it is the actionable half,
|
|
40
|
-
// so it is quoted rather than replaced by a generic line.
|
|
41
|
+
// so it is quoted rather than replaced by a generic line. The provider IS
|
|
42
|
+
// registered, so this is a partial outcome, not a failed add.
|
|
41
43
|
return {
|
|
42
44
|
text: options.ompNote
|
|
43
45
|
? `Provider registered, but models could not be listed: ${options.ompNote}`
|
|
44
46
|
: 'Auto-fetch models failed — provider added with default models.',
|
|
45
|
-
tone: '
|
|
47
|
+
tone: 'warning',
|
|
46
48
|
};
|
|
47
49
|
}
|
|
48
50
|
return { text: `${provider.name} registered — no new models to add.`, tone: 'success' };
|
|
@@ -56,7 +58,7 @@ export function addProviderMessage(
|
|
|
56
58
|
*/
|
|
57
59
|
export function fetchModelsMessage(counts: { addedCount: number; removedCount: number }): {
|
|
58
60
|
text: string;
|
|
59
|
-
tone:
|
|
61
|
+
tone: ToastTone;
|
|
60
62
|
} {
|
|
61
63
|
const plural = (count: number) => (count === 1 ? '' : 's');
|
|
62
64
|
if (counts.addedCount > 0 && counts.removedCount > 0) {
|
|
@@ -87,7 +89,7 @@ export function fetchModelsMessage(counts: { addedCount: number; removedCount: n
|
|
|
87
89
|
*/
|
|
88
90
|
export function fetchModelsNote(result: {
|
|
89
91
|
omp?: { written: boolean; addedCount: number; backfilledCount: number; removedCount?: number; reason?: string };
|
|
90
|
-
}): { text: string; tone:
|
|
92
|
+
}): { text: string; tone: ToastTone } | null {
|
|
91
93
|
if (!result.omp) return null;
|
|
92
94
|
if (result.omp.written) {
|
|
93
95
|
const parts: string[] = [];
|
|
@@ -106,7 +108,7 @@ export function fetchModelsNote(result: {
|
|
|
106
108
|
};
|
|
107
109
|
}
|
|
108
110
|
if (result.omp.reason) {
|
|
109
|
-
return { text: `omp models.yml not updated: ${result.omp.reason}`, tone: '
|
|
111
|
+
return { text: `omp models.yml not updated: ${result.omp.reason}`, tone: 'warning' };
|
|
110
112
|
}
|
|
111
113
|
return null;
|
|
112
114
|
}
|
|
@@ -122,7 +124,7 @@ export function fetchModelsNote(result: {
|
|
|
122
124
|
export function refreshModelsMessage(
|
|
123
125
|
providerName: string,
|
|
124
126
|
result: { added: number; removed: number },
|
|
125
|
-
): { text: string; tone:
|
|
127
|
+
): { text: string; tone: ToastTone } {
|
|
126
128
|
const plural = (count: number) => (count === 1 ? '' : 's');
|
|
127
129
|
if (result.added > 0 || result.removed > 0) {
|
|
128
130
|
const parts: string[] = [];
|
|
@@ -24,12 +24,13 @@ import {
|
|
|
24
24
|
import { removeLegacyKenariModels } from '@/shared/lib/models/provider/cleanup';
|
|
25
25
|
import { fetchModelsMessage, fetchModelsNote, refreshModelsMessage } from '@/client/hooks/settings/providers/messages';
|
|
26
26
|
import { saveModelOverrideRemote } from '@/client/hooks/settings/providers/api';
|
|
27
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
27
28
|
|
|
28
29
|
export interface ModelActionsDeps {
|
|
29
30
|
providers: ProviderItem[];
|
|
30
31
|
selectedProvider: ProviderItem | undefined;
|
|
31
32
|
isFetchingModels: boolean;
|
|
32
|
-
pushToast: (message: string, tone:
|
|
33
|
+
pushToast: (message: string, tone: ToastTone) => void;
|
|
33
34
|
setProviders: (providers: ProviderItem[]) => void;
|
|
34
35
|
setIsFetchingModels: (fetching: boolean) => void;
|
|
35
36
|
persistProviders: (updated: ProviderItem[]) => Promise<void>;
|
|
@@ -24,11 +24,12 @@
|
|
|
24
24
|
|
|
25
25
|
import { useKabmoEvent } from '@/client/hooks/ui/window-event';
|
|
26
26
|
import { EDITOR_ERROR_EVENT } from '@/client/lib/editor-errors';
|
|
27
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
27
28
|
|
|
28
29
|
/** What `pushToast` accepts, named so this hook does not import the toast host. */
|
|
29
30
|
type PushToast = (
|
|
30
31
|
message: string,
|
|
31
|
-
type?:
|
|
32
|
+
type?: ToastTone,
|
|
32
33
|
options?: { duration?: number | null },
|
|
33
34
|
) => void;
|
|
34
35
|
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { useEffect, useRef } from 'preact/hooks';
|
|
18
|
-
import type { WorkspaceFolderData } from '@/shared/types';
|
|
18
|
+
import type { SessionItemData, WorkspaceFolderData } from '@/shared/types';
|
|
19
19
|
import { triggerInputRequiredSound } from '@/client/hooks/ui/notification-sound';
|
|
20
|
+
import { sendNotification } from '@/client/hooks/ui/notifications';
|
|
20
21
|
|
|
21
22
|
export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
|
|
22
23
|
// Null until the first snapshot: a page load must not replay a cue for
|
|
@@ -24,19 +25,25 @@ export function useInputRequiredAlert(folders: WorkspaceFolderData[]): void {
|
|
|
24
25
|
const knownRef = useRef<Set<string> | null>(null);
|
|
25
26
|
|
|
26
27
|
useEffect(() => {
|
|
27
|
-
const waiting = new
|
|
28
|
+
const waiting = new Map<string, SessionItemData>();
|
|
28
29
|
for (const folder of folders) {
|
|
29
30
|
for (const session of folder.sessions ?? []) {
|
|
30
|
-
if (session.awaitingInput) waiting.
|
|
31
|
+
if (session.awaitingInput) waiting.set(String(session.id), session);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
const known = knownRef.current;
|
|
35
|
-
knownRef.current = waiting;
|
|
36
|
+
knownRef.current = new Set(waiting.keys());
|
|
36
37
|
if (!known) return;
|
|
37
|
-
for (const id of waiting) {
|
|
38
|
+
for (const [id, session] of waiting) {
|
|
38
39
|
if (known.has(id)) continue;
|
|
39
40
|
triggerInputRequiredSound();
|
|
41
|
+
sendNotification('ask', {
|
|
42
|
+
title: session.title?.trim() || 'Kabmo',
|
|
43
|
+
body: 'Waiting for your answer.',
|
|
44
|
+
tag: `ask:${id}`,
|
|
45
|
+
sessionId: id,
|
|
46
|
+
});
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
49
|
}, [folders]);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The one gate every system notification passes through.
|
|
8
|
+
*
|
|
9
|
+
* Two rules, and both are the feature rather than plumbing:
|
|
10
|
+
*
|
|
11
|
+
* - the event's own setting must be the literal `true` (they ship false);
|
|
12
|
+
* - the page must not be the window the user is looking at. The sidebar badge,
|
|
13
|
+
* the ask card and the inline error row already report these events on
|
|
14
|
+
* screen, so a banner over the app would only repeat what is visible.
|
|
15
|
+
*
|
|
16
|
+
* Text is clipped here because a failure reason can be a whole provider
|
|
17
|
+
* response; an OS notification is a headline, not a log.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { isNotificationEnabled, type NotificationEvent } from '@/shared/lib/notifications/settings';
|
|
21
|
+
import { showOsNotification, shouldShowSystemNotification } from '@/client/lib/notifications/os';
|
|
22
|
+
|
|
23
|
+
const TITLE_LIMIT = 120;
|
|
24
|
+
const BODY_LIMIT = 240;
|
|
25
|
+
|
|
26
|
+
function clip(text: string, limit: number): string {
|
|
27
|
+
const trimmed = text.trim();
|
|
28
|
+
if (trimmed.length <= limit) return trimmed;
|
|
29
|
+
return `${trimmed.slice(0, limit - 1).trimEnd()}…`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Send a system notification for `event`, unless the setting or focus says no. */
|
|
33
|
+
export function sendNotification(
|
|
34
|
+
event: NotificationEvent,
|
|
35
|
+
notification: { title: string; body: string; tag?: string; sessionId?: string },
|
|
36
|
+
): void {
|
|
37
|
+
if (!isNotificationEnabled(event)) return;
|
|
38
|
+
if (!shouldShowSystemNotification()) return;
|
|
39
|
+
void showOsNotification({
|
|
40
|
+
title: clip(notification.title, TITLE_LIMIT) || 'Kabmo',
|
|
41
|
+
body: clip(notification.body, BODY_LIMIT),
|
|
42
|
+
tag: notification.tag,
|
|
43
|
+
sessionId: notification.sessionId,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* App-wide "a run ended" cue.
|
|
8
|
+
*
|
|
9
|
+
* It reads the shared session list rather than the open timeline for the same
|
|
10
|
+
* reason `useInputRequiredAlert` does: the run that mattered is usually NOT the
|
|
11
|
+
* session on screen. The status topic is written by the server on every
|
|
12
|
+
* terminal settle, so this reaches a background session this tab never opened.
|
|
13
|
+
*
|
|
14
|
+
* Only a transition earns a banner — `stream` to `finish`, checked by
|
|
15
|
+
* `runOutcomeNotices` — so the badges already present at page load stay silent.
|
|
16
|
+
* A failed run is the same transition carrying `runFailure`, so finish and
|
|
17
|
+
* error cannot fire for one run.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useEffect, useRef } from 'preact/hooks';
|
|
21
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
22
|
+
import {
|
|
23
|
+
runOutcomeNotices,
|
|
24
|
+
streamOutcomes,
|
|
25
|
+
type StreamOutcome,
|
|
26
|
+
} from '@/shared/lib/notifications/outcomes';
|
|
27
|
+
import { sendNotification } from '@/client/hooks/ui/notifications';
|
|
28
|
+
|
|
29
|
+
export function useRunOutcomeAlert(folders: WorkspaceFolderData[]): void {
|
|
30
|
+
// Null until the first snapshot: a page load must not announce runs that had
|
|
31
|
+
// already finished before it.
|
|
32
|
+
const knownRef = useRef<Map<string, StreamOutcome> | null>(null);
|
|
33
|
+
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const previous = knownRef.current;
|
|
36
|
+
knownRef.current = streamOutcomes(folders);
|
|
37
|
+
if (!previous) return;
|
|
38
|
+
|
|
39
|
+
for (const notice of runOutcomeNotices(previous, folders)) {
|
|
40
|
+
sendNotification(notice.kind, {
|
|
41
|
+
title: notice.title,
|
|
42
|
+
body: notice.detail,
|
|
43
|
+
tag: `${notice.kind}:${notice.sessionId}`,
|
|
44
|
+
sessionId: notice.sessionId,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [folders]);
|
|
48
|
+
}
|
|
@@ -34,14 +34,14 @@ describe('archiveOutcomeMessage', () => {
|
|
|
34
34
|
.toEqual({ message: 'Archived 1 session.', tone: 'success' });
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test('a partial refusal names both counts and is
|
|
37
|
+
test('a partial refusal names both counts and is dressed as a warning', () => {
|
|
38
38
|
const report = archiveOutcomeMessage(outcome({
|
|
39
39
|
archived: ['a', 'b'],
|
|
40
40
|
refused: [{ id: 'new-1', error: 'This chat has not been created yet.' }],
|
|
41
41
|
}));
|
|
42
42
|
expect(report?.message).toContain('Archived 2 sessions');
|
|
43
43
|
expect(report?.message).toContain('1 refused');
|
|
44
|
-
expect(report?.tone).toBe('
|
|
44
|
+
expect(report?.tone).toBe('warning');
|
|
45
45
|
});
|
|
46
46
|
|
|
47
47
|
test('an all-refused run is an error and names the refusal count', () => {
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* against the list.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
18
|
+
|
|
17
19
|
export interface BatchArchiveRefusal {
|
|
18
20
|
id: string;
|
|
19
21
|
error: string;
|
|
@@ -60,7 +62,7 @@ export function archiveSessionsBatch(ids: readonly string[]): Promise<BatchArchi
|
|
|
60
62
|
*/
|
|
61
63
|
export function archiveOutcomeMessage(
|
|
62
64
|
outcome: BatchArchiveOutcome,
|
|
63
|
-
): { message: string; tone:
|
|
65
|
+
): { message: string; tone: ToastTone } | null {
|
|
64
66
|
if (outcome.error) return { message: outcome.error, tone: 'error' };
|
|
65
67
|
const archived = outcome.archived.length;
|
|
66
68
|
const refused = outcome.refused.length;
|
|
@@ -73,6 +75,6 @@ export function archiveOutcomeMessage(
|
|
|
73
75
|
}
|
|
74
76
|
return {
|
|
75
77
|
message: `Archived ${archived} ${archived === 1 ? 'session' : 'sessions'}; ${refused} refused.`,
|
|
76
|
-
tone: '
|
|
78
|
+
tone: 'warning',
|
|
77
79
|
};
|
|
78
80
|
}
|
|
@@ -4,27 +4,40 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Expanded-session
|
|
7
|
+
* Expanded-session branches, shared by the desktop and mobile session sidebars.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* phone
|
|
9
|
+
* One row has ONE branch — child sessions and its subagent roster — and one
|
|
10
|
+
* chevron opens it. Both sidebars must read and write ONE set, persisted in
|
|
11
|
+
* `app_settings.omp_sidebar_expanded_sessions`, or a branch expanded on the
|
|
12
|
+
* phone comes back collapsed on the desktop.
|
|
13
13
|
*
|
|
14
14
|
* The `?subagent=` deep link auto-expands its session row: a reload on a
|
|
15
|
-
* subagent transcript must leave the
|
|
15
|
+
* subagent transcript must leave the leaf that opened it visible.
|
|
16
|
+
*
|
|
17
|
+
* A pending CHILD (the row a "New child session" click creates) also opens its
|
|
18
|
+
* parent through `expandSessionBranch`, because the row would otherwise exist
|
|
19
|
+
* inside a collapsed branch and never be seen.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
import { useCallback, useEffect, useState } from 'preact/hooks';
|
|
19
23
|
import { useSearchParams } from '@/client/lib/router/search-params';
|
|
20
24
|
import { loadExpandedSessionIds, saveExpandedSessionIds } from '@/shared/lib/workspace/sidebar-expanded';
|
|
21
25
|
|
|
26
|
+
/** Fired by a pending child's creator so every sidebar opens its parent. */
|
|
27
|
+
const EXPAND_SESSION_EVENT = 'omp:expand-session';
|
|
28
|
+
|
|
22
29
|
export interface ExpandedSessionsHandle {
|
|
23
30
|
expandedSessionIds: Set<string>;
|
|
24
|
-
/** Collapse an expanded
|
|
31
|
+
/** Collapse an expanded branch, or expand a collapsed one. Persists it. */
|
|
25
32
|
toggleSession: (sessionId: string) => void;
|
|
26
33
|
}
|
|
27
34
|
|
|
35
|
+
/** Open one session's branch from outside the sidebar (a pending child). */
|
|
36
|
+
export function expandSessionBranch(sessionId: string): void {
|
|
37
|
+
if (typeof window === 'undefined' || !sessionId) return;
|
|
38
|
+
window.dispatchEvent(new CustomEvent(EXPAND_SESSION_EVENT, { detail: { sessionId } }));
|
|
39
|
+
}
|
|
40
|
+
|
|
28
41
|
export function useExpandedSessions(): ExpandedSessionsHandle {
|
|
29
42
|
const [searchParams] = useSearchParams();
|
|
30
43
|
const urlSubagentId = searchParams.get('subagent');
|
|
@@ -48,6 +61,22 @@ export function useExpandedSessions(): ExpandedSessionsHandle {
|
|
|
48
61
|
});
|
|
49
62
|
}, [urlSubagentId, urlSessionId]);
|
|
50
63
|
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
const onExpand = (event: Event) => {
|
|
66
|
+
const id = (event as CustomEvent<{ sessionId?: string }>).detail?.sessionId;
|
|
67
|
+
if (!id) return;
|
|
68
|
+
setExpandedSessionIds(prev => {
|
|
69
|
+
if (prev.has(id)) return prev;
|
|
70
|
+
const next = new Set(prev);
|
|
71
|
+
next.add(id);
|
|
72
|
+
saveExpandedSessionIds(next);
|
|
73
|
+
return next;
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
window.addEventListener(EXPAND_SESSION_EVENT, onExpand);
|
|
77
|
+
return () => window.removeEventListener(EXPAND_SESSION_EVENT, onExpand);
|
|
78
|
+
}, []);
|
|
79
|
+
|
|
51
80
|
const toggleSession = useCallback((sessionId: string) => {
|
|
52
81
|
setExpandedSessionIds((prev) => {
|
|
53
82
|
const next = new Set(prev);
|
|
@@ -28,6 +28,7 @@ import { useEffect, useRef } from 'preact/hooks';
|
|
|
28
28
|
import type { CommitHistoryPage } from '@/shared/types';
|
|
29
29
|
import type { GitActionFetcher } from '@/client/hooks/workspace/git-actions';
|
|
30
30
|
import { gitActionSuccessMessage } from '@/client/lib/git/action-message';
|
|
31
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
31
32
|
|
|
32
33
|
export interface GitActionOutcomeOptions {
|
|
33
34
|
/** The mutation channel, with the action its payload answers. */
|
|
@@ -36,8 +37,8 @@ export interface GitActionOutcomeOptions {
|
|
|
36
37
|
onPage: (page: CommitHistoryPage) => void;
|
|
37
38
|
/** An accepted mutation landed: re-read the working tree. */
|
|
38
39
|
onReload: () => void;
|
|
39
|
-
/** An accepted mutation, in the sentence the user reads. */
|
|
40
|
-
onSuccess: (message: string) => void;
|
|
40
|
+
/** An accepted mutation, in the sentence the user reads and the tone it earns. */
|
|
41
|
+
onSuccess: (message: string, tone: ToastTone) => void;
|
|
41
42
|
/** The server's refusal, or a transport failure. */
|
|
42
43
|
onError: (message: string) => void;
|
|
43
44
|
}
|
|
@@ -81,6 +82,6 @@ export function useGitActionOutcome(options: GitActionOutcomeOptions): void {
|
|
|
81
82
|
const message = dispatched
|
|
82
83
|
? gitActionSuccessMessage({ ...dispatched, stopped: payload.stopped })
|
|
83
84
|
: null;
|
|
84
|
-
if (message) handlers.onSuccess(message);
|
|
85
|
+
if (message) handlers.onSuccess(message, payload.stopped ? 'warning' : 'success');
|
|
85
86
|
}, [fetcher.state, fetcher.data, fetcher.lastAction]);
|
|
86
87
|
}
|
|
@@ -23,6 +23,7 @@ import { useSidebarData } from '@/client/hooks/chat/omp/session-list';
|
|
|
23
23
|
import { useSessionActions } from '@/client/hooks/workspace/session-actions';
|
|
24
24
|
import { useSessionDelete, type SessionDeleteActions } from '@/client/hooks/workspace/session-delete';
|
|
25
25
|
import type { WorkspaceFolderData } from '@/shared/types';
|
|
26
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
26
27
|
|
|
27
28
|
/** What `TopNavbar` needs to draw its title menu. */
|
|
28
29
|
export interface NavbarSessionMenu {
|
|
@@ -42,7 +43,7 @@ export interface NavbarSessionActions {
|
|
|
42
43
|
export function useNavbarSessionActions(
|
|
43
44
|
folders: WorkspaceFolderData[],
|
|
44
45
|
sessionId: string | null,
|
|
45
|
-
report: (message: string, tone?:
|
|
46
|
+
report: (message: string, tone?: ToastTone) => void,
|
|
46
47
|
): NavbarSessionActions {
|
|
47
48
|
const sidebar = useSidebarData();
|
|
48
49
|
const actions = useSessionActions(sidebar.refresh, report);
|
|
@@ -27,6 +27,7 @@ import { act } from 'preact/test-utils';
|
|
|
27
27
|
import { useSessionActions, type SessionActions } from '@/client/hooks/workspace/session-actions';
|
|
28
28
|
import { isSessionRenaming, setSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
|
|
29
29
|
import type { SessionItemData } from '@/shared/types';
|
|
30
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
30
31
|
|
|
31
32
|
const DOM_GLOBALS = ['window', 'document', 'navigator', 'Node', 'Element', 'HTMLElement', 'Event', 'CustomEvent'] as const;
|
|
32
33
|
/** The runner's own globals, restored on teardown — deleting them would strip natives (Event/CustomEvent) every later file needs. */
|
|
@@ -65,7 +66,7 @@ const session: SessionItemData = { id: 's1', folder_id: 1, title: 'old name' };
|
|
|
65
66
|
|
|
66
67
|
interface Reported {
|
|
67
68
|
message: string;
|
|
68
|
-
tone:
|
|
69
|
+
tone: ToastTone | undefined;
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
interface Harness {
|
|
@@ -18,9 +18,10 @@ import { publishClientSignal } from '@/client/lib/signals';
|
|
|
18
18
|
import { useFetcher } from '@/client/lib/router/fetcher';
|
|
19
19
|
import { isSessionRenaming, setSessionRenaming } from '@/client/hooks/workspace/renaming-sessions';
|
|
20
20
|
import type { SessionItemData } from '@/shared/types';
|
|
21
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
21
22
|
|
|
22
23
|
/** Surfaces an outcome to the user; omitted callers stay silent. */
|
|
23
|
-
export type ReportSessionOutcome = (message: string, tone?:
|
|
24
|
+
export type ReportSessionOutcome = (message: string, tone?: ToastTone) => void;
|
|
24
25
|
|
|
25
26
|
export interface SessionActions {
|
|
26
27
|
handleArchive: (session: SessionItemData) => void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* When a terminal may hold a PTY.
|
|
8
|
+
*
|
|
9
|
+
* The bug these pin: the terminal panel is mounted while hidden, so an attach
|
|
10
|
+
* on mount spawned one idle shell per session the user visited. The other half
|
|
11
|
+
* is just as load-bearing — once opened, a session keeps its shell when the
|
|
12
|
+
* view is hidden or the page reloads.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { describe, expect, test } from 'bun:test';
|
|
16
|
+
|
|
17
|
+
import { terminalConnection } from '@/client/hooks/workspace/terminal/connection';
|
|
18
|
+
|
|
19
|
+
describe('terminalConnection', () => {
|
|
20
|
+
test('a mounted but never-opened session connects nothing', () => {
|
|
21
|
+
expect(terminalConnection({ visible: false, ready: true, opened: false })).toEqual({
|
|
22
|
+
connect: false,
|
|
23
|
+
persist: false,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('a never-opened session whose blob has not loaded still connects nothing', () => {
|
|
28
|
+
expect(terminalConnection({ visible: false, ready: false, opened: false })).toEqual({
|
|
29
|
+
connect: false,
|
|
30
|
+
persist: false,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('the first on-screen render connects and records the opening', () => {
|
|
35
|
+
expect(terminalConnection({ visible: true, ready: true, opened: false })).toEqual({
|
|
36
|
+
connect: true,
|
|
37
|
+
persist: true,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('an on-screen terminal does not record the opening before the blob loads', () => {
|
|
42
|
+
// The write is deferred: the blob may already say opened, and overwriting a
|
|
43
|
+
// restored session's own value with a fresh "true" is not needed.
|
|
44
|
+
expect(terminalConnection({ visible: true, ready: false, opened: false })).toEqual({
|
|
45
|
+
connect: true,
|
|
46
|
+
persist: false,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('an opened session keeps its socket while the view is hidden', () => {
|
|
51
|
+
expect(terminalConnection({ visible: false, ready: true, opened: true })).toEqual({
|
|
52
|
+
connect: true,
|
|
53
|
+
persist: false,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('an opened session on screen writes nothing', () => {
|
|
58
|
+
expect(terminalConnection({ visible: true, ready: true, opened: true })).toEqual({
|
|
59
|
+
connect: true,
|
|
60
|
+
persist: false,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Whether this session's terminal should hold a socket — and therefore a PTY.
|
|
8
|
+
*
|
|
9
|
+
* Mounting is NOT opening. The desktop stack keeps every built-in panel mounted
|
|
10
|
+
* and hides it with CSS (`WorkspacePanels.tsx`), which is what preserves a
|
|
11
|
+
* tree's expansion, a search's results and a terminal's buffer across a switch;
|
|
12
|
+
* the terminal is additionally `liveWhileHidden` so it keeps reading while the
|
|
13
|
+
* user looks at Files. Starting the shell on mount therefore started one for
|
|
14
|
+
* every session the user merely VISITED: measured on a live server, 18 idle
|
|
15
|
+
* `zsh -i -l` children of the Kabmo pid, with a burst of seven inside two
|
|
16
|
+
* minutes, none of them opened by the user.
|
|
17
|
+
*
|
|
18
|
+
* So the shell starts on the first render where the panel is genuinely on
|
|
19
|
+
* screen, and from then on the session OWNS it: `terminal.opened` is persisted
|
|
20
|
+
* per session, so switching to another view, collapsing the column or reloading
|
|
21
|
+
* the page reattaches instead of letting the idle reaper collect a shell the
|
|
22
|
+
* user opened. `ready` gates only the WRITE — a blob that has not loaded yet
|
|
23
|
+
* cannot say whether this session was already opened.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export interface TerminalConnectionState {
|
|
27
|
+
/** The panel is on screen AND has a workspace to open the shell in. */
|
|
28
|
+
visible: boolean;
|
|
29
|
+
/** The session's state blob (with `terminal.opened`) has loaded. */
|
|
30
|
+
ready: boolean;
|
|
31
|
+
/** The persisted `terminal.opened` of this session. */
|
|
32
|
+
opened: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TerminalConnection {
|
|
36
|
+
/** Hold a socket for this session. */
|
|
37
|
+
connect: boolean;
|
|
38
|
+
/** This is the first opening; the caller persists it. */
|
|
39
|
+
persist: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function terminalConnection(state: TerminalConnectionState): TerminalConnection {
|
|
43
|
+
return {
|
|
44
|
+
connect: state.visible || state.opened,
|
|
45
|
+
persist: state.ready && state.visible && !state.opened,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -22,11 +22,22 @@ import { useSessionState } from '@/client/hooks/workspace/session-state';
|
|
|
22
22
|
import { useSessionStateContext } from '@/client/hooks/workspace/session-state/context';
|
|
23
23
|
import { getSessionValue } from '@/shared/lib/workspace/session-state/store';
|
|
24
24
|
import { connectTerminal, type TerminalSocket } from '@/client/hooks/workspace/terminal/socket';
|
|
25
|
+
import { terminalConnection } from '@/client/hooks/workspace/terminal/connection';
|
|
25
26
|
import { newTerminalId, type TerminalReadyFrame } from '@/shared/lib/workspace/terminal/protocol';
|
|
26
27
|
|
|
27
28
|
export type TerminalStatus = 'connecting' | 'running' | 'exited' | 'error';
|
|
28
29
|
|
|
29
30
|
export interface UseTerminalOptions {
|
|
31
|
+
/**
|
|
32
|
+
* True while the panel is actually on screen — selected AND its column open
|
|
33
|
+
* — and there is a workspace to launch the shell in.
|
|
34
|
+
*
|
|
35
|
+
* The desktop keeps every built-in view mounted while hidden, so a socket
|
|
36
|
+
* opened on mount started a PTY for every session the user merely visited.
|
|
37
|
+
* The shell starts on the first visible render instead, and stays for the
|
|
38
|
+
* rest of the session (see `connection.ts`).
|
|
39
|
+
*/
|
|
40
|
+
visible?: boolean;
|
|
30
41
|
root?: string;
|
|
31
42
|
repo?: string;
|
|
32
43
|
theme?: 'light' | 'dark';
|
|
@@ -59,6 +70,15 @@ export interface UseTerminalResult {
|
|
|
59
70
|
export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult {
|
|
60
71
|
const { sessionId, ready } = useSessionStateContext();
|
|
61
72
|
const [terminalId, setTerminalId] = useSessionState<string>('terminal.id', '');
|
|
73
|
+
// Set the first time the panel is genuinely on screen for this session; read
|
|
74
|
+
// on every later mount so a reload or a view switch reattaches to the shell
|
|
75
|
+
// instead of waiting for the user to open the panel again.
|
|
76
|
+
const [storedOpened, setStoredOpened] = useSessionState<boolean>('terminal.opened', false);
|
|
77
|
+
const connection = terminalConnection({
|
|
78
|
+
visible: options.visible === true,
|
|
79
|
+
ready,
|
|
80
|
+
opened: storedOpened,
|
|
81
|
+
});
|
|
62
82
|
const [status, setStatus] = useState<TerminalStatus>('connecting');
|
|
63
83
|
const [shell, setShell] = useState('');
|
|
64
84
|
const [exitCode, setExitCode] = useState<number | null>(null);
|
|
@@ -87,19 +107,30 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
|
|
|
87
107
|
/** Last `root\0repo` the shell was launched for; null until the first. */
|
|
88
108
|
const scopeRef = useRef<string | null>(null);
|
|
89
109
|
|
|
110
|
+
// The first render where the panel is on screen is the opening; from then on
|
|
111
|
+
// the session owns its shell, because the persisted flag — not the current
|
|
112
|
+
// visibility — is what the socket effect below reads.
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!connection.persist) return;
|
|
115
|
+
setStoredOpened(true);
|
|
116
|
+
}, [connection.persist]);
|
|
117
|
+
|
|
90
118
|
// One id per Kabmo session. The check reads the store, not the hook's local
|
|
91
119
|
// value: on the render where the blob first becomes ready, `useSessionState`
|
|
92
120
|
// still reports the fallback (its restore effect has not run yet), so
|
|
93
121
|
// deciding from the local value would mint a second id and overwrite the
|
|
94
122
|
// stored one — orphaning the live shell and its scrollback.
|
|
123
|
+
//
|
|
124
|
+
// Minted only for a session that may connect: an id for a panel nobody opened
|
|
125
|
+
// is state no shell will ever use.
|
|
95
126
|
useEffect(() => {
|
|
96
|
-
if (!ready) return;
|
|
127
|
+
if (!connection.connect || !ready) return;
|
|
97
128
|
if (getSessionValue<string>(sessionId, 'terminal.id')) return;
|
|
98
129
|
setIdRef.current(newTerminalId());
|
|
99
|
-
}, [ready, sessionId]);
|
|
130
|
+
}, [connection.connect, ready, sessionId]);
|
|
100
131
|
|
|
101
132
|
useEffect(() => {
|
|
102
|
-
if (!ready || !terminalId) return;
|
|
133
|
+
if (!connection.connect || !ready || !terminalId) return;
|
|
103
134
|
|
|
104
135
|
setStatus('connecting');
|
|
105
136
|
setError(null);
|
|
@@ -141,7 +172,7 @@ export function useTerminal(options: UseTerminalOptions = {}): UseTerminalResult
|
|
|
141
172
|
socket.release();
|
|
142
173
|
socketRef.current = null;
|
|
143
174
|
};
|
|
144
|
-
}, [ready, terminalId, generation]);
|
|
175
|
+
}, [connection.connect, ready, terminalId, generation]);
|
|
145
176
|
|
|
146
177
|
const restart = useCallback(() => {
|
|
147
178
|
// Kill the old shell before minting a new id: leaving it to the idle
|
|
@@ -23,6 +23,7 @@ import { useState } from 'preact/hooks';
|
|
|
23
23
|
import { useFetcher } from '@/client/lib/router/fetcher';
|
|
24
24
|
import { useSessionActions } from '@/client/hooks/workspace/session-actions';
|
|
25
25
|
import type { SessionItemData } from '@/shared/types';
|
|
26
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
26
27
|
|
|
27
28
|
/** Minimal folder shape the actions touch — avoids coupling to a full row. */
|
|
28
29
|
export interface WorkspaceFolderLike {
|
|
@@ -64,7 +65,7 @@ export interface WorkspaceFolderActions {
|
|
|
64
65
|
* same channel ("Renamed to …"), while a folder's own failures are the error
|
|
65
66
|
* tone their callers already assume.
|
|
66
67
|
*/
|
|
67
|
-
export type ReportFolderOutcome = (message: string, tone?:
|
|
68
|
+
export type ReportFolderOutcome = (message: string, tone?: ToastTone) => void;
|
|
68
69
|
|
|
69
70
|
export function useWorkspaceFolderActions(
|
|
70
71
|
folder: WorkspaceFolderLike,
|