@yunhozz/arc 0.5.2 → 0.5.4
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 +34 -30
- package/README.md +10 -1
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/references/coordination.md +6 -0
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/references/coordination.md +6 -0
- package/gemini/skill/SKILL.md +1 -1
- package/gemini/skill/references/coordination.md +6 -0
- package/grok/skill/SKILL.md +1 -1
- package/grok/skill/references/coordination.md +6 -0
- package/lib/installer/runtime-assets.mjs +2 -0
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/command.mjs +2 -2
- package/lib/runtime/host-service.mjs +155 -0
- package/lib/runtime/role-bridge-args.mjs +110 -8
- package/lib/runtime/role-bridge.mjs +47 -20
- package/lib/runtime/role-dispatch-policy.mjs +9 -1
- package/lib/runtime/role-dispatch-store.mjs +6 -2
- package/lib/runtime/role-observe.mjs +7 -2
- package/lib/runtime/role-routing.mjs +13 -1
- package/lib/runtime/role-supervisor.mjs +248 -9
- package/lib/runtime/tool-access.mjs +560 -0
- package/lib/watch/watcher.mjs +46 -25
- package/package.json +1 -1
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/command.mjs +2 -2
- package/shared/skill/runtime/host-service.mjs +155 -0
- package/shared/skill/runtime/role-bridge-args.mjs +110 -8
- package/shared/skill/runtime/role-bridge.mjs +47 -20
- package/shared/skill/runtime/role-dispatch-policy.mjs +9 -1
- package/shared/skill/runtime/role-dispatch-store.mjs +6 -2
- package/shared/skill/runtime/role-observe.mjs +7 -2
- package/shared/skill/runtime/role-routing.mjs +13 -1
- package/shared/skill/runtime/role-supervisor.mjs +248 -9
- package/shared/skill/runtime/tool-access.mjs +560 -0
|
@@ -3,13 +3,15 @@ import crypto from 'node:crypto';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {GROK_CONTRACT} from './grok-stream.mjs';
|
|
5
5
|
import {GEMINI_CONTRACT} from './gemini-stream.mjs';
|
|
6
|
-
import {DEFAULT_POLICY, effectiveClaudeSandboxSettings} from './role-dispatch-policy.mjs';
|
|
6
|
+
import {CODEX_PROFILE_ARGS_FORM, CODEX_PROFILE_GIT_ENTRIES, DEFAULT_POLICY, effectiveClaudeSandboxSettings} from './role-dispatch-policy.mjs';
|
|
7
|
+
import {TOOL_PATHS, TOOL_UNIX_SOCKETS} from './tool-access.mjs';
|
|
7
8
|
|
|
8
9
|
const ROLES = ['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer'];
|
|
9
10
|
const deepFreeze = value => { for (const child of Object.values(value)) if (child && typeof child === 'object') deepFreeze(child); return Object.freeze(value); };
|
|
10
11
|
export const ROLE_BRIDGE_PERMISSIONS = deepFreeze({
|
|
11
12
|
claude: {
|
|
12
|
-
arc_scouter: {permissionMode: 'default', sandbox: false
|
|
13
|
+
arc_scouter: {permissionMode: 'default', sandbox: false, allowedTools: ['WebFetch', 'WebSearch']},
|
|
14
|
+
arc_planner: {permissionMode: 'default', sandbox: false},
|
|
13
15
|
arc_implementer: {permissionMode: 'acceptEdits', sandbox: true}, arc_tester: {permissionMode: 'default', sandbox: true}, arc_reviewer: {permissionMode: 'default', sandbox: false}
|
|
14
16
|
},
|
|
15
17
|
gemini: {
|
|
@@ -183,28 +185,128 @@ const permissionsFor = (platform, role) => {
|
|
|
183
185
|
};
|
|
184
186
|
const requireText = (value, label) => { if (typeof value !== 'string' || value === '') throw Error(`Missing ${label}`); return value; };
|
|
185
187
|
|
|
186
|
-
|
|
188
|
+
function claudeSettingsFor(base, toolContext) {
|
|
189
|
+
if (toolContext === null) return {...base};
|
|
190
|
+
const {grants, scratch, forbidden, secretEnvNames} = toolContext;
|
|
191
|
+
const permissions = {...base.permissions};
|
|
192
|
+
const filesystem = {...base.sandbox.filesystem};
|
|
193
|
+
if (grants.network === 'domains') {
|
|
194
|
+
const reads = [...forbidden.readWhenExternal].sort((a, b) => a.path < b.path ? -1 : Number(a.path > b.path));
|
|
195
|
+
// Claude 2.1.327, 2026-11-24, MI-7
|
|
196
|
+
const readRules = reads.map(({path: name, kind}) => `Read(/${name}${kind === 'dir' ? '/**' : ''})`);
|
|
197
|
+
permissions.deny = [...permissions.deny, ...readRules];
|
|
198
|
+
// Claude 2.1.327, 2026-11-24, MI-9
|
|
199
|
+
filesystem.denyRead = reads.map(entry => entry.path);
|
|
200
|
+
}
|
|
201
|
+
if (grants.paths.length) filesystem.allowWrite = grants.paths.map(id => TOOL_PATHS[id]).sort();
|
|
202
|
+
const sandbox = {...base.sandbox, filesystem};
|
|
203
|
+
if (grants.network !== null) {
|
|
204
|
+
// Claude 2.1.327, 2026-11-24, MI-5
|
|
205
|
+
sandbox.network = {
|
|
206
|
+
allowedDomains: ['localhost', '127.0.0.1', ...[...grants.domains].sort()],
|
|
207
|
+
allowLocalBinding: true,
|
|
208
|
+
allowUnixSockets: [path.join(scratch, 'sock'), ...grants.unixSockets.map(id => TOOL_UNIX_SOCKETS[id]).sort()],
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
// Claude 2.1.327, 2026-11-24, MI-6
|
|
212
|
+
const values = new Map([...toolContext.env, ...secretEnvNames.map(name => [name, ''])]);
|
|
213
|
+
const env = Object.fromEntries([...values.keys()].sort().map(name => [name, values.get(name)]));
|
|
214
|
+
return {permissions, sandbox, env};
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export function buildClaudeArgs({role, profile, sessionId = null, policy = DEFAULT_POLICY, toolContext = null}) {
|
|
187
218
|
const permissions = permissionsFor('claude', role);
|
|
188
219
|
if (!Array.isArray(profile?.tools) || profile.tools.length === 0) throw Error('Claude profile tools are required');
|
|
189
220
|
const args = ['-p', '--safe-mode', '--output-format', 'stream-json', '--verbose', '--model', requireText(profile.model, 'model'), '--effort', requireText(profile.effort, 'effort'),
|
|
190
221
|
'--append-system-prompt', requireText(profile.instructions, 'instructions'), '--tools', profile.tools.join(','), '--permission-mode', permissions.permissionMode];
|
|
222
|
+
if (permissions.allowedTools) {
|
|
223
|
+
if (!permissions.allowedTools.every(tool => profile.tools.includes(tool))) throw Error('Claude allowedTools must be listed in profile tools');
|
|
224
|
+
args.push('--allowedTools', permissions.allowedTools.join(','));
|
|
225
|
+
}
|
|
191
226
|
if (permissions.sandbox) {
|
|
192
227
|
const settings = effectiveClaudeSandboxSettings(policy);
|
|
193
228
|
if (settings === null) throw Error('Claude sandbox settings are not available for this role');
|
|
194
|
-
args.push('--settings', JSON.stringify(settings));
|
|
229
|
+
args.push('--settings', JSON.stringify(claudeSettingsFor(settings, toolContext)));
|
|
195
230
|
}
|
|
196
231
|
if (policy?.gates?.G6 === 'strict') args.push('--strict-mcp-config');
|
|
197
232
|
if (sessionId !== null) args.push('--resume', requireText(sessionId, 'sessionId'));
|
|
198
233
|
return args;
|
|
199
234
|
}
|
|
200
235
|
|
|
201
|
-
|
|
236
|
+
const codexProtectionPaths = worktree => [path.join(worktree, '.git'), path.join(worktree, '.codex')];
|
|
237
|
+
|
|
238
|
+
export function assertCodexProtection(entries, worktree) {
|
|
239
|
+
if (!codexProtectionPaths(worktree).every((name, index) =>
|
|
240
|
+
entries[index]?.[0] === name && entries[index]?.[1] === 'read' && entries[index]?.length === 2)) {
|
|
241
|
+
throw Error('Codex profile protection entries missing');
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export function codexFilesystemEntries({worktree, gitDir, gitCommonDir, hostDir, grants, forbidden}, toolPaths = TOOL_PATHS) {
|
|
246
|
+
const protectedPaths = codexProtectionPaths(worktree);
|
|
247
|
+
if (CODEX_PROFILE_GIT_ENTRIES) protectedPaths.push(...[gitDir, gitCommonDir].filter(Boolean));
|
|
248
|
+
const entries = [...new Set(protectedPaths)].map(name => [name, 'read']);
|
|
249
|
+
if (hostDir) entries.push([hostDir, 'read']);
|
|
250
|
+
for (const name of grants.paths.map(id => toolPaths[id]).sort()) {
|
|
251
|
+
if (!path.isAbsolute(name)) throw Error('Absolute tool path required');
|
|
252
|
+
entries.push([name, 'write']);
|
|
253
|
+
}
|
|
254
|
+
if (grants.network === 'domains') {
|
|
255
|
+
for (const name of [...new Set(forbidden.readWhenExternal.map(entry => entry.path))].sort()) entries.push([name, 'none']);
|
|
256
|
+
}
|
|
257
|
+
return entries;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export function renderCodexTable(entries) {
|
|
261
|
+
return '{' + entries.map(([key, value]) => JSON.stringify(key) + '=' + JSON.stringify(value)).join(',') + '}';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function codexProfileSettings(toolContext, worktree, toolPaths) {
|
|
265
|
+
const {grants, scratch} = toolContext;
|
|
266
|
+
const entries = codexFilesystemEntries(toolContext, toolPaths);
|
|
267
|
+
assertCodexProtection(entries, worktree);
|
|
268
|
+
const profile = 'permissions.arc_bridge';
|
|
269
|
+
const settings = ['-c', `${profile}.extends=":workspace"`, '-c', `${profile}.filesystem=${renderCodexTable(entries)}`];
|
|
270
|
+
if (grants.network !== null) {
|
|
271
|
+
const domains = ['127.0.0.1', ...[...grants.domains].sort()].map(name => [name, 'allow']);
|
|
272
|
+
const sockets = [path.join(scratch, 'sock'), ...grants.unixSockets.map(id => TOOL_UNIX_SOCKETS[id]).sort()].map(name => [name, 'allow']);
|
|
273
|
+
settings.push('-c', `${profile}.network.enabled=true`,
|
|
274
|
+
'-c', `${profile}.network.domains=${renderCodexTable(domains)}`,
|
|
275
|
+
'-c', `${profile}.network.allow_local_binding=true`,
|
|
276
|
+
'-c', `${profile}.network.unix_sockets=${renderCodexTable(sockets)}`);
|
|
277
|
+
}
|
|
278
|
+
return settings;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export function buildCodexArgs({role, profile, worktree, resultPath, threadId = null, policy = DEFAULT_POLICY, toolContext = null},
|
|
282
|
+
{toolPaths = TOOL_PATHS} = {}) {
|
|
202
283
|
void policy;
|
|
203
284
|
const permissions = permissionsFor('codex', role);
|
|
204
285
|
if (typeof resultPath !== 'string' || !path.isAbsolute(resultPath)) throw Error('Absolute resultPath required');
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
286
|
+
const writerContext = permissions.sandboxMode === 'workspace-write' ? toolContext : null;
|
|
287
|
+
const profileMode = writerContext?.grants.mechanisms.includes('codexProfile');
|
|
288
|
+
const settings = [];
|
|
289
|
+
if (profileMode) {
|
|
290
|
+
if (CODEX_PROFILE_ARGS_FORM === 'B') {
|
|
291
|
+
settings.push('-c', 'default_permissions="arc_bridge"');
|
|
292
|
+
if (writerContext.grants.network !== null) settings.push('-c', 'features.network_proxy=true');
|
|
293
|
+
} else {
|
|
294
|
+
settings.push('-P', 'arc_bridge');
|
|
295
|
+
if (writerContext.grants.network !== null) settings.push('--enable', 'network_proxy');
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
settings.push('-m', requireText(profile?.model, 'model'), '-c', `model_reasoning_effort=${JSON.stringify(requireText(profile.effort, 'effort'))}`,
|
|
299
|
+
'-c', `developer_instructions=${JSON.stringify(requireText(profile.instructions, 'instructions'))}`);
|
|
300
|
+
if (profileMode) settings.push(...codexProfileSettings(writerContext, worktree, toolPaths));
|
|
301
|
+
else settings.push('-c', `sandbox_mode=${JSON.stringify(permissions.sandboxMode)}`);
|
|
302
|
+
settings.push('-c', 'approval_policy="never"');
|
|
303
|
+
for (const [key, value] of writerContext?.env ?? []) {
|
|
304
|
+
settings.push('-c', `shell_environment_policy.set.${key}=${JSON.stringify(value)}`);
|
|
305
|
+
}
|
|
306
|
+
if (profileMode && writerContext.grants.network === 'domains') {
|
|
307
|
+
settings.push('-c', `shell_environment_policy.exclude=${JSON.stringify(writerContext.forbidden.envWhenExternal)}`);
|
|
308
|
+
}
|
|
309
|
+
settings.push('-o', resultPath, '-');
|
|
208
310
|
if (threadId !== null) {
|
|
209
311
|
if (typeof threadId !== 'string' || !/^[A-Za-z0-9._-]+$/.test(threadId)) throw Error('Invalid threadId');
|
|
210
312
|
return [...(permissions.search ? ['--search'] : []), 'exec', 'resume', threadId, '--json', ...settings];
|
|
@@ -7,7 +7,7 @@ import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, bridgeGateReaso
|
|
|
7
7
|
import {displayRoutingRole} from './role-routing-config.mjs';
|
|
8
8
|
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
|
|
9
9
|
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
|
|
10
|
-
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation, reapRecordedDescendants} from './role-supervisor.mjs';
|
|
10
|
+
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation, reapRecordedDescendants, reapRecordedHostServices} from './role-supervisor.mjs';
|
|
11
11
|
|
|
12
12
|
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}]});
|
|
13
13
|
|
|
@@ -20,7 +20,7 @@ const environmentOf=(context,host)=>runtimeRegistryOf(context).getPlatform(host)
|
|
|
20
20
|
const validContext=context=>{const host=hostOf(context);return Boolean(host&&environmentOf(context,host)&&typeof context.workflowId==='string'&&context.workflowId&&typeof context.cwd==='string');};
|
|
21
21
|
const blank=(context,dispatchId,decision,code)=>({decision,routeStatus:'held',supportStatus:'unverified',dispatchId:typeof dispatchId==='string'&&ID.test(dispatchId)?dispatchId:null,route:null,profileName:null,executionEnvironment:context?.executionEnvironment??null,hostPlatform:context?.hostPlatform??null,role:null,requested:null,authentication:null,cliVersion:null,claims:null,reasons:[reason(code)]});
|
|
22
22
|
export function leaseTargetPlatform(lease,registry=DEFAULT_PLATFORM_REGISTRY){
|
|
23
|
-
if(lease.version
|
|
23
|
+
if(lease.version>=2)return lease.targetPlatform;
|
|
24
24
|
if(!v1Platforms.includes(lease.hostPlatform))throw Error('Invalid composite profile: unknown platform');
|
|
25
25
|
if(lease.route==='native')return lease.hostPlatform;
|
|
26
26
|
return v1Platforms.find(id=>id!==lease.hostPlatform);
|
|
@@ -40,7 +40,7 @@ const hold=(context,dispatchId,code,error)=>{const result=blank(context,dispatch
|
|
|
40
40
|
const classifyLock=error=>{const code=error?.code==='ARC_ROUTING_LOCK_RELEASE'&&error.failure?error.failure.code:error?.code;return code==='ARC_HOST_SANDBOX'?'host_sandbox_blocked':'activation_unverified';};
|
|
41
41
|
|
|
42
42
|
/** Starts the detached supervisor for a reserved bridge lease; the supervisor, not this function, spawns the child. */
|
|
43
|
-
export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now(),policy=DEFAULT_POLICY,startSupervisor:starter=startSupervisor}={}){
|
|
43
|
+
export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now(),policy=DEFAULT_POLICY,startSupervisor:starter=startSupervisor,observeToolContext}={}){
|
|
44
44
|
if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.')||typeof brief!=='string'){return blank(context,dispatchId,'deny','invalid_request');}
|
|
45
45
|
const bytes=Buffer.byteLength(brief,'utf8');
|
|
46
46
|
if(bytes<1||bytes>policy.briefMaxBytes)return blank(context,dispatchId,'deny','invalid_request');
|
|
@@ -60,7 +60,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
60
60
|
if(capabilities.length){result=blank(context,dispatchId,'hold',capabilities[0]);return;}
|
|
61
61
|
let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
62
62
|
const directory=artifactDirectory(target,lease.workflowId,dispatchId),resultPath=path.join(directory,'result.md');
|
|
63
|
-
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;}
|
|
63
|
+
let invocation;try{invocation=await buildBridgeInvocation({lease,config,homes,worktree:target.realpath,resultPath,userHome:context.userHome,env:context.env??process.env,target,runtimePlatforms,policy,observeToolContext});}catch(error){result=blank(context,dispatchId,'hold',error.reasonCode??'activation_unverified');return;}
|
|
64
64
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(directory,0o700);
|
|
65
65
|
await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
|
|
66
66
|
if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
|
|
@@ -82,18 +82,37 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
const TEXT=/^[^\p{Cc}]{1,256}$/u;
|
|
85
|
-
async function
|
|
86
|
-
if(!
|
|
85
|
+
async function recoverLostHostServices(anchorHome,cwd,lease,graceMs){
|
|
86
|
+
if(!lease.toolAccess?.services.length)return {};
|
|
87
|
+
let hostServiceRecovery='warning';
|
|
88
|
+
try{
|
|
89
|
+
const target=await resolveWorktree(cwd);
|
|
90
|
+
const directory=segmentDirectory(target,lease.workflowId,lease.dispatchId,lease.segment??0);
|
|
91
|
+
if(path.join(directory,'result.md')===lease.resultPath){
|
|
92
|
+
hostServiceRecovery=await reapRecordedHostServices(directory,lease,{anchorHome,graceMs});
|
|
93
|
+
}
|
|
94
|
+
}catch{/* A mismatched or unavailable artifact cannot authorize recovery. */}
|
|
95
|
+
return {hostServiceRecovery};
|
|
96
|
+
}
|
|
97
|
+
async function markLostIfDue(anchorHome,lease,{cwd,now,lostMs,policy,runtimePlatforms}){
|
|
98
|
+
if(!['starting','running'].includes(lease.state)||!lease.supervisor)return {lease};
|
|
87
99
|
const heartbeat=await readHeartbeat(anchorHome,lease.dispatchId);
|
|
88
100
|
const lastSeen=Math.max(heartbeat?.at??0,Date.parse(lease.updatedAt)||0);
|
|
89
|
-
if(now-lastSeen<=lostMs||processAlive(lease.supervisor))return lease;
|
|
101
|
+
if(now-lastSeen<=lostMs||processAlive(lease.supervisor))return {lease};
|
|
102
|
+
let lost=false,next;
|
|
90
103
|
try{
|
|
91
|
-
|
|
104
|
+
next=await withRoutingLock(anchorHome,async()=>{
|
|
92
105
|
const current=await readLease(anchorHome,lease.dispatchId,{runtimePlatforms});
|
|
93
|
-
if(!current||!['starting','running'].includes(current.state)
|
|
94
|
-
|
|
106
|
+
if(!current||!['starting','running'].includes(current.state)||current.segment!==lease.segment
|
|
107
|
+
||current.supervisor?.pid!==lease.supervisor.pid||current.supervisor?.startTime!==lease.supervisor.startTime)return current??lease;
|
|
108
|
+
const updated=await writeLease(anchorHome,{...current,state:'unknown',claims:{...(current.claims??{}),terminal:{level:'unverified',source:'none'}},reasons:[reason('terminal_state_unverified')]},{now,runtimePlatforms});
|
|
109
|
+
lost=true;return updated;
|
|
95
110
|
},{retryMs:policy.lockRetryMs});
|
|
96
|
-
}catch{
|
|
111
|
+
}catch(error){
|
|
112
|
+
if(error?.code==='ARC_ROUTING_LOCK_RELEASE'&&!error.failure&&lost)next=error.value;
|
|
113
|
+
else return {lease};// a busy lock only delays the transition; the next observe retries it
|
|
114
|
+
}
|
|
115
|
+
return {lease:next,...(lost?await recoverLostHostServices(anchorHome,cwd,next,policy.cancelGraceMs):{})};
|
|
97
116
|
}
|
|
98
117
|
async function recordNativeEvent({context,anchorHome,dispatchId,event,nativeAgentId,now,policy,runtimePlatforms}){
|
|
99
118
|
const view=(lease,decision)=>fromLease(lease,decision,runtimePlatforms);
|
|
@@ -131,8 +150,12 @@ export async function recordRoleObservation({context,dispatchId,waitMs,event,nat
|
|
|
131
150
|
const end=Date.now()+(waitMs??0),lost=lostMs??policy.supervisorLostMs;
|
|
132
151
|
try{
|
|
133
152
|
for(;;){
|
|
134
|
-
|
|
135
|
-
|
|
153
|
+
const observed=await markLostIfDue(anchorHome,lease,{cwd:context.cwd,now:now??Date.now(),lostMs:lost,policy,runtimePlatforms});
|
|
154
|
+
lease=observed.lease;
|
|
155
|
+
if(TERMINAL_STATES.includes(lease.state)||lease.state==='unknown'||Date.now()>=end){
|
|
156
|
+
const {hostServiceRecovery}=observed;
|
|
157
|
+
return {...view(lease),...(hostServiceRecovery?{hostServiceRecovery}:{})};
|
|
158
|
+
}
|
|
136
159
|
await sleep(Math.min(pollMs,Math.max(0,end-Date.now())));
|
|
137
160
|
lease=await readLease(anchorHome,dispatchId,{runtimePlatforms})??lease;
|
|
138
161
|
}
|
|
@@ -140,7 +163,7 @@ export async function recordRoleObservation({context,dispatchId,waitMs,event,nat
|
|
|
140
163
|
}
|
|
141
164
|
|
|
142
165
|
/** Continues a completed or failed bridge dispatch in its recorded session. The input carries no session id; only the lease value is used. */
|
|
143
|
-
export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(),policy=DEFAULT_POLICY,startSupervisor:starter=startSupervisor,supervisorImplementations=SUPERVISOR_IMPLEMENTATIONS}={}){
|
|
166
|
+
export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(),policy=DEFAULT_POLICY,startSupervisor:starter=startSupervisor,supervisorImplementations=SUPERVISOR_IMPLEMENTATIONS,observeToolContext}={}){
|
|
144
167
|
if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.')||typeof brief!=='string'){return blank(context,dispatchId,'deny','invalid_request');}
|
|
145
168
|
const bytes=Buffer.byteLength(brief,'utf8');
|
|
146
169
|
if(bytes<1||bytes>policy.briefMaxBytes)return blank(context,dispatchId,'deny','invalid_request');
|
|
@@ -174,7 +197,7 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
174
197
|
if(codes.size){result=blank(context,dispatchId,'hold','activation_unverified');result.reasons=[...codes].map(reason);return;}
|
|
175
198
|
let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
176
199
|
const segment=lease.segment+1,directory=segmentDirectory(target,lease.workflowId,dispatchId,segment),resultPath=path.join(directory,'result.md');
|
|
177
|
-
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;}
|
|
200
|
+
let invocation;try{invocation=await buildBridgeInvocation({lease:{...lease,segment},config,homes,worktree:target.realpath,resultPath,userHome:context.userHome,env:context.env??process.env,target,runtimePlatforms,policy,supervisorImplementations,observeToolContext});}catch(error){result=blank(context,dispatchId,'hold',error.reasonCode??'activation_unverified');return;}
|
|
178
201
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(path.dirname(directory),0o700);await fsp.chmod(directory,0o700);
|
|
179
202
|
await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
|
|
180
203
|
if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
|
|
@@ -205,7 +228,7 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
205
228
|
if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.'))return blank(context,dispatchId,'deny','invalid_request');
|
|
206
229
|
const homes=resolveRuntimeHomes(context),runtimePlatforms=runtimeRegistryOf(context);
|
|
207
230
|
const view=(lease,decision)=>fromLease(lease,decision,runtimePlatforms);
|
|
208
|
-
let anchorHome,result,direct=null,residual;
|
|
231
|
+
let anchorHome,result,direct=null,lostLease,residual;
|
|
209
232
|
try{anchorHome=await locateAnchorHome({host:context.hostPlatform,homes});}catch{return blank(context,dispatchId,'hold','activation_unverified');}
|
|
210
233
|
const graceMs=policy.cancelGraceMs;
|
|
211
234
|
try{
|
|
@@ -221,12 +244,14 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
221
244
|
}
|
|
222
245
|
if(TERMINAL_STATES.includes(lease.state)){result=view(lease,'allow');return;}
|
|
223
246
|
if(lease.state==='reserved'){result=view(await writeLease(anchorHome,{...lease,state:'cancelled',reasons:[]},{now,runtimePlatforms}),'allow');return;}
|
|
224
|
-
const
|
|
247
|
+
const supervisorAlive=lease.supervisor&&processAlive(lease.supervisor);
|
|
248
|
+
const supervised=['starting','running'].includes(lease.state)&&supervisorAlive;
|
|
225
249
|
if(supervised){
|
|
226
250
|
await requestCancel(anchorHome,dispatchId);
|
|
227
251
|
if(lease.child&&processAlive(lease.child))signalGroup(lease.child.pid,'SIGTERM');
|
|
228
252
|
result={...view(lease,'allow'),routeStatus:'cancelling'};return;
|
|
229
253
|
}
|
|
254
|
+
if(!supervisorAlive&&lease.toolAccess?.services.length)lostLease=lease;
|
|
230
255
|
if(lease.child&&processAlive(lease.child)){signalGroup(lease.child.pid,'SIGTERM');direct={lease,identified:true};}
|
|
231
256
|
else if(lease.child&&!groupExists(lease.child.pid)&&!pidExists(lease.child.pid))direct={lease,identified:false};
|
|
232
257
|
else result=view(lease,'hold');
|
|
@@ -241,14 +266,15 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
241
266
|
if(!killed&&Date.now()>=begin+graceMs){signalGroup(pid,'SIGKILL');killed=true;}
|
|
242
267
|
await sleep(25);gone=!groupExists(pid);
|
|
243
268
|
}
|
|
244
|
-
let
|
|
269
|
+
let cleanup={};
|
|
245
270
|
if(!direct.lease.supervisor||!processAlive(direct.lease.supervisor)){
|
|
246
271
|
try{
|
|
247
272
|
const target=await resolveWorktree(context.cwd);
|
|
248
273
|
const directory=segmentDirectory(target,direct.lease.workflowId,dispatchId,direct.lease.segment??0);
|
|
249
|
-
|
|
274
|
+
cleanup=await reapRecordedDescendants(directory,direct.lease,{graceMs});
|
|
250
275
|
}catch{/* A missing worktree does not change the group cancellation result. */}
|
|
251
276
|
}
|
|
277
|
+
if(lostLease){Object.assign(cleanup,await recoverLostHostServices(anchorHome,context.cwd,lostLease,graceMs));lostLease=null;}
|
|
252
278
|
if(!gone)result=view(direct.lease,'hold');
|
|
253
279
|
else{
|
|
254
280
|
try{
|
|
@@ -264,8 +290,9 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
264
290
|
else return hold(context,dispatchId,classifyLock(error),error);
|
|
265
291
|
}
|
|
266
292
|
}
|
|
267
|
-
if(result
|
|
293
|
+
if(result)Object.assign(result,cleanup);
|
|
268
294
|
}
|
|
295
|
+
if(lostLease)Object.assign(result,await recoverLostHostServices(anchorHome,context.cwd,lostLease,graceMs));
|
|
269
296
|
if(residual)result.residualPaths=residual;
|
|
270
297
|
return result;
|
|
271
298
|
}
|
|
@@ -7,6 +7,13 @@ export const BRIDGE_GATE_RESULTS = Object.freeze({G1: 'pass', G2: 'escalation',
|
|
|
7
7
|
export const HOST_SANDBOX_GATES = Object.freeze({grok: 'GK2', gemini: 'GG2'});
|
|
8
8
|
export const HOST_GATE_ALLOWED = Object.freeze(['pass', 'approval']);
|
|
9
9
|
|
|
10
|
+
// Codex 0.170.0, 2026-11-24, MI-1
|
|
11
|
+
export const CODEX_PROFILE_ARGS_FORM = 'B';
|
|
12
|
+
// Codex 0.170.0, 2026-11-24, MI-1
|
|
13
|
+
export const CODEX_PROFILE_SANDBOX_TYPE = 'workspace-write';
|
|
14
|
+
// Codex 0.170.0, 2026-11-24, MI-3
|
|
15
|
+
export const CODEX_PROFILE_GIT_ENTRIES = false;
|
|
16
|
+
|
|
10
17
|
function deepFreeze(value) {
|
|
11
18
|
for (const nested of Object.values(value)) {
|
|
12
19
|
if (nested !== null && typeof nested === 'object') deepFreeze(nested);
|
|
@@ -15,8 +22,9 @@ function deepFreeze(value) {
|
|
|
15
22
|
}
|
|
16
23
|
|
|
17
24
|
// Claude 2.1.327, 2026-11-20, T0 M-C10/M-C11/M-C12/FINAL
|
|
25
|
+
// Claude 2.1.327, 2026-11-24, T0 부수 발견(Write 규칙 무효 경고) + MI-4
|
|
18
26
|
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
-
permissions: {deny: ['Edit(./.git/**)'
|
|
27
|
+
permissions: {deny: ['Edit(./.git/**)']},
|
|
20
28
|
sandbox: {
|
|
21
29
|
enabled: true,
|
|
22
30
|
autoAllowBashIfSandboxed: true,
|
|
@@ -3,8 +3,10 @@ import fs from 'node:fs';
|
|
|
3
3
|
import fsp from 'node:fs/promises';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import crypto from 'node:crypto';
|
|
6
|
+
import {isDeepStrictEqual} from 'node:util';
|
|
6
7
|
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
7
8
|
import {displayRoutingRole} from './role-routing-config.mjs';
|
|
9
|
+
import {validateToolAccess} from './tool-access.mjs';
|
|
8
10
|
|
|
9
11
|
export const NON_TERMINAL_STATES = Object.freeze(['reserved', 'starting', 'running', 'unknown']);
|
|
10
12
|
export const TERMINAL_STATES = Object.freeze(['completed', 'failed', 'cancelled']);
|
|
@@ -21,15 +23,17 @@ const leasePath = (codexHome, dispatchId) => {
|
|
|
21
23
|
return path.join(dispatchDirectory(codexHome), `${dispatchId}.json`);
|
|
22
24
|
};
|
|
23
25
|
export function validateLease(value, options) {
|
|
24
|
-
const keys = value?.version === 2 ? [...KEYS, 'targetPlatform'] : KEYS;
|
|
26
|
+
const keys = value?.version === 3 ? [...KEYS, 'targetPlatform', 'toolAccess'] : value?.version === 2 ? [...KEYS, 'targetPlatform'] : KEYS;
|
|
25
27
|
if (!isObject(value) || Object.keys(value).length !== keys.length || keys.some(key => !Object.hasOwn(value, key))) throw Error('Invalid lease keys');
|
|
26
28
|
const registry = options?.registry ?? runtimeRegistryOf(options);
|
|
27
|
-
const
|
|
29
|
+
const normalized = value.version === 3 ? validateToolAccess(value.role, value.toolAccess) : null;
|
|
30
|
+
const ok = [1, 2, 3].includes(value.version) && typeof value.dispatchId === 'string' && ID.test(value.dispatchId) && !value.dispatchId.startsWith('.')
|
|
28
31
|
&& ['workflowId', 'taskId', 'requestId', 'role', 'executionEnvironment', 'revision', 'createdAt', 'updatedAt'].every(key => text(value[key]))
|
|
29
32
|
&& ['native', 'bridge'].includes(value.route) && registry.isPlatformId(value.hostPlatform)
|
|
30
33
|
&& (value.version === 1 || registry.isPlatformId(value.targetPlatform)
|
|
31
34
|
&& (value.route === 'native' ? value.targetPlatform === value.hostPlatform : value.targetPlatform !== value.hostPlatform)
|
|
32
35
|
&& (!options?.config || Object.values(options.config.roles).some(role => role.platform === value.targetPlatform)))
|
|
36
|
+
&& (value.version !== 3 || normalized !== null && isDeepStrictEqual(normalized, value.toolAccess))
|
|
33
37
|
&& nullableText(value.profileHash) && nullableText(value.argsDigest) && nullableText(value.sessionId) && nullableText(value.resultPath) && nullableText(value.nativeAgentId)
|
|
34
38
|
&& [...NON_TERMINAL_STATES, ...TERMINAL_STATES].includes(value.state) && process_(value.supervisor) && process_(value.child)
|
|
35
39
|
&& Number.isInteger(value.timeoutMinutes) && value.timeoutMinutes > 0 && Number.isInteger(value.segment) && value.segment >= 0
|
|
@@ -190,9 +190,12 @@ export async function readCodexTurnContext({codexHome, threadId, delegationNames
|
|
|
190
190
|
|
|
191
191
|
export function evaluateCodexContext({context, expected, policy = DEFAULT_POLICY}) {
|
|
192
192
|
const gates = policy.gates ?? DEFAULT_POLICY.gates;
|
|
193
|
+
const sandboxUnrecorded = expected.sandboxMode === null;
|
|
194
|
+
const sandboxNote = 'codex-profile-sandbox-type-unrecorded';
|
|
193
195
|
if (!isObject(context)) {
|
|
194
196
|
const none = {level: 'unverified', source: 'none'};
|
|
195
|
-
return {reason: null, claims: {model: {...none, requested: expected.model}, effort: {...none, requested: expected.effort},
|
|
197
|
+
return {reason: null, claims: {model: {...none, requested: expected.model}, effort: {...none, requested: expected.effort},
|
|
198
|
+
permissions: {...none, details: sandboxUnrecorded ? sandboxNote : null}}};
|
|
196
199
|
}
|
|
197
200
|
const turns = Array.isArray(context.turns) && context.turns.length ? context.turns : [context];
|
|
198
201
|
const present = value => value !== undefined && value !== null && value !== '';
|
|
@@ -202,11 +205,13 @@ export function evaluateCodexContext({context, expected, policy = DEFAULT_POLICY
|
|
|
202
205
|
return turns.every(item => present(item[field])) ? 'ok' : 'missing';
|
|
203
206
|
};
|
|
204
207
|
const model = judge('model', value => matchModel(expected.model, value)), effort = judge('effort', value => value === expected.effort);
|
|
205
|
-
const sandbox =
|
|
208
|
+
const sandbox = sandboxUnrecorded ? 'missing' : judge('sandboxMode', value => value === expected.sandboxMode);
|
|
209
|
+
const approval = judge('approvalPolicy', value => value === expected.approvalPolicy);
|
|
206
210
|
const settings = sandbox === 'mismatch' || approval === 'mismatch' ? 'mismatch' : sandbox === 'ok' && approval === 'ok' ? 'ok' : 'missing';
|
|
207
211
|
const delegationDetectable = gates.G3 === 'pass', delegated = delegationDetectable && context.delegationObserved === true;
|
|
208
212
|
// The child loads the user's Codex config (MCP servers and so on), which ARC does not control: the claim never exceeds operator-attested.
|
|
209
213
|
const notes = ['user-config-mcp-not-controlled'];
|
|
214
|
+
if (sandboxUnrecorded) notes.push(sandboxNote);
|
|
210
215
|
if (gates.G5 === 'wide') notes.push('writable-root-wider-than-worktree');
|
|
211
216
|
if (!delegationDetectable) notes.push('delegation-not-detectable');
|
|
212
217
|
if (settings === 'mismatch') notes.push('sandbox or approval policy differs from the requested values');
|
|
@@ -10,6 +10,7 @@ import {LEGACY_ROUTING_ROLES, ROUTING_ROLES, parseRoleRoutingConfig} from './rol
|
|
|
10
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
|
import {allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
13
|
+
import {effectiveGrants, toolAccessPreflight, toolAccessReasons, validateToolAccess} from './tool-access.mjs';
|
|
13
14
|
|
|
14
15
|
const exact=(value,keys)=>value&&typeof value==='object'&&!Array.isArray(value)&&Object.keys(value).length===keys.length&&keys.every(key=>Object.hasOwn(value,key));
|
|
15
16
|
const hash=bytes=>'sha256:'+crypto.createHash('sha256').update(bytes).digest('hex');
|
|
@@ -169,6 +170,7 @@ const environmentOf=(context,host)=>runtimeRegistryOf(context).getPlatform(host)
|
|
|
169
170
|
function validateAssignment(assignment,expectedRevision,context){
|
|
170
171
|
const role=assignment?.role;
|
|
171
172
|
if(!ROUTING_ROLES.includes(role)||!textValue(assignment.requestId)||!textValue(assignment.taskId)||!textValue(expectedRevision)||!textValue(context?.workflowId))return false;
|
|
173
|
+
if(assignment.toolAccess!==undefined&&validateToolAccess(role,assignment.toolAccess)===null)return false;
|
|
172
174
|
const paths=assignment.allowedPaths;
|
|
173
175
|
if(role==='arc_implementer')return Array.isArray(paths)&&paths.length>0&&paths.every(validRelativePath);
|
|
174
176
|
if(paths===undefined)return true;
|
|
@@ -242,6 +244,16 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
242
244
|
const requested=config.roles[role],route=requested.platform===host?'native':'bridge';
|
|
243
245
|
result.requested={...requested};result.route=route;result.profileName=profileName(requested.platform,role,{runtimePlatforms});
|
|
244
246
|
if(route==='bridge'&&allowedPathsCoverControl(assignment.allowedPaths??[])){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
247
|
+
const toolAccess=assignment.toolAccess===undefined?undefined:validateToolAccess(role,assignment.toolAccess);
|
|
248
|
+
if(toolAccess!==undefined){
|
|
249
|
+
const platform=requested.platform;
|
|
250
|
+
const {reasons,conditions}=toolAccessReasons({platform,role,route,toolAccess,policy});
|
|
251
|
+
if(reasons.length){result.reasons=reasons.map(reason);return;}
|
|
252
|
+
const grants=effectiveGrants(platform,role,toolAccess);
|
|
253
|
+
const preflightReasons=await toolAccessPreflight({platform,role,grants,worktree:context.cwd,userHome:context.userHome,homes,env:context.env,io:fs});
|
|
254
|
+
if(preflightReasons.length){result.reasons=preflightReasons.map(reason);return;}
|
|
255
|
+
result.toolAccess={conditions};
|
|
256
|
+
}
|
|
245
257
|
if(route==='bridge'&&requested.platform==='claude'&&(role==='arc_implementer'||role==='arc_tester')){
|
|
246
258
|
const target=typeof context.cwd==='string'?await resolveWorktree(context.cwd).catch(()=>null):null;
|
|
247
259
|
if(!target||await claudeProjectSettingsWidenScope(target.realpath)){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
@@ -278,7 +290,7 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
278
290
|
result.reasons=[...codes].map(reason);
|
|
279
291
|
if(codes.size){result.decision=duplicate?'deny':'hold';return;}
|
|
280
292
|
const claims=initialClaims(route,policy,requested),iso=new Date(now).toISOString(),dispatchId=crypto.randomUUID();
|
|
281
|
-
const lease=await createLease(anchorHome,{version:2,targetPlatform:route==='native'?host:requested.platform,dispatchId,workflowId:context.workflowId,taskId:assignment.taskId,requestId:assignment.requestId,role,route,hostPlatform:host,executionEnvironment:environment,revision:config.revision,profileHash:await readProfileHash(homes[requested.platform],role),argsDigest:null,state:'reserved',supervisor:null,child:null,sessionId:route==='bridge'&&(requested.platform==='gemini'||requested.platform==='grok')?crypto.randomUUID():null,timeoutMinutes:policy.roleTimeoutMinutes[role],claims,reasons:[],allowedPaths:assignment.allowedPaths??[],resultPath:null,segment:0,nativeAgentId:null,createdAt:iso,updatedAt:iso},{runtimePlatforms,config});
|
|
293
|
+
const lease=await createLease(anchorHome,{version:toolAccess===undefined?2:3,targetPlatform:route==='native'?host:requested.platform,dispatchId,workflowId:context.workflowId,taskId:assignment.taskId,requestId:assignment.requestId,role,route,hostPlatform:host,executionEnvironment:environment,revision:config.revision,profileHash:await readProfileHash(homes[requested.platform],role),argsDigest:null,state:'reserved',supervisor:null,child:null,sessionId:route==='bridge'&&(requested.platform==='gemini'||requested.platform==='grok')?crypto.randomUUID():null,timeoutMinutes:policy.roleTimeoutMinutes[role],claims,reasons:[],allowedPaths:assignment.allowedPaths??[],resultPath:null,segment:0,nativeAgentId:null,createdAt:iso,updatedAt:iso,...(toolAccess===undefined?{}:{toolAccess})},{runtimePlatforms,config});
|
|
282
294
|
Object.assign(result,{decision:'allow',routeStatus:'reserved',dispatchId:lease.dispatchId,claims});
|
|
283
295
|
},{retryMs:policy.lockRetryMs});
|
|
284
296
|
}catch(error){
|