@agentclientprotocol/claude-agent-acp 0.102.0 → 0.102.1-preview.2
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 +119 -439
- package/dist/acp-agent.d.ts.map +1 -1
- package/dist/acp-agent.js +380 -2412
- 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/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/native-subagents.d.ts +18 -8
- package/dist/native-subagents.d.ts.map +1 -1
- package/dist/native-subagents.js +7 -35
- 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/plans.d.ts +36 -6
- package/dist/plans.d.ts.map +1 -1
- package/dist/plans.js +49 -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/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 +39 -0
- package/dist/result-end.d.ts.map +1 -0
- package/dist/result-end.js +50 -0
- package/dist/serve.d.ts +7 -2
- 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 +2 -5
- 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/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/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 +165 -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 +1223 -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 +228 -0
- package/dist/v2/stream.d.ts.map +1 -0
- package/dist/v2/stream.js +506 -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
package/dist/acp-subagents.d.ts
CHANGED
|
@@ -6,8 +6,7 @@ export { AIR_NATIVE_SUBAGENT_SESSIONS_CAPABILITY } from "./air-extension.js";
|
|
|
6
6
|
* - `rfd`: the subagents RFD (agentclientprotocol/agent-client-protocol#1992,
|
|
7
7
|
* as revised): `subagent_update` and `session_message`, which the SDK types.
|
|
8
8
|
* A client that declares `clientCapabilities.subagents` and is not AIR gets
|
|
9
|
-
* it.
|
|
10
|
-
* are part of v2's baseline.)
|
|
9
|
+
* it.
|
|
11
10
|
* - `air`: the earlier draft of that RFD, which AIR implements:
|
|
12
11
|
* `subagent_spawned` and `subagent_state_update`, typed below. AIR gets it,
|
|
13
12
|
* whichever capability it declares (`docs/air-extensions.md`).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acp-subagents.d.ts","sourceRoot":"","sources":["../src/acp-subagents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,mCAAmC,CAAC;AAO3C,OAAO,EAAE,uCAAuC,EAAE,MAAM,oBAAoB,CAAC;AAE7E
|
|
1
|
+
{"version":3,"file":"acp-subagents.d.ts","sourceRoot":"","sources":["../src/acp-subagents.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AuthMethod } from "@agentclientprotocol/sdk/unstable";
|
|
2
|
+
/**
|
|
3
|
+
* The terminal login methods the agent advertises, in v1 form.
|
|
4
|
+
*
|
|
5
|
+
* - `terminal`: the client runs `args` against the agent's own command
|
|
6
|
+
* (`auth.terminal` in v1, an `auth.terminal` object in v2).
|
|
7
|
+
* - `metaTerminal`: the client reads `_meta["terminal-auth"]`, which names
|
|
8
|
+
* the command too.
|
|
9
|
+
*
|
|
10
|
+
* Without either, the client cannot run a login, and the list is empty. On a
|
|
11
|
+
* remote machine (SSH, `NO_BROWSER`, `CLAUDE_CODE_REMOTE`, as the SDK's own
|
|
12
|
+
* isRemote check) the OAuth redirect to localhost cannot reach a browser, and
|
|
13
|
+
* `claude auth login` falls back to a manual flow that does not work over ACP,
|
|
14
|
+
* so the one method runs the TUI's `claude /login` instead. The Claude
|
|
15
|
+
* subscription method is left out when `shouldHideClaudeAuth()` says so.
|
|
16
|
+
*/
|
|
17
|
+
export declare function terminalAuthMethods({ terminal, metaTerminal, }: {
|
|
18
|
+
terminal: boolean;
|
|
19
|
+
metaTerminal: boolean;
|
|
20
|
+
}): AuthMethod[];
|
|
21
|
+
//# sourceMappingURL=auth-methods.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-methods.d.ts","sourceRoot":"","sources":["../src/auth-methods.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAIpE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,YAAY,GACb,EAAE;IACD,QAAQ,EAAE,OAAO,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;CACvB,GAAG,UAAU,EAAE,CA8Df"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { agentCommand } from "./agent-command.js";
|
|
2
|
+
import { shouldHideClaudeAuth } from "./hide-claude-auth.js";
|
|
3
|
+
/**
|
|
4
|
+
* The terminal login methods the agent advertises, in v1 form.
|
|
5
|
+
*
|
|
6
|
+
* - `terminal`: the client runs `args` against the agent's own command
|
|
7
|
+
* (`auth.terminal` in v1, an `auth.terminal` object in v2).
|
|
8
|
+
* - `metaTerminal`: the client reads `_meta["terminal-auth"]`, which names
|
|
9
|
+
* the command too.
|
|
10
|
+
*
|
|
11
|
+
* Without either, the client cannot run a login, and the list is empty. On a
|
|
12
|
+
* remote machine (SSH, `NO_BROWSER`, `CLAUDE_CODE_REMOTE`, as the SDK's own
|
|
13
|
+
* isRemote check) the OAuth redirect to localhost cannot reach a browser, and
|
|
14
|
+
* `claude auth login` falls back to a manual flow that does not work over ACP,
|
|
15
|
+
* so the one method runs the TUI's `claude /login` instead. The Claude
|
|
16
|
+
* subscription method is left out when `shouldHideClaudeAuth()` says so.
|
|
17
|
+
*/
|
|
18
|
+
export function terminalAuthMethods({ terminal, metaTerminal, }) {
|
|
19
|
+
if (!terminal && !metaTerminal)
|
|
20
|
+
return [];
|
|
21
|
+
const withMeta = (method, label) => {
|
|
22
|
+
if (!metaTerminal)
|
|
23
|
+
return method;
|
|
24
|
+
const agent = agentCommand();
|
|
25
|
+
return {
|
|
26
|
+
...method,
|
|
27
|
+
_meta: {
|
|
28
|
+
"terminal-auth": { command: agent.command, args: [...agent.args, ...method.args], label },
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const isRemote = !!(process.env.NO_BROWSER ||
|
|
33
|
+
process.env.SSH_CONNECTION ||
|
|
34
|
+
process.env.SSH_CLIENT ||
|
|
35
|
+
process.env.SSH_TTY ||
|
|
36
|
+
process.env.CLAUDE_CODE_REMOTE);
|
|
37
|
+
if (isRemote) {
|
|
38
|
+
if (shouldHideClaudeAuth())
|
|
39
|
+
return [];
|
|
40
|
+
return [
|
|
41
|
+
withMeta({
|
|
42
|
+
description: "Run `claude /login` in the terminal",
|
|
43
|
+
name: "Log in with Claude",
|
|
44
|
+
id: "claude-login",
|
|
45
|
+
type: "terminal",
|
|
46
|
+
args: ["--cli"],
|
|
47
|
+
}, "Claude Login"),
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
const methods = [];
|
|
51
|
+
if (!shouldHideClaudeAuth()) {
|
|
52
|
+
methods.push(withMeta({
|
|
53
|
+
description: "Use Claude subscription ",
|
|
54
|
+
name: "Claude Subscription",
|
|
55
|
+
id: "claude-ai-login",
|
|
56
|
+
type: "terminal",
|
|
57
|
+
args: ["--cli", "auth", "login", "--claudeai"],
|
|
58
|
+
}, "Claude Login"));
|
|
59
|
+
}
|
|
60
|
+
methods.push(withMeta({
|
|
61
|
+
description: "Use Anthropic Console (API usage billing)",
|
|
62
|
+
name: "Anthropic Console",
|
|
63
|
+
id: "console-login",
|
|
64
|
+
type: "terminal",
|
|
65
|
+
args: ["--cli", "auth", "login", "--console"],
|
|
66
|
+
}, "Anthropic Console Login"));
|
|
67
|
+
return methods;
|
|
68
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type AccountInfo, type Options, type Settings } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type AuthStatus, type AuthStatusKind } from "./auth-status.js";
|
|
3
|
+
import type { SettingsManager } from "./settings.js";
|
|
4
|
+
type ReporterLogger = {
|
|
5
|
+
log: (...args: any[]) => void;
|
|
6
|
+
error: (...args: any[]) => void;
|
|
7
|
+
};
|
|
8
|
+
/** The settings a probe runs under: a session's cwd, its key helper, and its launch env. */
|
|
9
|
+
export type AuthStatusSettings = Pick<SettingsManager, "getCwd" | "getApiKeyHelper">;
|
|
10
|
+
export interface AuthStatusReporterOptions {
|
|
11
|
+
/** Sends `_auth/status_update`. */
|
|
12
|
+
push: (status: AuthStatus) => Promise<void>;
|
|
13
|
+
logger: ReporterLogger;
|
|
14
|
+
/** An ACP gateway login is active: the gateway, not the CLI store, is the identity. */
|
|
15
|
+
gatewayLogin: () => boolean;
|
|
16
|
+
/** A `providers/set` override is active: a session account describes its route. */
|
|
17
|
+
providerOverride: () => boolean;
|
|
18
|
+
/** A completed probe read `kind`. */
|
|
19
|
+
onProbe?: (kind: AuthStatusKind) => void;
|
|
20
|
+
}
|
|
21
|
+
export declare class AuthStatusReporter {
|
|
22
|
+
private readonly options;
|
|
23
|
+
/** Last identity reported to the client. Undefined means "not determined yet". */
|
|
24
|
+
current?: AuthStatus;
|
|
25
|
+
/**
|
|
26
|
+
* Counts auth-affecting events (a login, a logout, a new settings context).
|
|
27
|
+
* A probe records it at start and publishes only if it has not moved, so a
|
|
28
|
+
* slow read can never overwrite a newer login or logout.
|
|
29
|
+
*/
|
|
30
|
+
epoch: number;
|
|
31
|
+
private settings?;
|
|
32
|
+
private helper?;
|
|
33
|
+
/** In-flight `claude auth status --json` probe, shared by every caller so
|
|
34
|
+
* a concurrent `initialize` and start-of-prompt read never spawn two CLI
|
|
35
|
+
* processes. */
|
|
36
|
+
private probing;
|
|
37
|
+
/** Keeps the "session account told us nothing" note to one line per process
|
|
38
|
+
* instead of one per session. */
|
|
39
|
+
private loggedUninformativeAccount;
|
|
40
|
+
/** Same, for the "client provider override active" note. */
|
|
41
|
+
private loggedOverriddenAccount;
|
|
42
|
+
/** Same, for the "the CLI probe timed out" warning: a wedged CLI stays wedged
|
|
43
|
+
* and would otherwise warn once per probe, i.e. once per user prompt. */
|
|
44
|
+
private loggedProbeTimeout;
|
|
45
|
+
constructor(options: AuthStatusReporterOptions);
|
|
46
|
+
/**
|
|
47
|
+
* Stores `next` and pushes it to the client.
|
|
48
|
+
*
|
|
49
|
+
* A push goes out only when the payload changed. The identity is read on many
|
|
50
|
+
* occasions — each session create, each guarded turn, the start of each user
|
|
51
|
+
* prompt — and almost all of them see the same login. Clients replace their
|
|
52
|
+
* whole state on each update and tolerate duplicates, so a repeat is
|
|
53
|
+
* harmless, but it is also pure noise; {@link sameAuthStatus} drops it.
|
|
54
|
+
*
|
|
55
|
+
* What the agent owes is truth — a stale or uninformative source must not
|
|
56
|
+
* reach here at all (see the epoch check in the probe and the guards at
|
|
57
|
+
* session create).
|
|
58
|
+
*/
|
|
59
|
+
set(next: AuthStatus | undefined): void;
|
|
60
|
+
/** A login or a logout: any probe already running read the world before it. */
|
|
61
|
+
changed(): void;
|
|
62
|
+
/**
|
|
63
|
+
* Probes run under these settings from now on. A new context (cwd, key
|
|
64
|
+
* helper, or launch env) starts a fresh probe in it.
|
|
65
|
+
*/
|
|
66
|
+
useSettings(manager: AuthStatusSettings, settingsOverride?: Settings, launchEnv?: Options["env"]): void;
|
|
67
|
+
/**
|
|
68
|
+
* Report the identity behind a session's `AccountInfo`.
|
|
69
|
+
*
|
|
70
|
+
* `AccountInfo` is richer than the CLI probe (it is what the live query
|
|
71
|
+
* actually authenticates with). The v1 core calls it before the
|
|
72
|
+
* `--hide-claude-auth` guard may refuse the session or the turn: that flag
|
|
73
|
+
* blocks the *use* of a subscription, it does not make the state secret, and
|
|
74
|
+
* a refusal is when the client most needs to know the account it was
|
|
75
|
+
* refused for.
|
|
76
|
+
*
|
|
77
|
+
* Two cases skip it:
|
|
78
|
+
*
|
|
79
|
+
* - ACP gateway *authentication*: the gateway, not this account, is the
|
|
80
|
+
* agent-owned identity — already reported as `kind: "gateway"` by the login.
|
|
81
|
+
* - A client-driven provider override (`providers/set`): the session then
|
|
82
|
+
* routes through the client's endpoint and `AccountInfo` describes that
|
|
83
|
+
* route (e.g. `apiProvider: "gateway"`), which is NOT agent-owned state.
|
|
84
|
+
* `authStatus` reports the agent's own login only, so the CLI probe —
|
|
85
|
+
* which reads the credential store the override never touches — stays
|
|
86
|
+
* authoritative.
|
|
87
|
+
*
|
|
88
|
+
* An account with no identity signal (e.g. `{apiProvider: "firstParty"}`
|
|
89
|
+
* under an apiKeyHelper) means "nothing to add", not "logged out" — keep
|
|
90
|
+
* what the CLI probe already established instead of overwriting it.
|
|
91
|
+
*/
|
|
92
|
+
publishSessionAccount(account: AccountInfo | undefined, apiKeyHelper?: string): void;
|
|
93
|
+
/** Shares one in-flight `claude auth status --json` run between callers. The
|
|
94
|
+
* promise is released once settled so a later call re-probes instead of
|
|
95
|
+
* replaying a stale verdict. `fresh` forces a new run even when one is in
|
|
96
|
+
* flight — `logout` needs a read that started after the credentials were
|
|
97
|
+
* cleared. */
|
|
98
|
+
probe(options?: {
|
|
99
|
+
fresh?: boolean;
|
|
100
|
+
}): Promise<AuthStatus | undefined>;
|
|
101
|
+
/** Never rejects: an unavailable CLI means "not reported", not an error. */
|
|
102
|
+
private runProbe;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Runs `claude auth logout`. The Claude and Console logins keep their
|
|
106
|
+
* credentials in the CLI's store (keychain or config dir), which only the
|
|
107
|
+
* binary can clear. The command is non-interactive and idempotent. Throws an
|
|
108
|
+
* `internal_error` with the CLI's stderr when it fails.
|
|
109
|
+
*/
|
|
110
|
+
export declare function cliLogout(): Promise<void>;
|
|
111
|
+
export {};
|
|
112
|
+
//# sourceMappingURL=auth-status-reporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-status-reporter.d.ts","sourceRoot":"","sources":["../src/auth-status-reporter.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,OAAO,EAEZ,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,cAAc,EAKpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAIrD,KAAK,cAAc,GAAG;IAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;CAAE,CAAC;AAEzF,4FAA4F;AAC5F,MAAM,MAAM,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,iBAAiB,CAAC,CAAC;AAErF,MAAM,WAAW,yBAAyB;IACxC,mCAAmC;IACnC,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,cAAc,CAAC;IACvB,uFAAuF;IACvF,YAAY,EAAE,MAAM,OAAO,CAAC;IAC5B,mFAAmF;IACnF,gBAAgB,EAAE,MAAM,OAAO,CAAC;IAChC,qCAAqC;IACrC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC;CAC1C;AAED,qBAAa,kBAAkB;IA4BjB,OAAO,CAAC,QAAQ,CAAC,OAAO;IA3BpC,kFAAkF;IAClF,OAAO,CAAC,EAAE,UAAU,CAAC;IACrB;;;;OAIG;IACH,KAAK,SAAK;IACV,OAAO,CAAC,QAAQ,CAAC,CAIf;IACF,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB;;qBAEiB;IACjB,OAAO,CAAC,OAAO,CAAgD;IAC/D;sCACkC;IAClC,OAAO,CAAC,0BAA0B,CAAS;IAC3C,4DAA4D;IAC5D,OAAO,CAAC,uBAAuB,CAAS;IACxC;8EAC0E;IAC1E,OAAO,CAAC,kBAAkB,CAAS;gBAEN,OAAO,EAAE,yBAAyB;IAE/D;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,GAAG,IAAI;IAiBvC,+EAA+E;IAC/E,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACH,WAAW,CACT,OAAO,EAAE,kBAAkB,EAC3B,gBAAgB,CAAC,EAAE,QAAQ,EAC3B,SAAS,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC;IAkB5B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,qBAAqB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI;IAwBpF;;;;mBAIe;IACf,KAAK,CAAC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAcrE,4EAA4E;YAC9D,QAAQ;CAgFvB;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAc/C"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The connection's `authStatus` state, shared by the v1 core and the v2
|
|
3
|
+
* core: the last identity it reported, the `claude auth status --json` probe,
|
|
4
|
+
* and the `_auth/status_update` pushes (see `auth-status.ts` for when each
|
|
5
|
+
* core reads the identity).
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from "node:child_process";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
|
+
import { RequestError } from "@agentclientprotocol/sdk/unstable";
|
|
10
|
+
import { filterEscalatingDefaultMode, resolveSettings, } from "@anthropic-ai/claude-agent-sdk";
|
|
11
|
+
import { AUTH_STATUS_PROBE_TIMEOUT_MS, fromAccountInfo, fromCliStatus, mergeAuthStatus, sameAuthStatus, } from "./auth-status.js";
|
|
12
|
+
import { claudeCliPath } from "./claude-cli.js";
|
|
13
|
+
const execFileAsync = promisify(execFile);
|
|
14
|
+
export class AuthStatusReporter {
|
|
15
|
+
options;
|
|
16
|
+
/** Last identity reported to the client. Undefined means "not determined yet". */
|
|
17
|
+
current;
|
|
18
|
+
/**
|
|
19
|
+
* Counts auth-affecting events (a login, a logout, a new settings context).
|
|
20
|
+
* A probe records it at start and publishes only if it has not moved, so a
|
|
21
|
+
* slow read can never overwrite a newer login or logout.
|
|
22
|
+
*/
|
|
23
|
+
epoch = 0;
|
|
24
|
+
settings;
|
|
25
|
+
helper;
|
|
26
|
+
/** In-flight `claude auth status --json` probe, shared by every caller so
|
|
27
|
+
* a concurrent `initialize` and start-of-prompt read never spawn two CLI
|
|
28
|
+
* processes. */
|
|
29
|
+
probing = null;
|
|
30
|
+
/** Keeps the "session account told us nothing" note to one line per process
|
|
31
|
+
* instead of one per session. */
|
|
32
|
+
loggedUninformativeAccount = false;
|
|
33
|
+
/** Same, for the "client provider override active" note. */
|
|
34
|
+
loggedOverriddenAccount = false;
|
|
35
|
+
/** Same, for the "the CLI probe timed out" warning: a wedged CLI stays wedged
|
|
36
|
+
* and would otherwise warn once per probe, i.e. once per user prompt. */
|
|
37
|
+
loggedProbeTimeout = false;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Stores `next` and pushes it to the client.
|
|
43
|
+
*
|
|
44
|
+
* A push goes out only when the payload changed. The identity is read on many
|
|
45
|
+
* occasions — each session create, each guarded turn, the start of each user
|
|
46
|
+
* prompt — and almost all of them see the same login. Clients replace their
|
|
47
|
+
* whole state on each update and tolerate duplicates, so a repeat is
|
|
48
|
+
* harmless, but it is also pure noise; {@link sameAuthStatus} drops it.
|
|
49
|
+
*
|
|
50
|
+
* What the agent owes is truth — a stale or uninformative source must not
|
|
51
|
+
* reach here at all (see the epoch check in the probe and the guards at
|
|
52
|
+
* session create).
|
|
53
|
+
*/
|
|
54
|
+
set(next) {
|
|
55
|
+
if (!next) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (sameAuthStatus(this.current, next)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.current = next;
|
|
62
|
+
// ACP notifications get no reply, and clients that do not know the method
|
|
63
|
+
// drop it silently — send unconditionally and never fail a caller on it.
|
|
64
|
+
void Promise.resolve()
|
|
65
|
+
.then(() => this.options.push(next))
|
|
66
|
+
.catch((error) => {
|
|
67
|
+
this.options.logger.error("Failed to send _auth/status_update:", error);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/** A login or a logout: any probe already running read the world before it. */
|
|
71
|
+
changed() {
|
|
72
|
+
this.epoch += 1;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Probes run under these settings from now on. A new context (cwd, key
|
|
76
|
+
* helper, or launch env) starts a fresh probe in it.
|
|
77
|
+
*/
|
|
78
|
+
useSettings(manager, settingsOverride, launchEnv) {
|
|
79
|
+
const helper = manager.getApiKeyHelper(settingsOverride);
|
|
80
|
+
const changed = manager.getCwd() !== (this.settings?.manager.getCwd() ?? process.cwd()) ||
|
|
81
|
+
helper !== this.helper ||
|
|
82
|
+
JSON.stringify(launchEnv) !== JSON.stringify(this.settings?.env);
|
|
83
|
+
this.settings = { manager, override: settingsOverride, env: launchEnv };
|
|
84
|
+
this.helper = helper;
|
|
85
|
+
if (changed) {
|
|
86
|
+
// The epoch bump discards any probe that read the old context, and the
|
|
87
|
+
// session account may carry no identity signal (an apiKeyHelper), so
|
|
88
|
+
// only a probe in the new context can classify it.
|
|
89
|
+
this.epoch += 1;
|
|
90
|
+
void this.probe({ fresh: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Report the identity behind a session's `AccountInfo`.
|
|
95
|
+
*
|
|
96
|
+
* `AccountInfo` is richer than the CLI probe (it is what the live query
|
|
97
|
+
* actually authenticates with). The v1 core calls it before the
|
|
98
|
+
* `--hide-claude-auth` guard may refuse the session or the turn: that flag
|
|
99
|
+
* blocks the *use* of a subscription, it does not make the state secret, and
|
|
100
|
+
* a refusal is when the client most needs to know the account it was
|
|
101
|
+
* refused for.
|
|
102
|
+
*
|
|
103
|
+
* Two cases skip it:
|
|
104
|
+
*
|
|
105
|
+
* - ACP gateway *authentication*: the gateway, not this account, is the
|
|
106
|
+
* agent-owned identity — already reported as `kind: "gateway"` by the login.
|
|
107
|
+
* - A client-driven provider override (`providers/set`): the session then
|
|
108
|
+
* routes through the client's endpoint and `AccountInfo` describes that
|
|
109
|
+
* route (e.g. `apiProvider: "gateway"`), which is NOT agent-owned state.
|
|
110
|
+
* `authStatus` reports the agent's own login only, so the CLI probe —
|
|
111
|
+
* which reads the credential store the override never touches — stays
|
|
112
|
+
* authoritative.
|
|
113
|
+
*
|
|
114
|
+
* An account with no identity signal (e.g. `{apiProvider: "firstParty"}`
|
|
115
|
+
* under an apiKeyHelper) means "nothing to add", not "logged out" — keep
|
|
116
|
+
* what the CLI probe already established instead of overwriting it.
|
|
117
|
+
*/
|
|
118
|
+
publishSessionAccount(account, apiKeyHelper) {
|
|
119
|
+
if (this.options.providerOverride()) {
|
|
120
|
+
if (!this.loggedOverriddenAccount) {
|
|
121
|
+
this.loggedOverriddenAccount = true;
|
|
122
|
+
this.options.logger.log("[authStatus] client provider override active; keeping agent-owned probe state");
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (this.options.gatewayLogin()) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const fromSession = fromAccountInfo(account, apiKeyHelper);
|
|
130
|
+
if (fromSession) {
|
|
131
|
+
this.set(fromSession);
|
|
132
|
+
}
|
|
133
|
+
else if (!this.loggedUninformativeAccount) {
|
|
134
|
+
this.loggedUninformativeAccount = true;
|
|
135
|
+
this.options.logger.log("[authStatus] session account carries no identity signal; keeping probe");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Shares one in-flight `claude auth status --json` run between callers. The
|
|
139
|
+
* promise is released once settled so a later call re-probes instead of
|
|
140
|
+
* replaying a stale verdict. `fresh` forces a new run even when one is in
|
|
141
|
+
* flight — `logout` needs a read that started after the credentials were
|
|
142
|
+
* cleared. */
|
|
143
|
+
probe(options) {
|
|
144
|
+
if (!options?.fresh && this.probing) {
|
|
145
|
+
return this.probing;
|
|
146
|
+
}
|
|
147
|
+
const probe = this.runProbe();
|
|
148
|
+
this.probing = probe;
|
|
149
|
+
void probe.finally(() => {
|
|
150
|
+
if (this.probing === probe) {
|
|
151
|
+
this.probing = null;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return probe;
|
|
155
|
+
}
|
|
156
|
+
/** Never rejects: an unavailable CLI means "not reported", not an error. */
|
|
157
|
+
async runProbe() {
|
|
158
|
+
const { logger } = this.options;
|
|
159
|
+
// Monotonicity: a read that started before the connection's latest
|
|
160
|
+
// auth-affecting event describes a world that no longer exists. Remember
|
|
161
|
+
// which one this read belongs to and drop the answer if it moved on.
|
|
162
|
+
const epoch = this.epoch;
|
|
163
|
+
const context = this.settings;
|
|
164
|
+
const apiKeyHelper = context?.manager.getApiKeyHelper(context.override);
|
|
165
|
+
// ACP gateway auth bypasses the CLI credential store entirely, so the
|
|
166
|
+
// probe would report an identity that is not the one being used. A mere
|
|
167
|
+
// client provider override (`providers/set`) does NOT skip the probe: it
|
|
168
|
+
// reroutes traffic without touching the credential store, and the store is
|
|
169
|
+
// exactly the agent-owned login `authStatus` reports.
|
|
170
|
+
if (this.options.gatewayLogin()) {
|
|
171
|
+
return this.current;
|
|
172
|
+
}
|
|
173
|
+
let stdout;
|
|
174
|
+
try {
|
|
175
|
+
const cliPath = await claudeCliPath();
|
|
176
|
+
const args = ["auth", "status", "--json"];
|
|
177
|
+
// `--settings` is a global CLI option: after the `auth status` subcommand the CLI rejects
|
|
178
|
+
// it with "unknown option '--settings'", so it has to come first.
|
|
179
|
+
if (context?.override)
|
|
180
|
+
args.unshift("--settings", JSON.stringify(context.override));
|
|
181
|
+
({ stdout } = await execFileAsync(cliPath, args, {
|
|
182
|
+
timeout: AUTH_STATUS_PROBE_TIMEOUT_MS,
|
|
183
|
+
cwd: context?.manager.getCwd() ?? process.cwd(),
|
|
184
|
+
env: context?.env ? { ...process.env, ...context.env } : process.env,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
const failed = error;
|
|
189
|
+
// Node killed the child on the timeout. Whatever it printed so far is a
|
|
190
|
+
// truncated fragment, never valid JSON: report nothing and keep the last
|
|
191
|
+
// known state, so nothing regresses and no push goes out.
|
|
192
|
+
if (failed?.killed === true && failed.signal) {
|
|
193
|
+
if (!this.loggedProbeTimeout) {
|
|
194
|
+
this.loggedProbeTimeout = true;
|
|
195
|
+
logger.error("claude auth status did not answer within 5 s; the identity is not refreshed");
|
|
196
|
+
}
|
|
197
|
+
return this.current;
|
|
198
|
+
}
|
|
199
|
+
// The logged-out case exits 1 while still printing valid JSON, so the
|
|
200
|
+
// stdout of a failed exec is parsed just like a successful one.
|
|
201
|
+
if (typeof failed?.stdout !== "string" || failed.stdout.trim().length === 0) {
|
|
202
|
+
logger.error("claude auth status failed:", error instanceof Error ? error.message : String(error));
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
stdout = failed.stdout;
|
|
206
|
+
}
|
|
207
|
+
let status = fromCliStatus(stdout, apiKeyHelper);
|
|
208
|
+
if (!context && status?.kind === "api_key" && status.detail === "API key helper") {
|
|
209
|
+
try {
|
|
210
|
+
const resolved = await resolveSettings({ cwd: process.cwd() });
|
|
211
|
+
status = fromCliStatus(stdout, filterEscalatingDefaultMode(resolved).apiKeyHelper);
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
logger.error("Could not resolve auth source settings");
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (!status) {
|
|
218
|
+
logger.error("claude auth status returned unparseable output");
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
if (epoch !== this.epoch) {
|
|
222
|
+
// A login or logout landed while this probe was running; the newer
|
|
223
|
+
// state wins and this answer is discarded, never published.
|
|
224
|
+
logger.log("[authStatus] discarding a probe that predates the latest auth change");
|
|
225
|
+
return this.current;
|
|
226
|
+
}
|
|
227
|
+
// The CLI probe can be poorer than the session `AccountInfo` for the very
|
|
228
|
+
// same login (no organization, say). Keep those extra fields rather than
|
|
229
|
+
// regressing the payload; a different identity replaces it wholesale.
|
|
230
|
+
const merged = mergeAuthStatus(this.current, status);
|
|
231
|
+
this.set(merged);
|
|
232
|
+
this.options.onProbe?.(status.kind);
|
|
233
|
+
return merged;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Runs `claude auth logout`. The Claude and Console logins keep their
|
|
238
|
+
* credentials in the CLI's store (keychain or config dir), which only the
|
|
239
|
+
* binary can clear. The command is non-interactive and idempotent. Throws an
|
|
240
|
+
* `internal_error` with the CLI's stderr when it fails.
|
|
241
|
+
*/
|
|
242
|
+
export async function cliLogout() {
|
|
243
|
+
try {
|
|
244
|
+
const cliPath = await claudeCliPath();
|
|
245
|
+
await execFileAsync(cliPath, ["auth", "logout"]);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
const stderr = typeof error === "object" && error && "stderr" in error
|
|
249
|
+
? String(error.stderr).trim()
|
|
250
|
+
: undefined;
|
|
251
|
+
throw RequestError.internalError({ stderr: stderr || undefined }, `claude auth logout failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|