@nathapp/nax-agent-acp 0.3.1 → 0.84.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.
- package/CHANGELOG.md +16 -0
- package/README.md +86 -4
- package/bin/nax-agent.js +4 -0
- package/dist/client/elicitation.d.ts +4 -2
- package/dist/client/elicitation.js +14 -1
- package/dist/client/errors.d.ts +1 -1
- package/dist/client/errors.js +2 -2
- package/dist/client/open.js +17 -3
- package/dist/server/auth.d.ts +45 -0
- package/dist/server/auth.js +87 -0
- package/dist/server/capabilities.d.ts +7 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/cli.d.ts +26 -0
- package/dist/server/cli.js +87 -0
- package/dist/server/client-port.d.ts +39 -0
- package/dist/server/client-port.js +49 -0
- package/dist/server/connection.d.ts +22 -0
- package/dist/server/connection.js +56 -0
- package/dist/server/errors.d.ts +21 -0
- package/dist/server/errors.js +70 -0
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +6 -1
- package/dist/server/logger.d.ts +7 -0
- package/dist/server/logger.js +25 -0
- package/dist/server/login.d.ts +18 -0
- package/dist/server/login.js +29 -0
- package/dist/server/main.d.ts +19 -0
- package/dist/server/main.js +120 -0
- package/dist/server/nax-config.d.ts +30 -0
- package/dist/server/nax-config.js +138 -0
- package/dist/server/open-session.d.ts +37 -0
- package/dist/server/open-session.js +55 -0
- package/dist/server/options.d.ts +27 -0
- package/dist/server/options.js +55 -0
- package/dist/server/permissions.d.ts +44 -0
- package/dist/server/permissions.js +157 -0
- package/dist/server/process-entry.d.ts +15 -0
- package/dist/server/process-entry.js +28 -0
- package/dist/server/prompt.d.ts +8 -0
- package/dist/server/prompt.js +29 -0
- package/dist/server/questions.d.ts +33 -0
- package/dist/server/questions.js +79 -0
- package/dist/server/registry-open.d.ts +33 -0
- package/dist/server/registry-open.js +62 -0
- package/dist/server/registry.d.ts +64 -0
- package/dist/server/registry.js +262 -0
- package/dist/server/server-session.d.ts +43 -0
- package/dist/server/server-session.js +221 -0
- package/dist/server/session-config.d.ts +27 -0
- package/dist/server/session-config.js +93 -0
- package/dist/server/storage.d.ts +49 -0
- package/dist/server/storage.js +191 -0
- package/dist/server/translate/diff.d.ts +30 -0
- package/dist/server/translate/diff.js +81 -0
- package/dist/server/translate/events.d.ts +37 -0
- package/dist/server/translate/events.js +126 -0
- package/dist/server/translate/notice.d.ts +10 -0
- package/dist/server/translate/notice.js +14 -0
- package/dist/server/translate/replay.d.ts +11 -0
- package/dist/server/translate/replay.js +53 -0
- package/dist/server/translate/stop.d.ts +22 -0
- package/dist/server/translate/stop.js +48 -0
- package/dist/server/translate/tool-kind.d.ts +9 -0
- package/dist/server/translate/tool-kind.js +67 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +17 -0
- package/package.json +5 -2
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A turn's end as the answer to `session/prompt` (S5 spec §4.4). `errored` is a
|
|
3
|
+
* JSON-RPC error so editors show a failure, not a normal stop; a credential
|
|
4
|
+
* failure is `auth_required` (S5-4 M-32). `interrupted` only occurs after a
|
|
5
|
+
* resume and is reported the same way if it ever reaches here.
|
|
6
|
+
*/
|
|
7
|
+
import { RequestError } from "@agentclientprotocol/sdk";
|
|
8
|
+
import { redactSecrets } from "@nathapp/nax-agent";
|
|
9
|
+
import { authRequired, isAuthFailureCode } from "#src/server/errors";
|
|
10
|
+
import { announce } from "#src/server/translate/notice";
|
|
11
|
+
export function toAcpUsage(usage) {
|
|
12
|
+
const cacheRead = usage.cacheReadTokens;
|
|
13
|
+
const cacheWrite = usage.cacheWriteTokens;
|
|
14
|
+
return {
|
|
15
|
+
inputTokens: usage.inputTokens,
|
|
16
|
+
outputTokens: usage.outputTokens,
|
|
17
|
+
...(cacheRead !== undefined ? { cachedReadTokens: cacheRead } : {}),
|
|
18
|
+
...(cacheWrite !== undefined ? { cachedWriteTokens: cacheWrite } : {}),
|
|
19
|
+
totalTokens: usage.inputTokens + usage.outputTokens + (cacheRead ?? 0) + (cacheWrite ?? 0),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function failure(code, message) {
|
|
23
|
+
if (isAuthFailureCode(code))
|
|
24
|
+
return { kind: "error", error: authRequired(redactSecrets(message), { code, message }) };
|
|
25
|
+
return { kind: "error", error: RequestError.internalError({ code, message }, message) };
|
|
26
|
+
}
|
|
27
|
+
/** `notices`: whether the client advertised `session.notices` (else warnings become agent text). */
|
|
28
|
+
export function promptOutcome(end, turnTimeoutSeconds, notices) {
|
|
29
|
+
const usage = toAcpUsage(end.usage);
|
|
30
|
+
switch (end.status) {
|
|
31
|
+
case "completed":
|
|
32
|
+
return { kind: "response", response: { stopReason: "end_turn", usage }, notices: [] };
|
|
33
|
+
case "cancelled":
|
|
34
|
+
return { kind: "response", response: { stopReason: "cancelled", usage }, notices: [] };
|
|
35
|
+
case "timed_out":
|
|
36
|
+
return {
|
|
37
|
+
kind: "response",
|
|
38
|
+
response: { stopReason: "max_turn_requests", usage },
|
|
39
|
+
notices: [
|
|
40
|
+
announce(notices, "warning", "Turn timed out", `The turn reached its ${turnTimeoutSeconds}s time limit and was stopped.`),
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
case "errored":
|
|
44
|
+
return failure(end.error?.code ?? "AGENT_TURN_ERRORED", end.error?.message ?? "The turn failed");
|
|
45
|
+
case "interrupted":
|
|
46
|
+
return failure("AGENT_TURN_INTERRUPTED", "The turn was interrupted");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ToolCallLocation, ToolKind } from "@agentclientprotocol/sdk";
|
|
2
|
+
export declare const TITLE_DETAIL_MAX = 60;
|
|
3
|
+
export declare function toolKind(name: string): ToolKind;
|
|
4
|
+
export declare function inputString(input: unknown, key: string): string | undefined;
|
|
5
|
+
/** One line, no control or invisible (format, bidi) characters, cut by code point. */
|
|
6
|
+
export declare function displayLine(text: string): string;
|
|
7
|
+
export declare function toolTitle(name: string, input: unknown): string;
|
|
8
|
+
export declare function resolveToolPath(cwd: string, path: string): string;
|
|
9
|
+
export declare function toolLocations(name: string, input: unknown, cwd: string): ToolCallLocation[] | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a native tool call is shown to an ACP client (S5 spec §4.2): its kind, a
|
|
3
|
+
* one-line title and the file it touches. Inputs are model-written, so every
|
|
4
|
+
* field is checked before use and titles are stripped of control characters.
|
|
5
|
+
*/
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { isRecord, stripControl, stripInvisible } from "#src/client/text";
|
|
8
|
+
export const TITLE_DETAIL_MAX = 60;
|
|
9
|
+
const KIND_BY_TOOL = new Map([
|
|
10
|
+
["Read", "read"],
|
|
11
|
+
["ScratchpadRead", "read"],
|
|
12
|
+
["ScratchpadList", "read"],
|
|
13
|
+
["Glob", "search"],
|
|
14
|
+
["Grep", "search"],
|
|
15
|
+
["Edit", "edit"],
|
|
16
|
+
["Write", "edit"],
|
|
17
|
+
["ScratchpadWrite", "edit"],
|
|
18
|
+
["Delete", "delete"],
|
|
19
|
+
["Bash", "execute"],
|
|
20
|
+
["RunCommand", "execute"],
|
|
21
|
+
["Git", "execute"],
|
|
22
|
+
["GitCommit", "execute"],
|
|
23
|
+
]);
|
|
24
|
+
/** Tools whose `path` is a repository file (scratchpad paths are not). */
|
|
25
|
+
const FILE_TOOLS = new Set(["Read", "Write", "Edit", "Delete"]);
|
|
26
|
+
export function toolKind(name) {
|
|
27
|
+
return KIND_BY_TOOL.get(name) ?? "other";
|
|
28
|
+
}
|
|
29
|
+
export function inputString(input, key) {
|
|
30
|
+
if (!isRecord(input))
|
|
31
|
+
return undefined;
|
|
32
|
+
const value = input[key];
|
|
33
|
+
return typeof value === "string" ? value : undefined;
|
|
34
|
+
}
|
|
35
|
+
/** One line, no control or invisible (format, bidi) characters, cut by code point. */
|
|
36
|
+
export function displayLine(text) {
|
|
37
|
+
const points = Array.from(stripInvisible(stripControl(text)).replace(/\s+/g, " ").trim());
|
|
38
|
+
return points.length > TITLE_DETAIL_MAX ? `${points.slice(0, TITLE_DETAIL_MAX - 3).join("")}...` : points.join("");
|
|
39
|
+
}
|
|
40
|
+
export function toolTitle(name, input) {
|
|
41
|
+
const kind = toolKind(name);
|
|
42
|
+
const path = inputString(input, "path");
|
|
43
|
+
if (path !== undefined && (FILE_TOOLS.has(name) || name.startsWith("Scratchpad")))
|
|
44
|
+
return `${name} ${displayLine(path)}`;
|
|
45
|
+
const pattern = inputString(input, "pattern");
|
|
46
|
+
if (pattern !== undefined && kind === "search")
|
|
47
|
+
return `${name} ${displayLine(pattern)}`;
|
|
48
|
+
const command = inputString(input, "command");
|
|
49
|
+
if (command !== undefined && kind === "execute")
|
|
50
|
+
return `${name}: ${displayLine(command)}`;
|
|
51
|
+
const subcommand = inputString(input, "subcommand");
|
|
52
|
+
if (name === "Git" && subcommand !== undefined)
|
|
53
|
+
return `Git ${displayLine(subcommand)}`;
|
|
54
|
+
const message = inputString(input, "message");
|
|
55
|
+
if (name === "GitCommit" && message !== undefined)
|
|
56
|
+
return `GitCommit: ${displayLine(message.split("\n")[0] ?? "")}`;
|
|
57
|
+
return name;
|
|
58
|
+
}
|
|
59
|
+
export function resolveToolPath(cwd, path) {
|
|
60
|
+
return resolve(cwd, path);
|
|
61
|
+
}
|
|
62
|
+
export function toolLocations(name, input, cwd) {
|
|
63
|
+
if (!FILE_TOOLS.has(name))
|
|
64
|
+
return undefined;
|
|
65
|
+
const path = inputString(input, "path");
|
|
66
|
+
return path === undefined ? undefined : [{ path: resolveToolPath(cwd, path) }];
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function packageVersion(): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The package version. `package.json` sits two directories above this module in
|
|
3
|
+
* both layouts that run it: `src/server/` (workspace, bun) and `dist/server/`
|
|
4
|
+
* (published package, Node).
|
|
5
|
+
*/
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { NaxError } from "@nathapp/nax-agent";
|
|
8
|
+
const requireJson = createRequire(import.meta.url);
|
|
9
|
+
export function packageVersion() {
|
|
10
|
+
const manifest = requireJson("../../package.json");
|
|
11
|
+
if (typeof manifest === "object" && manifest !== null && "version" in manifest) {
|
|
12
|
+
const { version } = manifest;
|
|
13
|
+
if (typeof version === "string")
|
|
14
|
+
return version;
|
|
15
|
+
}
|
|
16
|
+
throw new NaxError("nax-agent-acp package.json has no version", "ACP_SERVER_NO_VERSION", { stage: "acp-server" });
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nax-agent-acp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.84.0",
|
|
4
4
|
"description": "ACP (Agent Client Protocol) backend for @nathapp/nax-agent sessions: drive Claude Code and other ACP agents through the nax-agent session API.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "William Khoo",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
"import": "./dist/server/index.js"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
+
"bin": {
|
|
35
|
+
"nax-agent": "./bin/nax-agent.js"
|
|
36
|
+
},
|
|
34
37
|
"imports": {
|
|
35
38
|
"#src/*": {
|
|
36
39
|
"types": "./dist/*.d.ts",
|
|
@@ -46,7 +49,7 @@
|
|
|
46
49
|
"zod": "^4.3.6"
|
|
47
50
|
},
|
|
48
51
|
"peerDependencies": {
|
|
49
|
-
"@nathapp/nax-agent": "^0.
|
|
52
|
+
"@nathapp/nax-agent": "^0.84.0"
|
|
50
53
|
},
|
|
51
54
|
"publishConfig": {
|
|
52
55
|
"access": "public",
|