@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
|
@@ -47,7 +47,9 @@ function processDouble(overrides: Record<string, unknown> = {}) {
|
|
|
47
47
|
return {
|
|
48
48
|
calls,
|
|
49
49
|
async initialize() {
|
|
50
|
-
|
|
50
|
+
// `session/load` is capability-gated on the AGENT's answer, so the double
|
|
51
|
+
// advertises it unless a case replaces the whole method.
|
|
52
|
+
return { protocolVersion: 1, agentCapabilities: { loadSession: true } };
|
|
51
53
|
},
|
|
52
54
|
async loadSession() {
|
|
53
55
|
calls.push('load');
|
|
@@ -73,6 +75,93 @@ describe('handshakeAcpSession', () => {
|
|
|
73
75
|
expect(proc.calls).toEqual(['load', 'new']);
|
|
74
76
|
});
|
|
75
77
|
|
|
78
|
+
test('an agent with no loadSession but sessionCapabilities.resume resumes in place', async () => {
|
|
79
|
+
const proc = processDouble({
|
|
80
|
+
async initialize() {
|
|
81
|
+
return {
|
|
82
|
+
protocolVersion: 1,
|
|
83
|
+
agentCapabilities: { loadSession: false, sessionCapabilities: { resume: {} } },
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
async resumeSession(sessionId: string) {
|
|
87
|
+
proc.calls.push(`resume:${sessionId}`);
|
|
88
|
+
return { configOptions: [{ id: 'model', category: 'model', type: 'select', currentValue: 'a/b' }] };
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const session = target();
|
|
92
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
93
|
+
// A resume replays nothing and creates nothing: no replacement session.
|
|
94
|
+
expect(proc.calls).toEqual(['resume:agent-1']);
|
|
95
|
+
expect(session.sessionId).toBe('agent-1');
|
|
96
|
+
expect(session.runModel).toEqual({ provider: 'a', modelId: 'b' });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a legacy modes list applies the requested mode through session/set_mode', async () => {
|
|
100
|
+
const proc = processDouble({
|
|
101
|
+
async newSession() {
|
|
102
|
+
proc.calls.push('new');
|
|
103
|
+
return {
|
|
104
|
+
sessionId: 'new-id',
|
|
105
|
+
modes: {
|
|
106
|
+
currentModeId: 'code',
|
|
107
|
+
availableModes: [{ id: 'code', name: 'Code' }, { id: 'plan', name: 'Plan' }],
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
const session = target();
|
|
113
|
+
const applied: string[] = [];
|
|
114
|
+
session.setMode = async (mode) => {
|
|
115
|
+
applied.push(mode);
|
|
116
|
+
return {};
|
|
117
|
+
};
|
|
118
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: 'plan' });
|
|
119
|
+
expect(applied).toEqual(['plan']);
|
|
120
|
+
expect(session.modes?.availableModes.map((entry) => entry.id)).toEqual(['code', 'plan']);
|
|
121
|
+
expect(session.capabilities.configMode).toBe(2);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
test('v2 resumes in place with resume, never session/load', async () => {
|
|
125
|
+
const proc = processDouble({
|
|
126
|
+
protocolVersion: 2,
|
|
127
|
+
async initialize() {
|
|
128
|
+
return {
|
|
129
|
+
protocolVersion: 2,
|
|
130
|
+
agentCapabilities: {
|
|
131
|
+
loadSession: false,
|
|
132
|
+
sessionCapabilities: { list: {}, resume: {}, close: {} },
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
async resumeSession(sessionId: string) {
|
|
137
|
+
proc.calls.push(`resume:${sessionId}`);
|
|
138
|
+
return {
|
|
139
|
+
configOptions: [{ id: 'model', category: 'model', currentValue: 'a/b' }],
|
|
140
|
+
availableCommands: [{ name: 'test', description: 'Run tests' }],
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
});
|
|
144
|
+
const session = target();
|
|
145
|
+
await handshakeAcpSession(session, proc, { model: null, thinking: null, mode: null }, 'agent-1');
|
|
146
|
+
expect(proc.calls).toEqual(['resume:agent-1']);
|
|
147
|
+
expect(session.sessionId).toBe('agent-1');
|
|
148
|
+
expect(session.runModel).toEqual({ provider: 'a', modelId: 'b' });
|
|
149
|
+
expect(session.agentCommands).toEqual([{ name: 'test', description: 'Run tests' }]);
|
|
150
|
+
expect(session.capabilities.resumeSession).toBe(true);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('neither load nor resume is refused instead of calling an unadvertised method', async () => {
|
|
154
|
+
const proc = processDouble({
|
|
155
|
+
async initialize() {
|
|
156
|
+
return { protocolVersion: 1, agentCapabilities: {} };
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
await expect(
|
|
160
|
+
handshakeAcpSession(target(), proc, { model: null, thinking: null, mode: null }, 'agent-1'),
|
|
161
|
+
).rejects.toThrow('neither session/load nor session/resume');
|
|
162
|
+
expect(proc.calls).toEqual([]);
|
|
163
|
+
});
|
|
164
|
+
|
|
76
165
|
test('fork asks the agent for session/fork and uses the returned id', async () => {
|
|
77
166
|
const proc = processDouble({
|
|
78
167
|
async forkSession(sessionId: string) {
|
|
@@ -28,8 +28,11 @@ import { newSessionAfterActivation } from '@/server/lib/harness/acp/activation';
|
|
|
28
28
|
import { applySelections, configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
|
|
29
29
|
import { capabilitiesFrom } from '@/server/lib/harness/launch';
|
|
30
30
|
import type {
|
|
31
|
+
AcpAgentCommand,
|
|
31
32
|
AcpConfigOption,
|
|
32
33
|
AcpInitializeResult,
|
|
34
|
+
AcpProtocolVersion,
|
|
35
|
+
AcpSessionModeState,
|
|
33
36
|
AcpSessionNewResult,
|
|
34
37
|
} from '@/server/lib/harness/acp/protocol';
|
|
35
38
|
import type { HarnessCapabilities } from '@/server/lib/harness/capabilities';
|
|
@@ -37,9 +40,13 @@ import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
|
37
40
|
|
|
38
41
|
/** The process slice a handshake drives; `AcpProcess` satisfies it as-is. */
|
|
39
42
|
export interface AcpHandshakeProcess {
|
|
40
|
-
initialize(params
|
|
43
|
+
initialize(params?: Record<string, unknown>, timeoutMs?: number): Promise<AcpInitializeResult>;
|
|
41
44
|
loadSession(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
|
|
42
45
|
newSession(cwd: string, timeoutMs?: number): Promise<AcpSessionNewResult>;
|
|
46
|
+
/** The negotiated major; absent on a test double, which is a v1 double. */
|
|
47
|
+
readonly protocolVersion?: AcpProtocolVersion;
|
|
48
|
+
/** `session/resume`; absent on a process double used by older tests. */
|
|
49
|
+
resumeSession?(sessionId: string, cwd: string, timeoutMs?: number): Promise<unknown>;
|
|
43
50
|
/** `session/fork`; absent on a process double used by older tests. */
|
|
44
51
|
forkSession?(
|
|
45
52
|
sessionId: string,
|
|
@@ -55,9 +62,20 @@ export interface AcpHandshakeTarget {
|
|
|
55
62
|
readonly harness: HarnessId;
|
|
56
63
|
sessionId: string;
|
|
57
64
|
configOptions: AcpConfigOption[];
|
|
65
|
+
/** The older Session Modes API, when the agent publishes no `mode` selector. */
|
|
66
|
+
modes?: AcpSessionModeState | null;
|
|
58
67
|
runModel: { provider: string; modelId: string } | null;
|
|
59
68
|
capabilities: HarnessCapabilities;
|
|
60
69
|
setConfig(configId: string, value: string | boolean): Promise<unknown>;
|
|
70
|
+
/** `session/set_mode`; absent on a target that only speaks config options. */
|
|
71
|
+
setMode?(modeId: string): Promise<unknown>;
|
|
72
|
+
/** Whether prompts may carry image blocks; the agent advertised `image`. */
|
|
73
|
+
acceptsImages?: boolean;
|
|
74
|
+
/** Initial slash commands from a v2 setup response. */
|
|
75
|
+
agentCommands?: AcpAgentCommand[];
|
|
76
|
+
/** Called as soon as `initialize` answers, before any session request, so a
|
|
77
|
+
* v2 resume snapshot can open a turn. */
|
|
78
|
+
onProtocol?(version: AcpProtocolVersion): void;
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
/** The picks the composer sent for a brand-new session. */
|
|
@@ -74,7 +92,8 @@ export async function handshakeAcpSession(
|
|
|
74
92
|
sessionIdToLoad?: string,
|
|
75
93
|
forkFromSessionId?: string,
|
|
76
94
|
): Promise<void> {
|
|
77
|
-
const init = await proc.initialize(
|
|
95
|
+
const init = await proc.initialize(undefined, 60_000);
|
|
96
|
+
target.onProtocol?.(init.protocolVersion === 2 ? 2 : 1);
|
|
78
97
|
/** opencode's plugin activation gate: the first `session/new`s refuse with
|
|
79
98
|
* `ServiceUnavailableError` until the agent's plugins finish booting. */
|
|
80
99
|
const newSession = (cwd: string, timeoutMs?: number) =>
|
|
@@ -101,15 +120,73 @@ export async function handshakeAcpSession(
|
|
|
101
120
|
target.harness === 'zcode' ? { kind: 'latestCheckpoint' } : undefined,
|
|
102
121
|
);
|
|
103
122
|
} else if (sessionIdToLoad) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
// ACP gates restoration on the AGENT's advertised capability: `loadSession`
|
|
124
|
+
// replays history, `sessionCapabilities.resume` restores without replay, and
|
|
125
|
+
// an agent that advertises neither must be refused in words. Calling
|
|
126
|
+
// `session/load` anyway asked a non-supporting agent for a method it had not
|
|
127
|
+
// advertised and surfaced its `-32601` as a spawn failure.
|
|
128
|
+
const caps = init.agentCapabilities ?? {};
|
|
129
|
+
const restored = proc.protocolVersion === 2
|
|
130
|
+
// v2 removed `session/load`; `session/resume` is baseline and replays
|
|
131
|
+
// nothing unless `replayFrom` asks, which is exactly what Kabmo wants —
|
|
132
|
+
// its own transcript is already on screen.
|
|
133
|
+
? await (proc.resumeSession
|
|
134
|
+
? proc.resumeSession(sessionIdToLoad, target.cwd, 120_000)
|
|
135
|
+
: Promise.reject(new Error(`${target.harness} cannot resume a session`)))
|
|
136
|
+
: caps.loadSession === true
|
|
137
|
+
? await loadReplacement(proc, newSession, sessionIdToLoad, target.cwd)
|
|
138
|
+
: caps.sessionCapabilities?.resume != null
|
|
139
|
+
? await (proc.resumeSession
|
|
140
|
+
? proc.resumeSession(sessionIdToLoad, target.cwd, 120_000)
|
|
141
|
+
: Promise.reject(new Error(`${target.harness} cannot resume a session`)))
|
|
142
|
+
: null;
|
|
143
|
+
if (restored === null) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`${target.harness} cannot restore this chat: it supports neither session/load nor session/resume`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
const state = restored && typeof restored === 'object'
|
|
149
|
+
? (restored as Partial<AcpSessionNewResult>)
|
|
150
|
+
: {};
|
|
151
|
+
// `session/resume` replays NOTHING and creates nothing: the id stays the
|
|
152
|
+
// caller's, and only the config/mode state the reply carries is adopted.
|
|
153
|
+
session = { ...state, sessionId: sessionIdToLoad };
|
|
107
154
|
} else {
|
|
108
155
|
session = await newSession(target.cwd, 120_000);
|
|
109
156
|
}
|
|
110
157
|
target.sessionId = session.sessionId || sessionIdToLoad || '';
|
|
111
158
|
target.configOptions = session.configOptions ?? [];
|
|
159
|
+
target.modes = session.modes ?? null;
|
|
160
|
+
target.acceptsImages = init.agentCapabilities?.promptCapabilities?.image === true;
|
|
161
|
+
if (session.availableCommands) target.agentCommands = session.availableCommands;
|
|
112
162
|
target.runModel = modelFromOption(configOption(target.configOptions, 'model'), target.harness);
|
|
113
|
-
target.capabilities = capabilitiesFrom(init, target.configOptions, { usage: false, plan: false });
|
|
163
|
+
target.capabilities = capabilitiesFrom(init, target.configOptions, { usage: false, plan: false }, target.modes);
|
|
114
164
|
await applySelections(target, wanted);
|
|
165
|
+
// A mode the composer asked for, on an agent that publishes only the older
|
|
166
|
+
// `modes` list: `session/set_mode` is the only way to apply it.
|
|
167
|
+
if (
|
|
168
|
+
wanted.mode
|
|
169
|
+
&& !configOption(target.configOptions, 'mode')
|
|
170
|
+
&& target.modes?.availableModes.some((entry) => entry.id === wanted.mode)
|
|
171
|
+
&& target.setMode
|
|
172
|
+
) {
|
|
173
|
+
await target.setMode(wanted.mode).catch(() => {});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The v1 load path: replay the agent's history into the mapper, then continue on
|
|
179
|
+
* a fresh agent session.
|
|
180
|
+
*
|
|
181
|
+
* Deliberate: measured on omp, a load answers a FORKED id, and continuing on it
|
|
182
|
+
* would write a second sidebar row for one chat.
|
|
183
|
+
*/
|
|
184
|
+
async function loadReplacement(
|
|
185
|
+
proc: AcpHandshakeProcess,
|
|
186
|
+
create: (cwd: string, timeoutMs?: number) => Promise<AcpSessionNewResult>,
|
|
187
|
+
sessionId: string,
|
|
188
|
+
cwd: string,
|
|
189
|
+
): Promise<unknown> {
|
|
190
|
+
await proc.loadSession(sessionId, cwd, 120_000);
|
|
191
|
+
return (await create(cwd).catch(() => null)) ?? { sessionId };
|
|
115
192
|
}
|
|
@@ -33,15 +33,16 @@ export interface AcpIdleHost {
|
|
|
33
33
|
* the user's question with it), and the answer is `false` so `IdleReaper`
|
|
34
34
|
* re-arms instead of waiting for a frame that a parked dialog will not send.
|
|
35
35
|
*
|
|
36
|
-
* A child that cannot be restored is also left alone:
|
|
37
|
-
*
|
|
38
|
-
* fresh agent under a chat's
|
|
39
|
-
*
|
|
40
|
-
* file, so the chat is restored
|
|
36
|
+
* A child that cannot be restored is also left alone: an agent with neither
|
|
37
|
+
* `session/load` nor `session/resume` has no way back, and
|
|
38
|
+
* `resumeRecordedHarnessSession` refuses to spawn a fresh agent under a chat's
|
|
39
|
+
* id, so reclaiming one would leave a chat that can never take another prompt.
|
|
40
|
+
* `omp-acp` is the exception — it writes a session file, so the chat is restored
|
|
41
|
+
* over RPC.
|
|
41
42
|
*/
|
|
42
43
|
export function reclaimIdleAcpSession(host: AcpIdleHost): boolean {
|
|
43
44
|
if (host.isBusy()) return false;
|
|
44
|
-
if (!host.capabilities.loadSession && host.harness !== 'omp-acp') return true;
|
|
45
|
+
if (!host.capabilities.loadSession && !host.capabilities.resumeSession && host.harness !== 'omp-acp') return true;
|
|
45
46
|
host.destroy();
|
|
46
47
|
return true;
|
|
47
48
|
}
|
|
@@ -26,18 +26,26 @@ import {
|
|
|
26
26
|
stampMessageModel,
|
|
27
27
|
type AcpConfigNotice,
|
|
28
28
|
} from '@/server/lib/harness/acp/session-config';
|
|
29
|
-
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
29
|
+
import type { AcpConfigOption, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
30
30
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
31
|
+
import { saveAcpPlanState } from '@/server/lib/harness/acp/acp-goal-state.server';
|
|
32
|
+
import { normalizeConfigOptions, planEntries } from '@/server/lib/harness/acp/v2';
|
|
31
33
|
|
|
32
34
|
export interface AcpNotificationHost extends AcpConfigNotice {
|
|
33
35
|
readonly harness: HarnessId;
|
|
36
|
+
/** The negotiated major; v2 renamed a few update payloads. */
|
|
37
|
+
readonly protocol: AcpProtocolVersion;
|
|
34
38
|
agentCommands: AgentCommand[];
|
|
35
39
|
planEntries: unknown[];
|
|
40
|
+
/** The older Session Modes API; updated when the agent switches itself. */
|
|
41
|
+
modes: AcpSessionModeState | null;
|
|
36
42
|
capabilities: HarnessCapabilities;
|
|
37
43
|
messageCount: number;
|
|
38
44
|
assistantCount: number;
|
|
39
45
|
absorbUsage(update: Record<string, unknown>): void;
|
|
40
46
|
acceptingFrames(): boolean;
|
|
47
|
+
/** v2's turn boundary; a no-op on v1 and when no turn is open. */
|
|
48
|
+
onStateUpdate(update: Record<string, unknown>): void;
|
|
41
49
|
mapUpdate(update: Record<string, unknown>): AgentEvent[];
|
|
42
50
|
emit(event: AgentEvent): void;
|
|
43
51
|
}
|
|
@@ -61,7 +69,14 @@ export function handleSessionNotification(
|
|
|
61
69
|
// capability flags entirely.
|
|
62
70
|
if (kind === 'available_commands_update') host.agentCommands = parseAgentCommands(record);
|
|
63
71
|
if (kind === 'plan') host.planEntries = Array.isArray(record.entries) ? record.entries : [];
|
|
72
|
+
if (kind === 'plan_update') host.planEntries = planEntries(record);
|
|
64
73
|
if (kind === 'usage_update') host.absorbUsage(record);
|
|
74
|
+
// v2's foreground lifecycle. `idle` closes the turn; it must reach the turn
|
|
75
|
+
// machine even when the mapper has nothing to draw.
|
|
76
|
+
if (kind === 'state_update') {
|
|
77
|
+
host.onStateUpdate(record);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
65
80
|
const absorbed = metadataCapabilities(host.capabilities, kind);
|
|
66
81
|
if (absorbed !== host.capabilities) host.capabilities = absorbed;
|
|
67
82
|
// The agent's own name for this chat arrives BETWEEN turns (measured on
|
|
@@ -76,8 +91,32 @@ export function handleSessionNotification(
|
|
|
76
91
|
// is adopted BEFORE the turn gate below — the session, telemetry and the goal
|
|
77
92
|
// audit must read the same model the client's `config_option_update` names.
|
|
78
93
|
if (kind === 'config_option_update' && Array.isArray(record.configOptions)) {
|
|
79
|
-
|
|
94
|
+
const options = host.protocol === 2
|
|
95
|
+
? normalizeConfigOptions(record.configOptions)
|
|
96
|
+
: (record.configOptions as AcpConfigOption[]);
|
|
97
|
+
adoptConfigList(host, options);
|
|
80
98
|
publishConfigChange(host);
|
|
99
|
+
// v2 removed `current_mode_update`; a mode change arrives here. The
|
|
100
|
+
// composer's Plan control reads the persisted flag, so mirror it.
|
|
101
|
+
const mode = options.find((option) => option.category === 'mode');
|
|
102
|
+
if (typeof mode?.currentValue === 'string') {
|
|
103
|
+
void saveAcpPlanState(host.sessionId, mode.currentValue === 'plan').catch(() => {});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// The agent moved its own mode (a plan-mode exit tool, a fallback). The
|
|
107
|
+
// composer's Plan control reads the persisted flag rather than the frame
|
|
108
|
+
// stream, so mirroring it here is what keeps the toggle truthful.
|
|
109
|
+
if (kind === 'current_mode_update' && typeof record.currentModeId === 'string') {
|
|
110
|
+
if (host.modes) host.modes = { ...host.modes, currentModeId: record.currentModeId };
|
|
111
|
+
void saveAcpPlanState(host.sessionId, record.currentModeId === 'plan').catch(() => {});
|
|
112
|
+
}
|
|
113
|
+
// A notice is a LIVE user-facing event, not conversation output: the spec
|
|
114
|
+
// allows it at any point while a session exists, and it requires the
|
|
115
|
+
// `session.notices` capability this client now advertises. Applying the turn
|
|
116
|
+
// gate below would have dropped exactly the notices that arrive between turns.
|
|
117
|
+
if (kind === 'notice') {
|
|
118
|
+
for (const event of host.mapUpdate(record)) host.emit(event);
|
|
119
|
+
return;
|
|
81
120
|
}
|
|
82
121
|
|
|
83
122
|
// No turn open: the user stopped it (or one is still queued), and anything
|
|
@@ -100,6 +100,18 @@ describe('ACP stream marker', () => {
|
|
|
100
100
|
expect(streamMarks()).toEqual(['stream', 'abort']);
|
|
101
101
|
});
|
|
102
102
|
|
|
103
|
+
test('a failed turn carries the agent reason onto the finish mark', async () => {
|
|
104
|
+
const { session, turn, streamMarks, streamMarkFailures } = mountSession();
|
|
105
|
+
await session.send({ type: 'prompt', message: 'Say DUMMY_OK' });
|
|
106
|
+
await turn.started;
|
|
107
|
+
// No answer at all is the ACP silent-turn verdict, and the only reason the
|
|
108
|
+
// notification has to show.
|
|
109
|
+
turn.finish({ stopReason: 'end_turn' });
|
|
110
|
+
for (let i = 0; i < 4; i += 1) await Promise.resolve();
|
|
111
|
+
expect(streamMarks()).toEqual(['stream', 'finish']);
|
|
112
|
+
expect(streamMarkFailures()).toEqual([null, 'The agent ended the turn without sending an answer']);
|
|
113
|
+
});
|
|
114
|
+
|
|
103
115
|
test('a refused prompt writes nothing', async () => {
|
|
104
116
|
const { session, turn, streamMarks } = mountSession();
|
|
105
117
|
await session.send({ type: 'prompt', message: 'first' });
|
|
@@ -169,6 +181,24 @@ describe('ACP session facts', () => {
|
|
|
169
181
|
expect(await session.send({ type: 'get_commands' })).toEqual({ commands: session.agentCommands });
|
|
170
182
|
});
|
|
171
183
|
|
|
184
|
+
test('presents a notice that arrives with no turn open', () => {
|
|
185
|
+
const { session, events } = mountSession();
|
|
186
|
+
// `session.notices` is advertised, so a spec-compliant agent sends these
|
|
187
|
+
// between turns. The turn gate exists for abandoned output, not for a live
|
|
188
|
+
// notice — dropping it here would have made the advertisement a lie.
|
|
189
|
+
notify(session, {
|
|
190
|
+
sessionUpdate: 'notice',
|
|
191
|
+
severity: 'warning',
|
|
192
|
+
title: 'MCP server unavailable',
|
|
193
|
+
description: 'Continuing without it.',
|
|
194
|
+
});
|
|
195
|
+
expect(events.at(-1)).toEqual({
|
|
196
|
+
type: 'notice',
|
|
197
|
+
level: 'warning',
|
|
198
|
+
message: 'MCP server unavailable — Continuing without it.',
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
172
202
|
test('records the agent’s own title, which arrives BETWEEN turns', async () => {
|
|
173
203
|
const { session } = mountSession();
|
|
174
204
|
await saveHarnessSession({ sessionId: 'acp-1', harness: 'opencode', agentSessionId: '', cwd: '/tmp' });
|
|
@@ -190,4 +220,37 @@ describe('ACP session facts', () => {
|
|
|
190
220
|
const [row] = await loadAcpSessions();
|
|
191
221
|
expect(row.title).toBe('Release train');
|
|
192
222
|
});
|
|
223
|
+
|
|
224
|
+
test('publishes the legacy mode list as a selector every consumer reads', () => {
|
|
225
|
+
const { session } = mountSession();
|
|
226
|
+
session.modes = {
|
|
227
|
+
currentModeId: 'plan',
|
|
228
|
+
availableModes: [{ id: 'plan', name: 'Plan' }, { id: 'code', name: 'Code' }],
|
|
229
|
+
};
|
|
230
|
+
expect(session.webState().configOptions).toEqual(expect.arrayContaining([
|
|
231
|
+
expect.objectContaining({ id: 'mode', category: 'mode', currentValue: 'plan' }),
|
|
232
|
+
]));
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
test('an agent-initiated mode change is adopted by the session', () => {
|
|
236
|
+
const { session } = mountSession();
|
|
237
|
+
session.modes = { currentModeId: 'code', availableModes: [{ id: 'code', name: 'Code' }] };
|
|
238
|
+
notify(session, { sessionUpdate: 'current_mode_update', currentModeId: 'plan' });
|
|
239
|
+
expect(session.modes?.currentModeId).toBe('plan');
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('agent-side delete runs only when the agent advertises it', async () => {
|
|
243
|
+
const { session, deletedSessions } = mountSession();
|
|
244
|
+
await session.deleteAgentSession();
|
|
245
|
+
expect(deletedSessions()).toEqual([]);
|
|
246
|
+
session.capabilities = { ...session.capabilities, deleteSession: true };
|
|
247
|
+
await session.deleteAgentSession();
|
|
248
|
+
expect(deletedSessions()).toEqual(['acp-1']);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('an image prompt is refused when the agent did not advertise image', () => {
|
|
252
|
+
const { session } = mountSession();
|
|
253
|
+
expect(() => session.startTurn('look', [{ data: 'AAAA', mimeType: 'image/png' }]))
|
|
254
|
+
.toThrow('does not accept image attachments');
|
|
255
|
+
});
|
|
193
256
|
});
|
|
@@ -103,3 +103,32 @@ describe('ACP permission gating', () => {
|
|
|
103
103
|
turn.finish({ stopReason: 'end_turn' });
|
|
104
104
|
});
|
|
105
105
|
});
|
|
106
|
+
|
|
107
|
+
describe('ACP cancellation answers parked approvals', () => {
|
|
108
|
+
test('Stop answers every parked request with the cancelled outcome', async () => {
|
|
109
|
+
const { session, permissionAnswers } = mountSession();
|
|
110
|
+
await permission(session, 21, 'execute');
|
|
111
|
+
session.cancelTurn();
|
|
112
|
+
expect(permissionAnswers()).toEqual([
|
|
113
|
+
{ id: 21, result: { outcome: { outcome: 'cancelled' } } },
|
|
114
|
+
]);
|
|
115
|
+
expect(session.isBusy()).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('$/cancel_request answers the named request and ignores an unknown id', async () => {
|
|
119
|
+
const { session, permissionAnswers } = mountSession();
|
|
120
|
+
await permission(session, 22, 'execute');
|
|
121
|
+
const cancel = (requestId: unknown): void => {
|
|
122
|
+
(session as unknown as {
|
|
123
|
+
onNotification(method: string, params: Record<string, unknown>): void;
|
|
124
|
+
}).onNotification('$/cancel_request', { requestId });
|
|
125
|
+
};
|
|
126
|
+
cancel(999);
|
|
127
|
+
expect(permissionAnswers()).toEqual([]);
|
|
128
|
+
cancel(22);
|
|
129
|
+
expect(permissionAnswers()).toEqual([
|
|
130
|
+
{ id: 22, result: { outcome: { outcome: 'cancelled' } } },
|
|
131
|
+
]);
|
|
132
|
+
expect(session.isBusy()).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
@@ -40,6 +40,42 @@ export function preApprovedOption(
|
|
|
40
40
|
return allowOption(options);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** What `session/request_permission` returns; `AcpProcess` satisfies it. */
|
|
44
|
+
export interface AcpPermissionResponder {
|
|
45
|
+
respond(id: string | number, result: unknown): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Answer one parked request with the `cancelled` outcome.
|
|
50
|
+
*
|
|
51
|
+
* ACP requires this whenever the turn is cancelled: a cancelled prompt whose
|
|
52
|
+
* permission request is still parked leaves the agent waiting on a question the
|
|
53
|
+
* user can no longer see. `requestId` is a JSON-RPC id from `$/cancel_request`,
|
|
54
|
+
* or the dialog id from the client's own Stop.
|
|
55
|
+
*/
|
|
56
|
+
export function cancelAcpPermission(
|
|
57
|
+
permissions: PendingPermissions,
|
|
58
|
+
responder: AcpPermissionResponder,
|
|
59
|
+
requestId: string | number,
|
|
60
|
+
): boolean {
|
|
61
|
+
const entry = permissions.take(String(requestId));
|
|
62
|
+
if (!entry) return false;
|
|
63
|
+
responder.respond(entry.id, { outcome: { outcome: 'cancelled' } });
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Cancel every parked request — the client's half of `session/cancel`. */
|
|
68
|
+
export function cancelAllAcpPermissions(
|
|
69
|
+
permissions: PendingPermissions,
|
|
70
|
+
responder: AcpPermissionResponder,
|
|
71
|
+
): number {
|
|
72
|
+
const drained = permissions.drain();
|
|
73
|
+
for (const entry of drained) {
|
|
74
|
+
responder.respond(entry.id, { outcome: { outcome: 'cancelled' } });
|
|
75
|
+
}
|
|
76
|
+
return drained.length;
|
|
77
|
+
}
|
|
78
|
+
|
|
43
79
|
/** The slice of a session a permission request needs. */
|
|
44
80
|
export interface PermissionRequestHost {
|
|
45
81
|
readonly sessionId: string;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Agent→client request routing.
|
|
8
|
+
*
|
|
9
|
+
* The two branches that are easy to get wrong: an unimplemented method must
|
|
10
|
+
* answer `-32601` (an agent falls back on that; an internal error looks like a
|
|
11
|
+
* client bug), and the advertised fs surface must actually be served rather
|
|
12
|
+
* than refused.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
17
|
+
import { tmpdir } from 'node:os';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
20
|
+
import { handleAcpClientRequest, type AcpClientRequestHost } from '@/server/lib/harness/acp/session-requests';
|
|
21
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
22
|
+
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
23
|
+
|
|
24
|
+
const scratch: string[] = [];
|
|
25
|
+
|
|
26
|
+
function host(cwd = '/tmp', protocol: 1 | 2 = 1): AcpClientRequestHost {
|
|
27
|
+
return {
|
|
28
|
+
sessionId: 's1',
|
|
29
|
+
cwd,
|
|
30
|
+
protocol,
|
|
31
|
+
accessMode: 'always-ask',
|
|
32
|
+
permissions: new PendingPermissions(),
|
|
33
|
+
emit: (_event: AgentEvent) => {},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
afterEach(async () => {
|
|
38
|
+
await Promise.all(scratch.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('handleAcpClientRequest', () => {
|
|
42
|
+
test('an unimplemented method is refused with method-not-found', async () => {
|
|
43
|
+
const answer = await handleAcpClientRequest(host(), 1, 'terminal/create', {
|
|
44
|
+
sessionId: 's1',
|
|
45
|
+
command: 'ls',
|
|
46
|
+
});
|
|
47
|
+
expect(answer).toEqual({
|
|
48
|
+
answered: false,
|
|
49
|
+
message: 'Kabmo does not implement terminal/create',
|
|
50
|
+
code: ACP_ERROR.methodNotFound,
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the advertised fs surface is served, not refused', async () => {
|
|
55
|
+
const dir = await mkdtemp(join(tmpdir(), 'kabmo-acp-req-'));
|
|
56
|
+
scratch.push(dir);
|
|
57
|
+
await Bun.write(join(dir, 'a.txt'), 'hi');
|
|
58
|
+
const answer = await handleAcpClientRequest(host(dir), 2, 'fs/read_text_file', {
|
|
59
|
+
sessionId: 's1',
|
|
60
|
+
path: join(dir, 'a.txt'),
|
|
61
|
+
});
|
|
62
|
+
expect(answer).toEqual({ answered: true, result: { content: 'hi' } });
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('a v2 tool_call subject is applied like the v1 tool call', async () => {
|
|
66
|
+
const request = host('/tmp', 2);
|
|
67
|
+
const answer = await handleAcpClientRequest(request, 3, 'session/request_permission', {
|
|
68
|
+
sessionId: 's1',
|
|
69
|
+
title: 'Read a file?',
|
|
70
|
+
subject: { type: 'tool_call', toolCall: { toolCallId: 'c1', kind: 'read' } },
|
|
71
|
+
options: [{ optionId: 'allow', kind: 'allow_once' }],
|
|
72
|
+
});
|
|
73
|
+
// `always-ask` auto-runs the read tier, exactly as it does for v1.
|
|
74
|
+
expect(answer).toMatchObject({ answered: true, result: { outcome: { outcome: 'selected' } } });
|
|
75
|
+
expect(request.permissions.size()).toBe(0);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('a v2 command subject parks the dialog with the command visible', async () => {
|
|
79
|
+
const request = host('/tmp', 2);
|
|
80
|
+
const answer = await handleAcpClientRequest(request, 4, 'session/request_permission', {
|
|
81
|
+
sessionId: 's1',
|
|
82
|
+
title: 'Run the tests?',
|
|
83
|
+
subject: { type: 'command', command: 'cargo test', cwd: '/repo' },
|
|
84
|
+
options: [{ optionId: 'allow', kind: 'allow_once' }, { optionId: 'deny', kind: 'reject_once' }],
|
|
85
|
+
});
|
|
86
|
+
expect(answer).toEqual({ answered: false, deferred: true });
|
|
87
|
+
expect(request.permissions.pendingDialogs()[0]).toMatchObject({
|
|
88
|
+
title: 'Run the tests?',
|
|
89
|
+
message: '$ cargo test',
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
});
|