@agentvault/grok-bridge 0.4.39 → 0.4.43

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.
@@ -0,0 +1,303 @@
1
+ /** Which grok child runs a turn. */
2
+ export type GrokToolProfile = "owner" | "restricted";
3
+ /**
4
+ * Which grok child — and so which tools — a turn runs with. THE ONE DECISION:
5
+ * every push site asks this, nothing else decides it, and anything it cannot
6
+ * place runs restricted (fail closed).
7
+ *
8
+ * `ownerOneToOne` is the owner's attested 1:1: `ownerDm1to1 === true` from
9
+ * SecureChannel, set only when the message decrypted under the owner's 1:1
10
+ * material (#621). Every room turn — the owner's own room message and an
11
+ * agent's (A2A) included — and every unattested 1:1 is restricted.
12
+ *
13
+ * `effective` is the agent's Full permissions state, read ONLY through the
14
+ * plugin's channel API (`channel.effective()`, PR-P1c-1). Phase 1 (§13.1):
15
+ * the switch does nothing, so it is accepted and NOT used. PR-PG (§13.8 row
16
+ * 12) relaxes this function, and only this function, when it is on.
17
+ */
18
+ export declare function grokToolProfileFor(turn: {
19
+ ownerOneToOne: boolean;
20
+ effective: boolean;
21
+ }): GrokToolProfile;
22
+ /**
23
+ * The restricted child's built-in tools. NEVER empty: an empty allowlist
24
+ * gives the full default toolset (measured). It must name a tool grok knows,
25
+ * and `todo_write` is the most harmless one. It is NOT a working tool here:
26
+ * the `Read` deny rule refuses it, like `search_tool` (PR #1824 review,
27
+ * measured). grok adds `search_tool` / `use_tool` to every toolset; only
28
+ * `use_tool` (inline arguments) works in this child, and it is the model's
29
+ * one way to call `room__say` / `room__send_file`.
30
+ */
31
+ export declare const RESTRICTED_TOOL_ALLOWLIST: readonly string[];
32
+ /** Every permission tool class grok knows except `MCPTool` (that is `room__say`). */
33
+ export declare const RESTRICTED_DENY_RULES: readonly string[];
34
+ /**
35
+ * Environment for the restricted child only (PR #1824 review). Cross-session
36
+ * memory and session search are paths between turns of different trust
37
+ * (owner 1:1 text into a room turn, room text into the full-tools lane). The
38
+ * restricted child now has its own grok home too (r3); these switches stay as
39
+ * a second layer. `GROK_MEMORY=0` is
40
+ * grok's process-wide force-off (it outranks config and managed settings);
41
+ * `GROK_SESSION_SEARCH=0` turns session search off. The restricted child
42
+ * then neither reads nor writes either store.
43
+ */
44
+ export declare const RESTRICTED_CHILD_ENV: Readonly<Record<string, string>>;
45
+ /**
46
+ * The exact call shapes, added to the restricted child's identity (PR #1824
47
+ * review). grok's own reminder tells the model to `search_tool` first, and in
48
+ * this child that call is denied. Naming the shapes means a model never needs
49
+ * to search, and does not go silent after a denied search. `search_tool` stays
50
+ * denied on purpose: allowing it would mean narrowing the bare `Read` deny,
51
+ * which is the rule that stops `use_tool` from reading its arguments from a
52
+ * file; and it would only ever list the two tools named here.
53
+ */
54
+ export declare function restrictedToolRule(sayTool: string, sendFileTool: string): string;
55
+ /** Where the restricted child's profile lives. */
56
+ export interface RestrictedProfilePaths {
57
+ /** The child's `HOME`. Holds `.claude/settings.json` (the deny rules) and nothing else. */
58
+ home: string;
59
+ /** The `--agent-profile` file (the tool allowlist). */
60
+ agentProfile: string;
61
+ }
62
+ export declare function restrictedAgentProfileText(): string;
63
+ export declare function restrictedSettingsText(): string;
64
+ /**
65
+ * PR #1824 review r3 (allowlist): the restricted child's OWN `GROK_HOME`,
66
+ * emptied and recreated at every start. It holds only our `config.toml`;
67
+ * grok adds its own empty defaults (`managed_config.toml`,
68
+ * `requirements.toml`, `trusted_folders.toml`, measured on 1.0.46) and its
69
+ * session store. Nothing from the shared fence home reaches it: no
70
+ * requirements, managed config, trust, sessions or history. Auth comes in by
71
+ * environment only (`restrictedChildEnv`: `GROK_AUTH_PATH` naming the fence's
72
+ * one `auth.json`, and/or `XAI_API_KEY`).
73
+ */
74
+ export declare const RESTRICTED_GROK_CONFIG = "# Written by the AgentVault grok bridge at every start (#1814). Do not edit.\n[memory]\nenabled = false\n";
75
+ export declare function prepareRestrictedGrokHome(dir: string): string;
76
+ /**
77
+ * PR #1824 final round: grok 1.0.46 writes bearer and refresh tokens into
78
+ * `<GROK_HOME>/logs/unified.jsonl`. Tighten what is looser than owner-only:
79
+ * `logs/` to 0700, `unified.jsonl` to 0600. PERMISSIONS ONLY — nothing is
80
+ * deleted, moved or rewritten (the fence home is shared and grok's). A
81
+ * symlink is left alone, never followed. Returns what it changed.
82
+ *
83
+ * #1827 (review of #1832): a symlinked `logs/` DIRECTORY is not followed
84
+ * either. Before, the file step `lstat`ed and `chmod`ed `logs/unified.jsonl`
85
+ * through the linked parent (lstat only refuses the LAST component), so a
86
+ * file elsewhere was tightened. Now each entry is opened with `O_NOFOLLOW`
87
+ * (`O_NONBLOCK`, so a FIFO cannot block the worker) and changed with
88
+ * `fchmod` on that descriptor, so there is no lstat→chmod window. The file
89
+ * step runs only when `logs/` opened as a plain directory, and only if
90
+ * `logs/` is still that same directory (device and inode) after the file is
91
+ * open.
92
+ */
93
+ export declare function tightenGrokLogs(grokHome: string): string[];
94
+ /**
95
+ * PR #1824 final round: grok also reads an admin layer from macOS device
96
+ * management (preference domain `ai.x.grok`), which no file in either grok
97
+ * home controls. Present in any form refuses restricted turns, like a file in
98
+ * `/etc/grok`.
99
+ *
100
+ * #1827 widened what "any form" covers. CFPreferences resolves a domain from
101
+ * more places than the managed plists, and a `defaults write` can sit in
102
+ * cfprefsd before it reaches disk, so this checks:
103
+ * - the plists: managed (machine-wide and per user), any-user
104
+ * (`/Library/Preferences`) and the user's own (`~/Library/Preferences`);
105
+ * - the user's ByHost plists (`~/Library/Preferences/ByHost/ai.x.grok.*.plist`);
106
+ * - the current user's live domain, through cfprefsd: `defaults read
107
+ * ai.x.grok` (any host) and `defaults -currentHost read ai.x.grok`, each
108
+ * with a short timeout and ONE retry on a timeout only.
109
+ * The probes see only the CURRENT USER's layers: `defaults read <domain>`
110
+ * does not read the any-user layer (`/Library/Preferences`; the #1832 review
111
+ * reproduced this). That layer is covered by the file check alone, so an
112
+ * any-user value cfprefsd has not flushed yet is caught at the first re-check
113
+ * (60 s timer) after it reaches disk.
114
+ * "Domain not found" is the only probe answer that passes. Values, a timeout
115
+ * (twice), a spawn failure or any other error refuse (fail closed). The values
116
+ * themselves are never logged.
117
+ *
118
+ * `home` is the REAL user's home (`userInfo()`, i.e. the password database),
119
+ * never `$HOME`: CFPreferences ignores `$HOME`, so grok in the restricted
120
+ * child (whose HOME is its own, emptied dir) still reads the real user's
121
+ * preferences. `defaults` runs with no HOME in its environment and resolves
122
+ * the user the same way.
123
+ *
124
+ * grok 1.0.46 itself only honours a value CFPreferences reports as FORCED
125
+ * (MDM): it calls `CFPreferencesAppValueIsForced` before
126
+ * `CFPreferencesCopyAppValue` for `requirements_toml_base64`. The wider check
127
+ * is deliberate: a later grok may drop that gate, and the threat (an admin or
128
+ * local write) is the same as `/etc/grok`.
129
+ */
130
+ export declare const MACOS_GROK_DOMAIN = "ai.x.grok";
131
+ /** Absolute path, so no PATH entry can stand in for it. */
132
+ export declare const MACOS_DEFAULTS_BIN = "/usr/bin/defaults";
133
+ /** Per probe. A normal read takes a few ms; this runs on the bridge's one worker. */
134
+ export declare const MACOS_DEFAULTS_TIMEOUT_MS = 2000;
135
+ /** What a `defaults` run returned (the shape of `spawnSync`'s result, trimmed). */
136
+ export interface DefaultsRun {
137
+ status: number | null;
138
+ signal?: string | null;
139
+ stdout: string;
140
+ stderr: string;
141
+ /** Set when the process could not run or was killed (`ETIMEDOUT` on timeout). */
142
+ error?: {
143
+ code?: string;
144
+ message: string;
145
+ };
146
+ }
147
+ export type DefaultsRunner = (args: string[]) => DefaultsRun;
148
+ /** The production runner: `/usr/bin/defaults <args>`, minimal environment, bounded time and output. */
149
+ export declare function runDefaults(args: string[]): DefaultsRun;
150
+ export type DefaultsVerdict = {
151
+ kind: "absent";
152
+ } | {
153
+ kind: "present";
154
+ } | {
155
+ kind: "error";
156
+ why: string;
157
+ };
158
+ /** Classify one `defaults read`: absent (the only pass), present, or an error (refuses). */
159
+ export declare function classifyDefaultsRead(r: DefaultsRun): DefaultsVerdict;
160
+ /** The user's ByHost dir (CFPreferences' current-host layer). */
161
+ export declare function macosByHostDir(home: string): string;
162
+ /** A ByHost plist for the domain: `ai.x.grok.<host id>.plist` (a bare `ai.x.grok.plist` counts too). */
163
+ export declare function isByHostGrokPlist(name: string): boolean;
164
+ export declare function macosManagedPrefsPaths(user: string, home: string): string[];
165
+ /** The two live-domain probes: the any-host and the current-host layer. */
166
+ export declare const MACOS_DEFAULTS_PROBES: readonly (readonly string[])[];
167
+ export declare function macosManagedPrefsProblems(o?: {
168
+ platform?: string;
169
+ user?: string;
170
+ home?: string;
171
+ exists?: (p: string) => boolean;
172
+ /** Test seam: list a directory (default `readdirSync`). */
173
+ readdir?: (dir: string) => string[];
174
+ /** Test seam: run `defaults` (default `runDefaults`). */
175
+ run?: DefaultsRunner;
176
+ }): string[];
177
+ /**
178
+ * Write the restricted child's profile under `dir`, REPLACING whatever is
179
+ * there (every start), and verify it. A directory that is a symlink, or a
180
+ * write that did not land, throws, and the caller does not start the child
181
+ * (fail closed). `dir` must not be inside the child's cwd or `GROK_HOME`: the
182
+ * `workspace` sandbox lets the child write those.
183
+ */
184
+ export declare function writeRestrictedToolProfile(dir: string): RestrictedProfilePaths;
185
+ /**
186
+ * grok CLI versions on which the restricted profile was verified against the
187
+ * real binary (`src/__tests__/tool-profile-1814.gate.test.ts`: no read, shell,
188
+ * network or write tool reaches a restricted turn; the owner 1:1 still reads).
189
+ * Add a version ONLY after that gate passes on it; the gate fails until you do.
190
+ *
191
+ * ⚠️ The version CAN change without anyone deciding to (PR #1824 review). The
192
+ * daemon turns off ITS child's self-update, but `~/.grok/bin/grok` — what
193
+ * `AV_GROK_PATH` normally names — is a symlink the interactive CLI's updater
194
+ * repoints, so the daemon runs the new version on its next restart. That is
195
+ * why an unverified version is REFUSED for restricted turns
196
+ * (`restrictedTurnReadiness`), not merely warned about.
197
+ *
198
+ * 1.0.46 (2765805b9442), macOS arm64 — 2026-11-21, #1814.
199
+ */
200
+ export declare const VERIFIED_GROK_TOOL_PROFILE_VERSIONS: ReadonlySet<string>;
201
+ /**
202
+ * The startup line about the restricted child's grok version. `warn` is true
203
+ * when the version is not one the profile was verified on, or grok reported
204
+ * none — and then room, A2A and non-owner turns are refused.
205
+ */
206
+ export declare function grokToolProfileVersionLine(version: string | null | undefined, verified?: ReadonlySet<string>): {
207
+ warn: boolean;
208
+ line: string;
209
+ };
210
+ /** Why restricted turns are refused, as short reasons; empty means they may run. */
211
+ export interface RestrictedReadiness {
212
+ ok: boolean;
213
+ /** Version reasons, for the owner notice. */
214
+ version: string[];
215
+ /** Config reasons (fence home, machine-wide, workspace trust), for the owner notice. */
216
+ config: string[];
217
+ }
218
+ /** Machine-wide grok config (admin-owned). Read like the fence's own (PR #1824 review r2). */
219
+ export declare const SYSTEM_GROK_DIR = "/etc/grok";
220
+ /**
221
+ * May the restricted child run room, A2A and non-owner turns? FAIL CLOSED on
222
+ * each check (PR #1824 review, rounds 1 and 2):
223
+ * - its grok version must be verified for BOTH the restricted tool profile
224
+ * and the `@`-file reference neutralizer (every restricted turn's text is
225
+ * neutralized; the owner's typed 1:1 text is not, so the owner 1:1 runs
226
+ * either way);
227
+ * - no grok config it loads may widen what an MCP tool may do or add a tool
228
+ * source (`grokConfigProblems`, over the fence's `GROK_HOME` and the
229
+ * machine-wide `/etc/grok`): `MCPTool` cannot be denied (it carries
230
+ * `room__say`), so for any other MCP server the bridge's permission
231
+ * handler is the only gate, and an always-approve mode or an MCP allow
232
+ * rule would skip it;
233
+ * - its working directory must be one no project config can come from
234
+ * (`restrictedCwdProblems`): not trusted (nor any parent) in grok's
235
+ * shared `trusted_folders.toml`, and holding no `.grok/`, `.claude/`,
236
+ * `.mcp.json` or `.cursor/`.
237
+ */
238
+ export declare function restrictedTurnReadiness(o: {
239
+ version: string | null | undefined;
240
+ grokHome: string;
241
+ /** The restricted child's working directory. */
242
+ cwd: string;
243
+ /** Test seam: the macOS `ai.x.grok` preferences check (default: the real one). */
244
+ macosPrefsProblems?: () => string[];
245
+ /** Test seam: the machine-wide grok dir (default `/etc/grok`). */
246
+ systemDir?: string;
247
+ toolProfileVersions?: ReadonlySet<string>;
248
+ fileRefVersions?: ReadonlySet<string>;
249
+ }): RestrictedReadiness;
250
+ /** A config file larger than this is a problem, never parsed (the re-check runs on the bridge's one worker). */
251
+ export declare const MAX_CONFIG_BYTES: number;
252
+ /**
253
+ * What in one grok config dir would let an MCP tool other than the room's run
254
+ * without the bridge being asked, or bring another tool source in. Files:
255
+ * `config.toml`, `managed_config.toml` (grok writes it from managed remote
256
+ * settings), and `settings.json`. Each is PARSED — TOML with smol-toml, JSON
257
+ * with JSON.parse — and its whole tree is evaluated by `riskyPaths` (PR #1824
258
+ * review r2: a line scanner missed inline tables, literal-quoted keys and
259
+ * headers, and quoted or spaced dotted keys, all of which grok honours). FAIL
260
+ * CLOSED: a file that exists but cannot be read or parsed, or whose root is
261
+ * not a table, is a problem; so is any key that looks permission-related.
262
+ */
263
+ export declare function grokConfigProblems(dir: string, o?: {
264
+ label?: string;
265
+ }): string[];
266
+ /**
267
+ * PR #1824 review r3: machine-wide `/etc/grok` is the one grok config source
268
+ * outside the bridge's control. ANY file there refuses restricted turns
269
+ * (absent or empty is fine); the parsed-tree check runs too, so the reason
270
+ * names what is there.
271
+ */
272
+ export declare function systemGrokDirProblems(dir: string): string[];
273
+ /** Kept for callers of the round-1 name: the fence home only. */
274
+ export declare function fenceConfigProblems(grokHome: string): string[];
275
+ /**
276
+ * Can project config reach the restricted child through its working
277
+ * directory? grok merges `<cwd>/.grok/config.toml` (MCP servers, plugins,
278
+ * permissions) once the folder is trusted, and records trust in the SHARED
279
+ * `GROK_HOME/trusted_folders.toml` (measured shape: `[folders."<path>"]
280
+ * trusted = true`). Problems:
281
+ * - any string or key in `trusted_folders.toml` naming the cwd or a parent of
282
+ * it (format-agnostic, so a future layout cannot hide one), or that file
283
+ * unreadable or unparseable;
284
+ * - a `.grok`, `.claude`, `.mcp.json` or `.cursor` entry in the cwd.
285
+ * The bridge also gives the restricted child its own, freshly emptied cwd
286
+ * (lane.ts), which nothing has a reason to trust.
287
+ */
288
+ export declare function restrictedCwdProblems(cwd: string, grokHome: string): string[];
289
+ /**
290
+ * The restricted child's own working directory, EMPTIED at every start
291
+ * (PR #1824 review r2): nothing in it, nothing that trusts it, and its grok
292
+ * session and history store (keyed by cwd under `GROK_HOME/sessions/`)
293
+ * separate from the owner child's. A symlink or non-directory there is
294
+ * refused, never followed. `dir` must be bridge-owned and hold nothing of
295
+ * value: it is deleted.
296
+ */
297
+ export declare function prepareRestrictedCwd(dir: string): string;
298
+ /**
299
+ * The ONE owner-visible sentence for refused restricted turns (sent once per
300
+ * process, to the owner's 1:1). Plain words; the exact reasons go to the log.
301
+ */
302
+ export declare function restrictedRefusalNotice(agentName: string, r: RestrictedReadiness): string;
303
+ //# sourceMappingURL=tool-profile.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvault/grok-bridge",
3
- "version": "0.4.39",
3
+ "version": "0.4.43",
4
4
  "type": "module",
5
5
  "description": "AgentVault Grok Bridge — daemon bridging a Grok agent into E2E-encrypted AgentVault direct messages and rooms.",
6
6
  "main": "dist/index.js",
@@ -9,7 +9,7 @@
9
9
  "agentvault-grok-bridge": "dist/index.js"
10
10
  },
11
11
  "engines": {
12
- "node": ">=18"
12
+ "node": ">=20"
13
13
  },
14
14
  "files": [
15
15
  "dist",
@@ -21,10 +21,13 @@
21
21
  "start": "node dist/index.js",
22
22
  "test": "vitest run",
23
23
  "gate:mac": "RUN_MAC_GATE=1 vitest run src/__tests__/sandbox-gate.mac.test.ts",
24
+ "gate:file-refs": "GROK_FILE_REF_GATE=1 vitest run src/__tests__/file-refs-1807.gate.test.ts",
25
+ "gate:tool-profile": "GROK_TOOL_PROFILE_GATE=1 vitest run src/__tests__/tool-profile-1814.gate.test.ts",
24
26
  "typecheck": "tsc -p tsconfig.test.json",
25
27
  "prepublishOnly": "npm run build"
26
28
  },
27
29
  "dependencies": {
30
+ "smol-toml": "1.9.1",
28
31
  "ws": "^8.22.1",
29
32
  "zod": "^4.6.7"
30
33
  },