@kabmo-labs/kabmo 0.25.0 → 0.26.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 +440 -436
- package/dist/client/static/js/{index-ga8cbpt4.js → index-95b3n20k.js} +945 -945
- package/dist/client/static/js/index-p2yw9ywf.css +1 -0
- package/package.json +1 -1
- 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/session-sidebar/CategoryItem.tsx +64 -68
- 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/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/index.tsx +28 -13
- package/src/client/components/layout/session-sidebar/modern/WorkspaceSection.tsx +59 -57
- package/src/client/components/mobile/mobile-session-sidebar/Item.tsx +57 -61
- 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/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/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 +28 -39
- package/src/client/components/workspace/chat-timeline/MessageList.tsx +7 -5
- package/src/client/components/workspace/chat-timeline/PendingChatView.tsx +10 -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/index.tsx +10 -21
- package/src/client/components/workspace/chat-timeline/target-picker/DraftTargetRow.tsx +115 -0
- package/src/client/components/workspace/chat-timeline/target-picker/ParentSessionPicker.tsx +173 -0
- package/src/client/components/workspace/chat-timeline/target-picker/parent-session-options.test.ts +49 -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 +4 -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-request.test.ts +54 -0
- package/src/client/hooks/chat/timeline/fork-request.ts +43 -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 +205 -0
- package/src/client/hooks/chat/timeline/pending-dispatch.ts +253 -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/models/use-harness-update.test.ts +137 -44
- package/src/client/hooks/models/use-harness-update.ts +133 -85
- 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/expanded-sessions.ts +36 -7
- 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/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/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/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
|
@@ -19,10 +19,12 @@ import { json } from '@/server/lib/remix-compat';
|
|
|
19
19
|
import type { ActionFunctionArgs } from '@/server/lib/remix-compat';
|
|
20
20
|
import { methodNotAllowed, parseJsonBody } from '@/server/lib/route-adapter';
|
|
21
21
|
import { emitRealtimeSignal } from '@/server/lib/realtime/signals.server';
|
|
22
|
+
import { readImages, readModel, readString } from '@/server/routes/sessions/body-readers';
|
|
23
|
+
import { isApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
24
|
+
import { isMockMode } from '@/server/mock.server';
|
|
22
25
|
import {
|
|
23
26
|
SessionSpawnError,
|
|
24
27
|
spawnChildSession,
|
|
25
|
-
type SpawnChildSessionInput,
|
|
26
28
|
} from '@/server/lib/sessions/spawn.server';
|
|
27
29
|
import { bearerToken, verifyAgentToken } from '@/server/lib/sessions/agent-token.server';
|
|
28
30
|
|
|
@@ -36,25 +38,15 @@ interface SpawnBody {
|
|
|
36
38
|
harness?: unknown;
|
|
37
39
|
cwd?: unknown;
|
|
38
40
|
prompt?: unknown;
|
|
41
|
+
images?: unknown;
|
|
39
42
|
model?: unknown;
|
|
40
43
|
thinkingLevel?: unknown;
|
|
44
|
+
accessMode?: unknown;
|
|
41
45
|
lifecycleOwnerSessionId?: unknown;
|
|
42
46
|
visibility?: unknown;
|
|
43
47
|
parentNotifications?: unknown;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
function readModel(value: unknown): SpawnChildSessionInput['model'] {
|
|
47
|
-
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
48
|
-
const record = value as Record<string, unknown>;
|
|
49
|
-
return typeof record.provider === 'string' && typeof record.modelId === 'string'
|
|
50
|
-
? { provider: record.provider, modelId: record.modelId }
|
|
51
|
-
: null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function readString(value: unknown): string | null {
|
|
55
|
-
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
50
|
function statusFor(code: SessionSpawnError['code']): number {
|
|
59
51
|
switch (code) {
|
|
60
52
|
case 'parent_not_found':
|
|
@@ -74,6 +66,12 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
|
|
|
74
66
|
const parsed = await parseJsonBody<SpawnBody>(request);
|
|
75
67
|
if (!parsed.ok) return json({ error: 'Invalid JSON body' }, { status: 400 });
|
|
76
68
|
|
|
69
|
+
// MOCK mode has no agent process to start. The client takes its simulated
|
|
70
|
+
// path on this CODE, exactly as it does for `POST /api/agent/new`.
|
|
71
|
+
if (isMockMode()) {
|
|
72
|
+
return json({ error: 'Mock mode runs no agent process', code: 'mock_mode' }, { status: 400 });
|
|
73
|
+
}
|
|
74
|
+
|
|
77
75
|
const prompt = readString(parsed.body.prompt);
|
|
78
76
|
if (!prompt) return json({ error: 'prompt is required' }, { status: 400 });
|
|
79
77
|
|
|
@@ -107,6 +105,9 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
|
|
|
107
105
|
) {
|
|
108
106
|
return json({ error: 'parentNotifications must be auto, stuck or off' }, { status: 400 });
|
|
109
107
|
}
|
|
108
|
+
if (parsed.body.accessMode !== undefined && !isApprovalMode(parsed.body.accessMode)) {
|
|
109
|
+
return json({ error: 'accessMode is not a valid approval mode' }, { status: 400 });
|
|
110
|
+
}
|
|
110
111
|
|
|
111
112
|
try {
|
|
112
113
|
const result = await spawnChildSession({
|
|
@@ -114,8 +115,10 @@ export async function spawnSession({ request }: ActionFunctionArgs) {
|
|
|
114
115
|
harness: readString(parsed.body.harness),
|
|
115
116
|
cwd: readString(parsed.body.cwd),
|
|
116
117
|
prompt,
|
|
118
|
+
images: readImages(parsed.body.images),
|
|
117
119
|
model: readModel(parsed.body.model),
|
|
118
120
|
thinkingLevel: readString(parsed.body.thinkingLevel),
|
|
121
|
+
accessMode: isApprovalMode(parsed.body.accessMode) ? parsed.body.accessMode : null,
|
|
119
122
|
lifecycleOwnerSessionId: readString(parsed.body.lifecycleOwnerSessionId),
|
|
120
123
|
...(visibility ? { visibility: visibility as Visibility } : {}),
|
|
121
124
|
...(notifications ? { parentNotifications: notifications as ParentNotifications } : {}),
|
|
@@ -18,6 +18,7 @@ import { extractTextFromContent, toChatMessage } from '@/shared/lib/omp/session/
|
|
|
18
18
|
import { normalizeNoticeText } from '@/shared/lib/chat/notice-text';
|
|
19
19
|
import { parseModeMarker } from '@/shared/lib/omp/mode/markers';
|
|
20
20
|
import { emitKabmoModeSignal } from '@/shared/lib/omp/mode/client-signal';
|
|
21
|
+
import { emitSessionModesChanged } from '@/shared/lib/harness/mode-signal';
|
|
21
22
|
import { KABMO_GOAL_EVALUATING_MARKER } from '@/shared/lib/omp/mode/types';
|
|
22
23
|
import { materializeTerminalMessages } from '@/shared/lib/chat/omp/terminal-messages';
|
|
23
24
|
import { invalidateComposerCache } from '@/shared/lib/chat/composer/client';
|
|
@@ -45,6 +46,9 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
|
|
|
45
46
|
switch (data.type) {
|
|
46
47
|
case 'agent_start':
|
|
47
48
|
deps.setState((prev) => ({ ...prev, isGenerating: true, error: null }));
|
|
49
|
+
// A cold chat has no live agent when the composer first reads `/modes`;
|
|
50
|
+
// this is the first frame after its spawn, so re-read the mode ladder.
|
|
51
|
+
emitSessionModesChanged(deps.sessionId);
|
|
48
52
|
deps.toolResultsRef.current?.clear();
|
|
49
53
|
deps.lastToolMessageRef.current = null;
|
|
50
54
|
// A fresh run restarts level tracking; the first turn relies on the
|
|
@@ -276,6 +280,13 @@ export function foldAgentEvent(data: OmpAgentEvent, deps: OmpAgentFoldDeps): voi
|
|
|
276
280
|
callbacks?.onModelChanged?.();
|
|
277
281
|
break;
|
|
278
282
|
|
|
283
|
+
// An ACP agent changed a config selector itself. `mode` is one of them and
|
|
284
|
+
// the composer's mode dropdown reads the live session, so re-read it.
|
|
285
|
+
case 'mode_changed':
|
|
286
|
+
case 'config_changed':
|
|
287
|
+
emitSessionModesChanged(deps.sessionId);
|
|
288
|
+
break;
|
|
289
|
+
|
|
279
290
|
// The live `thinking_level_changed` frame carries the new session level
|
|
280
291
|
// (e.g. { thinkingLevel: "high", configured, resolved }); null → "off".
|
|
281
292
|
// Record it so subsequent assistant turns are stamped with the level that
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*
|
|
5
|
+
* A cold chat has no live agent when the composer reads `/modes`; the first
|
|
6
|
+
* frame after its spawn is `agent_start`, so that frame must ask the composer
|
|
7
|
+
* to re-read the mode ladder.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test } from 'bun:test';
|
|
11
|
+
import { foldAgentEvent, type OmpAgentFoldDeps } from '@/shared/lib/chat/omp/agent-events';
|
|
12
|
+
import { subscribeClientSignal } from '@/client/lib/signals';
|
|
13
|
+
|
|
14
|
+
function foldDeps(): OmpAgentFoldDeps {
|
|
15
|
+
const noop = () => {};
|
|
16
|
+
const ref = <T,>(value: T) => ({ current: value });
|
|
17
|
+
return {
|
|
18
|
+
setState: noop,
|
|
19
|
+
sessionId: 'acp-cold-chat',
|
|
20
|
+
callbacksRef: { current: {} },
|
|
21
|
+
toolResultsRef: ref(new Map()),
|
|
22
|
+
lastToolMessageRef: ref(null),
|
|
23
|
+
activityRef: ref(''),
|
|
24
|
+
providerRetryVerbRef: ref(null),
|
|
25
|
+
currentThinkingLevelRef: ref(undefined),
|
|
26
|
+
fileMutatingCallsRef: ref(new Set()),
|
|
27
|
+
} as unknown as OmpAgentFoldDeps;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
describe('session-modes-changed signal', () => {
|
|
31
|
+
test('agent_start re-reads the live mode ladder', () => {
|
|
32
|
+
const seen: string[] = [];
|
|
33
|
+
const off = subscribeClientSignal('session-modes-changed', (payload) => seen.push(payload.sessionId));
|
|
34
|
+
try {
|
|
35
|
+
foldAgentEvent({ type: 'agent_start' } as never, foldDeps());
|
|
36
|
+
} finally {
|
|
37
|
+
off();
|
|
38
|
+
}
|
|
39
|
+
expect(seen).toEqual(['acp-cold-chat']);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Publishing "the agent changed its session mode/config".
|
|
8
|
+
*
|
|
9
|
+
* The fold sees `mode_changed` / `config_changed` frames; the composer's mode
|
|
10
|
+
* dropdown owns the `/modes` read and cannot see frames. This one-hop signal
|
|
11
|
+
* keeps the dropdown from polling: the frame is the event, and the consumer
|
|
12
|
+
* re-reads the authoritative value once.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { publishClientSignal } from '@/client/lib/signals';
|
|
16
|
+
|
|
17
|
+
export function emitSessionModesChanged(sessionId: string | undefined): void {
|
|
18
|
+
if (!sessionId) return;
|
|
19
|
+
publishClientSignal('session-modes-changed', { sessionId });
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The ACP session-mode selector, as the composer reads it.
|
|
8
|
+
*
|
|
9
|
+
* ACP exposes modes as a `mode`-category config option; this is the normalized
|
|
10
|
+
* shape the `/modes` route answers and the dropdown renders. It is shared so
|
|
11
|
+
* the server route, the client hook and the component agree on one spelling.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface SessionModeChoice {
|
|
15
|
+
value: string;
|
|
16
|
+
name: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SessionModeState {
|
|
20
|
+
/** The agent's current mode id. */
|
|
21
|
+
currentValue: string;
|
|
22
|
+
/** Every advertised value, in the agent's order. */
|
|
23
|
+
values: SessionModeChoice[];
|
|
24
|
+
}
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Reading a harness-update record that came from somewhere else, and the three
|
|
8
|
+
* questions every reader asks of one: is it waiting, is it running, and which
|
|
9
|
+
* step is it on.
|
|
8
10
|
*
|
|
9
11
|
* Two readers get one over the wire or off disk — the About card, which parses
|
|
10
|
-
* the status response, and the server, which parses the
|
|
12
|
+
* the status response, and the server, which parses the files a detached worker
|
|
11
13
|
* wrote — and neither may assume the shape: a half-written file or an older
|
|
12
14
|
* build's payload would otherwise reach `job.steps.find(...)` and throw inside a
|
|
13
15
|
* render. The guard IS the check, so a payload that fails it reads as "no run".
|
|
@@ -25,9 +27,54 @@ export function isHarnessUpdateJob(value: unknown): value is HarnessUpdateJob {
|
|
|
25
27
|
&& (job.finishedAt === null || typeof job.finishedAt === 'number');
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
/** The `job` field of a
|
|
30
|
+
/** The `job` field of a refusal payload, or null when it is not a record. */
|
|
29
31
|
export function updateJobFrom(payload: unknown): HarnessUpdateJob | null {
|
|
30
|
-
if (!payload || typeof payload !== 'object') return null;
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
if (!payload || typeof payload !== 'object' || !('job' in payload)) return null;
|
|
33
|
+
return isHarnessUpdateJob(payload.job) ? payload.job : null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The `jobs` field of a status payload, dropping anything that is not a record. */
|
|
37
|
+
export function updateJobsFrom(payload: unknown): HarnessUpdateJob[] {
|
|
38
|
+
if (!payload || typeof payload !== 'object' || !('jobs' in payload)) return [];
|
|
39
|
+
const found = payload.jobs;
|
|
40
|
+
return Array.isArray(found) ? found.filter(isHarnessUpdateJob) : [];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Is this run WAITING for another install to finish?
|
|
45
|
+
*
|
|
46
|
+
* The queue keeps the record on disk before the worker exists, so the ordinary
|
|
47
|
+
* "no pid and not finished" test would call it a run that died without writing a
|
|
48
|
+
* result. `queuedAt` is what separates the two.
|
|
49
|
+
*/
|
|
50
|
+
export function jobQueued(job: HarnessUpdateJob | null): boolean {
|
|
51
|
+
return job !== null && job.finishedAt === null && job.pid === null && (job.queuedAt ?? null) !== null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Is a worker installing right now? A queued run is not one. */
|
|
55
|
+
export function jobRunning(job: HarnessUpdateJob | null): boolean {
|
|
56
|
+
return job !== null && job.finishedAt === null && !jobQueued(job);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Has this record got a result yet (running, queued, or settled)? */
|
|
60
|
+
export function jobUnfinished(job: HarnessUpdateJob | null): boolean {
|
|
61
|
+
return job !== null && job.finishedAt === null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Is anything still moving for this record?
|
|
66
|
+
*
|
|
67
|
+
* A settled run is not always finished with the reader: the server probes the
|
|
68
|
+
* freshly installed agent afterwards, and until that answer lands the row quotes
|
|
69
|
+
* the version the update just replaced. Both the queue's ticker and the dialog's
|
|
70
|
+
* poll wait for `probe` to leave `pending`.
|
|
71
|
+
*/
|
|
72
|
+
export function jobMoving(job: HarnessUpdateJob | null): boolean {
|
|
73
|
+
return jobUnfinished(job) || (job !== null && job.probe === 'pending');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The step the worker is on (`adapter`, `Claude Code`, …), when it says. */
|
|
77
|
+
export function runningStepOf(job: HarnessUpdateJob | null): string | null {
|
|
78
|
+
const steps = job && Array.isArray(job.steps) ? job.steps : [];
|
|
79
|
+
return steps.find((step) => step.state === 'running')?.part ?? null;
|
|
33
80
|
}
|
|
@@ -33,40 +33,40 @@ import type { PaperBucket } from '@/shared/lib/icons/icon-tone';
|
|
|
33
33
|
export const ICON_HUES: Readonly<Record<string, number>> = {
|
|
34
34
|
Activity: 240, AlignJustify: 100, AlignLeft: 150, Archive: 50, ArchiveRestore: 90, ArrowDown: 100,
|
|
35
35
|
ArrowDownToLine: 330, ArrowLeft: 350, ArrowRight: 80, ArrowUp: 150, ArrowUpDown: 310, ArrowUpRight: 70,
|
|
36
|
-
BarChart3: 150, Blocks: 110, Bot: 220, Box: 260, Boxes: 220,
|
|
37
|
-
BrainCircuit: 300, Briefcase: 310, Camera: 60, CaseSensitive: 110, ChevronDown: 120,
|
|
38
|
-
ChevronRight: 300, ChevronUp: 250, ChevronsUpDown: 80, Circle: 50,
|
|
39
|
-
ClipboardCopy: 280, ClipboardList: 290, ClipboardPaste: 200, Cloud: 340,
|
|
40
|
-
Code2: 260, Coins: 210, Columns: 280, Columns2: 20,
|
|
41
|
-
Copy: 320, CopyPlus: 40, CornerDownLeft: 10, Cpu: 250,
|
|
42
|
-
|
|
43
|
-
ExternalLink: 60, Eye: 20, EyeOff: 350, File: 310,
|
|
44
|
-
FileEdit: 270, FileImage: 40, FilePlus: 350, FilePlus2: 350,
|
|
45
|
-
Files: 320, Flag: 350, FlaskConical: 170, Folder: 290,
|
|
46
|
-
FolderInput: 310, FolderOpen: 330, FolderPlus: 250, FolderSearch: 10,
|
|
47
|
-
GitBranch: 30, GitCommitVertical: 240, GitCompare: 340, GitFork: 30,
|
|
48
|
-
Globe: 340, GraduationCap: 190, GripVertical: 350, Hammer: 310,
|
|
49
|
-
Hash: 330, Heading: 250, Heart: 270, History: 110,
|
|
50
|
-
|
|
51
|
-
Leaf: 50, Library: 160, Lightbulb: 0, List: 170,
|
|
52
|
-
ListOrdered: 220, ListTodo: 210, ListTree: 330, Loader2: 40,
|
|
53
|
-
LockOpen: 180, LogIn: 140, LogOut: 190, Maximize: 310,
|
|
54
|
-
MessageSquare: 150, MessageSquareOff: 40, MessageSquarePlus: 350, MessagesSquare: 220,
|
|
55
|
-
Minimize: 290, Minimize2: 130, Minus: 110, Monitor: 250,
|
|
56
|
-
MousePointerClick: 70, MoveVertical: 300, Music: 280, Package: 270,
|
|
57
|
-
PanelLeft: 280, PanelLeftClose: 160, PanelRight: 330, PanelRightClose: 350,
|
|
58
|
-
|
|
59
|
-
Plug: 50, Plus: 210, Power: 340, Puzzle: 50,
|
|
60
|
-
Ratio: 160, RefreshCw: 180, Regex: 280, Replace: 190,
|
|
61
|
-
RotateCcw: 330, RotateCw: 0, Rows: 160, Rows3: 250,
|
|
62
|
-
Scissors: 260, Search: 250, Send: 110, Server: 300,
|
|
63
|
-
Settings2: 20, Shield: 160, Shrink: 160, Sliders: 290,
|
|
64
|
-
Space: 290, Sparkles: 180, Square: 60, SquareFunction: 220,
|
|
65
|
-
StickyNote: 100, Store: 340, Sun: 90, Tablet: 290,
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Zap: 120, ZoomIn: 250, ZoomOut: 340,
|
|
36
|
+
BarChart3: 150, BellRing: 260, Blocks: 110, Bot: 220, Box: 260, Boxes: 220,
|
|
37
|
+
Brain: 350, BrainCircuit: 300, Briefcase: 310, Camera: 60, CaseSensitive: 110, ChevronDown: 120,
|
|
38
|
+
ChevronLeft: 250, ChevronRight: 300, ChevronUp: 250, ChevronsUpDown: 80, Circle: 50, CircleCheck: 350,
|
|
39
|
+
CircleDashed: 120, CircleDot: 240, ClipboardCopy: 280, ClipboardList: 290, ClipboardPaste: 200, Cloud: 340,
|
|
40
|
+
CloudDownload: 300, Code: 200, Code2: 260, Coins: 210, Columns: 280, Columns2: 20,
|
|
41
|
+
Command: 100, Component: 200, Copy: 320, CopyPlus: 40, CornerDownLeft: 10, Cpu: 250,
|
|
42
|
+
Database: 280, Dice5: 50, Diff: 300, DollarSign: 220, Download: 210, DownloadCloud: 180,
|
|
43
|
+
Edit2: 210, Ellipsis: 100, ExternalLink: 60, Eye: 20, EyeOff: 350, File: 310,
|
|
44
|
+
FileCode: 260, FileCog: 340, FileEdit: 270, FileImage: 40, FilePlus: 350, FilePlus2: 350,
|
|
45
|
+
FileSearch: 310, FileText: 80, Files: 320, Flag: 350, FlaskConical: 170, Folder: 290,
|
|
46
|
+
FolderGit: 190, FolderGit2: 190, FolderInput: 310, FolderOpen: 330, FolderPlus: 250, FolderSearch: 10,
|
|
47
|
+
FolderTree: 10, Gamepad2: 300, GitBranch: 30, GitCommitVertical: 240, GitCompare: 340, GitFork: 30,
|
|
48
|
+
GitMerge: 90, GitPullRequest: 10, Globe: 340, GraduationCap: 190, GripVertical: 350, Hammer: 310,
|
|
49
|
+
Hand: 200, HardDrive: 0, Hash: 330, Heading: 250, Heart: 270, History: 110,
|
|
50
|
+
Home: 20, Image: 140, Key: 240, KeyRound: 240, Keyboard: 120, Laptop: 170,
|
|
51
|
+
Layers: 30, LayoutTemplate: 170, Leaf: 50, Library: 160, Lightbulb: 0, List: 170,
|
|
52
|
+
ListChecks: 320, ListFilter: 230, ListOrdered: 220, ListTodo: 210, ListTree: 330, Loader2: 40,
|
|
53
|
+
Lock: 220, LockKeyhole: 270, LockOpen: 180, LogIn: 140, LogOut: 190, Maximize: 310,
|
|
54
|
+
Maximize2: 270, Menu: 100, MessageSquare: 150, MessageSquareOff: 40, MessageSquarePlus: 350, MessagesSquare: 220,
|
|
55
|
+
Mic: 160, MicOff: 170, Minimize: 290, Minimize2: 130, Minus: 110, Monitor: 250,
|
|
56
|
+
Moon: 80, MoreHorizontal: 160, MousePointerClick: 70, MoveVertical: 300, Music: 280, Package: 270,
|
|
57
|
+
Paintbrush: 250, Palette: 320, PanelLeft: 280, PanelLeftClose: 160, PanelRight: 330, PanelRightClose: 350,
|
|
58
|
+
Paperclip: 310, Pause: 10, Pencil: 0, PencilLine: 260, Pin: 0, PinOff: 50,
|
|
59
|
+
Pipette: 120, Play: 310, Plug: 50, Plus: 210, Power: 340, Puzzle: 50,
|
|
60
|
+
Quote: 110, Radio: 320, Ratio: 160, RefreshCw: 180, Regex: 280, Replace: 190,
|
|
61
|
+
ReplaceAll: 140, Rocket: 210, RotateCcw: 330, RotateCw: 0, Rows: 160, Rows3: 250,
|
|
62
|
+
Save: 40, SaveAll: 190, Scissors: 260, Search: 250, Send: 110, Server: 300,
|
|
63
|
+
ServerCog: 50, Settings: 240, Settings2: 20, Shield: 160, Shrink: 160, Sliders: 290,
|
|
64
|
+
SlidersHorizontal: 50, Smartphone: 20, Space: 290, Sparkles: 180, Square: 60, SquareFunction: 220,
|
|
65
|
+
SquarePen: 10, Star: 170, StickyNote: 100, Store: 340, Sun: 90, Tablet: 290,
|
|
66
|
+
Tag: 310, Target: 200, Terminal: 210, TextSelect: 220, Ticket: 170, TriangleAlert: 210,
|
|
67
|
+
Type: 170, Undo2: 310, Upload: 0, UploadCloud: 50, User: 140, Variable: 330,
|
|
68
|
+
Volume2: 270, VolumeX: 50, Wand2: 270, WandSparkles: 40, Waypoints: 30, WholeWord: 240,
|
|
69
|
+
WrapText: 340, Wrench: 0, X: 230, Zap: 120, ZoomIn: 250, ZoomOut: 340,
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
/**
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Only a NEW stream→finish transition earns a notice; failures ride the same rule. */
|
|
7
|
+
|
|
8
|
+
import { describe, expect, test } from 'bun:test';
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
runOutcomeNotices,
|
|
12
|
+
streamOutcomes,
|
|
13
|
+
type StreamOutcome,
|
|
14
|
+
} from '@/shared/lib/notifications/outcomes';
|
|
15
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
16
|
+
|
|
17
|
+
function folders(
|
|
18
|
+
sessions: Array<{
|
|
19
|
+
id: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
streamStatus?: StreamOutcome;
|
|
22
|
+
runFailure?: string;
|
|
23
|
+
}>,
|
|
24
|
+
): WorkspaceFolderData[] {
|
|
25
|
+
return [
|
|
26
|
+
{
|
|
27
|
+
id: 1,
|
|
28
|
+
name: 'workspace',
|
|
29
|
+
isExpanded: true,
|
|
30
|
+
hasMore: false,
|
|
31
|
+
totalSessions: sessions.length,
|
|
32
|
+
sessions: sessions.map((session) => ({
|
|
33
|
+
id: session.id,
|
|
34
|
+
folder_id: 1,
|
|
35
|
+
title: session.title ?? session.id,
|
|
36
|
+
streamStatus: session.streamStatus,
|
|
37
|
+
runFailure: session.runFailure,
|
|
38
|
+
})),
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe('run outcome notices', () => {
|
|
44
|
+
test('a run that finished after streaming is one notice', () => {
|
|
45
|
+
const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
|
|
46
|
+
expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'finish' }]))).toEqual([
|
|
47
|
+
{ kind: 'finish', sessionId: 'a', title: 'a', detail: 'The run finished.' },
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('a badge already present at page load is not news', () => {
|
|
52
|
+
const previous = streamOutcomes(folders([{ id: 'a', streamStatus: 'finish' }]));
|
|
53
|
+
expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'finish' }]))).toEqual([]);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('an aborted run is silent', () => {
|
|
57
|
+
const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
|
|
58
|
+
expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'abort' }]))).toEqual([]);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('a failure is an error notice carrying the reason', () => {
|
|
62
|
+
const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
|
|
63
|
+
expect(
|
|
64
|
+
runOutcomeNotices(previous, folders([
|
|
65
|
+
{ id: 'a', title: 'Fix the build', streamStatus: 'finish', runFailure: ' 401 invalid api key ' },
|
|
66
|
+
])),
|
|
67
|
+
).toEqual([
|
|
68
|
+
{ kind: 'error', sessionId: 'a', title: 'Fix the build', detail: '401 invalid api key' },
|
|
69
|
+
]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('an untitled session still names Kabmo', () => {
|
|
73
|
+
const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
|
|
74
|
+
const [notice] = runOutcomeNotices(previous, folders([{ id: 'a', title: ' ', streamStatus: 'finish' }]));
|
|
75
|
+
expect(notice?.title).toBe('Kabmo');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('only sessions that moved are reported', () => {
|
|
79
|
+
const previous = new Map<string, StreamOutcome>([
|
|
80
|
+
['a', 'stream'],
|
|
81
|
+
['b', 'finish'],
|
|
82
|
+
['c', undefined],
|
|
83
|
+
]);
|
|
84
|
+
const notices = runOutcomeNotices(previous, folders([
|
|
85
|
+
{ id: 'a', streamStatus: 'finish' },
|
|
86
|
+
{ id: 'b', streamStatus: 'finish' },
|
|
87
|
+
{ id: 'c', streamStatus: 'finish' },
|
|
88
|
+
]));
|
|
89
|
+
expect(notices.map((notice) => notice.sessionId)).toEqual(['a']);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('a stream that keeps streaming earns nothing', () => {
|
|
93
|
+
const previous = new Map<string, StreamOutcome>([['a', 'stream']]);
|
|
94
|
+
expect(runOutcomeNotices(previous, folders([{ id: 'a', streamStatus: 'stream' }]))).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The run outcomes a sidebar-status snapshot is worth a notification for.
|
|
8
|
+
*
|
|
9
|
+
* Only `stream → finish` is news. `abort` is not: the operator either stopped
|
|
10
|
+
* the run themselves or a heal pass settled a process that had already gone
|
|
11
|
+
* away, and neither is an event to raise a banner for. A `finish` badge that is
|
|
12
|
+
* ALREADY there when the page loads is not news either — it is the state of the
|
|
13
|
+
* world the page woke up to, which is why the caller compares against the
|
|
14
|
+
* previous snapshot rather than notifying on presence.
|
|
15
|
+
*
|
|
16
|
+
* A failed run is the same transition with `runFailure` set, so the two
|
|
17
|
+
* notifications share one rule and cannot disagree about when they fire.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { WorkspaceFolderData } from '@/shared/types';
|
|
21
|
+
|
|
22
|
+
export type StreamOutcome = 'stream' | 'finish' | 'abort' | undefined;
|
|
23
|
+
|
|
24
|
+
export interface RunOutcomeNotice {
|
|
25
|
+
kind: 'finish' | 'error';
|
|
26
|
+
/** The session the message is about; also the notification's tag. */
|
|
27
|
+
sessionId: string;
|
|
28
|
+
title: string;
|
|
29
|
+
detail: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The status map one folder snapshot carries, for the next comparison. */
|
|
33
|
+
export function streamOutcomes(folders: WorkspaceFolderData[]): Map<string, StreamOutcome> {
|
|
34
|
+
const outcomes = new Map<string, StreamOutcome>();
|
|
35
|
+
for (const folder of folders) {
|
|
36
|
+
for (const session of folder.sessions ?? []) {
|
|
37
|
+
outcomes.set(String(session.id), session.streamStatus);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return outcomes;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The notices `folders` earns against `previous`. */
|
|
44
|
+
export function runOutcomeNotices(
|
|
45
|
+
previous: ReadonlyMap<string, StreamOutcome>,
|
|
46
|
+
folders: WorkspaceFolderData[],
|
|
47
|
+
): RunOutcomeNotice[] {
|
|
48
|
+
const notices: RunOutcomeNotice[] = [];
|
|
49
|
+
for (const folder of folders) {
|
|
50
|
+
for (const session of folder.sessions ?? []) {
|
|
51
|
+
const sessionId = String(session.id);
|
|
52
|
+
if (session.streamStatus !== 'finish') continue;
|
|
53
|
+
if (previous.get(sessionId) !== 'stream') continue;
|
|
54
|
+
const failure = typeof session.runFailure === 'string' ? session.runFailure.trim() : '';
|
|
55
|
+
notices.push({
|
|
56
|
+
kind: failure ? 'error' : 'finish',
|
|
57
|
+
sessionId,
|
|
58
|
+
title: session.title?.trim() || 'Kabmo',
|
|
59
|
+
detail: failure || 'The run finished.',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return notices;
|
|
64
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** The notification preferences are opt-in, and only the boolean `true` opts in. */
|
|
7
|
+
|
|
8
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
9
|
+
|
|
10
|
+
import { primeKabmoSettings } from '@/shared/lib/settings/client';
|
|
11
|
+
import { DEFAULT_SETTINGS } from '@/shared/lib/settings/defaults';
|
|
12
|
+
import {
|
|
13
|
+
isNotificationEnabled,
|
|
14
|
+
NOTIFICATION_SETTING_KEYS,
|
|
15
|
+
type NotificationEvent,
|
|
16
|
+
} from '@/shared/lib/notifications/settings';
|
|
17
|
+
|
|
18
|
+
const EVENTS: NotificationEvent[] = ['finish', 'ask', 'error'];
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
primeKabmoSettings({});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('notification settings', () => {
|
|
25
|
+
test('every event is off on a fresh install', () => {
|
|
26
|
+
primeKabmoSettings({});
|
|
27
|
+
for (const event of EVENTS) expect(isNotificationEnabled(event)).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('the shipped defaults are all false', () => {
|
|
31
|
+
// The defaults object is what the settings modal seeds from, so a `true`
|
|
32
|
+
// here would silently turn notifications on for a new install.
|
|
33
|
+
for (const event of EVENTS) {
|
|
34
|
+
expect(DEFAULT_SETTINGS[NOTIFICATION_SETTING_KEYS[event] as keyof typeof DEFAULT_SETTINGS]).toBe(false);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('each event reads its own key', () => {
|
|
39
|
+
primeKabmoSettings({ notifyOnFinish: true, notifyOnAsk: false, notifyOnError: true });
|
|
40
|
+
expect(isNotificationEnabled('finish')).toBe(true);
|
|
41
|
+
expect(isNotificationEnabled('ask')).toBe(false);
|
|
42
|
+
expect(isNotificationEnabled('error')).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('a truthy non-boolean does not opt in', () => {
|
|
46
|
+
primeKabmoSettings({ notifyOnFinish: 'yes' });
|
|
47
|
+
expect(isNotificationEnabled('finish')).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which system notification each event is allowed to send.
|
|
8
|
+
*
|
|
9
|
+
* All three default to FALSE, and only the literal `true` enables one. That
|
|
10
|
+
* strictness is the feature: an install that predates these keys has no value
|
|
11
|
+
* at all, and a truthy string from a hand-edited settings blob must not opt the
|
|
12
|
+
* user into OS notifications they never chose. It also keeps a fresh install
|
|
13
|
+
* from being prompted for permission by a shell on first launch.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { readKabmoSetting } from '@/shared/lib/settings/client';
|
|
17
|
+
|
|
18
|
+
/** The events a notification setting exists for. */
|
|
19
|
+
export type NotificationEvent = 'finish' | 'ask' | 'error';
|
|
20
|
+
|
|
21
|
+
/** The stored setting key for each event. */
|
|
22
|
+
export const NOTIFICATION_SETTING_KEYS: Readonly<Record<NotificationEvent, string>> = {
|
|
23
|
+
finish: 'notifyOnFinish',
|
|
24
|
+
ask: 'notifyOnAsk',
|
|
25
|
+
error: 'notifyOnError',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Whether the user asked for a system notification for `event`. */
|
|
29
|
+
export function isNotificationEnabled(
|
|
30
|
+
event: NotificationEvent,
|
|
31
|
+
appSettings?: Record<string, any>,
|
|
32
|
+
): boolean {
|
|
33
|
+
return readKabmoSetting<boolean>(NOTIFICATION_SETTING_KEYS[event], appSettings) === true;
|
|
34
|
+
}
|
|
@@ -24,10 +24,11 @@ function pad2(value: number): string {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/** `New Session - yyyy-mm-ddThh:mm:ss` (local time); plain "New Session" when
|
|
27
|
-
* the date is invalid.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
* the date is invalid. A child passes its own label (`New Child`), so a
|
|
28
|
+
* pending row says what it is before it has a transcript. */
|
|
29
|
+
export function formatNewSessionTitle(date: Date = new Date(), label = 'New Session'): string {
|
|
30
|
+
if (Number.isNaN(date.getTime())) return label;
|
|
31
|
+
return `${label} - ${date.getFullYear()}-${pad2(date.getMonth() + 1)}-${pad2(date.getDate())}T${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/** True for client-side pending session ids (`new-<epochMs>`, pre-spawn). */
|
|
@@ -79,13 +79,14 @@ describe('contentProfile', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
describe('migrateSessionStreamStateColumns', () => {
|
|
82
|
-
test('issues the additive owner, provider, and
|
|
82
|
+
test('issues the additive owner, provider, model and failure columns', async () => {
|
|
83
83
|
const statements: string[] = [];
|
|
84
84
|
await migrateSessionStreamStateColumns({ exec: async (sql: string) => { statements.push(sql); } } as never);
|
|
85
85
|
expect(statements).toEqual([
|
|
86
86
|
'ALTER TABLE session_stream_state ADD COLUMN owner_pid INTEGER;',
|
|
87
87
|
'ALTER TABLE session_stream_state ADD COLUMN model_provider TEXT;',
|
|
88
88
|
'ALTER TABLE session_stream_state ADD COLUMN model_id TEXT;',
|
|
89
|
+
'ALTER TABLE session_stream_state ADD COLUMN failure TEXT;',
|
|
89
90
|
]);
|
|
90
91
|
});
|
|
91
92
|
|
|
@@ -96,7 +97,7 @@ describe('migrateSessionStreamStateColumns', () => {
|
|
|
96
97
|
await migrateSessionStreamStateColumns({
|
|
97
98
|
exec: async () => { attempts += 1; throw new Error('duplicate column name: owner_pid'); },
|
|
98
99
|
} as never);
|
|
99
|
-
expect(attempts).toBe(
|
|
100
|
+
expect(attempts).toBe(4);
|
|
100
101
|
});
|
|
101
102
|
});
|
|
102
103
|
|
|
@@ -32,4 +32,8 @@ export async function migrateSessionStreamStateColumns(db: DbClient): Promise<vo
|
|
|
32
32
|
// stream status — instead of re-deriving it from the session JSONL.
|
|
33
33
|
await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN model_provider TEXT;');
|
|
34
34
|
await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN model_id TEXT;');
|
|
35
|
+
// Why a terminal `finish` row ended: the notification's own reason, and the
|
|
36
|
+
// only durable place a background tab can learn that a run failed. NULL is a
|
|
37
|
+
// normal stop, so every existing row keeps its meaning.
|
|
38
|
+
await addColumn(db, 'ALTER TABLE session_stream_state ADD COLUMN failure TEXT;');
|
|
35
39
|
}
|