@nathapp/nax-agent-acp 0.91.4 → 0.91.6
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 +8 -0
- package/dist/client/backend.js +8 -1
- package/dist/client/edit-targets.d.ts +1 -1
- package/dist/client/edit-targets.js +5 -2
- package/dist/client/permissions.d.ts +2 -0
- package/dist/client/permissions.js +1 -1
- package/dist/server/registry.js +5 -1
- package/dist/server/server-session.d.ts +2 -0
- package/dist/server/server-session.js +90 -37
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to `@nathapp/nax-agent-acp` are recorded here. Versions move in
|
|
4
4
|
step with `@nathapp/nax-agent`.
|
|
5
5
|
|
|
6
|
+
## [0.91.6] - 2026-10-24
|
|
7
|
+
|
|
8
|
+
- No changes in this package. Released in lockstep with the other nax packages.
|
|
9
|
+
|
|
10
|
+
## [0.91.5] - 2026-10-23
|
|
11
|
+
|
|
12
|
+
- No changes in this package. Released in lockstep with the other nax packages.
|
|
13
|
+
|
|
6
14
|
## [0.91.4] - 2026-10-23
|
|
7
15
|
|
|
8
16
|
- No changes in this package. Released in lockstep with the other nax packages.
|
package/dist/client/backend.js
CHANGED
|
@@ -92,7 +92,14 @@ function routerFor(ctx, options) {
|
|
|
92
92
|
cwd: ctx.workdir,
|
|
93
93
|
agentName: options.agentName,
|
|
94
94
|
rules: options.rules,
|
|
95
|
-
...(sandbox === undefined
|
|
95
|
+
...(sandbox === undefined
|
|
96
|
+
? {}
|
|
97
|
+
: {
|
|
98
|
+
sandbox,
|
|
99
|
+
...(ctx.sandbox?.kind === "policy" && ctx.sandbox.writeExemption !== undefined
|
|
100
|
+
? { writeExemption: ctx.sandbox.writeExemption }
|
|
101
|
+
: {}),
|
|
102
|
+
}),
|
|
96
103
|
...(options.shellSandboxPlan === undefined
|
|
97
104
|
? {}
|
|
98
105
|
: {
|
|
@@ -6,4 +6,4 @@ export declare const _editTargetsDeps: {
|
|
|
6
6
|
platform: () => string;
|
|
7
7
|
};
|
|
8
8
|
export declare function editTargets(toolCall: unknown): readonly string[];
|
|
9
|
-
export declare function firstOutsidePolicy(targets: readonly string[], policy: SandboxPolicy, cwd: string | undefined): Promise<string | undefined>;
|
|
9
|
+
export declare function firstOutsidePolicy(targets: readonly string[], policy: SandboxPolicy, cwd: string | undefined, writeExemption?: string): Promise<string | undefined>;
|
|
@@ -111,9 +111,10 @@ const contains = (path, root) => path === root || path.startsWith(root.endsWith(
|
|
|
111
111
|
const withinRoot = (path, root) => contains(nfc(path), nfc(root));
|
|
112
112
|
/** denyWrite matching: case-folded on darwin and win32, so a differently cased spelling is still denied. */
|
|
113
113
|
const withinDenied = (path, denied) => contains(foldCase(nfc(path)), foldCase(nfc(denied)));
|
|
114
|
-
export async function firstOutsidePolicy(targets, policy, cwd) {
|
|
114
|
+
export async function firstOutsidePolicy(targets, policy, cwd, writeExemption) {
|
|
115
115
|
const roots = await Promise.all(policy.writeRoots.map(canonicalPolicyPath));
|
|
116
116
|
const denied = await Promise.all(policy.denyWrite.map(canonicalPolicyPath));
|
|
117
|
+
const exemption = writeExemption === undefined ? undefined : await canonical(writeExemption);
|
|
117
118
|
for (const target of targets) {
|
|
118
119
|
if (hasDotDotSegment(target))
|
|
119
120
|
return target;
|
|
@@ -123,7 +124,9 @@ export async function firstOutsidePolicy(targets, policy, cwd) {
|
|
|
123
124
|
const real = await canonical(absolute);
|
|
124
125
|
if (real === undefined)
|
|
125
126
|
return target;
|
|
126
|
-
|
|
127
|
+
// Only this exact canonical file bypasses denyWrite; containment and traversal still apply.
|
|
128
|
+
const exempt = exemption !== undefined && nfc(real) === nfc(exemption);
|
|
129
|
+
if ((!exempt && denied.some((d) => withinDenied(real, d))) || !roots.some((r) => withinRoot(real, r)))
|
|
127
130
|
return target;
|
|
128
131
|
}
|
|
129
132
|
return undefined;
|
|
@@ -38,6 +38,8 @@ export interface PermissionContext {
|
|
|
38
38
|
readonly signal: AbortSignal;
|
|
39
39
|
/** nax#2500: the session sandbox policy (review/full on claude); drives the network and R4 path rules. */
|
|
40
40
|
readonly sandbox?: SandboxPolicy;
|
|
41
|
+
/** Single writable output; bypasses denyWrite only, never write-root containment. */
|
|
42
|
+
readonly writeExemption?: string;
|
|
41
43
|
/** nax#2500: the session cwd, for resolving relative edit targets (R4). */
|
|
42
44
|
readonly cwd?: string;
|
|
43
45
|
/**
|
|
@@ -177,7 +177,7 @@ async function decideFull(request, display, offered, auto, ctx) {
|
|
|
177
177
|
const targets = editTargets(request.toolCall);
|
|
178
178
|
const unknownWrite = ctx.sandbox !== undefined && WRITE_KINDS.has(display.tool) && targets.length === 0;
|
|
179
179
|
const outside = ctx.sandbox !== undefined && display.tool !== "execute" && !READ_ONLY_KINDS.has(display.tool)
|
|
180
|
-
? await firstOutsidePolicy(targets, ctx.sandbox, ctx.cwd)
|
|
180
|
+
? await firstOutsidePolicy(targets, ctx.sandbox, ctx.cwd, ctx.writeExemption)
|
|
181
181
|
: undefined;
|
|
182
182
|
if (unknownWrite || outside !== undefined) {
|
|
183
183
|
auto(OUTSIDE_WRITE_ROOTS_REASON, "deny");
|
package/dist/server/registry.js
CHANGED
|
@@ -161,7 +161,11 @@ export function createSessionRegistry(deps) {
|
|
|
161
161
|
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)));
|
|
162
162
|
}
|
|
163
163
|
catch (error) {
|
|
164
|
-
|
|
164
|
+
// A terminal close that interrupted the switch owns the cleanup (Approach 4):
|
|
165
|
+
// its closeRegistryEntry/closeEntries/delete awaits close(), then releases the
|
|
166
|
+
// lock and closes the MCP tools. Cleaning up here too would release the lock
|
|
167
|
+
// twice. Only a switch that failed on its own leaves a dead entry to clean.
|
|
168
|
+
if (entry.server.isClosed() && !entry.server.isClosing()) {
|
|
165
169
|
try {
|
|
166
170
|
await closeEntry(sessionId, entry);
|
|
167
171
|
}
|
|
@@ -41,6 +41,8 @@ export interface ServerSession {
|
|
|
41
41
|
/** Close-and-reopen for a mode or config change (spec §3.3); `restore` reopens the old settings when `open` fails. */
|
|
42
42
|
switchTo(open: () => Promise<SwitchTarget>, restore: () => Promise<SwitchTarget>): Promise<void>;
|
|
43
43
|
isClosed(): boolean;
|
|
44
|
+
/** A terminal close() was requested, whether or not it has finished (spec §Design 1). */
|
|
45
|
+
isClosing(): boolean;
|
|
44
46
|
cancel(): void;
|
|
45
47
|
close(): Promise<void>;
|
|
46
48
|
}
|
|
@@ -21,6 +21,10 @@ const CANCELLED_BEFORE_SEND = {
|
|
|
21
21
|
response: { stopReason: "cancelled", usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 } },
|
|
22
22
|
notices: [],
|
|
23
23
|
};
|
|
24
|
+
const SESSION_CLOSED = "session is closed";
|
|
25
|
+
function sessionClosed() {
|
|
26
|
+
return RequestError.invalidRequest(undefined, SESSION_CLOSED);
|
|
27
|
+
}
|
|
24
28
|
function react(event, turn, translator) {
|
|
25
29
|
switch (event.type) {
|
|
26
30
|
case "approval_requested":
|
|
@@ -78,6 +82,12 @@ export function createServerSession(deps) {
|
|
|
78
82
|
let queued = [];
|
|
79
83
|
let costUsd = deps.priorCostUsd ?? 0;
|
|
80
84
|
let closed = false;
|
|
85
|
+
/** The closing flag: set by the first close(), so isClosing() is true from then on. */
|
|
86
|
+
let closeRequested = false;
|
|
87
|
+
/** The in-flight switchTo, while its gap runs (§Design 2). */
|
|
88
|
+
let switching;
|
|
89
|
+
/** Whether the current agent is a live S3 session: false from the moment a switch closes it. */
|
|
90
|
+
let live = true;
|
|
81
91
|
let running = false;
|
|
82
92
|
/** A cancel before send() claimed the S3 turn, where AgentSession.cancel() is a no-op. */
|
|
83
93
|
let cancelBeforeSend = false;
|
|
@@ -150,9 +160,68 @@ export function createServerSession(deps) {
|
|
|
150
160
|
}
|
|
151
161
|
return outcome;
|
|
152
162
|
}
|
|
163
|
+
/** Adopts the session a switch's `open` or `restore` returned, and marks it live. */
|
|
164
|
+
function adopt(target) {
|
|
165
|
+
agent = target.session;
|
|
166
|
+
contextWindow = target.contextWindow;
|
|
167
|
+
live = true;
|
|
168
|
+
}
|
|
169
|
+
/** `open`, else `restore`; the open error survives even a successful restore. */
|
|
170
|
+
async function openOrRestore(open, restore) {
|
|
171
|
+
try {
|
|
172
|
+
return { kind: "opened", target: await open() };
|
|
173
|
+
}
|
|
174
|
+
catch (failure) {
|
|
175
|
+
try {
|
|
176
|
+
return { kind: "restored", target: await restore(), failure };
|
|
177
|
+
}
|
|
178
|
+
catch (restoreError) {
|
|
179
|
+
deps.logger.error("session", "could not reopen the session after a failed switch", {
|
|
180
|
+
sessionId: deps.session.id,
|
|
181
|
+
error: messageOf(restoreError),
|
|
182
|
+
});
|
|
183
|
+
return { kind: "failed", failure };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* One switchTo (§3.3, §Design 2-3): close the old S3 session, then adopt what
|
|
189
|
+
* `open` or `restore` left. A close requested meanwhile keeps the session
|
|
190
|
+
* closed and turns the outcome into `session is closed`, after the adoption so
|
|
191
|
+
* close() still knows what to close. Any failed open rejects, whatever its
|
|
192
|
+
* reason, including an `undefined` one.
|
|
193
|
+
*/
|
|
194
|
+
async function switchSession(open, restore) {
|
|
195
|
+
stopWaiting();
|
|
196
|
+
closed = true;
|
|
197
|
+
live = false;
|
|
198
|
+
try {
|
|
199
|
+
await agent.close();
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
deps.logger.warn("session", "session close failed during switch", {
|
|
203
|
+
sessionId: deps.session.id,
|
|
204
|
+
error: messageOf(error),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const outcome = await openOrRestore(open, restore);
|
|
208
|
+
// Nothing was adopted: the session stays dead for the registry's cleanup.
|
|
209
|
+
if (outcome.kind === "failed") {
|
|
210
|
+
if (closeRequested)
|
|
211
|
+
throw sessionClosed();
|
|
212
|
+
throw outcome.failure;
|
|
213
|
+
}
|
|
214
|
+
adopt(outcome.target);
|
|
215
|
+
if (closeRequested)
|
|
216
|
+
throw sessionClosed();
|
|
217
|
+
closed = false;
|
|
218
|
+
if (outcome.kind === "restored")
|
|
219
|
+
throw outcome.failure;
|
|
220
|
+
}
|
|
153
221
|
return {
|
|
154
222
|
id: deps.session.id,
|
|
155
223
|
isClosed: () => closed,
|
|
224
|
+
isClosing: () => closeRequested,
|
|
156
225
|
get running() {
|
|
157
226
|
return running;
|
|
158
227
|
},
|
|
@@ -163,7 +232,7 @@ export function createServerSession(deps) {
|
|
|
163
232
|
if (running)
|
|
164
233
|
throw turnInProgress();
|
|
165
234
|
if (closed)
|
|
166
|
-
throw
|
|
235
|
+
throw sessionClosed();
|
|
167
236
|
const message = flattenPrompt(blocks);
|
|
168
237
|
running = true;
|
|
169
238
|
cancelBeforeSend = false;
|
|
@@ -194,45 +263,18 @@ export function createServerSession(deps) {
|
|
|
194
263
|
},
|
|
195
264
|
async switchTo(open, restore) {
|
|
196
265
|
if (closed)
|
|
197
|
-
throw
|
|
266
|
+
throw sessionClosed();
|
|
198
267
|
if (running)
|
|
199
268
|
throw turnInProgress();
|
|
200
269
|
running = true;
|
|
270
|
+
const work = switchSession(open, restore);
|
|
271
|
+
switching = work;
|
|
201
272
|
try {
|
|
202
|
-
|
|
203
|
-
closed = true;
|
|
204
|
-
try {
|
|
205
|
-
await agent.close();
|
|
206
|
-
}
|
|
207
|
-
catch (error) {
|
|
208
|
-
deps.logger.warn("session", "session close failed during switch", {
|
|
209
|
-
sessionId: deps.session.id,
|
|
210
|
-
error: messageOf(error),
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
try {
|
|
214
|
-
const next = await open();
|
|
215
|
-
closed = false;
|
|
216
|
-
agent = next.session;
|
|
217
|
-
contextWindow = next.contextWindow;
|
|
218
|
-
}
|
|
219
|
-
catch (error) {
|
|
220
|
-
try {
|
|
221
|
-
const back = await restore();
|
|
222
|
-
closed = false;
|
|
223
|
-
agent = back.session;
|
|
224
|
-
contextWindow = back.contextWindow;
|
|
225
|
-
}
|
|
226
|
-
catch (restoreError) {
|
|
227
|
-
deps.logger.error("session", "could not reopen the session after a failed switch", {
|
|
228
|
-
sessionId: deps.session.id,
|
|
229
|
-
error: messageOf(restoreError),
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
throw error;
|
|
233
|
-
}
|
|
273
|
+
await work;
|
|
234
274
|
}
|
|
235
275
|
finally {
|
|
276
|
+
// Cleared before this promise settles, whatever the outcome (§Design 2).
|
|
277
|
+
switching = undefined;
|
|
236
278
|
running = false;
|
|
237
279
|
}
|
|
238
280
|
},
|
|
@@ -245,15 +287,26 @@ export function createServerSession(deps) {
|
|
|
245
287
|
close() {
|
|
246
288
|
if (closing !== undefined)
|
|
247
289
|
return closing;
|
|
248
|
-
|
|
249
|
-
|
|
290
|
+
closeRequested = true;
|
|
291
|
+
// A switch whose open and restore both failed leaves a dead session that
|
|
292
|
+
// the registry's dead-entry cleanup closes: nothing here to close.
|
|
293
|
+
if (closed && switching === undefined) {
|
|
294
|
+
closing = Promise.resolve();
|
|
295
|
+
return closing;
|
|
296
|
+
}
|
|
297
|
+
const inFlight = switching;
|
|
250
298
|
closed = true; // Refuse new prompts/switches before the first await.
|
|
251
299
|
cancelBeforeSend = true;
|
|
252
300
|
agent.cancel("session is closing");
|
|
253
301
|
stopWaiting();
|
|
254
302
|
closing = (async () => {
|
|
303
|
+
// The switch owns `agent` until it settles; then close only what it
|
|
304
|
+
// left live, so a switch that left nothing is not closed twice.
|
|
305
|
+
if (inFlight !== undefined)
|
|
306
|
+
await inFlight.catch(() => undefined);
|
|
255
307
|
try {
|
|
256
|
-
|
|
308
|
+
if (live)
|
|
309
|
+
await agent.close();
|
|
257
310
|
}
|
|
258
311
|
finally {
|
|
259
312
|
// AgentSession.close need not await the facade's event delivery or
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nathapp/nax-agent-acp",
|
|
3
|
-
"version": "0.91.
|
|
3
|
+
"version": "0.91.6",
|
|
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.91.
|
|
52
|
+
"@nathapp/nax-agent": "^0.91.6"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public",
|