@nathapp/nax-agent-acp 0.84.0 → 0.85.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 (48) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +52 -3
  3. package/dist/server/auth.d.ts +2 -0
  4. package/dist/server/auth.js +6 -6
  5. package/dist/server/capabilities.d.ts +2 -1
  6. package/dist/server/capabilities.js +3 -1
  7. package/dist/server/cli.d.ts +1 -0
  8. package/dist/server/cli.js +3 -0
  9. package/dist/server/default-model.d.ts +36 -0
  10. package/dist/server/default-model.js +158 -0
  11. package/dist/server/login.d.ts +2 -0
  12. package/dist/server/login.js +9 -0
  13. package/dist/server/main.d.ts +5 -0
  14. package/dist/server/main.js +35 -3
  15. package/dist/server/mcp/connect.d.ts +38 -0
  16. package/dist/server/mcp/connect.js +95 -0
  17. package/dist/server/mcp/naming.d.ts +12 -0
  18. package/dist/server/mcp/naming.js +43 -0
  19. package/dist/server/mcp/notices.d.ts +8 -0
  20. package/dist/server/mcp/notices.js +19 -0
  21. package/dist/server/mcp/parse.d.ts +24 -0
  22. package/dist/server/mcp/parse.js +107 -0
  23. package/dist/server/mcp/secrets.d.ts +4 -0
  24. package/dist/server/mcp/secrets.js +44 -0
  25. package/dist/server/mcp/session-tools.d.ts +37 -0
  26. package/dist/server/mcp/session-tools.js +70 -0
  27. package/dist/server/mcp/tool-shape.d.ts +19 -0
  28. package/dist/server/mcp/tool-shape.js +20 -0
  29. package/dist/server/nax-config.d.ts +1 -0
  30. package/dist/server/nax-config.js +1 -0
  31. package/dist/server/open-session.d.ts +2 -1
  32. package/dist/server/open-session.js +1 -0
  33. package/dist/server/options.d.ts +3 -0
  34. package/dist/server/options.js +17 -0
  35. package/dist/server/questions.js +13 -2
  36. package/dist/server/registry-open.d.ts +1 -2
  37. package/dist/server/registry-open.js +8 -10
  38. package/dist/server/registry.d.ts +18 -3
  39. package/dist/server/registry.js +116 -45
  40. package/dist/server/server-session.d.ts +2 -0
  41. package/dist/server/server-session.js +1 -0
  42. package/dist/server/session-config.d.ts +4 -2
  43. package/dist/server/session-config.js +11 -0
  44. package/dist/server/translate/events.d.ts +2 -0
  45. package/dist/server/translate/events.js +1 -1
  46. package/dist/server/translate/replay.d.ts +1 -1
  47. package/dist/server/translate/replay.js +6 -6
  48. package/package.json +2 -2
@@ -1,17 +1,23 @@
1
1
  import { type ListSessionsResponse, type SessionConfigOption, type SessionModeState } from "@agentclientprotocol/sdk";
2
- import type { AgentLogger, TranscriptStore } from "@nathapp/nax-agent";
2
+ import { type AgentLogger, type TranscriptStore } from "@nathapp/nax-agent";
3
3
  import type { ClientPort } from "#src/server/client-port";
4
+ import { type ConnectSessionMcp } from "#src/server/mcp/connect";
5
+ import type { McpSessionTools } from "#src/server/mcp/session-tools";
4
6
  import type { OpenSession } from "#src/server/open-session";
5
7
  import type { ServerOptions } from "#src/server/options";
6
8
  import { type ServerSession } from "#src/server/server-session";
7
9
  import type { SessionMeta, SessionStorage } from "#src/server/storage";
8
10
  import type { ReadOldText } from "#src/server/translate/diff";
9
- export declare const NO_MODEL_MESSAGE = "no model configured: set models.native.balanced or --model";
10
- export declare const MCP_NOTICE = "MCP servers are not supported yet; ignored";
11
+ export declare const NO_MODEL_MESSAGE = "no model configured: log in to pick one, or set models.native.balanced in config.json / NAX_AGENT_MODEL";
11
12
  export declare const INTERRUPTED_NOTICE = "The previous turn was interrupted";
12
13
  export declare const SHUTTING_DOWN = "server is shutting down";
13
14
  export declare const SHUTDOWN_WAIT_MS = 5000;
14
15
  export declare const TITLE_MAX = 80;
16
+ /** What re-reading the options found: the options, or why there are none (a short, redacted reason). */
17
+ export interface ReloadedOptions {
18
+ readonly options?: ServerOptions;
19
+ readonly problem?: string;
20
+ }
15
21
  export interface SessionState {
16
22
  readonly modes: SessionModeState;
17
23
  readonly configOptions: SessionConfigOption[];
@@ -52,12 +58,21 @@ export interface RegistryDeps {
52
58
  readonly shutdownWaitMs?: number;
53
59
  /** S5-4 M-30: refuses (auth_required) when the model's provider has no credential. */
54
60
  readonly ensureCredentials?: (model: string) => Promise<void>;
61
+ /** S5-5: connects a session's client-supplied MCP servers. Default: connects nothing (plan M-38). */
62
+ readonly connectMcp?: ConnectSessionMcp;
63
+ /**
64
+ * Re-resolves the options (flags and env still win over the config file). Called by
65
+ * session/new when no model is configured, so a model written by `nax-agent login`
66
+ * takes effect without restarting the server (#2414).
67
+ */
68
+ readonly reloadOptions?: () => Promise<ReloadedOptions>;
55
69
  }
56
70
  export interface Entry {
57
71
  readonly server: ServerSession;
58
72
  readonly port: ClientPort;
59
73
  readonly meta: SessionMeta;
60
74
  readonly release: () => Promise<void>;
75
+ readonly mcp: McpSessionTools;
61
76
  }
62
77
  /** One line, no control or invisible characters, at most TITLE_MAX code points. */
63
78
  export declare function titleOf(prompt: string): string;
@@ -7,14 +7,17 @@
7
7
  */
8
8
  import { isAbsolute } from "node:path";
9
9
  import { RequestError, } from "@agentclientprotocol/sdk";
10
+ import { redactSecrets } from "@nathapp/nax-agent";
10
11
  import { stripControl, stripInvisible } from "#src/client/text";
11
- import { invalidParams, messageOf, turnInProgress, unknownSession } from "#src/server/errors";
12
+ import { authRequired, invalidParams, messageOf, turnInProgress, unknownSession } from "#src/server/errors";
13
+ import { connectNothing } from "#src/server/mcp/connect";
14
+ import { disconnectNotice, modeNotice, openNotice } from "#src/server/mcp/notices";
15
+ import { NO_SERVERS, parseMcpServers } from "#src/server/mcp/parse";
16
+ import { mcpSecrets, scrubber } from "#src/server/mcp/secrets";
12
17
  import { createReopen, settingsOf } from "#src/server/registry-open";
13
18
  import { createServerSession } from "#src/server/server-session";
14
19
  import { applyConfigChange, applyModeChange, configOptions, modeState, sameSettings, } from "#src/server/session-config";
15
- import { announce } from "#src/server/translate/notice";
16
- export const NO_MODEL_MESSAGE = "no model configured: set models.native.balanced or --model";
17
- export const MCP_NOTICE = "MCP servers are not supported yet; ignored";
20
+ export const NO_MODEL_MESSAGE = "no model configured: log in to pick one, or set models.native.balanced in config.json / NAX_AGENT_MODEL";
18
21
  export const INTERRUPTED_NOTICE = "The previous turn was interrupted";
19
22
  export const SHUTTING_DOWN = "server is shutting down";
20
23
  export const SHUTDOWN_WAIT_MS = 5000;
@@ -34,7 +37,9 @@ function waitAtMost(ms) {
34
37
  }
35
38
  export function createSessionRegistry(deps) {
36
39
  const entries = new Map();
37
- const { options } = deps;
40
+ let options = deps.options;
41
+ const connectMcp = deps.connectMcp ?? connectNothing;
42
+ const shutdown = new AbortController();
38
43
  let closing = false;
39
44
  const contextWindowFor = (model) => options.tiers.find((tier) => tier.model === model)?.contextWindow;
40
45
  const stateOf = (settings) => ({
@@ -59,63 +64,105 @@ export function createSessionRegistry(deps) {
59
64
  entries.set(sessionId, { ...entry, meta });
60
65
  await deps.storage.writeMeta(meta);
61
66
  }
62
- async function target(sessionId, cwd, settings) {
67
+ async function target(sessionId, cwd, settings, tools) {
63
68
  const opened = await deps.openSession({
64
69
  sessionId,
65
70
  cwd,
66
71
  model: settings.model,
67
72
  profile: settings.mode,
68
73
  bashApproval: settings.bashApproval,
74
+ tools,
69
75
  });
70
76
  const contextWindow = contextWindowFor(settings.model);
71
77
  return { session: opened.session, ...(contextWindow !== undefined ? { contextWindow } : {}) };
72
78
  }
73
- /** Takes the lock, opens the S3 session, registers it. The lock is released if anything fails. */
74
- async function openEntry(meta, port) {
79
+ function startMcp(parsed, meta, port) {
80
+ // Built before connecting: a disconnect fired before connectMcp resolves must still be scrubbed.
81
+ const scrub = scrubber(mcpSecrets(parsed.servers));
82
+ return connectMcp({
83
+ parsed,
84
+ cwd: meta.cwd,
85
+ signal: shutdown.signal,
86
+ onDisconnect: (server, reason) => {
87
+ port.update(disconnectNotice(port.features.updates.notices, server, reason, scrub)).catch((error) => {
88
+ deps.logger.warn("session", "MCP disconnect notice failed", {
89
+ sessionId: meta.sessionId,
90
+ error: messageOf(error),
91
+ });
92
+ });
93
+ },
94
+ });
95
+ }
96
+ function queueMcpNotices(server, port, mcp, mode) {
97
+ const notices = port.features.updates.notices;
98
+ const open = openNotice(notices, mcp.noticeLines, mcp.scrub);
99
+ if (open !== undefined)
100
+ server.queueNotice(open);
101
+ if (mcp.tools.connectedCount > 0 && !mcp.tools.offersTools(mode))
102
+ server.queueNotice(modeNotice(notices, mode));
103
+ }
104
+ /** Parses MCP servers, takes the lock, connects MCP, opens the S3 session, registers it. Everything is undone on failure. */
105
+ async function openEntry(meta, port, mcpServers) {
75
106
  if (closing)
76
107
  throw RequestError.internalError(undefined, SHUTTING_DOWN);
108
+ const parsed = mcpServers.length === 0 ? NO_SERVERS : parseMcpServers(mcpServers);
77
109
  await deps.ensureCredentials?.(meta.model);
78
110
  const release = await deps.storage.acquireLock(meta.sessionId);
111
+ let mcp;
112
+ let opened;
79
113
  try {
114
+ mcp = await startMcp(parsed, meta, port);
115
+ if (closing)
116
+ throw RequestError.internalError(undefined, SHUTTING_DOWN); // shutdown during connect
80
117
  const settings = settingsOf(meta);
81
- const opened = await deps.openSession({
118
+ opened = await deps.openSession({
82
119
  sessionId: meta.sessionId,
83
120
  cwd: meta.cwd,
84
121
  model: settings.model,
85
122
  profile: settings.mode,
86
123
  bashApproval: settings.bashApproval,
124
+ tools: mcp.tools.embedderTools(settings.mode),
87
125
  });
88
126
  if (closing) {
89
- // Shutdown started while this open was in flight: closeAll has already
90
- // cleared the map, so nothing would close this session or its lock (M-26).
127
+ // Shutdown started while this open was in flight (M-26).
91
128
  await opened.session.close().catch(() => undefined);
129
+ opened = undefined; // already closed; the catch must not close it twice
92
130
  throw RequestError.internalError(undefined, SHUTTING_DOWN);
93
131
  }
94
- const contextWindow = contextWindowFor(settings.model);
95
- const server = createServerSession({
96
- session: opened.session,
97
- port,
98
- cwd: meta.cwd,
99
- ...(contextWindow !== undefined ? { contextWindow } : {}),
100
- readOldText: deps.readOldText,
101
- logger: deps.logger,
102
- turnTimeoutSeconds: deps.turnTimeoutSeconds,
103
- onTurnEnd: (prompt) => recordTurn(meta.sessionId, prompt),
104
- });
105
- entries.set(meta.sessionId, { server, port, meta, release });
132
+ const server = createEntryServer(meta, port, opened, mcp.tools);
133
+ queueMcpNotices(server, port, mcp, settings.mode);
134
+ entries.set(meta.sessionId, { server, port, meta, release, mcp: mcp.tools });
106
135
  return { server, opened };
107
136
  }
108
137
  catch (error) {
138
+ // If the facade session opened but a later step threw, do not orphan it.
139
+ await opened?.session.close().catch(() => undefined);
140
+ await mcp?.tools.closeAll();
109
141
  await release();
110
- throw error;
142
+ throw closing ? RequestError.internalError(undefined, SHUTTING_DOWN) : error;
111
143
  }
112
144
  }
145
+ function createEntryServer(meta, port, opened, mcp) {
146
+ const contextWindow = contextWindowFor(meta.model);
147
+ return createServerSession({
148
+ session: opened.session,
149
+ port,
150
+ cwd: meta.cwd,
151
+ ...(contextWindow !== undefined ? { contextWindow } : {}),
152
+ readOldText: deps.readOldText,
153
+ logger: deps.logger,
154
+ turnTimeoutSeconds: deps.turnTimeoutSeconds,
155
+ onTurnEnd: (prompt) => recordTurn(meta.sessionId, prompt),
156
+ titleFor: (name) => mcp.titleFor(name),
157
+ });
158
+ }
113
159
  async function closeEntry(sessionId, entry) {
114
160
  entries.delete(sessionId);
115
161
  try {
116
162
  await entry.server.close();
117
163
  }
118
164
  finally {
165
+ await entry.mcp.closeAll();
119
166
  await entry.release();
120
167
  }
121
168
  }
@@ -127,7 +174,6 @@ export function createSessionRegistry(deps) {
127
174
  openEntry,
128
175
  closeEntry,
129
176
  stateOf,
130
- mcpNotice: MCP_NOTICE,
131
177
  interruptedNotice: INTERRUPTED_NOTICE,
132
178
  }).reopen;
133
179
  /** Close-and-reopen with `next` (§3.3). Metadata is written only after the reopen succeeds. */
@@ -139,10 +185,12 @@ export function createSessionRegistry(deps) {
139
185
  // Before the live session is closed, so a refused model changes nothing (final review I6).
140
186
  if (next.model !== from.model)
141
187
  await deps.ensureCredentials?.(next.model);
142
- await entry.server.switchTo(() => target(sessionId, entry.meta.cwd, next), () => target(sessionId, entry.meta.cwd, from));
188
+ await entry.server.switchTo(() => target(sessionId, entry.meta.cwd, next, entry.mcp.embedderTools(next.mode)), () => target(sessionId, entry.meta.cwd, from, entry.mcp.embedderTools(from.mode)));
143
189
  const meta = { ...entry.meta, mode: next.mode, model: next.model, bashApproval: next.bashApproval };
144
190
  entries.set(sessionId, { ...entry, meta });
145
191
  await deps.storage.writeMeta(meta);
192
+ if (next.mode !== from.mode && entry.mcp.connectedCount > 0 && !entry.mcp.offersTools(next.mode))
193
+ await entry.port.update(modeNotice(entry.port.features.updates.notices, next.mode));
146
194
  }
147
195
  async function announceConfig(entry, settings) {
148
196
  await entry.port.update({
@@ -150,13 +198,45 @@ export function createSessionRegistry(deps) {
150
198
  configOptions: configOptions(settings, options.tiers),
151
199
  });
152
200
  }
201
+ /**
202
+ * The one path for set_mode and set_config_option: reopen when anything changed,
203
+ * then announce. `current_mode_update` follows every set_mode and any mode
204
+ * change; `config_option_update` follows every change (M-25).
205
+ */
206
+ async function applySettings(sessionId, entry, next, alwaysAnnounceMode) {
207
+ const from = settingsOf(entry.meta);
208
+ const changed = !sameSettings(from, next);
209
+ if (changed)
210
+ await switchTo(sessionId, entry, next);
211
+ if (alwaysAnnounceMode || next.mode !== from.mode) {
212
+ await entry.port.update({ sessionUpdate: "current_mode_update", currentModeId: next.mode });
213
+ }
214
+ if (changed)
215
+ await announceConfig(entry, next);
216
+ }
217
+ /** The default model, re-read from the config when none was configured at startup. */
218
+ async function reloadDefaultModel() {
219
+ let problem;
220
+ let fresh;
221
+ try {
222
+ ({ options: fresh, problem } = (await deps.reloadOptions?.()) ?? {});
223
+ }
224
+ catch (error) {
225
+ problem = redactSecrets(messageOf(error));
226
+ deps.logger.warn("config", "could not re-read the options", { error: problem });
227
+ }
228
+ if (fresh?.defaultModel === undefined) {
229
+ const reason = problem === undefined ? "" : `; config.json could not be used: ${problem}`;
230
+ throw authRequired(`${NO_MODEL_MESSAGE}${reason}`, {});
231
+ }
232
+ options = { ...options, defaultModel: fresh.defaultModel, tiers: fresh.tiers };
233
+ return fresh.defaultModel;
234
+ }
153
235
  return {
154
236
  async create(input) {
155
237
  if (!isAbsolute(input.cwd))
156
238
  throw invalidParams(`cwd must be an absolute path: ${input.cwd}`);
157
- const model = options.defaultModel;
158
- if (model === undefined)
159
- throw invalidParams(NO_MODEL_MESSAGE);
239
+ const model = options.defaultModel ?? (await reloadDefaultModel());
160
240
  const sessionId = deps.newId();
161
241
  const meta = {
162
242
  schemaVersion: 1,
@@ -170,7 +250,7 @@ export function createSessionRegistry(deps) {
170
250
  updatedAt: null,
171
251
  };
172
252
  const port = input.port(sessionId);
173
- const { server } = await openEntry(meta, port);
253
+ await openEntry(meta, port, input.mcpServers);
174
254
  try {
175
255
  await deps.storage.writeMeta(meta);
176
256
  }
@@ -191,8 +271,6 @@ export function createSessionRegistry(deps) {
191
271
  await deps.storage.removeMeta(sessionId);
192
272
  throw RequestError.internalError(undefined, SHUTTING_DOWN);
193
273
  }
194
- if (input.mcpServers.length > 0)
195
- server.queueNotice(announce(port.features.updates.notices, "warning", MCP_NOTICE));
196
274
  deps.logger.info("session", "session opened", { sessionId, cwd: input.cwd, model, mode: meta.mode });
197
275
  return { sessionId, ...stateOf(settingsOf(meta)) };
198
276
  },
@@ -221,26 +299,18 @@ export function createSessionRegistry(deps) {
221
299
  },
222
300
  async setMode(sessionId, modeId) {
223
301
  const entry = entryOf(sessionId);
224
- const from = settingsOf(entry.meta);
225
- const next = applyModeChange(from, modeId);
226
- if (!sameSettings(from, next))
227
- await switchTo(sessionId, entry, next);
228
- await entry.port.update({ sessionUpdate: "current_mode_update", currentModeId: next.mode });
229
- if (next.bashApproval !== from.bashApproval)
230
- await announceConfig(entry, next);
302
+ const next = applyModeChange(settingsOf(entry.meta), modeId);
303
+ await applySettings(sessionId, entry, next, true);
231
304
  },
232
305
  async setConfigOption(sessionId, configId, value) {
233
306
  const entry = entryOf(sessionId);
234
- const from = settingsOf(entry.meta);
235
- const next = applyConfigChange(from, configId, value, options.tiers);
236
- if (!sameSettings(from, next)) {
237
- await switchTo(sessionId, entry, next);
238
- await announceConfig(entry, next);
239
- }
307
+ const next = applyConfigChange(settingsOf(entry.meta), configId, value, options.tiers);
308
+ await applySettings(sessionId, entry, next, false);
240
309
  return configOptions(next, options.tiers);
241
310
  },
242
311
  async closeAll() {
243
312
  closing = true;
313
+ shutdown.abort();
244
314
  const open = [...entries.entries()];
245
315
  entries.clear();
246
316
  const wait = deps.shutdownWaitMs ?? SHUTDOWN_WAIT_MS;
@@ -255,6 +325,7 @@ export function createSessionRegistry(deps) {
255
325
  limit.cancel();
256
326
  if (outcome === "timeout")
257
327
  deps.logger.warn("session", "session did not close in time", { sessionId, waitMs: wait });
328
+ await entry.mcp.closeAll();
258
329
  await entry.release();
259
330
  }));
260
331
  },
@@ -23,6 +23,8 @@ export interface ServerSessionDeps {
23
23
  readonly now?: () => number;
24
24
  /** After every prompt that reached send() (S5-3: title and updatedAt). A rejection is logged, never thrown. */
25
25
  readonly onTurnEnd?: (message: string) => Promise<void>;
26
+ /** S5-5 (wired in S5-5b Task 10): a display title for an MCP tool call's model name. */
27
+ readonly titleFor?: (name: string) => string | undefined;
26
28
  }
27
29
  /** The S3 session and context window to adopt on a switchTo (spec §3.3). */
28
30
  export interface SwitchTarget {
@@ -106,6 +106,7 @@ export function createServerSession(deps) {
106
106
  readOldText: deps.readOldText,
107
107
  clientUpdates: deps.port.features.updates,
108
108
  priorCostUsd: costUsd,
109
+ ...(deps.titleFor !== undefined ? { titleFor: deps.titleFor } : {}),
109
110
  });
110
111
  const current = {
111
112
  permissions: createPermissionBroker({ port: deps.port, answer, memory, logger: deps.logger }),
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * What an ACP session exposes about its settings (S5 spec §5.2, §5.3): the four
3
- * modes (S3 profiles), and two select config options, the model (the configured
4
- * tiers plus the current model) and the bash approval mode. Changes are
3
+ * modes (S3 profiles), and three select config options (mode, which editors
4
+ * render in place of `modes`; the model (the configured
5
+ * tiers plus the current model); and the bash approval mode). Changes are
5
6
  * validated here; applying them is the registry's close-and-reopen (§3.3).
6
7
  */
7
8
  import type { SessionConfigOption, SessionMode, SessionModeState } from "@agentclientprotocol/sdk";
@@ -12,6 +13,7 @@ export interface SessionSettings {
12
13
  readonly model: string;
13
14
  readonly bashApproval: BashApproval;
14
15
  }
16
+ export declare const MODE_OPTION = "mode";
15
17
  export declare const MODEL_OPTION = "model";
16
18
  export declare const BASH_OPTION = "bashApproval";
17
19
  export declare const SESSION_MODES: readonly SessionMode[];
@@ -1,5 +1,6 @@
1
1
  import { invalidParams } from "#src/server/errors";
2
2
  import { BASH_APPROVALS, MODES } from "#src/server/nax-config";
3
+ export const MODE_OPTION = "mode";
3
4
  export const MODEL_OPTION = "model";
4
5
  export const BASH_OPTION = "bashApproval";
5
6
  export const SESSION_MODES = [
@@ -47,6 +48,14 @@ export function modelChoices(settings, tiers) {
47
48
  }
48
49
  export function configOptions(settings, tiers) {
49
50
  return [
51
+ {
52
+ id: MODE_OPTION,
53
+ name: "Mode",
54
+ category: "mode",
55
+ type: "select",
56
+ currentValue: settings.mode,
57
+ options: SESSION_MODES.map((m) => ({ value: m.id, name: m.name, description: m.description ?? null })),
58
+ },
50
59
  {
51
60
  id: MODEL_OPTION,
52
61
  name: "Model",
@@ -74,6 +83,8 @@ export function applyModeChange(settings, modeId) {
74
83
  export function applyConfigChange(settings, configId, value, tiers) {
75
84
  if (typeof value !== "string")
76
85
  throw invalidParams(`config option "${configId}" takes a string value`);
86
+ if (configId === MODE_OPTION)
87
+ return applyModeChange(settings, value);
77
88
  if (configId === MODEL_OPTION) {
78
89
  const valid = modelChoices(settings, tiers).map((choice) => choice.value);
79
90
  if (!valid.includes(value))
@@ -19,6 +19,8 @@ export interface EventTranslatorDeps {
19
19
  readonly clientUpdates: ClientUpdates;
20
20
  /** The session's cost before this turn; `usage_update.cost` is the cumulative session cost. */
21
21
  readonly priorCostUsd?: number;
22
+ /** S5-5b: a display title for an MCP tool call's model name (e.g. `git__status` -> `git: status`). */
23
+ readonly titleFor?: (name: string) => string | undefined;
22
24
  }
23
25
  export interface EventTranslator {
24
26
  translate(event: SessionEvent): Promise<readonly SessionUpdate[]>;
@@ -51,7 +51,7 @@ export function createEventTranslator(deps) {
51
51
  const locations = toolLocations(call.name, call.input, deps.cwd);
52
52
  return {
53
53
  toolCallId,
54
- title: toolTitle(call.name, call.input),
54
+ title: deps.titleFor?.(call.name) ?? toolTitle(call.name, call.input),
55
55
  kind: toolKind(call.name),
56
56
  rawInput: call.input,
57
57
  ...(locations !== undefined ? { locations } : {}),
@@ -8,4 +8,4 @@ import type { SessionUpdate } from "@agentclientprotocol/sdk";
8
8
  import { type TranscriptDoc } from "@nathapp/nax-agent";
9
9
  export type TranscriptMessage = TranscriptDoc["messages"][number];
10
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[];
11
+ export declare function replayTranscript(messages: readonly TranscriptMessage[], cwd: string, titleFor?: (name: string) => string | undefined): readonly SessionUpdate[];
@@ -3,7 +3,7 @@ import { editDiff } from "#src/server/translate/diff";
3
3
  import { textContent } from "#src/server/translate/events";
4
4
  import { toolKind, toolLocations, toolTitle } from "#src/server/translate/tool-kind";
5
5
  export const NO_RESULT_TEXT = "No result was recorded for this call.";
6
- function replayCall(call, result, cwd) {
6
+ function replayCall(call, result, cwd, titleFor) {
7
7
  const input = displayToolInput(call.input);
8
8
  const diff = call.name === "Edit" ? editDiff(input, cwd) : undefined;
9
9
  const locations = toolLocations(call.name, input, cwd);
@@ -11,7 +11,7 @@ function replayCall(call, result, cwd) {
11
11
  return {
12
12
  sessionUpdate: "tool_call",
13
13
  toolCallId: call.id,
14
- title: toolTitle(call.name, input),
14
+ title: titleFor?.(call.name) ?? toolTitle(call.name, input),
15
15
  kind: toolKind(call.name),
16
16
  status: result === undefined || result.isError ? "failed" : "completed",
17
17
  rawInput: input,
@@ -19,7 +19,7 @@ function replayCall(call, result, cwd) {
19
19
  content: [textContent(shown), ...(diff !== undefined ? [diff] : [])],
20
20
  };
21
21
  }
22
- function replayMessage(message, results, cwd) {
22
+ function replayMessage(message, results, cwd, titleFor) {
23
23
  switch (message.role) {
24
24
  case "user":
25
25
  return message.content === ""
@@ -37,17 +37,17 @@ function replayMessage(message, results, cwd) {
37
37
  const said = message.content === ""
38
38
  ? []
39
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));
40
+ const calls = (message.toolCalls ?? []).map((call) => replayCall(call, results.get(call.id), cwd, titleFor));
41
41
  return [...thoughts, ...said, ...calls];
42
42
  }
43
43
  }
44
44
  }
45
- export function replayTranscript(messages, cwd) {
45
+ export function replayTranscript(messages, cwd, titleFor) {
46
46
  const results = new Map();
47
47
  for (const message of messages) {
48
48
  if (message.role === "tool-result") {
49
49
  results.set(message.toolCallId, { content: message.content, isError: message.isError === true });
50
50
  }
51
51
  }
52
- return messages.flatMap((message) => replayMessage(message, results, cwd));
52
+ return messages.flatMap((message) => replayMessage(message, results, cwd, titleFor));
53
53
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nathapp/nax-agent-acp",
3
- "version": "0.84.0",
3
+ "version": "0.85.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",
@@ -49,7 +49,7 @@
49
49
  "zod": "^4.3.6"
50
50
  },
51
51
  "peerDependencies": {
52
- "@nathapp/nax-agent": "^0.84.0"
52
+ "@nathapp/nax-agent": "^0.85.0"
53
53
  },
54
54
  "publishConfig": {
55
55
  "access": "public",