@sejuneoh/aitop 0.28.0 → 0.30.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/README.md +29 -3
- package/bin/aitop.mjs +32 -4
- package/package.json +1 -1
- package/src/attention.mjs +66 -0
- package/src/config.mjs +20 -6
- package/src/doctor.mjs +64 -21
- package/src/help.mjs +6 -3
- package/src/i18n.mjs +72 -16
- package/src/json.mjs +3 -0
- package/src/keys.mjs +2 -0
- package/src/line.mjs +62 -17
- package/src/notify.mjs +47 -9
- package/src/procs.mjs +47 -3
- package/src/resume.mjs +57 -0
- package/src/sources/antigravity.mjs +2 -0
- package/src/sources/claude-ledger.mjs +55 -45
- package/src/sources/claude-tracker.mjs +45 -2
- package/src/sources/claude.mjs +180 -52
- package/src/sources/codex-ledger.mjs +6 -2
- package/src/sources/codex.mjs +82 -20
- package/src/sources/common.mjs +10 -0
- package/src/sources/dirs.mjs +140 -0
- package/src/sources/projects.mjs +12 -10
- package/src/summary.mjs +29 -2
- package/src/text.mjs +2 -2
- package/src/ui/chrome.mjs +14 -2
- package/src/ui/detail.mjs +36 -1
package/src/sources/codex.mjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
// Codex CLI: 실행 중인 codex 프로세스의 작업 폴더와 ~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl 을 짝지어 읽는다.
|
|
2
|
+
// Codex 홈이 여럿이면(dirs.mjs) 모두 보고, 같은 rollout 파일 이름은 하나로 센다.
|
|
2
3
|
import { readdirSync, statSync, existsSync, realpathSync, openSync, readSync, closeSync } from 'node:fs';
|
|
3
4
|
import { join, basename } from 'node:path';
|
|
4
|
-
import { homedir } from 'node:os';
|
|
5
5
|
import { JsonlTail } from '../tail.mjs';
|
|
6
6
|
import { loadCache, markDirty } from '../cache.mjs';
|
|
7
7
|
import { canListProcesses, findProcesses, isCodex, openFiles, processStart } from '../procs.mjs';
|
|
8
|
-
import { addActivity, emptyTokens, parseTs, pushEvent, describeTool, isNoisePrompt } from './common.mjs';
|
|
8
|
+
import { addActivity, emptyTokens, parseTs, pushEvent, describeTool, isNoisePrompt, sessionName } from './common.mjs';
|
|
9
9
|
import { addChange, mergeFiles } from './files.mjs';
|
|
10
10
|
import { codexCost } from '../pricing.mjs';
|
|
11
11
|
import { parsePatch, extractPatch, patchSucceeded } from './patch.mjs';
|
|
12
12
|
import { debug, debugIo } from '../log.mjs';
|
|
13
13
|
import { lastName } from '../paths.mjs';
|
|
14
|
+
import { codexHomes, codexSessionRoots, dedupeBy, homeOf } from './dirs.mjs';
|
|
14
15
|
|
|
15
16
|
// 지시 탭에 쓰는 지시 목록은 최근 것만 남긴다.
|
|
16
17
|
const MAX_TURNS = 50;
|
|
17
18
|
|
|
18
|
-
const ROOT = join(process.env.CODEX_HOME ?? join(homedir(), '.codex'), 'sessions');
|
|
19
19
|
const RECENT_MS = 24 * 3600 * 1000;
|
|
20
20
|
// 프로세스 목록을 못 얻는 OS(지금은 Windows)에서는 이 시간 안에 바뀐 기록을 실행 중으로 본다.
|
|
21
21
|
// codex 는 답할 때마다 기록에 쓰므로, 답을 읽고 다음 지시를 쓰는 동안(대개 몇 분)은 남고 닫은 세션은 곧 빠진다.
|
|
@@ -27,10 +27,14 @@ const states = new Map();
|
|
|
27
27
|
export function dayDirs(days = 7) {
|
|
28
28
|
const dirs = [];
|
|
29
29
|
// 며칠 동안 켜 둔 세션도 시작한 날짜 폴더에 기록하므로 일주일치 폴더를 본다.
|
|
30
|
+
const roots = codexSessionRoots();
|
|
30
31
|
for (let back = 0; back < days; back++) {
|
|
31
32
|
const d = new Date(Date.now() - back * 86400_000);
|
|
32
|
-
const
|
|
33
|
-
|
|
33
|
+
const ymd = [String(d.getFullYear()), String(d.getMonth() + 1).padStart(2, '0'), String(d.getDate()).padStart(2, '0')];
|
|
34
|
+
for (const root of roots) {
|
|
35
|
+
const p = join(root, ...ymd);
|
|
36
|
+
if (existsSync(p)) dirs.push(p);
|
|
37
|
+
}
|
|
34
38
|
}
|
|
35
39
|
return dirs;
|
|
36
40
|
}
|
|
@@ -45,7 +49,7 @@ export function allDayDirs() {
|
|
|
45
49
|
return [];
|
|
46
50
|
}
|
|
47
51
|
};
|
|
48
|
-
for (const y of sub(
|
|
52
|
+
for (const root of codexSessionRoots()) for (const y of sub(root)) for (const m of sub(y)) dirs.push(...sub(m));
|
|
49
53
|
return dirs;
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -56,7 +60,13 @@ let listed = { at: 0, paths: [] };
|
|
|
56
60
|
function recentFiles() {
|
|
57
61
|
if (Date.now() - listed.at >= LIST_TTL_MS) {
|
|
58
62
|
const paths = [];
|
|
59
|
-
for (const dir of dayDirs())
|
|
63
|
+
for (const dir of dayDirs()) {
|
|
64
|
+
try {
|
|
65
|
+
for (const n of readdirSync(dir)) if (n.endsWith('.jsonl')) paths.push(join(dir, n));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
debugIo('codex', 'day folder read failed', e, dir);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
60
70
|
listed = { at: Date.now(), paths };
|
|
61
71
|
}
|
|
62
72
|
const out = [];
|
|
@@ -67,9 +77,10 @@ function recentFiles() {
|
|
|
67
77
|
} catch {
|
|
68
78
|
continue;
|
|
69
79
|
}
|
|
70
|
-
if (Date.now() - m < RECENT_MS) out.push({ path: p, mtime: m });
|
|
80
|
+
if (Date.now() - m < RECENT_MS) out.push({ key: basename(p), path: p, mtime: m });
|
|
71
81
|
}
|
|
72
|
-
|
|
82
|
+
// 같은 rollout 이 두 홈에 있으면 더 최근 쪽 하나만.
|
|
83
|
+
return dedupeBy(out).sort((a, b) => b.mtime - a.mtime);
|
|
73
84
|
}
|
|
74
85
|
|
|
75
86
|
// 하루 넘게 쉰 세션은 최근 파일 목록에 없다. 짝을 못 찾은 codex 프로세스에만 같은 작업 폴더에서 가장 최근에
|
|
@@ -102,17 +113,22 @@ function headCwd(path) {
|
|
|
102
113
|
return cwd;
|
|
103
114
|
}
|
|
104
115
|
|
|
105
|
-
|
|
116
|
+
// 홈마다 sessions 경로와 그 실제 경로(realpath). 처음 쓸 때 한 번 만든다.
|
|
117
|
+
let prefixes = null;
|
|
106
118
|
|
|
107
119
|
function isRollout(p) {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
if (prefixes === null) {
|
|
121
|
+
prefixes = [];
|
|
122
|
+
for (const root of codexSessionRoots()) {
|
|
123
|
+
prefixes.push(root + '/');
|
|
124
|
+
try {
|
|
125
|
+
prefixes.push(realpathSync(root) + '/');
|
|
126
|
+
} catch (e) {
|
|
127
|
+
debugIo('codex', 'sessions realpath failed', e, root);
|
|
128
|
+
}
|
|
113
129
|
}
|
|
114
130
|
}
|
|
115
|
-
return
|
|
131
|
+
return prefixes.some((x) => p.startsWith(x)) && /\/rollout-[^/]*\.jsonl$/.test(p);
|
|
116
132
|
}
|
|
117
133
|
|
|
118
134
|
// 날짜 폴더에 파일이 생기면 그 폴더의 수정 시각이 바뀐다.
|
|
@@ -170,10 +186,46 @@ function searchByCwd(pid, cwd, taken, startOf) {
|
|
|
170
186
|
return path;
|
|
171
187
|
}
|
|
172
188
|
|
|
173
|
-
|
|
189
|
+
// Codex 홈마다 session_index.jsonl(한 줄에 { id, thread_name, updated_at })을 따라 읽어 id → 이름.
|
|
190
|
+
// 이름을 바꿀 때마다 뒤에 붙으므로 같은 id 는 마지막 줄이 이긴다. 새로 붙은 줄만 읽는다.
|
|
191
|
+
// indexes: 홈 → { tail, names }. 홈끼리 이름을 섞지 않는다.
|
|
192
|
+
const indexes = new Map();
|
|
193
|
+
|
|
194
|
+
function readIndex(budget) {
|
|
195
|
+
for (const home of codexHomes()) {
|
|
196
|
+
let ix = indexes.get(home);
|
|
197
|
+
if (!ix) {
|
|
198
|
+
const names = new Map();
|
|
199
|
+
ix = { tail: new JsonlTail(join(home, 'session_index.jsonl')), names };
|
|
200
|
+
ix.tail.onReset = () => names.clear();
|
|
201
|
+
indexes.set(home, ix);
|
|
202
|
+
}
|
|
203
|
+
ix.tail.read((x) => {
|
|
204
|
+
if (typeof x?.id !== 'string') return;
|
|
205
|
+
const name = sessionName(x.thread_name);
|
|
206
|
+
if (name) ix.names.set(x.id, name);
|
|
207
|
+
else ix.names.delete(x.id);
|
|
208
|
+
}, budget);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// rollout 이 든 홈의 이름을 먼저, 없으면 다른 홈의 이름 (같은 세션을 다른 홈으로 옮긴 경우).
|
|
213
|
+
function indexName(path, id) {
|
|
214
|
+
const homes = codexHomes();
|
|
215
|
+
const own = homeOf(path, homes);
|
|
216
|
+
const first = own ? indexes.get(own)?.names.get(id) : undefined;
|
|
217
|
+
if (first) return first;
|
|
218
|
+
for (const h of homes) {
|
|
219
|
+
const n = indexes.get(h)?.names.get(id);
|
|
220
|
+
if (n) return n;
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const SAVED = ['id', 'threadName', 'cwd', 'branch', 'model', 'busy', 'tokens', 'context', 'window', 'events', 'lastTool', 'startedAt', 'lastKind', 'files', 'turns', 'turnCount', 'activity'];
|
|
174
226
|
|
|
175
227
|
function newState(path) {
|
|
176
|
-
const st = { tail: new JsonlTail(path), id: basename(path), cwd: null, branch: null, model: null, busy: false, tokens: emptyTokens(), context: 0, window: 0, events: [], lastTool: null, startedAt: null, pending: new Map(), lastKind: null, files: [], turns: [], turnCount: 0, patches: {}, activity: {} };
|
|
228
|
+
const st = { tail: new JsonlTail(path), id: basename(path), threadName: null, cwd: null, branch: null, model: null, busy: false, tokens: emptyTokens(), context: 0, window: 0, events: [], lastTool: null, startedAt: null, pending: new Map(), lastKind: null, files: [], turns: [], turnCount: 0, patches: {}, activity: {} };
|
|
177
229
|
const c = loadCache(path);
|
|
178
230
|
if (c) {
|
|
179
231
|
st.tail.offset = c.offset;
|
|
@@ -241,6 +293,10 @@ function applyLine(st, x) {
|
|
|
241
293
|
}
|
|
242
294
|
st.lastKind = 'prompt';
|
|
243
295
|
break;
|
|
296
|
+
// 이름 바꾸기 이벤트 (Codex /rename 등). 빈 이름이면 지운다.
|
|
297
|
+
case 'thread_name_updated':
|
|
298
|
+
st.threadName = sessionName(p.thread_name);
|
|
299
|
+
break;
|
|
244
300
|
case 'agent_message':
|
|
245
301
|
pushEvent(st, x.timestamp, 'reply', p.message);
|
|
246
302
|
st.lastKind = 'reply';
|
|
@@ -283,7 +339,7 @@ function applyLine(st, x) {
|
|
|
283
339
|
}
|
|
284
340
|
}
|
|
285
341
|
|
|
286
|
-
export const _test = { newState, applyLine, phaseOf, snapshot };
|
|
342
|
+
export const _test = { newState, applyLine, phaseOf, snapshot, readIndex, indexName };
|
|
287
343
|
|
|
288
344
|
export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf = processStart, canList = canListProcesses }) {
|
|
289
345
|
// 프로세스를 못 세면 숨기지 않고 최근에 바뀐 기록으로 판정한다 (pid 는 null).
|
|
@@ -299,6 +355,7 @@ export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf =
|
|
|
299
355
|
if (st.tail.read((x) => applyLine(st, x), budget)) markDirty(path, () => snapshot(st));
|
|
300
356
|
};
|
|
301
357
|
for (const f of files) read(f.path);
|
|
358
|
+
readIndex(budget);
|
|
302
359
|
|
|
303
360
|
const liveByPath = new Map();
|
|
304
361
|
const claim = (path, pid) => {
|
|
@@ -358,12 +415,17 @@ export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf =
|
|
|
358
415
|
// 가격표에 없는 모델은 비용을 ? 로 보인다.
|
|
359
416
|
const cost = codexCost(st.model, st.tokens);
|
|
360
417
|
const used = st.tokens.total > 0;
|
|
418
|
+
// 기록 안의 이름 바꾸기 이벤트가 먼저, 없으면 session_index.jsonl 의 thread_name.
|
|
419
|
+
const customName = st.threadName ?? indexName(f.path, st.id);
|
|
361
420
|
out.push({
|
|
362
421
|
tool: 'codex',
|
|
363
422
|
id: st.id,
|
|
364
423
|
pid: pid ?? null,
|
|
365
424
|
kind: 'interactive',
|
|
366
|
-
name: lastName(st.cwd) || 'codex',
|
|
425
|
+
name: customName ?? (lastName(st.cwd) || 'codex'),
|
|
426
|
+
customName,
|
|
427
|
+
// rollout 이 든 Codex 홈. 기본 홈이 아니면 이어 열기 명령에 CODEX_HOME 을 붙인다.
|
|
428
|
+
home: homeOf(f.path, codexHomes()),
|
|
367
429
|
cwd: st.cwd,
|
|
368
430
|
project: lastName(st.cwd),
|
|
369
431
|
branch: st.branch,
|
package/src/sources/common.mjs
CHANGED
|
@@ -192,6 +192,16 @@ function rawDescribeTool(name, input) {
|
|
|
192
192
|
export const DETAIL_MAX = 2048;
|
|
193
193
|
const ANSI = /\x1b(?:\[[0-?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\)|[@-Z\\-_])/g;
|
|
194
194
|
|
|
195
|
+
// 사용자가 붙인 세션 이름 (Claude /rename 의 custom-title, Codex thread_name). 사용자·모델이 쓴 글이라
|
|
196
|
+
// 색 순서·제어문자를 지우고 한 줄로 줄인 뒤 비밀값을 가리고 NAME_MAX 자에서 자른다. 비었으면 null.
|
|
197
|
+
export const NAME_MAX = 80;
|
|
198
|
+
export function sessionName(raw) {
|
|
199
|
+
if (typeof raw !== 'string') return null;
|
|
200
|
+
const one = mask(oneLine(raw.replace(ANSI, '')));
|
|
201
|
+
if (!one) return null;
|
|
202
|
+
return one.length > NAME_MAX ? one.slice(0, NAME_MAX - 1) + '…' : one;
|
|
203
|
+
}
|
|
204
|
+
|
|
195
205
|
export function toolDetail(name, input = {}) {
|
|
196
206
|
const raw = rawToolDetail(name, input);
|
|
197
207
|
if (!raw) return null;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// Claude 설정 폴더와 Codex 홈 폴더 목록 (#212). 프로필을 여러 개 쓰면 폴더도 여럿이다.
|
|
2
|
+
// 순서: AITOP_CLAUDE_DIRS·AITOP_CODEX_HOMES(aitop 전용, 구분자 path.delimiter) > 설정 파일(claudeDirs, codexHomes)
|
|
3
|
+
// > 물려받은 CLAUDE_CONFIG_DIR·CODEX_HOME (Claude Code·Codex 가 쓰는 변수라 설정 파일보다 낮다) > 기본(~/.claude, ~/.codex).
|
|
4
|
+
// 설정 파일까지 본 결과는 bin/aitop.mjs 가 setDataDirs 로 넘긴다. 넘기지 않으면(테스트) 환경 변수와 기본값만 본다.
|
|
5
|
+
// 비슷한 이름의 폴더를 저절로 읽지는 않는다. --doctor 가 후보로 안내만 한다 (candidateDirs).
|
|
6
|
+
import { readdirSync, realpathSync, statSync } from 'node:fs';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
8
|
+
import { delimiter, join, resolve } from 'node:path';
|
|
9
|
+
|
|
10
|
+
const isDir = (p) => {
|
|
11
|
+
try {
|
|
12
|
+
return statSync(p).isDirectory();
|
|
13
|
+
} catch {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// 'a:b' 를 경로 배열로. 빈 칸은 버린다. 남는 것이 없으면 undefined (정하지 않은 것으로 본다).
|
|
19
|
+
// 값 전체가 있는 폴더면 나누지 않는다 (예전처럼 경로 하나를 준 사용자의 경로에 : 가 들어 있어도 그대로).
|
|
20
|
+
export function splitPaths(v, delim = delimiter, exists = isDir) {
|
|
21
|
+
if (typeof v !== 'string') return undefined;
|
|
22
|
+
if (v.includes(delim) && v.trim() && exists(expandHome(v.trim()))) return [v.trim()];
|
|
23
|
+
const out = v.split(delim).map((s) => s.trim()).filter(Boolean);
|
|
24
|
+
return out.length ? out : undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 맨 앞 ~ 를 홈 폴더로 바꾼다.
|
|
28
|
+
export function expandHome(p, home = homedir()) {
|
|
29
|
+
return p === '~' ? home : /^~[\\/]/.test(p) ? join(home, p.slice(2)) : p;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 설정 파일에 쓸 수 있는 경로: 절대 경로이거나 ~ 로 시작.
|
|
33
|
+
export const pathLike = (p) => typeof p === 'string' && p.trim() !== '' && (/^~(?:$|[\\/])/.test(p) || /^(?:\/|[A-Za-z]:[\\/]|\\\\)/.test(p));
|
|
34
|
+
|
|
35
|
+
const realOf = (p) => {
|
|
36
|
+
try {
|
|
37
|
+
return realpathSync(p);
|
|
38
|
+
} catch {
|
|
39
|
+
return p;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// ~ 를 풀고 절대 경로로 바꾼 뒤, 실제 경로(realpath)가 같은 것은 처음 것만 남긴다.
|
|
44
|
+
export function uniqueDirs(list, home = homedir()) {
|
|
45
|
+
const seen = new Set();
|
|
46
|
+
const out = [];
|
|
47
|
+
for (const raw of list ?? []) {
|
|
48
|
+
const p = resolve(expandHome(String(raw), home));
|
|
49
|
+
const real = realOf(p);
|
|
50
|
+
if (seen.has(real)) continue;
|
|
51
|
+
seen.add(real);
|
|
52
|
+
out.push(p);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 환경 변수 이름: aitop 전용(설정 파일보다 높음)과 물려받는 것(설정 파일보다 낮음).
|
|
58
|
+
export const DIR_ENV = {
|
|
59
|
+
claude: { own: 'AITOP_CLAUDE_DIRS', inherited: 'CLAUDE_CONFIG_DIR', home: '.claude' },
|
|
60
|
+
codex: { own: 'AITOP_CODEX_HOMES', inherited: 'CODEX_HOME', home: '.codex' },
|
|
61
|
+
};
|
|
62
|
+
// 설정 파일 없이 고른 목록 (테스트, setDataDirs 를 부르기 전).
|
|
63
|
+
const envDirs = (k, env, home) => splitPaths(env[DIR_ENV[k].own]) ?? splitPaths(env[DIR_ENV[k].inherited]) ?? [join(home, DIR_ENV[k].home)];
|
|
64
|
+
export const defaultClaudeDirs = (env = process.env, home = homedir()) => envDirs('claude', env, home);
|
|
65
|
+
export const defaultCodexHomes = (env = process.env, home = homedir()) => envDirs('codex', env, home);
|
|
66
|
+
|
|
67
|
+
let chosen = null;
|
|
68
|
+
|
|
69
|
+
// 설정까지 반영한 목록을 정한다. 소스 모듈이 처음 읽기 전에 불러야 한다.
|
|
70
|
+
export function setDataDirs({ claude, codex } = {}) {
|
|
71
|
+
chosen = { claude: uniqueDirs(claude ?? defaultClaudeDirs()), codex: uniqueDirs(codex ?? defaultCodexHomes()) };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const pick = () => (chosen ??= { claude: uniqueDirs(defaultClaudeDirs()), codex: uniqueDirs(defaultCodexHomes()) });
|
|
75
|
+
export const claudeDirs = () => pick().claude;
|
|
76
|
+
export const codexHomes = () => pick().codex;
|
|
77
|
+
export const claudeProjectRoots = () => claudeDirs().map((d) => join(d, 'projects'));
|
|
78
|
+
export const codexSessionRoots = () => codexHomes().map((h) => join(h, 'sessions'));
|
|
79
|
+
|
|
80
|
+
// 기록 파일이 든 홈 (roots 가운데 path 가 그 아래 sessions/ 에 있는 것). 없으면 null.
|
|
81
|
+
export const homeOf = (path, roots) => roots.find((h) => path.startsWith(join(h, 'sessions') + '/') || path.startsWith(join(h, 'sessions') + '\\')) ?? null;
|
|
82
|
+
|
|
83
|
+
// 이어 열기 명령 앞에 붙일 환경 변수 (#214). 도구가 스스로 고르는 폴더(물려받은 변수가 없으면 ~/.claude, ~/.codex)와
|
|
84
|
+
// 세션이 든 폴더가 같으면 null. 다르거나 셸에 물려받은 변수가 있으면 [변수 이름, 폴더] 로 그 폴더를 꼭 집어 준다.
|
|
85
|
+
export function homeEnv(kind, dir, env = process.env, home = homedir()) {
|
|
86
|
+
if (!dir) return null;
|
|
87
|
+
const { inherited, home: base } = DIR_ENV[kind];
|
|
88
|
+
if (!env[inherited] && resolve(dir) === resolve(home, base)) return null;
|
|
89
|
+
return [inherited, dir];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 여러 폴더에 같은 기록이 있으면(복사본, 링크) 한 번만 센다. key 가 같으면 더 최근에 바뀐 쪽, 같으면 앞 폴더 것.
|
|
93
|
+
// items: [{ key, mtime, ... }]. 순서는 처음 나온 자리를 지킨다.
|
|
94
|
+
export function dedupeBy(items) {
|
|
95
|
+
const at = new Map();
|
|
96
|
+
const out = [];
|
|
97
|
+
for (const it of items) {
|
|
98
|
+
const i = at.get(it.key);
|
|
99
|
+
if (i === undefined) {
|
|
100
|
+
at.set(it.key, out.length);
|
|
101
|
+
out.push(it);
|
|
102
|
+
} else if (it.mtime > out[i].mtime) out[i] = it;
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --doctor 용: 읽지 않는 폴더 중 기록이 있어 보이는 것. 홈 바로 아래 .claude 와 .claude-*·.claude.*·.claude_* (+ ~/.config/claude) 에
|
|
108
|
+
// projects/ 가 있거나, .codex-* 등에 sessions/ 가 있으면 후보다. 내 것(uid)이 아닌 폴더는 보지 않는다. 읽지는 않는다.
|
|
109
|
+
// 설정 파일 목록 때문에 쓰지 않게 된 CLAUDE_CONFIG_DIR·CODEX_HOME 의 폴더도 기록이 있으면 후보로 보인다.
|
|
110
|
+
export function candidateDirs({ home = homedir(), claude = claudeDirs(), codex = codexHomes(), uid = process.getuid?.(), env = process.env } = {}) {
|
|
111
|
+
let names = [];
|
|
112
|
+
try {
|
|
113
|
+
names = readdirSync(home);
|
|
114
|
+
} catch {}
|
|
115
|
+
const mine = (p) => {
|
|
116
|
+
try {
|
|
117
|
+
const st = statSync(p);
|
|
118
|
+
return st.isDirectory() && (uid == null || st.uid === uid);
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const look = (paths, read, sub) => {
|
|
124
|
+
const known = new Set(read.map(realOf));
|
|
125
|
+
const out = [];
|
|
126
|
+
for (const p of paths) {
|
|
127
|
+
const real = realOf(p);
|
|
128
|
+
if (known.has(real) || !mine(p) || !mine(join(p, sub))) continue;
|
|
129
|
+
known.add(real);
|
|
130
|
+
out.push(p);
|
|
131
|
+
}
|
|
132
|
+
return out;
|
|
133
|
+
};
|
|
134
|
+
const inherited = (k) => uniqueDirs(splitPaths(env[DIR_ENV[k].inherited]) ?? [], home);
|
|
135
|
+
const near = (re) => names.filter((n) => re.test(n)).sort().map((n) => join(home, n));
|
|
136
|
+
return {
|
|
137
|
+
claude: look([...inherited('claude'), join(home, '.claude'), ...near(/^\.claude[-_.]./), join(home, '.config', 'claude')], claude, 'projects'),
|
|
138
|
+
codex: look([...inherited('codex'), join(home, '.codex'), ...near(/^\.codex[-_.]./)], codex, 'sessions'),
|
|
139
|
+
};
|
|
140
|
+
}
|
package/src/sources/projects.mjs
CHANGED
|
@@ -4,14 +4,12 @@
|
|
|
4
4
|
// agy 기록은 immutable 로 열어 -wal 에만 있는 막 생긴 대화는 아직 안 보이므로, 그 대화는 (unknown) 으로 나올 수 있다.
|
|
5
5
|
// 장부 캐시 모양은 그대로 두고, 리포트를 낼 때만 파일 앞부분을 조금 읽는다.
|
|
6
6
|
import { openSync, readSync, closeSync, statSync } from 'node:fs';
|
|
7
|
-
import { basename, join, relative, sep } from 'node:path';
|
|
8
|
-
import { homedir } from 'node:os';
|
|
7
|
+
import { basename, isAbsolute, join, relative, sep } from 'node:path';
|
|
9
8
|
import { AGY_ROOT, cwdOf } from './antigravity.mjs';
|
|
10
9
|
import { openReadOnly } from '../sqlite.mjs';
|
|
11
10
|
import { debugIo } from '../log.mjs';
|
|
11
|
+
import { claudeProjectRoots } from './dirs.mjs';
|
|
12
12
|
|
|
13
|
-
const HOME = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude');
|
|
14
|
-
const PROJECTS = join(HOME, 'projects');
|
|
15
13
|
// 앞부분에서 cwd 를 찾을 때 읽는 최대 크기. Codex 의 첫 줄(session_meta)은 지침 글이 들어 있어 길 수 있다.
|
|
16
14
|
const HEAD_BYTES = 256 * 1024;
|
|
17
15
|
const heads = new Map();
|
|
@@ -78,11 +76,15 @@ export function claudeProject(path) {
|
|
|
78
76
|
export const encodeFolder = (cwd) => cwd.replace(/[^A-Za-z0-9]/g, '-');
|
|
79
77
|
|
|
80
78
|
// cwd 를 못 찾았을 때 쓰는 projects/ 바로 아래 폴더 이름. 작업 트리 꼴(--claude-worktrees-<이름>)이면 그 부분을 뗀다.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
// root 를 주지 않으면 설정 폴더 전부의 projects/ 중 path 를 담은 것을 쓴다.
|
|
80
|
+
export function claudeFolder(path, root) {
|
|
81
|
+
for (const r of root ? [root] : claudeProjectRoots()) {
|
|
82
|
+
const rel = relative(r, path);
|
|
83
|
+
const dir = rel.split(sep)[0];
|
|
84
|
+
if (!dir || rel.startsWith('..') || isAbsolute(rel) || dir === rel) continue;
|
|
85
|
+
return dir.replace(/--claude-worktrees-.*$/, '') || dir;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
export function codexProject(path) {
|
|
@@ -135,7 +137,7 @@ export function projectRoot(cwd) {
|
|
|
135
137
|
|
|
136
138
|
// books: collectDaily 의 [{ tool, path, days }]. 각 장부에 project(작업 폴더 경로 또는 null)를 붙여 돌려준다.
|
|
137
139
|
// Claude 기록에서 cwd 를 못 찾으면 폴더 이름을 쓰되, 같은 폴더 이름이 되는 경로를 다른 기록에서 찾았으면 그 경로로 묶는다.
|
|
138
|
-
export function attachProjects(books, root
|
|
140
|
+
export function attachProjects(books, root) {
|
|
139
141
|
let agy = null;
|
|
140
142
|
const folder = new Map();
|
|
141
143
|
const out = books.map((b) => {
|
package/src/summary.mjs
CHANGED
|
@@ -20,6 +20,25 @@ export const HEARTBEAT_MS = 20_000;
|
|
|
20
20
|
const SKEW_MS = 5_000;
|
|
21
21
|
|
|
22
22
|
const nat = (x) => Number.isInteger(x) && x >= 0;
|
|
23
|
+
// 요약에 적는 다른 도구 대기 세션 수 상한. --line 은 가장 오래 기다린 하나만 보이지만, 둘을 적어 둔다.
|
|
24
|
+
export const WAIT_TOP = 2;
|
|
25
|
+
// 이름은 화면에 보이는 것보다 넉넉히, 그래도 파일이 커지지 않게 자른다.
|
|
26
|
+
const NAME_MAX = 80;
|
|
27
|
+
|
|
28
|
+
// 요약의 waitTop: [{ tool, name, since }]. since 는 모르면 null. 형식이 맞는 항목만 남긴다 (예전 요약에는 없으므로 없으면 빈 목록).
|
|
29
|
+
function waitTopOf(x) {
|
|
30
|
+
if (!Array.isArray(x)) return [];
|
|
31
|
+
return x.filter((w) => typeof w?.name === 'string' && (w.since === null || Number.isFinite(w.since))).slice(0, WAIT_TOP);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 세션의 대기 시작 시각. 출처가 따로 적은 waitSince 가 있으면 그것(null 이면 모름), 없으면 updatedAt.
|
|
35
|
+
// 모르는 시각을 지금 시각으로 메우면 요약이 매번 바뀌고 대기 시간이 늘 0s 로 보인다.
|
|
36
|
+
function sinceOf(s) {
|
|
37
|
+
const t = s.waitSince !== undefined ? s.waitSince : s.updatedAt;
|
|
38
|
+
return Number.isFinite(t) ? t : null;
|
|
39
|
+
}
|
|
40
|
+
// 시각을 모르는 세션은 정렬에서 맨 뒤.
|
|
41
|
+
const sinceKey = (t) => t ?? Number.MAX_SAFE_INTEGER;
|
|
23
42
|
|
|
24
43
|
// 세션 목록에서 요약 값을 뽑는다. 화면 헤더(ui/table.mjs)와 같은 기준이다.
|
|
25
44
|
export function summarize(sessions, now = Date.now()) {
|
|
@@ -32,6 +51,13 @@ export function summarize(sessions, now = Date.now()) {
|
|
|
32
51
|
waiting: waiting.length,
|
|
33
52
|
// Claude 대기 수는 --line 이 세션 파일에서 바로 세므로, 그 밖의 도구 몫(지금은 Antigravity 만 대기 상태가 있다)을 따로 적는다.
|
|
34
53
|
waitingOther: waiting.filter((s) => s.tool !== 'claude').length,
|
|
54
|
+
// 그중 가장 오래 기다린 세션 이름과 대기 시작 시각 (화면 IDLE 칸과 같은 기준). 대기 시간은 읽는 쪽이 지금 시각으로 센다.
|
|
55
|
+
// v 는 그대로 둔다: 예전 aitop 은 이 칸을 모르고 넘기고, 새 aitop 은 이 칸이 없는 예전 요약도 읽는다.
|
|
56
|
+
waitTop: waiting
|
|
57
|
+
.filter((s) => s.tool !== 'claude')
|
|
58
|
+
.map((s) => ({ tool: s.tool, name: String(s.name ?? '').slice(0, NAME_MAX), since: sinceOf(s) }))
|
|
59
|
+
.sort((a, b) => sinceKey(a.since) - sinceKey(b.since))
|
|
60
|
+
.slice(0, WAIT_TOP),
|
|
35
61
|
};
|
|
36
62
|
}
|
|
37
63
|
|
|
@@ -62,7 +88,7 @@ export function readSummary({ file = SUMMARY_FILE, now = Date.now(), staleMs = S
|
|
|
62
88
|
}
|
|
63
89
|
if (s?.v !== V || !Number.isFinite(s.at) || ![s.running, s.waiting, s.waitingOther].every(nat)) return null;
|
|
64
90
|
if (now - s.at > staleMs || s.at - now > SKEW_MS) return null;
|
|
65
|
-
return s;
|
|
91
|
+
return { ...s, waitTop: waitTopOf(s.waitTop) };
|
|
66
92
|
}
|
|
67
93
|
|
|
68
94
|
// 실시간 화면용: 수가 바뀌면 지난번 쓴 뒤 minMs 가 지났을 때, 그대로면 heartbeatMs 마다 쓴다.
|
|
@@ -71,7 +97,8 @@ export function createSummaryWriter({ file = SUMMARY_FILE, minMs = MIN_WRITE_MS,
|
|
|
71
97
|
return (sessions, now = Date.now()) => {
|
|
72
98
|
const s = summarize(sessions, now);
|
|
73
99
|
const since = last ? now - last.at : Infinity;
|
|
74
|
-
const
|
|
100
|
+
const top = (x) => x.waitTop.map((w) => `${w.name}@${w.since}`).join('|');
|
|
101
|
+
const changed = !last || s.running !== last.running || s.waiting !== last.waiting || s.waitingOther !== last.waitingOther || top(s) !== top(last);
|
|
75
102
|
if (since < (changed ? minMs : heartbeatMs)) return false;
|
|
76
103
|
if (!write(s, file)) return false;
|
|
77
104
|
last = s;
|
package/src/text.mjs
CHANGED
|
@@ -75,10 +75,10 @@ export function width(s) {
|
|
|
75
75
|
return w;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
// mark: 자른 자리 표시. 기본은 … (ASCII 만 써야 하는 aitop --line 은 다른 글자를 넘긴다).
|
|
79
|
+
export function truncate(s, max, mark = ellipsis(max)) {
|
|
79
80
|
if (max <= 0) return '';
|
|
80
81
|
if (width(s) <= max) return s;
|
|
81
|
-
const mark = ellipsis(max);
|
|
82
82
|
const room = max - width(mark);
|
|
83
83
|
let out = '';
|
|
84
84
|
let w = 0;
|
package/src/ui/chrome.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { box, line, segsWidth } from './draw.mjs';
|
|
|
5
5
|
import { glyphs, legendMark } from './glyphs.mjs';
|
|
6
6
|
import { COMMON, VIEWS, helpContext, keysLine, options, settingsLine, viewText } from '../help.mjs';
|
|
7
7
|
import { getLang, t } from '../i18n.mjs';
|
|
8
|
+
import { resumeCmd } from '../resume.mjs';
|
|
8
9
|
|
|
9
10
|
// 상세 패널을 기본으로 여는 최소 화면 높이. 이보다 낮으면 세션 표에 줄을 준다.
|
|
10
11
|
export const DETAIL_MIN_H = 24;
|
|
@@ -128,8 +129,16 @@ function orderHint(view) {
|
|
|
128
129
|
return { segs: [...segs, { t: ' ' }] };
|
|
129
130
|
}
|
|
130
131
|
|
|
132
|
+
// y 를 누른 뒤 잠깐 보이는 알림 (view.toast = { key, until }). 시간이 지나면 빠진다.
|
|
133
|
+
function toastItem(view, now = Date.now()) {
|
|
134
|
+
const x = view.toast;
|
|
135
|
+
if (!x || now >= x.until) return [];
|
|
136
|
+
return [{ segs: [{ t: t(x.key), fg: x.key === 'foot.copied' ? PALETTE.busy : PALETTE.waiting, bold: true }, { t: ' ' }], keep: true }];
|
|
137
|
+
}
|
|
138
|
+
|
|
131
139
|
export function footer(view, W, matched, sel) {
|
|
132
140
|
const RO = t('foot.readOnly');
|
|
141
|
+
const toast = toastItem(view);
|
|
133
142
|
const tail = [
|
|
134
143
|
{ k: '?', t: t('foot.help'), keep: true },
|
|
135
144
|
{ k: 'q', t: t('key.quit'), keep: true },
|
|
@@ -146,7 +155,7 @@ export function footer(view, W, matched, sel) {
|
|
|
146
155
|
view.focus === 'diff'
|
|
147
156
|
? [{ k: '↑↓', t: t('key.scroll') }, { k: 'space', t: t('key.page') }, { k: '[ ]', t: t('key.prevNext') }, { k: 'Esc', t: t('foot.toFiles'), keep: true }]
|
|
148
157
|
: [{ k: '←→', t: t('foot.prompts') }, { k: '↑↓', t: t('foot.pickFile') }, { k: '⏎', t: t('foot.viewDiff') }, { k: 'Esc', t: t('foot.toSessions'), keep: true }];
|
|
149
|
-
return hintBar([...keys, ...tail], W, RO);
|
|
158
|
+
return hintBar([...toast, ...keys, ...tail], W, RO);
|
|
150
159
|
}
|
|
151
160
|
// 세션이 하나도 없으면 쓸 수 있는 키만 남긴다.
|
|
152
161
|
if (!view.filter && !view.data?.sessions?.length) return hintBar([ended, ...tail], W, RO);
|
|
@@ -155,6 +164,7 @@ export function footer(view, W, matched, sel) {
|
|
|
155
164
|
? { segs: [{ t: ` /${view.filter} `, fg: PALETTE.chipText, bg: PALETTE.brand, bold: true }, { t: ` ${t('foot.count', { n: matched })} `, fg: PALETTE.muted }, keyChip('Esc'), keyLabel(t('foot.clearSearch'))], keep: true }
|
|
156
165
|
: { k: '/', t: t('key.search') };
|
|
157
166
|
const items = [
|
|
167
|
+
...toast,
|
|
158
168
|
search,
|
|
159
169
|
{ k: '↑↓', t: t('key.select') },
|
|
160
170
|
{ k: 'n', t: t('foot.next') },
|
|
@@ -163,8 +173,10 @@ export function footer(view, W, matched, sel) {
|
|
|
163
173
|
{ k: 'd', t: t(view.showDetail ? 'foot.hideDetail' : 'foot.showDetail') },
|
|
164
174
|
ended,
|
|
165
175
|
{ k: 'c', t: t('foot.costMode') },
|
|
166
|
-
// 고정은 폭이 모자라면
|
|
176
|
+
// 고정은 폭이 모자라면 복사 다음으로 빠진다.
|
|
167
177
|
...(sel ? [{ k: 'p', t: t(view.pins?.includes(sel.id) ? 'foot.unpin' : 'key.pin') }] : []),
|
|
178
|
+
// 복사(y)는 상세 패널에 이어 여는 명령이 보일 때만 안내하고, 폭이 모자라면 가장 먼저 빠진다.
|
|
179
|
+
...(view.showDetail && resumeCmd(sel) ? [{ k: 'y', t: t('key.copy') }] : []),
|
|
168
180
|
...tail,
|
|
169
181
|
];
|
|
170
182
|
return hintBar(items, W, RO);
|
package/src/ui/detail.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import { NOW, box, clock, fill, gauge, glyph, hhmm, levelBar, money, rule, segsW
|
|
|
7
7
|
import { activitySeries } from '../sources/common.mjs';
|
|
8
8
|
import { glyphs } from './glyphs.mjs';
|
|
9
9
|
import { STRINGS, phaseText, t as tr } from '../i18n.mjs';
|
|
10
|
+
import { resumeCmd } from '../resume.mjs';
|
|
10
11
|
|
|
11
12
|
// 탭 이름: 이번 지시·전체 탭은 turns.mjs 가 ko 이름을 붙이므로 지금 언어로 바꾼다. 지시 탭(T5)은 그대로.
|
|
12
13
|
const tabLabel = (tab, short = false) => (tab.key === 'now' ? tr('detail.tabNow', null, { short }) : tab.key === 'all' ? tr('detail.tabAll') : tab.label);
|
|
@@ -318,13 +319,39 @@ export function summaryLines(s, w, frame, view) {
|
|
|
318
319
|
return [first, [{ t: ' ' }, ...second]];
|
|
319
320
|
}
|
|
320
321
|
|
|
322
|
+
// 이어 열기 명령을 폭에 맞춰 max 줄로 나눈다. 넘치면 마지막 줄 끝을 … 로 바꾼다 (복사하면 전체가 들어간다).
|
|
323
|
+
export function resumeLines(cmd, w, max) {
|
|
324
|
+
if (!cmd || max < 1) return [];
|
|
325
|
+
let lines = wrapText(cmd, Math.max(1, w));
|
|
326
|
+
if (lines.length > max) {
|
|
327
|
+
lines = lines.slice(0, max);
|
|
328
|
+
const mark = ellipsis(w);
|
|
329
|
+
const last = [...lines[max - 1]];
|
|
330
|
+
while (last.length && width(last.join('')) + width(mark) > w) last.pop();
|
|
331
|
+
lines[max - 1] = last.join('') + mark;
|
|
332
|
+
}
|
|
333
|
+
return lines;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// 좁은 화면의 셋째 요약 줄: '이어 열기 y …/repo && claude --resume <id>'. 한 줄을 넘으면 앞을 잘라 세션 id 를 남긴다.
|
|
337
|
+
export function resumeSummary(s, w) {
|
|
338
|
+
const cmd = resumeCmd(s);
|
|
339
|
+
if (!cmd) return null;
|
|
340
|
+
const head = [{ t: ' ' }, { t: tr('detail.resume'), fg: PALETTE.muted }, { t: ' y ', fg: PALETTE.info }];
|
|
341
|
+
const room = w - segsWidth(head);
|
|
342
|
+
if (room < 8) return null;
|
|
343
|
+
return [...head, { t: truncateLeft(cmd, room), fg: PALETTE.text }];
|
|
344
|
+
}
|
|
345
|
+
|
|
321
346
|
export function detail(s, W, H, frame, view) {
|
|
322
347
|
const tc = PALETTE.tools[s.tool];
|
|
323
348
|
// 제목: 세션 이름은 진하게, 도구·모델은 도구 색으로.
|
|
324
349
|
const title = [{ t: s.name ?? s.tool, fg: PALETTE.text, bold: true }, { t: ` ${s.tool}${s.model ? ' · ' + s.model : ''}`, fg: tc }];
|
|
325
350
|
if (W < NARROW_W) {
|
|
326
351
|
const inner = W - 4;
|
|
327
|
-
|
|
352
|
+
// 셋째 줄(이어 열기)은 오른쪽 칸이 넉넉할(ROOMY 줄 이상 남을) 때만 둔다. 낮은 화면의 구획 배치는 그대로다.
|
|
353
|
+
const resume = H - 5 >= ROOMY ? resumeSummary(s, inner) : null;
|
|
354
|
+
const top = [...summaryLines(s, inner, frame, view), ...(resume ? [resume] : [])];
|
|
328
355
|
const R = rightColumn(s, inner, H - 2 - top.length, view);
|
|
329
356
|
return box(title, W, H, null, [...top, ...R], 0, tc, Boolean(view?.focus));
|
|
330
357
|
}
|
|
@@ -362,6 +389,14 @@ export function detail(s, W, H, frame, view) {
|
|
|
362
389
|
L.push([INDENT, { t: pad(tr('detail.context'), 9), fg: PALETTE.muted }, { t: pad(`${fmtTokens(s.context.used)}/${fmtTokens(s.context.window)}`, 11) + ' ', fg: PALETTE.text }, ...gauge(s.context.used, s.context.window, Math.max(4, leftW - width(INDENT.t) - 26))]);
|
|
363
390
|
}
|
|
364
391
|
|
|
392
|
+
// 이어 열기: 다른 터미널에서 이 세션을 이어 여는 명령. y 로 복사한다. 맨 아래에 두고, 남는 줄(가로줄 + 적어도 1줄)이 있을 때만 최대 3줄.
|
|
393
|
+
const cmd = resumeCmd(s);
|
|
394
|
+
const room = H - 2 - L.length;
|
|
395
|
+
if (cmd && room >= 2) {
|
|
396
|
+
L.push(rule([{ t: tr('detail.resume'), fg: PALETTE.text, bold: true }], 'y', leftW));
|
|
397
|
+
for (const l of resumeLines(cmd, leftW - width(INDENT.t), Math.min(3, room - 1))) L.push([INDENT, { t: l, fg: PALETTE.muted }]);
|
|
398
|
+
}
|
|
399
|
+
|
|
365
400
|
const R = rightColumn(s, W - leftW - 7, H - 2, view);
|
|
366
401
|
return box(title, W, H, L, R, leftW, tc, Boolean(view?.focus));
|
|
367
402
|
}
|