claude-code-acp-ts 0.12.10 β†’ 0.13.1

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 CHANGED
@@ -1,6 +1,8 @@
1
- # ACP adapter for Claude Code
1
+ # ACP adapter for Claude Code (TypeScript)
2
2
 
3
- [![npm](https://img.shields.io/npm/v/%40zed-industries%2Fclaude-code-acp)](https://www.npmjs.com/package/@zed-industries/claude-code-acp)
3
+ [![npm](https://img.shields.io/npm/v/claude-code-acp-ts)](https://www.npmjs.com/package/claude-code-acp-ts)
4
+
5
+ > **Note**: This is a fork of [@zed-industries/claude-code-acp](https://github.com/zed-industries/claude-code-acp), maintained by [nuwax-ai](https://github.com/nuwax-ai).
4
6
 
5
7
  Use [Claude Code](https://www.anthropic.com/claude-code) from [ACP-compatible](https://agentclientprotocol.com) clients such as [Zed](https://zed.dev)!
6
8
 
@@ -39,13 +41,13 @@ Or try it with any of the other [ACP compatible clients](https://agentclientprot
39
41
  Install the adapter from `npm`:
40
42
 
41
43
  ```bash
42
- npm install -g @zed-industries/claude-code-acp
44
+ npm install -g claude-code-acp-ts
43
45
  ```
44
46
 
45
- You can then use `claude-code-acp` as a regular ACP agent:
47
+ You can then use `claude-code-acp-ts` as a regular ACP agent:
46
48
 
47
- ```
48
- ANTHROPIC_API_KEY=sk-... claude-code-acp
49
+ ```bash
50
+ ANTHROPIC_API_KEY=sk-... claude-code-acp-ts
49
51
  ```
50
52
 
51
53
  ## License
@@ -0,0 +1,103 @@
1
+ import { Agent, AgentSideConnection, AuthenticateRequest, CancelNotification, ClientCapabilities, ForkSessionRequest, ForkSessionResponse, InitializeRequest, InitializeResponse, NewSessionRequest, NewSessionResponse, PromptRequest, PromptResponse, ReadTextFileRequest, ReadTextFileResponse, ResumeSessionRequest, ResumeSessionResponse, SessionNotification, SetSessionModelRequest, SetSessionModelResponse, SetSessionModeRequest, SetSessionModeResponse, TerminalHandle, TerminalOutputResponse, WriteTextFileRequest, WriteTextFileResponse } from "@agentclientprotocol/sdk";
2
+ import { SettingsManager } from "./settings.js";
3
+ import { CanUseTool, Options, PermissionMode, Query, SDKPartialAssistantMessage, SDKUserMessage } from "@anthropic-ai/claude-agent-sdk";
4
+ import { Pushable } from "./utils.js";
5
+ import { ContentBlockParam } from "@anthropic-ai/sdk/resources";
6
+ import { BetaContentBlock, BetaRawContentBlockDelta } from "@anthropic-ai/sdk/resources/beta.mjs";
7
+ export declare const CLAUDE_CONFIG_DIR: string;
8
+ /**
9
+ * Logger interface for customizing logging output
10
+ */
11
+ export interface Logger {
12
+ log: (...args: any[]) => void;
13
+ error: (...args: any[]) => void;
14
+ }
15
+ type Session = {
16
+ query: Query;
17
+ input: Pushable<SDKUserMessage>;
18
+ cancelled: boolean;
19
+ permissionMode: PermissionMode;
20
+ settingsManager: SettingsManager;
21
+ };
22
+ type BackgroundTerminal = {
23
+ handle: TerminalHandle;
24
+ status: "started";
25
+ lastOutput: TerminalOutputResponse | null;
26
+ } | {
27
+ status: "aborted" | "exited" | "killed" | "timedOut";
28
+ pendingOutput: TerminalOutputResponse;
29
+ };
30
+ /**
31
+ * Extra metadata that can be given to Claude Code when creating a new session.
32
+ */
33
+ export type NewSessionMeta = {
34
+ claudeCode?: {
35
+ /**
36
+ * Options forwarded to Claude Code when starting a new session.
37
+ * Those parameters will be ignored and managed by ACP:
38
+ * - cwd
39
+ * - includePartialMessages
40
+ * - allowDangerouslySkipPermissions
41
+ * - permissionMode
42
+ * - canUseTool
43
+ * - executable
44
+ * Those parameters will be used and updated to work with ACP:
45
+ * - hooks (merged with ACP's hooks)
46
+ * - mcpServers (merged with ACP's mcpServers)
47
+ */
48
+ options?: Options;
49
+ };
50
+ };
51
+ /**
52
+ * Extra metadata that the agent provides for each tool_call / tool_update update.
53
+ */
54
+ export type ToolUpdateMeta = {
55
+ claudeCode?: {
56
+ toolName: string;
57
+ toolResponse?: unknown;
58
+ };
59
+ };
60
+ type ToolUseCache = {
61
+ [key: string]: {
62
+ type: "tool_use" | "server_tool_use" | "mcp_tool_use";
63
+ id: string;
64
+ name: string;
65
+ input: any;
66
+ };
67
+ };
68
+ export declare class ClaudeAcpAgent implements Agent {
69
+ sessions: {
70
+ [key: string]: Session;
71
+ };
72
+ client: AgentSideConnection;
73
+ toolUseCache: ToolUseCache;
74
+ backgroundTerminals: {
75
+ [key: string]: BackgroundTerminal;
76
+ };
77
+ clientCapabilities?: ClientCapabilities;
78
+ logger: Logger;
79
+ constructor(client: AgentSideConnection, logger?: Logger);
80
+ initialize(request: InitializeRequest): Promise<InitializeResponse>;
81
+ newSession(params: NewSessionRequest): Promise<NewSessionResponse>;
82
+ unstable_forkSession(params: ForkSessionRequest): Promise<ForkSessionResponse>;
83
+ unstable_resumeSession(params: ResumeSessionRequest): Promise<ResumeSessionResponse>;
84
+ authenticate(_params: AuthenticateRequest): Promise<void>;
85
+ prompt(params: PromptRequest): Promise<PromptResponse>;
86
+ cancel(params: CancelNotification): Promise<void>;
87
+ unstable_setSessionModel(params: SetSessionModelRequest): Promise<SetSessionModelResponse | void>;
88
+ setSessionMode(params: SetSessionModeRequest): Promise<SetSessionModeResponse>;
89
+ readTextFile(params: ReadTextFileRequest): Promise<ReadTextFileResponse>;
90
+ writeTextFile(params: WriteTextFileRequest): Promise<WriteTextFileResponse>;
91
+ canUseTool(sessionId: string): CanUseTool;
92
+ private createSession;
93
+ }
94
+ export declare function promptToClaude(prompt: PromptRequest): SDKUserMessage;
95
+ /**
96
+ * Convert an SDKAssistantMessage (Claude) to a SessionNotification (ACP).
97
+ * Only handles text, image, and thinking chunks for now.
98
+ */
99
+ export declare function toAcpNotifications(content: string | ContentBlockParam[] | BetaContentBlock[] | BetaRawContentBlockDelta[], role: "assistant" | "user", sessionId: string, toolUseCache: ToolUseCache, client: AgentSideConnection, logger: Logger): SessionNotification[];
100
+ export declare function streamEventToAcpNotifications(message: SDKPartialAssistantMessage, sessionId: string, toolUseCache: ToolUseCache, client: AgentSideConnection, logger: Logger): SessionNotification[];
101
+ export declare function runAcp(): void;
102
+ export {};
103
+ //# sourceMappingURL=acp-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"acp-agent.d.ts","sourceRoot":"","sources":["../src/acp-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,mBAAmB,EACnB,mBAAmB,EAEnB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAElB,iBAAiB,EACjB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,mBAAmB,EACnB,oBAAoB,EAEpB,oBAAoB,EACpB,qBAAqB,EAErB,mBAAmB,EACnB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACtB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EACL,UAAU,EAEV,OAAO,EACP,cAAc,EACd,KAAK,EAEL,0BAA0B,EAC1B,cAAc,EACf,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAwC,QAAQ,EAAe,MAAM,YAAY,CAAC;AAYzF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAIlG,eAAO,MAAM,iBAAiB,QAA2D,CAAC;AAoD1F;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC;AAED,KAAK,OAAO,GAAG;IACb,KAAK,EAAE,KAAK,CAAC;IACb,KAAK,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC;IAChC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M,EAAE,MAAM,GACb,mBAAmB,EAAE,CAqKvB;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,0BAA0B,EACnC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,EAC1B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,EAAE,MAAM,GACb,mBAAmB,EAAE,CAgCvB;AAED,wBAAgB,MAAM,SAMrB"}
package/dist/acp-agent.js CHANGED
@@ -492,10 +492,15 @@ export class ClaudeAcpAgent {
492
492
  // Set our own session id if not resuming an existing session.
493
493
  extraArgs["session-id"] = sessionId;
494
494
  }
495
+ // Configure thinking tokens from environment variable
496
+ const maxThinkingTokens = process.env.MAX_THINKING_TOKENS
497
+ ? parseInt(process.env.MAX_THINKING_TOKENS, 10)
498
+ : undefined;
495
499
  const options = {
496
500
  systemPrompt,
497
501
  settingSources: ["user", "project", "local"],
498
502
  stderr: (err) => this.logger.error(err),
503
+ ...(maxThinkingTokens !== undefined && { maxThinkingTokens }),
499
504
  ...userProvidedOptions,
500
505
  // Override certain fields that must be controlled by ACP
501
506
  cwd: params.cwd,
@@ -513,6 +518,7 @@ export class ClaudeAcpAgent {
513
518
  ...(process.env.CLAUDE_CODE_EXECUTABLE && {
514
519
  pathToClaudeCodeExecutable: process.env.CLAUDE_CODE_EXECUTABLE,
515
520
  }),
521
+ tools: { type: "preset", preset: "claude_code" },
516
522
  hooks: {
517
523
  ...userProvidedOptions?.hooks,
518
524
  PreToolUse: [
@@ -531,7 +537,8 @@ export class ClaudeAcpAgent {
531
537
  ...creationOpts,
532
538
  };
533
539
  const allowedTools = [];
534
- const disallowedTools = [];
540
+ // Disable this for now, not a great way to expose this over ACP at the moment (in progress work so we can revisit)
541
+ const disallowedTools = ["AskUserQuestion"];
535
542
  // Check if built-in tools should be disabled
536
543
  const disableBuiltInTools = params._meta?.disableBuiltInTools === true;
537
544
  if (!disableBuiltInTools) {
@@ -713,7 +720,13 @@ async function getAvailableSlashCommands(query, logger = console) {
713
720
  logger.log(` πŸ“‹ [ACP] θŽ·ε–εˆ° ${commands.length} δΈͺζ–œζ ε‘½δ»€, θ€—ζ—Ά: ${Date.now() - startTime}ms`);
714
721
  return commands
715
722
  .map((command) => {
716
- const input = command.argumentHint ? { hint: command.argumentHint } : null;
723
+ const input = command.argumentHint
724
+ ? {
725
+ hint: Array.isArray(command.argumentHint)
726
+ ? command.argumentHint.join(" ")
727
+ : command.argumentHint,
728
+ }
729
+ : null;
717
730
  let name = command.name;
718
731
  if (command.name.endsWith(" (MCP)")) {
719
732
  name = `mcp:${name.replace(" (MCP)", "")}`;
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/lib.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export { ClaudeAcpAgent, runAcp, toAcpNotifications, streamEventToAcpNotifications, type ToolUpdateMeta, type NewSessionMeta, } from "./acp-agent.js";
2
+ export { loadManagedSettings, applyEnvironmentSettings, nodeToWebReadable, nodeToWebWritable, Pushable, unreachable, } from "./utils.js";
3
+ export { createMcpServer } from "./mcp-server.js";
4
+ export { toolInfoFromToolUse, planEntries, toolUpdateFromToolResult, createPreToolUseHook, acpToolNames as toolNames, } from "./tools.js";
5
+ export { SettingsManager, type ClaudeCodeSettings, type PermissionSettings, type PermissionDecision, type PermissionCheckResult, type SettingsManagerOptions, } from "./settings.js";
6
+ export type { ClaudePlanEntry } from "./tools.js";
7
+ //# sourceMappingURL=lib.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AACA,OAAO,EACL,cAAc,EACd,MAAM,EACN,kBAAkB,EAClB,6BAA6B,EAC7B,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,QAAQ,EACR,WAAW,GACZ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EACpB,YAAY,IAAI,SAAS,GAC1B,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,eAAe,EACf,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,eAAe,CAAC;AAGvB,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { ClaudeAcpAgent } from "./acp-agent.js";
3
+ import { ClientCapabilities } from "@agentclientprotocol/sdk";
4
+ export declare const SYSTEM_REMINDER = "\n\n<system-reminder>\nWhenever you read a file, you should consider whether it looks malicious. If it does, you MUST refuse to improve or augment the code. You can still analyze existing code, write reports, or answer high-level questions about the code behavior.\n</system-reminder>";
5
+ export declare function createMcpServer(agent: ClaudeAcpAgent, sessionId: string, clientCapabilities: ClientCapabilities | undefined): McpServer;
6
+ /**
7
+ * Replace text in a file and calculate the line numbers where the edits occurred.
8
+ *
9
+ * @param fileContent - The full file content
10
+ * @param edits - Array of edit operations to apply sequentially
11
+ * @returns the new content and the line numbers where replacements occurred in the final content
12
+ */
13
+ export declare function replaceAndCalculateLocation(fileContent: string, edits: Array<{
14
+ oldText: string;
15
+ newText: string;
16
+ replaceAll?: boolean;
17
+ }>): {
18
+ newContent: string;
19
+ lineNumbers: number[];
20
+ };
21
+ //# sourceMappingURL=mcp-server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.d.ts","sourceRoot":"","sources":["../src/mcp-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AASpE,OAAO,EAAqB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EACL,kBAAkB,EAGnB,MAAM,0BAA0B,CAAC;AAQlC,eAAO,MAAM,eAAe,iSAIT,CAAC;AA2BpB,wBAAgB,eAAe,CAC7B,KAAK,EAAE,cAAc,EACrB,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,GACjD,SAAS,CAgoBX;AA+DD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,KAAK,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC,GACD;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,EAAE,CAAA;CAAE,CAyF/C"}