@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.
- package/MANIFEST.sha256 +146 -139
- package/README.md +12 -3
- package/claude/agents/arc-implementer.md +7 -7
- package/claude/agents/arc-planner.md +5 -5
- package/claude/agents/arc-reviewer.md +6 -6
- package/claude/agents/arc-scouter.md +5 -5
- package/claude/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/claude/skill/SKILL.md +6 -6
- package/claude/skill/models.toml +2 -2
- package/claude/skill/references/arc-visual-companion.md +2 -2
- package/claude/skill/references/commit.md +3 -3
- package/claude/skill/references/coordination.md +27 -21
- package/claude/skill/references/git-recovery.md +3 -1
- package/claude/skill/references/handoff-prep.md +3 -3
- package/claude/skill/references/handoff.md +16 -14
- package/claude/skill/references/limits.md +2 -2
- package/claude/skill/references/planning.md +12 -10
- package/claude/skill/references/verification.md +67 -35
- package/claude/skill/references/worktree-creation.md +2 -0
- package/claude/skill/scripts/model_config.py +25 -9
- package/codex/agents/arc-implementer.toml +7 -7
- package/codex/agents/arc-planner.toml +6 -6
- package/codex/agents/arc-reviewer.toml +7 -7
- package/codex/agents/arc-scouter.toml +6 -6
- package/codex/agents/{arc-qa.toml → arc-tester.toml} +10 -10
- package/codex/skill/SKILL.md +7 -7
- package/codex/skill/models.toml +2 -2
- package/codex/skill/references/arc-visual-companion.md +3 -3
- package/codex/skill/references/commit.md +4 -4
- package/codex/skill/references/coordination.md +26 -20
- package/codex/skill/references/git-recovery.md +2 -0
- package/codex/skill/references/handoff-prep.md +4 -4
- package/codex/skill/references/handoff.md +17 -15
- package/codex/skill/references/limits.md +2 -2
- package/codex/skill/references/planning.md +13 -11
- package/codex/skill/references/verification.md +68 -36
- package/codex/skill/references/worktree-creation.md +2 -0
- package/codex/skill/scripts/model_config.py +28 -15
- package/gemini/agents/arc-implementer.md +7 -7
- package/gemini/agents/arc-planner.md +5 -5
- package/gemini/agents/arc-reviewer.md +6 -6
- package/gemini/agents/arc-scouter.md +5 -5
- package/gemini/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/gemini/skill/SKILL.md +6 -6
- package/gemini/skill/models.toml +2 -2
- package/gemini/skill/references/arc-visual-companion.md +2 -2
- package/gemini/skill/references/commit.md +3 -3
- package/gemini/skill/references/coordination.md +27 -21
- package/gemini/skill/references/git-recovery.md +3 -1
- package/gemini/skill/references/handoff-prep.md +3 -3
- package/gemini/skill/references/handoff.md +16 -14
- package/gemini/skill/references/limits.md +2 -2
- package/gemini/skill/references/planning.md +12 -10
- package/gemini/skill/references/verification.md +67 -35
- package/gemini/skill/references/worktree-creation.md +2 -0
- package/grok/agents/arc-implementer.md +7 -7
- package/grok/agents/arc-planner.md +5 -5
- package/grok/agents/arc-reviewer.md +6 -6
- package/grok/agents/arc-scouter.md +5 -5
- package/grok/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/grok/skill/SKILL.md +6 -6
- package/grok/skill/models.toml +2 -2
- package/grok/skill/references/arc-visual-companion.md +2 -2
- package/grok/skill/references/commit.md +3 -3
- package/grok/skill/references/coordination.md +27 -21
- package/grok/skill/references/git-recovery.md +3 -1
- package/grok/skill/references/handoff-prep.md +3 -3
- package/grok/skill/references/handoff.md +16 -14
- package/grok/skill/references/limits.md +2 -2
- package/grok/skill/references/planning.md +12 -10
- package/grok/skill/references/verification.md +67 -35
- package/grok/skill/references/worktree-creation.md +2 -0
- package/lib/installer/install-mode.mjs +4 -2
- package/lib/installer/install.mjs +4 -3
- package/lib/installer/language.mjs +1 -1
- package/lib/installer/legacy-profiles.mjs +51 -0
- package/lib/installer/manifest.mjs +1 -1
- package/lib/installer/plan.mjs +5 -3
- package/lib/installer/preset.mjs +2 -2
- package/lib/installer/role-routing.mjs +49 -18
- package/lib/installer/runtime-assets.mjs +3 -0
- package/lib/installer/targets.mjs +1 -1
- package/lib/installer/transaction.mjs +35 -4
- package/lib/installer/uninstall.mjs +13 -10
- package/lib/installer/upgrade-state.mjs +13 -1
- package/lib/management/operations.mjs +10 -10
- package/lib/management/reapply.mjs +5 -3
- package/lib/models/config.mjs +25 -7
- package/lib/models/profiles.mjs +1 -1
- package/lib/platforms/formats/gemini-markdown.mjs +3 -3
- package/lib/platforms/formats/grok-markdown.mjs +3 -3
- package/lib/platforms/formats/markdown.mjs +2 -2
- package/lib/platforms/formats/toml.mjs +2 -2
- package/lib/policy/placement.mjs +1 -1
- package/lib/policy/render.mjs +3 -3
- package/lib/policy/role-policy.json +28 -28
- package/lib/prompts/agent-fragments.json +24 -24
- package/lib/prompts/render.mjs +9 -9
- package/lib/runtime/acceptance.mjs +4 -3
- package/lib/runtime/bootstrap.mjs +4 -2
- package/lib/runtime/command.mjs +29 -3
- package/lib/runtime/cooperative-schema.mjs +16 -5
- package/lib/runtime/cooperative.mjs +6 -3
- package/lib/runtime/evaluate.mjs +10 -7
- package/lib/runtime/handoff-record.mjs +58 -0
- package/lib/runtime/host-service.mjs +155 -0
- package/lib/runtime/identity.mjs +10 -7
- package/lib/runtime/operations.mjs +41 -3
- package/lib/runtime/role-bridge-args.mjs +115 -13
- package/lib/runtime/role-bridge.mjs +57 -22
- package/lib/runtime/role-dispatch-policy.mjs +15 -5
- package/lib/runtime/role-dispatch-store.mjs +9 -2
- package/lib/runtime/role-observe.mjs +12 -7
- package/lib/runtime/role-routing-config.mjs +20 -6
- package/lib/runtime/role-routing.mjs +17 -4
- package/lib/runtime/role-supervisor.mjs +248 -9
- package/lib/runtime/schema.mjs +8 -5
- package/lib/runtime/scope.mjs +1 -1
- package/lib/runtime/store.mjs +2 -2
- package/lib/runtime/tool-access.mjs +560 -0
- package/lib/runtime/verification.mjs +15 -7
- package/lib/tui/setup.mjs +1 -1
- package/lib/watch/labels.mjs +2 -1
- package/lib/watch/model.mjs +2 -2
- package/lib/watch/render.mjs +2 -2
- package/lib/watch/watcher.mjs +46 -25
- package/package.json +1 -1
- package/shared/skill/runtime/acceptance.mjs +4 -3
- package/shared/skill/runtime/bootstrap.mjs +4 -2
- package/shared/skill/runtime/command.mjs +29 -3
- package/shared/skill/runtime/cooperative-schema.mjs +16 -5
- package/shared/skill/runtime/cooperative.mjs +6 -3
- package/shared/skill/runtime/evaluate.mjs +10 -7
- package/shared/skill/runtime/handoff-record.mjs +58 -0
- package/shared/skill/runtime/host-service.mjs +155 -0
- package/shared/skill/runtime/identity.mjs +10 -7
- package/shared/skill/runtime/operations.mjs +41 -3
- package/shared/skill/runtime/role-bridge-args.mjs +115 -13
- package/shared/skill/runtime/role-bridge.mjs +57 -22
- package/shared/skill/runtime/role-dispatch-policy.mjs +15 -5
- package/shared/skill/runtime/role-dispatch-store.mjs +9 -2
- package/shared/skill/runtime/role-observe.mjs +12 -7
- package/shared/skill/runtime/role-policy.json +28 -28
- package/shared/skill/runtime/role-routing-config.mjs +20 -6
- package/shared/skill/runtime/role-routing.mjs +17 -4
- package/shared/skill/runtime/role-supervisor.mjs +248 -9
- package/shared/skill/runtime/schema.mjs +8 -5
- package/shared/skill/runtime/scope.mjs +1 -1
- package/shared/skill/runtime/store.mjs +2 -2
- package/shared/skill/runtime/tool-access.mjs +560 -0
- package/shared/skill/runtime/verification.mjs +15 -7
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import childProcess from 'node:child_process';
|
|
2
|
+
import {constants, readFileSync, realpathSync} from 'node:fs';
|
|
3
|
+
import fsp from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {setTimeout as sleep} from 'node:timers/promises';
|
|
6
|
+
import {CANCEL_GRACE_MS, PROBE_TIMEOUT_MS} from './role-dispatch-policy.mjs';
|
|
7
|
+
|
|
8
|
+
export const HOST_SERVICES = Object.freeze({
|
|
9
|
+
'browser-cdp': Object.freeze({kind: 'cdp'}),
|
|
10
|
+
'browser-playwright-chromium': Object.freeze({kind: 'playwright', browser: 'chromium'}),
|
|
11
|
+
'browser-playwright-firefox': Object.freeze({kind: 'playwright', browser: 'firefox'}),
|
|
12
|
+
'browser-playwright-webkit': Object.freeze({kind: 'playwright', browser: 'webkit'}),
|
|
13
|
+
});
|
|
14
|
+
export const CHROME_EXECUTABLE = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
|
|
15
|
+
export const SANDBOX_EXEC = '/usr/bin/sandbox-exec';
|
|
16
|
+
export const hostDirFor = dispatchId => `/private/tmp/arc-host-${dispatchId.replaceAll('-', '').slice(0, 8)}`;
|
|
17
|
+
|
|
18
|
+
export function resolveGlobalPlaywright({run = childProcess.spawnSync} = {}) {
|
|
19
|
+
const probe = run('npm', ['root', '-g'], {cwd: '/private/tmp', encoding: 'utf8', timeout: PROBE_TIMEOUT_MS});
|
|
20
|
+
const root = probe.stdout?.trim();
|
|
21
|
+
if (probe.status !== 0 || !root || !path.isAbsolute(root)) return null;
|
|
22
|
+
for (const name of ['playwright', 'playwright-core']) {
|
|
23
|
+
try {
|
|
24
|
+
const {version} = JSON.parse(readFileSync(path.join(root, name, 'package.json'), 'utf8'));
|
|
25
|
+
if (typeof version === 'string' && version.length > 0) return {root, name, version};
|
|
26
|
+
return null;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
if (error.code !== 'ENOENT') return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export async function hostServicePreflight({services, io = {}}) {
|
|
35
|
+
const hold = 'permission_scope_unverified';
|
|
36
|
+
for (const id of services) {
|
|
37
|
+
try {
|
|
38
|
+
switch (HOST_SERVICES[id]?.kind) {
|
|
39
|
+
case 'cdp': {
|
|
40
|
+
const access = io.access ?? fsp.access;
|
|
41
|
+
await access(CHROME_EXECUTABLE, constants.X_OK);
|
|
42
|
+
await access(SANDBOX_EXEC, constants.X_OK);
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
case 'playwright':
|
|
46
|
+
if (!(io.resolveGlobalPlaywright ?? resolveGlobalPlaywright)()) return hold;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
return hold;
|
|
50
|
+
}
|
|
51
|
+
} catch { return hold; }
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function profilePath(filename) {
|
|
57
|
+
const unsafe = /["\\\n\r]/;
|
|
58
|
+
if (unsafe.test(filename)) throw Error('invalid sandbox profile path');
|
|
59
|
+
const resolved = realpathSync(filename);
|
|
60
|
+
if (unsafe.test(resolved)) throw Error('invalid sandbox profile path');
|
|
61
|
+
return resolved;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function renderSandboxProfile({kind, userHome, dataDir}) {
|
|
65
|
+
if (kind === 'playwright') throw Error('playwright sandbox profile unmeasured (MI-B)');
|
|
66
|
+
if (kind !== 'cdp') throw Error('unknown host service kind');
|
|
67
|
+
return [
|
|
68
|
+
'(version 1)',
|
|
69
|
+
'(allow default)',
|
|
70
|
+
`(deny file-read* file-write* (subpath "${profilePath(userHome)}"))`,
|
|
71
|
+
'(deny process-exec (regex #"GoogleUpdater"))',
|
|
72
|
+
`(allow file-read* file-write* (subpath "${profilePath(dataDir)}"))`,
|
|
73
|
+
'(deny network-outbound)',
|
|
74
|
+
'(allow network-outbound (remote ip "localhost:*"))',
|
|
75
|
+
'',
|
|
76
|
+
].join('\n');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const startFailed = () => Object.assign(Error('Host service failed to start'), {reasonCode: 'execution_failed'});
|
|
80
|
+
|
|
81
|
+
async function waitForCdpPort(dataDir, timeoutMs, exited, wait) {
|
|
82
|
+
const deadline = performance.now() + timeoutMs;
|
|
83
|
+
while (!exited() && performance.now() < deadline) {
|
|
84
|
+
const bytes = await fsp.readFile(path.join(dataDir, 'DevToolsActivePort'), 'utf8').catch(error => {
|
|
85
|
+
if (error.code !== 'ENOENT') throw error;
|
|
86
|
+
return '';
|
|
87
|
+
});
|
|
88
|
+
const first = bytes.split('\n', 1)[0].trim();
|
|
89
|
+
const port = Number(first);
|
|
90
|
+
if (!exited() && /^\d+$/.test(first) && port > 0 && port <= 65535) return port;
|
|
91
|
+
const remaining = deadline - performance.now();
|
|
92
|
+
if (remaining > 0 && !exited()) await wait(Math.min(25, remaining));
|
|
93
|
+
}
|
|
94
|
+
throw startFailed();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function startHostService({id, dispatchId, userHome, timeoutMs = PROBE_TIMEOUT_MS, onSpawn, io = {}}) {
|
|
98
|
+
// Playwright launches remain disabled until each engine's isolation is measured.
|
|
99
|
+
if (HOST_SERVICES[id]?.kind !== 'cdp') throw startFailed();
|
|
100
|
+
const hostDir = hostDirFor(dispatchId);
|
|
101
|
+
const dir = path.join(hostDir, id), dataDir = path.join(dir, 'udd'), profile = path.join(dir, 'chrome.sb');
|
|
102
|
+
const wait = io.sleep ?? sleep, kill = io.kill ?? process.kill;
|
|
103
|
+
let child, created = false, exited = false, cleanup;
|
|
104
|
+
const stop = () => cleanup ??= (async () => {
|
|
105
|
+
let warning = false;
|
|
106
|
+
const signalGroup = signal => {
|
|
107
|
+
try { kill(-child.pid, signal); } catch (error) { if (error.code !== 'ESRCH') warning = true; }
|
|
108
|
+
};
|
|
109
|
+
let groupExists = Boolean(child?.pid);
|
|
110
|
+
if (groupExists && exited) {
|
|
111
|
+
try { kill(-child.pid, 0); } catch (error) {
|
|
112
|
+
if (error.code === 'ESRCH') groupExists = false;
|
|
113
|
+
else warning = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (groupExists) {
|
|
117
|
+
signalGroup('SIGTERM');
|
|
118
|
+
try { await wait(CANCEL_GRACE_MS); } catch { warning = true; }
|
|
119
|
+
signalGroup('SIGKILL');
|
|
120
|
+
}
|
|
121
|
+
// The supervisor removes the complete hostDir after collecting evidence.
|
|
122
|
+
if (created && io.removeDir) {
|
|
123
|
+
try { await io.removeDir(dir); } catch { warning = true; }
|
|
124
|
+
}
|
|
125
|
+
return warning ? 'warning' : 'ok';
|
|
126
|
+
})();
|
|
127
|
+
try {
|
|
128
|
+
// The supervisor reserves the host directory for the dispatch before starting any service.
|
|
129
|
+
await fsp.mkdir(dir, {mode: 0o700});
|
|
130
|
+
created = true;
|
|
131
|
+
await fsp.mkdir(dataDir, {mode: 0o700});
|
|
132
|
+
await fsp.writeFile(profile, renderSandboxProfile({kind: 'cdp', userHome, dataDir}), {flag: 'wx', mode: 0o600});
|
|
133
|
+
child = (io.spawn ?? childProcess.spawn)(SANDBOX_EXEC, [
|
|
134
|
+
'-f', profile, CHROME_EXECUTABLE,
|
|
135
|
+
'--headless=new', '--remote-debugging-address=127.0.0.1', '--remote-debugging-port=0',
|
|
136
|
+
`--user-data-dir=${dataDir}`, '--no-first-run', '--no-default-browser-check',
|
|
137
|
+
'--disable-extensions', '--use-mock-keychain', '--no-sandbox', '--disable-gpu',
|
|
138
|
+
'--proxy-server=127.0.0.1:9', '--proxy-bypass-list=127.0.0.1;localhost', 'about:blank',
|
|
139
|
+
], {cwd: hostDir, detached: true, stdio: 'ignore', shell: false});
|
|
140
|
+
const markExited = () => { exited = true; };
|
|
141
|
+
child.once('error', markExited);
|
|
142
|
+
child.once('exit', markExited);
|
|
143
|
+
if (child.pid) onSpawn?.(child.pid);
|
|
144
|
+
const port = await waitForCdpPort(dataDir, timeoutMs, () => exited, wait);
|
|
145
|
+
return {id, started: true, endpoint: {port, url: `http://127.0.0.1:${port}`}, stop};
|
|
146
|
+
} catch {
|
|
147
|
+
const cleanup = await stop();
|
|
148
|
+
throw Object.assign(startFailed(), {cleanup});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function writeServicesFile(scratch, records) {
|
|
153
|
+
const endpoints = Object.fromEntries(records.map(({id, endpoint}) => [id, endpoint]));
|
|
154
|
+
await fsp.writeFile(path.join(scratch, 'services.json'), JSON.stringify(endpoints) + '\n', {flag: 'wx', mode: 0o600});
|
|
155
|
+
}
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import {isPlatformId} from './platform-registry.mjs';
|
|
2
2
|
import {validateWorkflowState, text} from './schema.mjs';
|
|
3
|
-
import {ROLES} from './operations.mjs';
|
|
3
|
+
import {ROLES,canonicalCooperativeRole} from './operations.mjs';
|
|
4
4
|
import fs from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {fingerprintRequest,saveDurableState} from './store.mjs';
|
|
7
7
|
const same=(a,b)=>JSON.stringify(a)===JSON.stringify(b);
|
|
8
8
|
/** Observation is supplied by the trusted platform provider, never agent/tool arguments. */
|
|
9
9
|
export function registerAgentObservation(state, observation){
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const stored=state;
|
|
11
|
+
state=validateWorkflowState(state);
|
|
12
|
+
const result=(decision,reason)=>({decision,reason,state:stored,proposedTransition:null});
|
|
12
13
|
if(!observation||!text(observation.actorRef)||!text(observation.taskId)||!text(observation.observationRef)||!ROLES.includes(observation.role))return result('hold','complete observed identity required');
|
|
13
14
|
const old=state.identities.find(i=>i.actorRef===observation.actorRef);
|
|
14
15
|
const lease=state.leases.find(l=>l.actorRef===observation.actorRef);
|
|
15
|
-
if(old&&(old.taskId!==observation.taskId||old.role!==observation.role))return result('deny','identity rebind');
|
|
16
|
+
if(old&&(old.taskId!==observation.taskId||canonicalCooperativeRole(old.role)!==observation.role))return result('deny','identity rebind');
|
|
16
17
|
if(lease?.status==='retired')return result('deny','retired identity');
|
|
17
18
|
const p=observation.provenance;
|
|
18
19
|
if(!text(observation.eventRef)||!text(observation.correlationRef)||!p||p.source!=='platform-event'||p.eventRef!==observation.eventRef||p.actorRef!==observation.actorRef||p.platform!==observation.platform||p.correlationRef!==observation.correlationRef||p.verification?.status!=='verified'||!text(p.verification.verifierRef)||p.verification.sourceRef!==observation.eventRef)return result('hold','trusted platform spawn observation and correlation required');
|
|
19
20
|
const assignment=state.assignments.find(a=>a.assignmentId===observation.assignmentId&&a.correlationRef===observation.correlationRef);
|
|
20
|
-
if(
|
|
21
|
+
if(assignment?.status==='pending'&&assignment.role==='qa')return {...result('hold','Legacy pending assignment requires a current assignment'),reasonCode:'legacy_role_pending_assignment_unsupported'};
|
|
22
|
+
const assignedRole=assignment?.status==='active'?canonicalCooperativeRole(assignment.role):assignment?.role;
|
|
23
|
+
if(!assignment||assignment.taskId!==observation.taskId||assignedRole!==observation.role||assignment.platform!==observation.platform||assignment.approvalRef!==observation.approvalRef||!same(assignment.paths,observation.paths)||!same(assignment.operations,observation.operations))return result('hold','observation does not match approved pending assignment');
|
|
21
24
|
if(old){
|
|
22
25
|
if(assignment.status==='active'&&assignment.actorRef===old.actorRef&&old.observationRef===observation.observationRef&&lease?.status==='active')return result('allow','same confirmed observation');
|
|
23
26
|
return result('hold','existing identity cannot be assigned through another observation');
|
|
24
27
|
}
|
|
25
28
|
if(assignment.status!=='pending'||assignment.actorRef!==null||lease)return result('hold','new identity requires pending unbound assignment');
|
|
26
29
|
const task=state.tasks.find(t=>t.id===assignment.taskId);if(!task||['accepted','committed'].includes(task.status))return result('hold','task no longer accepts agent observations');
|
|
27
|
-
const next=structuredClone(
|
|
30
|
+
const next=structuredClone(stored);const active=next.assignments.find(a=>a.assignmentId===assignment.assignmentId);active.actorRef=observation.actorRef;active.status='active';active.observationRef=observation.observationRef;
|
|
28
31
|
next.identities.push({actorRef:observation.actorRef,taskId:observation.taskId,role:observation.role,observationRef:observation.observationRef});next.leases.push({actorRef:observation.actorRef,taskId:observation.taskId,status:'active'});next.tasks.find(t=>t.id===assignment.taskId).status='assigned';
|
|
29
32
|
validateWorkflowState(next);
|
|
30
33
|
return {decision:'allow',reason:'matching observed spawn bound to pending assignment',state:next,proposedTransition:next};
|
|
@@ -36,7 +39,7 @@ export async function recordPlannerAgentObservation({statePath,expectedRevision,
|
|
|
36
39
|
const parent=await fs.realpath(path.dirname(statePath));statePath=path.join(parent,path.basename(statePath));let lock;
|
|
37
40
|
try{
|
|
38
41
|
lock=await fs.open(statePath+'.lock','wx',0o600);const stat=await fs.lstat(statePath);if(!stat.isFile()||stat.isSymbolicLink())throw Error('Observation state must be regular file');
|
|
39
|
-
const state=validateWorkflowState(JSON.parse(await fs.readFile(statePath,'utf8'))),eventHash=fingerprintRequest({input,observation:observation??null});
|
|
42
|
+
const state=validateWorkflowState(JSON.parse(await fs.readFile(statePath,'utf8')),{preserveStoredOperations:true}),eventHash=fingerprintRequest({input,observation:observation??null});
|
|
40
43
|
if(state.plannerObservations?.some(o=>o.eventHash===eventHash))return {decision:'hold',reason:'Observation replay',proposedTransition:null,replayed:true};
|
|
41
44
|
const candidates=state.assignments.filter(a=>a.status==='pending'&&a.role==='planner');
|
|
42
45
|
let decision={decision:'hold',reason:'Raw event lacks verified assignment correlation',proposedTransition:null};
|
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
/** Canonical semantic operations, independent of platform tool aliases. */
|
|
2
|
-
export const ROLES = Object.freeze(['orchestrator','scouter','planner','implementer','
|
|
2
|
+
export const ROLES = Object.freeze(['orchestrator','scouter','planner','implementer','tester','reviewer']);
|
|
3
3
|
export const GIT_OPERATIONS = Object.freeze(['stage','commit','push','merge','rebase','reset','branch-create','branch-switch','worktree-create','worktree-remove']);
|
|
4
4
|
export const EXTERNAL_OPERATIONS = Object.freeze(['push','merge','deploy','publish','external-message']);
|
|
5
|
-
export const OPERATIONS = Object.freeze(['read','draft','write','check','
|
|
6
|
-
export const
|
|
5
|
+
export const OPERATIONS = Object.freeze(['read','draft','write','check','test','review','temporary-write','operational-query','install','prepare-target','request-approval','assign-agent','accept','transition','scope-expansion','indirect-bypass',...new Set([...GIT_OPERATIONS,...EXTERNAL_OPERATIONS])]);
|
|
6
|
+
export const LEGACY_OPERATIONS = Object.freeze({qa: 'test'});
|
|
7
|
+
export const LEGACY_COOPERATIVE_ROLES = Object.freeze({qa: 'tester'});
|
|
8
|
+
export const ROLE_OPERATIONS = Object.freeze({orchestrator:['read','write','check','prepare-target','request-approval','assign-agent','accept','transition','install',...GIT_OPERATIONS,...EXTERNAL_OPERATIONS],scouter:['read'],planner:['read','draft'],implementer:['read','write','check'],tester:['read','check','temporary-write'],reviewer:['read','review']});
|
|
9
|
+
|
|
10
|
+
/** Compare a stored role without rewriting historical evidence. */
|
|
11
|
+
export function canonicalCooperativeRole(role) {
|
|
12
|
+
return typeof role === 'string' && Object.hasOwn(LEGACY_COOPERATIVE_ROLES, role) ? LEGACY_COOPERATIVE_ROLES[role] : role;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const isLegacyOperation = operation => typeof operation === 'string' && Object.hasOwn(LEGACY_OPERATIONS, operation);
|
|
16
|
+
const currentOperation = operation => isLegacyOperation(operation) ? LEGACY_OPERATIONS[operation] : operation;
|
|
17
|
+
|
|
18
|
+
/** Interpret only the operation fields of stored state. Request inputs stay strict. */
|
|
19
|
+
export function normalizeStoredOperations(state) {
|
|
20
|
+
const normalizeList = operations => Array.isArray(operations) && operations.some(isLegacyOperation) ? operations.map(currentOperation) : operations;
|
|
21
|
+
const approvals = state.approvals.map(entry => {
|
|
22
|
+
const operations = normalizeList(entry?.scope?.operations);
|
|
23
|
+
return operations === entry?.scope?.operations ? entry : {...entry, scope: {...entry.scope, operations}};
|
|
24
|
+
});
|
|
25
|
+
const assignments = state.assignments.map(entry => {
|
|
26
|
+
const operations = normalizeList(entry?.operations);
|
|
27
|
+
return operations === entry?.operations ? entry : {...entry, operations};
|
|
28
|
+
});
|
|
29
|
+
const audit = state.audit.map(entry => isLegacyOperation(entry?.operation) ? {...entry, operation: currentOperation(entry.operation)} : entry);
|
|
30
|
+
if (approvals.some((entry, i) => entry !== state.approvals[i]) || assignments.some((entry, i) => entry !== state.assignments[i]) || audit.some((entry, i) => entry !== state.audit[i])) return {...state, approvals, assignments, audit};
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Writes may retain aliases on existing history, but must use current names for new records. */
|
|
35
|
+
export function hasNewStoredOperationAliases(state, previous) {
|
|
36
|
+
const hasNewAlias = (operations, original) => Array.isArray(operations)
|
|
37
|
+
&& operations.some((operation, index) => isLegacyOperation(operation) && operation !== original?.[index]);
|
|
38
|
+
const approvals = new Map(previous.approvals.map((entry, index) => [entry?.id ?? index, entry]));
|
|
39
|
+
const assignmentKey = (entry, index) => entry?.assignmentId ?? entry?.actorRef ?? entry?.intentId ?? index;
|
|
40
|
+
const assignments = new Map(previous.assignments.map((entry, index) => [assignmentKey(entry, index), entry]));
|
|
41
|
+
return state.approvals.some((entry, index) => hasNewAlias(entry?.scope?.operations, approvals.get(entry?.id ?? index)?.scope?.operations))
|
|
42
|
+
|| state.assignments.some((entry, index) => hasNewAlias(entry?.operations, assignments.get(assignmentKey(entry, index))?.operations))
|
|
43
|
+
|| state.audit.some((entry, index) => isLegacyOperation(entry?.operation) && entry.operation !== previous.audit[index]?.operation);
|
|
44
|
+
}
|
|
@@ -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', '
|
|
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
|
-
|
|
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},
|
|
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
|
-
|
|
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},
|
|
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
|
-
|
|
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];
|