@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.
Files changed (35) hide show
  1. package/MANIFEST.sha256 +34 -30
  2. package/README.md +10 -1
  3. package/claude/skill/SKILL.md +1 -1
  4. package/claude/skill/references/coordination.md +6 -0
  5. package/codex/skill/SKILL.md +1 -1
  6. package/codex/skill/references/coordination.md +6 -0
  7. package/gemini/skill/SKILL.md +1 -1
  8. package/gemini/skill/references/coordination.md +6 -0
  9. package/grok/skill/SKILL.md +1 -1
  10. package/grok/skill/references/coordination.md +6 -0
  11. package/lib/installer/runtime-assets.mjs +2 -0
  12. package/lib/runtime/bootstrap.mjs +1 -1
  13. package/lib/runtime/command.mjs +2 -2
  14. package/lib/runtime/host-service.mjs +155 -0
  15. package/lib/runtime/role-bridge-args.mjs +110 -8
  16. package/lib/runtime/role-bridge.mjs +47 -20
  17. package/lib/runtime/role-dispatch-policy.mjs +9 -1
  18. package/lib/runtime/role-dispatch-store.mjs +6 -2
  19. package/lib/runtime/role-observe.mjs +7 -2
  20. package/lib/runtime/role-routing.mjs +13 -1
  21. package/lib/runtime/role-supervisor.mjs +248 -9
  22. package/lib/runtime/tool-access.mjs +560 -0
  23. package/lib/watch/watcher.mjs +46 -25
  24. package/package.json +1 -1
  25. package/shared/skill/runtime/bootstrap.mjs +1 -1
  26. package/shared/skill/runtime/command.mjs +2 -2
  27. package/shared/skill/runtime/host-service.mjs +155 -0
  28. package/shared/skill/runtime/role-bridge-args.mjs +110 -8
  29. package/shared/skill/runtime/role-bridge.mjs +47 -20
  30. package/shared/skill/runtime/role-dispatch-policy.mjs +9 -1
  31. package/shared/skill/runtime/role-dispatch-store.mjs +6 -2
  32. package/shared/skill/runtime/role-observe.mjs +7 -2
  33. package/shared/skill/runtime/role-routing.mjs +13 -1
  34. package/shared/skill/runtime/role-supervisor.mjs +248 -9
  35. package/shared/skill/runtime/tool-access.mjs +560 -0
@@ -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===2)return lease.targetPlatform;
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 markLostIfDue(anchorHome,lease,{now,lostMs,policy,runtimePlatforms}){
86
- if(!['starting','running'].includes(lease.state)||!lease.supervisor)return lease;
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
- return await withRoutingLock(anchorHome,async()=>{
104
+ next=await withRoutingLock(anchorHome,async()=>{
92
105
  const current=await readLease(anchorHome,lease.dispatchId,{runtimePlatforms});
93
- if(!current||!['starting','running'].includes(current.state))return current??lease;
94
- return writeLease(anchorHome,{...current,state:'unknown',claims:{...(current.claims??{}),terminal:{level:'unverified',source:'none'}},reasons:[reason('terminal_state_unverified')]},{now,runtimePlatforms});
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{return lease;}// a busy lock only delays the transition; the next observe retries it
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
- lease=await markLostIfDue(anchorHome,lease,{now:now??Date.now(),lostMs:lost,policy,runtimePlatforms});
135
- if(TERMINAL_STATES.includes(lease.state)||lease.state==='unknown'||Date.now()>=end)return view(lease);
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 supervised=['starting','running'].includes(lease.state)&&lease.supervisor&&processAlive(lease.supervisor);
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 escapes={};
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
- escapes=await reapRecordedDescendants(directory,direct.lease,{graceMs});
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&&escapes.escapedDescendants)result={...result,...escapes};
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/**)', 'Write(./.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 ok = [1, 2].includes(value.version) && typeof value.dispatchId === 'string' && ID.test(value.dispatchId) && !value.dispatchId.startsWith('.')
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}, permissions: {...none, details: null}}};
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 = judge('sandboxMode', value => value === expected.sandboxMode), approval = judge('approvalPolicy', value => value === expected.approvalPolicy);
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){