@sejuneoh/aitop 0.37.0 → 0.38.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 +57 -0
- package/bin/aitop.mjs +4 -1
- package/package.json +1 -1
- package/src/collect.mjs +2 -1
- package/src/config.mjs +13 -1
- package/src/doctor.mjs +66 -23
- package/src/i18n.mjs +20 -0
- package/src/json.mjs +3 -1
- package/src/resume.mjs +2 -1
- package/src/sources/agy-ledger.mjs +48 -20
- package/src/sources/antigravity.mjs +172 -25
- package/src/sources/claude-ledger.mjs +8 -0
- package/src/sources/claude.mjs +16 -12
- package/src/sources/cowork.mjs +562 -0
- package/src/sources/dirs.mjs +42 -2
- package/src/sources/projects.mjs +9 -3
- package/src/summary.mjs +1 -1
- package/src/trace.mjs +6 -4
- package/src/ui/chrome.mjs +2 -0
- package/src/ui/detail.mjs +4 -2
- package/src/ui/table.mjs +4 -2
- package/src/ui/theme.mjs +2 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// - conversations/<id>.db 의 gen_metadata: 모델 호출 한 번에 한 줄. protobuf 안에 모델 이름과 토큰 사용량이 있다.
|
|
4
4
|
// 실행 중인 agy 와 대화는 /proc/<pid>/fd 에 열린 presence/<id>.lock 으로 짝짓는다. /proc 이 없으면 작업 폴더로 짝짓는다.
|
|
5
5
|
// 세션은 Gemini 탭에 보인다 (agy 는 Gemini CLI 의 후속 도구다).
|
|
6
|
-
import { statSync, openSync, readSync, closeSync, existsSync, realpathSync } from 'node:fs';
|
|
6
|
+
import { statSync, openSync, readSync, closeSync, existsSync, realpathSync, readdirSync } from 'node:fs';
|
|
7
7
|
import { join, basename, resolve } from 'node:path';
|
|
8
8
|
import { homedir } from 'node:os';
|
|
9
9
|
import { fileURLToPath } from 'node:url';
|
|
@@ -12,6 +12,16 @@ import { findProcesses, isAgy, openFiles } from '../procs.mjs';
|
|
|
12
12
|
import { addActivity, emptyTokens, mergeActivity, pushEvent, describeTool, toolDetail, isNoisePrompt, isLongTool, MEMBER_FADE_MS } from './common.mjs';
|
|
13
13
|
import { contextWindow, geminiCost } from '../pricing.mjs';
|
|
14
14
|
import { debug, debugIo } from '../log.mjs';
|
|
15
|
+
import { isWsl } from '../notify.mjs';
|
|
16
|
+
import { agyAppEnv, agyAppSetting, expandHome, wslWindowsHomes } from './dirs.mjs';
|
|
17
|
+
|
|
18
|
+
const isDir = (p) => {
|
|
19
|
+
try {
|
|
20
|
+
return statSync(p).isDirectory();
|
|
21
|
+
} catch {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
15
25
|
|
|
16
26
|
// /proc/<pid>/fd 의 링크는 늘 심볼릭 링크를 푼 절대 경로라서, 기록 폴더도 같은 모양으로 바꿔 둔다
|
|
17
27
|
// (끝의 /, 상대 경로, 심볼릭 링크로 걸린 ~/.gemini). 폴더가 없으면 절대 경로까지만 바꾼다.
|
|
@@ -24,6 +34,39 @@ export function agyRoot(dir) {
|
|
|
24
34
|
}
|
|
25
35
|
}
|
|
26
36
|
|
|
37
|
+
// 기록 폴더 목록 (#303): agy CLI 폴더와 Antigravity 데스크톱 앱 폴더. 앱의 대화 db 도 표 구성이 CLI 와 같다.
|
|
38
|
+
// - AITOP_AGY_APP_HOME: 앱 폴더 (여럿이면 path.delimiter 로 잇는다). off·0·none·false 면 앱 폴더를 읽지 않는다. 가장 높다.
|
|
39
|
+
// - AITOP_AGY_HOME: CLI 폴더 하나를 바꾼다. 이것을 주면 앱 폴더는 AITOP_AGY_APP_HOME 을 줄 때만 읽는다 (테스트를 실제 기록과 떼어 놓는다).
|
|
40
|
+
// - app: 설정 파일의 agyApp (false 면 끔, 경로 배열이면 그 폴더들, true·undefined 면 저절로 찾는다).
|
|
41
|
+
// - 저절로: ~/.gemini/antigravity, WSL 이면 Windows 홈의 .gemini/antigravity 도 (dirs.mjs wslWindowsHomes).
|
|
42
|
+
// CLI 폴더는 없어도 목록에 둔다 (--doctor 가 '없음' 으로 보인다). 앱 폴더는 conversations/ 가 있는 것만 넣는다.
|
|
43
|
+
// 앱 폴더에는 로그인 토큰 같은 다른 파일도 있으므로 conversations/, conversation_summaries.db 만 연다 (presence/ 는 CLI 의 /proc 짝짓기에서 경로만 본다).
|
|
44
|
+
// 같은 실제 폴더는 한 번만. 순서는 CLI 먼저, 대화 id 가 겹치면 앞 폴더 것을 쓴다.
|
|
45
|
+
export function findAgyRoots({ env = process.env, home = homedir(), app, wsl = null, winHomes = null, has = isDir } = {}) {
|
|
46
|
+
const roots = [{ dir: agyRoot(env.AITOP_AGY_HOME ?? join(home, '.gemini', 'antigravity-cli')), source: 'cli' }];
|
|
47
|
+
const own = agyAppEnv(env.AITOP_AGY_APP_HOME);
|
|
48
|
+
const choice = own !== undefined ? own : env.AITOP_AGY_HOME != null ? false : app;
|
|
49
|
+
let apps = [];
|
|
50
|
+
if (Array.isArray(choice)) apps = choice.map((p) => expandHome(p, home));
|
|
51
|
+
else if (choice !== false) {
|
|
52
|
+
apps = [join(home, '.gemini', 'antigravity')];
|
|
53
|
+
const onWsl = wsl ?? (process.platform === 'linux' && isWsl(env));
|
|
54
|
+
if (onWsl) for (const h of (winHomes ?? (() => wslWindowsHomes({ env })))()) apps.push(join(h, '.gemini', 'antigravity'));
|
|
55
|
+
}
|
|
56
|
+
const seen = new Set([roots[0].dir]);
|
|
57
|
+
for (const a of apps) {
|
|
58
|
+
const dir = agyRoot(a);
|
|
59
|
+
if (seen.has(dir) || !has(join(dir, 'conversations'))) continue;
|
|
60
|
+
seen.add(dir);
|
|
61
|
+
roots.push({ dir, source: 'app' });
|
|
62
|
+
}
|
|
63
|
+
return roots;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 처음 쓸 때 정한다. bin/aitop.mjs 가 설정 파일의 agyApp 을 setDataDirs 로 넘긴 뒤에 불려야 해서 모듈을 불러올 때 정하지 않는다.
|
|
67
|
+
let rootsCache = null;
|
|
68
|
+
export const agyRoots = () => (rootsCache ??= findAgyRoots({ app: agyAppSetting() }));
|
|
69
|
+
// CLI 폴더 (예전 이름 그대로, 기본값으로 쓰는 곳이 많다). 앱 설정과 상관없다.
|
|
27
70
|
export const AGY_ROOT = agyRoot(process.env.AITOP_AGY_HOME ?? join(homedir(), '.gemini', 'antigravity-cli'));
|
|
28
71
|
|
|
29
72
|
const RECENT_MS = 24 * 3600 * 1000;
|
|
@@ -466,12 +509,18 @@ const mtimeOf = (path) => {
|
|
|
466
509
|
export const maxIdx = (db, table) => db.prepare(`select max(idx) m from ${table}`).get()?.m ?? -1;
|
|
467
510
|
|
|
468
511
|
// 대화 기록 하나를 한 번 열어 토큰(gen_metadata)과 진행 기록(steps)을 함께 읽는다.
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
const path = join(
|
|
512
|
+
// root: 기록 폴더 (CLI 또는 앱). 읽은 상태는 파일 경로로 두어 폴더끼리 섞이지 않는다.
|
|
513
|
+
// ttl: 끝까지 읽은 뒤 이 시간(ms) 안에는 파일 서명도 다시 보지 않는다 (앱 폴더가 /mnt/c 처럼 느린 곳일 때, APP_TTL_MS).
|
|
514
|
+
export function readConversation(id, budget, root = AGY_ROOT, ttl = 0) {
|
|
515
|
+
const path = join(root, 'conversations', `${id}.db`);
|
|
516
|
+
let g = convs.get(path);
|
|
517
|
+
if (!g) convs.set(path, (g = fresh()));
|
|
518
|
+
if (ttl && g.checkedAt != null && Date.now() - g.checkedAt < ttl) return g;
|
|
473
519
|
const sig = sigOf(path);
|
|
474
|
-
if (sig === null || sig === g.sig)
|
|
520
|
+
if (sig === null || sig === g.sig) {
|
|
521
|
+
if (ttl && sig !== null) g.checkedAt = Date.now();
|
|
522
|
+
return g;
|
|
523
|
+
}
|
|
475
524
|
const mainSig = sigOf(path, false);
|
|
476
525
|
if (outOf(budget)) {
|
|
477
526
|
budget.exhausted = true;
|
|
@@ -510,6 +559,8 @@ export function readConversation(id, budget) {
|
|
|
510
559
|
db?.close();
|
|
511
560
|
}
|
|
512
561
|
if (ok) Object.assign(g, n);
|
|
562
|
+
// 끝까지 읽었을 때만 TTL 을 시작한다 (읽기 한도에 걸렸으면 다음 갱신에 이어 읽는다).
|
|
563
|
+
if (ttl) g.checkedAt = ok && g.sig === sig ? Date.now() : null;
|
|
513
564
|
return g;
|
|
514
565
|
}
|
|
515
566
|
|
|
@@ -521,13 +572,22 @@ export function parseTime(s) {
|
|
|
521
572
|
return Date.parse(s) || null;
|
|
522
573
|
}
|
|
523
574
|
|
|
524
|
-
|
|
575
|
+
// WSL 인지는 한 번만 본다 (/proc/version 읽기).
|
|
576
|
+
let onWsl = null;
|
|
577
|
+
const wslNow = () => (onWsl ??= process.platform === 'linux' && isWsl());
|
|
578
|
+
|
|
579
|
+
// wsl: WSL 인지 (테스트에서 바꿔 끼운다). WSL 에서 읽은 Windows 앱 대화의 작업 폴더(file:///c%3A/Users/…)는 /c:/Users/… 로 풀리므로
|
|
580
|
+
// /mnt/c/Users/… 로 바꿔 같은 폴더의 Claude·Codex 세션과 한 프로젝트로 묶이게 한다.
|
|
581
|
+
export function cwdOf(workspaceUris, { wsl = null } = {}) {
|
|
525
582
|
try {
|
|
526
583
|
const first = JSON.parse(workspaceUris || '[]')[0];
|
|
527
584
|
if (!first) return null;
|
|
528
585
|
const p = first.startsWith('file:') ? fileURLToPath(first) : first;
|
|
529
586
|
// Windows 의 file:///c%3A/… 는 c:\… 가 되므로 드라이브 문자를 대문자로 맞춘다 (Claude·Codex 의 C:\ 와 같은 프로젝트로 묶이게).
|
|
530
|
-
|
|
587
|
+
if (process.platform === 'win32') return p.replace(/^[a-z](?=:)/, (d) => d.toUpperCase());
|
|
588
|
+
const drive = /^\/?([A-Za-z]):(?:[\\/](.*))?$/.exec(p);
|
|
589
|
+
if (drive && (wsl ?? wslNow())) return ['/mnt', drive[1].toLowerCase(), ...(drive[2] ?? '').split(/[\\/]+/).filter(Boolean)].join('/');
|
|
590
|
+
return p;
|
|
531
591
|
} catch (e) {
|
|
532
592
|
debug('agy', 'workspace_uris parse failed', e);
|
|
533
593
|
return null;
|
|
@@ -535,12 +595,14 @@ export function cwdOf(workspaceUris) {
|
|
|
535
595
|
}
|
|
536
596
|
|
|
537
597
|
// 읽는 동안 agy 가 쓰면 결과를 버리고 지난번 목록을 쓴다 (한 번 갱신 동안 세션이 사라져 보이지 않게).
|
|
538
|
-
|
|
598
|
+
// 기록 폴더마다 따로 둔다. 줄마다 root(기록 폴더)와 source('cli'|'app')를 붙인다.
|
|
599
|
+
const summaryCache = new Map();
|
|
539
600
|
|
|
540
|
-
function readSummaries() {
|
|
541
|
-
const path = join(
|
|
601
|
+
function readSummaries(root = AGY_ROOT, source = 'cli') {
|
|
602
|
+
const path = join(root, 'conversation_summaries.db');
|
|
542
603
|
const sig = sigOf(path);
|
|
543
604
|
if (sig === null) return [];
|
|
605
|
+
let summaries = summaryCache.get(root) ?? { sig: null, rows: [] };
|
|
544
606
|
if (sig === summaries.sig) return summaries.rows;
|
|
545
607
|
const mainSig = sigOf(path, false);
|
|
546
608
|
let db;
|
|
@@ -554,8 +616,8 @@ function readSummaries() {
|
|
|
554
616
|
from conversation_summaries order by last_modified_time desc limit 500`,
|
|
555
617
|
)
|
|
556
618
|
.all()
|
|
557
|
-
.map((r) => ({ ...r, cwd: cwdOf(r.ws), updatedAt: parseTime(r.modified), running: r.status === RUNNING || Boolean(r.busy) }));
|
|
558
|
-
if (sigOf(path, false) === mainSig) summaries = { sig, rows };
|
|
619
|
+
.map((r) => ({ ...r, cwd: cwdOf(r.ws), updatedAt: parseTime(r.modified), running: r.status === RUNNING || Boolean(r.busy), root, source }));
|
|
620
|
+
if (sigOf(path, false) === mainSig) summaryCache.set(root, (summaries = { sig, rows }));
|
|
559
621
|
} catch (e) {
|
|
560
622
|
debugIo('agy', 'conversation_summaries read failed', e, path);
|
|
561
623
|
// 다음 갱신에 다시 읽는다.
|
|
@@ -580,13 +642,15 @@ const rootOf = (id, byId) => {
|
|
|
580
642
|
};
|
|
581
643
|
|
|
582
644
|
// 실행 중인 agy 프로세스와 최상위 대화를 짝짓는다. 짝을 못 찾은 프로세스는 따로 돌려준다.
|
|
645
|
+
// dir: CLI 기록 폴더 하나 또는 목록. 앱 대화(source 'app')는 agy 프로세스가 열지 않으므로 작업 폴더 짐작에서 뺀다.
|
|
583
646
|
export function matchLive(procs, rows, filesOf = openFiles, dir = AGY_ROOT) {
|
|
647
|
+
const dirs = [dir].flat();
|
|
584
648
|
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
585
649
|
const live = new Map();
|
|
586
650
|
const loose = [];
|
|
587
651
|
for (const p of procs) {
|
|
588
652
|
const files = filesOf(p.pid);
|
|
589
|
-
const ids = (files ?? []).
|
|
653
|
+
const ids = (files ?? []).flatMap((f) => dirs.map((d) => idFromPath(f, d))).filter((id) => id && byId.has(id));
|
|
590
654
|
if (ids.length) {
|
|
591
655
|
for (const id of ids) {
|
|
592
656
|
const root = rootOf(id, byId);
|
|
@@ -595,7 +659,7 @@ export function matchLive(procs, rows, filesOf = openFiles, dir = AGY_ROOT) {
|
|
|
595
659
|
continue;
|
|
596
660
|
}
|
|
597
661
|
// /proc 이 없으면 같은 작업 폴더에서 가장 최근에 바뀐 대화를 고른다.
|
|
598
|
-
const guess = files === null ? rows.find((r) => !r.parent && r.cwd === p.cwd && !live.has(r.id)) : null;
|
|
662
|
+
const guess = files === null ? rows.find((r) => !r.parent && r.source !== 'app' && r.cwd === p.cwd && !live.has(r.id)) : null;
|
|
599
663
|
if (guess) live.set(guess.id, p.pid);
|
|
600
664
|
else loose.push(p);
|
|
601
665
|
}
|
|
@@ -695,6 +759,7 @@ function placeholder(p, msg) {
|
|
|
695
759
|
id: `agy-${p.pid}`,
|
|
696
760
|
pid: p.pid,
|
|
697
761
|
kind: 'interactive',
|
|
762
|
+
source: 'cli',
|
|
698
763
|
name: basename(p.cwd ?? '') || 'agy',
|
|
699
764
|
cwd: p.cwd,
|
|
700
765
|
project: basename(p.cwd ?? ''),
|
|
@@ -712,14 +777,93 @@ function placeholder(p, msg) {
|
|
|
712
777
|
};
|
|
713
778
|
}
|
|
714
779
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
780
|
+
// 앱 대화의 실행 중 판정 (#303). 앱 프로세스는 WSL 에서 /proc 에 보이지 않고 열린 파일로 짝지을 수도 없어,
|
|
781
|
+
// APP_LIVE_MS 안에 바뀐 기록을 실행 중으로 본다 (codex 의 NO_PROC_LIVE_MS 와 따로 둔다).
|
|
782
|
+
export const APP_LIVE_MS = 2 * 60_000;
|
|
783
|
+
// conversations/ 목록을 한 번 읽고 -wal 만 stat 한다 (앱이 쓰고 있는 대화에만 -wal 이 있다). 대화 목록의 마지막 수정 시각도 본다.
|
|
784
|
+
// 서브에이전트 대화가 바뀌었으면 그 부모(최상위) 대화를 실행 중으로 본다.
|
|
785
|
+
// 앱 폴더의 -wal 수정 시각 (대화 id → ms). 폴더 목록을 한 번 읽고 -wal 만 stat 한다.
|
|
786
|
+
export function appWal(root) {
|
|
787
|
+
const out = new Map();
|
|
788
|
+
const dir = join(root, 'conversations');
|
|
789
|
+
let names = [];
|
|
790
|
+
try {
|
|
791
|
+
names = readdirSync(dir);
|
|
792
|
+
} catch (e) {
|
|
793
|
+
debugIo('agy', 'app conversations list failed', e, dir);
|
|
794
|
+
}
|
|
795
|
+
for (const n of names) {
|
|
796
|
+
const m = /^([\w-]+)\.db-wal$/.exec(n);
|
|
797
|
+
if (!m) continue;
|
|
798
|
+
try {
|
|
799
|
+
out.set(m[1], statSync(join(dir, n)).mtimeMs);
|
|
800
|
+
} catch {}
|
|
801
|
+
}
|
|
802
|
+
return out;
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// wal: appWal 결과 (TTL 동안은 지난 값을 쓴다). 2분 판정은 늘 지금 시각으로 한다.
|
|
806
|
+
export function appLive(root, rows, now = Date.now(), wal = appWal(root)) {
|
|
807
|
+
const ids = new Set();
|
|
808
|
+
for (const [id, at] of wal) if (now - at <= APP_LIVE_MS) ids.add(id);
|
|
809
|
+
for (const r of rows) if (r.updatedAt != null && now - r.updatedAt <= APP_LIVE_MS) ids.add(r.id);
|
|
810
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
811
|
+
return new Set([...ids].filter((id) => byId.has(id)).map((id) => rootOf(id, byId)));
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// 앱 폴더는 WSL 에서 /mnt/c(9P, stat 한 번에 약 0.6ms)에 있을 수 있어, 폴더가 있는지·대화 목록·-wal 목록·대화 기록 서명을
|
|
815
|
+
// APP_TTL_MS 마다 한 번만 본다. 실행 중 판정(APP_LIVE_MS)은 매 갱신 지금 시각으로 다시 한다.
|
|
816
|
+
export const APP_TTL_MS = 10_000;
|
|
817
|
+
const appCache = new Map();
|
|
818
|
+
|
|
819
|
+
// 앱 폴더 하나의 { exists, rows, wal }. TTL 안이면 지난 값을 쓴다.
|
|
820
|
+
function appSnapshot(root) {
|
|
821
|
+
const c = appCache.get(root);
|
|
822
|
+
if (c && Date.now() - c.at < APP_TTL_MS) return c;
|
|
823
|
+
const exists = existsSync(root);
|
|
824
|
+
const snap = { at: Date.now(), exists, rows: exists ? readSummaries(root, 'app') : [], wal: exists ? appWal(root) : new Map() };
|
|
825
|
+
appCache.set(root, snap);
|
|
826
|
+
return snap;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// 테스트용: 앱 폴더 캐시를 ms 만큼 오래된 것으로 만든다 (TTL 이 지난 것을 흉내 낸다).
|
|
830
|
+
export const _test = {
|
|
831
|
+
age(ms) {
|
|
832
|
+
for (const c of appCache.values()) c.at -= ms;
|
|
833
|
+
for (const g of convs.values()) if (g.checkedAt != null) g.checkedAt -= ms;
|
|
834
|
+
},
|
|
835
|
+
};
|
|
836
|
+
|
|
837
|
+
// 폴더마다 대화 목록을 읽어 합친다. 같은 대화 id 가 여러 폴더에 있으면 앞 폴더(CLI) 것만 둔다.
|
|
838
|
+
function readAllSummaries(roots) {
|
|
839
|
+
const seen = new Set();
|
|
840
|
+
const out = [];
|
|
841
|
+
for (const r of roots) {
|
|
842
|
+
for (const row of r.source === 'app' ? appSnapshot(r.dir).rows : readSummaries(r.dir, r.source)) {
|
|
843
|
+
if (seen.has(row.id)) continue;
|
|
844
|
+
seen.add(row.id);
|
|
845
|
+
out.push(row);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return out;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
export function collectAgy({ showEnded, budget, roots = agyRoots() }) {
|
|
852
|
+
// 기록 폴더가 없으면 그 쪽은 실행한 적이 없는 것이다 (테스트에서 AITOP_AGY_HOME 으로 실제 기록과 떼어 놓을 때도 쓴다).
|
|
853
|
+
// CLI 폴더가 없으면 agy 프로세스도 보지 않는다 (예전과 같다).
|
|
854
|
+
const have = roots.filter((r) => (r.source === 'app' ? appSnapshot(r.dir).exists : existsSync(r.dir)));
|
|
855
|
+
const cli = have.filter((r) => r.source !== 'app');
|
|
856
|
+
const apps = have.filter((r) => r.source === 'app');
|
|
857
|
+
const procs = cli.length ? findProcesses(isAgy) : [];
|
|
858
|
+
// 앱 대화는 프로세스 없이 수정 시각으로 판정하므로, agy 프로세스가 없어도 앱 폴더가 있으면 읽는다.
|
|
859
|
+
if (!have.length || (!procs.length && !apps.length && !showEnded)) return [];
|
|
719
860
|
if (!loadSqlite()) return procs.map((p) => placeholder(p, 'agyOldNode'));
|
|
720
861
|
|
|
721
|
-
const rows =
|
|
722
|
-
const { live, loose } = matchLive(procs, rows);
|
|
862
|
+
const rows = readAllSummaries(have);
|
|
863
|
+
const { live, loose } = matchLive(procs, rows, openFiles, cli.map((r) => r.dir));
|
|
864
|
+
for (const a of apps) {
|
|
865
|
+
for (const id of appLive(a.dir, rows.filter((r) => r.root === a.dir), Date.now(), appSnapshot(a.dir).wal)) if (!live.has(id)) live.set(id, null);
|
|
866
|
+
}
|
|
723
867
|
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
724
868
|
const children = new Map();
|
|
725
869
|
for (const r of rows) if (r.parent) {
|
|
@@ -734,10 +878,11 @@ export function collectAgy({ showEnded, budget }) {
|
|
|
734
878
|
tops.sort((a, b) => Number(live.has(b.id)) - Number(live.has(a.id)));
|
|
735
879
|
for (const r of tops) {
|
|
736
880
|
const isLive = live.has(r.id);
|
|
737
|
-
const
|
|
881
|
+
const ttlOf = (x) => (x.source === 'app' ? APP_TTL_MS : 0);
|
|
882
|
+
const g = readConversation(r.id, budget, r.root, ttlOf(r));
|
|
738
883
|
const kids = children.get(r.id) ?? [];
|
|
739
884
|
// 서브에이전트 기록은 한 번만 읽어 행과 합계가 같은 값을 쓰게 한다.
|
|
740
|
-
const kidUsage = kids.map((c) => readConversation(c.id, budget));
|
|
885
|
+
const kidUsage = kids.map((c) => readConversation(c.id, budget, c.root, ttlOf(c)));
|
|
741
886
|
const kidWaits = kids.map((c, i) => subWait(isLive, c, kidUsage[i]));
|
|
742
887
|
// 끝난 서브에이전트는 Claude 팀원처럼 잠시 "완료"로 보였다가 행에서 빠진다. 합계에는 그대로 남는다.
|
|
743
888
|
const members = kids
|
|
@@ -782,6 +927,8 @@ export function collectAgy({ showEnded, budget }) {
|
|
|
782
927
|
id: r.id,
|
|
783
928
|
pid: live.get(r.id) ?? null,
|
|
784
929
|
kind: 'interactive',
|
|
930
|
+
// 기록이 온 곳: 'cli'(agy CLI 폴더) 또는 'app'(Antigravity 데스크톱 앱 폴더). 상세 패널과 --json 에 보인다.
|
|
931
|
+
source: r.source ?? 'cli',
|
|
785
932
|
name: r.title || basename(r.cwd ?? '') || 'agy',
|
|
786
933
|
cwd: r.cwd,
|
|
787
934
|
project: basename(r.cwd ?? ''),
|
|
@@ -813,7 +960,7 @@ export function collectAgy({ showEnded, budget }) {
|
|
|
813
960
|
}
|
|
814
961
|
for (const p of loose) out.push(placeholder(p, 'firstInput'));
|
|
815
962
|
|
|
816
|
-
const keep = new Set(rows.map((r) => r.id));
|
|
817
|
-
for (const
|
|
963
|
+
const keep = new Set(rows.map((r) => join(r.root, 'conversations', `${r.id}.db`)));
|
|
964
|
+
for (const path of convs.keys()) if (!keep.has(path)) convs.delete(path);
|
|
818
965
|
return out;
|
|
819
966
|
}
|
|
@@ -14,6 +14,7 @@ import { debugIo } from '../log.mjs';
|
|
|
14
14
|
import { foldArchive, foldHi } from '../monthly.mjs';
|
|
15
15
|
import { attachProjects } from './projects.mjs';
|
|
16
16
|
import { claudeProjectRoots, dedupeBy } from './dirs.mjs';
|
|
17
|
+
import { coworkLedgerFiles } from './cowork.mjs';
|
|
17
18
|
|
|
18
19
|
export { dayKey };
|
|
19
20
|
|
|
@@ -128,6 +129,13 @@ function recentFiles(days = DAYS) {
|
|
|
128
129
|
}
|
|
129
130
|
}
|
|
130
131
|
}
|
|
132
|
+
// Claude Desktop Cowork 기록도 Claude 몫으로 함께 센다 (#304). key 가 같은 모양이라 ~/.claude/projects 에도 같은 기록이 있으면 한 번만.
|
|
133
|
+
// audit.jsonl 의 total_cost_usd 는 쓰지 않는다 (기록의 사용량으로만 센다).
|
|
134
|
+
try {
|
|
135
|
+
found.push(...coworkLedgerFiles(days));
|
|
136
|
+
} catch (e) {
|
|
137
|
+
debugIo('ledger', 'cowork files failed', e);
|
|
138
|
+
}
|
|
131
139
|
const files = dedupeBy(found).map((f) => f.path);
|
|
132
140
|
listed = { at: Date.now(), files, days };
|
|
133
141
|
return files;
|
package/src/sources/claude.mjs
CHANGED
|
@@ -95,12 +95,12 @@ function loadingPhase(t) {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
// 서브에이전트 전체(끝난 것 포함)의 토큰·비용 합계. 메인 세션 합계에 더해 화면에 보인다.
|
|
98
|
-
function emptySub() {
|
|
98
|
+
export function emptySub() {
|
|
99
99
|
return { count: 0, tokens: emptyTokens(), cost: 0, costNoCache: 0, costUnknown: false, loading: false, files: [], activity: [] };
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
// 메인 tracker 와 서브에이전트 합계를 화면에 보일 세션 숫자로 합친다. 기록을 아직 읽지 않았으면(t 없음) 비용은 null.
|
|
103
|
-
function sessionTotals(t, sub) {
|
|
103
|
+
export function sessionTotals(t, sub) {
|
|
104
104
|
const main = t?.tokens ?? emptyTokens();
|
|
105
105
|
const tokens = { main: main.total, sub: sub.tokens.total, subCount: sub.count };
|
|
106
106
|
for (const k of Object.keys(main)) tokens[k] = main[k] + sub.tokens[k];
|
|
@@ -120,16 +120,20 @@ function sessionTotals(t, sub) {
|
|
|
120
120
|
};
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
|
|
123
|
+
// track: 서브에이전트 기록 tracker 를 얻는 함수 (Cowork 는 자기 tracker 목록을 쓴다, cowork.mjs).
|
|
124
|
+
// meta: false 면 agent-<id>.meta.json 을 열지 않고 agent-<id>.jsonl 만 본다 (Cowork 앱 폴더의 허용 목록, #304).
|
|
125
|
+
// 그때는 팀원 이름이 'agent' 이고 작업 설명이 비며, 끝남 표시가 없어 기록이 MEMBER_STALE_MS 넘게 그대로면 끝난 것으로 본다.
|
|
126
|
+
export function readMembers(transcript, parent, budget, { track = (p, b) => tracker(subTrackers, p, b), meta: withMeta = true } = {}) {
|
|
124
127
|
const dir = join(transcript.replace(/\.jsonl$/, ''), 'subagents');
|
|
125
128
|
const sub = emptySub();
|
|
126
129
|
if (!existsSync(dir)) return { members: [], sub };
|
|
127
130
|
const members = [];
|
|
131
|
+
const tail = withMeta ? '.meta.json' : '.jsonl';
|
|
128
132
|
for (const f of readdirSync(dir)) {
|
|
129
|
-
if (!f.
|
|
130
|
-
const id = f.slice('agent-'.length, -
|
|
131
|
-
const meta = readJson(join(dir, f)) ?? {};
|
|
132
|
-
const t =
|
|
133
|
+
if (!f.startsWith('agent-') || !f.endsWith(tail)) continue;
|
|
134
|
+
const id = f.slice('agent-'.length, -tail.length);
|
|
135
|
+
const meta = (withMeta ? readJson(join(dir, f)) : null) ?? {};
|
|
136
|
+
const t = track(join(dir, `agent-${id}.jsonl`), budget);
|
|
133
137
|
sub.count++;
|
|
134
138
|
for (const k of Object.keys(sub.tokens)) sub.tokens[k] += t.tokens[k];
|
|
135
139
|
sub.cost += t.cost;
|
|
@@ -178,13 +182,13 @@ function statusOf(entry, alive, mtime) {
|
|
|
178
182
|
}
|
|
179
183
|
|
|
180
184
|
// 응답 대기는 Claude Code 가 세션 파일에 적은 값이다. 그동안 서브에이전트가 돌고 있으면 수를 args.agents 로 함께 보내 구분되게 한다.
|
|
181
|
-
function withRunningMembers(phase, status, members) {
|
|
185
|
+
export function withRunningMembers(phase, status, members) {
|
|
182
186
|
if (status !== 'waiting') return phase;
|
|
183
187
|
const running = members.filter((m) => m.status !== 'done' && m.phase?.kind !== 'done').length;
|
|
184
188
|
return running ? { ...phase, args: { ...phase.args, agents: running } } : phase;
|
|
185
189
|
}
|
|
186
190
|
|
|
187
|
-
function phaseOf(status, entry, t) {
|
|
191
|
+
export function phaseOf(status, entry, t) {
|
|
188
192
|
switch (status) {
|
|
189
193
|
case 'ended':
|
|
190
194
|
return { kind: 'ended' };
|
|
@@ -202,12 +206,12 @@ function phaseOf(status, entry, t) {
|
|
|
202
206
|
// 대기(idle) 중인 세션의 마지막 대화 줄이 API 오류면 '멈춤' 으로 보인다 (claude-tracker.mjs stopReasonOf).
|
|
203
207
|
// 응답 대기·작업 중·종료는 그대로 두고, 기록을 다 읽기 전에는 판단하지 않는다.
|
|
204
208
|
const STOP_MSG = { auth: 'stopAuth', network: 'stopNetwork', api: 'stopApi' };
|
|
205
|
-
function stoppedPhase(t) {
|
|
209
|
+
export function stoppedPhase(t) {
|
|
206
210
|
const r = t?.loading == null ? t?.stopReason : null;
|
|
207
211
|
return r ? { kind: 'stopped', msg: STOP_MSG[r.kind] ?? 'stopApi' } : null;
|
|
208
212
|
}
|
|
209
213
|
|
|
210
|
-
function cacheOf(alive, status, t) {
|
|
214
|
+
export function cacheOf(alive, status, t) {
|
|
211
215
|
const at = t?.cacheExpiresAt;
|
|
212
216
|
if (!alive || at == null || t.loading != null || (status !== 'waiting' && status !== 'idle') || (status === 'idle' && stoppedPhase(t))) return { cacheExpiresAt: null, cacheTtl: null };
|
|
213
217
|
return { cacheExpiresAt: at, cacheTtl: t.cacheTtl };
|
|
@@ -216,7 +220,7 @@ function cacheOf(alive, status, t) {
|
|
|
216
220
|
// 도구가 돌기 시작한 시각(ms). 작업 중(busy)이고 진행 단계가 열린 도구 실행일 때만 둔다 (claude-tracker.mjs toolStartedAt).
|
|
217
221
|
// 허락 대기 중에는 두지 않고, 그동안 본 시각을 적어 두어 허락한 뒤에는 그때부터 잰다 (markWaiting).
|
|
218
222
|
// 쉘 명령(! 입력, status 'shell')은 기록에 tool_use 가 없어 빼고, 기록을 다 읽기 전에도 뺀다.
|
|
219
|
-
function toolStartOf(status, phase, t) {
|
|
223
|
+
export function toolStartOf(status, phase, t) {
|
|
220
224
|
if (!t) return null;
|
|
221
225
|
if (status === 'waiting') {
|
|
222
226
|
t.markWaiting();
|