@nathapp/nax-agent-acp 0.3.0 → 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.
Files changed (87) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +117 -22
  3. package/bin/nax-agent.js +4 -0
  4. package/dist/client/backend.js +11 -2
  5. package/dist/client/capabilities.d.ts +9 -3
  6. package/dist/client/capabilities.js +26 -5
  7. package/dist/client/elicitation.d.ts +4 -2
  8. package/dist/client/elicitation.js +14 -1
  9. package/dist/client/errors.d.ts +9 -1
  10. package/dist/client/errors.js +19 -2
  11. package/dist/client/events.d.ts +5 -1
  12. package/dist/client/events.js +31 -2
  13. package/dist/client/index.d.ts +2 -1
  14. package/dist/client/index.js +1 -0
  15. package/dist/client/launchable.d.ts +4 -0
  16. package/dist/client/launchable.js +17 -0
  17. package/dist/client/open.js +75 -13
  18. package/dist/client/options.d.ts +11 -0
  19. package/dist/client/options.js +17 -3
  20. package/dist/client/permissions.d.ts +2 -2
  21. package/dist/client/pre-approval.d.ts +5 -13
  22. package/dist/client/pre-approval.js +3 -10
  23. package/dist/client/registry.d.ts +15 -2
  24. package/dist/client/registry.js +22 -2
  25. package/dist/client/tool-calls.js +0 -4
  26. package/dist/client/tool-events.d.ts +8 -1
  27. package/dist/client/tool-events.js +39 -6
  28. package/dist/client/turn.js +28 -8
  29. package/dist/server/auth.d.ts +45 -0
  30. package/dist/server/auth.js +87 -0
  31. package/dist/server/capabilities.d.ts +7 -0
  32. package/dist/server/capabilities.js +19 -0
  33. package/dist/server/cli.d.ts +26 -0
  34. package/dist/server/cli.js +87 -0
  35. package/dist/server/client-port.d.ts +39 -0
  36. package/dist/server/client-port.js +49 -0
  37. package/dist/server/connection.d.ts +22 -0
  38. package/dist/server/connection.js +56 -0
  39. package/dist/server/errors.d.ts +21 -0
  40. package/dist/server/errors.js +70 -0
  41. package/dist/server/index.d.ts +4 -3
  42. package/dist/server/index.js +6 -1
  43. package/dist/server/logger.d.ts +7 -0
  44. package/dist/server/logger.js +25 -0
  45. package/dist/server/login.d.ts +18 -0
  46. package/dist/server/login.js +29 -0
  47. package/dist/server/main.d.ts +19 -0
  48. package/dist/server/main.js +120 -0
  49. package/dist/server/nax-config.d.ts +30 -0
  50. package/dist/server/nax-config.js +138 -0
  51. package/dist/server/open-session.d.ts +37 -0
  52. package/dist/server/open-session.js +55 -0
  53. package/dist/server/options.d.ts +27 -0
  54. package/dist/server/options.js +55 -0
  55. package/dist/server/permissions.d.ts +44 -0
  56. package/dist/server/permissions.js +157 -0
  57. package/dist/server/process-entry.d.ts +15 -0
  58. package/dist/server/process-entry.js +28 -0
  59. package/dist/server/prompt.d.ts +8 -0
  60. package/dist/server/prompt.js +29 -0
  61. package/dist/server/questions.d.ts +33 -0
  62. package/dist/server/questions.js +79 -0
  63. package/dist/server/registry-open.d.ts +33 -0
  64. package/dist/server/registry-open.js +62 -0
  65. package/dist/server/registry.d.ts +64 -0
  66. package/dist/server/registry.js +262 -0
  67. package/dist/server/server-session.d.ts +43 -0
  68. package/dist/server/server-session.js +221 -0
  69. package/dist/server/session-config.d.ts +27 -0
  70. package/dist/server/session-config.js +93 -0
  71. package/dist/server/storage.d.ts +49 -0
  72. package/dist/server/storage.js +191 -0
  73. package/dist/server/translate/diff.d.ts +30 -0
  74. package/dist/server/translate/diff.js +81 -0
  75. package/dist/server/translate/events.d.ts +37 -0
  76. package/dist/server/translate/events.js +126 -0
  77. package/dist/server/translate/notice.d.ts +10 -0
  78. package/dist/server/translate/notice.js +14 -0
  79. package/dist/server/translate/replay.d.ts +11 -0
  80. package/dist/server/translate/replay.js +53 -0
  81. package/dist/server/translate/stop.d.ts +22 -0
  82. package/dist/server/translate/stop.js +48 -0
  83. package/dist/server/translate/tool-kind.d.ts +9 -0
  84. package/dist/server/translate/tool-kind.js +67 -0
  85. package/dist/server/version.d.ts +1 -0
  86. package/dist/server/version.js +17 -0
  87. package/package.json +6 -3
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Diffs for Edit and Write tool calls (S5 spec §4.2), built from the tool input
3
+ * so the editor can show them at permission time, before the tool runs. Write's
4
+ * old text is read from disk through an injected reader (the server runs locally).
5
+ */
6
+ import { readFile, realpath, stat } from "node:fs/promises";
7
+ import { isAbsolute, relative } from "node:path";
8
+ import { redactSecrets } from "@nathapp/nax-agent";
9
+ import { inputString, resolveToolPath } from "#src/server/translate/tool-kind";
10
+ export const WRITE_DIFF_OLD_MAX_BYTES = 1024 * 1024;
11
+ const NODE_FS = {
12
+ realpath: (path) => realpath(path),
13
+ stat,
14
+ readFile: (path, encoding) => readFile(path, encoding),
15
+ };
16
+ function isMissing(error) {
17
+ return typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT";
18
+ }
19
+ function isInside(root, path) {
20
+ const rel = relative(root, path);
21
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
22
+ }
23
+ export function fsReadOldText(fs = NODE_FS) {
24
+ return async (path, root) => {
25
+ try {
26
+ // Symlinks resolved on both sides: a link inside the workspace to a file outside it is outside.
27
+ const real = await fs.realpath(path);
28
+ if (!isInside(await fs.realpath(root), real))
29
+ return { kind: "outside-workspace" };
30
+ const info = await fs.stat(real);
31
+ if (!info.isFile())
32
+ return { kind: "unreadable" };
33
+ if (info.size > WRITE_DIFF_OLD_MAX_BYTES)
34
+ return { kind: "too-large" };
35
+ return { kind: "text", text: await fs.readFile(real, "utf8") };
36
+ }
37
+ catch (error) {
38
+ return isMissing(error) ? { kind: "missing" } : { kind: "unreadable" };
39
+ }
40
+ };
41
+ }
42
+ export function editDiff(input, cwd) {
43
+ const path = inputString(input, "path");
44
+ const oldText = inputString(input, "old_string");
45
+ const newText = inputString(input, "new_string");
46
+ if (path === undefined || oldText === undefined || newText === undefined)
47
+ return undefined;
48
+ return { type: "diff", path: resolveToolPath(cwd, path), oldText, newText };
49
+ }
50
+ async function writeDiff(input, cwd, readOld) {
51
+ const path = inputString(input, "path");
52
+ const newText = inputString(input, "content");
53
+ if (path === undefined || newText === undefined)
54
+ return undefined;
55
+ const absolute = resolveToolPath(cwd, path);
56
+ const old = await readOld(absolute, cwd);
57
+ switch (old.kind) {
58
+ case "text":
59
+ // Masked as live tool input is (the input's own text arrives masked from the session).
60
+ return { type: "diff", path: absolute, oldText: redactSecrets(old.text), newText };
61
+ case "missing":
62
+ return { type: "diff", path: absolute, oldText: null, newText };
63
+ case "too-large":
64
+ case "unreadable":
65
+ case "outside-workspace":
66
+ return {
67
+ type: "diff",
68
+ path: absolute,
69
+ oldText: null,
70
+ newText,
71
+ _meta: { naxAgent: { oldTextOmitted: old.kind } },
72
+ };
73
+ }
74
+ }
75
+ export async function toolDiff(name, input, cwd, readOld) {
76
+ if (name === "Edit")
77
+ return editDiff(input, cwd);
78
+ if (name === "Write")
79
+ return writeDiff(input, cwd, readOld);
80
+ return undefined;
81
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * S3 session events -> ACP session updates (S5 spec §4.1-§4.3). One translator
3
+ * per turn: it remembers tool calls (for result diffs and permission requests)
4
+ * and approval requests (to fail a call the session mode denied). Permission
5
+ * requests, questions and the turn end are the session's job (S5-2).
6
+ */
7
+ import type { SessionUpdate, ToolCallContent, ToolCallUpdate } from "@agentclientprotocol/sdk";
8
+ import type { SessionEvent } from "@nathapp/nax-agent";
9
+ import { type ReadOldText } from "#src/server/translate/diff";
10
+ /** Optional session updates the client advertised (`clientCapabilities.session`). */
11
+ export interface ClientUpdates {
12
+ readonly notices: boolean;
13
+ readonly compaction: boolean;
14
+ }
15
+ export interface EventTranslatorDeps {
16
+ readonly cwd: string;
17
+ readonly contextWindow?: number;
18
+ readonly readOldText: ReadOldText;
19
+ readonly clientUpdates: ClientUpdates;
20
+ /** The session's cost before this turn; `usage_update.cost` is the cumulative session cost. */
21
+ readonly priorCostUsd?: number;
22
+ }
23
+ export interface EventTranslator {
24
+ translate(event: SessionEvent): Promise<readonly SessionUpdate[]>;
25
+ toolCallFor(callId: string): ToolCallUpdate | undefined;
26
+ /** The session's priced cost so far, including this turn's rounds. */
27
+ costUsd(): number;
28
+ }
29
+ export type UsageEvent = Extract<SessionEvent, {
30
+ type: "usage";
31
+ }>;
32
+ export declare function textContent(text: string): Extract<ToolCallContent, {
33
+ type: "content";
34
+ }>;
35
+ /** `sessionCostUsd`: the cumulative session cost after this round (ACP `cost.amount` is cumulative). */
36
+ export declare function usageUpdate(event: UsageEvent, contextWindow: number | undefined, sessionCostUsd: number): SessionUpdate[];
37
+ export declare function createEventTranslator(deps: EventTranslatorDeps): EventTranslator;
@@ -0,0 +1,126 @@
1
+ import { toolDiff } from "#src/server/translate/diff";
2
+ import { announce } from "#src/server/translate/notice";
3
+ import { toolKind, toolLocations, toolTitle } from "#src/server/translate/tool-kind";
4
+ export function textContent(text) {
5
+ return { type: "content", content: { type: "text", text } };
6
+ }
7
+ /** `sessionCostUsd`: the cumulative session cost after this round (ACP `cost.amount` is cumulative). */
8
+ export function usageUpdate(event, contextWindow, sessionCostUsd) {
9
+ if (contextWindow === undefined)
10
+ return [];
11
+ const used = event.inputTokens + event.outputTokens + (event.cacheRead ?? 0) + (event.cacheWrite ?? 0);
12
+ return [
13
+ {
14
+ sessionUpdate: "usage_update",
15
+ used,
16
+ size: contextWindow,
17
+ cost: event.costSource === "unpriced" ? null : { amount: sessionCostUsd, currency: "USD" },
18
+ ...(event.costSource !== undefined ? { _meta: { naxAgent: { costSource: event.costSource } } } : {}),
19
+ },
20
+ ];
21
+ }
22
+ function toolResultUpdate(event, diff) {
23
+ return {
24
+ sessionUpdate: "tool_call_update",
25
+ toolCallId: event.callId,
26
+ status: event.isError ? "failed" : "completed",
27
+ content: [textContent(event.preview), ...(diff !== undefined ? [diff] : [])],
28
+ };
29
+ }
30
+ function profileDenial(approval, event) {
31
+ if (approval === undefined || event.decidedBy !== "profile" || event.decision !== "deny")
32
+ return [];
33
+ return [
34
+ {
35
+ sessionUpdate: "tool_call_update",
36
+ toolCallId: approval.callId,
37
+ status: "failed",
38
+ content: [textContent(`Denied by the session mode: ${approval.reason}`)],
39
+ },
40
+ ];
41
+ }
42
+ function streamResetUpdate(event, notices) {
43
+ return announce(notices, "info", "Response restarted", `The model stream was retried (attempt ${event.attempt}); text above may repeat.`);
44
+ }
45
+ export function createEventTranslator(deps) {
46
+ const calls = new Map();
47
+ const approvals = new Map();
48
+ let compactions = 0;
49
+ let sessionCostUsd = deps.priorCostUsd ?? 0;
50
+ const describeCall = (toolCallId, call) => {
51
+ const locations = toolLocations(call.name, call.input, deps.cwd);
52
+ return {
53
+ toolCallId,
54
+ title: toolTitle(call.name, call.input),
55
+ kind: toolKind(call.name),
56
+ rawInput: call.input,
57
+ ...(locations !== undefined ? { locations } : {}),
58
+ ...(call.diff !== undefined ? { content: [call.diff] } : {}),
59
+ };
60
+ };
61
+ async function toolCallUpdate(event) {
62
+ const diff = await toolDiff(event.name, event.input, deps.cwd, deps.readOldText);
63
+ const call = { name: event.name, input: event.input, ...(diff !== undefined ? { diff } : {}) };
64
+ calls.set(event.callId, call);
65
+ return { sessionUpdate: "tool_call", ...describeCall(event.callId, call), status: "in_progress" };
66
+ }
67
+ function usage(event) {
68
+ if (event.costSource !== "unpriced")
69
+ sessionCostUsd += event.costUsd;
70
+ return usageUpdate(event, deps.contextWindow, sessionCostUsd);
71
+ }
72
+ function compaction(event) {
73
+ if (!deps.clientUpdates.compaction)
74
+ return [];
75
+ compactions += 1;
76
+ return [
77
+ {
78
+ sessionUpdate: "compaction_update",
79
+ compactionId: `${event.turnId}-${compactions}`,
80
+ status: "completed",
81
+ _meta: { naxAgent: { reason: event.reason } },
82
+ },
83
+ ];
84
+ }
85
+ function resolved(event) {
86
+ const approval = approvals.get(event.requestId);
87
+ approvals.delete(event.requestId);
88
+ return profileDenial(approval, event);
89
+ }
90
+ async function translate(event) {
91
+ switch (event.type) {
92
+ case "text_delta":
93
+ return [{ sessionUpdate: "agent_message_chunk", content: { type: "text", text: event.text } }];
94
+ case "thinking_delta":
95
+ return [{ sessionUpdate: "agent_thought_chunk", content: { type: "text", text: event.text } }];
96
+ case "stream_reset":
97
+ return [streamResetUpdate(event, deps.clientUpdates.notices)];
98
+ case "tool_call":
99
+ return [await toolCallUpdate(event)];
100
+ case "tool_result":
101
+ return [toolResultUpdate(event, calls.get(event.callId)?.diff)];
102
+ case "usage":
103
+ return usage(event);
104
+ case "compaction":
105
+ return compaction(event);
106
+ case "approval_requested":
107
+ if (event.callId !== undefined)
108
+ approvals.set(event.requestId, { callId: event.callId, reason: event.reason });
109
+ return [];
110
+ case "approval_resolved":
111
+ return resolved(event);
112
+ case "turn_start":
113
+ case "question":
114
+ case "turn_end":
115
+ return [];
116
+ }
117
+ }
118
+ return {
119
+ translate,
120
+ costUsd: () => sessionCostUsd,
121
+ toolCallFor(callId) {
122
+ const call = calls.get(callId);
123
+ return call === undefined ? undefined : { ...describeCall(callId, call), status: "pending" };
124
+ },
125
+ };
126
+ }
@@ -0,0 +1,10 @@
1
+ /** A `notice` session update (S5 spec §4.1, §4.3, §4.4). */
2
+ import type { SessionUpdate } from "@agentclientprotocol/sdk";
3
+ export type NoticeSeverity = "info" | "warning" | "error";
4
+ export declare function notice(severity: NoticeSeverity, title: string, description?: string): SessionUpdate;
5
+ /**
6
+ * A notice when the client advertised `session.notices`; otherwise the same text
7
+ * as an agent message, which every client shows (ACP: agents MUST NOT send
8
+ * notices to a client that did not advertise them).
9
+ */
10
+ export declare function announce(notices: boolean, severity: NoticeSeverity, title: string, description?: string): SessionUpdate;
@@ -0,0 +1,14 @@
1
+ export function notice(severity, title, description) {
2
+ return { sessionUpdate: "notice", severity, title, ...(description !== undefined ? { description } : {}) };
3
+ }
4
+ /**
5
+ * A notice when the client advertised `session.notices`; otherwise the same text
6
+ * as an agent message, which every client shows (ACP: agents MUST NOT send
7
+ * notices to a client that did not advertise them).
8
+ */
9
+ export function announce(notices, severity, title, description) {
10
+ if (notices)
11
+ return notice(severity, title, description);
12
+ const text = description === undefined ? title : `${title}: ${description}`;
13
+ return { sessionUpdate: "agent_message_chunk", content: { type: "text", text: `\n\n${text}\n\n` } };
14
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * A stored transcript as session updates for `session/load` (S5 spec §5.4).
3
+ * Inputs and results go through nax-agent's live masking and caps (M-7), so a
4
+ * replay never shows more than the live turn did. Write gets no diff: the file's
5
+ * old content at that time is gone.
6
+ */
7
+ import type { SessionUpdate } from "@agentclientprotocol/sdk";
8
+ import { type TranscriptDoc } from "@nathapp/nax-agent";
9
+ export type TranscriptMessage = TranscriptDoc["messages"][number];
10
+ export declare const NO_RESULT_TEXT = "No result was recorded for this call.";
11
+ export declare function replayTranscript(messages: readonly TranscriptMessage[], cwd: string): readonly SessionUpdate[];
@@ -0,0 +1,53 @@
1
+ import { displayToolInput, toolResultPreview } from "@nathapp/nax-agent";
2
+ import { editDiff } from "#src/server/translate/diff";
3
+ import { textContent } from "#src/server/translate/events";
4
+ import { toolKind, toolLocations, toolTitle } from "#src/server/translate/tool-kind";
5
+ export const NO_RESULT_TEXT = "No result was recorded for this call.";
6
+ function replayCall(call, result, cwd) {
7
+ const input = displayToolInput(call.input);
8
+ const diff = call.name === "Edit" ? editDiff(input, cwd) : undefined;
9
+ const locations = toolLocations(call.name, input, cwd);
10
+ const shown = result === undefined ? NO_RESULT_TEXT : toolResultPreview(result.content);
11
+ return {
12
+ sessionUpdate: "tool_call",
13
+ toolCallId: call.id,
14
+ title: toolTitle(call.name, input),
15
+ kind: toolKind(call.name),
16
+ status: result === undefined || result.isError ? "failed" : "completed",
17
+ rawInput: input,
18
+ ...(locations !== undefined ? { locations } : {}),
19
+ content: [textContent(shown), ...(diff !== undefined ? [diff] : [])],
20
+ };
21
+ }
22
+ function replayMessage(message, results, cwd) {
23
+ switch (message.role) {
24
+ case "user":
25
+ return message.content === ""
26
+ ? []
27
+ : [{ sessionUpdate: "user_message_chunk", content: { type: "text", text: message.content } }];
28
+ case "tool-result":
29
+ return [];
30
+ case "assistant": {
31
+ const thoughts = (message.thinking ?? [])
32
+ .filter((block) => block.text !== "")
33
+ .map((block) => ({
34
+ sessionUpdate: "agent_thought_chunk",
35
+ content: { type: "text", text: block.text },
36
+ }));
37
+ const said = message.content === ""
38
+ ? []
39
+ : [{ sessionUpdate: "agent_message_chunk", content: { type: "text", text: message.content } }];
40
+ const calls = (message.toolCalls ?? []).map((call) => replayCall(call, results.get(call.id), cwd));
41
+ return [...thoughts, ...said, ...calls];
42
+ }
43
+ }
44
+ }
45
+ export function replayTranscript(messages, cwd) {
46
+ const results = new Map();
47
+ for (const message of messages) {
48
+ if (message.role === "tool-result") {
49
+ results.set(message.toolCallId, { content: message.content, isError: message.isError === true });
50
+ }
51
+ }
52
+ return messages.flatMap((message) => replayMessage(message, results, cwd));
53
+ }
@@ -0,0 +1,22 @@
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 { type PromptResponse, RequestError, type SessionUpdate, type Usage } from "@agentclientprotocol/sdk";
8
+ import { type SessionEvent, type TokenUsage } from "@nathapp/nax-agent";
9
+ export type TurnEndEvent = Extract<SessionEvent, {
10
+ type: "turn_end";
11
+ }>;
12
+ export type PromptOutcome = {
13
+ readonly kind: "response";
14
+ readonly response: PromptResponse;
15
+ readonly notices: readonly SessionUpdate[];
16
+ } | {
17
+ readonly kind: "error";
18
+ readonly error: RequestError;
19
+ };
20
+ export declare function toAcpUsage(usage: TokenUsage): Usage;
21
+ /** `notices`: whether the client advertised `session.notices` (else warnings become agent text). */
22
+ export declare function promptOutcome(end: TurnEndEvent, turnTimeoutSeconds: number, notices: boolean): PromptOutcome;
@@ -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.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,12 +49,12 @@
46
49
  "zod": "^4.3.6"
47
50
  },
48
51
  "peerDependencies": {
49
- "@nathapp/nax-agent": "^0.3.0"
52
+ "@nathapp/nax-agent": "^0.84.0"
50
53
  },
51
54
  "publishConfig": {
52
55
  "access": "public",
53
56
  "registry": "https://registry.npmjs.org/",
54
- "provenance": false,
57
+ "provenance": true,
55
58
  "tag": "latest"
56
59
  }
57
60
  }