@yunhozz/arc 0.5.0 → 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.
Files changed (57) hide show
  1. package/MANIFEST.sha256 +45 -51
  2. package/README.md +99 -33
  3. package/claude/agents/arc-implementer.md +1 -1
  4. package/claude/skill/SKILL.md +1 -1
  5. package/claude/skill/models.toml +6 -6
  6. package/claude/skill/references/coordination.md +0 -4
  7. package/claude/skill/references/handoff-prep.md +1 -1
  8. package/claude/skill/references/verification.md +4 -9
  9. package/codex/skill/SKILL.md +1 -1
  10. package/codex/skill/models.toml +6 -6
  11. package/codex/skill/references/coordination.md +0 -4
  12. package/codex/skill/references/handoff-prep.md +1 -1
  13. package/codex/skill/references/verification.md +4 -9
  14. package/gemini/agents/arc-implementer.md +2 -2
  15. package/gemini/agents/arc-planner.md +1 -1
  16. package/gemini/agents/arc-qa.md +1 -1
  17. package/gemini/agents/arc-scouter.md +1 -1
  18. package/gemini/skill/SKILL.md +1 -1
  19. package/gemini/skill/models.toml +5 -5
  20. package/gemini/skill/references/coordination.md +0 -4
  21. package/gemini/skill/references/handoff-prep.md +1 -1
  22. package/gemini/skill/references/verification.md +4 -9
  23. package/grok/agents/arc-implementer.md +1 -1
  24. package/grok/skill/SKILL.md +1 -1
  25. package/grok/skill/references/coordination.md +0 -4
  26. package/grok/skill/references/handoff-prep.md +1 -1
  27. package/grok/skill/references/verification.md +4 -9
  28. package/lib/installer/runtime-assets.mjs +1 -5
  29. package/lib/installer/targets.mjs +3 -1
  30. package/lib/management/operations.mjs +4 -4
  31. package/lib/prompts/agent-fragments.json +3 -3
  32. package/lib/runtime/local-cli.mjs +9 -2
  33. package/lib/runtime/role-dispatch-policy.mjs +5 -2
  34. package/lib/tui/app.mjs +36 -11
  35. package/lib/tui/interface.mjs +2 -2
  36. package/lib/tui/render.mjs +4 -2
  37. package/lib/tui/terminal.mjs +5 -3
  38. package/lib/watch/brief.mjs +44 -0
  39. package/lib/watch/dispatch.mjs +44 -6
  40. package/lib/watch/index.mjs +107 -22
  41. package/lib/watch/markdown.mjs +42 -9
  42. package/lib/watch/model.mjs +1 -0
  43. package/lib/watch/render.mjs +3 -2
  44. package/lib/watch/scope.mjs +125 -0
  45. package/lib/watch/watcher.mjs +149 -82
  46. package/lib/watch/worktree-menu.mjs +64 -0
  47. package/package.json +1 -1
  48. package/shared/skill/runtime/local-cli.mjs +9 -2
  49. package/shared/skill/runtime/role-dispatch-policy.mjs +5 -2
  50. package/lib/runtime/final-verify.mjs +0 -2158
  51. package/lib/runtime/node-test-reporter.mjs +0 -81
  52. package/lib/runtime/test-results.mjs +0 -736
  53. package/lib/runtime/verify-cli.mjs +0 -60
  54. package/shared/skill/runtime/final-verify.mjs +0 -2158
  55. package/shared/skill/runtime/node-test-reporter.mjs +0 -81
  56. package/shared/skill/runtime/test-results.mjs +0 -736
  57. package/shared/skill/runtime/verify-cli.mjs +0 -60
@@ -13,6 +13,7 @@ import {createDispatchIndex} from './dispatch.mjs';
13
13
  import {resolveDispatchStore} from './anchor-store.mjs';
14
14
  import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
15
15
  import {GIT_ALLOWED} from './git.mjs';
16
+ import {watchLocationLabel} from './status-line.mjs';
16
17
 
17
18
  /** Read-only, timer-free merger. The caller owns scheduling and output. */
18
19
  export function createWatcher({options, homes, scope: initialScope, git, now, registry = DEFAULT_PLATFORM_REGISTRY, dependencies = {}}) {
@@ -20,8 +21,10 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
20
21
  lstat = fsp.lstat, maxKnown = L.maxKnown, createClaudeDiscovery: claudeDiscovery = createClaudeDiscovery, createDispatchIndex: dispatchIndex = createDispatchIndex} = dependencies;
21
22
  const platforms = options.platforms ?? registry.byDisplayOrder().filter(d => d.capabilities.watch.state==='verified').map(d => d.id);
22
23
  const verbose = Boolean(options.verbose);
24
+ const probe = Boolean(options.probe);
23
25
  const tailCount = options.tail ?? L.defaultTail;
24
26
  let scope = initialScope, closed = false, started = false;
27
+ let earlierBacklog;
25
28
  let lastDiscovery = -Infinity, lastRefresh = now(), capped = false;
26
29
  const followed = new Map(), pending = new Map(), ignored = new Map(), detached = new Map();
27
30
  const seenAtStart = new Map(), heads = new Map(), metas = new Map(), agentMetas = new Map(), childLists = new Map();
@@ -32,7 +35,62 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
32
35
  let lastNestedRefresh = -Infinity;
33
36
  let shellCursor = 0;
34
37
  let dispatch;
35
- const claude = homes.claude ? claudeDiscovery({claudeHome:homes.claude}) : null;
38
+ let claude;
39
+ const TRANSCRIPT_HANDLERS = new Map([
40
+ ['codex', {
41
+ lineCwd:codexLineCwd,createState:createCodexState,
42
+ normalize:(line,state,home)=>normalizeCodexLine(line,state,{codexHome:home,userHome:homes.user}),
43
+ shouldHold:origin=>origin==='codex_exec',
44
+ async discover({platform,home,startup,out,rows}) {
45
+ for (const item of await codexCandidates(platform,home,startup)) {
46
+ if (item.platform != null && item.platform!==platform) continue;
47
+ rememberStart({...item,platform},startup);
48
+ if (item.compressed) {
49
+ if (!compressed.has(item.file)) debug(out,`compressed session skipped: ${path.basename(item.file)}`);
50
+ compressed.add(item.file); continue;
51
+ }
52
+ if ([...followed.values()].some(row=>row.file===item.file)) continue;
53
+ if (skipHead(item,startup)) continue;
54
+ const meta=await cachedHead(metas,item,codexMeta);
55
+ if (!meta) continue;
56
+ const row={...item,id:meta.threadId,platform,origin:meta.originator,cwd:meta.cwd,version:meta.cliVersion,parentId:meta.parentId,depth:meta.depth,agent:{agentRole:meta.agentRole,nickname:meta.agentNickname}};
57
+ rememberKnown(row);rows.push(row);
58
+ }
59
+ },
60
+ }],
61
+ ['claude', {
62
+ lineCwd:claudeLineCwd,createState:createClaudeState,normalize:normalizeClaudeLine,
63
+ shouldHold:()=>true,
64
+ async discover({platform,home,startup,rows}) {
65
+ claude ??= claudeDiscovery({claudeHome:home});
66
+ const prefixes=startup || dispatch.list().some(ref=>ref.inScope) ? null : claudeDirPrefixes(scope);
67
+ const mains=await claude.scan({prefixes,now:now(),startup:false});
68
+ for (const item of mains) {
69
+ if (item.platform != null && item.platform!==platform) continue;
70
+ rememberStart(item,startup);
71
+ const children=await childrenFor(item,startup);
72
+ for (const child of children) rememberStart(child,startup);
73
+ if (skipHead(item,startup)) continue;
74
+ const head=await cachedHead(heads,item,claudeHead);
75
+ if (!head) {
76
+ const wait=pending.get(item.file) ?? {...item,until:now()+L.claudeCwdWaitMs,cwdWaiting:true};
77
+ if (now()<wait.until) pending.set(item.file,wait); else {pending.delete(item.file);ignored.set(item.file,item.size);}
78
+ continue;
79
+ }
80
+ pending.delete(item.file);
81
+ const main={...item,id:head.sessionId,platform,origin:head.entrypoint,cwd:head.cwd,version:head.version};
82
+ rememberKnown(main);
83
+ if (!followed.has(main.id)) rows.push(main);
84
+ for (const child of children) {
85
+ if (skipHead(child,startup)) continue;
86
+ const childHead=await cachedHead(heads,child,claudeHead);
87
+ const row={...child,id:`agent-${child.agentId}`,platform,origin:head.entrypoint,cwd:childHead?.cwd??head.cwd,version:childHead?.version??head.version,parentId:main.id,agent:{agentType:child.meta?.agentType}};
88
+ rememberKnown(row);rows.push(row);
89
+ }
90
+ }
91
+ },
92
+ }],
93
+ ]);
36
94
  const stamp = () => new Date(now()).toISOString();
37
95
  const notice = text => ({v:1,ts:stamp(),observedAt:stamp(),source:'watch',label:'watch',kind:'notice',text});
38
96
  const debug = (out, text) => { if (verbose) out.push(notice(text)); };
@@ -53,13 +111,20 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
53
111
  const ref = dispatch.bySession(row.id);
54
112
  return ref && ref.inScope && (ref.cwd ? inScope(scope,ref.cwd) : cwdInScope(row.cwd)) ? ref : null;
55
113
  }
114
+ const followedDispatchRow = ref => [...followed.values()].find(row=>ref.sessionIds.includes(row.id) && mapped(row)===ref);
115
+ function dispatchPlatforms(ref, followedRow) {
116
+ const target = ref.targetPlatform ?? followedRow?.platform
117
+ ?? (ref.route==='native' ? ref.hostPlatform : undefined) ?? ref.childPlatform;
118
+ const display = homes[target]!=null && TRANSCRIPT_HANDLERS.has(target) ? target : ref.hostPlatform;
119
+ return {display,visible:display ? platforms.includes(display) : platforms.length>=2};
120
+ }
56
121
  const selectedRoot = cwd => path.resolve(cwd)===scope.roots[0] || realPath(cwd)===scope.roots[0];
57
122
  function cwdInScope(cwd) {
58
123
  if (!cwd || !inScope(scope,cwd)) return false;
59
- return scope.kind!=='repo' || selectedRoot(cwd) || nestedChecks.get(cwd)?.inside===true;
124
+ return probe || scope.kind!=='repo' || selectedRoot(cwd) || nestedChecks.get(cwd)?.inside===true;
60
125
  }
61
126
  async function verifyCwd(cwd, out) {
62
- if (scope.kind!=='repo' || !cwd || !inScope(scope,cwd) || selectedRoot(cwd) || nestedChecks.has(cwd)) return;
127
+ if (probe || scope.kind!=='repo' || !cwd || !inScope(scope,cwd) || selectedRoot(cwd) || nestedChecks.has(cwd)) return;
63
128
  if (now()-(nestedFailures.get(cwd)??-Infinity)<L.discoveryMs) return;
64
129
  let result;
65
130
  try { result=(await git(cwd,GIT_ALLOWED[0]))?.trim(); }
@@ -110,7 +175,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
110
175
  async function ensureShellRoot(row, out) {
111
176
  if (row.gitTop && !shellRoots.has(row.gitTop) && shellRoots.size < L.maxRepos) {
112
177
  const state = {snapshot:null,pending:false,pendingSince:undefined,lastTriggerAt:-Infinity,
113
- lastScanAt:-Infinity,prevScanAt:-Infinity,claims:new Map(),candidates:new Map(),failures:0,off:false};
178
+ lastScanAt:-Infinity,claims:new Map(),candidates:new Map(),failures:0,off:false};
114
179
  shellRoots.set(row.gitTop,state);
115
180
  await scanRoot(row.gitTop,state,out);
116
181
  }
@@ -141,10 +206,11 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
141
206
  ...(ref ? ['dispatch',ref.dispatchId,ref.workflowId] : [])].filter(Boolean).join(' ');
142
207
  }
143
208
  async function normalize(row, lines, live = false, out = []) {
209
+ const handler=TRANSCRIPT_HANDLERS.get(row.platform);
144
210
  const events = [];
145
211
  let sawInScope=false, firstSession;
146
212
  for (const line of lines) {
147
- const cwd=row.platform==='codex'?codexLineCwd(line):claudeLineCwd(line);
213
+ const cwd=handler.lineCwd(line);
148
214
  if (cwd) await setCwd(row,cwd,out);
149
215
  await verifyCwd(row.cwd,out);
150
216
  if (row.gitTop===undefined && gitTopByCwd.has(row.cwd)) {
@@ -155,10 +221,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
155
221
  if (entering) events.push(clean({...identity(row),ts:line.timestamp??stamp(),kind:'session',text:sessionText(row)}));
156
222
  if (row.inScopeNow===true && !inside) debug(out,`session ${row.id.slice(0,8)} left scope: cwd=${row.cwd}`);
157
223
  row.inScopeNow=inside;
158
- row.codexState.cwd=row.cwd;
159
- const normalized = row.platform === 'codex'
160
- ? normalizeCodexLine(line,row.codexState,{codexHome:homes.codex,userHome:homes.user})
161
- : normalizeClaudeLine(line,row.state);
224
+ const normalized=handler.normalize(line,row.state,homes[row.platform]);
162
225
  if (inside) {
163
226
  await ensureShellRoot(row,out); sawInScope=true;
164
227
  const shell=shellRoots.get(row.gitTop);
@@ -201,16 +264,21 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
201
264
  async function scanDispatch() {
202
265
  return dispatch.scan({gitCommonDirs:scope.gitCommonDir ? [scope.gitCommonDir] : []});
203
266
  }
204
- function dispatchEvents(updates, startup, out) {
267
+ function dispatchEvents(updates, startup, out, skipped) {
205
268
  for (const {ref,first} of updates) {
206
269
  if (!dispatchInScope(ref)) continue;
207
- if (startup && (tailCount === 0 || now()-Date.parse(ref.updatedAt) > L.historyWindowMs || !Number.isFinite(Date.parse(ref.updatedAt)))) continue;
208
- const followedRow = [...followed.values()].find(row=>ref.sessionIds.includes(row.id));
209
- const platform = ref.childPlatform ?? followedRow?.platform;
210
- if (platform ? !platforms.includes(platform) : platforms.length < 2) continue;
270
+ const hidden = startup && (tailCount === 0 || now()-Date.parse(ref.updatedAt) > L.historyWindowMs || !Number.isFinite(Date.parse(ref.updatedAt)));
271
+ if (hidden && !skipped) continue;
272
+ const followedRow = followedDispatchRow(ref);
273
+ const {display,visible} = dispatchPlatforms(ref,followedRow);
274
+ if (!visible) continue;
211
275
  const e = {v:1,ts:ref.updatedAt ?? stamp(),observedAt:stamp(),source:'dispatch',label:dispatchLabel(ref.rawRole,ref.dispatchId),kind:'dispatch',dispatchId:ref.dispatchId};
212
276
  for (const key of ['workflowId','role','state','reasons','route','hostPlatform']) if (ref[key] !== undefined && ref[key] !== null) e[key]=ref[key];
213
- if (platform) e.platform=platform;
277
+ if (display) e.platform=display;
278
+ if (hidden) {
279
+ skipped.push(e);
280
+ continue;
281
+ }
214
282
  out.push(clean(e));
215
283
  if (first && !followedRow && !missingDispatch.has(ref.dispatchId)) {
216
284
  debug(out,`transcript not found for dispatch ${ref.dispatchId}`); missingDispatch.add(ref.dispatchId);
@@ -224,22 +292,28 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
224
292
  if (chain.desktop) {ignored.set(row.file,row.size);return false;}
225
293
  return chain.resolved && anyCwdInScope(row);
226
294
  }
295
+ if (probe) return anyCwdInScope(row);
227
296
  const ref = mapped(row);
228
297
  return Boolean(ref) || anyCwdInScope(row);
229
298
  }
230
- async function attach(row, startup, out) {
299
+ async function attach(row, startup, out, skipped) {
300
+ if (probe) {
301
+ followed.set(row.id,row);
302
+ return;
303
+ }
231
304
  const previous = detached.get(row.file) ?? (!startup && !pending.has(row.file) ? seenAtStart.get(row.file) : undefined);
232
305
  let history;
233
306
  try { history = previous ? {endOffset:previous.offset} : await readTail(row.file); }
234
307
  catch (error) { debug(out,`session file unreadable: ${row.id.slice(0,8)} (${error.code ?? 'error'})`); ignored.set(row.file,row.size); return; }
235
308
  row.headCwd=row.cwd;
236
309
  row.tail=createTail(row.file,{offset:previous?.offset ?? history.endOffset});
237
- row.state=createClaudeState(); row.codexState=createCodexState(); row.active=false; row.held=[]; row.lastActivity=row.mtimeMs;
310
+ const handler=TRANSCRIPT_HANDLERS.get(row.platform);
311
+ row.state=handler.createState(); row.active=false; row.held=[]; row.lastActivity=row.mtimeMs;
238
312
  row.cwd=undefined;
239
313
  await setCwd(row,previous?.cwd??row.headCwd,out);
240
314
  await verifyCwd(row.cwd,out);
241
315
  followed.set(row.id,row); pending.delete(row.file); detached.delete(row.file);
242
- if (!startup && !previous && !row.parentId && !mapped(row) && (row.origin==='codex_exec'||row.platform==='claude') && now()-row.mtimeMs<=L.holdCreatedWithinMs) row.holdUntil=now()+L.holdMs;
316
+ if (!startup && !previous && !row.parentId && !mapped(row) && handler.shouldHold(row.origin) && now()-row.mtimeMs<=L.holdCreatedWithinMs) row.holdUntil=now()+L.holdMs;
243
317
  const showHistory = startup ? tailCount > 0 && now()-row.mtimeMs<=L.historyWindowMs : !previous;
244
318
  const {events,firstSession}=await normalize(row,history.lines??[],false,out);
245
319
  if (showHistory) {
@@ -249,7 +323,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
249
323
  if (initialSession) events.unshift(initialSession);
250
324
  }
251
325
  emit(row,events,out);
252
- }
326
+ } else if (startup && skipped) skipped.push(...events);
253
327
  if (row.inScopeNow===undefined) row.inScopeNow=lineGate(row);
254
328
  if (lineGate(row)) await ensureShellRoot(row,out);
255
329
  if (seenAtStart.has(row.file)) seenAtStart.get(row.file).cwd=row.cwd;
@@ -333,11 +407,11 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
333
407
  && seenAtStart.get(item.file)?.size === item.size && !pending.has(item.file)
334
408
  && ![...followed.values()].some(row=>row.file===item.file));
335
409
  }
336
- async function codexCandidates(startup) {
410
+ async function codexCandidates(platform, home, startup) {
337
411
  if (!startup) {
338
- const files = new Map((await listCodexRollouts({codexHome:homes.codex,now:now(),startup:false})).map(item=>[item.file,item]));
412
+ const files = new Map((await listCodexRollouts({codexHome:home,now:now(),startup:false})).map(item=>[item.file,item]));
339
413
  for (const [file,item] of new Map([...seenAtStart,...detached])) {
340
- if (item.platform !== 'codex' || files.has(file) || [...followed.values()].some(row=>row.file===file)) continue;
414
+ if (item.platform!==platform || files.has(file) || [...followed.values()].some(row=>row.file===file)) continue;
341
415
  const stat = await details(file);
342
416
  if (stat) files.set(file,{...item,...stat,file});
343
417
  }
@@ -348,54 +422,17 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
348
422
  for (let back=0;back<=L.lookbackDays;back+=2) {
349
423
  const date = new Date(now());
350
424
  date.setDate(date.getDate()-back);
351
- for (const item of await listCodexRollouts({codexHome:homes.codex,now:date.getTime(),startup:false})) files.set(item.file,item);
425
+ for (const item of await listCodexRollouts({codexHome:home,now:date.getTime(),startup:false})) files.set(item.file,item);
352
426
  }
353
427
  return [...files.values()];
354
428
  }
355
- async function discover(startup, out) {
429
+ async function discover(startup, out, skipped) {
356
430
  const rows=[];
357
- const updates = await scanDispatch();
431
+ const updates = probe ? [] : await scanDispatch();
358
432
  for (const file of pending.keys()) if (!await details(file)) pending.delete(file);
359
- if (homes.codex && platforms.includes('codex')) {
360
- for (const item of await codexCandidates(startup)) {
361
- rememberStart({...item,platform:'codex'},startup);
362
- if (item.compressed) {
363
- if (!compressed.has(item.file)) debug(out,`compressed session skipped: ${path.basename(item.file)}`);
364
- compressed.add(item.file); continue;
365
- }
366
- if ([...followed.values()].some(r=>r.file===item.file)) continue;
367
- if (skipHead(item,startup)) continue;
368
- const meta=await cachedHead(metas,item,codexMeta);
369
- if (!meta) continue;
370
- const row={...item,id:meta.threadId,platform:'codex',origin:meta.originator,cwd:meta.cwd,version:meta.cliVersion,parentId:meta.parentId,depth:meta.depth,agent:{agentRole:meta.agentRole,nickname:meta.agentNickname}};
371
- rememberKnown(row);rows.push(row);
372
- }
373
- }
374
- if (claude && platforms.includes('claude')) {
375
- const prefixes=dispatch.list().some(ref=>ref.inScope)?null:claudeDirPrefixes(scope);
376
- const mains=await claude.scan({prefixes:startup?null:prefixes,now:now(),startup:false});
377
- for (const item of mains) {
378
- rememberStart(item,startup);
379
- const children=await childrenFor(item,startup);
380
- for (const child of children) rememberStart(child,startup);
381
- if (skipHead(item,startup)) continue;
382
- const head=await cachedHead(heads,item,claudeHead);
383
- if (!head) {
384
- const wait=pending.get(item.file) ?? {...item,until:now()+L.claudeCwdWaitMs,cwdWaiting:true};
385
- if (now()<wait.until) pending.set(item.file,wait); else {pending.delete(item.file);ignored.set(item.file,item.size);}
386
- continue;
387
- }
388
- pending.delete(item.file);
389
- const main={...item,id:head.sessionId,platform:'claude',origin:head.entrypoint,cwd:head.cwd,version:head.version};
390
- rememberKnown(main);
391
- if (!followed.has(main.id)) rows.push(main);
392
- for (const child of children) {
393
- if (skipHead(child,startup)) continue;
394
- const childHead=await cachedHead(heads,child,claudeHead);
395
- const row={...child,id:`agent-${child.agentId}`,platform:'claude',origin:head.entrypoint,cwd:childHead?.cwd??head.cwd,version:childHead?.version??head.version,parentId:main.id,agent:{agentType:child.meta?.agentType}};
396
- rememberKnown(row);rows.push(row);
397
- }
398
- }
433
+ for (const [platform, handler] of TRANSCRIPT_HANDLERS) {
434
+ const home=homes[platform];
435
+ if (home && platforms.includes(platform)) await handler.discover({platform,home,startup,out,rows});
399
436
  }
400
437
  rows.sort((a,b)=>b.mtimeMs-a.mtimeMs||a.file.localeCompare(b.file));
401
438
  let remaining=rows.filter(row=> {
@@ -407,7 +444,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
407
444
  for (const row of remaining) {
408
445
  const previous=detached.get(row.file) ?? seenAtStart.get(row.file);
409
446
  if (startup || !previous || row.size>previous.size) {
410
- const extract=row.platform==='codex'?codexLineCwd:claudeLineCwd;
447
+ const extract=TRANSCRIPT_HANDLERS.get(row.platform).lineCwd;
411
448
  row.latestCwd=await cachedHead(latestCwds,row,file=>readLatestCwd(file,extract));
412
449
  }
413
450
  rememberStart(row,startup);
@@ -420,16 +457,17 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
420
457
  const next=[];
421
458
  for(const row of remaining) {
422
459
  if (!eligible(row)) {next.push(row);continue;}
423
- if (followed.size>=L.maxFollowed) {
460
+ if (!probe && followed.size>=L.maxFollowed) {
424
461
  const oldest=[...followed.values()].sort((a,b)=>a.mtimeMs-b.mtimeMs)[0];
425
462
  if (!capped) {out.push(notice('following the newest 64 sessions; others are skipped'));capped=true;}
426
463
  if (oldest.mtimeMs>=row.mtimeMs || row.parentId===oldest.id) continue;
427
464
  followed.delete(oldest.id); detached.set(oldest.file,{file:oldest.file,platform:oldest.platform,offset:oldest.tail.offset,size:oldest.size,cwd:oldest.cwd});
428
465
  }
429
- await attach(row,startup,out);progress=true;
466
+ await attach(row,startup,out,skipped);progress=true;
430
467
  }
431
468
  remaining=next;
432
469
  }
470
+ if (probe) return;
433
471
  for (const row of remaining) {
434
472
  const chain=ancestry(row);
435
473
  const missingParent=!chain.resolved;
@@ -449,7 +487,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
449
487
  }
450
488
  emit(row,[],out);
451
489
  }
452
- dispatchEvents(updates,startup,out);
490
+ dispatchEvents(updates,startup,out,skipped);
453
491
  lastDiscovery=now();
454
492
  }
455
493
  async function poll(out) {
@@ -462,7 +500,7 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
462
500
  }
463
501
  if (result.gone) {followed.delete(id);debug(out,`session file removed: ${row.id.slice(0,8)}`);continue;}
464
502
  if (result.reset) {
465
- row.state=createClaudeState();row.codexState=createCodexState();row.active=false;
503
+ row.state=TRANSCRIPT_HANDLERS.get(row.platform).createState();row.active=false;
466
504
  await setCwd(row,row.headCwd,out);row.inScopeNow=lineGate(row);
467
505
  debug(out,`session restarted from the beginning: ${row.id.slice(0,8)}`);
468
506
  }
@@ -519,16 +557,18 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
519
557
  }
520
558
  }
521
559
  state.snapshot=snapshot;
522
- const candidate=[...state.candidates].filter(([id,value])=>followed.has(id) && value?.identity).sort((a,b)=>b[1].ts-a[1].ts)[0];
523
- if (candidate) {
524
- const row=followed.get(candidate[0]);
525
- const events=Object.entries(changes).filter(([,files])=>files.length).map(([kind,files])=>
526
- clean({...candidate[1].identity,observedAt:stamp(),ts:stamp(),kind,paths:files.sort(),inferred:true}));
527
- emit(row,events,out);
560
+ const changed=Object.entries(changes).filter(([,files])=>files.length);
561
+ if (changed.length) {
562
+ const candidate=[...state.candidates].filter(([id,value])=>followed.has(id) && value?.identity).sort((a,b)=>b[1].ts-a[1].ts)[0];
563
+ if (candidate) {
564
+ const events=changed.map(([kind,files])=>
565
+ clean({...candidate[1].identity,observedAt:stamp(),ts:stamp(),kind,paths:files.sort(),inferred:true}));
566
+ emit(followed.get(candidate[0]),events,out);
567
+ }
528
568
  }
529
569
  }
530
570
  }
531
- state.prevScanAt=state.lastScanAt; state.lastScanAt=now();
571
+ state.lastScanAt=now();
532
572
  state.pending=false; state.pendingSince=undefined; state.candidates.clear();
533
573
  }
534
574
  async function scanShell(out) {
@@ -550,6 +590,10 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
550
590
  async start() {
551
591
  if (started||closed) return [];
552
592
  started=true;
593
+ if (probe) {
594
+ await discover(true,[]);
595
+ return [];
596
+ }
553
597
  const store = await resolveDispatchStore({homes, registry});
554
598
  // Keep observing the legacy path even when its first lease arrives after startup.
555
599
  const storeDir = store.kind === 'none' && homes.codex && registry.isPlatformId('codex')
@@ -557,14 +601,32 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
557
601
  dispatch = dispatchIndex({storeDir});
558
602
  const description=`scope ${scope.roots[0]}`+(scope.kind==='repo'?` (${scope.roots.length} worktrees)`:'');
559
603
  const out=[];
604
+ const skipped=options.earlier ? [] : undefined;
560
605
  if (store.kind === 'ambiguous') out.push(notice('dispatch store ambiguous'));
561
- await discover(true,out);
562
- const history=sort(out.filter(e=>e.source!=='watch')).slice(-tailCount || Infinity);
606
+ await discover(true,out,skipped);
607
+ const ordered=sort(out.filter(e=>e.source!=='watch'));
608
+ const history=ordered.slice(-tailCount || Infinity);
609
+ if (skipped) {
610
+ const hidden=skipped.concat(ordered.slice(0,ordered.length-history.length));
611
+ earlierBacklog=sort(hidden.filter(e=>e.source!=='watch')).slice(-L.earlierMax);
612
+ }
563
613
  const diagnostics=out.filter(e=>e.source==='watch');
564
- return markEmitted([notice(`arc watch: ${description} · ${platforms.map(name => name.toUpperCase()).join('+')} · Ctrl-C to stop`),...diagnostics,...(tailCount?history:[]),notice('live')]);
614
+ const brief = {
615
+ scope:scope.display ?? watchLocationLabel({dir:scope.roots[0],home:homes.user}),
616
+ ...(scope.branch ? {branch:scope.branch} : {}),
617
+ platforms:registry.byDisplayOrder().filter(({id}) => platforms.includes(id)).map(({id}) => id),
618
+ };
619
+ const header = notice(`arc watch: ${description} · ${platforms.map(name => name.toUpperCase()).join('+')} · Ctrl-C to stop`);
620
+ return markEmitted([{...header,brief},...diagnostics,...(tailCount?history:[]),{...notice('live'),startup:'live'}]);
621
+ },
622
+ earlier(count) {
623
+ const size=Math.trunc(count);
624
+ if (!earlierBacklog?.length || !(size>0)) return {events:[],remaining:earlierBacklog?.length ?? 0};
625
+ const events=earlierBacklog.splice(Math.max(0,earlierBacklog.length-size)).map(clean);
626
+ return {events,remaining:earlierBacklog.length};
565
627
  },
566
628
  async tick() {
567
- if (!started||closed) return [];
629
+ if (!started||closed||probe) return [];
568
630
  const out=[];
569
631
  if (now()-lastRefresh>=L.worktreeRefreshMs) {scope=await refreshScope(scope,git);lastRefresh=now();}
570
632
  if (now()-lastDiscovery>=L.discoveryMs||pending.size||[...followed.values()].some(row=>row.holdUntil!==undefined)) await discover(false,out);
@@ -572,7 +634,12 @@ export function createWatcher({options, homes, scope: initialScope, git, now, re
572
634
  await scanShell(out);
573
635
  return markEmitted(sort(out));
574
636
  },
637
+ listActivity() {
638
+ return [...followed.values()].map(row=>({
639
+ platform:row.platform,mtimeMs:row.mtimeMs,cwd:row.latestCwd ?? row.cwd,main:!row.parentId,
640
+ }));
641
+ },
575
642
  busy() {return [...followed.values()].some(row=>row.active && (row.inScopeNow || mapped(row)) && now()-row.lastActivity<=L.spinnerIdleMs);},
576
- async close() {closed=true;followed.clear();pending.clear();},
643
+ async close() {closed=true;followed.clear();pending.clear();earlierBacklog=undefined;},
577
644
  };
578
645
  }
@@ -0,0 +1,64 @@
1
+ import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
2
+ import {createTuiInterface} from '../tui/interface.mjs';
3
+ import {cellWidth, fitChoiceRow} from '../tui/render.mjs';
4
+ import {createTerminalSession} from '../tui/terminal.mjs';
5
+ import {WATCH_LIMITS as L} from './model.mjs';
6
+ import {sanitizeText} from './policy.mjs';
7
+ import {orderWorktrees, sameWorktree, worktreeBranch, worktreeDisplayPath} from './scope.mjs';
8
+
9
+ const columns = text => [...text].reduce((sum,character)=>sum+cellWidth(character),0);
10
+ const pad = (text,width) => text+' '.repeat(Math.max(0,width-columns(text)));
11
+
12
+ export function worktreeMenuRows(shown, groups, {
13
+ mainRoot,currentRoot,home,now,width=80,color,registry=DEFAULT_PLATFORM_REGISTRY,
14
+ }) {
15
+ const platforms = registry.byDisplayOrder().filter(row=>row.capabilities.watch.state==='verified');
16
+ const rows = shown.map(tree => {
17
+ const group = groups.get(tree.root);
18
+ const prefix = (sameWorktree(tree.root,currentRoot) ? 'here · ' : '')+(tree.locked ? 'locked · ' : '');
19
+ const branch = sanitizeText(worktreeBranch(tree));
20
+ if (!group) return {branch,activity:prefix+(color ? 'no recent activity' : '(no recent activity)'),tone:color ? 'dim' : undefined};
21
+ const elapsed = Math.max(0,now-group.lastActivity);
22
+ const relative = elapsed<60000 ? Math.floor(elapsed/1000)+'s' : Math.floor(elapsed/60000)+'m';
23
+ const names = platforms.filter(row=>group.platforms.has(row.id)).map(row=>row.label.toUpperCase()).join(', ');
24
+ const activity = prefix+(elapsed<=L.spinnerIdleMs ? '● ' : '')+`${relative} ago · ${group.sessions} session${group.sessions===1?'':'s'}`+
25
+ (names ? ' · '+names : '');
26
+ return {branch,activity};
27
+ });
28
+ const available = Math.max(0,width-7);
29
+ const naturalBranch = Math.max(0,...rows.map(row=>columns(row.branch)));
30
+ const naturalPath = Math.max(0,...shown.map(tree=>columns(worktreeDisplayPath(tree.root,{mainRoot,home}))));
31
+ const activityWidth = Math.max(0,...rows.map(row=>columns(row.activity)));
32
+ const pathBudget = Math.min(naturalPath,Math.max(12,available-naturalBranch-activityWidth));
33
+ const locations = shown.map(tree=>worktreeDisplayPath(tree.root,{mainRoot,home,width:pathBudget}));
34
+ // Align with the TUI's conservative cell widths when a path contains an ellipsis.
35
+ const pathWidth = Math.max(pathBudget,...locations.map(columns));
36
+ const branchWidth = Math.min(naturalBranch,Math.max(8,available-pathWidth-activityWidth));
37
+ return {rows:rows.map(({branch,activity},index)=>{
38
+ const location = locations[index];
39
+ return fitChoiceRow(pad(location,pathWidth)+' '+pad(fitChoiceRow(branch,branchWidth+3),branchWidth)+' '+activity,width);
40
+ }),tones:rows.map(row=>row.tone)};
41
+ }
42
+
43
+ export async function chooseWatchWorktree({
44
+ input,output,env=process.env,signals,worktrees,groups,mainRoot,currentRoot,home,now,
45
+ color=env.NO_COLOR===undefined && env.TERM!=='dumb',registry,createSession=createTerminalSession,
46
+ }) {
47
+ const {shown,hidden} = orderWorktrees(worktrees,groups,{currentRoot,mainRoot,home});
48
+ if (!shown.length) return null;
49
+ const session = createSession({input,output,env,signals});
50
+ try {
51
+ const ui = createTuiInterface(session,{input});
52
+ const {rows,tones} = worktreeMenuRows(shown,groups,{mainRoot,currentRoot,home,now,width:session.viewport().columns,color,registry});
53
+ const selected = await ui.menu('Which worktree to watch?',rows,{
54
+ backRow:true,backLabel:'exit',fitRows:true,
55
+ rowTones:tones,info:hidden ? [`${hidden} more worktrees not shown. Run arc watch inside a worktree to watch it.`] : [],
56
+ });
57
+ return selected===null ? null : shown[selected].root;
58
+ } catch (error) {
59
+ if (error.code==='ARC_TUI_EOF') return null;
60
+ throw error;
61
+ } finally {
62
+ session.dispose();
63
+ }
64
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yunhozz/arc",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -6,9 +6,16 @@ import {runtimeRegistryOf} from './platform-registry.mjs';
6
6
 
7
7
  const environments = new WeakMap();
8
8
  const authKinds = new WeakMap();
9
+ export function unknownPlatformMessage(platform, knownIds) {
10
+ const id = typeof platform === 'string'
11
+ ? [...platform.replace(/[\p{Cc}\u2028\u2029]/gu, '')].slice(0, 256).join('')
12
+ : '(invalid)';
13
+ return `Unknown platform: ${id}. Known platforms: ${knownIds.join(', ')}`;
14
+ }
9
15
  export function resolveConfigHome(platform, context = {}) {
10
- const descriptor = runtimeRegistryOf(context).getPlatform(platform);
11
- if (!descriptor) throw Error('Target must be codex or claude');
16
+ const registry = runtimeRegistryOf(context);
17
+ const descriptor = registry.getPlatform(platform);
18
+ if (!descriptor) throw Error(unknownPlatformMessage(platform, registry.byDisplayOrder().map(({id}) => id)));
12
19
  return descriptor.home.resolve(context);
13
20
  }
14
21
  export function resolveLocalCli(platform, { cwd, userHome, env = process.env, runtimePlatforms } = {}) {
@@ -1,4 +1,4 @@
1
- import {runtimeRegistryOf} from './platform-registry.mjs';
1
+ import {byDisplayOrder, runtimeRegistryOf} from './platform-registry.mjs';
2
2
  // Fixed policy values for composite role dispatch. G2 'escalation' means the bridge runs only with per-call user escalation approval on a Codex host; it is not a verified pass.
3
3
  // GK2/GG2 'approval' means a Grok/Gemini host keeps its platform-default sandbox (off), runs in ask mode, and obtains user approval for each runtime command; it is not a verified pass.
4
4
  // GK2 evidence: Grok 1.0.89, 2026-11-19, ask mode with the sandbox off.
@@ -65,6 +65,9 @@ export const DEFAULT_POLICY = Object.freeze({
65
65
  probeTimeoutMs: PROBE_TIMEOUT_MS
66
66
  });
67
67
 
68
+ const cliEnvironments = byDisplayOrder().flatMap(({executionEnvironments}) => executionEnvironments)
69
+ .filter(environment => environment.endsWith('-cli')).join(' or ');
70
+
68
71
  export const RELEASE_CONDITIONS = Object.freeze({
69
72
  activation_unverified: 'Verify the active configuration, all prepared markers, installed bytes, host limits and the shared lock, and inspect the lease records in <anchor home>/arc-role-dispatch for unreadable or corrupted files.',
70
73
  resume_unverified: 'Update ARC after verifying platform session resume against the recorded session UUID.',
@@ -72,7 +75,7 @@ export const RELEASE_CONDITIONS = Object.freeze({
72
75
  'Not Available': 'Install the target platform CLI so that it is found on PATH.',
73
76
  Unauthorized: 'Authenticate the target platform CLI.',
74
77
  Incomplete: 'Make the target platform CLI authentication status check complete successfully.',
75
- environment_unverified: 'Desktop hosts are held in this release. If this session is not running inside a Desktop app (for example a terminal or IDE terminal session), declare codex-cli or claude-cli instead; otherwise use a CLI host or a later ARC update that changes the support status.',
78
+ environment_unverified: `Desktop hosts are held in this release. If this session is not running inside a Desktop app (for example a terminal or IDE terminal session), declare a CLI environment (${cliEnvironments}) instead; otherwise use a CLI host or a later ARC update that changes the support status.`,
76
79
  host_sandbox_blocked: 'Allow the host to write the anchor home and keep a detached supervisor alive, with explicit user approval.',
77
80
  capacity_exhausted: 'Finish or release active bridge executions, or raise the host limits.',
78
81
  permission_scope_unverified: 'Update ARC and verify enforcement of the role permissions and approved scope before starting.',