@agentclientprotocol/claude-agent-acp 0.112.1-preview.2 → 0.113.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +1 -0
  2. package/dist/adapter-command.d.ts +56 -0
  3. package/dist/adapter-command.d.ts.map +1 -0
  4. package/dist/adapter-command.js +74 -0
  5. package/dist/claude-cli.d.ts +2 -0
  6. package/dist/claude-cli.d.ts.map +1 -1
  7. package/dist/claude-cli.js +5 -1
  8. package/dist/mcp-command.d.ts.map +1 -1
  9. package/dist/mcp-command.js +1 -14
  10. package/dist/plugin-command.d.ts +94 -0
  11. package/dist/plugin-command.d.ts.map +1 -0
  12. package/dist/plugin-command.js +633 -0
  13. package/dist/slash-commands.d.ts +1 -1
  14. package/dist/slash-commands.d.ts.map +1 -1
  15. package/dist/slash-commands.js +5 -12
  16. package/dist/usage-markdown.d.ts +4 -0
  17. package/dist/usage-markdown.d.ts.map +1 -1
  18. package/dist/usage-markdown.js +13 -0
  19. package/dist/v1/acp-agent.d.ts +16 -10
  20. package/dist/v1/acp-agent.d.ts.map +1 -1
  21. package/dist/v1/acp-agent.js +125 -77
  22. package/dist/v1/adapter-commands.d.ts +78 -0
  23. package/dist/v1/adapter-commands.d.ts.map +1 -0
  24. package/dist/v1/adapter-commands.js +124 -0
  25. package/dist/v1/remote-control.d.ts +10 -34
  26. package/dist/v1/remote-control.d.ts.map +1 -1
  27. package/dist/v1/remote-control.js +6 -26
  28. package/dist/v2/{remote-control.d.ts → adapter-commands.d.ts} +34 -17
  29. package/dist/v2/adapter-commands.d.ts.map +1 -0
  30. package/dist/v2/adapter-commands.js +121 -0
  31. package/dist/v2/agent.d.ts.map +1 -1
  32. package/dist/v2/agent.js +3 -2
  33. package/dist/v2/commands.d.ts +5 -4
  34. package/dist/v2/commands.d.ts.map +1 -1
  35. package/dist/v2/commands.js +4 -2
  36. package/dist/v2/session.d.ts +14 -8
  37. package/dist/v2/session.d.ts.map +1 -1
  38. package/dist/v2/session.js +68 -38
  39. package/dist/v2/subscription-guard.d.ts +2 -1
  40. package/dist/v2/subscription-guard.d.ts.map +1 -1
  41. package/package.json +1 -1
  42. package/dist/v2/remote-control.d.ts.map +0 -1
  43. package/dist/v2/remote-control.js +0 -97
package/README.md CHANGED
@@ -19,6 +19,7 @@ This tool implements an ACP agent by using the official [Claude Agent SDK](https
19
19
  - Client MCP servers, including the ones that the client serves over the ACP connection ([MCP-over-ACP](https://agentclientprotocol.com/rfds/mcp-over-acp), `"type": "acp"`). Where an organization's managed settings (`disableSideloadFlags`) keep them out, a session starts without them and says so in a notice
20
20
  - An Ultracode session config option, which turns on Claude Code's dynamic workflows for every task. It appears when dynamic workflows are enabled and the model supports ultracode (any model with `xhigh` effort)
21
21
  - `/mcp` in the chat: the MCP server status as a list. The adapter runs `/mcp reconnect`, `/mcp enable`, and `/mcp disable` through the SDK control API, because Claude Code refuses them in SDK mode. A reconnect of an ACP server that needs authentication starts MCP OAuth through URL elicitation
22
+ - `/plugin` (aliases `/plugins`, `/marketplace`) in the chat: the adapter runs `claude plugin …` for install, uninstall, enable, disable, update, and list, and `marketplace add|list|remove|update`, because Claude Code refuses `/plugin` in SDK mode, then reloads the session's plugins. It is not available in remote (`sdk-url`) sessions
22
23
  - Prompt suggestions: the prompt that Claude Code predicts the user sends next, as ACP's unstable `prompt_suggestions_update`, for a client that advertises `session.promptSuggestions`
23
24
  - Session-scoped long-running goals for AIR through the [goal extension](docs/air-extensions.md#goal) under `_meta.jetbrains.air.goal`
24
25
  - Structured errors, recovery, and warnings through the opt-in [session failure extension](docs/air-extensions.md#session-failure)
@@ -0,0 +1,56 @@
1
+ /**
2
+ * The commands the adapter serves itself instead of passing to Claude Code
3
+ * (`/remote-control` and `/plugin`), in one place so that the command list and
4
+ * the dispatch in the v1 and v2 cores apply the same rule.
5
+ */
6
+ import type { AvailableCommand } from "@agentclientprotocol/sdk/unstable";
7
+ import type { Query, SlashCommand } from "@anthropic-ai/claude-agent-sdk";
8
+ import { PLUGIN_COMMAND_NAME } from "./plugin-command.js";
9
+ import { REMOTE_CONTROL_COMMAND_NAME, type RemoteControlCommand } from "./remote-control.js";
10
+ type PromptContent = ReadonlyArray<{
11
+ type: string;
12
+ text?: unknown;
13
+ }>;
14
+ export interface AdapterCommand {
15
+ readonly name: typeof REMOTE_CONTROL_COMMAND_NAME | typeof PLUGIN_COMMAND_NAME;
16
+ /** The `RequestError` text while Claude is working. */
17
+ readonly busyMessage: string;
18
+ /** The `RequestError` text while another adapter command runs. */
19
+ readonly inFlightMessage: string;
20
+ /** What `/remote-control` was asked to do. A core records it before the
21
+ * command runs, so that a restart of the query keeps what the user chose
22
+ * (see `RemoteControlAtStartup.commandRan`). */
23
+ readonly remoteControl?: RemoteControlCommand;
24
+ /** Returns the reply text. A failure is in the text: this never throws. */
25
+ run(signal: AbortSignal): Promise<string>;
26
+ }
27
+ export interface AdapterCommandContext {
28
+ cwd: string;
29
+ env: Record<string, string | undefined>;
30
+ /** The session runs Claude Code remotely (`sdk-url`). */
31
+ remoteSession: boolean;
32
+ query: () => Query | undefined;
33
+ logError: (message: string) => void;
34
+ }
35
+ /** The session's client options (`_meta.claudeCode.options`) that decide where
36
+ * an adapter command runs: the CLI's `env`, and whether Claude Code is remote. */
37
+ export declare function sessionAdapterOptions(creationParams: {
38
+ _meta?: unknown;
39
+ } | undefined): {
40
+ env: Record<string, string | undefined>;
41
+ remoteSession: boolean;
42
+ };
43
+ /** A cheap synchronous check for the cores, before any await: the prompt has
44
+ * the form of an adapter command. Whether the adapter serves it is
45
+ * {@link adapterCommand}'s decision. */
46
+ export declare function mayBeAdapterCommand(prompt: PromptContent): boolean;
47
+ /** The adapter command of `prompt` that the adapter runs, or `null` for a
48
+ * prompt that goes to Claude Code. */
49
+ export declare function adapterCommand(prompt: PromptContent, query: Query, terminalCommands: readonly string[] | undefined, context: AdapterCommandContext): Promise<AdapterCommand | null>;
50
+ /** The entries of `available_commands_update` that the adapter serves,
51
+ * without those that Claude Code offers under the same name. */
52
+ export declare function adapterAvailableCommands(commands: readonly SlashCommand[], terminalCommands: readonly string[] | undefined, query: Query | undefined, { remoteSession }: {
53
+ remoteSession: boolean;
54
+ }): AvailableCommand[];
55
+ export {};
56
+ //# sourceMappingURL=adapter-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter-command.d.ts","sourceRoot":"","sources":["../src/adapter-command.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAG1E,OAAO,EAIL,mBAAmB,EAEpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,2BAA2B,EAC3B,KAAK,oBAAoB,EAG1B,MAAM,qBAAqB,CAAC;AAE7B,KAAK,aAAa,GAAG,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAErE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAE,OAAO,2BAA2B,GAAG,OAAO,mBAAmB,CAAC;IAC/E,uDAAuD;IACvD,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,kEAAkE;IAClE,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC;;qDAEiD;IACjD,QAAQ,CAAC,aAAa,CAAC,EAAE,oBAAoB,CAAC;IAC9C,2EAA2E;IAC3E,GAAG,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,qBAAqB;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,yDAAyD;IACzD,aAAa,EAAE,OAAO,CAAC;IACvB,KAAK,EAAE,MAAM,KAAK,GAAG,SAAS,CAAC;IAC/B,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC;AAED;mFACmF;AACnF,wBAAgB,qBAAqB,CAAC,cAAc,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,GAAG;IACtF,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACxC,aAAa,EAAE,OAAO,CAAC;CACxB,CAMA;AASD;;yCAEyC;AACzC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAElE;AAED;uCACuC;AACvC,wBAAsB,cAAc,CAClC,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC/C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAsChC;AAQD;iEACiE;AACjE,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,SAAS,YAAY,EAAE,EACjC,gBAAgB,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,EAC/C,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,EAAE,aAAa,EAAE,EAAE;IAAE,aAAa,EAAE,OAAO,CAAA;CAAE,GAC5C,gBAAgB,EAAE,CAOpB"}
@@ -0,0 +1,74 @@
1
+ import { claudeCliPath, isRemoteSession } from "./claude-cli.js";
2
+ import { parsePluginCommand, pluginCommandMarkdown, PLUGIN_AVAILABLE_COMMAND, PLUGIN_COMMAND_NAME, runPluginCommand, } from "./plugin-command.js";
3
+ import { adapterRemoteControlCommand, claudeCodeOffersCommand, parseRemoteControlCommand, REMOTE_CONTROL_COMMAND_NAME, runRemoteControlCommand, supportsRemoteControl, } from "./remote-control.js";
4
+ /** The session's client options (`_meta.claudeCode.options`) that decide where
5
+ * an adapter command runs: the CLI's `env`, and whether Claude Code is remote. */
6
+ export function sessionAdapterOptions(creationParams) {
7
+ const options = creationParams?._meta?.claudeCode?.options;
8
+ return {
9
+ env: { ...process.env, ...options?.env },
10
+ remoteSession: isRemoteSession(options?.extraArgs),
11
+ };
12
+ }
13
+ const REMOTE_CONTROL_ENTRY = {
14
+ name: REMOTE_CONTROL_COMMAND_NAME,
15
+ description: "Continue this session from claude.ai/code or the Claude mobile app; `off` disconnects",
16
+ input: { hint: "[session name | off]" },
17
+ };
18
+ /** A cheap synchronous check for the cores, before any await: the prompt has
19
+ * the form of an adapter command. Whether the adapter serves it is
20
+ * {@link adapterCommand}'s decision. */
21
+ export function mayBeAdapterCommand(prompt) {
22
+ return parseRemoteControlCommand(prompt) !== null || parsePluginCommand(prompt) !== null;
23
+ }
24
+ /** The adapter command of `prompt` that the adapter runs, or `null` for a
25
+ * prompt that goes to Claude Code. */
26
+ export async function adapterCommand(prompt, query, terminalCommands, context) {
27
+ const remoteControl = await adapterRemoteControlCommand(prompt, query, terminalCommands);
28
+ if (remoteControl) {
29
+ return {
30
+ name: REMOTE_CONTROL_COMMAND_NAME,
31
+ busyMessage: "Remote Control can't be changed while Claude is working. Try again when the turn ends.",
32
+ inFlightMessage: "Remote Control is already being changed. Try again in a moment.",
33
+ remoteControl: remoteControl.command,
34
+ run: () => runRemoteControlCommand(remoteControl.query, remoteControl.command, context.logError),
35
+ };
36
+ }
37
+ const command = parsePluginCommand(prompt);
38
+ // A session with `sdk-url` runs Claude Code on another machine; the CLI that
39
+ // the adapter would start here changes the plugins of this machine instead.
40
+ if (!command || context.remoteSession)
41
+ return null;
42
+ const typed = typedCommandName(prompt);
43
+ if (claudeCodeOffersCommand(await query.supportedCommands(), terminalCommands, typed)) {
44
+ return null;
45
+ }
46
+ return {
47
+ name: PLUGIN_COMMAND_NAME,
48
+ busyMessage: "/plugin can't run while Claude is working. Try again when the turn ends.",
49
+ inFlightMessage: "Another command is still running. Try again in a moment.",
50
+ run: async (signal) => pluginCommandMarkdown(await runPluginCommand(command, {
51
+ cliPath: claudeCliPath,
52
+ cwd: context.cwd,
53
+ env: context.env,
54
+ signal,
55
+ query: context.query,
56
+ logError: context.logError,
57
+ })),
58
+ };
59
+ }
60
+ /** The name the user typed: `plugin`, `plugins` or `marketplace`. */
61
+ function typedCommandName(prompt) {
62
+ const text = typeof prompt[0]?.text === "string" ? prompt[0].text : "";
63
+ return /^\/([^\s]+)/.exec(text.trim())?.[1] ?? PLUGIN_COMMAND_NAME;
64
+ }
65
+ /** The entries of `available_commands_update` that the adapter serves,
66
+ * without those that Claude Code offers under the same name. */
67
+ export function adapterAvailableCommands(commands, terminalCommands, query, { remoteSession }) {
68
+ const entries = [];
69
+ if (query && supportsRemoteControl(query))
70
+ entries.push(REMOTE_CONTROL_ENTRY);
71
+ if (!remoteSession)
72
+ entries.push(PLUGIN_AVAILABLE_COMMAND);
73
+ return entries.filter((entry) => !claudeCodeOffersCommand(commands, terminalCommands, entry.name));
74
+ }
@@ -14,6 +14,8 @@ export declare function useBundledClaudeCli(directory: string): void;
14
14
  export declare function claudeCliPath(): Promise<string>;
15
15
  /** How an option reaches the Claude CLI: in a flag, or over stdin in the SDK's initialize request. */
16
16
  type Delivery = NonNullable<Options["mcpServersDelivery"]>;
17
+ /** Whether the client's `extraArgs` name `sdk-url`: a remote session. */
18
+ export declare function isRemoteSession(clientExtraArgs: Options["extraArgs"]): boolean;
17
19
  /**
18
20
  * The SDK options that say how a session's MCP servers and its `settings`
19
21
  * reach the CLI of {@link claudeCliPath}. A client's own options replace them.
@@ -1 +1 @@
1
- {"version":3,"file":"claude-cli.d.ts","sourceRoot":"","sources":["../src/claude-cli.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAM9D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAQrD;AAED,sGAAsG;AACtG,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;IAClE,kBAAkB,EAAE,QAAQ,CAAC;IAC7B,gBAAgB,EAAE,QAAQ,CAAC;CAC5B,CAMA"}
1
+ {"version":3,"file":"claude-cli.d.ts","sourceRoot":"","sources":["../src/claude-cli.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AAM9D;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE3D;AAED;;;GAGG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAQrD;AAED,sGAAsG;AACtG,KAAK,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAE3D,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,OAAO,CAI9E;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,WAAW,CAAC,eAAe,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG;IAClE,kBAAkB,EAAE,QAAQ,CAAC;IAC7B,gBAAgB,EAAE,QAAQ,CAAC;CAC5B,CAIA"}
@@ -25,6 +25,10 @@ export async function claudeCliPath() {
25
25
  }
26
26
  return installedClaudeCliPath();
27
27
  }
28
+ /** Whether the client's `extraArgs` name `sdk-url`: a remote session. */
29
+ export function isRemoteSession(clientExtraArgs) {
30
+ return Object.keys(clientExtraArgs ?? {}).some((name) => name === "sdk-url" || name.startsWith("sdk-url="));
31
+ }
28
32
  /**
29
33
  * The SDK options that say how a session's MCP servers and its `settings`
30
34
  * reach the CLI of {@link claudeCliPath}. A client's own options replace them.
@@ -53,7 +57,7 @@ export async function claudeCliPath() {
53
57
  */
54
58
  export function cliDelivery(clientExtraArgs) {
55
59
  const delivery = process.env.CLAUDE_CODE_EXECUTABLE ? "argv" : "initialize";
56
- const settingsInFlag = Object.keys(clientExtraArgs ?? {}).some((name) => name === "settings" || name === "sdk-url" || name.startsWith("sdk-url="));
60
+ const settingsInFlag = "settings" in (clientExtraArgs ?? {}) || isRemoteSession(clientExtraArgs);
57
61
  return { mcpServersDelivery: delivery, settingsDelivery: settingsInFlag ? "argv" : delivery };
58
62
  }
59
63
  function bundledClaudeCliPath(directory) {
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-command.d.ts","sourceRoot":"","sources":["../src/mcp-command.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAI7E;;2BAE2B;AAC3B,eAAO,MAAM,qBAAqB,EAAE,gBAInC,CAAC;AAQF;;6EAE6E;AAC7E,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF;;+DAE+D;AAC/D,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,IAAI,CAe/D;AAED;;0CAE0C;AAC1C,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,EACrC,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,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AM,GAAG,UAAU,GAAG,IAAI,CAe/D;AAED;;0CAE0C;AAC1C,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,EACrC,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC,OAAO,CAAC,eAAe,EAAE,GAAG,IAAI,CAAC,CAkBnC;AA4DD;;;;kBAIkB;AAClB,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBnD;AA2DD;;8BAE8B;AAC9B,wBAAgB,eAAe,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,MAAM,CA6BnE;AAED,8CAA8C;AAC9C,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,KAAK,EACL,iBAAiB,GAAG,oBAAoB,GAAG,iBAAiB,CAC7D,CAAC;AAEF;;kCAEkC;AAClC,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AA4DnF;;;;;sDAKsD;AACtD,wBAAsB,aAAa,CACjC,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,UAAU,EACnB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAClC,OAAO,CAAC,iBAAiB,CAAC,CAoD5B"}
@@ -1,4 +1,4 @@
1
- import { escapeMarkdown } from "./usage-markdown.js";
1
+ import { codeSpan, escapeMarkdown } from "./usage-markdown.js";
2
2
  import { raceTimeoutAndAbort } from "./utils.js";
3
3
  /** The `/mcp` entry of `available_commands_update`. The adapter shows the
4
4
  * servers as a list, and runs a reconnect, an enable, or a disable through
@@ -79,19 +79,6 @@ const MAX_WRAPPER_LENGTH = 60;
79
79
  function needsReconnect(status) {
80
80
  return (status.status === "failed" || status.status === "pending" || status.status === "needs-auth");
81
81
  }
82
- /** The text as a Markdown code span. The fence is longer than the longest
83
- * backtick run in the text, so the span shows the text unchanged. The user
84
- * can copy a server name from it into `/mcp reconnect`. */
85
- function codeSpan(text) {
86
- const longestRun = Math.max(0, ...(text.match(/`+/g) ?? []).map((run) => run.length));
87
- const fence = "`".repeat(longestRun + 1);
88
- // CommonMark strips one space from each end of a span that is not all spaces
89
- // (line endings count as spaces), so a pad keeps the text unchanged. Plain
90
- // string checks, not one regex: `^ .*[^ ].* $` backtracks quadratically.
91
- const strippedByCommonMark = text.startsWith(" ") && text.endsWith(" ") && /[^ \r\n]/.test(text);
92
- const pad = text.startsWith("`") || text.endsWith("`") || strippedByCommonMark ? " " : "";
93
- return `${fence}${pad}${text}${pad}${fence}`;
94
- }
95
82
  function isErrorCode(segment) {
96
83
  return /^-?\d+$/.test(segment);
97
84
  }
@@ -0,0 +1,94 @@
1
+ import type { AvailableCommand } from "@agentclientprotocol/sdk/unstable";
2
+ import type { Query } from "@anthropic-ai/claude-agent-sdk";
3
+ /** The content blocks of a prompt, in v1 or v2 form: the command is one text block. */
4
+ type PromptContent = ReadonlyArray<{
5
+ type: string;
6
+ text?: unknown;
7
+ }>;
8
+ export declare const PLUGIN_COMMAND_NAME = "plugin";
9
+ /** The `/plugin` entry of `available_commands_update`. */
10
+ export declare const PLUGIN_AVAILABLE_COMMAND: AvailableCommand;
11
+ /** The CLI operations that the adapter runs. */
12
+ export type PluginCliOperation = "list" | "install" | "uninstall" | "enable" | "disable" | "update" | "marketplace-add" | "marketplace-list" | "marketplace-remove" | "marketplace-update";
13
+ export type PluginOperation = PluginCliOperation | "overview" | "usage";
14
+ export type PluginCommand =
15
+ /** Bare `/plugin` and `/plugin help`: usage, installed plugins and marketplaces. */
16
+ {
17
+ kind: "overview";
18
+ }
19
+ /** Anything outside the allowlist, or a missing argument. `reason` says which. */
20
+ | {
21
+ kind: "usage";
22
+ reason?: string;
23
+ }
24
+ /** One CLI run. `argv` is what follows `claude plugin`, without `--json`.
25
+ * `target` is the plugin or marketplace name the command is about, if it has one. */
26
+ | {
27
+ kind: "cli";
28
+ operation: PluginCliOperation;
29
+ argv: string[];
30
+ target?: string;
31
+ };
32
+ /**
33
+ * Parses `/plugin ...` (also `/plugins ...` and `/marketplace ...`, which are
34
+ * aliases: `/marketplace marketplace add x` is `/plugin marketplace add x`,
35
+ * and `/marketplace add x` is usage, like `/plugin add x`) from a single-text
36
+ * prompt. `null` for any other prompt, which goes to Claude Code.
37
+ */
38
+ export declare function parsePluginCommand(prompt: PromptContent): PluginCommand | null;
39
+ export type PluginReload = {
40
+ status: "applied" | "busy" | "failed" | "unavailable";
41
+ /** The names of the plugins the session has after a reload; with `applied`. */
42
+ plugins?: string[];
43
+ /** Why the reload failed; with `failed`. */
44
+ error?: string;
45
+ };
46
+ export interface PluginCommandResult {
47
+ ok: boolean;
48
+ operation: PluginOperation;
49
+ /** The CLI's own message, or the adapter's when the CLI did not run or did not answer. */
50
+ message: string;
51
+ /** The CLI's `failureCode`, such as `not_found` or `command_source_refused`. */
52
+ failureCode?: string;
53
+ /** With `command_source_refused`: the command that the marketplace declares as the install. */
54
+ shownCommand?: string;
55
+ /** With `shownCommand`: the terminal command that lets the user confirm it. */
56
+ terminalCommand?: string;
57
+ /** The parsed `--json` output of a list: an array, or `{installed, available}`; for an overview, `{plugins, marketplaces}` plus `pluginsError` or `marketplacesError` for a list that failed. */
58
+ data?: unknown;
59
+ reload?: PluginReload;
60
+ }
61
+ export interface ExecOptions {
62
+ cwd: string;
63
+ env: Record<string, string | undefined>;
64
+ signal: AbortSignal;
65
+ timeoutMs: number;
66
+ }
67
+ export interface ExecOutput {
68
+ stdout: string;
69
+ stderr: string;
70
+ /** The exit code. A run that ends with a non-zero code is a result, not an error. */
71
+ code: number;
72
+ }
73
+ /** Runs a program without a shell. Rejects when it cannot start, is aborted,
74
+ * times out, or prints too much. */
75
+ export type ExecLike = (file: string, args: string[], options: ExecOptions) => Promise<ExecOutput>;
76
+ export interface PluginCommandDeps {
77
+ cliPath: () => Promise<string>;
78
+ cwd: string;
79
+ env: Record<string, string | undefined>;
80
+ signal: AbortSignal;
81
+ /** Read after the CLI ends: the session's query can be replaced while it runs. */
82
+ query: () => Query | undefined;
83
+ logError: (message: string) => void;
84
+ exec?: ExecLike;
85
+ }
86
+ /**
87
+ * Runs a parsed `/plugin` command and, after a change, reloads the session's
88
+ * plugins. A failure is in the result: this never throws.
89
+ */
90
+ export declare function runPluginCommand(command: PluginCommand, deps: PluginCommandDeps): Promise<PluginCommandResult>;
91
+ /** The chat reply for a result of {@link runPluginCommand}. */
92
+ export declare function pluginCommandMarkdown(result: PluginCommandResult): string;
93
+ export {};
94
+ //# sourceMappingURL=plugin-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-command.d.ts","sourceRoot":"","sources":["../src/plugin-command.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAG5D,uFAAuF;AACvF,KAAK,aAAa,GAAG,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAErE,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,0DAA0D;AAC1D,eAAO,MAAM,wBAAwB,EAAE,gBAItC,CAAC;AAEF,gDAAgD;AAChD,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,SAAS,GACT,WAAW,GACX,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,iBAAiB,GACjB,kBAAkB,GAClB,oBAAoB,GACpB,oBAAoB,CAAC;AAEzB,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG,UAAU,GAAG,OAAO,CAAC;AAExE,MAAM,MAAM,aAAa;AACvB,oFAAoF;AAClF;IAAE,IAAI,EAAE,UAAU,CAAA;CAA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