@yunhozz/arc 0.3.5 → 0.4.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 +133 -94
- package/README.md +56 -21
- package/claude/skill/SKILL.md +1 -1
- package/claude/skill/references/commit.md +10 -8
- package/claude/skill/references/coordination.md +6 -4
- package/claude/skill/references/handoff-prep.md +12 -12
- package/claude/skill/references/handoff.md +2 -0
- package/claude/skill/references/planning.md +8 -8
- package/claude/skill/references/verification.md +6 -6
- package/codex/skill/SKILL.md +1 -1
- package/codex/skill/references/commit.md +10 -8
- package/codex/skill/references/coordination.md +6 -4
- package/codex/skill/references/handoff-prep.md +12 -12
- package/codex/skill/references/handoff.md +2 -0
- package/codex/skill/references/planning.md +8 -8
- package/codex/skill/references/verification.md +6 -6
- package/gemini/GEMINI.md +8 -0
- package/gemini/agents/arc-implementer.md +37 -0
- package/gemini/agents/arc-planner.md +47 -0
- package/gemini/agents/arc-qa.md +37 -0
- package/gemini/agents/arc-reviewer.md +39 -0
- package/gemini/agents/arc-scouter.md +38 -0
- package/gemini/instructions.md +4 -0
- package/gemini/skill/SKILL.md +78 -0
- package/gemini/skill/models.toml +23 -0
- package/gemini/skill/references/arc-visual-companion.md +28 -0
- package/gemini/skill/references/commit.md +55 -0
- package/gemini/skill/references/coordination.md +149 -0
- package/gemini/skill/references/git-recovery.md +34 -0
- package/gemini/skill/references/handoff-prep.md +110 -0
- package/gemini/skill/references/handoff.md +227 -0
- package/gemini/skill/references/limits.md +31 -0
- package/gemini/skill/references/planning.md +168 -0
- package/gemini/skill/references/verification.md +155 -0
- package/gemini/skill/references/worktree-creation.md +8 -0
- package/lib/color/palette.mjs +6 -0
- package/lib/installer/acquisition.mjs +7 -5
- package/lib/installer/install-mode.mjs +49 -26
- package/lib/installer/install.mjs +3 -2
- package/lib/installer/manifest.mjs +20 -14
- package/lib/installer/plan.mjs +24 -21
- package/lib/installer/preset.mjs +9 -8
- package/lib/installer/role-routing.mjs +160 -81
- package/lib/installer/runtime-assets.mjs +2 -0
- package/lib/installer/runtime-config.mjs +3 -0
- package/lib/installer/skill-sources.mjs +4 -3
- package/lib/installer/superpowers.mjs +2 -1
- package/lib/installer/target-errors.mjs +1 -0
- package/lib/installer/targets.mjs +14 -6
- package/lib/installer/uninstall.mjs +5 -4
- package/lib/installer/upgrade-state.mjs +14 -10
- package/lib/installer/upgrade.mjs +9 -5
- package/lib/management/operations.mjs +96 -48
- package/lib/management/status.mjs +10 -8
- package/lib/management/update.mjs +8 -7
- package/lib/models/catalog-gemini.mjs +48 -0
- package/lib/models/catalog.mjs +27 -12
- package/lib/models/config.mjs +23 -22
- package/lib/models/gemini-models.json +12 -0
- package/lib/models/profiles.mjs +7 -5
- package/lib/models/static-catalog.mjs +13 -14
- package/lib/npm/upgrade.mjs +2 -2
- package/lib/platforms/availability.mjs +98 -0
- package/lib/platforms/claude.mjs +14 -0
- package/lib/platforms/codex.mjs +16 -0
- package/lib/platforms/formats/gemini-markdown.mjs +48 -0
- package/lib/platforms/formats/markdown.mjs +39 -0
- package/lib/platforms/formats/toml.mjs +39 -0
- package/lib/platforms/gemini.mjs +14 -0
- package/lib/platforms/index.mjs +27 -0
- package/lib/policy/placement.mjs +4 -4
- package/lib/policy/render.mjs +13 -8
- package/lib/policy/role-policy.json +40 -21
- package/lib/prompts/agent-fragments.json +71 -1
- package/lib/prompts/render.mjs +32 -11
- package/lib/runtime/bootstrap.mjs +1 -1
- package/lib/runtime/cooperative-schema.mjs +0 -23
- package/lib/runtime/cooperative.mjs +13 -34
- package/lib/runtime/evaluate.mjs +3 -69
- package/lib/runtime/gemini-stream.mjs +32 -0
- package/lib/runtime/git-evidence.mjs +0 -98
- package/lib/runtime/identity.mjs +2 -1
- package/lib/runtime/local-cli.mjs +14 -24
- package/lib/runtime/operations.mjs +2 -2
- package/lib/runtime/platform-registry.mjs +130 -0
- package/lib/runtime/role-bridge-args.mjs +57 -2
- package/lib/runtime/role-bridge.mjs +86 -65
- package/lib/runtime/role-dispatch-policy.mjs +17 -7
- package/lib/runtime/role-dispatch-store.mjs +20 -14
- package/lib/runtime/role-observe.mjs +1 -0
- package/lib/runtime/role-routing-config.mjs +36 -9
- package/lib/runtime/role-routing.mjs +62 -29
- package/lib/runtime/role-supervisor.mjs +114 -49
- package/lib/runtime/schema.mjs +5 -4
- package/lib/tui/app.mjs +84 -35
- package/lib/tui/custom-preset.mjs +114 -68
- package/lib/tui/derive-install-plan.mjs +19 -0
- package/lib/tui/diagram.mjs +68 -0
- package/lib/tui/mode.mjs +77 -0
- package/lib/tui/render.mjs +47 -16
- package/lib/tui/setup.mjs +168 -100
- package/lib/tui/terminal.mjs +9 -6
- package/lib/watch/anchor-store.mjs +44 -0
- package/lib/watch/dispatch.mjs +3 -3
- package/lib/watch/index.mjs +37 -24
- package/lib/watch/model.mjs +1 -0
- package/lib/watch/normalize-claude.mjs +50 -10
- package/lib/watch/normalize-codex.mjs +79 -5
- package/lib/watch/render.mjs +30 -13
- package/lib/watch/scope.mjs +2 -1
- package/lib/watch/status-line.mjs +51 -0
- package/lib/watch/tail.mjs +27 -0
- package/lib/watch/watcher.mjs +193 -53
- package/package.json +2 -1
- package/scripts/update-manifest.mjs +2 -2
- package/shared/skill/runtime/bootstrap.mjs +1 -1
- package/shared/skill/runtime/cooperative-schema.mjs +0 -23
- package/shared/skill/runtime/cooperative.mjs +13 -34
- package/shared/skill/runtime/evaluate.mjs +3 -69
- package/shared/skill/runtime/gemini-stream.mjs +32 -0
- package/shared/skill/runtime/git-evidence.mjs +0 -98
- package/shared/skill/runtime/identity.mjs +2 -1
- package/shared/skill/runtime/local-cli.mjs +14 -24
- package/shared/skill/runtime/operations.mjs +2 -2
- package/shared/skill/runtime/platform-registry.mjs +130 -0
- package/shared/skill/runtime/role-bridge-args.mjs +57 -2
- package/shared/skill/runtime/role-bridge.mjs +86 -65
- package/shared/skill/runtime/role-dispatch-policy.mjs +17 -7
- package/shared/skill/runtime/role-dispatch-store.mjs +20 -14
- package/shared/skill/runtime/role-observe.mjs +1 -0
- package/shared/skill/runtime/role-policy.json +40 -21
- package/shared/skill/runtime/role-routing-config.mjs +36 -9
- package/shared/skill/runtime/role-routing.mjs +62 -29
- package/shared/skill/runtime/role-supervisor.mjs +114 -49
- package/shared/skill/runtime/schema.mjs +5 -4
package/lib/watch/index.mjs
CHANGED
|
@@ -2,10 +2,12 @@ import os from 'node:os';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import {parseWatchArgs} from './args.mjs';
|
|
4
4
|
import {resolveConfigHome} from '../runtime/local-cli.mjs';
|
|
5
|
+
import {DEFAULT_PLATFORM_REGISTRY} from '../runtime/platform-registry.mjs';
|
|
5
6
|
import {createWatcher} from './watcher.mjs';
|
|
6
7
|
import {resolveScope} from './scope.mjs';
|
|
7
8
|
import {createGitRunner} from './git.mjs';
|
|
8
9
|
import {renderHuman, renderJson} from './render.mjs';
|
|
10
|
+
import {watchLocationLabel, statusBlockLines} from './status-line.mjs';
|
|
9
11
|
import {WATCH_LIMITS as L} from './model.mjs';
|
|
10
12
|
|
|
11
13
|
export {parseWatchArgs};
|
|
@@ -26,9 +28,11 @@ Output:
|
|
|
26
28
|
--width <n> Maximum line width; one-line events are clipped, messages and file lists wrap (default: terminal width, or 200)
|
|
27
29
|
--help Show this help
|
|
28
30
|
|
|
31
|
+
Events are scoped by each session's working directory at that point; a session that moves into another worktree appears in that worktree's watch.
|
|
32
|
+
Skills and plugin tools in use are shown as SKILL and PLUGIN lines.
|
|
29
33
|
User and agent messages and file paths are shown in full; other events use one line.
|
|
30
34
|
Tool and command outputs are never shown; common secret patterns are masked.
|
|
31
|
-
A
|
|
35
|
+
A status block on the last lines shows the watched path and, while a turn is in progress, a spinner (TTY only).
|
|
32
36
|
Codex Desktop sessions are not included.
|
|
33
37
|
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
38
|
Press Ctrl-L to clear the screen (TTY only) and Ctrl-C to stop.`;
|
|
@@ -49,8 +53,9 @@ export async function runWatch(argv, io = {}) {
|
|
|
49
53
|
if (options.help) { output.write(WATCH_HELP + '\n'); return 0; }
|
|
50
54
|
if (io.signal?.aborted) return 0;
|
|
51
55
|
const userHome = io.userHome ?? os.homedir(), homes = {codex:null,claude:null}, disabled = [];
|
|
52
|
-
|
|
53
|
-
|
|
56
|
+
const registry = io.registry ?? DEFAULT_PLATFORM_REGISTRY;
|
|
57
|
+
for (const {id:platform} of registry.byAnchorOrder()) {
|
|
58
|
+
try { homes[platform] = resolveConfigHome(platform, {userHome,env,cwd,runtimePlatforms:registry}); }
|
|
54
59
|
catch (cause) { if (options.platforms.includes(platform)) disabled.push(`${platform} disabled: ${cause.message}`); }
|
|
55
60
|
}
|
|
56
61
|
options.platforms = options.platforms.filter(platform => homes[platform] !== null);
|
|
@@ -60,14 +65,17 @@ export async function runWatch(argv, io = {}) {
|
|
|
60
65
|
let width, watcher, timer, stopped = false, active;
|
|
61
66
|
const wrap = Boolean(!options.json && (output.isTTY || options.width != null));
|
|
62
67
|
const color = Boolean(output.isTTY && !options.json && !env.NO_COLOR);
|
|
63
|
-
const
|
|
68
|
+
const blockEnabled = Boolean(output.isTTY && !options.json);
|
|
69
|
+
const fancy = color && env.TERM !== 'dumb';
|
|
70
|
+
const label = watchLocationLabel({mode:options.mode,dir:options.dir ?? cwd,session:options.session,home:userHome});
|
|
64
71
|
const keysEnabled = Boolean(input.isTTY && output.isTTY && !options.json && typeof input.setRawMode === 'function');
|
|
65
72
|
const frames = ['⠋','⠙','⠹','⠸','⠼','⠴','⠦','⠧','⠇','⠏'];
|
|
66
|
-
let
|
|
67
|
-
const
|
|
68
|
-
if (!
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
let drawnLines = 0, frame = 0, tick = 0;
|
|
74
|
+
const eraseBlock = () => {
|
|
75
|
+
if (!drawnLines) return;
|
|
76
|
+
const erase = '\r\x1b[2K' + '\x1b[1A\x1b[2K'.repeat(drawnLines - 1);
|
|
77
|
+
drawnLines = 0;
|
|
78
|
+
output.write(erase);
|
|
71
79
|
};
|
|
72
80
|
const resize = () => { width = options.width ?? (output.isTTY ? Math.max(L.ttyWidthMin, output.columns || L.ttyWidthMin) : L.nonTtyWidth); };
|
|
73
81
|
resize();
|
|
@@ -83,7 +91,7 @@ export async function runWatch(argv, io = {}) {
|
|
|
83
91
|
try { input.setRawMode(false); } catch {}
|
|
84
92
|
input.pause();
|
|
85
93
|
}
|
|
86
|
-
|
|
94
|
+
eraseBlock();
|
|
87
95
|
if (timer !== undefined) unschedule(timer);
|
|
88
96
|
for (const signal of signals) proc.removeListener(signal, onSignal);
|
|
89
97
|
io.signal?.removeEventListener('abort', onSignal);
|
|
@@ -99,12 +107,14 @@ export async function runWatch(argv, io = {}) {
|
|
|
99
107
|
};
|
|
100
108
|
const onSignal = () => stop();
|
|
101
109
|
const onError = cause => stop(cause.code === 'EPIPE' ? 0 : 1, cause);
|
|
102
|
-
const
|
|
103
|
-
if (!stopped &&
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
110
|
+
const drawBlock = () => {
|
|
111
|
+
if (!stopped && blockEnabled) {
|
|
112
|
+
const busy = Boolean(watcher?.busy?.());
|
|
113
|
+
const blockWidth = Math.min(width, output.columns || width);
|
|
114
|
+
const lines = statusBlockLines({label,busy,glyph:frames[frame],tick,color,fancy,width:blockWidth});
|
|
115
|
+
if (busy) frame = (frame + 1) % frames.length;
|
|
116
|
+
drawnLines = lines.length;
|
|
117
|
+
output.write(lines.join('\n'));
|
|
108
118
|
}
|
|
109
119
|
};
|
|
110
120
|
const onKey = chunk => {
|
|
@@ -113,19 +123,19 @@ export async function runWatch(argv, io = {}) {
|
|
|
113
123
|
if (byte === 0x03) stop();
|
|
114
124
|
else if (byte === 0x0c) {
|
|
115
125
|
output.write('\x1b[H\x1b[2J\x1b[3J');
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
drawnLines = 0;
|
|
127
|
+
drawBlock();
|
|
118
128
|
}
|
|
119
129
|
}
|
|
120
130
|
};
|
|
121
131
|
const write = events => {
|
|
122
132
|
if (stopped) return;
|
|
123
|
-
|
|
133
|
+
eraseBlock();
|
|
124
134
|
for (const event of events) {
|
|
125
135
|
if (stopped) break;
|
|
126
136
|
output.write((options.json ? renderJson(event) : renderHuman(event,{width,color,verbose:options.verbose,wrap})) + '\n');
|
|
127
137
|
}
|
|
128
|
-
|
|
138
|
+
drawBlock();
|
|
129
139
|
};
|
|
130
140
|
for (const signal of signals) proc.on(signal, onSignal);
|
|
131
141
|
output.on('error', onError);
|
|
@@ -141,7 +151,7 @@ export async function runWatch(argv, io = {}) {
|
|
|
141
151
|
}
|
|
142
152
|
const scope = await resolveScope({mode:options.mode,dir:options.dir ?? cwd,session:options.session,git});
|
|
143
153
|
if (stopped) return;
|
|
144
|
-
watcher = createWatcher({options,homes,scope,git,now});
|
|
154
|
+
watcher = createWatcher({options,homes:{...homes,user:userHome},scope,git,now,registry});
|
|
145
155
|
for (const text of disabled) {
|
|
146
156
|
const ts = new Date(now()).toISOString();
|
|
147
157
|
write([{v:1,ts,observedAt:ts,source:'watch',kind:'notice',label:'watch',text}]);
|
|
@@ -151,9 +161,12 @@ export async function runWatch(argv, io = {}) {
|
|
|
151
161
|
nextPollAt = now() + L.filePollMs;
|
|
152
162
|
timer = schedule(() => {
|
|
153
163
|
if (stopped || ticking) return;
|
|
164
|
+
tick++;
|
|
154
165
|
if (now() < nextPollAt) {
|
|
155
|
-
|
|
156
|
-
|
|
166
|
+
if (watcher.busy()) {
|
|
167
|
+
eraseBlock();
|
|
168
|
+
drawBlock();
|
|
169
|
+
}
|
|
157
170
|
return;
|
|
158
171
|
}
|
|
159
172
|
nextPollAt = now() + L.filePollMs;
|
|
@@ -161,7 +174,7 @@ export async function runWatch(argv, io = {}) {
|
|
|
161
174
|
active = (async () => { try { write(await watcher.tick()); } finally { ticking = false; } })();
|
|
162
175
|
active.catch(onError);
|
|
163
176
|
return active;
|
|
164
|
-
},
|
|
177
|
+
}, blockEnabled ? 100 : L.filePollMs);
|
|
165
178
|
})();
|
|
166
179
|
active.catch(onError);
|
|
167
180
|
});
|
package/lib/watch/model.mjs
CHANGED
|
@@ -9,6 +9,7 @@ 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
|
+
cwdProbeBytes:65536, maxKnown:512,
|
|
12
13
|
jsonTextMax:1000, wrapMinBody:20, toolCacheMax:512, defaultTail:20,
|
|
13
14
|
maxTail:1000, widthMin:40, widthMax:2000, ttyWidthMin:60, nonTtyWidth:200,
|
|
14
15
|
gitTimeoutMs:10000, spinnerIdleMs:300000,
|
|
@@ -5,7 +5,11 @@ const object = value => value !== null && typeof value === 'object' && !Array.is
|
|
|
5
5
|
const string = value => typeof value === 'string';
|
|
6
6
|
|
|
7
7
|
export function createClaudeState() {
|
|
8
|
-
return {modelSeen:false, tools:new Map(), writes:new Map(), deletes:new Map()};
|
|
8
|
+
return {modelSeen:false, tools:new Map(), skills:new Map(), pendingCommand:null, writes:new Map(), deletes:new Map(), cwd:undefined};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function claudeLineCwd(obj) {
|
|
12
|
+
return object(obj) && string(obj.cwd) && obj.cwd ? obj.cwd : undefined;
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
export function parseClaudeHead(obj) {
|
|
@@ -26,10 +30,18 @@ export function parseClaudeAgentMeta(obj) {
|
|
|
26
30
|
} catch { return null; }
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
function
|
|
30
|
-
|
|
33
|
+
function contentText(content) {
|
|
34
|
+
return string(content) ? content : Array.isArray(content)
|
|
31
35
|
? content.filter(block => block?.type === 'text' && string(block.text)).map(block => block.text).join('') : '';
|
|
32
|
-
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function userText(content) {
|
|
39
|
+
return contentText(content).replace(/<(system-reminder|command-[\w-]+|local-command-[\w-]+|task-notification|bash-input|bash-stdout|bash-stderr)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/gi, '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function skillFields(skill) {
|
|
43
|
+
const idx = skill.indexOf(':');
|
|
44
|
+
return {skill, ...(idx > 0 ? {plugin:skill.slice(0,idx)} : {})};
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
// Parse only literal shell words. Expansions, pipelines and other shell syntax
|
|
@@ -94,13 +106,17 @@ function deletionPaths(command, cwd) {
|
|
|
94
106
|
return [...new Set(paths)];
|
|
95
107
|
}
|
|
96
108
|
|
|
97
|
-
/** State contains bounded tool-name, pending-Write and pending-deletion caches. */
|
|
109
|
+
/** State contains bounded tool-name, skill, pending-Write and pending-deletion caches. */
|
|
98
110
|
export function normalizeClaudeLine(obj, state) {
|
|
99
111
|
try {
|
|
100
|
-
if (!object(obj) || !['user','assistant'].includes(obj.type)
|
|
112
|
+
if (!object(obj) || !['user','assistant'].includes(obj.type)) return [];
|
|
101
113
|
if (!object(state) || !(state.tools instanceof Map)) return [];
|
|
114
|
+
if (!(state.skills instanceof Map)) state.skills = new Map();
|
|
102
115
|
if (!(state.writes instanceof Map)) state.writes = new Map();
|
|
103
116
|
if (!(state.deletes instanceof Map)) state.deletes = new Map();
|
|
117
|
+
const pendingCommand = state.pendingCommand;
|
|
118
|
+
state.pendingCommand = null;
|
|
119
|
+
if (!object(obj.message)) return [];
|
|
104
120
|
const events = [];
|
|
105
121
|
const emit = (kind, fields={}) => {
|
|
106
122
|
const event = {kind, ...fields};
|
|
@@ -110,6 +126,14 @@ export function normalizeClaudeLine(obj, state) {
|
|
|
110
126
|
const message = obj.message;
|
|
111
127
|
const blocks = Array.isArray(message.content) ? message.content : [];
|
|
112
128
|
if (obj.type === 'user') {
|
|
129
|
+
const rawText = contentText(message.content);
|
|
130
|
+
const command = /<command-name>([^<]*)<\/command-name>/.exec(rawText);
|
|
131
|
+
if (pendingCommand && obj.isMeta === true && rawText.startsWith('Base directory for this skill:')) {
|
|
132
|
+
emit('tool', {tool:pendingCommand.name, ...skillFields(pendingCommand.name.replace(/^\//,'')),
|
|
133
|
+
...(pendingCommand.args.trim() ? {text:pendingCommand.args} : {})});
|
|
134
|
+
} else if (command) {
|
|
135
|
+
state.pendingCommand = {name:command[1], args:/<command-args>([\s\S]*?)<\/command-args>/.exec(rawText)?.[1] ?? ''};
|
|
136
|
+
}
|
|
113
137
|
if (obj.isCompactSummary === true) {
|
|
114
138
|
const text = string(message.content) ? message.content : blocks
|
|
115
139
|
.filter(block => block?.type === 'text' && string(block.text)).map(block => block.text).join('');
|
|
@@ -125,7 +149,7 @@ export function normalizeClaudeLine(obj, state) {
|
|
|
125
149
|
state.deletes.delete(id);
|
|
126
150
|
if (block.is_error === true) {
|
|
127
151
|
const tool = state.tools.get(id);
|
|
128
|
-
emit('tool_failed', string(tool) ? {tool} : {});
|
|
152
|
+
emit('tool_failed', string(tool) ? {tool, ...state.skills.get(id)} : {});
|
|
129
153
|
} else if (deleted && obj.toolUseResult?.interrupted !== true && !obj.toolUseResult?.backgroundTaskId) {
|
|
130
154
|
emit('file_delete', {paths:deleted});
|
|
131
155
|
} else if (pending) {
|
|
@@ -153,16 +177,24 @@ export function normalizeClaudeLine(obj, state) {
|
|
|
153
177
|
else if (block.type === 'tool_use' && string(block.name)) {
|
|
154
178
|
const name = block.name;
|
|
155
179
|
if (string(block.id)) {
|
|
180
|
+
state.skills.delete(block.id);
|
|
156
181
|
state.tools.delete(block.id);
|
|
157
182
|
state.tools.set(block.id, name);
|
|
158
183
|
while (state.tools.size > WATCH_LIMITS.toolCacheMax) state.tools.delete(state.tools.keys().next().value);
|
|
159
184
|
}
|
|
160
185
|
const input = object(block.input) ? block.input : {};
|
|
161
|
-
if (name === '
|
|
186
|
+
if (name === 'Skill' && string(input.skill)) {
|
|
187
|
+
const fields = skillFields(input.skill);
|
|
188
|
+
if (string(block.id)) {
|
|
189
|
+
state.skills.set(block.id, fields);
|
|
190
|
+
while (state.skills.size > WATCH_LIMITS.toolCacheMax) state.skills.delete(state.skills.keys().next().value);
|
|
191
|
+
}
|
|
192
|
+
emit('tool', {tool:name, ...fields, ...(string(input.args) && input.args ? {text:input.args} : {})});
|
|
193
|
+
} else if (name === 'Bash') {
|
|
162
194
|
emit('command', string(input.command) ? {text:input.command} : {});
|
|
163
195
|
if (string(block.id)) {
|
|
164
196
|
state.deletes.delete(block.id);
|
|
165
|
-
const paths = input.run_in_background === true ? [] : deletionPaths(input.command,obj.cwd);
|
|
197
|
+
const paths = input.run_in_background === true ? [] : deletionPaths(input.command,string(obj.cwd) ? obj.cwd : state.cwd);
|
|
166
198
|
if (paths.length) state.deletes.set(block.id, paths);
|
|
167
199
|
while (state.deletes.size > WATCH_LIMITS.toolCacheMax) state.deletes.delete(state.deletes.keys().next().value);
|
|
168
200
|
}
|
|
@@ -183,7 +215,15 @@ export function normalizeClaudeLine(obj, state) {
|
|
|
183
215
|
emit('tool', {tool:name, ...(target === undefined ? {} : {text:target})});
|
|
184
216
|
} else if (name === 'SubagentHandback' && string(input.message) && input.message) {
|
|
185
217
|
emit('agent', {text:input.message});
|
|
186
|
-
} else
|
|
218
|
+
} else {
|
|
219
|
+
let plugin;
|
|
220
|
+
if (name.startsWith('mcp__plugin_')) {
|
|
221
|
+
const parts = name.split('__');
|
|
222
|
+
const rest = parts[1].slice('plugin_'.length), i = rest.indexOf('_');
|
|
223
|
+
if (parts.length >= 3 && i > 0) plugin = rest.slice(0,i);
|
|
224
|
+
}
|
|
225
|
+
emit('tool', {tool:name, ...(plugin === undefined ? {} : {plugin})});
|
|
226
|
+
}
|
|
187
227
|
if (name === 'SubagentHandback' && !turnEnded) {
|
|
188
228
|
emit('turn_end');
|
|
189
229
|
turnEnded = true;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {WATCH_LIMITS} from './model.mjs';
|
|
3
|
+
|
|
1
4
|
const object = value => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
2
5
|
const string = value => typeof value === 'string';
|
|
3
6
|
const strings = values => values.filter(string);
|
|
4
7
|
const optional = fields => Object.fromEntries(Object.entries(fields).filter(([,value]) => value !== undefined));
|
|
5
8
|
|
|
9
|
+
export function createCodexState() {
|
|
10
|
+
return {announced:new Set(), hostRoots:[], cwd:undefined};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function codexLineCwd(obj) {
|
|
14
|
+
if (!object(obj) || !object(obj.payload)) return undefined;
|
|
15
|
+
const p = obj.payload;
|
|
16
|
+
let cwd;
|
|
17
|
+
if (obj.type === 'session_meta' || obj.type === 'turn_context') cwd = p.cwd;
|
|
18
|
+
else if (obj.type === 'event_msg' && p.type === 'thread_settings_applied' && object(p.thread_settings)) cwd = p.thread_settings.cwd;
|
|
19
|
+
return string(cwd) && cwd ? cwd : undefined;
|
|
20
|
+
}
|
|
21
|
+
|
|
6
22
|
export function parseCodexMeta(obj) {
|
|
7
23
|
try {
|
|
8
24
|
if (obj?.type !== 'session_meta' || !object(obj.payload)) return null;
|
|
@@ -60,15 +76,58 @@ function splitChangePaths(changes) {
|
|
|
60
76
|
return {added:unique(added),changed:unique(changed),deleted:unique(deleted)};
|
|
61
77
|
}
|
|
62
78
|
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
const under = (file, root) => file === root || file.startsWith(root + path.sep);
|
|
80
|
+
|
|
81
|
+
function hostSkillRoots(body, userHome) {
|
|
82
|
+
const roots = [];
|
|
83
|
+
for (const line of body.split('\n')) {
|
|
84
|
+
const match = /^\s*`?r\d+`?\s*=\s*`?([^`]+?)`?\s*$/.exec(line);
|
|
85
|
+
if (!match) continue;
|
|
86
|
+
let root = match[1];
|
|
87
|
+
if (root === '~' || root.startsWith('~/')) {
|
|
88
|
+
if (!string(userHome) || !userHome) continue;
|
|
89
|
+
root = path.join(userHome, root.slice(2));
|
|
90
|
+
}
|
|
91
|
+
if (!path.isAbsolute(root)) continue;
|
|
92
|
+
roots.push(root);
|
|
93
|
+
if (roots.length >= WATCH_LIMITS.toolCacheMax) break;
|
|
94
|
+
}
|
|
95
|
+
return roots;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function commandSkills(item, state, codexHome) {
|
|
99
|
+
const cache = string(codexHome) && codexHome ? path.join(codexHome,'plugins','cache') : undefined;
|
|
100
|
+
const roots = [...state.hostRoots];
|
|
101
|
+
if (cache) roots.push(path.join(codexHome,'skills'), cache);
|
|
102
|
+
return item.parsed_cmd.map(parsed => {
|
|
103
|
+
if (parsed?.type !== 'read' || !string(parsed.path)) return undefined;
|
|
104
|
+
const cwd = item.cwd ?? state.cwd;
|
|
105
|
+
if (!path.isAbsolute(parsed.path) && (!string(cwd) || !cwd)) return undefined;
|
|
106
|
+
const file = path.isAbsolute(parsed.path) ? path.resolve(parsed.path) : path.resolve(cwd, parsed.path);
|
|
107
|
+
if (path.basename(file) !== 'SKILL.md' || !roots.some(root => under(file, root))) return undefined;
|
|
108
|
+
const name = path.basename(path.dirname(file));
|
|
109
|
+
if (cache && under(file,cache)) {
|
|
110
|
+
const [marketplace,plugin,...rest] = path.relative(cache,file).split(path.sep);
|
|
111
|
+
if (marketplace && plugin && rest.length) return {skill:`${plugin}:${name}`,plugin:`${plugin}@${marketplace}`};
|
|
112
|
+
}
|
|
113
|
+
return {skill:name};
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Normalize one parsed rollout line; optional transcript state, no I/O. */
|
|
118
|
+
export function normalizeCodexLine(obj, state, {codexHome, userHome} = {}) {
|
|
65
119
|
try {
|
|
66
120
|
if (!object(obj)) return [];
|
|
121
|
+
const hasState = object(state);
|
|
67
122
|
const emit = (kind, fields={}) => [optional({ts:string(obj.timestamp) ? obj.timestamp : undefined, kind, ...fields})];
|
|
68
123
|
const text = value => string(value) ? value : undefined;
|
|
69
124
|
if (obj.type === 'session_meta') return parseCodexMeta(obj) ? emit('session') : [];
|
|
70
125
|
const p = obj.payload;
|
|
71
126
|
if (!object(p)) return [];
|
|
127
|
+
if (obj.type === 'world_state') {
|
|
128
|
+
if (hasState && string(p.state?.host_skills?.body)) state.hostRoots = hostSkillRoots(p.state.host_skills.body,userHome);
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
72
131
|
if (obj.type === 'response_item') {
|
|
73
132
|
if (!['function_call','custom_tool_call'].includes(p.type) || !string(p.name) || !p.name.includes('spawn_agent')) return [];
|
|
74
133
|
let args;
|
|
@@ -83,7 +142,9 @@ export function normalizeCodexLine(obj) {
|
|
|
83
142
|
const settings = p.thread_settings;
|
|
84
143
|
return emit('settings', {model:text(settings?.model), effort:text(settings?.reasoning_effort), approval:text(settings?.approval_policy)});
|
|
85
144
|
}
|
|
86
|
-
case 'task_started':
|
|
145
|
+
case 'task_started':
|
|
146
|
+
if (hasState) state.announced.clear();
|
|
147
|
+
return emit('turn_start');
|
|
87
148
|
case 'task_complete': return p.error ? emit('turn_failed', {text:text(p.error.message)}) : emit('turn_end');
|
|
88
149
|
case 'turn_aborted': return emit('turn_end', {text:`aborted: ${text(p.reason) ?? ''}`});
|
|
89
150
|
case 'exec_approval_request': return emit('approval', {text:commandText(p.command)});
|
|
@@ -102,7 +163,20 @@ export function normalizeCodexLine(obj) {
|
|
|
102
163
|
const summary = Array.isArray(item.summary_text) ? strings(item.summary_text).join('') : '';
|
|
103
164
|
return summary ? emit('reasoning', {text:summary}) : [];
|
|
104
165
|
}
|
|
105
|
-
case 'CommandExecution':
|
|
166
|
+
case 'CommandExecution': {
|
|
167
|
+
const fields = {text:commandText(item.command), exitCode:Number.isFinite(item.exit_code) ? item.exit_code : undefined};
|
|
168
|
+
if (!hasState || !Array.isArray(item.parsed_cmd) || (Number.isFinite(item.exit_code) && item.exit_code !== 0)) return emit('command', fields);
|
|
169
|
+
const skills = commandSkills(item,state,codexHome);
|
|
170
|
+
const events = [];
|
|
171
|
+
for (const skill of skills) {
|
|
172
|
+
if (!skill || state.announced.has(skill.skill)) continue;
|
|
173
|
+
events.push(...emit('tool', {tool:'read',...skill}));
|
|
174
|
+
state.announced.add(skill.skill);
|
|
175
|
+
if (state.announced.size > WATCH_LIMITS.toolCacheMax) state.announced.delete(state.announced.values().next().value);
|
|
176
|
+
}
|
|
177
|
+
if (skills.length && skills.every(Boolean)) fields.skillOnly = true;
|
|
178
|
+
return [...events,...emit('command',fields)];
|
|
179
|
+
}
|
|
106
180
|
case 'FileChange':
|
|
107
181
|
case 'PatchApply': {
|
|
108
182
|
const {added,changed,deleted} = splitChangePaths(item.changes);
|
|
@@ -113,7 +187,7 @@ export function normalizeCodexLine(obj) {
|
|
|
113
187
|
...(deleted.length ? emit('file_delete', {paths:deleted}) : []),
|
|
114
188
|
];
|
|
115
189
|
}
|
|
116
|
-
case 'McpToolCall': return emit('tool', {tool:strings([item.server,item.tool]).join('.')});
|
|
190
|
+
case 'McpToolCall': return emit('tool', {tool:strings([item.server,item.tool]).join('.'),plugin:text(item.pluginId)});
|
|
117
191
|
case 'Extension':
|
|
118
192
|
return item.kind === 'web.search' ? emit('tool', {tool:'web.search', text:text(item.query)}) : emit('other', {text:`Extension:${text(item.kind) ?? ''}`});
|
|
119
193
|
default: return emit('other', {text:item.type});
|
package/lib/watch/render.mjs
CHANGED
|
@@ -5,8 +5,13 @@ import {realPath} from './scope.mjs';
|
|
|
5
5
|
|
|
6
6
|
const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
|
|
7
7
|
const roleLabels = new Map([
|
|
8
|
-
['scouter','
|
|
9
|
-
['qa','QA'], ['reviewer','
|
|
8
|
+
['scouter','SCOUTER'], ['planner','PLANNER'], ['implementer','IMPLEMENTER'],
|
|
9
|
+
['qa','QA'], ['reviewer','REVIEWER'], ['orchestrator','ORCHESTRATOR'],
|
|
10
|
+
]);
|
|
11
|
+
const roleBadgeColors = new Map([
|
|
12
|
+
['scouter','1;38;5;16;48;5;117'], ['planner','1;38;5;231;48;5;98'],
|
|
13
|
+
['implementer','1;38;5;16;48;5;214'], ['qa','1;38;5;16;48;5;228'],
|
|
14
|
+
['reviewer','1;38;5;231;48;5;161'], ['orchestrator','1;38;5;16;48;5;255'],
|
|
10
15
|
]);
|
|
11
16
|
const zeroWidth = /^[\u0300-\u036f\u200b-\u200f\ufe00-\ufe0f]+$/u;
|
|
12
17
|
const wide = /[\u1100-\u115f\u2e80-\u303e\u3041-\u33ff\u3400-\u4dbf\u4e00-\u9fff\ua000-\ua4cf\uac00-\ud7a3\uf900-\ufaff\ufe30-\ufe4f\uff00-\uff60\uffe0-\uffe6\u{1f300}-\u{1f64f}\u{1f900}-\u{1f9ff}\u{20000}-\u{3fffd}]/u;
|
|
@@ -56,7 +61,7 @@ export function wrapLine(text, avail) {
|
|
|
56
61
|
return lines.length ? lines : [''];
|
|
57
62
|
}
|
|
58
63
|
|
|
59
|
-
export const PLATFORM_COLORS = Object.freeze({codex:'36', claude:'38;5;208', other:'2'});
|
|
64
|
+
export const PLATFORM_COLORS = Object.freeze({codex:'36', claude:'38;5;208', gemini:'38;5;135', other:'2'});
|
|
60
65
|
|
|
61
66
|
// Compare both the lexical root and its real path (e.g. /tmp and /private/tmp).
|
|
62
67
|
export function displayPath(file, root) {
|
|
@@ -71,8 +76,9 @@ export function displayPath(file, root) {
|
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
export function tagColor(event) {
|
|
74
|
-
if (event.kind === '
|
|
75
|
-
|
|
79
|
+
if (event.kind === 'tool' && event.skill) return '38;5;110';
|
|
80
|
+
if (event.kind === 'tool' && event.plugin) return '38;5;175';
|
|
81
|
+
return ({command:'38;5;242', user:'1;35', agent:'32', file_change:'33', file_create:'38;5;69', file_delete:'31', tool:'38;5;101', spawn:'38;5;141',
|
|
76
82
|
dispatch:'38;5;137', approval:'1;4', turn_failed:'31', error:'31', tool_failed:'31'})[event.kind] ?? '2';
|
|
77
83
|
}
|
|
78
84
|
|
|
@@ -82,8 +88,9 @@ export function bodyColor(event) {
|
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
export function kindTag(event) {
|
|
85
|
-
if (event.kind === '
|
|
86
|
-
|
|
91
|
+
if (event.kind === 'tool' && event.skill) return 'SKILL';
|
|
92
|
+
if (event.kind === 'tool' && event.plugin) return 'PLUGIN';
|
|
93
|
+
return ({command:'CMD', session:'SESSION', settings:'SETTINGS', turn_start:'TURN', turn_end:'END',
|
|
87
94
|
turn_failed:'FAIL', user:'USER', agent:'AGENT', reasoning:'THINK', tool:'TOOL',
|
|
88
95
|
tool_failed:'TOOL!', file_change:'EDIT', file_create:'CREATE', file_delete:'DELETE', spawn:'SPAWN', approval:'APPROVE',
|
|
89
96
|
dispatch:'DISPATCH', error:'ERROR', other:'ITEM', notice:'NOTICE'})[event.kind] ?? 'ITEM';
|
|
@@ -91,6 +98,9 @@ export function kindTag(event) {
|
|
|
91
98
|
|
|
92
99
|
function eventText(event, verbose) {
|
|
93
100
|
if (event.kind === 'tool' || event.kind === 'tool_failed') {
|
|
101
|
+
if (event.kind === 'tool' && event.skill) return sanitizeText(event.skill);
|
|
102
|
+
if (event.kind === 'tool' && event.plugin) return [event.plugin, event.tool].map(sanitizeText).filter(Boolean).join(' ');
|
|
103
|
+
if (event.kind === 'tool_failed' && (event.skill || event.plugin)) return [event.tool, event.skill || event.plugin].map(sanitizeText).filter(Boolean).join(' ');
|
|
94
104
|
return [event.tool, event.text].map(sanitizeText).filter(Boolean).join(' ');
|
|
95
105
|
}
|
|
96
106
|
if (event.kind !== 'dispatch') return sanitizeText(event.text);
|
|
@@ -103,19 +113,24 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
103
113
|
let date = new Date(event.ts);
|
|
104
114
|
if (Number.isNaN(date.getTime())) date = new Date(event.observedAt);
|
|
105
115
|
const time = Number.isNaN(date.getTime()) ? '00:00:00' : date.toLocaleTimeString('en-GB', {hour12:false});
|
|
106
|
-
const platform = sanitizeText(event.source === 'watch' ? 'watch' : event.platform ?? 'arc').slice(0,6).padEnd(6);
|
|
116
|
+
const platform = sanitizeText(event.source === 'watch' ? 'watch' : event.platform?.toUpperCase() ?? 'arc').slice(0,6).padEnd(6);
|
|
107
117
|
const tag = sanitizeText(kindTag(event)).padEnd(8);
|
|
108
118
|
const prefix = `${time} ${platform} ${tag} `;
|
|
109
119
|
const message = MESSAGE_KINDS.includes(event.kind);
|
|
110
120
|
const fullLine = message || event.kind === 'file_change' || event.kind === 'file_create' || event.kind === 'file_delete';
|
|
111
121
|
const text = message ? sanitizeMessage(event.text) : eventText(event, verbose);
|
|
122
|
+
const paths = fullLine && !message ? (event.paths ?? []).map(file => sanitizeText(displayPath(file,event.root))).filter(Boolean) : [];
|
|
123
|
+
const listPaths = paths.length >= 2;
|
|
112
124
|
const bodyLines = message ? (text ? text.split('\n') : []) : fullLine
|
|
113
|
-
? [event.text, ...
|
|
125
|
+
? [sanitizeText(event.text), ...paths.map(file => listPaths ? '- ' + file : file)].filter(Boolean) : [];
|
|
114
126
|
const roleName = event.kind === 'agent' ? roleLabels.get(event.role) : undefined;
|
|
115
|
-
if (roleName && bodyLines.length) bodyLines
|
|
127
|
+
if (roleName && bodyLines.length) bodyLines.unshift(roleName);
|
|
116
128
|
const indent = ' '.repeat([...prefix].length);
|
|
117
129
|
const avail = width - Math.max([...prefix].length, displayWidth(prefix));
|
|
118
|
-
const lines = wrap && avail >= WATCH_LIMITS.wrapMinBody ? bodyLines.flatMap(
|
|
130
|
+
const lines = wrap && avail >= WATCH_LIMITS.wrapMinBody ? bodyLines.flatMap((line,i) =>
|
|
131
|
+
listPaths && paths.length && i >= bodyLines.length - paths.length
|
|
132
|
+
? wrapLine(line.slice(2),avail-2).map((piece,j) => (j ? ' ' : '- ') + piece)
|
|
133
|
+
: wrapLine(line,avail)) : bodyLines;
|
|
119
134
|
const bodyText = paintLine => lines.map((line,i) => !line ? '' : (i ? indent : '') + paintLine(line,i)).join('\n');
|
|
120
135
|
const plain = fullLine ? (message && !lines.length ? prefix.trimEnd() : prefix + bodyText(line => line)) : clipCodePoints(prefix + text, width).text;
|
|
121
136
|
if (!color || (!fullLine && [...prefix].length > width)) return plain;
|
|
@@ -127,7 +142,9 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
127
142
|
const clippedText = [...plain].slice([...prefix].length).join('');
|
|
128
143
|
if (message && !text) return `${time} ${paint(platform, platformColor)} ${paintedTag}`;
|
|
129
144
|
const body = fullLine ? bodyText((line,i) => {
|
|
130
|
-
if (roleName && i === 0)
|
|
145
|
+
if (roleName && i === 0) {
|
|
146
|
+
return paint(` ${line} `,roleBadgeColors.get(event.role));
|
|
147
|
+
}
|
|
131
148
|
return code ? paint(line,code) : line;
|
|
132
149
|
})
|
|
133
150
|
: code && clippedText ? paint(clippedText, code) : clippedText;
|
|
@@ -136,7 +153,7 @@ export function renderHuman(event, {width, color, verbose, wrap = false}) {
|
|
|
136
153
|
|
|
137
154
|
export function renderJson(event) {
|
|
138
155
|
const fields = ['ts','observedAt','platform','source','origin','sessionId','parentId','depth',
|
|
139
|
-
'label','role','dispatchId','workflowId','kind','text','truncated','exitCode','tool','paths','inferred',
|
|
156
|
+
'label','role','dispatchId','workflowId','kind','text','truncated','exitCode','tool','skill','plugin','paths','inferred',
|
|
140
157
|
'model','effort','approval','state','reasons','route','hostPlatform','cwd'];
|
|
141
158
|
const output = {v:1};
|
|
142
159
|
for (const key of fields) {
|
package/lib/watch/scope.mjs
CHANGED
|
@@ -60,5 +60,6 @@ export const normalizeSlug = value => value.replace(/[^A-Za-z0-9]/g, '-');
|
|
|
60
60
|
|
|
61
61
|
export function claudeDirPrefixes(scope) {
|
|
62
62
|
if (scope.kind === 'all' || scope.kind === 'session') return null;
|
|
63
|
-
|
|
63
|
+
const roots = scope.kind === 'repo' ? [...scope.roots, ...scope.excludedRoots ?? []] : scope.roots;
|
|
64
|
+
return [...new Set(roots.flatMap(root => [normalizeSlug(root), normalizeSlug(realPath(root))]))];
|
|
64
65
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import {gradientAt, shimmerIntensity, toAnsi256} from '../color/palette.mjs';
|
|
3
|
+
import {displayWidth} from './render.mjs';
|
|
4
|
+
import {sanitizeText} from './policy.mjs';
|
|
5
|
+
|
|
6
|
+
const graphemes = new Intl.Segmenter(undefined, {granularity:'grapheme'});
|
|
7
|
+
|
|
8
|
+
export function watchLocationLabel({mode, dir, session, home}) {
|
|
9
|
+
let label = dir;
|
|
10
|
+
if (session) label = `session ${session}`;
|
|
11
|
+
else if (mode === 'all') label = 'all directories';
|
|
12
|
+
else if (dir === home) label = '~';
|
|
13
|
+
else if (home && dir.startsWith(home + path.sep)) label = '~' + dir.slice(home.length);
|
|
14
|
+
return sanitizeText(label);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function shimmerText(text, tick) {
|
|
18
|
+
const characters = [...text];
|
|
19
|
+
return characters.map((character, i) => {
|
|
20
|
+
const base = gradientAt(i / Math.max(1, characters.length - 1));
|
|
21
|
+
const intensity = shimmerIntensity(i, 0, tick);
|
|
22
|
+
const rgb = base.map(value => Math.round(value + (255 - value) * intensity));
|
|
23
|
+
return `\x1b[38;5;${toAnsi256(rgb)}m${character}`;
|
|
24
|
+
}).join('') + '\x1b[0m';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function clipLine(text, columns) {
|
|
28
|
+
let result = '', used = 0, styled = false;
|
|
29
|
+
for (const part of text.split(/(\x1b\[[0-9;]*m)/)) {
|
|
30
|
+
if (part.startsWith('\x1b[')) {
|
|
31
|
+
result += part;
|
|
32
|
+
styled = true;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
for (const {segment} of graphemes.segment(part)) {
|
|
36
|
+
const size = displayWidth(segment);
|
|
37
|
+
if (used + size > columns) return result + (styled ? '\x1b[0m' : '');
|
|
38
|
+
result += segment;
|
|
39
|
+
used += size;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function statusBlockLines({label, busy, glyph, tick, color, fancy, width}) {
|
|
46
|
+
const lines = [color ? `\x1b[2m${label}\x1b[0m` : label];
|
|
47
|
+
if (busy) lines.push(color && fancy
|
|
48
|
+
? `\x1b[2m${glyph}\x1b[0m ${shimmerText('working…', tick)}`
|
|
49
|
+
: `${glyph} working…`);
|
|
50
|
+
return lines.map(line => clipLine(line, Math.max(0, width - 1)));
|
|
51
|
+
}
|
package/lib/watch/tail.mjs
CHANGED
|
@@ -52,6 +52,33 @@ export async function readTail(file, {maxBytes = WATCH_LIMITS.historyBytes} = {}
|
|
|
52
52
|
} finally { await handle.close(); }
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
export async function readLatestCwd(file, extract, {maxBytes = WATCH_LIMITS.cwdProbeBytes} = {}) {
|
|
56
|
+
let handle;
|
|
57
|
+
try {
|
|
58
|
+
handle = await fsp.open(file, 'r');
|
|
59
|
+
const {size} = await handle.stat(), start = Math.max(0, size - maxBytes);
|
|
60
|
+
const buffer = Buffer.alloc(size - start);
|
|
61
|
+
const {bytesRead} = await handle.read(buffer, 0, buffer.length, start);
|
|
62
|
+
let chunk = buffer.subarray(0, bytesRead);
|
|
63
|
+
if (start > 0) {
|
|
64
|
+
const newline = chunk.indexOf(10);
|
|
65
|
+
if (newline < 0) return undefined;
|
|
66
|
+
chunk = chunk.subarray(newline + 1);
|
|
67
|
+
}
|
|
68
|
+
const lines = [], parser = parserFor(line => lines.push(line));
|
|
69
|
+
parser.push(chunk);
|
|
70
|
+
parser.end();
|
|
71
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
72
|
+
const cwd = extract(lines[i]);
|
|
73
|
+
if (cwd !== undefined) return cwd;
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
if (!['ENOENT','EACCES'].includes(error.code)) throw error;
|
|
78
|
+
return undefined;
|
|
79
|
+
} finally { await handle?.close(); }
|
|
80
|
+
}
|
|
81
|
+
|
|
55
82
|
export async function readHead(file, {maxBytes, accept}) {
|
|
56
83
|
let handle;
|
|
57
84
|
try {
|