agent-run-inspector 0.0.0-stage → 0.8.2
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/LICENSE +21 -0
- package/README.ko.md +158 -0
- package/README.md +157 -2
- package/THIRD_PARTY_NOTICES.md +49 -0
- package/bin/cli.js +245 -0
- package/brand-map.json +51 -0
- package/package.json +44 -4
- package/prices.json +405 -0
- package/src/adapters/claude-code/agents.js +272 -0
- package/src/adapters/claude-code/index.js +246 -0
- package/src/adapters/claude-code/llm.js +160 -0
- package/src/adapters/claude-code/tools.js +116 -0
- package/src/adapters/codex/agents.js +91 -0
- package/src/adapters/codex/index.js +217 -0
- package/src/adapters/codex/llm.js +91 -0
- package/src/adapters/codex/tools.js +132 -0
- package/src/app.js +59 -0
- package/src/config.js +43 -0
- package/src/cost.js +104 -0
- package/src/dock.js +62 -0
- package/src/files.js +143 -0
- package/src/groups.js +53 -0
- package/src/index/index.js +73 -0
- package/src/index/scan.js +339 -0
- package/src/index/summary.js +265 -0
- package/src/live/sse.js +202 -0
- package/src/live/tail.js +98 -0
- package/src/live/watch.js +216 -0
- package/src/macos/AppIcon.icns +0 -0
- package/src/macos/app.js +324 -0
- package/src/model/detail.js +142 -0
- package/src/model/provider.js +30 -0
- package/src/model/redact.js +94 -0
- package/src/model/roles.js +23 -0
- package/src/model/tool-brand.js +52 -0
- package/src/model/tool-category.js +28 -0
- package/src/model/totals.js +87 -0
- package/src/model/types.js +72 -0
- package/src/open.js +74 -0
- package/src/roots.js +47 -0
- package/src/server/api-detail.js +40 -0
- package/src/server/api.js +125 -0
- package/src/server/auth.js +46 -0
- package/src/server/http.js +86 -0
- package/src/server/static.js +68 -0
- package/src/service.js +178 -0
- package/src/strings.js +76 -0
- package/src/update-check.js +44 -0
- package/web/agent-panel.js +125 -0
- package/web/api.js +116 -0
- package/web/app.css +453 -0
- package/web/app.js +302 -0
- package/web/call-detail.js +181 -0
- package/web/card.js +286 -0
- package/web/format.js +34 -0
- package/web/graph-layout.js +343 -0
- package/web/graph.js +295 -0
- package/web/groups.js +171 -0
- package/web/icon-192.png +0 -0
- package/web/icon-32.png +0 -0
- package/web/icon-512.png +0 -0
- package/web/icons.js +30 -0
- package/web/index.html +28 -0
- package/web/list-resize.js +43 -0
- package/web/live-follow.js +32 -0
- package/web/manifest.webmanifest +15 -0
- package/web/mini.js +167 -0
- package/web/run-header.js +230 -0
- package/web/session-list.js +378 -0
- package/web/state.js +26 -0
- package/web/strings.js +190 -0
- package/web/timeline-group.js +44 -0
- package/web/timeline-scale.js +146 -0
- package/web/timeline.js +499 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tae-Hoon Yong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.ko.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
[English](README.md) | 한국어
|
|
2
|
+
|
|
3
|
+
# agent-run-inspector
|
|
4
|
+
|
|
5
|
+
[](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](package.json)
|
|
8
|
+
|
|
9
|
+
Claude Code 와 Codex CLI 의 에이전트 실행을 로컬 브라우저에서 실시간으로 보는 읽기 전용 도구입니다. 누가 누구를 불렀는지, 호출마다 비용이 얼마인지, 어디서 실패했는지 한눈에 봅니다.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Get started
|
|
14
|
+
|
|
15
|
+
Claude Code 와 Codex CLI 가 이미 디스크에 남기는 실행 기록을 읽습니다. 에이전트 쪽에는 아무것도 설치하지 않습니다(훅·프록시 없음). Node 22 이상이 필요합니다(`node -v` 로 확인). Mac 에 없으면 `brew install node`([Homebrew](https://brew.sh))나 [nodejs.org](https://nodejs.org) 설치 파일로 설치하세요. `npm i -g` 가 `EACCES` 로 실패하면 nodejs.org 설치 파일로 깐 Node 라서 그렇습니다: `sudo` 대신 Homebrew 의 Node 나 [nvm](https://github.com/nvm-sh/nvm) 을 쓰세요.
|
|
16
|
+
|
|
17
|
+
### Mac: 앱으로 쓰기
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm i -g agent-run-inspector
|
|
21
|
+
ari service install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
이게 전부입니다. **Agent Run Inspector** 가 자체 창으로 열리고 Dock 에 남으며, Mac 을 켜면 함께 시작되므로 다시 터미널을 열 필요가 없습니다. 메뉴 막대에 진행 중인 run 수도 보여 줍니다. 자세한 내용은 [The Mac app](#the-mac-app) 을 보세요.
|
|
25
|
+
|
|
26
|
+
### 어디서나: 한 번 써 보기
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npx agent-run-inspector
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
브라우저에서 열리고, Ctrl+C 를 누를 때까지 실행됩니다.
|
|
33
|
+
|
|
34
|
+
## What you see
|
|
35
|
+
|
|
36
|
+
- **세션 목록**: 실행 중인 세션이 위, 최근 세션이 아래에 나옵니다(최근 목록은 눌러서 접기). 도구(Claude Code, Codex CLI)·기간(기본 Today)으로 거르거나 제목·프로젝트로 찾습니다. **그룹**: "+ New group" 으로 만들고 세션을 끌어다 놓거나 세션을 우클릭해 넣습니다. 그룹을 고르면 그 그룹의 세션만 보입니다. 그룹은 `~/.config/agent-run-inspector/groups.json` 에 저장됩니다. 에이전트 팀의 팀원(teammate)은 따로 나오지 않고, 자신을 띄운 실행 안에 묶여 보입니다.
|
|
37
|
+
- **그래프**: orchestrator 부터 에이전트마다 카드 하나. 카드에는 최근 호출, 상태, 비용, 시간, 호출 수가 보입니다. 카드를 누르면 그 에이전트만의 합계가 나오고, "Hide finished agents" 로 아직 일하는 에이전트만 남길 수 있습니다.
|
|
38
|
+
- **타임라인**: 모든 에이전트와 호출을 한 시간 축에 놓고 턴·컨텍스트 압축 시점도 표시합니다. 호출을 열면 자세한 내용이 보입니다.
|
|
39
|
+
- **합계**: 실행 전체나 고른 에이전트의 시간, 비용, 토큰, 모델 호출, 도구 호출, 오류.
|
|
40
|
+
- **실시간**: 기록에 새 줄이 생기면 새로 고침 없이 1초 안팎에 화면에 반영됩니다.
|
|
41
|
+
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
| 옵션 | 하는 일 |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `--port <n>` | 들을 포트 (기본: 비어 있는 포트 자동) |
|
|
47
|
+
| `--open[=<where>]` | 주소 열기: `auto`(기본; Orca 안이면 Orca 탭, 아니면 기본 브라우저), `orca`, `browser`, `none` |
|
|
48
|
+
| `--no-open` | 주소만 출력 (`--open=none` 과 같음) |
|
|
49
|
+
| `--root <dir>` | Claude Code projects 폴더 추가 (반복 가능) |
|
|
50
|
+
| `--codex-root <dir>` | Codex sessions 폴더 추가 (반복 가능) |
|
|
51
|
+
| `--source <name>` | `claude`, `codex`, `all` (기본: `all`) |
|
|
52
|
+
| `--since <age>` | 이 기간보다 새 실행만, 예: `24h`, `7d`, `30d` |
|
|
53
|
+
| `--redact[=strict]` | 메시지 본문 숨김 (`strict`: 더 많이 숨김) |
|
|
54
|
+
| `--prices <file>` | 내장 단가표를 덮어쓰는 단가표 |
|
|
55
|
+
| `--session <id>` | 이 세션을 바로 열기 |
|
|
56
|
+
| `--no-update-check` | npm 새 버전 확인 안 함 |
|
|
57
|
+
| `-v, --version` | 버전 출력 |
|
|
58
|
+
| `-h, --help` | 도움말 출력 |
|
|
59
|
+
| `ari roots list` | 쓰고 있는 기록 폴더 보기 |
|
|
60
|
+
| `ari roots add <dir>` | Claude Code 폴더 기억 (Codex 는 `--codex`) |
|
|
61
|
+
| `ari roots remove <dir>` | 기억한 폴더 잊기 |
|
|
62
|
+
| `ari service install` | macOS: 로그인할 때부터 계속 실행 (아래 참고) |
|
|
63
|
+
| `ari service uninstall` | 서비스 멈추고 지우기 |
|
|
64
|
+
| `--no-dock` | `service install` 때 앱을 Dock 에 넣지 않음 |
|
|
65
|
+
| `ari open` | 실행 중인 서비스를 브라우저로 열기 |
|
|
66
|
+
|
|
67
|
+
## Finding your logs
|
|
68
|
+
|
|
69
|
+
| 도구 | 기본 폴더 |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Claude Code | `$CLAUDE_CONFIG_DIR/projects` 가 있으면 그것, 없으면 `~/.claude/projects` |
|
|
72
|
+
| Codex CLI | `$CODEX_HOME/sessions` 가 있으면 그것, 없으면 `~/.codex/sessions` |
|
|
73
|
+
|
|
74
|
+
기록이 다른 곳에 있으면(예: 다른 앱의 프로필별 폴더) 한 번만 더해 두세요. `~/.config/agent-run-inspector/config.json` 에 기억됩니다.
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
ari roots add ~/some/profile/projects
|
|
78
|
+
ari roots add --codex ~/some/codex/sessions
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Opening inside Orca
|
|
82
|
+
|
|
83
|
+
Orca 안에서는 주소가 Orca 브라우저 새 탭으로 열립니다(`orca tab create`). 실패하거나 Orca 밖이면 기본 브라우저로 엽니다. `--open=none` 이나 `--no-open` 은 주소만 출력합니다.
|
|
84
|
+
|
|
85
|
+
## The Mac app
|
|
86
|
+
|
|
87
|
+
`ari service install` 은 세 가지를 준비합니다.
|
|
88
|
+
|
|
89
|
+
- **백그라운드 서비스**: 로그인할 때 `http://127.0.0.1:7317/` 에서 시작되어(`--port <n>` 으로 변경) 언제든 열 수 있습니다.
|
|
90
|
+
- **Agent Run Inspector.app**: `~/Applications` 에 만들고 Dock 에 넣습니다(`--no-dock` 으로 건너뜀). 자체 창·Launchpad 항목이 있고 실행할 때마다 자동으로 로그인합니다. 메뉴 막대에도 항목을 띄웁니다([The menu bar](#the-menu-bar) 참고). 로그인할 때는 메뉴 막대 항목만 띄우고, 창은 메뉴나 Dock 에서 엽니다. macOS 에 들어 있는 `osacompile` 로 이 Mac 에서 직접 만들므로 내려받을 것도, 개발자 서명도 없습니다. 실패하면 Chrome 이나 Edge 에서 주소를 열고 설치를 고르세요.
|
|
91
|
+
- **1년 유지되는 로그인**: 그 주소를 북마크해도 됩니다. 브라우저 탭에 "Signed out" 이 보이면 `ari open` 을 실행하세요.
|
|
92
|
+
|
|
93
|
+
**업데이트**: 앱이 6시간마다 GitHub 의 최신 릴리스를 확인합니다. 새 버전이 있으면 메뉴 막대 패널에 "Update to …" 버튼이, 우클릭 메뉴에 "Update to …" 항목이 나옵니다(평소에는 "Check for Updates…"). 화면 머리에도 배지가 뜹니다. 누르면 앱이 새 버전을 설치하고 다시 열립니다(1분 정도). 실패하면 직접 칠 명령을 보여 줍니다: 패키지를 다시 설치하고 `ari service install` 을 다시 실행하면 서비스와 앱이 새 코드로 재시작됩니다. `ari service uninstall` 이 서비스·앱·Dock 아이콘·로그인 항목을 지웁니다. 로그는 `~/Library/Logs/agent-run-inspector.log` 입니다.
|
|
94
|
+
|
|
95
|
+
### The menu bar
|
|
96
|
+
|
|
97
|
+
<img src="docs/menubar.png" width="400" alt="그룹별로 묶인 진행 중 세션 세 개가 보이는 메뉴 막대 패널: Shop API 는 test-writer 가 Bash 실행 중, Docs site 는 사용자 응답 대기, 그룹 없는 세션은 생각 중">
|
|
98
|
+
|
|
99
|
+
메뉴 막대에 앱 표시와 지금 진행 중인 세션 수가 보입니다. 다른 앱에서 일하면서 긴 작업을 지켜볼 수 있습니다. 그림에는 세션이 보일 수 있는 세 가지 상태가 나옵니다: 도구 실행 중, 사용자 응답 대기, 생각 중.
|
|
100
|
+
|
|
101
|
+
- **클릭**하면 진행 중인 세션이 패널로 나오고, 직접 만든 [그룹](#what-you-see)별로 묶여 보입니다. 맨 윗줄은 진행 중인 수와 지금까지의 비용 합계입니다.
|
|
102
|
+
- 세션마다 제목, 프로젝트, 시간, 비용, 토큰, 실패한 호출 수가 나옵니다. 강조된 한 줄이 지금 하는 일을 알려 줍니다. 쓰는 도구와 그 호출에 걸린 시간, 호출 사이에는 "Thinking…", 사용자에게 물어볼 때는 **Waiting for you** 입니다. 하위 에이전트가 있으면 점과 함께 나열되고(주황: 일하는 중, 회색: 끝남) 몇 개가 끝났는지 보입니다.
|
|
103
|
+
- **세션을 누르면** 앱 창에서 열립니다. 아래의 "Open Agent Run Inspector" 는 창을 그대로 엽니다.
|
|
104
|
+
- **우클릭**하면 진행 중인 세션, Open, Check for Updates, Quit 이 있는 간단한 메뉴가 나옵니다.
|
|
105
|
+
- 패널은 다른 곳을 누르면 닫히고, 지금 쓰는 앱 위로 앱 창을 끌어올리지 않습니다.
|
|
106
|
+
- 노치가 있는 Mac 에서는 메뉴 막대가 꽉 차면 항목이 가려질 수 있습니다. ⌘ 를 누른 채 메뉴 막대 항목을 끌어 자리를 만들거나, 필요 없는 앱의 항목을 끄세요.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## Security
|
|
110
|
+
|
|
111
|
+
실행 기록에는 고객 데이터나 비밀이 있을 수 있으므로, 화면에 보이는 것 말고는 이 컴퓨터 밖으로 나가지 않습니다.
|
|
112
|
+
|
|
113
|
+
- 서버는 `127.0.0.1` 에서만 듣습니다.
|
|
114
|
+
- 실행마다 무작위 토큰을 만듭니다. 첫 주소에 한 번 담기고, 이후 HttpOnly·SameSite=Strict 쿠키로 바뀌며 주소창에서 사라집니다. 쿠키 없는 요청은 401 입니다. 예외는 웹 앱 manifest 와 아이콘뿐입니다(브라우저가 쿠키 없이 가져가며, 기록에 관한 내용은 없습니다). Host·Origin 헤더도 검사합니다.
|
|
115
|
+
- 서비스(`ari service install`)는 대신 토큰 하나를 `~/.config/agent-run-inspector/service.json`(본인만 읽기 가능)에 두고, 쿠키는 1년 유지됩니다. 토큰은 LaunchAgent 파일·프로세스 인자·로그 어디에도 남지 않습니다. `ari service uninstall` 이 지우고, 다시 설치하면 그대로 씁니다.
|
|
116
|
+
- 외부 요청은 업데이트 확인뿐입니다. CLI 는 하루에 한 번 GitHub(`api.github.com`, 이 프로젝트의 최신 릴리스)에 묻고, 더 새 버전이 있으면 터미널에 한 줄 알려 줍니다. Mac 앱은 6시간마다 같은 것을 묻습니다. 사용자나 기록에 관한 정보는 보내지 않습니다. CLI 확인은 `--no-update-check` 나 `ARI_NO_UPDATE_CHECK=1` 로 끌 수 있습니다(`CI`·`NO_UPDATE_NOTIFIER` 가 있으면 저절로 꺼짐). 스크립트·아이콘은 패키지 안에 있고 글꼴은 시스템 글꼴을 씁니다: CDN·웹 글꼴·텔레메트리 없음.
|
|
117
|
+
- 업데이트는 Mac 앱에서 Update 를 눌렀을 때만 설치됩니다: `npm i -g agent-run-inspector`(최신 릴리스, 아직 릴리스 안 된 작업은 아님) 와 `ari service install` 을 실행하고, 결과를 `~/Library/Logs/agent-run-inspector-update.log` 에 남깁니다.
|
|
118
|
+
- 보안 문제를 찾았다면 [SECURITY.md](SECURITY.md) 를 봐 주세요.
|
|
119
|
+
- 읽기 전용: 기록 파일을 쓰거나 지우지 않습니다. 화면은 파일 경로를 보내지 않고, 파일은 불투명 id 로만 찾으며 알려진 기록 폴더 안이어야 합니다.
|
|
120
|
+
|
|
121
|
+
### Redaction
|
|
122
|
+
|
|
123
|
+
`--redact`(basic)는 메시지 본문, 도구 입력 값, 과제, 명령, 오류 문구를 숨기고 길이와 키 이름만 남깁니다. `--redact=strict` 는 세션 제목, 프로젝트 이름, 브랜치, 폴더 경로까지 숨깁니다(화면 공유용). 화면 공유, 녹화, 스크린샷처럼 다른 사람이 화면을 볼 때 쓰세요.
|
|
124
|
+
|
|
125
|
+
## Cost
|
|
126
|
+
|
|
127
|
+
비용은 청구서가 아닌 추정치입니다. 모델 호출마다 내장 `prices.json`(100만 토큰당 USD, 기준일 `asOf` 2026-11-13, 모델마다 출처 주소: Anthropic·OpenAI 공개 가격 페이지)으로 값을 매기고, 모르는 모델의 호출은 토큰만 보이며 합계에 부분 표시가 붙습니다. Claude Code 실행은 Claude Code 가 직접 기록한 세션 합계("Reported")가 있으면 그것을 씁니다. 단, 팀원 세션이 들어 있는 실행은 그 합계에 팀원 몫이 빠져 있으므로 쓰지 않습니다. `--prices <file>` 로 모델을 덮어쓰거나 더할 수 있고, 내장 표 위에 필드 단위로 합쳐집니다.
|
|
128
|
+
|
|
129
|
+
## Supported scope
|
|
130
|
+
|
|
131
|
+
Claude Code(메인 세션, 하위 에이전트, 에이전트 팀의 팀원)와 Codex CLI(0.40 ~ 0.166 롤아웃 파일). 넣지 않는 것: 에이전트 조작, 훅·프록시, 원격 접속·계정, Cursor·Gemini CLI 같은 다른 도구, 본문 검색, 내보내기, 알림.
|
|
132
|
+
|
|
133
|
+
### Known limits
|
|
134
|
+
|
|
135
|
+
- Codex 하위 에이전트는 시간으로 부모와 잇기 때문에, 여러 개가 동시에 시작하면 연결이 추정입니다.
|
|
136
|
+
- 하위 에이전트의 하위 에이전트(손자)는 본 기록에서 드물고, 다음 줄의 일반 카드로 그립니다.
|
|
137
|
+
- Claude Code 팀원은 기록 폴더가 리더와 같거나 그 아래일 때만(예: 리더 프로젝트의 `.claude/worktrees/...` 워크트리) 리더에 묶입니다. 그 밖이면 별도 세션으로 나옵니다. 팀원이 띄운 하위 에이전트는 아직 그리지 않습니다.
|
|
138
|
+
- 작업 폴더가 다른 실행(예: Orca 워크트리마다 하나씩)은 각각 별도 세션으로 나옵니다.
|
|
139
|
+
- 비용은 아는 모델이어야 계산되고, 모르는 모델은 토큰만 보입니다.
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
git clone https://github.com/th-yong/agent-run-inspector.git
|
|
145
|
+
cd agent-run-inspector
|
|
146
|
+
node bin/cli.js # 또는: npm link 후 ari 실행
|
|
147
|
+
npm test && npm run lint
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
앱 없이 `ari` 를 실행하면 `http://127.0.0.1:<port>/?t=<token>` 을 출력하고 엽니다. 토큰은 그 실행 동안만 브라우저를 로그인시킵니다.
|
|
151
|
+
|
|
152
|
+
## Third-party assets
|
|
153
|
+
|
|
154
|
+
브랜드 아이콘은 simple-icons 15.22.0(CC0-1.0)에서 가져와 의존성 없이 인라인했고, 호출이 어느 제공사·서비스의 것인지 표시하는 데만 씁니다. 브랜드 이름과 로고의 상표는 각 회사 소유이며, 이 프로젝트는 그 회사들과 제휴하거나 보증받지 않았습니다. 로고는 각 회사 고유색 그대로 씁니다. 가이드라인이 이런 사용을 허용하지 않는 회사(OpenAI, Google, Figma, Slack, Python, Docker, PostgreSQL, Linear, Vercel, Atlassian)의 로고는 그리지 않고 중립 기호로 대신합니다. 출처 표기(Git 로고 Jason Long, CC BY 3.0 / Yarn 로고 CC BY 4.0), 상표 고지, 회사별 가이드라인 검토 결과는 [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md) 에 있습니다.
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
코드는 [MIT License](LICENSE) 를 따릅니다. 이 라이선스는 다른 회사의 브랜드 이름과 로고에는 적용되지 않습니다.
|
package/README.md
CHANGED
|
@@ -1,3 +1,158 @@
|
|
|
1
|
-
|
|
1
|
+
English | [한국어](README.ko.md)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# agent-run-inspector
|
|
4
|
+
|
|
5
|
+
[](https://github.com/th-yong/agent-run-inspector/actions/workflows/ci.yml)
|
|
6
|
+
[](LICENSE)
|
|
7
|
+
[](package.json)
|
|
8
|
+
|
|
9
|
+
A local, read-only inspector for Claude Code and Codex CLI agent runs: see who called whom, what each call cost and where it failed, live, in your browser.
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
## Get started
|
|
14
|
+
|
|
15
|
+
It reads the run logs Claude Code and Codex CLI already write to disk. Nothing is installed into the agents (no hooks, no proxy). You need Node 22 or newer (check with `node -v`). On a Mac without it, install it with `brew install node` ([Homebrew](https://brew.sh)) or the installer from [nodejs.org](https://nodejs.org). If `npm i -g` fails with `EACCES`, your Node came from the nodejs.org installer: use Homebrew's Node or [nvm](https://github.com/nvm-sh/nvm) rather than `sudo`.
|
|
16
|
+
|
|
17
|
+
### On a Mac: use it as an app
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm i -g agent-run-inspector
|
|
21
|
+
ari service install
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
That's all. **Agent Run Inspector** opens in its own window and stays in your Dock, and it starts with your Mac, so you never need the terminal again. It also puts a menu bar item up that counts running runs. Details: [The Mac app](#the-mac-app).
|
|
25
|
+
|
|
26
|
+
### Anywhere: try it once
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
npx agent-run-inspector
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
It opens the inspector in your browser and runs until you press Ctrl+C.
|
|
33
|
+
|
|
34
|
+
## What you see
|
|
35
|
+
|
|
36
|
+
- **Session list**: running sessions on top, then recent ones (fold them with a click). Filter by tool (Claude Code, Codex CLI) and period (Today by default), or search by title or project. **Groups**: make one with "+ New group", then drag sessions onto it or right-click a session; pick a group to see only its sessions. Groups are kept in `~/.config/agent-run-inspector/groups.json`. Agent-team teammates are folded into the run that started them instead of being listed on their own.
|
|
37
|
+
- **Graph**: one card per agent, from the orchestrator down. Each card shows its latest calls, status, cost, time and call count. Click a card to total that agent; "Hide finished agents" keeps only the ones still working.
|
|
38
|
+
- **Timeline**: every agent and call on one time axis, with turns and context compactions. Open a call to see its details.
|
|
39
|
+
- **Totals**: time, cost, tokens, model calls, tool calls and errors for the whole run or the selected agent.
|
|
40
|
+
- **Live**: new lines in the logs show up within about a second, with no reload.
|
|
41
|
+
|
|
42
|
+
## Options
|
|
43
|
+
|
|
44
|
+
| Option | What it does |
|
|
45
|
+
|---|---|
|
|
46
|
+
| `--port <n>` | Port to listen on (default: random free port) |
|
|
47
|
+
| `--open[=<where>]` | Open the address: `auto` (default; Orca tab inside Orca, else default browser), `orca`, `browser` or `none` |
|
|
48
|
+
| `--no-open` | Only print the address (same as `--open=none`) |
|
|
49
|
+
| `--root <dir>` | Extra Claude Code projects folder (repeatable) |
|
|
50
|
+
| `--codex-root <dir>` | Extra Codex sessions folder (repeatable) |
|
|
51
|
+
| `--source <name>` | `claude`, `codex` or `all` (default: `all`) |
|
|
52
|
+
| `--since <age>` | Only runs newer than this, e.g. `24h`, `7d`, `30d` |
|
|
53
|
+
| `--redact[=strict]` | Hide message bodies (`strict`: hide more) |
|
|
54
|
+
| `--prices <file>` | Price table that overrides the built-in one |
|
|
55
|
+
| `--session <id>` | Open this session directly |
|
|
56
|
+
| `--no-update-check` | Do not check npm for a newer version |
|
|
57
|
+
| `-v, --version` | Print the version |
|
|
58
|
+
| `-h, --help` | Show the help |
|
|
59
|
+
| `ari roots list` | Show the log folders in use |
|
|
60
|
+
| `ari roots add <dir>` | Remember a Claude Code folder (`--codex` for Codex) |
|
|
61
|
+
| `ari roots remove <dir>` | Forget a remembered folder |
|
|
62
|
+
| `ari service install` | macOS: keep it running from login (see below) |
|
|
63
|
+
| `ari service uninstall` | Stop and remove the service |
|
|
64
|
+
| `--no-dock` | With `service install`: do not add the app to the Dock |
|
|
65
|
+
| `ari open` | Open the running service in the browser |
|
|
66
|
+
|
|
67
|
+
## Finding your logs
|
|
68
|
+
|
|
69
|
+
| Tool | Default folder |
|
|
70
|
+
|---|---|
|
|
71
|
+
| Claude Code | `$CLAUDE_CONFIG_DIR/projects` if set, else `~/.claude/projects` |
|
|
72
|
+
| Codex CLI | `$CODEX_HOME/sessions` if set, else `~/.codex/sessions` |
|
|
73
|
+
|
|
74
|
+
If your logs live elsewhere, for example in a per-profile folder of another app, add the folder once and it is remembered in `~/.config/agent-run-inspector/config.json`:
|
|
75
|
+
|
|
76
|
+
```sh
|
|
77
|
+
ari roots add ~/some/profile/projects
|
|
78
|
+
ari roots add --codex ~/some/codex/sessions
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Opening inside Orca
|
|
82
|
+
|
|
83
|
+
Inside Orca the address opens as a new Orca browser tab (`orca tab create`). If that fails, or outside Orca, it falls back to the default browser. `--open=none` or `--no-open` only prints the address.
|
|
84
|
+
|
|
85
|
+
## The Mac app
|
|
86
|
+
|
|
87
|
+
`ari service install` sets up three things:
|
|
88
|
+
|
|
89
|
+
- **A background service** that starts at login on `http://127.0.0.1:7317/` (`--port <n>` to change), so the inspector is always ready.
|
|
90
|
+
- **Agent Run Inspector.app** in `~/Applications`, added to the Dock (`--no-dock` to skip): its own window and Launchpad entry, signed in at every launch. It also puts an item in the menu bar (see [The menu bar](#the-menu-bar)). At login the app starts with only the menu bar item, and the window opens from the menu or the Dock. It is built on your Mac with the built-in `osacompile`, so there is nothing to download and no developer signing. If that fails, open the address in Chrome or Edge and choose Install instead.
|
|
91
|
+
- **A sign-in that lasts a year** for that address, so a bookmark works too. If a browser tab says "Signed out", run `ari open`.
|
|
92
|
+
|
|
93
|
+
**Updates**: the app checks the latest GitHub release every 6 hours. When there is a newer one, the menu bar panel shows an "Update to …" button and the right-click menu an "Update to …" item (otherwise "Check for Updates…"); the page header shows a badge too. Click it and the app installs the new version and reopens (about a minute). If that fails, it shows the commands to run: install the package again and run `ari service install` again, which restarts the service and the app on the new code. `ari service uninstall` removes the service, the app, its Dock icon and its login item. The log is `~/Library/Logs/agent-run-inspector.log`.
|
|
94
|
+
|
|
95
|
+
### The menu bar
|
|
96
|
+
|
|
97
|
+
<img src="docs/menubar.png" width="400" alt="Menu bar panel with three running sessions by group: Shop API, where test-writer is in a Bash call; Docs site, waiting for you; and an ungrouped one thinking">
|
|
98
|
+
|
|
99
|
+
The app's mark sits in the menu bar with the number of sessions running now, so you can follow long runs while you work in other apps. The picture shows the three states a session can be in: in a tool call, waiting for you, and thinking.
|
|
100
|
+
|
|
101
|
+
- **Click** for a panel of the running sessions, grouped by your [groups](#what-you-see). The top line shows how many are running and what they have cost so far.
|
|
102
|
+
- Each session shows its title, project, time, cost, tokens and failed calls. A highlighted line says what it is doing now: the tool and how long it has been in it, "Thinking…" between calls, or **Waiting for you** when it asks you something. When a run has sub-agents, they are listed with a dot each (orange: working, grey: done) and how many are done.
|
|
103
|
+
- **Click a session** to open it in the app window. "Open Agent Run Inspector" at the bottom opens the window as it was.
|
|
104
|
+
- **Right-click** for a plain menu: the running sessions, Open, Check for Updates and Quit.
|
|
105
|
+
- The panel closes when you click anywhere else, and it does not bring the app window in front of what you are working on.
|
|
106
|
+
- On a Mac with a notch, the item can be hidden when the menu bar is full. Hold ⌘ and drag menu bar items to make room, or quit an app whose item you don't need.
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
## Security
|
|
110
|
+
|
|
111
|
+
Run logs can hold customer data and secrets, so nothing leaves your machine except what you see on screen.
|
|
112
|
+
|
|
113
|
+
- The server listens on `127.0.0.1` only.
|
|
114
|
+
- Each run makes a random token. The first address carries it once, then it becomes an HttpOnly, SameSite=Strict cookie and disappears from the address bar. Requests without the cookie get 401, except the web app manifest and its icons (browsers fetch them without cookies; they hold nothing about your logs). Host and Origin headers are checked.
|
|
115
|
+
- The service (`ari service install`) instead keeps one token in `~/.config/agent-run-inspector/service.json` (readable by you only), and its cookie lasts a year. The token is never in the LaunchAgent file, the process arguments or the log. `ari service uninstall` deletes it; installing again keeps it.
|
|
116
|
+
- Outside requests are update checks only. The CLI asks GitHub (`api.github.com`, the latest release of this project) once a day and prints a line in the terminal if there is a newer version. The Mac app asks the same every 6 hours. Neither sends anything about you or your logs. Turn the CLI check off with `--no-update-check` or `ARI_NO_UPDATE_CHECK=1` (also off when `CI` or `NO_UPDATE_NOTIFIER` is set). Scripts and icons ship in the package and text uses the system's own fonts: no CDN, web fonts or telemetry.
|
|
117
|
+
- Updates install only when you press Update in the Mac app: it runs `npm i -g agent-run-inspector` (the newest release, not unreleased work) and `ari service install`, and writes what happened to `~/Library/Logs/agent-run-inspector-update.log`.
|
|
118
|
+
- Found a security problem? See [SECURITY.md](SECURITY.md).
|
|
119
|
+
- Read-only: log files are never written or deleted. The screen never sends a file path; files are found by opaque ids and must stay inside the known log folders.
|
|
120
|
+
|
|
121
|
+
### Redaction
|
|
122
|
+
|
|
123
|
+
`--redact` (basic) hides message bodies, tool input values, tasks, commands and error text, and keeps only lengths and key names. `--redact=strict` also hides session titles, project names, branches and folder paths, for screen sharing. Use it when someone else sees your screen: a screen share, a recording or a screenshot.
|
|
124
|
+
|
|
125
|
+
## Cost
|
|
126
|
+
|
|
127
|
+
Costs are estimates, not bills. Each model call is priced from the built-in `prices.json` (USD per 1M tokens, with an `asOf` date of 2026-11-13 and a source URL per model: the Anthropic and OpenAI public pricing pages); a call on an unknown model shows tokens only and the total is marked partial. For a Claude Code run, the session total that Claude Code itself recorded ("Reported") replaces the sum when it is there, except when teammate sessions are part of the run, since that total leaves them out. Override or add models with `--prices <file>`, which is merged field by field over the built-in table.
|
|
128
|
+
|
|
129
|
+
## Supported scope
|
|
130
|
+
|
|
131
|
+
Claude Code (main sessions, sub-agents, agent-team teammates) and Codex CLI (rollout files from 0.40 to 0.166). Not included: controlling agents, hooks or proxies, remote access or accounts, other tools such as Cursor or Gemini CLI, full-text search, exporting, and alerts.
|
|
132
|
+
|
|
133
|
+
### Known limits
|
|
134
|
+
|
|
135
|
+
- Codex sub-agents are linked to their parent by timing, so the link is an estimate when several start at once.
|
|
136
|
+
- Sub-agents of sub-agents are rare in the logs we have seen and are drawn as plain cards on the next row.
|
|
137
|
+
- A Claude Code teammate is joined to its lead only when its log folder is the lead's own or one below it (for example a `.claude/worktrees/...` worktree of the lead's project). Otherwise it is listed as a session of its own. Sub-agents started by a teammate are not drawn yet.
|
|
138
|
+
- Every run in its own working folder (for example one Orca worktree each) is listed as its own session.
|
|
139
|
+
- Cost needs a known model; unknown models show tokens only.
|
|
140
|
+
|
|
141
|
+
## Development
|
|
142
|
+
|
|
143
|
+
```sh
|
|
144
|
+
git clone https://github.com/th-yong/agent-run-inspector.git
|
|
145
|
+
cd agent-run-inspector
|
|
146
|
+
node bin/cli.js # or: npm link, then run ari
|
|
147
|
+
npm test && npm run lint
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Without the app, `ari` prints `http://127.0.0.1:<port>/?t=<token>` and opens it; the token signs the browser in for that run only.
|
|
151
|
+
|
|
152
|
+
## Third-party assets
|
|
153
|
+
|
|
154
|
+
Brand icons come from simple-icons 15.22.0 (CC0-1.0), inlined without a dependency, and only mark which provider or service a call belongs to. Brand names and logos are trademarks of their owners; this project is not affiliated with or endorsed by them. Logos keep their owners' colors. Logos whose owners' guidelines do not allow this use (OpenAI, Google, Figma, Slack, Python, Docker, PostgreSQL, Linear, Vercel, Atlassian) are not drawn; a neutral symbol stands in. Credits (Git logo by Jason Long, CC BY 3.0; Yarn logo, CC BY 4.0), trademark notices and the per-brand guideline review are in [THIRD_PARTY_NOTICES.md](THIRD_PARTY_NOTICES.md).
|
|
155
|
+
|
|
156
|
+
## License
|
|
157
|
+
|
|
158
|
+
The code is under the [MIT License](LICENSE). The license does not cover the third-party brand names and logos.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## Brand icons (`web/icons.js`)
|
|
4
|
+
|
|
5
|
+
The icon shapes come from [simple-icons](https://github.com/simple-icons/simple-icons) 15.22.0, released under CC0-1.0, and are inlined without a dependency (`scripts/build-icons.js`, mapping in `brand-map.json`). The icons appear next to model and tool names only so you can tell which provider or service a call belongs to. This project is not affiliated with, sponsored by or endorsed by any of these companies.
|
|
6
|
+
|
|
7
|
+
The MIT License in `LICENSE` covers this project's code only, not these names and logos. CC0 covers the copyright in the simple-icons files only. It does not grant any trademark right: each name and logo remains a trademark of its owner, and the owner's brand guidelines apply.
|
|
8
|
+
|
|
9
|
+
### Attributions required by the logo licenses
|
|
10
|
+
|
|
11
|
+
- **Git**: the Git logo is by [Jason Long](https://twitter.com/jasonlong), licensed under [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/). Shown here as a single-color icon.
|
|
12
|
+
- **Yarn**: the Yarn logo comes from [yarnpkg/assets](https://github.com/yarnpkg/assets), licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Shown here as a single-color icon.
|
|
13
|
+
|
|
14
|
+
### Trademark notices
|
|
15
|
+
|
|
16
|
+
- Redis is a registered trademark of Redis Ltd. Any rights therein are reserved to Redis Ltd. This project is not endorsed, supported or certified by Redis.
|
|
17
|
+
- Node.js is a trademark of the OpenJS Foundation. Kubernetes is a registered trademark of The Linux Foundation.
|
|
18
|
+
- Claude and Anthropic, GitHub, Git (word mark: Software Freedom Conservancy), Notion, npm, pnpm, Yarn, uv, Supabase, Sentry and Stripe are trademarks of their respective owners. Other product names that appear as text (for example in tool names) are trademarks of their respective owners.
|
|
19
|
+
|
|
20
|
+
### Brand guideline review (2026-11-16)
|
|
21
|
+
|
|
22
|
+
Each owner's public brand guideline was read on 2026-11-16. None of them is a license to ship their logo inside another product: at most they allow a logo to refer to the service, unchanged and without implying endorsement. So:
|
|
23
|
+
|
|
24
|
+
- Logos are drawn in the owner's own color. Black or gray logos use the theme text color (the owner's black or white variant). Colors are never shifted for contrast.
|
|
25
|
+
- Logos whose guideline forbids how this app would show them are **not drawn**: the neutral category symbol is shown instead, and the service is still recognized by name (`noIcon` in `brand-map.json`).
|
|
26
|
+
|
|
27
|
+
| Icon | Guideline | What it says | Here |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| Claude (Anthropic) | none found | No public logo guideline found | Drawn; unverified |
|
|
30
|
+
| GitHub | [brand.github.com](https://brand.github.com/foundations/logo) | Logo may show that a project integrates with GitHub; do not modify, including color | Drawn, black / white |
|
|
31
|
+
| Git | [git-scm.com logos](https://git-scm.com/community/logos) | CC BY 3.0 | Drawn, credit above |
|
|
32
|
+
| Yarn | [yarnpkg/assets](https://github.com/yarnpkg/assets) | CC BY 4.0 | Drawn, credit above |
|
|
33
|
+
| npm | [npm/logos](https://github.com/npm/logos) | Do not change the colors | Drawn, brand red |
|
|
34
|
+
| Kubernetes | [Linux Foundation trademark usage](https://www.linuxfoundation.org/legal/trademark-usage) | No color variations; official versions only | Drawn, brand blue |
|
|
35
|
+
| Redis | [Redis trademark policy](https://redis.io/legal/trademark-policy/) | Nominative reference allowed with the attribution line | Drawn, notice above |
|
|
36
|
+
| Node.js | [Node.js branding](https://nodejs.org/en/about/branding) | OpenJS Foundation trademark policy (PDF) | Drawn; unverified |
|
|
37
|
+
| Notion, pnpm, uv, Supabase, Sentry, Stripe | – | No public guideline could be read (Stripe: Marks Usage Agreement) | Drawn; unverified |
|
|
38
|
+
| OpenAI | [openai.com/brand](https://openai.com/brand/) | Use exactly as provided; no use without permission | Not drawn |
|
|
39
|
+
| Google (Gemini, Gmail, Drive, Docs, Calendar, Cloud, Chrome) | [Google trademark rules](https://partnermarketinghub.withgoogle.com/brands/google/trademarks-and-terms/trademark-guidelines-for-proper-usage/) | Do not alter any element; use needs approval | Not drawn |
|
|
40
|
+
| Figma | [Figma brand use](https://www.figma.com/using-the-figma-brand/) | Do not modify | Not drawn (multi-color logo) |
|
|
41
|
+
| Slack | [Slack media kit](https://slack.com/media-kit) | Brand center rules | Not drawn (multi-color logo) |
|
|
42
|
+
| Python | [PSF trademark policy](https://www.python.org/psf/trademarks/) | Unaltered logo, with ™ | Not drawn (two-color logo) |
|
|
43
|
+
| Docker | [Docker trademark guidelines](https://www.docker.com/legal/trademark-guidelines/) | Logo marks need written permission | Not drawn |
|
|
44
|
+
| PostgreSQL | [PostgreSQL trademark policy](https://www.postgresql.org/about/policies/trademarks/) | Not presented with other logos | Not drawn |
|
|
45
|
+
| Linear | [linear.app/brand](https://linear.app/brand) | Do not combine with other graphics without consent | Not drawn |
|
|
46
|
+
| Vercel | [Vercel brands](https://vercel.com/geist/brands) | Uses in software otherwise need permission | Not drawn |
|
|
47
|
+
| Atlassian, Jira, Confluence | [Atlassian logos](https://atlassian.design/foundations/logos) | Approved colors and tiles only | Not drawn |
|
|
48
|
+
|
|
49
|
+
If an unverified owner objects, add its slug to `noIcon.slugs` and run `node scripts/build-icons.js`.
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { execFile } from 'node:child_process';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { parseArgs, promisify } from 'node:util';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { HELP, MSG } from '../src/strings.js';
|
|
8
|
+
import { loadConfig, saveConfig } from '../src/config.js';
|
|
9
|
+
import { loadPrices } from '../src/cost.js';
|
|
10
|
+
import { realDir, resolveRoots } from '../src/roots.js';
|
|
11
|
+
import { startApp } from '../src/app.js';
|
|
12
|
+
import { OPEN_MODES, openAddress } from '../src/open.js';
|
|
13
|
+
import { checkForUpdate } from '../src/update-check.js';
|
|
14
|
+
import {
|
|
15
|
+
COOKIE_MAX_AGE, DEFAULT_PORT, ServiceError, appDir, buildApp, installLoginItem, installService, loadService, logFile, serviceUrl, stableNode, uninstallService,
|
|
16
|
+
} from '../src/service.js';
|
|
17
|
+
import { pinToDock, unpinFromDock } from '../src/dock.js';
|
|
18
|
+
|
|
19
|
+
const pkgUrl = new URL('../package.json', import.meta.url);
|
|
20
|
+
const { version } = JSON.parse(readFileSync(pkgUrl, 'utf8'));
|
|
21
|
+
|
|
22
|
+
const OPTIONS = {
|
|
23
|
+
port: { type: 'string' },
|
|
24
|
+
open: { type: 'string' },
|
|
25
|
+
'no-open': { type: 'boolean' },
|
|
26
|
+
'no-update-check': { type: 'boolean' },
|
|
27
|
+
'no-dock': { type: 'boolean' },
|
|
28
|
+
service: { type: 'boolean' }, // set by the LaunchAgent (ari service install), not meant to be typed
|
|
29
|
+
root: { type: 'string', multiple: true },
|
|
30
|
+
'codex-root': { type: 'string', multiple: true },
|
|
31
|
+
source: { type: 'string' },
|
|
32
|
+
since: { type: 'string' },
|
|
33
|
+
redact: { type: 'string' },
|
|
34
|
+
prices: { type: 'string' },
|
|
35
|
+
session: { type: 'string' },
|
|
36
|
+
codex: { type: 'boolean' },
|
|
37
|
+
help: { type: 'boolean', short: 'h' },
|
|
38
|
+
version: { type: 'boolean', short: 'v' },
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
class UsageError extends Error {}
|
|
42
|
+
|
|
43
|
+
// parseArgs has no optional values, so a bare --redact becomes --redact=basic and a bare --open becomes --open=auto.
|
|
44
|
+
function parseCli(argv) {
|
|
45
|
+
const fixed = argv.map((a) => (a === '--redact' ? '--redact=basic' : a === '--open' ? '--open=auto' : a));
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = parseArgs({ args: fixed, options: OPTIONS, allowPositionals: true, strict: true });
|
|
49
|
+
} catch (e) {
|
|
50
|
+
throw new UsageError(MSG.unknownOption(e.message.split('\n')[0]));
|
|
51
|
+
}
|
|
52
|
+
const v = parsed.values;
|
|
53
|
+
if (v.port !== undefined && !(/^\d+$/.test(v.port) && Number(v.port) <= 65535)) {
|
|
54
|
+
throw new UsageError(MSG.badValue('--port', '0-65535'));
|
|
55
|
+
}
|
|
56
|
+
if (v.source !== undefined && !['claude', 'codex', 'all'].includes(v.source)) {
|
|
57
|
+
throw new UsageError(MSG.badValue('--source', 'claude, codex or all'));
|
|
58
|
+
}
|
|
59
|
+
if (v.since !== undefined && !/^[1-9]\d*[hd]$/.test(v.since)) {
|
|
60
|
+
throw new UsageError(MSG.badValue('--since', 'e.g. 24h, 7d'));
|
|
61
|
+
}
|
|
62
|
+
if (v.redact !== undefined && !['basic', 'strict'].includes(v.redact)) {
|
|
63
|
+
throw new UsageError(MSG.badValue('--redact', 'only --redact or --redact=strict'));
|
|
64
|
+
}
|
|
65
|
+
if (v.open !== undefined && !OPEN_MODES.includes(v.open)) {
|
|
66
|
+
throw new UsageError(MSG.badValue('--open', 'auto, orca, browser or none'));
|
|
67
|
+
}
|
|
68
|
+
if (v.open !== undefined && v['no-open']) throw new UsageError(MSG.conflictOpen);
|
|
69
|
+
return parsed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function loadConfigOrFail(env) {
|
|
73
|
+
try {
|
|
74
|
+
return loadConfig(env);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
if (e.code !== 'ECONFIG') throw e;
|
|
77
|
+
throw new UsageError(MSG.badConfig(e.file));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function rootsCommand(positionals, values, env) {
|
|
82
|
+
const [, action, dir, ...extra] = positionals;
|
|
83
|
+
const cfg = loadConfigOrFail(env);
|
|
84
|
+
const key = values.codex ? 'codexRoots' : 'claudeRoots';
|
|
85
|
+
if (action === 'list' && !dir) {
|
|
86
|
+
const r = resolveRoots({ env, config: cfg });
|
|
87
|
+
const lines = [
|
|
88
|
+
...r.claude.map((x) => MSG.rootLine('claude', x.path, x.origin)),
|
|
89
|
+
...r.codex.map((x) => MSG.rootLine('codex', x.path, x.origin)),
|
|
90
|
+
];
|
|
91
|
+
console.log(lines.length ? lines.join('\n') : MSG.rootsNone);
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
if ((action !== 'add' && action !== 'remove') || extra.length) throw new UsageError(MSG.rootsUsage);
|
|
95
|
+
if (!dir) throw new UsageError(MSG.rootsNeedDir);
|
|
96
|
+
const abs = resolve(dir);
|
|
97
|
+
if (action === 'add') {
|
|
98
|
+
const real = realDir(abs);
|
|
99
|
+
if (!real) throw new UsageError(MSG.notADirectory(abs));
|
|
100
|
+
if (cfg[key].some((p) => p === real || realDir(p) === real)) {
|
|
101
|
+
console.log(MSG.rootExists(real));
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
cfg[key].push(real);
|
|
105
|
+
saveConfig(cfg, env);
|
|
106
|
+
console.log(MSG.rootAdded(real));
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
const real = realDir(abs);
|
|
110
|
+
const keep = cfg[key].filter((p) => p !== abs && p !== real && (!real || realDir(p) !== real));
|
|
111
|
+
if (keep.length === cfg[key].length) {
|
|
112
|
+
console.log(MSG.rootNotFound(abs));
|
|
113
|
+
return 1;
|
|
114
|
+
}
|
|
115
|
+
cfg[key] = keep;
|
|
116
|
+
saveConfig(cfg, env);
|
|
117
|
+
console.log(MSG.rootRemoved(abs));
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function serviceCommand(positionals, values, env) {
|
|
122
|
+
const [, action, ...extra] = positionals;
|
|
123
|
+
if ((action !== 'install' && action !== 'uninstall') || extra.length) throw new UsageError(MSG.serviceUsage);
|
|
124
|
+
const run = promisify(execFile);
|
|
125
|
+
try {
|
|
126
|
+
if (action === 'uninstall') {
|
|
127
|
+
if (process.platform === 'darwin' && (await unpinFromDock(appDir(env), run).catch(() => false))) console.log(MSG.dockRemoved);
|
|
128
|
+
console.log((await uninstallService({ env, run })) ? MSG.serviceRemoved : MSG.serviceNone);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
const port = values.port === undefined ? loadService(env)?.port ?? DEFAULT_PORT : Number(values.port);
|
|
132
|
+
if (port === 0) throw new UsageError(MSG.badValue('--port', '1-65535 for a service'));
|
|
133
|
+
const s = await installService({ env, port, node: stableNode(env), cli: fileURLToPath(import.meta.url), run });
|
|
134
|
+
console.log(MSG.serviceInstalled(`http://127.0.0.1:${s.port}/`, logFile(env)));
|
|
135
|
+
const app = await buildApp({ env, run, version }).catch(() => null); // the service is fine without the app
|
|
136
|
+
console.log(app ? MSG.appBuilt(app) : MSG.appFailed);
|
|
137
|
+
if (app) await installLoginItem({ env, app, run }); // at login: menu bar item only, window on demand
|
|
138
|
+
if (app && !values['no-dock'] && (await pinToDock(app, run).catch(() => false))) console.log(MSG.dockAdded);
|
|
139
|
+
if (!values['no-open']) {
|
|
140
|
+
if (app) await run('open', [app]).catch(() => {});
|
|
141
|
+
else await openAddress(serviceUrl(s), { mode: values.open ?? 'browser', env }).catch(() => {});
|
|
142
|
+
}
|
|
143
|
+
return 0;
|
|
144
|
+
} catch (e) {
|
|
145
|
+
if (e instanceof ServiceError) throw new UsageError(e.message);
|
|
146
|
+
if (e.code === 'ENOENT' || e.stderr !== undefined) throw new UsageError(MSG.serviceFailed(String(e.stderr || e.message).trim()));
|
|
147
|
+
throw e;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function openCommand(values, env) {
|
|
152
|
+
const s = loadService(env);
|
|
153
|
+
if (!s) throw new UsageError(MSG.serviceNone);
|
|
154
|
+
await openAddress(serviceUrl(s), { mode: values['no-open'] ? 'none' : values.open ?? 'auto', env });
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async function main(argv, env) {
|
|
159
|
+
const { values, positionals } = parseCli(argv);
|
|
160
|
+
if (values.help) {
|
|
161
|
+
console.log(HELP);
|
|
162
|
+
return 0;
|
|
163
|
+
}
|
|
164
|
+
if (values.version) {
|
|
165
|
+
console.log(version);
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
if (positionals[0] === 'roots') return rootsCommand(positionals, values, env);
|
|
169
|
+
if (positionals[0] === 'service') return serviceCommand(positionals, values, env);
|
|
170
|
+
if (positionals[0] === 'open' && positionals.length === 1) return openCommand(values, env);
|
|
171
|
+
if (positionals.length) throw new UsageError(MSG.unknownCommand(positionals[0]));
|
|
172
|
+
// Service mode: fixed port and token from the token file, a lasting cookie, no address printed (the log is not secret).
|
|
173
|
+
const svc = values.service ? loadService(env) : null;
|
|
174
|
+
if (values.service && !svc) throw new UsageError(MSG.serviceNone);
|
|
175
|
+
const cfg = loadConfigOrFail(env);
|
|
176
|
+
try {
|
|
177
|
+
loadPrices({ file: values.prices, config: cfg.prices }); // fail early on a bad price file
|
|
178
|
+
} catch (e) {
|
|
179
|
+
if (e.code !== 'EPRICES') throw e;
|
|
180
|
+
throw new UsageError(MSG.badPrices(e.message));
|
|
181
|
+
}
|
|
182
|
+
const roots = resolveRoots({
|
|
183
|
+
env,
|
|
184
|
+
config: cfg,
|
|
185
|
+
flags: { root: values.root, codexRoot: values['codex-root'] },
|
|
186
|
+
});
|
|
187
|
+
for (const p of roots.missing) console.error(`Warning: folder not found: ${p}`);
|
|
188
|
+
if (!roots.claude.length && !roots.codex.length) {
|
|
189
|
+
console.error(MSG.noRoots);
|
|
190
|
+
return 1;
|
|
191
|
+
}
|
|
192
|
+
const meta = { version, latest: null }; // /api/meta: the web header shows the version and a newer one
|
|
193
|
+
let app;
|
|
194
|
+
try {
|
|
195
|
+
app = await startApp({
|
|
196
|
+
meta,
|
|
197
|
+
config: cfg,
|
|
198
|
+
roots,
|
|
199
|
+
port: svc ? svc.port : values.port === undefined ? 0 : Number(values.port),
|
|
200
|
+
...(svc ? { token: svc.token, cookieMaxAge: COOKIE_MAX_AGE } : {}),
|
|
201
|
+
source: values.source,
|
|
202
|
+
since: values.since,
|
|
203
|
+
redact: values.redact,
|
|
204
|
+
prices: values.prices,
|
|
205
|
+
session: values.session,
|
|
206
|
+
});
|
|
207
|
+
} catch (e) {
|
|
208
|
+
if (e.code === 'EADDRINUSE') throw new UsageError(MSG.portInUse(svc?.port ?? values.port));
|
|
209
|
+
if (e.code === 'EACCES') throw new UsageError(MSG.portDenied(svc?.port ?? values.port));
|
|
210
|
+
throw e;
|
|
211
|
+
}
|
|
212
|
+
return new Promise((done) => {
|
|
213
|
+
let stopping = false;
|
|
214
|
+
const stop = () => {
|
|
215
|
+
if (stopping) return;
|
|
216
|
+
stopping = true;
|
|
217
|
+
app.close().then(() => done(0), () => done(0));
|
|
218
|
+
};
|
|
219
|
+
process.once('SIGINT', stop);
|
|
220
|
+
process.once('SIGTERM', stop);
|
|
221
|
+
// Print only after the handlers exist: a signal that arrives before then would kill the process with the default action.
|
|
222
|
+
if (svc) console.log(MSG.serviceStarted(`http://127.0.0.1:${svc.port}/`));
|
|
223
|
+
else {
|
|
224
|
+
console.log(app.url);
|
|
225
|
+
openAddress(app.url, { mode: values['no-open'] ? 'none' : values.open ?? 'auto', env }).catch(() => {});
|
|
226
|
+
}
|
|
227
|
+
if (!values['no-update-check']) {
|
|
228
|
+
const check = () => checkForUpdate({ version, env }).then((v) => {
|
|
229
|
+
meta.latest = v;
|
|
230
|
+
if (v && !stopping) console.error(MSG.updateAvailable(version, v));
|
|
231
|
+
}, () => {});
|
|
232
|
+
check();
|
|
233
|
+
if (svc) setInterval(check, 6 * 60 * 60 * 1000).unref(); // a service runs for days; the check itself is cached a day
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
process.exitCode = await main(process.argv.slice(2), process.env);
|
|
240
|
+
} catch (e) {
|
|
241
|
+
if (!(e instanceof UsageError)) throw e;
|
|
242
|
+
console.error(e.message);
|
|
243
|
+
console.error('Run "ari --help" for usage.');
|
|
244
|
+
process.exitCode = 2;
|
|
245
|
+
}
|