@raingor/pi-web-switch 0.4.1 → 0.4.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/README.ja.md CHANGED
@@ -88,17 +88,32 @@ npm run build # プロダクションビルド
88
88
 
89
89
  ## 🖥️ デスクトップアプリ(Electron)
90
90
 
91
- pi-web-switch はデスクトップアプリ(macOS / Windows / Linux)としても利用でき、専用ブランドアイコンを備えています。
91
+ pi-web-switch は **macOS メニューバーアプリ**(および Windows/Linux トレイアプリ)としても利用可能 — アプリはメニューバーに常駐し、トレイアイコンのクリックで使用量サマリー(今日の tokens / コスト / リクエスト数 + 7 日間の sparkline + Top プロバイダ)がポップアップします。フルダッシュボードはトレイメニュー or ダブルクリックで開けます。
92
92
 
93
93
  ```bash
94
- # 開発モードで実行(Vite 開発サーバー + Electron、HMR 対応)
94
+ # 開発モードで実行(Vite 開発サーバー + Electron、HMR 寂応)
95
95
  npm run electron:dev
96
96
 
97
- # インストーラー(DMG / NSIS / AppImage)を release/ にビルド
97
+ # インストーラー(macOS DMG+ZIP / Windows NSIS / Linux AppImage)を release/ にビルド
98
98
  npm run electron:build
99
+
100
+ # パッケージ化せずプロダクションビルドをプレビュー
101
+ npm run electron:preview
99
102
  ```
100
103
 
101
- アプリアイコンは `build/`(`icon.icns` / `icon.ico` / `icon.png`)にあり、プラットフォームごとに electron-builder へ組み込まれています。開発モードでは実行時に macOS の Dock アイコンを設定します。
104
+ ### 🍹 macOS メニューバーモード
105
+
106
+ パッケージ化された macOS アプリは **メニューバー専用アプリ** として実行 — Dock に表示されず、`Cmd+Q` でトレイメニューから終了。`electron-builder` の `extendInfo` で `LSUIElement = true` を設定して実装。開発モード(`electron:dev`)では Dock アイコンが表示されます(この Info.plist キーはパッケージビルドにのみ適用)。トレイアイコンは両モードで動作します。
107
+
108
+ | トレイ操作 | 動作 |
109
+ |------------|------|
110
+ | クリック | 使用量ポップアップの切替(今日 + 7 日 tokens / コスト / リクエスト数、sparkline、Top プロバイダ) |
111
+ | 右クリック | コンテキストメニュー:Dashboard を開く、使用量を更新、終了 |
112
+ | メニュー → "開く Dashboard" | フル React Dashboard ウィンドウを開く |
113
+
114
+ ポップアップは表示中 30 秒ごとに自動更新。トレイアイコンは 32×32 template PNG(`build/trayIconTemplate.png`)で明暗メニューバーに自動適合;`npm run tray:icon` で再生成。
115
+
116
+ アプリアイコンは `build/`(`icon.icns` / `icon.ico` / `icon.png`)にあり;開発モードでは実行時に `public/icon-512.png` から macOS の Dock アイコンを設定します。
102
117
 
103
118
  ## 🏗️ 技術スタック
104
119
 
@@ -124,9 +139,12 @@ pi-web-switch は **pi コーディングエージェント拡張** としてイ
124
139
 
125
140
  | コマンド | 説明 |
126
141
  |---------|------|
127
- | `/pi-web-switch start` | ダッシュボード起動 http://localhost:5173 |
128
- | `/pi-web-switch stop` | サーバー停止 |
129
- | `/pi-web-switch status` | 実行状態を確認 |
142
+ | `/pi-switch start` | ダッシュボード起動 http://localhost:5173 |
143
+ | `/pi-switch stop` | サーバー停止 |
144
+ | `/pi-switch status` | 実行状態を確認 |
145
+ | `/pi-usage` | 使用量サマリー(今日 + 7 日)を端末に印字 — tokens / コスト / リクエスト数 / デイリー sparkline、ダッシュボード起動不要 |
146
+
147
+ `/pi-usage` コマンドは `~/.pi/agent/sessions/*.jsonl` を直接読み込み、今日 + 直近 7 日の統計を集約します。どの pi セッションからでも一目で使用量を確認可能。macOS メニューバーポップアップと同じ内容を表示します。
130
148
 
131
149
  ### パッケージ構造
132
150
 
@@ -134,12 +152,18 @@ pi-web-switch は **pi コーディングエージェント拡張** としてイ
134
152
  pi-web-switch/
135
153
  ├── package.json # npm パッケージ + pi.extensions + pi.skills
136
154
  ├── pi-package/
137
- │ ├── index.ts # 拡張エントリ:/pi-web-switch コマンド登録
155
+ │ ├── index.ts # 拡張エントリ:/pi-switch、/pi-usage コマンド登録
138
156
  │ └── skills/
139
157
  │ └── pi-web-switch/
140
158
  │ └── SKILL.md # 使用ドキュメント
141
159
  ├── server/
142
160
  │ └── pi-reader.ts # サーバーサイド:~/.pi/agent/ 読み取り
161
+ ├── electron/ # デスクトップアプリ(macOS メニューバー / トレイ)
162
+ │ ├── main.ts # メインプロセス:トレイ、ポップアップ、IPC、ローカル API サーバー
163
+ │ ├── api-server.ts # ローカル HTTP サーバー(パッケージ版で dist/ + /api/pi/* を提供)
164
+ │ ├── preload.ts # contextBridge:settings/auth/models/usage IPC
165
+ │ ├── popup.html # メニューバー使用量ポップアップ
166
+ │ └── popup-render.ts # ポップアップ描画(今日/7 日 tokens、sparkline、Top プロバイダ)
143
167
  └── src/ # React フロントエンド
144
168
  ```
145
169
 
package/README.md CHANGED
@@ -139,17 +139,32 @@ The dev server automatically serves pi configuration via Vite middleware at `/ap
139
139
 
140
140
  ## 🖥️ Desktop App (Electron)
141
141
 
142
- pi-web-switch also runs as a desktop app (macOS / Windows / Linux) with its own branded app icon.
142
+ pi-web-switch also runs as a **macOS menu bar app** (and a Windows/Linux tray app) — the app lives in your menu bar, and a single click on the tray icon pops up a compact usage summary (today's tokens / cost / requests + a 7-day sparkline + top providers). The full Dashboard is still available from the tray menu or by double-clicking the tray icon.
143
143
 
144
144
  ```bash
145
145
  # Run in development (Vite dev server + Electron with HMR)
146
146
  npm run electron:dev
147
147
 
148
- # Build installers (DMG / NSIS / AppImage) into release/
148
+ # Build installers (DMG + ZIP for macOS, NSIS for Windows, AppImage for Linux) into release/
149
149
  npm run electron:build
150
+
151
+ # Preview the production build without packaging
152
+ npm run electron:preview
150
153
  ```
151
154
 
152
- App icons live in `build/` (`icon.icns` / `icon.ico` / `icon.png`) and are wired into electron-builder per platform; in development the macOS dock icon is set at runtime.
155
+ ### 🍹 macOS menu bar mode
156
+
157
+ The packaged macOS app runs as a **menu bar-only** app — it does not appear in the Dock, and `Cmd+Q` quits from the tray menu. This is wired in via `LSUIElement = true` in `electron-builder`'s `extendInfo`. In dev (`electron:dev`) the Dock icon still shows because that Info.plist key only applies to packaged builds; the tray icon works in both modes.
158
+
159
+ | Tray interaction | What happens |
160
+ |------------------|--------------|
161
+ | Click | Toggle the usage popup (today + 7d tokens / cost / requests, sparkline, top providers) |
162
+ | Right-click | Context menu: open Dashboard, refresh usage, quit |
163
+ | Menu → "打开 Dashboard" | Open the full React Dashboard window |
164
+
165
+ The popup auto-refreshes every 30 seconds while visible. The tray icon is a 16×16 template PNG (`build/trayIconTemplate.png`) that adapts to light/dark menu bars; regenerate it with `npm run tray:icon`.
166
+
167
+ App icons live in `build/` (`icon.icns` / `icon.ico` / `icon.png`); in development the macOS dock icon is set at runtime from `public/icon-512.png`.
153
168
 
154
169
  ## 🏗️ Tech Stack
155
170
 
@@ -170,10 +185,21 @@ App icons live in `build/` (`icon.icns` / `icon.ico` / `icon.png`) and are wired
170
185
  pi-web-switch/
171
186
  ├── index.html
172
187
  ├── package.json
173
- ├── vite.config.ts # Vite config + pi API plugin (middleware)
188
+ ├── vite.config.ts # Vite config + pi API plugin (middleware) + popup entry
174
189
  ├── tsconfig.json
175
190
  ├── server/
176
191
  │ └── pi-reader.ts # Server-side module: reads ~/.pi/agent/ files + parses sessions
192
+ ├── electron/ # Desktop app (macOS menu-bar / tray)
193
+ │ ├── main.ts # Main process: tray, popup window, IPC, local API server
194
+ │ ├── api-server.ts # Local HTTP server serving dist/ + /api/pi/* in packaged mode
195
+ │ ├── preload.ts # contextBridge: settings/auth/models/usage IPC
196
+ │ ├── popup.html # Menu-bar popup UI
197
+ │ └── popup-render.ts # Popup renderer (today/7d tokens, sparkline, top providers)
198
+ ├── scripts/
199
+ │ └── generate-tray-icon.mjs # Regenerates build/trayIconTemplate.png
200
+ ├── build/
201
+ │ ├── trayIconTemplate.png # 32x32 menu-bar template icon
202
+ │ └── icon.icns / icon.ico / icon.png
177
203
  ├── public/
178
204
  │ └── pi.svg
179
205
  └── src/
@@ -224,7 +250,7 @@ Changes made in the UI are written back to these files in real time — the pi a
224
250
 
225
251
  ## 🧩 API Routes
226
252
 
227
- The Vite dev server exposes these endpoints at `/api/pi/*`:
253
+ These endpoints at `/api/pi/*` are served by the Vite middleware in dev, and by the built-in HTTP server (`electron/api-server.ts`) in the packaged app — so the frontend works identically in both modes:
228
254
 
229
255
  | Method | Path | Description |
230
256
  |--------|------|-------------|
@@ -236,10 +262,29 @@ The Vite dev server exposes these endpoints at `/api/pi/*`:
236
262
  | POST | `/api/pi/models` | Write `models.json` |
237
263
  | GET | `/api/pi/builtin-providers` | List hardcoded built-in providers |
238
264
  | GET | `/api/pi/usage` | Aggregated token/cost/request data from sessions |
239
- | GET | `/api/pi/usage-range` | Date-range filtered usage with hourly/daily breakdown |
265
+ | GET | `/api/pi/usage-range` | Date-range filtered usage (pi sessions) `?range=today\|7d\|30d\|custom&from=&to=` |
266
+ | GET | `/api/pi/all-usage-range` | Same shape, but combined across **all** sources (pi + cindy + claude + codex + atomcode + copilot) |
267
+ | GET | `/api/pi/{cindy-pi\|claude\|codex\|opencode\|gemini\|grok\|atomcode\|copilot}-usage-range` | Per-source usage range |
268
+ | GET | `/api/pi/copilot-usage-range` | Local Copilot CLI usage from `~/.copilot/session-store.db` (tokens / requests per day per model; no GitHub API or token required) |
269
+ | GET | `/api/pi/copilot-config` | Read Copilot GitHub config (username, token) |
270
+ | POST | `/api/pi/copilot-config` | Write Copilot GitHub config |
240
271
  | GET | `/api/pi/sessions` | Session list grouped by project |
241
- | DELETE | `/api/pi/session?path=` | Delete a session file (path must be under sessions/) |
272
+ | DELETE | `/api/pi/session?path=` | Move a session file to trash (path must be under sessions/) |
273
+ | POST | `/api/pi/session/trash` | Move a session to trash (body: `{ path }`) |
274
+ | POST | `/api/pi/session/restore` | Restore a session from trash (body: `{ trashPath }`) |
275
+ | GET | `/api/pi/session-preview` | Preview session messages — `?path=` |
276
+ | GET | `/api/pi/trash` | List trashed sessions |
277
+ | DELETE | `/api/pi/trash?path=` | Permanently delete a trashed session |
242
278
  | GET | `/api/pi/memory` | Read MEMORY.md, USER.md, failures.md |
279
+ | POST | `/api/pi/memory/delete-entry` | Delete a memory entry (body: `{ filename, text }`) |
280
+ | GET | `/api/pi/subagents` | Read subagent run history |
281
+ | GET | `/api/pi/check-updates` | Check pi package updates |
282
+ | POST | `/api/pi/apply-updates` | Apply package updates (body: `{ names }`) |
283
+ | POST | `/api/pi/provider-test` | Test a provider connection (body: `{ baseUrl, apiKey }`) |
284
+ | POST | `/api/pi/provider-models` | Fetch a provider's live model list (body: `{ baseUrl, apiKey, providerId }`) |
285
+ | POST | `/api/pi/model-test` | Test a model (body: `{ baseUrl, modelId, apiKey, apiType }`) |
286
+
287
+ All `-usage-range` endpoints accept `&refresh=1` to force a rescan, bypassing the 30-second session cache (the Dashboard refresh button sends this).
243
288
 
244
289
  ## 📦 Pi Package
245
290
 
@@ -263,9 +308,12 @@ Once installed, the following commands are available in your pi session:
263
308
 
264
309
  | Command | Description |
265
310
  |---------|-------------|
266
- | `/pi-web-switch start` | Launch the dashboard at `http://localhost:5173` |
267
- | `/pi-web-switch stop` | Stop the server |
268
- | `/pi-web-switch status` | Check if the dashboard is running |
311
+ | `/pi-switch start` | Launch the dashboard at `http://localhost:5173` |
312
+ | `/pi-switch stop` | Stop the server |
313
+ | `/pi-switch status` | Check if the dashboard is running |
314
+ | `/pi-usage` | Print a quick usage summary (today + 7 days) in the terminal — tokens / cost / requests / daily sparkline, without launching the dashboard |
315
+
316
+ The `/pi-usage` command reads `~/.pi/agent/sessions/*.jsonl` directly and aggregates today + last-7-days stats, so you can see your usage at a glance from any pi session. It mirrors what the macOS menu bar popup shows.
269
317
 
270
318
  ### Package Structure
271
319
 
package/README.zh-CN.md CHANGED
@@ -126,17 +126,32 @@ npm run preview # 预览生产构建
126
126
 
127
127
  ## 🖥️ 桌面应用(Electron)
128
128
 
129
- pi-web-switch 同样提供桌面应用(macOS / Windows / Linux),并带有专属品牌图标。
129
+ pi-web-switch 同样提供 **macOS 菜单栏应用**(以及 Windows/Linux 托盘应用)—— 应用驻留在顶部菜单栏,点击托盘图标即可弹出使用量摘要(今日 tokens / 成本 / 请求数 + 7 天 sparkline + Top 提供商)。完整仪表盘仍可从托盘菜单或双击图标打开。
130
130
 
131
131
  ```bash
132
132
  # 开发模式运行(Vite 开发服务器 + Electron,支持 HMR)
133
133
  npm run electron:dev
134
134
 
135
- # 构建安装包(DMG / NSIS / AppImage)到 release/
135
+ # 构建安装包(macOS DMG+ZIP / Windows NSIS / Linux AppImage)到 release/
136
136
  npm run electron:build
137
+
138
+ # 不打包预览生产构建
139
+ npm run electron:preview
137
140
  ```
138
141
 
139
- 应用图标位于 `build/`(`icon.icns` / `icon.ico` / `icon.png`),已按平台接入 electron-builder;开发模式下会在运行时设置 macOS 程序坞图标。
142
+ ### 🍹 macOS 菜单栏模式
143
+
144
+ 打包后的 macOS 应用以 **纯菜单栏应用** 运行 —— 不出现在 Dock 中,`Cmd+Q` 从托盘菜单退出。通过 `electron-builder` 的 `extendInfo` 中 `LSUIElement = true` 实现。开发模式下(`electron:dev`)Dock 图标仍会显示(该 Info.plist 键仅对打包构建生效),托盘图标两种模式都可用。
145
+
146
+ | 托盘交互 | 行为 |
147
+ |----------|------|
148
+ | 点击 | 切换使用量弹窗(今日 + 7 天 tokens / 成本 / 请求数、sparkline、Top 提供商) |
149
+ | 右键 | 上下文菜单:打开 Dashboard、刷新使用量、退出 |
150
+ | 菜单 → "打开 Dashboard" | 打开完整 React Dashboard 窗口 |
151
+
152
+ 弹窗可见时每 30 秒自动刷新。托盘图标是 32×32 template PNG(`build/trayIconTemplate.png`),自动适配明暗菜单栏;用 `npm run tray:icon` 重新生成。
153
+
154
+ 应用图标位于 `build/`(`icon.icns` / `icon.ico` / `icon.png`);开发模式下会在运行时从 `public/icon-512.png` 设置 macOS 程序坞图标。
140
155
 
141
156
  ## 🏗️ 技术栈
142
157
 
@@ -162,9 +177,12 @@ pi-web-switch 可安装为 **pi 编码代理扩展**,在 pi 会话中直接启
162
177
 
163
178
  | 命令 | 说明 |
164
179
  |------|------|
165
- | `/pi-web-switch start` | 启动仪表盘 http://localhost:5173 |
166
- | `/pi-web-switch stop` | 停止服务器 |
167
- | `/pi-web-switch status` | 查看运行状态 |
180
+ | `/pi-switch start` | 启动仪表盘 http://localhost:5173 |
181
+ | `/pi-switch stop` | 娶止服务器 |
182
+ | `/pi-switch status` | 查看运行状态 |
183
+ | `/pi-usage` | 在终端打印使用量摘要(今日 + 7 天)—— tokens / 成本 / 请求数 / 每日 sparkline,无需启动仪表盘 |
184
+
185
+ `/pi-usage` 命令直接读取 `~/.pi/agent/sessions/*.jsonl` 并聚合今日 + 最近 7 天统计,让你在任何 pi 会话中一眼看到使用量。它与 macOS 菜单栏弹窗显示的内容一致。
168
186
 
169
187
  ### 包结构
170
188
 
@@ -172,12 +190,18 @@ pi-web-switch 可安装为 **pi 编码代理扩展**,在 pi 会话中直接启
172
190
  pi-web-switch/
173
191
  ├── package.json # npm 包 + pi.extensions + pi.skills
174
192
  ├── pi-package/
175
- │ ├── index.ts # 扩展入口:注册 /pi-web-switch 命令
193
+ │ ├── index.ts # 扩展入口:注册 /pi-switch、/pi-usage 命令
176
194
  │ └── skills/
177
195
  │ └── pi-web-switch/
178
196
  │ └── SKILL.md # 使用文档
179
197
  ├── server/
180
198
  │ └── pi-reader.ts # 服务端:读取 ~/.pi/agent/ 文件
199
+ ├── electron/ # 桌面应用(macOS 菜单栏 / 托盘)
200
+ │ ├── main.ts # 主进程:托盘、弹窗、IPC、本地 API 服务器
201
+ │ ├── api-server.ts # 本地 HTTP 服务器(打包模式提供 dist/ + /api/pi/*)
202
+ │ ├── preload.ts # contextBridge:settings/auth/models/usage IPC
203
+ │ ├── popup.html # 菜单栏使用量弹窗
204
+ │ └── popup-render.ts # 弹窗渲染(今日/7 天 tokens、sparkline、Top 提供商)
181
205
  └── src/ # React 前端
182
206
  ```
183
207