@yunhozz/arc 0.3.5 → 0.4.1
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 +133 -94
- package/README.md +56 -21
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/references/commit.md +10 -8
- package/claude/skill/references/coordination.md +6 -4
- package/claude/skill/references/handoff-prep.md +12 -12
- package/claude/skill/references/handoff.md +2 -0
- package/claude/skill/references/planning.md +8 -8
- package/claude/skill/references/verification.md +6 -6
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/references/commit.md +10 -8
- package/codex/skill/references/coordination.md +6 -4
- package/codex/skill/references/handoff-prep.md +12 -12
- package/codex/skill/references/handoff.md +2 -0
- package/codex/skill/references/planning.md +8 -8
- package/codex/skill/references/verification.md +6 -6
- package/gemini/GEMINI.md +8 -0
- package/gemini/agents/arc-implementer.md +37 -0
- package/gemini/agents/arc-planner.md +47 -0
- package/gemini/agents/arc-qa.md +37 -0
- package/gemini/agents/arc-reviewer.md +39 -0
- package/gemini/agents/arc-scouter.md +38 -0
- package/gemini/instructions.md +4 -0
- package/gemini/skill/SKILL.md +78 -0
- package/gemini/skill/models.toml +23 -0
- package/gemini/skill/references/arc-visual-companion.md +28 -0
- package/gemini/skill/references/commit.md +55 -0
- package/gemini/skill/references/coordination.md +149 -0
- package/gemini/skill/references/git-recovery.md +34 -0
- package/gemini/skill/references/handoff-prep.md +110 -0
- package/gemini/skill/references/handoff.md +227 -0
- package/gemini/skill/references/limits.md +31 -0
- package/gemini/skill/references/planning.md +168 -0
- package/gemini/skill/references/verification.md +155 -0
- package/gemini/skill/references/worktree-creation.md +8 -0
- package/lib/color/palette.mjs +6 -0
- package/lib/installer/acquisition.mjs +7 -5
- package/lib/installer/install-mode.mjs +49 -26
- package/lib/installer/install.mjs +3 -2
- package/lib/installer/manifest.mjs +20 -14
- package/lib/installer/plan.mjs +24 -21
- package/lib/installer/preset.mjs +9 -8
- package/lib/installer/role-routing.mjs +160 -81
- package/lib/installer/runtime-assets.mjs +2 -0
- package/lib/installer/runtime-config.mjs +3 -0
- package/lib/installer/skill-sources.mjs +4 -3
- package/lib/installer/superpowers.mjs +2 -1
- package/lib/installer/target-errors.mjs +1 -0
- package/lib/installer/targets.mjs +14 -6
- package/lib/installer/uninstall.mjs +5 -4
- package/lib/installer/upgrade-state.mjs +14 -10
- package/lib/installer/upgrade.mjs +9 -5
- package/lib/management/operations.mjs +96 -48
- package/lib/management/status.mjs +10 -8
- package/lib/management/update.mjs +8 -7
- package/lib/models/catalog-gemini.mjs +48 -0
- package/lib/models/catalog.mjs +27 -12
- package/lib/models/config.mjs +23 -22
- package/lib/models/gemini-models.json +12 -0
- package/lib/models/profiles.mjs +7 -5
- package/lib/models/static-catalog.mjs +13 -14
- package/lib/npm/upgrade.mjs +2 -2
- package/lib/platforms/availability.mjs +98 -0
- package/lib/platforms/claude.mjs +14 -0
- package/lib/platforms/codex.mjs +16 -0
- package/lib/platforms/formats/gemini-markdown.mjs +48 -0
- package/lib/platforms/formats/markdown.mjs +39 -0
- package/lib/platforms/formats/toml.mjs +39 -0
- package/lib/platforms/gemini.mjs +14 -0
- package/lib/platforms/index.mjs +27 -0
- package/lib/policy/placement.mjs +4 -4
- package/lib/policy/render.mjs +13 -8
- package/lib/policy/role-policy.json +40 -21
- package/lib/prompts/agent-fragments.json +71 -1
- package/lib/prompts/render.mjs +32 -11
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/cooperative-schema.mjs +0 -23
- package/lib/runtime/cooperative.mjs +13 -34
- package/lib/runtime/evaluate.mjs +3 -69
- package/lib/runtime/gemini-stream.mjs +32 -0
- package/lib/runtime/git-evidence.mjs +0 -98
- package/lib/runtime/identity.mjs +2 -1
- package/lib/runtime/local-cli.mjs +14 -24
- package/lib/runtime/operations.mjs +2 -2
- package/lib/runtime/platform-registry.mjs +130 -0
- package/lib/runtime/role-bridge-args.mjs +57 -2
- package/lib/runtime/role-bridge.mjs +86 -65
- package/lib/runtime/role-dispatch-policy.mjs +17 -7
- package/lib/runtime/role-dispatch-store.mjs +20 -14
- package/lib/runtime/role-observe.mjs +1 -0
- package/lib/runtime/role-routing-config.mjs +36 -9
- package/lib/runtime/role-routing.mjs +62 -29
- package/lib/runtime/role-supervisor.mjs +114 -49
- package/lib/runtime/schema.mjs +5 -4
- package/lib/tui/app.mjs +84 -35
- package/lib/tui/custom-preset.mjs +114 -68
- package/lib/tui/derive-install-plan.mjs +19 -0
- package/lib/tui/diagram.mjs +68 -0
- package/lib/tui/mode.mjs +77 -0
- package/lib/tui/render.mjs +47 -16
- package/lib/tui/setup.mjs +168 -100
- package/lib/tui/terminal.mjs +9 -6
- package/lib/watch/anchor-store.mjs +44 -0
- package/lib/watch/dispatch.mjs +3 -3
- package/lib/watch/index.mjs +37 -24
- package/lib/watch/model.mjs +1 -0
- package/lib/watch/normalize-claude.mjs +50 -10
- package/lib/watch/normalize-codex.mjs +79 -5
- package/lib/watch/render.mjs +30 -13
- package/lib/watch/scope.mjs +2 -1
- package/lib/watch/status-line.mjs +51 -0
- package/lib/watch/tail.mjs +27 -0
- package/lib/watch/watcher.mjs +193 -53
- package/package.json +2 -1
- package/scripts/update-manifest.mjs +2 -2
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/cooperative-schema.mjs +0 -23
- package/shared/skill/runtime/cooperative.mjs +13 -34
- package/shared/skill/runtime/evaluate.mjs +3 -69
- package/shared/skill/runtime/gemini-stream.mjs +32 -0
- package/shared/skill/runtime/git-evidence.mjs +0 -98
- package/shared/skill/runtime/identity.mjs +2 -1
- package/shared/skill/runtime/local-cli.mjs +14 -24
- package/shared/skill/runtime/operations.mjs +2 -2
- package/shared/skill/runtime/platform-registry.mjs +130 -0
- package/shared/skill/runtime/role-bridge-args.mjs +57 -2
- package/shared/skill/runtime/role-bridge.mjs +86 -65
- package/shared/skill/runtime/role-dispatch-policy.mjs +17 -7
- package/shared/skill/runtime/role-dispatch-store.mjs +20 -14
- package/shared/skill/runtime/role-observe.mjs +1 -0
- package/shared/skill/runtime/role-policy.json +40 -21
- package/shared/skill/runtime/role-routing-config.mjs +36 -9
- package/shared/skill/runtime/role-routing.mjs +62 -29
- package/shared/skill/runtime/role-supervisor.mjs +114 -49
- package/shared/skill/runtime/schema.mjs +5 -4
package/lib/watch/watcher.mjs
CHANGED
|
@@ -3,19 +3,21 @@ import fsp from 'node:fs/promises';
|
|
|
3
3
|
import {WATCH_LIMITS as L, MESSAGE_KINDS} from './model.mjs';
|
|
4
4
|
import {sanitizeText, sanitizeMessage, isVisible} from './policy.mjs';
|
|
5
5
|
import {topLabel, childLabel, dispatchLabel, roleFromName} from './labels.mjs';
|
|
6
|
-
import {normalizeCodexLine} from './normalize-codex.mjs';
|
|
7
|
-
import {createClaudeState, normalizeClaudeLine, parseClaudeAgentMeta} from './normalize-claude.mjs';
|
|
8
|
-
import {createTail, readTail, readHead} from './tail.mjs';
|
|
6
|
+
import {createCodexState, normalizeCodexLine, codexLineCwd} from './normalize-codex.mjs';
|
|
7
|
+
import {createClaudeState, normalizeClaudeLine, parseClaudeAgentMeta, claudeLineCwd} from './normalize-claude.mjs';
|
|
8
|
+
import {createTail, readTail, readHead, readLatestCwd} from './tail.mjs';
|
|
9
9
|
import {refreshScope, inScope, claudeDirPrefixes, realPath} from './scope.mjs';
|
|
10
10
|
import {listCodexRollouts, readCodexMeta} from './discover-codex.mjs';
|
|
11
11
|
import {createClaudeDiscovery, readClaudeHead} from './discover-claude.mjs';
|
|
12
12
|
import {createDispatchIndex} from './dispatch.mjs';
|
|
13
|
+
import {resolveDispatchStore} from './anchor-store.mjs';
|
|
14
|
+
import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
|
|
13
15
|
import {GIT_ALLOWED} from './git.mjs';
|
|
14
16
|
|
|
15
17
|
/** Read-only, timer-free merger. The caller owns scheduling and output. */
|
|
16
|
-
export function createWatcher({options, homes, scope: initialScope, git, now, dependencies = {}}) {
|
|
18
|
+
export function createWatcher({options, homes, scope: initialScope, git, now, registry = DEFAULT_PLATFORM_REGISTRY, dependencies = {}}) {
|
|
17
19
|
const {readClaudeHead: claudeHead = readClaudeHead, readCodexMeta: codexMeta = readCodexMeta,
|
|
18
|
-
lstat = fsp.lstat, createClaudeDiscovery: claudeDiscovery = createClaudeDiscovery, createDispatchIndex: dispatchIndex = createDispatchIndex} = dependencies;
|
|
20
|
+
lstat = fsp.lstat, maxKnown = L.maxKnown, createClaudeDiscovery: claudeDiscovery = createClaudeDiscovery, createDispatchIndex: dispatchIndex = createDispatchIndex} = dependencies;
|
|
19
21
|
const platforms = options.platforms ?? ['codex','claude'];
|
|
20
22
|
const session = options.session ?? null, verbose = Boolean(options.verbose);
|
|
21
23
|
const tailCount = options.tail ?? L.defaultTail;
|
|
@@ -23,10 +25,13 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
23
25
|
let lastDiscovery = -Infinity, lastRefresh = now(), capped = false, waiting = false;
|
|
24
26
|
const followed = new Map(), pending = new Map(), ignored = new Map(), detached = new Map();
|
|
25
27
|
const seenAtStart = new Map(), heads = new Map(), metas = new Map(), agentMetas = new Map(), childLists = new Map();
|
|
28
|
+
const known = new Map(), latestCwds = new Map();
|
|
26
29
|
const compressed = new Set(), missingDispatch = new Set(), repos = new Map();
|
|
27
30
|
const rootsByCwd = new Map(), gitTopByCwd = new Map(), shellRoots = new Map();
|
|
31
|
+
const nestedChecks = new Map(), nestedFailures = new Map();
|
|
32
|
+
let lastNestedRefresh = -Infinity;
|
|
28
33
|
let shellCursor = 0;
|
|
29
|
-
|
|
34
|
+
let dispatch;
|
|
30
35
|
const claude = homes.claude ? claudeDiscovery({claudeHome:homes.claude}) : null;
|
|
31
36
|
const stamp = () => new Date(now()).toISOString();
|
|
32
37
|
const notice = text => ({v:1,ts:stamp(),observedAt:stamp(),source:'watch',label:'watch',kind:'notice',text});
|
|
@@ -36,28 +41,94 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
36
41
|
const e = {...event};
|
|
37
42
|
if (e.text !== undefined) e.text = MESSAGE_KINDS.includes(e.kind) ? sanitizeMessage(e.text) : sanitizeText(e.text);
|
|
38
43
|
if (e.tool !== undefined) e.tool = sanitizeText(e.tool);
|
|
44
|
+
if (e.skill !== undefined) e.skill = sanitizeText(e.skill);
|
|
45
|
+
if (e.plugin !== undefined) e.plugin = sanitizeText(e.plugin);
|
|
46
|
+
delete e.skillOnly;
|
|
39
47
|
if (e.paths) e.paths = e.paths.map(sanitizeText);
|
|
40
48
|
return e;
|
|
41
49
|
};
|
|
42
50
|
const selectedDispatch = ref => !session || ref.dispatchId === session || ref.sessionIds.includes(session);
|
|
43
51
|
const dispatchInScope = ref => ref.inScope && (scope.kind==='all' || scope.kind==='session'
|
|
44
|
-
|| (ref.cwd ? inScope(scope,ref.cwd) : [...followed.values()].some(row=>ref.sessionIds.includes(row.id))));
|
|
52
|
+
|| (ref.cwd ? inScope(scope,ref.cwd) : [...followed.values()].some(row=>ref.sessionIds.includes(row.id) && cwdInScope(row.cwd))));
|
|
45
53
|
const allowedDispatch = ref => dispatchInScope(ref) && selectedDispatch(ref);
|
|
46
54
|
function mapped(row) {
|
|
47
55
|
const ref = dispatch.bySession(row.id);
|
|
48
56
|
return ref && ref.inScope && (scope.kind==='all' || scope.kind==='session'
|
|
49
|
-
|| (ref.cwd ? inScope(scope,ref.cwd) :
|
|
57
|
+
|| (ref.cwd ? inScope(scope,ref.cwd) : cwdInScope(row.cwd))) ? ref : null;
|
|
58
|
+
}
|
|
59
|
+
const selectedRoot = cwd => path.resolve(cwd)===scope.roots[0] || realPath(cwd)===scope.roots[0];
|
|
60
|
+
function cwdInScope(cwd) {
|
|
61
|
+
if (scope.kind==='all' || scope.kind==='session') return true;
|
|
62
|
+
if (!cwd || !inScope(scope,cwd)) return false;
|
|
63
|
+
return scope.kind!=='repo' || selectedRoot(cwd) || nestedChecks.get(cwd)?.inside===true;
|
|
64
|
+
}
|
|
65
|
+
async function verifyCwd(cwd, out) {
|
|
66
|
+
if (scope.kind!=='repo' || !cwd || !inScope(scope,cwd) || selectedRoot(cwd) || nestedChecks.has(cwd)) return;
|
|
67
|
+
if (now()-(nestedFailures.get(cwd)??-Infinity)<L.discoveryMs) return;
|
|
68
|
+
let result;
|
|
69
|
+
try { result=(await git(cwd,GIT_ALLOWED[0]))?.trim(); }
|
|
70
|
+
catch { /* A failed check remains outside until the next discovery interval. */ }
|
|
71
|
+
if (!result) {nestedFailures.set(cwd,now());return;}
|
|
72
|
+
const top=realPath(result), inside=top===scope.roots[0];
|
|
73
|
+
nestedFailures.delete(cwd);
|
|
74
|
+
if (nestedChecks.size>=L.maxRepos) nestedChecks.delete(nestedChecks.keys().next().value);
|
|
75
|
+
nestedChecks.set(cwd,{inside});
|
|
76
|
+
// Reuse successful lookups for root/shell identity without caching failures here.
|
|
77
|
+
if (gitTopByCwd.size>=L.maxRepos) gitTopByCwd.delete(gitTopByCwd.keys().next().value);
|
|
78
|
+
gitTopByCwd.set(cwd,top);
|
|
79
|
+
if (!inside && now()-lastNestedRefresh>=L.discoveryMs) {
|
|
80
|
+
scope=await refreshScope(scope,git);
|
|
81
|
+
lastRefresh=now();lastNestedRefresh=lastRefresh;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const anyCwdInScope = row => cwdInScope(row.cwd) || cwdInScope(row.latestCwd);
|
|
85
|
+
const parentOf = row => followed.get(row.parentId) ?? known.get(row.parentId);
|
|
86
|
+
function rememberKnown(row) {
|
|
87
|
+
const {id,platform,origin,parentId,agent,depth}=row;
|
|
88
|
+
known.delete(id);
|
|
89
|
+
known.set(id,{id,platform,origin,parentId,agent,depth});
|
|
90
|
+
while (known.size>maxKnown) known.delete(known.keys().next().value);
|
|
91
|
+
}
|
|
92
|
+
function ancestry(row) {
|
|
93
|
+
const seen=new Set([row.id]);
|
|
94
|
+
let desktop=false;
|
|
95
|
+
for (let steps=0; row.parentId && steps<maxKnown; steps++) {
|
|
96
|
+
const parent=parentOf(row);
|
|
97
|
+
if (!parent || seen.has(parent.id)) return {resolved:false,desktop};
|
|
98
|
+
desktop ||= parent.origin==='Codex Desktop';
|
|
99
|
+
seen.add(parent.id);
|
|
100
|
+
row=parent;
|
|
101
|
+
}
|
|
102
|
+
return {resolved:!row.parentId,desktop};
|
|
103
|
+
}
|
|
104
|
+
function lineGate(row) {
|
|
105
|
+
return scope.kind==='all' || scope.kind==='session' || Boolean(mapped(row)) || cwdInScope(row.cwd);
|
|
106
|
+
}
|
|
107
|
+
async function setCwd(row, cwd, out) {
|
|
108
|
+
row.state.cwd=cwd;
|
|
109
|
+
if (row.cwd===cwd) return;
|
|
110
|
+
row.cwd=cwd;
|
|
111
|
+
row.gitTop=await gitTop(cwd);
|
|
112
|
+
row.root=await sessionRoot(cwd);
|
|
113
|
+
}
|
|
114
|
+
async function ensureShellRoot(row, out) {
|
|
115
|
+
if (row.gitTop && !shellRoots.has(row.gitTop) && shellRoots.size < L.maxRepos) {
|
|
116
|
+
const state = {snapshot:null,pending:false,pendingSince:undefined,lastTriggerAt:-Infinity,
|
|
117
|
+
lastScanAt:-Infinity,prevScanAt:-Infinity,claims:new Map(),candidates:new Map(),failures:0,off:false};
|
|
118
|
+
shellRoots.set(row.gitTop,state);
|
|
119
|
+
await scanRoot(row.gitTop,state,out);
|
|
120
|
+
}
|
|
50
121
|
}
|
|
51
122
|
function label(row, seen = new Set()) {
|
|
52
123
|
if (seen.has(row.id)) return topLabel(row);
|
|
53
124
|
seen.add(row.id);
|
|
54
125
|
const ref = mapped(row);
|
|
55
126
|
if (ref) return dispatchLabel(ref.rawRole, ref.dispatchId);
|
|
56
|
-
const parent =
|
|
127
|
+
const parent = parentOf(row);
|
|
57
128
|
return parent ? childLabel(label(parent, seen), row.agent) : topLabel({platform:row.platform,origin:row.origin,sessionId:row.id});
|
|
58
129
|
}
|
|
59
130
|
function identity(row) {
|
|
60
|
-
const ref = mapped(row), parent =
|
|
131
|
+
const ref = mapped(row), parent = parentOf(row);
|
|
61
132
|
return {
|
|
62
133
|
v:1, observedAt:stamp(), platform:row.platform,
|
|
63
134
|
source:ref ? 'bridge' : parent ? 'subagent' : 'session',
|
|
@@ -73,11 +144,38 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
73
144
|
return [row.id.slice(0,8),row.origin,row.version,row.cwd ? `cwd=${row.cwd}` : '',
|
|
74
145
|
...(ref ? ['dispatch',ref.dispatchId,ref.workflowId] : [])].filter(Boolean).join(' ');
|
|
75
146
|
}
|
|
76
|
-
function normalize(row, lines, live = false) {
|
|
77
|
-
const
|
|
147
|
+
async function normalize(row, lines, live = false, out = []) {
|
|
148
|
+
const events = [];
|
|
149
|
+
let sawInScope=false, firstSession;
|
|
78
150
|
for (const line of lines) {
|
|
79
|
-
const
|
|
80
|
-
|
|
151
|
+
const cwd=row.platform==='codex'?codexLineCwd(line):claudeLineCwd(line);
|
|
152
|
+
if (cwd) await setCwd(row,cwd,out);
|
|
153
|
+
await verifyCwd(row.cwd,out);
|
|
154
|
+
if (row.gitTop===undefined && gitTopByCwd.has(row.cwd)) {
|
|
155
|
+
row.gitTop=await gitTop(row.cwd);
|
|
156
|
+
row.root=await sessionRoot(row.cwd);
|
|
157
|
+
}
|
|
158
|
+
const inside=lineGate(row), entering=row.inScopeNow===false && inside;
|
|
159
|
+
if (entering) events.push(clean({...identity(row),ts:line.timestamp??stamp(),kind:'session',text:sessionText(row)}));
|
|
160
|
+
if (row.inScopeNow===true && !inside) debug(out,`session ${row.id.slice(0,8)} left scope: cwd=${row.cwd}`);
|
|
161
|
+
row.inScopeNow=inside;
|
|
162
|
+
row.codexState.cwd=row.cwd;
|
|
163
|
+
const normalized = row.platform === 'codex'
|
|
164
|
+
? normalizeCodexLine(line,row.codexState,{codexHome:homes.codex,userHome:homes.user})
|
|
165
|
+
: normalizeClaudeLine(line,row.state);
|
|
166
|
+
if (inside) {
|
|
167
|
+
await ensureShellRoot(row,out); sawInScope=true;
|
|
168
|
+
const shell=shellRoots.get(row.gitTop);
|
|
169
|
+
if (live && shell && !shell.off) {
|
|
170
|
+
shell.pending=true; shell.pendingSince ??= now(); shell.lastTriggerAt=now();
|
|
171
|
+
shell.candidates.set(row.id,{ts:now(),identity:identity(row)});
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
for (const e of normalized) {
|
|
175
|
+
if (['turn_end','turn_failed'].includes(e.kind)) row.active = false;
|
|
176
|
+
else if (['turn_start','user','agent','reasoning','command','tool','tool_failed','file_change','file_create','file_delete','spawn','approval'].includes(e.kind)) row.active = true;
|
|
177
|
+
if (!inside) continue;
|
|
178
|
+
if (e.kind==='command' && e.skillOnly && !verbose) continue;
|
|
81
179
|
const shell = shellRoots.get(row.gitTop);
|
|
82
180
|
if (live && shell && !shell.off && ['file_change','file_create','file_delete'].includes(e.kind)) {
|
|
83
181
|
for (const file of e.paths ?? []) {
|
|
@@ -85,19 +183,22 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
85
183
|
shell.claims.set(path.join(realPath(path.dirname(absolute)),path.basename(absolute)),now());
|
|
86
184
|
}
|
|
87
185
|
}
|
|
88
|
-
if (['turn_end','turn_failed'].includes(e.kind)) row.active = false;
|
|
89
|
-
else if (['turn_start','user','agent','reasoning','command','tool','tool_failed','file_change','file_create','file_delete','spawn','approval'].includes(e.kind)) row.active = true;
|
|
90
186
|
if (!isVisible(e.kind,verbose) || (e.kind === 'notice' && !verbose)) continue;
|
|
91
|
-
|
|
187
|
+
firstSession ??= clean({...identity(row),ts:e.ts??stamp(),kind:'session',text:sessionText(row)});
|
|
188
|
+
if (entering && e.kind==='session') continue;
|
|
189
|
+
events.push(clean({...identity(row),...e,ts:e.ts ?? stamp(),...(e.kind === 'session' ? {text:sessionText(row)} : {})}));
|
|
92
190
|
}
|
|
93
191
|
}
|
|
94
|
-
return
|
|
192
|
+
return {events,sawInScope,firstSession};
|
|
95
193
|
}
|
|
96
194
|
function emit(row, events, out) {
|
|
97
195
|
if (row.holdUntil !== undefined && !mapped(row) && now() < row.holdUntil) row.held.push(...events);
|
|
98
196
|
else {
|
|
99
197
|
// Held events receive the final identity only when released.
|
|
100
|
-
out.push(...row.held.map(e=>
|
|
198
|
+
out.push(...row.held.map(e=>{
|
|
199
|
+
const atLine={...row,cwd:e.cwd,root:e.root};
|
|
200
|
+
return clean({...e,...identity(atLine),...(e.kind==='session'?{text:sessionText(atLine)}:{})});
|
|
201
|
+
}),...events);
|
|
101
202
|
row.held=[]; delete row.holdUntil;
|
|
102
203
|
}
|
|
103
204
|
}
|
|
@@ -128,37 +229,51 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
128
229
|
}
|
|
129
230
|
function eligible(row) {
|
|
130
231
|
if (!platforms.includes(row.platform) || row.origin === 'Codex Desktop') return false;
|
|
131
|
-
if (row.parentId)
|
|
232
|
+
if (row.parentId) {
|
|
233
|
+
if (scope.kind==='all' || scope.kind==='session') return followed.has(row.parentId);
|
|
234
|
+
const chain=ancestry(row);
|
|
235
|
+
if (chain.desktop) {ignored.set(row.file,row.size);return false;}
|
|
236
|
+
return chain.resolved && anyCwdInScope(row);
|
|
237
|
+
}
|
|
132
238
|
const ref = mapped(row);
|
|
133
239
|
if (session) return row.id === session || Boolean(ref && selectedDispatch(ref));
|
|
134
|
-
return Boolean(ref) || (row
|
|
240
|
+
return Boolean(ref) || anyCwdInScope(row);
|
|
135
241
|
}
|
|
136
242
|
async function attach(row, startup, out) {
|
|
137
243
|
const previous = detached.get(row.file) ?? (!startup && !pending.has(row.file) ? seenAtStart.get(row.file) : undefined);
|
|
138
244
|
let history;
|
|
139
245
|
try { history = previous ? {endOffset:previous.offset} : await readTail(row.file); }
|
|
140
246
|
catch (error) { debug(out,`session file unreadable: ${row.id.slice(0,8)} (${error.code ?? 'error'})`); ignored.set(row.file,row.size); return; }
|
|
141
|
-
row.
|
|
142
|
-
row.root = await sessionRoot(row.cwd);
|
|
143
|
-
if (row.gitTop && !shellRoots.has(row.gitTop) && shellRoots.size < L.maxRepos) {
|
|
144
|
-
const state = {snapshot:null,pending:false,pendingSince:undefined,lastTriggerAt:-Infinity,
|
|
145
|
-
lastScanAt:-Infinity,prevScanAt:-Infinity,claims:new Map(),candidates:new Map(),failures:0,off:false};
|
|
146
|
-
shellRoots.set(row.gitTop,state);
|
|
147
|
-
await scanRoot(row.gitTop,state,out);
|
|
148
|
-
}
|
|
247
|
+
row.headCwd=row.cwd;
|
|
149
248
|
row.tail=createTail(row.file,{offset:previous?.offset ?? history.endOffset});
|
|
150
|
-
row.state=createClaudeState(); row.active=false; row.held=[]; row.lastActivity=row.mtimeMs;
|
|
249
|
+
row.state=createClaudeState(); row.codexState=createCodexState(); row.active=false; row.held=[]; row.lastActivity=row.mtimeMs;
|
|
250
|
+
row.cwd=undefined;
|
|
251
|
+
await setCwd(row,previous?.cwd??row.headCwd,out);
|
|
252
|
+
await verifyCwd(row.cwd,out);
|
|
151
253
|
followed.set(row.id,row); pending.delete(row.file); detached.delete(row.file);
|
|
152
|
-
if (!startup && !previous && !mapped(row) && (row.origin==='codex_exec'||row.platform==='claude') && now()-row.mtimeMs<=L.holdCreatedWithinMs) row.holdUntil=now()+L.holdMs;
|
|
254
|
+
if (!startup && !previous && !row.parentId && !mapped(row) && (row.origin==='codex_exec'||row.platform==='claude') && now()-row.mtimeMs<=L.holdCreatedWithinMs) row.holdUntil=now()+L.holdMs;
|
|
153
255
|
const showHistory = startup ? tailCount > 0 && now()-row.mtimeMs<=L.historyWindowMs : !previous;
|
|
154
|
-
const events=
|
|
256
|
+
const {events,firstSession}=await normalize(row,history.lines??[],false,out);
|
|
155
257
|
if (showHistory) {
|
|
156
|
-
if (!events.some(e=>e.kind==='session'))
|
|
258
|
+
if (!events.some(e=>e.kind==='session')) {
|
|
259
|
+
const initialSession=firstSession ?? (lineGate(row)
|
|
260
|
+
? clean({...identity(row),ts:stamp(),kind:'session',text:sessionText(row)}) : undefined);
|
|
261
|
+
if (initialSession) events.unshift(initialSession);
|
|
262
|
+
}
|
|
157
263
|
emit(row,events,out);
|
|
158
264
|
}
|
|
265
|
+
if (row.inScopeNow===undefined) row.inScopeNow=lineGate(row);
|
|
266
|
+
if (lineGate(row)) await ensureShellRoot(row,out);
|
|
267
|
+
if (seenAtStart.has(row.file)) seenAtStart.get(row.file).cwd=row.cwd;
|
|
159
268
|
}
|
|
160
269
|
async function gitTop(cwd) {
|
|
161
270
|
if (!cwd) return undefined;
|
|
271
|
+
if (scope.kind==='repo' && inScope(scope,cwd)) {
|
|
272
|
+
// setCwd needs the same check before it can populate root/shell identity.
|
|
273
|
+
await verifyCwd(cwd);
|
|
274
|
+
if (selectedRoot(cwd)) return scope.roots[0];
|
|
275
|
+
if (nestedFailures.has(cwd)) return undefined;
|
|
276
|
+
}
|
|
162
277
|
if (gitTopByCwd.has(cwd)) return gitTopByCwd.get(cwd);
|
|
163
278
|
let top;
|
|
164
279
|
try {
|
|
@@ -183,7 +298,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
183
298
|
} catch { return cwd; }
|
|
184
299
|
}
|
|
185
300
|
function rememberStart(item, startup) {
|
|
186
|
-
if (startup) seenAtStart.set(item.file,{...item,offset:item.size});
|
|
301
|
+
if (startup) seenAtStart.set(item.file,{...item,offset:item.size,cwd:item.latestCwd??item.cwd});
|
|
187
302
|
}
|
|
188
303
|
async function details(file) {
|
|
189
304
|
try { const {size,mtimeMs} = await fsp.stat(file); return {size,mtimeMs}; }
|
|
@@ -264,7 +379,8 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
264
379
|
if (skipHead(item,startup)) continue;
|
|
265
380
|
const meta=await cachedHead(metas,item,codexMeta);
|
|
266
381
|
if (!meta) continue;
|
|
267
|
-
|
|
382
|
+
const row={...item,id:meta.threadId,platform:'codex',origin:meta.originator,cwd:meta.cwd,version:meta.cliVersion,parentId:meta.parentId,depth:meta.depth,agent:{agentRole:meta.agentRole,nickname:meta.agentNickname}};
|
|
383
|
+
rememberKnown(row);rows.push(row);
|
|
268
384
|
}
|
|
269
385
|
}
|
|
270
386
|
if (claude && platforms.includes('claude')) {
|
|
@@ -283,15 +399,19 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
283
399
|
}
|
|
284
400
|
pending.delete(item.file);
|
|
285
401
|
const main={...item,id:head.sessionId,platform:'claude',origin:head.entrypoint,cwd:head.cwd,version:head.version};
|
|
402
|
+
rememberKnown(main);
|
|
286
403
|
if (!followed.has(main.id)) rows.push(main);
|
|
287
404
|
for (const child of children) {
|
|
288
405
|
if (skipHead(child,startup)) continue;
|
|
289
406
|
const childHead=await cachedHead(heads,child,claudeHead);
|
|
290
|
-
|
|
407
|
+
const row={...child,id:`agent-${child.agentId}`,platform:'claude',origin:head.entrypoint,cwd:childHead?.cwd??head.cwd,version:childHead?.version??head.version,parentId:main.id,agent:{agentType:child.meta?.agentType}};
|
|
408
|
+
rememberKnown(row);rows.push(row);
|
|
291
409
|
}
|
|
292
410
|
}
|
|
293
411
|
}
|
|
294
|
-
for (const row of rows)
|
|
412
|
+
for (const row of rows) {
|
|
413
|
+
await rememberRepo(row.cwd);
|
|
414
|
+
}
|
|
295
415
|
updates ??= await scanDispatch();
|
|
296
416
|
rows.sort((a,b)=>b.mtimeMs-a.mtimeMs||a.file.localeCompare(b.file));
|
|
297
417
|
let remaining=rows.filter(row=> {
|
|
@@ -300,6 +420,16 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
300
420
|
const previous=detached.get(row.file) ?? seenAtStart.get(row.file);
|
|
301
421
|
return !previous || row.size>previous.size || pending.has(row.file);
|
|
302
422
|
});
|
|
423
|
+
for (const row of remaining) {
|
|
424
|
+
const previous=detached.get(row.file) ?? seenAtStart.get(row.file);
|
|
425
|
+
if (startup || !previous || row.size>previous.size) {
|
|
426
|
+
const extract=row.platform==='codex'?codexLineCwd:claudeLineCwd;
|
|
427
|
+
row.latestCwd=await cachedHead(latestCwds,row,file=>readLatestCwd(file,extract));
|
|
428
|
+
}
|
|
429
|
+
rememberStart(row,startup);
|
|
430
|
+
await verifyCwd(row.cwd,out);
|
|
431
|
+
await verifyCwd(row.latestCwd,out);
|
|
432
|
+
}
|
|
303
433
|
let progress=true;
|
|
304
434
|
while(progress) {
|
|
305
435
|
progress=false;
|
|
@@ -310,14 +440,17 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
310
440
|
const oldest=[...followed.values()].sort((a,b)=>a.mtimeMs-b.mtimeMs)[0];
|
|
311
441
|
if (!capped) {out.push(notice('following the newest 64 sessions; others are skipped'));capped=true;}
|
|
312
442
|
if (oldest.mtimeMs>=row.mtimeMs || row.parentId===oldest.id) continue;
|
|
313
|
-
followed.delete(oldest.id); detached.set(oldest.file,{file:oldest.file,platform:oldest.platform,offset:oldest.tail.offset,size:oldest.size});
|
|
443
|
+
followed.delete(oldest.id); detached.set(oldest.file,{file:oldest.file,platform:oldest.platform,offset:oldest.tail.offset,size:oldest.size,cwd:oldest.cwd});
|
|
314
444
|
}
|
|
315
445
|
await attach(row,startup,out);progress=true;
|
|
316
446
|
}
|
|
317
447
|
remaining=next;
|
|
318
448
|
}
|
|
319
449
|
for (const row of remaining) {
|
|
320
|
-
|
|
450
|
+
const chain=ancestry(row);
|
|
451
|
+
const missingParent=scope.kind==='all'||scope.kind==='session' ? !followed.has(row.parentId) : !chain.resolved;
|
|
452
|
+
if ((scope.kind==='repo'||scope.kind==='dir') && row.parentId && (!missingParent || chain.desktop)) pending.delete(row.file);
|
|
453
|
+
if (row.parentId && row.origin!=='Codex Desktop' && missingParent && !chain.desktop) {
|
|
321
454
|
const wait=pending.get(row.file) ?? {...row,until:now()+L.holdMs};
|
|
322
455
|
if (now()>=wait.until) {pending.delete(row.file);ignored.set(row.file,row.size);debug(out,`parent session not found for ${row.id}`);}
|
|
323
456
|
else pending.set(row.file,wait);
|
|
@@ -347,19 +480,19 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
347
480
|
debug(out,`session file unreadable: ${row.id.slice(0,8)} (${error.code??'error'})`);continue;
|
|
348
481
|
}
|
|
349
482
|
if (result.gone) {followed.delete(id);debug(out,`session file removed: ${row.id.slice(0,8)}`);continue;}
|
|
350
|
-
if (result.reset) {
|
|
483
|
+
if (result.reset) {
|
|
484
|
+
row.state=createClaudeState();row.codexState=createCodexState();row.active=false;
|
|
485
|
+
await setCwd(row,row.headCwd,out);row.inScopeNow=lineGate(row);
|
|
486
|
+
debug(out,`session restarted from the beginning: ${row.id.slice(0,8)}`);
|
|
487
|
+
}
|
|
351
488
|
if (result.overflowed && !row.overflowed) debug(out,`line over 4 MiB skipped in ${row.id.slice(0,8)}`);
|
|
352
489
|
row.overflowed=result.overflowed;
|
|
353
|
-
if (row.tail.offset!==row.size) row.lastActivity=now();
|
|
354
490
|
row.size=row.tail.offset;
|
|
355
|
-
const
|
|
356
|
-
if (
|
|
357
|
-
|
|
358
|
-
shell.candidates.set(row.id,now());
|
|
359
|
-
}
|
|
360
|
-
emit(row,normalize(row,result.lines,true),out);
|
|
491
|
+
const {events,sawInScope}=await normalize(row,result.lines,true,out);
|
|
492
|
+
if (sawInScope) row.lastActivity=now();
|
|
493
|
+
emit(row,events,out);
|
|
361
494
|
if (now()-row.lastActivity>=L.idleDetachMs && !row.held.length) {
|
|
362
|
-
followed.delete(id);detached.set(row.file,{file:row.file,platform:row.platform,offset:row.tail.offset,size:row.size});debug(out,`detached idle session ${row.id.slice(0,8)}`);
|
|
495
|
+
followed.delete(id);detached.set(row.file,{file:row.file,platform:row.platform,offset:row.tail.offset,size:row.size,cwd:row.cwd});debug(out,`detached idle session ${row.id.slice(0,8)}`);
|
|
363
496
|
}
|
|
364
497
|
}
|
|
365
498
|
}
|
|
@@ -405,11 +538,11 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
405
538
|
}
|
|
406
539
|
}
|
|
407
540
|
state.snapshot=snapshot;
|
|
408
|
-
const candidate=[...state.candidates].filter(([id])=>followed.has(id)).sort((a,b)=>b[1]-a[1])[0];
|
|
541
|
+
const candidate=[...state.candidates].filter(([id,value])=>followed.has(id) && value?.identity).sort((a,b)=>b[1].ts-a[1].ts)[0];
|
|
409
542
|
if (candidate) {
|
|
410
543
|
const row=followed.get(candidate[0]);
|
|
411
544
|
const events=Object.entries(changes).filter(([,files])=>files.length).map(([kind,files])=>
|
|
412
|
-
clean({...identity(
|
|
545
|
+
clean({...candidate[1].identity,observedAt:stamp(),ts:stamp(),kind,paths:files.sort(),inferred:true}));
|
|
413
546
|
emit(row,events,out);
|
|
414
547
|
}
|
|
415
548
|
}
|
|
@@ -436,11 +569,18 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
436
569
|
async start() {
|
|
437
570
|
if (started||closed) return [];
|
|
438
571
|
started=true;
|
|
572
|
+
const store = await resolveDispatchStore({homes, registry});
|
|
573
|
+
// Keep observing the legacy path even when its first lease arrives after startup.
|
|
574
|
+
const storeDir = store.kind === 'none' && homes.codex && registry.isPlatformId('codex')
|
|
575
|
+
? path.join(homes.codex, 'arc-role-dispatch') : store.dir;
|
|
576
|
+
dispatch = dispatchIndex({storeDir});
|
|
439
577
|
const description=session?`session ${session}`:scope.kind==='repo'?`scope ${scope.roots[0]} (${scope.roots.length} worktrees)`:scope.kind==='dir'?`scope ${scope.roots[0]}`:'scope all';
|
|
440
|
-
const out=[];
|
|
578
|
+
const out=[];
|
|
579
|
+
if (store.kind === 'ambiguous') out.push(notice('dispatch store ambiguous'));
|
|
580
|
+
await discover(true,out);
|
|
441
581
|
const history=sort(out.filter(e=>e.source!=='watch')).slice(-tailCount || Infinity);
|
|
442
582
|
const diagnostics=out.filter(e=>e.source==='watch');
|
|
443
|
-
return markEmitted([notice(`arc watch: ${description} · ${platforms.join('+')} · Ctrl-C to stop`),...diagnostics,...(tailCount?history:[]),notice('live')]);
|
|
583
|
+
return markEmitted([notice(`arc watch: ${description} · ${platforms.map(name => name.toUpperCase()).join('+')} · Ctrl-C to stop`),...diagnostics,...(tailCount?history:[]),notice('live')]);
|
|
444
584
|
},
|
|
445
585
|
async tick() {
|
|
446
586
|
if (!started||closed) return [];
|
|
@@ -451,7 +591,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, de
|
|
|
451
591
|
await scanShell(out);
|
|
452
592
|
return markEmitted(sort(out));
|
|
453
593
|
},
|
|
454
|
-
busy() {return [...followed.values()].some(row=>row.active && now()-row.lastActivity<=L.spinnerIdleMs);},
|
|
594
|
+
busy() {return [...followed.values()].some(row=>row.active && (row.inScopeNow || mapped(row)) && now()-row.lastActivity<=L.spinnerIdleMs);},
|
|
455
595
|
async close() {closed=true;followed.clear();pending.clear();},
|
|
456
596
|
};
|
|
457
597
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yunhozz/arc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"codex/agents/",
|
|
48
48
|
"claude/skill/",
|
|
49
49
|
"claude/agents/",
|
|
50
|
+
"gemini/",
|
|
50
51
|
"MANIFEST.sha256",
|
|
51
52
|
"install.command",
|
|
52
53
|
"!**/__pycache__/**",
|
|
@@ -4,7 +4,7 @@ import path from 'node:path';
|
|
|
4
4
|
import { fileURLToPath } from 'node:url';
|
|
5
5
|
const i = process.argv.indexOf('--root');
|
|
6
6
|
const root = i < 0 ? fileURLToPath(new URL('../', import.meta.url)) : path.resolve(process.argv[i + 1]);
|
|
7
|
-
const mutable = new Set(['codex/skill/models.toml', 'claude/skill/models.toml']);
|
|
7
|
+
const mutable = new Set(['codex/skill/models.toml', 'claude/skill/models.toml', 'gemini/skill/models.toml']);
|
|
8
8
|
const excluded = new Set(['.DS_Store', '__pycache__', 'build']);
|
|
9
9
|
const files = new Map();
|
|
10
10
|
function visit(relative) {
|
|
@@ -17,7 +17,7 @@ function visit(relative) {
|
|
|
17
17
|
} else if (stat.isFile() && !mutable.has(relative)) files.set(relative,fs.readFileSync(filename));
|
|
18
18
|
else if (!stat.isFile()) throw new Error(`Protected payload is not regular: ${relative}`);
|
|
19
19
|
}
|
|
20
|
-
for (const entry of ['README.md', 'install.command', 'package.json', 'bin', 'lib', 'native/binding.c', 'native/binding.gyp', 'scripts', 'vendor', 'prebuilds', 'shared/skill', 'codex/skill', 'codex/agents', 'claude/skill', 'claude/agents']) visit(entry);
|
|
20
|
+
for (const entry of ['README.md', 'install.command', 'package.json', 'bin', 'lib', 'native/binding.c', 'native/binding.gyp', 'scripts', 'vendor', 'prebuilds', 'shared/skill', 'codex/skill', 'codex/agents', 'claude/skill', 'claude/agents', 'gemini']) visit(entry);
|
|
21
21
|
const content = renderManifest(files);
|
|
22
22
|
const manifest = path.join(root, 'MANIFEST.sha256');
|
|
23
23
|
if (process.argv.includes('--check')) {
|
|
@@ -8,7 +8,7 @@ export const COOPERATIVE_RUNTIME_MODULES=Object.freeze([
|
|
|
8
8
|
'cli.mjs','command.mjs','bootstrap.mjs','cooperative-schema.mjs','cooperative.mjs','evaluate.mjs',
|
|
9
9
|
'scope.mjs','store.mjs','git-evidence.mjs','assignment.mjs','verification.mjs','acceptance.mjs','external.mjs','schema.mjs','operations.mjs','gate.mjs','adapters/codex.mjs','adapters/claude.mjs','capabilities.mjs','identity.mjs','git-query.mjs','target-preparation.mjs',
|
|
10
10
|
'local-cli.mjs','role-routing-config.mjs','role-routing.mjs','role-bridge.mjs',
|
|
11
|
-
'role-dispatch-policy.mjs','role-dispatch-store.mjs','role-bridge-args.mjs','role-observe.mjs','role-supervisor.mjs'
|
|
11
|
+
'role-dispatch-policy.mjs','role-dispatch-store.mjs','role-bridge-args.mjs','role-observe.mjs','role-supervisor.mjs','platform-registry.mjs','gemini-stream.mjs'
|
|
12
12
|
]);
|
|
13
13
|
export const cooperativeCoverage=()=>({enforcement:'cooperative',provenance:'operator-attested',nativeVerified:false});
|
|
14
14
|
export function commandResult({workflowId,state,input,decision='allow',ruleId='cooperative.recorded',persisted=false,...extra}){
|
|
@@ -2,7 +2,6 @@ import {ROLES} 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';
|
|
5
|
-
import path from 'node:path';
|
|
6
5
|
import {validateTargetPreparationRecord} from './target-preparation.mjs';
|
|
7
6
|
const fail=message=>{throw Error('Cooperative schema: '+message);};
|
|
8
7
|
const hash=value=>typeof value==='string'&&/^sha256:[a-f0-9]{64}$/.test(value);
|
|
@@ -11,24 +10,6 @@ const actor=value=>object(value)&&text(value.id)&&Object.keys(value).every(k=>['
|
|
|
11
10
|
const statement=value=>object(value)&&text(value.messageRef)&&object(value.data);
|
|
12
11
|
function fields(value,allowed){if(!object(value)||Object.keys(value).some(k=>!allowed.includes(k)))fail('unexpected input field');}
|
|
13
12
|
function json(value){try{const encoded=JSON.stringify(value);if(encoded===undefined)fail('JSON input');}catch{fail('JSON input');}}
|
|
14
|
-
const exact=(value,keys)=>object(value)&&Object.keys(value).length===keys.length&&keys.every(key=>Object.hasOwn(value,key));
|
|
15
|
-
const oid=value=>typeof value==='string'&&/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(value);
|
|
16
|
-
const time=value=>typeof value==='string'&&Number.isFinite(Date.parse(value))&&/(?:Z|[+-]\d\d:\d\d)$/.test(value);
|
|
17
|
-
const unique=value=>Array.isArray(value)&&new Set(value).size===value.length;
|
|
18
|
-
const gitPath=value=>text(value)&&!/[\\\x00\r\n:]/.test(value)&&!value.startsWith('/')&&!value.split('/').some(part=>!part||part==='.'||part==='..');
|
|
19
|
-
const ref=value=>text(value)&&/^refs\/[A-Za-z0-9][A-Za-z0-9._\/-]*$/.test(value)&&!value.includes('..')&&!value.includes('//')&&!value.endsWith('/')&&!value.endsWith('.')&&!value.endsWith('.lock');
|
|
20
|
-
const approval=value=>exact(value,['ref','version','hash','approvedAt'])&&text(value.ref)&&Number.isSafeInteger(value.version)&&value.version>0&&hash(value.hash)&&time(value.approvedAt);
|
|
21
|
-
const document=value=>exact(value,['version','hash','content'])&&Number.isSafeInteger(value.version)&&value.version>0&&hash(value.hash)&&typeof value.content==='string'&&Buffer.byteLength(value.content)<=1024*1024;
|
|
22
|
-
export function validatePlanAmendArguments(a){
|
|
23
|
-
if(!exact(a,['classification','reason','changedAt','affectedTaskIds','plan','history','approvals','writers','ownership','publication','remotes','recovery'])||!['contract','mechanical'].includes(a.classification)||!text(a.reason)||!time(a.changedAt)||!unique(a.affectedTaskIds)||!a.affectedTaskIds.length||!a.affectedTaskIds.every(text))fail('plan-amend request');
|
|
24
|
-
if(!exact(a.plan,['path','gitPath','old','new'])||!absolute(a.plan.path)||!gitPath(a.plan.gitPath)||!document(a.plan.old)||!document(a.plan.new)||a.plan.new.version<=a.plan.old.version)fail('plan-amend document');
|
|
25
|
-
if(!exact(a.history,['base','planCommit','head','branch'])||![a.history.base,a.history.planCommit,a.history.head].every(oid)||!text(a.history.branch)||/[\x00\r\n]/.test(a.history.branch))fail('plan-amend history');
|
|
26
|
-
if(!exact(a.approvals,['original','amendment'])||!approval(a.approvals.original)||!(a.classification==='mechanical'&&a.approvals.amendment===null||approval(a.approvals.amendment)))fail('plan-amend approvals');
|
|
27
|
-
if(!Array.isArray(a.writers)||!a.writers.length||a.writers.some(w=>!exact(w,['assignmentId','stoppedAt','evidenceRef'])||!text(w.assignmentId)||!time(w.stoppedAt)||!text(w.evidenceRef))||!unique(a.writers.map(w=>w.assignmentId)))fail('plan-amend writers');
|
|
28
|
-
if(!['exclusive','shared','unknown'].includes(a.ownership)||!['unpublished','published','unknown'].includes(a.publication)||!Array.isArray(a.remotes)||a.remotes.some(r=>!exact(r,['name','identity','complete','refs','observedAt','evidenceRef'])||!text(r.name)||!hash(r.identity)||r.complete!==true||!time(r.observedAt)||!text(r.evidenceRef)||!Array.isArray(r.refs)||r.refs.some(x=>!exact(x,['name','oid'])||!ref(x.name)||!oid(x.oid))||!unique(r.refs.map(x=>x.name)))||!unique(a.remotes.map(r=>r.name)))fail('plan-amend remote snapshot');
|
|
29
|
-
if(!exact(a.recovery,['ref','oid'])||!ref(a.recovery.ref)||!a.recovery.ref.startsWith('refs/arc/recovery/')||!oid(a.recovery.oid)||path.normalize(a.plan.path)!==a.plan.path)fail('plan-amend recovery');
|
|
30
|
-
return a;
|
|
31
|
-
}
|
|
32
13
|
export function validateCooperativeCommand(command){
|
|
33
14
|
assertSecretFree(command);fields(command,['command','input']);const {input,command:name}=command;
|
|
34
15
|
if(!['init','record','status','reconcile','prepare','result'].includes(name))fail('command');
|
|
@@ -53,7 +34,6 @@ export function validateCooperativeCommand(command){
|
|
|
53
34
|
if(input.result.status==='cancelled'&&(!object(input.result.notExecutedEvidence)||!text(input.result.notExecutedEvidence.messageRef)))fail('cancel requires not-executed evidence');
|
|
54
35
|
}
|
|
55
36
|
if((name==='prepare'||name==='result'&&!resultStatement)&&!text(input.operation))fail('operation');
|
|
56
|
-
if(name==='prepare'&&input.operation==='plan-amend')validatePlanAmendArguments(input.arguments);
|
|
57
37
|
return command;
|
|
58
38
|
}
|
|
59
39
|
export function validateCooperativeState(state){
|
|
@@ -65,15 +45,12 @@ export function validateCooperativeState(state){
|
|
|
65
45
|
for(const key of ['actors','selections','assignments','identities','leases','scopes','approvals','documents','tasks','requests','intents','results','checks','findings','acceptances','commits','audit','unresolved','records','targetHistory'])if(!Array.isArray(state[key]))fail(key);
|
|
66
46
|
if(state.tasks.some(t=>!object(t)||!text(t.id)||!Array.isArray(t.paths)||!Array.isArray(t.criteria)||!Array.isArray(t.requiredChecks)||!Array.isArray(t.dependencies))||new Set(state.tasks.map(t=>t.id)).size!==state.tasks.length)fail('task contracts');
|
|
67
47
|
if(state.commitObservations!==undefined&&(!Array.isArray(state.commitObservations)||state.commitObservations.some(o=>!object(o)||o.source!=='local-git'||!text(o.intentId)||!revision(o.revision))))fail('commit observations');
|
|
68
|
-
if(state.planAmendObservations!==undefined&&(!Array.isArray(state.planAmendObservations)||state.planAmendObservations.some(o=>!object(o)||o.source!=='local-git'||!text(o.intentId)||!revision(o.revision))))fail('plan-amend observations');
|
|
69
|
-
if(state.planAmendments!==undefined&&(!Array.isArray(state.planAmendments)||state.planAmendments.some(a=>!object(a)||a.source!=='operator-attested'||a.observationSource!=='local-git'||!text(a.intentId)||!absolute(a.path)||!hash(a.oldHash)||!hash(a.newHash)||!oid(a.oldCommit)||!oid(a.newCommit)||!Array.isArray(a.mapping)||!a.mapping.length)))fail('plan-amend connections');
|
|
70
48
|
if(!revision(state.scopeVersion)||!revision(state.targetVersion))fail('scope/target version');
|
|
71
49
|
if(state.actors.some(a=>!actor(a.actor)||a.source!=='operator-attested')||state.selections.some(s=>s.source!=='operator-attested'||!text(s.messageRef)))fail('attestations');
|
|
72
50
|
for(const key of ['scopes','approvals','documents','checks','findings','acceptances','commits'])if(state[key].some(entry=>!object(entry)||entry.source!=='operator-attested'))fail('attestation source');
|
|
73
51
|
if(state.records.some(r=>!actor(r.actor)||r.source!=='operator-attested'||!text(r.kind)||!statement(r)))fail('records');
|
|
74
52
|
if(state.requests.some(r=>!text(r.requestId)||!hash(r.requestFingerprint)||!object(r.decision))||new Set(state.requests.map(r=>r.requestId)).size!==state.requests.length)fail('request replay');
|
|
75
53
|
if(state.intents.some(i=>!text(i.requestId)||!['prepared','succeeded','failed','unknown','mismatch','cancelled'].includes(i.status)||!hash(i.fingerprint))||new Set(state.intents.map(i=>i.requestId)).size!==state.intents.length)fail('intents');
|
|
76
|
-
for(const intent of state.intents.filter(i=>i.operation==='plan-amend')){validatePlanAmendArguments(intent.arguments);if(!object(intent.target)||!object(intent.versions)||!object(intent.observation)||intent.source!=='operator-attested'||intent.checkpoint!==undefined&&!object(intent.checkpoint))fail('plan-amend intent');}
|
|
77
54
|
if(state.results.some(r=>!text(r.requestId)||!['succeeded','failed','unknown','mismatch','cancelled'].includes(r.status)||r.source!=='operator-attested'||!object(r.data)))fail('results');
|
|
78
55
|
if(state.plannerLedger!==undefined){validatePlannerLedger(state.plannerLedger);if(state.plannerLedger.stages.some(stage=>stage.workflowId!==state.workflowId||!Array.isArray(stage.artifacts)))fail('Planner workflow binding or artifacts');}
|
|
79
56
|
for(const key of ['targetIntents','targetCheckpoints','targetTransitions','targetDocuments'])if(state[key]!==undefined&&!Array.isArray(state[key]))fail(key);
|