@yunhozz/arc 0.5.1 → 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 +139 -136
- package/README.md +2 -2
- package/claude/agents/arc-implementer.md +7 -7
- package/claude/agents/arc-planner.md +5 -5
- package/claude/agents/arc-reviewer.md +6 -6
- package/claude/agents/arc-scouter.md +5 -5
- package/claude/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/claude/skill/SKILL.md +6 -6
- package/claude/skill/models.toml +2 -2
- package/claude/skill/references/arc-visual-companion.md +2 -2
- package/claude/skill/references/commit.md +3 -3
- package/claude/skill/references/coordination.md +21 -21
- package/claude/skill/references/git-recovery.md +3 -1
- package/claude/skill/references/handoff-prep.md +3 -3
- package/claude/skill/references/handoff.md +16 -14
- package/claude/skill/references/limits.md +2 -2
- package/claude/skill/references/planning.md +12 -10
- package/claude/skill/references/verification.md +67 -35
- package/claude/skill/references/worktree-creation.md +2 -0
- package/claude/skill/scripts/model_config.py +25 -9
- package/codex/agents/arc-implementer.toml +7 -7
- package/codex/agents/arc-planner.toml +6 -6
- package/codex/agents/arc-reviewer.toml +7 -7
- package/codex/agents/arc-scouter.toml +6 -6
- package/codex/agents/{arc-qa.toml → arc-tester.toml} +10 -10
- package/codex/skill/SKILL.md +7 -7
- package/codex/skill/models.toml +2 -2
- package/codex/skill/references/arc-visual-companion.md +3 -3
- package/codex/skill/references/commit.md +4 -4
- package/codex/skill/references/coordination.md +20 -20
- package/codex/skill/references/git-recovery.md +2 -0
- package/codex/skill/references/handoff-prep.md +4 -4
- package/codex/skill/references/handoff.md +17 -15
- package/codex/skill/references/limits.md +2 -2
- package/codex/skill/references/planning.md +13 -11
- package/codex/skill/references/verification.md +68 -36
- package/codex/skill/references/worktree-creation.md +2 -0
- package/codex/skill/scripts/model_config.py +28 -15
- package/gemini/agents/arc-implementer.md +7 -7
- package/gemini/agents/arc-planner.md +5 -5
- package/gemini/agents/arc-reviewer.md +6 -6
- package/gemini/agents/arc-scouter.md +5 -5
- package/gemini/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/gemini/skill/SKILL.md +6 -6
- package/gemini/skill/models.toml +2 -2
- package/gemini/skill/references/arc-visual-companion.md +2 -2
- package/gemini/skill/references/commit.md +3 -3
- package/gemini/skill/references/coordination.md +21 -21
- package/gemini/skill/references/git-recovery.md +3 -1
- package/gemini/skill/references/handoff-prep.md +3 -3
- package/gemini/skill/references/handoff.md +16 -14
- package/gemini/skill/references/limits.md +2 -2
- package/gemini/skill/references/planning.md +12 -10
- package/gemini/skill/references/verification.md +67 -35
- package/gemini/skill/references/worktree-creation.md +2 -0
- package/grok/agents/arc-implementer.md +7 -7
- package/grok/agents/arc-planner.md +5 -5
- package/grok/agents/arc-reviewer.md +6 -6
- package/grok/agents/arc-scouter.md +5 -5
- package/grok/agents/{arc-qa.md → arc-tester.md} +10 -10
- package/grok/skill/SKILL.md +6 -6
- package/grok/skill/models.toml +2 -2
- package/grok/skill/references/arc-visual-companion.md +2 -2
- package/grok/skill/references/commit.md +3 -3
- package/grok/skill/references/coordination.md +21 -21
- package/grok/skill/references/git-recovery.md +3 -1
- package/grok/skill/references/handoff-prep.md +3 -3
- package/grok/skill/references/handoff.md +16 -14
- package/grok/skill/references/limits.md +2 -2
- package/grok/skill/references/planning.md +12 -10
- package/grok/skill/references/verification.md +67 -35
- package/grok/skill/references/worktree-creation.md +2 -0
- package/lib/installer/install-mode.mjs +4 -2
- package/lib/installer/install.mjs +4 -3
- package/lib/installer/language.mjs +1 -1
- package/lib/installer/legacy-profiles.mjs +51 -0
- package/lib/installer/manifest.mjs +1 -1
- package/lib/installer/plan.mjs +5 -3
- package/lib/installer/preset.mjs +2 -2
- package/lib/installer/role-routing.mjs +49 -18
- package/lib/installer/runtime-assets.mjs +1 -0
- package/lib/installer/targets.mjs +1 -1
- package/lib/installer/transaction.mjs +35 -4
- package/lib/installer/uninstall.mjs +13 -10
- package/lib/installer/upgrade-state.mjs +13 -1
- package/lib/management/operations.mjs +10 -10
- package/lib/management/reapply.mjs +5 -3
- package/lib/models/config.mjs +25 -7
- package/lib/models/profiles.mjs +1 -1
- package/lib/platforms/formats/gemini-markdown.mjs +3 -3
- package/lib/platforms/formats/grok-markdown.mjs +3 -3
- package/lib/platforms/formats/markdown.mjs +2 -2
- package/lib/platforms/formats/toml.mjs +2 -2
- package/lib/policy/placement.mjs +1 -1
- package/lib/policy/render.mjs +3 -3
- package/lib/policy/role-policy.json +28 -28
- package/lib/prompts/agent-fragments.json +24 -24
- package/lib/prompts/render.mjs +9 -9
- package/lib/runtime/acceptance.mjs +4 -3
- package/lib/runtime/bootstrap.mjs +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/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 +6 -4
- 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/setup.mjs +1 -1
- package/lib/watch/labels.mjs +2 -1
- package/lib/watch/model.mjs +2 -2
- package/lib/watch/render.mjs +2 -2
- package/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/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 +6 -4
- 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
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {runtimeRegistryOf} from './platform-registry.mjs';
|
|
2
2
|
|
|
3
|
-
export const ROUTING_ROLES = Object.freeze(['arc_scouter', 'arc_planner', 'arc_implementer', '
|
|
3
|
+
export const ROUTING_ROLES = Object.freeze(['arc_scouter', 'arc_planner', 'arc_implementer', 'arc_tester', 'arc_reviewer']);
|
|
4
|
+
export const LEGACY_ROUTING_ROLES = Object.freeze({arc_qa: 'arc_tester'});
|
|
5
|
+
export const ROUTING_CONFIG_VERSION = 3;
|
|
4
6
|
const validText = value => typeof value === 'string' && value.length > 0 && value === value.trim() && !/[\p{Cc}\u2028\u2029]/u.test(value);
|
|
5
7
|
const exact = (value, keys) => value && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === keys.length && keys.every(key => Object.hasOwn(value, key));
|
|
6
8
|
const v1Platforms = Object.freeze(['codex', 'claude']);
|
|
@@ -8,22 +10,34 @@ const isV1Platforms = platforms => platforms.length === v1Platforms.length && v1
|
|
|
8
10
|
// Keep injected validation context out of the public config and serialized bytes.
|
|
9
11
|
const configRegistries = new WeakMap();
|
|
10
12
|
|
|
13
|
+
export function displayRoutingRole(role) {
|
|
14
|
+
if (ROUTING_ROLES.includes(role)) return role;
|
|
15
|
+
if (typeof role === 'string' && /^arc[_-](?:routing[_-])?qa$/.test(role)) return LEGACY_ROUTING_ROLES.arc_qa;
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export function validRoleValues(platform, model, effort, {runtimePlatforms} = {}) {
|
|
12
20
|
const registry = runtimeRegistryOf({runtimePlatforms});
|
|
13
21
|
return registry.isPlatformId(platform) && registry.getPlatform(platform).routing.validatePair(model, effort);
|
|
14
22
|
}
|
|
15
23
|
export function validateRoleRoutingConfig(config, opts = {}) {
|
|
16
24
|
const keys = ['version', 'revision', 'platforms', 'roles'];
|
|
17
|
-
if (!(exact(config, keys) || (config?.version === 1 && exact(config, ['version', 'revision', 'roles']))) || ![1, 2].includes(config.version) || !validText(config.revision)
|
|
25
|
+
if (!(exact(config, keys) || (config?.version === 1 && exact(config, ['version', 'revision', 'roles']))) || ![1, 2, ROUTING_CONFIG_VERSION].includes(config.version) || !validText(config.revision)) throw Error('Invalid role routing configuration');
|
|
26
|
+
let roles = config.roles;
|
|
27
|
+
if (roles && typeof roles === 'object' && !Array.isArray(roles) && Object.hasOwn(roles, 'arc_qa')) {
|
|
28
|
+
if (config.version === ROUTING_CONFIG_VERSION || Object.hasOwn(roles, 'arc_tester')) throw Error('Invalid role routing configuration');
|
|
29
|
+
roles = Object.fromEntries(Object.entries(roles).map(([role, fields]) => [Object.hasOwn(LEGACY_ROUTING_ROLES, role) ? LEGACY_ROUTING_ROLES[role] : role, fields]));
|
|
30
|
+
}
|
|
31
|
+
if (!exact(roles, ROUTING_ROLES)) throw Error('Invalid role routing configuration');
|
|
18
32
|
const registry = runtimeRegistryOf(opts);
|
|
19
33
|
const platforms = config.version === 1 && !Object.hasOwn(config, 'platforms') ? [...v1Platforms] : config.platforms;
|
|
20
34
|
if (!Array.isArray(platforms) || platforms.length < 2 || new Set(platforms).size !== platforms.length || platforms.some(id => !registry.isPlatformId(id))) throw Error('Invalid role routing platforms');
|
|
21
35
|
if (platforms.some((id, index) => index > 0 && registry.getPlatform(platforms[index - 1]).anchorOrder >= registry.getPlatform(id).anchorOrder) || (config.version === 1 && !isV1Platforms(platforms))) throw Error('Invalid role routing platforms');
|
|
22
36
|
for (const role of ROUTING_ROLES) {
|
|
23
|
-
const fields =
|
|
37
|
+
const fields = roles[role];
|
|
24
38
|
if (!exact(fields, ['platform', 'model', 'effort']) || !validRoleValues(fields.platform, fields.model, fields.effort, opts) || !platforms.includes(fields.platform)) throw Error(`Invalid role routing values for ${role}`);
|
|
25
39
|
}
|
|
26
|
-
const result = structuredClone({version: config.version, revision: config.revision, platforms, roles
|
|
40
|
+
const result = structuredClone({version: config.version, revision: config.revision, platforms, roles});
|
|
27
41
|
configRegistries.set(result, registry);
|
|
28
42
|
return result;
|
|
29
43
|
}
|
|
@@ -33,7 +47,7 @@ export function parseRoleRoutingConfig(text, opts) {
|
|
|
33
47
|
}
|
|
34
48
|
export function serializeRoleRoutingConfig(config) {
|
|
35
49
|
const {revision, platforms, roles} = validateRoleRoutingConfig(config, {runtimePlatforms: configRegistries.get(config)});
|
|
36
|
-
const value = {version:
|
|
50
|
+
const value = {version: ROUTING_CONFIG_VERSION, revision, platforms, roles};
|
|
37
51
|
return JSON.stringify(value, null, 2) + '\n';
|
|
38
52
|
}
|
|
39
53
|
export function buildRoleRoutingConfig({revision, platforms = [], roles}, opts = {}) {
|
|
@@ -42,5 +56,5 @@ export function buildRoleRoutingConfig({revision, platforms = [], roles}, opts =
|
|
|
42
56
|
const participating = [...new Set([...platforms, ...Object.values(roles).map(fields => fields.platform)])];
|
|
43
57
|
if (participating.some(id => !registry.isPlatformId(id))) throw Error('Invalid role routing platforms');
|
|
44
58
|
participating.sort((a, b) => registry.getPlatform(a).anchorOrder - registry.getPlatform(b).anchorOrder);
|
|
45
|
-
return validateRoleRoutingConfig({version:
|
|
59
|
+
return validateRoleRoutingConfig({version: ROUTING_CONFIG_VERSION, revision, platforms: participating, roles}, opts);
|
|
46
60
|
}
|
|
@@ -6,7 +6,7 @@ import crypto from 'node:crypto';
|
|
|
6
6
|
import {COOPERATIVE_RUNTIME_MODULES, cooperativeVersions} from './bootstrap.mjs';
|
|
7
7
|
import {inspectPath} from './scope.mjs';
|
|
8
8
|
import {resolveConfigHome, resolveLocalCli, probePlatformAuth, probeCodexAuthStatus, probeCliVersion} from './local-cli.mjs';
|
|
9
|
-
import {ROUTING_ROLES, parseRoleRoutingConfig} from './role-routing-config.mjs';
|
|
9
|
+
import {LEGACY_ROUTING_ROLES, ROUTING_ROLES, parseRoleRoutingConfig} from './role-routing-config.mjs';
|
|
10
10
|
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, revisionTag, hostGateReasons, bridgeGateReasons, environmentReasons, initialClaims, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
11
11
|
import {NON_TERMINAL_STATES, createLease, listLeases, pruneTerminalLeases, readHostLimits} from './role-dispatch-store.mjs';
|
|
12
12
|
import {allowedPathsCoverControl, claudeProjectSettingsWidenScope, resolveWorktree} from './role-observe.mjs';
|
|
@@ -172,7 +172,7 @@ function validateAssignment(assignment,expectedRevision,context){
|
|
|
172
172
|
const paths=assignment.allowedPaths;
|
|
173
173
|
if(role==='arc_implementer')return Array.isArray(paths)&&paths.length>0&&paths.every(validRelativePath);
|
|
174
174
|
if(paths===undefined)return true;
|
|
175
|
-
return role==='
|
|
175
|
+
return role==='arc_tester'&&Array.isArray(paths)&&paths.every(validRelativePath);
|
|
176
176
|
}
|
|
177
177
|
const blankResult=(host,environment,role)=>({decision:'hold',routeStatus:'held',supportStatus:'unverified',dispatchId:null,route:null,profileName:null,executionEnvironment:environment,hostPlatform:host,role,requested:null,authentication:null,cliVersion:null,claims:null,reasons:[]});
|
|
178
178
|
const classify=error=>{
|
|
@@ -230,6 +230,7 @@ export async function routingStatus({context,now=Date.now(),policy=DEFAULT_POLIC
|
|
|
230
230
|
export async function prepareRoleDispatch({context,assignment,expectedRevision,now=Date.now(),policy=DEFAULT_POLICY}={}){
|
|
231
231
|
const host=hostOf(context),environment=environmentOf(context,host),role=ROUTING_ROLES.includes(assignment?.role)?assignment.role:null;
|
|
232
232
|
const result=blankResult(host,environment,role);
|
|
233
|
+
if(typeof assignment?.role==='string'&&Object.hasOwn(LEGACY_ROUTING_ROLES,assignment.role)){result.decision='deny';result.reasons=[reason('legacy_role_arc_qa')];return result;}
|
|
233
234
|
if(!host||!environment||!validateAssignment(assignment,expectedRevision,context)){result.decision='deny';result.reasons=[reason('invalid_request')];return result;}
|
|
234
235
|
const codes=new Set();let duplicate=false,anchorHome;
|
|
235
236
|
const homes=resolveRuntimeHomes(context),runtimePlatforms=runtimeRegistryOf(context);
|
|
@@ -241,7 +242,7 @@ export async function prepareRoleDispatch({context,assignment,expectedRevision,n
|
|
|
241
242
|
const requested=config.roles[role],route=requested.platform===host?'native':'bridge';
|
|
242
243
|
result.requested={...requested};result.route=route;result.profileName=profileName(requested.platform,role,{runtimePlatforms});
|
|
243
244
|
if(route==='bridge'&&allowedPathsCoverControl(assignment.allowedPaths??[])){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
244
|
-
if(route==='bridge'&&requested.platform==='claude'&&(role==='arc_implementer'||role==='
|
|
245
|
+
if(route==='bridge'&&requested.platform==='claude'&&(role==='arc_implementer'||role==='arc_tester')){
|
|
245
246
|
const target=typeof context.cwd==='string'?await resolveWorktree(context.cwd).catch(()=>null):null;
|
|
246
247
|
if(!target||await claudeProjectSettingsWidenScope(target.realpath)){result.reasons=[reason('permission_scope_unverified')];return;}
|
|
247
248
|
}
|
|
@@ -26,7 +26,7 @@ import {isPlatformId} from './platform-registry.mjs';
|
|
|
26
26
|
* @property {Array<object>} [facts] Provider-confirmed facts tied to state and source references.
|
|
27
27
|
*/
|
|
28
28
|
import path from 'node:path';
|
|
29
|
-
import {ROLES, OPERATIONS} from './operations.mjs';
|
|
29
|
+
import {ROLES, OPERATIONS, canonicalCooperativeRole, hasNewStoredOperationAliases, normalizeStoredOperations} from './operations.mjs';
|
|
30
30
|
const fail = message => {throw new Error(`Runtime schema: ${message}`);};
|
|
31
31
|
export const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
32
32
|
export const text = value => typeof value === 'string' && value.length > 0;
|
|
@@ -36,7 +36,7 @@ const absolute = value => text(value) && path.isAbsolute(value) && path.normaliz
|
|
|
36
36
|
const unique = (items,key) => items.every(x=>object(x)&&text(x[key])) && new Set(items.map(x=>x[key])).size===items.length;
|
|
37
37
|
function approval(a){return object(a)&&text(a.id)&&['user-message','human-confirmation'].includes(a.source)&&text(a.messageRef)&&hash(a.contentHash)&&object(a.scope)&&text(a.scope.taskId)&&absolute(a.scope.target)&&strings(a.scope.operations)&&a.scope.operations.every(op=>OPERATIONS.includes(op))&&strings(a.scope.paths)&&a.scope.paths.every(absolute);}
|
|
38
38
|
/** Validate stored workflow data. Observed provenance must still be checked by evaluate. */
|
|
39
|
-
export function validateWorkflowState(s){
|
|
39
|
+
export function validateWorkflowState(s,{allowLegacyOperations=true,preserveStoredOperations=false,legacyOperationsFrom}={}){
|
|
40
40
|
if(object(s)&&s.workflowKind!==undefined)fail('provider state cannot use cooperative contract');
|
|
41
41
|
if(!object(s)||s.schemaVersion!==1||!text(s.workflowId)||!Number.isSafeInteger(s.revision)||s.revision<0)fail('version or identity');
|
|
42
42
|
if(!object(s.versions)||['policy','runtime','adapter','policyHash','runtimeHash','adapterHash'].some(k=>!text(s.versions[k])))fail('versions');
|
|
@@ -44,11 +44,14 @@ export function validateWorkflowState(s){
|
|
|
44
44
|
if(!object(s.target)||!absolute(s.target.realpath)||['repository','worktree','baseHead','head'].some(k=>!text(s.target[k]))||!(s.target.branch===null||text(s.target.branch)))fail('target');
|
|
45
45
|
if(!['plan','small-task','no-plan'].includes(s.mode))fail('mode');
|
|
46
46
|
for(const k of ['documents','approvals','tasks','assignments','identities','leases','checks','findings','acceptances','commits','audit','capabilities','requests'])if(!Array.isArray(s[k]))fail(k);
|
|
47
|
+
const stored=s,normalized=normalizeStoredOperations(s);
|
|
48
|
+
if(!allowLegacyOperations&&normalized!==s&&(!legacyOperationsFrom||hasNewStoredOperationAliases(s,legacyOperationsFrom)))fail('legacy operation in new state');
|
|
49
|
+
s=normalized;
|
|
47
50
|
if(!unique(s.tasks,'id')||s.tasks.some(t=>!['pending','assigned','rework','verification','accepted','committed'].includes(t.status)||!strings(t.paths)||t.paths.some(p=>!absolute(p))||!strings(t.dependencies)||!text(t.baseCommit)||!strings(t.criteria)||!strings(t.requiredChecks)))fail('tasks');
|
|
48
51
|
if(!unique(s.approvals,'id')||s.approvals.some(a=>!approval(a)))fail('approval provenance');
|
|
49
|
-
if(!unique(s.identities,'actorRef')||s.identities.some(i=>!ROLES.includes(i.role)||!text(i.taskId)||!text(i.observationRef)))fail('identity');
|
|
52
|
+
if(!unique(s.identities,'actorRef')||s.identities.some(i=>!ROLES.includes(canonicalCooperativeRole(i.role))||!text(i.taskId)||!text(i.observationRef)))fail('identity');
|
|
50
53
|
if(!unique(s.leases,'actorRef')||s.leases.some(l=>!text(l.taskId)||!['active','suspended','retired'].includes(l.status)))fail('lease');
|
|
51
|
-
if(s.assignments.some(a=>!object(a)||!((a.status==='pending'&&a.actorRef===null&&text(a.assignmentId)&&text(a.correlationRef)&&text(a.requestId)&&text(a.requestedBy)&&isPlatformId(a.platform))||text(a.actorRef))||!text(a.taskId)||!ROLES.includes(a.role)||!strings(a.paths)||a.paths.some(p=>!absolute(p))||!strings(a.operations)||a.operations.some(op=>!OPERATIONS.includes(op))||!text(a.approvalRef)))fail('assignment');
|
|
54
|
+
if(s.assignments.some(a=>!object(a)||!((a.status==='pending'&&a.actorRef===null&&text(a.assignmentId)&&text(a.correlationRef)&&text(a.requestId)&&text(a.requestedBy)&&isPlatformId(a.platform))||text(a.actorRef))||!text(a.taskId)||!ROLES.includes(canonicalCooperativeRole(a.role))||!strings(a.paths)||a.paths.some(p=>!absolute(p))||!strings(a.operations)||a.operations.some(op=>!OPERATIONS.includes(op))||!text(a.approvalRef)))fail('assignment');
|
|
52
55
|
for(const a of s.assignments){
|
|
53
56
|
if(a.checks!==undefined&&(!Array.isArray(a.checks)||a.checks.some(c=>!object(c)||!absolute(c.executable)||!Array.isArray(c.args)||!c.args.every(x=>typeof x==='string')||!absolute(c.cwd)||!object(c.env)||!strings(c.outputs)||c.outputs.some(p=>!absolute(p)))))fail('check descriptor');
|
|
54
57
|
if(a.temporary!==undefined&&(!object(a.temporary)||!strings(a.temporary.paths)||a.temporary.paths.some(p=>!absolute(p))||!text(a.temporary.cleanupOwner)||!Number.isFinite(Date.parse(a.temporary.expiresAt))))fail('temporary assignment');
|
|
@@ -61,7 +64,7 @@ export function validateWorkflowState(s){
|
|
|
61
64
|
if(s.commits.some(c=>!object(c)||!text(c.purpose)||!text(c.taskId)||!text(c.expectedParent)||!text(c.expectedTree)))fail('commits');
|
|
62
65
|
if(s.requests.some(r=>!object(r)||!text(r.requestId)||!hash(r.requestFingerprint)||!object(r.decision))||new Set(s.requests.map(r=>r.requestId)).size!==s.requests.length)fail('request replay');
|
|
63
66
|
if(s.plannerLedger!==undefined){validatePlannerLedger(s.plannerLedger);if(s.plannerLedger.stages.some(stage=>stage.workflowId!==s.workflowId))fail('Planner workflow binding');}
|
|
64
|
-
return s;
|
|
67
|
+
return preserveStoredOperations?stored:s;
|
|
65
68
|
}
|
|
66
69
|
export function validateRequest(r){
|
|
67
70
|
if(!object(r)||['requestId','actorRef','taskId','toolName'].some(k=>!text(r[k]))||!isPlatformId(r.platform)||!OPERATIONS.includes(r.operation)||!absolute(r.cwd)||!object(r.arguments)||!object(r.descriptor)||!strings(r.paths)||r.paths.some(p=>!absolute(p)))fail('request');
|
|
@@ -11,7 +11,7 @@ export async function inspectPath(filename,{missing=false,directory=false}={}){
|
|
|
11
11
|
for(let i=0;i<parts.length;i++){
|
|
12
12
|
cursor=path.join(cursor,parts[i]);let stat;
|
|
13
13
|
try{stat=await fs.lstat(cursor);}catch(error){if(missing&&error.code==='ENOENT')return;throw error;}
|
|
14
|
-
if(stat.isSymbolicLink())throw Error('Unsafe symlink path');
|
|
14
|
+
if(stat.isSymbolicLink())throw Object.assign(Error('Unsafe symlink path'),{symlinkPath:cursor});
|
|
15
15
|
if(i<parts.length-1||directory){if(!stat.isDirectory())throw Error('Unsafe directory type');}
|
|
16
16
|
else if(!stat.isFile())throw Error('State must be a regular file');
|
|
17
17
|
}
|
|
@@ -27,7 +27,7 @@ export async function transactWorkflow({statePath,expectedRevision,requestId,req
|
|
|
27
27
|
try{
|
|
28
28
|
lock=await fs.open(lockPath,'wx',0o600);
|
|
29
29
|
const stat=await fs.lstat(statePath);if(!stat.isFile()||stat.isSymbolicLink())throw Error('State must be regular file');
|
|
30
|
-
const state=validateWorkflowState(JSON.parse(await fs.readFile(statePath,'utf8')));
|
|
30
|
+
const state=validateWorkflowState(JSON.parse(await fs.readFile(statePath,'utf8')),{preserveStoredOperations:true});
|
|
31
31
|
const prior=state.requests.find(r=>r.requestId===requestId);
|
|
32
32
|
let decision;
|
|
33
33
|
if(prior){
|
|
@@ -52,7 +52,7 @@ export async function transactWorkflow({statePath,expectedRevision,requestId,req
|
|
|
52
52
|
for(const old of state.leases){const current=next.leases.find(l=>l.actorRef===old.actorRef);if(old.status==='retired'&&(!current||current.status!=='retired'||current.taskId!==old.taskId))throw Error('Retired lease revival forbidden');}
|
|
53
53
|
next.revision=state.revision+1;next.requests=prior?state.requests.map(r=>r.requestId===requestId?{requestId,requestFingerprint,decision}:r):[...state.requests,{requestId,requestFingerprint,decision}];
|
|
54
54
|
next.audit=[...state.audit,{requestId,revision:next.revision,decision:decision.decision,ruleIds:decision.ruleIds??[],result:'pending'}];
|
|
55
|
-
validateWorkflowState(next);
|
|
55
|
+
validateWorkflowState(next,{allowLegacyOperations:false,legacyOperationsFrom:state});
|
|
56
56
|
await saveDurableState({statePath,state:next});
|
|
57
57
|
return {state:next,decision,replayed:false};
|
|
58
58
|
}finally{
|
|
@@ -5,6 +5,8 @@ import {createHash} from 'node:crypto';
|
|
|
5
5
|
import {spawnSync} from 'node:child_process';
|
|
6
6
|
import {fingerprintRequest} from './store.mjs';
|
|
7
7
|
import {absolute,within,inspectPath} from './scope.mjs';
|
|
8
|
+
import {legacyCooperativeRoleDenial} from './cooperative-schema.mjs';
|
|
9
|
+
import {canonicalCooperativeRole} from './operations.mjs';
|
|
8
10
|
const same=(a,b)=>JSON.stringify(a)===JSON.stringify(b);
|
|
9
11
|
const text=v=>typeof v==='string'&&v.length>0;
|
|
10
12
|
const hash=v=>typeof v==='string'&&/^sha256:[a-f0-9]{64}$/.test(v);
|
|
@@ -27,7 +29,8 @@ const assignedImplementer=(state,id,taskId)=>state.assignments.some(a=>a.agentId
|
|
|
27
29
|
function independent(state,actor,taskId){
|
|
28
30
|
if(!fields(actor,['id','role'])||!text(actor.id))return false;
|
|
29
31
|
if(state.assignments.some(a=>a.agentId===actor.id))return false;
|
|
30
|
-
|
|
32
|
+
const conflicts=entry=>entry.verificationActor?.id===actor.id&&(canonicalCooperativeRole(entry.verificationActor.role)!==actor.role||actor.role==='tester'&&entry.taskId!==taskId);
|
|
33
|
+
return !(state.intents??[]).some(conflicts)&&!(state.checks??[]).some(conflicts);
|
|
31
34
|
}
|
|
32
35
|
/** Invalidate only the affected dependency closure; preserve all historical evidence. */
|
|
33
36
|
export function invalidateAffectedEvidence({state,changedVersions={},affectedTaskIds}={}){
|
|
@@ -62,6 +65,8 @@ function record({state,request,evidence}){
|
|
|
62
65
|
}
|
|
63
66
|
/** Pure cooperative gate: verifies recorded consistency, never identity or semantic sufficiency. */
|
|
64
67
|
export function evaluateCooperativeVerification({state,request,evidence}={}){
|
|
68
|
+
const denial=legacyCooperativeRoleDenial(request);
|
|
69
|
+
if(denial)return {...base(state),...denial};
|
|
65
70
|
if(state?.mode!=='plan')return hold(state,'unsupported','Only the complete spec and plan path is supported');
|
|
66
71
|
if(!request||request.expectedRevision!==state.revision)return hold(state,'revision','Stale verification request');
|
|
67
72
|
if(request.actor?.role!=='orchestrator')return hold(state,'verification-actor','Orchestrator statement required');
|
|
@@ -73,11 +78,11 @@ export function evaluateCooperativeVerification({state,request,evidence}={}){
|
|
|
73
78
|
if(a.scope==='task'&&(!authorized(state,t)||t.status==='held'||request.operation==='review'||!t.requiredChecks.some(d=>same(d,a.descriptor))))return hold(state,'verification-task','Current task approval and exact assigned check required; Reviewer is final only');
|
|
74
79
|
if(a.scope==='final'&&(request.taskId!==undefined||request.operation!=='review'||!state.tasks.length||state.tasks.some(t=>!authorized(state,t)||!['accepted','committed'].includes(t.status))))return hold(state,'verification-final','Final review follows accepted tasks and required task checks');
|
|
75
80
|
const finalCorrection=a.scope==='final'&&state.findings.some(f=>f.origin==='final-review'&&f.status==='resolved'&&a.findingIds?.includes(f.id));
|
|
76
|
-
if(a.scope==='final'&&!finalCorrection&&state.tasks.some(task=>task.requiredChecks.some(descriptor=>!state.checks.some(c=>c.scope==='task'&&c.taskId===task.id&&c.operation==='check'&&!c.stale&&c.status==='passed'&&c.verdict==='proven'&&text(c.resultRef)&&c.verificationActor?.role==='
|
|
77
|
-
if(a.actor?.role!==(request.operation==='review'?'reviewer':'
|
|
81
|
+
if(a.scope==='final'&&!finalCorrection&&state.tasks.some(task=>task.requiredChecks.some(descriptor=>!state.checks.some(c=>c.scope==='task'&&c.taskId===task.id&&c.operation==='check'&&!c.stale&&c.status==='passed'&&c.verdict==='proven'&&text(c.resultRef)&&canonicalCooperativeRole(c.verificationActor?.role)==='tester'&&same(c.descriptor,descriptor)&&(c.changeFingerprint===evidence.changes?.tasks?.[task.id]||task.status==='committed'&&state.commits?.some(commit=>commit.taskId===task.id&&commit.observationSource==='local-git'&&commit.fingerprint===c.changeFingerprint&&commit.postCommitFingerprint===evidence.changes?.tasks?.[task.id]))))))return hold(state,'verification-final-checks','Initial final review requires current task Tester evidence');
|
|
82
|
+
if(a.actor?.role!==(request.operation==='review'?'reviewer':'tester')||a.actor.id===request.actor.id||!independent(state,a.actor,request.taskId))return hold(state,'verification-independence','Independent actor statement and fresh task Tester required');
|
|
78
83
|
const findings=state.findings.filter(f=>f.status!=='closed'&&(a.scope==='final'||f.scope==='task'&&f.taskId===request.taskId));
|
|
79
84
|
if(a.findingIds!==undefined&&(!list(a.findingIds)||a.findingIds.some(id=>!findings.some(f=>f.id===id))))return hold(state,'finding-recheck','Unknown finding recheck');
|
|
80
|
-
if(findings.some(f=>f.status!=='resolved'||!text(f.resolutionRef)||f.resolutionActor?.role!=='implementer'||f.changeFingerprint!==a.changeFingerprint||!a.findingIds?.includes(f.id)||f.origin==='final-review'&&request.operation!=='review'||f.origin!=='final-review'&&request.operation!=='check'))return hold(state,'finding-recheck','Implementer resolution and the required
|
|
85
|
+
if(findings.some(f=>f.status!=='resolved'||!text(f.resolutionRef)||f.resolutionActor?.role!=='implementer'||f.changeFingerprint!==a.changeFingerprint||!a.findingIds?.includes(f.id)||f.origin==='final-review'&&request.operation!=='review'||f.origin!=='final-review'&&request.operation!=='check'))return hold(state,'finding-recheck','Implementer resolution and the required Tester or final Reviewer recheck required');
|
|
81
86
|
if(state.intents.some(i=>['check','review'].includes(i.operation)&&['prepared','unknown','mismatch'].includes(i.status)&&i.scope===a.scope&&i.taskId===request.taskId&&same(i.descriptor,a.descriptor)&&!i.stale))return hold(state,'verification-active','Reconcile the existing verification intent');
|
|
82
87
|
const intent={requestId:request.requestId,operation:request.operation,status:'prepared',scope:a.scope,taskId:request.taskId,verificationActor:structuredClone(a.actor),descriptor:structuredClone(a.descriptor),changeFingerprint:a.changeFingerprint,findingIds:[...(a.findingIds??[])],scopeVersion:state.scopeVersion,targetVersion:state.targetVersion,versions:structuredClone(state.versions),target:structuredClone(state.target),approval:structuredClone(approval(state,request.taskId)),taskFingerprint:fingerprintRequest(a.scope==='final'?state.tasks:t),fingerprint:fingerprintRequest(request),source:'operator-attested'};
|
|
83
88
|
return allow(state,{intent});
|
|
@@ -85,10 +90,13 @@ export function evaluateCooperativeVerification({state,request,evidence}={}){
|
|
|
85
90
|
function outcome({state,request,evidence}){
|
|
86
91
|
const intent=state.intents.find(i=>i.requestId===request.intentId),r=request.result,d=r?.data;
|
|
87
92
|
if(!intent||!['check','review'].includes(intent.operation)||!['prepared','unknown','mismatch'].includes(intent.status))return hold(state,'verification-intent','Matching unresolved verification intent required');
|
|
88
|
-
const
|
|
89
|
-
const
|
|
93
|
+
const storedActor=intent.verificationActor;
|
|
94
|
+
const role=canonicalCooperativeRole(storedActor?.role);
|
|
95
|
+
const verificationActor=role===storedActor?.role?storedActor:{...storedActor,role};
|
|
96
|
+
const valid=r&&['succeeded','failed','unknown','mismatch'].includes(r.status)&&text(r.messageRef)&&fields(d,['actor','descriptor','scope','taskId','changeFingerprint','verdict'])&&['proven','unmet','unverified'].includes(d.verdict)&&same(d.actor,verificationActor)&&same(d.descriptor,intent.descriptor)&&d.scope===intent.scope&&d.taskId===intent.taskId&&d.changeFingerprint===intent.changeFingerprint;
|
|
97
|
+
const fresh=!intent.stale&&intent.changeFingerprint===current(state,intent.scope,intent.taskId,evidence?.changes)&&(intent.scope==='task'||intent.scopeVersion===state.scopeVersion)&&intent.targetVersion===state.targetVersion&&same(intent.target,state.target)&&same(intent.versions,state.versions)&&independent(state,verificationActor,intent.taskId)&&same(intent.approval,approval(state,intent.taskId))&&intent.taskFingerprint===fingerprintRequest(intent.scope==='final'?state.tasks:state.tasks.find(t=>t.id===intent.taskId));
|
|
90
98
|
const status=!valid?'mismatch':r.status;
|
|
91
|
-
const check={id:intent.requestId,operation:intent.operation,scope:intent.scope,taskId:intent.taskId,descriptor:structuredClone(intent.descriptor),verificationActor:structuredClone(
|
|
99
|
+
const check={id:intent.requestId,operation:intent.operation,scope:intent.scope,taskId:intent.taskId,descriptor:structuredClone(intent.descriptor),verificationActor:structuredClone(verificationActor),changeFingerprint:intent.changeFingerprint,resultRef:r?.messageRef,verdict:valid?d.verdict:'unverified',status:fresh&&status==='succeeded'&&d.verdict==='proven'?'passed':status==='failed'||d?.verdict==='unmet'?'failed':'unverified',stale:!fresh,source:'operator-attested'};
|
|
92
100
|
const findings=[];
|
|
93
101
|
if(check.status==='failed')findings.push({id:intent.requestId+':failure',checkId:check.id,scope:intent.scope,taskId:intent.taskId,origin:intent.operation==='review'?'final-review':'check',status:'open',source:'operator-attested',messageRef:r.messageRef});
|
|
94
102
|
if(check.status==='passed')for(const id of intent.findingIds){const f=state.findings.find(f=>f.id===id);if(!f||f.status!=='resolved'||f.changeFingerprint!==intent.changeFingerprint)return hold(state,'finding-recheck','Finding changed after prepare');findings.push({...f,status:'closed',recheckRef:r.messageRef,recheckActor:structuredClone(d.actor)});}
|