@farmslot/agent-runtime 0.39.24 → 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.
- package/CHANGELOG.md +15 -0
- package/dist/native/account-common.d.ts +2 -1
- package/dist/native/account-common.d.ts.map +1 -1
- package/dist/native/account-common.js +10 -7
- package/dist/native/account-common.js.map +1 -1
- package/dist/native/account-grok.d.ts.map +1 -1
- package/dist/native/account-grok.js +2 -2
- package/dist/native/account-grok.js.map +1 -1
- package/dist/native/acp-rpc.d.ts +4 -0
- package/dist/native/acp-rpc.d.ts.map +1 -1
- package/dist/native/acp-rpc.js +9 -0
- package/dist/native/acp-rpc.js.map +1 -1
- package/dist/native/acp.d.ts +2 -2
- package/dist/native/acp.d.ts.map +1 -1
- package/dist/native/acp.js +4 -7
- package/dist/native/acp.js.map +1 -1
- package/dist/native/grok.d.ts +7 -0
- package/dist/native/grok.d.ts.map +1 -1
- package/dist/native/grok.js +19 -1
- package/dist/native/grok.js.map +1 -1
- package/dist/native/manager.d.ts.map +1 -1
- package/dist/native/manager.js +8 -3
- package/dist/native/manager.js.map +1 -1
- package/dist/native/registry.d.ts +5 -1
- package/dist/native/registry.d.ts.map +1 -1
- package/dist/native/registry.js +3 -1
- package/dist/native/registry.js.map +1 -1
- package/dist/native/review-sandbox.d.ts +6 -1
- package/dist/native/review-sandbox.d.ts.map +1 -1
- package/dist/native/review-sandbox.js.map +1 -1
- package/dist/native/worker-launch.d.ts +2 -0
- package/dist/native/worker-launch.d.ts.map +1 -1
- package/dist/native/worker-launch.js +6 -20
- package/dist/native/worker-launch.js.map +1 -1
- package/package.json +2 -1
- package/scripts/native-worker-env.cjs +59 -0
- package/scripts/review-account-preflight.cjs +123 -21
- package/scripts/review-filesystem.cjs +39 -3
- package/scripts/review-terminal.cjs +3 -0
- package/scripts/workspace-trust.cjs +27 -9
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
const { execFileSync } = require('node:child_process');
|
|
2
|
-
const {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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
|
-
'
|
|
42
|
-
'
|
|
43
|
-
'
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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:
|
|
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
|
-
//
|
|
73
|
-
if (
|
|
74
|
-
|
|
75
|
-
|
|
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
|
|
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 = {
|
|
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,
|
|
@@ -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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
260
|
+
checkGrokReviewWorkspace,
|
|
243
261
|
configureCodexReviewWorkspace,
|
|
244
262
|
workspaceTrustByRunner: {
|
|
245
263
|
codex: configureCodexReviewWorkspace,
|
|
246
|
-
grok:
|
|
264
|
+
grok: checkGrokReviewWorkspace,
|
|
247
265
|
claude: trustClaudeWorkspace,
|
|
248
266
|
},
|
|
249
267
|
trustClaudeWorkspace,
|