@yunhozz/arc 0.3.2 → 0.3.4

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 (151) hide show
  1. package/MANIFEST.sha256 +105 -147
  2. package/README.md +3 -3
  3. package/claude/agents/arc-implementer.md +4 -4
  4. package/claude/agents/arc-planner.md +5 -5
  5. package/claude/agents/arc-qa.md +4 -4
  6. package/claude/agents/arc-reviewer.md +4 -4
  7. package/claude/agents/arc-scouter.md +5 -5
  8. package/claude/skill/SKILL.md +13 -8
  9. package/claude/skill/references/arc-visual-companion.md +5 -5
  10. package/claude/skill/references/commit.md +8 -8
  11. package/claude/skill/references/coordination.md +23 -21
  12. package/claude/skill/references/git-recovery.md +9 -4
  13. package/claude/skill/references/handoff-prep.md +13 -15
  14. package/claude/skill/references/handoff.md +22 -22
  15. package/claude/skill/references/limits.md +2 -2
  16. package/claude/skill/references/planning.md +20 -15
  17. package/claude/skill/references/verification.md +9 -9
  18. package/claude/skill/references/worktree-creation.md +14 -0
  19. package/codex/agents/arc-implementer.toml +4 -4
  20. package/codex/agents/arc-planner.toml +4 -4
  21. package/codex/agents/arc-qa.toml +4 -4
  22. package/codex/agents/arc-reviewer.toml +4 -4
  23. package/codex/agents/arc-scouter.toml +4 -4
  24. package/codex/skill/SKILL.md +12 -8
  25. package/codex/skill/references/arc-visual-companion.md +2 -2
  26. package/codex/skill/references/commit.md +8 -8
  27. package/codex/skill/references/coordination.md +22 -20
  28. package/codex/skill/references/git-recovery.md +5 -9
  29. package/codex/skill/references/handoff-prep.md +9 -9
  30. package/codex/skill/references/handoff.md +20 -20
  31. package/codex/skill/references/limits.md +2 -2
  32. package/codex/skill/references/planning.md +15 -15
  33. package/codex/skill/references/verification.md +10 -10
  34. package/codex/skill/references/worktree-creation.md +20 -0
  35. package/lib/installer/global-config.mjs +2 -2
  36. package/lib/installer/manifest.mjs +10 -9
  37. package/lib/installer/package-references.mjs +2 -2
  38. package/lib/installer/plan.mjs +3 -1
  39. package/lib/installer/skill-sources.mjs +23 -0
  40. package/lib/installer/superpowers.mjs +5 -5
  41. package/lib/policy/role-policy.json +10 -10
  42. package/lib/prompts/agent-fragments.json +16 -16
  43. package/lib/runtime/bootstrap.mjs +1 -1
  44. package/lib/runtime/local-cli.mjs +10 -20
  45. package/lib/runtime/role-bridge.mjs +2 -4
  46. package/lib/runtime/role-dispatch-policy.mjs +4 -9
  47. package/lib/runtime/role-routing.mjs +1 -2
  48. package/lib/watch/dispatch.mjs +10 -2
  49. package/lib/watch/git.mjs +4 -2
  50. package/lib/watch/index.mjs +16 -8
  51. package/lib/watch/model.mjs +8 -4
  52. package/lib/watch/normalize-claude.mjs +89 -7
  53. package/lib/watch/normalize-codex.mjs +15 -11
  54. package/lib/watch/render.mjs +73 -19
  55. package/lib/watch/scope.mjs +5 -5
  56. package/lib/watch/watcher.mjs +110 -10
  57. package/package.json +2 -1
  58. package/scripts/check-installer-parity.mjs +3 -1
  59. package/scripts/update-manifest.mjs +1 -1
  60. package/scripts/update-runtime-assets.mjs +1 -1
  61. package/{codex → shared}/skill/references/handoff-worktree.md +21 -20
  62. package/{codex → shared}/skill/runtime/bootstrap.mjs +1 -1
  63. package/{codex → shared}/skill/runtime/local-cli.mjs +10 -20
  64. package/{codex → shared}/skill/runtime/role-bridge.mjs +2 -4
  65. package/{claude → shared}/skill/runtime/role-dispatch-policy.mjs +4 -9
  66. package/{claude → shared}/skill/runtime/role-policy.json +10 -10
  67. package/{claude → shared}/skill/runtime/role-routing.mjs +1 -2
  68. package/claude/skill/runtime/bootstrap.mjs +0 -38
  69. package/claude/skill/runtime/local-cli.mjs +0 -248
  70. package/claude/skill/runtime/role-bridge.mjs +0 -227
  71. package/codex/skill/references/brainstorming.md +0 -316
  72. package/codex/skill/references/builder-check-prompt.md +0 -23
  73. package/codex/skill/references/scripts/frame-template.html +0 -213
  74. package/codex/skill/references/scripts/helper.js +0 -167
  75. package/codex/skill/references/scripts/server.cjs +0 -723
  76. package/codex/skill/references/scripts/start-server.sh +0 -216
  77. package/codex/skill/references/scripts/stop-server.sh +0 -120
  78. package/codex/skill/references/superpowers-LICENSE +0 -21
  79. package/codex/skill/references/superpowers-provenance.json +0 -26
  80. package/codex/skill/references/test-driven-development.md +0 -330
  81. package/codex/skill/references/visual-companion.md +0 -299
  82. package/codex/skill/references/writing-good-tests.md +0 -198
  83. package/codex/skill/references/writing-plans.md +0 -204
  84. package/codex/skill/runtime/acceptance.mjs +0 -68
  85. package/codex/skill/runtime/adapters/claude.mjs +0 -86
  86. package/codex/skill/runtime/adapters/codex.mjs +0 -65
  87. package/codex/skill/runtime/assignment.mjs +0 -42
  88. package/codex/skill/runtime/capabilities.mjs +0 -44
  89. package/codex/skill/runtime/cli.mjs +0 -8
  90. package/codex/skill/runtime/command.mjs +0 -38
  91. package/codex/skill/runtime/cooperative-schema.mjs +0 -87
  92. package/codex/skill/runtime/cooperative.mjs +0 -239
  93. package/codex/skill/runtime/evaluate.mjs +0 -331
  94. package/codex/skill/runtime/external.mjs +0 -51
  95. package/codex/skill/runtime/gate.mjs +0 -71
  96. package/codex/skill/runtime/git-evidence.mjs +0 -258
  97. package/codex/skill/runtime/git-query.mjs +0 -88
  98. package/codex/skill/runtime/identity.mjs +0 -49
  99. package/codex/skill/runtime/operations.mjs +0 -6
  100. package/codex/skill/runtime/role-bridge-args.mjs +0 -148
  101. package/codex/skill/runtime/role-dispatch-policy.mjs +0 -110
  102. package/codex/skill/runtime/role-dispatch-store.mjs +0 -134
  103. package/codex/skill/runtime/role-observe.mjs +0 -299
  104. package/codex/skill/runtime/role-policy.json +0 -654
  105. package/codex/skill/runtime/role-routing-config.mjs +0 -19
  106. package/codex/skill/runtime/role-routing.mjs +0 -233
  107. package/codex/skill/runtime/role-supervisor.mjs +0 -356
  108. package/codex/skill/runtime/schema.mjs +0 -98
  109. package/codex/skill/runtime/scope.mjs +0 -36
  110. package/codex/skill/runtime/store.mjs +0 -94
  111. package/codex/skill/runtime/target-preparation.mjs +0 -110
  112. package/codex/skill/runtime/verification.mjs +0 -125
  113. /package/{claude → shared}/skill/references/brainstorming.md +0 -0
  114. /package/{claude → shared}/skill/references/builder-check-prompt.md +0 -0
  115. /package/{claude → shared}/skill/references/scripts/frame-template.html +0 -0
  116. /package/{claude → shared}/skill/references/scripts/helper.js +0 -0
  117. /package/{claude → shared}/skill/references/scripts/server.cjs +0 -0
  118. /package/{claude → shared}/skill/references/scripts/start-server.sh +0 -0
  119. /package/{claude → shared}/skill/references/scripts/stop-server.sh +0 -0
  120. /package/{claude → shared}/skill/references/superpowers-LICENSE +0 -0
  121. /package/{claude → shared}/skill/references/superpowers-provenance.json +0 -0
  122. /package/{claude → shared}/skill/references/test-driven-development.md +0 -0
  123. /package/{claude → shared}/skill/references/visual-companion.md +0 -0
  124. /package/{claude → shared}/skill/references/writing-good-tests.md +0 -0
  125. /package/{claude → shared}/skill/references/writing-plans.md +0 -0
  126. /package/{claude → shared}/skill/runtime/acceptance.mjs +0 -0
  127. /package/{claude → shared}/skill/runtime/adapters/claude.mjs +0 -0
  128. /package/{claude → shared}/skill/runtime/adapters/codex.mjs +0 -0
  129. /package/{claude → shared}/skill/runtime/assignment.mjs +0 -0
  130. /package/{claude → shared}/skill/runtime/capabilities.mjs +0 -0
  131. /package/{claude → shared}/skill/runtime/cli.mjs +0 -0
  132. /package/{claude → shared}/skill/runtime/command.mjs +0 -0
  133. /package/{claude → shared}/skill/runtime/cooperative-schema.mjs +0 -0
  134. /package/{claude → shared}/skill/runtime/cooperative.mjs +0 -0
  135. /package/{claude → shared}/skill/runtime/evaluate.mjs +0 -0
  136. /package/{claude → shared}/skill/runtime/external.mjs +0 -0
  137. /package/{claude → shared}/skill/runtime/gate.mjs +0 -0
  138. /package/{claude → shared}/skill/runtime/git-evidence.mjs +0 -0
  139. /package/{claude → shared}/skill/runtime/git-query.mjs +0 -0
  140. /package/{claude → shared}/skill/runtime/identity.mjs +0 -0
  141. /package/{claude → shared}/skill/runtime/operations.mjs +0 -0
  142. /package/{claude → shared}/skill/runtime/role-bridge-args.mjs +0 -0
  143. /package/{claude → shared}/skill/runtime/role-dispatch-store.mjs +0 -0
  144. /package/{claude → shared}/skill/runtime/role-observe.mjs +0 -0
  145. /package/{claude → shared}/skill/runtime/role-routing-config.mjs +0 -0
  146. /package/{claude → shared}/skill/runtime/role-supervisor.mjs +0 -0
  147. /package/{claude → shared}/skill/runtime/schema.mjs +0 -0
  148. /package/{claude → shared}/skill/runtime/scope.mjs +0 -0
  149. /package/{claude → shared}/skill/runtime/store.mjs +0 -0
  150. /package/{claude → shared}/skill/runtime/target-preparation.mjs +0 -0
  151. /package/{claude → shared}/skill/runtime/verification.mjs +0 -0
@@ -13,8 +13,8 @@ export const WATCH_HELP = `Usage: arc watch [options]
13
13
 
14
14
  Follow Claude Code and Codex session activity in one read-only stream.
15
15
 
16
- Scope (default: every worktree of the current Git repository, or the current directory):
17
- --cwd <dir> Watch the repository or directory at <dir>
16
+ Scope (default: the current Git worktree, or the current directory):
17
+ --cwd <dir> Watch the worktree or directory at <dir>
18
18
  --all Watch sessions from every directory
19
19
  --session <id> Follow one session or ARC dispatch and its subagents
20
20
  --platform <name> codex or claude (default: both)
@@ -23,14 +23,14 @@ Output:
23
23
  --tail <n> First show the last <n> events from recently active sessions (default 20, 0 = new only)
24
24
  --verbose Also show reasoning, settings, turn starts and diagnostics
25
25
  --json Write one JSON object per line
26
- --width <n> Maximum width of one-line events (default: terminal width, or 200)
26
+ --width <n> Maximum line width; one-line events are clipped, messages and file lists wrap (default: terminal width, or 200)
27
27
  --help Show this help
28
28
 
29
- User and agent messages are shown in full; other events use one line.
29
+ User and agent messages and file paths are shown in full; other events use one line.
30
30
  Tool and command outputs are never shown; common secret patterns are masked.
31
31
  A spinner on the last line shows while a turn is in progress (TTY only).
32
32
  Codex Desktop sessions are not included.
33
- Bridge roles on a Codex host are currently held (host_sandbox_blocked) and appear once they run.
33
+ Claude bridge Scouter, Planner and Reviewer on a Codex host need per-call escalation approval (otherwise host_sandbox_blocked) and appear once they run; Claude bridge Implementer and QA stay held.
34
34
  Press Ctrl-L to clear the screen (TTY only) and Ctrl-C to stop.`;
35
35
 
36
36
  export async function runWatch(argv, io = {}) {
@@ -58,6 +58,7 @@ export async function runWatch(argv, io = {}) {
58
58
  const now = io.now ?? Date.now, git = io.git ?? createGitRunner({env});
59
59
  const proc = io.process ?? process, schedule = io.setInterval ?? setInterval, unschedule = io.clearInterval ?? clearInterval;
60
60
  let width, watcher, timer, stopped = false, active;
61
+ const wrap = Boolean(!options.json && (output.isTTY || options.width != null));
61
62
  const color = Boolean(output.isTTY && !options.json && !env.NO_COLOR);
62
63
  const spinnerEnabled = Boolean(output.isTTY && !options.json);
63
64
  const keysEnabled = Boolean(input.isTTY && output.isTTY && !options.json && typeof input.setRawMode === 'function');
@@ -122,7 +123,7 @@ export async function runWatch(argv, io = {}) {
122
123
  eraseSpinner();
123
124
  for (const event of events) {
124
125
  if (stopped) break;
125
- output.write((options.json ? renderJson(event) : renderHuman(event,{width,color,verbose:options.verbose})) + '\n');
126
+ output.write((options.json ? renderJson(event) : renderHuman(event,{width,color,verbose:options.verbose,wrap})) + '\n');
126
127
  }
127
128
  drawSpinner();
128
129
  };
@@ -130,7 +131,7 @@ export async function runWatch(argv, io = {}) {
130
131
  output.on('error', onError);
131
132
  output.on('resize', resize);
132
133
  io.signal?.addEventListener('abort', onSignal, {once:true});
133
- let ticking = false;
134
+ let ticking = false, nextPollAt;
134
135
  active = (async () => {
135
136
  if (keysEnabled) {
136
137
  rawModeEnabled = true;
@@ -147,13 +148,20 @@ export async function runWatch(argv, io = {}) {
147
148
  }
148
149
  write(await watcher.start());
149
150
  if (stopped) return;
151
+ nextPollAt = now() + L.filePollMs;
150
152
  timer = schedule(() => {
151
153
  if (stopped || ticking) return;
154
+ if (now() < nextPollAt) {
155
+ eraseSpinner();
156
+ drawSpinner();
157
+ return;
158
+ }
159
+ nextPollAt = now() + L.filePollMs;
152
160
  ticking = true;
153
161
  active = (async () => { try { write(await watcher.tick()); } finally { ticking = false; } })();
154
162
  active.catch(onError);
155
163
  return active;
156
- }, L.filePollMs);
164
+ }, spinnerEnabled ? 100 : L.filePollMs);
157
165
  })();
158
166
  active.catch(onError);
159
167
  });
@@ -1,4 +1,4 @@
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','spawn','approval','dispatch','error','other','notice']);
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
2
  export const MESSAGE_KINDS = Object.freeze(['user','agent']);
3
3
  export const VERBOSE_KINDS = Object.freeze(['settings','turn_start','reasoning','other']);
4
4
  export const ROLE_NAMES = Object.freeze(['scouter','planner','implementer','qa','reviewer']);
@@ -9,9 +9,12 @@ export const WATCH_LIMITS = Object.freeze({
9
9
  idleDetachMs:1800000, maxFollowed:64, maxReadBytesPerTick:1048576,
10
10
  maxLineBytes:4194304, historyBytes:262144, maxRepos:32, claudeHeadBytes:1048576,
11
11
  claudeCwdWaitMs:10000, codexMetaBytes:4194304, lookbackDays:7,
12
- jsonTextMax:1000, agentNameMax:20, pathsMax:20, toolCacheMax:512, defaultTail:20,
12
+ jsonTextMax:1000, wrapMinBody:20, toolCacheMax:512, defaultTail:20,
13
13
  maxTail:1000, widthMin:40, widthMax:2000, ttyWidthMin:60, nonTtyWidth:200,
14
14
  gitTimeoutMs:10000, spinnerIdleMs:300000,
15
+ shellScanDelayMs:1000, shellScanMinIntervalMs:3000, shellScansPerTick:2,
16
+ shellScanMaxFiles:20000, shellScanTimeoutMs:5000, shellScanFailureMax:3,
17
+ shellLstatBatch:256, shellClaimTtlMs:120000, gitMaxBufferBytes:16777216,
15
18
  });
16
19
 
17
20
  /**
@@ -31,12 +34,13 @@ export const WATCH_LIMITS = Object.freeze({
31
34
  * @property {'scouter'|'planner'|'implementer'|'qa'|'reviewer'|'orchestrator'} [role]
32
35
  * @property {string} [dispatchId]
33
36
  * @property {string} [workflowId]
34
- * @property {'session'|'settings'|'turn_start'|'turn_end'|'turn_failed'|'user'|'agent'|'reasoning'|'command'|'tool'|'tool_failed'|'file_change'|'file_create'|'spawn'|'approval'|'dispatch'|'error'|'other'|'notice'} kind
37
+ * @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
35
38
  * @property {string} [text] Sanitized, masked text; user/agent preserve newlines without a length cap. Other JSON text is capped at 1000 code points.
36
39
  * @property {boolean} [truncated]
37
40
  * @property {number} [exitCode]
38
41
  * @property {string} [tool]
39
- * @property {string[]} [paths] At most 20 paths.
42
+ * @property {string[]} [paths] All reported paths, deduplicated; no fixed cap.
43
+ * @property {boolean} [inferred] True for file events inferred from a Git file-list and lstat comparison.
40
44
  * @property {string} [model]
41
45
  * @property {string} [effort]
42
46
  * @property {string} [approval]
@@ -1,10 +1,11 @@
1
+ import path from 'node:path';
1
2
  import {WATCH_LIMITS} from './model.mjs';
2
3
 
3
4
  const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
4
5
  const string = value => typeof value === 'string';
5
6
 
6
7
  export function createClaudeState() {
7
- return {modelSeen:false, tools:new Map(), writes:new Map()};
8
+ return {modelSeen:false, tools:new Map(), writes:new Map(), deletes:new Map()};
8
9
  }
9
10
 
10
11
  export function parseClaudeHead(obj) {
@@ -31,12 +32,75 @@ function userText(content) {
31
32
  return text.replace(/<(system-reminder|command-[\w-]+|local-command-[\w-]+|task-notification|bash-input|bash-stdout|bash-stderr)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/gi, '');
32
33
  }
33
34
 
34
- /** State contains the first-model flag and bounded tool-name and pending-Write caches. */
35
+ // Parse only literal shell words. Expansions, pipelines and other shell syntax
36
+ // stay command events because their deletion targets cannot be inferred safely.
37
+ function literalCommands(command) {
38
+ if (!string(command) || /[\r\n]/.test(command)) return null;
39
+ const commands = [[]];
40
+ let word = '', started = false, quote = '';
41
+ const flush = () => {
42
+ if (started) commands.at(-1).push(word);
43
+ word = ''; started = false;
44
+ };
45
+ for (let i=0;i<command.length;i++) {
46
+ const c = command[i];
47
+ if (quote === "'") {
48
+ if (c === quote) quote = ''; else word += c;
49
+ } else if (quote === '"') {
50
+ if (c === quote) quote = '';
51
+ else if (c === '$' || c === '`') return null;
52
+ else if (c === '\\' && /["\\$`]/.test(command[i+1] ?? '')) word += command[++i];
53
+ else word += c;
54
+ } else if (c === "'" || c === '"') {
55
+ quote = c; started = true;
56
+ } else if (c === '\\') {
57
+ if (++i >= command.length) return null;
58
+ word += command[i]; started = true;
59
+ } else if (/[ \t]/.test(c)) flush();
60
+ else if (c === '&' && command[i+1] === '&') {
61
+ flush(); commands.push([]); i++;
62
+ } else if (/[;|&<>$`*?\[\]{}()]/.test(c) || (!started && (c === '~' || c === '#'))) return null;
63
+ else { word += c; started = true; }
64
+ }
65
+ if (quote) return null;
66
+ flush();
67
+ return commands.every(words => words.length) ? commands : null;
68
+ }
69
+
70
+ function deletionPaths(command, cwd) {
71
+ const commands = literalCommands(command);
72
+ if (!commands || commands.length > 2) return [];
73
+ let base = string(cwd) && path.isAbsolute(cwd) ? cwd : undefined;
74
+ if (commands.length === 2) {
75
+ const [name,...args] = commands.shift();
76
+ if (args[0] === '--') args.shift();
77
+ if (name !== 'cd' || args.length !== 1 || !args[0] || args[0].startsWith('-')) return [];
78
+ if (!path.isAbsolute(args[0]) && !base) return [];
79
+ base = path.resolve(base ?? '/',args[0]);
80
+ }
81
+ const [name,...args] = commands[0];
82
+ if (!['rm','/bin/rm','/usr/bin/rm'].includes(name)) return [];
83
+ const paths = [];
84
+ let options = true;
85
+ for (const arg of args) {
86
+ if (options && arg === '--') { options = false; continue; }
87
+ if (options && arg.startsWith('-') && arg !== '-') {
88
+ if (!/^-[fRrvd]+$/.test(arg) && !['--force','--recursive','--verbose','--dir'].includes(arg)) return [];
89
+ continue;
90
+ }
91
+ if (!arg) return [];
92
+ paths.push(base ? path.resolve(base,arg) : arg);
93
+ }
94
+ return [...new Set(paths)];
95
+ }
96
+
97
+ /** State contains bounded tool-name, pending-Write and pending-deletion caches. */
35
98
  export function normalizeClaudeLine(obj, state) {
36
99
  try {
37
100
  if (!object(obj) || !['user','assistant'].includes(obj.type) || !object(obj.message)) return [];
38
101
  if (!object(state) || !(state.tools instanceof Map)) return [];
39
102
  if (!(state.writes instanceof Map)) state.writes = new Map();
103
+ if (!(state.deletes instanceof Map)) state.deletes = new Map();
40
104
  const events = [];
41
105
  const emit = (kind, fields={}) => {
42
106
  const event = {kind, ...fields};
@@ -57,12 +121,16 @@ export function normalizeClaudeLine(obj, state) {
57
121
  if (block?.type !== 'tool_result') continue;
58
122
  const id = block.tool_use_id, pending = state.writes.has(id), path = state.writes.get(id);
59
123
  state.writes.delete(id);
124
+ const deleted = state.deletes.get(id);
125
+ state.deletes.delete(id);
60
126
  if (block.is_error === true) {
61
127
  const tool = state.tools.get(id);
62
128
  emit('tool_failed', string(tool) ? {tool} : {});
129
+ } else if (deleted && obj.toolUseResult?.interrupted !== true && !obj.toolUseResult?.backgroundTaskId) {
130
+ emit('file_delete', {paths:deleted});
63
131
  } else if (pending) {
64
132
  const result = obj.toolUseResult;
65
- const paths = [...new Set([string(result?.filePath) ? result.filePath : path].filter(string))].slice(0,WATCH_LIMITS.pathsMax);
133
+ const paths = [...new Set([string(result?.filePath) ? result.filePath : path].filter(string))];
66
134
  emit(result?.type === 'create' ? 'file_create' : 'file_change', {paths});
67
135
  }
68
136
  }
@@ -77,6 +145,7 @@ export function normalizeClaudeLine(obj, state) {
77
145
  state.modelSeen = true;
78
146
  emit('settings', {model:message.model});
79
147
  }
148
+ let turnEnded = false;
80
149
  for (const block of blocks) {
81
150
  if (!object(block)) continue;
82
151
  if (block.type === 'text' && string(block.text)) emit('agent', {text:block.text});
@@ -89,15 +158,22 @@ export function normalizeClaudeLine(obj, state) {
89
158
  while (state.tools.size > WATCH_LIMITS.toolCacheMax) state.tools.delete(state.tools.keys().next().value);
90
159
  }
91
160
  const input = object(block.input) ? block.input : {};
92
- if (name === 'Bash') emit('command', string(input.command) ? {text:input.command} : {});
93
- else if (name === 'Write') {
161
+ if (name === 'Bash') {
162
+ emit('command', string(input.command) ? {text:input.command} : {});
163
+ if (string(block.id)) {
164
+ state.deletes.delete(block.id);
165
+ const paths = input.run_in_background === true ? [] : deletionPaths(input.command,obj.cwd);
166
+ if (paths.length) state.deletes.set(block.id, paths);
167
+ while (state.deletes.size > WATCH_LIMITS.toolCacheMax) state.deletes.delete(state.deletes.keys().next().value);
168
+ }
169
+ } else if (name === 'Write') {
94
170
  if (string(block.id)) {
95
171
  state.writes.delete(block.id);
96
172
  state.writes.set(block.id, string(input.file_path) ? input.file_path : undefined);
97
173
  while (state.writes.size > WATCH_LIMITS.toolCacheMax) state.writes.delete(state.writes.keys().next().value);
98
174
  }
99
175
  } else if (['Edit','MultiEdit','NotebookEdit'].includes(name)) {
100
- emit('file_change', {paths:[...new Set([input.file_path,input.notebook_path].filter(string))].slice(0,WATCH_LIMITS.pathsMax)});
176
+ emit('file_change', {paths:[...new Set([input.file_path,input.notebook_path].filter(string))]});
101
177
  } else if (['Agent','Task'].includes(name)) {
102
178
  const agent = string(input.subagent_type) ? input.subagent_type : '';
103
179
  const description = string(input.description) ? input.description : '';
@@ -105,10 +181,16 @@ export function normalizeClaudeLine(obj, state) {
105
181
  } else if (['Read','Grep','Glob','WebFetch','WebSearch'].includes(name)) {
106
182
  const target = [input.file_path,input.pattern,input.path,input.url,input.query].find(string);
107
183
  emit('tool', {tool:name, ...(target === undefined ? {} : {text:target})});
184
+ } else if (name === 'SubagentHandback' && string(input.message) && input.message) {
185
+ emit('agent', {text:input.message});
108
186
  } else emit('tool', {tool:name});
187
+ if (name === 'SubagentHandback' && !turnEnded) {
188
+ emit('turn_end');
189
+ turnEnded = true;
190
+ }
109
191
  }
110
192
  }
111
- if (message.stop_reason === 'end_turn') emit('turn_end');
193
+ if (message.stop_reason === 'end_turn' && !turnEnded) emit('turn_end');
112
194
  return events;
113
195
  } catch { return []; }
114
196
  }
@@ -1,5 +1,3 @@
1
- import {WATCH_LIMITS} from './model.mjs';
2
-
3
1
  const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
4
2
  const string = value => typeof value === 'string';
5
3
  const strings = values => values.filter(string);
@@ -39,25 +37,27 @@ function changePaths(changes) {
39
37
  } else if (object(changes)) {
40
38
  for (const [path, change] of Object.entries(changes)) paths.push(path, change?.move_path);
41
39
  }
42
- return [...new Set(strings(paths))].slice(0, WATCH_LIMITS.pathsMax);
40
+ return [...new Set(strings(paths))];
43
41
  }
44
42
 
45
43
  function splitChangePaths(changes) {
46
- const added = [], changed = [];
44
+ const added = [], changed = [], deleted = [];
47
45
  const isAdd = change => object(change) && (change.type === 'add' || change.kind?.type === 'add' || Object.hasOwn(change,'add'));
46
+ const isDelete = change => object(change) && (change.type === 'delete' || change.kind?.type === 'delete' || Object.hasOwn(change,'delete'));
47
+ const group = change => isAdd(change) ? added : isDelete(change) ? deleted : changed;
48
48
  if (Array.isArray(changes)) {
49
49
  for (const change of changes) {
50
- (isAdd(change) ? added : changed).push(change?.path, change?.file);
50
+ group(change).push(change?.path, change?.file);
51
51
  changed.push(change?.move_path);
52
52
  }
53
53
  } else if (object(changes)) {
54
54
  for (const [path, change] of Object.entries(changes)) {
55
- (isAdd(change) ? added : changed).push(path);
55
+ group(change).push(path);
56
56
  changed.push(change?.move_path);
57
57
  }
58
58
  }
59
- const unique = paths => [...new Set(strings(paths))].slice(0,WATCH_LIMITS.pathsMax);
60
- return {added:unique(added),changed:unique(changed)};
59
+ const unique = paths => [...new Set(strings(paths))];
60
+ return {added:unique(added),changed:unique(changed),deleted:unique(deleted)};
61
61
  }
62
62
 
63
63
  /** Normalize one parsed rollout line; no I/O or transcript state. */
@@ -105,9 +105,13 @@ export function normalizeCodexLine(obj) {
105
105
  case 'CommandExecution': return emit('command', {text:commandText(item.command), exitCode:Number.isFinite(item.exit_code) ? item.exit_code : undefined});
106
106
  case 'FileChange':
107
107
  case 'PatchApply': {
108
- const {added,changed} = splitChangePaths(item.changes);
109
- if (!added.length) return emit('file_change', {paths:changePaths(item.changes)});
110
- return [...emit('file_create', {paths:added}), ...(changed.length ? emit('file_change', {paths:changed}) : [])];
108
+ const {added,changed,deleted} = splitChangePaths(item.changes);
109
+ if (!added.length && !deleted.length) return emit('file_change', {paths:changePaths(item.changes)});
110
+ return [
111
+ ...(added.length ? emit('file_create', {paths:added}) : []),
112
+ ...(changed.length ? emit('file_change', {paths:changed}) : []),
113
+ ...(deleted.length ? emit('file_delete', {paths:deleted}) : []),
114
+ ];
111
115
  }
112
116
  case 'McpToolCall': return emit('tool', {tool:strings([item.server,item.tool]).join('.')});
113
117
  case 'Extension':
@@ -3,6 +3,59 @@ 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
5
 
6
+ const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
7
+ const roleLabels = new Map([
8
+ ['scouter','Scouter'], ['planner','Planner'], ['implementer','Implementer'],
9
+ ['qa','QA'], ['reviewer','Reviewer'], ['orchestrator','Orchestrator'],
10
+ ]);
11
+ const zeroWidth = /^[\u0300-\u036f\u200b-\u200f\ufe00-\ufe0f]+$/u;
12
+ 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;
13
+ function graphemeWidth(text) {
14
+ if (zeroWidth.test(text)) return 0;
15
+ if (wide.test(text) || /\p{Emoji_Presentation}/u.test(text) || (/[\u200d\ufe0f]/u.test(text) && /\p{Extended_Pictographic}/u.test(text))) return 2;
16
+ return 1;
17
+ }
18
+
19
+ export function displayWidth(text) {
20
+ let width = 0;
21
+ for (const {segment} of graphemes.segment(text)) width += graphemeWidth(segment);
22
+ return width;
23
+ }
24
+
25
+ export function wrapLine(text, avail) {
26
+ if (avail <= 0) return [text];
27
+ const parts = [...graphemes.segment(text)].map(({segment}) => segment);
28
+ const widths = parts.map(graphemeWidth);
29
+ const lines = [];
30
+ let start = 0;
31
+ while (start < parts.length) {
32
+ let end = start, cols = 0, space = -1, hasContent = false;
33
+ while (end < parts.length && cols + widths[end] <= avail) {
34
+ if (parts[end] === ' ') { if (hasContent) space = end; }
35
+ else hasContent = true;
36
+ cols += widths[end++];
37
+ }
38
+ if (end === parts.length) {
39
+ const piece = parts.slice(start).join('');
40
+ if (piece.trim()) lines.push(piece);
41
+ break;
42
+ }
43
+ // A space immediately after a full line can be discarded as the boundary.
44
+ if (parts[end] === ' ' && hasContent) space = end;
45
+ let piece;
46
+ if (space >= 0) {
47
+ piece = parts.slice(start,space).join('');
48
+ start = space + 1;
49
+ } else {
50
+ end = Math.max(start + 1,end);
51
+ piece = parts.slice(start,end).join('');
52
+ start = end;
53
+ }
54
+ if (piece.trim()) lines.push(piece);
55
+ }
56
+ return lines.length ? lines : [''];
57
+ }
58
+
6
59
  export const PLATFORM_COLORS = Object.freeze({codex:'36', claude:'38;5;208', other:'2'});
7
60
 
8
61
  // Compare both the lexical root and its real path (e.g. /tmp and /private/tmp).
@@ -19,7 +72,7 @@ export function displayPath(file, root) {
19
72
 
20
73
  export function tagColor(event) {
21
74
  if (event.kind === 'command') return event.exitCode == null || event.exitCode === 0 ? '38;5;242' : '31';
22
- return ({user:'1;35', agent:'32', file_change:'33', file_create:'38;5;69', tool:'2', spawn:'38;5;141',
75
+ return ({user:'1;35', agent:'32', file_change:'33', file_create:'38;5;69', file_delete:'31', tool:'2', spawn:'38;5;141',
23
76
  dispatch:'38;5;137', approval:'1;4', turn_failed:'31', error:'31', tool_failed:'31'})[event.kind] ?? '2';
24
77
  }
25
78
 
@@ -29,15 +82,10 @@ export function bodyColor(event) {
29
82
  }
30
83
 
31
84
  export function kindTag(event) {
32
- if (event.kind === 'agent') {
33
- const name = event.role || (event.source === 'subagent' && event.label?.includes('/') ? event.label.split('/').at(-1) : '');
34
- const safeName = clipCodePoints(sanitizeText(name), WATCH_LIMITS.agentNameMax).text;
35
- return safeName ? `AGENT(${safeName})` : 'AGENT';
36
- }
37
85
  if (event.kind === 'command') return event.exitCode == null ? 'CMD' : `CMD(${event.exitCode})`;
38
86
  return ({session:'SESSION', settings:'SETTINGS', turn_start:'TURN', turn_end:'END',
39
87
  turn_failed:'FAIL', user:'USER', agent:'AGENT', reasoning:'THINK', tool:'TOOL',
40
- tool_failed:'TOOL!', file_change:'EDIT', file_create:'CREATE', spawn:'SPAWN', approval:'APPROVE',
88
+ tool_failed:'TOOL!', file_change:'EDIT', file_create:'CREATE', file_delete:'DELETE', spawn:'SPAWN', approval:'APPROVE',
41
89
  dispatch:'DISPATCH', error:'ERROR', other:'ITEM', notice:'NOTICE'})[event.kind] ?? 'ITEM';
42
90
  }
43
91
 
@@ -45,16 +93,13 @@ function eventText(event, verbose) {
45
93
  if (event.kind === 'tool' || event.kind === 'tool_failed') {
46
94
  return [event.tool, event.text].map(sanitizeText).filter(Boolean).join(' ');
47
95
  }
48
- if (event.kind === 'file_change' || event.kind === 'file_create') {
49
- return [event.text, ...(event.paths ?? []).map(file => displayPath(file,event.root))].map(sanitizeText).filter(Boolean).join(' ');
50
- }
51
96
  if (event.kind !== 'dispatch') return sanitizeText(event.text);
52
97
  return sanitizeText([event.state, event.route, event.workflowId,
53
98
  event.reasons?.join(','), verbose && event.hostPlatform ? `host=${event.hostPlatform}` : undefined,
54
99
  ].filter(Boolean).join(' '));
55
100
  }
56
101
 
57
- export function renderHuman(event, {width, color, verbose}) {
102
+ export function renderHuman(event, {width, color, verbose, wrap = false}) {
58
103
  let date = new Date(event.ts);
59
104
  if (Number.isNaN(date.getTime())) date = new Date(event.observedAt);
60
105
  const time = Number.isNaN(date.getTime()) ? '00:00:00' : date.toLocaleTimeString('en-GB', {hour12:false});
@@ -62,26 +107,36 @@ export function renderHuman(event, {width, color, verbose}) {
62
107
  const tag = sanitizeText(kindTag(event)).padEnd(8);
63
108
  const prefix = `${time} ${platform} ${tag} `;
64
109
  const message = MESSAGE_KINDS.includes(event.kind);
65
- const fullLine = message || event.kind === 'file_change' || event.kind === 'file_create';
110
+ const fullLine = message || event.kind === 'file_change' || event.kind === 'file_create' || event.kind === 'file_delete';
66
111
  const text = message ? sanitizeMessage(event.text) : eventText(event, verbose);
67
- const messageBody = text.split('\n').map((line, i) => !line ? '' : (i ? ' '.repeat([...prefix].length) : '') + line).join('\n');
68
- const plain = message ? (text ? prefix + messageBody : prefix.trimEnd()) : fullLine ? prefix + text : clipCodePoints(prefix + text, width).text;
112
+ const bodyLines = message ? (text ? text.split('\n') : []) : fullLine
113
+ ? [event.text, ...(event.paths ?? []).map(file => displayPath(file,event.root))].map(sanitizeText).filter(Boolean) : [];
114
+ const roleName = event.kind === 'agent' ? roleLabels.get(event.role) : undefined;
115
+ if (roleName && bodyLines.length) bodyLines[0] = `[${roleName}] ${bodyLines[0]}`;
116
+ const indent = ' '.repeat([...prefix].length);
117
+ const avail = width - Math.max([...prefix].length, displayWidth(prefix));
118
+ const lines = wrap && avail >= WATCH_LIMITS.wrapMinBody ? bodyLines.flatMap(line => wrapLine(line,avail)) : bodyLines;
119
+ const bodyText = paintLine => lines.map((line,i) => !line ? '' : (i ? indent : '') + paintLine(line,i)).join('\n');
120
+ const plain = fullLine ? (message && !lines.length ? prefix.trimEnd() : prefix + bodyText(line => line)) : clipCodePoints(prefix + text, width).text;
69
121
  if (!color || (!fullLine && [...prefix].length > width)) return plain;
70
122
  const code = bodyColor(event);
71
123
  const paint = (value, code) => `\x1b[${code}m${value}\x1b[0m`;
72
124
  const platformColor = event.source === 'watch' ? PLATFORM_COLORS.other : PLATFORM_COLORS[event.platform] ?? PLATFORM_COLORS.other;
73
125
  const paintedTag = paint(tag.trimEnd(), tagColor(event));
74
126
  const padding = tag.slice(tag.trimEnd().length);
75
- const clippedText = message ? messageBody : [...plain].slice([...prefix].length).join('');
127
+ const clippedText = [...plain].slice([...prefix].length).join('');
76
128
  if (message && !text) return `${time} ${paint(platform, platformColor)} ${paintedTag}`;
77
- const body = message ? text.split('\n').map((line, i) => !line ? '' : (i ? ' '.repeat([...prefix].length) : '') + (code ? paint(line, code) : line)).join('\n')
129
+ const body = fullLine ? bodyText((line,i) => {
130
+ if (roleName && i === 0) line = line.replace(`[${roleName}]`, `[\x1b[1m${roleName}\x1b[22m]`);
131
+ return code ? paint(line,code) : line;
132
+ })
78
133
  : code && clippedText ? paint(clippedText, code) : clippedText;
79
134
  return `${time} ${paint(platform, platformColor)} ${paintedTag}${padding} ${body}`;
80
135
  }
81
136
 
82
137
  export function renderJson(event) {
83
138
  const fields = ['ts','observedAt','platform','source','origin','sessionId','parentId','depth',
84
- 'label','role','dispatchId','workflowId','kind','text','truncated','exitCode','tool','paths',
139
+ 'label','role','dispatchId','workflowId','kind','text','truncated','exitCode','tool','paths','inferred',
85
140
  'model','effort','approval','state','reasons','route','hostPlatform','cwd'];
86
141
  const output = {v:1};
87
142
  for (const key of fields) {
@@ -98,8 +153,7 @@ export function renderJson(event) {
98
153
  } else if (key === 'truncated') {
99
154
  if (value || output.truncated) output.truncated = true;
100
155
  } else if (Array.isArray(value)) {
101
- output[key] = (key === 'paths' ? value.slice(0, WATCH_LIMITS.pathsMax) : value)
102
- .filter(item => item != null).map(item => sanitizeText(item));
156
+ output[key] = value.filter(item => item != null).map(item => sanitizeText(item));
103
157
  } else {
104
158
  output[key] = typeof value === 'string' ? sanitizeText(value) : value;
105
159
  }
@@ -30,8 +30,8 @@ export async function resolveScope({mode, dir, session, git}) {
30
30
  if (top !== null) {
31
31
  const common = await git(root, GIT_ALLOWED[1]), trees = await git(root, GIT_ALLOWED[2]);
32
32
  if (common !== null && trees !== null) {
33
- const roots = worktreeRoots(trees);
34
- return {kind:'repo', roots:roots.length ? roots : [realPath(top.trim())], gitCommonDir:realPath(common.trim()), description:`Repository ${top.trim()}`};
33
+ const selected = realPath(top.trim());
34
+ return {kind:'repo', roots:[selected], excludedRoots:worktreeRoots(trees).filter(root=>root!==selected), gitCommonDir:realPath(common.trim()), description:`Worktree ${selected}`};
35
35
  }
36
36
  }
37
37
  return {kind:'dir', roots:[root], gitCommonDir:null, description:`Directory ${root}`};
@@ -41,8 +41,7 @@ export async function refreshScope(scope, git) {
41
41
  if (scope.kind !== 'repo') return scope;
42
42
  const output = await git(scope.roots[0], GIT_ALLOWED[2]);
43
43
  if (output === null) return scope;
44
- const roots = worktreeRoots(output);
45
- return roots.length ? {...scope, roots} : scope;
44
+ return {...scope, excludedRoots:worktreeRoots(output).filter(root=>!scope.roots.includes(root))};
46
45
  }
47
46
 
48
47
  export function inScope(scope, cwd) {
@@ -51,7 +50,8 @@ export function inScope(scope, cwd) {
51
50
  if (!cache) { cache = new Map(); scopeCaches.set(scope, cache); }
52
51
  if (cache.has(cwd)) return cache.get(cwd);
53
52
  const candidates = [path.resolve(cwd), realPath(cwd)];
54
- const inside = scope.roots.some(root => [path.resolve(root), realPath(root)].some(base => candidates.some(candidate => candidate === base || candidate.startsWith(base.endsWith(path.sep) ? base : base + path.sep))));
53
+ const contains = root => [path.resolve(root), realPath(root)].some(base => candidates.some(candidate => candidate === base || candidate.startsWith(base.endsWith(path.sep) ? base : base + path.sep)));
54
+ const inside = scope.roots.some(contains) && !(scope.excludedRoots ?? []).some(root=>scope.roots.some(base=>root.startsWith(base+path.sep)) && contains(root));
55
55
  cache.set(cwd, inside);
56
56
  return inside;
57
57
  }