send-to-pi 1.2.0 → 1.3.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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [**简体中文**](./README_CN.md) | **English**
4
4
 
5
- > Seamlessly bridge your web browser to the [Pi Coding Agent](https://github.com/earendil-works/pi-coding-agent). Send snippets, articles, or links directly into your Pi terminal prompt with one click or keyboard shortcut.
5
+ > Seamlessly bridge your web browser to the [Pi Coding Agent](https://github.com/earendil-works/pi-coding-agent). Send snippets, articles, or links directly into your Pi terminal prompt in **any terminal client**—with zero-daemon direct delivery when Pi is open, and 4-layer adaptive cold-start launch when it isn't.
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/send-to-pi.svg)](https://www.npmjs.com/package/send-to-pi)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -11,155 +11,99 @@
11
11
 
12
12
  ---
13
13
 
14
- ## 💡 Why send-to-pi?
14
+ ## 💡 Highlights
15
15
 
16
- Modern AI coding agents (like Pi, Claude Code, Aider) shine inside the terminal, but **a massive portion of a developer's daily context lives inside the browser**—GitHub Issues, PR reviews, documentation, Stack Overflow threads, error logs, and technical blog posts.
17
-
18
- Traditionally, sending webpage context to an agent means:
19
- 1. Selecting text
20
- 2. Switching windows
21
- 3. Pasting into the terminal
22
- 4. Dealing with broken indentation or destroyed tables, then typing instructions manually
23
-
24
- **With `send-to-pi`:**
25
- Right-click on any selected text, link, or page ➔ **The text is instantly formatted into Markdown and prefilled into your Pi terminal input box**, with the source title & URL cleanly formatted.
26
- - 🎯 **Prefill Mode (No Auto-Submit)**: The prompt is populated into the editor without auto-submitting. You can review, refine, or append instructions before pressing <kbd>Enter</kbd>.
27
- - 📝 **HTML to Markdown Preservation**: Selection captures `<pre><code>` blocks, language tags, indentation, `<table>` grids, lists, quotes, and links without loss. Falls back gracefully when restricted.
28
- - 📖 **Clean Article Extraction (Readability Mode)**: Extract clean article markdown stripped of navigation, footers, sidebars, and ads. X/Twitter pages target the main tweet/article instead of scanning the entire body, then fall back to title and link.
29
- - ⌨️ **Keyboard Shortcut**: Instant delivery with <kbd>Alt+Shift+S</kbd> (<kbd>Cmd+Shift+S</kbd> on macOS) right after highlighting text or code.
30
- - 🔄 **Dynamic Port Discovery & Session Routing**: Pi sessions probe 18091~18095 and register in `~/.pi/send-to-pi/sessions.json`. The Bridge routes to the most recent healthy session and keeps the legacy `~/.pi/send-to-pi.json` format compatible.
31
- - ⚡ **Cold-Start Auto-Wake**: If Pi isn't running, it automatically opens your terminal, starts Pi, and populates the text once the session boots up.
32
- - 🍏 **True Cross-Platform**: Native terminal launch support for **macOS** (Terminal.app, iTerm2, Ghostty, WezTerm), **Windows** (Windows Terminal, PowerShell), and **Linux**.
33
- - 🔒 **100% Local & Private**: All communication happens via `127.0.0.1`. No cloud proxy, no data logging.
16
+ - 🔌 **Zero-Daemon Direct Mode (100% Terminal-Agnostic)**: When Pi is already running—in **Rex, Ghostty, iTerm2, Warp, WezTerm, kitty, Alacritty, VS Code, Cursor, Windows Terminal, tmux**, or any other terminal—the Chrome extension talks directly to Pi (`18091~18095`) and prefills via `ctx.ui.setEditorText()`. **No background daemon required for hot delivery.**
17
+ - 🪟 **Active Session Routing & Popup Switcher**: Tracks real user activity (`input` / `agent_start`) across multiple Pi sessions and routes to the most recently used window. Click the extension toolbar icon to view all online Pi sessions (project + terminal) and pin a target if needed.
18
+ - 🎯 **Prefill Mode (No Auto-Submit)**: Inserts formatted Markdown at your cursor without pressing Enter, so you can append instructions first.
19
+ - 📝 **HTML to Markdown & Clean Article Extraction**: Preserves `<pre><code>` language tags, indentation, tables, lists, quotes, and links. Extracts clean articles (including X/Twitter main posts).
20
+ - ⚡ **4-Layer Adaptive Cold-Start (Optional Bridge Daemon)**: Start the optional Bridge Daemon (`npx send-to-pi start`) to wake Pi even when closed:
21
+ 1. **Custom Command Template** (`PI_LAUNCH_CMD` or `~/.pi/send-to-pi/config.json`) — one-line escape hatch for any terminal client.
22
+ 2. **Last Used Terminal Memory** — Pi records the terminal you actually use (`~/.pi/send-to-pi/last-terminal.json`), so cold-start launches the right client (including **Rex**, Ghostty, Warp, WezTerm, kitty, Alacritty, iTerm2, Windows Terminal, etc.).
23
+ 3. **Running / Installed Smart Detection** — prefers currently running terminals before OS defaults.
24
+ 4. **Clipboard Fallback** — if no terminal can be launched, formatted Markdown is copied to your clipboard automatically so nothing is ever lost.
25
+ - 🔒 **100% Local & Private**: Loopback `127.0.0.1` only. Zero cloud calls, zero telemetry.
34
26
 
35
27
  ---
36
28
 
37
29
  ## 🛠️ Architecture
38
30
 
39
31
  ```mermaid
40
- sequenceDiagram
41
- autonumber
42
- actor User as Developer
43
- participant Browser as Chrome Extension
44
- participant Bridge as Bridge Daemon (:18090)
45
- participant Pi as Active Pi Session (18091~18095)
46
-
47
- User->>Browser: Select or Extract Article (Menu / Shortcut)
48
- Browser->>Bridge: HTTP POST /send (Markdown, URL, Title)
49
- alt Active Pi Running
50
- Bridge->>Bridge: Read and clean ~/.pi/send-to-pi/sessions.json
51
- Bridge->>Bridge: Fall back to ~/.pi/send-to-pi.json or probe ports
52
- Bridge->>Pi: Forward to port /receive
53
- Pi->>Pi: ctx.ui.setEditorText() (Prefill)
54
- Bridge-->>Browser: 200 OK (Prefilled)
55
- else Pi Not Running (Cold Start)
56
- Bridge->>Bridge: Save to ~/.pi/pending-browser-input.txt
57
- Bridge->>User: Launch Terminal (osascript / wt.exe) & run `pi`
58
- User->>Pi: Session Boots
59
- Pi->>Pi: Read pending file & prefill input box
60
- Bridge-->>Browser: 200 OK (Launched)
61
- end
32
+ flowchart LR
33
+ Chrome[Chrome Extension] -->|1. Primary :18090| Bridge[Bridge Daemon<br/>Optional · Cold-Start]
34
+ Chrome -.->|2. Zero-Daemon Direct<br/>Probes :18091~18095| Pi[Active Pi Session]
35
+ Bridge -->|Hot Delivery :18091~18095| Pi
36
+ Pi -->|ctx.ui.setEditorText| Editor[Any Terminal Client<br/>Rex / Ghostty / Warp / VS Code / WT...]
37
+ Bridge -->|Cold-Start 4 Layers| Launcher[Custom Cmd → Last Terminal<br/>→ Running/Installed → Clipboard]
38
+ Chrome -.->|3. Fallback when all offline| Clip[Clipboard Copy]
62
39
  ```
63
40
 
64
41
  ---
65
42
 
66
- ## 📦 Quick Start (3 Steps)
43
+ ## 📦 Quick Start (2 Steps for Direct Mode)
67
44
 
68
45
  ### Step 1: Install the Pi Extension
69
- You can install it directly via Pi's built-in package manager:
70
-
71
46
  ```bash
72
47
  pi install npm:send-to-pi
73
48
  ```
74
49
 
75
- *(Or from GitHub: `pi install git:github.com/Wude-m/send-to-pi`)*
76
-
77
- ### Step 2: Start the Bridge Daemon
78
- The bridge daemon runs in the background on your machine:
79
-
80
- ```bash
81
- # Using npx directly
82
- npx send-to-pi start
83
-
84
- # Or clone and run
85
- git clone https://github.com/Wude-m/send-to-pi.git
86
- cd send-to-pi
87
- npm start
88
- ```
89
-
90
- *(Tip: macOS users can run `bash scripts/start-mac.sh` to run in background. Windows users can double-click `scripts/start-win.vbs` for silent background execution.)*
91
-
92
- ### Step 3: Load the Chrome Extension
93
- You don't need to hunt for the folder manually! Just run:
50
+ Restart or open `pi` in **any terminal**. The extension listens on `127.0.0.1:18091~18095`.
94
51
 
52
+ ### Step 2: Load the Chrome Extension
95
53
  ```bash
96
54
  npx send-to-pi extension
97
55
  ```
98
56
 
99
- This will print the exact folder path and **automatically open the extension directory in your file manager**. Then:
100
- 1. Open Google Chrome or Microsoft Edge and navigate to `chrome://extensions/`.
101
- 2. Toggle on **Developer mode** in the top-right corner.
102
- 3. Click **Load unpacked** and select the folder that just opened.
103
- 4. You're all set!
104
-
105
- ---
106
-
107
- ## ⌨️ How to Use
57
+ 1. Open `chrome://extensions/` in Chrome or Edge.
58
+ 2. Enable **Developer mode** (top-right).
59
+ 3. Click **Load unpacked** and select the opened folder.
108
60
 
109
- 1. **Send Selected Text / Code (Markdown)**:
110
- - Highlight text or code ➔ Right-click ➔ Choose `🚀 Send Selection to Pi`;
111
- - Or press shortcut <kbd>Alt+Shift+S</kbd> (<kbd>Cmd+Shift+S</kbd> on macOS).
112
- 2. **Send Clean Article (Readability Mode)**:
113
- - Right-click anywhere on the webpage ➔ Choose `🚀 Send Clean Article to Pi`.
114
- - The article body is parsed into clean Markdown without ads or navigation menus.
115
- 3. **Send Hyperlink**:
116
- - Right-click any link ➔ Choose `🚀 Send Link to Pi`.
61
+ That's it! Highlight text on any page and press <kbd>Cmd+Shift+S</kbd> (Windows/Linux: <kbd>Alt+Shift+S</kbd>) or right-click to send directly into your active Pi terminal.
117
62
 
118
- The formatted context will immediately appear at your terminal cursor:
119
- ```text
120
- [Source]: GitHub - earendil-works/pi-coding-agent (https://github.com/...)
63
+ ### Optional Step 3: Start Bridge Daemon (for Cold-Start Auto-Wake)
64
+ Only needed if you want `send-to-pi` to automatically launch a terminal when no Pi session is running:
121
65
 
122
- ```typescript
123
- export default function (pi: ExtensionAPI) { ... }
66
+ ```bash
67
+ npx send-to-pi start
124
68
  ```
125
- _ [Cursor waits here for your instructions]
69
+
70
+ Check live status anytime (shows both Bridge and Direct-Mode Pi sessions):
71
+ ```bash
72
+ npx send-to-pi status
126
73
  ```
127
74
 
128
75
  ---
129
76
 
130
- ## ⚙️ Configuration & Terminal Customization
77
+ ## ⚙️ Configuration (`~/.pi/send-to-pi/config.json` or Env Vars)
131
78
 
132
- You can configure options via environment variables when launching the daemon:
79
+ Run `npx send-to-pi config` to view your config path and effective settings.
133
80
 
134
- | Environment Variable | Default | Description |
135
- | :--- | :--- | :--- |
136
- | `PI_BRIDGE_PORT` | `18090` | Port listened by the Bridge Daemon |
137
- | `PI_INTERNAL_PORT` | `18091` | Starting port for active Pi sessions (probes 18091~18095) |
138
- | `PI_WORKDIR` | Current directory | Default working directory when auto-launching Pi |
139
- | `PI_TERMINAL` | Auto-detect | Preferred terminal: `iterm2`, `ghostty`, `terminal`, `wezterm`, `alacritty` |
140
-
141
- Example on macOS:
142
- ```bash
143
- PI_TERMINAL=ghostty PI_WORKDIR=~/mycode npx send-to-pi start
81
+ Example `~/.pi/send-to-pi/config.json`:
82
+ ```json
83
+ {
84
+ "terminal": "rex",
85
+ "launchCommand": "rex run --interactive --cwd \"{workdir}\" --keep-open -- pi",
86
+ "focusOnSend": false
87
+ }
144
88
  ```
145
89
 
146
- ---
147
-
148
- ## 🆕 v1.2.0 Changes
149
-
150
- - Fixed X/Twitter article extraction without reading the full page body.
151
- - Preserved selection and link sending modes.
152
- - Added multi-session registry and recent healthy-session routing.
153
- - Added `activeAt`, `terminal`, and `window` session metadata for future terminal routing.
90
+ | Env Variable | Config Key | Default | Description |
91
+ | :--- | :--- | :--- | :--- |
92
+ | `PI_BRIDGE_PORT` | `bridgePort` | `18090` | Port listened by the optional Bridge Daemon |
93
+ | `PI_INTERNAL_PORT` | `internalPort` | `18091` | Starting port for Pi sessions (probes 5 ports) |
94
+ | `PI_WORKDIR` | `workDir` | Last Pi workdir / cwd | Working directory for cold-start launch |
95
+ | `PI_TERMINAL` | `terminal` | Auto (last used) | Preferred terminal (`rex`, `ghostty`, `iterm2`, `warp`, `wezterm`, `kitty`, `alacritty`, `wt`, `terminal`) |
96
+ | `PI_LAUNCH_CMD` | `launchCommand` | Empty | Custom launch command template with `{workdir}` placeholder |
97
+ | `PI_FOCUS_ON_SEND` | `focusOnSend` | `false` | Bring the target terminal app to front after sending (macOS) |
154
98
 
155
- ## 🤝 Contributing
99
+ ---
156
100
 
157
- Contributions are warmly welcome! Whether it's:
158
- - Supporting Firefox / Safari extensions
159
- - Adding more terminal emulators
160
- - Providing Homebrew / AUR packages
101
+ ## 🆕 v1.3.0 Changes
161
102
 
162
- Please feel free to open an Issue or Pull Request.
103
+ - **Zero-Daemon Direct Delivery**: Chrome extension automatically falls back to probing active Pi sessions (`18091~18095`) when Bridge (`18090`) is not running—works out of the box on any terminal client.
104
+ - **Toolbar Popup Session Switcher**: View Bridge status and all online Pi sessions (workdir + terminal) and switch between Auto (most recent) or a pinned session.
105
+ - **Real Activity Tracking**: Added `input` and `agent_start` hooks in Pi extension so `activeAt` always reflects the window you are actively using.
106
+ - **4-Layer Cross-Client Cold-Start**: Added native **Rex** (plus Warp, kitty, Alacritty, WezTerm, Ghostty, iTerm2, Windows Terminal) support, automatic `last-terminal.json` memory, custom `launchCommand` template escape hatch, and clipboard fallback.
163
107
 
164
108
  ---
165
109
 
package/README_CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **简体中文** | [**English**](./README.md)
4
4
 
5
- > 让你的网页浏览器与 [Pi 终端编程助手](https://github.com/earendil-works/pi-coding-agent) 无缝打通。在网页上选中文字、提取整页文章或捕获链接,一键直达终端输入框,自动排版并预填上下文。
5
+ > 让浏览器与 [Pi 终端编程助手](https://github.com/earendil-works/pi-coding-agent) 无缝打通。无论你使用 **Rex、Ghostty、iTerm2、Warp、WezTerm、kitty、Alacritty、VS Code、Cursor 还是 Windows Terminal**,打开 Pi 即可**零守护进程直连**预填到输入框;未打开时也可通过可选 Bridge 实现 4 层自适应冷启动唤醒。
6
6
 
7
7
  [![npm version](https://img.shields.io/npm/v/send-to-pi.svg)](https://www.npmjs.com/package/send-to-pi)
8
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
@@ -11,156 +11,97 @@
11
11
 
12
12
  ---
13
13
 
14
- ## 💡 为什么需要 send-to-pi?
14
+ ## 💡 核心特性
15
15
 
16
- 现代 AI Coding Agent(如 Pi、Claude Code、Aider 等)在命令行终端里表现极其出色,但日常开发中**绝大部分上下文其实都在浏览器里**——比如正在查阅的 GitHub Issue、PR 代码 Review、官方文档、Stack Overflow 问答、前端报错页面以及技术博文。
17
-
18
- 以往把网页内容喂给终端 Agent 的流程非常繁琐:
19
- 1. 鼠标划词复制
20
- 2. Alt+Tab 切到终端窗口
21
- 3. 粘贴进输入框
22
- 4. 代码缩进变形、表格散架、手动打字写“请参考以上网页/报错...”
23
-
24
- **有了 `send-to-pi` 之后:**
25
- 在任何网页上划选文字、提取文章或点击链接 ➔ **内容自动携带网页标题与来源 URL,毫秒级预填进 Pi 终端输入框**。
26
- - 🎯 **Prefill 预填模式(绝不自作主张回车)**:内容送到输入框后,光标停留在末尾,你可以从容补充具体指令(如“请根据这段代码重构...”),最后按回车自主发送。
27
- - 📝 **HTML 智能转 Markdown(保留代码与表格格式)**:划词内容自动识别并还原 `<pre><code>` 语言/缩进、`<table>` 表格、列表、引用及超链接;页面受限时自动平滑降级。
28
- - 📖 **整页正文提取(Readability 模式)**:自动剔除页眉、页脚、侧边栏及广告噪声。X/Twitter 页面只提取主 tweet/article,不读取整个 body;失败时回退为标题与链接。
29
- - ⌨️ **快捷键一键直达**:支持全局划选快捷键(默认 <kbd>Alt+Shift+S</kbd> / Mac <kbd>Cmd+Shift+S</kbd>),无需右键鼠标二次点击。
30
- - 🔄 **动态端口发现与会话路由**:Pi 会话自动探测 18091~18095,并写入 `~/.pi/send-to-pi/sessions.json`。Bridge 优先路由最近的健康会话,并兼容旧版 `~/.pi/send-to-pi.json`。
31
- - ⚡ **冷启动自动唤醒终端**:若当前未运行 Pi,自动为你拉起终端、启动 `pi`,并在会话初始化完成后自动填入内容!
32
- - 🍏 **全平台终端适配**:原生支持 **macOS**(Terminal.app、iTerm2、Ghostty、WezTerm 等)、**Windows**(Windows Terminal、PowerShell)以及 **Linux**。
33
- - 🔒 **纯本地与隐私安全**:全链路通过本地环回地址 `127.0.0.1` 传输,无云端中转,零数据收集。
16
+ - 🔌 **零 Daemon 直连模式(100% 终端客户端无关)**:只要你的 Pi 正在运行(无论在 Rex、Ghostty、Warp、VS Code、Cursor、Windows Terminal 还是 tmux 里),Chrome 扩展在未检测到 `18090` Bridge 时会自动直连 `18091~18095` 的 Pi 扩展,通过 `ctx.ui.setEditorText()` 直接填入输入框——**无需常驻后台进程**。
17
+ - 🪟 **真实活跃会话路由 + 扩展弹窗选窗口**:Pi 扩展通过 `input` / `agent_start` 实时更新活跃时间,多开窗口时自动送到你刚聊天的那个窗口;点击浏览器工具栏扩展图标可查看全部在线 Pi 会话(项目名 + 终端名)并一键锁定目标窗口。
18
+ - 🎯 **Prefill 预填模式(绝不自动回车)**:内容送到输入框后停在末尾,方便你补充指令再回车发送。
19
+ - 📝 **HTML 智能转 Markdown & 正文提取**:保留代码块语言/缩进、表格、列表与链接,支持 X/Twitter 主帖及常见文章正文提取。
20
+ - ⚡ **4 层跨客户端冷启动(可选 Bridge 守护进程)**:当所有 Pi 都关闭时,若启动了 Bridge(`npx send-to-pi start`),按以下 4 层依次兜底:
21
+ 1. **自定义启动命令模板**(`PI_LAUNCH_CMD` 或 `~/.pi/send-to-pi/config.json`):支持 `{workdir}` 占位符,任何小众终端一行接入。
22
+ 2. **记住上次实际运行 Pi 的终端**(`~/.pi/send-to-pi/last-terminal.json`):原生支持 **Rex**、Ghostty、Warp、WezTerm、kitty、Alacritty、iTerm2、Windows Terminal 等,不再瞎猜或误开旧终端。
23
+ 3. **运行中终端优先 > 已安装终端 > 系统默认终端**。
24
+ 4. **剪贴板终极兜底**:冷启动失败或无运行中 Pi 时自动把排好版的 Markdown 复制到剪贴板并弹通知,绝不丢内容。
25
+ - 🔒 **纯本地隐私安全**:全链路走 `127.0.0.1`,无云端中转、零数据上报。
34
26
 
35
27
  ---
36
28
 
37
- ## 🛠️ 系统架构与工作流程
29
+ ## 🛠️ 工作架构
38
30
 
39
31
  ```mermaid
40
- sequenceDiagram
41
- autonumber
42
- actor User as 开发者
43
- participant Browser as Chrome 扩展
44
- participant Bridge as Bridge 守护进程 (:18090)
45
- participant Pi as 活跃 Pi 终端 (18091~18095)
46
-
47
- User->>Browser: 划选/文章提取 (右键或快捷键)
48
- Browser->>Bridge: HTTP POST /send (Markdown、URL、标题)
49
- alt 存在活跃 Pi 会话
50
- Bridge->>Bridge: 读取并清理 ~/.pi/send-to-pi/sessions.json
51
- Bridge->>Bridge: 回退读取 ~/.pi/send-to-pi.json 或端口探测
52
- Bridge->>Pi: 转发至对应端口 /receive
53
- Pi->>Pi: ctx.ui.setEditorText() (预填到输入框)
54
- Bridge-->>Browser: 200 OK (已填入输入框)
55
- else Pi 未运行 (冷启动模式)
56
- Bridge->>Bridge: 写入暂存文件 ~/.pi/pending-browser-input.txt
57
- Bridge->>User: 自动拉起终端并运行 `pi`
58
- User->>Pi: 会话初始化完成
59
- Pi->>Pi: 读取暂存文件并填入输入框
60
- Bridge-->>Browser: 200 OK (已唤醒终端)
61
- end
32
+ flowchart LR
33
+ Chrome[Chrome 扩展] -->|1. 优先 :18090| Bridge[Bridge 守护进程<br/>可选 · 冷启动唤醒]
34
+ Chrome -.->|2. 零 Daemon 直连<br/>探测 :18091~18095| Pi[活跃 Pi 会话]
35
+ Bridge -->|热投递 :18091~18095| Pi
36
+ Pi -->|ctx.ui.setEditorText| Editor[任意终端里的 Pi 输入框<br/>Rex / Ghostty / Warp / VS Code / WT...]
37
+ Bridge -->|冷启动 4 层策略| Launcher[自定义命令 → 上次终端<br/>→ 运行中/已装探测 → 剪贴板]
38
+ Chrome -.->|3. 全部离线时兜底| Clip[复制 Markdown 到剪贴板]
62
39
  ```
63
40
 
64
41
  ---
65
42
 
66
- ## 📦 三步快速上手
67
-
68
- ### 第一步:安装 Pi 原生扩展
69
- 你可以直接使用 Pi 内置的包管理器一键安装:
43
+ ## 📦 两步极速上手(直连模式)
70
44
 
45
+ ### 第一步:安装 Pi 扩展
71
46
  ```bash
72
47
  pi install npm:send-to-pi
73
48
  ```
74
49
 
75
- *(或者通过 GitHub 安装: `pi install git:github.com/Wude-m/send-to-pi`)*
76
-
77
- ### 第一步启动后,扩展会自动随 Pi 启动并在可用端口(18091~18095)监听接收。
78
-
79
- ### 第二步:启动 Bridge 守护进程
80
- 调度守护进程负责在后台监听浏览器请求并在需要时唤醒终端:
50
+ 在**任意终端**打开或重启 `pi`,扩展会自动在 `127.0.0.1:18091~18095` 待命。
81
51
 
52
+ ### 第二步:加载 Chrome 扩展
82
53
  ```bash
83
- # 直接使用 npx 运行
84
- npx send-to-pi start
85
-
86
- # 或者克隆本仓库后运行
87
- git clone https://github.com/Wude-m/send-to-pi.git
88
- cd send-to-pi
89
- npm start
54
+ npx send-to-pi extension
90
55
  ```
91
56
 
92
- > **后台常驻小提示**:
93
- > - **macOS / Linux 用户**:直接运行 `bash scripts/start-mac.sh` 即可在后台静默运行。
94
- > - **Windows 用户**:双击 `scripts/start-win.vbs` 即可无黑框后台静默运行。
57
+ 1. 在 Chrome / Edge 打开 `chrome://extensions/`;
58
+ 2. 开启右上角 **开发者模式**;
59
+ 3. 点击 **加载已解压的扩展程序**,选择弹出的文件夹即可。
95
60
 
96
- ### 第三步:加载 Chrome 浏览器扩展
97
- 你完全不需要手动去翻找目录,只需在终端运行:
61
+ 现在即可在任意网页划词按 <kbd>Cmd+Shift+S</kbd>(Windows/Linux: <kbd>Alt+Shift+S</kbd>)或右键直发到 Pi 输入框!
98
62
 
63
+ ### 可选第三步:启动 Bridge 守护进程(需要冷启动自动拉起终端时)
99
64
  ```bash
100
- npx send-to-pi extension
65
+ npx send-to-pi start
101
66
  ```
102
67
 
103
- 该命令会打印出扩展目录并**自动在系统文件管理器中打开该文件夹**。然后:
104
- 1. 打开 Chrome 或 Edge 浏览器,访问 `chrome://extensions/`;
105
- 2. 开启右上角的 **“开发者模式”**(Developer mode);
106
- 3. 点击左上角的 **“加载已解压的扩展程序”**(Load unpacked),选择刚刚为你弹出的文件夹即可!
107
-
108
- ---
109
-
110
- ## ⌨️ 日常使用演示
111
-
112
- 1. **发送划选内容(Markdown 格式)**:
113
- - 网页上鼠标选中任何代码或文本 ➔ 右键 ➔ 点击 `🚀 发送选中内容给 Pi`;
114
- - 或划选后直接按下快捷键 <kbd>Alt+Shift+S</kbd>(Mac: <kbd>Cmd+Shift+S</kbd>)。
115
- 2. **发送精简正文(Readability 模式)**:
116
- - 在网页任意空白处 ➔ 右键 ➔ 点击 `🚀 发送精简文章给 Pi`;
117
- - 自动解析正文结构转为 Markdown,剔除无关导航和广告。
118
- 3. **发送超链接**:
119
- - 在任意超链接上 ➔ 右键 ➔ 点击 `🚀 发送此链接给 Pi`。
120
-
121
- 终端输入框中会立即呈现带有来源标题与 URL 的整洁 Markdown 内容:
122
- ```text
123
- 【来源】:GitHub - earendil-works/pi-coding-agent (https://github.com/...)
124
-
125
- ```typescript
126
- export default function (pi: ExtensionAPI) { ... }
127
- ```
128
- _ [光标停在此处,等待你补充提示词]
68
+ 随时检查在线状态(同时显示 Bridge 与直连 Pi 会话):
69
+ ```bash
70
+ npx send-to-pi status
129
71
  ```
130
72
 
131
73
  ---
132
74
 
133
- ## ⚙️ 环境变量与终端自定义
75
+ ## ⚙️ 自定义配置(`~/.pi/send-to-pi/config.json` 或环境变量)
134
76
 
135
- 支持通过环境变量调整守护进程行为:
77
+ 运行 `npx send-to-pi config` 查看配置文件路径与当前生效值。
136
78
 
137
- | 环境变量 | 默认值 | 说明 |
138
- | :--- | :--- | :--- |
139
- | `PI_BRIDGE_PORT` | `18090` | Bridge 调度进程监听的端口 |
140
- | `PI_INTERNAL_PORT` | `18091` | 活跃 Pi 会话内部起始端口(自动探测 18091~18095) |
141
- | `PI_WORKDIR` | 当前目录 | 自动唤醒 Pi 时默认进入的工作目录 |
142
- | `PI_TERMINAL` | 自动探测 | macOS/Linux 指定偏好终端(如 `iterm2`, `ghostty`, `terminal`, `alacritty`) |
143
-
144
- macOS 示例:
145
- ```bash
146
- PI_TERMINAL=ghostty PI_WORKDIR=~/mycode npx send-to-pi start
79
+ 示例 `~/.pi/send-to-pi/config.json`:
80
+ ```json
81
+ {
82
+ "terminal": "rex",
83
+ "launchCommand": "rex run --interactive --cwd \"{workdir}\" --keep-open -- pi",
84
+ "focusOnSend": false
85
+ }
147
86
  ```
148
87
 
149
- ---
88
+ | 环境变量 | 配置文件键 | 默认值 | 说明 |
89
+ | :--- | :--- | :--- | :--- |
90
+ | `PI_BRIDGE_PORT` | `bridgePort` | `18090` | 可选 Bridge 守护进程监听端口 |
91
+ | `PI_INTERNAL_PORT` | `internalPort` | `18091` | Pi 会话直连起始端口(自动探测 5 个端口) |
92
+ | `PI_WORKDIR` | `workDir` | 上次 Pi 目录 / cwd | 冷启动默认进入的工作目录 |
93
+ | `PI_TERMINAL` | `terminal` | 自动(上次终端) | 偏好终端(`rex`, `ghostty`, `iterm2`, `warp`, `wezterm`, `kitty`, `alacritty`, `wt`, `terminal`) |
94
+ | `PI_LAUNCH_CMD` | `launchCommand` | 空 | 万能自定义冷启动命令模板,支持 `{workdir}` 占位符 |
95
+ | `PI_FOCUS_ON_SEND` | `focusOnSend` | `false` | 设为 `true` 时热投递后自动切回对应终端窗口(macOS) |
150
96
 
151
- ## 🆕 v1.2.0 变更
152
-
153
- - 修复 X/Twitter 文章提取,避免读取整个页面 body。
154
- - 保留选中内容与链接发送模式。
155
- - 新增多 Pi 会话注册表及最近健康会话路由。
156
- - 注册会话预留 `activeAt`、`terminal`、`window` 字段。
97
+ ---
157
98
 
158
- ## 🤝 欢迎贡献
99
+ ## 🆕 v1.3.0 变更
159
100
 
160
- 欢迎提交 PR 或 Issue!无论是:
161
- - 适配 Firefox / Safari 扩展
162
- - 支持更多小众终端仿真器
163
- - 完善打包与系统服务脚本
101
+ - **零 Daemon 直连模式**:未启动 Bridge 时自动探测活跃 Pi(`18091~18095`)直发到输入框,彻底摆脱对后台守护进程和特定终端的依赖。
102
+ - **扩展弹窗会话切换器**:点击工具栏图标即可查看 Bridge 状态与全部在线 Pi 会话(项目名 + 终端名),支持自动路由或手动锁定窗口。
103
+ - **真实活跃度追踪**:补齐 `input` / `agent_start` 钩子,多开窗口时精准投递到刚交互的会话。
104
+ - **4 层跨客户端冷启动**:新增 **Rex**、Warp、kitty、Alacritty 等终端支持,增加 `last-terminal.json` 自动记忆、`launchCommand` 自定义命令逃生舱与剪贴板终极兜底。
164
105
 
165
106
  ---
166
107