peer-bridge 0.0.0-stage → 0.6.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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.ko.md +134 -0
  3. package/README.md +161 -2
  4. package/adapters/antigravity/bin/agy-hook.mjs +24 -0
  5. package/adapters/antigravity/hooks.json +23 -0
  6. package/adapters/antigravity/mcp_config.json +8 -0
  7. package/adapters/antigravity/plugin.json +4 -0
  8. package/adapters/antigravity/rules/AGENTS.md +6 -0
  9. package/adapters/antigravity/skills/peer-bridge/SKILL.md +19 -0
  10. package/adapters/claude/.claude-plugin/plugin.json +5 -0
  11. package/adapters/claude/.mcp.json +8 -0
  12. package/adapters/claude/bin/cc-hook.mjs +20 -0
  13. package/adapters/claude/hooks/hooks.json +46 -0
  14. package/adapters/claude/skills/peer-bridge/SKILL.md +18 -0
  15. package/adapters/codex/bin/codex-hook.mjs +10 -0
  16. package/adapters/codex/config.toml.example +5 -0
  17. package/adapters/codex/hooks.json +44 -0
  18. package/adapters/codex/skills/peer-bridge/SKILL.md +12 -0
  19. package/adapters/gemini/bin/gemini-hook.mjs +10 -0
  20. package/adapters/gemini/settings.json +51 -0
  21. package/adapters/gemini/skills/peer-bridge/SKILL.md +12 -0
  22. package/adapters/paseo/SKILL.md +24 -0
  23. package/bin/pbridge-mcp.mjs +37 -0
  24. package/bin/pbridge-tui.mjs +7 -0
  25. package/bin/pbridge.mjs +5 -0
  26. package/bin/pbridged.mjs +16 -0
  27. package/package.json +42 -4
  28. package/src/adapters/antigravity/hooks.mjs +207 -0
  29. package/src/adapters/claude/hooks.mjs +204 -0
  30. package/src/adapters/codex/hooks.mjs +142 -0
  31. package/src/adapters/gemini/hooks.mjs +159 -0
  32. package/src/adapters/installer.mjs +328 -0
  33. package/src/cli/main.mjs +729 -0
  34. package/src/client/rpc.mjs +243 -0
  35. package/src/config.mjs +154 -0
  36. package/src/daemon/broker.mjs +1799 -0
  37. package/src/daemon/resolver.mjs +200 -0
  38. package/src/daemon/server.mjs +221 -0
  39. package/src/index.mjs +53 -0
  40. package/src/mcp/server.mjs +668 -0
  41. package/src/orchestrator/workflows.mjs +496 -0
  42. package/src/project.mjs +81 -0
  43. package/src/protocol.mjs +203 -0
  44. package/src/runtime/conv-api.mjs +101 -0
  45. package/src/runtime/host-discovery.mjs +635 -0
  46. package/src/runtime/native-claude.mjs +88 -0
  47. package/src/runtime/paseo.mjs +289 -0
  48. package/src/runtime/workers.mjs +751 -0
  49. package/src/storage/db.mjs +704 -0
  50. package/src/tui/render.mjs +472 -0
  51. package/src/tui/viewer.mjs +443 -0
@@ -0,0 +1,88 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { isProcessAlive } from '../config.mjs';
4
+
5
+ function safeReadJson(filePath) {
6
+ try {
7
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
8
+ } catch {
9
+ return null;
10
+ }
11
+ }
12
+
13
+ export function scanNativeClaudePeers(claudeDir, { skipPidCheck = false } = {}) {
14
+ const peers = [];
15
+ if (!claudeDir || !fs.existsSync(claudeDir)) return peers;
16
+
17
+ const sessionsDir = path.join(claudeDir, 'sessions');
18
+ if (fs.existsSync(sessionsDir)) {
19
+ let entries = [];
20
+ try {
21
+ entries = fs.readdirSync(sessionsDir);
22
+ } catch {
23
+ entries = [];
24
+ }
25
+ for (const file of entries) {
26
+ if (!file.endsWith('.json')) continue;
27
+ const data = safeReadJson(path.join(sessionsDir, file));
28
+ if (!data) continue;
29
+ const pid = Number(data.pid);
30
+ if (!skipPidCheck && Number.isInteger(pid) && pid > 0 && !isProcessAlive(pid)) {
31
+ continue;
32
+ }
33
+ const sessionId = data.sessionId || data.session_id || file.replace(/\.json$/, '');
34
+ const name = data.name || data.agentName || null;
35
+ peers.push({
36
+ source: 'claude-session',
37
+ runtime: 'cc',
38
+ id: sessionId,
39
+ name: name || sessionId.slice(0, 8),
40
+ raw_name: name,
41
+ pid: Number.isInteger(pid) ? pid : null,
42
+ cwd: data.cwd || null,
43
+ status: data.status || 'active',
44
+ kind: data.kind || 'session',
45
+ });
46
+ }
47
+ }
48
+
49
+ const teamsDir = path.join(claudeDir, 'teams');
50
+ if (fs.existsSync(teamsDir)) {
51
+ let teamDirs = [];
52
+ try {
53
+ teamDirs = fs.readdirSync(teamsDir);
54
+ } catch {
55
+ teamDirs = [];
56
+ }
57
+ for (const team of teamDirs) {
58
+ const cfg = safeReadJson(path.join(teamsDir, team, 'config.json'));
59
+ if (!cfg || !Array.isArray(cfg.members)) continue;
60
+ for (const member of cfg.members) {
61
+ if (!member?.name) continue;
62
+ peers.push({
63
+ source: 'claude-team',
64
+ runtime: 'cc',
65
+ id: member.agentId || `${team}/${member.name}`,
66
+ name: member.name,
67
+ raw_name: member.name,
68
+ team,
69
+ status: member.status || 'active',
70
+ kind: 'teammate',
71
+ });
72
+ }
73
+ }
74
+ }
75
+
76
+ return peers;
77
+ }
78
+
79
+ export function matchNativeClaudePeers(nativePeers, query) {
80
+ const q = String(query || '').trim();
81
+ if (!q) return [];
82
+ const exactName = nativePeers.filter((p) => p.raw_name === q || p.name === q);
83
+ if (exactName.length) return exactName;
84
+ if (q.length >= 6) {
85
+ return nativePeers.filter((p) => p.id && p.id.startsWith(q));
86
+ }
87
+ return [];
88
+ }
@@ -0,0 +1,289 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { execFile } from 'node:child_process';
3
+ import { promisify } from 'node:util';
4
+ import { resolveRuntimeBin } from '../config.mjs';
5
+ import { RpcError } from '../protocol.mjs';
6
+
7
+ const execFileAsync = promisify(execFile);
8
+
9
+ function parsePaseoJson(raw) {
10
+ const txt = String(raw || '').trim();
11
+ if (!txt) return {};
12
+ try {
13
+ return JSON.parse(txt);
14
+ } catch {
15
+ const firstBrace = txt.indexOf('{');
16
+ const firstBracket = txt.indexOf('[');
17
+ const start =
18
+ firstBrace === -1
19
+ ? firstBracket
20
+ : firstBracket === -1
21
+ ? firstBrace
22
+ : Math.min(firstBrace, firstBracket);
23
+ if (start >= 0) {
24
+ try {
25
+ return JSON.parse(txt.slice(start));
26
+ } catch {
27
+ // fall through
28
+ }
29
+ }
30
+ return { raw: txt };
31
+ }
32
+ }
33
+
34
+ export class PaseoClient {
35
+ constructor({ paseoBin = resolveRuntimeBin('paseo'), host = null, home = null, execFn = null } = {}) {
36
+ this.paseoBin = paseoBin;
37
+ this.host = host || null;
38
+ this.home = home || null;
39
+ this.execFn =
40
+ execFn ||
41
+ (async (bin, args, opts) => {
42
+ try {
43
+ const { stdout, stderr } = await execFileAsync(bin, args, {
44
+ maxBuffer: 16 * 1024 * 1024,
45
+ timeout: opts?.timeoutMs || 180_000,
46
+ cwd: opts?.cwd || process.cwd(),
47
+ env: { ...process.env, ...(opts?.env || {}) },
48
+ ...(process.platform === 'win32'
49
+ ? { windowsHide: true, shell: /\.(cmd|bat)$/i.test(String(bin || '')) }
50
+ : {}),
51
+ });
52
+ return { code: 0, stdout, stderr };
53
+ } catch (err) {
54
+ return {
55
+ code: typeof err.code === 'number' ? err.code : 1,
56
+ stdout: err.stdout || '',
57
+ stderr: err.stderr || err.message || '',
58
+ };
59
+ }
60
+ });
61
+ }
62
+
63
+ _globalFlags() {
64
+ const flags = ['--json'];
65
+ if (this.host) flags.push('--host', this.host);
66
+ if (this.home) flags.push('--home', this.home);
67
+ return flags;
68
+ }
69
+
70
+ async _exec(subArgs, opts = {}) {
71
+ const args = [...this._globalFlags(), ...subArgs];
72
+ const res = await this.execFn(this.paseoBin, args, opts);
73
+ const parsed = parsePaseoJson(res.stdout || res.stderr);
74
+ if (parsed?.error) {
75
+ const code =
76
+ parsed.error.code === 'DAEMON_NOT_RUNNING'
77
+ ? 'PASEO_DAEMON_UNAVAILABLE'
78
+ : parsed.error.code || 'PASEO_ERROR';
79
+ throw new RpcError(code, parsed.error.message || 'Paseo CLI error', parsed.error);
80
+ }
81
+ if (res.code !== 0) {
82
+ const msg = (res.stderr || res.stdout || `paseo exited with code ${res.code}`).trim();
83
+ throw new RpcError('PASEO_ERROR', msg);
84
+ }
85
+ return parsed;
86
+ }
87
+
88
+ async listAgents({ cwd = null, includeAll = false, global = false } = {}) {
89
+ const args = ['ls'];
90
+ if (includeAll) args.push('--all');
91
+ if (global || !cwd) args.push('--global');
92
+ const out = await this._exec(args, { cwd: cwd || process.cwd(), timeoutMs: 15_000 });
93
+ const agents = Array.isArray(out)
94
+ ? out
95
+ : Array.isArray(out.agents)
96
+ ? out.agents
97
+ : Array.isArray(out.items)
98
+ ? out.items
99
+ : [];
100
+ if (cwd) {
101
+ return agents.filter((a) => !a.cwd || a.cwd === cwd);
102
+ }
103
+ return agents;
104
+ }
105
+
106
+ async inspectAgent(agentId) {
107
+ return this._exec(['inspect', agentId], { timeoutMs: 15_000 });
108
+ }
109
+
110
+ async runAgent({
111
+ prompt,
112
+ title = null,
113
+ provider = null,
114
+ model = null,
115
+ mode = null,
116
+ workspaceId = null,
117
+ cwd = null,
118
+ labels = [],
119
+ wait = true,
120
+ waitTimeout = null,
121
+ timeoutMs = 180_000,
122
+ } = {}) {
123
+ const args = ['run'];
124
+ if (!wait) args.push('--no-wait');
125
+ if (title) args.push('--title', title);
126
+ if (provider) args.push('--provider', provider);
127
+ if (model) args.push('--model', model);
128
+ if (mode) args.push('--mode', mode);
129
+ if (workspaceId) args.push('--workspace', workspaceId);
130
+ if (cwd) args.push('--cwd', cwd);
131
+ if (waitTimeout) args.push('--wait-timeout', waitTimeout);
132
+ for (const lbl of labels) {
133
+ args.push('--label', lbl);
134
+ }
135
+ args.push('--', String(prompt || ''));
136
+ return this._exec(args, { cwd: cwd || process.cwd(), timeoutMs });
137
+ }
138
+
139
+ async sendAgentPrompt({
140
+ agentId,
141
+ prompt,
142
+ behavior = 'steer',
143
+ wait = true,
144
+ timeoutMs = 180_000,
145
+ } = {}) {
146
+ const args = ['send', '--behavior', behavior];
147
+ if (!wait) args.push('--no-wait');
148
+ args.push(agentId, '--prompt', String(prompt || ''));
149
+ return this._exec(args, { timeoutMs });
150
+ }
151
+
152
+ async stopAgent(agentId) {
153
+ return this._exec(['stop', agentId], { timeoutMs: 15_000 });
154
+ }
155
+
156
+ async deleteAgent(agentId) {
157
+ return this._exec(['delete', agentId], { timeoutMs: 15_000 });
158
+ }
159
+ }
160
+
161
+ function extractPaseoAgentId(res) {
162
+ return (
163
+ res?.agentId ||
164
+ res?.agent_id ||
165
+ res?.id ||
166
+ res?.agent?.agentId ||
167
+ res?.agent?.id ||
168
+ null
169
+ );
170
+ }
171
+
172
+ function extractPaseoResponse(res) {
173
+ if (typeof res === 'string') return res;
174
+ if (!res || typeof res !== 'object') return '';
175
+ const direct =
176
+ res.response ??
177
+ res.output ??
178
+ res.result ??
179
+ res.lastMessage ??
180
+ res.last_message ??
181
+ res.message ??
182
+ res.text;
183
+ if (typeof direct === 'string') return direct;
184
+ if (direct && typeof direct === 'object' && typeof direct.content === 'string') {
185
+ return direct.content;
186
+ }
187
+ return JSON.stringify(res);
188
+ }
189
+
190
+ export class PaseoAgentWorker extends EventEmitter {
191
+ constructor({
192
+ peerId,
193
+ name,
194
+ client,
195
+ sessionId = null,
196
+ provider = null,
197
+ model = null,
198
+ agentMode = null,
199
+ workspaceId = null,
200
+ cwd = null,
201
+ behavior = 'steer',
202
+ wait = true,
203
+ }) {
204
+ super();
205
+ this.peerId = peerId;
206
+ this.name = name;
207
+ this.runtime = 'paseo';
208
+ this.client = client;
209
+ this.sessionId = sessionId || null;
210
+ this.provider = provider || null;
211
+ this.model = model || null;
212
+ this.agentMode = agentMode || null;
213
+ this.workspaceId = workspaceId || null;
214
+ this.cwd = cwd || process.cwd();
215
+ this.behavior = behavior || 'steer';
216
+ this.wait = wait !== false;
217
+ this.closed = false;
218
+ this.pid = null;
219
+ this.turnQueue = Promise.resolve();
220
+ }
221
+
222
+ start() {
223
+ if (this.sessionId) {
224
+ queueMicrotask(() => this.emit('session_id', this.sessionId));
225
+ }
226
+ return this;
227
+ }
228
+
229
+ sendTurn(content, { timeoutMs = 180_000, behavior = null, wait = null } = {}) {
230
+ const run = async () => {
231
+ if (this.closed) {
232
+ throw new Error('paseo worker is closed');
233
+ }
234
+ this.emit('turn_start', { content });
235
+ const effectiveWait = wait !== null ? Boolean(wait) : this.wait;
236
+ const effectiveBehavior = behavior || this.behavior;
237
+
238
+ let raw;
239
+ if (!this.sessionId) {
240
+ raw = await this.client.runAgent({
241
+ prompt: content,
242
+ title: `peer-bridge:${this.name}`,
243
+ provider: this.provider,
244
+ model: this.model,
245
+ mode: this.agentMode,
246
+ workspaceId: this.workspaceId,
247
+ cwd: this.cwd,
248
+ labels: ['peer-bridge=spawned'],
249
+ wait: effectiveWait,
250
+ timeoutMs,
251
+ });
252
+ const agentId = extractPaseoAgentId(raw);
253
+ if (agentId) {
254
+ this.sessionId = agentId;
255
+ this.emit('session_id', agentId);
256
+ }
257
+ } else {
258
+ raw = await this.client.sendAgentPrompt({
259
+ agentId: this.sessionId,
260
+ prompt: content,
261
+ behavior: effectiveBehavior,
262
+ wait: effectiveWait,
263
+ timeoutMs,
264
+ });
265
+ }
266
+
267
+ const result = {
268
+ status: raw?.status === 'error' || raw?.is_error ? 'ERROR' : 'DONE',
269
+ is_error: Boolean(raw?.status === 'error' || raw?.is_error),
270
+ error: raw?.error?.message || (raw?.is_error ? String(raw.error || 'paseo error') : null),
271
+ response: extractPaseoResponse(raw),
272
+ session_id: this.sessionId,
273
+ raw,
274
+ };
275
+ this.emit('turn_result', result);
276
+ return result;
277
+ };
278
+
279
+ const next = this.turnQueue.then(run, run);
280
+ this.turnQueue = next.catch(() => {});
281
+ return next;
282
+ }
283
+
284
+ async stop() {
285
+ if (this.closed) return;
286
+ this.closed = true;
287
+ this.emit('exit', { code: 0, signal: null, stderr: '' });
288
+ }
289
+ }