@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
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What a pending child chat sends to `/api/sessions/spawn`.
|
|
8
|
+
*
|
|
9
|
+
* The fields are OMITTED when the composer has no value: the route inherits the
|
|
10
|
+
* parent's harness and model when they are absent, and sending `null`/`auto`
|
|
11
|
+
* would override that inheritance with a value the agent never asked for.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { describe, expect, test } from 'bun:test';
|
|
15
|
+
import { childSpawnBody } from '@/client/hooks/chat/timeline/child-spawn';
|
|
16
|
+
|
|
17
|
+
describe('childSpawnBody', () => {
|
|
18
|
+
test('carries the parent, prompt and every pick the composer made', () => {
|
|
19
|
+
expect(
|
|
20
|
+
childSpawnBody('parent', 'review this', {
|
|
21
|
+
harness: 'claude',
|
|
22
|
+
model: { provider: 'acme', modelId: 'big' },
|
|
23
|
+
thinkingLevel: 'high',
|
|
24
|
+
accessMode: 'yolo',
|
|
25
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
26
|
+
}),
|
|
27
|
+
).toEqual({
|
|
28
|
+
parentSessionId: 'parent',
|
|
29
|
+
prompt: 'review this',
|
|
30
|
+
harness: 'claude',
|
|
31
|
+
model: { provider: 'acme', modelId: 'big' },
|
|
32
|
+
thinkingLevel: 'high',
|
|
33
|
+
accessMode: 'yolo',
|
|
34
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('leaves unknown picks out so the server inherits them', () => {
|
|
39
|
+
const body = childSpawnBody('parent', 'go', {
|
|
40
|
+
harness: null,
|
|
41
|
+
model: null,
|
|
42
|
+
thinkingLevel: 'auto',
|
|
43
|
+
accessMode: null,
|
|
44
|
+
images: [],
|
|
45
|
+
});
|
|
46
|
+
expect(body).toEqual({ parentSessionId: 'parent', prompt: 'go' });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a half-named model is not sent', () => {
|
|
50
|
+
const body = childSpawnBody('parent', 'go', {
|
|
51
|
+
model: { provider: 'acme', modelId: '' },
|
|
52
|
+
});
|
|
53
|
+
expect(body).not.toHaveProperty('model');
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The body of `POST /api/sessions/spawn` for a pending child chat.
|
|
8
|
+
*
|
|
9
|
+
* Split out so the payload rule can be asserted without mounting the composer:
|
|
10
|
+
* every field the composer does not actually have a value for must be OMITTED,
|
|
11
|
+
* never sent as `null` — the route treats an absent harness as "inherit the
|
|
12
|
+
* parent's", and an absent model as "use the parent/project default".
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { AgentImage } from '@/shared/types';
|
|
16
|
+
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
17
|
+
|
|
18
|
+
export interface ChildSpawnPicks {
|
|
19
|
+
harness?: string | null;
|
|
20
|
+
model?: { provider: string; modelId: string } | null;
|
|
21
|
+
thinkingLevel?: string | null;
|
|
22
|
+
accessMode?: ApprovalMode | null;
|
|
23
|
+
images?: AgentImage[] | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function childSpawnBody(
|
|
27
|
+
parentSessionId: string,
|
|
28
|
+
prompt: string,
|
|
29
|
+
picks: ChildSpawnPicks = {},
|
|
30
|
+
): Record<string, unknown> {
|
|
31
|
+
const model = picks.model;
|
|
32
|
+
return {
|
|
33
|
+
parentSessionId,
|
|
34
|
+
prompt,
|
|
35
|
+
...(picks.harness ? { harness: picks.harness } : {}),
|
|
36
|
+
...(model?.provider && model.modelId ? { model } : {}),
|
|
37
|
+
// `auto` means "leave the agent's own level alone"; sending it would move a
|
|
38
|
+
// configured level to a literal the ACP handshake may not accept.
|
|
39
|
+
...(picks.thinkingLevel && picks.thinkingLevel !== 'auto'
|
|
40
|
+
? { thinkingLevel: picks.thinkingLevel }
|
|
41
|
+
: {}),
|
|
42
|
+
...(picks.accessMode ? { accessMode: picks.accessMode } : {}),
|
|
43
|
+
...(picks.images?.length ? { images: picks.images } : {}),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The fork preview's TRANSPORT half: which source it reads, and what happens
|
|
8
|
+
* when "Fork from" moves.
|
|
9
|
+
*
|
|
10
|
+
* The slice itself is asserted in `shared/lib/chat/timeline/fork-preview.test.ts`;
|
|
11
|
+
* this pins the two behaviours the picker depends on — a source switch refetches
|
|
12
|
+
* (the old rows must not stand in for the new source) and a late answer for a
|
|
13
|
+
* source that is no longer selected is dropped, not painted.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
17
|
+
import { Window } from 'happy-dom';
|
|
18
|
+
import { h, render } from 'preact';
|
|
19
|
+
import { act } from 'preact/test-utils';
|
|
20
|
+
|
|
21
|
+
import { installDomGlobals, restoreDomGlobals } from '@/test-support/pristine-globals';
|
|
22
|
+
import { useForkPreview, type ForkPreview } from '@/client/hooks/chat/timeline/fork-preview';
|
|
23
|
+
import type { ChatMessageData } from '@/shared/types';
|
|
24
|
+
|
|
25
|
+
let container: HTMLElement;
|
|
26
|
+
let requested: string[];
|
|
27
|
+
/** The runner's own fetch: a stub left installed poisons every later suite. */
|
|
28
|
+
const originalFetch = Bun.fetch;
|
|
29
|
+
interface DeferredResponse {
|
|
30
|
+
promise: Promise<Response>;
|
|
31
|
+
resolve: (value: Response) => void;
|
|
32
|
+
}
|
|
33
|
+
const gates = new Map<string, DeferredResponse>();
|
|
34
|
+
|
|
35
|
+
beforeAll(() => installDomGlobals(new Window({ url: 'http://localhost' })));
|
|
36
|
+
afterAll(() => restoreDomGlobals());
|
|
37
|
+
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
requested = [];
|
|
40
|
+
gates.clear();
|
|
41
|
+
globalThis.fetch = ((input: RequestInfo | URL) => {
|
|
42
|
+
const url = String(input);
|
|
43
|
+
requested.push(url);
|
|
44
|
+
const gate = Promise.withResolvers<Response>();
|
|
45
|
+
gates.set(url, gate);
|
|
46
|
+
return gate.promise;
|
|
47
|
+
}) as typeof fetch;
|
|
48
|
+
container = document.createElement('div');
|
|
49
|
+
document.body.appendChild(container);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
globalThis.fetch = originalFetch;
|
|
54
|
+
render(null, container);
|
|
55
|
+
container.remove();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const sessionResponse = (id: string, messages: ChatMessageData[]) =>
|
|
59
|
+
Response.json({ session: { id, messages } });
|
|
60
|
+
|
|
61
|
+
/** Mounts the hook and records its latest value. */
|
|
62
|
+
function mount(source: string | null, anchor: string | null): { current: ForkPreview | null } {
|
|
63
|
+
const state: { current: ForkPreview | null } = { current: null };
|
|
64
|
+
function Probe({ sourceId, anchorId }: { sourceId: string | null; anchorId: string | null }) {
|
|
65
|
+
state.current = useForkPreview(sourceId, anchorId);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
act(() => render(h(Probe, { sourceId: source, anchorId: anchor }), container));
|
|
69
|
+
return state;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async function settle(): Promise<void> {
|
|
73
|
+
// The fetch chain is microtasks only: drain them deterministically rather
|
|
74
|
+
// than guessing a wall-clock delay.
|
|
75
|
+
await act(async () => {
|
|
76
|
+
for (let tick = 0; tick < 8; tick += 1) await Promise.resolve();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe('useForkPreview', () => {
|
|
81
|
+
test('reads the whole source transcript and slices it at the anchor', async () => {
|
|
82
|
+
const state = mount('sess-a', 'a1');
|
|
83
|
+
expect(requested).toEqual(['/api/chat/sess-a?limit=all']);
|
|
84
|
+
|
|
85
|
+
const gate = gates.get('/api/chat/sess-a?limit=all')!;
|
|
86
|
+
gate.resolve(sessionResponse('sess-a', [
|
|
87
|
+
{ id: 'u1', role: 'user', content: 'one' },
|
|
88
|
+
{ id: 'a1', role: 'ai', content: 'two' },
|
|
89
|
+
{ id: 'u2', role: 'user', content: 'three' },
|
|
90
|
+
]));
|
|
91
|
+
await settle();
|
|
92
|
+
|
|
93
|
+
expect(state.current?.loading).toBe(false);
|
|
94
|
+
expect(state.current?.messages.map((m) => m.id)).toEqual(['u1', 'a1']);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('a new "Fork from" refetches and never shows the previous source rows', async () => {
|
|
98
|
+
const state = mount('sess-a', null);
|
|
99
|
+
gates.get('/api/chat/sess-a?limit=all')!.resolve(sessionResponse('sess-a', [
|
|
100
|
+
{ id: 'a1', role: 'user', content: 'from A' },
|
|
101
|
+
]));
|
|
102
|
+
await settle();
|
|
103
|
+
expect(state.current?.messages.map((m) => m.id)).toEqual(['a1']);
|
|
104
|
+
|
|
105
|
+
act(() => {
|
|
106
|
+
render(h(function Next() {
|
|
107
|
+
state.current = useForkPreview('sess-b', null);
|
|
108
|
+
return null;
|
|
109
|
+
}, {}), container);
|
|
110
|
+
});
|
|
111
|
+
// The picker moved: A's transcript is gone from the surface immediately.
|
|
112
|
+
expect(state.current?.messages).toEqual([]);
|
|
113
|
+
expect(requested.at(-1)).toBe('/api/chat/sess-b?limit=all');
|
|
114
|
+
|
|
115
|
+
gates.get('/api/chat/sess-b?limit=all')!.resolve(sessionResponse('sess-b', [
|
|
116
|
+
{ id: 'b1', role: 'user', content: 'from B' },
|
|
117
|
+
]));
|
|
118
|
+
await settle();
|
|
119
|
+
expect(state.current?.messages.map((m) => m.id)).toEqual(['b1']);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('a late answer for an abandoned source is dropped', async () => {
|
|
123
|
+
const state = mount('sess-a', null);
|
|
124
|
+
act(() => {
|
|
125
|
+
render(h(function Next() {
|
|
126
|
+
state.current = useForkPreview('sess-b', null);
|
|
127
|
+
return null;
|
|
128
|
+
}, {}), container);
|
|
129
|
+
});
|
|
130
|
+
gates.get('/api/chat/sess-b?limit=all')!.resolve(sessionResponse('sess-b', [
|
|
131
|
+
{ id: 'b1', role: 'user', content: 'from B' },
|
|
132
|
+
]));
|
|
133
|
+
await settle();
|
|
134
|
+
gates.get('/api/chat/sess-a?limit=all')!.resolve(sessionResponse('sess-a', [
|
|
135
|
+
{ id: 'a1', role: 'user', content: 'from A' },
|
|
136
|
+
]));
|
|
137
|
+
await settle();
|
|
138
|
+
expect(state.current?.messages.map((m) => m.id)).toEqual(['b1']);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
test('a failed read is reported, not replaced with an empty transcript', async () => {
|
|
142
|
+
const state = mount('sess-a', null);
|
|
143
|
+
gates.get('/api/chat/sess-a?limit=all')!.resolve(Response.json({ error: 'not found' }, { status: 404 }));
|
|
144
|
+
await settle();
|
|
145
|
+
expect(state.current?.error).toBe('not found');
|
|
146
|
+
expect(state.current?.messages).toEqual([]);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The SOURCE transcript of the fork being composed.
|
|
8
|
+
*
|
|
9
|
+
* A fork chat is empty until the first send, so the operator had no sight of
|
|
10
|
+
* the history the first turn continues — and after switching "Fork from" the
|
|
11
|
+
* old preview stayed. This reads the source session and slices it the way the
|
|
12
|
+
* server will cut the branch (`forkPreviewMessages`), refetching when the
|
|
13
|
+
* source changes.
|
|
14
|
+
*
|
|
15
|
+
* `limit=all` on purpose: the default 120-row window would cut the preview at
|
|
16
|
+
* a different row than the branch file, and a fork of a long session usually
|
|
17
|
+
* anchors further back than that window covers.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { useEffect, useMemo, useState } from 'preact/hooks';
|
|
21
|
+
import type { ChatMessageData } from '@/shared/types';
|
|
22
|
+
import { forkPreviewMessages } from '@/shared/lib/chat/timeline/fork-preview';
|
|
23
|
+
|
|
24
|
+
export interface ForkPreview {
|
|
25
|
+
/** The rows the fork will carry, in source order; empty while loading. */
|
|
26
|
+
messages: ChatMessageData[];
|
|
27
|
+
loading: boolean;
|
|
28
|
+
/** Why the source transcript could not be read, or null. */
|
|
29
|
+
error: string | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface LoadedSource {
|
|
33
|
+
id: string;
|
|
34
|
+
messages: ChatMessageData[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const EMPTY: ChatMessageData[] = [];
|
|
38
|
+
|
|
39
|
+
export function useForkPreview(
|
|
40
|
+
sourceSessionId: string | null,
|
|
41
|
+
anchorEntryId: string | null,
|
|
42
|
+
): ForkPreview {
|
|
43
|
+
const [loaded, setLoaded] = useState<LoadedSource | null>(null);
|
|
44
|
+
const [loading, setLoading] = useState(false);
|
|
45
|
+
const [error, setError] = useState<{ id: string; message: string } | null>(null);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!sourceSessionId) {
|
|
49
|
+
setLoaded(null);
|
|
50
|
+
setLoading(false);
|
|
51
|
+
setError(null);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const controller = new AbortController();
|
|
55
|
+
let live = true;
|
|
56
|
+
setLoading(true);
|
|
57
|
+
setError(null);
|
|
58
|
+
fetch(`/api/chat/${encodeURIComponent(sourceSessionId)}?limit=all`, {
|
|
59
|
+
signal: controller.signal,
|
|
60
|
+
})
|
|
61
|
+
.then(async (response) => {
|
|
62
|
+
const body = (await response.json().catch(() => null)) as
|
|
63
|
+
| { session?: { messages?: ChatMessageData[] }; error?: string }
|
|
64
|
+
| null;
|
|
65
|
+
if (!live) return;
|
|
66
|
+
if (!response.ok) {
|
|
67
|
+
setError({ id: sourceSessionId, message: body?.error ?? `HTTP ${response.status}` });
|
|
68
|
+
setLoaded(null);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
setLoaded({ id: sourceSessionId, messages: body?.session?.messages ?? [] });
|
|
72
|
+
})
|
|
73
|
+
.catch((err: unknown) => {
|
|
74
|
+
if (!live || controller.signal.aborted) return;
|
|
75
|
+
setError({
|
|
76
|
+
id: sourceSessionId,
|
|
77
|
+
message: err instanceof Error ? err.message : 'Could not load the source transcript',
|
|
78
|
+
});
|
|
79
|
+
setLoaded(null);
|
|
80
|
+
})
|
|
81
|
+
.finally(() => {
|
|
82
|
+
if (live) setLoading(false);
|
|
83
|
+
});
|
|
84
|
+
return () => {
|
|
85
|
+
live = false;
|
|
86
|
+
controller.abort();
|
|
87
|
+
};
|
|
88
|
+
}, [sourceSessionId]);
|
|
89
|
+
|
|
90
|
+
// Rows from a previous source are not this fork's history: they disappear
|
|
91
|
+
// the moment the picker moves, rather than standing in for the new source.
|
|
92
|
+
const messages = useMemo(
|
|
93
|
+
() => (loaded && loaded.id === sourceSessionId
|
|
94
|
+
? forkPreviewMessages(loaded.messages, anchorEntryId)
|
|
95
|
+
: EMPTY),
|
|
96
|
+
[loaded, sourceSessionId, anchorEntryId],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
messages,
|
|
101
|
+
loading,
|
|
102
|
+
error: error && error.id === sourceSessionId ? error.message : null,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* What the fork composer sends to `/api/sessions/:id/fork`.
|
|
8
|
+
*
|
|
9
|
+
* Omitted fields let the fork keep the source's own model/thinking level and
|
|
10
|
+
* an absent message lets it branch without a first turn — both are normal.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { describe, expect, test } from 'bun:test';
|
|
14
|
+
import { forkRequestBody } from '@/client/hooks/chat/timeline/fork-request';
|
|
15
|
+
|
|
16
|
+
describe('forkRequestBody', () => {
|
|
17
|
+
test('carries the anchor and every pick the composer made', () => {
|
|
18
|
+
expect(
|
|
19
|
+
forkRequestBody('u2', {
|
|
20
|
+
prompt: 'try another angle',
|
|
21
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
22
|
+
model: { provider: 'acme', modelId: 'big' },
|
|
23
|
+
thinkingLevel: 'high',
|
|
24
|
+
accessMode: 'write',
|
|
25
|
+
}),
|
|
26
|
+
).toEqual({
|
|
27
|
+
anchorEntryId: 'u2',
|
|
28
|
+
prompt: 'try another angle',
|
|
29
|
+
images: [{ type: 'image', data: 'aGk=', mimeType: 'image/png' }],
|
|
30
|
+
model: { provider: 'acme', modelId: 'big' },
|
|
31
|
+
thinkingLevel: 'high',
|
|
32
|
+
accessMode: 'write',
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('a bare fork sends only the anchor', () => {
|
|
37
|
+
expect(forkRequestBody('a2')).toEqual({ anchorEntryId: 'a2' });
|
|
38
|
+
expect(
|
|
39
|
+
forkRequestBody('a2', {
|
|
40
|
+
prompt: ' ',
|
|
41
|
+
images: [],
|
|
42
|
+
model: null,
|
|
43
|
+
thinkingLevel: 'auto',
|
|
44
|
+
accessMode: null,
|
|
45
|
+
}),
|
|
46
|
+
).toEqual({ anchorEntryId: 'a2' });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('a half-named model is not sent', () => {
|
|
50
|
+
expect(forkRequestBody('u1', { model: { provider: '', modelId: 'x' } })).toEqual({
|
|
51
|
+
anchorEntryId: 'u1',
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The body of `POST /api/sessions/:id/fork` for the fork composer.
|
|
8
|
+
*
|
|
9
|
+
* Same rule as the child-session spawn: a field the composer has no value for
|
|
10
|
+
* is OMITTED, so the server keeps what the source transcript already carries.
|
|
11
|
+
* A fork with no message is a real case — the branch is still created.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { AgentImage } from '@/shared/types';
|
|
15
|
+
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
16
|
+
|
|
17
|
+
export interface ForkComposerPicks {
|
|
18
|
+
prompt?: string | null;
|
|
19
|
+
images?: AgentImage[] | null;
|
|
20
|
+
model?: { provider: string; modelId: string } | null;
|
|
21
|
+
thinkingLevel?: string | null;
|
|
22
|
+
accessMode?: ApprovalMode | null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function forkRequestBody(
|
|
26
|
+
anchorEntryId: string | null | undefined,
|
|
27
|
+
picks: ForkComposerPicks = {},
|
|
28
|
+
): Record<string, unknown> {
|
|
29
|
+
const prompt = picks.prompt?.trim() ? picks.prompt.trim() : null;
|
|
30
|
+
const images = picks.images?.length ? picks.images : null;
|
|
31
|
+
const model = picks.model;
|
|
32
|
+
return {
|
|
33
|
+
...(anchorEntryId ? { anchorEntryId } : {}),
|
|
34
|
+
...(prompt ? { prompt } : {}),
|
|
35
|
+
...(images ? { images } : {}),
|
|
36
|
+
...(model?.provider && model.modelId ? { model } : {}),
|
|
37
|
+
// `auto` means "leave the source transcript's level alone".
|
|
38
|
+
...(picks.thinkingLevel && picks.thinkingLevel !== 'auto'
|
|
39
|
+
? { thinkingLevel: picks.thinkingLevel }
|
|
40
|
+
: {}),
|
|
41
|
+
...(picks.accessMode ? { accessMode: picks.accessMode } : {}),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The FORK send: the branch inherits the source's history, so the chat that
|
|
8
|
+
* continues it must render that history — not just the new turn.
|
|
9
|
+
*
|
|
10
|
+
* The fork's file on disk already holds the copied rows, but the timeline skips
|
|
11
|
+
* a committed read while a run this page dispatched owns the rows, and a run
|
|
12
|
+
* that ends cleanly never re-reads the transcript. Measured symptom: the first
|
|
13
|
+
* forked turn appeared in an empty-looking chat and the conversation it
|
|
14
|
+
* continued only came back after a reload.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
18
|
+
import {
|
|
19
|
+
act,
|
|
20
|
+
installDomGlobals,
|
|
21
|
+
makeSendHarness,
|
|
22
|
+
originalFetch,
|
|
23
|
+
requests,
|
|
24
|
+
restoreDomGlobals,
|
|
25
|
+
} from '@/client/hooks/chat/timeline/send.test-util';
|
|
26
|
+
import {
|
|
27
|
+
listPendingSessions,
|
|
28
|
+
releasePendingSession,
|
|
29
|
+
startPendingSession,
|
|
30
|
+
} from '@/client/hooks/chat/omp/pending-sessions';
|
|
31
|
+
|
|
32
|
+
beforeAll(() => installDomGlobals());
|
|
33
|
+
afterAll(() => restoreDomGlobals());
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
globalThis.fetch = originalFetch;
|
|
36
|
+
for (const entry of listPendingSessions()) releasePendingSession(entry.id);
|
|
37
|
+
});
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
requests.length = 0;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const SOURCE_MESSAGES = [
|
|
43
|
+
{ id: 'u1', role: 'user', content: 'first question' },
|
|
44
|
+
{ id: 'a1', role: 'ai', content: 'first answer' },
|
|
45
|
+
{ id: 'u2', role: 'user', content: 'second question' },
|
|
46
|
+
{ id: 'a2', role: 'ai', content: 'second answer' },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
interface ForkStub {
|
|
50
|
+
/** Resolves the source transcript read, so a case can order the race. */
|
|
51
|
+
resolveSource: (body: unknown) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Answers the fork POST and holds the source read open until a case asks. */
|
|
55
|
+
function stubForkFetch(): ForkStub {
|
|
56
|
+
const source = Promise.withResolvers<Response>();
|
|
57
|
+
globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
58
|
+
const url = String(input);
|
|
59
|
+
requests.push({ url, method: init?.method ?? 'GET', body: init?.body === undefined ? null : String(init.body) });
|
|
60
|
+
if (url.startsWith('/api/sessions/src-1/fork')) {
|
|
61
|
+
return Response.json({ sessionId: 'fork-9', sourceSessionId: 'src-1', originKind: 'fork' }, { status: 201 });
|
|
62
|
+
}
|
|
63
|
+
if (url.startsWith('/api/chat/src-1?limit=all')) return source.promise;
|
|
64
|
+
return new Response('{}', { status: 200, headers: { 'content-type': 'application/json' } });
|
|
65
|
+
}) as typeof fetch;
|
|
66
|
+
return { resolveSource: (body) => source.resolve(Response.json(body)) };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** A pending fork chat bound to `src-1`, anchored at `anchor` (null = tip). */
|
|
70
|
+
function pendingFork(anchor: string | null): string {
|
|
71
|
+
return startPendingSession(4, {
|
|
72
|
+
forkSourceSessionId: 'src-1',
|
|
73
|
+
...(anchor ? { forkAnchorEntryId: anchor } : {}),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function flush(): Promise<void> {
|
|
78
|
+
await act(async () => {
|
|
79
|
+
for (let tick = 0; tick < 8; tick += 1) await Promise.resolve();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
describe('fork send inherits the source history', () => {
|
|
84
|
+
test('the branch transcript lands above the optimistic turn', async () => {
|
|
85
|
+
const stub = stubForkFetch();
|
|
86
|
+
const h1 = makeSendHarness({
|
|
87
|
+
isOmpSession: false,
|
|
88
|
+
sessionId: pendingFork('a2'),
|
|
89
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
90
|
+
selectedFolderId: 4,
|
|
91
|
+
});
|
|
92
|
+
await act(async () => {
|
|
93
|
+
await h1.sends.executeSend('continue it', []);
|
|
94
|
+
});
|
|
95
|
+
expect(h1.adoptedSessionIdRef.current).toBe('fork-9');
|
|
96
|
+
|
|
97
|
+
stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
|
|
98
|
+
await flush();
|
|
99
|
+
|
|
100
|
+
expect(h1.state.messages.map((m) => m.id)).toEqual([
|
|
101
|
+
'u1', 'a1', 'u2', 'a2', expect.stringMatching(/^msg-\d+-user$/), expect.stringMatching(/^msg-\d+-ai$/),
|
|
102
|
+
]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('the anchor cuts the prefix the same way the branch cuts the file', async () => {
|
|
106
|
+
const stub = stubForkFetch();
|
|
107
|
+
const h1 = makeSendHarness({
|
|
108
|
+
isOmpSession: false,
|
|
109
|
+
sessionId: pendingFork('u2'),
|
|
110
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
111
|
+
selectedFolderId: 4,
|
|
112
|
+
});
|
|
113
|
+
await act(async () => {
|
|
114
|
+
await h1.sends.executeSend('continue it', []);
|
|
115
|
+
});
|
|
116
|
+
stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
|
|
117
|
+
await flush();
|
|
118
|
+
// A user anchor branches BEFORE that turn: 'u2' is the message being replaced.
|
|
119
|
+
expect(h1.state.messages.slice(0, 2).map((m) => m.id)).toEqual(['u1', 'a1']);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('a read that lands after the chat moved on is dropped', async () => {
|
|
123
|
+
const stub = stubForkFetch();
|
|
124
|
+
const h1 = makeSendHarness({
|
|
125
|
+
isOmpSession: false,
|
|
126
|
+
sessionId: pendingFork(null),
|
|
127
|
+
folders: [{ id: 4, name: 'demo', project_path: '/tmp/demo' }],
|
|
128
|
+
selectedFolderId: 4,
|
|
129
|
+
});
|
|
130
|
+
await act(async () => {
|
|
131
|
+
await h1.sends.executeSend('continue it', []);
|
|
132
|
+
});
|
|
133
|
+
h1.adoptedSessionIdRef.current = 'another-chat';
|
|
134
|
+
stub.resolveSource({ session: { messages: SOURCE_MESSAGES } });
|
|
135
|
+
await flush();
|
|
136
|
+
expect(h1.state.messages).toHaveLength(2);
|
|
137
|
+
expect(h1.state.messages[0]?.id).toMatch(/^msg-\d+-user$/);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { describe, expect, test } from 'bun:test';
|
|
17
|
-
import { modeAvailability } from '@/client/hooks/chat/timeline/
|
|
17
|
+
import { modeAvailability } from '@/client/hooks/chat/timeline/mode-availability';
|
|
18
18
|
|
|
19
19
|
describe('modeAvailability', () => {
|
|
20
20
|
test('omp RPC carries both modes', () => {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Which mode toggles a harness can actually honour.
|
|
8
|
+
*
|
|
9
|
+
* Pure, so the rule is testable without a render. Split from `modes.ts` when
|
|
10
|
+
* the compositor's ACP mode selector pushed that hook toward the file ceiling.
|
|
11
|
+
*
|
|
12
|
+
* Goal is available on every harness: Kabmo owns the record and the loop for
|
|
13
|
+
* ACP (`acp-goal.server.ts`), and omp carries the extension. Plan is different —
|
|
14
|
+
* it must be a real mode the agent publishes (`claude` does, `opencode` does
|
|
15
|
+
* not), except on omp's own two transports, which always expose the Plan
|
|
16
|
+
* toggle. An unknown harness keeps the old surface: the row may simply not have
|
|
17
|
+
* arrived yet.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export interface ModeCapabilities {
|
|
21
|
+
/** The harness that owns this chat, when the tab knows it. */
|
|
22
|
+
harness?: string | null;
|
|
23
|
+
/** The harness's own `mode` values, from its probe: `plan` is a real mode on
|
|
24
|
+
* the agents that publish one. */
|
|
25
|
+
modeValues?: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function modeAvailability(capabilities: ModeCapabilities): { plan: boolean; goal: boolean } {
|
|
29
|
+
if (capabilities.harness === 'omp-rpc') return { plan: true, goal: true };
|
|
30
|
+
if (!capabilities.harness) return { plan: true, goal: true };
|
|
31
|
+
if (capabilities.harness === 'omp-acp') return { plan: true, goal: true };
|
|
32
|
+
return { plan: capabilities.modeValues?.includes('plan') === true, goal: true };
|
|
33
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { useEffect, useRef } from 'preact/hooks';
|
|
17
17
|
import type { KabmoModeSelection, GoalContinuation, GoalRecord } from '@/shared/lib/omp/mode/types';
|
|
18
|
+
import type { SessionModeState } from '@/shared/lib/harness/session-modes';
|
|
18
19
|
import { KABMO_MODE_SIGNAL } from '@/shared/lib/omp/mode/client-signal';
|
|
19
20
|
import { isModeMarker } from '@/shared/lib/omp/mode/constants';
|
|
20
21
|
import { subscribeClientSignal } from '@/client/lib/signals';
|
|
@@ -27,7 +28,12 @@ import {
|
|
|
27
28
|
|
|
28
29
|
/** The persisted selection, plus the goal record the same read returns. */
|
|
29
30
|
export interface ModesResponse {
|
|
30
|
-
modes?: KabmoModeSelection & {
|
|
31
|
+
modes?: KabmoModeSelection & {
|
|
32
|
+
goalRecord?: GoalRecord | null;
|
|
33
|
+
goalContinuation?: GoalContinuation | null;
|
|
34
|
+
/** The agent's own mode selector, for an ACP chat. */
|
|
35
|
+
mode?: SessionModeState | null;
|
|
36
|
+
};
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
/**
|