@yunhozz/arc 0.4.5 → 0.4.7
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 +78 -73
- package/README.md +35 -51
- package/claude/agents/arc-implementer.md +2 -2
- package/claude/agents/arc-planner.md +1 -1
- package/claude/agents/arc-qa.md +1 -1
- package/claude/agents/arc-reviewer.md +1 -1
- package/claude/agents/arc-scouter.md +1 -1
- package/claude/skill/references/coordination.md +4 -2
- package/claude/skill/references/handoff-prep.md +5 -0
- package/claude/skill/references/handoff.md +2 -2
- package/claude/skill/references/planning.md +2 -2
- package/claude/skill/references/verification.md +16 -3
- package/claude/skill/references/worktree-creation.md +2 -2
- package/codex/agents/arc-implementer.toml +1 -1
- package/codex/agents/arc-planner.toml +1 -1
- package/codex/agents/arc-qa.toml +1 -1
- package/codex/agents/arc-reviewer.toml +1 -1
- package/codex/agents/arc-scouter.toml +1 -1
- package/codex/skill/references/coordination.md +4 -2
- package/codex/skill/references/handoff-prep.md +5 -0
- package/codex/skill/references/handoff.md +2 -2
- package/codex/skill/references/planning.md +2 -2
- package/codex/skill/references/verification.md +15 -2
- package/gemini/agents/arc-implementer.md +2 -2
- package/gemini/agents/arc-planner.md +1 -1
- package/gemini/agents/arc-qa.md +1 -1
- package/gemini/agents/arc-reviewer.md +1 -1
- package/gemini/agents/arc-scouter.md +1 -1
- package/gemini/skill/references/coordination.md +5 -3
- package/gemini/skill/references/handoff-prep.md +5 -0
- package/gemini/skill/references/handoff.md +2 -2
- package/gemini/skill/references/planning.md +2 -2
- package/gemini/skill/references/verification.md +16 -3
- package/gemini/skill/references/worktree-creation.md +2 -2
- package/grok/agents/arc-implementer.md +2 -2
- package/grok/agents/arc-planner.md +1 -1
- package/grok/agents/arc-qa.md +1 -1
- package/grok/agents/arc-reviewer.md +1 -1
- package/grok/agents/arc-scouter.md +1 -1
- package/grok/skill/references/coordination.md +4 -2
- package/grok/skill/references/handoff-prep.md +5 -0
- package/grok/skill/references/handoff.md +2 -2
- package/grok/skill/references/planning.md +2 -2
- package/grok/skill/references/verification.md +16 -3
- package/grok/skill/references/worktree-creation.md +2 -2
- package/lib/cli/root.mjs +1 -1
- package/lib/management/reapply.mjs +117 -0
- package/lib/management/update.mjs +59 -5
- package/lib/npm/upgrade.mjs +6 -2
- package/lib/policy/role-policy.json +1 -1
- package/lib/prompts/agent-fragments.json +5 -5
- package/lib/runtime/grok-sandbox.mjs +74 -0
- package/lib/runtime/role-bridge.mjs +10 -1
- package/lib/runtime/role-dispatch-policy.mjs +7 -1
- package/lib/runtime/role-observe.mjs +401 -13
- package/lib/runtime/role-routing.mjs +6 -0
- package/lib/runtime/role-supervisor.mjs +285 -33
- package/lib/tui/app.mjs +3 -39
- package/lib/tui/interface.mjs +40 -0
- package/lib/tui/setup.mjs +27 -16
- package/lib/watch/args.mjs +12 -27
- package/lib/watch/dispatch.mjs +2 -2
- package/lib/watch/index.mjs +38 -26
- package/lib/watch/markdown.mjs +232 -0
- package/lib/watch/menu.mjs +43 -0
- package/lib/watch/model.mjs +7 -3
- package/lib/watch/render.mjs +28 -67
- package/lib/watch/scope.mjs +1 -5
- package/lib/watch/status-line.mjs +2 -4
- package/lib/watch/text-width.mjs +43 -0
- package/lib/watch/watcher.mjs +17 -36
- package/package.json +1 -1
- package/shared/skill/runtime/grok-sandbox.mjs +74 -0
- package/shared/skill/runtime/role-bridge.mjs +10 -1
- package/shared/skill/runtime/role-dispatch-policy.mjs +7 -1
- package/shared/skill/runtime/role-observe.mjs +401 -13
- package/shared/skill/runtime/role-policy.json +1 -1
- package/shared/skill/runtime/role-routing.mjs +6 -0
- package/shared/skill/runtime/role-supervisor.mjs +285 -33
package/lib/watch/render.mjs
CHANGED
|
@@ -2,8 +2,11 @@ import path from 'node:path';
|
|
|
2
2
|
import {WATCH_LIMITS, MESSAGE_KINDS} from './model.mjs';
|
|
3
3
|
import {sanitizeText, sanitizeMessage, clipCodePoints} from './policy.mjs';
|
|
4
4
|
import {realPath} from './scope.mjs';
|
|
5
|
+
import {renderMarkdown} from './markdown.mjs';
|
|
6
|
+
import {displayWidth, wrapLine} from './text-width.mjs';
|
|
7
|
+
|
|
8
|
+
export {displayWidth, wrapLine} from './text-width.mjs';
|
|
5
9
|
|
|
6
|
-
const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
|
|
7
10
|
const roleLabels = new Map([
|
|
8
11
|
['scouter','SCOUTER'], ['planner','PLANNER'], ['implementer','IMPLEMENTER'],
|
|
9
12
|
['qa','QA'], ['reviewer','REVIEWER'], ['orchestrator','ORCHESTRATOR'],
|
|
@@ -13,54 +16,6 @@ const roleBadgeColors = new Map([
|
|
|
13
16
|
['implementer','1;38;5;16;48;5;214'], ['qa','1;38;5;16;48;5;228'],
|
|
14
17
|
['reviewer','1;38;5;231;48;5;161'], ['orchestrator','1;38;5;16;48;5;255'],
|
|
15
18
|
]);
|
|
16
|
-
const zeroWidth = /^[\u0300-\u036f\u200b-\u200f\ufe00-\ufe0f]+$/u;
|
|
17
|
-
const wide = /[\u1100-\u115f\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\u{1f300}-\u{1f64f}\u{1f900}-\u{1f9ff}\u{20000}-\u{3fffd}]/u;
|
|
18
|
-
function graphemeWidth(text) {
|
|
19
|
-
if (zeroWidth.test(text)) return 0;
|
|
20
|
-
if (wide.test(text) || /\p{Emoji_Presentation}/u.test(text) || (/[\u200d\ufe0f]/u.test(text) && /\p{Extended_Pictographic}/u.test(text))) return 2;
|
|
21
|
-
return 1;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function displayWidth(text) {
|
|
25
|
-
let width = 0;
|
|
26
|
-
for (const {segment} of graphemes.segment(text)) width += graphemeWidth(segment);
|
|
27
|
-
return width;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function wrapLine(text, avail) {
|
|
31
|
-
if (avail <= 0) return [text];
|
|
32
|
-
const parts = [...graphemes.segment(text)].map(({segment}) => segment);
|
|
33
|
-
const widths = parts.map(graphemeWidth);
|
|
34
|
-
const lines = [];
|
|
35
|
-
let start = 0;
|
|
36
|
-
while (start < parts.length) {
|
|
37
|
-
let end = start, cols = 0, space = -1, hasContent = false;
|
|
38
|
-
while (end < parts.length && cols + widths[end] <= avail) {
|
|
39
|
-
if (parts[end] === ' ') { if (hasContent) space = end; }
|
|
40
|
-
else hasContent = true;
|
|
41
|
-
cols += widths[end++];
|
|
42
|
-
}
|
|
43
|
-
if (end === parts.length) {
|
|
44
|
-
const piece = parts.slice(start).join('');
|
|
45
|
-
if (piece.trim()) lines.push(piece);
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
// A space immediately after a full line can be discarded as the boundary.
|
|
49
|
-
if (parts[end] === ' ' && hasContent) space = end;
|
|
50
|
-
let piece;
|
|
51
|
-
if (space >= 0) {
|
|
52
|
-
piece = parts.slice(start,space).join('');
|
|
53
|
-
start = space + 1;
|
|
54
|
-
} else {
|
|
55
|
-
end = Math.max(start + 1,end);
|
|
56
|
-
piece = parts.slice(start,end).join('');
|
|
57
|
-
start = end;
|
|
58
|
-
}
|
|
59
|
-
if (piece.trim()) lines.push(piece);
|
|
60
|
-
}
|
|
61
|
-
return lines.length ? lines : [''];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
19
|
export const PLATFORM_COLORS = Object.freeze({codex:'36', claude:'38;5;208', gemini:'38;5;135', other:'2'});
|
|
65
20
|
|
|
66
21
|
// Compare both the lexical root and its real path (e.g. /tmp and /private/tmp).
|
|
@@ -78,7 +33,7 @@ export function displayPath(file, root) {
|
|
|
78
33
|
export function tagColor(event) {
|
|
79
34
|
if (event.kind === 'tool' && event.skill) return '38;5;110';
|
|
80
35
|
if (event.kind === 'tool' && event.plugin) return '38;5;175';
|
|
81
|
-
return ({command:'38;5;242', user:'1;35', agent:'32', file_change:'33', file_create:'38;5;69', file_delete:'31', tool:'38;5;101', spawn:'38;5;141',
|
|
36
|
+
return ({command:'38;5;242', user:'1;97', prompt:'1;35', agent:'32', file_change:'33', file_create:'38;5;69', file_delete:'31', tool:'38;5;101', spawn:'38;5;141',
|
|
82
37
|
dispatch:'38;5;137', approval:'1;4', turn_failed:'31', error:'31', tool_failed:'31'})[event.kind] ?? '2';
|
|
83
38
|
}
|
|
84
39
|
|
|
@@ -91,7 +46,7 @@ export function kindTag(event) {
|
|
|
91
46
|
if (event.kind === 'tool' && event.skill) return 'SKILL';
|
|
92
47
|
if (event.kind === 'tool' && event.plugin) return 'PLUGIN';
|
|
93
48
|
return ({command:'CMD', session:'SESSION', settings:'SETTINGS', turn_start:'TURN', turn_end:'END',
|
|
94
|
-
turn_failed:'FAIL', user:'USER', agent:'AGENT', reasoning:'THINK', tool:'TOOL',
|
|
49
|
+
turn_failed:'FAIL', user:'USER', prompt:'PROMPT', agent:'AGENT', reasoning:'THINK', tool:'TOOL',
|
|
95
50
|
tool_failed:'TOOL!', file_change:'EDIT', file_create:'CREATE', file_delete:'DELETE', spawn:'SPAWN', approval:'APPROVE',
|
|
96
51
|
dispatch:'DISPATCH', error:'ERROR', other:'ITEM', notice:'NOTICE'})[event.kind] ?? 'ITEM';
|
|
97
52
|
}
|
|
@@ -119,15 +74,30 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
119
74
|
const message = MESSAGE_KINDS.includes(event.kind);
|
|
120
75
|
const fullLine = message || event.kind === 'file_change' || event.kind === 'file_create' || event.kind === 'file_delete';
|
|
121
76
|
const text = message ? sanitizeMessage(event.text) : eventText(event, verbose);
|
|
77
|
+
const roleName = event.kind === 'agent' ? roleLabels.get(event.role) : undefined;
|
|
78
|
+
const indent = ' '.repeat([...prefix].length);
|
|
79
|
+
const avail = width - Math.max([...prefix].length, displayWidth(prefix));
|
|
80
|
+
const canWrap = wrap && avail >= WATCH_LIMITS.wrapMinBody;
|
|
81
|
+
const paint = (value, code) => `\x1b[${code}m${value}\x1b[0m`;
|
|
82
|
+
const paintedPrefix = () => {
|
|
83
|
+
const platformColor = event.source === 'watch' ? PLATFORM_COLORS.other : PLATFORM_COLORS[event.platform] ?? PLATFORM_COLORS.other;
|
|
84
|
+
return `${time} ${paint(platform, platformColor)} ${paint(tag.trimEnd(), tagColor(event))}`;
|
|
85
|
+
};
|
|
86
|
+
const padding = tag.slice(tag.trimEnd().length);
|
|
87
|
+
const roleBadge = () => paint(` ${roleName} `,roleBadgeColors.get(event.role));
|
|
88
|
+
if (color && fullLine && (event.kind === 'agent' || event.kind === 'prompt')) {
|
|
89
|
+
const lines = text ? renderMarkdown(text, {width:canWrap ? avail : Infinity, baseCode:bodyColor(event)}) : [];
|
|
90
|
+
if (text && roleName) lines.unshift(roleBadge());
|
|
91
|
+
const body = lines.map((line,i) => i && line ? indent + line : line).join('\n');
|
|
92
|
+
return body ? `${paintedPrefix()}${padding} ${body}` : paintedPrefix();
|
|
93
|
+
}
|
|
94
|
+
|
|
122
95
|
const paths = fullLine && !message ? (event.paths ?? []).map(file => sanitizeText(displayPath(file,event.root))).filter(Boolean) : [];
|
|
123
96
|
const listPaths = paths.length >= 2;
|
|
124
97
|
const bodyLines = message ? (text ? text.split('\n') : []) : fullLine
|
|
125
98
|
? [sanitizeText(event.text), ...paths.map(file => listPaths ? '- ' + file : file)].filter(Boolean) : [];
|
|
126
|
-
const roleName = event.kind === 'agent' ? roleLabels.get(event.role) : undefined;
|
|
127
99
|
if (roleName && bodyLines.length) bodyLines.unshift(roleName);
|
|
128
|
-
const
|
|
129
|
-
const avail = width - Math.max([...prefix].length, displayWidth(prefix));
|
|
130
|
-
const lines = wrap && avail >= WATCH_LIMITS.wrapMinBody ? bodyLines.flatMap((line,i) =>
|
|
100
|
+
const lines = canWrap ? bodyLines.flatMap((line,i) =>
|
|
131
101
|
listPaths && paths.length && i >= bodyLines.length - paths.length
|
|
132
102
|
? wrapLine(line.slice(2),avail-2).map((piece,j) => (j ? ' ' : '- ') + piece)
|
|
133
103
|
: wrapLine(line,avail)) : bodyLines;
|
|
@@ -135,20 +105,11 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
135
105
|
const plain = fullLine ? (message && !lines.length ? prefix.trimEnd() : prefix + bodyText(line => line)) : clipCodePoints(prefix + text, width).text;
|
|
136
106
|
if (!color || (!fullLine && [...prefix].length > width)) return plain;
|
|
137
107
|
const code = bodyColor(event);
|
|
138
|
-
const paint = (value, code) => `\x1b[${code}m${value}\x1b[0m`;
|
|
139
|
-
const platformColor = event.source === 'watch' ? PLATFORM_COLORS.other : PLATFORM_COLORS[event.platform] ?? PLATFORM_COLORS.other;
|
|
140
|
-
const paintedTag = paint(tag.trimEnd(), tagColor(event));
|
|
141
|
-
const padding = tag.slice(tag.trimEnd().length);
|
|
142
108
|
const clippedText = [...plain].slice([...prefix].length).join('');
|
|
143
|
-
if (message && !text) return
|
|
144
|
-
const body = fullLine ? bodyText((line,
|
|
145
|
-
if (roleName && i === 0) {
|
|
146
|
-
return paint(` ${line} `,roleBadgeColors.get(event.role));
|
|
147
|
-
}
|
|
148
|
-
return code ? paint(line,code) : line;
|
|
149
|
-
})
|
|
109
|
+
if (message && !text) return paintedPrefix();
|
|
110
|
+
const body = fullLine ? bodyText(line => code ? paint(line,code) : line)
|
|
150
111
|
: code && clippedText ? paint(clippedText, code) : clippedText;
|
|
151
|
-
return `${
|
|
112
|
+
return `${paintedPrefix()}${padding} ${body}`;
|
|
152
113
|
}
|
|
153
114
|
|
|
154
115
|
export function renderJson(event) {
|
package/lib/watch/scope.mjs
CHANGED
|
@@ -23,9 +23,7 @@ function worktreeRoots(output) {
|
|
|
23
23
|
return [...new Set(output.split('\0').filter(field => field.startsWith('worktree ')).map(field => realPath(field.slice(9))))];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export async function resolveScope({
|
|
27
|
-
if (mode === 'all') return {kind:'all', roots:[], gitCommonDir:null, description:'All sessions'};
|
|
28
|
-
if (mode === 'session') return {kind:'session', roots:[], gitCommonDir:null, description:`Session ${session}`};
|
|
26
|
+
export async function resolveScope({dir, git}) {
|
|
29
27
|
const root = realPath(dir), top = await git(root, GIT_ALLOWED[0]);
|
|
30
28
|
if (top !== null) {
|
|
31
29
|
const common = await git(root, GIT_ALLOWED[1]), trees = await git(root, GIT_ALLOWED[2]);
|
|
@@ -45,7 +43,6 @@ export async function refreshScope(scope, git) {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
export function inScope(scope, cwd) {
|
|
48
|
-
if (scope.kind === 'all' || scope.kind === 'session') return true;
|
|
49
46
|
let cache = scopeCaches.get(scope);
|
|
50
47
|
if (!cache) { cache = new Map(); scopeCaches.set(scope, cache); }
|
|
51
48
|
if (cache.has(cwd)) return cache.get(cwd);
|
|
@@ -59,7 +56,6 @@ export function inScope(scope, cwd) {
|
|
|
59
56
|
export const normalizeSlug = value => value.replace(/[^A-Za-z0-9]/g, '-');
|
|
60
57
|
|
|
61
58
|
export function claudeDirPrefixes(scope) {
|
|
62
|
-
if (scope.kind === 'all' || scope.kind === 'session') return null;
|
|
63
59
|
const roots = scope.kind === 'repo' ? [...scope.roots, ...scope.excludedRoots ?? []] : scope.roots;
|
|
64
60
|
return [...new Set(roots.flatMap(root => [normalizeSlug(root), normalizeSlug(realPath(root))]))];
|
|
65
61
|
}
|
|
@@ -13,11 +13,9 @@ function watchShimmerIntensity(index, tick) {
|
|
|
13
13
|
return Math.max(0, 1 - Math.abs(index - c) / R) ** 2;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export function watchLocationLabel({
|
|
16
|
+
export function watchLocationLabel({dir, home}) {
|
|
17
17
|
let label = dir;
|
|
18
|
-
if (
|
|
19
|
-
else if (mode === 'all') label = 'all directories';
|
|
20
|
-
else if (dir === home) label = '~';
|
|
18
|
+
if (dir === home) label = '~';
|
|
21
19
|
else if (home && dir.startsWith(home + path.sep)) label = '~' + dir.slice(home.length);
|
|
22
20
|
return sanitizeText(label);
|
|
23
21
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
|
|
2
|
+
const zeroWidth = /^[\u0300-\u036f\u200b-\u200f\ufe00-\ufe0f]+$/u;
|
|
3
|
+
const wide = /[\u1100-\u115f\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\u{1f300}-\u{1f64f}\u{1f900}-\u{1f9ff}\u{20000}-\u{3fffd}]/u;
|
|
4
|
+
function graphemeWidth(text) {
|
|
5
|
+
if (zeroWidth.test(text)) return 0;
|
|
6
|
+
if (wide.test(text) || /\p{Emoji_Presentation}/u.test(text) || (/[\u200d\ufe0f]/u.test(text) && /\p{Extended_Pictographic}/u.test(text))) return 2;
|
|
7
|
+
return 1;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function displayWidth(text) {
|
|
11
|
+
let width = 0;
|
|
12
|
+
for (const {segment} of graphemes.segment(text)) width += graphemeWidth(segment);
|
|
13
|
+
return width;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Return UTF-16 offsets so styled callers can wrap before adding SGR codes.
|
|
17
|
+
export function wrapLineRanges(text, avail, {preserveWhitespace = false} = {}) {
|
|
18
|
+
const parts = Array.from(graphemes.segment(text), ({segment, index}) => ({segment, index, width:graphemeWidth(segment)}));
|
|
19
|
+
const lines = [];
|
|
20
|
+
let start = 0;
|
|
21
|
+
while (start < parts.length) {
|
|
22
|
+
let end = start, cols = 0, space = -1, hasContent = false;
|
|
23
|
+
while (end < parts.length && cols + parts[end].width <= avail) {
|
|
24
|
+
if (parts[end].segment === ' ') { if (hasContent) space = end; }
|
|
25
|
+
else hasContent = true;
|
|
26
|
+
cols += parts[end++].width;
|
|
27
|
+
}
|
|
28
|
+
if (!preserveWhitespace && parts[end]?.segment === ' ' && hasContent) space = end;
|
|
29
|
+
const useSpace = !preserveWhitespace && end < parts.length && space >= 0;
|
|
30
|
+
const overflows = end === start;
|
|
31
|
+
const pieceEnd = useSpace ? space : Math.max(start + 1, end);
|
|
32
|
+
const from = parts[start].index;
|
|
33
|
+
const to = parts[pieceEnd]?.index ?? text.length;
|
|
34
|
+
if (preserveWhitespace || text.slice(from, to).trim()) lines.push({from, to, overflows});
|
|
35
|
+
start = useSpace ? space + 1 : pieceEnd;
|
|
36
|
+
}
|
|
37
|
+
return lines.length ? lines : [{from:0, to:0}];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function wrapLine(text, avail) {
|
|
41
|
+
if (avail <= 0) return [text];
|
|
42
|
+
return wrapLineRanges(text, avail).map(({from, to}) => text.slice(from, to));
|
|
43
|
+
}
|
package/lib/watch/watcher.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import fsp from 'node:fs/promises';
|
|
3
|
-
import {WATCH_LIMITS as L, MESSAGE_KINDS} from './model.mjs';
|
|
3
|
+
import {WATCH_LIMITS as L, MESSAGE_KINDS, classifyMessageKind} from './model.mjs';
|
|
4
4
|
import {sanitizeText, sanitizeMessage, isVisible} from './policy.mjs';
|
|
5
5
|
import {topLabel, childLabel, dispatchLabel, roleFromName} from './labels.mjs';
|
|
6
6
|
import {createCodexState, normalizeCodexLine, codexLineCwd} from './normalize-codex.mjs';
|
|
@@ -18,15 +18,15 @@ import {GIT_ALLOWED} from './git.mjs';
|
|
|
18
18
|
export function createWatcher({options, homes, scope: initialScope, git, now, registry = DEFAULT_PLATFORM_REGISTRY, dependencies = {}}) {
|
|
19
19
|
const {readClaudeHead: claudeHead = readClaudeHead, readCodexMeta: codexMeta = readCodexMeta,
|
|
20
20
|
lstat = fsp.lstat, maxKnown = L.maxKnown, createClaudeDiscovery: claudeDiscovery = createClaudeDiscovery, createDispatchIndex: dispatchIndex = createDispatchIndex} = dependencies;
|
|
21
|
-
const platforms = options.platforms ??
|
|
22
|
-
const
|
|
21
|
+
const platforms = options.platforms ?? registry.byDisplayOrder().filter(d => d.capabilities.watch.state==='verified').map(d => d.id);
|
|
22
|
+
const verbose = Boolean(options.verbose);
|
|
23
23
|
const tailCount = options.tail ?? L.defaultTail;
|
|
24
24
|
let scope = initialScope, closed = false, started = false;
|
|
25
|
-
let lastDiscovery = -Infinity, lastRefresh = now(), capped = false
|
|
25
|
+
let lastDiscovery = -Infinity, lastRefresh = now(), capped = false;
|
|
26
26
|
const followed = new Map(), pending = new Map(), ignored = new Map(), detached = new Map();
|
|
27
27
|
const seenAtStart = new Map(), heads = new Map(), metas = new Map(), agentMetas = new Map(), childLists = new Map();
|
|
28
28
|
const known = new Map(), latestCwds = new Map();
|
|
29
|
-
const compressed = new Set(), missingDispatch = new Set()
|
|
29
|
+
const compressed = new Set(), missingDispatch = new Set();
|
|
30
30
|
const rootsByCwd = new Map(), gitTopByCwd = new Map(), shellRoots = new Map();
|
|
31
31
|
const nestedChecks = new Map(), nestedFailures = new Map();
|
|
32
32
|
let lastNestedRefresh = -Infinity;
|
|
@@ -38,7 +38,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
38
38
|
const debug = (out, text) => { if (verbose) out.push(notice(text)); };
|
|
39
39
|
const sort = events => events.sort((a,b) => (Date.parse(a.ts) || 0) - (Date.parse(b.ts) || 0));
|
|
40
40
|
const clean = event => {
|
|
41
|
-
const e = {...event};
|
|
41
|
+
const e = {...event,kind:classifyMessageKind(event)};
|
|
42
42
|
if (e.text !== undefined) e.text = MESSAGE_KINDS.includes(e.kind) ? sanitizeMessage(e.text) : sanitizeText(e.text);
|
|
43
43
|
if (e.tool !== undefined) e.tool = sanitizeText(e.tool);
|
|
44
44
|
if (e.skill !== undefined) e.skill = sanitizeText(e.skill);
|
|
@@ -47,18 +47,14 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
47
47
|
if (e.paths) e.paths = e.paths.map(sanitizeText);
|
|
48
48
|
return e;
|
|
49
49
|
};
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|| (ref.cwd ? inScope(scope,ref.cwd) : [...followed.values()].some(row=>ref.sessionIds.includes(row.id) && cwdInScope(row.cwd))));
|
|
53
|
-
const allowedDispatch = ref => dispatchInScope(ref) && selectedDispatch(ref);
|
|
50
|
+
const dispatchInScope = ref => ref.inScope && (ref.cwd ? inScope(scope,ref.cwd)
|
|
51
|
+
: [...followed.values()].some(row=>ref.sessionIds.includes(row.id) && cwdInScope(row.cwd)));
|
|
54
52
|
function mapped(row) {
|
|
55
53
|
const ref = dispatch.bySession(row.id);
|
|
56
|
-
return ref && ref.inScope && (
|
|
57
|
-
|| (ref.cwd ? inScope(scope,ref.cwd) : cwdInScope(row.cwd))) ? ref : null;
|
|
54
|
+
return ref && ref.inScope && (ref.cwd ? inScope(scope,ref.cwd) : cwdInScope(row.cwd)) ? ref : null;
|
|
58
55
|
}
|
|
59
56
|
const selectedRoot = cwd => path.resolve(cwd)===scope.roots[0] || realPath(cwd)===scope.roots[0];
|
|
60
57
|
function cwdInScope(cwd) {
|
|
61
|
-
if (scope.kind==='all' || scope.kind==='session') return true;
|
|
62
58
|
if (!cwd || !inScope(scope,cwd)) return false;
|
|
63
59
|
return scope.kind!=='repo' || selectedRoot(cwd) || nestedChecks.get(cwd)?.inside===true;
|
|
64
60
|
}
|
|
@@ -102,7 +98,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
102
98
|
return {resolved:!row.parentId,desktop};
|
|
103
99
|
}
|
|
104
100
|
function lineGate(row) {
|
|
105
|
-
return
|
|
101
|
+
return Boolean(mapped(row)) || cwdInScope(row.cwd);
|
|
106
102
|
}
|
|
107
103
|
async function setCwd(row, cwd, out) {
|
|
108
104
|
row.state.cwd=cwd;
|
|
@@ -173,7 +169,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
173
169
|
}
|
|
174
170
|
for (const e of normalized) {
|
|
175
171
|
if (['turn_end','turn_failed'].includes(e.kind)) row.active = false;
|
|
176
|
-
else if (['turn_start','
|
|
172
|
+
else if (MESSAGE_KINDS.includes(e.kind) || ['turn_start','reasoning','command','tool','tool_failed','file_change','file_create','file_delete','spawn','approval'].includes(e.kind)) row.active = true;
|
|
177
173
|
if (!inside) continue;
|
|
178
174
|
if (e.kind==='command' && e.skillOnly && !verbose) continue;
|
|
179
175
|
const shell = shellRoots.get(row.gitTop);
|
|
@@ -202,18 +198,12 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
202
198
|
row.held=[]; delete row.holdUntil;
|
|
203
199
|
}
|
|
204
200
|
}
|
|
205
|
-
async function rememberRepo(cwd) {
|
|
206
|
-
if (scope.kind !== 'all' && scope.kind !== 'session') return;
|
|
207
|
-
if (repos.has(cwd) || repos.size >= L.maxRepos) return;
|
|
208
|
-
repos.set(cwd, await git(cwd,GIT_ALLOWED[1]));
|
|
209
|
-
}
|
|
210
201
|
async function scanDispatch() {
|
|
211
|
-
|
|
212
|
-
return dispatch.scan({gitCommonDirs:dirs,includeAllLeases:scope.kind==='all'||scope.kind==='session'});
|
|
202
|
+
return dispatch.scan({gitCommonDirs:scope.gitCommonDir ? [scope.gitCommonDir] : []});
|
|
213
203
|
}
|
|
214
204
|
function dispatchEvents(updates, startup, out) {
|
|
215
205
|
for (const {ref,first} of updates) {
|
|
216
|
-
if (!
|
|
206
|
+
if (!dispatchInScope(ref)) continue;
|
|
217
207
|
if (startup && (tailCount === 0 || now()-Date.parse(ref.updatedAt) > L.historyWindowMs || !Number.isFinite(Date.parse(ref.updatedAt)))) continue;
|
|
218
208
|
const followedRow = [...followed.values()].find(row=>ref.sessionIds.includes(row.id));
|
|
219
209
|
const platform = ref.childPlatform ?? followedRow?.platform;
|
|
@@ -230,13 +220,11 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
230
220
|
function eligible(row) {
|
|
231
221
|
if (!platforms.includes(row.platform) || row.origin === 'Codex Desktop') return false;
|
|
232
222
|
if (row.parentId) {
|
|
233
|
-
if (scope.kind==='all' || scope.kind==='session') return followed.has(row.parentId);
|
|
234
223
|
const chain=ancestry(row);
|
|
235
224
|
if (chain.desktop) {ignored.set(row.file,row.size);return false;}
|
|
236
225
|
return chain.resolved && anyCwdInScope(row);
|
|
237
226
|
}
|
|
238
227
|
const ref = mapped(row);
|
|
239
|
-
if (session) return row.id === session || Boolean(ref && selectedDispatch(ref));
|
|
240
228
|
return Boolean(ref) || anyCwdInScope(row);
|
|
241
229
|
}
|
|
242
230
|
async function attach(row, startup, out) {
|
|
@@ -366,7 +354,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
366
354
|
}
|
|
367
355
|
async function discover(startup, out) {
|
|
368
356
|
const rows=[];
|
|
369
|
-
|
|
357
|
+
const updates = await scanDispatch();
|
|
370
358
|
for (const file of pending.keys()) if (!await details(file)) pending.delete(file);
|
|
371
359
|
if (homes.codex && platforms.includes('codex')) {
|
|
372
360
|
for (const item of await codexCandidates(startup)) {
|
|
@@ -409,10 +397,6 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
409
397
|
}
|
|
410
398
|
}
|
|
411
399
|
}
|
|
412
|
-
for (const row of rows) {
|
|
413
|
-
await rememberRepo(row.cwd);
|
|
414
|
-
}
|
|
415
|
-
updates ??= await scanDispatch();
|
|
416
400
|
rows.sort((a,b)=>b.mtimeMs-a.mtimeMs||a.file.localeCompare(b.file));
|
|
417
401
|
let remaining=rows.filter(row=> {
|
|
418
402
|
if (followed.has(row.id) || ignored.get(row.file)===row.size) return false;
|
|
@@ -448,8 +432,8 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
448
432
|
}
|
|
449
433
|
for (const row of remaining) {
|
|
450
434
|
const chain=ancestry(row);
|
|
451
|
-
const missingParent
|
|
452
|
-
if (
|
|
435
|
+
const missingParent=!chain.resolved;
|
|
436
|
+
if (row.parentId && (!missingParent || chain.desktop)) pending.delete(row.file);
|
|
453
437
|
if (row.parentId && row.origin!=='Codex Desktop' && missingParent && !chain.desktop) {
|
|
454
438
|
const wait=pending.get(row.file) ?? {...row,until:now()+L.holdMs};
|
|
455
439
|
if (now()>=wait.until) {pending.delete(row.file);ignored.set(row.file,row.size);debug(out,`parent session not found for ${row.id}`);}
|
|
@@ -466,9 +450,6 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
466
450
|
emit(row,[],out);
|
|
467
451
|
}
|
|
468
452
|
dispatchEvents(updates,startup,out);
|
|
469
|
-
if (session && !waiting && ![...followed.values()].some(row=>row.id===session||mapped(row)?.dispatchId===session) && !dispatch.byId(session)?.inScope) {
|
|
470
|
-
debug(out,`waiting for session ${session}`);waiting=true;
|
|
471
|
-
}
|
|
472
453
|
lastDiscovery=now();
|
|
473
454
|
}
|
|
474
455
|
async function poll(out) {
|
|
@@ -574,7 +555,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
|
|
|
574
555
|
const storeDir = store.kind === 'none' && homes.codex && registry.isPlatformId('codex')
|
|
575
556
|
? path.join(homes.codex, 'arc-role-dispatch') : store.dir;
|
|
576
557
|
dispatch = dispatchIndex({storeDir});
|
|
577
|
-
const description
|
|
558
|
+
const description=`scope ${scope.roots[0]}`+(scope.kind==='repo'?` (${scope.roots.length} worktrees)`:'');
|
|
578
559
|
const out=[];
|
|
579
560
|
if (store.kind === 'ambiguous') out.push(notice('dispatch store ambiguous'));
|
|
580
561
|
await discover(true,out);
|
package/package.json
CHANGED
|
@@ -19,6 +19,80 @@ const sameEntry = (first, second) => first.dev === second.dev && first.ino === s
|
|
|
19
19
|
const identityOf = ({dev, ino}) => ({dev, ino});
|
|
20
20
|
const sandboxEventsPath = grokHome => path.join(grokHome, 'sessions', 'sandbox-events.jsonl');
|
|
21
21
|
|
|
22
|
+
function parseConfigKeyPath(source) {
|
|
23
|
+
const segment = /\s*(?:"([^"\\]*)"|'([^'\\]*)'|([\w-]+))\s*/y;
|
|
24
|
+
const segments = [];
|
|
25
|
+
for (;;) {
|
|
26
|
+
const match = segment.exec(source);
|
|
27
|
+
if (!match) return null;
|
|
28
|
+
segments.push(match[1] ?? match[2] ?? match[3]);
|
|
29
|
+
if (source[segment.lastIndex] !== '.') return {segments, rest: source.slice(segment.lastIndex)};
|
|
30
|
+
segment.lastIndex += 1;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function isGrokSecurityPath(segments) {
|
|
35
|
+
return segments.includes('permission_mode') || (segments[0] === 'compat' && segments[1] === 'claude')
|
|
36
|
+
|| /^sandbox[\w-]*$/.test(segments[0]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function arrayDepthAfterLine(value, depth) {
|
|
40
|
+
let quote = null;
|
|
41
|
+
for (let i = 0; i < value.length; i++) {
|
|
42
|
+
const char = value[i];
|
|
43
|
+
if (quote) {
|
|
44
|
+
if (quote === '"' && char === '\\') i += 1;
|
|
45
|
+
else if (char === quote) quote = null;
|
|
46
|
+
} else if (char === '"' || char === "'") {
|
|
47
|
+
quote = char;
|
|
48
|
+
} else if (char === '#') {
|
|
49
|
+
break;
|
|
50
|
+
} else if (char === '[') {
|
|
51
|
+
depth += 1;
|
|
52
|
+
} else if (char === ']') {
|
|
53
|
+
depth -= 1;
|
|
54
|
+
if (depth < 0) return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return quote ? null : depth;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function grokConfigSecurityProjection(bytes) {
|
|
61
|
+
let config;
|
|
62
|
+
try { config = new TextDecoder('utf-8', {fatal: true}).decode(bytes); } catch { return null; }
|
|
63
|
+
if (config.includes('"""') || config.includes("'''")) return null;
|
|
64
|
+
|
|
65
|
+
const lines = [];
|
|
66
|
+
let table = [];
|
|
67
|
+
let arrayDepth = 0, securityValue = false;
|
|
68
|
+
for (const raw of config.split('\n')) {
|
|
69
|
+
const line = raw.trim();
|
|
70
|
+
if (!line || line.startsWith('#')) continue;
|
|
71
|
+
if (arrayDepth > 0) {
|
|
72
|
+
arrayDepth = arrayDepthAfterLine(line, arrayDepth);
|
|
73
|
+
if (arrayDepth === null) return null;
|
|
74
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (line.startsWith('[')) {
|
|
78
|
+
const arrayTable = line.startsWith('[[');
|
|
79
|
+
const header = parseConfigKeyPath(line.slice(arrayTable ? 2 : 1));
|
|
80
|
+
const closing = arrayTable ? /^\]\]\s*(?:#.*)?$/ : /^\]\s*(?:#.*)?$/;
|
|
81
|
+
if (!header || !closing.test(header.rest)) return null;
|
|
82
|
+
table = header.segments;
|
|
83
|
+
if (isGrokSecurityPath(table)) lines.push(`${table.join('.')}\t${line}`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
const key = parseConfigKeyPath(line);
|
|
87
|
+
if (!key || !key.rest.startsWith('=')) return null;
|
|
88
|
+
arrayDepth = arrayDepthAfterLine(key.rest.slice(1), 0);
|
|
89
|
+
if (arrayDepth === null) return null;
|
|
90
|
+
securityValue = isGrokSecurityPath([...table, ...key.segments]);
|
|
91
|
+
if (securityValue) lines.push(`${table.join('.')}\t${line}`);
|
|
92
|
+
}
|
|
93
|
+
return arrayDepth === 0 ? lines.join('\n') : null;
|
|
94
|
+
}
|
|
95
|
+
|
|
22
96
|
export function grokSandboxProfileName(dispatchId) {
|
|
23
97
|
const prefix = typeof dispatchId === 'string' ? dispatchId.slice(0, 8) : '';
|
|
24
98
|
return /^[0-9a-f]{8}$/.test(prefix) ? 'arc-bridge-' + prefix : null;
|
|
@@ -6,7 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import {DEFAULT_POLICY, HOST_SANDBOX_GATES, reason, profileName, bridgeGateReasons, environmentReasons, capabilityReasons} from './role-dispatch-policy.mjs';
|
|
7
7
|
import {readLease, writeLease, listLeases, readHostLimits, NON_TERMINAL_STATES, readHeartbeat, requestCancel, clearCancel, TERMINAL_STATES, validateLease} from './role-dispatch-store.mjs';
|
|
8
8
|
import {withRoutingLock, readActivation, readRevision, authenticate, resolveRuntimeHomes, locateAnchorHome, probeHomeWritable} from './role-routing.mjs';
|
|
9
|
-
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation} from './role-supervisor.mjs';
|
|
9
|
+
import {SUPERVISOR_IMPLEMENTATIONS, startSupervisor, processAlive, resolveWorktree, artifactDirectory, segmentDirectory, buildBridgeInvocation, reapRecordedDescendants} from './role-supervisor.mjs';
|
|
10
10
|
|
|
11
11
|
export const heldRoutingResult=(code,releaseCondition)=>({decision:'hold',routeStatus:'held',supportStatus:'unverified',route:null,executionEnvironment:null,hostPlatform:null,role:null,requested:null,authentication:null,reasons:[{code,releaseCondition}]});
|
|
12
12
|
|
|
@@ -233,6 +233,14 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
233
233
|
if(!killed&&Date.now()>=begin+graceMs){signalGroup(pid,'SIGKILL');killed=true;}
|
|
234
234
|
await sleep(25);gone=!groupExists(pid);
|
|
235
235
|
}
|
|
236
|
+
let escapes={};
|
|
237
|
+
if(!direct.lease.supervisor||!processAlive(direct.lease.supervisor)){
|
|
238
|
+
try{
|
|
239
|
+
const target=await resolveWorktree(context.cwd);
|
|
240
|
+
const directory=segmentDirectory(target,direct.lease.workflowId,dispatchId,direct.lease.segment??0);
|
|
241
|
+
escapes=await reapRecordedDescendants(directory,direct.lease,{graceMs});
|
|
242
|
+
}catch{/* A missing worktree does not change the group cancellation result. */}
|
|
243
|
+
}
|
|
236
244
|
if(!gone)result=view(direct.lease,'hold');
|
|
237
245
|
else{
|
|
238
246
|
try{
|
|
@@ -248,6 +256,7 @@ export async function cancelRoleDispatch({context,dispatchId,now=Date.now(),poli
|
|
|
248
256
|
else return hold(context,dispatchId,classifyLock(error),error);
|
|
249
257
|
}
|
|
250
258
|
}
|
|
259
|
+
if(result&&escapes.escapedDescendants)result={...result,...escapes};
|
|
251
260
|
}
|
|
252
261
|
if(residual)result.residualPaths=residual;
|
|
253
262
|
return result;
|
|
@@ -14,13 +14,15 @@ function deepFreeze(value) {
|
|
|
14
14
|
return Object.freeze(value);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
// Claude 2.1.
|
|
17
|
+
// Claude 2.1.327, 2026-11-20, T0 M-C10/M-C11/M-C12/FINAL
|
|
18
18
|
const RECORDED_CLAUDE_SANDBOX_SETTINGS = deepFreeze({
|
|
19
|
+
permissions: {deny: ['Edit(./.git/**)', 'Write(./.git/**)']},
|
|
19
20
|
sandbox: {
|
|
20
21
|
enabled: true,
|
|
21
22
|
autoAllowBashIfSandboxed: true,
|
|
22
23
|
allowUnsandboxedCommands: false,
|
|
23
24
|
failIfUnavailable: true,
|
|
25
|
+
filesystem: {denyWrite: ['./.git']},
|
|
24
26
|
},
|
|
25
27
|
});
|
|
26
28
|
const isRecordedObject = value => value !== null && typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
@@ -38,11 +40,15 @@ export const OBSERVE_MAX_WAIT_MS = 540000;
|
|
|
38
40
|
export const BRIEF_MAX_BYTES = 262144;
|
|
39
41
|
export const EVENTS_MAX_BYTES = 4194304;
|
|
40
42
|
export const CANCEL_GRACE_MS = 10000;
|
|
43
|
+
export const DESCENDANT_SAMPLE_MS = 1000;
|
|
44
|
+
export const DESCENDANT_LIMIT = 256;
|
|
41
45
|
export const LOCK_RETRY_MS = 2000;
|
|
42
46
|
export const LEASE_RETENTION_MS = 2592000000;
|
|
43
47
|
export const PROBE_TIMEOUT_MS = 10000;
|
|
44
48
|
|
|
45
49
|
export const DEFAULT_POLICY = Object.freeze({
|
|
50
|
+
descendantSampleMs: DESCENDANT_SAMPLE_MS,
|
|
51
|
+
descendantLimit: DESCENDANT_LIMIT,
|
|
46
52
|
gates: BRIDGE_GATE_RESULTS,
|
|
47
53
|
claudeSandboxSettings: CLAUDE_SANDBOX_SETTINGS,
|
|
48
54
|
codexDelegationCallNames: CODEX_DELEGATION_CALL_NAMES,
|