@agentclientprotocol/claude-agent-acp 0.102.1-preview.2 → 0.102.1-preview.3
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/acp-agent.d.ts +14 -217
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +18 -1076
- package/dist/acp-client.d.ts +28 -0
- package/dist/acp-client.d.ts.map +1 -0
- package/dist/acp-client.js +1 -0
- package/dist/lib.d.ts +5 -1
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +3 -1
- package/dist/logger.d.ts +10 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +1 -0
- package/dist/message-filters.d.ts +43 -0
- package/dist/message-filters.d.ts.map +1 -0
- package/dist/message-filters.js +197 -0
- package/dist/new-session-meta.d.ts +40 -0
- package/dist/new-session-meta.d.ts.map +1 -0
- package/dist/new-session-meta.js +1 -0
- package/dist/prompt-to-claude.d.ts +10 -0
- package/dist/prompt-to-claude.d.ts.map +1 -0
- package/dist/prompt-to-claude.js +120 -0
- package/dist/result-end.d.ts +33 -4
- package/dist/result-end.d.ts.map +1 -1
- package/dist/result-end.js +34 -0
- package/dist/sdk-to-acp.d.ts +93 -0
- package/dist/sdk-to-acp.d.ts.map +1 -0
- package/dist/sdk-to-acp.js +635 -0
- package/dist/serve.d.ts +2 -1
- package/dist/serve.d.ts.map +1 -1
- package/dist/session-index/connection.d.ts +3 -1
- package/dist/session-index/connection.d.ts.map +1 -1
- package/dist/slash-commands.d.ts +10 -0
- package/dist/slash-commands.d.ts.map +1 -0
- package/dist/slash-commands.js +99 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/v2/agent.d.ts +1 -1
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +1 -1
- package/dist/v2/auth.d.ts +1 -1
- package/dist/v2/auth.d.ts.map +1 -1
- package/dist/v2/commands.js +1 -1
- package/dist/v2/config.d.ts +1 -1
- package/dist/v2/config.d.ts.map +1 -1
- package/dist/v2/elicitation.d.ts +1 -1
- package/dist/v2/elicitation.d.ts.map +1 -1
- package/dist/v2/file-preview.d.ts +1 -1
- package/dist/v2/file-preview.d.ts.map +1 -1
- package/dist/v2/outcome.d.ts.map +1 -1
- package/dist/v2/outcome.js +2 -1
- package/dist/v2/remote-control.d.ts +1 -1
- package/dist/v2/remote-control.d.ts.map +1 -1
- package/dist/v2/reports.d.ts +1 -1
- package/dist/v2/reports.d.ts.map +1 -1
- package/dist/v2/restarts.d.ts +1 -1
- package/dist/v2/restarts.d.ts.map +1 -1
- package/dist/v2/session.d.ts +1 -1
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +2 -1
- package/dist/v2/setup.d.ts +1 -1
- package/dist/v2/setup.d.ts.map +1 -1
- package/dist/v2/stopped-work.js +1 -1
- package/dist/v2/stream.d.ts +3 -2
- package/dist/v2/stream.d.ts.map +1 -1
- package/dist/v2/stream.js +2 -1
- package/dist/v2/subagent-replay.d.ts +1 -1
- package/dist/v2/subagent-replay.d.ts.map +1 -1
- package/dist/v2/subscription-guard.d.ts +1 -1
- package/dist/v2/subscription-guard.d.ts.map +1 -1
- package/dist/v2/tasks.d.ts +1 -1
- package/dist/v2/tasks.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CompleteElicitationNotification, CreateElicitationRequest, CreateElicitationResponse, ReadTextFileRequest, ReadTextFileResponse, RequestPermissionResponse, WriteTextFileRequest, WriteTextFileResponse } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
import type { AcpSessionNotification } from "./acp-subagents.js";
|
|
3
|
+
import type { AcpPermissionRequest } from "./permissions/presentation.js";
|
|
4
|
+
/**
|
|
5
|
+
* Client-facing surface the agent calls back into. This is the subset of ACP
|
|
6
|
+
* client methods the agent actually uses, expressed as a narrow interface so
|
|
7
|
+
* tests can supply lightweight mocks. In the v1 agent it is backed by
|
|
8
|
+
* `ClientConnection` (`acp-agent.ts`) over the SDK's typed `AgentContext`.
|
|
9
|
+
* The v2 session output passes one that only takes `sessionUpdate`
|
|
10
|
+
* (`v2/stream.ts`).
|
|
11
|
+
*/
|
|
12
|
+
export interface AcpClient {
|
|
13
|
+
sessionUpdate(params: AcpSessionNotification): Promise<void>;
|
|
14
|
+
/** `signal`, when aborted, sends `$/cancel_request` for the in-flight
|
|
15
|
+
* permission request so the client can dismiss its prompt, and rejects the
|
|
16
|
+
* call at once: a client that ignores the cancel never answers. */
|
|
17
|
+
requestPermission(params: AcpPermissionRequest, signal?: AbortSignal): Promise<RequestPermissionResponse>;
|
|
18
|
+
readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
|
|
19
|
+
writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
|
|
20
|
+
/** `signal`, when aborted, sends `$/cancel_request` for the in-flight
|
|
21
|
+
* elicitation so the client can dismiss its prompt, and rejects the call
|
|
22
|
+
* at once, as {@link requestPermission} does. */
|
|
23
|
+
createElicitation(params: CreateElicitationRequest, signal?: AbortSignal): Promise<CreateElicitationResponse>;
|
|
24
|
+
completeElicitation(params: CompleteElicitationNotification): Promise<void>;
|
|
25
|
+
/** Send a custom (extension) notification, e.g. `_claude/sdkMessage`. */
|
|
26
|
+
extNotification(method: string, params: Record<string, unknown>): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=acp-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-client.d.ts","sourceRoot":"","sources":["../src/acp-client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,+BAA+B,EAC/B,wBAAwB,EACxB,yBAAyB,EACzB,mBAAmB,EACnB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAE1E;;;;;;;GAOG;AACH,MAAM,WAAW,SAAS;IACxB,aAAa,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D;;wEAEoE;IACpE,iBAAiB,CACf,MAAM,EAAE,oBAAoB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACtC,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACzE,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAC5E;;sDAEkD;IAClD,iBAAiB,CACf,MAAM,EAAE,wBAAwB,EAChC,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,yBAAyB,CAAC,CAAC;IACtC,mBAAmB,CAAC,MAAM,EAAE,+BAA+B,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5E,yEAAyE;IACzE,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export { ClaudeAcpAgent,
|
|
1
|
+
export { ClaudeAcpAgent, runAcp } from "./acp-agent.js";
|
|
2
|
+
export { isLocalCommandMetadata, stripLocalCommandMetadata } from "./message-filters.js";
|
|
3
|
+
export { toAcpNotifications, streamEventToAcpNotifications } from "./sdk-to-acp.js";
|
|
4
|
+
export type { NewSessionMeta, SDKMessageFilter } from "./new-session-meta.js";
|
|
5
|
+
export type { ToolUpdateMeta } from "./tool-calls/renderer.js";
|
|
2
6
|
export { nodeToWebReadable, nodeToWebWritable, Pushable, unreachable } from "./utils.js";
|
|
3
7
|
export { toolInfoFromToolUse, toDisplayPath, planEntries, toolUpdateFromToolResult, } from "./tools.js";
|
|
4
8
|
export { SettingsManager, type SettingsManagerOptions } from "./settings.js";
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACzF,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,MAAM,iBAAiB,CAAC;AACpF,YAAY,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAC9E,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,wBAAwB,GACzB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,KAAK,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAG7E,OAAO,EACL,yBAAyB,EACzB,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,4BAA4B,GAClC,MAAM,kBAAkB,CAAC;AAG1B,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/lib.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Export the main agent class and utilities for library usage
|
|
2
|
-
export { ClaudeAcpAgent,
|
|
2
|
+
export { ClaudeAcpAgent, runAcp } from "./acp-agent.js";
|
|
3
|
+
export { isLocalCommandMetadata, stripLocalCommandMetadata } from "./message-filters.js";
|
|
4
|
+
export { toAcpNotifications, streamEventToAcpNotifications } from "./sdk-to-acp.js";
|
|
3
5
|
export { nodeToWebReadable, nodeToWebWritable, Pushable, unreachable } from "./utils.js";
|
|
4
6
|
export { toolInfoFromToolUse, toDisplayPath, planEntries, toolUpdateFromToolResult, } from "./tools.js";
|
|
5
7
|
export { SettingsManager } from "./settings.js";
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger interface for customizing logging output
|
|
3
|
+
*/
|
|
4
|
+
export interface Logger {
|
|
5
|
+
log: (...args: any[]) => void;
|
|
6
|
+
error: (...args: any[]) => void;
|
|
7
|
+
/** Optional: a caller that supplies no `warn` gets its warnings on `error`. */
|
|
8
|
+
warn?: (...args: any[]) => void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAChC,+EAA+E;IAC/E,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const LOCAL_ONLY_COMMANDS: Set<string>;
|
|
2
|
+
/**
|
|
3
|
+
* Return user-message content with local-command and injected-context marker
|
|
4
|
+
* tags removed, or `null` if nothing meaningful remains (caller should skip
|
|
5
|
+
* the message). Preserves real prose that's mixed in alongside the markers —
|
|
6
|
+
* e.g. a message like `<command-name>…</command-name>hi` becomes `hi`, and
|
|
7
|
+
* `hi<system-reminder>…</system-reminder>` becomes `hi`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stripLocalCommandMetadata(content: unknown): unknown | null;
|
|
10
|
+
export declare function isLocalCommandMetadata(content: unknown): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* True for the synthetic assistant message the CLI injects into the transcript
|
|
13
|
+
* when a turn fails authentication (e.g. "Not logged in · Please run /login",
|
|
14
|
+
* "Session expired. Please run /login to sign in again."). The `/login`
|
|
15
|
+
* instruction is Claude Code TUI-specific and meaningless to ACP clients
|
|
16
|
+
* (issue #863). The live prompt loop suppresses the text and fails the turn
|
|
17
|
+
* with `authRequired` so the client can run its own auth flow; replay must
|
|
18
|
+
* skip it too — both for parity with what the client saw live and because the
|
|
19
|
+
* message stays in the transcript forever, so it would resurface on every
|
|
20
|
+
* session/load even after the user has logged back in.
|
|
21
|
+
*
|
|
22
|
+
* Takes the API message (`message.message`), which replay only knows as
|
|
23
|
+
* `unknown`. The persisted record's structured `error` marker is stripped by
|
|
24
|
+
* `getSessionMessages`, and the CLI does not always set it to
|
|
25
|
+
* `authentication_failed` anyway: an expired login with no refresh token
|
|
26
|
+
* ("Login expired · Run /login to sign in again, …") arrives as
|
|
27
|
+
* `invalid_request`. So the synthetic model + text is what both paths match on.
|
|
28
|
+
* Usage-limit banners are excluded because some of them also mention `/login`
|
|
29
|
+
* (to switch accounts) and have their own handling.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSyntheticLoginMessage(apiMessage: unknown): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* True for a transcript message delivered to the model from another agent,
|
|
34
|
+
* session or channel. Since SDK 0.3.284 `getSessionMessages` returns these as
|
|
35
|
+
* `is_meta` user messages whose content is the full harness framing (envelope
|
|
36
|
+
* XML plus the "not typed by your user" preamble). The live prompt loop never
|
|
37
|
+
* renders them, so replay skips them too rather than presenting them as text
|
|
38
|
+
* the user typed. Other `is_meta` messages (compact summaries) are kept.
|
|
39
|
+
*
|
|
40
|
+
* `is_meta` and `origin` are runtime fields not declared on `SessionMessage`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isReplayHiddenMetaMessage(message: unknown): boolean;
|
|
43
|
+
//# sourceMappingURL=message-filters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-filters.d.ts","sourceRoot":"","sources":["../src/message-filters.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,mBAAmB,aAAqD,CAAC;AA+FtF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAyB1E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEhE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAgBpE;AAYD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAanE"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Claude Code messages and content that a client never sees as the user's
|
|
3
|
+
* or the agent's text: local slash command markers, context the CLI injects,
|
|
4
|
+
* the synthetic `/login` message and meta messages from other agents. The live
|
|
5
|
+
* stream and the `session/load` replay both filter with these.
|
|
6
|
+
*/
|
|
7
|
+
import { isLoginRequiredText } from "./result-end.js";
|
|
8
|
+
import { isSyntheticUsageLimitMessage } from "./session-failure-extension.js";
|
|
9
|
+
import { markerTagText, TASK_NOTIFICATION_TAG } from "./task-notifications.js";
|
|
10
|
+
// Slash commands that the SDK handles locally without replaying the user
|
|
11
|
+
// message and without invoking the model.
|
|
12
|
+
export const LOCAL_ONLY_COMMANDS = new Set(["/context", "/heapdump", "/extra-usage"]);
|
|
13
|
+
// Commands whose marker-only transcript records are ACP/client-local UI noise,
|
|
14
|
+
// not model-visible user prompts. Marker-only custom slash skills are not in
|
|
15
|
+
// this list, so replay can reconstruct them from `<command-name>`/`<command-args>`.
|
|
16
|
+
const REPLAY_HIDDEN_COMMANDS = new Set([
|
|
17
|
+
...LOCAL_ONLY_COMMANDS,
|
|
18
|
+
"/compact",
|
|
19
|
+
"/model",
|
|
20
|
+
"/mcp",
|
|
21
|
+
"/status",
|
|
22
|
+
"/usage",
|
|
23
|
+
]);
|
|
24
|
+
// The Claude SDK persists local slash command invocations (e.g. `/model`) and
|
|
25
|
+
// their output as user messages in the session transcript, wrapping the
|
|
26
|
+
// payload in these XML-like markers that the CLI uses for its own display.
|
|
27
|
+
// The live prompt loop drops them; replay must strip them too or they leak
|
|
28
|
+
// into the UI on session/load.
|
|
29
|
+
const LOCAL_COMMAND_MARKERS = [
|
|
30
|
+
"command-name",
|
|
31
|
+
"command-message",
|
|
32
|
+
"command-args",
|
|
33
|
+
"local-command-stdout",
|
|
34
|
+
"local-command-stderr",
|
|
35
|
+
].map((tag) => ({ open: `<${tag}>`, close: `</${tag}>` }));
|
|
36
|
+
// Context the CLI injects into a user turn to steer the model, appended to
|
|
37
|
+
// whatever the user typed. Nobody wrote it and no client sees it live — the
|
|
38
|
+
// prompt loop's user-message skip covers the whole message — but it is
|
|
39
|
+
// persisted alongside that prose, so replay would hand the client a prompt
|
|
40
|
+
// with instructions in it the user never gave. A `task-notification` tells the
|
|
41
|
+
// model that a background task stopped; live, the SDK `task_notification`
|
|
42
|
+
// frame reports the same stop, so replay restores the task state from it (see
|
|
43
|
+
// taskNotificationsOf) instead of showing it.
|
|
44
|
+
const INJECTED_CONTEXT_MARKERS = ["system-reminder", TASK_NOTIFICATION_TAG].map((tag) => ({
|
|
45
|
+
open: `<${tag}>`,
|
|
46
|
+
close: `</${tag}>`,
|
|
47
|
+
}));
|
|
48
|
+
// Everything a replayed user message may be wrapped in that is not speech.
|
|
49
|
+
const TRANSCRIPT_MARKERS = [...LOCAL_COMMAND_MARKERS, ...INJECTED_CONTEXT_MARKERS];
|
|
50
|
+
// Single-pass scanner that removes each `<tag>…</tag>` marker (matching the
|
|
51
|
+
// nearest closing tag of the same name, like a lazy regex would).
|
|
52
|
+
function stripMarkerTags(text) {
|
|
53
|
+
const dead = new Set();
|
|
54
|
+
let result = "";
|
|
55
|
+
let copiedUpTo = 0;
|
|
56
|
+
let i = 0;
|
|
57
|
+
while (i < text.length) {
|
|
58
|
+
if (text[i] === "<") {
|
|
59
|
+
const marker = TRANSCRIPT_MARKERS.find((m) => !dead.has(m.open) && text.startsWith(m.open, i));
|
|
60
|
+
if (marker) {
|
|
61
|
+
const end = text.indexOf(marker.close, i + marker.open.length);
|
|
62
|
+
if (end !== -1) {
|
|
63
|
+
result += text.slice(copiedUpTo, i);
|
|
64
|
+
i = copiedUpTo = end + marker.close.length;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
// No closing marker remains anywhere ahead, and `indexOf` only ever
|
|
68
|
+
// searches forward from here on, so stop treating this tag as an
|
|
69
|
+
// opener — that avoids rescanning the tail for it on every match.
|
|
70
|
+
dead.add(marker.open);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
i++;
|
|
74
|
+
}
|
|
75
|
+
return result + text.slice(copiedUpTo);
|
|
76
|
+
}
|
|
77
|
+
function hasMarkerTag(text, tag) {
|
|
78
|
+
return markerTagText(text, tag) !== undefined;
|
|
79
|
+
}
|
|
80
|
+
function commandInvocationFromMarkerOnlyText(text) {
|
|
81
|
+
if (hasMarkerTag(text, "local-command-stdout") || hasMarkerTag(text, "local-command-stderr")) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const commandName = markerTagText(text, "command-name")?.trim();
|
|
85
|
+
if (!commandName?.startsWith("/"))
|
|
86
|
+
return null;
|
|
87
|
+
if (REPLAY_HIDDEN_COMMANDS.has(commandName.split(" ", 1)[0]))
|
|
88
|
+
return null;
|
|
89
|
+
const commandArgs = markerTagText(text, "command-args")?.trim();
|
|
90
|
+
return commandArgs ? `${commandName} ${commandArgs}` : commandName;
|
|
91
|
+
}
|
|
92
|
+
function stripLocalCommandMetadataText(text) {
|
|
93
|
+
const stripped = stripMarkerTags(text);
|
|
94
|
+
if (stripped.trim() !== "")
|
|
95
|
+
return stripped;
|
|
96
|
+
return commandInvocationFromMarkerOnlyText(text);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Return user-message content with local-command and injected-context marker
|
|
100
|
+
* tags removed, or `null` if nothing meaningful remains (caller should skip
|
|
101
|
+
* the message). Preserves real prose that's mixed in alongside the markers —
|
|
102
|
+
* e.g. a message like `<command-name>…</command-name>hi` becomes `hi`, and
|
|
103
|
+
* `hi<system-reminder>…</system-reminder>` becomes `hi`.
|
|
104
|
+
*/
|
|
105
|
+
export function stripLocalCommandMetadata(content) {
|
|
106
|
+
if (typeof content === "string") {
|
|
107
|
+
return stripLocalCommandMetadataText(content);
|
|
108
|
+
}
|
|
109
|
+
if (!Array.isArray(content))
|
|
110
|
+
return content;
|
|
111
|
+
const kept = [];
|
|
112
|
+
for (const block of content) {
|
|
113
|
+
if (block &&
|
|
114
|
+
typeof block === "object" &&
|
|
115
|
+
"type" in block &&
|
|
116
|
+
block.type === "text" &&
|
|
117
|
+
"text" in block &&
|
|
118
|
+
typeof block.text === "string") {
|
|
119
|
+
const stripped = stripLocalCommandMetadataText(block.text);
|
|
120
|
+
if (stripped === null)
|
|
121
|
+
continue;
|
|
122
|
+
kept.push({ ...block, text: stripped });
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
kept.push(block);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (kept.length === 0)
|
|
129
|
+
return null;
|
|
130
|
+
return kept;
|
|
131
|
+
}
|
|
132
|
+
export function isLocalCommandMetadata(content) {
|
|
133
|
+
return stripLocalCommandMetadata(content) === null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* True for the synthetic assistant message the CLI injects into the transcript
|
|
137
|
+
* when a turn fails authentication (e.g. "Not logged in · Please run /login",
|
|
138
|
+
* "Session expired. Please run /login to sign in again."). The `/login`
|
|
139
|
+
* instruction is Claude Code TUI-specific and meaningless to ACP clients
|
|
140
|
+
* (issue #863). The live prompt loop suppresses the text and fails the turn
|
|
141
|
+
* with `authRequired` so the client can run its own auth flow; replay must
|
|
142
|
+
* skip it too — both for parity with what the client saw live and because the
|
|
143
|
+
* message stays in the transcript forever, so it would resurface on every
|
|
144
|
+
* session/load even after the user has logged back in.
|
|
145
|
+
*
|
|
146
|
+
* Takes the API message (`message.message`), which replay only knows as
|
|
147
|
+
* `unknown`. The persisted record's structured `error` marker is stripped by
|
|
148
|
+
* `getSessionMessages`, and the CLI does not always set it to
|
|
149
|
+
* `authentication_failed` anyway: an expired login with no refresh token
|
|
150
|
+
* ("Login expired · Run /login to sign in again, …") arrives as
|
|
151
|
+
* `invalid_request`. So the synthetic model + text is what both paths match on.
|
|
152
|
+
* Usage-limit banners are excluded because some of them also mention `/login`
|
|
153
|
+
* (to switch accounts) and have their own handling.
|
|
154
|
+
*/
|
|
155
|
+
export function isSyntheticLoginMessage(apiMessage) {
|
|
156
|
+
if (!apiMessage || typeof apiMessage !== "object") {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
const { model, content } = apiMessage;
|
|
160
|
+
if (model !== "<synthetic>" || !Array.isArray(content) || content.length !== 1) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
const block = content[0];
|
|
164
|
+
return (!!block &&
|
|
165
|
+
block.type === "text" &&
|
|
166
|
+
typeof block.text === "string" &&
|
|
167
|
+
isLoginRequiredText(block.text) &&
|
|
168
|
+
!isSyntheticUsageLimitMessage(apiMessage));
|
|
169
|
+
}
|
|
170
|
+
/** Origin kinds of the meta user messages `getSessionMessages` returns since
|
|
171
|
+
* SDK 0.3.284 (messages from other agents, sessions and channels). */
|
|
172
|
+
const REPLAY_HIDDEN_META_ORIGIN_KINDS = new Set([
|
|
173
|
+
"peer",
|
|
174
|
+
"channel",
|
|
175
|
+
"observer",
|
|
176
|
+
"observer-activity",
|
|
177
|
+
"slack-ping",
|
|
178
|
+
]);
|
|
179
|
+
/**
|
|
180
|
+
* True for a transcript message delivered to the model from another agent,
|
|
181
|
+
* session or channel. Since SDK 0.3.284 `getSessionMessages` returns these as
|
|
182
|
+
* `is_meta` user messages whose content is the full harness framing (envelope
|
|
183
|
+
* XML plus the "not typed by your user" preamble). The live prompt loop never
|
|
184
|
+
* renders them, so replay skips them too rather than presenting them as text
|
|
185
|
+
* the user typed. Other `is_meta` messages (compact summaries) are kept.
|
|
186
|
+
*
|
|
187
|
+
* `is_meta` and `origin` are runtime fields not declared on `SessionMessage`.
|
|
188
|
+
*/
|
|
189
|
+
export function isReplayHiddenMetaMessage(message) {
|
|
190
|
+
if (!message || typeof message !== "object")
|
|
191
|
+
return false;
|
|
192
|
+
const { type, is_meta, origin } = message;
|
|
193
|
+
return (type === "user" &&
|
|
194
|
+
is_meta === true &&
|
|
195
|
+
typeof origin?.kind === "string" &&
|
|
196
|
+
REPLAY_HIDDEN_META_ORIGIN_KINDS.has(origin.kind));
|
|
197
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { Options, SDKMessageOrigin } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
export type SDKMessageFilter = {
|
|
3
|
+
type: string;
|
|
4
|
+
subtype?: string;
|
|
5
|
+
origin?: SDKMessageOrigin["kind"];
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Extra metadata that can be given when creating a new session.
|
|
9
|
+
*/
|
|
10
|
+
export type NewSessionMeta = {
|
|
11
|
+
claudeCode?: {
|
|
12
|
+
/**
|
|
13
|
+
* Options forwarded to Claude Code when starting a new session.
|
|
14
|
+
* Those parameters will be ignored and managed by ACP:
|
|
15
|
+
* - cwd
|
|
16
|
+
* - includePartialMessages
|
|
17
|
+
* - permissionMode
|
|
18
|
+
* - canUseTool
|
|
19
|
+
* - executable
|
|
20
|
+
* Those parameters will be used and updated to work with ACP:
|
|
21
|
+
* - hooks (merged with ACP's hooks)
|
|
22
|
+
* - mcpServers (merged with ACP's mcpServers)
|
|
23
|
+
* - disallowedTools (merged with ACP's disallowedTools)
|
|
24
|
+
* - tools (passed through; defaults to claude_code preset if not provided)
|
|
25
|
+
* - allowDangerouslySkipPermissions (set to `false` to remove bypassPermissions
|
|
26
|
+
* from this session; repeat it on session/load. `true` cannot override root)
|
|
27
|
+
*/
|
|
28
|
+
options?: Options;
|
|
29
|
+
/**
|
|
30
|
+
* When set, raw SDK messages are emitted as extNotification("_claude/sdkMessage", message)
|
|
31
|
+
* in addition to normal processing.
|
|
32
|
+
* - true: emit all messages
|
|
33
|
+
* - false/undefined: emit nothing (default)
|
|
34
|
+
* - SDKMessageFilter[]: emit only messages matching at least one filter
|
|
35
|
+
*/
|
|
36
|
+
emitRawSDKMessages?: boolean | SDKMessageFilter[];
|
|
37
|
+
};
|
|
38
|
+
additionalRoots?: string[];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=new-session-meta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"new-session-meta.d.ts","sourceRoot":"","sources":["../src/new-session-meta.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAEhF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,UAAU,CAAC,EAAE;QACX;;;;;;;;;;;;;;;WAeG;QACH,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB;;;;;;WAMG;QACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,gBAAgB,EAAE,CAAC;KACnD,CAAC;IACF,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conversion of an ACP prompt into the Claude Code user message.
|
|
3
|
+
*/
|
|
4
|
+
import type { PromptRequest } from "@agentclientprotocol/sdk/unstable";
|
|
5
|
+
import type { SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
6
|
+
/** The prompt content block types that `promptToClaude` converts. The agent
|
|
7
|
+
* advertises no `audio` prompt capability. */
|
|
8
|
+
export declare const SUPPORTED_PROMPT_CONTENT_TYPES: readonly string[];
|
|
9
|
+
export declare function promptToClaude(prompt: PromptRequest): SDKUserMessage;
|
|
10
|
+
//# sourceMappingURL=prompt-to-claude.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt-to-claude.d.ts","sourceRoot":"","sources":["../src/prompt-to-claude.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAoBrE;+CAC+C;AAC/C,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAK3D,CAAC;AAEF,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,cAAc,CA+FpE"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { blobResourceToClaude } from "./blob-resources.js";
|
|
2
|
+
function formatUriAsLink(uri) {
|
|
3
|
+
try {
|
|
4
|
+
if (uri.startsWith("file://")) {
|
|
5
|
+
const path = uri.slice(7); // Remove "file://"
|
|
6
|
+
const name = path.split("/").pop() || path;
|
|
7
|
+
return `[@${name}](${uri})`;
|
|
8
|
+
}
|
|
9
|
+
else if (uri.startsWith("zed://")) {
|
|
10
|
+
const parts = uri.split("/");
|
|
11
|
+
const name = parts[parts.length - 1] || uri;
|
|
12
|
+
return `[@${name}](${uri})`;
|
|
13
|
+
}
|
|
14
|
+
return uri;
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return uri;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** The prompt content block types that `promptToClaude` converts. The agent
|
|
21
|
+
* advertises no `audio` prompt capability. */
|
|
22
|
+
export const SUPPORTED_PROMPT_CONTENT_TYPES = [
|
|
23
|
+
"text",
|
|
24
|
+
"image",
|
|
25
|
+
"resource_link",
|
|
26
|
+
"resource",
|
|
27
|
+
];
|
|
28
|
+
export function promptToClaude(prompt) {
|
|
29
|
+
const content = [];
|
|
30
|
+
const context = [];
|
|
31
|
+
const firstText = prompt.prompt.find((chunk) => chunk.type === "text");
|
|
32
|
+
for (const chunk of prompt.prompt) {
|
|
33
|
+
switch (chunk.type) {
|
|
34
|
+
case "text": {
|
|
35
|
+
let text = chunk.text;
|
|
36
|
+
// A slash command is the first text block. Change
|
|
37
|
+
// `/mcp:server:command args` to `/server:command (MCP) args`; the
|
|
38
|
+
// arguments can span lines.
|
|
39
|
+
const mcpMatch = chunk === firstText ? text.match(/^\/mcp:([^:\s]+):(\S+)(?:\s+([\s\S]*))?$/) : null;
|
|
40
|
+
if (mcpMatch) {
|
|
41
|
+
const [, server, command, args] = mcpMatch;
|
|
42
|
+
text = `/${server}:${command} (MCP)${args ? ` ${args}` : ""}`;
|
|
43
|
+
}
|
|
44
|
+
content.push({ type: "text", text });
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "resource_link": {
|
|
48
|
+
const formattedUri = formatUriAsLink(chunk.uri);
|
|
49
|
+
content.push({
|
|
50
|
+
type: "text",
|
|
51
|
+
text: formattedUri,
|
|
52
|
+
});
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case "resource": {
|
|
56
|
+
const { uri } = chunk.resource;
|
|
57
|
+
// A blob resource becomes an image or document block, or its decoded
|
|
58
|
+
// text. A v1 prompt skips a blob of any other type, e.g.
|
|
59
|
+
// `application/zip`; a v2 prompt rejects it (see `v1PromptRequest`).
|
|
60
|
+
const blob = "blob" in chunk.resource ? blobResourceToClaude(chunk.resource) : undefined;
|
|
61
|
+
const text = "text" in chunk.resource
|
|
62
|
+
? chunk.resource.text
|
|
63
|
+
: blob?.kind === "text"
|
|
64
|
+
? blob.text
|
|
65
|
+
: undefined;
|
|
66
|
+
if (blob?.kind === "image" || blob?.kind === "document") {
|
|
67
|
+
content.push({ type: "text", text: formatUriAsLink(uri) }, blob.block);
|
|
68
|
+
}
|
|
69
|
+
else if (text !== undefined) {
|
|
70
|
+
content.push({ type: "text", text: formatUriAsLink(uri) });
|
|
71
|
+
context.push({
|
|
72
|
+
type: "text",
|
|
73
|
+
text: `\n<context ref="${uri}">\n${text}\n</context>`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case "image":
|
|
79
|
+
if (chunk.data) {
|
|
80
|
+
content.push({
|
|
81
|
+
type: "image",
|
|
82
|
+
source: {
|
|
83
|
+
type: "base64",
|
|
84
|
+
data: chunk.data,
|
|
85
|
+
media_type: chunk.mimeType,
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
else if (chunk.uri && chunk.uri.startsWith("http")) {
|
|
90
|
+
content.push({
|
|
91
|
+
type: "image",
|
|
92
|
+
source: {
|
|
93
|
+
type: "url",
|
|
94
|
+
url: chunk.uri,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
// Ignore audio and other unsupported types
|
|
100
|
+
default:
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
content.push(...context);
|
|
105
|
+
return {
|
|
106
|
+
type: "user",
|
|
107
|
+
message: {
|
|
108
|
+
role: "user",
|
|
109
|
+
content: content,
|
|
110
|
+
},
|
|
111
|
+
session_id: prompt.sessionId,
|
|
112
|
+
parent_tool_use_id: null,
|
|
113
|
+
// ACP prompts are the user's own input relayed by the client. Stamp the
|
|
114
|
+
// provenance explicitly: per the SDK, a host wrapping keyboard input must
|
|
115
|
+
// send `{kind: "human"}` — an absent `origin` is treated as unattributed
|
|
116
|
+
// and fails closed at the CLI's strict isHuman() trust gates (e.g. the
|
|
117
|
+
// ultracode keyword opt-in honors only human-originated turns).
|
|
118
|
+
origin: { kind: "human" },
|
|
119
|
+
};
|
|
120
|
+
}
|
package/dist/result-end.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* How Claude Code's `result` ends the work that it reports
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* How Claude Code's `result` ends the work that it reports, and whether that
|
|
3
|
+
* work was the user's turn or a cycle Claude Code started on its own: the
|
|
4
|
+
* rules that both cores read a turn's result with (the v1 prompt loop in
|
|
5
|
+
* `acp-agent.ts` and `v2/`). Each core adds its own side effects, such as v1's
|
|
5
6
|
* session failure category.
|
|
6
7
|
*/
|
|
7
|
-
import type { SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
8
|
+
import type { SDKMessage, SDKMessageOrigin, SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
8
9
|
export type ResultEnd = {
|
|
9
10
|
stopReason: "refusal" | "max_tokens" | "end_turn" | "max_turn_requests";
|
|
10
11
|
}
|
|
@@ -36,4 +37,32 @@ export declare function isLoginRequiredText(text: string): boolean;
|
|
|
36
37
|
* the stop reason. Otherwise `max_turn_requests`.
|
|
37
38
|
*/
|
|
38
39
|
export declare function resultEnd(result: SDKResultMessage): ResultEnd;
|
|
40
|
+
/** Result-message origin kinds that mark an AUTONOMOUS cycle — work the
|
|
41
|
+
* model did on its own (a task-notification followup, a peer/coordinator/
|
|
42
|
+
* observer message it handled) rather than the user's prompt. Absent,
|
|
43
|
+
* `human`, and `channel` origins are the user's own turn (this adapter's
|
|
44
|
+
* prompts arrive as the ACP channel on some CLI configurations — ALL
|
|
45
|
+
* channel servers are treated as user, so a foreign channel integration's
|
|
46
|
+
* autonomously-handled result is misclassified as the user's; accepted,
|
|
47
|
+
* see below), and `auto-continuation` continues the user's turn, so its
|
|
48
|
+
* result is the turn's real terminal.
|
|
49
|
+
*
|
|
50
|
+
* Deliberately fail-OPEN: an unknown future kind defaults to the user
|
|
51
|
+
* lane — including `unclassified` (SDK 0.3.232+), the CLI's own "couldn't
|
|
52
|
+
* attribute this" marker, which gets the same safe default. Misrouting a
|
|
53
|
+
* USER result into the autonomous lane hangs the prompt un-detectably
|
|
54
|
+
* (the result is skipped, its trailing idle absorbed as owed, so the
|
|
55
|
+
* #825 detector can't fire); misrouting an autonomous result into the
|
|
56
|
+
* user lane is the bounded misattribution class this set exists to
|
|
57
|
+
* reduce.
|
|
58
|
+
*
|
|
59
|
+
* Exception: a result from one of these origins that names a pending prompt
|
|
60
|
+
* in `user_message_uuids` consumed that folded prompt and takes the user
|
|
61
|
+
* lane (see the result handler of each core). */
|
|
62
|
+
export declare const AUTONOMOUS_RESULT_ORIGINS: ReadonlySet<SDKMessageOrigin["kind"]>;
|
|
63
|
+
/** Whether Claude Code ended the work of `result` because an interrupt
|
|
64
|
+
* stopped it, while the model streamed or while a tool ran. */
|
|
65
|
+
export declare function isAbortedResult(result: Extract<SDKMessage, {
|
|
66
|
+
type: "result";
|
|
67
|
+
}>): boolean;
|
|
39
68
|
//# sourceMappingURL=result-end.d.ts.map
|
package/dist/result-end.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"result-end.d.ts","sourceRoot":"","sources":["../src/result-end.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"result-end.d.ts","sourceRoot":"","sources":["../src/result-end.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,SAAS,GACjB;IAAE,UAAU,EAAE,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,mBAAmB,CAAA;CAAE;AAC7E;;;GAGG;GACD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAmB7D;AAMD;;;;;;;;;;;;;;;;;;;;;kDAqBkD;AAClD,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAM1E,CAAC;AAEH;gEACgE;AAChE,wBAAgB,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG,OAAO,CAIxF"}
|
package/dist/result-end.js
CHANGED
|
@@ -48,3 +48,37 @@ export function resultEnd(result) {
|
|
|
48
48
|
function failed(result) {
|
|
49
49
|
return { error: result.errors.join(", ") || result.subtype, loginRequired: false };
|
|
50
50
|
}
|
|
51
|
+
/** Result-message origin kinds that mark an AUTONOMOUS cycle — work the
|
|
52
|
+
* model did on its own (a task-notification followup, a peer/coordinator/
|
|
53
|
+
* observer message it handled) rather than the user's prompt. Absent,
|
|
54
|
+
* `human`, and `channel` origins are the user's own turn (this adapter's
|
|
55
|
+
* prompts arrive as the ACP channel on some CLI configurations — ALL
|
|
56
|
+
* channel servers are treated as user, so a foreign channel integration's
|
|
57
|
+
* autonomously-handled result is misclassified as the user's; accepted,
|
|
58
|
+
* see below), and `auto-continuation` continues the user's turn, so its
|
|
59
|
+
* result is the turn's real terminal.
|
|
60
|
+
*
|
|
61
|
+
* Deliberately fail-OPEN: an unknown future kind defaults to the user
|
|
62
|
+
* lane — including `unclassified` (SDK 0.3.232+), the CLI's own "couldn't
|
|
63
|
+
* attribute this" marker, which gets the same safe default. Misrouting a
|
|
64
|
+
* USER result into the autonomous lane hangs the prompt un-detectably
|
|
65
|
+
* (the result is skipped, its trailing idle absorbed as owed, so the
|
|
66
|
+
* #825 detector can't fire); misrouting an autonomous result into the
|
|
67
|
+
* user lane is the bounded misattribution class this set exists to
|
|
68
|
+
* reduce.
|
|
69
|
+
*
|
|
70
|
+
* Exception: a result from one of these origins that names a pending prompt
|
|
71
|
+
* in `user_message_uuids` consumed that folded prompt and takes the user
|
|
72
|
+
* lane (see the result handler of each core). */
|
|
73
|
+
export const AUTONOMOUS_RESULT_ORIGINS = new Set([
|
|
74
|
+
"task-notification",
|
|
75
|
+
"peer",
|
|
76
|
+
"coordinator",
|
|
77
|
+
"observer",
|
|
78
|
+
"observer-activity",
|
|
79
|
+
]);
|
|
80
|
+
/** Whether Claude Code ended the work of `result` because an interrupt
|
|
81
|
+
* stopped it, while the model streamed or while a tool ran. */
|
|
82
|
+
export function isAbortedResult(result) {
|
|
83
|
+
return (result.terminal_reason === "aborted_streaming" || result.terminal_reason === "aborted_tools");
|
|
84
|
+
}
|