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 +57 -105
- package/README_CN.md +57 -108
- package/chrome-extension/background.js +275 -56
- package/chrome-extension/manifest.json +10 -1
- package/chrome-extension/options.html +8 -2
- package/chrome-extension/options.js +22 -11
- package/chrome-extension/popup.html +160 -0
- package/chrome-extension/popup.js +145 -0
- package/package.json +3 -2
- package/pi-extension/README.md +9 -16
- package/pi-extension/index.ts +334 -37
- package/server/bin/send-to-pi.js +97 -42
- package/server/src/clipboard.js +53 -0
- package/server/src/config.js +107 -10
- package/server/src/index.js +190 -46
- package/server/src/launchers/custom.js +55 -0
- package/server/src/launchers/darwin.js +289 -45
- package/server/src/launchers/index.js +51 -8
- package/server/src/launchers/linux.js +60 -36
- package/server/src/launchers/win32.js +110 -43
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Send to Pi</title>
|
|
6
|
+
<style>
|
|
7
|
+
:root {
|
|
8
|
+
color-scheme: light dark;
|
|
9
|
+
--bg: #ffffff;
|
|
10
|
+
--card: #f5f7fa;
|
|
11
|
+
--border: #e2e8f0;
|
|
12
|
+
--text: #0f172a;
|
|
13
|
+
--muted: #64748b;
|
|
14
|
+
--accent: #2563eb;
|
|
15
|
+
--ok: #16a34a;
|
|
16
|
+
--warn: #d97706;
|
|
17
|
+
}
|
|
18
|
+
@media (prefers-color-scheme: dark) {
|
|
19
|
+
:root {
|
|
20
|
+
--bg: #111827;
|
|
21
|
+
--card: #1f2937;
|
|
22
|
+
--border: #374151;
|
|
23
|
+
--text: #f9fafb;
|
|
24
|
+
--muted: #9ca3af;
|
|
25
|
+
--accent: #60a5fa;
|
|
26
|
+
--ok: #4ade80;
|
|
27
|
+
--warn: #fbbf24;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
body {
|
|
31
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
|
|
32
|
+
background: var(--bg);
|
|
33
|
+
color: var(--text);
|
|
34
|
+
margin: 0;
|
|
35
|
+
padding: 14px 16px;
|
|
36
|
+
width: 320px;
|
|
37
|
+
box-sizing: border-box;
|
|
38
|
+
}
|
|
39
|
+
.header {
|
|
40
|
+
display: flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: space-between;
|
|
43
|
+
margin-bottom: 12px;
|
|
44
|
+
}
|
|
45
|
+
.title {
|
|
46
|
+
font-size: 15px;
|
|
47
|
+
font-weight: 700;
|
|
48
|
+
display: flex;
|
|
49
|
+
align-items: center;
|
|
50
|
+
gap: 6px;
|
|
51
|
+
}
|
|
52
|
+
.badge {
|
|
53
|
+
font-size: 11px;
|
|
54
|
+
padding: 2px 8px;
|
|
55
|
+
border-radius: 999px;
|
|
56
|
+
border: 1px solid var(--border);
|
|
57
|
+
background: var(--card);
|
|
58
|
+
color: var(--muted);
|
|
59
|
+
}
|
|
60
|
+
.badge.ok { color: var(--ok); border-color: var(--ok); }
|
|
61
|
+
.badge.warn { color: var(--warn); border-color: var(--warn); }
|
|
62
|
+
.section-label {
|
|
63
|
+
font-size: 11px;
|
|
64
|
+
font-weight: 600;
|
|
65
|
+
text-transform: uppercase;
|
|
66
|
+
letter-spacing: 0.04em;
|
|
67
|
+
color: var(--muted);
|
|
68
|
+
margin: 10px 0 6px;
|
|
69
|
+
}
|
|
70
|
+
.list {
|
|
71
|
+
display: flex;
|
|
72
|
+
flex-direction: column;
|
|
73
|
+
gap: 6px;
|
|
74
|
+
}
|
|
75
|
+
.item {
|
|
76
|
+
display: flex;
|
|
77
|
+
align-items: center;
|
|
78
|
+
justify-content: space-between;
|
|
79
|
+
padding: 8px 10px;
|
|
80
|
+
border-radius: 8px;
|
|
81
|
+
border: 1px solid var(--border);
|
|
82
|
+
background: var(--card);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font-size: 12px;
|
|
85
|
+
transition: border-color 0.15s;
|
|
86
|
+
}
|
|
87
|
+
.item:hover { border-color: var(--accent); }
|
|
88
|
+
.item.active {
|
|
89
|
+
border-color: var(--accent);
|
|
90
|
+
box-shadow: 0 0 0 1px var(--accent);
|
|
91
|
+
}
|
|
92
|
+
.item-main {
|
|
93
|
+
display: flex;
|
|
94
|
+
flex-direction: column;
|
|
95
|
+
gap: 2px;
|
|
96
|
+
min-width: 0;
|
|
97
|
+
}
|
|
98
|
+
.item-name {
|
|
99
|
+
font-weight: 600;
|
|
100
|
+
overflow: hidden;
|
|
101
|
+
text-overflow: ellipsis;
|
|
102
|
+
white-space: nowrap;
|
|
103
|
+
}
|
|
104
|
+
.item-sub {
|
|
105
|
+
font-size: 11px;
|
|
106
|
+
color: var(--muted);
|
|
107
|
+
overflow: hidden;
|
|
108
|
+
text-overflow: ellipsis;
|
|
109
|
+
white-space: nowrap;
|
|
110
|
+
}
|
|
111
|
+
.pill {
|
|
112
|
+
font-size: 11px;
|
|
113
|
+
color: var(--accent);
|
|
114
|
+
font-weight: 600;
|
|
115
|
+
flex-shrink: 0;
|
|
116
|
+
margin-left: 8px;
|
|
117
|
+
}
|
|
118
|
+
.empty {
|
|
119
|
+
font-size: 12px;
|
|
120
|
+
color: var(--muted);
|
|
121
|
+
padding: 10px;
|
|
122
|
+
border-radius: 8px;
|
|
123
|
+
border: 1px dashed var(--border);
|
|
124
|
+
text-align: center;
|
|
125
|
+
}
|
|
126
|
+
.footer {
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
justify-content: space-between;
|
|
130
|
+
margin-top: 12px;
|
|
131
|
+
padding-top: 10px;
|
|
132
|
+
border-top: 1px solid var(--border);
|
|
133
|
+
}
|
|
134
|
+
button.link {
|
|
135
|
+
background: none;
|
|
136
|
+
border: none;
|
|
137
|
+
color: var(--accent);
|
|
138
|
+
font-size: 12px;
|
|
139
|
+
cursor: pointer;
|
|
140
|
+
padding: 0;
|
|
141
|
+
}
|
|
142
|
+
button.link:hover { text-decoration: underline; }
|
|
143
|
+
</style>
|
|
144
|
+
</head>
|
|
145
|
+
<body>
|
|
146
|
+
<div class="header">
|
|
147
|
+
<div class="title">🚀 Send to Pi</div>
|
|
148
|
+
<div id="bridgeBadge" class="badge">Checking...</div>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div id="sectionLabel" class="section-label">Target Pi Session</div>
|
|
152
|
+
<div id="sessionList" class="list"></div>
|
|
153
|
+
|
|
154
|
+
<div class="footer">
|
|
155
|
+
<button id="refreshBtn" class="link">Refresh</button>
|
|
156
|
+
<button id="optionsBtn" class="link">Settings</button>
|
|
157
|
+
</div>
|
|
158
|
+
<script src="popup.js"></script>
|
|
159
|
+
</body>
|
|
160
|
+
</html>
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const DEFAULT_BRIDGE_PORT = 18090;
|
|
2
|
+
const DEFAULT_INTERNAL_PORT_START = 18091;
|
|
3
|
+
const INTERNAL_PORT_COUNT = 5;
|
|
4
|
+
const isChinese = (navigator.language || "").toLowerCase().startsWith("zh");
|
|
5
|
+
|
|
6
|
+
const t = {
|
|
7
|
+
targetLabel: isChinese ? "目标 Pi 会话" : "Target Pi Session",
|
|
8
|
+
bridgeOnline: isChinese ? "Bridge 在线" : "Bridge Online",
|
|
9
|
+
bridgeDirect: isChinese ? "直连模式 (无 Bridge)" : "Direct Mode (No Bridge)",
|
|
10
|
+
autoName: isChinese ? "自动路由(最近活跃)" : "Auto (Most Recent)",
|
|
11
|
+
autoSub: isChinese ? "优先发送到刚刚交互的 Pi 窗口" : "Routes to the most recently active Pi session",
|
|
12
|
+
empty: isChinese
|
|
13
|
+
? "未发现运行中的 Pi 会话。打开任意终端运行 pi 即可直连,或启动 Bridge 支持冷启动。"
|
|
14
|
+
: "No active Pi session found. Open Pi in any terminal for direct send, or start Bridge for cold-start.",
|
|
15
|
+
selected: isChinese ? "已选" : "Selected",
|
|
16
|
+
refresh: isChinese ? "刷新列表" : "Refresh",
|
|
17
|
+
settings: isChinese ? "端口设置" : "Settings",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
async function fetchJson(url, timeoutMs = 450) {
|
|
21
|
+
const controller = new AbortController();
|
|
22
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
25
|
+
if (!res.ok) return null;
|
|
26
|
+
return await res.json();
|
|
27
|
+
} catch (_err) {
|
|
28
|
+
return null;
|
|
29
|
+
} finally {
|
|
30
|
+
clearTimeout(timer);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function getSettings() {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
chrome.storage.sync.get(
|
|
37
|
+
{
|
|
38
|
+
bridgePort: DEFAULT_BRIDGE_PORT,
|
|
39
|
+
internalPortStart: DEFAULT_INTERNAL_PORT_START,
|
|
40
|
+
preferredPort: 0,
|
|
41
|
+
},
|
|
42
|
+
(items) => {
|
|
43
|
+
resolve({
|
|
44
|
+
bridgePort: Number(items.bridgePort) || DEFAULT_BRIDGE_PORT,
|
|
45
|
+
internalPortStart: Number(items.internalPortStart) || DEFAULT_INTERNAL_PORT_START,
|
|
46
|
+
preferredPort: Number(items.preferredPort) || 0,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function setPreferredPort(port) {
|
|
54
|
+
return new Promise((resolve) => {
|
|
55
|
+
chrome.storage.sync.set({ preferredPort: port }, resolve);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function basename(p) {
|
|
60
|
+
if (!p) return "Pi Session";
|
|
61
|
+
const clean = String(p).replace(/[\\/]+$/, "");
|
|
62
|
+
return clean.split(/[\\/]/).pop() || p;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function render() {
|
|
66
|
+
document.getElementById("sectionLabel").textContent = t.targetLabel;
|
|
67
|
+
document.getElementById("refreshBtn").textContent = t.refresh;
|
|
68
|
+
document.getElementById("optionsBtn").textContent = t.settings;
|
|
69
|
+
|
|
70
|
+
const { bridgePort, internalPortStart, preferredPort } = await getSettings();
|
|
71
|
+
const bridgeBadge = document.getElementById("bridgeBadge");
|
|
72
|
+
const listEl = document.getElementById("sessionList");
|
|
73
|
+
|
|
74
|
+
const ports = Array.from({ length: INTERNAL_PORT_COUNT }, (_, i) => internalPortStart + i);
|
|
75
|
+
const [bridgeHealth, ...piResults] = await Promise.all([
|
|
76
|
+
fetchJson(`http://127.0.0.1:${bridgePort}/health`, 500),
|
|
77
|
+
...ports.map(async (p) => {
|
|
78
|
+
const info = await fetchJson(`http://127.0.0.1:${p}/health`, 450);
|
|
79
|
+
return info && info.status === "alive" ? { ...info, port: p } : null;
|
|
80
|
+
}),
|
|
81
|
+
]);
|
|
82
|
+
|
|
83
|
+
if (bridgeHealth && bridgeHealth.status === "ok") {
|
|
84
|
+
bridgeBadge.textContent = t.bridgeOnline;
|
|
85
|
+
bridgeBadge.className = "badge ok";
|
|
86
|
+
} else {
|
|
87
|
+
bridgeBadge.textContent = t.bridgeDirect;
|
|
88
|
+
bridgeBadge.className = "badge warn";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const sessions = piResults
|
|
92
|
+
.filter(Boolean)
|
|
93
|
+
.sort((a, b) => Number(b.activeAt || b.updatedAt || 0) - Number(a.activeAt || a.updatedAt || 0));
|
|
94
|
+
|
|
95
|
+
listEl.innerHTML = "";
|
|
96
|
+
|
|
97
|
+
// Auto option
|
|
98
|
+
const autoItem = document.createElement("div");
|
|
99
|
+
autoItem.className = "item" + (preferredPort === 0 ? " active" : "");
|
|
100
|
+
autoItem.innerHTML = `
|
|
101
|
+
<div class="item-main">
|
|
102
|
+
<div class="item-name">${t.autoName}</div>
|
|
103
|
+
<div class="item-sub">${t.autoSub}</div>
|
|
104
|
+
</div>
|
|
105
|
+
${preferredPort === 0 ? `<span class="pill">${t.selected}</span>` : ""}
|
|
106
|
+
`;
|
|
107
|
+
autoItem.addEventListener("click", async () => {
|
|
108
|
+
await setPreferredPort(0);
|
|
109
|
+
render();
|
|
110
|
+
});
|
|
111
|
+
listEl.appendChild(autoItem);
|
|
112
|
+
|
|
113
|
+
if (sessions.length === 0) {
|
|
114
|
+
const empty = document.createElement("div");
|
|
115
|
+
empty.className = "empty";
|
|
116
|
+
empty.textContent = t.empty;
|
|
117
|
+
listEl.appendChild(empty);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
for (const s of sessions) {
|
|
122
|
+
const item = document.createElement("div");
|
|
123
|
+
const isSelected = preferredPort === s.port;
|
|
124
|
+
item.className = "item" + (isSelected ? " active" : "");
|
|
125
|
+
const termLabel = s.appName || s.terminal || "terminal";
|
|
126
|
+
item.innerHTML = `
|
|
127
|
+
<div class="item-main">
|
|
128
|
+
<div class="item-name">${basename(s.workdir)} · ${termLabel}</div>
|
|
129
|
+
<div class="item-sub">:${s.port} · ${s.workdir || ""}</div>
|
|
130
|
+
</div>
|
|
131
|
+
${isSelected ? `<span class="pill">${t.selected}</span>` : ""}
|
|
132
|
+
`;
|
|
133
|
+
item.addEventListener("click", async () => {
|
|
134
|
+
await setPreferredPort(s.port);
|
|
135
|
+
render();
|
|
136
|
+
});
|
|
137
|
+
listEl.appendChild(item);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
document.getElementById("refreshBtn").addEventListener("click", render);
|
|
142
|
+
document.getElementById("optionsBtn").addEventListener("click", () => {
|
|
143
|
+
chrome.runtime.openOptionsPage();
|
|
144
|
+
});
|
|
145
|
+
document.addEventListener("DOMContentLoaded", render);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "send-to-pi",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Send webpage snippets, URLs, or articles directly to your local Pi coding agent terminal.",
|
|
5
5
|
"main": "server/src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"start": "node server/src/index.js",
|
|
11
11
|
"status": "node server/bin/send-to-pi.js status",
|
|
12
|
+
"config": "node server/bin/send-to-pi.js config",
|
|
12
13
|
"extension": "node server/bin/send-to-pi.js extension",
|
|
13
|
-
"test": "node
|
|
14
|
+
"test": "node --test test/*.test.js"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
16
17
|
"pi-package",
|
package/pi-extension/README.md
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
1
1
|
# send-to-pi: Pi Coding Agent Extension
|
|
2
2
|
|
|
3
|
-
这是 `send-to-pi` 运行在 Pi coding agent
|
|
3
|
+
这是 `send-to-pi` 运行在 Pi coding agent 端的核心扩展(v1.3.0)。
|
|
4
4
|
|
|
5
5
|
## 作用
|
|
6
|
-
1.
|
|
7
|
-
2.
|
|
8
|
-
3.
|
|
9
|
-
4.
|
|
6
|
+
1. 自动探测并监听本地内部端口 `127.0.0.1:18091~18095`,支持 **Chrome 扩展零 Daemon 直连**与 Bridge 转发两种模式;
|
|
7
|
+
2. 自动识别当前宿主终端(Rex、Ghostty、iTerm2、Warp、WezTerm、kitty、Alacritty、VS Code、Cursor、Windows Terminal、Terminal.app 等),将活跃会话写入 `~/.pi/send-to-pi/sessions.json`,并将最近使用的终端环境持久化到 `~/.pi/send-to-pi/last-terminal.json`;
|
|
8
|
+
3. 监听 `session_start`、`input`、`agent_start` 事件实时更新 `activeAt`,多开窗口时精准路由到用户刚刚交互的会话;
|
|
9
|
+
4. 收到内容后通过 Pi 原生 API `ctx.ui.setEditorText()` **预填到终端输入框(Prefill 模式,绝不自动回车)**;
|
|
10
|
+
5. 会话启动时自动消费冷启动暂存文件(`~/.pi/pending-browser-input.txt`)。
|
|
10
11
|
|
|
11
12
|
## 安装方式
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
推荐直接使用 Pi 内置包管理器安装:
|
|
14
15
|
|
|
15
|
-
### macOS / Linux
|
|
16
16
|
```bash
|
|
17
|
-
|
|
18
|
-
cp index.ts ~/.pi/agent/extensions/send-to-pi.ts
|
|
17
|
+
pi install npm:send-to-pi
|
|
19
18
|
```
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
```powershell
|
|
23
|
-
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.pi\agent\extensions"
|
|
24
|
-
Copy-Item index.ts "$env:USERPROFILE\.pi\agent\extensions\send-to-pi.ts"
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
重启 `pi` 会话后即可自动加载!
|
|
20
|
+
或手动复制 `index.ts` 到 `~/.pi/agent/extensions/send-to-pi.ts` 后重启 `pi`。
|