@agentclientprotocol/claude-agent-acp 0.102.1-preview.1 → 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/README.md +5 -1
- package/dist/acp-agent.d.ts +93 -622
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +369 -3474
- 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/acp-subagents.d.ts +1 -2
- package/dist/acp-subagents.d.ts.map +1 -1
- package/dist/auth-methods.d.ts +21 -0
- package/dist/auth-methods.d.ts.map +1 -0
- package/dist/auth-methods.js +68 -0
- package/dist/auth-status-reporter.d.ts +112 -0
- package/dist/auth-status-reporter.d.ts.map +1 -0
- package/dist/auth-status-reporter.js +253 -0
- package/dist/background-work.d.ts +12 -265
- package/dist/background-work.d.ts.map +1 -1
- package/dist/background-work.js +8 -558
- package/dist/client-system-prompt.d.ts +7 -0
- package/dist/client-system-prompt.d.ts.map +1 -1
- package/dist/client-system-prompt.js +24 -0
- package/dist/context-compaction.d.ts +20 -0
- package/dist/context-compaction.d.ts.map +1 -1
- package/dist/context-compaction.js +26 -0
- package/dist/context-window.d.ts +70 -0
- package/dist/context-window.d.ts.map +1 -0
- package/dist/context-window.js +132 -0
- package/dist/diff.d.ts +1 -1
- package/dist/diff.js +1 -1
- package/dist/elicitation.d.ts +66 -1
- package/dist/elicitation.d.ts.map +1 -1
- package/dist/elicitation.js +109 -0
- package/dist/file-change-audit.d.ts +4 -3
- package/dist/file-change-audit.d.ts.map +1 -1
- package/dist/file-change-audit.js +3 -2
- 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/mcp-oauth.d.ts +44 -0
- package/dist/mcp-oauth.d.ts.map +1 -0
- package/dist/mcp-oauth.js +142 -0
- package/dist/mcp-servers.d.ts +10 -0
- package/dist/mcp-servers.d.ts.map +1 -0
- package/dist/mcp-servers.js +29 -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/native-subagents.d.ts +18 -8
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +7 -35
- 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/permissions/presentation.d.ts +29 -0
- package/dist/permissions/presentation.d.ts.map +1 -1
- package/dist/permissions/presentation.js +38 -11
- package/dist/prompt-suggestions.d.ts +29 -0
- package/dist/prompt-suggestions.d.ts.map +1 -1
- package/dist/prompt-suggestions.js +45 -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/providers.d.ts +139 -0
- package/dist/providers.d.ts.map +1 -0
- package/dist/providers.js +286 -0
- package/dist/remote-control.d.ts +62 -0
- package/dist/remote-control.d.ts.map +1 -0
- package/dist/remote-control.js +78 -0
- package/dist/result-end.d.ts +68 -0
- package/dist/result-end.d.ts.map +1 -0
- package/dist/result-end.js +84 -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 +9 -3
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +10 -5
- package/dist/session-config-ids.d.ts +1 -0
- package/dist/session-config-ids.d.ts.map +1 -1
- package/dist/session-config-ids.js +1 -0
- package/dist/session-config-options.d.ts +64 -0
- package/dist/session-config-options.d.ts.map +1 -0
- package/dist/session-config-options.js +162 -0
- package/dist/session-effort.d.ts +67 -0
- package/dist/session-effort.d.ts.map +1 -1
- package/dist/session-effort.js +98 -0
- package/dist/session-env.d.ts +22 -0
- package/dist/session-env.d.ts.map +1 -0
- package/dist/session-env.js +66 -0
- package/dist/session-fast-mode.d.ts +83 -0
- package/dist/session-fast-mode.d.ts.map +1 -0
- package/dist/session-fast-mode.js +142 -0
- package/dist/session-index/connection.d.ts +5 -6
- package/dist/session-index/connection.d.ts.map +1 -1
- package/dist/session-index/connection.js +3 -5
- package/dist/session-mode.d.ts +1 -0
- package/dist/session-mode.d.ts.map +1 -1
- package/dist/session-mode.js +1 -1
- package/dist/session-model.d.ts +41 -0
- package/dist/session-model.d.ts.map +1 -1
- package/dist/session-model.js +110 -45
- package/dist/session-notices.d.ts +44 -0
- package/dist/session-notices.d.ts.map +1 -1
- package/dist/session-notices.js +68 -0
- package/dist/session-titles.d.ts +34 -12
- package/dist/session-titles.d.ts.map +1 -1
- package/dist/session-titles.js +7 -6
- package/dist/session-usage.d.ts +125 -0
- package/dist/session-usage.d.ts.map +1 -0
- package/dist/session-usage.js +196 -0
- 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/streamed-text.d.ts +33 -0
- package/dist/streamed-text.d.ts.map +1 -0
- package/dist/streamed-text.js +71 -0
- package/dist/subagent-configuration.d.ts +32 -0
- package/dist/subagent-configuration.d.ts.map +1 -0
- package/dist/subagent-configuration.js +70 -0
- package/dist/subagent-replay.d.ts +18 -0
- package/dist/subagent-replay.d.ts.map +1 -1
- package/dist/subagent-replay.js +25 -15
- package/dist/tool-calls/client-capabilities.d.ts +8 -8
- package/dist/tool-calls/client-capabilities.js +4 -4
- package/dist/tool-calls/renderer.d.ts +4 -5
- package/dist/tool-calls/renderer.d.ts.map +1 -1
- package/dist/tool-calls/renderer.js +4 -5
- package/dist/turn-events.d.ts +6 -46
- package/dist/turn-events.d.ts.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/v2/agent.d.ts +7 -11
- package/dist/v2/agent.d.ts.map +1 -1
- package/dist/v2/agent.js +751 -331
- package/dist/v2/air.d.ts +33 -0
- package/dist/v2/air.d.ts.map +1 -0
- package/dist/v2/air.js +29 -0
- package/dist/v2/auth.d.ts +97 -0
- package/dist/v2/auth.d.ts.map +1 -0
- package/dist/v2/auth.js +216 -0
- package/dist/v2/background.d.ts +27 -16
- package/dist/v2/background.d.ts.map +1 -1
- package/dist/v2/background.js +4 -32
- package/dist/v2/child-config.d.ts +55 -0
- package/dist/v2/child-config.d.ts.map +1 -0
- package/dist/v2/child-config.js +92 -0
- package/dist/v2/clear-context.d.ts +94 -0
- package/dist/v2/clear-context.d.ts.map +1 -0
- package/dist/v2/clear-context.js +176 -0
- package/dist/v2/commands.d.ts +46 -0
- package/dist/v2/commands.d.ts.map +1 -0
- package/dist/v2/commands.js +54 -0
- package/dist/v2/config.d.ts +187 -0
- package/dist/v2/config.d.ts.map +1 -0
- package/dist/v2/config.js +494 -0
- package/dist/v2/elicitation.d.ts +93 -0
- package/dist/v2/elicitation.d.ts.map +1 -0
- package/dist/v2/elicitation.js +160 -0
- package/dist/v2/file-changes.d.ts +61 -0
- package/dist/v2/file-changes.d.ts.map +1 -0
- package/dist/v2/file-changes.js +108 -0
- package/dist/v2/file-preview.d.ts +18 -0
- package/dist/v2/file-preview.d.ts.map +1 -0
- package/dist/v2/file-preview.js +29 -0
- package/dist/v2/initialize.d.ts +10 -24
- package/dist/v2/initialize.d.ts.map +1 -1
- package/dist/v2/initialize.js +4 -111
- package/dist/v2/outcome.d.ts +81 -0
- package/dist/v2/outcome.d.ts.map +1 -0
- package/dist/v2/outcome.js +166 -0
- package/dist/v2/permissions.d.ts +92 -0
- package/dist/v2/permissions.d.ts.map +1 -0
- package/dist/v2/permissions.js +162 -0
- package/dist/v2/prompt.d.ts +2 -42
- package/dist/v2/prompt.d.ts.map +1 -1
- package/dist/v2/prompt.js +2 -119
- package/dist/v2/remote-control.d.ts +41 -0
- package/dist/v2/remote-control.d.ts.map +1 -0
- package/dist/v2/remote-control.js +63 -0
- package/dist/v2/reports.d.ts +198 -0
- package/dist/v2/reports.d.ts.map +1 -0
- package/dist/v2/reports.js +487 -0
- package/dist/v2/restarts.d.ts +128 -0
- package/dist/v2/restarts.d.ts.map +1 -0
- package/dist/v2/restarts.js +348 -0
- package/dist/v2/session-requests.d.ts +20 -0
- package/dist/v2/session-requests.d.ts.map +1 -0
- package/dist/v2/session-requests.js +108 -0
- package/dist/v2/session-update.d.ts +2 -13
- package/dist/v2/session-update.d.ts.map +1 -1
- package/dist/v2/session-update.js +2 -22
- package/dist/v2/session.d.ts +340 -41
- package/dist/v2/session.d.ts.map +1 -1
- package/dist/v2/session.js +1224 -141
- package/dist/v2/setup.d.ts +49 -0
- package/dist/v2/setup.d.ts.map +1 -0
- package/dist/v2/setup.js +62 -0
- package/dist/v2/stopped-work.d.ts +123 -0
- package/dist/v2/stopped-work.d.ts.map +1 -0
- package/dist/v2/stopped-work.js +210 -0
- package/dist/v2/stream.d.ts +229 -0
- package/dist/v2/stream.d.ts.map +1 -0
- package/dist/v2/stream.js +507 -0
- package/dist/v2/subagent-replay.d.ts +115 -0
- package/dist/v2/subagent-replay.d.ts.map +1 -0
- package/dist/v2/subagent-replay.js +479 -0
- package/dist/v2/subscription-guard.d.ts +60 -0
- package/dist/v2/subscription-guard.d.ts.map +1 -0
- package/dist/v2/subscription-guard.js +84 -0
- package/dist/v2/tasks.d.ts +492 -0
- package/dist/v2/tasks.d.ts.map +1 -0
- package/dist/v2/tasks.js +1728 -0
- package/dist/v2/terminal.d.ts.map +1 -1
- package/dist/v2/terminal.js +6 -1
- package/dist/v2/tool-call.d.ts +3 -2
- package/dist/v2/tool-call.d.ts.map +1 -1
- package/dist/v2/update-translator.d.ts +36 -0
- package/dist/v2/update-translator.d.ts.map +1 -0
- package/dist/v2/update-translator.js +80 -0
- package/dist/workflow-progress.d.ts +23 -0
- package/dist/workflow-progress.d.ts.map +1 -1
- package/dist/workflow-progress.js +31 -8
- package/package.json +1 -1
- package/dist/v2/permission.d.ts +0 -28
- package/dist/v2/permission.d.ts.map +0 -1
- package/dist/v2/permission.js +0 -41
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-notices.d.ts","sourceRoot":"","sources":["../src/session-notices.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAEjG;;8DAE8D;AAC9D,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IACvC,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;kEACkE;AAClE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C;;oEAEoE;AACpE,wBAAgB,qBAAqB,CAAC,YAAY,CAAC,EAAE,kBAAkB,GAAG,IAAI,GAAG,OAAO,CAGvF;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAOjF;AAED,+EAA+E;AAC/E,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAElE;AAED;;;gFAGgF;AAChF,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,aAAa,EACrB,eAAe,EAAE,OAAO,EACxB,cAAc,GAAE,MAAqC,EACrD,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvC,mBAAmB,CAAC,QAAQ,CAAC,CAO/B;AAED;;;;aAIa;AACb,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAGpD;AAID;;6EAE6E;AAC7E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;iDACiD;AACjD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;4EAC4E;AAC5E,wBAAgB,m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DACwD;IACxD,MAAM,EAAE,aAAa,CAAC;IACtB,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;CACpB,CA0BA"}
|
package/dist/session-notices.js
CHANGED
|
@@ -88,3 +88,71 @@ export function splitNoticeText(text, fallbackTitle) {
|
|
|
88
88
|
}
|
|
89
89
|
return rest ? { title: firstLine, description: rest } : { title: firstLine };
|
|
90
90
|
}
|
|
91
|
+
/** The notice of Claude Code's `informational` message (e.g. why a Stop hook
|
|
92
|
+
* blocked continuation): a warning at level `warning`, else info. */
|
|
93
|
+
export function informationalNotice(message) {
|
|
94
|
+
const severity = message.level === "warning" ? "warning" : "info";
|
|
95
|
+
return {
|
|
96
|
+
severity,
|
|
97
|
+
...splitNoticeText(message.content, severity === "warning" ? "Claude reported a warning" : "Claude reported a notice"),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/** The notice of a client MCP server that the `system/init` lists as not
|
|
101
|
+
* started: `failed`, or `needs-auth` when the client cannot run the OAuth
|
|
102
|
+
* flow (`oauthAvailable`). Undefined for any other status. */
|
|
103
|
+
export function mcpServerStartupNotice(server, oauthAvailable) {
|
|
104
|
+
if (server.status === "failed") {
|
|
105
|
+
return {
|
|
106
|
+
severity: "warning",
|
|
107
|
+
title: `MCP server "${server.name}" failed to start`,
|
|
108
|
+
description: "Its tools are unavailable in this session. Run /mcp for the error.",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
if (server.status === "needs-auth" && !oauthAvailable) {
|
|
112
|
+
return {
|
|
113
|
+
severity: "info",
|
|
114
|
+
title: `MCP server "${server.name}" needs authentication`,
|
|
115
|
+
description: "Its tools are unavailable until the server is authenticated.",
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* What Claude Code's `model_refusal_fallback` tells the user: the SDK retried
|
|
122
|
+
* a refused turn on the fallback model.
|
|
123
|
+
*
|
|
124
|
+
* Current CLIs only emit direction "retry", a swap that lasts for the
|
|
125
|
+
* session. "revert"/"sticky" are retained in the SDK enum for older CLIs,
|
|
126
|
+
* where "revert" marked a turn-only fallback: the session stays on the
|
|
127
|
+
* original model. `scope` (CLI 2.1.232+) "local" means a subagent,
|
|
128
|
+
* side-question or background fork response fell back and the session model
|
|
129
|
+
* is unchanged. Absent scope means an older CLI, where every retry was a
|
|
130
|
+
* session-level swap. `persistent` is whether the session now runs
|
|
131
|
+
* `fallback_model`, so its model option must follow.
|
|
132
|
+
*/
|
|
133
|
+
export function modelRefusalFallback(message) {
|
|
134
|
+
const local = message.scope === "local";
|
|
135
|
+
const persistent = message.direction !== "revert" && !local;
|
|
136
|
+
const category = message.api_refusal_category ? ` (${message.api_refusal_category})` : "";
|
|
137
|
+
const outcome = persistent
|
|
138
|
+
? `The session will continue on ${message.fallback_model}.`
|
|
139
|
+
: local
|
|
140
|
+
? `Only that response came from ${message.fallback_model}; the session stays on ${message.original_model}.`
|
|
141
|
+
: `The session stays on ${message.original_model}.`;
|
|
142
|
+
const summary = `${message.original_model} declined this request${category}; ` +
|
|
143
|
+
`retried with ${message.fallback_model}. ${outcome}`;
|
|
144
|
+
const explanation = message.api_refusal_explanation || undefined;
|
|
145
|
+
const full = explanation ? `${summary}\n\n${explanation}` : summary;
|
|
146
|
+
return {
|
|
147
|
+
persistent,
|
|
148
|
+
summary,
|
|
149
|
+
explanation,
|
|
150
|
+
notice: {
|
|
151
|
+
severity: "warning",
|
|
152
|
+
...(summary.length > MAX_NOTICE_TITLE_LENGTH
|
|
153
|
+
? { title: "Model fallback", description: full }
|
|
154
|
+
: { title: summary, ...(explanation ? { description: explanation } : {}) }),
|
|
155
|
+
},
|
|
156
|
+
transcript: `**Model fallback:** ${full}`,
|
|
157
|
+
};
|
|
158
|
+
}
|
package/dist/session-titles.d.ts
CHANGED
|
@@ -11,15 +11,37 @@
|
|
|
11
11
|
* `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` or
|
|
12
12
|
* `CLAUDE_CODE_DISABLE_TERMINAL_TITLE` set), the same request generates it.
|
|
13
13
|
*
|
|
14
|
-
* {@link SessionTitles} holds the per-session state and is owned by
|
|
15
|
-
* `acp-agent.ts`
|
|
16
|
-
*
|
|
17
|
-
* {@link SessionTitles.
|
|
18
|
-
* {@link SessionTitles.
|
|
19
|
-
* {@link SessionTitles.
|
|
14
|
+
* {@link SessionTitles} holds the per-session state and is owned by the
|
|
15
|
+
* session, in the v1 core (`acp-agent.ts`) and the v2 core
|
|
16
|
+
* (`v2/session.ts`). Each drives it from the same places:
|
|
17
|
+
* {@link SessionTitles.onPrompt} and {@link SessionTitles.onAssistantText} to
|
|
18
|
+
* collect text, {@link SessionTitles.onPromptQueued} once a prompt is sent to
|
|
19
|
+
* the CLI, {@link SessionTitles.onTurnEnd} at `session_state_changed: idle`,
|
|
20
|
+
* and, in v1, {@link SessionTitles.reset} on `conversation_reset`.
|
|
20
21
|
*/
|
|
21
|
-
import type { ContentBlock, PromptRequest } from "@agentclientprotocol/sdk/unstable";
|
|
22
|
-
import
|
|
22
|
+
import type { ContentBlock, PromptRequest, SessionNotification } from "@agentclientprotocol/sdk/unstable";
|
|
23
|
+
import { type Query } from "@anthropic-ai/claude-agent-sdk";
|
|
24
|
+
/** What titles read of their session. */
|
|
25
|
+
export interface TitledSession {
|
|
26
|
+
readonly query: Query;
|
|
27
|
+
readonly queryClosed?: boolean;
|
|
28
|
+
/** Whether a cancel stopped the session's work: no title is generated then. */
|
|
29
|
+
readonly cancelled?: boolean;
|
|
30
|
+
readonly cwd: string;
|
|
31
|
+
}
|
|
32
|
+
/** What titles need of the core that serves the session (`ClaudeAcpAgent` in v1). */
|
|
33
|
+
export interface TitleOwner {
|
|
34
|
+
readonly client: {
|
|
35
|
+
sessionUpdate(notification: SessionNotification): Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
readonly logger: {
|
|
38
|
+
error: (...args: any[]) => void;
|
|
39
|
+
};
|
|
40
|
+
/** The live sessions by id: a session replaced or closed meanwhile adopts no title. */
|
|
41
|
+
readonly sessions: Readonly<Record<string, TitledSession | undefined>>;
|
|
42
|
+
/** The title as the client shows it, such as with an archive prefix removed. */
|
|
43
|
+
clientTitle?(title: string): string;
|
|
44
|
+
}
|
|
23
45
|
export declare function sanitizeTitle(text: string): string;
|
|
24
46
|
/** Rolling text a title is generated from: `previous` plus `text`, keeping only
|
|
25
47
|
* the trailing {@link MAX_TITLE_CONTEXT_LENGTH} characters. */
|
|
@@ -57,7 +79,7 @@ export declare class SessionTitles {
|
|
|
57
79
|
get storedTitle(): string | undefined;
|
|
58
80
|
/** The title last published, as the client shows it. */
|
|
59
81
|
get shownTitle(): string | undefined;
|
|
60
|
-
constructor(agent:
|
|
82
|
+
constructor(agent: TitleOwner, sessionId: string);
|
|
61
83
|
/** Collect a prompt's own text for the title, skipping openers not worth
|
|
62
84
|
* titling after. No-op once the title is settled. */
|
|
63
85
|
onPrompt(prompt: PromptRequest["prompt"]): void;
|
|
@@ -69,7 +91,7 @@ export declare class SessionTitles {
|
|
|
69
91
|
* prompt alone is the description, because the CLI titles from the prompt
|
|
70
92
|
* alone. When this yields no title, the stored summary is published and
|
|
71
93
|
* the next prompt tries again. */
|
|
72
|
-
onPromptQueued(session:
|
|
94
|
+
onPromptQueued(session: TitledSession, prompt: PromptRequest["prompt"]): void;
|
|
73
95
|
/** Collect the assistant's own answer for the title. Chunks are appended
|
|
74
96
|
* verbatim so streamed text reassembles. No-op once the title is settled. */
|
|
75
97
|
onAssistantText(content: ContentBlock): void;
|
|
@@ -89,7 +111,7 @@ export declare class SessionTitles {
|
|
|
89
111
|
* turn-end must not wait on it. That covers a prompt too short to title
|
|
90
112
|
* from, such as "hi". Only when that is not possible do we fall back to
|
|
91
113
|
* `summary`, which for an SDK-driven session is just the raw first prompt. */
|
|
92
|
-
onTurnEnd(session:
|
|
114
|
+
onTurnEnd(session: TitledSession): Promise<void>;
|
|
93
115
|
/** Applies a title that the client chose (a rename, an archive or an
|
|
94
116
|
* unarchive). Settles the title for good, waits for a generation in flight
|
|
95
117
|
* so that its persisted title cannot land after this one, persists the
|
|
@@ -102,7 +124,7 @@ export declare class SessionTitles {
|
|
|
102
124
|
* have it. Both come from the session file, as `session/list` reports
|
|
103
125
|
* them; a session with no file yet sends the last title published, if any,
|
|
104
126
|
* without `updatedAt`. */
|
|
105
|
-
publishCurrent(session:
|
|
127
|
+
publishCurrent(session: TitledSession): Promise<void>;
|
|
106
128
|
/** Records a title the CLI took, as soon as it took it. */
|
|
107
129
|
rememberStoredTitle(title: string): void;
|
|
108
130
|
/** Read the SDK's stored info for this session. A missing session file or read
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-titles.d.ts","sourceRoot":"","sources":["../src/session-titles.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"session-titles.d.ts","sourceRoot":"","sources":["../src/session-titles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAC3C,OAAO,EAAkB,KAAK,KAAK,EAAuB,MAAM,gCAAgC,CAAC;AAGjG,yCAAyC;AACzC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC;IACtB,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAC/B,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAED,qFAAqF;AACrF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,MAAM,EAAE;QAAE,aAAa,CAAC,YAAY,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;KAAE,CAAC;IACrF,QAAQ,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE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,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,GAAG,IAAI;IAkB7E;kFAC8E;IAC9E,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAO5C;iEAC6D;IAC7D,KAAK,IAAI,IAAI;IASb;;;;;;;;;;;;mFAY+E;IACzE,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IA4CtD;;;;;8DAK0D;IACpD,gBAAgB,CACpB,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,KAAK,MAAM,CAAC,GAAG,SAAS,EACtE,OAAO,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC;IAkChB;;;;+BAI2B;IACrB,cAAc,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAqB3D,2DAA2D;IAC3D,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIxC;oFACgF;YAClE,eAAe;IAS7B,uEAAuE;YACzD,OAAO;IAgBrB;iFAC6E;IAC7E,OAAO,CAAC,UAAU;IAUlB;;8DAE0D;IAC1D,OAAO,CAAC,eAAe;IASvB;;;wCAGoC;YACtB,eAAe;IAgB7B;;;;+EAI2E;YAC7D,oBAAoB;CAoCnC"}
|
package/dist/session-titles.js
CHANGED
|
@@ -11,12 +11,13 @@
|
|
|
11
11
|
* `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` or
|
|
12
12
|
* `CLAUDE_CODE_DISABLE_TERMINAL_TITLE` set), the same request generates it.
|
|
13
13
|
*
|
|
14
|
-
* {@link SessionTitles} holds the per-session state and is owned by
|
|
15
|
-
* `acp-agent.ts`
|
|
16
|
-
*
|
|
17
|
-
* {@link SessionTitles.
|
|
18
|
-
* {@link SessionTitles.
|
|
19
|
-
* {@link SessionTitles.
|
|
14
|
+
* {@link SessionTitles} holds the per-session state and is owned by the
|
|
15
|
+
* session, in the v1 core (`acp-agent.ts`) and the v2 core
|
|
16
|
+
* (`v2/session.ts`). Each drives it from the same places:
|
|
17
|
+
* {@link SessionTitles.onPrompt} and {@link SessionTitles.onAssistantText} to
|
|
18
|
+
* collect text, {@link SessionTitles.onPromptQueued} once a prompt is sent to
|
|
19
|
+
* the CLI, {@link SessionTitles.onTurnEnd} at `session_state_changed: idle`,
|
|
20
|
+
* and, in v1, {@link SessionTitles.reset} on `conversation_reset`.
|
|
20
21
|
*/
|
|
21
22
|
import { getSessionInfo } from "@anthropic-ai/claude-agent-sdk";
|
|
22
23
|
import { ExplicitTitle } from "./session-index/explicit-title.js";
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token usage as Claude Code reports it: the context window figures of
|
|
3
|
+
* `usage_update` and the `_meta.quota` of a turn. Shared by the v1 core and
|
|
4
|
+
* the v2 core.
|
|
5
|
+
*/
|
|
6
|
+
import type { ModelUsage } from "@anthropic-ai/claude-agent-sdk";
|
|
7
|
+
export type AccumulatedUsage = {
|
|
8
|
+
inputTokens: number;
|
|
9
|
+
outputTokens: number;
|
|
10
|
+
cachedReadTokens: number;
|
|
11
|
+
cachedWriteTokens: number;
|
|
12
|
+
};
|
|
13
|
+
/** Per-model token tallies keyed by the model id the SDK reported them under
|
|
14
|
+
* (its resolved spelling, e.g. "claude-opus-5[1m]"). */
|
|
15
|
+
export type ModelTokenTally = Record<string, AccumulatedUsage>;
|
|
16
|
+
export type UsageSnapshot = {
|
|
17
|
+
input_tokens: number;
|
|
18
|
+
output_tokens: number;
|
|
19
|
+
cache_read_input_tokens: number;
|
|
20
|
+
cache_creation_input_tokens: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const ZERO_USAGE: Readonly<{
|
|
23
|
+
input_tokens: 0;
|
|
24
|
+
output_tokens: 0;
|
|
25
|
+
cache_read_input_tokens: 0;
|
|
26
|
+
cache_creation_input_tokens: 0;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const DEFAULT_CONTEXT_WINDOW = 200000;
|
|
29
|
+
/** `_meta.quota` for work that spent `usage` in its main agent loop and
|
|
30
|
+
* `modelUsage` by model (see `turnQuotaMeta` in `acp-agent.ts`). */
|
|
31
|
+
export declare function quotaMeta(usage: AccumulatedUsage, modelUsage: ModelTokenTally | undefined): {
|
|
32
|
+
quota: {
|
|
33
|
+
token_count: {
|
|
34
|
+
totalTokens: number;
|
|
35
|
+
inputTokens: number;
|
|
36
|
+
cachedInputTokens: number;
|
|
37
|
+
cachedWriteTokens: number;
|
|
38
|
+
outputTokens: number;
|
|
39
|
+
reasoningOutputTokens: number;
|
|
40
|
+
};
|
|
41
|
+
model_usage: {
|
|
42
|
+
model: string;
|
|
43
|
+
token_count: {
|
|
44
|
+
totalTokens: number;
|
|
45
|
+
inputTokens: number;
|
|
46
|
+
cachedInputTokens: number;
|
|
47
|
+
cachedWriteTokens: number;
|
|
48
|
+
outputTokens: number;
|
|
49
|
+
reasoningOutputTokens: number;
|
|
50
|
+
};
|
|
51
|
+
}[];
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/** Sum a tally's four counters. Per the Anthropic API `inputTokens` excludes
|
|
55
|
+
* the cache counters, so this is not double-counting (see `totalTokens`). */
|
|
56
|
+
export declare function tallyTotal(usage: AccumulatedUsage): number;
|
|
57
|
+
/** Project `result.modelUsage` into our tally shape. Counters are coerced the
|
|
58
|
+
* way `snapshotFromUsage` coerces the stream's: third-party backends have been
|
|
59
|
+
* observed omitting fields, and a missing or NaN counter must not reach the
|
|
60
|
+
* wire as NaN (which `JSON.stringify` writes as `null`). */
|
|
61
|
+
export declare function normalizeModelUsage(modelUsage: Record<string, ModelUsage> | undefined): ModelTokenTally;
|
|
62
|
+
/** `current - previous` per model, dropping models with nothing to report so a
|
|
63
|
+
* turn only lists the models it actually ran on. A reading that fell BELOW the
|
|
64
|
+
* previous one means the running total restarted under us (a mid-session
|
|
65
|
+
* /clear, a zeroed crash result): there is no usable reference left to
|
|
66
|
+
* subtract, so the reading itself is the increment. */
|
|
67
|
+
export declare function modelUsageIncrement(current: ModelTokenTally, previous: ModelTokenTally): ModelTokenTally;
|
|
68
|
+
/** The per-model rows for the first result of a resumed session. Its
|
|
69
|
+
* `modelUsage` reading continues from the totals the transcript saved (SDK
|
|
70
|
+
* 0.3.277+; older transcripts may hold none), so there is no earlier reading
|
|
71
|
+
* to subtract from, and taking the reading itself would charge the whole
|
|
72
|
+
* pre-resume history to this one turn. The result's own `usage` is per-turn
|
|
73
|
+
* (main agent loop only, like the response's `usage`), so it stands in under
|
|
74
|
+
* the turn's top-level model — `key` is that model's `modelUsage` spelling
|
|
75
|
+
* when the reading has one, else the assistant message's own. Any subagent
|
|
76
|
+
* spend on this one turn goes unlisted rather than over-listed. */
|
|
77
|
+
export declare function resumedFirstResultModelUsage(usage: {
|
|
78
|
+
input_tokens?: number | null;
|
|
79
|
+
output_tokens?: number | null;
|
|
80
|
+
cache_read_input_tokens?: number | null;
|
|
81
|
+
cache_creation_input_tokens?: number | null;
|
|
82
|
+
}, key: string | null): ModelTokenTally;
|
|
83
|
+
/** Fold `increment` into `base` per model — the per-model counterpart of the
|
|
84
|
+
* `+=` the turn's flat accumulator uses. */
|
|
85
|
+
export declare function addModelUsage(base: ModelTokenTally, increment: ModelTokenTally): ModelTokenTally;
|
|
86
|
+
/** Sum all four fields as a proxy for post-turn context occupancy: the current
|
|
87
|
+
* turn's output becomes next turn's input. Per the Anthropic API, input_tokens
|
|
88
|
+
* excludes cache tokens — cache_read and cache_creation are reported
|
|
89
|
+
* separately — so summing all four is not double-counting. */
|
|
90
|
+
export declare function totalTokens(usage: UsageSnapshot): number;
|
|
91
|
+
/** Project a nullable API usage object into our non-null snapshot shape.
|
|
92
|
+
* Both SDK message_start and assistant message `usage` have `number | null`
|
|
93
|
+
* cache fields; we coerce absent values to 0 so `totalTokens` never hits
|
|
94
|
+
* NaN. `input_tokens`/`output_tokens` are typed `number` by the SDK but
|
|
95
|
+
* synthetic or third-party-backend stream events have been observed emitting
|
|
96
|
+
* them as null/undefined — coerce those too so a malformed upstream event
|
|
97
|
+
* can't leak NaN into the wire `used` field. Delta events have different
|
|
98
|
+
* semantics (cumulative + prev fallback) and are handled inline. */
|
|
99
|
+
export declare function snapshotFromUsage(usage: {
|
|
100
|
+
input_tokens?: number | null;
|
|
101
|
+
output_tokens?: number | null;
|
|
102
|
+
cache_read_input_tokens?: number | null;
|
|
103
|
+
cache_creation_input_tokens?: number | null;
|
|
104
|
+
}): UsageSnapshot;
|
|
105
|
+
/** Best-effort first guess of a model's context window, used to seed the
|
|
106
|
+
* window synchronously (via `immediateContextWindow`) until a `result` message
|
|
107
|
+
* arrives with the authoritative `modelUsage` value.
|
|
108
|
+
*
|
|
109
|
+
* Anthropic 1M-context variants encode "1m" as a distinct token in the SDK
|
|
110
|
+
* model ID (e.g., "claude-opus-4-6-1m"), which `\b1m\b` catches without also
|
|
111
|
+
* matching things like "10m" or embedded substrings. Semantic aliases like
|
|
112
|
+
* `default` carry no such token in the ID, but their `resolvedModel` and the
|
|
113
|
+
* SDK's human-facing `displayName`/`description` can (e.g.
|
|
114
|
+
* "claude-opus-4-8[1m]", "Opus 4.7 (1M context)"), so callers pass those too.
|
|
115
|
+
* This text scan can't catch every model — some resolve to extended-context
|
|
116
|
+
* models with no "1m" anywhere (e.g. `sonnet` → claude-sonnet-5, natively
|
|
117
|
+
* ~1M). Such a miss falls back to the default window, is refined by the
|
|
118
|
+
* background `getContextUsage` (`refreshContextWindowInBackground`), and is
|
|
119
|
+
* corrected by `result.modelUsage` (and cached) within one turn. */
|
|
120
|
+
export declare function inferContextWindowFromModel(...texts: Array<string | undefined>): number | null;
|
|
121
|
+
export declare function getMatchingModelUsage(modelUsage: Record<string, ModelUsage>, currentModel: string): {
|
|
122
|
+
key: string;
|
|
123
|
+
usage: ModelUsage;
|
|
124
|
+
} | undefined;
|
|
125
|
+
//# sourceMappingURL=session-usage.d.ts.map
|
|
@@ -0,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;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C,EACD,GAAG,EAAE,MAAM,GAAG,IAAI,GACjB,eAAe,CAWjB;AAED;6CAC6C;AAC7C,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,CAchG;AAED;;;+DAG+D;AAC/D,wBAAgB,WAAW,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,CAOxD;AAED;;;;;;;qEAOqE;AACrE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C,GAAG,aAAa,CAOhB;AAUD;;;;;;;;;;;;;;qEAcqE;AACrE,wBAAgB,2BAA2B,CAAC,GAAG,KAAK,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,IAAI,CAG9F;AAED,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACtC,YAAY,EAAE,MAAM;;;cAsBrB"}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
export const ZERO_USAGE = Object.freeze({
|
|
2
|
+
input_tokens: 0,
|
|
3
|
+
output_tokens: 0,
|
|
4
|
+
cache_read_input_tokens: 0,
|
|
5
|
+
cache_creation_input_tokens: 0,
|
|
6
|
+
});
|
|
7
|
+
export const DEFAULT_CONTEXT_WINDOW = 200000;
|
|
8
|
+
/** `_meta.quota` for work that spent `usage` in its main agent loop and
|
|
9
|
+
* `modelUsage` by model (see `turnQuotaMeta` in `acp-agent.ts`). */
|
|
10
|
+
export function quotaMeta(usage, modelUsage) {
|
|
11
|
+
return {
|
|
12
|
+
quota: {
|
|
13
|
+
token_count: quotaTokenCount(usage),
|
|
14
|
+
model_usage: Object.entries(modelUsage ?? {}).map(([model, usage]) => ({
|
|
15
|
+
model,
|
|
16
|
+
token_count: quotaTokenCount(usage),
|
|
17
|
+
})),
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** One `token_count` object. `cachedInputTokens` is cache reads, matching
|
|
22
|
+
* codex's field; Claude also reports cache writes, which codex has no slot
|
|
23
|
+
* for, so those ride along in an extra sibling (the same name the ACP `usage`
|
|
24
|
+
* field already uses) and are counted in `totalTokens`. `reasoningOutputTokens`
|
|
25
|
+
* is always 0: Claude bills thinking inside its output tokens and never breaks
|
|
26
|
+
* it out — the key is kept so the shape stays uniform across agents. */
|
|
27
|
+
function quotaTokenCount(usage) {
|
|
28
|
+
return {
|
|
29
|
+
totalTokens: tallyTotal(usage),
|
|
30
|
+
inputTokens: usage.inputTokens,
|
|
31
|
+
cachedInputTokens: usage.cachedReadTokens,
|
|
32
|
+
cachedWriteTokens: usage.cachedWriteTokens,
|
|
33
|
+
outputTokens: usage.outputTokens,
|
|
34
|
+
reasoningOutputTokens: 0,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/** Sum a tally's four counters. Per the Anthropic API `inputTokens` excludes
|
|
38
|
+
* the cache counters, so this is not double-counting (see `totalTokens`). */
|
|
39
|
+
export function tallyTotal(usage) {
|
|
40
|
+
return usage.inputTokens + usage.outputTokens + usage.cachedReadTokens + usage.cachedWriteTokens;
|
|
41
|
+
}
|
|
42
|
+
/** Project `result.modelUsage` into our tally shape. Counters are coerced the
|
|
43
|
+
* way `snapshotFromUsage` coerces the stream's: third-party backends have been
|
|
44
|
+
* observed omitting fields, and a missing or NaN counter must not reach the
|
|
45
|
+
* wire as NaN (which `JSON.stringify` writes as `null`). */
|
|
46
|
+
export function normalizeModelUsage(modelUsage) {
|
|
47
|
+
const tally = {};
|
|
48
|
+
for (const [model, usage] of Object.entries(modelUsage ?? {})) {
|
|
49
|
+
tally[model] = {
|
|
50
|
+
inputTokens: finiteCount(usage?.inputTokens),
|
|
51
|
+
outputTokens: finiteCount(usage?.outputTokens),
|
|
52
|
+
cachedReadTokens: finiteCount(usage?.cacheReadInputTokens),
|
|
53
|
+
cachedWriteTokens: finiteCount(usage?.cacheCreationInputTokens),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return tally;
|
|
57
|
+
}
|
|
58
|
+
function finiteCount(value) {
|
|
59
|
+
return typeof value === "number" && Number.isFinite(value) ? value : 0;
|
|
60
|
+
}
|
|
61
|
+
/** `current - previous` per model, dropping models with nothing to report so a
|
|
62
|
+
* turn only lists the models it actually ran on. A reading that fell BELOW the
|
|
63
|
+
* previous one means the running total restarted under us (a mid-session
|
|
64
|
+
* /clear, a zeroed crash result): there is no usable reference left to
|
|
65
|
+
* subtract, so the reading itself is the increment. */
|
|
66
|
+
export function modelUsageIncrement(current, previous) {
|
|
67
|
+
const increment = {};
|
|
68
|
+
for (const [model, usage] of Object.entries(current)) {
|
|
69
|
+
const base = previous[model];
|
|
70
|
+
const subtracted = base
|
|
71
|
+
? {
|
|
72
|
+
inputTokens: usage.inputTokens - base.inputTokens,
|
|
73
|
+
outputTokens: usage.outputTokens - base.outputTokens,
|
|
74
|
+
cachedReadTokens: usage.cachedReadTokens - base.cachedReadTokens,
|
|
75
|
+
cachedWriteTokens: usage.cachedWriteTokens - base.cachedWriteTokens,
|
|
76
|
+
}
|
|
77
|
+
: usage;
|
|
78
|
+
const rewound = Object.values(subtracted).some((count) => count < 0);
|
|
79
|
+
const resolved = rewound ? usage : subtracted;
|
|
80
|
+
if (tallyTotal(resolved) > 0) {
|
|
81
|
+
increment[model] = resolved;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return increment;
|
|
85
|
+
}
|
|
86
|
+
/** The per-model rows for the first result of a resumed session. Its
|
|
87
|
+
* `modelUsage` reading continues from the totals the transcript saved (SDK
|
|
88
|
+
* 0.3.277+; older transcripts may hold none), so there is no earlier reading
|
|
89
|
+
* to subtract from, and taking the reading itself would charge the whole
|
|
90
|
+
* pre-resume history to this one turn. The result's own `usage` is per-turn
|
|
91
|
+
* (main agent loop only, like the response's `usage`), so it stands in under
|
|
92
|
+
* the turn's top-level model — `key` is that model's `modelUsage` spelling
|
|
93
|
+
* when the reading has one, else the assistant message's own. Any subagent
|
|
94
|
+
* spend on this one turn goes unlisted rather than over-listed. */
|
|
95
|
+
export function resumedFirstResultModelUsage(usage, key) {
|
|
96
|
+
if (key === null) {
|
|
97
|
+
return {};
|
|
98
|
+
}
|
|
99
|
+
const row = {
|
|
100
|
+
inputTokens: finiteCount(usage.input_tokens),
|
|
101
|
+
outputTokens: finiteCount(usage.output_tokens),
|
|
102
|
+
cachedReadTokens: finiteCount(usage.cache_read_input_tokens),
|
|
103
|
+
cachedWriteTokens: finiteCount(usage.cache_creation_input_tokens),
|
|
104
|
+
};
|
|
105
|
+
return tallyTotal(row) > 0 ? { [key]: row } : {};
|
|
106
|
+
}
|
|
107
|
+
/** Fold `increment` into `base` per model — the per-model counterpart of the
|
|
108
|
+
* `+=` the turn's flat accumulator uses. */
|
|
109
|
+
export function addModelUsage(base, increment) {
|
|
110
|
+
const merged = { ...base };
|
|
111
|
+
for (const [model, usage] of Object.entries(increment)) {
|
|
112
|
+
const existing = merged[model];
|
|
113
|
+
merged[model] = existing
|
|
114
|
+
? {
|
|
115
|
+
inputTokens: existing.inputTokens + usage.inputTokens,
|
|
116
|
+
outputTokens: existing.outputTokens + usage.outputTokens,
|
|
117
|
+
cachedReadTokens: existing.cachedReadTokens + usage.cachedReadTokens,
|
|
118
|
+
cachedWriteTokens: existing.cachedWriteTokens + usage.cachedWriteTokens,
|
|
119
|
+
}
|
|
120
|
+
: usage;
|
|
121
|
+
}
|
|
122
|
+
return merged;
|
|
123
|
+
}
|
|
124
|
+
/** Sum all four fields as a proxy for post-turn context occupancy: the current
|
|
125
|
+
* turn's output becomes next turn's input. Per the Anthropic API, input_tokens
|
|
126
|
+
* excludes cache tokens — cache_read and cache_creation are reported
|
|
127
|
+
* separately — so summing all four is not double-counting. */
|
|
128
|
+
export function totalTokens(usage) {
|
|
129
|
+
return (usage.input_tokens +
|
|
130
|
+
usage.output_tokens +
|
|
131
|
+
usage.cache_read_input_tokens +
|
|
132
|
+
usage.cache_creation_input_tokens);
|
|
133
|
+
}
|
|
134
|
+
/** Project a nullable API usage object into our non-null snapshot shape.
|
|
135
|
+
* Both SDK message_start and assistant message `usage` have `number | null`
|
|
136
|
+
* cache fields; we coerce absent values to 0 so `totalTokens` never hits
|
|
137
|
+
* NaN. `input_tokens`/`output_tokens` are typed `number` by the SDK but
|
|
138
|
+
* synthetic or third-party-backend stream events have been observed emitting
|
|
139
|
+
* them as null/undefined — coerce those too so a malformed upstream event
|
|
140
|
+
* can't leak NaN into the wire `used` field. Delta events have different
|
|
141
|
+
* semantics (cumulative + prev fallback) and are handled inline. */
|
|
142
|
+
export function snapshotFromUsage(usage) {
|
|
143
|
+
return {
|
|
144
|
+
input_tokens: usage.input_tokens ?? 0,
|
|
145
|
+
output_tokens: usage.output_tokens ?? 0,
|
|
146
|
+
cache_read_input_tokens: usage.cache_read_input_tokens ?? 0,
|
|
147
|
+
cache_creation_input_tokens: usage.cache_creation_input_tokens ?? 0,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
function commonPrefixLength(a, b) {
|
|
151
|
+
let i = 0;
|
|
152
|
+
while (i < a.length && i < b.length && a[i] === b[i]) {
|
|
153
|
+
i++;
|
|
154
|
+
}
|
|
155
|
+
return i;
|
|
156
|
+
}
|
|
157
|
+
/** Best-effort first guess of a model's context window, used to seed the
|
|
158
|
+
* window synchronously (via `immediateContextWindow`) until a `result` message
|
|
159
|
+
* arrives with the authoritative `modelUsage` value.
|
|
160
|
+
*
|
|
161
|
+
* Anthropic 1M-context variants encode "1m" as a distinct token in the SDK
|
|
162
|
+
* model ID (e.g., "claude-opus-4-6-1m"), which `\b1m\b` catches without also
|
|
163
|
+
* matching things like "10m" or embedded substrings. Semantic aliases like
|
|
164
|
+
* `default` carry no such token in the ID, but their `resolvedModel` and the
|
|
165
|
+
* SDK's human-facing `displayName`/`description` can (e.g.
|
|
166
|
+
* "claude-opus-4-8[1m]", "Opus 4.7 (1M context)"), so callers pass those too.
|
|
167
|
+
* This text scan can't catch every model — some resolve to extended-context
|
|
168
|
+
* models with no "1m" anywhere (e.g. `sonnet` → claude-sonnet-5, natively
|
|
169
|
+
* ~1M). Such a miss falls back to the default window, is refined by the
|
|
170
|
+
* background `getContextUsage` (`refreshContextWindowInBackground`), and is
|
|
171
|
+
* corrected by `result.modelUsage` (and cached) within one turn. */
|
|
172
|
+
export function inferContextWindowFromModel(...texts) {
|
|
173
|
+
if (texts.some((text) => text != null && /\b1m\b/i.test(text)))
|
|
174
|
+
return 1_000_000;
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
export function getMatchingModelUsage(modelUsage, currentModel) {
|
|
178
|
+
let bestKey = null;
|
|
179
|
+
let bestLen = 0;
|
|
180
|
+
for (const key of Object.keys(modelUsage)) {
|
|
181
|
+
const len = commonPrefixLength(key, currentModel);
|
|
182
|
+
if (len > bestLen) {
|
|
183
|
+
bestLen = len;
|
|
184
|
+
bestKey = key;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
if (bestKey) {
|
|
188
|
+
// `bestKey` is the SDK's resolved model id (e.g. "claude-sonnet-5[1m]"),
|
|
189
|
+
// the same spelling as ModelInfo.resolvedModel — the primary key the
|
|
190
|
+
// window is cached under. `currentModel` (the assistant message's
|
|
191
|
+
// `.model`) can be the bare form (e.g. "claude-sonnet-5"); the result
|
|
192
|
+
// handler caches under that spelling too, for seed-time reads that fall
|
|
193
|
+
// back to a bare id (rows without `resolvedModel`).
|
|
194
|
+
return { key: bestKey, usage: modelUsage[bestKey] };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `available_commands_update` list: the slash commands Claude Code reports,
|
|
3
|
+
* minus the ones ACP clients can't run, plus the commands the adapter adds.
|
|
4
|
+
*/
|
|
5
|
+
import type { AvailableCommand } from "@agentclientprotocol/sdk/unstable";
|
|
6
|
+
import type { Query, SlashCommand } from "@anthropic-ai/claude-agent-sdk";
|
|
7
|
+
export declare function getAvailableSlashCommands(commands: SlashCommand[], terminalCommands?: readonly string[], airSkillCwd?: string, skillPaths?: Map<string, string | undefined>, query?: Query, skillFiles?: ReadonlyMap<string, {
|
|
8
|
+
path?: string;
|
|
9
|
+
}>): AvailableCommand[];
|
|
10
|
+
//# sourceMappingURL=slash-commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slash-commands.d.ts","sourceRoot":"","sources":["../src/slash-commands.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAU1E,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,YAAY,EAAE,EAIxB,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,EAGpC,WAAW,CAAC,EAAE,MAAM,EAEpB,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAC5C,KAAK,CAAC,EAAE,KAAK,EAIb,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAClD,gBAAgB,EAAE,CA4FpB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AIR_KIND_KEY, AIR_SKILL_PATH_KEY, withAirMeta } from "./air-extension.js";
|
|
2
|
+
import { MCP_AVAILABLE_COMMAND } from "./mcp-command.js";
|
|
3
|
+
import { claudeCodeOffersCommand, REMOTE_CONTROL_COMMAND_NAME, supportsRemoteControl, } from "./remote-control.js";
|
|
4
|
+
import { resolveSkillPath } from "./tool-calls/reporters/interaction.js";
|
|
5
|
+
export function getAvailableSlashCommands(commands,
|
|
6
|
+
// Names the CLI tagged terminal-bound on `system`/init (their UX lives in
|
|
7
|
+
// the CLI's own terminal, which ACP clients aren't) — filtered alongside
|
|
8
|
+
// the static list. Raw CLI names, matched before the MCP rename.
|
|
9
|
+
terminalCommands,
|
|
10
|
+
// The session cwd of an AIR client, or undefined for every other client.
|
|
11
|
+
// AIR gets the kind and the SKILL.md path of each skill command.
|
|
12
|
+
airSkillCwd,
|
|
13
|
+
// The resolved SKILL.md paths of the session, keyed by the cwd and the name.
|
|
14
|
+
skillPaths, query,
|
|
15
|
+
// The skill files Claude Code reports (`getContextUsage().skills.skillFrontmatter`).
|
|
16
|
+
// A listed skill gets its path from here; one that is not listed, or has no
|
|
17
|
+
// path (remote connections), is looked up on disk.
|
|
18
|
+
skillFiles) {
|
|
19
|
+
// The container listings of this one pass, so a list of a hundred commands lists each container once.
|
|
20
|
+
const skillScans = new Map();
|
|
21
|
+
const skillPath = (name, cwd) => {
|
|
22
|
+
const key = `${cwd}\0${name}`;
|
|
23
|
+
if (skillPaths?.has(key))
|
|
24
|
+
return skillPaths.get(key);
|
|
25
|
+
const resolved = resolveSkillPath(name, cwd, skillScans);
|
|
26
|
+
skillPaths?.set(key, resolved);
|
|
27
|
+
return resolved;
|
|
28
|
+
};
|
|
29
|
+
const UNSUPPORTED_COMMANDS = [
|
|
30
|
+
"clear",
|
|
31
|
+
"cost",
|
|
32
|
+
"keybindings-help",
|
|
33
|
+
"login",
|
|
34
|
+
"logout",
|
|
35
|
+
"output-style:new",
|
|
36
|
+
"release-notes",
|
|
37
|
+
"todos",
|
|
38
|
+
];
|
|
39
|
+
const remoteControlCommands = query && supportsRemoteControl(query)
|
|
40
|
+
? [
|
|
41
|
+
{
|
|
42
|
+
name: REMOTE_CONTROL_COMMAND_NAME,
|
|
43
|
+
description: "Continue this session from claude.ai/code or the Claude mobile app; `off` disconnects",
|
|
44
|
+
input: { hint: "[session name | off]" },
|
|
45
|
+
},
|
|
46
|
+
]
|
|
47
|
+
: [];
|
|
48
|
+
// The adapter replaces the terminal text of `/mcp` and runs its actions,
|
|
49
|
+
// even when Claude Code tags the command terminal-bound.
|
|
50
|
+
const advertised = commands
|
|
51
|
+
.filter((command) => command.name !== "mcp" && !terminalCommands?.includes(command.name))
|
|
52
|
+
.map((command) => {
|
|
53
|
+
const input = command.argumentHint
|
|
54
|
+
? {
|
|
55
|
+
hint: Array.isArray(command.argumentHint)
|
|
56
|
+
? command.argumentHint.join(" ")
|
|
57
|
+
: command.argumentHint,
|
|
58
|
+
}
|
|
59
|
+
: null;
|
|
60
|
+
let name = command.name;
|
|
61
|
+
const mcpPrompt = command.name.endsWith(" (MCP)");
|
|
62
|
+
if (mcpPrompt) {
|
|
63
|
+
name = `mcp:${name.replace(" (MCP)", "")}`;
|
|
64
|
+
}
|
|
65
|
+
const skillFile = airSkillCwd && !mcpPrompt ? skillFiles?.get(command.name) : undefined;
|
|
66
|
+
const skillMdPath = skillFile?.path ??
|
|
67
|
+
(airSkillCwd && !command.builtin && !mcpPrompt
|
|
68
|
+
? skillPath(command.name, airSkillCwd)
|
|
69
|
+
: undefined);
|
|
70
|
+
return {
|
|
71
|
+
name,
|
|
72
|
+
description: command.description || "",
|
|
73
|
+
input,
|
|
74
|
+
...(skillMdPath
|
|
75
|
+
? {
|
|
76
|
+
_meta: withAirMeta(withAirMeta(undefined, AIR_KIND_KEY, "skill"), AIR_SKILL_PATH_KEY, skillMdPath),
|
|
77
|
+
}
|
|
78
|
+
: skillFile
|
|
79
|
+
? // A skill without a file (bundled with the CLI, like `simplify`, or a remote connection): kind only.
|
|
80
|
+
{ _meta: withAirMeta(undefined, AIR_KIND_KEY, "skill") }
|
|
81
|
+
: {}),
|
|
82
|
+
};
|
|
83
|
+
})
|
|
84
|
+
.filter((command) => !UNSUPPORTED_COMMANDS.includes(command.name));
|
|
85
|
+
// Command names must not contain whitespace and must be unique. A name
|
|
86
|
+
// like "my command" is dropped, and of two commands named "review" only the
|
|
87
|
+
// first is kept.
|
|
88
|
+
const names = new Set();
|
|
89
|
+
return [
|
|
90
|
+
...advertised,
|
|
91
|
+
MCP_AVAILABLE_COMMAND,
|
|
92
|
+
...remoteControlCommands.filter((command) => !claudeCodeOffersCommand(commands, terminalCommands, command.name)),
|
|
93
|
+
].filter((command) => {
|
|
94
|
+
if (/\s/.test(command.name) || names.has(command.name))
|
|
95
|
+
return false;
|
|
96
|
+
names.add(command.name);
|
|
97
|
+
return true;
|
|
98
|
+
});
|
|
99
|
+
}
|