@sejuneoh/aitop 0.31.2 → 0.33.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 +24 -7
- package/package.json +1 -1
- package/src/attention.mjs +4 -2
- package/src/i18n.mjs +30 -2
- package/src/json.mjs +10 -1
- package/src/order.mjs +5 -1
- package/src/sessions-report.mjs +20 -5
- package/src/sources/antigravity.mjs +65 -14
- package/src/sources/claude-tracker.mjs +162 -6
- package/src/sources/claude.mjs +43 -4
- package/src/sources/codex.mjs +21 -5
- package/src/sources/common.mjs +23 -0
- package/src/sources/sheets.mjs +81 -7
- package/src/text.mjs +9 -0
- package/src/ui/chrome.mjs +1 -0
- package/src/ui/detail.mjs +6 -1
- package/src/ui/draw.mjs +34 -2
- package/src/ui/table.mjs +38 -6
- package/src/ui/theme.mjs +1 -1
- package/src/ui.mjs +1 -1
|
@@ -15,8 +15,8 @@ const LOADING_MIN_BYTES = 4 * 1024 * 1024;
|
|
|
15
15
|
const TAIL_BYTES = 256 * 1024;
|
|
16
16
|
const CUSTOM_TITLE = '"type":"custom-title"';
|
|
17
17
|
|
|
18
|
-
// 기록 끝 TAIL_BYTES
|
|
19
|
-
|
|
18
|
+
// 기록 끝 TAIL_BYTES 의 줄들. 읽지 못하면 null.
|
|
19
|
+
function tailLines(path) {
|
|
20
20
|
let text;
|
|
21
21
|
try {
|
|
22
22
|
const fd = openSync(path, 'r');
|
|
@@ -30,9 +30,15 @@ export function tailCustomTitle(path) {
|
|
|
30
30
|
}
|
|
31
31
|
} catch (e) {
|
|
32
32
|
debugIo('claude', 'transcript tail read failed', e, path);
|
|
33
|
-
return
|
|
33
|
+
return null;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
return text.split('\n');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// 기록 끝 TAIL_BYTES 에서 마지막 custom-title 이름. 줄이 없으면 undefined, 이름이 비었으면 null.
|
|
39
|
+
export function tailCustomTitle(path) {
|
|
40
|
+
const lines = tailLines(path);
|
|
41
|
+
if (!lines) return undefined;
|
|
36
42
|
for (let i = lines.length - 1; i >= 0; i--) {
|
|
37
43
|
if (!lines[i].includes(CUSTOM_TITLE)) continue;
|
|
38
44
|
try {
|
|
@@ -43,6 +49,106 @@ export function tailCustomTitle(path) {
|
|
|
43
49
|
return undefined;
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
// API 오류 줄(isApiErrorMessage)이 말하는 멈춘 이유. 이 PC 기록 표본에서 확인한 형식만 가른다.
|
|
53
|
+
// error: 'authentication_failed' (본문 'Login expired · Please run /login', 'OAuth session expired ...') → auth
|
|
54
|
+
// apiError: 'connection_failed' (error: 'server_error', 본문 'API Error: Connection lost mid-response ...') → network
|
|
55
|
+
// 사용 한도 줄은 표본이 없어 따로 가르지 않고(재개 시각도 읽지 않는다) 그 밖의 오류와 함께 api 로 둔다.
|
|
56
|
+
export function stopReasonOf(x) {
|
|
57
|
+
if (x?.type !== 'assistant' || x.isApiErrorMessage !== true) return null;
|
|
58
|
+
if (x.error === 'authentication_failed') return { kind: 'auth' };
|
|
59
|
+
if (x.apiError === 'connection_failed') return { kind: 'network' };
|
|
60
|
+
return { kind: 'api' };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 기록 끝에서 멈춘 이유를 다시 찾는다: 마지막 대화 줄(assistant·user, isMeta 제외)이 API 오류면 그 이유, 아니면 null.
|
|
64
|
+
// 이 필드가 생기기 전 캐시를 위해서다. 오류 뒤에는 대화가 아닌 줄(last-prompt, turn_duration 등)만 붙는다.
|
|
65
|
+
export function tailStopReason(path) {
|
|
66
|
+
const lines = tailLines(path);
|
|
67
|
+
if (!lines) return null;
|
|
68
|
+
for (let i = lines.length - 1; i >= 0; i--) {
|
|
69
|
+
const l = lines[i];
|
|
70
|
+
if (!l.includes('"type":"assistant"') && !l.includes('"type":"user"')) continue;
|
|
71
|
+
try {
|
|
72
|
+
const x = JSON.parse(l);
|
|
73
|
+
if ((x.type === 'assistant' || x.type === 'user') && x.message && !x.isMeta) return stopReasonOf(x);
|
|
74
|
+
} catch {}
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// 프롬프트 캐시 수명. 공식 문서(https://platform.claude.com/docs/en/build-with-claude/prompt-caching) 기준:
|
|
80
|
+
// 기본 5분, 1시간은 선택. 캐시를 쓰거나 읽을 때마다 수명이 새로 시작되고, 수명은 응답 끝이 아니라 그 요청이 시작된 때부터 잰다.
|
|
81
|
+
// 요청 시작 시각은 기록에 없으므로 그 응답 바로 앞의 사용자 줄(지시·도구 결과) 시각으로 잡는다. 없으면 응답 줄 시각.
|
|
82
|
+
export const CACHE_TTL_5M = 300;
|
|
83
|
+
export const CACHE_TTL_1H = 3600;
|
|
84
|
+
|
|
85
|
+
// 응답 한 줄의 usage 로 캐시 상태를 갱신한다. st: { cacheAt, cacheTtl, inputAt, inputFor }. 바꾸면 true.
|
|
86
|
+
// inputAt 은 한 요청(message.id)에만 쓴다. 사용자 줄 없이 다른 응답이 이어지면 그 응답 줄 시각을 쓴다.
|
|
87
|
+
// 1시간 쓰기 토큰이 있으면 1시간, 5분 쓰기 토큰(또는 쪼갠 값이 없는 쓰기)이 있으면 5분.
|
|
88
|
+
// 읽기만 있으면 읽은 항목의 수명이 다시 시작되므로 앞서 정한 TTL 을 그대로 쓴다 (모르면 기본 5분).
|
|
89
|
+
// 캐시를 쓰지도 읽지도 않은 응답은 캐시를 건드리지 않는다.
|
|
90
|
+
export function applyCacheUsage(st, u, at, id = null) {
|
|
91
|
+
if (!u || !Number.isFinite(at)) return false;
|
|
92
|
+
const cc = u.cache_creation;
|
|
93
|
+
const h1 = cc?.ephemeral_1h_input_tokens ?? 0;
|
|
94
|
+
const m5 = cc?.ephemeral_5m_input_tokens ?? 0;
|
|
95
|
+
const write = u.cache_creation_input_tokens ?? 0;
|
|
96
|
+
const read = u.cache_read_input_tokens ?? 0;
|
|
97
|
+
let ttl;
|
|
98
|
+
if (h1 > 0) ttl = CACHE_TTL_1H;
|
|
99
|
+
else if (m5 > 0 || write > 0) ttl = CACHE_TTL_5M;
|
|
100
|
+
else if (read > 0) ttl = st.cacheTtl ?? CACHE_TTL_5M;
|
|
101
|
+
else return false;
|
|
102
|
+
const fresh = Number.isFinite(st.inputAt) && st.inputAt <= at && (st.inputFor == null || st.inputFor === id);
|
|
103
|
+
st.cacheAt = fresh ? st.inputAt : at;
|
|
104
|
+
st.inputFor = fresh ? id : null;
|
|
105
|
+
if (!fresh) st.inputAt = null;
|
|
106
|
+
st.cacheTtl = ttl;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 기록 끝 TAIL_BYTES 를 앞에서부터 다시 읽어 캐시 상태를 만든다. 이 필드가 생기기 전 캐시를 위해서다.
|
|
111
|
+
export function tailCacheState(path) {
|
|
112
|
+
const st = { cacheAt: null, cacheTtl: null, inputAt: null, inputFor: null };
|
|
113
|
+
for (const l of tailLines(path) ?? []) {
|
|
114
|
+
if (!l.includes('"type":"assistant"') && !l.includes('"type":"user"')) continue;
|
|
115
|
+
try {
|
|
116
|
+
cacheStep(st, JSON.parse(l));
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
119
|
+
return st;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// 대화 줄 하나를 캐시 상태에 반영한다 (apply 와 tailCacheState 가 같이 쓴다).
|
|
123
|
+
function cacheStep(st, x) {
|
|
124
|
+
if (x.isMeta || !x.message) return;
|
|
125
|
+
if (x.type === 'user') {
|
|
126
|
+
st.inputAt = parseTs(x.timestamp);
|
|
127
|
+
st.inputFor = null;
|
|
128
|
+
}
|
|
129
|
+
// API 오류 줄은 사용량이 0 이라 캐시를 건드리지 않는다.
|
|
130
|
+
else if (x.type === 'assistant' && x.message.usage) applyCacheUsage(st, x.message.usage, parseTs(x.timestamp), x.message.id ?? null);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// 결과가 아직 없는 tool_use 의 시작 시각(at)을 기록 끝에서 찾아 채운다. at 필드가 생기기 전 캐시를 위해서다.
|
|
134
|
+
// pending: Map(tool_use id → 열린 호출). at 이 없는 것만 고치고, 고친 것이 있으면 true.
|
|
135
|
+
export function tailToolStarts(path, pending) {
|
|
136
|
+
const want = [...pending].filter(([, p]) => !('at' in p));
|
|
137
|
+
if (!want.length) return false;
|
|
138
|
+
for (const [, p] of want) p.at = null;
|
|
139
|
+
const ids = new Map(want);
|
|
140
|
+
for (const l of tailLines(path) ?? []) {
|
|
141
|
+
if (!l.includes('"tool_use"')) continue;
|
|
142
|
+
try {
|
|
143
|
+
const x = JSON.parse(l);
|
|
144
|
+
for (const c of Array.isArray(x.message?.content) ? x.message.content : []) {
|
|
145
|
+
if (c.type === 'tool_use' && ids.has(c.id)) ids.get(c.id).at = parseTs(x.timestamp);
|
|
146
|
+
}
|
|
147
|
+
} catch {}
|
|
148
|
+
}
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
|
|
46
152
|
export class ClaudeTracker {
|
|
47
153
|
constructor(path) {
|
|
48
154
|
this.tail = new JsonlTail(path);
|
|
@@ -56,7 +162,7 @@ export class ClaudeTracker {
|
|
|
56
162
|
const c = loadCache(path);
|
|
57
163
|
if (c) {
|
|
58
164
|
this.tail.offset = c.offset;
|
|
59
|
-
Object.assign(this, { tokens: c.tokens, cost: c.cost, costNoCache: c.costNoCache, costUnknown: c.costUnknown, context: c.context, model: c.model, title: c.title, customTitle: c.customTitle ?? null, branch: c.branch, events: c.events, lastTool: c.lastTool, lastKind: c.lastKind, files: c.files ?? [], turns: c.turns ?? [], turnCount: c.turnCount ?? 0, firstAt: c.firstAt ?? null, activity: c.activity ?? {} });
|
|
165
|
+
Object.assign(this, { tokens: c.tokens, cost: c.cost, costNoCache: c.costNoCache, costUnknown: c.costUnknown, context: c.context, model: c.model, title: c.title, customTitle: c.customTitle ?? null, branch: c.branch, events: c.events, lastTool: c.lastTool, lastKind: c.lastKind, files: c.files ?? [], turns: c.turns ?? [], turnCount: c.turnCount ?? 0, firstAt: c.firstAt ?? null, activity: c.activity ?? {}, stopReason: c.stopReason ?? null, cacheAt: c.cacheAt ?? null, cacheTtl: c.cacheTtl ?? null, inputAt: c.inputAt ?? null, inputFor: c.inputFor ?? null });
|
|
60
166
|
this.recent = new Map(c.recent);
|
|
61
167
|
this.pending = new Map(c.pending);
|
|
62
168
|
// 이 필드가 생기기 전 캐시는 이미 지나간 custom-title 을 모른다. 끝부분을 한 번 훑어 채우고 캐시에 다시 적어
|
|
@@ -65,6 +171,19 @@ export class ClaudeTracker {
|
|
|
65
171
|
this.customTitle = tailCustomTitle(path) ?? null;
|
|
66
172
|
markDirty(path, () => this.snapshot());
|
|
67
173
|
}
|
|
174
|
+
// 멈춘 이유도 같은 방식으로 한 번만 채운다 (캐시 버전은 그대로).
|
|
175
|
+
if (!('stopReason' in c)) {
|
|
176
|
+
this.stopReason = tailStopReason(path);
|
|
177
|
+
markDirty(path, () => this.snapshot());
|
|
178
|
+
}
|
|
179
|
+
// 프롬프트 캐시 상태도 같은 방식으로 한 번만 채운다 (캐시 버전은 그대로).
|
|
180
|
+
if (!('cacheAt' in c)) {
|
|
181
|
+
const { cacheAt, cacheTtl } = tailCacheState(path);
|
|
182
|
+
Object.assign(this, { cacheAt, cacheTtl });
|
|
183
|
+
markDirty(path, () => this.snapshot());
|
|
184
|
+
}
|
|
185
|
+
// 열린 도구 호출의 시작 시각도 같은 방식으로 한 번만 채운다 (캐시 버전은 그대로).
|
|
186
|
+
if (tailToolStarts(path, this.pending)) markDirty(path, () => this.snapshot());
|
|
68
187
|
}
|
|
69
188
|
}
|
|
70
189
|
|
|
@@ -91,6 +210,19 @@ export class ClaudeTracker {
|
|
|
91
210
|
this.firstAt = null;
|
|
92
211
|
// 시간별 토큰 (common.mjs addActivity)
|
|
93
212
|
this.activity = {};
|
|
213
|
+
// 마지막 대화 줄이 API 오류면 멈춘 이유 { kind: 'auth'|'network'|'api' } (stopReasonOf), 아니면 null.
|
|
214
|
+
// 그 뒤 정상 assistant 줄이나 사용자 줄이 오면 지운다.
|
|
215
|
+
this.stopReason = null;
|
|
216
|
+
// 프롬프트 캐시 (applyCacheUsage): 수명이 시작된 시각(ms), TTL(초), 마지막 사용자 줄 시각(다음 요청 시작으로 본다).
|
|
217
|
+
this.cacheAt = null;
|
|
218
|
+
this.cacheTtl = null;
|
|
219
|
+
this.inputAt = null;
|
|
220
|
+
this.inputFor = null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// 프롬프트 캐시가 만료되는 시각(ms). 캐시를 쓴 응답이 없으면 null.
|
|
224
|
+
get cacheExpiresAt() {
|
|
225
|
+
return Number.isFinite(this.cacheAt) && this.cacheTtl ? this.cacheAt + this.cacheTtl * 1000 : null;
|
|
94
226
|
}
|
|
95
227
|
|
|
96
228
|
get path() {
|
|
@@ -135,6 +267,11 @@ export class ClaudeTracker {
|
|
|
135
267
|
turnCount: this.turnCount,
|
|
136
268
|
firstAt: this.firstAt,
|
|
137
269
|
activity: this.activity,
|
|
270
|
+
stopReason: this.stopReason,
|
|
271
|
+
cacheAt: this.cacheAt,
|
|
272
|
+
cacheTtl: this.cacheTtl,
|
|
273
|
+
inputAt: this.inputAt,
|
|
274
|
+
inputFor: this.inputFor,
|
|
138
275
|
};
|
|
139
276
|
}
|
|
140
277
|
|
|
@@ -167,6 +304,11 @@ export class ClaudeTracker {
|
|
|
167
304
|
if (this.firstAt == null && x.timestamp) this.firstAt = parseTs(x.timestamp);
|
|
168
305
|
if (x.isMeta) return;
|
|
169
306
|
|
|
307
|
+
if ((x.type === 'assistant' || x.type === 'user') && x.message) {
|
|
308
|
+
this.stopReason = stopReasonOf(x);
|
|
309
|
+
cacheStep(this, x);
|
|
310
|
+
}
|
|
311
|
+
|
|
170
312
|
if (x.type === 'assistant' && x.message) {
|
|
171
313
|
const m = x.message;
|
|
172
314
|
if (m.model && !m.model.startsWith('<')) this.model = m.model;
|
|
@@ -177,7 +319,8 @@ export class ClaudeTracker {
|
|
|
177
319
|
for (const c of Array.isArray(m.content) ? m.content : []) {
|
|
178
320
|
if (c.type === 'tool_use') {
|
|
179
321
|
this.lastTool = describeTool(c.name, c.input);
|
|
180
|
-
|
|
322
|
+
// at: 호출을 낸 줄의 시각 (도구 실행 경과 시간의 기준). resumeAt: 허락 대기를 마지막으로 본 시각 (markWaiting).
|
|
323
|
+
this.pending.set(c.id, { name: c.name, what: this.lastTool, detail: toolDetail(c.name, c.input), agent: c.input?.subagent_type ?? null, at: parseTs(x.timestamp) });
|
|
181
324
|
pushEvent(this, x.timestamp, 'tool', this.lastTool);
|
|
182
325
|
this.lastKind = 'tool';
|
|
183
326
|
} else if (c.type === 'text' && c.text?.trim()) {
|
|
@@ -213,6 +356,19 @@ export class ClaudeTracker {
|
|
|
213
356
|
return (named.at(-1) ?? tools.at(-1))?.detail ?? null;
|
|
214
357
|
}
|
|
215
358
|
|
|
359
|
+
// 허락 대기를 보는 동안 열린 도구 호출마다 그 시각을 적는다. 허락한 뒤의 경과 시간은 여기서부터 잰다 (toolStartedAt).
|
|
360
|
+
// 기록에는 허락한 시각이 없으므로 대기를 마지막으로 본 시각(갱신 1초 간격)으로 갈음한다. 기록이 바뀐 것은 아니라 캐시에 따로 적지 않는다.
|
|
361
|
+
markWaiting(now = Date.now()) {
|
|
362
|
+
for (const p of this.pending.values()) if (p.name !== 'Agent' && p.name !== 'Task') p.resumeAt = now;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// phase() 가 보이는 도구(열린 도구 호출 가운데 마지막 것)가 돌기 시작한 시각(ms). 허락을 기다렸으면 대기가 끝난 뒤부터. 모르면 null.
|
|
366
|
+
toolStartedAt() {
|
|
367
|
+
const p = [...this.pending.values()].filter((p) => p.name !== 'Agent' && p.name !== 'Task').at(-1);
|
|
368
|
+
if (!p || !Number.isFinite(p.at)) return null;
|
|
369
|
+
return Number.isFinite(p.resumeAt) ? Math.max(p.at, p.resumeAt) : p.at;
|
|
370
|
+
}
|
|
371
|
+
|
|
216
372
|
// 지금 무엇을 하는 단계인지: 도구 실행 / 팀원 대기 / 생각 중 / 답변 작성 중.
|
|
217
373
|
phase() {
|
|
218
374
|
const open = [...this.pending.values()];
|
package/src/sources/claude.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { contextWindow } from '../pricing.mjs';
|
|
|
7
7
|
import { join, basename } from 'node:path';
|
|
8
8
|
import { isSessionAlive } from '../procs.mjs';
|
|
9
9
|
import { ClaudeTracker, tailCustomTitle } from './claude-tracker.mjs';
|
|
10
|
-
import { emptyTokens, mergeActivity, MEMBER_FADE_MS, sessionName } from './common.mjs';
|
|
10
|
+
import { emptyTokens, isLongTool, mergeActivity, MEMBER_FADE_MS, sessionName } from './common.mjs';
|
|
11
11
|
import { mergeFiles } from './files.mjs';
|
|
12
12
|
import { debug, debugIo } from '../log.mjs';
|
|
13
13
|
import { claudeDirs, claudeProjectRoots, dedupeBy } from './dirs.mjs';
|
|
@@ -148,7 +148,11 @@ function readMembers(transcript, parent, budget) {
|
|
|
148
148
|
costNoCache: t.costNoCache,
|
|
149
149
|
costUnknown: t.costUnknown,
|
|
150
150
|
loading: t.loading != null,
|
|
151
|
-
|
|
151
|
+
// 경과 시간의 기준은 서브에이전트 기록의 첫 줄 시각, 멈춘 듯 판단은 기록 파일의 마지막 수정 시각이다.
|
|
152
|
+
startedAt: t.firstAt ?? t.events[0]?.at,
|
|
153
|
+
lastActivityAt: t.mtimeMs || null,
|
|
154
|
+
// Bash 처럼 결과가 오기까지 오래 걸릴 수 있는 도구가 도는 중이면 멈춘 듯 기준을 길게 잡는다 (common.mjs).
|
|
155
|
+
longStep: [...t.pending.values()].some((p) => isLongTool(p.name)),
|
|
152
156
|
});
|
|
153
157
|
}
|
|
154
158
|
members.sort((a, b) => (a.startedAt ?? 0) - (b.startedAt ?? 0));
|
|
@@ -178,12 +182,39 @@ function phaseOf(status, entry, t) {
|
|
|
178
182
|
case 'shell':
|
|
179
183
|
return { kind: 'tool', msg: 'shell' };
|
|
180
184
|
case 'idle':
|
|
181
|
-
return { kind: 'idle' };
|
|
185
|
+
return stoppedPhase(t) ?? { kind: 'idle' };
|
|
182
186
|
default:
|
|
183
187
|
return loadingPhase(t) ?? (t ? t.phase() : { kind: 'think', msg: 'working' });
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
|
|
191
|
+
// 대기(idle) 중인 세션의 마지막 대화 줄이 API 오류면 '멈춤' 으로 보인다 (claude-tracker.mjs stopReasonOf).
|
|
192
|
+
// 응답 대기·작업 중·종료는 그대로 두고, 기록을 다 읽기 전에는 판단하지 않는다.
|
|
193
|
+
const STOP_MSG = { auth: 'stopAuth', network: 'stopNetwork', api: 'stopApi' };
|
|
194
|
+
function stoppedPhase(t) {
|
|
195
|
+
const r = t?.loading == null ? t?.stopReason : null;
|
|
196
|
+
return r ? { kind: 'stopped', msg: STOP_MSG[r.kind] ?? 'stopApi' } : null;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function cacheOf(alive, status, t) {
|
|
200
|
+
const at = t?.cacheExpiresAt;
|
|
201
|
+
if (!alive || at == null || t.loading != null || (status !== 'waiting' && status !== 'idle') || (status === 'idle' && stoppedPhase(t))) return { cacheExpiresAt: null, cacheTtl: null };
|
|
202
|
+
return { cacheExpiresAt: at, cacheTtl: t.cacheTtl };
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// 도구가 돌기 시작한 시각(ms). 작업 중(busy)이고 진행 단계가 열린 도구 실행일 때만 둔다 (claude-tracker.mjs toolStartedAt).
|
|
206
|
+
// 허락 대기 중에는 두지 않고, 그동안 본 시각을 적어 두어 허락한 뒤에는 그때부터 잰다 (markWaiting).
|
|
207
|
+
// 쉘 명령(! 입력, status 'shell')은 기록에 tool_use 가 없어 빼고, 기록을 다 읽기 전에도 뺀다.
|
|
208
|
+
function toolStartOf(status, phase, t) {
|
|
209
|
+
if (!t) return null;
|
|
210
|
+
if (status === 'waiting') {
|
|
211
|
+
t.markWaiting();
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
if (status !== 'busy' || phase?.kind !== 'tool' || t.loading != null) return null;
|
|
215
|
+
return t.toolStartedAt();
|
|
216
|
+
}
|
|
217
|
+
|
|
187
218
|
// sessions/<pid>.json 은 세션이 끝나면 지워지므로, 끝난 세션은 최근에 바뀐 기록 파일로 찾는다.
|
|
188
219
|
// 폴더를 매번 훑지 않게 목록은 잠깐 재사용하고, 기록 앞부분에서 이름·폴더만 읽어 둔다.
|
|
189
220
|
const DISCOVER_TTL_MS = 10_000;
|
|
@@ -465,6 +496,7 @@ export function collectClaude({ showEnded, budget, selectedId }) {
|
|
|
465
496
|
const { members, sub } = transcript ? readMembers(transcript, t, budget) : { members: [], sub: emptySub() };
|
|
466
497
|
const mtime = Math.max(t?.mtimeMs ?? 0, touched);
|
|
467
498
|
const status = statusOf(e, e.alive, mtime);
|
|
499
|
+
const phase = withRunningMembers(phaseOf(status, e, t), status, members);
|
|
468
500
|
|
|
469
501
|
out.push({
|
|
470
502
|
tool: 'claude',
|
|
@@ -482,7 +514,14 @@ export function collectClaude({ showEnded, budget, selectedId }) {
|
|
|
482
514
|
status,
|
|
483
515
|
// Claude Code 가 상태를 남기지 않아 기록 수정 시각으로 추측한 경우
|
|
484
516
|
statusGuessed: e.alive && !e.waitingFor && !['busy', 'shell', 'idle'].includes(e.status),
|
|
485
|
-
phase
|
|
517
|
+
phase,
|
|
518
|
+
// 지금 도는 도구가 시작된 시각(ms) 또는 null. 화면은 1분이 지나야 STATUS 글 뒤에 경과 시간을 붙인다 (draw.mjs toolElapsed).
|
|
519
|
+
toolStartedAt: toolStartOf(status, phase, t),
|
|
520
|
+
// 멈춘 이유 (phase 가 stopped 일 때만). 끝남(done) 알림과 확인 전(●)을 이 동안 막는다 (attention.mjs).
|
|
521
|
+
stopReason: status === 'idle' && stoppedPhase(t) ? t.stopReason : null,
|
|
522
|
+
// 프롬프트 캐시 만료 시각(ms)과 TTL(초). 응답 대기·다음 지시 대기인 살아 있는 세션에만 둔다 (claude-tracker.mjs applyCacheUsage).
|
|
523
|
+
// 오류로 멈춘 세션과 기록을 다 읽기 전의 세션은 빼고, 시간이 지나 만료돼도 그대로 둔다 (화면이 '캐시 만료' 로 보인다).
|
|
524
|
+
...cacheOf(e.alive, status, t),
|
|
486
525
|
waitingFor: e.waitingFor ?? null,
|
|
487
526
|
waitDetail: status === 'waiting' ? (t?.waitDetail(e.waitingFor) ?? null) : null,
|
|
488
527
|
now: t?.lastTool ?? t?.events.at(-1)?.text ?? '',
|
package/src/sources/codex.mjs
CHANGED
|
@@ -222,10 +222,10 @@ function indexName(path, id) {
|
|
|
222
222
|
return null;
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
const SAVED = ['id', 'threadName', 'cwd', 'branch', 'model', 'busy', 'tokens', 'context', 'window', 'events', 'lastTool', 'startedAt', 'lastKind', 'files', 'turns', 'turnCount', 'activity'];
|
|
225
|
+
const SAVED = ['id', 'threadName', 'cwd', 'branch', 'model', 'busy', 'tokens', 'context', 'window', 'events', 'lastTool', 'startedAt', 'lastKind', 'files', 'turns', 'turnCount', 'activity', 'pendingAt'];
|
|
226
226
|
|
|
227
227
|
function newState(path) {
|
|
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: {} };
|
|
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: {}, pendingAt: {} };
|
|
229
229
|
const c = loadCache(path);
|
|
230
230
|
if (c) {
|
|
231
231
|
st.tail.offset = c.offset;
|
|
@@ -249,6 +249,14 @@ function phaseOf(st, live) {
|
|
|
249
249
|
return st.lastKind === 'reply' ? { kind: 'write' } : { kind: 'think' };
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
// phaseOf 가 보이는 도구(열린 호출 가운데 마지막 것)가 시작된 시각(ms). function_call·custom_tool_call 줄의 시각이다.
|
|
253
|
+
// pendingAt 이 생기기 전 캐시에서 이어 읽는 호출은 시각을 몰라 null. Codex 기록에는 허락 대기 상태가 없어 따로 빼지 않는다.
|
|
254
|
+
function toolStartOf(st, phase) {
|
|
255
|
+
if (phase.kind !== 'tool') return null;
|
|
256
|
+
const at = st.pendingAt?.[[...st.pending.keys()].at(-1)];
|
|
257
|
+
return Number.isFinite(at) ? at : null;
|
|
258
|
+
}
|
|
259
|
+
|
|
252
260
|
function applyLine(st, x) {
|
|
253
261
|
const p = x.payload ?? {};
|
|
254
262
|
if (x.type === 'session_meta') {
|
|
@@ -269,6 +277,7 @@ function applyLine(st, x) {
|
|
|
269
277
|
case 'turn_aborted':
|
|
270
278
|
st.busy = false;
|
|
271
279
|
st.pending.clear();
|
|
280
|
+
st.pendingAt = {};
|
|
272
281
|
st.patches = {};
|
|
273
282
|
break;
|
|
274
283
|
case 'token_count': {
|
|
@@ -328,11 +337,15 @@ function applyLine(st, x) {
|
|
|
328
337
|
if (patchSucceeded(p.output)) for (const r of parsePatch(patch.text, st.cwd)) addChange(st.files, r, patch.at);
|
|
329
338
|
}
|
|
330
339
|
st.pending.delete(p.call_id);
|
|
340
|
+
if (st.pendingAt) delete st.pendingAt[p.call_id];
|
|
331
341
|
st.lastKind = 'result';
|
|
332
342
|
}
|
|
333
343
|
if (what) {
|
|
334
344
|
st.lastTool = what;
|
|
335
|
-
if (p.call_id && p.type !== 'web_search_call')
|
|
345
|
+
if (p.call_id && p.type !== 'web_search_call') {
|
|
346
|
+
st.pending.set(p.call_id, p.name);
|
|
347
|
+
(st.pendingAt ??= {})[p.call_id] = parseTs(x.timestamp);
|
|
348
|
+
}
|
|
336
349
|
pushEvent(st, x.timestamp, 'tool', what);
|
|
337
350
|
st.lastKind = 'tool';
|
|
338
351
|
}
|
|
@@ -346,7 +359,7 @@ export function codexIndexName(path, id) {
|
|
|
346
359
|
return indexName(path, id);
|
|
347
360
|
}
|
|
348
361
|
|
|
349
|
-
export const _test = { newState, applyLine, phaseOf, snapshot, readIndex, indexName };
|
|
362
|
+
export const _test = { newState, applyLine, phaseOf, toolStartOf, snapshot, readIndex, indexName };
|
|
350
363
|
|
|
351
364
|
export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf = processStart, canList = canListProcesses }) {
|
|
352
365
|
// 프로세스를 못 세면 숨기지 않고 최근에 바뀐 기록으로 판정한다 (pid 는 null).
|
|
@@ -424,6 +437,7 @@ export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf =
|
|
|
424
437
|
const used = st.tokens.total > 0;
|
|
425
438
|
// 기록 안의 이름 바꾸기 이벤트가 먼저, 없으면 session_index.jsonl 의 thread_name.
|
|
426
439
|
const customName = st.threadName ?? indexName(f.path, st.id);
|
|
440
|
+
const phase = phaseOf(st, live);
|
|
427
441
|
out.push({
|
|
428
442
|
tool: 'codex',
|
|
429
443
|
id: st.id,
|
|
@@ -439,7 +453,9 @@ export function collectCodex({ showEnded, budget, filesOf = openFiles, startOf =
|
|
|
439
453
|
model: st.model,
|
|
440
454
|
live,
|
|
441
455
|
status: !live ? 'ended' : st.busy ? 'busy' : 'idle',
|
|
442
|
-
phase
|
|
456
|
+
phase,
|
|
457
|
+
// 지금 도는 도구가 시작된 시각(ms) 또는 null (toolStartOf).
|
|
458
|
+
toolStartedAt: toolStartOf(st, phase),
|
|
443
459
|
cost: cost?.total ?? (used ? 0 : null),
|
|
444
460
|
costNoCache: cost?.noCache ?? null,
|
|
445
461
|
costUnknown: used && !cost,
|
package/src/sources/common.mjs
CHANGED
|
@@ -5,6 +5,29 @@ export const MAX_EVENTS = 40;
|
|
|
5
5
|
// 끝난 서브에이전트(팀원)는 이 시간 동안 "완료"로 보였다가 목록에서 사라진다.
|
|
6
6
|
export const MEMBER_FADE_MS = 6000;
|
|
7
7
|
|
|
8
|
+
// 작업 중인 서브에이전트가 '멈춘 듯' 보이기까지 기록이 바뀌지 않은 시간.
|
|
9
|
+
// 서브에이전트는 모델 응답 한 번, 도구 결과 한 번마다 기록에 한 줄을 쓴다. 긴 생각을 하는 응답도 대개 1~2분 안에 끝나므로
|
|
10
|
+
// 3분 동안 한 줄도 없으면 드문 일로 본다. 다만 Bash 같은 도구가 도는 동안에는 결과가 올 때까지 쓰지 않는데,
|
|
11
|
+
// Claude Code 의 Bash 시간 제한이 최대 10분이라 그런 단계에서는 10분을 기다린다.
|
|
12
|
+
// 짐작일 뿐이라 화면에 흐리게만 보이고 정렬·알림·창 제목·--line 에는 쓰지 않는다.
|
|
13
|
+
export const MEMBER_STALL_MS = 3 * 60_000;
|
|
14
|
+
export const MEMBER_STALL_LONG_MS = 10 * 60_000;
|
|
15
|
+
// 결과가 올 때까지 오래 기록이 없을 수 있는 도구 (Claude·agy 이름). 서브에이전트 안의 서브에이전트(Agent·Task)도 그동안 쓰지 않는다.
|
|
16
|
+
// Skill 은 지침 글을 바로 돌려주는 도구라 넣지 않는다.
|
|
17
|
+
export const LONG_TOOLS = new Set(['Bash', 'PowerShell', 'Agent', 'Task', 'WebFetch', 'WebSearch', 'run_command', 'shell', 'call_mcp_tool']);
|
|
18
|
+
// MCP 도구(mcp__서버__도구, agy 는 call_mcp_tool)는 바깥 서버가 응답할 때까지 기다리므로 얼마나 걸릴지 알 수 없어 오래 걸리는 쪽으로 본다.
|
|
19
|
+
export const isLongTool = (name) => LONG_TOOLS.has(name) || String(name ?? '').startsWith('mcp__');
|
|
20
|
+
|
|
21
|
+
// m: 수집기가 만든 팀원. status 'busy' 이고 lastActivityAt 이 기준보다 오래됐으면 true. longStep 이면 긴 기준을 쓴다.
|
|
22
|
+
// 허락을 기다리는 동안은 기록이 멈추는 것이 정상이므로, 팀원이 응답 대기('waiting')이거나 부모 세션(parentStatus)이
|
|
23
|
+
// 응답 대기면 멈춘 듯으로 보지 않는다 (Claude 는 서브에이전트의 허락 요청이 부모 세션의 대기로만 보인다).
|
|
24
|
+
// 팀원 쪽은 'busy' 가 아니면(대기·완료 모두) 따로 보지 않고 false 다. 부모가 기다리면 형제 팀원의 표시도 함께 꺼진다 (덜 알리는 쪽).
|
|
25
|
+
export function memberStalled(m, now = Date.now(), parentStatus = null) {
|
|
26
|
+
if (parentStatus === 'waiting') return false;
|
|
27
|
+
if (m?.status !== 'busy' || !Number.isFinite(m.lastActivityAt)) return false;
|
|
28
|
+
return now - m.lastActivityAt >= (m.longStep ? MEMBER_STALL_LONG_MS : MEMBER_STALL_MS);
|
|
29
|
+
}
|
|
30
|
+
|
|
8
31
|
export function emptyTokens() {
|
|
9
32
|
return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 };
|
|
10
33
|
}
|
package/src/sources/sheets.mjs
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// 세션 이름(사용자 이름, 그 밖 이름)을 모은다. 사용량(토큰·비용)은 장부(claude-ledger.mjs 등)가 세고, 여기서는 세지 않는다.
|
|
3
3
|
// 장부 캐시 모양은 그대로 두고 따로 읽는다 (장부를 다시 세지 않게). 리포트가 기간 안에 사용량이 있는 기록만 부른다.
|
|
4
4
|
// 기록은 읽기만 하고, 어디까지 읽었는지는 aitop 캐시에 둔다.
|
|
5
|
+
// 날짜별로 "나를 기다린 시간"(w, ms)도 모은다: 에이전트 쪽 마지막 줄(응답·도구 결과) 시각부터 다음 사용자 입력(지시, 허락·질문 답)
|
|
6
|
+
// 시각까지의 간격 합이다. 기록에는 화면 앞에 있었는지가 없어 자리를 비운 시간과 가르지 못하는 추정값이다.
|
|
5
7
|
import { JsonlTail } from '../tail.mjs';
|
|
6
8
|
import { loadCache, markDirty } from '../cache.mjs';
|
|
7
9
|
import { dayKey, isNoisePrompt, recentDays, sessionName } from './common.mjs';
|
|
@@ -9,7 +11,9 @@ import { readChange } from './files.mjs';
|
|
|
9
11
|
import { parsePatch, extractPatch, patchSucceeded } from './patch.mjs';
|
|
10
12
|
import { mask, oneLine } from '../text.mjs';
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
// 2: 날짜별 기다린 시간(w)과 이어 읽기용 상태(agentAt)를 더했다 (#243). 예전 캐시는 이미 읽은 줄의 w 가 없어
|
|
15
|
+
// 0 으로 보이므로 kind 를 올려 기록을 한 번 다시 읽는다.
|
|
16
|
+
const KIND = 'sheet2';
|
|
13
17
|
// 하루에 남기는 고친 파일 수 상한 (캐시가 커지지 않게). 넘으면 more 에 표시해 '200+' 처럼 보인다.
|
|
14
18
|
export const FILES_MAX = 200;
|
|
15
19
|
// 캐시에 남기는 지시 글 길이. 화면에는 더 짧게 자른다.
|
|
@@ -18,6 +22,28 @@ const PROMPT_MAX = 200;
|
|
|
18
22
|
const PENDING_MAX = 50;
|
|
19
23
|
// 날짜를 남기는 일수 (리포트가 보는 30일보다 조금 길게).
|
|
20
24
|
const KEEP = 32;
|
|
25
|
+
// 간격 하나에서 세는 기다린 시간 상한 (2시간). 그보다 긴 간격은 대개 자리를 비웠거나 다음 날 이어 쓴 것이라,
|
|
26
|
+
// 그대로 더하면 밤새 열어 둔 세션 하나가 합계를 덮는다. 버리지 않고 앞 2시간만 센다 (에이전트가 끝낸 직후가 실제로 기다린 몫에 가깝다).
|
|
27
|
+
export const WAIT_CAP_MS = 2 * 3600_000;
|
|
28
|
+
|
|
29
|
+
// 다음 로컬 0시 (기다린 시간을 날짜별로 나눌 때 쓴다).
|
|
30
|
+
const nextMidnight = (at) => {
|
|
31
|
+
const d = new Date(at);
|
|
32
|
+
d.setHours(24, 0, 0, 0);
|
|
33
|
+
return d.getTime();
|
|
34
|
+
};
|
|
35
|
+
// Claude 사용자 줄의 글.
|
|
36
|
+
const textOf = (c) => (typeof c === 'string' ? c : Array.isArray(c) ? c.filter((p) => p?.type === 'text').map((p) => p.text).join(' ') : '');
|
|
37
|
+
// 사람이 직접 낸 지시인지. 새 기록은 origin.kind(human, task-notification 등)나 turnOrigin 이 있고, 예전 기록은 글로 가른다
|
|
38
|
+
// (꺾쇠로 시작하는 글 가운데 슬래시 명령만 사람 입력이다).
|
|
39
|
+
function isHumanPrompt(x, text) {
|
|
40
|
+
if (x.origin?.kind) return x.origin.kind === 'human';
|
|
41
|
+
if (x.turnOrigin) return x.turnOrigin === 'human';
|
|
42
|
+
return Boolean(text) && (!isNoisePrompt(text) || /^\s*<command-(name|message)>/.test(text));
|
|
43
|
+
}
|
|
44
|
+
// 도구 결과가 사용자의 답인지: 허락 창에서 사용자가 고른 결과(permissionDecision.source 가 user_ 로 시작)와 질문 도구(AskUserQuestion)의 답.
|
|
45
|
+
// 허락 창이 뜬 시각은 기록에 없어, 도구 호출 줄부터 결과 줄까지를 기다림으로 센다 (허락 뒤 도구가 돈 시간도 섞인다).
|
|
46
|
+
const isUserAnswer = (x) => /^user/.test(x.permissionDecision?.source ?? '') || (x.toolUseResult?.questions != null && x.toolUseResult?.answers != null);
|
|
21
47
|
|
|
22
48
|
const clip = (s) => {
|
|
23
49
|
const one = mask(oneLine(s));
|
|
@@ -41,6 +67,7 @@ export class SessionSheet {
|
|
|
41
67
|
this.id = c.id ?? null;
|
|
42
68
|
this.cwd = c.cwd ?? null;
|
|
43
69
|
this.pending = c.pending ?? {};
|
|
70
|
+
this.agentAt = c.agentAt ?? null;
|
|
44
71
|
}
|
|
45
72
|
}
|
|
46
73
|
|
|
@@ -55,6 +82,8 @@ export class SessionSheet {
|
|
|
55
82
|
this.cwd = null;
|
|
56
83
|
// Codex: 결과를 기다리는 패치 호출 id → 고칠 파일 경로들.
|
|
57
84
|
this.pending = {};
|
|
85
|
+
// 에이전트 쪽 마지막 줄 시각. 그 뒤 사용자 입력이 오면 그 사이를 기다린 시간으로 센다. 사용자 입력 뒤에는 null.
|
|
86
|
+
this.agentAt = null;
|
|
58
87
|
}
|
|
59
88
|
|
|
60
89
|
// 아직 읽지 않은 크기.
|
|
@@ -73,16 +102,54 @@ export class SessionSheet {
|
|
|
73
102
|
}
|
|
74
103
|
|
|
75
104
|
snapshot() {
|
|
76
|
-
return { offset: this.tail.lineOffset, days: recentDays(this.days, KEEP), custom: this.custom, title: this.title, id: this.id, cwd: this.cwd, pending: this.pending };
|
|
105
|
+
return { offset: this.tail.lineOffset, days: recentDays(this.days, KEEP), custom: this.custom, title: this.title, id: this.id, cwd: this.cwd, pending: this.pending, agentAt: this.agentAt };
|
|
77
106
|
}
|
|
78
107
|
|
|
79
108
|
day(at) {
|
|
80
109
|
const d = (this.days[dayKey(at)] ??= { a: at, z: at, f: [] });
|
|
81
|
-
|
|
82
|
-
if (
|
|
110
|
+
// 기다린 시간만 넘어온 날(answer)은 a·z 가 없다.
|
|
111
|
+
if (!(d.a <= at)) d.a = at;
|
|
112
|
+
if (!(d.z >= at)) d.z = at;
|
|
83
113
|
return d;
|
|
84
114
|
}
|
|
85
115
|
|
|
116
|
+
// 에이전트 쪽 줄: 여기부터 사용자를 기다린다.
|
|
117
|
+
agent(at) {
|
|
118
|
+
this.agentAt = at;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 사용자 입력: 에이전트 쪽 마지막 줄부터 지금까지(상한 WAIT_CAP_MS)를 날짜별로 나눠 더한다.
|
|
122
|
+
// 기간은 로컬 0시에 끊기므로 날짜별로 나눠 두면 기간 경계에 걸친 간격도 기간 안 몫만 세어진다.
|
|
123
|
+
answer(at) {
|
|
124
|
+
const from = this.agentAt;
|
|
125
|
+
this.agentAt = null;
|
|
126
|
+
if (from == null || !(at > from)) return;
|
|
127
|
+
const end = from + Math.min(at - from, WAIT_CAP_MS);
|
|
128
|
+
for (let t = from; t < end; ) {
|
|
129
|
+
const cut = Math.min(end, nextMidnight(t));
|
|
130
|
+
const d = (this.days[dayKey(t)] ??= { f: [] });
|
|
131
|
+
d.w = (d.w ?? 0) + (cut - t);
|
|
132
|
+
t = cut;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Claude 줄 하나로 기다린 시간 상태를 바꾼다. 서브에이전트 기록은 세지 않는다 (부모 세션에서만 센다, 이중 계산 방지).
|
|
137
|
+
waitClaude(x, at) {
|
|
138
|
+
// 예전 기록은 서브에이전트 줄(isSidechain)을 부모 기록 안에 섞어 썼다.
|
|
139
|
+
if (this.sub || x.isSidechain) return;
|
|
140
|
+
if (x.type === 'assistant') return this.agent(at);
|
|
141
|
+
if (x.isMeta || x.isCompactSummary || !x.message) return;
|
|
142
|
+
const c = x.message.content;
|
|
143
|
+
if (Array.isArray(c) && c.some((p) => p?.type === 'tool_result')) return isUserAnswer(x) ? this.answer(at) : this.agent(at);
|
|
144
|
+
const text = textOf(c);
|
|
145
|
+
// 사용자가 끊으면 에이전트는 그때 멈추고 다음 지시를 기다린다. 끊기 전은 에이전트가 일하던 시간이다.
|
|
146
|
+
if (/^\s*\[Request interrupted/.test(text)) return this.agent(at);
|
|
147
|
+
if (!isHumanPrompt(x, text)) return;
|
|
148
|
+
// 에이전트가 일하는 동안 미리 넣어 둔 지시(queued)는 기다림이 아니다.
|
|
149
|
+
if (x.promptSource === 'queued') this.agentAt = null;
|
|
150
|
+
else this.answer(at);
|
|
151
|
+
}
|
|
152
|
+
|
|
86
153
|
addFile(at, path) {
|
|
87
154
|
if (typeof path !== 'string' || !path) return;
|
|
88
155
|
const d = this.day(at);
|
|
@@ -105,14 +172,14 @@ export class SessionSheet {
|
|
|
105
172
|
const at = Date.parse(x.timestamp);
|
|
106
173
|
if (!Number.isFinite(at)) return;
|
|
107
174
|
this.day(at);
|
|
175
|
+
this.waitClaude(x, at);
|
|
108
176
|
if (x.type !== 'user' || x.isMeta || !x.message) return;
|
|
109
177
|
if (x.toolUseResult) {
|
|
110
178
|
const c = readChange(x.toolUseResult, at);
|
|
111
179
|
if (c) this.addFile(at, c.path);
|
|
112
180
|
}
|
|
113
181
|
const c = x.message.content;
|
|
114
|
-
|
|
115
|
-
this.prompt(at, text);
|
|
182
|
+
this.prompt(at, textOf(c));
|
|
116
183
|
}
|
|
117
184
|
|
|
118
185
|
applyCodex(x) {
|
|
@@ -129,9 +196,16 @@ export class SessionSheet {
|
|
|
129
196
|
this.day(at);
|
|
130
197
|
if (x.type === 'event_msg') {
|
|
131
198
|
if (p.type === 'thread_name_updated') this.custom = sessionName(p.thread_name);
|
|
132
|
-
if (p.type === 'user_message')
|
|
199
|
+
if (p.type === 'user_message') {
|
|
200
|
+
this.prompt(at, p.message);
|
|
201
|
+
this.answer(at);
|
|
202
|
+
} else if (p.type === 'turn_aborted') this.agent(at);
|
|
203
|
+
// 차례 시작 알림은 사용자 지시와 함께 오므로 에이전트 줄로 보지 않는다. 그 밖(agent_message, token_count 등)은 에이전트 쪽이다.
|
|
204
|
+
else if (p.type !== 'thread_name_updated' && p.type !== 'task_started' && p.type !== 'turn_started') this.agent(at);
|
|
133
205
|
return;
|
|
134
206
|
}
|
|
207
|
+
// Codex 는 허락 요청·답을 기록에 남기지 않아 user_message 만 사용자 입력으로 센다. 사용자·개발자 메시지 줄은 에이전트 쪽이 아니다.
|
|
208
|
+
if (!(p.type === 'message' && p.role !== 'assistant')) this.agent(at);
|
|
135
209
|
// 패치는 결과가 성공일 때만 고친 파일로 센다 (codex.mjs 와 같다).
|
|
136
210
|
let text = null;
|
|
137
211
|
if (p.type === 'custom_tool_call' && p.name === 'apply_patch') text = String(p.input ?? '');
|
package/src/text.mjs
CHANGED
|
@@ -254,3 +254,12 @@ export function fmtAgo(ms) {
|
|
|
254
254
|
if (s < 86400) return Math.floor(s / 3600) + 'h';
|
|
255
255
|
return Math.floor(s / 86400) + 'd';
|
|
256
256
|
}
|
|
257
|
+
|
|
258
|
+
// 서브에이전트 경과 시간. 1분 아래는 42s, 1시간 아래는 3m12s, 그 위는 1h05m (초는 버린다).
|
|
259
|
+
export function fmtElapsed(ms) {
|
|
260
|
+
const s = Math.max(0, Math.floor(ms / 1000));
|
|
261
|
+
const two = (n) => String(n).padStart(2, '0');
|
|
262
|
+
if (s < 60) return `${s}s`;
|
|
263
|
+
if (s < 3600) return `${Math.floor(s / 60)}m${two(s % 60)}s`;
|
|
264
|
+
return `${Math.floor(s / 3600)}h${two(Math.floor(s / 60) % 60)}m`;
|
|
265
|
+
}
|
package/src/ui/chrome.mjs
CHANGED
package/src/ui/detail.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { ellipsis, fmtAgo, fmtTokens, pad, truncateLeft, width } from '../text.m
|
|
|
3
3
|
import { currentTab, filesForTab, turnTabs } from '../turns.mjs';
|
|
4
4
|
import { isAbsolute, relative } from 'node:path';
|
|
5
5
|
import { PALETTE, PHASE_COLOR } from './theme.mjs';
|
|
6
|
-
import { NOW, box, clock, fill, gauge, glyph, hhmm, levelBar, money, rule, segsWidth, tilde } from './draw.mjs';
|
|
6
|
+
import { NOW, box, cacheState, clock, fill, gauge, glyph, hhmm, levelBar, money, rule, segsWidth, tilde } from './draw.mjs';
|
|
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';
|
|
@@ -287,10 +287,13 @@ export function summaryLines(s, w, frame, view) {
|
|
|
287
287
|
const g = glyph(s, frame);
|
|
288
288
|
const phase = [{ ...g, t: g.t + ' ' }, { t: phaseText(s.phase) || s.status, fg: PHASE_COLOR[s.phase?.kind] ?? PALETTE.text, bold: true }];
|
|
289
289
|
const sep = { t: ' · ', fg: PALETTE.info };
|
|
290
|
+
const cache = cacheState(s);
|
|
290
291
|
const optional = [
|
|
291
292
|
s.branch && [sep, { t: s.branch, fg: PALETTE.info }],
|
|
292
293
|
s.kind && [sep, { t: s.kind, fg: PALETTE.info }],
|
|
293
294
|
s.startedAt && [sep, { t: tr('detail.startedAgo', { at: hhmm(s.startedAt), ago: fmtAgo(NOW - s.startedAt) }), fg: PALETTE.info }],
|
|
295
|
+
// 캐시 남은 시간은 표의 STATUS 칸과 같은 짧은 글로, 가장 먼저 뺀다.
|
|
296
|
+
cache && [sep, { t: cache.text, fg: cache.fg, bold: cache.bold }],
|
|
294
297
|
].filter(Boolean);
|
|
295
298
|
// 폴더가 FOLDER_MIN 칸(짧으면 제 길이)을 얻을 때까지 시작 → 종류 → 브랜치 순으로 뺀다. 폴더는 왼쪽부터 줄여 끝 이름을 남긴다.
|
|
296
299
|
const path = tilde(s.cwd ?? '');
|
|
@@ -364,6 +367,8 @@ export function detail(s, W, H, frame, view) {
|
|
|
364
367
|
|
|
365
368
|
const g = glyph(s, frame);
|
|
366
369
|
L.push([{ ...g, t: g.t + ' ' }, { t: phaseText(s.phase) || s.status, fg: PHASE_COLOR[s.phase?.kind] ?? PALETTE.text, bold: true }]);
|
|
370
|
+
const cache = cacheState(s);
|
|
371
|
+
if (cache) L.push([{ t: ' ' }, { t: cache.expired ? tr('detail.cacheExpired', { ttl: cache.ttl }) : tr('detail.cacheLeft', { t: cache.left, ttl: cache.ttl }), fg: cache.expired ? PALETTE.info : cache.fg, bold: cache.bold }]);
|
|
367
372
|
section(tr('detail.session'));
|
|
368
373
|
kv(tr('detail.folder'), tilde(s.cwd));
|
|
369
374
|
if (s.branch) kv(tr('detail.branch'), s.branch);
|