send-to-pi 1.0.2 → 1.2.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 right-click.
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.
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)
@@ -19,11 +19,15 @@ Traditionally, sending webpage context to an agent means:
19
19
  1. Selecting text
20
20
  2. Switching windows
21
21
  3. Pasting into the terminal
22
- 4. Typing instructions
22
+ 4. Dealing with broken indentation or destroyed tables, then typing instructions manually
23
23
 
24
24
  **With `send-to-pi`:**
25
- Right-click on any selected text, link, or page ➔ **The text is instantly prefilled into your Pi terminal input box**, with the source title & URL cleanly formatted.
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
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.
27
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.
28
32
  - 🍏 **True Cross-Platform**: Native terminal launch support for **macOS** (Terminal.app, iTerm2, Ghostty, WezTerm), **Windows** (Windows Terminal, PowerShell), and **Linux**.
29
33
  - 🔒 **100% Local & Private**: All communication happens via `127.0.0.1`. No cloud proxy, no data logging.
@@ -38,12 +42,14 @@ sequenceDiagram
38
42
  actor User as Developer
39
43
  participant Browser as Chrome Extension
40
44
  participant Bridge as Bridge Daemon (:18090)
41
- participant Pi as Pi Agent Session (:18091)
45
+ participant Pi as Active Pi Session (18091~18095)
42
46
 
43
- User->>Browser: Right-click & "Send to Pi"
44
- Browser->>Bridge: HTTP POST /send (Snippet, URL, Title)
47
+ User->>Browser: Select or Extract Article (Menu / Shortcut)
48
+ Browser->>Bridge: HTTP POST /send (Markdown, URL, Title)
45
49
  alt Active Pi Running
46
- Bridge->>Pi: Forward to 127.0.0.1:18091/receive
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
47
53
  Pi->>Pi: ctx.ui.setEditorText() (Prefill)
48
54
  Bridge-->>Browser: 200 OK (Prefilled)
49
55
  else Pi Not Running (Cold Start)
@@ -100,15 +106,22 @@ This will print the exact folder path and **automatically open the extension dir
100
106
 
101
107
  ## ⌨️ How to Use
102
108
 
103
- 1. **Send Selected Text**: Highlight code or text on any webpage ➔ Right-click ➔ Choose `🚀 Send Selection to Pi`.
104
- 2. **Send Whole Page Link & Title**: Right-click anywhere on the page ➔ Choose `🚀 Send Current Page to Pi`.
105
- 3. **Send Hyperlink**: Right-click any link ➔ Choose `🚀 Send Link to Pi`.
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`.
106
117
 
107
118
  The formatted context will immediately appear at your terminal cursor:
108
119
  ```text
109
120
  [Source]: GitHub - earendil-works/pi-coding-agent (https://github.com/...)
110
121
 
111
- Here is the code snippet or issue description...
122
+ ```typescript
123
+ export default function (pi: ExtensionAPI) { ... }
124
+ ```
112
125
  _ [Cursor waits here for your instructions]
113
126
  ```
114
127
 
@@ -121,7 +134,7 @@ You can configure options via environment variables when launching the daemon:
121
134
  | Environment Variable | Default | Description |
122
135
  | :--- | :--- | :--- |
123
136
  | `PI_BRIDGE_PORT` | `18090` | Port listened by the Bridge Daemon |
124
- | `PI_INTERNAL_PORT` | `18091` | Internal port used by the active Pi session |
137
+ | `PI_INTERNAL_PORT` | `18091` | Starting port for active Pi sessions (probes 18091~18095) |
125
138
  | `PI_WORKDIR` | Current directory | Default working directory when auto-launching Pi |
126
139
  | `PI_TERMINAL` | Auto-detect | Preferred terminal: `iterm2`, `ghostty`, `terminal`, `wezterm`, `alacritty` |
127
140
 
@@ -132,6 +145,13 @@ PI_TERMINAL=ghostty PI_WORKDIR=~/mycode npx send-to-pi start
132
145
 
133
146
  ---
134
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.
154
+
135
155
  ## 🤝 Contributing
136
156
 
137
157
  Contributions are warmly welcome! Whether it's:
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) 无缝打通。在网页上选中文字、提取整页文章或捕获链接,一键直达终端输入框,自动排版并预填上下文。
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)
@@ -19,12 +19,16 @@
19
19
  1. 鼠标划词复制
20
20
  2. Alt+Tab 切到终端窗口
21
21
  3. 粘贴进输入框
22
- 4. 手动打字写“请参考以上网页/报错...”
22
+ 4. 代码缩进变形、表格散架、手动打字写“请参考以上网页/报错...”
23
23
 
24
24
  **有了 `send-to-pi` 之后:**
25
- 在任何网页上划选文字、右键链接或页面 ➔ **内容自动携带网页标题与来源 URL,毫秒级预填进 Pi 终端输入框**。
25
+ 在任何网页上划选文字、提取文章或点击链接 ➔ **内容自动携带网页标题与来源 URL,毫秒级预填进 Pi 终端输入框**。
26
26
  - 🎯 **Prefill 预填模式(绝不自作主张回车)**:内容送到输入框后,光标停留在末尾,你可以从容补充具体指令(如“请根据这段代码重构...”),最后按回车自主发送。
27
- - ⚡ **冷启动自动唤醒终端**:就算你当前没有开着 Pi 终端,右键发送也会自动为你拉起终端、运行 `pi`,并在会话初始化完成后自动填入内容!
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`,并在会话初始化完成后自动填入内容!
28
32
  - 🍏 **全平台终端适配**:原生支持 **macOS**(Terminal.app、iTerm2、Ghostty、WezTerm 等)、**Windows**(Windows Terminal、PowerShell)以及 **Linux**。
29
33
  - 🔒 **纯本地与隐私安全**:全链路通过本地环回地址 `127.0.0.1` 传输,无云端中转,零数据收集。
30
34
 
@@ -36,14 +40,16 @@
36
40
  sequenceDiagram
37
41
  autonumber
38
42
  actor User as 开发者
39
- participant Browser as Chrome 浏览器扩展
40
- participant Bridge as Bridge 调度守护进程 (:18090)
41
- participant Pi as Pi Agent 终端会话 (:18091)
42
-
43
- User->>Browser: 右键菜单点击 "发送给 Pi"
44
- Browser->>Bridge: HTTP POST /send (正文、URL、标题)
45
- alt Pi 正在运行
46
- Bridge->>Pi: 转发至 127.0.0.1:18091/receive
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
47
53
  Pi->>Pi: ctx.ui.setEditorText() (预填到输入框)
48
54
  Bridge-->>Browser: 200 OK (已填入输入框)
49
55
  else Pi 未运行 (冷启动模式)
@@ -68,6 +74,8 @@ pi install npm:send-to-pi
68
74
 
69
75
  *(或者通过 GitHub 安装: `pi install git:github.com/Wude-m/send-to-pi`)*
70
76
 
77
+ ### 第一步启动后,扩展会自动随 Pi 启动并在可用端口(18091~18095)监听接收。
78
+
71
79
  ### 第二步:启动 Bridge 守护进程
72
80
  调度守护进程负责在后台监听浏览器请求并在需要时唤醒终端:
73
81
 
@@ -101,15 +109,22 @@ npx send-to-pi extension
101
109
 
102
110
  ## ⌨️ 日常使用演示
103
111
 
104
- 1. **发送划选内容**:网页上鼠标选中任何代码或文本 ➔ 右键 ➔ 点击 `🚀 发送选中内容给 Pi`;
105
- 2. **发送整个网页**:在页面空白处 ➔ 右键 ➔ 点击 `🚀 发送当前网页给 Pi`;
106
- 3. **发送超链接**:在任意链接上 ➔ 右键 ➔ 点击 `🚀 发送此链接给 Pi`。
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`。
107
120
 
108
- 终端输入框中会立即呈现带有来源标题与 URL 的整洁内容:
121
+ 终端输入框中会立即呈现带有来源标题与 URL 的整洁 Markdown 内容:
109
122
  ```text
110
123
  【来源】:GitHub - earendil-works/pi-coding-agent (https://github.com/...)
111
124
 
112
- 这里是选中的代码片段或技术文档内容...
125
+ ```typescript
126
+ export default function (pi: ExtensionAPI) { ... }
127
+ ```
113
128
  _ [光标停在此处,等待你补充提示词]
114
129
  ```
115
130
 
@@ -122,7 +137,7 @@ _ [光标停在此处,等待你补充提示词]
122
137
  | 环境变量 | 默认值 | 说明 |
123
138
  | :--- | :--- | :--- |
124
139
  | `PI_BRIDGE_PORT` | `18090` | Bridge 调度进程监听的端口 |
125
- | `PI_INTERNAL_PORT` | `18091` | 活跃 Pi 会话内部接收端口 |
140
+ | `PI_INTERNAL_PORT` | `18091` | 活跃 Pi 会话内部起始端口(自动探测 18091~18095) |
126
141
  | `PI_WORKDIR` | 当前目录 | 自动唤醒 Pi 时默认进入的工作目录 |
127
142
  | `PI_TERMINAL` | 自动探测 | macOS/Linux 指定偏好终端(如 `iterm2`, `ghostty`, `terminal`, `alacritty`) |
128
143
 
@@ -133,6 +148,13 @@ PI_TERMINAL=ghostty PI_WORKDIR=~/mycode npx send-to-pi start
133
148
 
134
149
  ---
135
150
 
151
+ ## 🆕 v1.2.0 变更
152
+
153
+ - 修复 X/Twitter 文章提取,避免读取整个页面 body。
154
+ - 保留选中内容与链接发送模式。
155
+ - 新增多 Pi 会话注册表及最近健康会话路由。
156
+ - 注册会话预留 `activeAt`、`terminal`、`window` 字段。
157
+
136
158
  ## 🤝 欢迎贡献
137
159
 
138
160
  欢迎提交 PR 或 Issue!无论是: