send-to-pi 1.1.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,147 +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. Pi gets immediate full-text context without extra fetching.
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 & Anti-Collision**: Pi sessions automatically probe 18091~18095 and track the most active session in `~/.pi/send-to-pi.json`.
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 ~/.pi/send-to-pi.json or probe ports
51
- Bridge->>Pi: Forward to port /receive
52
- Pi->>Pi: ctx.ui.setEditorText() (Prefill)
53
- Bridge-->>Browser: 200 OK (Prefilled)
54
- else Pi Not Running (Cold Start)
55
- Bridge->>Bridge: Save to ~/.pi/pending-browser-input.txt
56
- Bridge->>User: Launch Terminal (osascript / wt.exe) & run `pi`
57
- User->>Pi: Session Boots
58
- Pi->>Pi: Read pending file & prefill input box
59
- Bridge-->>Browser: 200 OK (Launched)
60
- 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]
61
39
  ```
62
40
 
63
41
  ---
64
42
 
65
- ## 📦 Quick Start (3 Steps)
43
+ ## 📦 Quick Start (2 Steps for Direct Mode)
66
44
 
67
45
  ### Step 1: Install the Pi Extension
68
- You can install it directly via Pi's built-in package manager:
69
-
70
46
  ```bash
71
47
  pi install npm:send-to-pi
72
48
  ```
73
49
 
74
- *(Or from GitHub: `pi install git:github.com/Wude-m/send-to-pi`)*
75
-
76
- ### Step 2: Start the Bridge Daemon
77
- The bridge daemon runs in the background on your machine:
78
-
79
- ```bash
80
- # Using npx directly
81
- npx send-to-pi start
82
-
83
- # Or clone and run
84
- git clone https://github.com/Wude-m/send-to-pi.git
85
- cd send-to-pi
86
- npm start
87
- ```
88
-
89
- *(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.)*
90
-
91
- ### Step 3: Load the Chrome Extension
92
- 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`.
93
51
 
52
+ ### Step 2: Load the Chrome Extension
94
53
  ```bash
95
54
  npx send-to-pi extension
96
55
  ```
97
56
 
98
- This will print the exact folder path and **automatically open the extension directory in your file manager**. Then:
99
- 1. Open Google Chrome or Microsoft Edge and navigate to `chrome://extensions/`.
100
- 2. Toggle on **Developer mode** in the top-right corner.
101
- 3. Click **Load unpacked** and select the folder that just opened.
102
- 4. You're all set!
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.
103
60
 
104
- ---
105
-
106
- ## ⌨️ How to Use
107
-
108
- 1. **Send Selected Text / Code (Markdown)**:
109
- - Highlight text or code ➔ Right-click ➔ Choose `🚀 Send Selection to Pi`;
110
- - Or press shortcut <kbd>Alt+Shift+S</kbd> (<kbd>Cmd+Shift+S</kbd> on macOS).
111
- 2. **Send Clean Article (Readability Mode)**:
112
- - Right-click anywhere on the webpage ➔ Choose `🚀 Send Clean Article to Pi`.
113
- - The article body is parsed into clean Markdown without ads or navigation menus.
114
- 3. **Send Hyperlink**:
115
- - 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.
116
62
 
117
- The formatted context will immediately appear at your terminal cursor:
118
- ```text
119
- [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:
120
65
 
121
- ```typescript
122
- export default function (pi: ExtensionAPI) { ... }
66
+ ```bash
67
+ npx send-to-pi start
123
68
  ```
124
- _ [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
125
73
  ```
126
74
 
127
75
  ---
128
76
 
129
- ## ⚙️ Configuration & Terminal Customization
130
-
131
- You can configure options via environment variables when launching the daemon:
77
+ ## ⚙️ Configuration (`~/.pi/send-to-pi/config.json` or Env Vars)
132
78
 
133
- | Environment Variable | Default | Description |
134
- | :--- | :--- | :--- |
135
- | `PI_BRIDGE_PORT` | `18090` | Port listened by the Bridge Daemon |
136
- | `PI_INTERNAL_PORT` | `18091` | Starting port for active Pi sessions (probes 18091~18095) |
137
- | `PI_WORKDIR` | Current directory | Default working directory when auto-launching Pi |
138
- | `PI_TERMINAL` | Auto-detect | Preferred terminal: `iterm2`, `ghostty`, `terminal`, `wezterm`, `alacritty` |
79
+ Run `npx send-to-pi config` to view your config path and effective settings.
139
80
 
140
- Example on macOS:
141
- ```bash
142
- 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
+ }
143
88
  ```
144
89
 
145
- ---
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) |
146
98
 
147
- ## 🤝 Contributing
99
+ ---
148
100
 
149
- Contributions are warmly welcome! Whether it's:
150
- - Supporting Firefox / Safari extensions
151
- - Adding more terminal emulators
152
- - Providing Homebrew / AUR packages
101
+ ## 🆕 v1.3.0 Changes
153
102
 
154
- 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.
155
107
 
156
108
  ---
157
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,148 +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 模式)**:右键点击“发送精简文章”,自动剔除页眉、页脚、侧边栏及广告噪声,将干净的正文转为 Markdown 一键交付,终端无需再额外发起网络请求。
29
- - ⌨️ **快捷键一键直达**:支持全局划选快捷键(默认 <kbd>Alt+Shift+S</kbd> / Mac <kbd>Cmd+Shift+S</kbd>),无需右键鼠标二次点击。
30
- - 🔄 **动态端口发现与防串台**:Pi 会话自动在 18091~18095 范围内探测可用端口,并通过 `~/.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.json 或端口探测
51
- Bridge->>Pi: 转发至对应端口 /receive
52
- Pi->>Pi: ctx.ui.setEditorText() (预填到输入框)
53
- Bridge-->>Browser: 200 OK (已填入输入框)
54
- else Pi 未运行 (冷启动模式)
55
- Bridge->>Bridge: 写入暂存文件 ~/.pi/pending-browser-input.txt
56
- Bridge->>User: 自动拉起终端并运行 `pi`
57
- User->>Pi: 会话初始化完成
58
- Pi->>Pi: 读取暂存文件并填入输入框
59
- Bridge-->>Browser: 200 OK (已唤醒终端)
60
- 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 到剪贴板]
61
39
  ```
62
40
 
63
41
  ---
64
42
 
65
- ## 📦 三步快速上手
66
-
67
- ### 第一步:安装 Pi 原生扩展
68
- 你可以直接使用 Pi 内置的包管理器一键安装:
43
+ ## 📦 两步极速上手(直连模式)
69
44
 
45
+ ### 第一步:安装 Pi 扩展
70
46
  ```bash
71
47
  pi install npm:send-to-pi
72
48
  ```
73
49
 
74
- *(或者通过 GitHub 安装: `pi install git:github.com/Wude-m/send-to-pi`)*
75
-
76
- ### 第一步启动后,扩展会自动随 Pi 启动并在可用端口(18091~18095)监听接收。
77
-
78
- ### 第二步:启动 Bridge 守护进程
79
- 调度守护进程负责在后台监听浏览器请求并在需要时唤醒终端:
50
+ 在**任意终端**打开或重启 `pi`,扩展会自动在 `127.0.0.1:18091~18095` 待命。
80
51
 
52
+ ### 第二步:加载 Chrome 扩展
81
53
  ```bash
82
- # 直接使用 npx 运行
83
- npx send-to-pi start
84
-
85
- # 或者克隆本仓库后运行
86
- git clone https://github.com/Wude-m/send-to-pi.git
87
- cd send-to-pi
88
- npm start
54
+ npx send-to-pi extension
89
55
  ```
90
56
 
91
- > **后台常驻小提示**:
92
- > - **macOS / Linux 用户**:直接运行 `bash scripts/start-mac.sh` 即可在后台静默运行。
93
- > - **Windows 用户**:双击 `scripts/start-win.vbs` 即可无黑框后台静默运行。
57
+ 1. 在 Chrome / Edge 打开 `chrome://extensions/`;
58
+ 2. 开启右上角 **开发者模式**;
59
+ 3. 点击 **加载已解压的扩展程序**,选择弹出的文件夹即可。
94
60
 
95
- ### 第三步:加载 Chrome 浏览器扩展
96
- 你完全不需要手动去翻找目录,只需在终端运行:
61
+ 现在即可在任意网页划词按 <kbd>Cmd+Shift+S</kbd>(Windows/Linux: <kbd>Alt+Shift+S</kbd>)或右键直发到 Pi 输入框!
97
62
 
63
+ ### 可选第三步:启动 Bridge 守护进程(需要冷启动自动拉起终端时)
98
64
  ```bash
99
- npx send-to-pi extension
65
+ npx send-to-pi start
100
66
  ```
101
67
 
102
- 该命令会打印出扩展目录并**自动在系统文件管理器中打开该文件夹**。然后:
103
- 1. 打开 Chrome 或 Edge 浏览器,访问 `chrome://extensions/`;
104
- 2. 开启右上角的 **“开发者模式”**(Developer mode);
105
- 3. 点击左上角的 **“加载已解压的扩展程序”**(Load unpacked),选择刚刚为你弹出的文件夹即可!
106
-
107
- ---
108
-
109
- ## ⌨️ 日常使用演示
110
-
111
- 1. **发送划选内容(Markdown 格式)**:
112
- - 网页上鼠标选中任何代码或文本 ➔ 右键 ➔ 点击 `🚀 发送选中内容给 Pi`;
113
- - 或划选后直接按下快捷键 <kbd>Alt+Shift+S</kbd>(Mac: <kbd>Cmd+Shift+S</kbd>)。
114
- 2. **发送精简正文(Readability 模式)**:
115
- - 在网页任意空白处 ➔ 右键 ➔ 点击 `🚀 发送精简文章给 Pi`;
116
- - 自动解析正文结构转为 Markdown,剔除无关导航和广告。
117
- 3. **发送超链接**:
118
- - 在任意超链接上 ➔ 右键 ➔ 点击 `🚀 发送此链接给 Pi`。
119
-
120
- 终端输入框中会立即呈现带有来源标题与 URL 的整洁 Markdown 内容:
121
- ```text
122
- 【来源】:GitHub - earendil-works/pi-coding-agent (https://github.com/...)
123
-
124
- ```typescript
125
- export default function (pi: ExtensionAPI) { ... }
126
- ```
127
- _ [光标停在此处,等待你补充提示词]
68
+ 随时检查在线状态(同时显示 Bridge 与直连 Pi 会话):
69
+ ```bash
70
+ npx send-to-pi status
128
71
  ```
129
72
 
130
73
  ---
131
74
 
132
- ## ⚙️ 环境变量与终端自定义
133
-
134
- 支持通过环境变量调整守护进程行为:
75
+ ## ⚙️ 自定义配置(`~/.pi/send-to-pi/config.json` 或环境变量)
135
76
 
136
- | 环境变量 | 默认值 | 说明 |
137
- | :--- | :--- | :--- |
138
- | `PI_BRIDGE_PORT` | `18090` | Bridge 调度进程监听的端口 |
139
- | `PI_INTERNAL_PORT` | `18091` | 活跃 Pi 会话内部起始端口(自动探测 18091~18095) |
140
- | `PI_WORKDIR` | 当前目录 | 自动唤醒 Pi 时默认进入的工作目录 |
141
- | `PI_TERMINAL` | 自动探测 | macOS/Linux 指定偏好终端(如 `iterm2`, `ghostty`, `terminal`, `alacritty`) |
77
+ 运行 `npx send-to-pi config` 查看配置文件路径与当前生效值。
142
78
 
143
- macOS 示例:
144
- ```bash
145
- 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
+ }
146
86
  ```
147
87
 
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) |
96
+
148
97
  ---
149
98
 
150
- ## 🤝 欢迎贡献
99
+ ## 🆕 v1.3.0 变更
151
100
 
152
- 欢迎提交 PR 或 Issue!无论是:
153
- - 适配 Firefox / Safari 扩展
154
- - 支持更多小众终端仿真器
155
- - 完善打包与系统服务脚本
101
+ - **零 Daemon 直连模式**:未启动 Bridge 时自动探测活跃 Pi(`18091~18095`)直发到输入框,彻底摆脱对后台守护进程和特定终端的依赖。
102
+ - **扩展弹窗会话切换器**:点击工具栏图标即可查看 Bridge 状态与全部在线 Pi 会话(项目名 + 终端名),支持自动路由或手动锁定窗口。
103
+ - **真实活跃度追踪**:补齐 `input` / `agent_start` 钩子,多开窗口时精准投递到刚交互的会话。
104
+ - **4 层跨客户端冷启动**:新增 **Rex**、Warp、kitty、Alacritty 等终端支持,增加 `last-terminal.json` 自动记忆、`launchCommand` 自定义命令逃生舱与剪贴板终极兜底。
156
105
 
157
106
  ---
158
107