@yunhozz/arc 0.4.3 → 0.4.5
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 +86 -84
- package/README.md +3 -2
- package/claude/agents/arc-implementer.md +1 -0
- package/claude/agents/arc-planner.md +1 -0
- package/claude/agents/arc-qa.md +1 -0
- package/claude/agents/arc-reviewer.md +1 -0
- package/claude/agents/arc-scouter.md +1 -0
- package/claude/skill/SKILL.md +7 -4
- package/claude/skill/references/commit.md +6 -4
- package/claude/skill/references/coordination.md +84 -9
- package/claude/skill/references/handoff-prep.md +4 -4
- package/claude/skill/references/handoff.md +1 -1
- package/claude/skill/references/planning.md +41 -4
- package/claude/skill/references/verification.md +4 -4
- package/codex/agents/arc-implementer.toml +1 -0
- package/codex/agents/arc-planner.toml +1 -0
- package/codex/agents/arc-qa.toml +1 -0
- package/codex/agents/arc-reviewer.toml +1 -0
- package/codex/agents/arc-scouter.toml +1 -0
- package/codex/skill/SKILL.md +7 -4
- package/codex/skill/references/commit.md +6 -4
- package/codex/skill/references/coordination.md +84 -9
- package/codex/skill/references/handoff-prep.md +4 -4
- package/codex/skill/references/handoff.md +1 -1
- package/codex/skill/references/planning.md +41 -4
- package/codex/skill/references/verification.md +4 -4
- package/gemini/agents/arc-implementer.md +1 -0
- package/gemini/agents/arc-planner.md +1 -0
- package/gemini/agents/arc-qa.md +1 -0
- package/gemini/agents/arc-reviewer.md +1 -0
- package/gemini/agents/arc-scouter.md +1 -0
- package/gemini/skill/SKILL.md +7 -4
- package/gemini/skill/references/commit.md +6 -4
- package/gemini/skill/references/coordination.md +85 -10
- package/gemini/skill/references/handoff-prep.md +4 -4
- package/gemini/skill/references/handoff.md +1 -1
- package/gemini/skill/references/planning.md +41 -4
- package/gemini/skill/references/verification.md +4 -4
- package/grok/agents/arc-implementer.md +1 -0
- package/grok/agents/arc-planner.md +1 -0
- package/grok/agents/arc-qa.md +1 -0
- package/grok/agents/arc-reviewer.md +1 -0
- package/grok/agents/arc-scouter.md +1 -0
- package/grok/skill/SKILL.md +7 -4
- package/grok/skill/references/commit.md +6 -4
- package/grok/skill/references/coordination.md +88 -13
- package/grok/skill/references/handoff-prep.md +4 -4
- package/grok/skill/references/handoff.md +1 -1
- package/grok/skill/references/planning.md +41 -4
- package/grok/skill/references/verification.md +4 -4
- package/lib/installer/global-config.mjs +8 -3
- package/lib/installer/language.mjs +54 -6
- package/lib/installer/plan.mjs +13 -11
- package/lib/installer/role-routing.mjs +2 -2
- package/lib/installer/runtime-assets.mjs +1 -0
- package/lib/installer/upgrade-state.mjs +10 -3
- package/lib/installer/upgrade.mjs +3 -3
- package/lib/management/operations.mjs +9 -6
- package/lib/management/status.mjs +22 -3
- package/lib/platforms/claude.mjs +1 -0
- package/lib/platforms/codex.mjs +1 -0
- package/lib/platforms/index.mjs +7 -0
- package/lib/policy/placement.mjs +2 -2
- package/lib/policy/render.mjs +1 -1
- package/lib/policy/role-policy.json +28 -2
- package/lib/prompts/agent-fragments.json +1 -1
- package/lib/prompts/render.mjs +1 -1
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/grok-sandbox.mjs +234 -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 +30 -5
- package/lib/runtime/role-routing.mjs +31 -4
- package/lib/runtime/role-supervisor.mjs +77 -16
- package/lib/tui/mode.mjs +15 -3
- package/lib/tui/setup.mjs +51 -34
- package/package.json +1 -1
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/grok-sandbox.mjs +234 -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 +30 -5
- package/shared/skill/runtime/role-policy.json +28 -2
- package/shared/skill/runtime/role-routing.mjs +31 -4
- package/shared/skill/runtime/role-supervisor.mjs +77 -16
|
@@ -0,0 +1,234 @@
|
|
|
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
|
+
export function grokSandboxProfileName(dispatchId) {
|
|
23
|
+
const prefix = typeof dispatchId === 'string' ? dispatchId.slice(0, 8) : '';
|
|
24
|
+
return /^[0-9a-f]{8}$/.test(prefix) ? 'arc-bridge-' + prefix : null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function renderGrokSandboxProfile(name) {
|
|
28
|
+
if (typeof name !== 'string' || !/^arc-bridge-[0-9a-f]{8}$/.test(name)) throw Error('Invalid Grok profile name');
|
|
29
|
+
const deny = GROK_SANDBOX_DENY.map(entry => JSON.stringify(entry)).join(', ');
|
|
30
|
+
return Buffer.from(`[profiles.${name}]\nextends = "workspace"\ndeny = [${deny}]\n`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function grokProfileCovered(allowedPaths) {
|
|
34
|
+
return allowedPaths.some(entry => (entry.endsWith('/') ? GROK_SANDBOX_RELATIVE.startsWith(entry) : entry === GROK_SANDBOX_RELATIVE)
|
|
35
|
+
|| entry === '.grok' || entry.startsWith('.grok/'));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function inspectGrokProfileSlot(worktree) {
|
|
39
|
+
const file = path.join(worktree, GROK_SANDBOX_RELATIVE), directory = path.dirname(file);
|
|
40
|
+
try {
|
|
41
|
+
const parent = fs.lstatSync(directory, {throwIfNoEntry: false});
|
|
42
|
+
if (parent && !parent.isDirectory()) throw Error('.grok is not a real directory');
|
|
43
|
+
if (fs.lstatSync(file, {throwIfNoEntry: false})) throw Error('Sandbox profile slot is occupied');
|
|
44
|
+
} catch (cause) {
|
|
45
|
+
throw scopeError('Grok sandbox profile slot unavailable', cause);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function checkGrokHome({grokHome, userHome, childEnv}) {
|
|
50
|
+
if (typeof grokHome !== 'string' || childEnv?.GROK_HOME !== grokHome) return false;
|
|
51
|
+
try {
|
|
52
|
+
if (Object.hasOwn(childEnv, 'HOME') && fs.realpathSync(childEnv.HOME) !== fs.realpathSync(userHome)) return false;
|
|
53
|
+
return !fs.lstatSync(grokHome, {throwIfNoEntry: false})?.isSymbolicLink();
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createGrokSandboxProfile({worktree, bytes}) {
|
|
60
|
+
const file = path.join(worktree, GROK_SANDBOX_RELATIVE), directory = path.dirname(file);
|
|
61
|
+
const profile = {path: file, sha256: digest(bytes), dirCreated: false};
|
|
62
|
+
let fd;
|
|
63
|
+
try {
|
|
64
|
+
try {
|
|
65
|
+
fs.mkdirSync(directory, 0o700);
|
|
66
|
+
profile.dirCreated = true;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
if (error.code !== 'EEXIST') throw error;
|
|
69
|
+
}
|
|
70
|
+
const parent = fs.lstatSync(directory);
|
|
71
|
+
if (!parent.isDirectory()) throw Error('.grok is not a real directory');
|
|
72
|
+
profile.directoryIdentity = identityOf(parent);
|
|
73
|
+
// During creation, the parent .grok can become a symlink between its identity lstat and open.
|
|
74
|
+
fd = fs.openSync(file, fs.constants.O_WRONLY | fs.constants.O_CREAT | fs.constants.O_EXCL | fs.constants.O_NOFOLLOW, 0o444);
|
|
75
|
+
try {
|
|
76
|
+
const opened = fs.fstatSync(fd);
|
|
77
|
+
if (!opened.isFile()) throw Error('Grok sandbox profile is not a regular file');
|
|
78
|
+
profile.fileIdentity = identityOf(opened);
|
|
79
|
+
checkProfileEntries(profile);
|
|
80
|
+
fs.writeFileSync(fd, bytes);
|
|
81
|
+
fs.fchmodSync(fd, 0o444);
|
|
82
|
+
} finally {
|
|
83
|
+
fs.closeSync(fd);
|
|
84
|
+
}
|
|
85
|
+
checkProfileEntries(profile);
|
|
86
|
+
return profile;
|
|
87
|
+
} catch (cause) {
|
|
88
|
+
const error = scopeError('Grok sandbox profile creation failed', cause);
|
|
89
|
+
if (fd !== undefined) {
|
|
90
|
+
const {removed, dirRemoved, violation} = profile.fileIdentity
|
|
91
|
+
? removeGrokSandboxProfile(profile)
|
|
92
|
+
: {removed: false, dirRemoved: false, violation: true};
|
|
93
|
+
error.cleanup = {path: file, retained: !removed, violation, dirRemoved};
|
|
94
|
+
} else if (profile.dirCreated && profile.directoryIdentity) {
|
|
95
|
+
try {
|
|
96
|
+
checkProfileDirectory(profile);
|
|
97
|
+
fs.rmdirSync(directory);
|
|
98
|
+
} catch { /* retain a concurrently occupied or replaced directory */ }
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function checkProfileDirectory({path: file, directoryIdentity}) {
|
|
105
|
+
const parent = fs.lstatSync(path.dirname(file));
|
|
106
|
+
if (!parent.isDirectory() || !sameEntry(parent, directoryIdentity)) throw Error('Grok sandbox directory changed');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function checkProfileEntries(profile) {
|
|
110
|
+
checkProfileDirectory(profile);
|
|
111
|
+
const stat = fs.lstatSync(profile.path);
|
|
112
|
+
if (!stat.isFile() || !sameEntry(stat, profile.fileIdentity)) throw Error('Grok sandbox profile was replaced');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function verifyGrokSandboxProfile(profile) {
|
|
116
|
+
const {path: file, sha256, fileIdentity} = profile;
|
|
117
|
+
try {
|
|
118
|
+
checkProfileEntries(profile);
|
|
119
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
120
|
+
try {
|
|
121
|
+
const opened = fs.fstatSync(fd);
|
|
122
|
+
if (!opened.isFile() || !sameEntry(opened, fileIdentity) || digest(fs.readFileSync(fd)) !== sha256) return false;
|
|
123
|
+
} finally {
|
|
124
|
+
fs.closeSync(fd);
|
|
125
|
+
}
|
|
126
|
+
checkProfileEntries(profile);
|
|
127
|
+
return true;
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function removeGrokSandboxProfile(profile) {
|
|
134
|
+
const {path: file, dirCreated} = profile;
|
|
135
|
+
const result = {removed: false, dirRemoved: false, violation: false};
|
|
136
|
+
if (!verifyGrokSandboxProfile(profile)) return {...result, violation: true};
|
|
137
|
+
try {
|
|
138
|
+
// Node has no unlinkat, so a race remains between the final identity check and unlink.
|
|
139
|
+
fs.unlinkSync(file);
|
|
140
|
+
result.removed = true;
|
|
141
|
+
if (dirCreated) {
|
|
142
|
+
try {
|
|
143
|
+
checkProfileDirectory(profile);
|
|
144
|
+
fs.rmdirSync(path.dirname(file));
|
|
145
|
+
result.dirRemoved = true;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
if (error.code !== 'ENOTEMPTY') throw error;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
result.violation = true;
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function grokEventsBaseline(grokHome) {
|
|
157
|
+
const stat = fs.lstatSync(sandboxEventsPath(grokHome), {throwIfNoEntry: false});
|
|
158
|
+
if (!stat) return {exists: false, size: 0};
|
|
159
|
+
if (!stat.isFile()) throw Error('Grok sandbox events are not a regular file');
|
|
160
|
+
return {exists: true, dev: stat.dev, ino: stat.ino, size: stat.size};
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const unapplied = (reason, candidates = 0) => ({ok: false, reason, candidates, applied: null});
|
|
164
|
+
|
|
165
|
+
function eventsFileIssue(baseline, current, maxBytes) {
|
|
166
|
+
if (!current.exists) return baseline.exists ? 'rotated' : 'no_candidate';
|
|
167
|
+
if (!current.regular) return 'not_regular';
|
|
168
|
+
if (baseline.exists && !sameEntry(baseline, current)) return 'rotated';
|
|
169
|
+
if (current.size < baseline.size) return 'truncated';
|
|
170
|
+
if (current.size - baseline.size > maxBytes) return 'too_large';
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function evaluateGrokProfileApplied({text, baseline, current, spawnAtMs, name, worktreeRealpath, maxBytes = EVENTS_MAX_BYTES}) {
|
|
175
|
+
const issue = eventsFileIssue(baseline, current, maxBytes);
|
|
176
|
+
if (issue) return unapplied(issue);
|
|
177
|
+
|
|
178
|
+
const lines = text.split('\n');
|
|
179
|
+
lines.pop(); // The last entry is empty or an unfinished append.
|
|
180
|
+
let candidate = null, candidates = 0, invalidTimestamp = false;
|
|
181
|
+
for (const line of lines) {
|
|
182
|
+
let event;
|
|
183
|
+
try { event = JSON.parse(line); } catch { continue; }
|
|
184
|
+
if (event?.event_type !== 'ProfileApplied' || event.profile !== name || event.workspace !== worktreeRealpath) continue;
|
|
185
|
+
const timestamp = typeof event.timestamp === 'string' ? Date.parse(event.timestamp) : NaN;
|
|
186
|
+
if (Number.isNaN(timestamp)) {
|
|
187
|
+
invalidTimestamp = true;
|
|
188
|
+
candidates++;
|
|
189
|
+
} else if (timestamp >= spawnAtMs) {
|
|
190
|
+
candidate = event;
|
|
191
|
+
candidates++;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (invalidTimestamp) return unapplied('timestamp_invalid', candidates);
|
|
195
|
+
if (!candidates) return unapplied('no_candidate');
|
|
196
|
+
if (candidates > 1) return unapplied('multiple_candidates', candidates);
|
|
197
|
+
if (candidate.enforced !== true) return unapplied('not_enforced', candidates);
|
|
198
|
+
if (candidate.inherited === true) return unapplied('inherited', candidates);
|
|
199
|
+
const expectedDeny = path.join(worktreeRealpath, GROK_SANDBOX_RELATIVE);
|
|
200
|
+
if (!Array.isArray(candidate.deny_paths) || !candidate.deny_paths.includes(expectedDeny)) return unapplied('deny_missing', candidates);
|
|
201
|
+
const applied = {timestamp: candidate.timestamp, enforced: true, inherited: false, denyOk: true};
|
|
202
|
+
return {ok: true, reason: null, candidates, applied};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function readGrokProfileApplied({grokHome, baseline, spawnAtMs, name, worktreeRealpath}) {
|
|
206
|
+
const file = sandboxEventsPath(grokHome);
|
|
207
|
+
try {
|
|
208
|
+
const stat = fs.lstatSync(file, {throwIfNoEntry: false});
|
|
209
|
+
const current = stat ? {exists: true, regular: stat.isFile(), dev: stat.dev, ino: stat.ino, size: stat.size} : {exists: false};
|
|
210
|
+
const issue = eventsFileIssue(baseline, current, EVENTS_MAX_BYTES);
|
|
211
|
+
if (issue) return unapplied(issue);
|
|
212
|
+
|
|
213
|
+
const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW | fs.constants.O_NONBLOCK);
|
|
214
|
+
try {
|
|
215
|
+
const opened = fs.fstatSync(fd);
|
|
216
|
+
if (!sameEntry(opened, stat)) return unapplied('rotated');
|
|
217
|
+
if (!opened.isFile()) return unapplied('not_regular');
|
|
218
|
+
if (opened.size < stat.size) return unapplied('truncated');
|
|
219
|
+
|
|
220
|
+
const bytes = Buffer.alloc(stat.size - baseline.size);
|
|
221
|
+
let offset = 0;
|
|
222
|
+
while (offset < bytes.length) {
|
|
223
|
+
const read = fs.readSync(fd, bytes, offset, bytes.length - offset, baseline.size + offset);
|
|
224
|
+
if (read === 0) return unapplied('truncated');
|
|
225
|
+
offset += read;
|
|
226
|
+
}
|
|
227
|
+
return evaluateGrokProfileApplied({text: bytes.toString('utf8'), baseline, current, spawnAtMs, name, worktreeRealpath});
|
|
228
|
+
} finally {
|
|
229
|
+
fs.closeSync(fd);
|
|
230
|
+
}
|
|
231
|
+
} catch (error) {
|
|
232
|
+
return unapplied(error.code === 'ENOENT' || error.code === 'ELOOP' ? 'rotated' : 'not_regular');
|
|
233
|
+
}
|
|
234
|
+
}
|
|
@@ -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,28 @@
|
|
|
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.328, 2026-11-19, macOS Seatbelt: /private/tmp/claude-<uid> is writable, Bash exits 71 per command if sandboxing is unavailable, and M-C4 found no widening in trusted or untrusted workspaces.
|
|
18
|
+
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
+
sandbox: {
|
|
20
|
+
enabled: true,
|
|
21
|
+
autoAllowBashIfSandboxed: true,
|
|
22
|
+
allowUnsandboxedCommands: false,
|
|
23
|
+
failIfUnavailable: true,
|
|
24
|
+
},
|
|
25
|
+
});
|
|
6
26
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
7
27
|
export const CLAUDE_SANDBOX_SETTINGS = BRIDGE_GATE_RESULTS.G1 === 'pass' && isRecordedObject(RECORDED_CLAUDE_SANDBOX_SETTINGS) ? RECORDED_CLAUDE_SANDBOX_SETTINGS : null;
|
|
8
28
|
/** G1 counts as passed only with an explicitly recorded settings object; otherwise the settings are null. */
|
|
@@ -83,13 +103,18 @@ export function capabilityReasons({hostPlatform, targetPlatform, route, runtimeP
|
|
|
83
103
|
&& (route !== 'bridge' || target?.capabilities.bridge.state === 'verified') ? [] : ['capability_not_verified'];
|
|
84
104
|
}
|
|
85
105
|
|
|
106
|
+
export function hostGateReasons({hostPlatform, policy = DEFAULT_POLICY}) {
|
|
107
|
+
if (!Object.hasOwn(HOST_SANDBOX_GATES, hostPlatform)) return [];
|
|
108
|
+
const gates = policy.gates ?? BRIDGE_GATE_RESULTS;
|
|
109
|
+
return HOST_GATE_ALLOWED.includes(gates[HOST_SANDBOX_GATES[hostPlatform]]) ? [] : ['host_sandbox_blocked'];
|
|
110
|
+
}
|
|
111
|
+
|
|
86
112
|
export function bridgeGateReasons({platform, role, hostPlatform, policy = DEFAULT_POLICY}) {
|
|
87
113
|
const gates = policy.gates ?? BRIDGE_GATE_RESULTS, codes = [];
|
|
88
114
|
if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_qa') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
|
|
89
115
|
if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
|
|
90
116
|
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');
|
|
117
|
+
codes.push(...hostGateReasons({hostPlatform, policy}));
|
|
93
118
|
if (platform === 'codex' && gates.G4 === 'fail') codes.push('permission_scope_unverified');
|
|
94
119
|
if (hostPlatform === 'codex' && gates.G2 === 'fail') codes.push('host_sandbox_blocked');
|
|
95
120
|
return [...new Set(codes)];
|
|
@@ -7,7 +7,7 @@ import {COOPERATIVE_RUNTIME_MODULES, cooperativeVersions} from './bootstrap.mjs'
|
|
|
7
7
|
import {inspectPath} from './scope.mjs';
|
|
8
8
|
import {resolveConfigHome, resolveLocalCli, probePlatformAuth, probeCodexAuthStatus, probeCliVersion} from './local-cli.mjs';
|
|
9
9
|
import {ROUTING_ROLES, parseRoleRoutingConfig} from './role-routing-config.mjs';
|
|
10
|
-
import {DEFAULT_POLICY, reason, profileName, revisionTag, bridgeGateReasons, environmentReasons, initialClaims, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
10
|
+
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, revisionTag, hostGateReasons, bridgeGateReasons, environmentReasons, initialClaims, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
11
11
|
import {NON_TERMINAL_STATES, createLease, listLeases, pruneTerminalLeases, readHostLimits} from './role-dispatch-store.mjs';
|
|
12
12
|
|
|
13
13
|
const exact=(value,keys)=>value&&typeof value==='object'&&!Array.isArray(value)&&Object.keys(value).length===keys.length&&keys.every(key=>Object.hasOwn(value,key));
|
|
@@ -114,6 +114,27 @@ export async function readActivation(homes,expectedRevision,{anchorHome=homes.co
|
|
|
114
114
|
|
|
115
115
|
|
|
116
116
|
const HOST_ERRORS=['EACCES','EPERM','EROFS'];
|
|
117
|
+
export async function probeHomeWritable(home, {unlink = fs.unlink} = {}) {
|
|
118
|
+
const file = path.join(home, '.arc-host-probe-' + crypto.randomUUID());
|
|
119
|
+
let handle;
|
|
120
|
+
try {
|
|
121
|
+
handle = await fs.open(file, constants.O_WRONLY | constants.O_CREAT | constants.O_EXCL | constants.O_NOFOLLOW, 0o600);
|
|
122
|
+
} catch (error) {
|
|
123
|
+
return {ok: false, code: HOST_ERRORS.includes(error?.code) ? 'host_sandbox_blocked' : 'activation_unverified'};
|
|
124
|
+
}
|
|
125
|
+
let closed = false;
|
|
126
|
+
try {
|
|
127
|
+
await handle.close();
|
|
128
|
+
closed = true;
|
|
129
|
+
} catch { /* Attempt to remove the file even if close fails. */ }
|
|
130
|
+
try {
|
|
131
|
+
await unlink(file);
|
|
132
|
+
} catch {
|
|
133
|
+
return {ok: false, code: 'host_sandbox_blocked', residualPaths: [file]};
|
|
134
|
+
}
|
|
135
|
+
return closed ? {ok: true} : {ok: false, code: 'activation_unverified'};
|
|
136
|
+
}
|
|
137
|
+
|
|
117
138
|
const sleep=ms=>new Promise(resolve=>setTimeout(resolve,ms));
|
|
118
139
|
const lockFile=codexHome=>path.join(codexHome,'arc-role-platform-routing.lock');
|
|
119
140
|
/** Runs fn under the shared routing lock. Only EEXIST is retried; the lock file is never removed except by its owner. */
|
|
@@ -231,14 +252,20 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
231
252
|
const leases=await listLeases(anchorHome,{runtimePlatforms});
|
|
232
253
|
const live=leases.filter(lease=>NON_TERMINAL_STATES.includes(lease.state));
|
|
233
254
|
if(leases.some(lease=>lease.requestId===assignment.requestId)||live.some(lease=>lease.workflowId===context.workflowId&&lease.taskId===assignment.taskId&&lease.role===role)){duplicate=true;codes.add('duplicate_dispatch');}
|
|
234
|
-
|
|
235
|
-
if(host==='gemini'&&(policy.gates?.GG2??DEFAULT_POLICY.gates.GG2)!=='pass')codes.add('host_sandbox_blocked');
|
|
255
|
+
for(const code of hostGateReasons({hostPlatform:host,policy}))codes.add(code);
|
|
236
256
|
if(route==='bridge'){
|
|
237
257
|
let limits;try{limits=readHostLimits(resolveConfigHome(host,context));}catch{codes.add('activation_unverified');}
|
|
238
258
|
if(limits){
|
|
239
259
|
const bridges=leases.filter(lease=>lease.route==='bridge');
|
|
240
260
|
if(bridges.filter(lease=>NON_TERMINAL_STATES.includes(lease.state)).length>=limits.maxConcurrent||bridges.filter(lease=>lease.workflowId===context.workflowId).length>=limits.maxTotal)codes.add('capacity_exhausted');
|
|
241
261
|
}
|
|
262
|
+
if(Object.hasOwn(HOST_SANDBOX_GATES,host)){
|
|
263
|
+
const probe=await probeHomeWritable(homes[requested.platform]);
|
|
264
|
+
if(!probe.ok){
|
|
265
|
+
codes.add(probe.code);
|
|
266
|
+
if(probe.residualPaths)result.residualPaths=probe.residualPaths;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
242
269
|
for(const code of bridgeGateReasons({platform:requested.platform,role,hostPlatform:host,policy}))codes.add(code);
|
|
243
270
|
}
|
|
244
271
|
result.reasons=[...codes].map(reason);
|
|
@@ -254,7 +281,7 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
254
281
|
}else{
|
|
255
282
|
Object.assign(result,{decision:'hold',routeStatus:'held',dispatchId:null,claims:null,reasons:[reason(classify(error))]});
|
|
256
283
|
}
|
|
257
|
-
const residual=residualOf(error);if(residual)result.residualPaths=residual;
|
|
284
|
+
const residual=residualOf(error);if(residual)result.residualPaths=[...(result.residualPaths??[]),...residual];
|
|
258
285
|
}
|
|
259
286
|
return result;
|
|
260
287
|
}
|