@sudocode-ai/claude-code-acp 0.12.9 → 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 +3 -9
- package/dist/acp-agent.d.ts +194 -0
- package/dist/acp-agent.d.ts.map +1 -0
- package/dist/acp-agent.js +371 -29
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lib.d.ts +7 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/mcp-server.d.ts +21 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +214 -158
- package/dist/settings.d.ts +123 -0
- package/dist/settings.d.ts.map +1 -0
- package/dist/tools.d.ts +50 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +62 -39
- package/dist/utils.d.ts +32 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +22 -12
- package/dist/tests/acp-agent.test.js +0 -753
- package/dist/tests/extract-lines.test.js +0 -79
- package/dist/tests/fork-session.test.js +0 -83
- package/dist/tests/replace-and-calculate-location.test.js +0 -266
- package/dist/tests/settings.test.js +0 -462
package/dist/tools.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SYSTEM_REMINDER } from "./mcp-server.js";
|
|
2
|
+
import * as diff from "diff";
|
|
2
3
|
const acpUnqualifiedToolNames = {
|
|
3
4
|
read: "Read",
|
|
4
5
|
edit: "Edit",
|
|
@@ -17,7 +18,7 @@ export const acpToolNames = {
|
|
|
17
18
|
bashOutput: ACP_TOOL_NAME_PREFIX + acpUnqualifiedToolNames.bashOutput,
|
|
18
19
|
};
|
|
19
20
|
export const EDIT_TOOL_NAMES = [acpToolNames.edit, acpToolNames.write];
|
|
20
|
-
export function toolInfoFromToolUse(toolUse
|
|
21
|
+
export function toolInfoFromToolUse(toolUse) {
|
|
21
22
|
const name = toolUse.name;
|
|
22
23
|
const input = toolUse.input;
|
|
23
24
|
switch (name) {
|
|
@@ -130,27 +131,6 @@ export function toolInfoFromToolUse(toolUse, cachedFileContent, logger = console
|
|
|
130
131
|
case acpToolNames.edit:
|
|
131
132
|
case "Edit": {
|
|
132
133
|
const path = input?.file_path ?? input?.file_path;
|
|
133
|
-
let oldText = input.old_string ?? null;
|
|
134
|
-
let newText = input.new_string ?? "";
|
|
135
|
-
let affectedLines = [];
|
|
136
|
-
if (path && oldText) {
|
|
137
|
-
try {
|
|
138
|
-
const oldContent = cachedFileContent[path] || "";
|
|
139
|
-
const newContent = replaceAndCalculateLocation(oldContent, [
|
|
140
|
-
{
|
|
141
|
-
oldText,
|
|
142
|
-
newText,
|
|
143
|
-
replaceAll: false,
|
|
144
|
-
},
|
|
145
|
-
]);
|
|
146
|
-
oldText = oldContent;
|
|
147
|
-
newText = newContent.newContent;
|
|
148
|
-
affectedLines = newContent.lineNumbers;
|
|
149
|
-
}
|
|
150
|
-
catch (e) {
|
|
151
|
-
logger.error(e);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
134
|
return {
|
|
155
135
|
title: path ? `Edit \`${path}\`` : "Edit",
|
|
156
136
|
kind: "edit",
|
|
@@ -159,16 +139,12 @@ export function toolInfoFromToolUse(toolUse, cachedFileContent, logger = console
|
|
|
159
139
|
{
|
|
160
140
|
type: "diff",
|
|
161
141
|
path,
|
|
162
|
-
oldText,
|
|
163
|
-
newText,
|
|
142
|
+
oldText: input.old_string ?? null,
|
|
143
|
+
newText: input.new_string ?? "",
|
|
164
144
|
},
|
|
165
145
|
]
|
|
166
146
|
: [],
|
|
167
|
-
locations: path
|
|
168
|
-
? affectedLines.length > 0
|
|
169
|
-
? affectedLines.map((line) => ({ line, path }))
|
|
170
|
-
: [{ path }]
|
|
171
|
-
: [],
|
|
147
|
+
locations: path ? [{ path }] : undefined,
|
|
172
148
|
};
|
|
173
149
|
}
|
|
174
150
|
case acpToolNames.write: {
|
|
@@ -271,7 +247,9 @@ export function toolInfoFromToolUse(toolUse, cachedFileContent, logger = console
|
|
|
271
247
|
if (input.multiline) {
|
|
272
248
|
label += " -P";
|
|
273
249
|
}
|
|
274
|
-
|
|
250
|
+
if (input.pattern) {
|
|
251
|
+
label += ` "${input.pattern}"`;
|
|
252
|
+
}
|
|
275
253
|
if (input.path) {
|
|
276
254
|
label += ` ${input.path}`;
|
|
277
255
|
}
|
|
@@ -355,6 +333,13 @@ export function toolInfoFromToolUse(toolUse, cachedFileContent, logger = console
|
|
|
355
333
|
}
|
|
356
334
|
}
|
|
357
335
|
export function toolUpdateFromToolResult(toolResult, toolUse) {
|
|
336
|
+
if ("is_error" in toolResult &&
|
|
337
|
+
toolResult.is_error &&
|
|
338
|
+
toolResult.content &&
|
|
339
|
+
toolResult.content.length > 0) {
|
|
340
|
+
// Only return errors
|
|
341
|
+
return toAcpContentUpdate(toolResult.content, true);
|
|
342
|
+
}
|
|
358
343
|
switch (toolUse?.name) {
|
|
359
344
|
case "Read":
|
|
360
345
|
case acpToolNames.read:
|
|
@@ -385,19 +370,57 @@ export function toolUpdateFromToolResult(toolResult, toolUse) {
|
|
|
385
370
|
};
|
|
386
371
|
}
|
|
387
372
|
return {};
|
|
373
|
+
case acpToolNames.edit: {
|
|
374
|
+
const content = [];
|
|
375
|
+
const locations = [];
|
|
376
|
+
if (Array.isArray(toolResult.content) &&
|
|
377
|
+
toolResult.content.length > 0 &&
|
|
378
|
+
"text" in toolResult.content[0] &&
|
|
379
|
+
typeof toolResult.content[0].text === "string") {
|
|
380
|
+
const patches = diff.parsePatch(toolResult.content[0].text);
|
|
381
|
+
console.error(JSON.stringify(patches));
|
|
382
|
+
for (const { oldFileName, newFileName, hunks } of patches) {
|
|
383
|
+
for (const { lines, newStart } of hunks) {
|
|
384
|
+
const oldText = [];
|
|
385
|
+
const newText = [];
|
|
386
|
+
for (const line of lines) {
|
|
387
|
+
if (line.startsWith("-")) {
|
|
388
|
+
oldText.push(line.slice(1));
|
|
389
|
+
}
|
|
390
|
+
else if (line.startsWith("+")) {
|
|
391
|
+
newText.push(line.slice(1));
|
|
392
|
+
}
|
|
393
|
+
else {
|
|
394
|
+
oldText.push(line.slice(1));
|
|
395
|
+
newText.push(line.slice(1));
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (oldText.length > 0 || newText.length > 0) {
|
|
399
|
+
locations.push({ path: newFileName || oldFileName, line: newStart });
|
|
400
|
+
content.push({
|
|
401
|
+
type: "diff",
|
|
402
|
+
path: newFileName || oldFileName,
|
|
403
|
+
oldText: oldText.join("\n") || null,
|
|
404
|
+
newText: newText.join("\n"),
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
const result = {};
|
|
411
|
+
if (content.length > 0) {
|
|
412
|
+
result.content = content;
|
|
413
|
+
}
|
|
414
|
+
if (locations.length > 0) {
|
|
415
|
+
result.locations = locations;
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
}
|
|
388
419
|
case acpToolNames.bash:
|
|
389
420
|
case "edit":
|
|
390
421
|
case "Edit":
|
|
391
|
-
case acpToolNames.edit:
|
|
392
422
|
case acpToolNames.write:
|
|
393
423
|
case "Write": {
|
|
394
|
-
if ("is_error" in toolResult &&
|
|
395
|
-
toolResult.is_error &&
|
|
396
|
-
toolResult.content &&
|
|
397
|
-
toolResult.content.length > 0) {
|
|
398
|
-
// Only return errors
|
|
399
|
-
return toAcpContentUpdate(toolResult.content, true);
|
|
400
|
-
}
|
|
401
424
|
return {};
|
|
402
425
|
}
|
|
403
426
|
case "ExitPlanMode": {
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Readable, Writable } from "node:stream";
|
|
2
|
+
import { WritableStream, ReadableStream } from "node:stream/web";
|
|
3
|
+
import { Logger } from "./acp-agent.js";
|
|
4
|
+
import { ClaudeCodeSettings } from "./settings.js";
|
|
5
|
+
export declare class Pushable<T> implements AsyncIterable<T> {
|
|
6
|
+
private queue;
|
|
7
|
+
private resolvers;
|
|
8
|
+
private done;
|
|
9
|
+
push(item: T): void;
|
|
10
|
+
end(): void;
|
|
11
|
+
[Symbol.asyncIterator](): AsyncIterator<T>;
|
|
12
|
+
}
|
|
13
|
+
export declare function nodeToWebWritable(nodeStream: Writable): WritableStream<Uint8Array>;
|
|
14
|
+
export declare function nodeToWebReadable(nodeStream: Readable): ReadableStream<Uint8Array>;
|
|
15
|
+
export declare function unreachable(value: never, logger?: Logger): void;
|
|
16
|
+
export declare function sleep(time: number): Promise<void>;
|
|
17
|
+
export declare function loadManagedSettings(): ClaudeCodeSettings | null;
|
|
18
|
+
export declare function applyEnvironmentSettings(settings: ClaudeCodeSettings): void;
|
|
19
|
+
export interface ExtractLinesResult {
|
|
20
|
+
content: string;
|
|
21
|
+
wasLimited: boolean;
|
|
22
|
+
linesRead: number;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Extracts lines from file content with byte limit enforcement.
|
|
26
|
+
*
|
|
27
|
+
* @param fullContent - The complete file content
|
|
28
|
+
* @param maxContentLength - Maximum number of UTF-16 Code Units to return
|
|
29
|
+
* @returns Object containing extracted content and metadata
|
|
30
|
+
*/
|
|
31
|
+
export declare function extractLinesWithByteLimit(fullContent: string, maxContentLength: number): ExtractLinesResult;
|
|
32
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAA0B,MAAM,eAAe,CAAC;AAG3E,qBAAa,QAAQ,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,SAAS,CAA8C;IAC/D,OAAO,CAAC,IAAI,CAAS;IAErB,IAAI,CAAC,IAAI,EAAE,CAAC;IASZ,GAAG;IAQH,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC;CAgB3C;AAGD,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAclF;AAED,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,QAAQ,GAAG,cAAc,CAAC,UAAU,CAAC,CAUlF;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,GAAE,MAAgB,QAQjE;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjD;AAED,wBAAgB,mBAAmB,IAAI,kBAAkB,GAAG,IAAI,CAM/D;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAM3E;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,MAAM,GACvB,kBAAkB,CA8CpB"}
|
package/package.json
CHANGED
|
@@ -3,15 +3,24 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.13.1",
|
|
7
7
|
"description": "An ACP-compatible coding agent powered by the Claude Code SDK (TypeScript)",
|
|
8
8
|
"main": "dist/lib.js",
|
|
9
|
+
"types": "dist/lib.d.ts",
|
|
9
10
|
"bin": {
|
|
10
11
|
"claude-code-acp": "./dist/index.js"
|
|
11
12
|
},
|
|
12
13
|
"type": "module",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/lib.d.ts",
|
|
17
|
+
"import": "./dist/lib.js"
|
|
18
|
+
},
|
|
19
|
+
"./*": "./*"
|
|
20
|
+
},
|
|
13
21
|
"files": [
|
|
14
22
|
"dist/",
|
|
23
|
+
"!dist/tests/",
|
|
15
24
|
"README.md",
|
|
16
25
|
"LICENSE",
|
|
17
26
|
"package.json"
|
|
@@ -25,6 +34,7 @@
|
|
|
25
34
|
"format": "prettier --write .",
|
|
26
35
|
"format:check": "prettier --check .",
|
|
27
36
|
"check": "npm run lint && npm run format:check",
|
|
37
|
+
"sync-upstream": "git merge upstream/main",
|
|
28
38
|
"test": "vitest",
|
|
29
39
|
"test:integration": "RUN_INTEGRATION_TESTS=true vitest run",
|
|
30
40
|
"test:run": "vitest run",
|
|
@@ -56,23 +66,23 @@
|
|
|
56
66
|
"author": "Sudocode AI",
|
|
57
67
|
"license": "Apache-2.0",
|
|
58
68
|
"dependencies": {
|
|
59
|
-
"@agentclientprotocol/sdk": "0.
|
|
60
|
-
"@anthropic-ai/claude-agent-sdk": "0.
|
|
61
|
-
"@modelcontextprotocol/sdk": "1.25.
|
|
62
|
-
"diff": "8.0.
|
|
63
|
-
"minimatch": "
|
|
69
|
+
"@agentclientprotocol/sdk": "0.13.0",
|
|
70
|
+
"@anthropic-ai/claude-agent-sdk": "0.2.7",
|
|
71
|
+
"@modelcontextprotocol/sdk": "1.25.2",
|
|
72
|
+
"diff": "8.0.3",
|
|
73
|
+
"minimatch": "10.1.1"
|
|
64
74
|
},
|
|
65
75
|
"devDependencies": {
|
|
66
76
|
"@anthropic-ai/sdk": "0.71.2",
|
|
67
|
-
"@types/node": "25.0.
|
|
68
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
69
|
-
"@typescript-eslint/parser": "8.
|
|
77
|
+
"@types/node": "25.0.8",
|
|
78
|
+
"@typescript-eslint/eslint-plugin": "8.53.0",
|
|
79
|
+
"@typescript-eslint/parser": "8.53.0",
|
|
70
80
|
"eslint": "9.39.2",
|
|
71
81
|
"eslint-config-prettier": "10.1.8",
|
|
72
|
-
"globals": "
|
|
73
|
-
"prettier": "3.
|
|
82
|
+
"globals": "17.0.0",
|
|
83
|
+
"prettier": "3.8.0",
|
|
74
84
|
"ts-node": "10.9.2",
|
|
75
85
|
"typescript": "5.9.3",
|
|
76
|
-
"vitest": "4.0.
|
|
86
|
+
"vitest": "4.0.17"
|
|
77
87
|
}
|
|
78
88
|
}
|