@yunhozz/arc 0.4.4 → 0.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MANIFEST.sha256 +56 -54
- package/README.md +2 -2
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/references/commit.md +6 -4
- package/claude/skill/references/coordination.md +87 -10
- package/claude/skill/references/handoff-prep.md +4 -4
- package/claude/skill/references/handoff.md +1 -1
- package/claude/skill/references/planning.md +5 -4
- package/claude/skill/references/verification.md +4 -4
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/references/commit.md +6 -4
- package/codex/skill/references/coordination.md +87 -10
- package/codex/skill/references/handoff-prep.md +4 -4
- package/codex/skill/references/handoff.md +1 -1
- package/codex/skill/references/planning.md +5 -4
- package/codex/skill/references/verification.md +4 -4
- package/gemini/skill/SKILL.md +1 -1
- package/gemini/skill/references/commit.md +6 -4
- package/gemini/skill/references/coordination.md +88 -11
- package/gemini/skill/references/handoff-prep.md +4 -4
- package/gemini/skill/references/handoff.md +1 -1
- package/gemini/skill/references/planning.md +5 -4
- package/gemini/skill/references/verification.md +4 -4
- package/grok/skill/SKILL.md +1 -1
- package/grok/skill/references/commit.md +6 -4
- package/grok/skill/references/coordination.md +91 -14
- package/grok/skill/references/handoff-prep.md +4 -4
- package/grok/skill/references/handoff.md +1 -1
- package/grok/skill/references/planning.md +5 -4
- package/grok/skill/references/verification.md +4 -4
- package/lib/installer/role-routing.mjs +2 -2
- package/lib/installer/runtime-assets.mjs +1 -0
- package/lib/management/operations.mjs +2 -2
- package/lib/platforms/claude.mjs +1 -0
- package/lib/platforms/codex.mjs +1 -0
- package/lib/platforms/index.mjs +7 -0
- package/lib/policy/role-policy.json +2 -2
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/grok-sandbox.mjs +308 -0
- package/lib/runtime/platform-registry.mjs +2 -2
- package/lib/runtime/role-bridge-args.mjs +6 -4
- package/lib/runtime/role-bridge.mjs +14 -6
- package/lib/runtime/role-dispatch-policy.mjs +32 -5
- package/lib/runtime/role-observe.mjs +213 -3
- package/lib/runtime/role-routing.mjs +37 -4
- package/lib/runtime/role-supervisor.mjs +95 -27
- package/package.json +1 -1
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/grok-sandbox.mjs +308 -0
- package/shared/skill/runtime/platform-registry.mjs +2 -2
- package/shared/skill/runtime/role-bridge-args.mjs +6 -4
- package/shared/skill/runtime/role-bridge.mjs +14 -6
- package/shared/skill/runtime/role-dispatch-policy.mjs +32 -5
- package/shared/skill/runtime/role-observe.mjs +213 -3
- package/shared/skill/runtime/role-policy.json +2 -2
- package/shared/skill/runtime/role-routing.mjs +37 -4
- package/shared/skill/runtime/role-supervisor.mjs +95 -27
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import {EVENTS_MAX_BYTES} from './role-dispatch-policy.mjs';
|
|
5
|
+
|
|
6
|
+
export const GROK_SANDBOX_RELATIVE = '.grok/sandbox.toml';
|
|
7
|
+
export const GROK_SANDBOX_DENY = Object.freeze([
|
|
8
|
+
'.grok/sandbox.toml', '~/.grok/skills', '~/.grok/agents', '~/.grok/rules',
|
|
9
|
+
'~/.grok/workflows', '~/.grok/plugins', '~/.grok/installed-plugins', '~/.grok/plugin-data',
|
|
10
|
+
'~/.grok/personas', '~/.grok/memory', '~/.grok/memory-v2', '~/.grok/AGENTS.md',
|
|
11
|
+
'~/.grok/statusline.sh', '~/.grok/lsp.json', '~/.grok/bin', '~/.grok/downloads',
|
|
12
|
+
'~/.grok/bundled', '~/.grok/bundles', '~/.grok/settings.json', '~/.grok/pager.toml',
|
|
13
|
+
'~/.grok/mcp_credentials.json', '~/.grok/worktrees', '~/.grok/workspaces', '~/.grok/daemon',
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const digest = bytes => 'sha256:' + crypto.createHash('sha256').update(bytes).digest('hex');
|
|
17
|
+
const scopeError = (message, cause) => Object.assign(Error(message, {cause}), {reasonCode: 'permission_scope_unverified'});
|
|
18
|
+
const sameEntry = (first, second) => first.dev === second.dev && first.ino === second.ino;
|
|
19
|
+
const identityOf = ({dev, ino}) => ({dev, ino});
|
|
20
|
+
const sandboxEventsPath = grokHome => path.join(grokHome, 'sessions', 'sandbox-events.jsonl');
|
|
21
|
+
|
|
22
|
+
function parseConfigKeyPath(source) {
|
|
23
|
+
const segment = /\s*(?:"([^"\\]*)"|'([^'\\]*)'|([\w-]+))\s*/y;
|
|
24
|
+
const segments = [];
|
|
25
|
+
for (;;) {
|
|
26
|
+
const match = segment.exec(source);
|
|
27
|
+
if (!match) return null;
|
|
28
|
+
segments.push(match[1] ?? match[2] ?? match[3]);
|
|
29
|
+
if (source[segment.lastIndex] !== '.') return {segments, rest: source.slice(segment.lastIndex)};
|
|
30
|
+
segment.lastIndex += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isGrokSecurityPath(segments) {
|
|
35
|
+
return segments.includes('permission_mode') || (segments[0] === 'compat' && segments[1] === 'claude')
|
|
36
|
+
|| /^sandbox[\w-]*$/.test(segments[0]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function arrayDepthAfterLine(value, depth) {
|
|
40
|
+
let quote = null;
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
const char = value[i];
|
|
43
|
+
if (quote) {
|
|
44
|
+
if (quote === '"' && char === '\\') i += 1;
|
|
45
|
+
else if (char === quote) quote = null;
|
|
46
|
+
} else if (char === '"' || char === "'") {
|
|
47
|
+
quote = char;
|
|
48
|
+
} else if (char === '#') {
|
|
49
|
+
break;
|
|
50
|
+
} else if (char === '[') {
|
|
51
|
+
depth += 1;
|
|
52
|
+
} else if (char === ']') {
|
|
53
|
+
depth -= 1;
|
|
54
|
+
if (depth < 0) return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return quote ? null : depth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function grokConfigSecurityProjection(bytes) {
|
|
61
|
+
let config;
|
|
62
|
+
try { config = new TextDecoder('utf-8', {fatal: true}).decode(bytes); } catch { return null; }
|
|
63
|
+
if (config.includes('"""') || config.includes("'''")) return null;
|
|
64
|
+
|
|
65
|
+
const lines = [];
|
|
66
|
+
let table = [];
|
|
67
|
+
let arrayDepth = 0, securityValue = false;
|
|
68
|
+
for (const raw of config.split('\n')) {
|
|
69
|
+
const line = raw.trim();
|
|
70
|
+
if (!line || line.startsWith('#')) continue;
|
|
71
|
+
if (arrayDepth > 0) {
|
|
72
|
+
arrayDepth = arrayDepthAfterLine(line, arrayDepth);
|
|
73
|
+
if (arrayDepth === null) return null;
|
|
74
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (line.startsWith('[')) {
|
|
78
|
+
const arrayTable = line.startsWith('[[');
|
|
79
|
+
const header = parseConfigKeyPath(line.slice(arrayTable ? 2 : 1));
|
|
80
|
+
const closing = arrayTable ? /^\]\]\s*(?:#.*)?$/ : /^\]\s*(?:#.*)?$/;
|
|
81
|
+
if (!header || !closing.test(header.rest)) return null;
|
|
82
|
+
table = header.segments;
|
|
83
|
+
if (isGrokSecurityPath(table)) lines.push(`${table.join('.')}\t${line}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = parseConfigKeyPath(line);
|
|
87
|
+
if (!key || !key.rest.startsWith('=')) return null;
|
|
88
|
+
arrayDepth = arrayDepthAfterLine(key.rest.slice(1), 0);
|
|
89
|
+
if (arrayDepth === null) return null;
|
|
90
|
+
securityValue = isGrokSecurityPath([...table, ...key.segments]);
|
|
91
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
92
|
+
}
|
|
93
|
+
return arrayDepth === 0 ? lines.join('\n') : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export function grokSandboxProfileName(dispatchId) {
|
|
97
|
+
const prefix = typeof dispatchId === 'string' ? dispatchId.slice(0, 8) : '';
|
|
98
|
+
return /^[0-9a-f]{8}$/.test(prefix) ? 'arc-bridge-' + prefix : null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function renderGrokSandboxProfile(name) {
|
|
102
|
+
if (typeof name !== 'string' || !/^arc-bridge-[0-9a-f]{8}$/.test(name)) throw Error('Invalid Grok profile name');
|
|
103
|
+
const deny = GROK_SANDBOX_DENY.map(entry => JSON.stringify(entry)).join(', ');
|
|
104
|
+
return Buffer.from(`[profiles.${name}]\nextends = "workspace"\ndeny = [${deny}]\n`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export function grokProfileCovered(allowedPaths) {
|
|
108
|
+
return allowedPaths.some(entry => (entry.endsWith('/') ? GROK_SANDBOX_RELATIVE.startsWith(entry) : entry === GROK_SANDBOX_RELATIVE)
|
|
109
|
+
|| entry === '.grok' || entry.startsWith('.grok/'));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function inspectGrokProfileSlot(worktree) {
|
|
113
|
+
const file = path.join(worktree, GROK_SANDBOX_RELATIVE), directory = path.dirname(file);
|
|
114
|
+
try {
|
|
115
|
+
const parent = fs.lstatSync(directory, {throwIfNoEntry: false});
|
|
116
|
+
if (parent && !parent.isDirectory()) throw Error('.grok is not a real directory');
|
|
117
|
+
if (fs.lstatSync(file, {throwIfNoEntry: false})) throw Error('Sandbox profile slot is occupied');
|
|
118
|
+
} catch (cause) {
|
|
119
|
+
throw scopeError('Grok sandbox profile slot unavailable', cause);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function checkGrokHome({grokHome, userHome, childEnv}) {
|
|
124
|
+
if (typeof grokHome !== 'string' || childEnv?.GROK_HOME !== grokHome) return false;
|
|
125
|
+
try {
|
|
126
|
+
if (Object.hasOwn(childEnv, 'HOME') && fs.realpathSync(childEnv.HOME) !== fs.realpathSync(userHome)) return false;
|
|
127
|
+
return !fs.lstatSync(grokHome, {throwIfNoEntry: false})?.isSymbolicLink();
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function createGrokSandboxProfile({worktree, bytes}) {
|
|
134
|
+
const file = path.join(worktree, GROK_SANDBOX_RELATIVE), directory = path.dirname(file);
|
|
135
|
+
const profile = {path: file, sha256: digest(bytes), dirCreated: false};
|
|
136
|
+
let fd;
|
|
137
|
+
try {
|
|
138
|
+
try {
|
|
139
|
+
fs.mkdirSync(directory, 0o700);
|
|
140
|
+
profile.dirCreated = true;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (error.code !== 'EEXIST') throw error;
|
|
143
|
+
}
|
|
144
|
+
const parent = fs.lstatSync(directory);
|
|
145
|
+
if (!parent.isDirectory()) throw Error('.grok is not a real directory');
|
|
146
|
+
profile.directoryIdentity = identityOf(parent);
|
|
147
|
+
// During creation, the parent .grok can become a symlink between its identity lstat and open.
|
|
148
|
+
fd = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW, 0o444);
|
|
149
|
+
try {
|
|
150
|
+
const opened = fs.fstatSync(fd);
|
|
151
|
+
if (!opened.isFile()) throw Error('Grok sandbox profile is not a regular file');
|
|
152
|
+
profile.fileIdentity = identityOf(opened);
|
|
153
|
+
checkProfileEntries(profile);
|
|
154
|
+
fs.writeFileSync(fd, bytes);
|
|
155
|
+
fs.fchmodSync(fd, 0o444);
|
|
156
|
+
} finally {
|
|
157
|
+
fs.closeSync(fd);
|
|
158
|
+
}
|
|
159
|
+
checkProfileEntries(profile);
|
|
160
|
+
return profile;
|
|
161
|
+
} catch (cause) {
|
|
162
|
+
const error = scopeError('Grok sandbox profile creation failed', cause);
|
|
163
|
+
if (fd !== undefined) {
|
|
164
|
+
const {removed, dirRemoved, violation} = profile.fileIdentity
|
|
165
|
+
? removeGrokSandboxProfile(profile)
|
|
166
|
+
: {removed: false, dirRemoved: false, violation: true};
|
|
167
|
+
error.cleanup = {path: file, retained: !removed, violation, dirRemoved};
|
|
168
|
+
} else if (profile.dirCreated && profile.directoryIdentity) {
|
|
169
|
+
try {
|
|
170
|
+
checkProfileDirectory(profile);
|
|
171
|
+
fs.rmdirSync(directory);
|
|
172
|
+
} catch { /* retain a concurrently occupied or replaced directory */ }
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function checkProfileDirectory({path: file, directoryIdentity}) {
|
|
179
|
+
const parent = fs.lstatSync(path.dirname(file));
|
|
180
|
+
if (!parent.isDirectory() || !sameEntry(parent, directoryIdentity)) throw Error('Grok sandbox directory changed');
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function checkProfileEntries(profile) {
|
|
184
|
+
checkProfileDirectory(profile);
|
|
185
|
+
const stat = fs.lstatSync(profile.path);
|
|
186
|
+
if (!stat.isFile() || !sameEntry(stat, profile.fileIdentity)) throw Error('Grok sandbox profile was replaced');
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function verifyGrokSandboxProfile(profile) {
|
|
190
|
+
const {path: file, sha256, fileIdentity} = profile;
|
|
191
|
+
try {
|
|
192
|
+
checkProfileEntries(profile);
|
|
193
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
194
|
+
try {
|
|
195
|
+
const opened = fs.fstatSync(fd);
|
|
196
|
+
if (!opened.isFile() || !sameEntry(opened, fileIdentity) || digest(fs.readFileSync(fd)) !== sha256) return false;
|
|
197
|
+
} finally {
|
|
198
|
+
fs.closeSync(fd);
|
|
199
|
+
}
|
|
200
|
+
checkProfileEntries(profile);
|
|
201
|
+
return true;
|
|
202
|
+
} catch {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function removeGrokSandboxProfile(profile) {
|
|
208
|
+
const {path: file, dirCreated} = profile;
|
|
209
|
+
const result = {removed: false, dirRemoved: false, violation: false};
|
|
210
|
+
if (!verifyGrokSandboxProfile(profile)) return {...result, violation: true};
|
|
211
|
+
try {
|
|
212
|
+
// Node has no unlinkat, so a race remains between the final identity check and unlink.
|
|
213
|
+
fs.unlinkSync(file);
|
|
214
|
+
result.removed = true;
|
|
215
|
+
if (dirCreated) {
|
|
216
|
+
try {
|
|
217
|
+
checkProfileDirectory(profile);
|
|
218
|
+
fs.rmdirSync(path.dirname(file));
|
|
219
|
+
result.dirRemoved = true;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (error.code !== 'ENOTEMPTY') throw error;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
} catch {
|
|
225
|
+
result.violation = true;
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export function grokEventsBaseline(grokHome) {
|
|
231
|
+
const stat = fs.lstatSync(sandboxEventsPath(grokHome), {throwIfNoEntry: false});
|
|
232
|
+
if (!stat) return {exists: false, size: 0};
|
|
233
|
+
if (!stat.isFile()) throw Error('Grok sandbox events are not a regular file');
|
|
234
|
+
return {exists: true, dev: stat.dev, ino: stat.ino, size: stat.size};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const unapplied = (reason, candidates = 0) => ({ok: false, reason, candidates, applied: null});
|
|
238
|
+
|
|
239
|
+
function eventsFileIssue(baseline, current, maxBytes) {
|
|
240
|
+
if (!current.exists) return baseline.exists ? 'rotated' : 'no_candidate';
|
|
241
|
+
if (!current.regular) return 'not_regular';
|
|
242
|
+
if (baseline.exists && !sameEntry(baseline, current)) return 'rotated';
|
|
243
|
+
if (current.size < baseline.size) return 'truncated';
|
|
244
|
+
if (current.size - baseline.size > maxBytes) return 'too_large';
|
|
245
|
+
return null;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function evaluateGrokProfileApplied({text, baseline, current, spawnAtMs, name, worktreeRealpath, maxBytes = EVENTS_MAX_BYTES}) {
|
|
249
|
+
const issue = eventsFileIssue(baseline, current, maxBytes);
|
|
250
|
+
if (issue) return unapplied(issue);
|
|
251
|
+
|
|
252
|
+
const lines = text.split('\n');
|
|
253
|
+
lines.pop(); // The last entry is empty or an unfinished append.
|
|
254
|
+
let candidate = null, candidates = 0, invalidTimestamp = false;
|
|
255
|
+
for (const line of lines) {
|
|
256
|
+
let event;
|
|
257
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
258
|
+
if (event?.event_type !== 'ProfileApplied' || event.profile !== name || event.workspace !== worktreeRealpath) continue;
|
|
259
|
+
const timestamp = typeof event.timestamp === 'string' ? Date.parse(event.timestamp) : NaN;
|
|
260
|
+
if (Number.isNaN(timestamp)) {
|
|
261
|
+
invalidTimestamp = true;
|
|
262
|
+
candidates++;
|
|
263
|
+
} else if (timestamp >= spawnAtMs) {
|
|
264
|
+
candidate = event;
|
|
265
|
+
candidates++;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (invalidTimestamp) return unapplied('timestamp_invalid', candidates);
|
|
269
|
+
if (!candidates) return unapplied('no_candidate');
|
|
270
|
+
if (candidates > 1) return unapplied('multiple_candidates', candidates);
|
|
271
|
+
if (candidate.enforced !== true) return unapplied('not_enforced', candidates);
|
|
272
|
+
if (candidate.inherited === true) return unapplied('inherited', candidates);
|
|
273
|
+
const expectedDeny = path.join(worktreeRealpath, GROK_SANDBOX_RELATIVE);
|
|
274
|
+
if (!Array.isArray(candidate.deny_paths) || !candidate.deny_paths.includes(expectedDeny)) return unapplied('deny_missing', candidates);
|
|
275
|
+
const applied = {timestamp: candidate.timestamp, enforced: true, inherited: false, denyOk: true};
|
|
276
|
+
return {ok: true, reason: null, candidates, applied};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export function readGrokProfileApplied({grokHome, baseline, spawnAtMs, name, worktreeRealpath}) {
|
|
280
|
+
const file = sandboxEventsPath(grokHome);
|
|
281
|
+
try {
|
|
282
|
+
const stat = fs.lstatSync(file, {throwIfNoEntry: false});
|
|
283
|
+
const current = stat ? {exists: true, regular: stat.isFile(), dev: stat.dev, ino: stat.ino, size: stat.size} : {exists: false};
|
|
284
|
+
const issue = eventsFileIssue(baseline, current, EVENTS_MAX_BYTES);
|
|
285
|
+
if (issue) return unapplied(issue);
|
|
286
|
+
|
|
287
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
288
|
+
try {
|
|
289
|
+
const opened = fs.fstatSync(fd);
|
|
290
|
+
if (!sameEntry(opened, stat)) return unapplied('rotated');
|
|
291
|
+
if (!opened.isFile()) return unapplied('not_regular');
|
|
292
|
+
if (opened.size < stat.size) return unapplied('truncated');
|
|
293
|
+
|
|
294
|
+
const bytes = Buffer.alloc(stat.size - baseline.size);
|
|
295
|
+
let offset = 0;
|
|
296
|
+
while (offset < bytes.length) {
|
|
297
|
+
const read = fs.readSync(fd, bytes, offset, bytes.length - offset, baseline.size + offset);
|
|
298
|
+
if (read === 0) return unapplied('truncated');
|
|
299
|
+
offset += read;
|
|
300
|
+
}
|
|
301
|
+
return evaluateGrokProfileApplied({text: bytes.toString('utf8'), baseline, current, spawnAtMs, name, worktreeRealpath});
|
|
302
|
+
} finally {
|
|
303
|
+
fs.closeSync(fd);
|
|
304
|
+
}
|
|
305
|
+
} catch (error) {
|
|
306
|
+
return unapplied(error.code === 'ENOENT' || error.code === 'ELOOP' ? 'rotated' : 'not_regular');
|
|
307
|
+
}
|
|
308
|
+
}
|
|
@@ -137,8 +137,8 @@ export const DEFAULT_PLATFORM_REGISTRY = createPlatformRegistry([
|
|
|
137
137
|
},
|
|
138
138
|
executionEnvironments: ['grok-cli'],
|
|
139
139
|
routing: {validatePair: (model, effort) => validText(model) && /^[A-Za-z0-9][A-Za-z0-9._:/@+\-]*$/.test(model) && effort === 'default'},
|
|
140
|
-
capabilities: {install: {state: 'verified'}, nativeProfile: {state: 'verified'}, catalog: {state: 'verified'}, standalone: {state: 'verified'}, bridge: {state: 'verified'}, compositeRole: {state: 'verified'}, ...Object.fromEntries(Object.entries({
|
|
141
|
-
|
|
140
|
+
capabilities: {install: {state: 'verified'}, nativeProfile: {state: 'verified'}, catalog: {state: 'verified'}, standalone: {state: 'verified'}, bridge: {state: 'verified'}, compositeRole: {state: 'verified'}, compositeHost: {state: 'verified'}, ...Object.fromEntries(Object.entries({
|
|
141
|
+
authProbe: 'no official auth status command',
|
|
142
142
|
watch: 'watch support out of scope',
|
|
143
143
|
}).map(([key, reason]) => [key, {state: 'off', reason}]))},
|
|
144
144
|
},
|
|
@@ -20,8 +20,8 @@ export const ROLE_BRIDGE_PERMISSIONS = deepFreeze({
|
|
|
20
20
|
arc_scouter: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
21
21
|
arc_planner: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
22
22
|
arc_reviewer: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
23
|
-
arc_implementer: {permissionMode: 'acceptEdits', sandbox: '
|
|
24
|
-
arc_qa: {permissionMode: 'acceptEdits', sandbox: '
|
|
23
|
+
arc_implementer: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
24
|
+
arc_qa: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
25
25
|
},
|
|
26
26
|
codex: {
|
|
27
27
|
arc_scouter: {sandboxMode: 'read-only', search: true}, arc_planner: {sandboxMode: 'read-only', search: false},
|
|
@@ -231,13 +231,15 @@ export function buildGeminiArgs({role, model, profile, sessionId, policyFile, pr
|
|
|
231
231
|
return args;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
export function buildGrokArgs({role, profile, sessionId, promptFile}) {
|
|
234
|
+
export function buildGrokArgs({role, profile, sessionId, promptFile, sandboxProfile}) {
|
|
235
235
|
const permissions = permissionsFor('grok', role);
|
|
236
236
|
if (typeof promptFile !== 'string' || !path.isAbsolute(promptFile)) throw Error('Absolute promptFile required');
|
|
237
237
|
if (typeof sessionId !== 'string' || !/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(sessionId)) throw Error('Grok sessionId must be a UUID');
|
|
238
238
|
const model = requireText(profile?.model, 'model');
|
|
239
239
|
if (!/^[A-Za-z0-9][A-Za-z0-9._:/@+\-]*$/.test(model)) throw Error('Invalid Grok model');
|
|
240
|
+
const sandbox = permissions.sandbox === 'custom' ? sandboxProfile : permissions.sandbox;
|
|
241
|
+
if (permissions.sandbox === 'custom' && (typeof sandbox !== 'string' || !/^arc-bridge-[0-9a-f]{8}$/.test(sandbox))) throw Error('Invalid Grok sandbox profile');
|
|
240
242
|
return ['--prompt-file', promptFile, '--output-format', GROK_CONTRACT.outputFormat, '-m', model, '--session-id', sessionId,
|
|
241
|
-
'--permission-mode', permissions.permissionMode, '--sandbox',
|
|
243
|
+
'--permission-mode', permissions.permissionMode, '--sandbox', sandbox,
|
|
242
244
|
...permissions.deny.flatMap(rule => ['--deny', rule]), ...GROK_CONTRACT.isolationArgs];
|
|
243
245
|
}
|
|
@@ -3,9 +3,9 @@ import {runtimeRegistryOf, DEFAULT_PLATFORM_REGISTRY} from './platform-registry.
|
|
|
3
3
|
// run-dispatch only asks the supervisor (the sole child spawner) to start; observe reads and records state under the routing lock.
|
|
4
4
|
import fsp from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
-
import {DEFAULT_POLICY, reason, profileName, bridgeGateReasons, environmentReasons, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
6
|
+
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, bridgeGateReasons, environmentReasons, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
7
7
|
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
|
|
8
|
-
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome} from './role-routing.mjs';
|
|
8
|
+
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
|
|
9
9
|
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation} from './role-supervisor.mjs';
|
|
10
10
|
|
|
11
11
|
export const heldRoutingResult=(code,releaseCondition)=>({decision:'hold',routeStatus:'held',supportStatus:'unverified',route:null,executionEnvironment:null,hostPlatform:null,role:null,requested:null,authentication:null,reasons:[{code,releaseCondition}]});
|
|
@@ -47,16 +47,20 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
47
47
|
await withRoutingLock(anchorHome,async()=>{
|
|
48
48
|
const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
|
|
49
49
|
if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform||lease.route!=='bridge'||lease.state!=='reserved'){result=blank(context,dispatchId,'deny','invalid_request');return;}
|
|
50
|
-
leaseTargetPlatform(lease,runtimePlatforms);
|
|
50
|
+
const platform=leaseTargetPlatform(lease,runtimePlatforms);
|
|
51
51
|
let config;try{config=await readActivation(homes,lease.revision,{anchorHome,host:context.hostPlatform,runtimePlatforms});}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
52
52
|
validateLease(lease,{runtimePlatforms,config});
|
|
53
|
-
const capabilities=capabilityReasons({hostPlatform:lease.hostPlatform,targetPlatform:
|
|
53
|
+
const capabilities=capabilityReasons({hostPlatform:lease.hostPlatform,targetPlatform:platform,route:lease.route,runtimePlatforms});
|
|
54
54
|
if(capabilities.length){result=blank(context,dispatchId,'hold',capabilities[0]);return;}
|
|
55
55
|
let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
56
56
|
const directory=artifactDirectory(target,lease.workflowId,dispatchId),resultPath=path.join(directory,'result.md');
|
|
57
57
|
let invocation;try{invocation=await buildBridgeInvocation({lease,config,homes,worktree:target.realpath,resultPath,policy});}catch(error){result=blank(context,dispatchId,'hold',error.reasonCode??'activation_unverified');return;}
|
|
58
58
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(directory,0o700);
|
|
59
59
|
await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
|
|
60
|
+
if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
|
|
61
|
+
const probe=await probeHomeWritable(homes[platform]);
|
|
62
|
+
if(!probe.ok){result=hold(context,dispatchId,probe.code,probe);return;}
|
|
63
|
+
}
|
|
60
64
|
let supervisor;
|
|
61
65
|
try{supervisor=await starter({codexHome:anchorHome,dispatchId,cwd:target.realpath,userHome:context.userHome,env:context.env??process.env});}
|
|
62
66
|
catch{result=blank(context,dispatchId,'hold','host_sandbox_blocked');return;}
|
|
@@ -67,7 +71,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
67
71
|
if(error?.code==='ARC_ROUTING_LOCK_RELEASE'&&!error.failure&&result){residual=residualOf(error);}
|
|
68
72
|
else return hold(context,dispatchId,classifyLock(error),error);
|
|
69
73
|
}
|
|
70
|
-
if(residual)result.residualPaths=residual;
|
|
74
|
+
if(residual)result.residualPaths=[...(result.residualPaths??[]),...residual];
|
|
71
75
|
return result;
|
|
72
76
|
}
|
|
73
77
|
|
|
@@ -165,6 +169,10 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
165
169
|
let invocation;try{invocation=await buildBridgeInvocation({lease:{...lease,segment},config,homes,worktree:target.realpath,resultPath,policy,supervisorImplementations});}catch(error){result=blank(context,dispatchId,'hold',error.reasonCode??'activation_unverified');return;}
|
|
166
170
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(path.dirname(directory),0o700);await fsp.chmod(directory,0o700);
|
|
167
171
|
await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
|
|
172
|
+
if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
|
|
173
|
+
const probe=await probeHomeWritable(homes[platform]);
|
|
174
|
+
if(!probe.ok){result=hold(context,dispatchId,probe.code,probe);return;}
|
|
175
|
+
}
|
|
168
176
|
await clearCancel(anchorHome,dispatchId);
|
|
169
177
|
let supervisor;
|
|
170
178
|
try{supervisor=await starter({codexHome:anchorHome,dispatchId,cwd:target.realpath,userHome:context.userHome,env:context.env??process.env});}
|
|
@@ -177,7 +185,7 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
177
185
|
if(error?.code==='ARC_ROUTING_LOCK_RELEASE'&&!error.failure&&result){residual=residualOf(error);}
|
|
178
186
|
else return hold(context,dispatchId,classifyLock(error),error);
|
|
179
187
|
}
|
|
180
|
-
if(residual)result.residualPaths=residual;
|
|
188
|
+
if(residual)result.residualPaths=[...(result.residualPaths??[]),...residual];
|
|
181
189
|
return result;
|
|
182
190
|
}
|
|
183
191
|
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
2
2
|
// Fixed policy values for composite role dispatch. G2 'escalation' means the bridge runs only with per-call user escalation approval on a Codex host; it is not a verified pass.
|
|
3
|
-
|
|
4
|
-
//
|
|
5
|
-
|
|
3
|
+
// GK2/GG2 'approval' means a Grok/Gemini host keeps its platform-default sandbox (off), runs in ask mode, and obtains user approval for each runtime command; it is not a verified pass.
|
|
4
|
+
// GK2 evidence: Grok 1.0.89, 2026-11-19, ask mode with the sandbox off.
|
|
5
|
+
// GK1 evidence: Grok 1.0.89, 2026-11-19, writing roles only, with mandatory ProfileApplied verification.
|
|
6
|
+
export const BRIDGE_GATE_RESULTS = Object.freeze({G1: 'pass', G2: 'escalation', G3: 'pass', G4: 'pass', G5: 'wide', G6: 'strict', G7: 'pass', G8: 'pass', GG1: 'fail', GG2: 'fail', GK1: 'pass', GK2: 'approval'});
|
|
7
|
+
export const HOST_SANDBOX_GATES = Object.freeze({grok: 'GK2', gemini: 'GG2'});
|
|
8
|
+
export const HOST_GATE_ALLOWED = Object.freeze(['pass', 'approval']);
|
|
9
|
+
|
|
10
|
+
function deepFreeze(value) {
|
|
11
|
+
for (const nested of Object.values(value)) {
|
|
12
|
+
if (nested !== null && typeof nested === 'object') deepFreeze(nested);
|
|
13
|
+
}
|
|
14
|
+
return Object.freeze(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Claude 2.1.327, 2026-11-20, T0 M-C10/M-C11/M-C12/FINAL
|
|
18
|
+
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
+
permissions: {deny: ['Edit(./.git/**)', 'Write(./.git/**)']},
|
|
20
|
+
sandbox: {
|
|
21
|
+
enabled: true,
|
|
22
|
+
autoAllowBashIfSandboxed: true,
|
|
23
|
+
allowUnsandboxedCommands: false,
|
|
24
|
+
failIfUnavailable: true,
|
|
25
|
+
filesystem: {denyWrite: ['./.git']},
|
|
26
|
+
},
|
|
27
|
+
});
|
|
6
28
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
7
29
|
export const CLAUDE_SANDBOX_SETTINGS = BRIDGE_GATE_RESULTS.G1 === 'pass' && isRecordedObject(RECORDED_CLAUDE_SANDBOX_SETTINGS) ? RECORDED_CLAUDE_SANDBOX_SETTINGS : null;
|
|
8
30
|
/** G1 counts as passed only with an explicitly recorded settings object; otherwise the settings are null. */
|
|
@@ -83,13 +105,18 @@ export function capabilityReasons({hostPlatform, targetPlatform, route, runtimeP
|
|
|
83
105
|
&& (route !== 'bridge' || target?.capabilities.bridge.state === 'verified') ? [] : ['capability_not_verified'];
|
|
84
106
|
}
|
|
85
107
|
|
|
108
|
+
export function hostGateReasons({hostPlatform, policy = DEFAULT_POLICY}) {
|
|
109
|
+
if (!Object.hasOwn(HOST_SANDBOX_GATES, hostPlatform)) return [];
|
|
110
|
+
const gates = policy.gates ?? BRIDGE_GATE_RESULTS;
|
|
111
|
+
return HOST_GATE_ALLOWED.includes(gates[HOST_SANDBOX_GATES[hostPlatform]]) ? [] : ['host_sandbox_blocked'];
|
|
112
|
+
}
|
|
113
|
+
|
|
86
114
|
export function bridgeGateReasons({platform, role, hostPlatform, policy = DEFAULT_POLICY}) {
|
|
87
115
|
const gates = policy.gates ?? BRIDGE_GATE_RESULTS, codes = [];
|
|
88
116
|
if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_qa') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
|
|
89
117
|
if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
|
|
90
118
|
if (platform === 'grok' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GK1 !== 'pass') codes.push('permission_scope_unverified');
|
|
91
|
-
|
|
92
|
-
if (hostPlatform === 'gemini' && gates.GG2 !== 'pass') codes.push('host_sandbox_blocked');
|
|
119
|
+
codes.push(...hostGateReasons({hostPlatform, policy}));
|
|
93
120
|
if (platform === 'codex' && gates.G4 === 'fail') codes.push('permission_scope_unverified');
|
|
94
121
|
if (hostPlatform === 'codex' && gates.G2 === 'fail') codes.push('host_sandbox_blocked');
|
|
95
122
|
return [...new Set(codes)];
|