@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/src/ui/draw.mjs CHANGED
@@ -1,9 +1,11 @@
1
1
  // 그리기 기본: 조각(segment) 줄 만들기·자르기·채우기, 상자, 가로줄, 게이지, 시각·금액 표기.
2
- import { pad, stripControl, truncate, width } from '../text.mjs';
2
+ import { fmtElapsed, pad, stripControl, truncate, width } from '../text.mjs';
3
3
  import { homedir } from 'node:os';
4
4
  import { tildeIn } from '../paths.mjs';
5
5
  import { NO_COLOR, PALETTE, PHASE_COLOR, RESET, style } from './theme.mjs';
6
6
  import { glyphs } from './glyphs.mjs';
7
+ import { t as tr } from '../i18n.mjs';
8
+ import { MEMBER_STALL_LONG_MS } from '../sources/common.mjs';
7
9
 
8
10
  // segs: [{ t: 텍스트, ...style }]. 폭 W 에 맞춰 자르고, 남는 칸은 bg 로 채운다.
9
11
  // 화면에 나가는 글자는 모두 여기를 지나므로, 기록에서 온 제어문자도 여기서 한 번 더 지운다.
@@ -43,12 +45,14 @@ export function glyph(s, frame) {
43
45
  if (k === 'ended') return { t: G.ended, fg: PALETTE.ended };
44
46
  if (k === 'done') return { t: '✓', fg: PALETTE.info };
45
47
  if (k === 'unseen') return { t: G.unseen, fg: PALETTE.busy, bold: true };
48
+ // 오류로 멈춤: 돌지 않는 ! 로 작업 중(스피너)과 구분한다.
49
+ if (k === 'stopped') return { t: '!', fg: PALETTE.alert, bold: true };
46
50
  if (k === 'idle') return s.status === 'live' ? { t: G.live, fg: PALETTE.tools[s.tool] } : { t: G.idle, fg: PALETTE.idle };
47
51
  return { t: SPIN[frame % SPIN.length], fg: PHASE_COLOR[k] ?? PALETTE.busy, bold: true };
48
52
  }
49
53
 
50
54
  // glyph 가 frame 에 따라 모양을 바꾸는지 (응답 대기 깜빡임, 작업 중 스피너).
51
- export const glyphMoves = (s) => s.status === 'waiting' || !['ended', 'done', 'unseen', 'idle'].includes(s.phase?.kind);
55
+ export const glyphMoves = (s) => s.status === 'waiting' || !['ended', 'done', 'unseen', 'idle', 'stopped'].includes(s.phase?.kind);
52
56
 
53
57
  // 막대는 같은 높이의 얇은 블록(▃)으로 그리고 채운 칸과 빈칸은 색으로 나눈다. 칸 높이가 모두 같아 끝이 튀어나오지 않는다.
54
58
  // 색이 없으면 빈칸을 가장 얇은 ▁ 로 그려 모양으로 구분한다. 기호는 glyphs().bar 에 있다.
@@ -153,3 +157,31 @@ export function levelBar(values) {
153
157
  const max = Math.max(0, ...v);
154
158
  return v.map((x) => (!(x > 0) || !(max > 0) ? { t: bars[0], fg: PALETTE.faint } : { t: bars[Math.min(7, Math.max(1, Math.ceil((x / max) * 7)))], fg: PALETTE.info }));
155
159
  }
160
+
161
+ // 프롬프트 캐시 만료까지 남은 시간 (claude.mjs cacheOf). 남은 시간은 m:ss 로, 1분 미만이면 경고색, 만료면 흐린 '캐시 만료'.
162
+ // 초 단위로 바뀌지만 타이머를 따로 두지 않는다: 실시간 화면은 데이터 갱신(1초마다)에 맞춰 다시 그리므로 그때 바뀐다.
163
+ // 그래서 animating() 에 넣지 않고, 스피너가 없는 화면에서 120ms 프레임 타이머를 깨우지 않는다.
164
+ export const CACHE_WARN_MS = 60_000;
165
+ export function cacheState(s, now = NOW) {
166
+ if (s?.cacheExpiresAt == null || !s.live || (s.status !== 'waiting' && s.status !== 'idle')) return null;
167
+ const left = s.cacheExpiresAt - now;
168
+ const ttl = tr(s.cacheTtl >= 3600 ? 'cache.ttl1h' : 'cache.ttl5m');
169
+ if (left <= 0) return { expired: true, ttl, text: tr('cache.expired'), fg: PALETTE.faint };
170
+ const sec = Math.ceil(left / 1000);
171
+ const t = `${Math.floor(sec / 60)}:${String(sec % 60).padStart(2, '0')}`;
172
+ return { expired: false, ttl, left: t, text: tr('cache.left', { t }), fg: left < CACHE_WARN_MS ? PALETTE.alert : PALETTE.info, bold: left < CACHE_WARN_MS };
173
+ }
174
+
175
+ // 지금 도는 도구의 경과 시간 (수집기의 toolStartedAt). 작업 중이고 진행 단계가 도구 실행인 세션만 본다.
176
+ // 1분 미만은 대부분의 도구 호출이 끝나는 시간이라 보이지 않는다 (짧은 도구마다 숫자가 깜빡이지 않게).
177
+ // TOOL_LONG_MS(10분) 이상이면 흐린 경고색: Claude Code 의 Bash 시간 제한이 최대 10분이라 #233 의 '멈춘 듯' 긴 기준과 같은 값을 쓴다.
178
+ // 형식은 팀원 행 경과 시간과 같은 fmtElapsed 다. 이 세션은 작업 중이라 스피너가 돌고(animating) 그 틱에 실려 바뀌므로 타이머를 따로 두지 않는다.
179
+ export const TOOL_SHOW_MS = 60_000;
180
+ export const TOOL_LONG_MS = MEMBER_STALL_LONG_MS;
181
+ export function toolElapsed(s, now = NOW) {
182
+ if (!Number.isFinite(s?.toolStartedAt) || s.status !== 'busy' || s.phase?.kind !== 'tool') return null;
183
+ const ms = now - s.toolStartedAt;
184
+ if (ms < TOOL_SHOW_MS) return null;
185
+ const long = ms >= TOOL_LONG_MS;
186
+ return { text: fmtElapsed(ms), fg: long ? PALETTE.alert : PALETTE.info, dim: long, long };
187
+ }
package/src/ui/table.mjs CHANGED
@@ -2,9 +2,10 @@
2
2
  import { describe } from '../doctor.mjs';
3
3
  import { BRAND } from '../brand.mjs';
4
4
  import { projectBudget } from '../budget.mjs';
5
- import { fmtAgo, fmtTokens, pad, truncate, width } from '../text.mjs';
5
+ import { fmtAgo, fmtElapsed, fmtTokens, pad, truncate, width } from '../text.mjs';
6
+ import { memberStalled } from '../sources/common.mjs';
6
7
  import { BUDGET_COLOR, PALETTE, PHASE_COLOR, RESET, style } from './theme.mjs';
7
- import { NOW, SPIN, clock, costOf, gauge, glyph, levelBar, line, money, segsWidth, shortModel } from './draw.mjs';
8
+ import { NOW, SPIN, cacheState, clock, toolElapsed, costOf, gauge, glyph, levelBar, line, money, segsWidth, shortModel } from './draw.mjs';
8
9
  import { glyphs } from './glyphs.mjs';
9
10
  import { phaseText, t } from '../i18n.mjs';
10
11
  import { NO_FOLDER } from '../order.mjs';
@@ -349,7 +350,7 @@ export function sessionRow(s, c, W, selected, frame, hot, costMode = 'api', pinn
349
350
  segs.push(...pin, { t: pad(s.name ?? '', c.name - segsWidth(pin)) + ' ', fg: ended ? PALETTE.ended : PALETTE.text, bold: selected });
350
351
  if (c.showProject) segs.push({ t: pad(s.project ?? '', c.project) + ' ', fg: ended ? PALETTE.ended : PALETTE.muted });
351
352
  segs.push(
352
- { t: pad(status, c.status) + ' ', fg: pc, bold: s.status === 'waiting' },
353
+ ...statusCell(status, cacheState(s) ?? toolElapsed(s), c.status, { fg: pc, bold: s.status === 'waiting' }),
353
354
  { t: pad(partial ? '…' : blank ? '' : fmtTokens(s.tokens.total), c.tokens, 'right') + ' ', fg: ended ? PALETTE.ended : partial ? PALETTE.info : PALETTE.muted },
354
355
  );
355
356
  if (c.showCost) segs.push(partial ? { t: pad('…', c.cost, 'right') + ' ', fg: PALETTE.info } : { t: pad(blank ? '' : (hot?.has(s.id) ? glyphs().hot : '') + money(costOf(s, costMode), s.costUnknown), c.cost, 'right') + ' ', fg: s.cost == null || ended ? PALETTE.info : hot?.has(s.id) ? PALETTE.money : PALETTE.muted, bold: Boolean(hot?.has(s.id)) });
@@ -358,6 +359,20 @@ export function sessionRow(s, c, W, selected, frame, hot, costMode = 'api', pinn
358
359
  return line(ended ? segs.map((x) => ({ ...x, italic: true })) : segs, W, bg);
359
360
  }
360
361
 
362
+ // 세션 행의 STATUS 칸 (뒤 공백 포함). 덧붙일 짧은 글(tag)이 있으면 상태 글 뒤에 ' · 캐시 3:12' 처럼 붙인다.
363
+ // tag 는 기다리는 세션의 캐시 남은 시간(cacheState) 또는 작업 중 세션의 도구 경과 시간(toolElapsed)이다. 두 상태가 달라 함께 붙지 않는다.
364
+ // 덧붙인 글이 먼저 빠지는 정보다: 다 들어가면 그대로, 상태 글을 TAG_STATUS_MIN 칸까지 줄여 들어가면 줄여서 붙이고, 아니면 뺀다.
365
+ const TAG_STATUS_MIN = 12;
366
+ export function statusCell(status, tag, w, look) {
367
+ const plain = [{ t: pad(status, w) + ' ', ...look }];
368
+ if (!tag) return plain;
369
+ const segs = [{ t: ' · ', fg: PALETTE.info }, { t: tag.text, fg: tag.fg, bold: tag.bold, dim: tag.dim }];
370
+ const room = w - segsWidth(segs);
371
+ if (room < Math.min(width(status), TAG_STATUS_MIN)) return plain;
372
+ const head = truncate(status, room);
373
+ return [{ t: head, ...look }, ...segs, { t: ' '.repeat(Math.max(0, room - width(head))) + ' ' }];
374
+ }
375
+
361
376
  // 기록을 읽는 중인 세션의 CONTEXT 칸: 빈 막대와 … (gauge 와 같은 폭).
362
377
  const pendingGauge = (cells) => [{ t: glyphs().bar.empty.repeat(cells), fg: PALETTE.faint }, { t: pad('…', 5, 'right'), fg: PALETTE.info }];
363
378
 
@@ -366,8 +381,10 @@ const pendingGauge = (cells) => [{ t: glyphs().bar.empty.repeat(cells), fg: PALE
366
381
  export const statusText = (phase) => phaseText(phase, { short: true });
367
382
 
368
383
  // 메인 세션 아래에 붙는 팀원(서브에이전트) 행. 끝나면 잠깐 "완료"로 보였다가 사라진다.
369
- // parentModel: 부모와 같은 모델이면 모델 칸을 비운다. costMode: 'api' | 'net'.
370
- export function memberRow(m, last, c, W, frame, parentModel, costMode = 'api') {
384
+ // parentModel: 부모와 같은 모델이면 모델 칸을 비운다. costMode: 'api' | 'net'. parentStatus: 부모 세션 상태 (응답 대기면 멈춘 듯을 붙이지 않는다).
385
+ // 경과 시간은 초 단위로 바뀌지만 타이머를 따로 두지 않는다. 작업 중인 팀원이 있으면 ui.mjs animating() 이 이미 참이라
386
+ // 스피너 틱(120ms)마다 다시 그리고 있고, 그 틱에 실려 바뀐다. 끝난 팀원(done)은 경과 시간을 그리지 않아 틱을 붙잡지 않는다.
387
+ export function memberRow(m, last, c, W, frame, parentModel, costMode = 'api', parentStatus = null) {
371
388
  const done = m.status === 'done';
372
389
  const g = done ? { t: '✓', fg: PALETTE.info } : { t: SPIN[(frame + 3) % SPIN.length], fg: PALETTE.team, bold: true };
373
390
  const branch = last ? glyphs().memberLast : glyphs().member;
@@ -389,11 +406,26 @@ export function memberRow(m, last, c, W, frame, parentModel, costMode = 'api') {
389
406
  { t: label, fg: done ? PALETTE.info : PALETTE.team },
390
407
  { t: pad(showSuffix ? suffix : '', nameW - width(label)) + ' ', fg: PALETTE.info },
391
408
  );
409
+ // 팀원 행은 CONTEXT·IDLE 칸이 비므로 그 자리(둘 사이 공백 포함)에 작업 중 경과 시간과 '멈춘 듯' 을 오른쪽 맞춤으로 둔다.
410
+ // 두 칸은 폭과 상관없이 늘 있는 열이라, 좁아지면 이름·STATUS 가 먼저 줄고 경과 시간은 남는다 (세션 행의 IDLE 과 같은 규칙).
411
+ // '멈춘 듯' 은 글자로 적어 색이 없어도 구분되고, 흐린 색으로만 둔다. 놓는 곳은 위에서부터 들어가는 첫 자리다:
412
+ // 끝 칸에 '멈춘 듯 3m12s' → STATUS 칸 앞 (CTX 5칸만 남는 폭) → STATUS 칸도 그보다 좁으면 경과 시간 뒤에 '?' 하나 (3m12s?).
413
+ const tailW = c.ctx + 1 + c.age;
414
+ const elapsed = !done && Number.isFinite(m.startedAt) ? fmtElapsed(NOW - m.startedAt) : '';
415
+ const stalled = !done && memberStalled(m, NOW, parentStatus) ? t('member.stalled') : '';
416
+ const both = stalled && elapsed ? width(stalled) + 1 + width(elapsed) <= tailW : Boolean(stalled);
417
+ const before = stalled && !both && c.status >= width(stalled) + 1;
418
+ const quest = stalled && !both && !before;
419
+ const inStatus = before ? [{ t: `${stalled} `, fg: PALETTE.info, italic: true }] : [];
392
420
  segs.push(
393
- { t: pad(statusText(m.phase), c.status) + ' ', fg: done ? PALETTE.info : PHASE_COLOR[m.phase?.kind] ?? PALETTE.muted },
421
+ ...inStatus,
422
+ { t: pad(statusText(m.phase), Math.max(0, c.status - segsWidth(inStatus))) + ' ', fg: done ? PALETTE.info : PHASE_COLOR[m.phase?.kind] ?? PALETTE.muted },
394
423
  { t: pad(m.loading ? '…' : started ? fmtTokens(m.tokens ?? 0) : '', c.tokens, 'right') + ' ', fg: done || m.loading ? PALETTE.info : PALETTE.muted },
395
424
  );
396
425
  if (c.showCost) segs.push({ t: pad(m.loading ? '…' : started ? money(costOf(m, costMode), m.costUnknown) : '', c.cost, 'right') + ' ', fg: done || m.loading ? PALETTE.info : PALETTE.muted });
426
+ const mark = stalled && both ? [{ t: stalled, fg: PALETTE.info, italic: true }, ...(elapsed ? [{ t: ' ' }] : [])] : [];
427
+ const time = elapsed ? [{ t: elapsed, fg: PALETTE.info }, ...(quest ? [{ t: '?', fg: PALETTE.info, italic: true }] : [])] : [];
428
+ if (mark.length || time.length) segs.push({ t: ' '.repeat(Math.max(0, tailW - segsWidth([...mark, ...time]))) }, ...mark, ...time);
397
429
  // 끝난 팀원은 종료 행처럼 기울임꼴로 둔다.
398
430
  return line(done ? segs.map((x) => ({ ...x, italic: true })) : segs, W);
399
431
  }
package/src/ui/theme.mjs CHANGED
@@ -128,7 +128,7 @@ export const RESET = NO_COLOR ? '' : '\x1b[0m';
128
128
  export const BUDGET_TOKEN = { caution: 'team', warn: 'alert' };
129
129
  export const BUDGET_COLOR = { caution: PALETTE[BUDGET_TOKEN.caution], warn: PALETTE[BUDGET_TOKEN.warn] };
130
130
 
131
- export const PHASE_COLOR = { tool: PALETTE.tool, team: PALETTE.team, think: PALETTE.busy, write: PALETTE.busy, waiting: PALETTE.waiting, idle: PALETTE.idle, ended: PALETTE.ended, done: PALETTE.info, unseen: PALETTE.busy };
131
+ export const PHASE_COLOR = { tool: PALETTE.tool, team: PALETTE.team, think: PALETTE.busy, write: PALETTE.busy, waiting: PALETTE.waiting, idle: PALETTE.idle, ended: PALETTE.ended, done: PALETTE.info, unseen: PALETTE.busy, stopped: PALETTE.alert };
132
132
 
133
133
  // 상자 테두리. 포커스가 있으면 강조색으로, 색이 없으면 굵은 선으로 구분한다.
134
134
  export const EDGE = {
package/src/ui.mjs CHANGED
@@ -84,7 +84,7 @@ export function render(view, W, H) {
84
84
  // 준비 완료 전에는 값이 커지는 대로 ▲ 가 옮겨 다니므로 붙이지 않는다.
85
85
  const hot = view.ready === false ? null : topCost(visible.filter(isSession).map((r) => r.s), view.costMode);
86
86
  if (!sessions.length) table.push(...(view.filter ? [line([{ t: ` ${t('ui.noMatch', { q: view.filter })}`, fg: PALETTE.muted, italic: true }], TW)] : emptyLines(view, TW)));
87
- for (const r of visible) table.push(r.g ? groupRow(r.g, TW) : r.m ? memberRow(r.m, r.last, c, TW, view.frame, r.s.model, view.costMode) : sessionRow(r.s, c, TW, r.s === sel, view.frame, hot, view.costMode, Boolean(view.pins?.includes(r.s.id))));
87
+ for (const r of visible) table.push(r.g ? groupRow(r.g, TW) : r.m ? memberRow(r.m, r.last, c, TW, view.frame, r.s.model, view.costMode, r.s.status) : sessionRow(r.s, c, TW, r.s === sel, view.frame, hot, view.costMode, Boolean(view.pins?.includes(r.s.id))));
88
88
  if (clipped) {
89
89
  const onScreen = new Set(visible.filter(isSession).map((r) => r.s));
90
90
  const hidden = sessions.filter((s) => !onScreen.has(s));