@yunhozz/arc 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MANIFEST.sha256 +89 -76
- 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/models.toml +7 -7
- package/claude/skill/references/coordination.md +6 -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 +21 -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/models.toml +5 -5
- package/codex/skill/references/coordination.md +6 -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 +20 -2
- package/gemini/agents/arc-implementer.md +3 -3
- package/gemini/agents/arc-planner.md +2 -2
- package/gemini/agents/arc-qa.md +2 -2
- package/gemini/agents/arc-reviewer.md +2 -2
- package/gemini/agents/arc-scouter.md +2 -2
- package/gemini/skill/models.toml +6 -6
- package/gemini/skill/references/coordination.md +7 -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 +21 -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 +6 -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 +21 -3
- package/grok/skill/references/worktree-creation.md +2 -2
- package/lib/cli/postinstall.mjs +1 -1
- package/lib/cli/root.mjs +1 -1
- package/lib/installer/runtime-assets.mjs +5 -1
- package/lib/management/reapply.mjs +117 -0
- package/lib/management/update.mjs +59 -5
- package/lib/models/catalog-gemini.mjs +4 -1
- package/lib/models/gemini-models.json +4 -0
- 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/final-verify.mjs +2158 -0
- package/lib/runtime/node-test-reporter.mjs +81 -0
- package/lib/runtime/platform-registry.mjs +1 -1
- package/lib/runtime/role-bridge.mjs +10 -1
- package/lib/runtime/role-dispatch-policy.mjs +4 -0
- package/lib/runtime/role-observe.mjs +192 -14
- package/lib/runtime/role-supervisor.mjs +268 -23
- package/lib/runtime/test-results.mjs +736 -0
- package/lib/runtime/verify-cli.mjs +60 -0
- package/lib/tui/app.mjs +7 -41
- package/lib/tui/interface.mjs +40 -0
- package/lib/tui/render.mjs +1 -1
- 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 +54 -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/final-verify.mjs +2158 -0
- package/shared/skill/runtime/node-test-reporter.mjs +81 -0
- package/shared/skill/runtime/platform-registry.mjs +1 -1
- package/shared/skill/runtime/role-bridge.mjs +10 -1
- package/shared/skill/runtime/role-dispatch-policy.mjs +4 -0
- package/shared/skill/runtime/role-observe.mjs +192 -14
- package/shared/skill/runtime/role-policy.json +1 -1
- package/shared/skill/runtime/role-supervisor.mjs +268 -23
- package/shared/skill/runtime/test-results.mjs +736 -0
- package/shared/skill/runtime/verify-cli.mjs +60 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import {displayWidth, wrapLineRanges} from './text-width.mjs';
|
|
2
|
+
|
|
3
|
+
const reset = '\x1b[0m';
|
|
4
|
+
const inline = /(?<!`)`(?<code>[^`]+)`(?!`)|\[(?<label>[^\[\]]+)\]\((?<url>[^\s()]+)\)|(?<delimiter>(?<!\*)\*\*|(?<![\p{L}\p{N}_*])\*)(?![\s*])(?<emphasis>[^*]*?)(?<!\s)\k<delimiter>(?!\*)/gu;
|
|
5
|
+
const fenceMarker = /^ *(`{3,}|~{3,})(.*)$/;
|
|
6
|
+
const pipeStart = /^ *\|/;
|
|
7
|
+
|
|
8
|
+
function inlineSpans(text) {
|
|
9
|
+
const spans = [];
|
|
10
|
+
let start = 0;
|
|
11
|
+
for (const {index, 0:token, groups:{code, label, url, delimiter, emphasis}} of text.matchAll(inline)) {
|
|
12
|
+
if (index > start) spans.push({text:text.slice(start, index)});
|
|
13
|
+
if (code !== undefined) spans.push({text:code, style:'38;5;180'});
|
|
14
|
+
else if (label !== undefined) spans.push({text:`${label} (${url})`});
|
|
15
|
+
else spans.push({text:emphasis, style:delimiter === '**' ? '1' : '3'});
|
|
16
|
+
start = index + token.length;
|
|
17
|
+
}
|
|
18
|
+
if (start < text.length) spans.push({text:text.slice(start)});
|
|
19
|
+
return spans;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function renderLine(spans, {width, baseCode, blockStyle, prefix = '', preserveWhitespace}) {
|
|
23
|
+
const blockCode = blockStyle ? `${baseCode};${blockStyle}` : baseCode;
|
|
24
|
+
// Very narrow widths may leave no room after a marker. Wrap it with the body in that case.
|
|
25
|
+
if (prefix && width - prefix.length < 2) {
|
|
26
|
+
spans.unshift({text:prefix});
|
|
27
|
+
prefix = '';
|
|
28
|
+
}
|
|
29
|
+
const text = spans.map(span => span.text).join('');
|
|
30
|
+
const avail = width - prefix.length;
|
|
31
|
+
const ranges = avail === Infinity ? [{from:0, to:text.length}]
|
|
32
|
+
: avail > 0 ? wrapLineRanges(text, avail, {preserveWhitespace}) : [{from:0, to:0}];
|
|
33
|
+
let spanIndex = 0, spanStart = 0;
|
|
34
|
+
return ranges.map(({from, to, overflows}, index) => {
|
|
35
|
+
let line = index ? ' '.repeat(prefix.length) : prefix;
|
|
36
|
+
let active = blockCode;
|
|
37
|
+
if (line) line = `\x1b[${active}m${line}`;
|
|
38
|
+
if (overflows) return `${line || `\x1b[${active}m`}�${reset}`;
|
|
39
|
+
while (from < to && spanIndex < spans.length) {
|
|
40
|
+
const span = spans[spanIndex];
|
|
41
|
+
const spanEnd = spanStart + span.text.length;
|
|
42
|
+
if (spanEnd > from) {
|
|
43
|
+
const code = span.style ? `${blockCode};${span.style}` : blockCode;
|
|
44
|
+
if (!line) line = `\x1b[${code}m`;
|
|
45
|
+
else if (active !== code) line += `\x1b[0;${code}m`;
|
|
46
|
+
line += span.text.slice(Math.max(from - spanStart, 0), to - spanStart);
|
|
47
|
+
active = code;
|
|
48
|
+
}
|
|
49
|
+
if (spanEnd >= to) break;
|
|
50
|
+
spanStart = spanEnd;
|
|
51
|
+
spanIndex++;
|
|
52
|
+
}
|
|
53
|
+
return line ? `${line}${reset}` : '';
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function splitTableRow(line) {
|
|
58
|
+
if (!line?.includes('|')) return;
|
|
59
|
+
const row = line.trim();
|
|
60
|
+
const cells = [];
|
|
61
|
+
let start = 0;
|
|
62
|
+
const cell = end => row.slice(start, end).trim().replace(/\\\\|\\\|/g, token => token === '\\|' ? '|' : token);
|
|
63
|
+
for (const {0:token, index} of row.matchAll(/\\[\\|]|(?<!`)`[^`]+`(?!`)|\|/g)) {
|
|
64
|
+
if (token !== '|') continue;
|
|
65
|
+
if (index) cells.push(cell(index));
|
|
66
|
+
start = index + 1;
|
|
67
|
+
}
|
|
68
|
+
if (!start) return;
|
|
69
|
+
if (start < row.length) cells.push(cell(row.length));
|
|
70
|
+
return cells;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function readTable(source, index) {
|
|
74
|
+
if (!pipeStart.test(source[index])) return;
|
|
75
|
+
const divider = source[index + 1];
|
|
76
|
+
if (!divider?.includes('|') || !/^[ |:-]+$/.test(divider)) return;
|
|
77
|
+
const header = splitTableRow(source[index]);
|
|
78
|
+
const columns = splitTableRow(divider);
|
|
79
|
+
if (!header?.length || columns.length !== header.length || !columns.every(cell => /^:?-+:?$/.test(cell))) return;
|
|
80
|
+
|
|
81
|
+
const rows = [];
|
|
82
|
+
let end = index + 2;
|
|
83
|
+
for (; end < source.length && !fenceMarker.test(source[end]); end++) {
|
|
84
|
+
const cells = splitTableRow(source[end]);
|
|
85
|
+
if (!cells) break;
|
|
86
|
+
rows.push(header.map((_, col) => col === header.length - 1 ? cells.slice(col).join(' | ') : cells[col] ?? ''));
|
|
87
|
+
}
|
|
88
|
+
if (!rows.length) return;
|
|
89
|
+
const alignments = columns.map(cell => !cell.endsWith(':') ? 'left' : cell.startsWith(':') ? 'center' : 'right');
|
|
90
|
+
return {header, rows, alignments, end};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function fitTableWidths(natural, width) {
|
|
94
|
+
const available = width - (3 * natural.length + 1);
|
|
95
|
+
if (natural.reduce((sum, cols) => sum + cols, 0) <= available) return natural;
|
|
96
|
+
if (6 * natural.length > available) return;
|
|
97
|
+
|
|
98
|
+
// Cap the widest columns together, then use any remaining space among those columns.
|
|
99
|
+
let low = 6, high = available;
|
|
100
|
+
while (low < high) {
|
|
101
|
+
const cap = Math.ceil((low + high) / 2);
|
|
102
|
+
const total = natural.reduce((sum, cols) => sum + Math.min(cols, cap), 0);
|
|
103
|
+
if (total <= available) low = cap;
|
|
104
|
+
else high = cap - 1;
|
|
105
|
+
}
|
|
106
|
+
const widths = natural.map(cols => Math.min(cols, low));
|
|
107
|
+
let remaining = available - widths.reduce((sum, cols) => sum + cols, 0);
|
|
108
|
+
for (let col = widths.length - 1; col >= 0 && remaining > 0; col--) {
|
|
109
|
+
if (natural[col] > low) {
|
|
110
|
+
widths[col]++;
|
|
111
|
+
remaining--;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return widths;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function renderCards([header, ...rows], {width, baseCode}) {
|
|
118
|
+
const lines = [];
|
|
119
|
+
for (const row of rows) {
|
|
120
|
+
if (lines.length) lines.push('');
|
|
121
|
+
for (const [col, value] of row.entries()) {
|
|
122
|
+
const marker = col === 0 ? '▸ ' : ' ';
|
|
123
|
+
const label = `${header[col].map(span => span.text).join('')}:`;
|
|
124
|
+
const prefix = `${marker}${label} `;
|
|
125
|
+
const prefixWidth = displayWidth(prefix);
|
|
126
|
+
if (width - prefixWidth < 2) {
|
|
127
|
+
lines.push(...renderLine([{text:label}], {width, baseCode, prefix:marker}));
|
|
128
|
+
if (value.length) lines.push(...renderLine(value, {width, baseCode, prefix:' '}));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const wrapped = renderLine(value, {width:width - prefixWidth, baseCode});
|
|
132
|
+
for (const [index, piece] of wrapped.entries()) {
|
|
133
|
+
const lead = index ? ' '.repeat(prefixWidth) : prefix;
|
|
134
|
+
lines.push(piece ? `\x1b[${baseCode}m${lead}${piece}` : `\x1b[${baseCode}m${lead.trimEnd()}${reset}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return lines;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function renderTable({header, rows, alignments}, options) {
|
|
142
|
+
const {baseCode, width} = options;
|
|
143
|
+
const cells = [header, ...rows].map(row => row.map(inlineSpans));
|
|
144
|
+
const natural = header.map(() => 1);
|
|
145
|
+
for (const row of cells) {
|
|
146
|
+
for (const [col, spans] of row.entries()) {
|
|
147
|
+
natural[col] = Math.max(natural[col], displayWidth(spans.map(span => span.text).join('')));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const widths = fitTableWidths(natural, width);
|
|
151
|
+
if (!widths) return renderCards(cells, options);
|
|
152
|
+
|
|
153
|
+
const border = (left, cross, right) => `\x1b[${baseCode}m${left}${widths.map(cols => '─'.repeat(cols + 2)).join(cross)}${right}${reset}`;
|
|
154
|
+
const lines = [border('┌', '┬', '┐')];
|
|
155
|
+
for (const [index, row] of cells.entries()) {
|
|
156
|
+
if (index) lines.push(border('├', '┼', '┤'));
|
|
157
|
+
const wrapped = row.map((spans, col) => renderLine(spans, {width:widths[col], baseCode, blockStyle:index === 0 ? '1' : undefined}));
|
|
158
|
+
const height = wrapped.reduce((max, cell) => Math.max(max, cell.length), 0);
|
|
159
|
+
for (let line = 0; line < height; line++) {
|
|
160
|
+
let visual = `\x1b[${baseCode}m│`;
|
|
161
|
+
for (const [col, cell] of wrapped.entries()) {
|
|
162
|
+
const piece = cell[line] ?? '';
|
|
163
|
+
const pad = widths[col] - displayWidth(piece.replace(/\x1b\[[0-9;]*m/g, ''));
|
|
164
|
+
const left = alignments[col] === 'right' ? pad : alignments[col] === 'center' ? Math.floor(pad / 2) : 0;
|
|
165
|
+
visual += ' '.repeat(left + 1);
|
|
166
|
+
if (piece) visual += `${piece}\x1b[${baseCode}m`;
|
|
167
|
+
visual += `${' '.repeat(pad - left + 1)}│`;
|
|
168
|
+
}
|
|
169
|
+
lines.push(visual + reset);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
lines.push(border('└', '┴', '┘'));
|
|
173
|
+
return lines;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function renderMarkdown(text, {width, baseCode}) {
|
|
177
|
+
const lines = [];
|
|
178
|
+
const source = text.replace(/[\x00-\x09\x0b-\x1f\x7f-\x9f]/g, '').split('\n');
|
|
179
|
+
let fence;
|
|
180
|
+
for (let index = 0; index < source.length; index++) {
|
|
181
|
+
const line = source[index];
|
|
182
|
+
const marker = fenceMarker.exec(line);
|
|
183
|
+
if (fence) {
|
|
184
|
+
if (marker && marker[1][0] === fence[0] && marker[1].length >= fence.length && !marker[2].trim()) {
|
|
185
|
+
fence = undefined;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
} else if (marker && (marker[1][0] === '~' || !marker[2].includes('`'))) {
|
|
189
|
+
fence = marker[1];
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
if (!line) {
|
|
193
|
+
lines.push('');
|
|
194
|
+
continue;
|
|
195
|
+
}
|
|
196
|
+
if (!fence) {
|
|
197
|
+
const table = readTable(source, index);
|
|
198
|
+
if (table) {
|
|
199
|
+
for (const visual of renderTable(table, {width, baseCode})) lines.push(visual);
|
|
200
|
+
index = table.end - 1;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
let content = line, prefix, blockStyle;
|
|
206
|
+
const rawPipe = pipeStart.test(line);
|
|
207
|
+
if (fence) {
|
|
208
|
+
prefix = ' ';
|
|
209
|
+
blockStyle = '2';
|
|
210
|
+
} else if (!rawPipe) {
|
|
211
|
+
const heading = /^#{1,6} (.*)$/.exec(line);
|
|
212
|
+
const list = /^( *)([-*+]|\d+\.) (.*)$/.exec(line);
|
|
213
|
+
if (heading) {
|
|
214
|
+
content = heading[1];
|
|
215
|
+
blockStyle = '1;4';
|
|
216
|
+
} else if (/^ *(?:---|\*\*\*|___) *$/.test(line)) {
|
|
217
|
+
content = '─'.repeat(Math.max(0, Math.min(width, 40)));
|
|
218
|
+
} else if (list) {
|
|
219
|
+
const indent = ' '.repeat(list[1].length - list[1].length % 2);
|
|
220
|
+
prefix = `${indent}${list[2].endsWith('.') ? list[2] : '•'} `;
|
|
221
|
+
content = list[3];
|
|
222
|
+
} else if (line.startsWith('> ')) {
|
|
223
|
+
prefix = '│ ';
|
|
224
|
+
blockStyle = '2';
|
|
225
|
+
content = line.slice(2);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
const spans = fence || rawPipe ? [{text:content}] : inlineSpans(content);
|
|
229
|
+
for (const visual of renderLine(spans, {width, baseCode, prefix, blockStyle, preserveWhitespace:Boolean(fence)})) lines.push(visual);
|
|
230
|
+
}
|
|
231
|
+
return lines;
|
|
232
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {createTuiInterface} from '../tui/interface.mjs';
|
|
2
|
+
import {createTerminalSession} from '../tui/terminal.mjs';
|
|
3
|
+
|
|
4
|
+
export function watchMenuRows(registry) {
|
|
5
|
+
return registry.byDisplayOrder().map(({id,label,capabilities}) => ({
|
|
6
|
+
id,label,supported:capabilities.watch.state === 'verified',
|
|
7
|
+
}));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function chooseWatchPlatforms({input,output,env,signals,registry,createSession=createTerminalSession}) {
|
|
11
|
+
const rows = watchMenuRows(registry);
|
|
12
|
+
const checked = new Set(rows.filter(row => row.supported).map(row => row.id));
|
|
13
|
+
const watchIndex = rows.length;
|
|
14
|
+
const actionKinds = [...rows.map(() => undefined),'confirm'];
|
|
15
|
+
const session = createSession({input,output,env,signals});
|
|
16
|
+
try {
|
|
17
|
+
const ui = createTuiInterface(session,{input});
|
|
18
|
+
let selected = watchIndex, notice = [];
|
|
19
|
+
for (;;) {
|
|
20
|
+
const labels = rows.map(({id,label,supported}) => {
|
|
21
|
+
if (!supported) return '[-] '+label+' (not supported)';
|
|
22
|
+
return (checked.has(id) ? '[x] ' : '[ ] ')+label;
|
|
23
|
+
});
|
|
24
|
+
labels.push('Watch');
|
|
25
|
+
const previous = selected;
|
|
26
|
+
selected = await ui.menu('Which platforms to watch?',labels,{
|
|
27
|
+
selected,backRow:true,backLabel:'exit',hint:'checklist',actionKinds,
|
|
28
|
+
notice:({selected:current})=>{
|
|
29
|
+
if (current !== previous) notice = [];
|
|
30
|
+
return notice;
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (selected === null) return null;
|
|
34
|
+
if (selected === watchIndex) {
|
|
35
|
+
if (checked.size) return rows.filter(row => checked.has(row.id)).map(row => row.id);
|
|
36
|
+
notice = ['Select at least one platform to watch.'];
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const row = rows[selected];
|
|
40
|
+
if (!row.supported) {
|
|
41
|
+
notice = [row.label+' is not supported by arc watch.'];
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if (checked.has(row.id)) checked.delete(row.id);
|
|
45
|
+
else checked.add(row.id);
|
|
46
|
+
notice = [];
|
|
47
|
+
}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error.code === 'ARC_TUI_EOF') return null;
|
|
50
|
+
throw error;
|
|
51
|
+
} finally {
|
|
52
|
+
session.dispose();
|
|
53
|
+
}
|
|
54
|
+
}
|
package/lib/watch/model.mjs
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
export const WATCH_KINDS = Object.freeze(['session','settings','turn_start','turn_end','turn_failed','user','agent','reasoning','command','tool','tool_failed','file_change','file_create','file_delete','spawn','approval','dispatch','error','other','notice']);
|
|
2
|
-
export const MESSAGE_KINDS = Object.freeze(['user','agent']);
|
|
1
|
+
export const WATCH_KINDS = Object.freeze(['session','settings','turn_start','turn_end','turn_failed','user','prompt','agent','reasoning','command','tool','tool_failed','file_change','file_create','file_delete','spawn','approval','dispatch','error','other','notice']);
|
|
2
|
+
export const MESSAGE_KINDS = Object.freeze(['user','prompt','agent']);
|
|
3
|
+
|
|
4
|
+
export function classifyMessageKind(event) {
|
|
5
|
+
return event.kind === 'user' && (event.parentId || event.dispatchId) ? 'prompt' : event.kind;
|
|
6
|
+
}
|
|
3
7
|
export const VERBOSE_KINDS = Object.freeze(['settings','turn_start','reasoning','other']);
|
|
4
8
|
export const ROLE_NAMES = Object.freeze(['scouter','planner','implementer','qa','reviewer']);
|
|
5
9
|
|
|
@@ -35,7 +39,7 @@ export const WATCH_LIMITS = Object.freeze({
|
|
|
35
39
|
* @property {'scouter'|'planner'|'implementer'|'qa'|'reviewer'|'orchestrator'} [role]
|
|
36
40
|
* @property {string} [dispatchId]
|
|
37
41
|
* @property {string} [workflowId]
|
|
38
|
-
* @property {'session'|'settings'|'turn_start'|'turn_end'|'turn_failed'|'user'|'agent'|'reasoning'|'command'|'tool'|'tool_failed'|'file_change'|'file_create'|'file_delete'|'spawn'|'approval'|'dispatch'|'error'|'other'|'notice'} kind
|
|
42
|
+
* @property {'session'|'settings'|'turn_start'|'turn_end'|'turn_failed'|'user'|'prompt'|'agent'|'reasoning'|'command'|'tool'|'tool_failed'|'file_change'|'file_create'|'file_delete'|'spawn'|'approval'|'dispatch'|'error'|'other'|'notice'} kind
|
|
39
43
|
* @property {string} [text] Sanitized, masked text; user/agent preserve newlines without a length cap. Other JSON text is capped at 1000 code points.
|
|
40
44
|
* @property {boolean} [truncated]
|
|
41
45
|
* @property {number} [exitCode]
|
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
|
+
}
|