sprag-cli 3.130.0 → 3.132.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +11 -1
- package/mac/SpragBar.swift +3141 -0
- package/mod/sprag-statusline/hooks/register.tsx +58 -3
- package/package.json +2 -1
- package/src/agent-activity.js +485 -0
- package/src/agent-detail.js +266 -0
- package/src/agent-usage.js +410 -0
- package/src/agent-warnings.js +128 -0
- package/src/bar-app.js +330 -0
- package/src/bar-rules.js +133 -0
- package/src/bar-settings.js +78 -0
- package/src/brief.js +40 -13
- package/src/caps-cache.js +4 -3
- package/src/claude-version.js +38 -0
- package/src/codex/budget.js +1 -1
- package/src/codex/delegation-diagnostics.js +1 -1
- package/src/codex/panel.js +1 -7
- package/src/commands/bar.js +370 -0
- package/src/commands/delegate.js +1 -0
- package/src/commands/feedback.js +2 -2
- package/src/commands/install.js +4 -1
- package/src/commands/last.js +1 -1
- package/src/commands/route-scan.js +39 -1
- package/src/commands/team.js +1 -1
- package/src/commands/uninstall.js +2 -0
- package/src/commands/upgrade.js +1 -1
- package/src/compact-window.js +1 -1
- package/src/cowork-sync.js +1 -1
- package/src/ctx-window-cache.js +11 -8
- package/src/delegation-agents.js +41 -2
- package/src/doc2md.cjs +1 -0
- package/src/gateway-auth.js +1 -0
- package/src/handoff.js +1 -0
- package/src/history.js +18 -1
- package/src/installer.js +43 -0
- package/src/korean-style.js +1 -1
- package/src/permission-secrets.js +1 -1
- package/src/session-cache.js +19 -0
- package/src/statusline-guard.js +17 -0
- package/src/team-sync.js +1 -1
- package/src/transcript-lines.js +1 -1
- package/src/window-labels.js +11 -0
|
@@ -48,6 +48,17 @@ function readPackageVersion() {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* macOS menu bar app: start it, or start building it, when a session starts.
|
|
53
|
+
* Called after the hook has printed everything, and it can neither throw nor
|
|
54
|
+
* delay the hook past a few file reads: the compile runs in a detached child.
|
|
55
|
+
*/
|
|
56
|
+
async function startBarApp() {
|
|
57
|
+
try {
|
|
58
|
+
(await import('../bar-app.js')).ensureBar();
|
|
59
|
+
} catch (e) { debug('route-scan:bar-app', e); }
|
|
60
|
+
}
|
|
61
|
+
|
|
51
62
|
export async function run({ args, hasFlag, numArg }) {
|
|
52
63
|
const rs = await import('../route-scan.js');
|
|
53
64
|
const { userLanguage } = await import('../config.js');
|
|
@@ -292,6 +303,22 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
292
303
|
return;
|
|
293
304
|
}
|
|
294
305
|
|
|
306
|
+
// --hook-compact: SessionStart hook for source "compact". Tells the model
|
|
307
|
+
// that a context warning it received before the compaction is out of date.
|
|
308
|
+
// Read-only and instant: no scan, no cache read, no child process.
|
|
309
|
+
if (hasFlag('--hook-compact')) {
|
|
310
|
+
try {
|
|
311
|
+
const payload = readStdinJson() || {};
|
|
312
|
+
if (payload.source !== undefined && payload.source !== 'compact') return;
|
|
313
|
+
const { compactionNotice } = await import('../brief.js');
|
|
314
|
+
const text = compactionNotice({ sessionId: payload.session_id, lang });
|
|
315
|
+
if (text) console.log(text);
|
|
316
|
+
} catch (e) {
|
|
317
|
+
debug('route-scan:compact-notice', e);
|
|
318
|
+
}
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
295
322
|
// --hook: SessionStart hook mode. Never scans inline (session start must
|
|
296
323
|
// stay fast) — reads the cache, kicks a detached refresh when stale, and
|
|
297
324
|
// prints delegation-candidate context for the new session.
|
|
@@ -327,7 +354,14 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
327
354
|
// session start; this one uses whatever was already cached.
|
|
328
355
|
try { (await import('../preset-sync.js')).spawnPresetSyncIfDue(); } catch (e) { debug('route-scan:preset-sync', e); }
|
|
329
356
|
// Agent files come first so the ratchet-model.md rendered next names them.
|
|
330
|
-
|
|
357
|
+
let agentsFirstBlock = null;
|
|
358
|
+
let agentsSync = null;
|
|
359
|
+
let da = null;
|
|
360
|
+
try {
|
|
361
|
+
da = await import('../delegation-agents.js');
|
|
362
|
+
agentsSync = da.syncDelegationAgents();
|
|
363
|
+
} catch (e) { debug('route-scan:delegation-agents', e); }
|
|
364
|
+
try { if (da && agentsSync) agentsFirstBlock = da.firstInstallNotice(agentsSync, { lang }); } catch (e) { debug('route-scan:agents-first', e); }
|
|
331
365
|
// The session's project is passed so its rule-less file follows the
|
|
332
366
|
// routing switch as well (see syncAllFiles).
|
|
333
367
|
try {
|
|
@@ -449,10 +483,12 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
449
483
|
if (updateBlock) console.log(updateBlock);
|
|
450
484
|
if (monthlyResetBlock) console.log(monthlyResetBlock);
|
|
451
485
|
if (driftBlock) console.log(driftBlock);
|
|
486
|
+
if (agentsFirstBlock) console.log(agentsFirstBlock);
|
|
452
487
|
if (seedBlock) console.log(seedBlock);
|
|
453
488
|
if (doc2mdBlock) console.log(doc2mdBlock);
|
|
454
489
|
if (koreanBlock) console.log(koreanBlock);
|
|
455
490
|
if (cohesionBlock) console.log(cohesionBlock);
|
|
491
|
+
await startBarApp();
|
|
456
492
|
return; // nothing else to inject
|
|
457
493
|
}
|
|
458
494
|
if (secretsBlock) console.log(secretsBlock);
|
|
@@ -460,6 +496,7 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
460
496
|
if (updateBlock) console.log(updateBlock);
|
|
461
497
|
if (monthlyResetBlock) console.log(monthlyResetBlock);
|
|
462
498
|
if (driftBlock) console.log(driftBlock);
|
|
499
|
+
if (agentsFirstBlock) console.log(agentsFirstBlock);
|
|
463
500
|
if (seedBlock) console.log(seedBlock);
|
|
464
501
|
if (doc2mdBlock) console.log(doc2mdBlock);
|
|
465
502
|
// This text is injected straight into the model's context, so it must
|
|
@@ -541,6 +578,7 @@ export async function run({ args, hasFlag, numArg }) {
|
|
|
541
578
|
...reviewRules.map((r) => `health|${r.signature}|${r.scope}`),
|
|
542
579
|
]);
|
|
543
580
|
} catch (e) { debug('route-scan:seed-briefed', e); /* worst case is one duplicate brief */ }
|
|
581
|
+
await startBarApp();
|
|
544
582
|
return;
|
|
545
583
|
}
|
|
546
584
|
|
package/src/commands/team.js
CHANGED
|
@@ -233,7 +233,7 @@ function openInBrowser(url) {
|
|
|
233
233
|
const cmd = process.platform === 'darwin' ? 'open' : win ? 'cmd' : 'xdg-open';
|
|
234
234
|
const args = win ? ['/c', 'start', '', url] : [url];
|
|
235
235
|
try {
|
|
236
|
-
const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
|
|
236
|
+
const child = spawn(cmd, args, { detached: true, stdio: 'ignore', windowsHide: true });
|
|
237
237
|
child.on('error', () => {});
|
|
238
238
|
child.unref();
|
|
239
239
|
} catch { /* no opener on this machine */ }
|
|
@@ -29,6 +29,8 @@ export async function run({ hasFlag, args = [] }) {
|
|
|
29
29
|
// The Cowork copies and the settings.json exclude entry are ours too.
|
|
30
30
|
try { (await import('../cowork-sync.js')).removeCoworkRatchets(); } catch { /* uninstall goes on */ }
|
|
31
31
|
try { (await import('../delegation-agents.js')).removeDelegationAgents(); } catch { /* uninstall goes on */ }
|
|
32
|
+
// The menu bar app and what it compiled into the data directory.
|
|
33
|
+
try { (await import('../bar-app.js')).removeBarFiles(); } catch { /* uninstall goes on */ }
|
|
32
34
|
|
|
33
35
|
if (r.removed.length === 0) {
|
|
34
36
|
console.log(lang === 'ko' ? '설치된 항목이 없습니다.' : 'Nothing was installed.');
|
package/src/commands/upgrade.js
CHANGED
|
@@ -23,7 +23,7 @@ function runCommand(cmd) {
|
|
|
23
23
|
// Shell form: the upgrade command is a fixed string we composed ourselves
|
|
24
24
|
// (no user input reaches it), and `npm install -g` needs the user's PATH
|
|
25
25
|
// resolution to find the same npm that installed us.
|
|
26
|
-
const child = spawn(cmd, { shell: true, stdio: 'inherit' });
|
|
26
|
+
const child = spawn(cmd, { shell: true, stdio: 'inherit', windowsHide: true });
|
|
27
27
|
child.on('close', (code) => resolve(code === null ? 1 : code));
|
|
28
28
|
child.on('error', () => resolve(1));
|
|
29
29
|
});
|
package/src/compact-window.js
CHANGED
|
@@ -40,7 +40,7 @@ import { parseJsonText } from './json-text.js';
|
|
|
40
40
|
export const MODEL_SETTINGS_MIN_VERSION = '2.1.288';
|
|
41
41
|
|
|
42
42
|
/** Installed Claude Code version (`2.1.302`), or null when it cannot be read. */
|
|
43
|
-
export function claudeCodeVersion({ run = () => execFileSync('claude', ['--version'], { encoding: 'utf8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'] }) } = {}) {
|
|
43
|
+
export function claudeCodeVersion({ run = () => execFileSync('claude', ['--version'], { encoding: 'utf8', timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true }) } = {}) {
|
|
44
44
|
try {
|
|
45
45
|
const m = String(run()).match(/(\d+\.\d+\.\d+)/);
|
|
46
46
|
return m ? m[1] : null;
|
package/src/cowork-sync.js
CHANGED
|
@@ -204,7 +204,7 @@ const isOwned = (file) => { try { return firstLine(file) === COWORK_MARKER; } ca
|
|
|
204
204
|
// ---------- git exclude ----------
|
|
205
205
|
|
|
206
206
|
const git = (dir, args) => execFileSync('git', ['-C', dir, ...args], {
|
|
207
|
-
timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8',
|
|
207
|
+
timeout: 3000, stdio: ['ignore', 'pipe', 'ignore'], encoding: 'utf8', windowsHide: true,
|
|
208
208
|
}).trim();
|
|
209
209
|
|
|
210
210
|
function addGitExclude(dir) {
|
package/src/ctx-window-cache.js
CHANGED
|
@@ -32,9 +32,9 @@ export function ctxWindowCachePath() {
|
|
|
32
32
|
return join(userDataDir(), 'ctx-window.json');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function load() {
|
|
35
|
+
function load(path = ctxWindowCachePath()) {
|
|
36
36
|
try {
|
|
37
|
-
const s = JSON.parse(readFileSync(
|
|
37
|
+
const s = JSON.parse(readFileSync(path, 'utf8'));
|
|
38
38
|
return s && s.sessions && typeof s.sessions === 'object' && !Array.isArray(s.sessions) ? s : { sessions: {} };
|
|
39
39
|
} catch {
|
|
40
40
|
return { sessions: {} };
|
|
@@ -58,10 +58,13 @@ export function recordLiveWindow(sessionId, size, now = Date.now(), model = null
|
|
|
58
58
|
return true;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
|
|
61
|
+
/**
|
|
62
|
+
* The recorded window for a session, or null when the statusline never reported one.
|
|
63
|
+
* `file` reads another copy of the state file (`sprag bar` passes its own data folder's).
|
|
64
|
+
*/
|
|
65
|
+
export function liveWindowFor(sessionId, file = ctxWindowCachePath()) {
|
|
63
66
|
if (typeof sessionId !== 'string' || sessionId === '') return null;
|
|
64
|
-
const s = load().sessions[sessionId];
|
|
67
|
+
const s = load(file).sessions[sessionId];
|
|
65
68
|
return s && validSize(s.size) ? s.size : null;
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -98,10 +101,10 @@ export function liveWindowsByModel() {
|
|
|
98
101
|
.map((s) => ({ model: s.model, size: s.size, ts: s.ts }));
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
/** The model id a session's statusline payload reported, or null. */
|
|
102
|
-
export function liveModelFor(sessionId) {
|
|
104
|
+
/** The model id a session's statusline payload reported, or null. `file` is as in liveWindowFor. */
|
|
105
|
+
export function liveModelFor(sessionId, file = ctxWindowCachePath()) {
|
|
103
106
|
if (typeof sessionId !== 'string' || sessionId === '') return null;
|
|
104
|
-
const s = load().sessions[sessionId];
|
|
107
|
+
const s = load(file).sessions[sessionId];
|
|
105
108
|
return s && typeof s.model === 'string' && s.model !== '' ? s.model : null;
|
|
106
109
|
}
|
|
107
110
|
|
package/src/delegation-agents.js
CHANGED
|
@@ -17,6 +17,7 @@ import { join } from 'node:path';
|
|
|
17
17
|
import { claudeUserDir } from './paths.js';
|
|
18
18
|
import { loadConfig, saveConfig } from './config.js';
|
|
19
19
|
import { agentDefinitions, cliVersion, presetSource } from './presets-source.js';
|
|
20
|
+
import { AGENTS_LIVE_MIN_VERSION, agentsLoadMidSession, sessionClaudeVersion } from './claude-version.js';
|
|
20
21
|
|
|
21
22
|
export const OWNER_MARK = 'sprag:delegation-agent';
|
|
22
23
|
const MARK_LINE = `# managed by sprag (${OWNER_MARK}); edits are overwritten`;
|
|
@@ -100,16 +101,19 @@ export function removeDelegationAgents() {
|
|
|
100
101
|
if (f && isOwned(f.text)) { unlinkSync(p); removed.push(name); }
|
|
101
102
|
} catch { /* one file failing does not stop the rest */ }
|
|
102
103
|
}
|
|
103
|
-
return { written: [], unchanged: [], skipped: [], removed };
|
|
104
|
+
return { written: [], unchanged: [], skipped: [], removed, createdDir: false };
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
export function syncDelegationAgents({ agent = 'claude' } = {}) {
|
|
107
|
-
const res = { written: [], unchanged: [], skipped: [], removed: [] };
|
|
108
|
+
const res = { written: [], unchanged: [], skipped: [], removed: [], createdDir: false };
|
|
108
109
|
if (agent === 'codex') return res;
|
|
109
110
|
try {
|
|
110
111
|
if (loadConfig().delegationAgents === false) return removeDelegationAgents();
|
|
111
112
|
} catch { /* an unreadable config means the default, on */ }
|
|
112
113
|
const defs = definitions();
|
|
114
|
+
// Remembered before the loop: a Claude Code older than 2.1.326 does not see
|
|
115
|
+
// an agents folder that first appears mid-session (see claude-version.js).
|
|
116
|
+
const dirExisted = existsSync(agentsDir());
|
|
113
117
|
for (const def of defs) {
|
|
114
118
|
try {
|
|
115
119
|
const p = fileOf(def.name);
|
|
@@ -134,9 +138,44 @@ export function syncDelegationAgents({ agent = 'claude' } = {}) {
|
|
|
134
138
|
try { unlinkSync(fileOf(name)); res.removed.push(name); } catch { /* left for the next sync */ }
|
|
135
139
|
}
|
|
136
140
|
}
|
|
141
|
+
res.createdDir = !dirExisted && res.written.length > 0;
|
|
137
142
|
return res;
|
|
138
143
|
}
|
|
139
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Session-start notice for the first install of the agent files. Only a Claude
|
|
147
|
+
* Code older than AGENTS_LIVE_MIN_VERSION (or one whose version is unknown)
|
|
148
|
+
* needs it: it cannot find an agent created mid-session, so the model is told
|
|
149
|
+
* to delegate through general-purpose for this one session. Returns null when
|
|
150
|
+
* the folder was not just created or the running version finds the agents.
|
|
151
|
+
*/
|
|
152
|
+
export function firstInstallNotice(result, { lang = 'ko', env = process.env } = {}) {
|
|
153
|
+
if (!result || !result.createdDir || !Array.isArray(result.written) || result.written.length === 0) return null;
|
|
154
|
+
if (agentsLoadMidSession(sessionClaudeVersion(env)) === true) return null;
|
|
155
|
+
const names = result.written.join(', ');
|
|
156
|
+
const n = result.written.length;
|
|
157
|
+
return lang === 'ko'
|
|
158
|
+
? `✇ [sprag agents] 이번 세션을 시작하면서 위임 전용 에이전트 ${n}개(${names})를 처음 설치했습니다. Claude Code ${AGENTS_LIVE_MIN_VERSION} 미만은 세션 도중 처음 생긴 에이전트를 찾지 못하므로 이 세션에서는 이 이름으로 위임하지 말고 general-purpose에 model 인자(haiku, sonnet, opus)를 넘기십시오. 다음 세션부터는 에이전트 이름으로 위임합니다.`
|
|
159
|
+
: `✇ [sprag agents] This session start installed ${n} delegation-only agent(s) for the first time (${names}). Claude Code before ${AGENTS_LIVE_MIN_VERSION} does not find an agent first created mid-session, so in this session do not delegate by these names: use general-purpose with a model argument (haiku, sonnet, opus). From the next session on, delegate by agent name.`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The line `sprag install` and `delegate agents on` print after the first
|
|
164
|
+
* install of the agent files: whether a session already running can use them.
|
|
165
|
+
* One copy here so the two commands cannot drift apart.
|
|
166
|
+
*/
|
|
167
|
+
export function firstInstallCliLine({ lang = 'ko', env = process.env } = {}) {
|
|
168
|
+
const version = sessionClaudeVersion(env);
|
|
169
|
+
if (agentsLoadMidSession(version) === true) {
|
|
170
|
+
return lang === 'ko'
|
|
171
|
+
? ` 실행 중인 Claude Code 세션에서도 바로 쓸 수 있습니다(Claude Code ${version}).`
|
|
172
|
+
: ` Running Claude Code sessions can use them right away (Claude Code ${version}).`;
|
|
173
|
+
}
|
|
174
|
+
return lang === 'ko'
|
|
175
|
+
? ` 실행 중인 Claude Code 세션이 바로 찾으려면 ${AGENTS_LIVE_MIN_VERSION} 이상이어야 합니다. 그보다 오래된 버전은 새 세션부터 씁니다.`
|
|
176
|
+
: ` A running Claude Code session finds them right away only on ${AGENTS_LIVE_MIN_VERSION} or later; older versions pick them up from the next session.`;
|
|
177
|
+
}
|
|
178
|
+
|
|
140
179
|
export function delegationAgentStatus() {
|
|
141
180
|
let enabled = true;
|
|
142
181
|
try { enabled = loadConfig().delegationAgents !== false; } catch { /* default on */ }
|
package/src/doc2md.cjs
CHANGED
|
@@ -478,6 +478,7 @@ function spawnFigConvert(fig2md, filePath) {
|
|
|
478
478
|
encoding: 'utf8',
|
|
479
479
|
timeout: CONVERT_TIMEOUT_MS,
|
|
480
480
|
maxBuffer: MAX_MARKDOWN_BYTES * 4,
|
|
481
|
+
windowsHide: true,
|
|
481
482
|
});
|
|
482
483
|
if (run.error && run.error.code === 'ETIMEDOUT') return { ok: false, reason: 'timeout' };
|
|
483
484
|
if (run.status !== 0) {
|
package/src/gateway-auth.js
CHANGED
|
@@ -104,6 +104,7 @@ export function keyFromApiKeyHelper(cwd = process.cwd()) {
|
|
|
104
104
|
timeout: HELPER_TIMEOUT_MS,
|
|
105
105
|
stdio: ['ignore', 'pipe', 'ignore'],
|
|
106
106
|
env: { ...process.env, APIKEY_HELPER_NONINTERACTIVE: '1' },
|
|
107
|
+
windowsHide: true,
|
|
107
108
|
});
|
|
108
109
|
// 진행 로그를 함께 출력하는 헬퍼가 있으므로 마지막 비어 있지 않은 줄을 취합니다.
|
|
109
110
|
const token = out.trim().split(/\r?\n/).filter(Boolean).pop();
|
package/src/handoff.js
CHANGED
package/src/history.js
CHANGED
|
@@ -57,6 +57,23 @@ function loadState() {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
/**
|
|
61
|
+
* The chip the statusline last announced and when, for readers outside this
|
|
62
|
+
* module (the menu bar snapshot). Missing or broken file gives both null.
|
|
63
|
+
* loadState() keeps its own shape: it also carries the cap_* slots.
|
|
64
|
+
*/
|
|
65
|
+
export function readChipState(dir = BASE_DIR) {
|
|
66
|
+
try {
|
|
67
|
+
const s = JSON.parse(readFileSync(join(dir, 'last-chip.json'), 'utf8'));
|
|
68
|
+
return {
|
|
69
|
+
chip: typeof s?.chip === 'string' ? s.chip : null,
|
|
70
|
+
ts: typeof s?.ts === 'string' ? s.ts : null,
|
|
71
|
+
};
|
|
72
|
+
} catch {
|
|
73
|
+
return { chip: null, ts: null };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
function saveState(state) {
|
|
61
78
|
ensureDir(BASE_DIR);
|
|
62
79
|
writeFileSync(STATE_PATH, JSON.stringify(state) + '\n');
|
|
@@ -93,7 +110,7 @@ function chipKo(chip) {
|
|
|
93
110
|
* "session {ID}: CODE_A, CODE_B"
|
|
94
111
|
* Anything else falls through unchanged.
|
|
95
112
|
*/
|
|
96
|
-
function detailKo(detail) {
|
|
113
|
+
export function detailKo(detail) {
|
|
97
114
|
if (!detail) return detail;
|
|
98
115
|
// The threshold moved from 200k to 500k in v3.32, so both spellings have to
|
|
99
116
|
// resolve: history files written by older versions still carry the old one.
|
package/src/installer.js
CHANGED
|
@@ -573,6 +573,48 @@ export function installSessionStartHook() {
|
|
|
573
573
|
return { path: file, action: 'created' };
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
+
/**
|
|
577
|
+
* SessionStart hook for source "compact". The context warning sprag injects at
|
|
578
|
+
* 80% and 95% can reach the user after the compaction it warned about has run;
|
|
579
|
+
* this hook tells the model that the earlier warning is out of date.
|
|
580
|
+
*
|
|
581
|
+
* Its own group with matcher `compact`: the `startup|clear` group may hold hooks
|
|
582
|
+
* that are not ours, and widening its matcher would change when those run.
|
|
583
|
+
*/
|
|
584
|
+
const ROUTE_SCAN_COMPACT_HOOK_COMMAND = `${CLI} route-scan --hook-compact`;
|
|
585
|
+
|
|
586
|
+
export function installCompactNoticeHook() {
|
|
587
|
+
const dir = claudeUserDir();
|
|
588
|
+
const file = join(dir, 'settings.json');
|
|
589
|
+
mkdirSync(dir, { recursive: true });
|
|
590
|
+
|
|
591
|
+
const read = readSettings(file);
|
|
592
|
+
if (read.state === 'unusable') return { path: file, action: 'skipped', reason: read.reason };
|
|
593
|
+
const settings = read.settings;
|
|
594
|
+
|
|
595
|
+
const hooksProblem = ensureHooksObject(settings);
|
|
596
|
+
if (hooksProblem) return { path: file, action: 'skipped', reason: hooksProblem };
|
|
597
|
+
if (settings.hooks.SessionStart !== undefined && !Array.isArray(settings.hooks.SessionStart)) {
|
|
598
|
+
return { path: file, action: 'skipped', reason: 'hooks.SessionStart is not an array — fix settings.json manually' };
|
|
599
|
+
}
|
|
600
|
+
const list = Array.isArray(settings.hooks.SessionStart) ? settings.hooks.SessionStart : [];
|
|
601
|
+
const already = list.some((m) =>
|
|
602
|
+
Array.isArray(m?.hooks) && m.hooks.some((h) => isOurSubcommand(h?.command, 'route-scan', '--hook-compact')),
|
|
603
|
+
);
|
|
604
|
+
if (already) return { path: file, action: 'exists' };
|
|
605
|
+
|
|
606
|
+
list.push({
|
|
607
|
+
matcher: 'compact',
|
|
608
|
+
hooks: [{ type: 'command', command: ROUTE_SCAN_COMPACT_HOOK_COMMAND, timeout: 10 }],
|
|
609
|
+
});
|
|
610
|
+
settings.hooks.SessionStart = list;
|
|
611
|
+
{
|
|
612
|
+
const writeProblem = writeSettings(file, settings);
|
|
613
|
+
if (writeProblem) return { path: file, action: 'skipped', reason: writeProblem };
|
|
614
|
+
}
|
|
615
|
+
return { path: file, action: 'created' };
|
|
616
|
+
}
|
|
617
|
+
|
|
576
618
|
// Registers the UserPromptSubmit hook that briefs mid-session state changes
|
|
577
619
|
// (ctx tier crossings, new route candidates, rule-health flips) into the
|
|
578
620
|
// conversation — the model cannot see statusline chips, so without this a
|
|
@@ -1474,6 +1516,7 @@ export function installAll({ force = false } = {}) {
|
|
|
1474
1516
|
skill: installSkill({ force }),
|
|
1475
1517
|
statusline: installStatusline({ force }),
|
|
1476
1518
|
sessionStartHook: installSessionStartHook(),
|
|
1519
|
+
compactNoticeHook: installCompactNoticeHook(),
|
|
1477
1520
|
delegationHook: installDelegationHook(),
|
|
1478
1521
|
delegationMeterMod: installDelegationMeterMod(),
|
|
1479
1522
|
statuslineMod: installStatuslineMod(),
|
package/src/korean-style.js
CHANGED
|
@@ -89,7 +89,7 @@ export function koreanLocaleDetected({ env = process.env, platform = process.pla
|
|
|
89
89
|
// locale is the only reliable signal there.
|
|
90
90
|
const { execFileSync } = require('node:child_process');
|
|
91
91
|
const out = execFileSync('defaults', ['read', '-g', 'AppleLocale'], {
|
|
92
|
-
encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'],
|
|
92
|
+
encoding: 'utf8', timeout: 2000, stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true,
|
|
93
93
|
}).trim();
|
|
94
94
|
if (/^ko(_|-|$)/i.test(out)) return true;
|
|
95
95
|
} catch { /* `defaults` missing or slow — treat as "not detected" */ }
|
|
@@ -95,7 +95,7 @@ export function scanSettingsFile(path) {
|
|
|
95
95
|
/** Run git without a shell. Returns the exit status, or null when git cannot answer (missing, timed out). */
|
|
96
96
|
function gitStatus(args, cwd) {
|
|
97
97
|
try {
|
|
98
|
-
execFileSync('git', args, { cwd, stdio: 'ignore', timeout: GIT_TIMEOUT_MS });
|
|
98
|
+
execFileSync('git', args, { cwd, stdio: 'ignore', timeout: GIT_TIMEOUT_MS, windowsHide: true });
|
|
99
99
|
return 0;
|
|
100
100
|
} catch (e) {
|
|
101
101
|
return typeof e.status === 'number' ? e.status : null;
|
package/src/session-cache.js
CHANGED
|
@@ -155,6 +155,25 @@ export function putCached(cache, file, session) {
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* The last summary stored for a transcript path, whatever the file looks like
|
|
160
|
+
* now. It skips the (mtimeMs, size) check that getCached does, so it can be a
|
|
161
|
+
* few seconds behind a transcript that is still growing: that is fine for a
|
|
162
|
+
* display, and it must never feed an aggregate.
|
|
163
|
+
*
|
|
164
|
+
* @returns {SessionSummary|null} null when the path has no entry
|
|
165
|
+
*/
|
|
166
|
+
export function peekCached(cache, path, projectDir = '') {
|
|
167
|
+
const e = cache?.entries?.[path];
|
|
168
|
+
if (!e || !e.s) return null;
|
|
169
|
+
try {
|
|
170
|
+
return deserialize(e.s, path, projectDir);
|
|
171
|
+
} catch (err) {
|
|
172
|
+
debug('session-cache:peek', err);
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
158
177
|
/**
|
|
159
178
|
* A session re-aggregated from a fixed point in time (the start of the month),
|
|
160
179
|
* stored beside the full summary of the same file. One slot per entry: the
|
package/src/statusline-guard.js
CHANGED
|
@@ -117,6 +117,23 @@ export function readLastRender({ dir = userDataDir(), key = 'default' } = {}) {
|
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Epoch ms of the newest statusline render of any session, or null. A render
|
|
122
|
+
* rewrites its own entry every refresh, so a stale value means no statusline
|
|
123
|
+
* is running.
|
|
124
|
+
*/
|
|
125
|
+
export function newestRenderAt({ dir = userDataDir() } = {}) {
|
|
126
|
+
try {
|
|
127
|
+
let best = null;
|
|
128
|
+
for (const v of Object.values(readLastMap(dir))) {
|
|
129
|
+
if (v && Number.isFinite(v.at) && (best === null || v.at > best)) best = v.at;
|
|
130
|
+
}
|
|
131
|
+
return best;
|
|
132
|
+
} catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
120
137
|
export function writeLastRender({
|
|
121
138
|
dir = userDataDir(), key = 'default', text, now = Date.now(), maxAgeMs = DAY_MS,
|
|
122
139
|
} = {}) {
|
package/src/team-sync.js
CHANGED
|
@@ -715,7 +715,7 @@ const DARWIN_TO_MACOS = { 20: '11', 21: '12', 22: '13', 23: '14', 24: '15', 25:
|
|
|
715
715
|
|
|
716
716
|
export function deviceInfo({
|
|
717
717
|
platform = process.platform, release = osRelease(),
|
|
718
|
-
exec = (cmd, args) => execFileSync(cmd, args, { timeout: 2000, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }),
|
|
718
|
+
exec = (cmd, args) => execFileSync(cmd, args, { timeout: 2000, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true }),
|
|
719
719
|
readText = (f) => readFileSync(f, 'utf8'),
|
|
720
720
|
} = {}) {
|
|
721
721
|
let os = String(platform);
|
package/src/transcript-lines.js
CHANGED
|
@@ -80,7 +80,7 @@ async function* zstdLines(filePath) {
|
|
|
80
80
|
|
|
81
81
|
// Node before 22.15 has no zstd in zlib; the binary is the only way to read these files there.
|
|
82
82
|
async function* zstdBinaryLines(filePath) {
|
|
83
|
-
const child = spawn('zstd', ['-dc', '--', filePath], { stdio: ['ignore', 'pipe', 'ignore'] });
|
|
83
|
+
const child = spawn('zstd', ['-dc', '--', filePath], { stdio: ['ignore', 'pipe', 'ignore'], windowsHide: true });
|
|
84
84
|
// Registered before any await, so a very fast exit cannot slip past it.
|
|
85
85
|
const closed = new Promise((resolve) => child.once('close', (code) => resolve(code)));
|
|
86
86
|
// A missing binary reports through 'error', not through stdout, so settle that first.
|
package/src/window-labels.js
CHANGED
|
@@ -78,3 +78,14 @@ export function labelForKey(key) {
|
|
|
78
78
|
const short = deriveShort(key);
|
|
79
79
|
return { short, long: deriveLong(key), icon: '⏱', narrowIcon: '◕', usageLabel: short };
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Label for a Codex rate-limit window from its length in minutes: 300 is `5H`,
|
|
84
|
+
* 10080 is `7D`, 90 is `90m`. Without a usable length it falls back to `fallback`.
|
|
85
|
+
*/
|
|
86
|
+
export function windowLabel(minutes, fallback) {
|
|
87
|
+
if (!Number.isFinite(minutes) || minutes <= 0) return fallback;
|
|
88
|
+
if (minutes % 1440 === 0) return `${minutes / 1440}D`;
|
|
89
|
+
if (minutes % 60 === 0) return `${minutes / 60}H`;
|
|
90
|
+
return `${minutes}m`;
|
|
91
|
+
}
|