@nathapp/nax-agent-acp 0.90.0 → 0.90.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.
@@ -1,4 +1,6 @@
1
1
  import { editTargets, firstOutsidePolicy, OUTSIDE_WRITE_ROOTS_REASON, WRITE_KINDS } from "#src/client/edit-targets";
2
+ import { NO_RULES } from "#src/client/rule-policy";
3
+ import { SHELL_RULE_REASON, shellCommandOf, shellRuleVerdict } from "#src/client/shell-rules";
2
4
  import { isRecord } from "#src/client/text";
3
5
  import { describeToolCall } from "#src/client/tool-display";
4
6
  export const NO_ALLOW_ONCE_REASON = "agent offered no allow-once option";
@@ -34,6 +36,15 @@ export function offeredOptions(request) {
34
36
  ...(rejectOnce === undefined ? {} : { rejectOnce }),
35
37
  };
36
38
  }
39
+ /** A deny: `cancelled`, or a selected option the agent offered as a reject kind (nax#2582). */
40
+ export function isDenial(request, response) {
41
+ if (response.outcome.outcome === "cancelled")
42
+ return true;
43
+ const { optionId } = response.outcome;
44
+ const options = Array.isArray(request.options) ? request.options : [];
45
+ const chosen = options.find((option) => isRecord(option) && option.optionId === optionId);
46
+ return isRecord(chosen) && (chosen.kind === "reject_once" || chosen.kind === "reject_always");
47
+ }
37
48
  const cancelled = () => ({ outcome: { outcome: "cancelled" } });
38
49
  const selected = (optionId) => ({ outcome: { outcome: "selected", optionId } });
39
50
  /** A deny: the agent's reject_once, or `cancelled` when it offered none. */
@@ -69,18 +80,7 @@ export async function decidePermission(request, ctx) {
69
80
  auto(readOnlyReason(ctx.profile), "deny");
70
81
  return rejectWith(offered);
71
82
  case "review":
72
- if (display.tool !== "execute") {
73
- auto(readOnlyReason(ctx.profile), "deny");
74
- return rejectWith(offered);
75
- }
76
- if (ctx.sandbox === undefined) {
77
- auto(REVIEW_NO_SANDBOX_REASON, "deny");
78
- return rejectWith(offered);
79
- }
80
- if (offered.allowOnce === undefined)
81
- return denyNoAllowOnce(offered, auto);
82
- auto(REVIEW_EXECUTE_REASON, "allow");
83
- return selected(offered.allowOnce);
83
+ return decideReview(request, display, offered, auto, ctx);
84
84
  case "full":
85
85
  return decideFull(request, display, offered, auto, ctx);
86
86
  case "ask":
@@ -97,6 +97,39 @@ export async function decidePermission(request, ctx) {
97
97
  return rejectWith(offered);
98
98
  }
99
99
  }
100
+ /**
101
+ * review (SPEC-cursor-pi-acp-read-only US-003): a command may run when a sandbox
102
+ * holds it (Claude, nax#2500) or when the operator's own Bash rules allow the
103
+ * raw command. With no sandbox the rules are the whole decision — a command nax
104
+ * cannot read, a redirect, an opaque token, no allow rule, or an ask rule all
105
+ * deny — and everything that is not a command stays read-only.
106
+ */
107
+ function decideReview(request, display, offered, auto, ctx) {
108
+ if (ctx.sandbox !== undefined) {
109
+ if (display.tool !== "execute") {
110
+ auto(readOnlyReason(ctx.profile), "deny");
111
+ return rejectWith(offered);
112
+ }
113
+ if (offered.allowOnce === undefined)
114
+ return denyNoAllowOnce(offered, auto);
115
+ auto(REVIEW_EXECUTE_REASON, "allow");
116
+ return selected(offered.allowOnce);
117
+ }
118
+ const command = shellCommandOf(ctx.agentName ?? "", request.toolCall);
119
+ if (command === undefined) {
120
+ // An execute request with no derivable command fails closed; anything else was never a command.
121
+ auto(display.tool === "execute" ? REVIEW_NO_SANDBOX_REASON : readOnlyReason(ctx.profile), "deny");
122
+ return rejectWith(offered);
123
+ }
124
+ if (shellRuleVerdict(command, ctx.rules ?? NO_RULES) === "deny") {
125
+ auto(REVIEW_NO_SANDBOX_REASON, "deny");
126
+ return rejectWith(offered);
127
+ }
128
+ if (offered.allowOnce === undefined)
129
+ return denyNoAllowOnce(offered, auto);
130
+ auto(SHELL_RULE_REASON, "allow");
131
+ return selected(offered.allowOnce);
132
+ }
100
133
  /**
101
134
  * ACP kinds exempt from the R4 path check (nax#2500 R5/R8): they do not write a path
102
135
  * the sandbox has to police. execute is the Bash sandbox's job. Every other kind,
@@ -0,0 +1,17 @@
1
+ /** Every file-system call the writers make; a test overrides them before any real write. */
2
+ export interface PolicyFileDeps {
3
+ mkdir(path: string, options: {
4
+ readonly recursive: true;
5
+ readonly mode: number;
6
+ }): Promise<unknown>;
7
+ writeFile(path: string, content: string): Promise<unknown>;
8
+ chmod(path: string, mode: number): Promise<unknown>;
9
+ rename(from: string, to: string): Promise<unknown>;
10
+ }
11
+ export declare const _policyFilesDeps: PolicyFileDeps;
12
+ /** The two pi files: the gate extension pi loads, and the wrapper `PI_ACP_PI_COMMAND` names. */
13
+ export type PiPolicyFile = "shell-gate" | "wrapper";
14
+ /** Cursor's isolated config: `<stateDir>/cursor/<h>/cli-config.json`. Returns the directory to point CURSOR_CONFIG_DIR at. */
15
+ export declare function writeCursorPolicy(stateDir: string, content: string): Promise<string>;
16
+ /** pi's `<stateDir>/pi/<name>-<h><ext>`; returns the file path. */
17
+ export declare function writePiFile(stateDir: string, name: PiPolicyFile, content: string, mode: number): Promise<string>;
@@ -0,0 +1,65 @@
1
+ /**
2
+ * The policy files Cursor and pi read (SPEC-cursor-pi-acp-read-only US-004).
3
+ * Neither agent reads nax's rules directly: Cursor loads a `cli-config.json` from
4
+ * `CURSOR_CONFIG_DIR` and pi loads an extension with `-e` and takes its tool
5
+ * allowlist from `--tools`, so nax writes the files and points the process's
6
+ * environment at them (rule-policy.ts).
7
+ *
8
+ * Each file is content-addressed — the first 16 hex characters of the SHA-256 of
9
+ * its body — and written atomically through a temporary name in its target
10
+ * directory, on every launch: Cursor rewrites its config itself, and a rewrite
11
+ * replaces a planted or half-written file. The state directory's owner is the
12
+ * trust boundary; this package creates the directories 0700 and never reads back
13
+ * what is already there.
14
+ */
15
+ import { createHash, randomBytes } from "node:crypto";
16
+ import { chmod, mkdir, rename, writeFile } from "node:fs/promises";
17
+ import { basename, dirname, join } from "node:path";
18
+ import { backendUnavailable } from "#src/client/errors";
19
+ export const _policyFilesDeps = { mkdir, writeFile, chmod, rename };
20
+ const PI_EXTENSIONS = Object.freeze({ "shell-gate": ".ts", wrapper: ".sh" });
21
+ /** Nothing here is readable by another user: the directory is ours, the policy files are ours. */
22
+ const DIR_MODE = 0o700;
23
+ const CURSOR_CONFIG_MODE = 0o600;
24
+ /** The content-addressed part of a policy path. */
25
+ function digest(content) {
26
+ return createHash("sha256").update(content).digest("hex").slice(0, 16);
27
+ }
28
+ function messageOf(err) {
29
+ return err instanceof Error ? err.message : String(err);
30
+ }
31
+ /**
32
+ * `target` with `content`, atomically and every time. The chmod runs on the
33
+ * temporary file before the rename, so the umask cannot narrow the mode and no
34
+ * reader ever sees a partial file. The temporary name is unique per call: two
35
+ * opens racing on the same content (two sessions, one process) never rename each
36
+ * other's file away. Any failure refuses the open — the caller has launched
37
+ * nothing yet — naming the path that could not be written.
38
+ */
39
+ async function writeAtomic(target, content, mode) {
40
+ const dir = dirname(target);
41
+ const temp = join(dir, `${basename(target)}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`);
42
+ try {
43
+ await _policyFilesDeps.mkdir(dir, { recursive: true, mode: DIR_MODE });
44
+ await _policyFilesDeps.writeFile(temp, content);
45
+ await _policyFilesDeps.chmod(temp, mode);
46
+ await _policyFilesDeps.rename(temp, target);
47
+ }
48
+ catch (err) {
49
+ throw backendUnavailable(`the read-only policy file "${target}" could not be written: ${messageOf(err)}`, {
50
+ path: target,
51
+ });
52
+ }
53
+ }
54
+ /** Cursor's isolated config: `<stateDir>/cursor/<h>/cli-config.json`. Returns the directory to point CURSOR_CONFIG_DIR at. */
55
+ export async function writeCursorPolicy(stateDir, content) {
56
+ const dir = join(stateDir, "cursor", digest(content));
57
+ await writeAtomic(join(dir, "cli-config.json"), content, CURSOR_CONFIG_MODE);
58
+ return dir;
59
+ }
60
+ /** pi's `<stateDir>/pi/<name>-<h><ext>`; returns the file path. */
61
+ export async function writePiFile(stateDir, name, content, mode) {
62
+ const target = join(stateDir, "pi", `${name}-${digest(content)}${PI_EXTENSIONS[name]}`);
63
+ await writeAtomic(target, content, mode);
64
+ return target;
65
+ }
@@ -6,7 +6,7 @@
6
6
  * agents (`{ name, command }`) have no entry: no mode ids, no pre-approval and no
7
7
  * auth variables, so their requirements fail closed.
8
8
  */
9
- export type AcpAgentName = "claude" | "codex" | "gemini" | "opencode" | "pi";
9
+ export type AcpAgentName = "claude" | "codex" | "cursor" | "gemini" | "opencode" | "pi";
10
10
  export interface LaunchCandidate {
11
11
  readonly command: string;
12
12
  readonly args: readonly string[];
@@ -17,23 +17,34 @@ export interface ModeSetting {
17
17
  readonly value: string;
18
18
  }
19
19
  /**
20
- * How profiles none and read are enforced on this agent (§6.4 layer 1, as revised
21
- * by the 2026-10-07 fix bundle). Applied through the agent's pre-approval channel,
22
- * so only an agent with one may declare it.
20
+ * How profiles none, read and review are enforced on this agent (§6.4 layer 1, as
21
+ * revised by the 2026-10-07 fix bundle). An agent may enforce read-only through its
22
+ * mode alone (codex-acp's `read-only`, nax#2372) or through variables injected into
23
+ * its process environment (opencode's `OPENCODE_CONFIG_CONTENT` permission policy);
24
+ * `disallowedTools` and `sessionOptions` go through the pre-approval channel and are
25
+ * empty for an agent that has none.
23
26
  */
24
27
  export interface ReadOnlyEnforcement {
25
- /** The mode set for none/read. */
26
- readonly mode: ModeSetting;
27
- /** Agent tools removed from the session under none/read. */
28
+ /** The mode set for none/read/review; undefined means nax sets no mode for them. */
29
+ readonly mode: ModeSetting | undefined;
30
+ /** Agent tools removed from the session under none/read/review. */
28
31
  readonly disallowedTools: readonly string[];
29
- /** Extra agent options under none/read, merged into the pre-approval channel's options. */
32
+ /** Extra agent options under none/read/review, merged into the pre-approval channel's options. */
30
33
  readonly sessionOptions: Readonly<Record<string, unknown>>;
34
+ /** Extra agent process environment under none/read/review, by profile; {} when the agent needs none. */
35
+ readonly launchEnv: Readonly<Partial<Record<"none" | "read" | "review", Readonly<Record<string, string>>>>>;
36
+ /**
37
+ * The rule-policy translator that builds this agent's launch env from nax's
38
+ * permission rules (rule-policy.ts); undefined means the agent's env is the
39
+ * `launchEnv` above, whatever the rules.
40
+ */
41
+ readonly policy: "opencode" | "cursor" | "pi" | undefined;
31
42
  }
32
43
  export interface AgentRegistryEntry {
33
44
  readonly name: AcpAgentName;
34
45
  /** Tried in order; the first command found wins (S4-2 launch). */
35
46
  readonly launch: readonly LaunchCandidate[];
36
- /** How profiles `none` and `read` are enforced; undefined means those profiles are unsupported (§6.4). */
47
+ /** How profiles `none`, `read` and `review` are enforced; undefined means those profiles are unsupported (§6.4). */
37
48
  readonly readOnly: ReadOnlyEnforcement | undefined;
38
49
  /** Mode for profiles `ask` and `full`; undefined means the agent's own default is kept. */
39
50
  readonly defaultMode: ModeSetting | undefined;
@@ -42,6 +53,12 @@ export interface AgentRegistryEntry {
42
53
  /** Variables passed through the env allowlist so the adapter can authenticate itself (§6.2). */
43
54
  readonly authEnv: readonly string[];
44
55
  }
56
+ /** none: no tool at all. */
57
+ export declare const OPENCODE_NONE_CONFIG: string;
58
+ /** read: only opencode's read tools. */
59
+ export declare const OPENCODE_READ_CONFIG: string;
60
+ /** review: the read tools, plus shell commands asked of nax (decided by the review rule). */
61
+ export declare const OPENCODE_REVIEW_CONFIG: string;
45
62
  export declare const ACP_AGENT_NAMES: readonly AcpAgentName[];
46
63
  export declare function isAcpAgentName(name: string): name is AcpAgentName;
47
64
  /** The registry entry for a registered agent name; undefined for anything else (custom agents included). */
@@ -15,19 +15,38 @@ function freezeReadOnly(readOnly) {
15
15
  key,
16
16
  Array.isArray(value) ? Object.freeze([...value]) : value,
17
17
  ]);
18
+ const launchEnv = Object.entries(readOnly.launchEnv).map(([profile, env]) => [profile, Object.freeze({ ...env })]);
19
+ // A mode-less agent (opencode, nax#2372) sets no mode at all: there is nothing to copy.
20
+ const mode = readOnly.mode === undefined ? undefined : Object.freeze({ ...readOnly.mode });
18
21
  return Object.freeze({
19
- mode: Object.freeze({ ...readOnly.mode }),
22
+ mode,
20
23
  disallowedTools: Object.freeze([...readOnly.disallowedTools]),
21
24
  sessionOptions: Object.freeze(Object.fromEntries(options)),
25
+ launchEnv: Object.freeze(Object.fromEntries(launchEnv)),
26
+ policy: readOnly.policy,
22
27
  });
23
28
  }
24
- function entry(name, launch, authEnv, claude) {
29
+ // opencode's permission policy, injected as `OPENCODE_CONFIG_CONTENT` (its highest-rank
30
+ // config source). Rules are last-match-wins over { action, resource }, so the catch-all
31
+ // deny comes first and each allowance after it. A denied tool is removed from opencode's
32
+ // catalog, so the model never sees it.
33
+ /** none: no tool at all. */
34
+ export const OPENCODE_NONE_CONFIG = JSON.stringify({ permission: { "*": "deny" } });
35
+ /** read: only opencode's read tools. */
36
+ export const OPENCODE_READ_CONFIG = JSON.stringify({
37
+ permission: { "*": "deny", read: "allow", glob: "allow", grep: "allow", list: "allow" },
38
+ });
39
+ /** review: the read tools, plus shell commands asked of nax (decided by the review rule). */
40
+ export const OPENCODE_REVIEW_CONFIG = JSON.stringify({
41
+ permission: { "*": "deny", read: "allow", glob: "allow", grep: "allow", list: "allow", bash: "ask" },
42
+ });
43
+ function entry(name, launch, authEnv, policy) {
25
44
  return Object.freeze({
26
45
  name,
27
46
  launch: Object.freeze(launch.map((c) => Object.freeze({ command: c.command, args: Object.freeze([...c.args]) }))),
28
- readOnly: freezeReadOnly(claude?.readOnly),
29
- defaultMode: claude?.defaultMode === undefined ? undefined : Object.freeze({ ...claude.defaultMode }),
30
- preApproval: claude?.preApproval,
47
+ readOnly: freezeReadOnly(policy?.readOnly),
48
+ defaultMode: policy?.defaultMode === undefined ? undefined : Object.freeze({ ...policy.defaultMode }),
49
+ preApproval: policy?.preApproval,
31
50
  authEnv: Object.freeze([...authEnv]),
32
51
  });
33
52
  }
@@ -42,16 +61,112 @@ const REGISTRY = new Map([
42
61
  mode: { configId: "mode", value: "default" },
43
62
  disallowedTools: ["Write", "Edit", "MultiEdit", "NotebookEdit", "EnterPlanMode"],
44
63
  sessionOptions: { settingSources: [], allowDangerouslySkipPermissions: false },
64
+ launchEnv: {},
65
+ policy: undefined,
45
66
  },
46
67
  defaultMode: { configId: "mode", value: "default" },
47
68
  preApproval: "claudeCode.allowedTools",
48
69
  }),
49
70
  ],
50
- ["codex", entry("codex", [local("codex-acp"), npx("@agentclientprotocol/codex-acp@~2.1.1")], ["OPENAI_API_KEY"])],
51
- ["gemini", entry("gemini", [local("gemini", "--acp")], ["GEMINI_API_KEY"])],
52
- ["opencode", entry("opencode", [local("opencode", "acp")], [])],
71
+ [
72
+ "codex",
73
+ entry("codex", [local("codex-acp"), npx("@agentclientprotocol/codex-acp@~2.1.1")], ["OPENAI_API_KEY"], {
74
+ // nax#2372: codex-acp enforces none/read/review with its own `read-only` mode (OS
75
+ // sandbox, read-only filesystem, no network, every escalation asked of us). It has
76
+ // no pre-approval channel, so no settings and no removed tools ride along; full and
77
+ // ask keep the launch mode (US-002 sets it from config).
78
+ readOnly: {
79
+ mode: { configId: "mode", value: "read-only" },
80
+ disallowedTools: [],
81
+ sessionOptions: {},
82
+ launchEnv: {},
83
+ policy: undefined,
84
+ },
85
+ defaultMode: undefined,
86
+ preApproval: undefined,
87
+ }),
88
+ ],
89
+ // nax#2372: cursor's own modes do not enforce anything (probed: mode `ask` let a forced
90
+ // write through, mode `plan` let the model switch back to `agent` and write), so `ask`
91
+ // only tells the model it is read-only; the real enforcement is its permission config
92
+ // (US-004: an isolated cli-config.json, pointed at by CURSOR_CONFIG_DIR). No plan mode
93
+ // is ever used here.
94
+ [
95
+ "cursor",
96
+ entry("cursor", [local("cursor-agent", "acp")], ["CURSOR_API_KEY"], {
97
+ readOnly: {
98
+ mode: { configId: "mode", value: "ask" },
99
+ disallowedTools: [],
100
+ sessionOptions: {},
101
+ launchEnv: {},
102
+ policy: "cursor",
103
+ },
104
+ defaultMode: undefined,
105
+ preApproval: undefined,
106
+ }),
107
+ ],
108
+ // nax#2372: gemini's `plan` mode is its read-only mode (read tools only, no shell
109
+ // tool). It has no pre-approval channel, so no settings and no removed tools ride
110
+ // along; full and ask keep the launch mode.
111
+ [
112
+ "gemini",
113
+ entry("gemini", [local("gemini", "--acp")], ["GEMINI_API_KEY"], {
114
+ readOnly: {
115
+ mode: { configId: "mode", value: "plan" },
116
+ disallowedTools: [],
117
+ sessionOptions: {},
118
+ launchEnv: {},
119
+ policy: undefined,
120
+ },
121
+ defaultMode: undefined,
122
+ preApproval: undefined,
123
+ }),
124
+ ],
125
+ // nax#2372: opencode has no read-only mode (its `plan` agent still runs shell and web
126
+ // tools). Enforcement is its own permission config, injected per profile as an env
127
+ // variable: opencode denies every tool, then allows its read tools back for read and
128
+ // review, and under review asks nax about each shell command. No mode is set, and it
129
+ // has no pre-approval channel (embedder tools stay unsupported). The launch env below
130
+ // is what an operator with no read-tool deny rule gets; `policy: "opencode"` lets
131
+ // rule-policy.ts translate an unconditional deny of Read, Glob or Grep instead.
132
+ [
133
+ "opencode",
134
+ entry("opencode", [local("opencode", "acp")], [], {
135
+ readOnly: {
136
+ mode: undefined,
137
+ disallowedTools: [],
138
+ sessionOptions: {},
139
+ launchEnv: {
140
+ none: { OPENCODE_CONFIG_CONTENT: OPENCODE_NONE_CONFIG },
141
+ read: { OPENCODE_CONFIG_CONTENT: OPENCODE_READ_CONFIG },
142
+ review: { OPENCODE_CONFIG_CONTENT: OPENCODE_REVIEW_CONFIG },
143
+ },
144
+ policy: "opencode",
145
+ },
146
+ defaultMode: undefined,
147
+ preApproval: undefined,
148
+ }),
149
+ ],
53
150
  // Exact pin: a tilde range does not pin 0.0.x.
54
- ["pi", entry("pi", [local("pi-acp"), npx("pi-acp@0.0.34")], [])],
151
+ // nax#2372, US-004: pi has no mode and no permission config of its own. Read-only is
152
+ // its own tool allowlist (`--tools` / `--no-tools`) plus, under review, the gate
153
+ // extension that turns every bash call into a confirm prompt nax decides
154
+ // (rule-policy.ts, shell-rules.ts). Both are written per launch and named by the
155
+ // wrapper PI_ACP_PI_COMMAND points at.
156
+ [
157
+ "pi",
158
+ entry("pi", [local("pi-acp"), npx("pi-acp@0.0.34")], [], {
159
+ readOnly: {
160
+ mode: undefined,
161
+ disallowedTools: [],
162
+ sessionOptions: {},
163
+ launchEnv: {},
164
+ policy: "pi",
165
+ },
166
+ defaultMode: undefined,
167
+ preApproval: undefined,
168
+ }),
169
+ ],
55
170
  ]);
56
171
  export const ACP_AGENT_NAMES = Object.freeze([...REGISTRY.keys()]);
57
172
  export function isAcpAgentName(name) {
@@ -1,8 +1,9 @@
1
- import type { LoadSessionResponse, McpServer, ResumeSessionResponse, SessionConfigOption } from "@agentclientprotocol/sdk";
1
+ import type { LoadSessionResponse, McpServer, ResumeSessionResponse } from "@agentclientprotocol/sdk";
2
2
  import { type BackendOpenContext, type TranscriptDoc } from "@nathapp/nax-agent";
3
3
  import type { CapabilityRecord } from "#src/client/capabilities";
4
4
  import type { AcpLink } from "#src/client/connection";
5
5
  import type { ResolvedAcpOptions } from "#src/client/options";
6
+ import { type SessionOffers } from "#src/client/session-offers";
6
7
  /** An agent session id longer than this is not trusted (S4-2 Review Focus 5). */
7
8
  export declare const MAX_SESSION_ID_CHARS = 512;
8
9
  /** A stored agent session to restore: from the document (resume) or the live session (reconnect). */
@@ -17,7 +18,8 @@ export type RestoredWith = "resume" | "load";
17
18
  export interface RestoredSession {
18
19
  readonly agentSessionId: string;
19
20
  readonly cwd: string;
20
- readonly configOptions: readonly SessionConfigOption[];
21
+ /** What the resume/load answer offers a profile: config options and the legacy blocks (session-offers.ts). */
22
+ readonly offers: SessionOffers;
21
23
  readonly restoredWith: RestoredWith;
22
24
  }
23
25
  /** What session/new, session/resume and session/load add to `cwd`: the tool host's entry and Claude's `_meta` (§6.6, #2365). */
@@ -31,7 +33,7 @@ export declare function isUsableSessionId(value: unknown): value is string;
31
33
  export declare function canRestore(record: CapabilityRecord): boolean;
32
34
  /** §6.9 step 1 (D6-b, D6-c). Throws before anything is spawned. */
33
35
  export declare function storedSessionOf(doc: TranscriptDoc, ctx: BackendOpenContext, options: ResolvedAcpOptions): Restore;
34
- /** §6.9 step 3 (D6-d): an echoed id must be the stored one. A null answer (D6-k) has no config options. */
36
+ /** §6.9 step 3 (D6-d): an echoed id must be the stored one. A null answer (D6-k) offers nothing. */
35
37
  export declare function checkRestored(restore: Restore, via: RestoredWith, response: ResumeSessionResponse | LoadSessionResponse): RestoredSession;
36
38
  /** §6.9 step 2: session/resume when advertised, else session/load; never a fresh session. */
37
39
  export declare function restoreSession(restore: Restore, record: CapabilityRecord, setup: SessionSetup, link: AcpLink, step: OpenStep): Promise<RestoredSession>;
@@ -14,6 +14,7 @@ import { realpathSync } from "node:fs";
14
14
  import { resolve } from "node:path";
15
15
  import { AgentSessionError, NaxError } from "@nathapp/nax-agent";
16
16
  import { capabilityUnsupported } from "#src/client/errors";
17
+ import { sessionOffers } from "#src/client/session-offers";
17
18
  import { isRecord } from "#src/client/text";
18
19
  /** An agent session id longer than this is not trusted (S4-2 Review Focus 5). */
19
20
  export const MAX_SESSION_ID_CHARS = 512;
@@ -65,7 +66,7 @@ export function storedSessionOf(doc, ctx, options) {
65
66
  }
66
67
  return { agentSessionId: acp.agentSessionId, cwd: acp.cwd, costUsd: costOf(acp.costUsd) };
67
68
  }
68
- /** §6.9 step 3 (D6-d): an echoed id must be the stored one. A null answer (D6-k) has no config options. */
69
+ /** §6.9 step 3 (D6-d): an echoed id must be the stored one. A null answer (D6-k) offers nothing. */
69
70
  export function checkRestored(restore, via, response) {
70
71
  const raw = response;
71
72
  const echoed = isRecord(raw) ? raw.sessionId : undefined;
@@ -78,7 +79,7 @@ export function checkRestored(restore, via, response) {
78
79
  return {
79
80
  agentSessionId: restore.agentSessionId,
80
81
  cwd: restore.cwd,
81
- configOptions: isRecord(raw) ? (response.configOptions ?? []) : [],
82
+ offers: sessionOffers(raw),
82
83
  restoredWith: via,
83
84
  };
84
85
  }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * nax's permission rules, translated into an ACP agent's own configuration
3
+ * (SPEC-cursor-pi-acp-read-only). A rule is one `Tool(...)` grant of the grammar
4
+ * native sessions use: `tool` names the tool, `patterns` are its patterns, and a
5
+ * rule is unconditional when one of its patterns is `*` (nax's own test, which
6
+ * treats `["*", "src/**"]` as unconditional too).
7
+ *
8
+ * Only an unconditional deny of a read tool (`Read`, `Glob`, `Grep`) is
9
+ * translated here, and only for profiles `read` and `review`: a read-only
10
+ * profile already runs with the agent's write tools removed, so no rule can
11
+ * widen it. Bash rules are applied by nax itself (shell-rules.ts, US-003), and
12
+ * a path-scoped or non-deny rule is left to the native matcher.
13
+ */
14
+ import type { AgentSessionProfile } from "@nathapp/nax-agent";
15
+ import type { ResolvedAcpOptions } from "#src/client/options";
16
+ export interface AcpRule {
17
+ readonly tool: string;
18
+ readonly patterns: readonly string[];
19
+ }
20
+ export interface AcpPermissionRules {
21
+ readonly allow: readonly AcpRule[];
22
+ readonly deny: readonly AcpRule[];
23
+ readonly ask: readonly AcpRule[];
24
+ }
25
+ /** The rules of a caller that has none: every list empty. */
26
+ export declare const NO_RULES: AcpPermissionRules;
27
+ /**
28
+ * opencode's permission config for a read-only profile (SPEC US-002). An
29
+ * unconditional deny of a read tool removes its entries, so opencode drops the
30
+ * tool from the model's catalog; with no such rule the result is byte-identical
31
+ * to the registry's OPENCODE_*_CONFIG. `none` ignores the rules: every tool is
32
+ * denied there and no rule can widen it. Bash rules are never translated (an
33
+ * agent matching command text knows nothing of redirects), and `read` keeps no
34
+ * shell tool while `review` asks nax about every command.
35
+ */
36
+ export declare function opencodePermissionConfig(profile: "none" | "read" | "review", rules: AcpPermissionRules): string;
37
+ /**
38
+ * Cursor's isolated permission config (SPEC US-004). Cursor's own modes enforce
39
+ * nothing, so this file is the whole enforcement: `Read(**)` is allowed unless an
40
+ * unconditional Read deny removes it (and then joins the deny list), writes, MCP
41
+ * and the web are denied, and shell is denied under `read` and absent under
42
+ * `review`, where Cursor asks the client about every command and nax decides it
43
+ * (shell-rules.ts). `none` ignores the rules: everything is denied there, and no
44
+ * rule can widen it.
45
+ */
46
+ export declare function cursorCliConfig(profile: "none" | "read" | "review", rules: AcpPermissionRules): string;
47
+ /**
48
+ * pi's `--tools` arguments (SPEC US-004): `--no-tools` under `none`, else pi's
49
+ * read tools in a fixed order minus the ones an unconditional deny removed.
50
+ * `Glob` owns pi's `find` and `ls`. Under `review` with a Bash allow rule, `bash`
51
+ * is appended after the read tools and the gate extension is loaded first, so
52
+ * every command goes through the nax shell gate.
53
+ */
54
+ export declare function piToolArgs(profile: "none" | "read" | "review", rules: AcpPermissionRules, gatePath: string): readonly string[];
55
+ /**
56
+ * The environment the profile's rules add to the agent process (SPEC US-002,
57
+ * extended by US-004), the one seam every launch goes through — a new session, a
58
+ * resume and a reconnect. An agent whose entry names no policy keeps its
59
+ * `launchEnv` untouched, so its env is exactly what it was before rules existed;
60
+ * a custom agent has no entry and gets nothing. Cursor and pi read their policy
61
+ * from files under the state directory, written here before anything is spawned:
62
+ * a file that cannot be written refuses the open (policy-files.ts). The caller
63
+ * spreads this over its own env, so neither the caller nor a model can weaken the
64
+ * enforcement value.
65
+ */
66
+ export declare function policyLaunchEnv(profile: AgentSessionProfile, options: ResolvedAcpOptions): Promise<Readonly<Record<string, string>>>;