@yunhozz/arc 0.4.7 → 0.5.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 +47 -45
- package/README.md +99 -33
- package/claude/agents/arc-implementer.md +1 -1
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/models.toml +9 -9
- package/claude/skill/references/handoff-prep.md +1 -1
- package/claude/skill/references/verification.md +4 -4
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/models.toml +9 -9
- package/codex/skill/references/handoff-prep.md +1 -1
- package/codex/skill/references/verification.md +4 -4
- 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/SKILL.md +1 -1
- package/gemini/skill/models.toml +6 -6
- package/gemini/skill/references/handoff-prep.md +1 -1
- package/gemini/skill/references/verification.md +4 -4
- package/grok/agents/arc-implementer.md +1 -1
- package/grok/skill/SKILL.md +1 -1
- package/grok/skill/references/handoff-prep.md +1 -1
- package/grok/skill/references/verification.md +4 -4
- package/lib/cli/postinstall.mjs +1 -1
- package/lib/installer/targets.mjs +3 -1
- package/lib/management/operations.mjs +4 -4
- package/lib/models/catalog-gemini.mjs +4 -1
- package/lib/models/gemini-models.json +4 -0
- package/lib/prompts/agent-fragments.json +3 -3
- package/lib/runtime/local-cli.mjs +9 -2
- package/lib/runtime/platform-registry.mjs +1 -1
- package/lib/runtime/role-dispatch-policy.mjs +5 -2
- package/lib/tui/app.mjs +36 -9
- package/lib/tui/interface.mjs +2 -2
- package/lib/tui/render.mjs +5 -3
- package/lib/tui/terminal.mjs +5 -3
- package/lib/watch/brief.mjs +44 -0
- package/lib/watch/dispatch.mjs +44 -6
- package/lib/watch/index.mjs +107 -22
- package/lib/watch/markdown.mjs +42 -9
- package/lib/watch/menu.mjs +26 -15
- package/lib/watch/model.mjs +1 -0
- package/lib/watch/render.mjs +3 -2
- package/lib/watch/scope.mjs +125 -0
- package/lib/watch/watcher.mjs +149 -82
- package/lib/watch/worktree-menu.mjs +64 -0
- package/package.json +1 -1
- package/shared/skill/runtime/local-cli.mjs +9 -2
- package/shared/skill/runtime/platform-registry.mjs +1 -1
- package/shared/skill/runtime/role-dispatch-policy.mjs +5 -2
package/lib/tui/render.mjs
CHANGED
|
@@ -13,7 +13,7 @@ export function navigationHint(mode='menu',{backLabel='back',horizontal=false}={
|
|
|
13
13
|
if(mode==='text')return'↑/↓: Select · Type/Paste Input · Backspace Delete · Enter Continue · Esc Home';
|
|
14
14
|
if(mode==='busy')return'Ctrl+C Interrupt';
|
|
15
15
|
if(mode==='page')return'↑/↓: Scroll · Enter Back · Esc Home';
|
|
16
|
-
if(mode==='checklist')return'↑/↓: Select · Enter Toggle · Esc Home';
|
|
16
|
+
if(mode==='checklist')return'↑/↓: Select · Enter Toggle · Esc '+(backLabel==='exit'?'Exit':'Home');
|
|
17
17
|
return'↑/↓: Select · '+(horizontal?'←/→: Change · ':'')+'Enter Continue · Esc '+(backLabel==='exit'?'Exit':'Home');
|
|
18
18
|
}
|
|
19
19
|
export function arrowValue(text,frame,active){return active&&Math.floor(frame/5)%2===1?' <'+text+'> ':'< '+text+' >';}
|
|
@@ -81,9 +81,10 @@ export function renderScreen(screen={}, {columns=80,rows=24}={}){
|
|
|
81
81
|
const selectedLine=heading.length+selected;
|
|
82
82
|
for(let line=0;line<visible.length;line++){
|
|
83
83
|
const source=indices[line],runs=[];
|
|
84
|
+
const dim=source>=heading.length&&source<heading.length+entries.length&&rowTones[source-heading.length]==='dim';
|
|
84
85
|
function add(from,to,role,fg,bg,bold){
|
|
85
86
|
to=Math.min(to,[...visible[line]].length);if(from>=to)return;
|
|
86
|
-
const run={from,to,role,...(fg?{fg}:{}),...(bg?{bg}:{}),...(bold?{bold}: {})},last=runs.at(-1);
|
|
87
|
+
const run={from,to,role,...(fg?{fg}:{}),...(bg?{bg}:{}),...(bold?{bold}: {}),...(dim?{dim:true}:{})},last=runs.at(-1);
|
|
87
88
|
if(last&&last.to===from&&last.role===role&&JSON.stringify(last.fg)===JSON.stringify(fg)&&JSON.stringify(last.bg)===JSON.stringify(bg)&&last.bold===run.bold)last.to=to;else runs.push(run);
|
|
88
89
|
}
|
|
89
90
|
const length=[...visible[line]].length;
|
|
@@ -107,7 +108,8 @@ export function renderScreen(screen={}, {columns=80,rows=24}={}){
|
|
|
107
108
|
}
|
|
108
109
|
else if(source>=heading.length&&source<heading.length+entries.length&&rowTones[source-heading.length]){
|
|
109
110
|
const tone=rowTones[source-heading.length],text=visible[line].slice(2);
|
|
110
|
-
if(tone==='
|
|
111
|
+
if(tone==='dim')add(0,length,'dim');
|
|
112
|
+
else if(tone==='status'||tone==='platform-status')for(const {from,to,role} of rowStatusSpans[source-heading.length]??(tone==='status'?statusSpans:platformStatusSpans)(entries[source-heading.length]))add(from+2,to+2,role,TONE_FG[role]);
|
|
111
113
|
else if(tone==='diagnostic'){const separator=text.indexOf(': ');if(separator>=0)add(2+[...text.slice(0,separator+2)].length,length,'warn',TONE_FG.warn);}
|
|
112
114
|
else if(tone==='diagnostic-cont'||tone==='note')add(2,length,'warn',TONE_FG.warn);
|
|
113
115
|
}
|
package/lib/tui/terminal.mjs
CHANGED
|
@@ -9,11 +9,13 @@ export function formatLine(line,style,depth){
|
|
|
9
9
|
if(depth==='none'||!style?.runs?.length)return line;
|
|
10
10
|
const characters=[...line];let result='',end=0,painted=false;
|
|
11
11
|
for(const run of style.runs){
|
|
12
|
-
if(
|
|
12
|
+
if(run.role!=='dim'&&!Object.hasOwn(BASIC,run.role))continue;
|
|
13
13
|
const from=Math.max(end,Math.min(characters.length,run.from)),to=Math.min(characters.length,run.to);if(from>=to)continue;
|
|
14
14
|
if(from>end){if(painted){result+='\x1b[0m';painted=false;}result+=characters.slice(end,from).join('');}
|
|
15
|
-
let params=BASIC[run.role];if(depth!=='16'){const values=run.bold?['1']:[];for(const [key,code] of [['fg',38],['bg',48]])if(run[key])values.push(depth==='truecolor'?code+';2;'+rgb(run[key]).join(';'):code+';5;'+toAnsi256(run[key]));params=values.join(';');}
|
|
16
|
-
|
|
15
|
+
let params=BASIC[run.role]??'';if(depth!=='16'){const values=run.bold?['1']:[];for(const [key,code] of [['fg',38],['bg',48]])if(run[key])values.push(depth==='truecolor'?code+';2;'+rgb(run[key]).join(';'):code+';5;'+toAnsi256(run[key]));params=values.join(';');}
|
|
16
|
+
const dim=run.dim||run.role==='dim';
|
|
17
|
+
const escape=(params?'\x1b[0;'+params+'m':'')+(dim?'\x1b[2m':'');
|
|
18
|
+
if(escape){if(painted!==escape)result+=(!params&&painted?'\x1b[0m':'')+escape;painted=escape;}else if(painted){result+='\x1b[0m';painted=false;}
|
|
17
19
|
result+=characters.slice(from,to).join('');end=to;
|
|
18
20
|
}
|
|
19
21
|
if(painted)result+='\x1b[0m';return result+characters.slice(end).join('');
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {renderBox} from './markdown.mjs';
|
|
2
|
+
import {sanitizeText} from './policy.mjs';
|
|
3
|
+
import {displayWidth, wrapLineRanges} from './text-width.mjs';
|
|
4
|
+
|
|
5
|
+
function wrapPlain(text, width) {
|
|
6
|
+
return wrapLineRanges(text, width).map(({from,to,overflows}) => overflows ? '�' : text.slice(from,to));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function briefLines(brief, {version, keys}) {
|
|
10
|
+
const scope = sanitizeText(brief.scope + (brief.branch ? ` (${brief.branch})` : ''));
|
|
11
|
+
return [
|
|
12
|
+
`arc watch ${version}`,
|
|
13
|
+
`**Scope** ${scope.replace(/[\\*`\[]/g, '\\$&')}`,
|
|
14
|
+
`**Platforms** ${brief.platforms.map(platform => platform.toUpperCase()).join(' · ')}`,
|
|
15
|
+
`**Keys** ${keys.join(' · ')}`,
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function earlierPageLines({shown, remaining}) {
|
|
20
|
+
if (!shown) return {start:'── no earlier events in loaded history ──'};
|
|
21
|
+
const position = remaining ? `${remaining} more` : 'start of loaded history';
|
|
22
|
+
return {start:`── earlier ${shown} events · ${position} ──`,end:'── back to live ──'};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function renderBrief(brief, {version, keys, width, color}) {
|
|
26
|
+
const columns = width - 1;
|
|
27
|
+
if (columns < 1) return [];
|
|
28
|
+
const lines = briefLines(brief, {version, keys});
|
|
29
|
+
if (width >= 24) return renderBox(lines, {width:columns, baseCode:color ? '2' : undefined});
|
|
30
|
+
return lines.flatMap(markdown => {
|
|
31
|
+
const label = /^\*\*([^*]+)\*\* /.exec(markdown);
|
|
32
|
+
const value = markdown.slice(label?.[0].length ?? 0).replace(/\\([\\*`\[])/g, '$1');
|
|
33
|
+
if (!label) return wrapPlain(value, columns);
|
|
34
|
+
|
|
35
|
+
const prefix = `${label[1]} `;
|
|
36
|
+
const available = columns - displayWidth(prefix);
|
|
37
|
+
if (available < 1 || !value) return wrapPlain(prefix + value, columns);
|
|
38
|
+
const [first] = wrapLineRanges(value, available);
|
|
39
|
+
if (first.overflows) return wrapPlain(prefix + value, columns);
|
|
40
|
+
|
|
41
|
+
const rest = value.slice(first.to).trimStart();
|
|
42
|
+
return [prefix + value.slice(first.from, first.to), ...(rest ? wrapPlain(rest, columns) : [])];
|
|
43
|
+
});
|
|
44
|
+
}
|
package/lib/watch/dispatch.mjs
CHANGED
|
@@ -3,6 +3,17 @@ import path from 'node:path';
|
|
|
3
3
|
import {createTail} from './tail.mjs';
|
|
4
4
|
import {roleFromName} from './labels.mjs';
|
|
5
5
|
|
|
6
|
+
const HEARTBEAT_SUFFIX = '.heartbeat.json';
|
|
7
|
+
|
|
8
|
+
function parseHeartbeat(text) {
|
|
9
|
+
try {
|
|
10
|
+
const {at} = JSON.parse(text) ?? {};
|
|
11
|
+
return Number.isFinite(at) ? at : null;
|
|
12
|
+
} catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
export function parseLeaseLenient(text) {
|
|
7
18
|
let value;
|
|
8
19
|
try { value = JSON.parse(text); } catch { return null; }
|
|
@@ -11,6 +22,8 @@ export function parseLeaseLenient(text) {
|
|
|
11
22
|
for (const key of ['dispatchId', 'workflowId', 'role', 'route', 'hostPlatform', 'state', 'sessionId', 'nativeAgentId', 'createdAt', 'updatedAt']) {
|
|
12
23
|
if (typeof value[key] === 'string') lease[key] = value[key];
|
|
13
24
|
}
|
|
25
|
+
if (typeof value.version === 'number') lease.version = value.version;
|
|
26
|
+
if (value.version === 2 && typeof value.targetPlatform === 'string') lease.targetPlatform = value.targetPlatform;
|
|
14
27
|
lease.reasons = Array.isArray(value.reasons) ? value.reasons.filter(reason => typeof reason === 'string') : [];
|
|
15
28
|
return lease;
|
|
16
29
|
}
|
|
@@ -25,13 +38,27 @@ async function entries(dir) {
|
|
|
25
38
|
|
|
26
39
|
export function createDispatchIndex({storeDir} = {}) {
|
|
27
40
|
const refs = new Map(), leases = new Map(), tails = new Map(), records = new Map(), signatures = new Map();
|
|
41
|
+
const sessionEventKinds = new Map();
|
|
42
|
+
const heartbeats = new Map();
|
|
28
43
|
|
|
29
|
-
async function
|
|
44
|
+
async function readStore() {
|
|
30
45
|
const dir = storeDir, seen = new Set();
|
|
31
|
-
for (const entry of await entries(dir)) {
|
|
32
|
-
if (!entry.isFile() || entry.name.startsWith('.') || !entry.name.endsWith('.json')
|
|
46
|
+
for (const entry of dir ? await entries(dir) : []) {
|
|
47
|
+
if (!entry.isFile() || entry.name.startsWith('.') || !entry.name.endsWith('.json')) continue;
|
|
33
48
|
const file = path.join(dir, entry.name);
|
|
34
49
|
seen.add(file);
|
|
50
|
+
if (entry.name.endsWith(HEARTBEAT_SUFFIX)) {
|
|
51
|
+
try {
|
|
52
|
+
const {mtimeMs} = await fsp.stat(file);
|
|
53
|
+
if (heartbeats.get(file)?.mtimeMs === mtimeMs) continue;
|
|
54
|
+
const at = parseHeartbeat(await fsp.readFile(file, 'utf8'));
|
|
55
|
+
heartbeats.set(file, {mtimeMs, at});
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (error.code === 'ENOENT') heartbeats.delete(file);
|
|
58
|
+
else heartbeats.set(file, {at:null});
|
|
59
|
+
}
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
35
62
|
try {
|
|
36
63
|
const {mtimeMs} = await fsp.stat(file);
|
|
37
64
|
if (leases.get(file)?.mtimeMs === mtimeMs) continue;
|
|
@@ -42,7 +69,11 @@ export function createDispatchIndex({storeDir} = {}) {
|
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
71
|
for (const file of leases.keys()) if (!seen.has(file)) leases.delete(file);
|
|
45
|
-
|
|
72
|
+
for (const file of heartbeats.keys()) if (!seen.has(file)) heartbeats.delete(file);
|
|
73
|
+
return {
|
|
74
|
+
currentLeases: new Map([...leases.values()].map(({value}) => [value.dispatchId, value])),
|
|
75
|
+
heartbeatTimes: new Map([...heartbeats].map(([file,{at}]) => [path.basename(file,HEARTBEAT_SUFFIX), at])),
|
|
76
|
+
};
|
|
46
77
|
}
|
|
47
78
|
|
|
48
79
|
async function readRecord(dir) {
|
|
@@ -69,7 +100,7 @@ export function createDispatchIndex({storeDir} = {}) {
|
|
|
69
100
|
const sessionId = event?.kind === 'thread' ? event.threadId : event?.kind === 'init' ? event.sessionId : null;
|
|
70
101
|
if (typeof sessionId !== 'string') continue;
|
|
71
102
|
if (!ref.sessionIds.includes(sessionId)) ref.sessionIds.push(sessionId);
|
|
72
|
-
ref.
|
|
103
|
+
sessionEventKinds.set(ref.dispatchId, event.kind);
|
|
73
104
|
}
|
|
74
105
|
}
|
|
75
106
|
|
|
@@ -80,7 +111,8 @@ export function createDispatchIndex({storeDir} = {}) {
|
|
|
80
111
|
|
|
81
112
|
return {
|
|
82
113
|
async scan({gitCommonDirs}) {
|
|
83
|
-
const currentLeases =
|
|
114
|
+
const {currentLeases,heartbeatTimes} = await readStore();
|
|
115
|
+
const artifacts = new Map();
|
|
84
116
|
for (const gcd of gitCommonDirs) {
|
|
85
117
|
const workflows = path.join(gcd, 'arc', 'workflows');
|
|
86
118
|
for (const workflow of await entries(workflows)) {
|
|
@@ -116,6 +148,12 @@ export function createDispatchIndex({storeDir} = {}) {
|
|
|
116
148
|
ref.inScope = Boolean(artifact);
|
|
117
149
|
ref.artifactDir = artifact?.dir ?? null;
|
|
118
150
|
ref.cwd = artifact?.cwd ?? null;
|
|
151
|
+
ref.heartbeatAt = lease ? heartbeatTimes.get(id) : undefined;
|
|
152
|
+
const sessionEvent = sessionEventKinds.get(id);
|
|
153
|
+
ref.childPlatform = (lease?.version ?? 1) === 1 && sessionEvent
|
|
154
|
+
? (sessionEvent === 'thread' ? 'codex' : 'claude') : null;
|
|
155
|
+
if (lease?.targetPlatform !== undefined) ref.targetPlatform = lease.targetPlatform;
|
|
156
|
+
else delete ref.targetPlatform;
|
|
119
157
|
if (!lease && !artifact) continue;
|
|
120
158
|
for (const key of ['workflowId', 'rawRole', 'route', 'hostPlatform', 'state', 'updatedAt']) delete ref[key];
|
|
121
159
|
if (artifact) ref.workflowId = artifact.workflowId;
|
package/lib/watch/index.mjs
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import os from 'node:os';
|
|
2
|
+
import {readFileSync} from 'node:fs';
|
|
2
3
|
import {parseWatchArgs} from './args.mjs';
|
|
3
4
|
import {resolveConfigHome} from '../runtime/local-cli.mjs';
|
|
4
5
|
import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
|
|
5
6
|
import {createWatcher} from './watcher.mjs';
|
|
6
|
-
import {resolveScope} from './scope.mjs';
|
|
7
|
-
import {createGitRunner} from './git.mjs';
|
|
7
|
+
import {groupActivity, parseWorktreeList, resolveScope, scopeForWorktree, selectableWorktrees} from './scope.mjs';
|
|
8
|
+
import {createGitRunner, GIT_ALLOWED} from './git.mjs';
|
|
8
9
|
import {renderHuman, renderJson} from './render.mjs';
|
|
9
10
|
import {watchLocationLabel, statusBlockLines} from './status-line.mjs';
|
|
10
11
|
import {WATCH_LIMITS as L} from './model.mjs';
|
|
12
|
+
import {earlierPageLines, renderBrief} from './brief.mjs';
|
|
13
|
+
|
|
14
|
+
const packageVersion = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')).version;
|
|
11
15
|
|
|
12
16
|
export {parseWatchArgs};
|
|
13
17
|
export const WATCH_HELP = `Usage: arc watch [options]
|
|
@@ -15,7 +19,7 @@ export const WATCH_HELP = `Usage: arc watch [options]
|
|
|
15
19
|
Follow session activity of supported platforms in one read-only stream.
|
|
16
20
|
|
|
17
21
|
Scope:
|
|
18
|
-
|
|
22
|
+
In a Git repository, first choose the worktree to watch from git worktree list, wherever it was created; the current worktree is selected, recent session activity is shown, and worktrees without recent activity are dimmed. Outside Git the current directory is watched. Then check the platforms to watch; all supported platforms are checked by default. Requires an interactive terminal.
|
|
19
23
|
|
|
20
24
|
Output:
|
|
21
25
|
--tail <n> First show the last <n> events from recently active sessions (default 20, 0 = new only)
|
|
@@ -30,8 +34,34 @@ User messages, agent messages, prompts and file paths are shown in full; other e
|
|
|
30
34
|
PROMPT is an agent-generated prompt sent to a child session (kind "prompt" in JSON).
|
|
31
35
|
Color TTY output renders Markdown in AGENT and PROMPT messages. NO_COLOR, piped output and --json keep the Markdown source text.
|
|
32
36
|
Tool and command outputs are never shown; common secret patterns are masked.
|
|
37
|
+
A summary box at the start shows the scope, platforms and keys (TTY only).
|
|
33
38
|
A status block on the last lines shows the watched path and, while a turn is in progress, a spinner (TTY only).
|
|
34
|
-
Press Ctrl-L to clear the screen
|
|
39
|
+
Press Ctrl-H to show earlier events from the history loaded at start, 20 at a time, Ctrl-L to clear the screen and Ctrl-C to stop. Ctrl-H and Ctrl-L work in a TTY only.
|
|
40
|
+
Terminals that send ^H for Backspace also show earlier events on Backspace.`;
|
|
41
|
+
|
|
42
|
+
function resolveWatchHomes({registry,userHome,env,cwd}) {
|
|
43
|
+
const homes = {}, homeErrors = {};
|
|
44
|
+
for (const {id} of registry.byAnchorOrder()) {
|
|
45
|
+
try { homes[id] = resolveConfigHome(id,{userHome,env,cwd,runtimePlatforms:registry}); }
|
|
46
|
+
catch (cause) { homes[id] = null; homeErrors[id] = cause.message; }
|
|
47
|
+
}
|
|
48
|
+
return {homes,homeErrors};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async function probeWorktrees({worktrees,scope,homes,userHome,git,now,registry}) {
|
|
52
|
+
const platforms = registry.byDisplayOrder().filter(row=>row.capabilities.watch.state==='verified').map(row=>row.id);
|
|
53
|
+
const probe = createWatcher({
|
|
54
|
+
options:{probe:true,platforms,tail:0},homes:{...homes,user:userHome},git,now,registry,
|
|
55
|
+
scope:{kind:'repo',roots:worktrees.map(tree=>tree.root),excludedRoots:[],gitCommonDir:scope.gitCommonDir},
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
await probe.start();
|
|
59
|
+
const time = now();
|
|
60
|
+
return {groups:groupActivity(worktrees,probe.listActivity(),{now:time}),now:time};
|
|
61
|
+
} finally {
|
|
62
|
+
await probe.close();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
35
65
|
|
|
36
66
|
export async function runWatch(argv, io = {}) {
|
|
37
67
|
const input = io.input ?? process.stdin;
|
|
@@ -46,16 +76,52 @@ export async function runWatch(argv, io = {}) {
|
|
|
46
76
|
return 2;
|
|
47
77
|
}
|
|
48
78
|
const registry = io.registry ?? DEFAULT_PLATFORM_REGISTRY;
|
|
79
|
+
const cwd = io.cwd ?? process.cwd(), env = io.env ?? process.env, userHome = io.userHome ?? os.homedir();
|
|
80
|
+
const git = io.git ?? createGitRunner({env}), now = io.now ?? Date.now;
|
|
81
|
+
const {homes,homeErrors} = resolveWatchHomes({registry,userHome,env,cwd});
|
|
82
|
+
let porcelain, scope;
|
|
83
|
+
try {
|
|
84
|
+
scope = await resolveScope({dir:cwd,git:async (dir,args)=>{
|
|
85
|
+
if (args!==GIT_ALLOWED[2]) return git(dir,args);
|
|
86
|
+
try { porcelain = await git(dir,args); } catch { porcelain = null; }
|
|
87
|
+
// A missing list should not turn a confirmed Git worktree into a directory scope.
|
|
88
|
+
return porcelain ?? '';
|
|
89
|
+
}});
|
|
90
|
+
} catch (cause) {
|
|
91
|
+
error.write(`Error: ${String(cause.message ?? cause).replace(/[\r\n]+/g,' ')}\n`);
|
|
92
|
+
return 1;
|
|
93
|
+
}
|
|
94
|
+
if (io.signal?.aborted) return 0;
|
|
49
95
|
const choose = io.choosePlatforms ?? (await import('./menu.mjs')).chooseWatchPlatforms;
|
|
50
96
|
let platforms;
|
|
51
97
|
try {
|
|
52
|
-
|
|
98
|
+
if (scope.kind==='repo' && porcelain) {
|
|
99
|
+
const currentRoot = scope.roots[0];
|
|
100
|
+
let picker;
|
|
101
|
+
try {
|
|
102
|
+
const {worktrees,mainRoot} = selectableWorktrees(parseWorktreeList(porcelain));
|
|
103
|
+
if (worktrees.some(tree=>tree.root===currentRoot)) {
|
|
104
|
+
scope = scopeForWorktree(scope,worktrees,currentRoot,{home:userHome});
|
|
105
|
+
picker = {worktrees,mainRoot,...await probeWorktrees({worktrees,scope,homes,userHome,git,now,registry})};
|
|
106
|
+
}
|
|
107
|
+
} catch {
|
|
108
|
+
// A corrupt list or unreadable probe leaves the current worktree selected.
|
|
109
|
+
}
|
|
110
|
+
if (io.signal?.aborted) return 0;
|
|
111
|
+
if (picker) {
|
|
112
|
+
const {chooseWatchWorktree} = await import('./worktree-menu.mjs');
|
|
113
|
+
const root = await chooseWatchWorktree({input,output,env,signals:io.process,registry,currentRoot,home:userHome,...picker});
|
|
114
|
+
if (root===null) return 0;
|
|
115
|
+
scope = scopeForWorktree(scope,picker.worktrees,root,{home:userHome});
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
platforms = await choose({input,output,env,signals:io.process,registry});
|
|
53
119
|
} catch (cause) {
|
|
54
120
|
if (cause.code === 'ARC_CANCELLED') return 130;
|
|
55
121
|
throw cause;
|
|
56
122
|
}
|
|
57
123
|
if (platforms === null) return 0;
|
|
58
|
-
return followWatch(options,{...io,input,output,error,registry,platforms});
|
|
124
|
+
return followWatch(options,{...io,input,output,error,registry,platforms,scope,homes,homeErrors,git});
|
|
59
125
|
}
|
|
60
126
|
|
|
61
127
|
export async function followWatch(options, io = {}) {
|
|
@@ -64,12 +130,11 @@ export async function followWatch(options, io = {}) {
|
|
|
64
130
|
const output = io.output ?? process.stdout, error = io.error ?? process.stderr;
|
|
65
131
|
const cwd = io.cwd ?? process.cwd(), env = io.env ?? process.env;
|
|
66
132
|
const registry = io.registry ?? DEFAULT_PLATFORM_REGISTRY;
|
|
67
|
-
const userHome = io.userHome ?? os.homedir()
|
|
68
|
-
const homes =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
133
|
+
const userHome = io.userHome ?? os.homedir();
|
|
134
|
+
const {homes,homeErrors} = io.homes ? {homes:io.homes,homeErrors:io.homeErrors ?? {}}
|
|
135
|
+
: resolveWatchHomes({registry,userHome,env,cwd});
|
|
136
|
+
const disabled = Object.entries(homeErrors).filter(([platform])=>io.platforms.includes(platform))
|
|
137
|
+
.map(([platform,message])=>`${platform} disabled: ${message}`);
|
|
73
138
|
const platforms = io.platforms.filter(platform => homes[platform] !== null);
|
|
74
139
|
if (!platforms.length) { error.write('Error: no usable watch source.\n'); return 1; }
|
|
75
140
|
const now = io.now ?? Date.now, git = io.git ?? createGitRunner({env});
|
|
@@ -79,7 +144,7 @@ export async function followWatch(options, io = {}) {
|
|
|
79
144
|
const color = Boolean(output.isTTY && !options.json && !env.NO_COLOR);
|
|
80
145
|
const blockEnabled = Boolean(output.isTTY && !options.json);
|
|
81
146
|
const fancy = color && env.TERM !== 'dumb';
|
|
82
|
-
const label = watchLocationLabel({dir:cwd,home:userHome});
|
|
147
|
+
const label = io.scope?.display ?? watchLocationLabel({dir:cwd,home:userHome});
|
|
83
148
|
const keysEnabled = Boolean(input.isTTY && output.isTTY && !options.json && typeof input.setRawMode === 'function');
|
|
84
149
|
const frames = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
|
|
85
150
|
let drawnLines = 0, frame = 0, tick = 0;
|
|
@@ -90,10 +155,11 @@ export async function followWatch(options, io = {}) {
|
|
|
90
155
|
output.write(erase);
|
|
91
156
|
};
|
|
92
157
|
const resize = () => { width = options.width ?? (output.isTTY ? Math.max(L.ttyWidthMin, output.columns || L.ttyWidthMin) : L.nonTtyWidth); };
|
|
158
|
+
const blockWidth = () => Math.min(width, output.columns || width);
|
|
93
159
|
resize();
|
|
94
160
|
return new Promise(resolve => {
|
|
95
161
|
const signals = ['SIGINT','SIGTERM','SIGHUP'];
|
|
96
|
-
let rawModeEnabled = false;
|
|
162
|
+
let rawModeEnabled = false, startupComplete = false;
|
|
97
163
|
const stop = (code = 0, cause) => {
|
|
98
164
|
if (stopped) return;
|
|
99
165
|
stopped = true;
|
|
@@ -122,8 +188,7 @@ export async function followWatch(options, io = {}) {
|
|
|
122
188
|
const drawBlock = () => {
|
|
123
189
|
if (!stopped && blockEnabled) {
|
|
124
190
|
const busy = Boolean(watcher?.busy?.());
|
|
125
|
-
const
|
|
126
|
-
const lines = statusBlockLines({label,busy,glyph:frames[frame],tick,color,fancy,width:blockWidth});
|
|
191
|
+
const lines = statusBlockLines({label,busy,glyph:frames[frame],tick,color,fancy,width:blockWidth()});
|
|
127
192
|
if (busy) frame = (frame + 1) % frames.length;
|
|
128
193
|
drawnLines = lines.length;
|
|
129
194
|
output.write(lines.join('\n'));
|
|
@@ -133,20 +198,30 @@ export async function followWatch(options, io = {}) {
|
|
|
133
198
|
for (const byte of Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)) {
|
|
134
199
|
if (stopped) break;
|
|
135
200
|
if (byte === 0x03) stop();
|
|
136
|
-
else if (byte ===
|
|
201
|
+
else if (byte === 0x08 && startupComplete) {
|
|
202
|
+
const {events,remaining} = watcher.earlier(L.earlierPage);
|
|
203
|
+
const {start,end} = earlierPageLines({shown:events.length,remaining});
|
|
204
|
+
const separator = line => {
|
|
205
|
+
const clipped = line.slice(0, Math.max(0, blockWidth() - 1));
|
|
206
|
+
return color ? `\x1b[2m${clipped}\x1b[0m` : clipped;
|
|
207
|
+
};
|
|
208
|
+
write(events,[separator(start)],end === undefined ? undefined : separator(end));
|
|
209
|
+
} else if (byte === 0x0c) {
|
|
137
210
|
output.write('\x1b[H\x1b[2J\x1b[3J');
|
|
138
211
|
drawnLines = 0;
|
|
139
212
|
drawBlock();
|
|
140
213
|
}
|
|
141
214
|
}
|
|
142
215
|
};
|
|
143
|
-
const write = events => {
|
|
216
|
+
const write = (events, leadingLines, trailingLine) => {
|
|
144
217
|
if (stopped) return;
|
|
145
218
|
eraseBlock();
|
|
219
|
+
if (leadingLines?.length) output.write(leadingLines.join('\n') + '\n');
|
|
146
220
|
for (const event of events) {
|
|
147
221
|
if (stopped) break;
|
|
148
222
|
output.write((options.json ? renderJson(event) : renderHuman(event,{width,color,verbose:options.verbose,wrap})) + '\n');
|
|
149
223
|
}
|
|
224
|
+
if (!stopped && trailingLine !== undefined) output.write(trailingLine + '\n');
|
|
150
225
|
drawBlock();
|
|
151
226
|
};
|
|
152
227
|
for (const signal of signals) proc.on(signal, onSignal);
|
|
@@ -161,14 +236,24 @@ export async function followWatch(options, io = {}) {
|
|
|
161
236
|
input.resume();
|
|
162
237
|
input.on('data', onKey);
|
|
163
238
|
}
|
|
164
|
-
const scope = await resolveScope({dir:cwd,git});
|
|
239
|
+
const scope = io.scope ?? await resolveScope({dir:cwd,git});
|
|
165
240
|
if (stopped) return;
|
|
166
|
-
watcher = createWatcher({options:{...options,platforms},homes:{...homes,user:userHome},scope,git,now,registry});
|
|
241
|
+
watcher = createWatcher({options:{...options,platforms,earlier:keysEnabled},homes:{...homes,user:userHome},scope,git,now,registry});
|
|
242
|
+
const disabledEvents = [];
|
|
167
243
|
for (const text of disabled) {
|
|
168
244
|
const ts = new Date(now()).toISOString();
|
|
169
|
-
|
|
245
|
+
const event = {v:1,ts,observedAt:ts,source:'watch',kind:'notice',label:'watch',text};
|
|
246
|
+
if (blockEnabled) disabledEvents.push(event);
|
|
247
|
+
else write([event]);
|
|
170
248
|
}
|
|
171
|
-
|
|
249
|
+
const startup = await watcher.start();
|
|
250
|
+
if (blockEnabled) {
|
|
251
|
+
const [header, ...events] = startup;
|
|
252
|
+
const keys = keysEnabled ? ['Ctrl-C stop','Ctrl-H earlier','Ctrl-L clear'] : ['Ctrl-C stop'];
|
|
253
|
+
const lines = renderBrief(header.brief, {version:packageVersion,keys,width:blockWidth(),color});
|
|
254
|
+
write([...disabledEvents,...events.filter(event => event.startup !== 'live')], lines);
|
|
255
|
+
} else write(startup);
|
|
256
|
+
startupComplete = true;
|
|
172
257
|
if (stopped) return;
|
|
173
258
|
nextPollAt = now() + L.filePollMs;
|
|
174
259
|
timer = schedule(() => {
|
package/lib/watch/markdown.mjs
CHANGED
|
@@ -2,15 +2,17 @@ import {displayWidth, wrapLineRanges} from './text-width.mjs';
|
|
|
2
2
|
|
|
3
3
|
const reset = '\x1b[0m';
|
|
4
4
|
const inline = /(?<!`)`(?<code>[^`]+)`(?!`)|\[(?<label>[^\[\]]+)\]\((?<url>[^\s()]+)\)|(?<delimiter>(?<!\*)\*\*|(?<![\p{L}\p{N}_*])\*)(?![\s*])(?<emphasis>[^*]*?)(?<!\s)\k<delimiter>(?!\*)/gu;
|
|
5
|
+
const boxInline = new RegExp(/\\(?<escaped>[\\*`\[])/.source + '|' + inline.source, inline.flags);
|
|
5
6
|
const fenceMarker = /^ *(`{3,}|~{3,})(.*)$/;
|
|
6
7
|
const pipeStart = /^ *\|/;
|
|
7
8
|
|
|
8
|
-
function inlineSpans(text) {
|
|
9
|
+
function inlineSpans(text, pattern = inline) {
|
|
9
10
|
const spans = [];
|
|
10
11
|
let start = 0;
|
|
11
|
-
for (const {index, 0:token, groups:{code, label, url, delimiter, emphasis}} of text.matchAll(
|
|
12
|
+
for (const {index, 0:token, groups:{code, label, url, delimiter, emphasis, escaped}} of text.matchAll(pattern)) {
|
|
12
13
|
if (index > start) spans.push({text:text.slice(start, index)});
|
|
13
|
-
if (
|
|
14
|
+
if (escaped !== undefined) spans.push({text:escaped});
|
|
15
|
+
else if (code !== undefined) spans.push({text:code, style:'38;5;180'});
|
|
14
16
|
else if (label !== undefined) spans.push({text:`${label} (${url})`});
|
|
15
17
|
else spans.push({text:emphasis, style:delimiter === '**' ? '1' : '3'});
|
|
16
18
|
start = index + token.length;
|
|
@@ -34,15 +36,17 @@ function renderLine(spans, {width, baseCode, blockStyle, prefix = '', preserveWh
|
|
|
34
36
|
return ranges.map(({from, to, overflows}, index) => {
|
|
35
37
|
let line = index ? ' '.repeat(prefix.length) : prefix;
|
|
36
38
|
let active = blockCode;
|
|
37
|
-
if (line) line = `\x1b[${active}m${line}`;
|
|
38
|
-
if (overflows) return `${line || `\x1b[${active}m`}�${reset}
|
|
39
|
+
if (line && baseCode) line = `\x1b[${active}m${line}`;
|
|
40
|
+
if (overflows) return baseCode ? `${line || `\x1b[${active}m`}�${reset}` : `${line}�`;
|
|
39
41
|
while (from < to && spanIndex < spans.length) {
|
|
40
42
|
const span = spans[spanIndex];
|
|
41
43
|
const spanEnd = spanStart + span.text.length;
|
|
42
44
|
if (spanEnd > from) {
|
|
43
45
|
const code = span.style ? `${blockCode};${span.style}` : blockCode;
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
+
if (baseCode) {
|
|
47
|
+
if (!line) line = `\x1b[${code}m`;
|
|
48
|
+
else if (active !== code) line += `\x1b[0;${code}m`;
|
|
49
|
+
}
|
|
46
50
|
line += span.text.slice(Math.max(from - spanStart, 0), to - spanStart);
|
|
47
51
|
active = code;
|
|
48
52
|
}
|
|
@@ -50,10 +54,39 @@ function renderLine(spans, {width, baseCode, blockStyle, prefix = '', preserveWh
|
|
|
50
54
|
spanStart = spanEnd;
|
|
51
55
|
spanIndex++;
|
|
52
56
|
}
|
|
53
|
-
return line ? `${line}${reset}` :
|
|
57
|
+
return line && baseCode ? `${line}${reset}` : line;
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
60
|
|
|
61
|
+
export function renderBox(lines, {width, baseCode}) {
|
|
62
|
+
if (width < 5) return [];
|
|
63
|
+
const rows = lines.map(line => {
|
|
64
|
+
const prefix = /^\*\*([^*]+)\*\* /.exec(line);
|
|
65
|
+
return prefix
|
|
66
|
+
? {label:prefix[1], spans:inlineSpans(line.slice(prefix[0].length), boxInline)}
|
|
67
|
+
: {label:'', spans:inlineSpans(line, boxInline)};
|
|
68
|
+
});
|
|
69
|
+
const labelWidth = Math.max(0, ...rows.map(row => displayWidth(row.label)));
|
|
70
|
+
const natural = Math.max(1, ...rows.map(({label,spans}) =>
|
|
71
|
+
(label ? labelWidth + 2 : 0) + displayWidth(spans.map(span => span.text).join(''))));
|
|
72
|
+
const contentWidth = Math.min(natural, width - 4);
|
|
73
|
+
const paint = (text, code) => code ? `\x1b[${code}m${text}${reset}` : text;
|
|
74
|
+
const border = (left, right) => paint(left + '─'.repeat(contentWidth + 2) + right, baseCode);
|
|
75
|
+
const body = rows.flatMap(({label,spans}) => {
|
|
76
|
+
const alignLabel = label && contentWidth - labelWidth - 2 >= 2;
|
|
77
|
+
const prefixWidth = alignLabel ? labelWidth + 2 : 0;
|
|
78
|
+
const value = !alignLabel && label ? [{text:label,style:'1'},{text:' '},...spans] : spans;
|
|
79
|
+
return renderLine(value, {width:contentWidth - prefixWidth, baseCode:baseCode && '0'}).map((line, index) => {
|
|
80
|
+
const prefix = alignLabel && !index
|
|
81
|
+
? paint(label, baseCode && '1') + ' '.repeat(prefixWidth - displayWidth(label))
|
|
82
|
+
: ' '.repeat(prefixWidth);
|
|
83
|
+
const pad = contentWidth - prefixWidth - displayWidth(line.replace(/\x1b\[[0-9;]*m/g, ''));
|
|
84
|
+
return `${paint('│',baseCode)} ${prefix}${line}${' '.repeat(pad + 1)}${paint('│',baseCode)}`;
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
return [border('┌', '┐'), ...body, border('└', '┘')];
|
|
88
|
+
}
|
|
89
|
+
|
|
57
90
|
function splitTableRow(line) {
|
|
58
91
|
if (!line?.includes('|')) return;
|
|
59
92
|
const row = line.trim();
|
|
@@ -140,7 +173,7 @@ function renderCards([header, ...rows], {width, baseCode}) {
|
|
|
140
173
|
|
|
141
174
|
function renderTable({header, rows, alignments}, options) {
|
|
142
175
|
const {baseCode, width} = options;
|
|
143
|
-
const cells = [header, ...rows].map(row => row.map(inlineSpans));
|
|
176
|
+
const cells = [header, ...rows].map(row => row.map(cell => inlineSpans(cell)));
|
|
144
177
|
const natural = header.map(() => 1);
|
|
145
178
|
for (const row of cells) {
|
|
146
179
|
for (const [col, spans] of row.entries()) {
|
package/lib/watch/menu.mjs
CHANGED
|
@@ -2,37 +2,48 @@ import {createTuiInterface} from '../tui/interface.mjs';
|
|
|
2
2
|
import {createTerminalSession} from '../tui/terminal.mjs';
|
|
3
3
|
|
|
4
4
|
export function watchMenuRows(registry) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
return {label:label+' (not supported)',platforms:null};
|
|
9
|
-
}
|
|
10
|
-
all.platforms.push(id);
|
|
11
|
-
return {label,platforms:[id]};
|
|
12
|
-
});
|
|
13
|
-
return [all,...rows];
|
|
5
|
+
return registry.byDisplayOrder().map(({id,label,capabilities}) => ({
|
|
6
|
+
id,label,supported:capabilities.watch.state === 'verified',
|
|
7
|
+
}));
|
|
14
8
|
}
|
|
15
9
|
|
|
16
10
|
export async function chooseWatchPlatforms({input,output,env,signals,registry,createSession=createTerminalSession}) {
|
|
17
11
|
const rows = watchMenuRows(registry);
|
|
18
|
-
const
|
|
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'];
|
|
19
15
|
const session = createSession({input,output,env,signals});
|
|
20
16
|
try {
|
|
21
17
|
const ui = createTuiInterface(session,{input});
|
|
22
|
-
let selected =
|
|
18
|
+
let selected = watchIndex, notice = [];
|
|
23
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');
|
|
24
25
|
const previous = selected;
|
|
25
|
-
selected = await ui.menu('Which
|
|
26
|
-
selected,backRow:true,backLabel:'exit',
|
|
26
|
+
selected = await ui.menu('Which platforms to watch?',labels,{
|
|
27
|
+
selected,backRow:true,backLabel:'exit',hint:'checklist',actionKinds,
|
|
27
28
|
notice:({selected:current})=>{
|
|
28
29
|
if (current !== previous) notice = [];
|
|
29
30
|
return notice;
|
|
30
31
|
},
|
|
31
32
|
});
|
|
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
|
+
}
|
|
33
39
|
const row = rows[selected];
|
|
34
|
-
if (row.
|
|
35
|
-
|
|
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 = [];
|
|
36
47
|
}
|
|
37
48
|
} catch (error) {
|
|
38
49
|
if (error.code === 'ARC_TUI_EOF') return null;
|
package/lib/watch/model.mjs
CHANGED
|
@@ -15,6 +15,7 @@ export const WATCH_LIMITS = Object.freeze({
|
|
|
15
15
|
claudeCwdWaitMs:10000, codexMetaBytes:4194304, lookbackDays:7,
|
|
16
16
|
cwdProbeBytes:65536, maxKnown:512,
|
|
17
17
|
jsonTextMax:1000, wrapMinBody:20, toolCacheMax:512, defaultTail:20,
|
|
18
|
+
earlierPage:20, earlierMax:2000, worktreePickerMax:20,
|
|
18
19
|
maxTail:1000, widthMin:40, widthMax:2000, ttyWidthMin:60, nonTtyWidth:200,
|
|
19
20
|
gitTimeoutMs:10000, spinnerIdleMs:300000,
|
|
20
21
|
shellScanDelayMs:1000, shellScanMinIntervalMs:3000, shellScansPerTick:2,
|
package/lib/watch/render.mjs
CHANGED
|
@@ -94,12 +94,13 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
94
94
|
|
|
95
95
|
const paths = fullLine && !message ? (event.paths ?? []).map(file => sanitizeText(displayPath(file,event.root))).filter(Boolean) : [];
|
|
96
96
|
const listPaths = paths.length >= 2;
|
|
97
|
+
const pathLines = listPaths ? paths.map(file => '• ' + file) : paths;
|
|
97
98
|
const bodyLines = message ? (text ? text.split('\n') : []) : fullLine
|
|
98
|
-
? [sanitizeText(event.text), ...
|
|
99
|
+
? [sanitizeText(event.text), ...pathLines].filter(Boolean) : [];
|
|
99
100
|
if (roleName && bodyLines.length) bodyLines.unshift(roleName);
|
|
100
101
|
const lines = canWrap ? bodyLines.flatMap((line,i) =>
|
|
101
102
|
listPaths && paths.length && i >= bodyLines.length - paths.length
|
|
102
|
-
? wrapLine(line.slice(2),avail-2).map((piece,j) => (j ? ' ' : '
|
|
103
|
+
? wrapLine(line.slice(2),avail-2).map((piece,j) => (j ? ' ' : '• ') + piece)
|
|
103
104
|
: wrapLine(line,avail)) : bodyLines;
|
|
104
105
|
const bodyText = paintLine => lines.map((line,i) => !line ? '' : (i ? indent : '') + paintLine(line,i)).join('\n');
|
|
105
106
|
const plain = fullLine ? (message && !lines.length ? prefix.trimEnd() : prefix + bodyText(line => line)) : clipCodePoints(prefix + text, width).text;
|