@chatpanel/bridge 0.1.2 → 0.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
@@ -14,22 +14,38 @@ the ones the bridge reports as available.
14
14
 
15
15
  ## Run it
16
16
 
17
- **No clone, no install** `npx` fetches the package (and its one dependency) and
18
- starts the server:
17
+ ### Option Adownload the app (no Node.js needed)
18
+
19
+ Grab the standalone binary for your OS from the
20
+ [latest release](https://github.com/chatpanel/chatpanel-bridge/releases/latest) —
21
+ it bundles its own runtime, so **nothing to install**. Run it once to set it up to
22
+ start automatically at login and run in the background:
19
23
 
20
24
  ```bash
21
- npx @chatpanel/bridge # http://127.0.0.1:4319
25
+ # macOS / Linux (make it executable first on macOS)
26
+ chmod +x chatpanel-bridge-macos-arm64
27
+ ./chatpanel-bridge-macos-arm64 --install
28
+
29
+ # Windows (PowerShell)
30
+ .\chatpanel-bridge-windows-x64.exe --install
22
31
  ```
23
32
 
24
- …then leave it running and open the ChatPanel side panel. That's the whole setup.
33
+ That's it open the ChatPanel side panel and your agents appear. Manage it with
34
+ `--status` (is it set up?) and `--uninstall` (remove auto-start). Run with no flags
35
+ to start it once in the foreground instead.
25
36
 
26
- Prefer a persistent command? Install it globally:
37
+ > Until these binaries are code-signed, macOS Gatekeeper / Windows SmartScreen may
38
+ > warn on first run (on macOS, right-click the file → **Open**). Signing is on the way.
39
+
40
+ ### Option B — via npm (needs Node.js 18+)
27
41
 
28
42
  ```bash
29
- npm i -g @chatpanel/bridge
30
- chatpanel-bridge # → http://127.0.0.1:4319
43
+ npx @chatpanel/bridge # → http://127.0.0.1:4319
31
44
  ```
32
45
 
46
+ …then leave it running and open the ChatPanel side panel. Prefer a persistent
47
+ command? `npm i -g @chatpanel/bridge` then `chatpanel-bridge`.
48
+
33
49
  Prerequisites (the agents you want to use must already be set up):
34
50
 
35
51
  - **Claude Code**: be signed in (`claude`) or set `ANTHROPIC_API_KEY`.
package/package.json CHANGED
@@ -1,18 +1,40 @@
1
1
  {
2
2
  "name": "@chatpanel/bridge",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (Agent SDK), Codex (CLI), and Gemini CLI — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
6
- "keywords": ["chatpanel", "claude-code", "codex", "gemini-cli", "chrome-extension", "ai-agents", "bridge"],
6
+ "keywords": [
7
+ "chatpanel",
8
+ "claude-code",
9
+ "codex",
10
+ "gemini-cli",
11
+ "chrome-extension",
12
+ "ai-agents",
13
+ "bridge"
14
+ ],
7
15
  "homepage": "https://chatpanel.net",
8
- "repository": { "type": "git", "url": "git+https://github.com/chatpanel/chatpanel-bridge.git" },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/chatpanel/chatpanel-bridge.git"
19
+ },
9
20
  "license": "MIT",
10
- "bin": { "chatpanel-bridge": "src/server.js" },
11
- "files": ["src", "README.md", "LICENSE", ".env.example"],
12
- "engines": { "node": ">=18" },
21
+ "bin": {
22
+ "chatpanel-bridge": "src/server.js"
23
+ },
24
+ "files": [
25
+ "src",
26
+ "scripts",
27
+ "README.md",
28
+ "LICENSE",
29
+ ".env.example"
30
+ ],
31
+ "engines": {
32
+ "node": ">=18"
33
+ },
13
34
  "scripts": {
14
35
  "start": "node src/server.js",
15
- "dev": "node --watch src/server.js"
36
+ "dev": "node --watch src/server.js",
37
+ "build:bin": "bash scripts/build-binaries.sh"
16
38
  },
17
39
  "dependencies": {
18
40
  "@anthropic-ai/claude-agent-sdk": "^0.1.0"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ # Compile the bridge into standalone, single-file binaries (no Node required to
3
+ # run them). Needs Bun: https://bun.sh
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+ mkdir -p dist
7
+ rm -f dist/chatpanel-bridge-*
8
+
9
+ targets=(
10
+ "bun-darwin-arm64:chatpanel-bridge-macos-arm64"
11
+ "bun-darwin-x64:chatpanel-bridge-macos-x64"
12
+ "bun-linux-x64:chatpanel-bridge-linux-x64"
13
+ "bun-windows-x64:chatpanel-bridge-windows-x64.exe"
14
+ )
15
+ for t in "${targets[@]}"; do
16
+ target="${t%%:*}"; out="${t##*:}"
17
+ echo "→ building dist/$out ($target)"
18
+ bun build src/server.js --compile --target="$target" --outfile "dist/$out"
19
+ done
20
+ echo "✓ binaries in dist/"
21
+ ls -la dist
package/src/server.js CHANGED
@@ -18,8 +18,9 @@ import { createServer } from 'node:http';
18
18
  import * as claude from './engines/claude.js';
19
19
  import * as codex from './engines/codex.js';
20
20
  import * as gemini from './engines/gemini.js';
21
+ import { installService, uninstallService, serviceStatus } from './service.js';
21
22
 
22
- const VERSION = '0.1.0';
23
+ const VERSION = '0.2.0';
23
24
  const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
24
25
  const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
25
26
 
@@ -145,11 +146,74 @@ function log(level, msg) {
145
146
  fn(`[chatpanel-bridge] ${msg}`);
146
147
  }
147
148
 
148
- server.listen(PORT, HOST, async () => {
149
- log('info', `listening on http://${HOST}:${PORT}`);
150
- for (const [id, { engine, label }] of Object.entries(ENGINES)) {
151
- const a = await engine.available().catch(() => ({ ok: false }));
152
- log('info', ` ${a.ok ? '✓' : '✕'} ${label}${a.ok ? '' : ' — ' + (a.reason || 'unavailable')}`);
149
+ function startServer() {
150
+ server.listen(PORT, HOST, async () => {
151
+ log('info', `listening on http://${HOST}:${PORT}`);
152
+ for (const [, { engine, label }] of Object.entries(ENGINES)) {
153
+ const a = await engine.available().catch(() => ({ ok: false }));
154
+ log('info', ` ${a.ok ? '✓' : '✕'} ${label}${a.ok ? '' : ' — ' + (a.reason || 'unavailable')}`);
155
+ }
156
+ log('info', 'Open the ChatPanel side panel; installed agents (Claude Code, Codex, Gemini CLI) appear automatically.');
157
+ });
158
+ }
159
+
160
+ function printHelp() {
161
+ console.log(`ChatPanel Bridge v${VERSION}
162
+
163
+ Usage:
164
+ chatpanel-bridge start the bridge (foreground) on ${HOST}:${PORT}
165
+ chatpanel-bridge --install run automatically at login, in the background
166
+ chatpanel-bridge --uninstall remove the login auto-start
167
+ chatpanel-bridge --status show whether auto-start is set up
168
+ chatpanel-bridge --version print the version
169
+
170
+ Env: CHATPANEL_BRIDGE_HOST, CHATPANEL_BRIDGE_PORT`);
171
+ }
172
+
173
+ // Handle CLI commands before starting the server. Returns true if a command ran.
174
+ function runCli() {
175
+ const argv = process.argv;
176
+ const has = (...flags) => flags.some((f) => argv.includes(f));
177
+
178
+ if (has('--help', '-h')) {
179
+ printHelp();
180
+ return true;
153
181
  }
154
- log('info', 'Open the ChatPanel side panel; installed agents (Claude Code, Codex, Gemini CLI) appear automatically.');
155
- });
182
+ if (has('--version', '-v')) {
183
+ console.log(VERSION);
184
+ return true;
185
+ }
186
+ if (has('--install')) {
187
+ try {
188
+ installService();
189
+ log('info', 'Installed. The bridge now starts automatically at login and is running in the background.');
190
+ } catch (e) {
191
+ log('error', 'Install failed: ' + (e?.message || e));
192
+ process.exitCode = 1;
193
+ }
194
+ return true;
195
+ }
196
+ if (has('--uninstall')) {
197
+ try {
198
+ uninstallService();
199
+ log('info', 'Removed the login auto-start.');
200
+ } catch (e) {
201
+ log('error', 'Uninstall failed: ' + (e?.message || e));
202
+ process.exitCode = 1;
203
+ }
204
+ return true;
205
+ }
206
+ if (has('--status')) {
207
+ let on = false;
208
+ try {
209
+ on = serviceStatus();
210
+ } catch (e) {
211
+ log('error', String(e?.message || e));
212
+ }
213
+ log('info', `auto-start: ${on ? 'installed' : 'not installed'}`);
214
+ return true;
215
+ }
216
+ return false;
217
+ }
218
+
219
+ if (!runCli()) startServer();
package/src/service.js ADDED
@@ -0,0 +1,147 @@
1
+ // Background auto-start for the ChatPanel Bridge.
2
+ //
3
+ // So non-technical users never touch a terminal: download the app, run it once
4
+ // with --install, and it launches at login and stays running.
5
+ //
6
+ // chatpanel-bridge --install register login auto-start + start now
7
+ // chatpanel-bridge --uninstall remove it
8
+ // chatpanel-bridge --status is it registered?
9
+ //
10
+ // macOS → LaunchAgent · Windows → Scheduled Task (ONLOGON) · Linux → systemd user.
11
+
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ import { mkdirSync, writeFileSync, rmSync, existsSync } from 'node:fs';
15
+ import { spawnSync } from 'node:child_process';
16
+
17
+ const LABEL = 'net.chatpanel.bridge';
18
+ const DISPLAY = 'ChatPanel Bridge';
19
+
20
+ // The command that launches THIS bridge. A compiled single-file binary launches
21
+ // itself (no args); running under node/bun launches the interpreter + this script.
22
+ export function resolveLaunch() {
23
+ const exe = process.execPath;
24
+ const base = path.basename(exe).toLowerCase();
25
+ const underInterpreter = base.startsWith('node') || base.startsWith('bun');
26
+ if (underInterpreter && process.argv[1]) {
27
+ return { program: exe, args: [path.resolve(process.argv[1])] };
28
+ }
29
+ return { program: exe, args: [] };
30
+ }
31
+
32
+ function logPaths() {
33
+ const dir = path.join(os.homedir(), '.chatpanel');
34
+ mkdirSync(dir, { recursive: true });
35
+ return { out: path.join(dir, 'bridge.log'), err: path.join(dir, 'bridge.err.log') };
36
+ }
37
+
38
+ function run(cmd, args, opts = {}) {
39
+ return spawnSync(cmd, args, { encoding: 'utf8', ...opts });
40
+ }
41
+
42
+ // ---------------------------------------------------------------- macOS
43
+ const macPlist = () => path.join(os.homedir(), 'Library', 'LaunchAgents', `${LABEL}.plist`);
44
+
45
+ function macInstall() {
46
+ const { program, args } = resolveLaunch();
47
+ const { out, err } = logPaths();
48
+ const progArgs = [program, ...args].map((a) => ` <string>${a}</string>`).join('\n');
49
+ const plist = `<?xml version="1.0" encoding="UTF-8"?>
50
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
51
+ <plist version="1.0">
52
+ <dict>
53
+ <key>Label</key><string>${LABEL}</string>
54
+ <key>ProgramArguments</key>
55
+ <array>
56
+ ${progArgs}
57
+ </array>
58
+ <key>RunAtLoad</key><true/>
59
+ <key>KeepAlive</key><true/>
60
+ <key>StandardOutPath</key><string>${out}</string>
61
+ <key>StandardErrorPath</key><string>${err}</string>
62
+ </dict>
63
+ </plist>
64
+ `;
65
+ const p = macPlist();
66
+ mkdirSync(path.dirname(p), { recursive: true });
67
+ writeFileSync(p, plist);
68
+ run('launchctl', ['unload', p]); // ignore if not loaded
69
+ const r = run('launchctl', ['load', '-w', p]);
70
+ if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'launchctl load failed');
71
+ }
72
+ function macUninstall() {
73
+ const p = macPlist();
74
+ run('launchctl', ['unload', '-w', p]);
75
+ if (existsSync(p)) rmSync(p);
76
+ }
77
+ function macStatus() {
78
+ return (run('launchctl', ['list']).stdout || '').includes(LABEL);
79
+ }
80
+
81
+ // ---------------------------------------------------------------- Windows
82
+ const WIN_TASK = 'ChatPanelBridge';
83
+
84
+ function winInstall() {
85
+ const { program, args } = resolveLaunch();
86
+ const tr = [`"${program}"`, ...args.map((a) => `"${a}"`)].join(' ');
87
+ const r = run('schtasks', ['/Create', '/TN', WIN_TASK, '/TR', tr, '/SC', 'ONLOGON', '/RL', 'LIMITED', '/F']);
88
+ if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'schtasks create failed');
89
+ run('schtasks', ['/Run', '/TN', WIN_TASK]); // start now
90
+ }
91
+ function winUninstall() {
92
+ run('schtasks', ['/Delete', '/TN', WIN_TASK, '/F']);
93
+ }
94
+ function winStatus() {
95
+ return run('schtasks', ['/Query', '/TN', WIN_TASK]).status === 0;
96
+ }
97
+
98
+ // ---------------------------------------------------------------- Linux (systemd user)
99
+ const linUnit = () => path.join(os.homedir(), '.config', 'systemd', 'user', 'chatpanel-bridge.service');
100
+
101
+ function linInstall() {
102
+ const { program, args } = resolveLaunch();
103
+ const exec = [program, ...args].map((a) => (/\s/.test(a) ? `"${a}"` : a)).join(' ');
104
+ const unit = `[Unit]
105
+ Description=${DISPLAY}
106
+ After=network.target
107
+
108
+ [Service]
109
+ ExecStart=${exec}
110
+ Restart=on-failure
111
+
112
+ [Install]
113
+ WantedBy=default.target
114
+ `;
115
+ const p = linUnit();
116
+ mkdirSync(path.dirname(p), { recursive: true });
117
+ writeFileSync(p, unit);
118
+ run('systemctl', ['--user', 'daemon-reload']);
119
+ const r = run('systemctl', ['--user', 'enable', '--now', 'chatpanel-bridge']);
120
+ if (r.status !== 0) throw new Error((r.stderr || '').trim() || 'systemctl enable failed');
121
+ }
122
+ function linUninstall() {
123
+ run('systemctl', ['--user', 'disable', '--now', 'chatpanel-bridge']);
124
+ const p = linUnit();
125
+ if (existsSync(p)) rmSync(p);
126
+ }
127
+ function linStatus() {
128
+ return (run('systemctl', ['--user', 'is-enabled', 'chatpanel-bridge']).stdout || '').trim() === 'enabled';
129
+ }
130
+
131
+ // ---------------------------------------------------------------- dispatch
132
+ function byPlatform(mac, win, lin) {
133
+ if (process.platform === 'darwin') return mac();
134
+ if (process.platform === 'win32') return win();
135
+ if (process.platform === 'linux') return lin();
136
+ throw new Error(`Auto-start isn't supported on ${process.platform} yet — run the bridge directly.`);
137
+ }
138
+
139
+ export function installService() {
140
+ return byPlatform(macInstall, winInstall, linInstall);
141
+ }
142
+ export function uninstallService() {
143
+ return byPlatform(macUninstall, winUninstall, linUninstall);
144
+ }
145
+ export function serviceStatus() {
146
+ return byPlatform(macStatus, winStatus, linStatus);
147
+ }