@farmslot/agent-runtime 0.39.23 → 0.39.25

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 (76) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/native/account-common.d.ts +11 -0
  3. package/dist/native/account-common.d.ts.map +1 -1
  4. package/dist/native/account-common.js +44 -0
  5. package/dist/native/account-common.js.map +1 -1
  6. package/dist/native/account-grok.d.ts.map +1 -1
  7. package/dist/native/account-grok.js +6 -35
  8. package/dist/native/account-grok.js.map +1 -1
  9. package/dist/native/account-opencode.d.ts +10 -0
  10. package/dist/native/account-opencode.d.ts.map +1 -0
  11. package/dist/native/account-opencode.js +19 -0
  12. package/dist/native/account-opencode.js.map +1 -0
  13. package/dist/native/account-pi.d.ts +10 -0
  14. package/dist/native/account-pi.d.ts.map +1 -0
  15. package/dist/native/account-pi.js +30 -0
  16. package/dist/native/account-pi.js.map +1 -0
  17. package/dist/native/acp-rpc.d.ts +10 -0
  18. package/dist/native/acp-rpc.d.ts.map +1 -1
  19. package/dist/native/acp-rpc.js +25 -1
  20. package/dist/native/acp-rpc.js.map +1 -1
  21. package/dist/native/acp.d.ts +6 -2
  22. package/dist/native/acp.d.ts.map +1 -1
  23. package/dist/native/acp.js +12 -8
  24. package/dist/native/acp.js.map +1 -1
  25. package/dist/native/cursor-model.d.ts +2 -4
  26. package/dist/native/cursor-model.d.ts.map +1 -1
  27. package/dist/native/cursor-model.js +4 -11
  28. package/dist/native/cursor-model.js.map +1 -1
  29. package/dist/native/cursor.d.ts.map +1 -1
  30. package/dist/native/cursor.js +2 -4
  31. package/dist/native/cursor.js.map +1 -1
  32. package/dist/native/grok.d.ts +7 -0
  33. package/dist/native/grok.d.ts.map +1 -1
  34. package/dist/native/grok.js +21 -5
  35. package/dist/native/grok.js.map +1 -1
  36. package/dist/native/index.d.ts +2 -0
  37. package/dist/native/index.d.ts.map +1 -1
  38. package/dist/native/index.js +2 -0
  39. package/dist/native/index.js.map +1 -1
  40. package/dist/native/manager.d.ts.map +1 -1
  41. package/dist/native/manager.js +8 -3
  42. package/dist/native/manager.js.map +1 -1
  43. package/dist/native/opencode-model.d.ts +4 -0
  44. package/dist/native/opencode-model.d.ts.map +1 -0
  45. package/dist/native/opencode-model.js +13 -0
  46. package/dist/native/opencode-model.js.map +1 -0
  47. package/dist/native/opencode.d.ts +10 -0
  48. package/dist/native/opencode.d.ts.map +1 -0
  49. package/dist/native/opencode.js +24 -0
  50. package/dist/native/opencode.js.map +1 -0
  51. package/dist/native/pi-rpc.d.ts +21 -0
  52. package/dist/native/pi-rpc.d.ts.map +1 -0
  53. package/dist/native/pi-rpc.js +68 -0
  54. package/dist/native/pi-rpc.js.map +1 -0
  55. package/dist/native/pi.d.ts +7 -0
  56. package/dist/native/pi.d.ts.map +1 -0
  57. package/dist/native/pi.js +233 -0
  58. package/dist/native/pi.js.map +1 -0
  59. package/dist/native/registry.d.ts +5 -1
  60. package/dist/native/registry.d.ts.map +1 -1
  61. package/dist/native/registry.js +37 -1
  62. package/dist/native/registry.js.map +1 -1
  63. package/dist/native/review-sandbox.d.ts +6 -1
  64. package/dist/native/review-sandbox.d.ts.map +1 -1
  65. package/dist/native/review-sandbox.js.map +1 -1
  66. package/dist/native/worker-launch.d.ts +2 -0
  67. package/dist/native/worker-launch.d.ts.map +1 -1
  68. package/dist/native/worker-launch.js +6 -20
  69. package/dist/native/worker-launch.js.map +1 -1
  70. package/package.json +2 -1
  71. package/scripts/native-worker-env.cjs +59 -0
  72. package/scripts/review-account-preflight.cjs +123 -21
  73. package/scripts/review-filesystem.cjs +39 -3
  74. package/scripts/review-terminal.cjs +3 -0
  75. package/scripts/worker-terminal-contract.cjs +14 -8
  76. package/scripts/workspace-trust.cjs +27 -9
@@ -0,0 +1,59 @@
1
+ // The one place a native worker's process environment is built. The native host starts workers
2
+ // with it, and the gateway's launch preflight runs its probes through this file on the same node,
3
+ // so a probe resolves Node and the package manager exactly as the worker will (F318).
4
+ const { spawnSync } = require('node:child_process');
5
+ const { existsSync } = require('node:fs');
6
+ const { constants, homedir } = require('node:os');
7
+ const { delimiter, join } = require('node:path');
8
+
9
+ // Project-pinned tools win over a runner's own directory (a runner installed under one Node, or
10
+ // bundling one) and over machine-global installs such as Homebrew's node, as in tmux worker shells
11
+ // (scripts/lib/worker-env-prefix.sh). The native host applies this last, after it puts the runner's
12
+ // directory ahead of PATH.
13
+ function projectToolsFirst(env) {
14
+ const shims = join(env.ASDF_DATA_DIR ?? join(env.HOME ?? homedir(), '.asdf'), 'shims');
15
+ if (!existsSync(shims)) return env;
16
+ const rest = (env.PATH ?? '').split(delimiter).filter((entry) => entry && entry !== shims);
17
+ return { ...env, PATH: [shims, ...rest].join(delimiter) };
18
+ }
19
+
20
+ /** The host's environment without the launch's unset names, plus its set values. */
21
+ function nativeWorkerProcessEnvironment(environment, base = process.env) {
22
+ const unset = new Set(environment.unset);
23
+ // Object.fromEntries treats names as data, including names matching Object.prototype keys.
24
+ const env = Object.fromEntries([
25
+ ...Object.entries(base).filter(([key]) => !unset.has(key)),
26
+ ...Object.entries(environment.set),
27
+ ]);
28
+ env.DISABLE_OMC = '1';
29
+ env.DISABLE_OMX = '1';
30
+ delete env.CLAUDECODE;
31
+ // Workers do not need control-plane credentials, including configured overrides.
32
+ delete env.FARMSLOT_NODE_TOKEN;
33
+ delete env.FARMSLOT_GATEWAY_TOKEN;
34
+ delete env.FARMSLOT_GATEWAY_PASSWORD;
35
+ // A profile may move HOME (Cursor's does). Keep the asdf root this worker resolves its tools from,
36
+ // so its shims stay first and still find their installs under the profile's HOME.
37
+ if (!env.ASDF_DATA_DIR) {
38
+ const root = join(env.HOME ?? homedir(), '.asdf');
39
+ if (existsSync(join(root, 'shims'))) env.ASDF_DATA_DIR = root;
40
+ }
41
+ return projectToolsFirst(env);
42
+ }
43
+
44
+ module.exports = { nativeWorkerProcessEnvironment, projectToolsFirst };
45
+
46
+ // `node native-worker-env.cjs <environment-json> <command> [args...]` runs the command in that
47
+ // environment and exits with its status.
48
+ if (require.main === module) {
49
+ const [environment, command, ...args] = process.argv.slice(2);
50
+ const result = spawnSync(command, args, {
51
+ env: nativeWorkerProcessEnvironment(JSON.parse(environment)),
52
+ stdio: 'inherit',
53
+ });
54
+ if (result.error) {
55
+ console.error(result.error.message);
56
+ process.exit(127);
57
+ }
58
+ process.exit(result.status ?? 128 + (constants.signals[result.signal] ?? 0));
59
+ }
@@ -1,10 +1,17 @@
1
1
  const { execFileSync } = require('node:child_process');
2
- const { existsSync, realpathSync } = require('node:fs');
3
- const { homedir } = require('node:os');
4
- const { join, resolve } = require('node:path');
2
+ const {
3
+ existsSync,
4
+ mkdtempSync,
5
+ readFileSync,
6
+ realpathSync,
7
+ rmSync,
8
+ writeFileSync,
9
+ } = require('node:fs');
10
+ const { homedir, tmpdir } = require('node:os');
11
+ const { dirname, join, resolve } = require('node:path');
5
12
 
6
13
  function grokProfileEnvironment(directory, base = process.env) {
7
- const home = base.HOME || homedir();
14
+ const home = homeDirectory(base);
8
15
  const defaultDirectory = join(home, '.grok');
9
16
  const canonicalDefault = existsSync(defaultDirectory)
10
17
  ? realpathSync(defaultDirectory)
@@ -36,24 +43,56 @@ function canResumeGrokProfileContext(previous, current, ambientHome) {
36
43
  );
37
44
  }
38
45
 
46
+ const homeDirectory = (env) => env.HOME || homedir();
47
+ /** Where Grok reads its login and settings when no profile selects another directory. */
48
+ const grokHome = (env) => env.GROK_HOME || join(homeDirectory(env), '.grok');
49
+
50
+ function readGrokHomeFile(env, file) {
51
+ try {
52
+ return readFileSync(join(grokHome(env), file), 'utf8');
53
+ } catch (error) {
54
+ if (error?.code === 'ENOENT') return '';
55
+ throw error;
56
+ }
57
+ }
58
+
59
+ // A grant covers the folder's subdirectories, so the store must name neither the checkout nor any
60
+ // parent, in either TOML string form.
61
+ function grokTrustStoreNamesCheckout(cwd, env) {
62
+ const store = readGrokHomeFile(env, 'trusted_folders.toml');
63
+ const folders = new Set();
64
+ for (const start of [resolve(cwd), ...(existsSync(cwd) ? [realpathSync(cwd)] : [])])
65
+ for (let folder = start; ; folder = dirname(folder)) {
66
+ folders.add(folder);
67
+ if (dirname(folder) === folder) break;
68
+ }
69
+ return [...folders].some(
70
+ (folder) => store.includes(JSON.stringify(folder)) || store.includes(`'${folder}'`),
71
+ );
72
+ }
73
+
39
74
  function assertGrokReviewAccount(cwd, env, launch = {}) {
40
75
  const remedy =
41
- 'Set allow_managed_hooks_only = true in the selected GROK_HOME/requirements.toml, ' +
42
- 'disable or remove native, plugin and compatibility hooks, and verify grok inspect --json ' +
43
- 'reports nonManagedHooks disabled and every hook disabled; then retry. Use another runner if enforced hooks cannot be disabled.';
76
+ 'Use a GROK_HOME with no hooks, MCP or LSP servers, plugins, agents or notification commands of its own, or set ' +
77
+ 'allow_managed_hooks_only = true in its requirements.toml; keep folder trust on, and the review ' +
78
+ 'checkout and its parents out of its trusted_folders.toml; verify with grok inspect --json; then ' +
79
+ 'retry. Use another runner if the account cannot meet this.';
44
80
  const executable = launch.executable || 'grok';
45
- // Account discovery must not confuse intentionally masked PR configuration with unreadable account hooks.
46
- const inspectionCwd = launch.inspectionCwd || cwd;
47
- const args = ['--no-leader', '--no-auto-update', '--cwd', inspectionCwd, 'inspect', '--json'];
48
- let inspection;
49
- try {
50
- inspection = JSON.parse(
81
+ const inspect = (directory) => {
82
+ const args = ['--no-leader', '--no-auto-update', '--cwd', directory, 'inspect', '--json'];
83
+ return JSON.parse(
51
84
  execFileSync(
52
85
  launch.processSandbox?.executable || executable,
53
86
  launch.processSandbox ? [...launch.processSandbox.args, executable, ...args] : args,
54
- { cwd: inspectionCwd, env, encoding: 'utf8', stdio: 'pipe', timeout: 10000 },
87
+ { cwd: directory, env, encoding: 'utf8', stdio: 'pipe', timeout: 10000 },
55
88
  ),
56
89
  );
90
+ };
91
+ // Grok lists the account's own hooks only from a folder it trusts for them. The home directory
92
+ // is one, and Grok loads no project configuration there.
93
+ let inspection;
94
+ try {
95
+ inspection = inspect(homeDirectory(env));
57
96
  } catch {
58
97
  // Inspector output can include account secrets. Refuse without echoing stdout/stderr.
59
98
  throw new Error('Grok review refused: account hook safety could not be verified. ' + remedy);
@@ -61,7 +100,10 @@ function assertGrokReviewAccount(cwd, env, launch = {}) {
61
100
  if (
62
101
  !inspection ||
63
102
  typeof inspection.grokVersion !== 'string' ||
103
+ inspection.projectTrusted !== true ||
64
104
  !Array.isArray(inspection.hooks) ||
105
+ !Array.isArray(inspection.mcpServers) ||
106
+ !Array.isArray(inspection.lspServers) ||
65
107
  (inspection.hookLoadErrors !== undefined &&
66
108
  (!Array.isArray(inspection.hookLoadErrors) || inspection.hookLoadErrors.length > 0))
67
109
  )
@@ -69,16 +111,76 @@ function assertGrokReviewAccount(cwd, env, launch = {}) {
69
111
  // Do not classify commands as safe: a global hook can invoke any PR-supplied file.
70
112
  if (inspection.hooks.some((hook) => hook?.disabled !== true))
71
113
  throw new Error('Grok review refused: this account has startup hooks enabled. ' + remedy);
72
- // The native pin also covers agent/frontmatter and notification hooks loaded after inspection.
73
- if (
74
- !Array.isArray(inspection.permissions?.enforced) ||
75
- !inspection.permissions.enforced.some(
114
+ // An account's MCP or LSP server is a command too, and the hook pin does not cover it.
115
+ if (inspection.mcpServers.length > 0 || inspection.lspServers.length > 0)
116
+ throw new Error(
117
+ 'Grok review refused: this account starts its own MCP or LSP servers. ' + remedy,
118
+ );
119
+ // Grok loads a checkout's hooks, agents, MCP and LSP servers, instructions and skills only once
120
+ // the folder is trusted, so the review checkout must stay untrusted.
121
+ let named;
122
+ try {
123
+ named = grokTrustStoreNamesCheckout(cwd, env);
124
+ } catch {
125
+ throw new Error('Grok review refused: folder trust could not be verified. ' + remedy);
126
+ }
127
+ if (named)
128
+ throw new Error(
129
+ 'Grok review refused: this account trusts the review checkout or one of its parents. ' +
130
+ remedy,
131
+ );
132
+ // The environment, any config layer, device management or remote settings can switch folder
133
+ // trust off. Ask Grok: a fresh folder holding only project instructions must read as untrusted.
134
+ let gated;
135
+ let probe;
136
+ try {
137
+ probe = mkdtempSync(join(launch.inspectionCwd || tmpdir(), 'grok-trust-probe-'));
138
+ writeFileSync(join(probe, 'AGENTS.md'), 'Folder-trust probe.\n');
139
+ const result = inspect(probe);
140
+ gated =
141
+ result?.projectTrusted === false &&
142
+ Array.isArray(result.projectInstructions) &&
143
+ result.projectInstructions.length === 0;
144
+ } catch {
145
+ throw new Error('Grok review refused: folder trust could not be verified. ' + remedy);
146
+ } finally {
147
+ if (probe) rmSync(probe, { recursive: true, force: true });
148
+ }
149
+ if (!gated)
150
+ throw new Error('Grok review refused: folder trust is off for this account. ' + remedy);
151
+ // Plugin hooks, agent frontmatter hooks and notification commands load after inspection. The
152
+ // native pin disables them; without it, the account must have none.
153
+ const pinned =
154
+ Array.isArray(inspection.permissions?.enforced) &&
155
+ inspection.permissions.enforced.some(
76
156
  (pin) => pin?.setting === 'nonManagedHooks' && pin.enabled === false,
77
- )
157
+ );
158
+ if (pinned) return;
159
+ let notifications;
160
+ try {
161
+ notifications = readGrokHomeFile(env, 'config.toml')
162
+ .split('\n')
163
+ .some((line) => !line.trim().startsWith('#') && line.includes('notifications'));
164
+ } catch {
165
+ throw new Error('Grok review refused: account hook safety could not be verified. ' + remedy);
166
+ }
167
+ if (
168
+ !Array.isArray(inspection.plugins) ||
169
+ inspection.plugins.length > 0 ||
170
+ !Array.isArray(inspection.agents) ||
171
+ inspection.agents.some((agent) => agent?.source?.type !== 'builtin') ||
172
+ notifications
78
173
  )
79
174
  throw new Error(
80
- 'Grok review refused: account startup hooks are not disabled by policy. ' + remedy,
175
+ 'Grok review refused: account plugins, agents or notification commands can run and are not disabled by policy. ' +
176
+ remedy,
81
177
  );
82
178
  }
83
179
 
84
- module.exports = { assertGrokReviewAccount, grokProfileEnvironment, canResumeGrokProfileContext };
180
+ module.exports = {
181
+ assertGrokReviewAccount,
182
+ grokHome,
183
+ grokProfileEnvironment,
184
+ canResumeGrokProfileContext,
185
+ homeDirectory,
186
+ };
@@ -1,6 +1,6 @@
1
1
  const { accessSync, constants } = require('node:fs');
2
- const { mkdir, realpath } = require('node:fs/promises');
3
- const { join, sep } = require('node:path');
2
+ const { lstat, mkdir, realpath, writeFile } = require('node:fs/promises');
3
+ const { basename, dirname, join, sep } = require('node:path');
4
4
 
5
5
  function available() {
6
6
  if (process.platform !== 'darwin') return false;
@@ -12,7 +12,7 @@ function available() {
12
12
  throw error;
13
13
  }
14
14
  }
15
- async function sandbox(policy, runtimeRoots, configurationRoots = []) {
15
+ async function sandbox(policy, runtimeRoots, configurationRoots = [], runtimeAccess = {}) {
16
16
  if (!available())
17
17
  throw new Error('This runner needs the macOS review sandbox on its execution node');
18
18
  const temporaryDirectory = join(policy.writableRoots[0], '.review-runtime', 'tmp');
@@ -23,6 +23,34 @@ async function sandbox(policy, runtimeRoots, configurationRoots = []) {
23
23
  await mkdir(root, { recursive: true, mode: 0o700 });
24
24
  writable.push(await realpath(root));
25
25
  }
26
+ // A runtime root that names writable paths or data files is read-only apart from them, and no
27
+ // link can be made in it, so one review cannot change what the next one loads, runs or writes.
28
+ const runtime = writable.slice(policy.writableRoots.length);
29
+ const inRuntime = async (file) => {
30
+ const resolved = join(await realpath(dirname(file)), basename(file));
31
+ if (!runtime.some((root) => resolved.startsWith(root + sep)))
32
+ throw new Error('Writable review runtime path must belong to a runtime root');
33
+ return resolved;
34
+ };
35
+ const runtimeWritable = [];
36
+ for (const file of runtimeAccess.writablePaths ?? []) runtimeWritable.push(await inRuntime(file));
37
+ // A data file keeps its identity: a review may write its bytes but not replace, rename or
38
+ // remove it, so a later process that opens it cannot be pointed elsewhere.
39
+ const runtimeData = [];
40
+ for (const file of runtimeAccess.dataFiles ?? []) {
41
+ const resolved = await inRuntime(file);
42
+ try {
43
+ await writeFile(resolved, '', { flag: 'wx', mode: 0o600 });
44
+ } catch (error) {
45
+ if (error.code !== 'EEXIST') throw error;
46
+ }
47
+ if (!(await lstat(resolved)).isFile())
48
+ throw new Error('Review runtime data file must be a regular file');
49
+ runtimeData.push(resolved);
50
+ }
51
+ const restrictedRuntime = runtime.filter((root) =>
52
+ [...runtimeWritable, ...runtimeData].some((file) => file.startsWith(root + sep)),
53
+ );
26
54
  const blockedConfiguration = [];
27
55
  for (const file of configurationRoots) {
28
56
  const source = readOnly.find((root) => file.startsWith(root + sep));
@@ -47,6 +75,14 @@ async function sandbox(policy, runtimeRoots, configurationRoots = []) {
47
75
  ...writable.map((root) => `(allow file-write* (subpath ${JSON.stringify(root)}))`),
48
76
  '(allow file-write* (literal "/dev/null") (literal "/dev/tty"))',
49
77
  ...readOnly.map((root) => `(deny file-write* (subpath ${JSON.stringify(root)}))`),
78
+ ...restrictedRuntime.map((root) => `(deny file-write* (subpath ${JSON.stringify(root)}))`),
79
+ ...runtimeWritable.map((file) => `(allow file-write* (subpath ${JSON.stringify(file)}))`),
80
+ ...runtimeData.map((file) => `(allow file-write-data (literal ${JSON.stringify(file)}))`),
81
+ ...restrictedRuntime.map(
82
+ (root) =>
83
+ `(deny file-write-create (require-all (subpath ${JSON.stringify(root)}) (vnode-type SYMLINK)))`,
84
+ ),
85
+ ...restrictedRuntime.map((root) => `(deny file-link (subpath ${JSON.stringify(root)}))`),
50
86
  ...blockedConfiguration.map(
51
87
  (root) => `(deny file-read-data (subpath ${JSON.stringify(root)}))`,
52
88
  ),
@@ -133,7 +133,10 @@ async function main() {
133
133
  const {
134
134
  workspaceTrustByRunner,
135
135
  reviewConfigurationRootsByRunner,
136
+ terminalReviewRefusalByRunner,
136
137
  } = require('./workspace-trust.cjs');
138
+ if (terminalReviewRefusalByRunner[input.runner])
139
+ throw new Error(terminalReviewRefusalByRunner[input.runner]);
137
140
  const guard = await sandbox(
138
141
  policy,
139
142
  runtimeRoots,
@@ -249,14 +249,20 @@ function resolveWorkerTerminalContract(projectConfig, flowType, options = {}) {
249
249
  requireSignal = false;
250
250
  }
251
251
 
252
- const whenPresent = Array.isArray(projectConfig?.whenPresent)
253
- ? projectConfig.whenPresent.map((rule) => ({
254
- path: rule.path,
255
- alsoRequire: [...(rule.alsoRequire ?? [])],
256
- ...(rule.requireRecipeQuality ? { requireRecipeQuality: true } : {}),
257
- ...(rule.requireRecipeCoverage ? { requireRecipeCoverage: true } : {}),
258
- }))
259
- : DEFAULT_WHEN_PRESENT.map((rule) => ({ ...rule, alsoRequire: [...rule.alsoRequire] }));
252
+ // A run's reviewer shares its worker's task directory and judges the worker's recipe
253
+ // artifacts; it does not produce them, so no recipe rule binds its own terminal mark.
254
+ // Otherwise a blocked worker's recipe.json leaves every reviewer unable to complete.
255
+ const whenPresent =
256
+ flowKey === 'review'
257
+ ? []
258
+ : Array.isArray(projectConfig?.whenPresent)
259
+ ? projectConfig.whenPresent.map((rule) => ({
260
+ path: rule.path,
261
+ alsoRequire: [...(rule.alsoRequire ?? [])],
262
+ ...(rule.requireRecipeQuality ? { requireRecipeQuality: true } : {}),
263
+ ...(rule.requireRecipeCoverage ? { requireRecipeCoverage: true } : {}),
264
+ }))
265
+ : DEFAULT_WHEN_PRESENT.map((rule) => ({ ...rule, alsoRequire: [...rule.alsoRequire] }));
260
266
 
261
267
  const acceptanceRules =
262
268
  projectConfig?.acceptance || flowLayer?.acceptance
@@ -1,9 +1,12 @@
1
1
  // Runner-native trust stores. Callers admit only farm-created worker workspaces.
2
2
  const fs = require('node:fs');
3
3
  const path = require('node:path');
4
- const os = require('node:os');
5
4
  const { execFileSync } = require('node:child_process');
6
- const { assertGrokReviewAccount } = require('./review-account-preflight.cjs');
5
+ const {
6
+ assertGrokReviewAccount,
7
+ grokHome,
8
+ homeDirectory: home,
9
+ } = require('./review-account-preflight.cjs');
7
10
  const { tomlSectionHeaderIndexes, tomlBareStringValue } = require('./toml-scan.cjs');
8
11
 
9
12
  const lockScript = String.raw`
@@ -126,10 +129,8 @@ function seed(file, folders, values, namespace, env) {
126
129
  ),
127
130
  );
128
131
  }
129
- const home = (env) => env.HOME || os.homedir();
130
- /** Where Codex and Grok read their login when no profile selects another directory. */
132
+ /** Where Codex reads its login when no profile selects another directory. */
131
133
  const codexHome = (env) => env.CODEX_HOME || path.join(home(env), '.codex');
132
- const grokHome = (env) => env.GROK_HOME || path.join(home(env), '.grok');
133
134
  function trustGrokFolders(folders, env = process.env) {
134
135
  const file = path.join(grokHome(env), 'trusted_folders.toml');
135
136
  const added = seed(
@@ -172,10 +173,11 @@ function farmReviewWorkspace(cwd, owner) {
172
173
  throw new Error('Review workspace ownership marker does not match this launch');
173
174
  return true;
174
175
  }
175
- function trustGrokWorkspace(cwd, env = process.env, owner, launch) {
176
+ // A Grok review checkout stays untrusted, so Grok loads none of its hooks, agents, MCP or LSP
177
+ // servers, instructions or skills. The preflight refuses an account that already trusts it.
178
+ function checkGrokReviewWorkspace(cwd, env = process.env, owner, launch) {
176
179
  if (!farmReviewWorkspace(cwd, owner)) return;
177
180
  assertGrokReviewAccount(cwd, env, launch);
178
- trustGrokFolders([path.resolve(cwd), fs.realpathSync(cwd)], env);
179
181
  }
180
182
  function configureCodexReviewWorkspace(cwd, env = process.env, owner) {
181
183
  if (!farmReviewWorkspace(cwd, owner)) return;
@@ -217,6 +219,20 @@ const reviewConfigurationRoots = (cwd) =>
217
219
  '.lsp.json',
218
220
  '.envrc',
219
221
  ].map((name) => path.join(fs.realpathSync(cwd), name));
222
+ // What a Grok review may write in its home: its sessions and logs, and the bytes of the sign-in
223
+ // lock that a token refresh takes. Everything else stays read-only: hooks, configuration, policy,
224
+ // bundled and user agents, skills, memory, the model catalog cache, the stored login, the external
225
+ // sign-in command in bin/, and shell startup files (a profile's HOME is its Grok home). So one
226
+ // review cannot change what the next one loads, runs, signs in with or sends requests to.
227
+ const grokReviewHomeAccess = (env) => ({
228
+ writablePaths: ['sessions', 'logs'].map((name) => path.join(grokHome(env), name)),
229
+ dataFiles: [path.join(grokHome(env), 'auth.json.lock')],
230
+ });
231
+ // A Grok review checkout stays untrusted (ADR-057 Amendment 13), and Grok's terminal then stops
232
+ // at "Do you trust the contents of this directory?" for any checkout with project configuration.
233
+ const terminalReviewRefusalByRunner = {
234
+ grok: "Grok terminal reviews are unavailable: the review checkout stays untrusted and Grok's terminal stops at its folder-trust prompt. Use the native Grok transport.",
235
+ };
220
236
  const reviewConfigurationRootsByRunner = {
221
237
  grok: reviewConfigurationRoots,
222
238
  claude: reviewConfigurationRoots,
@@ -237,13 +253,15 @@ module.exports = {
237
253
  codexHome,
238
254
  grokHome,
239
255
  reviewConfigurationRootsByRunner,
256
+ terminalReviewRefusalByRunner,
257
+ grokReviewHomeAccess,
240
258
  codexWorkspaceTrustConfig,
241
259
  trustGrokFolders,
242
- trustGrokWorkspace,
260
+ checkGrokReviewWorkspace,
243
261
  configureCodexReviewWorkspace,
244
262
  workspaceTrustByRunner: {
245
263
  codex: configureCodexReviewWorkspace,
246
- grok: trustGrokWorkspace,
264
+ grok: checkGrokReviewWorkspace,
247
265
  claude: trustClaudeWorkspace,
248
266
  },
249
267
  trustClaudeWorkspace,