@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
|
@@ -15,6 +15,7 @@ import { useCallback, useMemo } from 'preact/hooks';
|
|
|
15
15
|
import { useWaitingPrompts } from '@/client/hooks/chat/waiting/store';
|
|
16
16
|
import { useCancelWait } from '@/client/hooks/chat/waiting/cancel';
|
|
17
17
|
import type { WaitingPrompt } from '@/shared/types/waiting';
|
|
18
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
18
19
|
|
|
19
20
|
export interface HeldWait {
|
|
20
21
|
/** The waiting row for the open chat, or null. */
|
|
@@ -25,7 +26,7 @@ export interface HeldWait {
|
|
|
25
26
|
export function useHeldWait(
|
|
26
27
|
sessionId: string | null,
|
|
27
28
|
isPendingSession: boolean,
|
|
28
|
-
onNotice?: (message: string, type?:
|
|
29
|
+
onNotice?: (message: string, type?: ToastTone) => void,
|
|
29
30
|
): HeldWait {
|
|
30
31
|
const { prompts } = useWaitingPrompts();
|
|
31
32
|
const cancelWait = useCancelWait(onNotice);
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
/**
|
|
7
7
|
* The dialog's half of the background harness update.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* a `202` means the install is running in a WORKER (so the card must follow it)
|
|
11
|
-
* a
|
|
9
|
+
* Four properties, and each one is a failure this design exists to prevent:
|
|
10
|
+
* a `202` means the install is running in a WORKER (so the card must follow it);
|
|
11
|
+
* a second harness pressed while the first installs is ACCEPTED and QUEUED (it
|
|
12
|
+
* must be followed too, and its own settle reported); a `409` for the SAME
|
|
13
|
+
* harness must come back as the refusal it is (no second install); and a run
|
|
12
14
|
* already in flight must be ADOPTED when the card opens — otherwise a reload
|
|
13
15
|
* loses the spinner and the user presses the button again.
|
|
14
16
|
*
|
|
@@ -29,8 +31,10 @@ const realFetch = Bun.fetch;
|
|
|
29
31
|
const TEST_POLL_MS = 1;
|
|
30
32
|
let container: HTMLElement;
|
|
31
33
|
let calls: string[] = [];
|
|
32
|
-
let
|
|
33
|
-
let
|
|
34
|
+
let postReplies: { status: number; body: unknown }[] = [];
|
|
35
|
+
let statusJobs: HarnessUpdateJob[] = [];
|
|
36
|
+
/** Called when the card re-reads the version rows (the probe-arrival signal). */
|
|
37
|
+
let onVersionsRead: (() => void) | null = null;
|
|
34
38
|
|
|
35
39
|
function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
36
40
|
return {
|
|
@@ -38,6 +42,7 @@ function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
|
38
42
|
label: 'claude',
|
|
39
43
|
startedAt: Date.now(),
|
|
40
44
|
finishedAt: null,
|
|
45
|
+
queuedAt: null,
|
|
41
46
|
pid: 1234,
|
|
42
47
|
steps: [{ part: 'adapter', command: 'npm install -g x', argv: ['npm', 'install', '-g', 'x'], state: 'running', code: null }],
|
|
43
48
|
output: '',
|
|
@@ -49,19 +54,30 @@ function job(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
|
49
54
|
};
|
|
50
55
|
}
|
|
51
56
|
|
|
57
|
+
function finished(overrides: Partial<HarnessUpdateJob> = {}): HarnessUpdateJob {
|
|
58
|
+
return job({ pid: null, finishedAt: Date.now(), ok: true, applied: true, ...overrides });
|
|
59
|
+
}
|
|
60
|
+
|
|
52
61
|
beforeEach(() => {
|
|
53
62
|
installDomGlobals(new Window({ url: 'http://localhost' }));
|
|
54
63
|
container = document.createElement('div');
|
|
55
64
|
document.body.appendChild(container);
|
|
56
65
|
calls = [];
|
|
57
|
-
|
|
58
|
-
|
|
66
|
+
statusJobs = [];
|
|
67
|
+
postReplies = [];
|
|
68
|
+
onVersionsRead = null;
|
|
59
69
|
(globalThis as unknown as Record<string, unknown>).fetch = async (input: unknown, init?: { method?: string }) => {
|
|
60
70
|
calls.push(`${init?.method ?? 'GET'} ${String(input)}`);
|
|
61
71
|
if (init?.method === 'POST') {
|
|
62
|
-
|
|
72
|
+
const reply = postReplies.length > 1 ? postReplies.shift()! : postReplies[0];
|
|
73
|
+
return new Response(JSON.stringify(reply?.body ?? {}), { status: reply?.status ?? 202 });
|
|
74
|
+
}
|
|
75
|
+
if (String(input).includes('/api/harness/versions')) {
|
|
76
|
+
onVersionsRead?.();
|
|
77
|
+
onVersionsRead = null;
|
|
78
|
+
return new Response(JSON.stringify({ harnesses: [] }), { status: 200 });
|
|
63
79
|
}
|
|
64
|
-
return new Response(JSON.stringify({
|
|
80
|
+
return new Response(JSON.stringify({ jobs: statusJobs }), { status: 200 });
|
|
65
81
|
};
|
|
66
82
|
});
|
|
67
83
|
|
|
@@ -74,15 +90,21 @@ afterEach(() => {
|
|
|
74
90
|
|
|
75
91
|
interface Harness {
|
|
76
92
|
current: () => ReturnType<typeof useHarnessUpdate>;
|
|
77
|
-
/**
|
|
78
|
-
|
|
93
|
+
/** The settled messages, in order. */
|
|
94
|
+
settlements: Array<{ message: string; ok: boolean }>;
|
|
95
|
+
/** Resolves when settlement number `index` has been reported. */
|
|
96
|
+
settlement: (index: number) => Promise<{ message: string; ok: boolean }>;
|
|
79
97
|
}
|
|
80
98
|
|
|
81
99
|
function mount(): Harness {
|
|
82
|
-
const
|
|
100
|
+
const settlements: Array<{ message: string; ok: boolean }> = [];
|
|
101
|
+
const waiters: Array<() => void> = [];
|
|
83
102
|
const box = { latest: null as ReturnType<typeof useHarnessUpdate> | null };
|
|
84
103
|
function Consumer() {
|
|
85
|
-
box.latest = useHarnessUpdate((message, ok) =>
|
|
104
|
+
box.latest = useHarnessUpdate((message, ok) => {
|
|
105
|
+
settlements.push({ message, ok });
|
|
106
|
+
waiters.shift()?.();
|
|
107
|
+
}, { pollMs: TEST_POLL_MS });
|
|
86
108
|
return null;
|
|
87
109
|
}
|
|
88
110
|
const host = document.createElement('div');
|
|
@@ -93,7 +115,15 @@ function mount(): Harness {
|
|
|
93
115
|
if (!box.latest) throw new Error('consumer did not render');
|
|
94
116
|
return box.latest;
|
|
95
117
|
},
|
|
96
|
-
|
|
118
|
+
settlements,
|
|
119
|
+
settlement: async (index) => {
|
|
120
|
+
while (settlements.length <= index) {
|
|
121
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
122
|
+
waiters.push(resolve);
|
|
123
|
+
await promise;
|
|
124
|
+
}
|
|
125
|
+
return settlements[index];
|
|
126
|
+
},
|
|
97
127
|
};
|
|
98
128
|
}
|
|
99
129
|
|
|
@@ -105,38 +135,76 @@ async function flush(): Promise<void> {
|
|
|
105
135
|
});
|
|
106
136
|
}
|
|
107
137
|
|
|
138
|
+
const GETS = (): string[] => calls.filter((call) => call.startsWith('GET /api/harness/update/status'));
|
|
139
|
+
|
|
108
140
|
describe('useHarnessUpdate', () => {
|
|
109
141
|
test('a 202 starts a run and the finished record settles it', async () => {
|
|
110
142
|
const harness = mount();
|
|
111
143
|
await flush();
|
|
112
|
-
expect(harness.current().
|
|
144
|
+
expect(harness.current().jobs).toEqual([]);
|
|
113
145
|
|
|
114
|
-
|
|
146
|
+
postReplies = [{ status: 202, body: { started: true, queued: false, job: job() } }];
|
|
115
147
|
// The worker is already done by the time the first status read lands: this
|
|
116
148
|
// is the spinners-then-message path, with no real delay anywhere.
|
|
117
|
-
|
|
149
|
+
statusJobs = [finished({ message: 'claude updated (adapter)' })];
|
|
118
150
|
|
|
119
151
|
const started: { problem: string | null } = { problem: 'unset' };
|
|
120
152
|
await act(async () => {
|
|
121
153
|
started.problem = await harness.current().start('claude');
|
|
122
154
|
});
|
|
123
155
|
expect(started.problem).toBeNull();
|
|
124
|
-
|
|
125
|
-
// record was already finished, so the run settles inside the same flush.
|
|
126
|
-
expect(await harness.settled).toEqual({ message: 'claude updated (adapter)', ok: true });
|
|
127
|
-
expect(harness.current().updating).toBeNull();
|
|
156
|
+
expect(await harness.settlement(0)).toEqual({ message: 'claude updated (adapter)', ok: true });
|
|
128
157
|
// The record outlives the spinner: the log panel reads it AFTER the run, and
|
|
129
|
-
// a cleared
|
|
130
|
-
expect(harness.current().
|
|
158
|
+
// a cleared list would close the reader's only view of what was installed.
|
|
159
|
+
expect(harness.current().jobs[0]?.message).toBe('claude updated (adapter)');
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
test('a second harness is ACCEPTED as queued, and both settles are reported', async () => {
|
|
163
|
+
// The bug this fixes: pressing the second row while the first installed got
|
|
164
|
+
// a 409 and nothing else. Both presses now return 202 — the second with a
|
|
165
|
+
// `queued` record — and the queue starts it after the first settles.
|
|
166
|
+
const harness = mount();
|
|
167
|
+
await flush();
|
|
168
|
+
|
|
169
|
+
postReplies = [
|
|
170
|
+
{ status: 202, body: { started: true, queued: false, job: job() } },
|
|
171
|
+
{ status: 202, body: { started: true, queued: true, job: job({ harness: 'codex', label: 'codex', pid: null, queuedAt: Date.now() }) } },
|
|
172
|
+
];
|
|
173
|
+
statusJobs = [job(), job({ harness: 'codex', label: 'codex', pid: null, queuedAt: Date.now() })];
|
|
174
|
+
|
|
175
|
+
let first: string | null = 'unset';
|
|
176
|
+
let second: string | null = 'unset';
|
|
177
|
+
await act(async () => {
|
|
178
|
+
first = await harness.current().start('claude');
|
|
179
|
+
second = await harness.current().start('codex');
|
|
180
|
+
});
|
|
181
|
+
expect(first).toBeNull();
|
|
182
|
+
expect(second).toBeNull();
|
|
183
|
+
expect(harness.current().jobs.map((entry) => entry.harness).sort()).toEqual(['claude', 'codex']);
|
|
184
|
+
|
|
185
|
+
// Claude finishes, the queue starts codex, codex finishes.
|
|
186
|
+
statusJobs = [
|
|
187
|
+
finished({ message: 'claude updated (adapter)' }),
|
|
188
|
+
job({ harness: 'codex', label: 'codex' }),
|
|
189
|
+
];
|
|
190
|
+
expect(await harness.settlement(0)).toEqual({ message: 'claude updated (adapter)', ok: true });
|
|
191
|
+
|
|
192
|
+
statusJobs = [
|
|
193
|
+
finished({ message: 'claude updated (adapter)' }),
|
|
194
|
+
finished({ harness: 'codex', label: 'codex', message: 'codex updated (codex-acp)' }),
|
|
195
|
+
];
|
|
196
|
+
expect(await harness.settlement(1)).toEqual({ message: 'codex updated (codex-acp)', ok: true });
|
|
197
|
+
// One settle each, not one per poll.
|
|
198
|
+
expect(harness.settlements).toHaveLength(2);
|
|
131
199
|
});
|
|
132
200
|
|
|
133
201
|
test('a 409 comes back as the refusal, and its record is still readable', async () => {
|
|
134
|
-
// The refusal carries the
|
|
135
|
-
// race can still open the log of the install it collided with.
|
|
136
|
-
|
|
202
|
+
// The refusal carries the unfinished record (`job`), so the press that lost
|
|
203
|
+
// the race can still open the log of the install it collided with.
|
|
204
|
+
postReplies = [{
|
|
137
205
|
status: 409,
|
|
138
206
|
body: { error: 'claude update is already running — it continues in the background', job: job({ pid: 999 }) },
|
|
139
|
-
};
|
|
207
|
+
}];
|
|
140
208
|
const harness = mount();
|
|
141
209
|
await flush();
|
|
142
210
|
|
|
@@ -145,36 +213,63 @@ describe('useHarnessUpdate', () => {
|
|
|
145
213
|
refusal.problem = await harness.current().start('claude');
|
|
146
214
|
});
|
|
147
215
|
expect(refusal.problem).toContain('already running');
|
|
148
|
-
expect(harness.current().
|
|
149
|
-
expect(harness.
|
|
216
|
+
expect(harness.current().jobs[0]?.pid).toBe(999);
|
|
217
|
+
expect(harness.settlements).toEqual([]);
|
|
150
218
|
});
|
|
151
219
|
|
|
152
220
|
test('an in-flight run is adopted when the card opens', async () => {
|
|
153
|
-
|
|
221
|
+
statusJobs = [job()];
|
|
154
222
|
const harness = mount();
|
|
155
223
|
await flush();
|
|
156
224
|
// The spinner belongs to a run this page did not start — a second tab, or
|
|
157
225
|
// this one after a reload.
|
|
158
|
-
expect(harness.current().
|
|
226
|
+
expect(harness.current().jobs[0]?.harness).toBe('claude');
|
|
227
|
+
|
|
228
|
+
statusJobs = [finished({ ok: false, message: 'claude update failed (exit 1)' })];
|
|
229
|
+
expect(await harness.settlement(0)).toEqual({ message: 'claude update failed (exit 1)', ok: false });
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('a settled run keeps polling until its PROBE answers, then re-reads the rows', async () => {
|
|
233
|
+
// The row quotes the version the install just replaced until the server has
|
|
234
|
+
// asked the new binary what it is. The poll is what carries that answer to
|
|
235
|
+
// the row; without it, "updated" and a stale number sit side by side and the
|
|
236
|
+
// only way out is pressing Check status.
|
|
237
|
+
statusJobs = [finished({ message: 'claude updated (adapter)', probe: 'pending' })];
|
|
238
|
+
const versionsRead = Promise.withResolvers<void>();
|
|
239
|
+
onVersionsRead = versionsRead.resolve;
|
|
240
|
+
const harness = mount();
|
|
241
|
+
await flush();
|
|
242
|
+
expect(harness.current().jobs[0]?.probe).toBe('pending');
|
|
243
|
+
expect(harness.settlements).toEqual([]);
|
|
159
244
|
|
|
160
|
-
|
|
161
|
-
|
|
245
|
+
// The probe answers on a later poll; the row's own read is the proof that it
|
|
246
|
+
// arrived, and it is awaited rather than slept for.
|
|
247
|
+
statusJobs = [finished({ message: 'claude updated (adapter) — it now reports 0.103.0', probe: 'done' })];
|
|
248
|
+
await versionsRead.promise;
|
|
249
|
+
expect(calls).toContain('GET /api/harness/versions');
|
|
250
|
+
expect(harness.current().jobs[0]?.probe).toBe('done');
|
|
251
|
+
// The probe arriving is not a second toast: one run, one report.
|
|
252
|
+
expect(harness.settlements).toEqual([]);
|
|
162
253
|
});
|
|
163
254
|
|
|
164
|
-
test('a finished record on open is history, not a run to
|
|
165
|
-
|
|
255
|
+
test('a finished record on open is history, not a run to toast about', async () => {
|
|
256
|
+
statusJobs = [finished({ message: 'claude updated (adapter)' })];
|
|
166
257
|
const harness = mount();
|
|
167
258
|
await flush();
|
|
168
|
-
|
|
259
|
+
// The loop stopped after the ONE read: no unfinished record means nothing to
|
|
260
|
+
// follow, so a finished record can never be reported as a fresh settle.
|
|
261
|
+
expect(harness.settlements).toEqual([]);
|
|
169
262
|
// No spinner, but the row can still offer the log of what ran.
|
|
170
|
-
expect(harness.current().
|
|
263
|
+
expect(harness.current().jobs[0]?.harness).toBe('claude');
|
|
264
|
+
// One read and no follow-up: nothing is unfinished.
|
|
265
|
+
expect(GETS()).toHaveLength(1);
|
|
171
266
|
});
|
|
172
267
|
|
|
173
268
|
test('"already up to date" is reported without following a job', async () => {
|
|
174
|
-
|
|
269
|
+
postReplies = [{
|
|
175
270
|
status: 200,
|
|
176
271
|
body: { success: true, id: 'claude', message: 'claude is already up to date (adapter 0.102.0)' },
|
|
177
|
-
};
|
|
272
|
+
}];
|
|
178
273
|
const harness = mount();
|
|
179
274
|
await flush();
|
|
180
275
|
|
|
@@ -183,11 +278,9 @@ describe('useHarnessUpdate', () => {
|
|
|
183
278
|
current.problem = await harness.current().start('claude');
|
|
184
279
|
});
|
|
185
280
|
expect(current.problem).toBeNull();
|
|
186
|
-
expect(harness.current().
|
|
187
|
-
|
|
188
|
-
expect(harness.current().job).toBeNull();
|
|
189
|
-
expect(await harness.settled).toEqual({ message: 'claude is already up to date (adapter 0.102.0)', ok: true });
|
|
281
|
+
expect(harness.current().jobs).toEqual([]);
|
|
282
|
+
expect(await harness.settlement(0)).toEqual({ message: 'claude is already up to date (adapter 0.102.0)', ok: true });
|
|
190
283
|
// One read — the mount's — and no poll for a job that does not exist.
|
|
191
|
-
expect(
|
|
284
|
+
expect(GETS()).toHaveLength(1);
|
|
192
285
|
});
|
|
193
286
|
});
|
|
@@ -4,23 +4,36 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Starting
|
|
7
|
+
* Starting harness updates, and following every background run they became.
|
|
8
8
|
*
|
|
9
9
|
* The POST used to hold the request open for the whole install; now it answers
|
|
10
|
-
* `202` and
|
|
10
|
+
* `202` and each run continues in a detached worker. So the dialog's job has two
|
|
11
11
|
* halves: start it, then poll `GET /api/harness/update/status` until the record
|
|
12
|
-
* says it finished — and, on open, ADOPT
|
|
12
|
+
* says it finished — and, on open, ADOPT whatever is already in flight. That
|
|
13
13
|
* second half is what makes the update really background: closing About, or
|
|
14
14
|
* reloading the page, does not lose the button's state, and a reopened card
|
|
15
15
|
* shows the spinner for the run that is still installing.
|
|
16
16
|
*
|
|
17
|
-
*
|
|
17
|
+
* **ONE loop for EVERY run, because two presses are two records.** A second
|
|
18
|
+
* harness is accepted while the first installs: its record carries `queuedAt`
|
|
19
|
+
* and the server's queue starts it when the run ahead settles, so the card has
|
|
20
|
+
* to follow a run it did not start AND one that has not started yet. A finished
|
|
21
|
+
* run is reported once per harness, and a record that was already finished when
|
|
22
|
+
* the card opened is HISTORY — a reopened dialog must not re-toast last week's
|
|
23
|
+
* install.
|
|
24
|
+
*
|
|
25
|
+
* The rows are re-read once a run settles (`invalidateHarnessVersions`): the
|
|
18
26
|
* update forgot the cached probe, so the next read is the first honest one.
|
|
19
27
|
*/
|
|
20
28
|
|
|
21
29
|
import { useCallback, useEffect, useRef, useState } from 'preact/hooks';
|
|
22
30
|
import { invalidateHarnessVersions } from '@/client/hooks/models/use-harness-versions';
|
|
23
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
isHarnessUpdateJob,
|
|
33
|
+
jobMoving,
|
|
34
|
+
jobUnfinished,
|
|
35
|
+
updateJobsFrom,
|
|
36
|
+
} from '@/shared/lib/harness/update-job';
|
|
24
37
|
import type { HarnessUpdateJob } from '@/shared/types/harness-update';
|
|
25
38
|
|
|
26
39
|
/** One poll per second: the worker flushes at 400ms, and this is a dialog. */
|
|
@@ -29,9 +42,10 @@ export const HARNESS_UPDATE_POLL_MS = 1_000;
|
|
|
29
42
|
/**
|
|
30
43
|
* Stop polling after this long and hand the control back.
|
|
31
44
|
*
|
|
32
|
-
* The install itself is bounded per step by the worker; this only stops an
|
|
33
|
-
*
|
|
34
|
-
* cancelled — closing the dialog never cancels anything
|
|
45
|
+
* The install itself is bounded per step by the worker; this only stops an open
|
|
46
|
+
* dialog from asking forever if the server stopped answering. The run is not
|
|
47
|
+
* cancelled — closing the dialog never cancels anything, and a queued run is
|
|
48
|
+
* started by the server's own ticker.
|
|
35
49
|
*/
|
|
36
50
|
const MAX_FOLLOW_MS = 45 * 60_000;
|
|
37
51
|
|
|
@@ -47,105 +61,137 @@ export interface HarnessUpdateOptions {
|
|
|
47
61
|
}
|
|
48
62
|
|
|
49
63
|
export interface HarnessUpdateController {
|
|
50
|
-
/** The harness whose run this dialog is following, or null. */
|
|
51
|
-
updating: string | null;
|
|
52
|
-
/** The step the worker is on (`adapter`, `Claude Code`, …), when it says. */
|
|
53
|
-
progress: string | null;
|
|
54
64
|
/**
|
|
55
|
-
* The
|
|
65
|
+
* The last known record per harness — waiting, installing, or the last run
|
|
66
|
+
* that finished.
|
|
56
67
|
*
|
|
57
|
-
* The
|
|
58
|
-
*
|
|
59
|
-
* run
|
|
60
|
-
* it failed.
|
|
68
|
+
* The rows render from this: `jobQueued`/`jobRunning`/`runningStepOf` answer
|
|
69
|
+
* what to draw, and the log dialog renders the record's own steps and output.
|
|
70
|
+
* A settled run is NOT cleared, because the interesting moment to read the log
|
|
71
|
+
* is often after it failed.
|
|
61
72
|
*/
|
|
62
|
-
|
|
73
|
+
jobs: HarnessUpdateJob[];
|
|
63
74
|
/** Start an update; resolves to a refusal, or null when the run was started
|
|
64
|
-
* (or
|
|
75
|
+
* (immediately or queued behind the one already installing). */
|
|
65
76
|
start: (id: string) => Promise<string | null>;
|
|
66
77
|
}
|
|
67
78
|
|
|
68
79
|
type Settled = (message: string, ok: boolean) => void;
|
|
69
80
|
|
|
70
|
-
function runningStep(job: HarnessUpdateJob | null): string | null {
|
|
71
|
-
const steps = job && Array.isArray(job.steps) ? job.steps : [];
|
|
72
|
-
return steps.find((step) => step.state === 'running')?.part ?? null;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
81
|
export function useHarnessUpdate(
|
|
76
82
|
onSettled: Settled,
|
|
77
83
|
{ pollMs = HARNESS_UPDATE_POLL_MS, enabled = true }: HarnessUpdateOptions = {},
|
|
78
84
|
): HarnessUpdateController {
|
|
79
|
-
const [
|
|
80
|
-
const [progress, setProgress] = useState<string | null>(null);
|
|
81
|
-
const [job, setJob] = useState<HarnessUpdateJob | null>(null);
|
|
85
|
+
const [jobs, setJobs] = useState<HarnessUpdateJob[]>([]);
|
|
82
86
|
const alive = useRef(true);
|
|
87
|
+
const polling = useRef(false);
|
|
88
|
+
// Which harnesses this card WATCHED install. A run it only saw as history is
|
|
89
|
+
// not one to toast about, and the same harness must not be reported twice.
|
|
90
|
+
const watched = useRef(new Set<string>());
|
|
91
|
+
const reported = useRef(new Set<string>());
|
|
92
|
+
// Runs whose post-install probe answer has already been reflected in the rows.
|
|
93
|
+
const probed = useRef(new Set<string>());
|
|
83
94
|
// The callback is read through a ref so an inline arrow from the caller does
|
|
84
|
-
// not restart the mount effect (and re-adopt the
|
|
95
|
+
// not restart the mount effect (and re-adopt the records) on every render.
|
|
85
96
|
const settled = useRef(onSettled);
|
|
86
97
|
settled.current = onSettled;
|
|
87
98
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
99
|
+
/** Fold one harness's record into the list, keeping the newer one. */
|
|
100
|
+
const merge = useCallback((incoming: HarnessUpdateJob | null) => {
|
|
101
|
+
if (!incoming) return;
|
|
102
|
+
setJobs((current) => {
|
|
103
|
+
const index = current.findIndex((job) => job.harness === incoming.harness);
|
|
104
|
+
if (index < 0) return [...current, incoming];
|
|
105
|
+
const next = current.slice();
|
|
106
|
+
next[index] = incoming;
|
|
107
|
+
return next;
|
|
108
|
+
});
|
|
109
|
+
}, []);
|
|
100
110
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Report the runs that went from unfinished to finished, and re-read the rows
|
|
113
|
+
* once each run's post-install PROBE answers.
|
|
114
|
+
*
|
|
115
|
+
* The probe is what stops the row quoting the version the update replaced, and
|
|
116
|
+
* it lands AFTER the run settles — so the settle report and the version refresh
|
|
117
|
+
* are two separate moments, not one.
|
|
118
|
+
*/
|
|
119
|
+
const observe = useCallback((incoming: HarnessUpdateJob[]) => {
|
|
120
|
+
setJobs(incoming);
|
|
121
|
+
for (const job of incoming) {
|
|
122
|
+
if (jobUnfinished(job)) {
|
|
123
|
+
watched.current.add(job.harness);
|
|
124
|
+
reported.current.delete(job.harness);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (watched.current.has(job.harness) && !reported.current.has(job.harness)) {
|
|
128
|
+
reported.current.add(job.harness);
|
|
108
129
|
invalidateHarnessVersions();
|
|
109
130
|
settled.current(job.message ?? (job.ok ? 'Update finished' : 'Update failed'), Boolean(job.ok));
|
|
110
|
-
return;
|
|
111
131
|
}
|
|
112
|
-
|
|
132
|
+
// A run whose probe settled: the numbers the row reads are now the new
|
|
133
|
+
// ones, so the cached rows must be dropped. `startedAt` identifies the run,
|
|
134
|
+
// because the next update replaces the record under the same harness.
|
|
135
|
+
if (job.probe === 'done') {
|
|
136
|
+
const key = `${job.harness}:${job.startedAt}`;
|
|
137
|
+
if (!probed.current.has(key)) {
|
|
138
|
+
probed.current.add(key);
|
|
139
|
+
invalidateHarnessVersions();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}, []);
|
|
113
144
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Follow every unfinished record until they all settle.
|
|
147
|
+
*
|
|
148
|
+
* One loop, not one per harness: a queued run and an installing run are two
|
|
149
|
+
* rows of the same poll, and a loop per press would double the reads for no
|
|
150
|
+
* extra answer. `polling` keeps a second caller (the mount effect and a press
|
|
151
|
+
* landing together) from starting a second loop.
|
|
152
|
+
*/
|
|
153
|
+
const follow = useCallback(async (): Promise<void> => {
|
|
154
|
+
if (polling.current) return;
|
|
155
|
+
polling.current = true;
|
|
156
|
+
const startedAt = Date.now();
|
|
157
|
+
try {
|
|
158
|
+
while (alive.current) {
|
|
159
|
+
let next: HarnessUpdateJob[] | null = null;
|
|
160
|
+
try {
|
|
161
|
+
const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
|
|
162
|
+
if (!response.ok) throw new Error(String(response.status));
|
|
163
|
+
next = updateJobsFrom(await response.json());
|
|
164
|
+
} catch {
|
|
165
|
+
// A transient failure is not the update failing: the records live on
|
|
166
|
+
// disk and the next poll reads them.
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!alive.current) return;
|
|
170
|
+
if (next) observe(next);
|
|
171
|
+
// Nothing left to watch — a queued run keeps this loop alive (the
|
|
172
|
+
// server starts it when the install ahead finishes), and so does a run
|
|
173
|
+
// whose post-install probe has not answered yet.
|
|
174
|
+
if (!next || !next.some(jobMoving)) return;
|
|
175
|
+
if (Date.now() - startedAt > MAX_FOLLOW_MS) return;
|
|
176
|
+
const { promise, resolve } = Promise.withResolvers<void>();
|
|
177
|
+
setTimeout(resolve, pollMs);
|
|
178
|
+
await promise;
|
|
118
179
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
await promise;
|
|
180
|
+
} finally {
|
|
181
|
+
polling.current = false;
|
|
122
182
|
}
|
|
123
|
-
}, [pollMs]);
|
|
183
|
+
}, [observe, pollMs]);
|
|
124
184
|
|
|
125
|
-
// Adopt
|
|
185
|
+
// Adopt whatever is already going: another tab, a run accepted before a
|
|
186
|
+
// reload, or a queued one. A closed card has nothing to show and nothing to
|
|
187
|
+
// poll for; the workers and the queue keep going either way.
|
|
126
188
|
useEffect(() => {
|
|
127
|
-
// A closed card has nothing to show and nothing to poll for; the run keeps
|
|
128
|
-
// going in its worker either way.
|
|
129
189
|
if (!enabled) {
|
|
130
190
|
alive.current = false;
|
|
131
191
|
return;
|
|
132
192
|
}
|
|
133
193
|
alive.current = true;
|
|
134
|
-
void (
|
|
135
|
-
try {
|
|
136
|
-
const response = await fetch('/api/harness/update/status', { cache: 'no-store' });
|
|
137
|
-
if (!response.ok) return;
|
|
138
|
-
const running = updateJobFrom(await response.json());
|
|
139
|
-
if (!alive.current || !running) return;
|
|
140
|
-
setJob(running);
|
|
141
|
-
if (running.finishedAt !== null) return;
|
|
142
|
-
setUpdating(running.harness);
|
|
143
|
-
setProgress(runningStep(running));
|
|
144
|
-
void follow(running.harness);
|
|
145
|
-
} catch {
|
|
146
|
-
// Nothing running, or no server to ask: the list still renders.
|
|
147
|
-
}
|
|
148
|
-
})();
|
|
194
|
+
void follow();
|
|
149
195
|
return () => {
|
|
150
196
|
alive.current = false;
|
|
151
197
|
};
|
|
@@ -168,7 +214,8 @@ export function useHarnessUpdate(
|
|
|
168
214
|
message?: string;
|
|
169
215
|
success?: boolean;
|
|
170
216
|
started?: boolean;
|
|
171
|
-
|
|
217
|
+
queued?: boolean;
|
|
218
|
+
job?: unknown;
|
|
172
219
|
};
|
|
173
220
|
|
|
174
221
|
// The POST's own record is trusted only if it IS a record; a payload that
|
|
@@ -176,16 +223,17 @@ export function useHarnessUpdate(
|
|
|
176
223
|
const posted = isHarnessUpdateJob(payload.job) ? payload.job : null;
|
|
177
224
|
|
|
178
225
|
if (response.status === 202 && payload.started) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
226
|
+
// `started` covers both halves: installing now, or waiting its turn.
|
|
227
|
+
watched.current.add(id);
|
|
228
|
+
reported.current.delete(id);
|
|
229
|
+
merge(posted);
|
|
230
|
+
void follow();
|
|
183
231
|
return null;
|
|
184
232
|
}
|
|
185
233
|
if (!response.ok) {
|
|
186
|
-
// A refusal carries the
|
|
187
|
-
// instead of only being told to wait.
|
|
188
|
-
if (
|
|
234
|
+
// A refusal carries the record that caused it (`job`), so the reader can
|
|
235
|
+
// open ITS log instead of only being told to wait.
|
|
236
|
+
if (posted) merge(posted);
|
|
189
237
|
return payload.error ?? `Update failed (HTTP ${response.status})`;
|
|
190
238
|
}
|
|
191
239
|
if (payload.success) {
|
|
@@ -196,7 +244,7 @@ export function useHarnessUpdate(
|
|
|
196
244
|
return null;
|
|
197
245
|
}
|
|
198
246
|
return payload.error ?? 'Update failed';
|
|
199
|
-
}, [follow]);
|
|
247
|
+
}, [follow, merge]);
|
|
200
248
|
|
|
201
|
-
return {
|
|
249
|
+
return { jobs, start };
|
|
202
250
|
}
|
|
@@ -31,12 +31,13 @@ import type { ProviderItem } from '@/shared/types';
|
|
|
31
31
|
import { saveProviderOverlay, setProviderEnabled, deleteProvider } from '@/shared/lib/models/provider/connection';
|
|
32
32
|
import { addProviderMessage } from '@/client/hooks/settings/providers/messages';
|
|
33
33
|
import { loadProvidersFromApi } from '@/client/hooks/settings/providers/api';
|
|
34
|
+
import type { ToastTone } from '@/shared/lib/ui/toast-duration';
|
|
34
35
|
|
|
35
36
|
export interface ProviderActionsDeps {
|
|
36
37
|
providers: ProviderItem[];
|
|
37
38
|
selectedProvider: ProviderItem | undefined;
|
|
38
39
|
isDeletingProvider: boolean;
|
|
39
|
-
pushToast: (message: string, tone:
|
|
40
|
+
pushToast: (message: string, tone: ToastTone) => void;
|
|
40
41
|
setProviders: (providers: ProviderItem[]) => void;
|
|
41
42
|
setSelectedProviderId: (id: string) => void;
|
|
42
43
|
setIsAddModalOpen: (open: boolean) => void;
|
|
@@ -209,7 +210,7 @@ export function createProviderActions(deps: ProviderActionsDeps) {
|
|
|
209
210
|
// The overlay row is gone even when the file cleanup failed, so the
|
|
210
211
|
// warning is reported rather than presented as a clean delete.
|
|
211
212
|
if (result.warning) {
|
|
212
|
-
pushToast(`${provider.name} removed from Kabmo, but models.yml cleanup failed: ${result.warning}`, '
|
|
213
|
+
pushToast(`${provider.name} removed from Kabmo, but models.yml cleanup failed: ${result.warning}`, 'warning');
|
|
213
214
|
} else if (result.removedFromOmp) {
|
|
214
215
|
const count = result.modelsRemoved ?? 0;
|
|
215
216
|
pushToast(
|