@yunhozz/arc 0.5.0 → 0.5.2
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 +152 -155
- package/README.md +101 -35
- 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 +7 -7
- package/claude/skill/models.toml +8 -8
- package/claude/skill/references/arc-visual-companion.md +2 -2
- package/claude/skill/references/commit.md +3 -3
- package/claude/skill/references/coordination.md +21 -25
- 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 +66 -39
- 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 +8 -8
- package/codex/skill/models.toml +8 -8
- package/codex/skill/references/arc-visual-companion.md +3 -3
- package/codex/skill/references/commit.md +4 -4
- package/codex/skill/references/coordination.md +20 -24
- 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 +67 -40
- package/codex/skill/references/worktree-creation.md +2 -0
- package/codex/skill/scripts/model_config.py +28 -15
- package/gemini/agents/arc-implementer.md +8 -8
- package/gemini/agents/arc-planner.md +6 -6
- package/gemini/agents/arc-reviewer.md +6 -6
- package/gemini/agents/arc-scouter.md +6 -6
- package/gemini/agents/{arc-qa.md → arc-tester.md} +11 -11
- package/gemini/skill/SKILL.md +7 -7
- package/gemini/skill/models.toml +7 -7
- package/gemini/skill/references/arc-visual-companion.md +2 -2
- package/gemini/skill/references/commit.md +3 -3
- package/gemini/skill/references/coordination.md +21 -25
- 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 +66 -39
- 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 +7 -7
- 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 +21 -25
- 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 +66 -39
- 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 +2 -5
- package/lib/installer/targets.mjs +4 -2
- 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 +13 -13
- 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 +3 -1
- package/lib/runtime/command.mjs +27 -1
- 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/identity.mjs +10 -7
- package/lib/runtime/local-cli.mjs +9 -2
- package/lib/runtime/operations.mjs +41 -3
- package/lib/runtime/role-bridge-args.mjs +5 -5
- package/lib/runtime/role-bridge.mjs +10 -2
- package/lib/runtime/role-dispatch-policy.mjs +11 -6
- package/lib/runtime/role-dispatch-store.mjs +3 -0
- package/lib/runtime/role-observe.mjs +5 -5
- package/lib/runtime/role-routing-config.mjs +20 -6
- package/lib/runtime/role-routing.mjs +4 -3
- package/lib/runtime/schema.mjs +8 -5
- package/lib/runtime/scope.mjs +1 -1
- package/lib/runtime/store.mjs +2 -2
- package/lib/runtime/verification.mjs +15 -7
- package/lib/tui/app.mjs +36 -11
- package/lib/tui/interface.mjs +2 -2
- package/lib/tui/render.mjs +4 -2
- package/lib/tui/setup.mjs +1 -1
- package/lib/tui/terminal.mjs +5 -3
- package/lib/watch/brief.mjs +44 -0
- package/lib/watch/dispatch.mjs +44 -6
- package/lib/watch/index.mjs +107 -22
- package/lib/watch/labels.mjs +2 -1
- package/lib/watch/markdown.mjs +42 -9
- package/lib/watch/model.mjs +3 -2
- package/lib/watch/render.mjs +5 -4
- package/lib/watch/scope.mjs +125 -0
- package/lib/watch/watcher.mjs +149 -82
- package/lib/watch/worktree-menu.mjs +64 -0
- package/package.json +1 -1
- package/shared/skill/runtime/acceptance.mjs +4 -3
- package/shared/skill/runtime/bootstrap.mjs +3 -1
- package/shared/skill/runtime/command.mjs +27 -1
- 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/identity.mjs +10 -7
- package/shared/skill/runtime/local-cli.mjs +9 -2
- package/shared/skill/runtime/operations.mjs +41 -3
- package/shared/skill/runtime/role-bridge-args.mjs +5 -5
- package/shared/skill/runtime/role-bridge.mjs +10 -2
- package/shared/skill/runtime/role-dispatch-policy.mjs +11 -6
- package/shared/skill/runtime/role-dispatch-store.mjs +3 -0
- package/shared/skill/runtime/role-observe.mjs +5 -5
- 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 +4 -3
- 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/verification.mjs +15 -7
- package/lib/runtime/final-verify.mjs +0 -2158
- package/lib/runtime/node-test-reporter.mjs +0 -81
- package/lib/runtime/test-results.mjs +0 -736
- package/lib/runtime/verify-cli.mjs +0 -60
- package/shared/skill/runtime/final-verify.mjs +0 -2158
- package/shared/skill/runtime/node-test-reporter.mjs +0 -81
- package/shared/skill/runtime/test-results.mjs +0 -736
- package/shared/skill/runtime/verify-cli.mjs +0 -60
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {ROLES} from './operations.mjs';
|
|
1
|
+
import {ROLES,canonicalCooperativeRole,hasNewStoredOperationAliases,isLegacyOperation,normalizeStoredOperations} from './operations.mjs';
|
|
2
2
|
import {assertSecretFree} from './external.mjs';
|
|
3
3
|
import {object,text,validatePlannerLedger} from './schema.mjs';
|
|
4
4
|
import {absolute,validateWorkflowId} from './scope.mjs';
|
|
@@ -6,10 +6,17 @@ import {validateTargetPreparationRecord} from './target-preparation.mjs';
|
|
|
6
6
|
const fail=message=>{throw Error('Cooperative schema: '+message);};
|
|
7
7
|
const hash=value=>typeof value==='string'&&/^sha256:[a-f0-9]{64}$/.test(value);
|
|
8
8
|
const revision=value=>Number.isSafeInteger(value)&&value>=0;
|
|
9
|
-
const actor=value=>object(value)&&text(value.id)&&Object.keys(value).every(k=>['id','role'].includes(k))&&(value.role===undefined||ROLES.includes(value.role));
|
|
9
|
+
const actor=value=>object(value)&&text(value.id)&&Object.keys(value).every(k=>['id','role'].includes(k))&&(value.role===undefined||ROLES.includes(canonicalCooperativeRole(value.role)));
|
|
10
10
|
const statement=value=>object(value)&&text(value.messageRef)&&object(value.data);
|
|
11
11
|
function fields(value,allowed){if(!object(value)||Object.keys(value).some(k=>!allowed.includes(k)))fail('unexpected input field');}
|
|
12
12
|
function json(value){try{const encoded=JSON.stringify(value);if(encoded===undefined)fail('JSON input');}catch{fail('JSON input');}}
|
|
13
|
+
export function legacyCooperativeRoleDenial(input){
|
|
14
|
+
let ruleId;
|
|
15
|
+
if(input?.actor?.role==='qa')ruleId='cooperative.verification-actor';
|
|
16
|
+
else if(input?.arguments?.actor?.role==='qa'||input?.result?.data?.actor?.role==='qa')ruleId='cooperative.verification-independence';
|
|
17
|
+
else if(input?.evidence?.kind==='finding'&&input.evidence.data?.actor?.role==='qa')ruleId='cooperative.finding-resolution';
|
|
18
|
+
if(ruleId)return {decision:'deny',ruleIds:[ruleId],reason:'legacy_role_qa'};
|
|
19
|
+
}
|
|
13
20
|
export function validateCooperativeCommand(command){
|
|
14
21
|
assertSecretFree(command);fields(command,['command','input']);const {input,command:name}=command;
|
|
15
22
|
if(!['init','record','status','reconcile','prepare','result'].includes(name))fail('command');
|
|
@@ -17,6 +24,7 @@ export function validateCooperativeCommand(command){
|
|
|
17
24
|
const resultStatement=name==='reconcile'||name==='result'&&input?.operation===undefined;
|
|
18
25
|
const allowed=name==='init'?['mode','actor','selection']:name==='record'?['requestId','expectedRevision','actor','evidence']:resultStatement?['requestId','expectedRevision','actor','intentId','result']:['requestId','expectedRevision','actor','operation','taskId','arguments'];
|
|
19
26
|
fields(input,allowed);json(input);
|
|
27
|
+
// Recognize this input shape so command entry points can return the role denial.
|
|
20
28
|
if(!actor(input.actor))fail('actor attestation');
|
|
21
29
|
if(name==='init'){
|
|
22
30
|
if(!['plan','no-plan','small-task'].includes(input.mode)||!object(input.selection)||!text(input.selection.messageRef)||!hash(input.selection.contentHash)||Object.keys(input.selection).some(k=>!['messageRef','contentHash'].includes(k)))fail('target selection');
|
|
@@ -33,10 +41,10 @@ export function validateCooperativeCommand(command){
|
|
|
33
41
|
if(!text(input.intentId)||!statement(input.result)||!['succeeded','failed','unknown','mismatch','cancelled'].includes(input.result.status))fail('result evidence');
|
|
34
42
|
if(input.result.status==='cancelled'&&(!object(input.result.notExecutedEvidence)||!text(input.result.notExecutedEvidence.messageRef)))fail('cancel requires not-executed evidence');
|
|
35
43
|
}
|
|
36
|
-
if((name==='prepare'||name==='result'&&!resultStatement)
|
|
44
|
+
if((name==='prepare'||name==='result'&&!resultStatement)&&(!text(input.operation)||isLegacyOperation(input.operation)))fail('operation');
|
|
37
45
|
return command;
|
|
38
46
|
}
|
|
39
|
-
export function validateCooperativeState(state){
|
|
47
|
+
export function validateCooperativeState(state,{allowLegacyOperations=true,preserveStoredOperations=false,legacyOperationsFrom}={}){
|
|
40
48
|
if(!object(state)||state.workflowKind!=='cooperative'||state.contractVersion!==1||state.schemaVersion!==1||!revision(state.revision)||state.mode!=='plan')fail('explicit cooperative contract');
|
|
41
49
|
validateWorkflowId(state.workflowId);
|
|
42
50
|
if(!object(state.target)||!absolute(state.target.realpath)||!absolute(state.target.gitCommonDir)||!absolute(state.target.gitDir)||!/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(state.target.head)||!(state.target.branch===null||text(state.target.branch)))fail('target');
|
|
@@ -60,5 +68,8 @@ export function validateCooperativeState(state){
|
|
|
60
68
|
for(const checkpoint of checkpoints){try{validateTargetPreparationRecord('checkpoint',{type:'checkpoint',...checkpoint});}catch{fail('target checkpoint');}if(checkpoint.source!=='operator-attested'||!text(checkpoint.messageRef)||!preparationIntents.some(i=>i.id===checkpoint.intentId&&i.firstStageId===checkpoint.stageId)||!state.records.some(r=>r.kind==='target-preparation'&&r.messageRef===checkpoint.messageRef&&r.source==='operator-attested'))fail('target checkpoint provenance');}
|
|
61
69
|
for(const transition of transitions){const request=transition.validation?.request;try{validateTargetPreparationRecord('transition',request);}catch{fail('target transition');}if(!object(transition.target)||!text(transition.messageRef)||!Number.isSafeInteger(transition.targetVersion)||transition.targetVersion!==transition.sourceTargetVersion+1||request.intentId!==transition.intentId||request.checkpointRef!==transition.checkpointRef||!preparationIntents.some(i=>i.id===transition.intentId)||!checkpoints.some(c=>c.intentId===transition.intentId&&c.messageRef===transition.checkpointRef)||!state.records.some(r=>r.kind==='target-preparation'&&r.messageRef===transition.messageRef&&r.source==='operator-attested'))fail('target transition provenance');}
|
|
62
70
|
for(const document of documents){try{validateTargetPreparationRecord('destination',document);}catch{fail('target document');}if(document.sourceLink!=='operator-attested'||document.verification?.status!=='verified'||document.verification?.source!=='local-bytes'||!text(document.messageRef)||!transitions.some(t=>t.intentId===document.intentId&&t.messageRef===document.transitionRef&&t.targetVersion===document.targetVersion)||!state.records.some(r=>r.kind==='target-preparation'&&r.messageRef===document.messageRef&&r.source==='operator-attested'))fail('target document provenance');}
|
|
63
|
-
assertSecretFree(state);json(state);
|
|
71
|
+
assertSecretFree(state);json(state);
|
|
72
|
+
const normalized=normalizeStoredOperations(state);
|
|
73
|
+
if(!allowLegacyOperations&&normalized!==state&&(!legacyOperationsFrom||hasNewStoredOperationAliases(state,legacyOperationsFrom)))fail('legacy operation in new state');
|
|
74
|
+
return preserveStoredOperations?state:normalized;
|
|
64
75
|
}
|
|
@@ -7,7 +7,7 @@ import fs from 'node:fs/promises';
|
|
|
7
7
|
import {constants} from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import {createHash} from 'node:crypto';
|
|
10
|
-
import {validateCooperativeCommand,validateCooperativeState} from './cooperative-schema.mjs';
|
|
10
|
+
import {legacyCooperativeRoleDenial,validateCooperativeCommand,validateCooperativeState} from './cooperative-schema.mjs';
|
|
11
11
|
import {observeCooperativeTarget,validateObservedTarget,validateWorkflowId,workflowStatePath,inspectPath,absolute,within} from './scope.mjs';
|
|
12
12
|
import {fingerprintRequest,saveDurableState,applyCooperativeCommitTransition,applyCooperativeTargetTransition} from './store.mjs';
|
|
13
13
|
import {commandResult,cooperativeVersions} from './bootstrap.mjs';
|
|
@@ -18,9 +18,11 @@ const sameCheckout=(a,b)=>['realpath','gitCommonDir','gitDir'].every(k=>a[k]===b
|
|
|
18
18
|
/** Only trusted code may inject observation/storage. CLI JSON cannot set either. */
|
|
19
19
|
export async function runCooperativeCommand({cwd,workflowId,command,input,observe=observeCooperativeTarget,storage={},readGit=readAssignmentGitEvidence,readChanges=readCooperativeChanges,readCommitGit=readCooperativeCommitGitEvidence}){
|
|
20
20
|
validateWorkflowId(workflowId);validateCooperativeCommand({command,input});
|
|
21
|
+
const denial=legacyCooperativeRoleDenial(input);
|
|
22
|
+
if(denial)return commandResult({workflowId,input,...denial});
|
|
21
23
|
if(command==='init')throw Error('Use initializeCooperativeWorkflow for init');
|
|
22
24
|
const target=await validateObservedTarget(cwd,await observe(cwd)),statePath=await workflowStatePath(target,workflowId);
|
|
23
|
-
const read=async()=>{await inspectPath(statePath);const state=validateCooperativeState(JSON.parse(await fs.readFile(statePath,'utf8')));if(state.workflowId!==workflowId)throw Error('Workflow identity mismatch');return state;};
|
|
25
|
+
const read=async()=>{await inspectPath(statePath);const state=validateCooperativeState(JSON.parse(await fs.readFile(statePath,'utf8')),{preserveStoredOperations:command!=='status'});if(state.workflowId!==workflowId)throw Error('Workflow identity mismatch');return state;};
|
|
24
26
|
const result=(state,decision,extra={})=>commandResult({workflowId,state,input,...decision,...extra});
|
|
25
27
|
const removedDecision=state=>{const decision=evaluateCooperative({state,request:{command,input}});return decision.ruleIds[0]==='cooperative.plan-amend-removed'?decision:null;};
|
|
26
28
|
if(command==='status'){
|
|
@@ -35,6 +37,7 @@ export async function runCooperativeCommand({cwd,workflowId,command,input,observ
|
|
|
35
37
|
let lock,plannerLock;
|
|
36
38
|
try{
|
|
37
39
|
lock=await fs.open(statePath+'.lock','wx',0o600);let state=await read();
|
|
40
|
+
const previousOperations={approvals:[...state.approvals],assignments:[...state.assignments],audit:[...state.audit]};
|
|
38
41
|
const removed=removedDecision(state);if(removed)return result(state,removed);
|
|
39
42
|
const plannerWork=command==='prepare'&&input.operation==='planner-call'||command==='record'&&input.evidence.kind.startsWith('planner-');
|
|
40
43
|
if(plannerWork)plannerLock=await fs.open(path.join(target.gitCommonDir,'arc','planner.lock'),'wx',0o600);
|
|
@@ -182,7 +185,7 @@ export async function runCooperativeCommand({cwd,workflowId,command,input,observ
|
|
|
182
185
|
const output=result(state,decision,{persisted:true});
|
|
183
186
|
state.requests.push({requestId:input.requestId,requestFingerprint,request:structuredClone({command,input}),decision:output});
|
|
184
187
|
state.audit.push({command,requestId:input.requestId,revision:state.revision,decision:output.decision,ruleIds:output.ruleIds,source:'operator-attested',actor:input.actor,...(input.intentId?{intentId:input.intentId,resolution:state.results.at(-1)?.status}:{}),...(input.operation?{operation:input.operation}:{})});
|
|
185
|
-
validateCooperativeState(state);await inspectPath(statePath);await saveDurableState({statePath,state,storage});return output;
|
|
188
|
+
validateCooperativeState(state,{allowLegacyOperations:false,legacyOperationsFrom:previousOperations});await inspectPath(statePath);await saveDurableState({statePath,state,storage});return output;
|
|
186
189
|
}finally{if(plannerLock){await plannerLock.close();await fs.unlink(path.join(target.gitCommonDir,'arc','planner.lock'));}if(lock){await lock.close();await fs.unlink(statePath+'.lock');}}
|
|
187
190
|
}
|
|
188
191
|
|
|
@@ -14,20 +14,21 @@ import {prepareCooperativeAssignment} from './assignment.mjs';
|
|
|
14
14
|
* @property {object} coverage
|
|
15
15
|
*/
|
|
16
16
|
import path from 'node:path';
|
|
17
|
-
import {validateCooperativeState,validateCooperativeCommand} from './cooperative-schema.mjs';
|
|
17
|
+
import {legacyCooperativeRoleDenial,validateCooperativeState,validateCooperativeCommand} from './cooperative-schema.mjs';
|
|
18
18
|
import {validateWorkflowState, validateRequest, validateEvidence,validatePlannerStage} from './schema.mjs';
|
|
19
|
-
import {ROLES, ROLE_OPERATIONS, GIT_OPERATIONS, EXTERNAL_OPERATIONS} from './operations.mjs';
|
|
19
|
+
import {ROLES, ROLE_OPERATIONS, GIT_OPERATIONS, EXTERNAL_OPERATIONS, canonicalCooperativeRole} from './operations.mjs';
|
|
20
20
|
const same=(a,b)=>JSON.stringify(a)===JSON.stringify(b);
|
|
21
21
|
const within=(base,file)=>{const relative=path.relative(base,file);return relative===''||(!relative.startsWith('..'+path.sep)&&relative!=='..'&&!path.isAbsolute(relative));};
|
|
22
22
|
/** Pure policy decision. Evidence is supplied by a trusted adapter/provider, never tool arguments. */
|
|
23
23
|
export function evaluate(policy, state, request, evidence){
|
|
24
|
+
const stored=state;
|
|
24
25
|
const result=(decision,id,reason,requiredEvidence=[])=>({decision,ruleIds:[id],reason,requiredEvidence,expectedRevision:state?.revision??0,proposedTransition:null,coverage:{platform:request?.platform??'unknown',enforcement:'decision-only'}});
|
|
25
|
-
try{validateWorkflowState(state);validateRequest(request);validateEvidence(evidence);}catch(error){return result('hold','runtime.schema',error.message,['valid-state-request-evidence']);}
|
|
26
|
+
try{state=validateWorkflowState(state);validateRequest(request);validateEvidence(evidence);}catch(error){return result('hold','runtime.schema',error.message,['valid-state-request-evidence']);}
|
|
26
27
|
if(policy?.runtime?.schemaVersion!==1||!same(policy.runtime.roles,ROLES)||!Array.isArray(policy.runtime.ruleIds)||!Array.isArray(policy.runtime.requiredEvidence)||policy.runtime.status!=='decision-only')return result('hold','runtime.policy','runtime policy unavailable',['runtime-policy']);
|
|
27
28
|
const actor=state.identities.find(i=>i.actorRef===request.actorRef);
|
|
28
29
|
if(!actor)return result('hold','runtime.identity','platform identity unresolved',['platform-identity']);
|
|
29
30
|
const role=actor.role;
|
|
30
|
-
const roleRule={orchestrator:'role.orchestrator-boundary',scouter:'role.scouter-read-only',planner:'role.planner-draft-only',implementer:'role.implementer-implementation',
|
|
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
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');
|
|
32
33
|
const lease=state.leases.find(l=>l.actorRef===actor.actorRef);
|
|
33
34
|
if(lease?.status==='retired')return result('deny','runtime.identity','retired identity');
|
|
@@ -53,7 +54,7 @@ export function evaluate(policy, state, request, evidence){
|
|
|
53
54
|
if(role==='implementer'&&['accepted','committed'].includes(task.status))return result('deny','runtime.identity','task execution ended');
|
|
54
55
|
if(request.operation==='temporary-write'){
|
|
55
56
|
const temporary=assignment.temporary;
|
|
56
|
-
if(!temporary||temporary.cleanupOwner!==request.actorRef||!Number.isFinite(Date.parse(temporary.expiresAt))||!Number.isFinite(Date.parse(evidence.observedAt))||Date.parse(temporary.expiresAt)<=Date.parse(evidence.observedAt)||!request.paths.every(p=>temporary.paths?.some(base=>within(base,p))))return result('hold','role.
|
|
57
|
+
if(!temporary||temporary.cleanupOwner!==request.actorRef||!Number.isFinite(Date.parse(temporary.expiresAt))||!Number.isFinite(Date.parse(evidence.observedAt))||Date.parse(temporary.expiresAt)<=Date.parse(evidence.observedAt)||!request.paths.every(p=>temporary.paths?.some(base=>within(base,p))))return result('hold','role.tester-verification','temporary scope lifetime and cleanup ownership required',['temporary-assignment']);
|
|
57
58
|
}
|
|
58
59
|
if(request.operation==='check'){
|
|
59
60
|
if(!assignment.checks?.some(c=>same(c,request.descriptor)))return result('hold',roleRule,'exact assigned check descriptor required',['check-descriptor']);
|
|
@@ -82,7 +83,7 @@ export function evaluate(policy, state, request, evidence){
|
|
|
82
83
|
if(d.checks&&(!Array.isArray(approval.scope.checks)||d.checks.some(c=>!approval.scope.checks.some(approved=>same(approved,c)))))return result('hold','runtime.assignment','delegated checks not approved',['delegated-checks']);
|
|
83
84
|
if(d.temporary&&!same(d.temporary,approval.scope.temporary))return result('hold','runtime.assignment','delegated temporary scope not approved',['delegated-temporary-scope']);
|
|
84
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']);
|
|
85
|
-
const next=structuredClone(
|
|
86
|
+
const next=structuredClone(stored);
|
|
86
87
|
if(d.role==='planner'){
|
|
87
88
|
const stage=state.plannerLedger?.stages.find(s=>s.id===d.plannerCall?.stageId),proof=fact('planner-call');
|
|
88
89
|
const contract=stage&&{document:stage.document,inputVersion:stage.inputVersion,criteriaVersion:stage.criteriaVersion,scopeVersion:stage.scopeVersion};
|
|
@@ -98,7 +99,7 @@ export function evaluate(policy, state, request, evidence){
|
|
|
98
99
|
}
|
|
99
100
|
if(request.operation==='accept'){
|
|
100
101
|
const d=request.descriptor;const observed=fact('acceptance')?.data;
|
|
101
|
-
const checks=Array.isArray(d.checkIds)&&task.requiredChecks?.every(id=>d.checkIds?.includes(id)&&state.checks.some(c=>c.id===id&&c.taskId===task.id&&c.status==='passed'&&c.fingerprint===d.fingerprint&&c.resultRef&&c.actorRef!==actor.actorRef&&state.identities.some(i=>i.actorRef===c.actorRef&&i.taskId===task.id&&i.role==='
|
|
102
|
+
const checks=Array.isArray(d.checkIds)&&task.requiredChecks?.every(id=>d.checkIds?.includes(id)&&state.checks.some(c=>c.id===id&&c.taskId===task.id&&c.status==='passed'&&c.fingerprint===d.fingerprint&&c.resultRef&&c.actorRef!==actor.actorRef&&state.identities.some(i=>i.actorRef===c.actorRef&&i.taskId===task.id&&canonicalCooperativeRole(i.role)==='tester')));
|
|
102
103
|
const findings=state.findings.filter(f=>f.taskId===task.id);
|
|
103
104
|
if(!observed||!same(observed,d)||!d.fingerprint||!task.criteria?.length||!same(task.criteria,d.criteria)||!checks||findings.some(f=>!Array.isArray(d.findingIds)||!d.findingIds.includes(f.id)||!f.resolutionRef))return result('hold','git.orchestrator-accept-commit','criteria checks findings and fingerprint verification required',['acceptance-evidence']);
|
|
104
105
|
}
|
|
@@ -123,6 +124,8 @@ export function evaluateCooperative({policy,state,request,evidence}={}){
|
|
|
123
124
|
const base={expectedRevision:state?.revision??0,coverage:{enforcement:'cooperative',provenance:'operator-attested',nativeVerified:false}};
|
|
124
125
|
const hold=(id,reason)=>({...base,decision:'hold',ruleIds:[id],reason,requiredEvidence:[],nextActions:[],proposedTransition:null});
|
|
125
126
|
try{validateCooperativeState(state);validateCooperativeCommand(request);}catch(error){return hold('cooperative.schema',error.message);}
|
|
127
|
+
const denial=legacyCooperativeRoleDenial(request.input);
|
|
128
|
+
if(denial)return {...base,...denial,requiredEvidence:[],nextActions:[],proposedTransition:null};
|
|
126
129
|
if(state.intents.some(i=>i.operation==='plan-amend'&&['prepared','unknown','mismatch','failed'].includes(i.status)))return {...hold('cooperative.plan-amend-removed','Legacy plan-amend intent is no longer supported; inspect Git history and any refs/arc/recovery/* refs manually, then start a new workflow'),nextActions:['inspect-legacy-plan-amend','start-new-workflow']};
|
|
127
130
|
if(request.command==='prepare'&&request.input?.operation==='plan-amend')return hold('cooperative.plan-amend-removed','Plan-amend operation is no longer supported');
|
|
128
131
|
if(policy!==undefined&&policy.workflowKind!=='cooperative')return hold('cooperative.contract','Explicit cooperative policy required');
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {randomUUID} from 'node:crypto';
|
|
4
|
+
import {inspectPath, observeCooperativeTarget, within} from './scope.mjs';
|
|
5
|
+
|
|
6
|
+
export async function writeHandoffRecord({cwd, slug, content}) {
|
|
7
|
+
if (typeof slug !== 'string' || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(slug) || slug.includes('..')) {
|
|
8
|
+
return {decision: 'deny', reasonCode: 'invalid_slug', message: 'Invalid handoff record slug.'};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let gitCommonDir;
|
|
12
|
+
let filename;
|
|
13
|
+
let temporaryFile;
|
|
14
|
+
try {
|
|
15
|
+
if (typeof content !== 'string' || !content.length) throw Error('Expected nonempty handoff content.');
|
|
16
|
+
({gitCommonDir} = await observeCooperativeTarget(cwd));
|
|
17
|
+
const directory = path.join(gitCommonDir, 'arc', 'handoff');
|
|
18
|
+
filename = path.join(directory, `${slug}.md`);
|
|
19
|
+
if (!within(gitCommonDir, filename)) {
|
|
20
|
+
return {decision: 'deny', reasonCode: 'path_outside_common_dir', message: 'Handoff record path must stay inside the Git common directory.'};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
await inspectPath(filename, {missing: true});
|
|
24
|
+
await fs.mkdir(directory, {recursive: true, mode: 0o700});
|
|
25
|
+
await inspectPath(filename, {missing: true});
|
|
26
|
+
let created = false;
|
|
27
|
+
try {
|
|
28
|
+
await fs.lstat(filename);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error.code !== 'ENOENT') throw error;
|
|
31
|
+
created = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const candidate = path.join(directory, `.handoff-${randomUUID()}.tmp`);
|
|
35
|
+
const file = await fs.open(candidate, 'wx', 0o600);
|
|
36
|
+
temporaryFile = candidate;
|
|
37
|
+
try {
|
|
38
|
+
await file.writeFile(content, 'utf8');
|
|
39
|
+
await file.sync();
|
|
40
|
+
} finally {
|
|
41
|
+
await file.close();
|
|
42
|
+
}
|
|
43
|
+
await fs.rename(temporaryFile, filename);
|
|
44
|
+
temporaryFile = undefined;
|
|
45
|
+
return {decision: 'allow', path: filename, created};
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (gitCommonDir && error.symlinkPath && within(gitCommonDir, error.symlinkPath)) {
|
|
48
|
+
const destination = await fs.readlink(error.symlinkPath).catch(() => null);
|
|
49
|
+
if (destination !== null && !within(gitCommonDir, path.resolve(path.dirname(error.symlinkPath), destination))) {
|
|
50
|
+
return {decision: 'deny', reasonCode: 'path_outside_common_dir', message: `Handoff record path must stay inside the Git common directory: ${filename}`};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const failedPath = error.symlinkPath ?? filename;
|
|
54
|
+
return {decision: 'hold', reasonCode: 'handoff_write_failed', message: failedPath ? `${failedPath}: ${error.message}` : error.message, fallback: 'inline'};
|
|
55
|
+
} finally {
|
|
56
|
+
if (temporaryFile) await fs.rm(temporaryFile, {force: true}).catch(() => {});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -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};
|
|
@@ -6,9 +6,16 @@ import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
|
6
6
|
|
|
7
7
|
const environments = new WeakMap();
|
|
8
8
|
const authKinds = new WeakMap();
|
|
9
|
+
export function unknownPlatformMessage(platform, knownIds) {
|
|
10
|
+
const id = typeof platform === 'string'
|
|
11
|
+
? [...platform.replace(/[\p{Cc}\u2028\u2029]/gu, '')].slice(0, 256).join('')
|
|
12
|
+
: '(invalid)';
|
|
13
|
+
return `Unknown platform: ${id}. Known platforms: ${knownIds.join(', ')}`;
|
|
14
|
+
}
|
|
9
15
|
export function resolveConfigHome(platform, context = {}) {
|
|
10
|
-
const
|
|
11
|
-
|
|
16
|
+
const registry = runtimeRegistryOf(context);
|
|
17
|
+
const descriptor = registry.getPlatform(platform);
|
|
18
|
+
if (!descriptor) throw Error(unknownPlatformMessage(platform, registry.byDisplayOrder().map(({id}) => id)));
|
|
12
19
|
return descriptor.home.resolve(context);
|
|
13
20
|
}
|
|
14
21
|
export function resolveLocalCli(platform, { cwd, userHome, env = process.env, runtimePlatforms } = {}) {
|
|
@@ -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
|
+
}
|
|
@@ -5,27 +5,27 @@ import {GROK_CONTRACT} from './grok-stream.mjs';
|
|
|
5
5
|
import {GEMINI_CONTRACT} from './gemini-stream.mjs';
|
|
6
6
|
import {DEFAULT_POLICY, effectiveClaudeSandboxSettings} from './role-dispatch-policy.mjs';
|
|
7
7
|
|
|
8
|
-
const ROLES = ['arc_scouter', 'arc_planner', 'arc_implementer', '
|
|
8
|
+
const ROLES = ['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer'];
|
|
9
9
|
const deepFreeze = value => { for (const child of Object.values(value)) if (child && typeof child === 'object') deepFreeze(child); return Object.freeze(value); };
|
|
10
10
|
export const ROLE_BRIDGE_PERMISSIONS = deepFreeze({
|
|
11
11
|
claude: {
|
|
12
12
|
arc_scouter: {permissionMode: 'default', sandbox: false}, arc_planner: {permissionMode: 'default', sandbox: false},
|
|
13
|
-
arc_implementer: {permissionMode: 'acceptEdits', sandbox: true},
|
|
13
|
+
arc_implementer: {permissionMode: 'acceptEdits', sandbox: true}, arc_tester: {permissionMode: 'default', sandbox: true}, arc_reviewer: {permissionMode: 'default', sandbox: false}
|
|
14
14
|
},
|
|
15
15
|
gemini: {
|
|
16
16
|
arc_scouter: {approvalMode: 'plan', sandbox: false}, arc_planner: {approvalMode: 'plan', sandbox: false},
|
|
17
|
-
arc_implementer: {approvalMode: 'auto_edit', sandbox: true},
|
|
17
|
+
arc_implementer: {approvalMode: 'auto_edit', sandbox: true}, arc_tester: {approvalMode: 'auto_edit', sandbox: true}, arc_reviewer: {approvalMode: 'plan', sandbox: false}
|
|
18
18
|
},
|
|
19
19
|
grok: {
|
|
20
20
|
arc_scouter: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
21
21
|
arc_planner: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
22
22
|
arc_reviewer: {permissionMode: 'plan', sandbox: 'read-only', deny: GROK_CONTRACT.readOnlyDeny},
|
|
23
23
|
arc_implementer: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
24
|
-
|
|
24
|
+
arc_tester: {permissionMode: 'acceptEdits', sandbox: 'custom', deny: []},
|
|
25
25
|
},
|
|
26
26
|
codex: {
|
|
27
27
|
arc_scouter: {sandboxMode: 'read-only', search: true}, arc_planner: {sandboxMode: 'read-only', search: false},
|
|
28
|
-
arc_implementer: {sandboxMode: 'workspace-write', search: false},
|
|
28
|
+
arc_implementer: {sandboxMode: 'workspace-write', search: false}, arc_tester: {sandboxMode: 'workspace-write', search: false}, arc_reviewer: {sandboxMode: 'read-only', search: false}
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
|
|
@@ -4,6 +4,7 @@ import {runtimeRegistryOf, DEFAULT_PLATFORM_REGISTRY} from './platform-registry.
|
|
|
4
4
|
import fsp from 'node:fs/promises';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, bridgeGateReasons, environmentReasons, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
7
|
+
import {displayRoutingRole} from './role-routing-config.mjs';
|
|
7
8
|
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
|
|
8
9
|
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
|
|
9
10
|
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation, reapRecordedDescendants} from './role-supervisor.mjs';
|
|
@@ -25,10 +26,14 @@ export function leaseTargetPlatform(lease,registry=DEFAULT_PLATFORM_REGISTRY){
|
|
|
25
26
|
return v1Platforms.find(id=>id!==lease.hostPlatform);
|
|
26
27
|
}
|
|
27
28
|
const supportOf=lease=>lease.route==='bridge'&&!String(lease.executionEnvironment).endsWith('-desktop')&&lease.state==='completed'&&lease.reasons.length===0&&['identity','model','effort','permissions','terminal'].every(key=>lease.claims?.[key]?.level==='runtime-observed')?'verified':'unverified';
|
|
29
|
+
const displayRoleOf=lease=>displayRoutingRole(lease.role)??lease.role;
|
|
28
30
|
/** Result view of a lease. failed and unknown hold dependent work; every other observed state is reported as allow. */
|
|
29
31
|
function fromLease(lease,decision=['failed','unknown'].includes(lease.state)?'hold':'allow',runtimePlatforms=DEFAULT_PLATFORM_REGISTRY){
|
|
30
32
|
const platform=leaseTargetPlatform(lease,runtimePlatforms);
|
|
31
|
-
|
|
33
|
+
const role=displayRoleOf(lease);
|
|
34
|
+
const legacy=lease.role!==role;
|
|
35
|
+
const name=legacy&&/^arc[_-]routing[_-]/.test(lease.role)?lease.role:profileName(platform,legacy?'arc_qa':role,{runtimePlatforms});
|
|
36
|
+
return {decision,routeStatus:lease.state,supportStatus:supportOf(lease),dispatchId:lease.dispatchId,route:lease.route,profileName:name,executionEnvironment:lease.executionEnvironment,hostPlatform:lease.hostPlatform,role,requested:{platform,model:lease.claims?.model?.requested??null,effort:lease.claims?.effort?.requested??null},authentication:null,cliVersion:null,claims:lease.claims,reasons:lease.reasons,resultPath:lease.resultPath};
|
|
32
37
|
}
|
|
33
38
|
const residualOf=error=>Array.isArray(error?.residualPaths)?error.residualPaths:undefined;
|
|
34
39
|
const hold=(context,dispatchId,code,error)=>{const result=blank(context,dispatchId,'hold',code);const residual=residualOf(error);if(residual)result.residualPaths=residual;return result;};
|
|
@@ -47,6 +52,7 @@ export async function runBridgeDispatch({context,dispatchId,brief,now=Date.now()
|
|
|
47
52
|
await withRoutingLock(anchorHome,async()=>{
|
|
48
53
|
const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
|
|
49
54
|
if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform||lease.route!=='bridge'||lease.state!=='reserved'){result=blank(context,dispatchId,'deny','invalid_request');return;}
|
|
55
|
+
if(displayRoleOf(lease)!==lease.role){result=blank(context,dispatchId,'deny','legacy_role_arc_qa');return;}
|
|
50
56
|
const platform=leaseTargetPlatform(lease,runtimePlatforms);
|
|
51
57
|
let config;try{config=await readActivation(homes,lease.revision,{anchorHome,host:context.hostPlatform,runtimePlatforms});}catch{result=blank(context,dispatchId,'hold','activation_unverified');return;}
|
|
52
58
|
validateLease(lease,{runtimePlatforms,config});
|
|
@@ -145,7 +151,9 @@ export async function resumeRoleDispatch({context,dispatchId,brief,now=Date.now(
|
|
|
145
151
|
try{
|
|
146
152
|
await withRoutingLock(anchorHome,async()=>{
|
|
147
153
|
const lease=await readLease(anchorHome,dispatchId,{runtimePlatforms});
|
|
148
|
-
if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform
|
|
154
|
+
if(!lease||lease.workflowId!==context.workflowId||lease.hostPlatform!==context.hostPlatform){result=blank(context,dispatchId,'deny','invalid_request');return;}
|
|
155
|
+
if(displayRoleOf(lease)!==lease.role){result=blank(context,dispatchId,'hold','legacy_role_resume_unsupported');return;}
|
|
156
|
+
if(lease.route!=='bridge'||!['completed','failed'].includes(lease.state)){result=blank(context,dispatchId,'deny','invalid_request');return;}
|
|
149
157
|
const targetPlatform=leaseTargetPlatform(lease,runtimePlatforms);
|
|
150
158
|
if((targetPlatform==='gemini'||targetPlatform==='grok')&&!['on','verified'].includes(supervisorImplementations.get(targetPlatform)?.resume)){result=blank(context,dispatchId,'hold','resume_unverified');return;}
|
|
151
159
|
if(!lease.sessionId){result=blank(context,dispatchId,'hold','execution_identity_unverified');return;}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
1
|
+
import {byDisplayOrder, runtimeRegistryOf} from './platform-registry.mjs';
|
|
2
2
|
// Fixed policy values for composite role dispatch. G2 'escalation' means the bridge runs only with per-call user escalation approval on a Codex host; it is not a verified pass.
|
|
3
3
|
// GK2/GG2 'approval' means a Grok/Gemini host keeps its platform-default sandbox (off), runs in ask mode, and obtains user approval for each runtime command; it is not a verified pass.
|
|
4
4
|
// GK2 evidence: Grok 1.0.89, 2026-11-19, ask mode with the sandbox off.
|
|
@@ -33,7 +33,7 @@ export const effectiveClaudeSandboxSettings = policy => policy?.gates?.G1 === 'p
|
|
|
33
33
|
export const CATALOG_MODEL_ALIASES = Object.freeze(['fable', 'opus', 'sonnet', 'haiku']);
|
|
34
34
|
export const CODEX_DELEGATION_CALL_NAMES = Object.freeze(['spawn_agent', 'wait_agent']);
|
|
35
35
|
export const DESKTOP_CHECKLIST_PASSED = Object.freeze({'claude-desktop': false, 'codex-desktop': false});
|
|
36
|
-
export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_planner: 20, arc_implementer: 60,
|
|
36
|
+
export const ROLE_TIMEOUT_MINUTES = Object.freeze({arc_scouter: 20, arc_planner: 20, arc_implementer: 60, arc_tester: 60, arc_reviewer: 20});
|
|
37
37
|
export const HEARTBEAT_MS = 5000;
|
|
38
38
|
export const SUPERVISOR_LOST_MS = 30000;
|
|
39
39
|
export const OBSERVE_MAX_WAIT_MS = 540000;
|
|
@@ -65,6 +65,9 @@ export const DEFAULT_POLICY = Object.freeze({
|
|
|
65
65
|
probeTimeoutMs: PROBE_TIMEOUT_MS
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
+
const cliEnvironments = byDisplayOrder().flatMap(({executionEnvironments}) => executionEnvironments)
|
|
69
|
+
.filter(environment => environment.endsWith('-cli')).join(' or ');
|
|
70
|
+
|
|
68
71
|
export const RELEASE_CONDITIONS = Object.freeze({
|
|
69
72
|
activation_unverified: 'Verify the active configuration, all prepared markers, installed bytes, host limits and the shared lock, and inspect the lease records in <anchor home>/arc-role-dispatch for unreadable or corrupted files.',
|
|
70
73
|
resume_unverified: 'Update ARC after verifying platform session resume against the recorded session UUID.',
|
|
@@ -72,12 +75,14 @@ export const RELEASE_CONDITIONS = Object.freeze({
|
|
|
72
75
|
'Not Available': 'Install the target platform CLI so that it is found on PATH.',
|
|
73
76
|
Unauthorized: 'Authenticate the target platform CLI.',
|
|
74
77
|
Incomplete: 'Make the target platform CLI authentication status check complete successfully.',
|
|
75
|
-
environment_unverified:
|
|
78
|
+
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.`,
|
|
76
79
|
host_sandbox_blocked: 'Allow the host to write the anchor home and keep a detached supervisor alive, with explicit user approval.',
|
|
77
80
|
capacity_exhausted: 'Finish or release active bridge executions, or raise the host limits.',
|
|
78
81
|
permission_scope_unverified: 'Update ARC and verify enforcement of the role permissions and approved scope before starting.',
|
|
79
82
|
native_profile_reload_unverified: 'Verify that the host session loaded the requested profile revision.',
|
|
80
83
|
revision_changed: 'Re-run routing-status and prepare a new dispatch under the current revision.',
|
|
84
|
+
legacy_role_resume_unsupported: 'Prepare a new arc_tester dispatch under the current routing revision.',
|
|
85
|
+
legacy_role_arc_qa: 'Use arc_tester when preparing a new dispatch.',
|
|
81
86
|
duplicate_dispatch: 'Use a new requestId, or finish the existing dispatch for the same workflow, task and role.',
|
|
82
87
|
invalid_request: 'Provide a valid request with exactly the documented keys.',
|
|
83
88
|
permission_scope_mismatch: 'Inspect the recorded permission mismatch before dependent work.',
|
|
@@ -117,9 +122,9 @@ export function hostGateReasons({hostPlatform, policy = DEFAULT_POLICY}) {
|
|
|
117
122
|
|
|
118
123
|
export function bridgeGateReasons({platform, role, hostPlatform, policy = DEFAULT_POLICY}) {
|
|
119
124
|
const gates = policy.gates ?? BRIDGE_GATE_RESULTS, codes = [];
|
|
120
|
-
if (platform === 'claude' && (role === 'arc_implementer' || role === '
|
|
121
|
-
if (platform === 'gemini' && (role === 'arc_implementer' || role === '
|
|
122
|
-
if (platform === 'grok' && (role === 'arc_implementer' || role === '
|
|
125
|
+
if (platform === 'claude' && (role === 'arc_implementer' || role === 'arc_tester') && effectiveClaudeSandboxSettings({gates, claudeSandboxSettings: policy.claudeSandboxSettings}) === null) codes.push('permission_scope_unverified');
|
|
126
|
+
if (platform === 'gemini' && (role === 'arc_implementer' || role === 'arc_tester') && gates.GG1 !== 'pass') codes.push('permission_scope_unverified');
|
|
127
|
+
if (platform === 'grok' && (role === 'arc_implementer' || role === 'arc_tester') && gates.GK1 !== 'pass') codes.push('permission_scope_unverified');
|
|
123
128
|
codes.push(...hostGateReasons({hostPlatform, policy}));
|
|
124
129
|
if (platform === 'codex' && gates.G4 === 'fail') codes.push('permission_scope_unverified');
|
|
125
130
|
if (hostPlatform === 'codex' && gates.G2 === 'fail') codes.push('host_sandbox_blocked');
|
|
@@ -4,6 +4,7 @@ import fsp from 'node:fs/promises';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import crypto from 'node:crypto';
|
|
6
6
|
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
7
|
+
import {displayRoutingRole} from './role-routing-config.mjs';
|
|
7
8
|
|
|
8
9
|
export const NON_TERMINAL_STATES = Object.freeze(['reserved', 'starting', 'running', 'unknown']);
|
|
9
10
|
export const TERMINAL_STATES = Object.freeze(['completed', 'failed', 'cancelled']);
|
|
@@ -48,6 +49,8 @@ export async function ensureDispatchDirectory(codexHome, {uid = process.getuid?.
|
|
|
48
49
|
}
|
|
49
50
|
export async function createLease(codexHome, lease, options) {
|
|
50
51
|
const value = validateLease(lease, options);
|
|
52
|
+
const role = displayRoutingRole(value.role);
|
|
53
|
+
if (role !== null && role !== value.role) throw Error('Cannot create a lease with a legacy dispatch role');
|
|
51
54
|
await ensureDispatchDirectory(codexHome);
|
|
52
55
|
const handle = await fsp.open(leasePath(codexHome, value.dispatchId), 'wx', 0o600);
|
|
53
56
|
try { await handle.writeFile(JSON.stringify(value, null, 2) + '\n'); await handle.sync(); } finally { await handle.close(); }
|
|
@@ -608,7 +608,7 @@ export async function observeHeadAdvance(root, before, after, role, allowedPaths
|
|
|
608
608
|
}
|
|
609
609
|
const paths = [...uniquePaths].sort();
|
|
610
610
|
const allowed = Array.isArray(allowedPaths) ? allowedPaths : [];
|
|
611
|
-
if (role === 'arc_implementer' || (role === '
|
|
611
|
+
if (role === 'arc_implementer' || (role === 'arc_tester' && allowed.length)) {
|
|
612
612
|
const outOfScopePaths = paths.filter(file => !allowedBy(allowed, file));
|
|
613
613
|
if (outOfScopePaths.length) return {...reject('out_of_scope'), outOfScopePaths};
|
|
614
614
|
}
|
|
@@ -624,10 +624,10 @@ export async function observeHeadAdvance(root, before, after, role, allowedPaths
|
|
|
624
624
|
* git:info/refs are tolerated and returned separately from violations.
|
|
625
625
|
* Other HEAD changes and branch switches are violations.
|
|
626
626
|
* Any other ref creation, deletion or movement is a violation.
|
|
627
|
-
* Implementer and
|
|
627
|
+
* Implementer and Tester may change only allowedPaths in the worktree; with an
|
|
628
628
|
* empty or missing list they may change no worktree paths. Fast-forward
|
|
629
|
-
* commit paths must stay within allowedPaths for Implementer and for
|
|
630
|
-
* non-empty list;
|
|
629
|
+
* commit paths must stay within allowedPaths for Implementer and for Tester with a
|
|
630
|
+
* non-empty list; Tester with an empty or missing list, like read-only roles, may
|
|
631
631
|
* land a verified fast-forward touching any path.
|
|
632
632
|
* Read-only roles may change no worktree paths beyond verified fast-forward
|
|
633
633
|
* commits. Ordinary worktree snapshots omit Git-ignored paths. Control files
|
|
@@ -656,7 +656,7 @@ export function detectViolations({role, allowedPaths, before, after, headAdvance
|
|
|
656
656
|
refsChanged = true;
|
|
657
657
|
}
|
|
658
658
|
}
|
|
659
|
-
const allowed = (role === 'arc_implementer' || role === '
|
|
659
|
+
const allowed = (role === 'arc_implementer' || role === 'arc_tester') && Array.isArray(allowedPaths) ? allowedPaths : [];
|
|
660
660
|
const changed = new Set();
|
|
661
661
|
for (const file of new Set([...before.entries.keys(), ...after.entries.keys()])) {
|
|
662
662
|
if (before.entries.get(file) !== after.entries.get(file) && !allowedBy(allowed, file)) changed.add(file);
|