@yunhozz/arc 0.5.1 → 0.5.3

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 (151) hide show
  1. package/MANIFEST.sha256 +146 -139
  2. package/README.md +12 -3
  3. package/claude/agents/arc-implementer.md +7 -7
  4. package/claude/agents/arc-planner.md +5 -5
  5. package/claude/agents/arc-reviewer.md +6 -6
  6. package/claude/agents/arc-scouter.md +5 -5
  7. package/claude/agents/{arc-qa.md → arc-tester.md} +10 -10
  8. package/claude/skill/SKILL.md +6 -6
  9. package/claude/skill/models.toml +2 -2
  10. package/claude/skill/references/arc-visual-companion.md +2 -2
  11. package/claude/skill/references/commit.md +3 -3
  12. package/claude/skill/references/coordination.md +27 -21
  13. package/claude/skill/references/git-recovery.md +3 -1
  14. package/claude/skill/references/handoff-prep.md +3 -3
  15. package/claude/skill/references/handoff.md +16 -14
  16. package/claude/skill/references/limits.md +2 -2
  17. package/claude/skill/references/planning.md +12 -10
  18. package/claude/skill/references/verification.md +67 -35
  19. package/claude/skill/references/worktree-creation.md +2 -0
  20. package/claude/skill/scripts/model_config.py +25 -9
  21. package/codex/agents/arc-implementer.toml +7 -7
  22. package/codex/agents/arc-planner.toml +6 -6
  23. package/codex/agents/arc-reviewer.toml +7 -7
  24. package/codex/agents/arc-scouter.toml +6 -6
  25. package/codex/agents/{arc-qa.toml → arc-tester.toml} +10 -10
  26. package/codex/skill/SKILL.md +7 -7
  27. package/codex/skill/models.toml +2 -2
  28. package/codex/skill/references/arc-visual-companion.md +3 -3
  29. package/codex/skill/references/commit.md +4 -4
  30. package/codex/skill/references/coordination.md +26 -20
  31. package/codex/skill/references/git-recovery.md +2 -0
  32. package/codex/skill/references/handoff-prep.md +4 -4
  33. package/codex/skill/references/handoff.md +17 -15
  34. package/codex/skill/references/limits.md +2 -2
  35. package/codex/skill/references/planning.md +13 -11
  36. package/codex/skill/references/verification.md +68 -36
  37. package/codex/skill/references/worktree-creation.md +2 -0
  38. package/codex/skill/scripts/model_config.py +28 -15
  39. package/gemini/agents/arc-implementer.md +7 -7
  40. package/gemini/agents/arc-planner.md +5 -5
  41. package/gemini/agents/arc-reviewer.md +6 -6
  42. package/gemini/agents/arc-scouter.md +5 -5
  43. package/gemini/agents/{arc-qa.md → arc-tester.md} +10 -10
  44. package/gemini/skill/SKILL.md +6 -6
  45. package/gemini/skill/models.toml +2 -2
  46. package/gemini/skill/references/arc-visual-companion.md +2 -2
  47. package/gemini/skill/references/commit.md +3 -3
  48. package/gemini/skill/references/coordination.md +27 -21
  49. package/gemini/skill/references/git-recovery.md +3 -1
  50. package/gemini/skill/references/handoff-prep.md +3 -3
  51. package/gemini/skill/references/handoff.md +16 -14
  52. package/gemini/skill/references/limits.md +2 -2
  53. package/gemini/skill/references/planning.md +12 -10
  54. package/gemini/skill/references/verification.md +67 -35
  55. package/gemini/skill/references/worktree-creation.md +2 -0
  56. package/grok/agents/arc-implementer.md +7 -7
  57. package/grok/agents/arc-planner.md +5 -5
  58. package/grok/agents/arc-reviewer.md +6 -6
  59. package/grok/agents/arc-scouter.md +5 -5
  60. package/grok/agents/{arc-qa.md → arc-tester.md} +10 -10
  61. package/grok/skill/SKILL.md +6 -6
  62. package/grok/skill/models.toml +2 -2
  63. package/grok/skill/references/arc-visual-companion.md +2 -2
  64. package/grok/skill/references/commit.md +3 -3
  65. package/grok/skill/references/coordination.md +27 -21
  66. package/grok/skill/references/git-recovery.md +3 -1
  67. package/grok/skill/references/handoff-prep.md +3 -3
  68. package/grok/skill/references/handoff.md +16 -14
  69. package/grok/skill/references/limits.md +2 -2
  70. package/grok/skill/references/planning.md +12 -10
  71. package/grok/skill/references/verification.md +67 -35
  72. package/grok/skill/references/worktree-creation.md +2 -0
  73. package/lib/installer/install-mode.mjs +4 -2
  74. package/lib/installer/install.mjs +4 -3
  75. package/lib/installer/language.mjs +1 -1
  76. package/lib/installer/legacy-profiles.mjs +51 -0
  77. package/lib/installer/manifest.mjs +1 -1
  78. package/lib/installer/plan.mjs +5 -3
  79. package/lib/installer/preset.mjs +2 -2
  80. package/lib/installer/role-routing.mjs +49 -18
  81. package/lib/installer/runtime-assets.mjs +3 -0
  82. package/lib/installer/targets.mjs +1 -1
  83. package/lib/installer/transaction.mjs +35 -4
  84. package/lib/installer/uninstall.mjs +13 -10
  85. package/lib/installer/upgrade-state.mjs +13 -1
  86. package/lib/management/operations.mjs +10 -10
  87. package/lib/management/reapply.mjs +5 -3
  88. package/lib/models/config.mjs +25 -7
  89. package/lib/models/profiles.mjs +1 -1
  90. package/lib/platforms/formats/gemini-markdown.mjs +3 -3
  91. package/lib/platforms/formats/grok-markdown.mjs +3 -3
  92. package/lib/platforms/formats/markdown.mjs +2 -2
  93. package/lib/platforms/formats/toml.mjs +2 -2
  94. package/lib/policy/placement.mjs +1 -1
  95. package/lib/policy/render.mjs +3 -3
  96. package/lib/policy/role-policy.json +28 -28
  97. package/lib/prompts/agent-fragments.json +24 -24
  98. package/lib/prompts/render.mjs +9 -9
  99. package/lib/runtime/acceptance.mjs +4 -3
  100. package/lib/runtime/bootstrap.mjs +4 -2
  101. package/lib/runtime/command.mjs +29 -3
  102. package/lib/runtime/cooperative-schema.mjs +16 -5
  103. package/lib/runtime/cooperative.mjs +6 -3
  104. package/lib/runtime/evaluate.mjs +10 -7
  105. package/lib/runtime/handoff-record.mjs +58 -0
  106. package/lib/runtime/host-service.mjs +155 -0
  107. package/lib/runtime/identity.mjs +10 -7
  108. package/lib/runtime/operations.mjs +41 -3
  109. package/lib/runtime/role-bridge-args.mjs +115 -13
  110. package/lib/runtime/role-bridge.mjs +57 -22
  111. package/lib/runtime/role-dispatch-policy.mjs +15 -5
  112. package/lib/runtime/role-dispatch-store.mjs +9 -2
  113. package/lib/runtime/role-observe.mjs +12 -7
  114. package/lib/runtime/role-routing-config.mjs +20 -6
  115. package/lib/runtime/role-routing.mjs +17 -4
  116. package/lib/runtime/role-supervisor.mjs +248 -9
  117. package/lib/runtime/schema.mjs +8 -5
  118. package/lib/runtime/scope.mjs +1 -1
  119. package/lib/runtime/store.mjs +2 -2
  120. package/lib/runtime/tool-access.mjs +560 -0
  121. package/lib/runtime/verification.mjs +15 -7
  122. package/lib/tui/setup.mjs +1 -1
  123. package/lib/watch/labels.mjs +2 -1
  124. package/lib/watch/model.mjs +2 -2
  125. package/lib/watch/render.mjs +2 -2
  126. package/lib/watch/watcher.mjs +46 -25
  127. package/package.json +1 -1
  128. package/shared/skill/runtime/acceptance.mjs +4 -3
  129. package/shared/skill/runtime/bootstrap.mjs +4 -2
  130. package/shared/skill/runtime/command.mjs +29 -3
  131. package/shared/skill/runtime/cooperative-schema.mjs +16 -5
  132. package/shared/skill/runtime/cooperative.mjs +6 -3
  133. package/shared/skill/runtime/evaluate.mjs +10 -7
  134. package/shared/skill/runtime/handoff-record.mjs +58 -0
  135. package/shared/skill/runtime/host-service.mjs +155 -0
  136. package/shared/skill/runtime/identity.mjs +10 -7
  137. package/shared/skill/runtime/operations.mjs +41 -3
  138. package/shared/skill/runtime/role-bridge-args.mjs +115 -13
  139. package/shared/skill/runtime/role-bridge.mjs +57 -22
  140. package/shared/skill/runtime/role-dispatch-policy.mjs +15 -5
  141. package/shared/skill/runtime/role-dispatch-store.mjs +9 -2
  142. package/shared/skill/runtime/role-observe.mjs +12 -7
  143. package/shared/skill/runtime/role-policy.json +28 -28
  144. package/shared/skill/runtime/role-routing-config.mjs +20 -6
  145. package/shared/skill/runtime/role-routing.mjs +17 -4
  146. package/shared/skill/runtime/role-supervisor.mjs +248 -9
  147. package/shared/skill/runtime/schema.mjs +8 -5
  148. package/shared/skill/runtime/scope.mjs +1 -1
  149. package/shared/skill/runtime/store.mjs +2 -2
  150. package/shared/skill/runtime/tool-access.mjs +560 -0
  151. package/shared/skill/runtime/verification.mjs +15 -7
@@ -3,29 +3,31 @@ 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
- const ROLES = ['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_qa', 'arc_reviewer'];
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}, arc_planner: {permissionMode: 'default', sandbox: false},
13
- arc_implementer: {permissionMode: 'acceptEdits', sandbox: true}, arc_qa: {permissionMode: 'default', sandbox: true}, arc_reviewer: {permissionMode: 'default', sandbox: false}
13
+ arc_scouter: {permissionMode: 'default', sandbox: false, allowedTools: ['WebFetch', 'WebSearch']},
14
+ arc_planner: {permissionMode: 'default', sandbox: false},
15
+ arc_implementer: {permissionMode: 'acceptEdits', sandbox: true}, arc_tester: {permissionMode: 'default', sandbox: true}, arc_reviewer: {permissionMode: 'default', sandbox: false}
14
16
  },
15
17
  gemini: {
16
18
  arc_scouter: {approvalMode: 'plan', sandbox: false}, arc_planner: {approvalMode: 'plan', sandbox: false},
17
- arc_implementer: {approvalMode: 'auto_edit', sandbox: true}, arc_qa: {approvalMode: 'auto_edit', sandbox: true}, arc_reviewer: {approvalMode: 'plan', sandbox: false}
19
+ arc_implementer: {approvalMode: 'auto_edit', sandbox: true}, arc_tester: {approvalMode: 'auto_edit', sandbox: true}, arc_reviewer: {approvalMode: 'plan', sandbox: false}
18
20
  },
19
21
  grok: {
20
22
  arc_scouter: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
21
23
  arc_planner: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
22
24
  arc_reviewer: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
23
25
  arc_implementer: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
24
- arc_qa: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
26
+ arc_tester: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
25
27
  },
26
28
  codex: {
27
29
  arc_scouter: {sandboxMode: 'read-only', search: true}, arc_planner: {sandboxMode: 'read-only', search: false},
28
- arc_implementer: {sandboxMode: 'workspace-write', search: false}, arc_qa: {sandboxMode: 'workspace-write', search: false}, arc_reviewer: {sandboxMode: 'read-only', search: false}
30
+ arc_implementer: {sandboxMode: 'workspace-write', search: false}, arc_tester: {sandboxMode: 'workspace-write', search: false}, arc_reviewer: {sandboxMode: 'read-only', search: false}
29
31
  }
30
32
  });
31
33
 
@@ -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
- export function buildClaudeArgs({role, profile, sessionId = null, policy = DEFAULT_POLICY}) {
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
- export function buildCodexArgs({role, profile, worktree, resultPath, threadId = null, policy = DEFAULT_POLICY}) {
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 settings = ['-m', requireText(profile?.model, 'model'), '-c', `model_reasoning_effort=${JSON.stringify(requireText(profile.effort, 'effort'))}`,
206
- '-c', `developer_instructions=${JSON.stringify(requireText(profile.instructions, 'instructions'))}`, '-c', `sandbox_mode=${JSON.stringify(permissions.sandboxMode)}`,
207
- '-c', 'approval_policy="never"', '-o', resultPath, '-'];
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];
@@ -4,9 +4,10 @@ import {runtimeRegistryOf, DEFAULT_PLATFORM_REGISTRY} from './platform-registry.
4
4
  import fsp from 'node:fs/promises';
5
5
  import path from 'node:path';
6
6
  import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, bridgeGateReasons, environmentReasons, capabilityReasons} from './role-dispatch-policy.mjs';
7
+ import {displayRoutingRole} from './role-routing-config.mjs';
7
8
  import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
8
9
  import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
9
- 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';
10
11
 
11
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}]});
12
13
 
@@ -19,23 +20,27 @@ const environmentOf=(context,host)=>runtimeRegistryOf(context).getPlatform(host)
19
20
  const validContext=context=>{const host=hostOf(context);return Boolean(host&&environmentOf(context,host)&&typeof context.workflowId==='string'&&context.workflowId&&typeof context.cwd==='string');};
20
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)]});
21
22
  export function leaseTargetPlatform(lease,registry=DEFAULT_PLATFORM_REGISTRY){
22
- if(lease.version===2)return lease.targetPlatform;
23
+ if(lease.version>=2)return lease.targetPlatform;
23
24
  if(!v1Platforms.includes(lease.hostPlatform))throw Error('Invalid composite profile: unknown platform');
24
25
  if(lease.route==='native')return lease.hostPlatform;
25
26
  return v1Platforms.find(id=>id!==lease.hostPlatform);
26
27
  }
27
28
  const supportOf=lease=>lease.route==='bridge'&&!String(lease.executionEnvironment).endsWith('-desktop')&&lease.state==='completed'&&lease.reasons.length===0&&['identity','model','effort','permissions','terminal'].every(key=>lease.claims?.[key]?.level==='runtime-observed')?'verified':'unverified';
29
+ const displayRoleOf=lease=>displayRoutingRole(lease.role)??lease.role;
28
30
  /** Result view of a lease. failed and unknown hold dependent work; every other observed state is reported as allow. */
29
31
  function fromLease(lease,decision=['failed','unknown'].includes(lease.state)?'hold':'allow',runtimePlatforms=DEFAULT_PLATFORM_REGISTRY){
30
32
  const platform=leaseTargetPlatform(lease,runtimePlatforms);
31
- return {decision,routeStatus:lease.state,supportStatus:supportOf(lease),dispatchId:lease.dispatchId,route:lease.route,profileName:profileName(platform,lease.role,{runtimePlatforms}),executionEnvironment:lease.executionEnvironment,hostPlatform:lease.hostPlatform,role:lease.role,requested:{platform,model:lease.claims?.model?.requested??null,effort:lease.claims?.effort?.requested??null},authentication:null,cliVersion:null,claims:lease.claims,reasons:lease.reasons,resultPath:lease.resultPath};
33
+ const role=displayRoleOf(lease);
34
+ const legacy=lease.role!==role;
35
+ const name=legacy&&/^arc[_-]routing[_-]/.test(lease.role)?lease.role:profileName(platform,legacy?'arc_qa':role,{runtimePlatforms});
36
+ return {decision,routeStatus:lease.state,supportStatus:supportOf(lease),dispatchId:lease.dispatchId,route:lease.route,profileName:name,executionEnvironment:lease.executionEnvironment,hostPlatform:lease.hostPlatform,role,requested:{platform,model:lease.claims?.model?.requested??null,effort:lease.claims?.effort?.requested??null},authentication:null,cliVersion:null,claims:lease.claims,reasons:lease.reasons,resultPath:lease.resultPath};
32
37
  }
33
38
  const residualOf=error=>Array.isArray(error?.residualPaths)?error.residualPaths:undefined;
34
39
  const hold=(context,dispatchId,code,error)=>{const result=blank(context,dispatchId,'hold',code);const residual=residualOf(error);if(residual)result.residualPaths=residual;return result;};
35
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';};
36
41
 
37
42
  /** Starts the detached supervisor for a reserved bridge lease; the supervisor, not this function, spawns the child. */
38
- 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}={}){
39
44
  if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.')||typeof brief!=='string'){return blank(context,dispatchId,'deny','invalid_request');}
40
45
  const bytes=Buffer.byteLength(brief,'utf8');
41
46
  if(bytes<1||bytes>policy.briefMaxBytes)return blank(context,dispatchId,'deny','invalid_request');
@@ -47,6 +52,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
47
52
  await withRoutingLock(anchorHome,async()=>{
48
53
  const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
49
54
  if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform||lease.route!=='bridge'||lease.state!=='reserved'){result=blank(context,dispatchId,'deny','invalid_request');return;}
55
+ if(displayRoleOf(lease)!==lease.role){result=blank(context,dispatchId,'deny','legacy_role_arc_qa');return;}
50
56
  const platform=leaseTargetPlatform(lease,runtimePlatforms);
51
57
  let config;try{config=await readActivation(homes,lease.revision,{anchorHome,host:context.hostPlatform,runtimePlatforms});}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
52
58
  validateLease(lease,{runtimePlatforms,config});
@@ -54,7 +60,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
54
60
  if(capabilities.length){result=blank(context,dispatchId,'hold',capabilities[0]);return;}
55
61
  let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
56
62
  const directory=artifactDirectory(target,lease.workflowId,dispatchId),resultPath=path.join(directory,'result.md');
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;}
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;}
58
64
  await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(directory,0o700);
59
65
  await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
60
66
  if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
@@ -76,18 +82,37 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
76
82
  }
77
83
 
78
84
  const TEXT=/^[^\p{Cc}]{1,256}$/u;
79
- async function markLostIfDue(anchorHome,lease,{now,lostMs,policy,runtimePlatforms}){
80
- 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};
81
99
  const heartbeat=await readHeartbeat(anchorHome,lease.dispatchId);
82
100
  const lastSeen=Math.max(heartbeat?.at??0,Date.parse(lease.updatedAt)||0);
83
- if(now-lastSeen<=lostMs||processAlive(lease.supervisor))return lease;
101
+ if(now-lastSeen<=lostMs||processAlive(lease.supervisor))return {lease};
102
+ let lost=false,next;
84
103
  try{
85
- return await withRoutingLock(anchorHome,async()=>{
104
+ next=await withRoutingLock(anchorHome,async()=>{
86
105
  const current=await readLease(anchorHome,lease.dispatchId,{runtimePlatforms});
87
- if(!current||!['starting','running'].includes(current.state))return current??lease;
88
- 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;
89
110
  },{retryMs:policy.lockRetryMs});
90
- }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):{})};
91
116
  }
92
117
  async function recordNativeEvent({context,anchorHome,dispatchId,event,nativeAgentId,now,policy,runtimePlatforms}){
93
118
  const view=(lease,decision)=>fromLease(lease,decision,runtimePlatforms);
@@ -125,8 +150,12 @@ export async function recordRoleObservation({context,dispatchId,waitMs,event,nat
125
150
  const end=Date.now()+(waitMs??0),lost=lostMs??policy.supervisorLostMs;
126
151
  try{
127
152
  for(;;){
128
- lease=await markLostIfDue(anchorHome,lease,{now:now??Date.now(),lostMs:lost,policy,runtimePlatforms});
129
- 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
+ }
130
159
  await sleep(Math.min(pollMs,Math.max(0,end-Date.now())));
131
160
  lease=await readLease(anchorHome,dispatchId,{runtimePlatforms})??lease;
132
161
  }
@@ -134,7 +163,7 @@ export async function recordRoleObservation({context,dispatchId,waitMs,event,nat
134
163
  }
135
164
 
136
165
  /** Continues a completed or failed bridge dispatch in its recorded session. The input carries no session id; only the lease value is used. */
137
- 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}={}){
138
167
  if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.')||typeof brief!=='string'){return blank(context,dispatchId,'deny','invalid_request');}
139
168
  const bytes=Buffer.byteLength(brief,'utf8');
140
169
  if(bytes<1||bytes>policy.briefMaxBytes)return blank(context,dispatchId,'deny','invalid_request');
@@ -145,7 +174,9 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
145
174
  try{
146
175
  await withRoutingLock(anchorHome,async()=>{
147
176
  const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
148
- if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform||lease.route!=='bridge'||!['completed','failed'].includes(lease.state)){result=blank(context,dispatchId,'deny','invalid_request');return;}
177
+ if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform){result=blank(context,dispatchId,'deny','invalid_request');return;}
178
+ if(displayRoleOf(lease)!==lease.role){result=blank(context,dispatchId,'hold','legacy_role_resume_unsupported');return;}
179
+ if(lease.route!=='bridge'||!['completed','failed'].includes(lease.state)){result=blank(context,dispatchId,'deny','invalid_request');return;}
149
180
  const targetPlatform=leaseTargetPlatform(lease,runtimePlatforms);
150
181
  if((targetPlatform==='gemini'||targetPlatform==='grok')&&!['on','verified'].includes(supervisorImplementations.get(targetPlatform)?.resume)){result=blank(context,dispatchId,'hold','resume_unverified');return;}
151
182
  if(!lease.sessionId){result=blank(context,dispatchId,'hold','execution_identity_unverified');return;}
@@ -166,7 +197,7 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
166
197
  if(codes.size){result=blank(context,dispatchId,'hold','activation_unverified');result.reasons=[...codes].map(reason);return;}
167
198
  let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
168
199
  const segment=lease.segment+1,directory=segmentDirectory(target,lease.workflowId,dispatchId,segment),resultPath=path.join(directory,'result.md');
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;}
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;}
170
201
  await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(path.dirname(directory),0o700);await fsp.chmod(directory,0o700);
171
202
  await fsp.writeFile(path.join(directory,'brief.md'),brief,{mode:0o600,flag:'w'});await fsp.chmod(path.join(directory,'brief.md'),0o600);
172
203
  if(Object.hasOwn(HOST_SANDBOX_GATES,lease.hostPlatform)){
@@ -197,7 +228,7 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
197
228
  if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.'))return blank(context,dispatchId,'deny','invalid_request');
198
229
  const homes=resolveRuntimeHomes(context),runtimePlatforms=runtimeRegistryOf(context);
199
230
  const view=(lease,decision)=>fromLease(lease,decision,runtimePlatforms);
200
- let anchorHome,result,direct=null,residual;
231
+ let anchorHome,result,direct=null,lostLease,residual;
201
232
  try{anchorHome=await locateAnchorHome({host:context.hostPlatform,homes});}catch{return blank(context,dispatchId,'hold','activation_unverified');}
202
233
  const graceMs=policy.cancelGraceMs;
203
234
  try{
@@ -213,12 +244,14 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
213
244
  }
214
245
  if(TERMINAL_STATES.includes(lease.state)){result=view(lease,'allow');return;}
215
246
  if(lease.state==='reserved'){result=view(await writeLease(anchorHome,{...lease,state:'cancelled',reasons:[]},{now,runtimePlatforms}),'allow');return;}
216
- 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;
217
249
  if(supervised){
218
250
  await requestCancel(anchorHome,dispatchId);
219
251
  if(lease.child&&processAlive(lease.child))signalGroup(lease.child.pid,'SIGTERM');
220
252
  result={...view(lease,'allow'),routeStatus:'cancelling'};return;
221
253
  }
254
+ if(!supervisorAlive&&lease.toolAccess?.services.length)lostLease=lease;
222
255
  if(lease.child&&processAlive(lease.child)){signalGroup(lease.child.pid,'SIGTERM');direct={lease,identified:true};}
223
256
  else if(lease.child&&!groupExists(lease.child.pid)&&!pidExists(lease.child.pid))direct={lease,identified:false};
224
257
  else result=view(lease,'hold');
@@ -233,14 +266,15 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
233
266
  if(!killed&&Date.now()>=begin+graceMs){signalGroup(pid,'SIGKILL');killed=true;}
234
267
  await sleep(25);gone=!groupExists(pid);
235
268
  }
236
- let escapes={};
269
+ let cleanup={};
237
270
  if(!direct.lease.supervisor||!processAlive(direct.lease.supervisor)){
238
271
  try{
239
272
  const target=await resolveWorktree(context.cwd);
240
273
  const directory=segmentDirectory(target,direct.lease.workflowId,dispatchId,direct.lease.segment??0);
241
- escapes=await reapRecordedDescendants(directory,direct.lease,{graceMs});
274
+ cleanup=await reapRecordedDescendants(directory,direct.lease,{graceMs});
242
275
  }catch{/* A missing worktree does not change the group cancellation result. */}
243
276
  }
277
+ if(lostLease){Object.assign(cleanup,await recoverLostHostServices(anchorHome,context.cwd,lostLease,graceMs));lostLease=null;}
244
278
  if(!gone)result=view(direct.lease,'hold');
245
279
  else{
246
280
  try{
@@ -256,8 +290,9 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
256
290
  else return hold(context,dispatchId,classifyLock(error),error);
257
291
  }
258
292
  }
259
- if(result&&escapes.escapedDescendants)result={...result,...escapes};
293
+ if(result)Object.assign(result,cleanup);
260
294
  }
295
+ if(lostLease)Object.assign(result,await recoverLostHostServices(anchorHome,context.cwd,lostLease,graceMs));
261
296
  if(residual)result.residualPaths=residual;
262
297
  return result;
263
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,
@@ -33,7 +41,7 @@ export const effectiveClaudeSandboxSettings = policy => policy?.gates?.G1 === 'p
33
41
  export const CATALOG_MODEL_ALIASES = Object.freeze(['fable', 'opus', 'sonnet', 'haiku']);
34
42
  export const CODEX_DELEGATION_CALL_NAMES = Object.freeze(['spawn_agent', 'wait_agent']);
35
43
  export const DESKTOP_CHECKLIST_PASSED = Object.freeze({'claude-desktop': false, 'codex-desktop': false});
36
- export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_planner: 20, arc_implementer: 60, arc_qa: 30, arc_reviewer: 20});
44
+ export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_planner: 20, arc_implementer: 60, arc_tester: 60, arc_reviewer: 20});
37
45
  export const HEARTBEAT_MS = 5000;
38
46
  export const SUPERVISOR_LOST_MS = 30000;
39
47
  export const OBSERVE_MAX_WAIT_MS = 540000;
@@ -81,6 +89,8 @@ export const RELEASE_CONDITIONS = Object.freeze({
81
89
  permission_scope_unverified: 'Update ARC and verify enforcement of the role permissions and approved scope before starting.',
82
90
  native_profile_reload_unverified: 'Verify that the host session loaded the requested profile revision.',
83
91
  revision_changed: 'Re-run routing-status and prepare a new dispatch under the current revision.',
92
+ legacy_role_resume_unsupported: 'Prepare a new arc_tester dispatch under the current routing revision.',
93
+ legacy_role_arc_qa: 'Use arc_tester when preparing a new dispatch.',
84
94
  duplicate_dispatch: 'Use a new requestId, or finish the existing dispatch for the same workflow, task and role.',
85
95
  invalid_request: 'Provide a valid request with exactly the documented keys.',
86
96
  permission_scope_mismatch: 'Inspect the recorded permission mismatch before dependent work.',
@@ -120,9 +130,9 @@ export function hostGateReasons({hostPlatform, policy = DEFAULT_POLICY}) {
120
130
 
121
131
  export function bridgeGateReasons({platform, role, hostPlatform, policy = DEFAULT_POLICY}) {
122
132
  const gates = policy.gates ?? BRIDGE_GATE_RESULTS, codes = [];
123
- if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_qa') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
124
- if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
125
- if (platform === 'grok' && (role === 'arc_implementer' || role === 'arc_qa') && gates.GK1 !== 'pass') codes.push('permission_scope_unverified');
133
+ if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_tester') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
134
+ if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_tester') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
135
+ if (platform === 'grok' && (role === 'arc_implementer' || role === 'arc_tester') && gates.GK1 !== 'pass') codes.push('permission_scope_unverified');
126
136
  codes.push(...hostGateReasons({hostPlatform, policy}));
127
137
  if (platform === 'codex' && gates.G4 === 'fail') codes.push('permission_scope_unverified');
128
138
  if (hostPlatform === 'codex' && gates.G2 === 'fail') codes.push('host_sandbox_blocked');
@@ -3,7 +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';
8
+ import {displayRoutingRole} from './role-routing-config.mjs';
9
+ import {validateToolAccess} from './tool-access.mjs';
7
10
 
8
11
  export const NON_TERMINAL_STATES = Object.freeze(['reserved', 'starting', 'running', 'unknown']);
9
12
  export const TERMINAL_STATES = Object.freeze(['completed', 'failed', 'cancelled']);
@@ -20,15 +23,17 @@ const leasePath = (codexHome, dispatchId) => {
20
23
  return path.join(dispatchDirectory(codexHome), `${dispatchId}.json`);
21
24
  };
22
25
  export function validateLease(value, options) {
23
- const keys = value?.version === 2 ? [...KEYS, 'targetPlatform'] : KEYS;
26
+ const keys = value?.version === 3 ? [...KEYS, 'targetPlatform', 'toolAccess'] : value?.version === 2 ? [...KEYS, 'targetPlatform'] : KEYS;
24
27
  if (!isObject(value) || Object.keys(value).length !== keys.length || keys.some(key => !Object.hasOwn(value, key))) throw Error('Invalid lease keys');
25
28
  const registry = options?.registry ?? runtimeRegistryOf(options);
26
- 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('.')
27
31
  && ['workflowId', 'taskId', 'requestId', 'role', 'executionEnvironment', 'revision', 'createdAt', 'updatedAt'].every(key => text(value[key]))
28
32
  && ['native', 'bridge'].includes(value.route) && registry.isPlatformId(value.hostPlatform)
29
33
  && (value.version === 1 || registry.isPlatformId(value.targetPlatform)
30
34
  && (value.route === 'native' ? value.targetPlatform === value.hostPlatform : value.targetPlatform !== value.hostPlatform)
31
35
  && (!options?.config || Object.values(options.config.roles).some(role => role.platform === value.targetPlatform)))
36
+ && (value.version !== 3 || normalized !== null && isDeepStrictEqual(normalized, value.toolAccess))
32
37
  && nullableText(value.profileHash) && nullableText(value.argsDigest) && nullableText(value.sessionId) && nullableText(value.resultPath) && nullableText(value.nativeAgentId)
33
38
  && [...NON_TERMINAL_STATES, ...TERMINAL_STATES].includes(value.state) && process_(value.supervisor) && process_(value.child)
34
39
  && Number.isInteger(value.timeoutMinutes) && value.timeoutMinutes > 0 && Number.isInteger(value.segment) && value.segment >= 0
@@ -48,6 +53,8 @@ export async function ensureDispatchDirectory(codexHome, {uid = process.getuid?.
48
53
  }
49
54
  export async function createLease(codexHome, lease, options) {
50
55
  const value = validateLease(lease, options);
56
+ const role = displayRoutingRole(value.role);
57
+ if (role !== null && role !== value.role) throw Error('Cannot create a lease with a legacy dispatch role');
51
58
  await ensureDispatchDirectory(codexHome);
52
59
  const handle = await fsp.open(leasePath(codexHome, value.dispatchId), 'wx', 0o600);
53
60
  try { await handle.writeFile(JSON.stringify(value, null, 2) + '\n'); await handle.sync(); } finally { await handle.close(); }
@@ -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');
@@ -608,7 +613,7 @@ export async function observeHeadAdvance(root, before, after, role, allowedPaths
608
613
  }
609
614
  const paths = [...uniquePaths].sort();
610
615
  const allowed = Array.isArray(allowedPaths) ? allowedPaths : [];
611
- if (role === 'arc_implementer' || (role === 'arc_qa' && allowed.length)) {
616
+ if (role === 'arc_implementer' || (role === 'arc_tester' && allowed.length)) {
612
617
  const outOfScopePaths = paths.filter(file => !allowedBy(allowed, file));
613
618
  if (outOfScopePaths.length) return {...reject('out_of_scope'), outOfScopePaths};
614
619
  }
@@ -624,10 +629,10 @@ export async function observeHeadAdvance(root, before, after, role, allowedPaths
624
629
  * git:info/refs are tolerated and returned separately from violations.
625
630
  * Other HEAD changes and branch switches are violations.
626
631
  * Any other ref creation, deletion or movement is a violation.
627
- * Implementer and QA may change only allowedPaths in the worktree; with an
632
+ * Implementer and Tester may change only allowedPaths in the worktree; with an
628
633
  * empty or missing list they may change no worktree paths. Fast-forward
629
- * commit paths must stay within allowedPaths for Implementer and for QA with a
630
- * non-empty list; QA with an empty or missing list, like read-only roles, may
634
+ * commit paths must stay within allowedPaths for Implementer and for Tester with a
635
+ * non-empty list; Tester with an empty or missing list, like read-only roles, may
631
636
  * land a verified fast-forward touching any path.
632
637
  * Read-only roles may change no worktree paths beyond verified fast-forward
633
638
  * commits. Ordinary worktree snapshots omit Git-ignored paths. Control files
@@ -656,7 +661,7 @@ export function detectViolations({role, allowedPaths, before, after, headAdvance
656
661
  refsChanged = true;
657
662
  }
658
663
  }
659
- const allowed = (role === 'arc_implementer' || role === 'arc_qa') && Array.isArray(allowedPaths) ? allowedPaths : [];
664
+ const allowed = (role === 'arc_implementer' || role === 'arc_tester') && Array.isArray(allowedPaths) ? allowedPaths : [];
660
665
  const changed = new Set();
661
666
  for (const file of new Set([...before.entries.keys(), ...after.entries.keys()])) {
662
667
  if (before.entries.get(file) !== after.entries.get(file) && !allowedBy(allowed, file)) changed.add(file);
@@ -1,6 +1,8 @@
1
1
  import {runtimeRegistryOf} from './platform-registry.mjs';
2
2
 
3
- export const ROUTING_ROLES = Object.freeze(['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_qa', 'arc_reviewer']);
3
+ export const ROUTING_ROLES = Object.freeze(['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer']);
4
+ export const LEGACY_ROUTING_ROLES = Object.freeze({arc_qa: 'arc_tester'});
5
+ export const ROUTING_CONFIG_VERSION = 3;
4
6
  const validText = value => typeof value === 'string' && value.length > 0 && value === value.trim() && !/[\p{Cc}\u2028\u2029]/u.test(value);
5
7
  const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
6
8
  const v1Platforms = Object.freeze(['codex', 'claude']);
@@ -8,22 +10,34 @@ const isV1Platforms = platforms => platforms.length === v1Platforms.length && v1
8
10
  // Keep injected validation context out of the public config and serialized bytes.
9
11
  const configRegistries = new WeakMap();
10
12
 
13
+ export function displayRoutingRole(role) {
14
+ if (ROUTING_ROLES.includes(role)) return role;
15
+ if (typeof role === 'string' && /^arc[_-](?:routing[_-])?qa$/.test(role)) return LEGACY_ROUTING_ROLES.arc_qa;
16
+ return null;
17
+ }
18
+
11
19
  export function validRoleValues(platform, model, effort, {runtimePlatforms} = {}) {
12
20
  const registry = runtimeRegistryOf({runtimePlatforms});
13
21
  return registry.isPlatformId(platform) && registry.getPlatform(platform).routing.validatePair(model, effort);
14
22
  }
15
23
  export function validateRoleRoutingConfig(config, opts = {}) {
16
24
  const keys = ['version', 'revision', 'platforms', 'roles'];
17
- if (!(exact(config, keys) || (config?.version === 1 && exact(config, ['version', 'revision', 'roles']))) || ![1, 2].includes(config.version) || !validText(config.revision) || !exact(config.roles, ROUTING_ROLES)) throw Error('Invalid role routing configuration');
25
+ if (!(exact(config, keys) || (config?.version === 1 && exact(config, ['version', 'revision', 'roles']))) || ![1, 2, ROUTING_CONFIG_VERSION].includes(config.version) || !validText(config.revision)) throw Error('Invalid role routing configuration');
26
+ let roles = config.roles;
27
+ if (roles && typeof roles === 'object' && !Array.isArray(roles) && Object.hasOwn(roles, 'arc_qa')) {
28
+ if (config.version === ROUTING_CONFIG_VERSION || Object.hasOwn(roles, 'arc_tester')) throw Error('Invalid role routing configuration');
29
+ roles = Object.fromEntries(Object.entries(roles).map(([role, fields]) => [Object.hasOwn(LEGACY_ROUTING_ROLES, role) ? LEGACY_ROUTING_ROLES[role] : role, fields]));
30
+ }
31
+ if (!exact(roles, ROUTING_ROLES)) throw Error('Invalid role routing configuration');
18
32
  const registry = runtimeRegistryOf(opts);
19
33
  const platforms = config.version === 1 && !Object.hasOwn(config, 'platforms') ? [...v1Platforms] : config.platforms;
20
34
  if (!Array.isArray(platforms) || platforms.length < 2 || new Set(platforms).size !== platforms.length || platforms.some(id => !registry.isPlatformId(id))) throw Error('Invalid role routing platforms');
21
35
  if (platforms.some((id, index) => index > 0 && registry.getPlatform(platforms[index - 1]).anchorOrder >= registry.getPlatform(id).anchorOrder) || (config.version === 1 && !isV1Platforms(platforms))) throw Error('Invalid role routing platforms');
22
36
  for (const role of ROUTING_ROLES) {
23
- const fields = config.roles[role];
37
+ const fields = roles[role];
24
38
  if (!exact(fields, ['platform', 'model', 'effort']) || !validRoleValues(fields.platform, fields.model, fields.effort, opts) || !platforms.includes(fields.platform)) throw Error(`Invalid role routing values for ${role}`);
25
39
  }
26
- const result = structuredClone({version: config.version, revision: config.revision, platforms, roles: config.roles});
40
+ const result = structuredClone({version: config.version, revision: config.revision, platforms, roles});
27
41
  configRegistries.set(result, registry);
28
42
  return result;
29
43
  }
@@ -33,7 +47,7 @@ export function parseRoleRoutingConfig(text, opts) {
33
47
  }
34
48
  export function serializeRoleRoutingConfig(config) {
35
49
  const {revision, platforms, roles} = validateRoleRoutingConfig(config, {runtimePlatforms: configRegistries.get(config)});
36
- const value = {version: 2, revision, platforms, roles};
50
+ const value = {version: ROUTING_CONFIG_VERSION, revision, platforms, roles};
37
51
  return JSON.stringify(value, null, 2) + '\n';
38
52
  }
39
53
  export function buildRoleRoutingConfig({revision, platforms = [], roles}, opts = {}) {
@@ -42,5 +56,5 @@ export function buildRoleRoutingConfig({revision, platforms = [], roles}, opts =
42
56
  const participating = [...new Set([...platforms, ...Object.values(roles).map(fields => fields.platform)])];
43
57
  if (participating.some(id => !registry.isPlatformId(id))) throw Error('Invalid role routing platforms');
44
58
  participating.sort((a, b) => registry.getPlatform(a).anchorOrder - registry.getPlatform(b).anchorOrder);
45
- return validateRoleRoutingConfig({version: 2, revision, platforms: participating, roles}, opts);
59
+ return validateRoleRoutingConfig({version: ROUTING_CONFIG_VERSION, revision, platforms: participating, roles}, opts);
46
60
  }