@sejuneoh/aitop 0.21.3 → 0.23.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 +16 -1
- package/bin/aitop.mjs +51 -43
- package/package.json +3 -3
- package/src/config.mjs +33 -25
- package/src/doctor.mjs +45 -24
- package/src/help.mjs +87 -57
- package/src/i18n.mjs +809 -0
- package/src/json.mjs +8 -2
- package/src/line.mjs +78 -0
- package/src/notify.mjs +14 -8
- package/src/order.mjs +4 -3
- package/src/sources/antigravity.mjs +16 -15
- package/src/sources/claude-tracker.mjs +4 -4
- package/src/sources/claude.mjs +27 -13
- package/src/sources/codex.mjs +5 -5
- package/src/sources/gemini.mjs +1 -1
- package/src/ui/chrome.mjs +62 -54
- package/src/ui/detail.mjs +49 -42
- package/src/ui/table.mjs +35 -33
- package/src/ui.mjs +4 -3
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
- **Changed files and diffs** per session and per prompt
|
|
12
12
|
- **Read-only**: no network, no ports, no dependencies. It only reads the session logs each CLI already writes
|
|
13
13
|
|
|
14
|
-
> The
|
|
14
|
+
> The UI follows your locale: English by default, Korean when the locale starts with `ko`. Set `AITOP_LANG=ko|en` (or `--lang`) to pick one. This covers the live screen, `--once`, `--help`, `--doctor`, error messages and desktop notifications. Keys and options work the same in both.
|
|
15
15
|
|
|
16
16
|
## Install
|
|
17
17
|
|
|
@@ -29,7 +29,22 @@ aitop live screen
|
|
|
29
29
|
aitop --all include sessions that ended in the last 24 hours
|
|
30
30
|
aitop --json print a snapshot as JSON and exit
|
|
31
31
|
aitop --doctor check which tools and logs aitop can see
|
|
32
|
+
aitop --line print one short status line and exit (for tmux, e.g. $54.13/$50 wait 2 $3.1/h)
|
|
32
33
|
aitop --help all options
|
|
34
|
+
aitop --lang ko Korean screen, help, doctor and error messages (also AITOP_LANG=ko or "lang": "ko" in the config file)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The language is picked from `--lang`, then `AITOP_LANG`, then `lang` in the config file, then `LC_ALL`, `LC_MESSAGES` and `LANG`: Korean when the locale starts with `ko`, English otherwise (including `C.UTF-8` and unset). If you used aitop on a `C.UTF-8` or `en_US` locale before, the screen, help and doctor output are now in English; set `AITOP_LANG=ko` to keep Korean.
|
|
38
|
+
|
|
39
|
+
In `--json`, `phase` stays the Korean status text in every language (as does `AITOP_WAITING_FOR` for `--on-waiting`). For scripts, use `phaseKind`, a stable state name: `think`, `write`, `tool`, `team`, `waiting`, `idle`, `done`, `ended` (or `null`). Other text fields follow their own rules: with English selected, `--doctor --json` has Korean `tools.*.hint` but English `config.problems`.
|
|
40
|
+
|
|
41
|
+
### tmux status line
|
|
42
|
+
|
|
43
|
+
`aitop --line` prints today's cost (API list price, `/$<budget>` when a daily budget is set), the number of Claude Code sessions waiting for you, and spend over the last hour. Items that are 0 are left out, and `--line-width N` (default 40) drops items from the end. It reads only aitop's cache, so it is fast once `aitop` has run before; with no cache yet it prints `...` after about 1.5 seconds. `--line=tmux` adds tmux colors, `NO_COLOR` turns them off.
|
|
44
|
+
|
|
45
|
+
```tmux
|
|
46
|
+
set -g status-right '#(aitop --line=tmux)'
|
|
47
|
+
set -g status-interval 15
|
|
33
48
|
```
|
|
34
49
|
|
|
35
50
|
Keys: `↑↓` select · `n` next session to check · `/` search · `s` sort · `g` group · `p` pin · `f` changed files · `?` help · `q` quit
|
package/bin/aitop.mjs
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
|
-
import { budgetDayOption, configJson, configText, resolveConfig } from '../src/config.mjs';
|
|
3
|
+
import { budgetDayOption, configJson, configPath, configText, readConfigFile, resolveConfig } from '../src/config.mjs';
|
|
4
|
+
import { langOption, pickLang, setLang, t } from '../src/i18n.mjs';
|
|
4
5
|
import { notifyOptions } from '../src/notify.mjs';
|
|
6
|
+
import { lineOption } from '../src/line.mjs';
|
|
5
7
|
import { mask, setAmbiguous, stripControl } from '../src/text.mjs';
|
|
6
8
|
|
|
7
9
|
const KNOWN = new Set(['-h', '--help', '-v', '--version', '--once', '--all', '--json', '--doctor', '--bell', '--show-requests', '--print-config', '--no-bell', '--no-all', '--no-show-requests', '--debug', '--no-debug', '--color-blind', '--no-color-blind']);
|
|
8
10
|
const THEMES = ['light', 'dark'];
|
|
9
11
|
const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
|
|
10
12
|
|
|
13
|
+
// 언어는 다른 옵션의 오류 문구보다 먼저 정한다: --lang > AITOP_LANG > 설정 파일 lang > LC_ALL > LC_MESSAGES > LANG.
|
|
14
|
+
// 설정 파일의 문제 문구는 읽을 때 만들어지므로(처음엔 한국어) 언어가 한국어가 아니면 한 번 더 읽는다.
|
|
15
|
+
const langOpt = langOption(process.argv.slice(2));
|
|
16
|
+
const cfgPath = configPath();
|
|
17
|
+
let cfgFile = readConfigFile(cfgPath);
|
|
18
|
+
if (setLang(pickLang({ flag: langOpt.value, file: cfgFile.values.lang })) !== 'ko') cfgFile = readConfigFile(cfgPath);
|
|
19
|
+
if (langOpt.error) {
|
|
20
|
+
process.stderr.write(`aitop: ${t(...langOpt.error)}\n`);
|
|
21
|
+
process.exit(2);
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
// --notify, --no-notify, --on-waiting, --no-on-waiting 은 notifyOptions 한 곳에서 해석한다. 여기서는 명령줄에서 준 값만 본다.
|
|
12
|
-
const cliArgs =
|
|
25
|
+
const cliArgs = langOpt.rest;
|
|
13
26
|
const cli = notifyOptions(cliArgs);
|
|
14
27
|
if (cli.error) {
|
|
15
28
|
process.stderr.write(`aitop: ${cli.error}\n`);
|
|
@@ -21,8 +34,16 @@ if (budget.error) {
|
|
|
21
34
|
process.stderr.write(`aitop: ${budget.error}\n`);
|
|
22
35
|
process.exit(2);
|
|
23
36
|
}
|
|
37
|
+
// --line, --line=tmux, --line-width <N> 은 lineOption 이 꺼낸다.
|
|
38
|
+
const line = lineOption(budget.rest);
|
|
39
|
+
if (line.error) {
|
|
40
|
+
process.stderr.write(`aitop: ${line.error}\n`);
|
|
41
|
+
process.exit(2);
|
|
42
|
+
}
|
|
43
|
+
// 사용자가 준 NO_COLOR. 아래에서 파이프 출력이면 NO_COLOR 를 켜므로 그 전에 읽어 둔다 (tmux 의 #() 는 TTY 가 아니다).
|
|
44
|
+
const userNoColor = Boolean(process.env.NO_COLOR);
|
|
24
45
|
// --theme light, --theme=light 처럼 값을 받는 옵션은 따로 꺼낸다.
|
|
25
|
-
const argv =
|
|
46
|
+
const argv = line.rest;
|
|
26
47
|
let theme = null;
|
|
27
48
|
const rest = [];
|
|
28
49
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -43,7 +64,7 @@ const flag = (name) => {
|
|
|
43
64
|
const notifyFlag = cli.notify ? true : notifyOptions(cliArgs, { notify: true }).notify ? undefined : false;
|
|
44
65
|
// onWaiting 은 --on-waiting 이 뒤에 오면 그 명령, --no-on-waiting 이 뒤에 오면 null(끔), 둘 다 없으면 정하지 않은 것이다.
|
|
45
66
|
const onWaitingFlag = cli.onWaiting ?? (notifyOptions(cliArgs, { onWaiting: 'x' }).onWaiting === null ? null : undefined);
|
|
46
|
-
const config = resolveConfig({ flags: { theme: THEMES.includes(theme) ? theme : undefined, colorBlind: flag('color-blind'), bell: flag('bell'), showRequests: flag('show-requests'), all: flag('all'), debug: flag('debug'), notify: notifyFlag, onWaiting: onWaitingFlag, budgetDay: budget.value } });
|
|
67
|
+
const config = resolveConfig({ flags: { theme: THEMES.includes(theme) ? theme : undefined, colorBlind: flag('color-blind'), bell: flag('bell'), showRequests: flag('show-requests'), all: flag('all'), debug: flag('debug'), notify: notifyFlag, onWaiting: onWaitingFlag, budgetDay: budget.value, lang: langOpt.value }, file: cfgFile });
|
|
47
68
|
const opt = Object.fromEntries(Object.entries(config.values).map(([k, v]) => [k, v.value]));
|
|
48
69
|
// 알림은 설정 파일 값(onWaiting 은 권한 검사를 통과한 것만)을 깔고 명령줄 옵션이 덮는다.
|
|
49
70
|
const fromFile = (k) => (config.values[k].source === 'file' ? config.values[k].value : undefined);
|
|
@@ -66,52 +87,21 @@ process.on('unhandledRejection', (reason) => {
|
|
|
66
87
|
restore();
|
|
67
88
|
} catch {}
|
|
68
89
|
const why = reason instanceof Error ? reason.message : String(reason);
|
|
69
|
-
process.stderr.write(`aitop:
|
|
90
|
+
process.stderr.write(`aitop: ${t('cli.unhandled', { why: stripControl(mask(why)).slice(0, 200) })}\n`);
|
|
70
91
|
process.exit(1);
|
|
71
92
|
});
|
|
72
93
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
aitop 실시간 화면
|
|
76
|
-
aitop --once 현재 상태를 한 번 출력하고 끝낸다
|
|
77
|
-
aitop --all 종료된 세션(24시간 이내)도 함께 본다
|
|
78
|
-
aitop --json 세션 목록과 사용량 합계를 JSON 으로 한 번 출력한다 (--all 과 함께 쓸 수 있다)
|
|
79
|
-
aitop --doctor Claude · Codex · Antigravity · Gemini 기록과 실행 중인 프로세스, 설정 파일을 점검한다 (--json 과 함께 쓸 수 있다)
|
|
80
|
-
aitop --bell 응답 대기 세션이 새로 생기면 터미널 벨을 울린다
|
|
81
|
-
aitop --notify 응답 대기 세션이 새로 생기면 데스크톱 알림을 띄운다 (notify-send · osascript, 없으면 건너뜀)
|
|
82
|
-
aitop --on-waiting <명령> 응답 대기 세션이 새로 생기면 /bin/sh -c 로 명령을 실행한다 (내 권한으로 실행, 10초 제한)
|
|
83
|
-
세션 정보는 환경변수로만: AITOP_TOOL AITOP_PROJECT AITOP_SESSION_ID AITOP_CWD AITOP_WAITING_FOR
|
|
84
|
-
aitop --show-requests 응답 대기 요청 전체를 상세 패널·--json 에 보인다 (AITOP_SHOW_REQUESTS=1). 비밀값 가림은 최선일 뿐이라 명령 속 비밀값이 보일 수 있다
|
|
85
|
-
aitop --budget-day <달러> 하루 예산. 헤더에 오늘 $12.30/$50 처럼 보이고, 오늘 끝 예상 비용(오늘 + 최근 속도 × 자정까지, 늘 API 환산)이
|
|
86
|
-
80% 를 넘으면 '예상 $45', 100% 를 넘으면 '예상 $60!' 로 알린다 (AITOP_BUDGET_DAY, 설정 파일 budgetDay)
|
|
87
|
-
aitop --theme light|dark 밝은 배경 / 어두운 배경 색 (없으면 COLORFGBG 로 고른다)
|
|
88
|
-
aitop --color-blind 적록 색약용 색. 응답 대기·돈·경고·diff 를 노랑·파랑 계열로 가른다 (AITOP_COLOR_BLIND=1, 설정 파일 colorBlind). --theme 과 함께 쓴다
|
|
89
|
-
aitop --no-bell · --no-all · --no-show-requests · --no-notify · --no-on-waiting · --no-budget-day · --no-debug · --no-color-blind 설정 파일에서 켠 값을 이번 실행만 끈다
|
|
90
|
-
aitop --debug 디버그 로그를 남긴다 (AITOP_DEBUG=1, 설정 파일 debug). 기록 형식이 바뀌어 값이 빌 때 원인 확인용
|
|
91
|
-
${logPath()} (1MB 넘으면 .1 로 하나만 남김, 오류 이름·파일 이름만 쓰고 비밀값은 가림)
|
|
92
|
-
aitop --print-config 설정 값마다 값과 출처(flag/env/file/default), 설정 파일 위치를 보인다 (--json 과 함께 쓸 수 있다)
|
|
93
|
-
aitop --version 설치된 버전을 보인다
|
|
94
|
-
|
|
95
|
-
AITOP_ICONS=plain 창 제목의 Nerd Font 아이콘과 WezTerm 탭 값을 끈다 (ascii 면 로고도 ASCII)
|
|
96
|
-
AITOP_AMBIGUOUS=wide ·, →, ─, ● 같은 폭이 모호한 기호를 2칸으로 그리는 터미널(동아시아 폭 설정)용. 표·상자 기호를 1칸 기호로 바꿔 줄이 밀리지 않게 한다 (설정 파일 ambiguous)
|
|
97
|
-
|
|
98
|
-
설정 파일: ${config.path}
|
|
99
|
-
예) { "theme": "light", "icons": "plain", "bell": true, "notify": true, "onWaiting": "say 대기", "budgetDay": 50, "ambiguous": "wide", "hideIdleTools": false }
|
|
100
|
-
hideIdleTools: 실행 중 세션이 없고 7일 동안 쓰지 않은 도구를 헤더 아래 도구 줄에서 숨긴다 (기본 true, false 면 늘 셋 다)
|
|
101
|
-
onWaiting 은 파일 소유자가 나이고 그룹·다른 사용자가 쓸 수 없을 때(chmod 600)만 받는다.
|
|
102
|
-
옵션 > 환경 변수 > 설정 파일 순서로 정한다. 잘못된 값은 무시하고 --doctor 에 알린다.
|
|
103
|
-
|
|
104
|
-
${keysText().replace(/^/gm, ' ')}
|
|
105
|
-
실시간 화면에서 ? 를 누르면 지금 화면의 키부터 보인다`;
|
|
94
|
+
// --help 문구는 i18n.mjs 의 help.usage 표에 있다.
|
|
95
|
+
const HELP = t('help.usage', { logo: BRAND.logo, logPath: logPath(), configPath: config.path, keys: keysText().replace(/^/gm, ' ') });
|
|
106
96
|
|
|
107
97
|
if (theme === '') {
|
|
108
|
-
process.stderr.write(`aitop:
|
|
98
|
+
process.stderr.write(`aitop: ${t('cli.themeMissing')}\n`);
|
|
109
99
|
process.exit(2);
|
|
110
100
|
}
|
|
111
101
|
const unknown = [...args].filter((a) => !KNOWN.has(a));
|
|
112
102
|
if (theme != null && !THEMES.includes(theme)) unknown.push(`--theme ${theme}`);
|
|
113
103
|
if (unknown.length) {
|
|
114
|
-
process.stderr.write(`aitop:
|
|
104
|
+
process.stderr.write(`aitop: ${t('cli.unknown', { opts: unknown.join(' ') })}\n\n${HELP}\n`);
|
|
115
105
|
process.exit(2);
|
|
116
106
|
}
|
|
117
107
|
if (args.has('-h') || args.has('--help')) {
|
|
@@ -129,7 +119,25 @@ if (args.has('--print-config')) {
|
|
|
129
119
|
|
|
130
120
|
// 디버그 로그는 켰을 때만 파일을 만든다. --help·--version·--print-config 처럼 바로 끝나는 경우에는 만들지 않는다.
|
|
131
121
|
const log = initLog({ enabled: opt.debug, version: VERSION });
|
|
132
|
-
if (opt.debug && !log.on) process.stderr.write(`aitop:
|
|
122
|
+
if (opt.debug && !log.on) process.stderr.write(`aitop: ${t('cli.logOff', { path: log.path })}\n`);
|
|
123
|
+
|
|
124
|
+
// --line: 세션 화면·프로세스 목록 없이 장부 캐시만 읽어 한 줄을 내고 끝낸다. 실패해도 tmux 에 오류를 남기지 않게 0 으로 끝낸다.
|
|
125
|
+
if (line.mode) {
|
|
126
|
+
const { collectLine, formatLine, PENDING } = await import('../src/line.mjs');
|
|
127
|
+
const { flushCache } = await import('../src/cache.mjs');
|
|
128
|
+
let text = PENDING;
|
|
129
|
+
try {
|
|
130
|
+
// AITOP_LINE_MS: 시간 상한(ms). 테스트에서 캐시 없는 첫 실행을 흉내 낼 때 쓴다.
|
|
131
|
+
const capMs = Number(process.env.AITOP_LINE_MS) > 0 ? Number(process.env.AITOP_LINE_MS) : undefined;
|
|
132
|
+
const v = await collectLine({ capMs });
|
|
133
|
+
if (v) text = formatLine({ ...v, budgetDay: opt.budgetDay }, { mode: line.mode, noColor: userNoColor, width: line.width, colorBlind: opt.colorBlind });
|
|
134
|
+
flushCache();
|
|
135
|
+
} catch (e) {
|
|
136
|
+
debug('aitop', 'line failed', e);
|
|
137
|
+
}
|
|
138
|
+
await new Promise((resolve) => process.stdout.write(text + '\n', resolve));
|
|
139
|
+
process.exit(0);
|
|
140
|
+
}
|
|
133
141
|
|
|
134
142
|
// 파이프나 파일로 받을 때는 색 코드를 넣지 않는다. 화면 모듈이 불러올 때 NO_COLOR 를 읽으므로 그 전에 정한다.
|
|
135
143
|
const forced = process.env.FORCE_COLOR != null && !['', '0', 'false'].includes(process.env.FORCE_COLOR);
|
|
@@ -145,7 +153,7 @@ const printAndExit = async (text) => {
|
|
|
145
153
|
|
|
146
154
|
// 알림은 실시간 화면에서만 동작한다.
|
|
147
155
|
if ((cli.notify || cli.onWaiting) && (args.has('--once') || args.has('--json') || args.has('--doctor') || !process.stdout.isTTY)) {
|
|
148
|
-
process.stderr.write(
|
|
156
|
+
process.stderr.write(`aitop: ${t('cli.notifyLiveOnly')}\n`);
|
|
149
157
|
}
|
|
150
158
|
|
|
151
159
|
const { checkTools, doctorText, toolsJson } = await import('../src/doctor.mjs');
|
|
@@ -193,7 +201,7 @@ function refresh() {
|
|
|
193
201
|
view.tab = 'now';
|
|
194
202
|
}
|
|
195
203
|
updateAttention(attention, data.sessions, view.selectedId);
|
|
196
|
-
data.sessions = data.sessions.map((s) => (attention.unseen.has(s.id) ? { ...s, unseen: true, phase: { kind: 'unseen'
|
|
204
|
+
data.sessions = data.sessions.map((s) => (attention.unseen.has(s.id) ? { ...s, unseen: true, phase: { kind: 'unseen' }, plain: s } : s));
|
|
197
205
|
// 도구별 점검은 기록 폴더를 훑으므로 30초에 한 번만 한다.
|
|
198
206
|
if (!tools || Date.now() - tools.at > 30_000) tools = { at: Date.now(), result: checkTools() };
|
|
199
207
|
data.tools = tools.result;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sejuneoh/aitop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "터미널에서 Claude Code · Codex · Antigravity · Gemini 세션과 토큰을 실시간으로 보는 읽기 전용 모니터",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"scripts": {
|
|
34
34
|
"start": "node bin/aitop.mjs",
|
|
35
|
-
"test": "node --test test/*.test.mjs",
|
|
36
|
-
"test:e2e": "node --test test/e2e/*.e2e.mjs"
|
|
35
|
+
"test": "AITOP_LANG=ko node --test test/*.test.mjs",
|
|
36
|
+
"test:e2e": "AITOP_LANG=ko node --test test/e2e/*.e2e.mjs"
|
|
37
37
|
}
|
|
38
38
|
}
|
package/src/config.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { closeSync, constants, fstatSync, openSync, readSync, statSync } from 'n
|
|
|
6
6
|
import { homedir } from 'node:os';
|
|
7
7
|
import { isAbsolute, join } from 'node:path';
|
|
8
8
|
import { stripControl } from './text.mjs';
|
|
9
|
+
import { langValue, localeLang, t } from './i18n.mjs';
|
|
9
10
|
|
|
10
11
|
const bool = (v) => typeof v === 'boolean';
|
|
11
12
|
const oneOf = (...xs) => (v) => xs.includes(v);
|
|
@@ -37,31 +38,37 @@ export function budgetDayOption(argv) {
|
|
|
37
38
|
const next = argv[i + 1];
|
|
38
39
|
const raw = m[1] ?? (next == null || (next.startsWith('-') && !/^-[\d.]/.test(next)) ? '' : argv[++i]);
|
|
39
40
|
const n = usd(raw);
|
|
40
|
-
if (n == null) error ??= raw === '' ? '
|
|
41
|
+
if (n == null) error ??= raw === '' ? t('opt.budgetMissing') : t('opt.budgetBad', { value: JSON.stringify(raw) });
|
|
41
42
|
else value = n;
|
|
42
43
|
}
|
|
43
44
|
return { value, rest, error };
|
|
44
45
|
}
|
|
45
46
|
|
|
47
|
+
const BOOL = ['true', 'false'];
|
|
48
|
+
// expect, envExpect: 둘 중 하나면 [a, b], 아니면 i18n 키. 문구는 쓸 때 지금 언어로 만든다.
|
|
49
|
+
const expectText = (x) => (Array.isArray(x) ? t('cfg.either', { a: x[0], b: x[1] }) : t(x));
|
|
50
|
+
|
|
46
51
|
// env: 환경 변수 이름과 그 값을 옵션 값으로 바꾸는 함수 (undefined 면 설정하지 않은 것으로 본다).
|
|
47
52
|
// envProblem: 환경 변수 값이 잘못되면 무시하고 problems 에 남긴다 (--doctor, --print-config 가 보인다).
|
|
48
53
|
// notify, onWaiting 은 응답 대기 알림(notify.mjs)이 쓴다. debug 는 디버그 로그(log.mjs)를 켠다. budgetDay 는 하루 예산(달러)으로, 헤더와 --json 의 예상 비용 경고(budget.mjs)가 쓴다.
|
|
49
54
|
export const KEYS = {
|
|
50
|
-
theme: { ok: oneOf('light', 'dark'), expect: 'light
|
|
51
|
-
icons: { ok: oneOf('plain', 'ascii'), expect: 'plain
|
|
52
|
-
bell: { ok: bool, expect:
|
|
53
|
-
showRequests: { ok: bool, expect:
|
|
54
|
-
all: { ok: bool, expect:
|
|
55
|
-
notify: { ok: bool, expect:
|
|
56
|
-
onWaiting: { ok: (v) => typeof v === 'string' && v.trim() !== '', expect: '
|
|
57
|
-
debug: { ok: bool, expect:
|
|
58
|
-
budgetDay: { ok: (v) => typeof v === 'number' && Number.isFinite(v) && v > 0, expect: '
|
|
55
|
+
theme: { ok: oneOf('light', 'dark'), expect: ['light', 'dark'], def: null, env: ['AITOP_THEME', (v) => (v === 'light' || v === 'dark' ? v : undefined)] },
|
|
56
|
+
icons: { ok: oneOf('plain', 'ascii'), expect: ['plain', 'ascii'], def: 'full', env: ['AITOP_ICONS', (v) => (v === 'plain' || v === 'ascii' ? v : undefined)] },
|
|
57
|
+
bell: { ok: bool, expect: BOOL, def: false },
|
|
58
|
+
showRequests: { ok: bool, expect: BOOL, def: false, env: ['AITOP_SHOW_REQUESTS', (v) => (v === '1' ? true : v === '0' ? false : undefined)] },
|
|
59
|
+
all: { ok: bool, expect: BOOL, def: false },
|
|
60
|
+
notify: { ok: bool, expect: BOOL, def: false },
|
|
61
|
+
onWaiting: { ok: (v) => typeof v === 'string' && v.trim() !== '', expect: 'cfg.command', def: null },
|
|
62
|
+
debug: { ok: bool, expect: BOOL, def: false, env: ['AITOP_DEBUG', (v) => (v === '1' ? true : v === '0' ? false : undefined)], envProblem: true, envExpect: ['1', '0'] },
|
|
63
|
+
budgetDay: { ok: (v) => typeof v === 'number' && Number.isFinite(v) && v > 0, expect: 'cfg.positive', def: null, env: ['AITOP_BUDGET_DAY', (v) => usd(v) ?? undefined], envProblem: true },
|
|
59
64
|
// colorBlind 는 적록 색약 팔레트(ui/theme.mjs)를 고른다. theme(밝기)과 따로 정한다.
|
|
60
|
-
colorBlind: { ok: bool, expect:
|
|
65
|
+
colorBlind: { ok: bool, expect: BOOL, def: false, env: ['AITOP_COLOR_BLIND', (v) => (v === '1' ? true : v === '0' ? false : undefined)], envProblem: true, envExpect: ['1', '0'] },
|
|
61
66
|
// 실행 중 세션이 없고 7일 동안 쓰지 않은 도구를 도구 줄에서 숨긴다. false 면 늘 셋 다 보인다.
|
|
62
|
-
hideIdleTools: { ok: bool, expect:
|
|
67
|
+
hideIdleTools: { ok: bool, expect: BOOL, def: true },
|
|
63
68
|
// 폭이 모호한 기호(·, →, ─, ● 등)를 2칸으로 그리는 터미널이면 wide. 표 칸이 밀리지 않게 1칸 기호로 바꾸고 폭을 2칸으로 센다.
|
|
64
|
-
ambiguous: { ok: oneOf('narrow', 'wide'), expect: 'narrow
|
|
69
|
+
ambiguous: { ok: oneOf('narrow', 'wide'), expect: ['narrow', 'wide'], def: 'narrow', env: ['AITOP_AMBIGUOUS', (v) => (v === 'narrow' || v === 'wide' ? v : undefined)], envProblem: true },
|
|
70
|
+
// --help·--doctor·오류 문구의 언어(i18n.mjs). 기본값은 로캘(LC_ALL > LC_MESSAGES > LANG)이 ko 로 시작하면 ko, 아니면 en.
|
|
71
|
+
lang: { ok: oneOf('ko', 'en'), expect: ['ko', 'en'], def: localeLang, env: ['AITOP_LANG', langValue], envProblem: true },
|
|
65
72
|
};
|
|
66
73
|
|
|
67
74
|
export function configPath(env = process.env, home = homedir()) {
|
|
@@ -80,8 +87,8 @@ export function readConfigFile(path, { uid = process.getuid?.() } = {}) {
|
|
|
80
87
|
let fd;
|
|
81
88
|
let text;
|
|
82
89
|
let st;
|
|
83
|
-
const notFile = () => res.problems.push('
|
|
84
|
-
const tooBig = () => res.problems.push(
|
|
90
|
+
const notFile = () => res.problems.push(t('cfg.notFile'));
|
|
91
|
+
const tooBig = () => res.problems.push(t('cfg.tooBig', { kb: MAX_BYTES / 1024 }));
|
|
85
92
|
try {
|
|
86
93
|
// FIFO 나 장치 파일을 열면 멈출 수 있으므로 열기 전에 확인하고, 열 때도 기다리지 않게 연다.
|
|
87
94
|
st = statSync(path);
|
|
@@ -101,7 +108,7 @@ export function readConfigFile(path, { uid = process.getuid?.() } = {}) {
|
|
|
101
108
|
} catch (err) {
|
|
102
109
|
if (err.code !== 'ENOENT') {
|
|
103
110
|
res.exists = err.code !== 'ENOTDIR';
|
|
104
|
-
res.problems.push(
|
|
111
|
+
res.problems.push(t('cfg.unreadable', { code: err.code ?? err.message }));
|
|
105
112
|
}
|
|
106
113
|
return res;
|
|
107
114
|
} finally {
|
|
@@ -112,17 +119,17 @@ export function readConfigFile(path, { uid = process.getuid?.() } = {}) {
|
|
|
112
119
|
obj = JSON.parse(text);
|
|
113
120
|
} catch (err) {
|
|
114
121
|
// 오류 문구에 파일 내용 일부가 들어가므로 제어문자를 지우고 줄인다.
|
|
115
|
-
res.problems.push(
|
|
122
|
+
res.problems.push(t('cfg.badJson', { why: stripControl(err.message).slice(0, 120) }));
|
|
116
123
|
return res;
|
|
117
124
|
}
|
|
118
125
|
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
119
|
-
res.problems.push(
|
|
126
|
+
res.problems.push(t('cfg.notObject'));
|
|
120
127
|
return res;
|
|
121
128
|
}
|
|
122
129
|
for (const [key, value] of Object.entries(obj)) {
|
|
123
130
|
const spec = Object.hasOwn(KEYS, key) ? KEYS[key] : null;
|
|
124
|
-
if (!spec) res.problems.push(
|
|
125
|
-
else if (!spec.ok(value)) res.problems.push(
|
|
131
|
+
if (!spec) res.problems.push(t('cfg.unknownKey', { key: show(key) }));
|
|
132
|
+
else if (!spec.ok(value)) res.problems.push(t('cfg.badValue', { key, value: show(value), expect: expectText(spec.expect) }));
|
|
126
133
|
else res.values[key] = value;
|
|
127
134
|
}
|
|
128
135
|
// 응답 대기 때 실행할 명령은 다른 사용자가 바꿀 수 없는 파일에서만 받는다.
|
|
@@ -131,8 +138,8 @@ export function readConfigFile(path, { uid = process.getuid?.() } = {}) {
|
|
|
131
138
|
const shared = (st.mode & 0o022) !== 0;
|
|
132
139
|
if (!mine || shared) {
|
|
133
140
|
delete res.values.onWaiting;
|
|
134
|
-
const why = [!mine && '
|
|
135
|
-
res.problems.push(
|
|
141
|
+
const why = [!mine && t('cfg.notMine'), shared && t('cfg.shared', { mode: (st.mode & 0o777).toString(8).padStart(3, '0') })].filter(Boolean).join(', ');
|
|
142
|
+
res.problems.push(t('cfg.onWaitingIgnored', { why }));
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
return res;
|
|
@@ -145,18 +152,19 @@ export function resolveConfig({ flags = {}, env = process.env, file } = {}) {
|
|
|
145
152
|
const problems = [...file.problems];
|
|
146
153
|
for (const [key, spec] of Object.entries(KEYS)) {
|
|
147
154
|
const fromEnv = spec.env && env[spec.env[0]] != null ? spec.env[1](env[spec.env[0]]) : undefined;
|
|
148
|
-
if (spec.envProblem && env[spec.env[0]] != null && fromEnv === undefined) problems.push(
|
|
155
|
+
if (spec.envProblem && env[spec.env[0]] != null && fromEnv === undefined) problems.push(t('cfg.badEnv', { name: spec.env[0], value: show(env[spec.env[0]]), expect: expectText(spec.envExpect ?? spec.expect) }));
|
|
149
156
|
if (flags[key] !== undefined) values[key] = { value: flags[key], source: 'flag' };
|
|
150
157
|
else if (fromEnv !== undefined) values[key] = { value: fromEnv, source: 'env' };
|
|
151
158
|
else if (key in file.values) values[key] = { value: file.values[key], source: 'file' };
|
|
152
|
-
|
|
159
|
+
// 기본값이 함수면 환경에서 고른다 (lang 은 로캘).
|
|
160
|
+
else values[key] = { value: typeof spec.def === 'function' ? spec.def(env) : spec.def, source: 'default' };
|
|
153
161
|
}
|
|
154
162
|
return { path: file.path, exists: file.exists, values, problems };
|
|
155
163
|
}
|
|
156
164
|
|
|
157
165
|
// --print-config 의 사람용 출력.
|
|
158
166
|
export function configText(cfg) {
|
|
159
|
-
const out = [
|
|
167
|
+
const out = [t('cfg.file', { path: stripControl(cfg.path), state: t(cfg.exists ? 'cfg.exists' : 'cfg.missing') }), ''];
|
|
160
168
|
for (const [key, { value, source }] of Object.entries(cfg.values)) {
|
|
161
169
|
const v = value == null ? (key === 'theme' ? 'auto' : '-') : typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
162
170
|
out.push(`${key.padEnd(14)}${v.padEnd(12)} ${source}`);
|
package/src/doctor.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { loadSqlite, openReadOnly } from './sqlite.mjs';
|
|
|
10
10
|
import { fmtAgo, pad, stripControl } from './text.mjs';
|
|
11
11
|
import { BRAND } from './brand.mjs';
|
|
12
12
|
import { findNotifier, isWsl } from './notify.mjs';
|
|
13
|
+
import { getLang, t as tr } from './i18n.mjs';
|
|
13
14
|
|
|
14
15
|
const UNIT = { s: '초', m: '분', h: '시간', d: '일' };
|
|
15
16
|
const ago = (ms) => fmtAgo(ms).replace(/[smhd]$/, (u) => UNIT[u]);
|
|
@@ -106,7 +107,7 @@ function claude() {
|
|
|
106
107
|
const running = canListProcesses()
|
|
107
108
|
? ls(join(CLAUDE, 'sessions')).filter((e) => /^\d+\.json$/.test(e.name) && isAlive(Number(e.name.split('.')[0]))).length
|
|
108
109
|
: null;
|
|
109
|
-
if (!files) return { tool: 'claude', state: 'missing', path: tilde(dir), records: 0, lastAt: null, running, readable: null, hint:
|
|
110
|
+
if (!files) return { tool: 'claude', state: 'missing', path: tilde(dir), records: 0, lastAt: null, running, readable: null, hint: null };
|
|
110
111
|
return { tool: 'claude', state: 'ok', path: tilde(dir), records: files.length, lastAt: last?.mtime ?? null, running, readable: last ? firstLineIsJson(last.path) : null, hint: null };
|
|
111
112
|
}
|
|
112
113
|
|
|
@@ -114,7 +115,7 @@ function codex() {
|
|
|
114
115
|
const files = existsSync(CODEX) ? walk(CODEX, 3, (n) => n.startsWith('rollout-') && n.endsWith('.jsonl')) : null;
|
|
115
116
|
const last = files && newest(files);
|
|
116
117
|
const running = canListProcesses() ? findProcesses(isCodex).length : null;
|
|
117
|
-
if (!files) return { tool: 'codex', state: 'missing', path: tilde(CODEX), records: 0, lastAt: null, running, readable: null, hint:
|
|
118
|
+
if (!files) return { tool: 'codex', state: 'missing', path: tilde(CODEX), records: 0, lastAt: null, running, readable: null, hint: null };
|
|
118
119
|
return { tool: 'codex', state: 'ok', path: tilde(CODEX), records: files.length, lastAt: last?.mtime ?? null, running, readable: last ? firstLineIsJson(last.path) : null, hint: null };
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -132,7 +133,7 @@ function gemini() {
|
|
|
132
133
|
running: canListProcesses() ? findProcesses(isGemini).length : null,
|
|
133
134
|
readable: null,
|
|
134
135
|
keys: last ? topKeys(last.path) : [],
|
|
135
|
-
hint:
|
|
136
|
+
hint: null,
|
|
136
137
|
};
|
|
137
138
|
}
|
|
138
139
|
|
|
@@ -141,9 +142,9 @@ function agy() {
|
|
|
141
142
|
const dir = join(AGY_ROOT, 'conversations');
|
|
142
143
|
const running = canListProcesses() ? findProcesses(isAgy).length : null;
|
|
143
144
|
const files = existsSync(dir) ? walk(dir, 0, (n) => n.endsWith('.db')) : null;
|
|
144
|
-
if (!files) return { tool: 'agy', state: 'missing', path: tilde(AGY_ROOT), records: 0, lastAt: null, running, readable: null, hint:
|
|
145
|
+
if (!files) return { tool: 'agy', state: 'missing', path: tilde(AGY_ROOT), records: 0, lastAt: null, running, readable: null, hint: null };
|
|
145
146
|
const last = newest(files.flatMap((f) => [f, `${f}-wal`]).filter((f) => existsSync(f)));
|
|
146
|
-
if (!loadSqlite()) return { tool: 'agy', state: 'limited', path: tilde(AGY_ROOT), records: files.length, lastAt: last?.mtime ?? null, running, readable: null, hint:
|
|
147
|
+
if (!loadSqlite()) return { tool: 'agy', state: 'limited', path: tilde(AGY_ROOT), records: files.length, lastAt: last?.mtime ?? null, running, readable: null, hint: null };
|
|
147
148
|
let readable = false;
|
|
148
149
|
let db;
|
|
149
150
|
try {
|
|
@@ -157,10 +158,20 @@ function agy() {
|
|
|
157
158
|
return { tool: 'agy', state: 'ok', path: tilde(AGY_ROOT), records: files.length, lastAt: last?.mtime ?? null, running, readable, hint: null };
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
// 도구별 안내 한 줄. 없으면 null. 점검 결과(--json 의 tools.*.hint)에는 예전처럼 한국어로 넣고, --doctor 글은 지금 언어로 다시 만든다.
|
|
162
|
+
export function hintOf(r, lang = 'ko') {
|
|
163
|
+
const o = { lang };
|
|
164
|
+
if (r.tool === 'gemini') return tr('doctor.hint.gemini', null, o);
|
|
165
|
+
if (r.state === 'missing') return r.tool === 'agy' ? tr('doctor.hint.agyMissing', null, o) : tr('doctor.hint.missing', { tool: r.tool }, o);
|
|
166
|
+
if (r.tool === 'agy' && r.state === 'limited') return tr('doctor.hint.agyNode', { node: process.versions.node }, o);
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
|
|
160
170
|
export function checkTools() {
|
|
161
171
|
const tools = {};
|
|
162
172
|
for (const fn of [claude, codex, gemini, agy]) {
|
|
163
173
|
const r = fn();
|
|
174
|
+
r.hint = hintOf(r, 'ko');
|
|
164
175
|
tools[r.tool] = r;
|
|
165
176
|
}
|
|
166
177
|
const n = findNotifier();
|
|
@@ -168,11 +179,12 @@ export function checkTools() {
|
|
|
168
179
|
}
|
|
169
180
|
|
|
170
181
|
// --notify 에 쓸 데스크톱 알림 도구.
|
|
171
|
-
export function notifierText(n, plat = platform()) {
|
|
172
|
-
|
|
182
|
+
export function notifierText(n, plat = platform(), lang = getLang()) {
|
|
183
|
+
const o = { lang };
|
|
184
|
+
if (n) return tr('doctor.notifier', { kind: n.kind, path: n.path }, o);
|
|
173
185
|
const want = plat === 'darwin' ? 'osascript' : 'notify-send';
|
|
174
|
-
const wsl = plat === 'linux' && isWsl() ? '
|
|
175
|
-
return
|
|
186
|
+
const wsl = plat === 'linux' && isWsl() ? tr('doctor.wsl', null, o) : '';
|
|
187
|
+
return tr('doctor.noNotifier', { want, wsl }, o);
|
|
176
188
|
}
|
|
177
189
|
|
|
178
190
|
// JSON 용: 시각은 ISO 문자열로.
|
|
@@ -185,34 +197,43 @@ export function toolsJson(tools) {
|
|
|
185
197
|
export const MARK = { ok: '✓', missing: '✗', limited: '○' };
|
|
186
198
|
export const STATE_TEXT = { ok: '찾음', missing: '없음', limited: '일부 지원' };
|
|
187
199
|
|
|
188
|
-
|
|
200
|
+
// lang: 빈 화면(세션 없을 때의 점검 줄)과 --doctor 모두 지금 언어가 기본이다.
|
|
201
|
+
export function describe(t, now = Date.now(), lang = getLang()) {
|
|
202
|
+
const o = { lang };
|
|
189
203
|
const parts = [];
|
|
190
|
-
if (t.found === false && t.state === 'limited') parts.push('
|
|
191
|
-
else if (t.state !== 'missing') parts.push(
|
|
192
|
-
if (t.lastAt) parts.push(
|
|
193
|
-
parts.push(t.running == null ? '
|
|
194
|
-
if (t.readable === false) parts.push('
|
|
195
|
-
if (t.keys?.length) parts.push(
|
|
196
|
-
|
|
204
|
+
if (t.found === false && t.state === 'limited') parts.push(tr('doctor.noFolder', null, o));
|
|
205
|
+
else if (t.state !== 'missing') parts.push(tr('doctor.records', { n: t.records.toLocaleString('en-US') }, o));
|
|
206
|
+
if (t.lastAt) parts.push(tr('doctor.last', { ago: lang === 'ko' ? ago(now - t.lastAt) : fmtAgo(now - t.lastAt) }, o));
|
|
207
|
+
parts.push(t.running == null ? tr('doctor.runningUnknown', null, o) : tr('doctor.running', { n: t.running }, o));
|
|
208
|
+
if (t.readable === false) parts.push(tr('doctor.unreadable', null, o));
|
|
209
|
+
if (t.keys?.length) parts.push(tr('doctor.keys', { keys: t.keys.join(', ') }, o));
|
|
210
|
+
// 한국어 안내는 점검 결과에 든 그대로, 다른 언어는 같은 조건으로 다시 만든다.
|
|
211
|
+
const hint = lang === 'ko' || !t.hint ? t.hint : (hintOf(t, lang) ?? t.hint);
|
|
212
|
+
return { mark: MARK[t.state], state: lang === 'ko' ? STATE_TEXT[t.state] : tr(`doctor.state.${t.state}`, null, { lang, short: true }), path: t.path, detail: parts.join(' · '), hint };
|
|
197
213
|
}
|
|
198
214
|
|
|
199
215
|
// aitop --doctor 의 사람용 출력.
|
|
200
|
-
export function doctorText(result, version, now = Date.now()) {
|
|
201
|
-
const
|
|
202
|
-
const
|
|
216
|
+
export function doctorText(result, version, now = Date.now(), lang = getLang()) {
|
|
217
|
+
const o = { lang };
|
|
218
|
+
const os = tr('doctor.os', { platform: result.platform, state: tr(result.processes ? 'doctor.procsOk' : 'doctor.procsNo', null, o) }, o);
|
|
219
|
+
const out = [tr('doctor.title', { logo: BRAND.logo, version, os }, o), ''];
|
|
203
220
|
for (const t of Object.values(result.tools)) {
|
|
204
|
-
const d = describe(t, now);
|
|
221
|
+
const d = describe(t, now, lang);
|
|
205
222
|
out.push(`${d.mark} ${pad(t.tool, 7)}${pad(d.state, 10)}${d.path}`);
|
|
206
223
|
out.push(` ${d.detail}`);
|
|
207
224
|
if (d.hint) out.push(` → ${d.hint}`);
|
|
208
225
|
}
|
|
209
|
-
if ('notifier' in result) out.push('', notifierText(result.notifier, result.platform));
|
|
226
|
+
if ('notifier' in result) out.push('', notifierText(result.notifier, result.platform, lang));
|
|
210
227
|
// 설정 파일: 무시한 키와 값, 받지 않은 onWaiting 을 알린다.
|
|
211
228
|
const cfg = result.config;
|
|
212
229
|
if (cfg) {
|
|
213
|
-
|
|
230
|
+
const state = pad(tr(cfg.exists ? 'doctor.configExists' : 'doctor.configMissing', null, o), 10);
|
|
231
|
+
out.push('', tr('doctor.config', { mark: cfg.problems.length ? '!' : '✓', state, path: tilde(cfg.path) }, o));
|
|
214
232
|
for (const p of cfg.problems) out.push(` ! ${p}`);
|
|
215
233
|
}
|
|
216
|
-
if (result.log)
|
|
234
|
+
if (result.log) {
|
|
235
|
+
const on = result.log.on;
|
|
236
|
+
out.push('', tr('doctor.debug', { mark: on ? '✓' : '○', state: pad(tr(on ? 'doctor.debugOn' : 'doctor.debugOff', null, o), 10), path: tilde(result.log.path), tail: on ? '' : tr('doctor.debugTail', null, o) }, o));
|
|
237
|
+
}
|
|
217
238
|
return stripControl(out.join('\n'));
|
|
218
239
|
}
|