officepals 0.3.0 → 0.3.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/CHANGELOG.md +45 -0
- package/README.md +140 -57
- package/package.json +6 -3
- package/src/server.mjs +47 -2
- package/web/index.html +9 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.3.2 — 2026-11-30
|
|
4
|
+
|
|
5
|
+
- A README that leads with why you'd use it, with a table of what each kind of work looks like in the office (English and Chinese).
|
|
6
|
+
- This changelog ships with the package.
|
|
7
|
+
|
|
8
|
+
## 0.3.1 — 2026-11-30
|
|
9
|
+
|
|
10
|
+
- Renaming a session in Claude Code or Codex updates the name over its head right away (the server watches where the names live instead of waiting for the session's next event).
|
|
11
|
+
- The pop-out and small windows render at full pixel density: no more blur on Retina screens.
|
|
12
|
+
|
|
13
|
+
## 0.3.0 — 2026-11-30
|
|
14
|
+
|
|
15
|
+
**cozy-agents is now officepals.** Run `npx officepals`: it replaces cozy-agents' hooks (Claude Code and Codex) and copies your daily stats over by itself.
|
|
16
|
+
|
|
17
|
+
- **Codex** (CLI and app): its sessions join the office with their titles, plans on the whiteboard and a small "Codex" tag. `install`, `uninstall` and `status` cover `~/.codex/hooks.json`; Codex asks you to trust the hooks once.
|
|
18
|
+
- The installed relay is now `~/.officepals/hooks/relay.mjs`.
|
|
19
|
+
|
|
20
|
+
## 0.2.1 — 2026-11-30 (cozy-agents)
|
|
21
|
+
|
|
22
|
+
- A door: coworkers walk in when a session starts and out when it ends.
|
|
23
|
+
- Day and night, on the office's wall clock (a day in 24 minutes) or your computer's; nights stay light.
|
|
24
|
+
|
|
25
|
+
## 0.2.0 — 2026-11-30 (cozy-agents)
|
|
26
|
+
|
|
27
|
+
- **What each one is doing:** named after the conversation, the to-do list on a real whiteboard, stations by kind of work (tests at a bench with a signal tower, git at a mailbox, installs at a box pile, MCP tools by purpose), a turn clock, a card on click.
|
|
28
|
+
- **Waiting on you:** what for, and how risky it looks (judged in the hook relay; the command never leaves it). Today's totals kept across restarts.
|
|
29
|
+
- **A livelier office:** sitting at desks, room for ten (sofa, whiteboard), five places at every station, no walking through each other, labels that keep clear, idle coffee / sofa / stretches / chats, dozing.
|
|
30
|
+
- **Under the hood:** works offline (three.js in the package), draws less when calm, finds sessions that were already open and sees closed ones off in seconds.
|
|
31
|
+
|
|
32
|
+
## 0.1.2 — 2026-11-30 (cozy-agents)
|
|
33
|
+
|
|
34
|
+
- Coworkers are named after their conversation and show the to-do step in progress.
|
|
35
|
+
- A job of a minute or more ends with a cheer, a chime and a notification.
|
|
36
|
+
- Livelier pacing: thinking between tool calls, a teleport to your desk when they need you, quiet on routine errors.
|
|
37
|
+
|
|
38
|
+
## 0.1.1 — 2026-11-30 (cozy-agents)
|
|
39
|
+
|
|
40
|
+
- Alerts: a chime when an agent starts waiting on you, a notification when the page is out of sight, another on strike.
|
|
41
|
+
- Pop out: an always-on-top mini window (Chrome / Edge 116+).
|
|
42
|
+
|
|
43
|
+
## 0.1.0 — 2026-11-30 (cozy-agents)
|
|
44
|
+
|
|
45
|
+
- `npx cozy-agents`: a 3D office that fills with your Claude Code sessions, live from hooks. Coworkers walk to the bookshelf, desks and server rack, get impatient when they wait on you, and go on strike after three minutes. English and Chinese.
|
package/README.md
CHANGED
|
@@ -1,84 +1,119 @@
|
|
|
1
1
|
# officepals
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**See at a glance what every AI coding agent is doing — and which one is waiting on you.**
|
|
4
|
+
|
|
5
|
+
A cozy 3D office for your Claude Code and Codex sessions. Each session is a little coworker; keep them waiting too long and they go on strike.
|
|
4
6
|
|
|
5
7
|
[English](#english) · [中文](#中文)
|
|
6
8
|
|
|
7
9
|
> Formerly **cozy-agents**. Already had it? Just run `npx officepals`: it moves your hooks and stats over. 原名 cozy-agents;之前装过的话,直接运行 `npx officepals`,会自动把 hooks 和统计搬过来。
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
<!-- A short GIF of the office goes here. -->
|
|
10
12
|
|
|
11
13
|
---
|
|
12
14
|
|
|
13
15
|
## English
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
And when an agent needs **you** — a permission prompt, a question, a plan to approve — it walks over to your desk and waits. Leave it hanging and it gets impatient:
|
|
18
|
-
|
|
19
|
-
| Waiting | What you see |
|
|
20
|
-
| --- | --- |
|
|
21
|
-
| just asked | raises a hand, a patience bar appears |
|
|
22
|
-
| 20 s | waves harder, taps a foot, starts to sweat |
|
|
23
|
-
| 1 min | red in the face, jumping up and down, steaming |
|
|
24
|
-
| 3 min | lies down on the floor next to a **"strike!"** sign |
|
|
25
|
-
|
|
26
|
-
Approve it and it jumps up, cheers, and gets back to work.
|
|
17
|
+
### Why
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
Run three or four agents at once and you lose track: one is stuck on a permission prompt you never saw, one finished ten minutes ago, one is quietly running your tests. officepals puts them all in one small window you can keep in the corner of your screen:
|
|
29
20
|
|
|
30
|
-
|
|
21
|
+
- **Who needs you** — whoever is waiting walks to your desk, with what it wants and how risky it looks ("🔴 deletes files", "🟢 runs the tests"), and grows more impatient by the minute.
|
|
22
|
+
- **What each one is doing** — reading, editing, testing, committing, installing, browsing, each in its own spot, with its to-do list on the whiteboard and a clock on how long this turn has run.
|
|
23
|
+
- **When a long job is done** — a cheer, a chime, a notification.
|
|
31
24
|
|
|
32
|
-
|
|
33
|
-
- **⧉ Pop out.** Shrink the office into an always-on-top mini window (Chrome / Edge 116+) and keep it next to your editor. Other browsers get a small window you can park in a corner.
|
|
25
|
+
Everything stays on your machine.
|
|
34
26
|
|
|
35
|
-
###
|
|
27
|
+
### Quick start
|
|
36
28
|
|
|
37
|
-
|
|
29
|
+
Needs Node.js 18+ and [Claude Code](https://docs.anthropic.com/en/docs/claude-code) and/or Codex.
|
|
38
30
|
|
|
39
31
|
```bash
|
|
40
32
|
npx officepals
|
|
41
33
|
```
|
|
42
34
|
|
|
43
|
-
The first run asks to add officepals' hooks to `~/.claude/settings.json`
|
|
35
|
+
The first run asks to add officepals' hooks to `~/.claude/settings.json` — and to `~/.codex/hooks.json` if Codex is installed — then opens the office at `http://127.0.0.1:4747`. Your existing settings are kept and backed up. Start a session and your new coworker walks in through the door.
|
|
44
36
|
|
|
45
|
-
**Codex
|
|
37
|
+
**Codex:** Codex asks you to trust new hooks once. Run `/hooks` in the Codex CLI, or open Settings → Hooks in the Codex app, and trust the officepals entries.
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
| Command | |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| `npx officepals --demo` | scripted demo coworkers, nothing to install |
|
|
42
|
+
| `npx officepals status` | are the hooks installed? |
|
|
43
|
+
| `npx officepals uninstall` | remove the hooks (nothing else is touched) |
|
|
44
|
+
| `npx officepals --help` | all options |
|
|
45
|
+
|
|
46
|
+
### What you'll see
|
|
47
|
+
|
|
48
|
+
| Your agent… | In the office |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| reads files, greps, lists | browses the bookshelf |
|
|
51
|
+
| edits code | sits at its desk and types; the screen lights up |
|
|
52
|
+
| runs tests | goes to the test bench; the signal tower blinks, then turns green or red |
|
|
53
|
+
| uses git | posts a letter at the mailbox; the flag goes up |
|
|
54
|
+
| installs packages | carries a box from the pile |
|
|
55
|
+
| builds, runs commands | works at the server rack |
|
|
56
|
+
| browses, searches the web | at the globe |
|
|
57
|
+
| writes a plan | writes it up on the whiteboard; its notes move from *to do* to *done* |
|
|
58
|
+
| spawns a sub-agent | a little helper pops up beside it |
|
|
59
|
+
| needs your approval or answer | teleports to your desk: raises a hand, then sweats (20 s), steams (1 min), lies down on **strike** (3 min) |
|
|
60
|
+
| is between turns | coffee, the sofa, a stretch by the window, a chat; dozes off after 8 minutes |
|
|
61
|
+
| starts or ends a session | walks in or out through the door |
|
|
62
|
+
|
|
63
|
+
Click a coworker for its card: what it's doing, its to-do progress, this turn's time, how often it has waited on you, and the tools it used this turn.
|
|
64
|
+
|
|
65
|
+
### Made for the corner of your screen
|
|
66
|
+
|
|
67
|
+
- **⧉ Pop out** — an always-on-top mini window (Chrome / Edge 116+) to keep next to your editor.
|
|
68
|
+
- **🔔 Alerts** — a chime when someone starts waiting on you, a notification when the page is out of sight, another on strike, and a "done" chime when a job of a minute or more finishes.
|
|
69
|
+
- **Today's totals** — how long your agents were kept waiting today, kept across restarts.
|
|
70
|
+
- **Day and night** — on the office's wall clock (a day in 24 minutes) or your own; nights stay light.
|
|
71
|
+
- **English and 中文** — follows your browser; the button by the status badge switches it.
|
|
72
|
+
- **Light on your laptop** — it draws less when nothing moves and nothing at all when hidden; works offline.
|
|
73
|
+
|
|
74
|
+
### Privacy
|
|
50
75
|
|
|
51
|
-
|
|
76
|
+
Everything stays on your computer. The hook relay sends a server on `127.0.0.1` only what the office shows:
|
|
52
77
|
|
|
53
|
-
|
|
78
|
+
- session ids, folder names, tool names and short labels (a file's name, a host, the description Claude gives a command)
|
|
79
|
+
- for shell commands, their **kind** (test, build, install, git, look) — never the command itself
|
|
80
|
+
- for approvals, a **risk** judged inside the relay ("deletes files") — still never the command
|
|
81
|
+
- the question or plan title you're asked about, and each to-do step's title (clipped) and status
|
|
82
|
+
|
|
83
|
+
The server reads conversation titles locally (Claude Code's session log and list, Codex's session index) and keeps daily totals in `~/.officepals/stats.json` — numbers only. Prompts, code and tool output never leave your agents. The hooks run in the background and never slow them down.
|
|
84
|
+
|
|
85
|
+
### How it works
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
Claude Code / Codex ──hooks──▶ relay (node, async) ──HTTP──▶ local server ──SSE──▶ the office (three.js)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
No dependencies beyond Node: the relay and server are plain Node.js, the office is one page with three.js bundled in. Tested on macOS.
|
|
54
92
|
|
|
55
93
|
<details><summary>Run from source</summary>
|
|
56
94
|
|
|
57
95
|
```bash
|
|
58
96
|
git clone https://github.com/guluguludog0-commits/officepals.git
|
|
59
97
|
cd officepals
|
|
98
|
+
npm test
|
|
60
99
|
node bin/officepals.mjs
|
|
61
100
|
```
|
|
62
|
-
</details>
|
|
63
101
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
Everything stays on your machine. The hook relay forwards only session ids, tool names, a short label (a file's name, a host name, the description Claude gives a command), the kind of a shell command (test, build, install, git or look, never the command itself), for a permission request how risky it looks (judged inside the relay, e.g. "deletes files"), the question or plan title it asks you about, the session's to-do list (each step's title, clipped, and its status) and the path of the session's log to a server that listens on `127.0.0.1` only. The server reads just the conversation's title from that log, locally. It also checks Claude Code's list of running sessions (`~/.claude/sessions`: session ids, folders, names, busy or idle) so that sessions already open show up at once and closed ones leave within seconds. Daily totals (how often and how long agents waited on you, how many turns they finished) are kept in `~/.officepals/stats.json`, numbers only. Prompts, code, command lines and tool output never leave Claude Code. The hooks run in the background, so they never slow it down.
|
|
102
|
+
Add `?demo` for demo coworkers or `?time=21` to preview an hour of the day.
|
|
103
|
+
</details>
|
|
67
104
|
|
|
68
105
|
### Roadmap
|
|
69
106
|
|
|
70
|
-
- [x] 3D office
|
|
71
|
-
- [x]
|
|
72
|
-
- [x]
|
|
73
|
-
- [x]
|
|
74
|
-
- [x] What each one is working on: its title, to-do list on the whiteboard, stations by kind of work
|
|
75
|
-
- [x] Alerts, a pop-out window, a done chime for long jobs, risk hints on approvals
|
|
76
|
-
- [x] Today's totals, kept across restarts
|
|
77
|
-
- [ ] Daily stats page: how long did your agents wait on you this week?
|
|
78
|
-
- [x] A door to come and go by; day and night on the office clock (or yours)
|
|
107
|
+
- [x] Live 3D office from Claude Code hooks: moods, strike, approvals
|
|
108
|
+
- [x] What each one is doing: titles, stations by kind of work, to-do whiteboard, turn clock, cards
|
|
109
|
+
- [x] Alerts, pop-out, done chimes, risk hints, today's totals
|
|
110
|
+
- [x] Room for ten, a door, idle life, day and night
|
|
79
111
|
- [x] Codex (CLI and app)
|
|
112
|
+
- [ ] Daily stats page: how long did your agents wait on you this week?
|
|
80
113
|
- [ ] More agents: Gemini CLI, …
|
|
81
114
|
|
|
115
|
+
See [CHANGELOG.md](CHANGELOG.md) for what changed in each release.
|
|
116
|
+
|
|
82
117
|
### Credits
|
|
83
118
|
|
|
84
119
|
- Inspired by [Pixel Agents](https://github.com/pixel-agents-hq/pixel-agents), which first turned coding agents into office characters.
|
|
@@ -88,35 +123,83 @@ Everything stays on your machine. The hook relay forwards only session ids, tool
|
|
|
88
123
|
|
|
89
124
|
## 中文
|
|
90
125
|
|
|
91
|
-
|
|
126
|
+
### 为什么用它
|
|
127
|
+
|
|
128
|
+
同时开三四个 Agent 时,很容易顾不过来:一个卡在你没看到的权限确认上,一个十分钟前就干完了,一个正在默默跑测试。officepals 把它们都放进一个小窗口,你可以把它放在屏幕角落:
|
|
129
|
+
|
|
130
|
+
- **谁在等你**:等你批准或回答的同事会走到你的工位旁,写着它要干什么、风险高不高("🔴 会删除文件""🟢 运行项目代码"),等得越久越着急。
|
|
131
|
+
- **每个人在干什么**:读文件、改代码、跑测试、提交 git、装依赖、查资料,各有各的地方;白板上贴着它的待办清单,头顶显示这一轮干了多久。
|
|
132
|
+
- **长任务什么时候干完**:小人欢呼,响提示音,弹通知。
|
|
133
|
+
|
|
134
|
+
所有数据只留在你的电脑上。
|
|
135
|
+
|
|
136
|
+
### 快速开始
|
|
137
|
+
|
|
138
|
+
需要 Node.js 18+,以及 [Claude Code](https://docs.anthropic.com/en/docs/claude-code) 或 Codex(两个都有更好)。
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
npx officepals
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
第一次运行会询问是否把 hooks 加到 `~/.claude/settings.json`(装了 Codex 的话,也加到 `~/.codex/hooks.json`),然后打开 `http://127.0.0.1:4747`。你原有的配置会保留并备份。开一个会话,你的新同事就会从门口走进来。
|
|
92
145
|
|
|
93
|
-
|
|
146
|
+
**Codex:** Codex 要求新 hooks 先经你信任一次。在 Codex 命令行里输入 `/hooks`,或在 Codex 应用的"设置 → Hooks"里,把 officepals 的几条信任上。
|
|
147
|
+
|
|
148
|
+
| 命令 | |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `npx officepals --demo` | 演示模式,不用装任何东西 |
|
|
151
|
+
| `npx officepals status` | 查看 hooks 装好了没有 |
|
|
152
|
+
| `npx officepals uninstall` | 卸载 hooks(其他配置不动) |
|
|
153
|
+
| `npx officepals --help` | 全部选项 |
|
|
94
154
|
|
|
95
|
-
|
|
155
|
+
### 你会看到什么
|
|
96
156
|
|
|
97
|
-
|
|
|
157
|
+
| Agent 在… | 办公室里 |
|
|
98
158
|
| --- | --- |
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
|
159
|
+
| 读文件、搜索、看目录 | 在书架前翻书 |
|
|
160
|
+
| 改代码 | 坐在工位上打字,屏幕亮起来 |
|
|
161
|
+
| 跑测试 | 去测试台,信号灯闪黄灯,通过变绿、失败变红 |
|
|
162
|
+
| 用 git | 去邮筒投信,小旗子竖起来 |
|
|
163
|
+
| 装依赖 | 从纸箱堆里抱起一个箱子 |
|
|
164
|
+
| 构建、执行命令 | 在服务器机柜前操作 |
|
|
165
|
+
| 上网查资料 | 在地球仪旁边 |
|
|
166
|
+
| 写计划 | 走到白板前写上,便利贴从"待办"挪到"已完成" |
|
|
167
|
+
| 派出子 Agent | 身边冒出一个小助手 |
|
|
168
|
+
| 需要你批准或回答 | 瞬移到你的工位旁:举手,20 秒冒汗,1 分钟冒蒸汽,3 分钟躺下**罢工** |
|
|
169
|
+
| 一轮结束、等你的下一个指令 | 喝咖啡、坐沙发、在窗边伸懒腰、和同事闲聊;超过 8 分钟回工位打盹 |
|
|
170
|
+
| 会话开始或结束 | 从门口走进来或走出去 |
|
|
103
171
|
|
|
104
|
-
|
|
172
|
+
点一下小人,会弹出它的卡片:在干什么、待办进度、这一轮用时、等过你几次、这一轮用过哪些工具。
|
|
105
173
|
|
|
106
|
-
|
|
174
|
+
### 适合放在屏幕角落
|
|
107
175
|
|
|
108
|
-
|
|
176
|
+
- **⧉ 悬浮小窗**:置顶的小窗(Chrome / Edge 116+),放在编辑器旁边。
|
|
177
|
+
- **🔔 提醒**:有人开始等你时响提示音,页面不在眼前时弹通知,罢工时再提醒一次;干了一分钟以上的活完成时响"完成"提示音。
|
|
178
|
+
- **今日统计**:今天 Agent 一共干等了你多久,重启也不清零。
|
|
179
|
+
- **昼夜变化**:跟着办公室墙上的钟(24 分钟一整天)或你电脑的时间;夜里也不压抑。
|
|
180
|
+
- **中英文界面**:默认跟随浏览器,左上角按钮可以切换。
|
|
181
|
+
- **不费电**:画面不动时降低帧率,看不见时完全不画;断网也能用。
|
|
109
182
|
|
|
110
|
-
|
|
111
|
-
- **⧉ 悬浮小窗**:一键把办公室缩成置顶小窗(Chrome / Edge 116+),放在编辑器旁边。其他浏览器会打开一个可以拖到屏幕角落的小窗口。
|
|
183
|
+
### 隐私
|
|
112
184
|
|
|
113
|
-
|
|
185
|
+
所有数据只在你的电脑上。hook 中转脚本只把办公室要显示的东西发给本机(`127.0.0.1`)上的服务器:
|
|
114
186
|
|
|
115
|
-
|
|
187
|
+
- 会话 id、文件夹名、工具名和简短标签(文件名、网站域名、Claude 给命令写的说明)
|
|
188
|
+
- 终端命令只发**类型**(测试、构建、装依赖、git、查看),从不发命令本身
|
|
189
|
+
- 需要你批准时,附上中转脚本在本地判断出的**风险**(如"会删除文件"),同样不发命令本身
|
|
190
|
+
- 向你提的问题、计划标题,以及每一步待办的标题(截短)和状态
|
|
191
|
+
|
|
192
|
+
会话标题由服务器在本地读取(Claude Code 的会话记录和会话列表、Codex 的会话索引)。每天的统计只记数字,存在 `~/.officepals/stats.json`。提示词、代码和工具输出从不离开你的 Agent。hooks 在后台运行,不会拖慢它们。
|
|
193
|
+
|
|
194
|
+
### 工作原理
|
|
195
|
+
|
|
196
|
+
```
|
|
197
|
+
Claude Code / Codex ──hooks──▶ 中转脚本(node,后台运行)──HTTP──▶ 本地服务器 ──SSE──▶ 办公室页面(three.js)
|
|
198
|
+
```
|
|
116
199
|
|
|
117
|
-
|
|
200
|
+
除了 Node.js 不依赖任何东西:中转脚本和服务器是纯 Node.js,办公室是一个网页,three.js 已打包在内。目前在 macOS 上测试。
|
|
118
201
|
|
|
119
|
-
|
|
202
|
+
各版本的改动见 [CHANGELOG.md](CHANGELOG.md)。
|
|
120
203
|
|
|
121
204
|
## License
|
|
122
205
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "officepals",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"description": "See at a glance what every AI coding agent is doing — a cozy 3D office for Claude Code and Codex sessions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"officepals": "bin/officepals.mjs"
|
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"src/",
|
|
12
12
|
"web/",
|
|
13
13
|
"LICENSE",
|
|
14
|
-
"README.md"
|
|
14
|
+
"README.md",
|
|
15
|
+
"CHANGELOG.md"
|
|
15
16
|
],
|
|
16
17
|
"scripts": {
|
|
17
18
|
"start": "node bin/officepals.mjs",
|
|
@@ -22,7 +23,9 @@
|
|
|
22
23
|
},
|
|
23
24
|
"keywords": [
|
|
24
25
|
"claude-code",
|
|
26
|
+
"codex",
|
|
25
27
|
"ai-agents",
|
|
28
|
+
"coding-agents",
|
|
26
29
|
"three.js",
|
|
27
30
|
"visualization",
|
|
28
31
|
"hooks",
|
package/src/server.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import * as fs from 'node:fs';
|
|
|
11
11
|
import * as http from 'node:http';
|
|
12
12
|
import * as path from 'node:path';
|
|
13
13
|
|
|
14
|
-
import { serverFile, statsFile } from './paths.mjs';
|
|
14
|
+
import { codexIndexPath, serverFile, statsFile } from './paths.mjs';
|
|
15
15
|
import { runningSessions, registryDir } from './sessions.mjs';
|
|
16
16
|
import { adopt, apply, createState, prune, setTitle } from './state.mjs';
|
|
17
17
|
import { createStats, dayKey, loadStats, record, saveStats, today } from './stats.mjs';
|
|
@@ -29,6 +29,8 @@ const RUNNING_EVERY_MS = 4_000;
|
|
|
29
29
|
const MISSES_TO_LEAVE = 2;
|
|
30
30
|
/** A session that just said goodbye isn't let back in while its process exits. */
|
|
31
31
|
const ENDED_GRACE_MS = 60_000;
|
|
32
|
+
/** A rename lands in a file; react this soon after it changes (debounced). */
|
|
33
|
+
const WATCH_DEBOUNCE_MS = 120;
|
|
32
34
|
/** Stats are written this long after the last change (and on close). */
|
|
33
35
|
const SAVE_STATS_AFTER_MS = 2_000;
|
|
34
36
|
const TYPES = {
|
|
@@ -45,7 +47,7 @@ function loopbackHost(hostHeader, port) {
|
|
|
45
47
|
return allowed.includes(String(hostHeader).toLowerCase());
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
export async function startServer({ port, webDir, log = () => {}, writeServerFile = true, sessionsDir = registryDir(), stats: statsPath = statsFile() }) {
|
|
50
|
+
export async function startServer({ port, webDir, log = () => {}, writeServerFile = true, sessionsDir = registryDir(), stats: statsPath = statsFile(), codexIndex = codexIndexPath() }) {
|
|
49
51
|
const token = crypto.randomBytes(24).toString('hex');
|
|
50
52
|
const state = createState();
|
|
51
53
|
// Daily stats: loaded from disk, saved shortly after each change.
|
|
@@ -66,6 +68,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
66
68
|
const clients = new Set();
|
|
67
69
|
const titleReadAt = new Map(); // session id -> last read
|
|
68
70
|
const misses = new Map(); // tracked session id -> checks it was missing from
|
|
71
|
+
const registryName = new Map(); // session id -> the name Claude Code lists it under
|
|
69
72
|
const endedAt = new Map(); // session id -> when SessionEnd arrived
|
|
70
73
|
|
|
71
74
|
/** Let in sessions that are running but not here yet; see off those whose
|
|
@@ -85,6 +88,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
85
88
|
changed = true;
|
|
86
89
|
log(`found running session · ${r.project ?? r.id.slice(0, 8)}`);
|
|
87
90
|
}
|
|
91
|
+
// Renamed in Claude Code: the list has the new name at once.
|
|
92
|
+
if (r.name && registryName.get(r.id) !== r.name) {
|
|
93
|
+
registryName.set(r.id, r.name);
|
|
94
|
+
if (setTitle(state, r.id, r.name) && !changed) announceTitle(r.id);
|
|
95
|
+
}
|
|
88
96
|
}
|
|
89
97
|
for (const [id, s] of Object.entries(state.sessions)) {
|
|
90
98
|
if (!s.tracked || ids.has(id)) continue;
|
|
@@ -95,6 +103,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
95
103
|
}
|
|
96
104
|
misses.delete(id);
|
|
97
105
|
titleReadAt.delete(id);
|
|
106
|
+
registryName.delete(id);
|
|
98
107
|
delete state.sessions[id];
|
|
99
108
|
changed = true;
|
|
100
109
|
log(`session gone · ${s.project ?? id.slice(0, 8)}`);
|
|
@@ -107,6 +116,7 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
107
116
|
const s = state.sessions[ev.session];
|
|
108
117
|
const codex = ev.provider === 'codex';
|
|
109
118
|
if (!s || (!codex && !ev.transcript)) return;
|
|
119
|
+
if (registryName.has(ev.session)) return; // Claude Code's own list has the current name
|
|
110
120
|
const last = titleReadAt.get(ev.session) ?? 0;
|
|
111
121
|
if (s.title && !TITLE_EVENTS.has(ev.event) && Date.now() - last < TITLE_EVERY_MS) return;
|
|
112
122
|
titleReadAt.set(ev.session, Date.now());
|
|
@@ -116,6 +126,34 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
|
|
129
|
+
const announceTitle = (id) =>
|
|
130
|
+
broadcast({ type: 'update', ts: Date.now(), event: { session: id, event: 'TitleChanged' }, session: state.sessions[id] });
|
|
131
|
+
|
|
132
|
+
/** Codex's session index changed (a rename, a new title): re-read its sessions' titles. */
|
|
133
|
+
async function refreshCodexTitles() {
|
|
134
|
+
for (const [id, s] of Object.entries(state.sessions)) {
|
|
135
|
+
if (s.provider !== 'codex') continue;
|
|
136
|
+
const title = await readCodexTitle(id, codexIndex);
|
|
137
|
+
if (title && setTitle(state, id, title)) announceTitle(id);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Watch a folder for changes (to one file, if named), debounced; null if it can't be watched. */
|
|
142
|
+
function watch(dir, file, onChange) {
|
|
143
|
+
let timer = null;
|
|
144
|
+
try {
|
|
145
|
+
const w = fs.watch(dir, (_, name) => {
|
|
146
|
+
if (file && name && name !== file) return;
|
|
147
|
+
clearTimeout(timer);
|
|
148
|
+
timer = setTimeout(onChange, WATCH_DEBOUNCE_MS);
|
|
149
|
+
});
|
|
150
|
+
w.on('error', () => w.close());
|
|
151
|
+
return { close: () => { clearTimeout(timer); w.close(); } };
|
|
152
|
+
} catch {
|
|
153
|
+
return null; // missing folder: the timers still catch changes, just later
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
119
157
|
const send = (res, msg) => res.write(`data: ${JSON.stringify(msg)}\n\n`);
|
|
120
158
|
const broadcast = (msg) => clients.forEach((res) => send(res, msg));
|
|
121
159
|
const snapshot = () => ({ type: 'snapshot', now: Date.now(), sessions: state.sessions, stats: today(stats, Date.now()) });
|
|
@@ -205,6 +243,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
205
243
|
}
|
|
206
244
|
|
|
207
245
|
syncRunning();
|
|
246
|
+
// Renames show up at once: watch the files the names live in.
|
|
247
|
+
const watchers = [
|
|
248
|
+
sessionsDir && watch(sessionsDir, null, syncRunning),
|
|
249
|
+
codexIndex && watch(path.dirname(codexIndex), path.basename(codexIndex), refreshCodexTitles),
|
|
250
|
+
].filter(Boolean);
|
|
208
251
|
const timers = [
|
|
209
252
|
setInterval(syncRunning, RUNNING_EVERY_MS),
|
|
210
253
|
setInterval(() => {
|
|
@@ -225,9 +268,11 @@ export async function startServer({ port, webDir, log = () => {}, writeServerFil
|
|
|
225
268
|
token,
|
|
226
269
|
state,
|
|
227
270
|
syncRunning, // checks now (tests; it also runs on a timer)
|
|
271
|
+
refreshCodexTitles,
|
|
228
272
|
stats,
|
|
229
273
|
close() {
|
|
230
274
|
timers.forEach(clearInterval);
|
|
275
|
+
watchers.forEach((w) => w.close());
|
|
231
276
|
if (saveTimer) saveNow();
|
|
232
277
|
clients.forEach((res) => res.end());
|
|
233
278
|
if (writeServerFile) {
|
package/web/index.html
CHANGED
|
@@ -2246,17 +2246,16 @@ pipBtn.addEventListener('click', popOut);
|
|
|
2246
2246
|
document.getElementById('pip-back').addEventListener('click', () => pipWindow?.close());
|
|
2247
2247
|
renderPipButton();
|
|
2248
2248
|
|
|
2249
|
-
// ── Power:
|
|
2250
|
-
//
|
|
2251
|
-
//
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2249
|
+
// ── Power: the loop draws only as often as needed ──────────────
|
|
2250
|
+
// Sharpness: every window, the pop-out included, renders at the screen's own
|
|
2251
|
+
// pixel density (up to 2×). A small window is few pixels even at 2×, so
|
|
2252
|
+
// dropping the density there saved little and made it blurry on Retina.
|
|
2253
|
+
const SHADOW_SIZE = 2048;
|
|
2254
|
+
function applyQuality() {
|
|
2255
2255
|
const dpr = (pipWindow ?? window).devicePixelRatio || 1;
|
|
2256
|
-
renderer.setPixelRatio(Math.min(dpr,
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
sun.shadow.mapSize.set(size, size);
|
|
2256
|
+
renderer.setPixelRatio(Math.min(dpr, 2));
|
|
2257
|
+
if (sun.shadow.mapSize.x !== SHADOW_SIZE) {
|
|
2258
|
+
sun.shadow.mapSize.set(SHADOW_SIZE, SHADOW_SIZE);
|
|
2260
2259
|
sun.shadow.map?.dispose();
|
|
2261
2260
|
sun.shadow.map = null; // rebuilt at the new size on the next draw
|
|
2262
2261
|
}
|