@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
|
@@ -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
|
+
});
|
|
@@ -11,14 +11,19 @@
|
|
|
11
11
|
* auto-answer cannot disagree.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { answerPermissionRequest } from '@/server/lib/harness/acp/session-permissions';
|
|
15
|
-
import
|
|
14
|
+
import { answerPermissionRequest, cancelAcpPermission } from '@/server/lib/harness/acp/session-permissions';
|
|
15
|
+
import { handleAcpFsRequest, isAcpFsMethod } from '@/server/lib/harness/acp/client-fs';
|
|
16
|
+
import { ACP_ERROR } from '@/server/lib/harness/acp/protocol';
|
|
17
|
+
import { normalizePermissionParams } from '@/server/lib/harness/acp/v2';
|
|
18
|
+
import type { AcpId, AcpProtocolVersion } from '@/server/lib/harness/acp/protocol';
|
|
16
19
|
import type { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
17
20
|
import type { AgentEvent } from '@/server/lib/omp/rpc/constants';
|
|
18
21
|
import type { ApprovalMode } from '@/shared/lib/omp/config/access-mode';
|
|
19
22
|
|
|
20
23
|
export interface AcpClientRequestHost {
|
|
21
|
-
sessionId: string;
|
|
24
|
+
readonly sessionId: string;
|
|
25
|
+
readonly cwd: string;
|
|
26
|
+
readonly protocol: AcpProtocolVersion;
|
|
22
27
|
accessMode: ApprovalMode;
|
|
23
28
|
permissions: PendingPermissions;
|
|
24
29
|
emit: (event: AgentEvent) => void;
|
|
@@ -26,7 +31,7 @@ export interface AcpClientRequestHost {
|
|
|
26
31
|
|
|
27
32
|
export type AcpClientRequestAnswer =
|
|
28
33
|
| { answered: true; result: unknown }
|
|
29
|
-
| { answered: false; message: string }
|
|
34
|
+
| { answered: false; message: string; code?: number }
|
|
30
35
|
| { answered: false; deferred: true };
|
|
31
36
|
|
|
32
37
|
export function handleAcpClientRequest(
|
|
@@ -36,12 +41,49 @@ export function handleAcpClientRequest(
|
|
|
36
41
|
params: Record<string, unknown>,
|
|
37
42
|
): Promise<AcpClientRequestAnswer> {
|
|
38
43
|
if (method === 'session/request_permission') {
|
|
44
|
+
// v2 restructured this call: a required `title` and an optional `subject`
|
|
45
|
+
// replace the v1 `toolCall`. The approval queue keeps its v1 shape.
|
|
46
|
+
const normalized = host.protocol === 2 ? normalizePermissionParams(params) : params;
|
|
39
47
|
return answerPermissionRequest({
|
|
40
48
|
sessionId: host.sessionId,
|
|
41
49
|
accessMode: host.accessMode,
|
|
42
50
|
permissions: host.permissions,
|
|
43
51
|
emit: (event) => host.emit(event),
|
|
44
|
-
}, id,
|
|
52
|
+
}, id, normalized);
|
|
45
53
|
}
|
|
46
|
-
|
|
54
|
+
// The file surface the client advertised at `initialize`. Routed before the
|
|
55
|
+
// refusal so an agent that took the advertisement at its word gets an answer.
|
|
56
|
+
if (isAcpFsMethod(method)) return handleAcpFsRequest(host, method, params);
|
|
57
|
+
// `-32601`, not "internal error": the agent decides from the code whether this
|
|
58
|
+
// client simply lacks the method (Spec §Errors).
|
|
59
|
+
return Promise.resolve({
|
|
60
|
+
answered: false,
|
|
61
|
+
message: `Kabmo does not implement ${method}`,
|
|
62
|
+
code: ACP_ERROR.methodNotFound,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The host a cancellation notification needs; `AcpSession` satisfies it. */
|
|
67
|
+
export interface AcpCancelHost {
|
|
68
|
+
readonly permissions: PendingPermissions;
|
|
69
|
+
respond(id: AcpId, result: unknown): void;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Handle `$/cancel_request` — the agent withdrawing a request it made on this
|
|
74
|
+
* client. The only long-lived one Kabmo parks is an approval, and ACP requires
|
|
75
|
+
* the `cancelled` outcome for it. Returns false for a different method so the
|
|
76
|
+
* caller keeps routing.
|
|
77
|
+
*/
|
|
78
|
+
export function handleAcpCancelRequest(
|
|
79
|
+
host: AcpCancelHost,
|
|
80
|
+
method: string,
|
|
81
|
+
params: Record<string, unknown>,
|
|
82
|
+
): boolean {
|
|
83
|
+
if (method !== '$/cancel_request') return false;
|
|
84
|
+
const requestId = params.requestId;
|
|
85
|
+
if (typeof requestId === 'string' || typeof requestId === 'number') {
|
|
86
|
+
cancelAcpPermission(host.permissions, host, requestId);
|
|
87
|
+
}
|
|
88
|
+
return true;
|
|
47
89
|
}
|
|
@@ -53,7 +53,7 @@ export interface AcpTurnTarget {
|
|
|
53
53
|
totalCost: number;
|
|
54
54
|
runModel: { provider: string; modelId: string } | null;
|
|
55
55
|
/** The durable run marker; a field on the session so a test can stub it. */
|
|
56
|
-
markStream: (status: 'stream' | 'finish' | 'abort') => void;
|
|
56
|
+
markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void;
|
|
57
57
|
isAlive(): boolean;
|
|
58
58
|
isBusy(): boolean;
|
|
59
59
|
send(command: Record<string, unknown>): Promise<unknown>;
|
|
@@ -86,8 +86,13 @@ export function settleAcpTurn(target: AcpTurnTarget, info: AcpTurnEndInfo): void
|
|
|
86
86
|
totalCost: target.totalCost,
|
|
87
87
|
runModel: target.runModel,
|
|
88
88
|
});
|
|
89
|
-
// A cancelled turn is an `abort` badge
|
|
90
|
-
|
|
89
|
+
// A cancelled turn is an `abort` badge; every other ending a `finish` — and a
|
|
90
|
+
// failed turn carries the agent's own reason, which is the only copy a tab
|
|
91
|
+
// that never opened the session can read.
|
|
92
|
+
const failure = info.failed === true
|
|
93
|
+
? (info.failure?.trim() || 'The agent ended the turn without an answer')
|
|
94
|
+
: null;
|
|
95
|
+
target.markStream(info.stopReason === 'cancelled' ? 'abort' : 'finish', failure);
|
|
91
96
|
// Todo/plan/telemetry panels read their own topics; without this signal an
|
|
92
97
|
// ACP turn's usage and titles never republished (the RPC settle path does it).
|
|
93
98
|
emitRealtimeSignal('session-data-dirty', target.sessionId);
|
|
@@ -42,6 +42,10 @@ export class AcpUsageMeter {
|
|
|
42
42
|
this.turnPeak = Math.max(this.turnPeak, used);
|
|
43
43
|
}
|
|
44
44
|
const cost = update.cost;
|
|
45
|
+
if (cost === null) {
|
|
46
|
+
this.totalCost = 0;
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
45
49
|
if (cost && typeof cost === 'object' && 'amount' in cost && typeof cost.amount === 'number') {
|
|
46
50
|
this.totalCost = cost.amount;
|
|
47
51
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
import { configOption, modelFromOption } from '@/server/lib/harness/acp/prompt';
|
|
23
|
-
import type { AcpConfigOption } from '@/server/lib/harness/acp/protocol';
|
|
23
|
+
import type { AcpConfigOption, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
24
24
|
import type { HarnessId } from '@/shared/lib/harness/catalog';
|
|
25
25
|
|
|
26
26
|
export interface AcpStateView {
|
|
@@ -34,9 +34,34 @@ export interface AcpStateView {
|
|
|
34
34
|
totalCost: number;
|
|
35
35
|
runModel: { provider: string; modelId: string } | null;
|
|
36
36
|
configOptions: AcpConfigOption[];
|
|
37
|
+
/** The older Session Modes API, when the agent published no selector. */
|
|
38
|
+
modes: AcpSessionModeState | null;
|
|
37
39
|
harness: HarnessId;
|
|
38
40
|
}
|
|
39
41
|
|
|
42
|
+
/**
|
|
43
|
+
* The agent's legacy mode list as the selector every Kabmo consumer already
|
|
44
|
+
* reads. `applyHarnessMode` and the composer look for a `category: "mode"`
|
|
45
|
+
* config option; without this an agent that only speaks `modes` had no Plan
|
|
46
|
+
* control at all. Writing the synthesized id routes back to `session/set_mode`
|
|
47
|
+
* in `AcpSession.setConfig`.
|
|
48
|
+
*/
|
|
49
|
+
function modeSelector(modes: AcpSessionModeState | null): AcpConfigOption[] {
|
|
50
|
+
if (!modes) return [];
|
|
51
|
+
return [{
|
|
52
|
+
id: 'mode',
|
|
53
|
+
name: 'Session Mode',
|
|
54
|
+
category: 'mode',
|
|
55
|
+
type: 'select',
|
|
56
|
+
currentValue: modes.currentModeId,
|
|
57
|
+
options: modes.availableModes.map((entry) => ({
|
|
58
|
+
value: entry.id,
|
|
59
|
+
name: entry.name,
|
|
60
|
+
...(entry.description ? { description: entry.description } : {}),
|
|
61
|
+
})),
|
|
62
|
+
}];
|
|
63
|
+
}
|
|
64
|
+
|
|
40
65
|
export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
41
66
|
const thinking = configOption(view.configOptions, 'thought_level');
|
|
42
67
|
// The run's model is seeded at `start()` and refreshed by every config write,
|
|
@@ -44,6 +69,9 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
|
44
69
|
// must report, since an alias or a fallback can differ from the request. The
|
|
45
70
|
// fallback exists only for a session whose selector list never carried a model.
|
|
46
71
|
const serving = view.runModel ?? modelFromOption(configOption(view.configOptions, 'model'), view.harness);
|
|
72
|
+
const configOptions = configOption(view.configOptions, 'mode')
|
|
73
|
+
? view.configOptions
|
|
74
|
+
: [...view.configOptions, ...modeSelector(view.modes)];
|
|
47
75
|
return {
|
|
48
76
|
sessionId: view.sessionId,
|
|
49
77
|
isStreaming: view.isStreaming,
|
|
@@ -56,6 +84,6 @@ export function acpWebState(view: AcpStateView): Record<string, unknown> {
|
|
|
56
84
|
totalCost: view.totalCost,
|
|
57
85
|
model: serving ? { id: serving.modelId, provider: serving.provider } : undefined,
|
|
58
86
|
thinkingLevel: typeof thinking?.currentValue === 'string' ? thinking.currentValue : undefined,
|
|
59
|
-
configOptions
|
|
87
|
+
configOptions,
|
|
60
88
|
};
|
|
61
89
|
}
|
|
@@ -47,6 +47,12 @@ export interface MountedSession {
|
|
|
47
47
|
turnEnds: () => number;
|
|
48
48
|
/** The durable run markers written for this session, in order. */
|
|
49
49
|
streamMarks: () => string[];
|
|
50
|
+
/** The `failure` argument written with each marker, in the same order. */
|
|
51
|
+
streamMarkFailures: () => Array<string | null>;
|
|
52
|
+
/** Results the session answered an agent→client request with. */
|
|
53
|
+
permissionAnswers: () => { id: unknown; result: unknown }[];
|
|
54
|
+
/** Session ids the session asked the agent to delete. */
|
|
55
|
+
deletedSessions: () => string[];
|
|
50
56
|
/** How many times a command or frame deferred the idle reclaim. */
|
|
51
57
|
idleResets: () => number;
|
|
52
58
|
/** Whether a destroy stopped the reclaim clock. */
|
|
@@ -106,6 +112,11 @@ export function mountSession(): MountedSession {
|
|
|
106
112
|
// A config write; the default reply omits the list, which is the shape a
|
|
107
113
|
// harness that ignores the protocol's "complete list" rule returns.
|
|
108
114
|
setConfigOption: async (_sessionId: string, _configId: string, _value: string | boolean) => ({}),
|
|
115
|
+
deleteSession: async (sessionId: string) => {
|
|
116
|
+
deletes.push(sessionId);
|
|
117
|
+
return {};
|
|
118
|
+
},
|
|
119
|
+
respond: (id: string | number, result: unknown) => answers.push({ id, result }),
|
|
109
120
|
dispose: async () => {},
|
|
110
121
|
isAlive: true,
|
|
111
122
|
};
|
|
@@ -124,6 +135,9 @@ export function mountSession(): MountedSession {
|
|
|
124
135
|
},
|
|
125
136
|
});
|
|
126
137
|
const marks: string[] = [];
|
|
138
|
+
const markFailures: Array<string | null> = [];
|
|
139
|
+
const answers: { id: unknown; result: unknown }[] = [];
|
|
140
|
+
const deletes: string[] = [];
|
|
127
141
|
const eventSink = new SessionListeners();
|
|
128
142
|
eventSink.add((event) => events.push(event));
|
|
129
143
|
let background: BackgroundProbeStub = {
|
|
@@ -132,8 +146,9 @@ export function mountSession(): MountedSession {
|
|
|
132
146
|
consume: () => false,
|
|
133
147
|
};
|
|
134
148
|
Object.assign(session as unknown as Record<string, unknown>, {
|
|
135
|
-
markStream: (status: string) => {
|
|
149
|
+
markStream: (status: string, failure?: string | null) => {
|
|
136
150
|
marks.push(status);
|
|
151
|
+
markFailures.push(failure ?? null);
|
|
137
152
|
},
|
|
138
153
|
harness: 'opencode',
|
|
139
154
|
cwd: '/tmp',
|
|
@@ -163,6 +178,9 @@ export function mountSession(): MountedSession {
|
|
|
163
178
|
turn,
|
|
164
179
|
turnEnds: () => turnEndCount,
|
|
165
180
|
streamMarks: () => marks,
|
|
181
|
+
streamMarkFailures: () => markFailures,
|
|
182
|
+
permissionAnswers: () => answers,
|
|
183
|
+
deletedSessions: () => deletes,
|
|
166
184
|
idleResets: () => idleResets,
|
|
167
185
|
idleStopped: () => idleStopped,
|
|
168
186
|
setBackground: (probe) => {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
import { AcpProcess } from '@/server/lib/harness/acp/client';
|
|
24
24
|
import { AcpTurns, type AcpTurnEndInfo } from '@/server/lib/harness/acp/turn';
|
|
25
25
|
import { AcpFrameMapper } from '@/server/lib/harness/acp/frames';
|
|
26
|
-
import type { AcpConfigOption, AcpId } from '@/server/lib/harness/acp/protocol';
|
|
26
|
+
import type { AcpConfigOption, AcpId, AcpProtocolVersion, AcpSessionModeState } from '@/server/lib/harness/acp/protocol';
|
|
27
27
|
import { promptBlocks } from '@/server/lib/harness/acp/prompt';
|
|
28
28
|
import { withGatewayCompatibility } from '@/server/lib/harness/acp/gateway-env';
|
|
29
29
|
import { adoptConfigAnswer, publishConfigChange, settlePermissionDialog, stampMessageModel } from '@/server/lib/harness/acp/session-config';
|
|
@@ -32,9 +32,10 @@ import { driveAcpGoalAfterTurn } from '@/server/lib/harness/acp/acp-goal-driver.
|
|
|
32
32
|
import { handshakeAcpSession } from '@/server/lib/harness/acp/session-handshake';
|
|
33
33
|
import { capabilitiesFrom } from '@/server/lib/harness/launch';
|
|
34
34
|
import { PendingPermissions } from '@/server/lib/harness/acp/permissions';
|
|
35
|
+
import { cancelAllAcpPermissions } from '@/server/lib/harness/acp/session-permissions';
|
|
35
36
|
import { handleSessionNotification } from '@/server/lib/harness/acp/session-notifications';
|
|
36
37
|
import { AcpUsageMeter, type AcpContextUsage } from '@/server/lib/harness/acp/session-usage';
|
|
37
|
-
import { handleAcpClientRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
|
|
38
|
+
import { handleAcpClientRequest, handleAcpCancelRequest, type AcpClientRequestAnswer } from '@/server/lib/harness/acp/session-requests';
|
|
38
39
|
import { acpExitFailureFrames } from '@/server/lib/harness/acp/session-exit';
|
|
39
40
|
import { SessionListeners } from '@/server/lib/harness/acp/session-listeners';
|
|
40
41
|
import {
|
|
@@ -64,13 +65,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
64
65
|
/** The turn in flight — the only one whose frames are accepted. */
|
|
65
66
|
private readonly turns: AcpTurns;
|
|
66
67
|
runModel: { provider: string; modelId: string } | null = null;
|
|
67
|
-
/** The agent's own slash-command list
|
|
68
|
-
* composer's `/` pool reads it for this session (omp's utility child answers
|
|
69
|
-
* that question for the RPC transport). */
|
|
68
|
+
/** The agent's own slash-command list; the composer's `/` pool reads it. */
|
|
70
69
|
agentCommands: { name: string; description?: string; inputHint?: string }[] = [];
|
|
71
|
-
/** The agent's plan entries
|
|
72
|
-
* Todos panel renders them through the same payload omp's transcript
|
|
73
|
-
* snapshot produces. */
|
|
70
|
+
/** The agent's plan entries, published for the Todos panel. */
|
|
74
71
|
planEntries: unknown[] = [];
|
|
75
72
|
/** Messages this session has moved: prompts sent plus assistant messages the
|
|
76
73
|
* mapper closed. omp reports the same quantity from its transcript. */
|
|
@@ -81,22 +78,17 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
81
78
|
assistantCount = 0;
|
|
82
79
|
/** The last `usage_update` the agent reported, or null when it never did. */
|
|
83
80
|
private readonly usage = new AcpUsageMeter();
|
|
84
|
-
|
|
85
|
-
get
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get totalCost(): number {
|
|
90
|
-
return this.usage.totalCost;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get usageTokens(): number {
|
|
94
|
-
return this.usage.usageTokens;
|
|
95
|
-
}
|
|
81
|
+
get contextUsage(): AcpContextUsage | null { return this.usage.contextUsage; }
|
|
82
|
+
get totalCost(): number { return this.usage.totalCost; }
|
|
83
|
+
get usageTokens(): number { return this.usage.usageTokens; }
|
|
96
84
|
/** The composer's approval tier. Answered in-process by {@link onClientRequest}. */
|
|
97
85
|
accessMode: ApprovalMode = DEFAULT_APPROVAL_MODE;
|
|
98
86
|
capabilities: HarnessCapabilities = capabilitiesFrom({ protocolVersion: 1 }, [], { usage: false, plan: false });
|
|
99
87
|
configOptions: AcpConfigOption[] = [];
|
|
88
|
+
/** The older Session Modes API, adopted when the agent publishes one. */
|
|
89
|
+
modes: AcpSessionModeState | null = null;
|
|
90
|
+
/** Whether the agent advertised `promptCapabilities.image`. */
|
|
91
|
+
acceptsImages = false;
|
|
100
92
|
private readonly proc: AcpProcess;
|
|
101
93
|
/** The quiet-window reclaim; the rules live in `session-idle.ts`. */
|
|
102
94
|
readonly idle: IdleReaper;
|
|
@@ -107,9 +99,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
107
99
|
readonly permissions = new PendingPermissions();
|
|
108
100
|
private destroyHook: (() => void) | null = null;
|
|
109
101
|
private destroyed = false;
|
|
110
|
-
/** Set when Kabmo
|
|
111
|
-
* as an agent failure. `force_reset` is the Stop button's escalation, and the
|
|
112
|
-
* user must not get an "agent exited" error for a stop they asked for. */
|
|
102
|
+
/** Set when Kabmo ends the process, so a requested stop is not reported as a failure. */
|
|
113
103
|
private closing = false;
|
|
114
104
|
|
|
115
105
|
constructor(options: AcpSessionOptions, cwd: string) {
|
|
@@ -173,33 +163,16 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
173
163
|
return { sessionId: this.sessionId };
|
|
174
164
|
}
|
|
175
165
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
get isStreaming(): boolean {
|
|
181
|
-
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
isRunning(): boolean {
|
|
189
|
-
return this.isAlive() && (this.turns.isPromptRunning || this.turns.isStreaming);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
isBusy(): boolean {
|
|
193
|
-
return this.isRunning() || this.permissions.size() > 0;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
onEvent(listener: (event: AgentEvent) => void): () => void {
|
|
197
|
-
return this.events.add(listener);
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
emit(event: AgentEvent): void {
|
|
201
|
-
this.events.emit(event);
|
|
202
|
-
}
|
|
166
|
+
get protocol(): AcpProtocolVersion { return this.proc.protocolVersion === 2 ? 2 : 1; }
|
|
167
|
+
/** Set by the handshake as soon as `initialize` answers. */
|
|
168
|
+
onProtocol(version: AcpProtocolVersion): void { this.turns.completion = version === 2 ? 'state' : 'response'; }
|
|
169
|
+
isAlive(): boolean { return !this.destroyed && this.proc.isAlive; }
|
|
170
|
+
get isStreaming(): boolean { return this.turns.isStreaming; }
|
|
171
|
+
get isPromptRunning(): boolean { return this.turns.isPromptRunning; }
|
|
172
|
+
isRunning(): boolean { return this.isAlive() && (this.turns.isPromptRunning || this.turns.isStreaming); }
|
|
173
|
+
isBusy(): boolean { return this.isRunning() || this.permissions.size() > 0; }
|
|
174
|
+
onEvent(listener: (event: AgentEvent) => void): () => void { return this.events.add(listener); }
|
|
175
|
+
emit(event: AgentEvent): void { this.events.emit(event); }
|
|
203
176
|
|
|
204
177
|
getPendingUiDialogs(): Record<string, unknown>[] {
|
|
205
178
|
// Widened for the shared `HarnessSession` contract, which predates the
|
|
@@ -232,9 +205,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
232
205
|
* spinner and a reattaching tab's "still running" answer read. A field so a
|
|
233
206
|
* unit test can stub it: the default writes the same row omp's dispatch writes.
|
|
234
207
|
*/
|
|
235
|
-
markStream: (status: 'stream' | 'finish' | 'abort') => void = (status) => {
|
|
208
|
+
markStream: (status: 'stream' | 'finish' | 'abort', failure?: string | null) => void = (status, failure) => {
|
|
236
209
|
if (!this.sessionId) return;
|
|
237
|
-
void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined).catch(() => {});
|
|
210
|
+
void markStreamStatus(this.sessionId, status, status === 'stream' ? this.runModel : undefined, failure).catch(() => {});
|
|
238
211
|
};
|
|
239
212
|
|
|
240
213
|
/** Turn-end bookkeeping the panels read — see `session-turns.ts`. A cancelled
|
|
@@ -253,10 +226,11 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
253
226
|
void driveAcpGoalAfterTurn(this, info.message, { cancelled: info.cancelled === true }).catch(() => {});
|
|
254
227
|
}
|
|
255
228
|
|
|
256
|
-
/** Dispatcher seam: stop the turn
|
|
229
|
+
/** Dispatcher seam: stop the turn and answer every parked approval. */
|
|
257
230
|
cancelTurn(): void {
|
|
258
231
|
this.background.stop();
|
|
259
232
|
this.turns.cancel();
|
|
233
|
+
cancelAllAcpPermissions(this.permissions, this.proc);
|
|
260
234
|
}
|
|
261
235
|
|
|
262
236
|
/** Dispatcher seam: adopt the composer's access pick. ACP answers approvals
|
|
@@ -268,12 +242,25 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
268
242
|
/** Dispatcher seam: write one config selector and adopt the answer — see
|
|
269
243
|
* `session-config.ts` for why the AGENT's resolved value is what is kept. */
|
|
270
244
|
async setConfig(configId: string, value: string | boolean): Promise<unknown> {
|
|
245
|
+
// The synthesized selector `webState()` publishes for an agent that speaks
|
|
246
|
+
// only `modes`; there is no config option to write, so the mode verb is.
|
|
247
|
+
if (configId === 'mode' && typeof value === 'string' && !this.configOptions.some((option) => option.id === 'mode') && this.modes) {
|
|
248
|
+
return this.setMode(value);
|
|
249
|
+
}
|
|
271
250
|
const result = await this.proc.setConfigOption(this.sessionId, configId, value);
|
|
272
251
|
adoptConfigAnswer(this, result, { configId, value });
|
|
273
252
|
publishConfigChange(this, configId);
|
|
274
253
|
return result;
|
|
275
254
|
}
|
|
276
255
|
|
|
256
|
+
/** `session/set_mode`: the pre-config-options way to move a mode. */
|
|
257
|
+
async setMode(modeId: string): Promise<unknown> {
|
|
258
|
+
const result = await this.proc.setMode(this.sessionId, modeId);
|
|
259
|
+
if (this.modes) this.modes = { ...this.modes, currentModeId: modeId };
|
|
260
|
+
this.emit({ type: 'mode_changed', modeId });
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
|
|
277
264
|
/** Dispatcher seam: answer a pending approval dialog. Every exit answers the
|
|
278
265
|
* agent — a silent return would hang it (see `session-config.ts`). */
|
|
279
266
|
resolvePermission(dialogId: string, confirmed: boolean): unknown {
|
|
@@ -281,9 +268,7 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
281
268
|
return null;
|
|
282
269
|
}
|
|
283
270
|
|
|
284
|
-
webState(): Record<string, unknown> {
|
|
285
|
-
return acpWebState(this);
|
|
286
|
-
}
|
|
271
|
+
webState(): Record<string, unknown> { return acpWebState(this); }
|
|
287
272
|
|
|
288
273
|
/** Run one turn. The promise IS the turn: ACP resolves `session/prompt` when
|
|
289
274
|
* the agent is done, so the reply is awaited for its whole duration. The ACK,
|
|
@@ -291,6 +276,11 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
291
276
|
* `session-turns.ts`.
|
|
292
277
|
*/
|
|
293
278
|
startTurn(message: string, images: unknown): unknown {
|
|
279
|
+
// ACP's prompt capabilities are a MUST: an agent that did not advertise
|
|
280
|
+
// `image` has to be told, not sent blocks its dispatcher rejects.
|
|
281
|
+
if (!this.acceptsImages && Array.isArray(images) && images.length > 0) {
|
|
282
|
+
throw new Error(`This harness does not accept image attachments (${this.harness})`);
|
|
283
|
+
}
|
|
294
284
|
// A new prompt is the next request, so the agent flushes any held update
|
|
295
285
|
// itself; a probe would duplicate it.
|
|
296
286
|
this.background.stop();
|
|
@@ -302,6 +292,9 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
302
292
|
private onNotification(method: string, params: Record<string, unknown>): void {
|
|
303
293
|
// A long turn emits no commands but plenty of `session/update` frames.
|
|
304
294
|
this.idle.reset();
|
|
295
|
+
// `$/cancel_request` names an agent→client request the agent no longer
|
|
296
|
+
// wants; the approval it parks is answered `cancelled`.
|
|
297
|
+
if (handleAcpCancelRequest(this, method, params)) return;
|
|
305
298
|
// A `session/load` replay repeats the whole chat; leave it to the probe.
|
|
306
299
|
if (this.background.consume(method, params)) return;
|
|
307
300
|
handleSessionNotification(this, method, params);
|
|
@@ -310,9 +303,10 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
310
303
|
absorbUsage(update: Record<string, unknown>): void { this.usage.absorb(update); }
|
|
311
304
|
resetUsageTokens(): void { this.usage.reset(); }
|
|
312
305
|
acceptingFrames(): boolean { return this.turns.acceptingFrames(); }
|
|
313
|
-
|
|
314
306
|
mapUpdate(update: Record<string, unknown>): AgentEvent[] { return this.mapper.mapUpdate(update); }
|
|
315
|
-
|
|
307
|
+
onStateUpdate(update: Record<string, unknown>): void { this.turns.onStateUpdate(update); }
|
|
308
|
+
/** Answer an agent→client request with a result (cancellation uses it). */
|
|
309
|
+
respond(id: AcpId, result: unknown): void { this.proc.respond(id, result); }
|
|
316
310
|
/** Agent→client requests: every branch answers or refuses — an unanswered call parks the turn. */
|
|
317
311
|
private onClientRequest(
|
|
318
312
|
id: AcpId,
|
|
@@ -333,8 +327,14 @@ export class AcpSession implements HarnessSession, AcpCommandHost {
|
|
|
333
327
|
this.destroyHook?.();
|
|
334
328
|
}
|
|
335
329
|
|
|
336
|
-
destroy(): void {
|
|
337
|
-
|
|
330
|
+
destroy(): void { void this.destroyAndWait(); }
|
|
331
|
+
|
|
332
|
+
/** Remove this chat from the agent's own history, when it offers the method. */
|
|
333
|
+
async deleteAgentSession(): Promise<void> {
|
|
334
|
+
if (!this.sessionId || !this.capabilities.deleteSession) return;
|
|
335
|
+
await this.proc.deleteSession(this.sessionId, 10_000).catch((error: unknown) => {
|
|
336
|
+
console.error(`[harness] could not delete ${this.harness} session ${this.sessionId}:`, error);
|
|
337
|
+
});
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
async destroyAndWait(): Promise<void> {
|