@yunhozz/arc 0.5.7 → 0.6.0
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 +104 -99
- package/README.md +37 -113
- package/claude/agents/arc-architect.md +44 -0
- package/claude/agents/arc-planner.md +4 -4
- package/claude/skill/SKILL.md +5 -5
- package/claude/skill/models.toml +5 -1
- package/claude/skill/references/commit.md +2 -2
- package/claude/skill/references/coordination.md +10 -9
- package/claude/skill/references/git-recovery.md +1 -1
- package/claude/skill/references/handoff-prep.md +2 -2
- package/claude/skill/references/handoff.md +1 -1
- package/claude/skill/references/planning.md +12 -12
- package/claude/skill/references/verification.md +1 -1
- package/claude/skill/scripts/model_config.py +24 -11
- package/codex/agents/arc-architect.md +36 -0
- package/codex/agents/{arc-implementer.toml → arc-implementer.md} +7 -4
- package/codex/agents/{arc-planner.toml → arc-planner.md} +10 -7
- package/codex/agents/{arc-reviewer.toml → arc-reviewer.md} +7 -4
- package/codex/agents/{arc-scouter.toml → arc-scouter.md} +7 -4
- package/codex/agents/{arc-tester.toml → arc-tester.md} +7 -4
- package/codex/skill/SKILL.md +5 -5
- package/codex/skill/models.toml +5 -1
- package/codex/skill/references/commit.md +2 -2
- package/codex/skill/references/coordination.md +6 -5
- package/codex/skill/references/handoff-prep.md +2 -2
- package/codex/skill/references/handoff.md +1 -1
- package/codex/skill/references/planning.md +12 -12
- package/codex/skill/references/verification.md +1 -1
- package/codex/skill/scripts/apply-models.py +5 -5
- package/codex/skill/scripts/model_config.py +23 -12
- package/gemini/GEMINI.md +1 -1
- package/gemini/agents/arc-architect.md +39 -0
- package/gemini/agents/arc-planner.md +4 -4
- package/gemini/instructions.md +1 -1
- package/gemini/skill/SKILL.md +5 -5
- package/gemini/skill/models.toml +5 -1
- package/gemini/skill/references/commit.md +2 -2
- package/gemini/skill/references/coordination.md +10 -9
- package/gemini/skill/references/git-recovery.md +1 -1
- package/gemini/skill/references/handoff-prep.md +2 -2
- package/gemini/skill/references/handoff.md +1 -1
- package/gemini/skill/references/planning.md +12 -12
- package/gemini/skill/references/verification.md +1 -1
- package/grok/AGENTS.md +1 -1
- package/grok/agents/arc-architect.md +39 -0
- package/grok/agents/arc-planner.md +4 -4
- package/grok/instructions.md +1 -1
- package/grok/skill/SKILL.md +5 -5
- package/grok/skill/models.toml +5 -1
- package/grok/skill/references/commit.md +2 -2
- package/grok/skill/references/coordination.md +10 -9
- package/grok/skill/references/git-recovery.md +1 -1
- package/grok/skill/references/handoff-prep.md +2 -2
- package/grok/skill/references/handoff.md +1 -1
- package/grok/skill/references/planning.md +12 -12
- package/grok/skill/references/verification.md +1 -1
- package/lib/installer/global-config.mjs +1 -1
- package/lib/installer/manifest.mjs +20 -3
- package/lib/installer/role-routing.mjs +6 -3
- package/lib/installer/targets.mjs +1 -1
- package/lib/installer/upgrade-state.mjs +3 -2
- package/lib/models/config.mjs +22 -5
- package/lib/models/profiles.mjs +6 -1
- package/lib/platforms/agent-templates.mjs +1 -0
- package/lib/platforms/codex.mjs +2 -0
- package/lib/platforms/formats/codex-markdown.mjs +58 -0
- package/lib/platforms/formats/gemini-markdown.mjs +3 -2
- package/lib/platforms/formats/grok-markdown.mjs +3 -2
- package/lib/platforms/formats/markdown.mjs +3 -2
- package/lib/platforms/formats/toml.mjs +3 -2
- package/lib/policy/placement.mjs +1 -1
- package/lib/policy/render.mjs +6 -5
- package/lib/policy/role-policy.json +36 -7
- package/lib/prompts/agent-fragments.json +90 -18
- package/lib/prompts/render.mjs +53 -14
- package/lib/runtime/evaluate.mjs +4 -3
- package/lib/runtime/identity.mjs +1 -1
- package/lib/runtime/operations.mjs +2 -2
- package/lib/runtime/role-bridge-args.mjs +5 -3
- package/lib/runtime/role-bridge.mjs +24 -2
- package/lib/runtime/role-dispatch-policy.mjs +2 -1
- package/lib/runtime/role-dispatch-store.mjs +44 -1
- package/lib/runtime/role-observe.mjs +12 -4
- package/lib/runtime/role-routing-config.mjs +9 -4
- package/lib/runtime/role-supervisor.mjs +16 -2
- package/lib/tui/diagram.mjs +2 -3
- package/lib/tui/setup.mjs +13 -11
- package/lib/watch/labels.mjs +1 -1
- package/lib/watch/model.mjs +2 -2
- package/lib/watch/render.mjs +2 -2
- package/package.json +1 -1
- package/scripts/update-manifest.mjs +1 -1
- package/shared/skill/references/arc-visual-companion-common.md +2 -2
- package/shared/skill/references/commit-common.md +3 -3
- package/shared/skill/references/coordination-common.md +19 -12
- package/shared/skill/references/handoff-common.md +5 -5
- package/shared/skill/references/handoff-prep-common.md +1 -1
- package/shared/skill/references/planning-common.md +25 -25
- package/shared/skill/references/verification-common.md +5 -3
- package/shared/skill/runtime/evaluate.mjs +4 -3
- package/shared/skill/runtime/identity.mjs +1 -1
- package/shared/skill/runtime/operations.mjs +2 -2
- package/shared/skill/runtime/role-bridge-args.mjs +5 -3
- package/shared/skill/runtime/role-bridge.mjs +24 -2
- package/shared/skill/runtime/role-dispatch-policy.mjs +2 -1
- package/shared/skill/runtime/role-dispatch-store.mjs +44 -1
- package/shared/skill/runtime/role-observe.mjs +12 -4
- package/shared/skill/runtime/role-policy.json +36 -7
- package/shared/skill/runtime/role-routing-config.mjs +9 -4
- package/shared/skill/runtime/role-supervisor.mjs +16 -2
package/lib/prompts/render.mjs
CHANGED
|
@@ -12,6 +12,19 @@ const EXPECTED = {
|
|
|
12
12
|
"common.profile-guidance",
|
|
13
13
|
"implementer.execution-steps"
|
|
14
14
|
],
|
|
15
|
+
"claude/agents/arc-architect.md": [
|
|
16
|
+
"common.brief-boundary",
|
|
17
|
+
"common.specialist-basics",
|
|
18
|
+
"common.preservation-choice-inspection",
|
|
19
|
+
"claude.incident-prefix",
|
|
20
|
+
"common.optional-read-exception",
|
|
21
|
+
"common.resume-gates",
|
|
22
|
+
"common.profile-guidance",
|
|
23
|
+
"architect.target-evidence",
|
|
24
|
+
"architect.workflow-contract",
|
|
25
|
+
"drafting.exploration-budget",
|
|
26
|
+
"architect.visual-question"
|
|
27
|
+
],
|
|
15
28
|
"claude/agents/arc-planner.md": [
|
|
16
29
|
"common.brief-boundary",
|
|
17
30
|
"common.specialist-basics",
|
|
@@ -22,10 +35,10 @@ const EXPECTED = {
|
|
|
22
35
|
"common.profile-guidance",
|
|
23
36
|
"planner.target-evidence",
|
|
24
37
|
"planner.workflow-contract",
|
|
38
|
+
"drafting.exploration-budget",
|
|
25
39
|
"planner.exploration-density",
|
|
26
40
|
"planner.task-shape",
|
|
27
41
|
"planner.commit-boundary",
|
|
28
|
-
"planner.visual-question",
|
|
29
42
|
"planner.final-plan-recheck"
|
|
30
43
|
],
|
|
31
44
|
"claude/agents/arc-tester.md": [
|
|
@@ -67,7 +80,7 @@ const EXPECTED = {
|
|
|
67
80
|
"common.read-only-no-mutations",
|
|
68
81
|
"scouter.additional-boundaries"
|
|
69
82
|
],
|
|
70
|
-
"codex/agents/arc-implementer.
|
|
83
|
+
"codex/agents/arc-implementer.md": [
|
|
71
84
|
"common.brief-boundary",
|
|
72
85
|
"common.specialist-basics",
|
|
73
86
|
"common.preservation-choice-inspection",
|
|
@@ -77,7 +90,20 @@ const EXPECTED = {
|
|
|
77
90
|
"common.profile-guidance",
|
|
78
91
|
"implementer.execution-steps"
|
|
79
92
|
],
|
|
80
|
-
"codex/agents/arc-
|
|
93
|
+
"codex/agents/arc-architect.md": [
|
|
94
|
+
"common.brief-boundary",
|
|
95
|
+
"common.specialist-basics",
|
|
96
|
+
"common.preservation-choice-inspection",
|
|
97
|
+
"codex.incident-prefix",
|
|
98
|
+
"common.optional-read-exception",
|
|
99
|
+
"common.resume-gates",
|
|
100
|
+
"common.profile-guidance",
|
|
101
|
+
"architect.target-evidence",
|
|
102
|
+
"architect.workflow-contract",
|
|
103
|
+
"drafting.exploration-budget",
|
|
104
|
+
"architect.visual-question"
|
|
105
|
+
],
|
|
106
|
+
"codex/agents/arc-planner.md": [
|
|
81
107
|
"common.brief-boundary",
|
|
82
108
|
"common.specialist-basics",
|
|
83
109
|
"common.preservation-choice-inspection",
|
|
@@ -87,13 +113,13 @@ const EXPECTED = {
|
|
|
87
113
|
"common.profile-guidance",
|
|
88
114
|
"planner.target-evidence",
|
|
89
115
|
"planner.workflow-contract",
|
|
116
|
+
"drafting.exploration-budget",
|
|
90
117
|
"planner.exploration-density",
|
|
91
118
|
"planner.task-shape",
|
|
92
119
|
"planner.commit-boundary",
|
|
93
|
-
"planner.visual-question",
|
|
94
120
|
"planner.final-plan-recheck"
|
|
95
121
|
],
|
|
96
|
-
"codex/agents/arc-tester.
|
|
122
|
+
"codex/agents/arc-tester.md": [
|
|
97
123
|
"common.brief-boundary",
|
|
98
124
|
"common.specialist-basics",
|
|
99
125
|
"common.preservation-choice-inspection",
|
|
@@ -105,7 +131,7 @@ const EXPECTED = {
|
|
|
105
131
|
"common.verification-reference",
|
|
106
132
|
"tester.verification-steps"
|
|
107
133
|
],
|
|
108
|
-
"codex/agents/arc-reviewer.
|
|
134
|
+
"codex/agents/arc-reviewer.md": [
|
|
109
135
|
"common.brief-boundary",
|
|
110
136
|
"common.specialist-basics",
|
|
111
137
|
"common.preservation-choice-inspection",
|
|
@@ -119,7 +145,7 @@ const EXPECTED = {
|
|
|
119
145
|
"common.read-only-no-mutations",
|
|
120
146
|
"reviewer.final-plan-findings"
|
|
121
147
|
],
|
|
122
|
-
"codex/agents/arc-scouter.
|
|
148
|
+
"codex/agents/arc-scouter.md": [
|
|
123
149
|
"common.brief-boundary",
|
|
124
150
|
"common.specialist-basics",
|
|
125
151
|
"common.preservation-choice-inspection",
|
|
@@ -133,12 +159,14 @@ const EXPECTED = {
|
|
|
133
159
|
"scouter.additional-boundaries"
|
|
134
160
|
],
|
|
135
161
|
"gemini/agents/arc-implementer.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "implementer.execution-steps"],
|
|
136
|
-
"gemini/agents/arc-
|
|
162
|
+
"gemini/agents/arc-architect.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "architect.target-evidence", "architect.workflow-contract", "drafting.exploration-budget", "architect.visual-question"],
|
|
163
|
+
"gemini/agents/arc-planner.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "planner.target-evidence", "planner.workflow-contract", "drafting.exploration-budget", "planner.exploration-density", "planner.task-shape", "planner.commit-boundary", "planner.final-plan-recheck"],
|
|
137
164
|
"gemini/agents/arc-tester.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "tester.contract-intro", "common.verification-reference", "tester.verification-steps"],
|
|
138
165
|
"gemini/agents/arc-reviewer.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "reviewer.contract-intro", "common.verification-reference", "reviewer.review-steps", "common.read-only-no-mutations", "reviewer.final-plan-findings"],
|
|
139
166
|
"gemini/agents/arc-scouter.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "scouter.research-brief", "scouter.research-mode", "common.read-only-no-mutations", "scouter.additional-boundaries"],
|
|
140
167
|
"grok/agents/arc-implementer.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "implementer.execution-steps"],
|
|
141
|
-
"grok/agents/arc-
|
|
168
|
+
"grok/agents/arc-architect.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "architect.target-evidence", "architect.workflow-contract", "drafting.exploration-budget", "architect.visual-question"],
|
|
169
|
+
"grok/agents/arc-planner.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "planner.target-evidence", "planner.workflow-contract", "drafting.exploration-budget", "planner.exploration-density", "planner.task-shape", "planner.commit-boundary", "planner.final-plan-recheck"],
|
|
142
170
|
"grok/agents/arc-tester.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "tester.contract-intro", "common.verification-reference", "tester.verification-steps"],
|
|
143
171
|
"grok/agents/arc-reviewer.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "reviewer.contract-intro", "common.verification-reference", "reviewer.review-steps", "common.read-only-no-mutations", "reviewer.final-plan-findings"],
|
|
144
172
|
"grok/agents/arc-scouter.md": ["common.brief-boundary", "common.specialist-basics", "common.preservation-choice-inspection", "common.optional-read-exception", "common.resume-gates", "scouter.research-brief", "scouter.research-mode", "common.read-only-no-mutations", "scouter.additional-boundaries"]
|
|
@@ -206,29 +234,40 @@ function bounds(path, text) {
|
|
|
206
234
|
}
|
|
207
235
|
function templateSources(context) {
|
|
208
236
|
const sources = new Map();
|
|
237
|
+
const ownTemplates = new Map();
|
|
238
|
+
const inheritedTemplates = [];
|
|
209
239
|
for (const {runtime, payloadPrefix, agentTemplates} of installerRegistryOf(context).byAnchorOrder()) {
|
|
210
240
|
const source = agentTemplates?.expectationsFrom ?? runtime.id;
|
|
211
|
-
for (const role of ['scouter', 'planner', 'implementer', 'tester', 'reviewer']) {
|
|
241
|
+
for (const role of ['scouter', 'architect', 'planner', 'implementer', 'tester', 'reviewer']) {
|
|
212
242
|
const expected = Object.keys(EXPECTED).find(name => name.startsWith(`${source}/agents/arc-${role}.`));
|
|
213
|
-
|
|
243
|
+
const installed = `${payloadPrefix}/agents/${standaloneProfileFile(runtime, `arc_${role}`)}`;
|
|
244
|
+
if (expected && installed.slice(0, installed.lastIndexOf('.')) === expected.slice(0, expected.lastIndexOf('.'))) {
|
|
245
|
+
ownTemplates.set(expected, installed);
|
|
246
|
+
} else {
|
|
247
|
+
inheritedTemplates.push([installed, expected]);
|
|
248
|
+
}
|
|
214
249
|
}
|
|
215
250
|
}
|
|
216
251
|
// Preserve the default template validation order and its first error.
|
|
217
|
-
|
|
252
|
+
for (const name of Object.keys(EXPECTED)) {
|
|
253
|
+
if (ownTemplates.has(name)) sources.set(ownTemplates.get(name), name);
|
|
254
|
+
}
|
|
255
|
+
for (const [installed, expected] of inheritedTemplates) sources.set(installed, expected);
|
|
256
|
+
return sources;
|
|
218
257
|
}
|
|
219
258
|
export function renderAgentProfile(path, input, registry, context = {}) {
|
|
220
259
|
const fragments = validateAgentRegistry(registry);
|
|
221
260
|
const source = templateSources(context).get(path);
|
|
222
261
|
if (!source || !Buffer.isBuffer(input)) throw Error('Invalid profile input');
|
|
223
262
|
const text = new TextDecoder('utf-8', {fatal: true}).decode(input);
|
|
224
|
-
const [start, end] = bounds(
|
|
263
|
+
const [start, end] = bounds(path, text);
|
|
225
264
|
const matches = [...text.matchAll(marker)];
|
|
226
265
|
if (JSON.stringify(matches.map(m => m[1])) !== JSON.stringify(EXPECTED[source]) || matches.some(m => m.index < start || m.index + m[0].length > end)) throw Error('Invalid profile markers');
|
|
227
266
|
const stripped = text.replace(marker, '');
|
|
228
267
|
if (stripped.includes('ARC_AGENT_FRAGMENT')) throw Error('Malformed fragment marker');
|
|
229
268
|
const crlf = text.includes('\r\n');
|
|
230
269
|
const output = text.replace(marker, (_, id) => crlf ? fragments.get(id).replaceAll('\n', '\r\n') : fragments.get(id));
|
|
231
|
-
if (
|
|
270
|
+
if (path.endsWith('.toml')) parseToml(output);
|
|
232
271
|
return Buffer.from(output);
|
|
233
272
|
}
|
|
234
273
|
export function validateAgentTemplates(templates, registry, context = {}) {
|
package/lib/runtime/evaluate.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export function evaluate(policy, state, request, evidence){
|
|
|
28
28
|
const actor=state.identities.find(i=>i.actorRef===request.actorRef);
|
|
29
29
|
if(!actor)return result('hold','runtime.identity','platform identity unresolved',['platform-identity']);
|
|
30
30
|
const role=actor.role;
|
|
31
|
-
const roleRule={orchestrator:'role.orchestrator-boundary',scouter:'role.scouter-read-only',planner:'role.planner-draft-only',implementer:'role.implementer-implementation',tester:'role.tester-verification',reviewer:'role.reviewer-independent'}[role]??'runtime.identity';
|
|
31
|
+
const roleRule={orchestrator:'role.orchestrator-boundary',scouter:'role.scouter-read-only',architect:'role.architect-draft-only',planner:'role.planner-draft-only',implementer:'role.implementer-implementation',tester:'role.tester-verification',reviewer:'role.reviewer-independent'}[role]??'runtime.identity';
|
|
32
32
|
if(!ROLE_OPERATIONS[role]?.includes(request.operation))return result('deny',GIT_OPERATIONS.includes(request.operation)?'git.specialists-deny':roleRule,'operation forbidden for assigned role');
|
|
33
33
|
const lease=state.leases.find(l=>l.actorRef===actor.actorRef);
|
|
34
34
|
if(lease?.status==='retired')return result('deny','runtime.identity','retired identity');
|
|
@@ -84,11 +84,12 @@ export function evaluate(policy, state, request, evidence){
|
|
|
84
84
|
if(d.temporary&&!same(d.temporary,approval.scope.temporary))return result('hold','runtime.assignment','delegated temporary scope not approved',['delegated-temporary-scope']);
|
|
85
85
|
if(state.assignments.some(a=>a.assignmentId===request.requestId||a.correlationRef===d.correlationRef))return result('hold','runtime.identity','assignment correlation already registered',['new-assignment-correlation']);
|
|
86
86
|
const next=structuredClone(stored);
|
|
87
|
-
if(d.role==='planner'){
|
|
87
|
+
if(d.role==='planner'||d.role==='architect'){
|
|
88
88
|
const stage=state.plannerLedger?.stages.find(s=>s.id===d.plannerCall?.stageId),proof=fact('planner-call');
|
|
89
89
|
const contract=stage&&{document:stage.document,inputVersion:stage.inputVersion,criteriaVersion:stage.criteriaVersion,scopeVersion:stage.scopeVersion};
|
|
90
90
|
if(!stage||stage.workflowId!==state.workflowId||stage.approvalRef!==approval.id||!same(approval.scope.plannerStage,contract)||!d.paths.includes(stage.document.path)||proof?.sourceRef!==correlation.sourceRef||!same({stageId:proof?.data.stageId,inputVersion:proof?.data.inputVersion,criteriaVersion:proof?.data.criteriaVersion,scopeVersion:proof?.data.scopeVersion},{stageId:stage.id,inputVersion:stage.inputVersion,criteriaVersion:stage.criteriaVersion,scopeVersion:stage.scopeVersion}))return result('hold','runtime.planner-call','Current approved Planner stage and provider evidence required',['planner-stage-ledger','planner-call-evidence']);
|
|
91
91
|
if(state.planningDepth==='Bounded'&&stage.document.kind==='spec')return result('hold','runtime.planner-call','Bounded depth has no spec stage',['approved-spec']);
|
|
92
|
+
if((d.role==='architect')!==(stage.document.kind==='spec'))return result('hold','runtime.planner-call','Architect binds only spec stages and Planner only plan stages',['planner-stage-role']);
|
|
92
93
|
if(stage.document.kind==='plan'&&state.planningDepth!=='Bounded'){
|
|
93
94
|
const reviewedSpecStage=state.plannerLedger.stages.some(s=>s.workflowId===state.workflowId&&s.document.kind==='spec'&&s.ready===true&&s.review.full===true&&s.review.complete===true&&s.scopeVersion===stage.scopeVersion);
|
|
94
95
|
const approvedSpec=reviewedSpecStage||state.documents.some(doc=>doc.kind==='spec'&&state.approvals.some(a=>a.id===doc.approvalRef&&a.contentHash===doc.contentHash&&evidence.provenance.some(p=>p.id===a.id&&p.messageRef===a.messageRef&&p.contentHash===doc.contentHash&&p.verification.sourceRef===a.messageRef)));
|
|
@@ -98,7 +99,7 @@ export function evaluate(policy, state, request, evidence){
|
|
|
98
99
|
if(planner.decision!=='allow')return planner;
|
|
99
100
|
next.plannerLedger.stages[next.plannerLedger.stages.findIndex(s=>s.id===stage.id)]=planner.proposedTransition;
|
|
100
101
|
}
|
|
101
|
-
next.assignments.push({assignmentId:request.requestId,requestId:request.requestId,requestedBy:request.actorRef,status:'pending',actorRef:null,platform:request.platform,correlationRef:d.correlationRef,role:d.role,taskId:d.taskId,paths:[...d.paths],operations:[...d.operations],approvalRef:d.approvalRef,...(d.role==='planner'?{plannerStageId:d.plannerCall.stageId}:{}),...(d.checks?{checks:structuredClone(d.checks)}:{}),...(d.temporary?{temporary:structuredClone(d.temporary)}:{})});
|
|
102
|
+
next.assignments.push({assignmentId:request.requestId,requestId:request.requestId,requestedBy:request.actorRef,status:'pending',actorRef:null,platform:request.platform,correlationRef:d.correlationRef,role:d.role,taskId:d.taskId,paths:[...d.paths],operations:[...d.operations],approvalRef:d.approvalRef,...((d.role==='planner'||d.role==='architect')?{plannerStageId:d.plannerCall.stageId}:{}),...(d.checks?{checks:structuredClone(d.checks)}:{}),...(d.temporary?{temporary:structuredClone(d.temporary)}:{})});
|
|
102
103
|
try{validateWorkflowState(next);}catch{return result('hold','runtime.assignment','invalid pending assignment scope',['valid-assignment']);}
|
|
103
104
|
return {...result('allow','runtime.assignment','pending assignment authorized; observed spawn result still required'),proposedTransition:next};
|
|
104
105
|
}
|
package/lib/runtime/identity.mjs
CHANGED
|
@@ -41,7 +41,7 @@ export async function recordPlannerAgentObservation({statePath,expectedRevision,
|
|
|
41
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');
|
|
42
42
|
const state=validateWorkflowState(JSON.parse(await fs.readFile(statePath,'utf8')),{preserveStoredOperations:true}),eventHash=fingerprintRequest({input,observation:observation??null});
|
|
43
43
|
if(state.plannerObservations?.some(o=>o.eventHash===eventHash))return {decision:'hold',reason:'Observation replay',proposedTransition:null,replayed:true};
|
|
44
|
-
const candidates=state.assignments.filter(a=>a.status==='pending'&&a.role==='planner');
|
|
44
|
+
const candidates=state.assignments.filter(a=>a.status==='pending'&&(a.role==='planner'||a.role==='architect'));
|
|
45
45
|
let decision={decision:'hold',reason:'Raw event lacks verified assignment correlation',proposedTransition:null};
|
|
46
46
|
if(state.revision!==expectedRevision)decision.reason='Stale provider context cannot bind identity';
|
|
47
47
|
else if(observation?.actorRef===input.agent_id&&observation.platform===platform)decision=registerAgentObservation(state,observation);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/** Canonical semantic operations, independent of platform tool aliases. */
|
|
2
|
-
export const ROLES = Object.freeze(['orchestrator','scouter','planner','implementer','tester','reviewer']);
|
|
2
|
+
export const ROLES = Object.freeze(['orchestrator','scouter','architect','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
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
6
|
export const LEGACY_OPERATIONS = Object.freeze({qa: 'test'});
|
|
7
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']});
|
|
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'],architect:['read','draft'],planner:['read','draft'],implementer:['read','write','check'],tester:['read','check','temporary-write'],reviewer:['read','review']});
|
|
9
9
|
|
|
10
10
|
/** Compare a stored role without rewriting historical evidence. */
|
|
11
11
|
export function canonicalCooperativeRole(role) {
|
|
@@ -6,27 +6,29 @@ import {GEMINI_CONTRACT} from './gemini-stream.mjs';
|
|
|
6
6
|
import {CODEX_PROFILE_ARGS_FORM, CODEX_PROFILE_GIT_ENTRIES, DEFAULT_POLICY, effectiveClaudeSandboxSettings} from './role-dispatch-policy.mjs';
|
|
7
7
|
import {TOOL_PATHS, TOOL_UNIX_SOCKETS} from './tool-access.mjs';
|
|
8
8
|
|
|
9
|
-
const ROLES = ['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer'];
|
|
9
|
+
const ROLES = ['arc_scouter', 'arc_architect', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer'];
|
|
10
10
|
const deepFreeze = value => { for (const child of Object.values(value)) if (child && typeof child === 'object') deepFreeze(child); return Object.freeze(value); };
|
|
11
11
|
export const ROLE_BRIDGE_PERMISSIONS = deepFreeze({
|
|
12
12
|
claude: {
|
|
13
13
|
arc_scouter: {permissionMode: 'default', sandbox: false, allowedTools: ['WebFetch', 'WebSearch']},
|
|
14
|
+
arc_architect: {permissionMode: 'default', sandbox: false},
|
|
14
15
|
arc_planner: {permissionMode: 'default', sandbox: false},
|
|
15
16
|
arc_implementer: {permissionMode: 'acceptEdits', sandbox: true}, arc_tester: {permissionMode: 'default', sandbox: true}, arc_reviewer: {permissionMode: 'default', sandbox: false}
|
|
16
17
|
},
|
|
17
18
|
gemini: {
|
|
18
|
-
arc_scouter: {approvalMode: 'plan', sandbox: false}, arc_planner: {approvalMode: 'plan', sandbox: false},
|
|
19
|
+
arc_scouter: {approvalMode: 'plan', sandbox: false}, arc_architect: {approvalMode: 'plan', sandbox: false}, arc_planner: {approvalMode: 'plan', sandbox: false},
|
|
19
20
|
arc_implementer: {approvalMode: 'auto_edit', sandbox: true}, arc_tester: {approvalMode: 'auto_edit', sandbox: true}, arc_reviewer: {approvalMode: 'plan', sandbox: false}
|
|
20
21
|
},
|
|
21
22
|
grok: {
|
|
22
23
|
arc_scouter: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
24
|
+
arc_architect: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
23
25
|
arc_planner: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
24
26
|
arc_reviewer: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
25
27
|
arc_implementer: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
26
28
|
arc_tester: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
27
29
|
},
|
|
28
30
|
codex: {
|
|
29
|
-
arc_scouter: {sandboxMode: 'read-only', search: true}, arc_planner: {sandboxMode: 'read-only', search: false},
|
|
31
|
+
arc_scouter: {sandboxMode: 'read-only', search: true}, arc_architect: {sandboxMode: 'read-only', search: false}, arc_planner: {sandboxMode: 'read-only', search: false},
|
|
30
32
|
arc_implementer: {sandboxMode: 'workspace-write', search: false}, arc_tester: {sandboxMode: 'workspace-write', search: false}, arc_reviewer: {sandboxMode: 'read-only', search: false}
|
|
31
33
|
}
|
|
32
34
|
});
|
|
@@ -5,7 +5,8 @@ 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
7
|
import {displayRoutingRole} from './role-routing-config.mjs';
|
|
8
|
-
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
|
|
8
|
+
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease, readWorktreeRecord, writeWorktreeRecord, removeWorktreeRecord, worktreeWriters} from './role-dispatch-store.mjs';
|
|
9
|
+
import {pathsOverlap} from './role-observe.mjs';
|
|
9
10
|
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
|
|
10
11
|
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation, reapRecordedDescendants, reapRecordedHostServices} from './role-supervisor.mjs';
|
|
11
12
|
|
|
@@ -39,6 +40,18 @@ const residualOf=error=>Array.isArray(error?.residualPaths)?error.residualPaths:
|
|
|
39
40
|
const hold=(context,dispatchId,code,error)=>{const result=blank(context,dispatchId,'hold',code);const residual=residualOf(error);if(residual)result.residualPaths=residual;return result;};
|
|
40
41
|
const classifyLock=error=>{const code=error?.code==='ARC_ROUTING_LOCK_RELEASE'&&error.failure?error.failure.code:error?.code;return code==='ARC_HOST_SANDBOX'?'host_sandbox_blocked':'activation_unverified';};
|
|
41
42
|
|
|
43
|
+
async function overlapHold({anchorHome,lease,worktree,runtimePlatforms}){
|
|
44
|
+
const leases=await listLeases(anchorHome,{runtimePlatforms});
|
|
45
|
+
const records=new Map();
|
|
46
|
+
for(const item of leases){
|
|
47
|
+
if(item.route==='bridge'&&(item.role==='arc_implementer'||item.role==='arc_tester')){
|
|
48
|
+
records.set(item.dispatchId,await readWorktreeRecord(anchorHome,item.dispatchId));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const owners=worktreeWriters({leases,records,dispatchId:lease.dispatchId,worktree,terminalSinceMs:null});
|
|
52
|
+
return owners.some(owner=>pathsOverlap(owner.allowedPaths,lease.allowedPaths));
|
|
53
|
+
}
|
|
54
|
+
|
|
42
55
|
/** Starts the detached supervisor for a reserved bridge lease; the supervisor, not this function, spawns the child. */
|
|
43
56
|
export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now(),policy=DEFAULT_POLICY,startSupervisor:starter=startSupervisor,observeToolContext}={}){
|
|
44
57
|
if(!validContext(context)||typeof dispatchId!=='string'||!ID.test(dispatchId)||dispatchId.startsWith('.')||typeof brief!=='string'){return blank(context,dispatchId,'deny','invalid_request');}
|
|
@@ -59,6 +72,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
59
72
|
const capabilities=capabilityReasons({hostPlatform:lease.hostPlatform,targetPlatform:platform,route:lease.route,runtimePlatforms});
|
|
60
73
|
if(capabilities.length){result=blank(context,dispatchId,'hold',capabilities[0]);return;}
|
|
61
74
|
let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
75
|
+
if(await overlapHold({anchorHome,lease,worktree:target.realpath,runtimePlatforms})){result=blank(context,dispatchId,'hold','allowed_paths_overlap');return;}
|
|
62
76
|
const directory=artifactDirectory(target,lease.workflowId,dispatchId),resultPath=path.join(directory,'result.md');
|
|
63
77
|
let invocation;try{invocation=await buildBridgeInvocation({lease,config,homes,worktree:target.realpath,resultPath,userHome:context.userHome,env:context.env??process.env,target,runtimePlatforms,policy,observeToolContext});}catch(error){result=blank(context,dispatchId,'hold',error.reasonCode??'activation_unverified');return;}
|
|
64
78
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(directory,0o700);
|
|
@@ -68,6 +82,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
68
82
|
if(!probe.ok){result=hold(context,dispatchId,probe.code,probe);return;}
|
|
69
83
|
}
|
|
70
84
|
let supervisor;
|
|
85
|
+
await writeWorktreeRecord(anchorHome,dispatchId,{segment:lease.segment,worktree:target.realpath});
|
|
71
86
|
try{supervisor=await starter({codexHome:anchorHome,dispatchId,cwd:target.realpath,userHome:context.userHome,env:context.env??process.env});}
|
|
72
87
|
catch{result=blank(context,dispatchId,'hold','host_sandbox_blocked');return;}
|
|
73
88
|
const next=await writeLease(anchorHome,{...lease,state:'starting',supervisor,argsDigest:invocation.argsDigest,resultPath},{now,runtimePlatforms});
|
|
@@ -196,6 +211,7 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
196
211
|
if(limits&&(await listLeases(anchorHome,{runtimePlatforms})).filter(item=>item.route==='bridge'&&NON_TERMINAL_STATES.includes(item.state)).length+1>limits.maxConcurrent)codes.add('capacity_exhausted');
|
|
197
212
|
if(codes.size){result=blank(context,dispatchId,'hold','activation_unverified');result.reasons=[...codes].map(reason);return;}
|
|
198
213
|
let target;try{target=await resolveWorktree(context.cwd);}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
214
|
+
if(await overlapHold({anchorHome,lease,worktree:target.realpath,runtimePlatforms})){result=blank(context,dispatchId,'hold','allowed_paths_overlap');return;}
|
|
199
215
|
const segment=lease.segment+1,directory=segmentDirectory(target,lease.workflowId,dispatchId,segment),resultPath=path.join(directory,'result.md');
|
|
200
216
|
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;}
|
|
201
217
|
await fsp.mkdir(directory,{recursive:true,mode:0o700});await fsp.chmod(path.dirname(directory),0o700);await fsp.chmod(directory,0o700);
|
|
@@ -204,10 +220,16 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
204
220
|
const probe=await probeHomeWritable(homes[platform]);
|
|
205
221
|
if(!probe.ok){result=hold(context,dispatchId,probe.code,probe);return;}
|
|
206
222
|
}
|
|
223
|
+
const previousRecord=await readWorktreeRecord(anchorHome,dispatchId);
|
|
224
|
+
await writeWorktreeRecord(anchorHome,dispatchId,{segment,worktree:target.realpath});
|
|
207
225
|
await clearCancel(anchorHome,dispatchId);
|
|
208
226
|
let supervisor;
|
|
209
227
|
try{supervisor=await starter({codexHome:anchorHome,dispatchId,cwd:target.realpath,userHome:context.userHome,env:context.env??process.env});}
|
|
210
|
-
catch{
|
|
228
|
+
catch{
|
|
229
|
+
if(previousRecord)await writeWorktreeRecord(anchorHome,dispatchId,previousRecord);
|
|
230
|
+
else await removeWorktreeRecord(anchorHome,dispatchId);
|
|
231
|
+
result=blank(context,dispatchId,'hold','host_sandbox_blocked');return;
|
|
232
|
+
}
|
|
211
233
|
const claims=lease.claims?{...lease.claims,terminal:{level:'unverified',source:'none'}}:null;
|
|
212
234
|
const next=await writeLease(anchorHome,{...lease,state:'starting',supervisor,child:null,argsDigest:invocation.argsDigest,resultPath,segment,claims,reasons:[]},{now,runtimePlatforms});
|
|
213
235
|
result={...view(next,'allow'),segment};
|
|
@@ -41,7 +41,7 @@ export const effectiveClaudeSandboxSettings = policy => policy?.gates?.G1 === 'p
|
|
|
41
41
|
export const CATALOG_MODEL_ALIASES = Object.freeze(['fable', 'opus', 'sonnet', 'haiku']);
|
|
42
42
|
export const CODEX_DELEGATION_CALL_NAMES = Object.freeze(['spawn_agent', 'wait_agent']);
|
|
43
43
|
export const DESKTOP_CHECKLIST_PASSED = Object.freeze({'claude-desktop': false, 'codex-desktop': false});
|
|
44
|
-
export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_planner: 20, arc_implementer: 60, arc_tester: 60, arc_reviewer: 20});
|
|
44
|
+
export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_architect: 20, arc_planner: 20, arc_implementer: 60, arc_tester: 60, arc_reviewer: 20});
|
|
45
45
|
export const HEARTBEAT_MS = 5000;
|
|
46
46
|
export const SUPERVISOR_LOST_MS = 30000;
|
|
47
47
|
export const OBSERVE_MAX_WAIT_MS = 540000;
|
|
@@ -86,6 +86,7 @@ export const RELEASE_CONDITIONS = Object.freeze({
|
|
|
86
86
|
environment_unverified: `Desktop hosts are held in this release. If this session is not running inside a Desktop app (for example a terminal or IDE terminal session), declare a CLI environment (${cliEnvironments}) instead; otherwise use a CLI host or a later ARC update that changes the support status.`,
|
|
87
87
|
host_sandbox_blocked: 'Allow the host to write the anchor home and keep a detached supervisor alive, with explicit user approval.',
|
|
88
88
|
capacity_exhausted: 'Finish or release active bridge executions, or raise the host limits.',
|
|
89
|
+
allowed_paths_overlap: 'Wait until the started bridge dispatch whose allowedPaths overlap in the same worktree reaches a terminal state, resolving it first when it is unknown, or prepare a new dispatch with non-overlapping allowedPaths; then run or resume again.',
|
|
89
90
|
permission_scope_unverified: 'Update ARC and verify enforcement of the role permissions and approved scope before starting.',
|
|
90
91
|
native_profile_reload_unverified: 'Verify that the host session loaded the requested profile revision.',
|
|
91
92
|
revision_changed: 'Re-run routing-status and prepare a new dispatch under the current revision.',
|
|
@@ -77,6 +77,7 @@ export async function writeLease(codexHome, lease, {now = Date.now(), runtimePla
|
|
|
77
77
|
return value;
|
|
78
78
|
}
|
|
79
79
|
const HEARTBEAT_SUFFIX = '.heartbeat.json';
|
|
80
|
+
const WORKTREE_SUFFIX = '.worktree';
|
|
80
81
|
const leaseFiles = async codexHome => {
|
|
81
82
|
try { return (await fsp.readdir(dispatchDirectory(codexHome))).filter(name => name.endsWith('.json') && !name.endsWith(HEARTBEAT_SUFFIX) && !name.startsWith('.')).sort(); }
|
|
82
83
|
catch (error) { if (error.code === 'ENOENT') return []; throw error; }
|
|
@@ -97,7 +98,7 @@ export async function pruneTerminalLeases(codexHome, {now = Date.now(), retentio
|
|
|
97
98
|
const updated = Date.parse(lease.updatedAt);
|
|
98
99
|
if (!TERMINAL_STATES.includes(lease.state) || !Number.isFinite(updated) || now - updated <= retentionMs) continue;
|
|
99
100
|
await fsp.unlink(file); removed += 1;
|
|
100
|
-
for (const
|
|
101
|
+
for (const suffix of [HEARTBEAT_SUFFIX, '.cancel', WORKTREE_SUFFIX]) await fsp.unlink(sidecarPath(codexHome, lease.dispatchId, suffix)).catch(() => {});
|
|
101
102
|
} catch { errors += 1; }
|
|
102
103
|
}
|
|
103
104
|
return {removed, errors};
|
|
@@ -117,6 +118,48 @@ export function readHostLimits(hostHome) {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
const sidecarPath = (codexHome, dispatchId, suffix) => path.join(dispatchDirectory(codexHome), `${path.basename(leasePath(codexHome, dispatchId), '.json')}${suffix}`);
|
|
121
|
+
const validWorktree = (segment, worktree) => Number.isInteger(segment) && segment >= 0 && typeof worktree === 'string' && path.isAbsolute(worktree);
|
|
122
|
+
|
|
123
|
+
/** Records the worktree for one segment while the caller holds the routing lock. */
|
|
124
|
+
export async function writeWorktreeRecord(codexHome, dispatchId, {segment, worktree}) {
|
|
125
|
+
if (!validWorktree(segment, worktree)) throw Error('Invalid worktree record');
|
|
126
|
+
const target = sidecarPath(codexHome, dispatchId, WORKTREE_SUFFIX);
|
|
127
|
+
const temp = path.join(dispatchDirectory(codexHome), `.${dispatchId}.${crypto.randomUUID()}.wt.tmp`);
|
|
128
|
+
try {
|
|
129
|
+
const handle = await fsp.open(temp, 'wx', 0o600);
|
|
130
|
+
try { await handle.writeFile(JSON.stringify({version: 1, dispatchId, segment, worktree}) + '\n'); } finally { await handle.close(); }
|
|
131
|
+
await fsp.rename(temp, target);
|
|
132
|
+
} catch (error) { await fsp.unlink(temp).catch(() => {}); throw error; }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export async function readWorktreeRecord(codexHome, dispatchId) {
|
|
136
|
+
try {
|
|
137
|
+
const value = JSON.parse(await fsp.readFile(sidecarPath(codexHome, dispatchId, WORKTREE_SUFFIX), 'utf8'));
|
|
138
|
+
if (!isObject(value) || Object.keys(value).length !== 4 || value.version !== 1 ||
|
|
139
|
+
value.dispatchId !== dispatchId || !validWorktree(value.segment, value.worktree)) return null;
|
|
140
|
+
return value;
|
|
141
|
+
} catch { return null; }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function removeWorktreeRecord(codexHome, dispatchId) {
|
|
145
|
+
try { await fsp.unlink(sidecarPath(codexHome, dispatchId, WORKTREE_SUFFIX)); }
|
|
146
|
+
catch (error) { if (error.code !== 'ENOENT') throw error; }
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function worktreeWriters({leases, records, dispatchId, worktree, terminalSinceMs, excludeUnknown = false}) {
|
|
150
|
+
const writers = leases.filter(lease => {
|
|
151
|
+
if (lease.dispatchId === dispatchId || lease.route !== 'bridge' ||
|
|
152
|
+
(lease.role !== 'arc_implementer' && lease.role !== 'arc_tester') || !lease.allowedPaths.length) return false;
|
|
153
|
+
if (excludeUnknown && lease.state === 'unknown') return false;
|
|
154
|
+
const record = records.get(lease.dispatchId);
|
|
155
|
+
if (!record || record.segment !== lease.segment || record.worktree !== worktree) return false;
|
|
156
|
+
return (lease.state !== 'reserved' && NON_TERMINAL_STATES.includes(lease.state)) ||
|
|
157
|
+
(terminalSinceMs !== null && TERMINAL_STATES.includes(lease.state) && Date.parse(lease.updatedAt) >= terminalSinceMs);
|
|
158
|
+
});
|
|
159
|
+
return writers.sort((a, b) => a.dispatchId < b.dispatchId ? -1 : a.dispatchId > b.dispatchId ? 1 : 0)
|
|
160
|
+
.map(({dispatchId, allowedPaths}) => ({dispatchId, allowedPaths}));
|
|
161
|
+
}
|
|
162
|
+
|
|
120
163
|
/** The supervisor alone writes its heartbeat; no routing lock is needed because the file is replaced atomically and holds no lease state. */
|
|
121
164
|
export async function writeHeartbeat(codexHome, dispatchId, {at, pid}) {
|
|
122
165
|
if (!Number.isFinite(at) || !Number.isInteger(pid) || pid <= 0) throw Error('Invalid heartbeat');
|
|
@@ -568,6 +568,8 @@ function otherWorktreeBranches(before, after) {
|
|
|
568
568
|
}
|
|
569
569
|
|
|
570
570
|
const allowedBy = (allowedPaths, file) => allowedPaths.some(entry => entry.endsWith('/') ? file.startsWith(entry) : file === entry);
|
|
571
|
+
export const pathsOverlap = (a, b) => a.some(file => allowedBy(b, file)) || b.some(file => allowedBy(a, file));
|
|
572
|
+
const byPath = (a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0;
|
|
571
573
|
const hasBranchRefs = (before, after) => before.branchRef !== undefined && after.branchRef !== undefined;
|
|
572
574
|
const branchChanged = (before, after) => hasBranchRefs(before, after)
|
|
573
575
|
? before.branchRef !== after.branchRef
|
|
@@ -638,7 +640,7 @@ export async function observeHeadAdvance(root, before, after, role, allowedPaths
|
|
|
638
640
|
* commits. Ordinary worktree snapshots omit Git-ignored paths. Control files
|
|
639
641
|
* are compared regardless of role and allowedPaths.
|
|
640
642
|
*/
|
|
641
|
-
export function detectViolations({role, allowedPaths, before, after, headAdvance}) {
|
|
643
|
+
export function detectViolations({role, allowedPaths, before, after, headAdvance, otherOwners = []}) {
|
|
642
644
|
const branchSwitched = branchChanged(before, after);
|
|
643
645
|
const headMoved = before.head !== after.head;
|
|
644
646
|
const targetBranch = before.branchRef;
|
|
@@ -663,8 +665,12 @@ export function detectViolations({role, allowedPaths, before, after, headAdvance
|
|
|
663
665
|
}
|
|
664
666
|
const allowed = (role === 'arc_implementer' || role === 'arc_tester') && Array.isArray(allowedPaths) ? allowedPaths : [];
|
|
665
667
|
const changed = new Set();
|
|
668
|
+
const attributedPaths = [];
|
|
666
669
|
for (const file of new Set([...before.entries.keys(), ...after.entries.keys()])) {
|
|
667
|
-
if (before.entries.get(file)
|
|
670
|
+
if (before.entries.get(file) === after.entries.get(file) || allowedBy(allowed, file)) continue;
|
|
671
|
+
const owners = otherOwners.filter(owner => allowedBy(owner.allowedPaths, file)).map(owner => owner.dispatchId).sort();
|
|
672
|
+
if (owners.length) attributedPaths.push({path: file, owners});
|
|
673
|
+
else changed.add(file);
|
|
668
674
|
}
|
|
669
675
|
if (headAdvance?.state === 'rejected') {
|
|
670
676
|
for (const file of headAdvance.outOfScopePaths ?? []) changed.add(file);
|
|
@@ -679,15 +685,17 @@ export function detectViolations({role, allowedPaths, before, after, headAdvance
|
|
|
679
685
|
}
|
|
680
686
|
const reason = headChanged || refsChanged || changedPaths.length || controlChanged.length ? 'permission_violation_observed' : null;
|
|
681
687
|
const toleratedCommitPaths = acceptedAdvance ? [...headAdvance.paths].sort() : [];
|
|
682
|
-
return {reason, changedPaths, headChanged, refsChanged, controlChanged: controlChanged.sort(), toleratedRefs: toleratedRefs.sort(), toleratedControl, toleratedCommitPaths};
|
|
688
|
+
return {reason, changedPaths, headChanged, refsChanged, controlChanged: controlChanged.sort(), toleratedRefs: toleratedRefs.sort(), toleratedControl, toleratedCommitPaths, attributedPaths: attributedPaths.sort(byPath)};
|
|
683
689
|
}
|
|
684
690
|
|
|
685
|
-
export function toleratedRecord({toleratedRefs = [], toleratedControl = [], toleratedCommitPaths = []} = {}) {
|
|
691
|
+
export function toleratedRecord({toleratedRefs = [], toleratedControl = [], toleratedCommitPaths = [], attributedPaths = []} = {}) {
|
|
686
692
|
const record = {};
|
|
687
693
|
for (const [key, names] of [['refs', toleratedRefs], ['control', toleratedControl], ['commitPaths', toleratedCommitPaths]]) {
|
|
688
694
|
if (!names.length) continue;
|
|
689
695
|
record[key] = [...names].sort().slice(0, 100);
|
|
690
696
|
if (names.length > 100) record.truncated = true;
|
|
691
697
|
}
|
|
698
|
+
if (attributedPaths.length) record.attributed = [...attributedPaths].sort(byPath).slice(0, 100);
|
|
699
|
+
if (attributedPaths.length > 100) record.truncated = true;
|
|
692
700
|
return Object.keys(record).length ? record : null;
|
|
693
701
|
}
|
|
@@ -1,8 +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_tester', 'arc_reviewer']);
|
|
3
|
+
export const ROUTING_ROLES = Object.freeze(['arc_scouter', 'arc_architect', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer']);
|
|
4
4
|
export const LEGACY_ROUTING_ROLES = Object.freeze({arc_qa: 'arc_tester'});
|
|
5
|
-
export const ROUTING_CONFIG_VERSION =
|
|
5
|
+
export const ROUTING_CONFIG_VERSION = 4;
|
|
6
6
|
const validText = value => typeof value === 'string' && value.length > 0 && value === value.trim() && !/[\p{Cc}\u2028\u2029]/u.test(value);
|
|
7
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));
|
|
8
8
|
const v1Platforms = Object.freeze(['codex', 'claude']);
|
|
@@ -22,13 +22,18 @@ export function validRoleValues(platform, model, effort, {runtimePlatforms} = {}
|
|
|
22
22
|
}
|
|
23
23
|
export function validateRoleRoutingConfig(config, opts = {}) {
|
|
24
24
|
const keys = ['version', 'revision', 'platforms', 'roles'];
|
|
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');
|
|
25
|
+
if (!(exact(config, keys) || (config?.version === 1 && exact(config, ['version', 'revision', 'roles']))) || ![1, 2, 3, ROUTING_CONFIG_VERSION].includes(config.version) || !validText(config.revision)) throw Error('Invalid role routing configuration');
|
|
26
26
|
let roles = config.roles;
|
|
27
27
|
if (roles && typeof roles === 'object' && !Array.isArray(roles) && Object.hasOwn(roles, 'arc_qa')) {
|
|
28
|
-
if (config.version
|
|
28
|
+
if (config.version >= 3 || Object.hasOwn(roles, 'arc_tester')) throw Error('Invalid role routing configuration');
|
|
29
29
|
roles = Object.fromEntries(Object.entries(roles).map(([role, fields]) => [Object.hasOwn(LEGACY_ROUTING_ROLES, role) ? LEGACY_ROUTING_ROLES[role] : role, fields]));
|
|
30
30
|
}
|
|
31
|
+
if (config.version < ROUTING_CONFIG_VERSION && roles && typeof roles === 'object' && !Array.isArray(roles)
|
|
32
|
+
&& !Object.hasOwn(roles, 'arc_architect') && Object.hasOwn(roles, 'arc_planner')) {
|
|
33
|
+
roles = {...roles, arc_architect: structuredClone(roles.arc_planner)};
|
|
34
|
+
}
|
|
31
35
|
if (!exact(roles, ROUTING_ROLES)) throw Error('Invalid role routing configuration');
|
|
36
|
+
roles = Object.fromEntries(ROUTING_ROLES.map(role => [role, roles[role]]));
|
|
32
37
|
const registry = runtimeRegistryOf(opts);
|
|
33
38
|
const platforms = config.version === 1 && !Object.hasOwn(config, 'platforms') ? [...v1Platforms] : config.platforms;
|
|
34
39
|
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');
|
|
@@ -11,7 +11,7 @@ import {GROK_CONTRACT, normalizeGrokStreamEvent, evaluateGrokObservation} from '
|
|
|
11
11
|
import {GROK_SANDBOX_RELATIVE, grokSandboxProfileName, renderGrokSandboxProfile, grokProfileCovered, inspectGrokProfileSlot, checkGrokHome, createGrokSandboxProfile, verifyGrokSandboxProfile, removeGrokSandboxProfile, grokEventsBaseline, readGrokProfileApplied, grokConfigSecurityProjection} from './grok-sandbox.mjs';
|
|
12
12
|
import {GEMINI_CONTRACT, normalizeGeminiStreamEvent, evaluateGeminiObservation} from './gemini-stream.mjs';
|
|
13
13
|
import {CODEX_PROFILE_SANDBOX_TYPE, DEFAULT_POLICY, DESCENDANT_LIMIT, DESCENDANT_SAMPLE_MS, reason, bridgeGateReasons} from './role-dispatch-policy.mjs';
|
|
14
|
-
import {readLease, writeLease, writeHeartbeat, cancelRequested, dispatchDirectory, TERMINAL_STATES} from './role-dispatch-store.mjs';
|
|
14
|
+
import {readLease, writeLease, writeHeartbeat, cancelRequested, dispatchDirectory, TERMINAL_STATES, listLeases, readWorktreeRecord, worktreeWriters} from './role-dispatch-store.mjs';
|
|
15
15
|
import {withRoutingLock, readActivation, resolveRuntimeHomes} from './role-routing.mjs';
|
|
16
16
|
import {resolveLocalCli, localCliEnvironment} from './local-cli.mjs';
|
|
17
17
|
import {parseCompositeProfile, buildBridgeArgs, argsDigest, ROLE_BRIDGE_PERMISSIONS} from './role-bridge-args.mjs';
|
|
@@ -743,6 +743,7 @@ export async function runSupervisor(options) {
|
|
|
743
743
|
control: await snapshotControlFiles({gitCommonDir: target.gitCommonDir, gitDir: target.gitDir, worktree: target.realpath, extra}),
|
|
744
744
|
});
|
|
745
745
|
let before;
|
|
746
|
+
const sinceMs = Date.now();
|
|
746
747
|
try { before = await snapshot(); } catch { return await failWithProfileCleanup('execution_failed'); }
|
|
747
748
|
|
|
748
749
|
if (invocation.promptFile) {
|
|
@@ -925,9 +926,22 @@ export async function runSupervisor(options) {
|
|
|
925
926
|
}
|
|
926
927
|
|
|
927
928
|
let after = null;
|
|
929
|
+
const otherOwners = await locked(async () => {
|
|
930
|
+
const worktree = target.realpath;
|
|
931
|
+
const own = await readWorktreeRecord(codexHome, dispatchId);
|
|
932
|
+
if (own?.segment !== lease.segment || own.worktree !== worktree) return [];
|
|
933
|
+
const leases = await listLeases(codexHome, {runtimePlatforms});
|
|
934
|
+
const records = new Map();
|
|
935
|
+
for (const item of leases) {
|
|
936
|
+
if (item.dispatchId !== dispatchId && item.route === 'bridge' && (item.role === 'arc_implementer' || item.role === 'arc_tester')) {
|
|
937
|
+
records.set(item.dispatchId, await readWorktreeRecord(codexHome, item.dispatchId));
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
return worktreeWriters({leases, records, dispatchId, worktree, terminalSinceMs: sinceMs, excludeUnknown: true});
|
|
941
|
+
}).catch(() => []);
|
|
928
942
|
try { after = await snapshot(); } catch { after = null; }
|
|
929
943
|
const headAdvance = after ? await observeHeadAdvance(target.realpath, before, after, lease.role, lease.allowedPaths) : null;
|
|
930
|
-
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after, headAdvance}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false, controlChanged: [], toleratedRefs: [], toleratedControl: [], toleratedCommitPaths: []};
|
|
944
|
+
const violations = after ? detectViolations({role: lease.role, allowedPaths: lease.allowedPaths, before, after, headAdvance, otherOwners}) : {reason: null, changedPaths: [], headChanged: false, refsChanged: false, controlChanged: [], toleratedRefs: [], toleratedControl: [], toleratedCommitPaths: [], attributedPaths: []};
|
|
931
945
|
const codes = [];
|
|
932
946
|
if (state.mismatch) codes.push(state.mismatch);
|
|
933
947
|
if (state.internal) codes.push(state.internal);
|
package/lib/tui/diagram.mjs
CHANGED
|
@@ -42,7 +42,6 @@ export function diagramRows(roleRows,{columns=80,rows=24,selectedRole,blink=true
|
|
|
42
42
|
return {mode:'compact',rows:[...values.map(roleRow),'']};
|
|
43
43
|
}
|
|
44
44
|
const center=Math.floor(boxWidth/2),middle=boxWidth+2+center,right=2*(boxWidth+2)+center;
|
|
45
|
-
const indent=Math.floor((total-(boxWidth*2+2))/2),bottomLeft=indent+center,bottomRight=bottomLeft+boxWidth+2;
|
|
46
45
|
const box=(value,index,up)=>{
|
|
47
46
|
const hidden=index===selectedRole&&!blink,edge=hidden?' ':'│',label=(index===selectedRole?'> ':'')+value.label;
|
|
48
47
|
const top=hidden?' '+label+' '.repeat(boxWidth-3-cells(label)):'┌─ '+label+' '+'─'.repeat(boxWidth-cells(label)-5)+'┐';
|
|
@@ -62,7 +61,7 @@ export function diagramRows(roleRows,{columns=80,rows=24,selectedRole,blink=true
|
|
|
62
61
|
};
|
|
63
62
|
return {mode:'full',rows:[
|
|
64
63
|
...group([0,1,2],0,false),bus(center,right,[center,middle,right],true),
|
|
65
|
-
' '.repeat(Math.max(0,middle-6))+'Orchestrator',bus(
|
|
66
|
-
...group([3,4],
|
|
64
|
+
' '.repeat(Math.max(0,middle-6))+'Orchestrator',bus(center,right,[center,middle,right]),
|
|
65
|
+
...group([3,4,5],0,true),
|
|
67
66
|
]};
|
|
68
67
|
}
|