peer-bridge 0.0.0-stage → 0.7.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/LICENSE +21 -0
- package/README.ko.md +202 -0
- package/README.md +242 -2
- package/adapters/antigravity/bin/agy-hook.mjs +24 -0
- package/adapters/antigravity/hooks.json +23 -0
- package/adapters/antigravity/mcp_config.json +8 -0
- package/adapters/antigravity/plugin.json +4 -0
- package/adapters/antigravity/rules/AGENTS.md +6 -0
- package/adapters/antigravity/skills/peer-bridge/SKILL.md +19 -0
- package/adapters/claude/.claude-plugin/plugin.json +5 -0
- package/adapters/claude/.mcp.json +8 -0
- package/adapters/claude/bin/cc-hook.mjs +20 -0
- package/adapters/claude/hooks/hooks.json +46 -0
- package/adapters/claude/skills/peer-bridge/SKILL.md +19 -0
- package/adapters/codex/bin/codex-hook.mjs +10 -0
- package/adapters/codex/config.toml.example +5 -0
- package/adapters/codex/hooks.json +44 -0
- package/adapters/codex/skills/peer-bridge/SKILL.md +12 -0
- package/adapters/gemini/bin/gemini-hook.mjs +10 -0
- package/adapters/gemini/settings.json +51 -0
- package/adapters/gemini/skills/peer-bridge/SKILL.md +12 -0
- package/adapters/paseo/SKILL.md +24 -0
- package/bin/pbridge-mcp.mjs +37 -0
- package/bin/pbridge-tui.mjs +7 -0
- package/bin/pbridge.mjs +5 -0
- package/bin/pbridged.mjs +16 -0
- package/package.json +57 -4
- package/scripts/postinstall.mjs +25 -0
- package/scripts/preuninstall.mjs +20 -0
- package/skills/peer-bridge/SKILL.md +70 -0
- package/src/adapters/antigravity/hooks.mjs +207 -0
- package/src/adapters/claude/hooks.mjs +204 -0
- package/src/adapters/codex/hooks.mjs +142 -0
- package/src/adapters/gemini/hooks.mjs +159 -0
- package/src/adapters/installer.mjs +328 -0
- package/src/cli/main.mjs +785 -0
- package/src/client/rpc.mjs +243 -0
- package/src/config.mjs +154 -0
- package/src/daemon/broker.mjs +1799 -0
- package/src/daemon/resolver.mjs +200 -0
- package/src/daemon/server.mjs +221 -0
- package/src/index.mjs +60 -0
- package/src/mcp/server.mjs +668 -0
- package/src/orchestrator/workflows.mjs +496 -0
- package/src/project.mjs +81 -0
- package/src/protocol.mjs +203 -0
- package/src/runtime/conv-api.mjs +101 -0
- package/src/runtime/host-discovery.mjs +635 -0
- package/src/runtime/native-claude.mjs +88 -0
- package/src/runtime/paseo.mjs +289 -0
- package/src/runtime/workers.mjs +751 -0
- package/src/skills.mjs +115 -0
- package/src/storage/db.mjs +704 -0
- package/src/tui/render.mjs +472 -0
- package/src/tui/viewer.mjs +443 -0
package/src/cli/main.mjs
ADDED
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import {
|
|
3
|
+
callRpc,
|
|
4
|
+
isDaemonRunning,
|
|
5
|
+
startDaemonDetached,
|
|
6
|
+
stopDaemon,
|
|
7
|
+
} from '../client/rpc.mjs';
|
|
8
|
+
import { getConfig } from '../config.mjs';
|
|
9
|
+
import {
|
|
10
|
+
detectDefaultProjectCwd,
|
|
11
|
+
getProjectLabel,
|
|
12
|
+
normalizeProjectPath,
|
|
13
|
+
} from '../project.mjs';
|
|
14
|
+
import { BrokerServer } from '../daemon/server.mjs';
|
|
15
|
+
import { RpcError } from '../protocol.mjs';
|
|
16
|
+
import { startMcpServer } from '../mcp/server.mjs';
|
|
17
|
+
import { runClaudeHook } from '../adapters/claude/hooks.mjs';
|
|
18
|
+
import { runAntigravityHook } from '../adapters/antigravity/hooks.mjs';
|
|
19
|
+
import { runCodexHook } from '../adapters/codex/hooks.mjs';
|
|
20
|
+
import { runGeminiHook } from '../adapters/gemini/hooks.mjs';
|
|
21
|
+
import { installAdapter } from '../adapters/installer.mjs';
|
|
22
|
+
import {
|
|
23
|
+
getGlobalSkillsStatus,
|
|
24
|
+
installGlobalSkills,
|
|
25
|
+
uninstallGlobalSkills,
|
|
26
|
+
} from '../skills.mjs';
|
|
27
|
+
import { runTuiViewer } from '../tui/viewer.mjs';
|
|
28
|
+
|
|
29
|
+
function parseArgs(argv) {
|
|
30
|
+
const positionals = [];
|
|
31
|
+
const flags = {};
|
|
32
|
+
for (let i = 0; i < argv.length; i++) {
|
|
33
|
+
const arg = argv[i];
|
|
34
|
+
if (arg === '--') {
|
|
35
|
+
positionals.push(...argv.slice(i + 1));
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (arg.startsWith('--')) {
|
|
39
|
+
const eq = arg.indexOf('=');
|
|
40
|
+
if (eq !== -1) {
|
|
41
|
+
flags[arg.slice(2, eq)] = arg.slice(eq + 1);
|
|
42
|
+
} else {
|
|
43
|
+
const key = arg.slice(2);
|
|
44
|
+
const next = argv[i + 1];
|
|
45
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
46
|
+
flags[key] = next;
|
|
47
|
+
i++;
|
|
48
|
+
} else {
|
|
49
|
+
flags[key] = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
} else if (arg.startsWith('-') && arg.length === 2) {
|
|
53
|
+
const key = arg.slice(1);
|
|
54
|
+
const next = argv[i + 1];
|
|
55
|
+
if (next !== undefined && !next.startsWith('-')) {
|
|
56
|
+
flags[key] = next;
|
|
57
|
+
i++;
|
|
58
|
+
} else {
|
|
59
|
+
flags[key] = true;
|
|
60
|
+
}
|
|
61
|
+
} else {
|
|
62
|
+
positionals.push(arg);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return { positionals, flags };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function resolveCliScopeCwd(flags) {
|
|
69
|
+
if (flags.all || flags.A) return null;
|
|
70
|
+
if (typeof flags.cwd === 'string') return normalizeProjectPath(flags.cwd);
|
|
71
|
+
if (typeof flags.project === 'string') return normalizeProjectPath(flags.project);
|
|
72
|
+
return detectDefaultProjectCwd(process.cwd());
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function printJson(obj) {
|
|
76
|
+
process.stdout.write(`${JSON.stringify(obj, null, 2)}\n`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function printHelp() {
|
|
80
|
+
const help = `pbridge — Local peer-bridge broker CLI
|
|
81
|
+
|
|
82
|
+
Usage:
|
|
83
|
+
pbridge daemon start [--foreground] | status | stop
|
|
84
|
+
pbridge peers [--runtime cc|agy|codex|gemini|paseo] [--cwd <dir>] [--all] [--offline] [--native] [--json]
|
|
85
|
+
pbridge register <runtime> --name <name> [--session <id>] [--origin attached|spawned] [--cwd <dir>] [--json]
|
|
86
|
+
pbridge spawn <agy|cc|codex|gemini|paseo> --name <name> [--cwd <path>] [--model <model>] [--provider <p>] [--sandbox <m>] [--no-mcp] [--mode headless|pane|external] [-p "<prompt>"] [--no-wait] [--json]
|
|
87
|
+
pbridge close <target> [--graceful | --archive | --delete | --detach] [--force] [--reason "<text>"] [--json]
|
|
88
|
+
pbridge send <to> "<message>" [--from <peer>] [--thread <id>] [--no-reply] [--max-hops <n>] [--wait-reply] [--json]
|
|
89
|
+
pbridge poll (--session <id> | --target <handle>) [--json]
|
|
90
|
+
pbridge wait (--session <id> | --target <handle>) [--runtime <r>] [--name <n>] [--timeout <sec>] [--json]
|
|
91
|
+
pbridge task delegate <to> "<prompt>" [--title <t>] [--artifact <p1,p2>] [--require-artifacts] [--callback <peer>] [--no-notify] [--wait] [--json]
|
|
92
|
+
pbridge task complete <request_id> ["<summary>"] [--failed] [--error "<msg>"] [--json]
|
|
93
|
+
pbridge task status <request_id> [--json] | list [--status <s>] [--workflow <wf>] [--cwd <dir>] [--all] [--json] | wait <request_id> [--timeout <ms>] [--json]
|
|
94
|
+
pbridge workflow cross-review --author <peer> --reviewer <peer> --prompt "<text>" [--rounds <n>] [--artifact <p1,p2>] [--coordinator <peer>] [--async] [--json]
|
|
95
|
+
pbridge workflow fanout (--spec <json|file> | --workers <p1,p2> --prompt "<text>") [--join <peer>] [--coordinator <peer>] [--async] [--json]
|
|
96
|
+
pbridge workflow status <wf_id> [--json] | list [--cwd <dir>] [--all] [--json] | wait <wf_id> [--timeout <ms>] [--json] | cancel <wf_id> [--json]
|
|
97
|
+
pbridge paseo sync [--cwd <dir>] [--host <host>] [--all] [--json]
|
|
98
|
+
pbridge logs [--thread <id>] [--peer <target>] [--tail <n>] [--json]
|
|
99
|
+
pbridge mcp [--runtime agy|cc|codex|gemini] [--channel] [--name <n>] [--session <id>]
|
|
100
|
+
pbridge hook <cc|agy|codex|gemini> <event>
|
|
101
|
+
pbridge install <cc|agy|codex|gemini|all> [--project <dir> | --global] [--dry-run] [--json]
|
|
102
|
+
pbridge skills [status|install|uninstall] [--all] [--dry-run] [--json]
|
|
103
|
+
pbridge tui|agents [--runtime <r>] [--cwd <dir>] [--all] [--broker-only] [--active] [--once] [--json] [--tmux-split | --tmux-popup]
|
|
104
|
+
`;
|
|
105
|
+
process.stdout.write(help);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function pad(str, len) {
|
|
109
|
+
const s = String(str ?? '');
|
|
110
|
+
return s.length >= len ? s.slice(0, len) : s + ' '.repeat(len - s.length);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function runCli(argv = process.argv.slice(2)) {
|
|
114
|
+
const { positionals, flags } = parseArgs(argv);
|
|
115
|
+
const cmd = positionals[0];
|
|
116
|
+
const asJson = Boolean(flags.json);
|
|
117
|
+
|
|
118
|
+
if (!cmd || cmd === 'help' || flags.help || flags.h) {
|
|
119
|
+
printHelp();
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
if (cmd === 'daemon') {
|
|
125
|
+
const sub = positionals[1] || 'status';
|
|
126
|
+
const config = getConfig();
|
|
127
|
+
|
|
128
|
+
if (sub === 'start') {
|
|
129
|
+
if (!process.env.PBRIDGE_HOME && !process.env.CI && process.env.PBRIDGE_NO_AUTO_SKILL !== '1') {
|
|
130
|
+
try {
|
|
131
|
+
installGlobalSkills();
|
|
132
|
+
} catch {
|
|
133
|
+
// best-effort fallback for package managers that skip postinstall
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (flags.foreground) {
|
|
137
|
+
const server = new BrokerServer({ config });
|
|
138
|
+
const status = await server.start();
|
|
139
|
+
if (asJson) printJson(status);
|
|
140
|
+
else process.stdout.write(`pbridged running in foreground (pid=${status.pid}, sock=${status.sock_path})\n`);
|
|
141
|
+
const stopNow = async () => {
|
|
142
|
+
await server.stop();
|
|
143
|
+
process.exit(0);
|
|
144
|
+
};
|
|
145
|
+
process.once('SIGINT', stopNow);
|
|
146
|
+
process.once('SIGTERM', stopNow);
|
|
147
|
+
await new Promise(() => {});
|
|
148
|
+
}
|
|
149
|
+
const status = await startDaemonDetached({ config });
|
|
150
|
+
if (asJson) printJson(status);
|
|
151
|
+
else process.stdout.write(`pbridged started (pid=${status.pid}, sock=${status.sock_path})\n`);
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (sub === 'status') {
|
|
156
|
+
const running = await isDaemonRunning({ config });
|
|
157
|
+
if (!running) {
|
|
158
|
+
if (asJson) printJson({ running: false, sock_path: config.sockPath });
|
|
159
|
+
else process.stdout.write(`pbridged is stopped (${config.sockPath})\n`);
|
|
160
|
+
return 1;
|
|
161
|
+
}
|
|
162
|
+
const status = await callRpc('daemon.status', {}, { config, timeoutMs: 3000 });
|
|
163
|
+
if (asJson) printJson({ running: true, ...status });
|
|
164
|
+
else {
|
|
165
|
+
process.stdout.write(
|
|
166
|
+
`pbridged running (pid=${status.pid}, peers=${status.active_peers}, workers=${status.managed_workers}, waiters=${status.active_waiters})\n`,
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (sub === 'stop') {
|
|
173
|
+
const res = await stopDaemon({ config });
|
|
174
|
+
if (asJson) printJson(res);
|
|
175
|
+
else process.stdout.write('pbridged stopped\n');
|
|
176
|
+
return 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
throw new Error(`Unknown daemon subcommand "${sub}". Use start | status | stop.`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (cmd === 'peers') {
|
|
183
|
+
const scopeCwd = resolveCliScopeCwd(flags);
|
|
184
|
+
const res = await callRpc('peer.list', {
|
|
185
|
+
runtime: flags.runtime || null,
|
|
186
|
+
cwd: scopeCwd,
|
|
187
|
+
include_offline: Boolean(flags.offline || flags.all),
|
|
188
|
+
include_native_claude: Boolean(flags.native),
|
|
189
|
+
});
|
|
190
|
+
if (asJson) {
|
|
191
|
+
printJson(res);
|
|
192
|
+
} else {
|
|
193
|
+
if (!res.peers.length) {
|
|
194
|
+
if (scopeCwd) {
|
|
195
|
+
process.stdout.write(
|
|
196
|
+
`No active peers in project ${getProjectLabel(scopeCwd)} (pass --all for all projects).\n`,
|
|
197
|
+
);
|
|
198
|
+
} else {
|
|
199
|
+
process.stdout.write('No peers registered.\n');
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
process.stdout.write(
|
|
203
|
+
`${pad('HANDLE', 20)} ${pad('STATE', 10)} ${pad('ORIGIN', 9)} ${pad('MODE', 12)} ${pad('SESSION/ID', 14)} CWD\n`,
|
|
204
|
+
);
|
|
205
|
+
for (const p of res.peers) {
|
|
206
|
+
const sid = (p.session_id || p.peer_id || '').slice(0, 12);
|
|
207
|
+
process.stdout.write(
|
|
208
|
+
`${pad(p.handle, 20)} ${pad(p.state, 10)} ${pad(p.origin, 9)} ${pad(p.exec_mode, 12)} ${pad(sid, 14)} ${p.cwd || '-'}\n`,
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (cmd === 'register') {
|
|
217
|
+
const runtime = positionals[1] || flags.runtime;
|
|
218
|
+
const res = await callRpc('peer.register', {
|
|
219
|
+
runtime,
|
|
220
|
+
name: flags.name,
|
|
221
|
+
session_id: flags.session || process.env.ANTIGRAVITY_CONVERSATION_ID || null,
|
|
222
|
+
origin: flags.origin || 'attached',
|
|
223
|
+
exec_mode: flags.mode || 'interactive',
|
|
224
|
+
state: flags.state || 'idle',
|
|
225
|
+
cwd: flags.cwd || process.cwd(),
|
|
226
|
+
pid: flags.pid ? Number(flags.pid) : null,
|
|
227
|
+
ls_address: flags['ls-addr'] || process.env.ANTIGRAVITY_LS_ADDRESS || null,
|
|
228
|
+
csrf_token: flags.csrf || process.env.ANTIGRAVITY_CSRF_TOKEN || null,
|
|
229
|
+
project_id: flags.project || process.env.ANTIGRAVITY_PROJECT_ID || null,
|
|
230
|
+
});
|
|
231
|
+
if (asJson) printJson(res);
|
|
232
|
+
else process.stdout.write(`Registered ${res.peer.handle} (${res.peer.peer_id})\n`);
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
if (cmd === 'spawn') {
|
|
237
|
+
const runtime = positionals[1] || flags.runtime;
|
|
238
|
+
const res = await callRpc(
|
|
239
|
+
'peer.spawn',
|
|
240
|
+
{
|
|
241
|
+
runtime,
|
|
242
|
+
name: flags.name,
|
|
243
|
+
cwd: flags.cwd || process.cwd(),
|
|
244
|
+
model: flags.model || undefined,
|
|
245
|
+
provider: flags.provider || undefined,
|
|
246
|
+
sandbox_mode: flags.sandbox || undefined,
|
|
247
|
+
approval_mode: flags['approval-mode'] || undefined,
|
|
248
|
+
no_mcp: Boolean(flags['no-mcp']),
|
|
249
|
+
host: flags.host || undefined,
|
|
250
|
+
mode: flags.mode || (runtime === 'paseo' ? 'external' : 'headless'),
|
|
251
|
+
initial_prompt: flags.p || flags.prompt || undefined,
|
|
252
|
+
await_initial: !flags['no-wait'],
|
|
253
|
+
spawned_by: flags.from || undefined,
|
|
254
|
+
mock: Boolean(flags.mock),
|
|
255
|
+
tmux_socket: flags['tmux-socket'] || undefined,
|
|
256
|
+
ls_address: flags['ls-addr'] || process.env.ANTIGRAVITY_LS_ADDRESS || undefined,
|
|
257
|
+
csrf_token: flags.csrf || process.env.ANTIGRAVITY_CSRF_TOKEN || undefined,
|
|
258
|
+
project_id: flags.project || process.env.ANTIGRAVITY_PROJECT_ID || undefined,
|
|
259
|
+
},
|
|
260
|
+
{ timeoutMs: 240_000 },
|
|
261
|
+
);
|
|
262
|
+
if (asJson) {
|
|
263
|
+
printJson(res);
|
|
264
|
+
} else {
|
|
265
|
+
process.stdout.write(
|
|
266
|
+
`Spawned ${res.peer.handle} (peer_id=${res.peer.peer_id}, session=${res.peer.session_id || '-'}, mode=${res.peer.exec_mode}, state=${res.peer.state})\n`,
|
|
267
|
+
);
|
|
268
|
+
if (res.initial_result?.response) {
|
|
269
|
+
process.stdout.write(`Response: ${res.initial_result.response}\n`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return 0;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (cmd === 'close') {
|
|
276
|
+
const target = positionals[1] || flags.target;
|
|
277
|
+
let policy = flags.policy;
|
|
278
|
+
if (!policy) {
|
|
279
|
+
if (flags.delete) policy = 'delete';
|
|
280
|
+
else if (flags.archive) policy = 'archive';
|
|
281
|
+
else if (flags.detach) policy = 'detach';
|
|
282
|
+
else if (flags.graceful) policy = 'graceful';
|
|
283
|
+
}
|
|
284
|
+
const res = await callRpc('peer.close', {
|
|
285
|
+
target,
|
|
286
|
+
policy,
|
|
287
|
+
force: Boolean(flags.force),
|
|
288
|
+
reason: flags.reason || undefined,
|
|
289
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : process.cwd(),
|
|
290
|
+
ls_address: flags['ls-addr'] || process.env.ANTIGRAVITY_LS_ADDRESS || undefined,
|
|
291
|
+
csrf_token: flags.csrf || process.env.ANTIGRAVITY_CSRF_TOKEN || undefined,
|
|
292
|
+
project_id: flags.project || process.env.ANTIGRAVITY_PROJECT_ID || undefined,
|
|
293
|
+
});
|
|
294
|
+
if (asJson) printJson(res);
|
|
295
|
+
else {
|
|
296
|
+
process.stdout.write(
|
|
297
|
+
`Closed ${res.closed_peer.handle} (${res.previous_state} -> ${res.action_taken}, conv=${res.conversation_action})\n`,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
return 0;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (cmd === 'send') {
|
|
304
|
+
const to = positionals[1];
|
|
305
|
+
const message = positionals.slice(2).join(' ') || flags.message;
|
|
306
|
+
const waitReply = Boolean(flags['wait-reply'] || flags.await);
|
|
307
|
+
const res = await callRpc(
|
|
308
|
+
'message.send',
|
|
309
|
+
{
|
|
310
|
+
to,
|
|
311
|
+
body: message,
|
|
312
|
+
from: flags.from || undefined,
|
|
313
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : process.cwd(),
|
|
314
|
+
thread_id: flags.thread || undefined,
|
|
315
|
+
reply_expected: !flags['no-reply'],
|
|
316
|
+
max_hops: flags['max-hops'] ? Number(flags['max-hops']) : undefined,
|
|
317
|
+
delivery_mode: flags.mode || 'immediate',
|
|
318
|
+
wait_reply: waitReply,
|
|
319
|
+
},
|
|
320
|
+
{ timeoutMs: waitReply ? 240_000 : 30_000 },
|
|
321
|
+
);
|
|
322
|
+
if (asJson) {
|
|
323
|
+
printJson(res);
|
|
324
|
+
} else if (res.blocked) {
|
|
325
|
+
process.stderr.write(`BLOCKED [${res.code}]: ${res.message}\n`);
|
|
326
|
+
return 2;
|
|
327
|
+
} else {
|
|
328
|
+
process.stdout.write(
|
|
329
|
+
`Sent ${res.msg_id} -> ${res.resolved_to} (thread=${res.thread_id}, hop=${res.hop_count}/${res.max_hops}, status=${res.delivery_status})\n`,
|
|
330
|
+
);
|
|
331
|
+
if (res.worker_result?.response) {
|
|
332
|
+
process.stdout.write(`Reply: ${res.worker_result.response}\n`);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return res.blocked ? 2 : 0;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (cmd === 'poll') {
|
|
339
|
+
const res = await callRpc('message.poll', {
|
|
340
|
+
session_id: flags.session || undefined,
|
|
341
|
+
target: flags.target || positionals[1] || undefined,
|
|
342
|
+
peer_id: flags.peer || undefined,
|
|
343
|
+
});
|
|
344
|
+
if (asJson) printJson(res);
|
|
345
|
+
else if (res.count === 0) process.stdout.write('No pending messages.\n');
|
|
346
|
+
else {
|
|
347
|
+
for (const m of res.messages) {
|
|
348
|
+
process.stdout.write(`${m.formatted_xml}\n`);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return 0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
if (cmd === 'wait') {
|
|
355
|
+
const timeoutSec = flags.timeout ? Number(flags.timeout) : 600;
|
|
356
|
+
const timeoutMs = Math.max(100, timeoutSec * 1000);
|
|
357
|
+
const res = await callRpc(
|
|
358
|
+
'message.wait',
|
|
359
|
+
{
|
|
360
|
+
session_id: flags.session || undefined,
|
|
361
|
+
target: flags.target || positionals[1] || undefined,
|
|
362
|
+
peer_id: flags.peer || undefined,
|
|
363
|
+
runtime: flags.runtime || undefined,
|
|
364
|
+
name: flags.name || undefined,
|
|
365
|
+
cwd: flags.cwd || process.cwd(),
|
|
366
|
+
timeout_ms: timeoutMs,
|
|
367
|
+
ls_address: flags['ls-addr'] || process.env.ANTIGRAVITY_LS_ADDRESS || undefined,
|
|
368
|
+
csrf_token: flags.csrf || process.env.ANTIGRAVITY_CSRF_TOKEN || undefined,
|
|
369
|
+
project_id: flags.project || process.env.ANTIGRAVITY_PROJECT_ID || undefined,
|
|
370
|
+
},
|
|
371
|
+
{ timeoutMs: timeoutMs + 5000 },
|
|
372
|
+
);
|
|
373
|
+
if (asJson) {
|
|
374
|
+
printJson(res);
|
|
375
|
+
} else if (res.reason === 'shutdown') {
|
|
376
|
+
process.stdout.write(`[peer-bridge] Shutdown received: ${res.system?.reason || ''}\n`);
|
|
377
|
+
} else if (!res.woke) {
|
|
378
|
+
process.stdout.write(`[peer-bridge] Wait ended (${res.reason})\n`);
|
|
379
|
+
} else {
|
|
380
|
+
for (const m of res.messages) {
|
|
381
|
+
process.stdout.write(`${m.formatted_xml}\n`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return 0;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (cmd === 'logs') {
|
|
388
|
+
const res = await callRpc('logs.tail', {
|
|
389
|
+
thread_id: flags.thread || undefined,
|
|
390
|
+
peer: flags.peer || undefined,
|
|
391
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : process.cwd(),
|
|
392
|
+
limit: flags.tail ? Number(flags.tail) : 20,
|
|
393
|
+
});
|
|
394
|
+
if (asJson) {
|
|
395
|
+
printJson(res);
|
|
396
|
+
} else if (!res.entries.length) {
|
|
397
|
+
process.stdout.write('No messages logged.\n');
|
|
398
|
+
} else {
|
|
399
|
+
for (const e of res.entries) {
|
|
400
|
+
const from = e.from_runtime ? `${e.from_runtime}:${e.from_name}` : e.from_name || '-';
|
|
401
|
+
process.stdout.write(
|
|
402
|
+
`${e.created_at} [${e.status}/${e.last_channel || '-'}] thr=${e.thread_id} hop=${e.hop_count}/${e.max_hops} ${from} -> ${e.to_raw} :: ${e.body.slice(0, 80)}\n`,
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return 0;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
if (cmd === 'mcp') {
|
|
410
|
+
const runtime = typeof flags.runtime === 'string' ? flags.runtime : 'agy';
|
|
411
|
+
const enableChannel = Boolean(flags.channel) || runtime === 'cc';
|
|
412
|
+
startMcpServer({
|
|
413
|
+
runtime,
|
|
414
|
+
enableChannel,
|
|
415
|
+
peerName: typeof flags.name === 'string' ? flags.name : null,
|
|
416
|
+
sessionId: typeof flags.session === 'string' ? flags.session : null,
|
|
417
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : process.cwd(),
|
|
418
|
+
});
|
|
419
|
+
await new Promise(() => {});
|
|
420
|
+
return 0;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (cmd === 'hook') {
|
|
424
|
+
const runtime = positionals[1];
|
|
425
|
+
const eventName = positionals[2] || '';
|
|
426
|
+
let raw = '';
|
|
427
|
+
try {
|
|
428
|
+
raw = fs.readFileSync(0, 'utf8');
|
|
429
|
+
} catch {
|
|
430
|
+
raw = '';
|
|
431
|
+
}
|
|
432
|
+
let out;
|
|
433
|
+
if (runtime === 'cc') {
|
|
434
|
+
out = await runClaudeHook(eventName, raw);
|
|
435
|
+
} else if (runtime === 'agy') {
|
|
436
|
+
out = await runAntigravityHook(eventName, raw);
|
|
437
|
+
} else if (runtime === 'codex') {
|
|
438
|
+
out = await runCodexHook(eventName, raw);
|
|
439
|
+
} else if (runtime === 'gemini') {
|
|
440
|
+
out = await runGeminiHook(eventName, raw);
|
|
441
|
+
} else {
|
|
442
|
+
throw new Error('Usage: pbridge hook <cc|agy|codex|gemini> <event>');
|
|
443
|
+
}
|
|
444
|
+
process.stdout.write(`${JSON.stringify(out || {})}\n`);
|
|
445
|
+
return 0;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (cmd === 'paseo') {
|
|
449
|
+
const sub = positionals[1] || 'sync';
|
|
450
|
+
if (sub !== 'sync') {
|
|
451
|
+
throw new Error('Usage: pbridge paseo sync [--cwd <dir>] [--host <host>] [--all] [--json]');
|
|
452
|
+
}
|
|
453
|
+
const res = await callRpc('paseo.sync', {
|
|
454
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : undefined,
|
|
455
|
+
host: typeof flags.host === 'string' ? flags.host : undefined,
|
|
456
|
+
include_all: Boolean(flags.all),
|
|
457
|
+
global: !flags.cwd,
|
|
458
|
+
});
|
|
459
|
+
if (asJson) printJson(res);
|
|
460
|
+
else process.stdout.write(`Synced ${res.synced_count} Paseo agent(s).\n`);
|
|
461
|
+
return 0;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (cmd === 'task') {
|
|
465
|
+
const sub = positionals[1] || 'list';
|
|
466
|
+
if (sub === 'delegate') {
|
|
467
|
+
const to = positionals[2] || flags.to;
|
|
468
|
+
const prompt = positionals.slice(3).join(' ') || flags.prompt || flags.p;
|
|
469
|
+
const artifacts =
|
|
470
|
+
typeof flags.artifact === 'string'
|
|
471
|
+
? flags.artifact.split(',').map((s) => s.trim()).filter(Boolean)
|
|
472
|
+
: [];
|
|
473
|
+
const timeoutMs = flags.timeout ? Number(flags.timeout) : 180_000;
|
|
474
|
+
const res = await callRpc(
|
|
475
|
+
'task.create',
|
|
476
|
+
{
|
|
477
|
+
to,
|
|
478
|
+
prompt,
|
|
479
|
+
title: typeof flags.title === 'string' ? flags.title : undefined,
|
|
480
|
+
request_id: typeof flags.id === 'string' ? flags.id : undefined,
|
|
481
|
+
from: typeof flags.from === 'string' ? flags.from : undefined,
|
|
482
|
+
expected_artifacts: artifacts,
|
|
483
|
+
require_artifacts: Boolean(flags['require-artifacts']),
|
|
484
|
+
notify_on_finish: !flags['no-notify'],
|
|
485
|
+
callback_to: typeof flags.callback === 'string' ? flags.callback : undefined,
|
|
486
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : undefined,
|
|
487
|
+
wait: Boolean(flags.wait),
|
|
488
|
+
timeout_ms: timeoutMs,
|
|
489
|
+
},
|
|
490
|
+
{ timeoutMs: flags.wait ? timeoutMs + 5_000 : 30_000 },
|
|
491
|
+
);
|
|
492
|
+
if (asJson) printJson(res);
|
|
493
|
+
else {
|
|
494
|
+
process.stdout.write(
|
|
495
|
+
`Task ${res.request_id} -> ${res.to_handle} (status=${res.status})\n`,
|
|
496
|
+
);
|
|
497
|
+
if (res.result_summary) process.stdout.write(`Summary: ${res.result_summary}\n`);
|
|
498
|
+
}
|
|
499
|
+
return res.status === 'failed' ? 1 : 0;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (sub === 'complete') {
|
|
503
|
+
const requestId = positionals[2] || flags.id;
|
|
504
|
+
const summary = positionals.slice(3).join(' ') || flags.summary || undefined;
|
|
505
|
+
const status = flags.failed ? 'failed' : flags.cancelled ? 'cancelled' : 'completed';
|
|
506
|
+
const res = await callRpc('task.complete', {
|
|
507
|
+
request_id: requestId,
|
|
508
|
+
status,
|
|
509
|
+
summary,
|
|
510
|
+
error: typeof flags.error === 'string' ? flags.error : undefined,
|
|
511
|
+
});
|
|
512
|
+
if (asJson) printJson(res);
|
|
513
|
+
else process.stdout.write(`Task ${res.request_id} marked ${res.status}\n`);
|
|
514
|
+
return res.status === 'failed' ? 1 : 0;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
if (sub === 'status') {
|
|
518
|
+
const res = await callRpc('task.get', { request_id: positionals[2] || flags.id });
|
|
519
|
+
if (asJson) printJson(res);
|
|
520
|
+
else {
|
|
521
|
+
process.stdout.write(
|
|
522
|
+
`Task ${res.request_id} (${res.to_handle}): status=${res.status}${res.error ? ` error=${res.error}` : ''}\n`,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
return 0;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (sub === 'wait') {
|
|
529
|
+
const timeoutMs = flags.timeout ? Number(flags.timeout) : 180_000;
|
|
530
|
+
const res = await callRpc(
|
|
531
|
+
'task.wait',
|
|
532
|
+
{ request_id: positionals[2] || flags.id, timeout_ms: timeoutMs },
|
|
533
|
+
{ timeoutMs: timeoutMs + 5_000 },
|
|
534
|
+
);
|
|
535
|
+
if (asJson) printJson(res);
|
|
536
|
+
else process.stdout.write(`Task ${res.request_id} finished: ${res.status}\n`);
|
|
537
|
+
return res.status === 'failed' ? 1 : 0;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const res = await callRpc('task.list', {
|
|
541
|
+
status: typeof flags.status === 'string' ? flags.status : undefined,
|
|
542
|
+
workflow_id: typeof flags.workflow === 'string' ? flags.workflow : undefined,
|
|
543
|
+
cwd: resolveCliScopeCwd(flags),
|
|
544
|
+
limit: flags.limit ? Number(flags.limit) : 50,
|
|
545
|
+
});
|
|
546
|
+
if (asJson) printJson(res);
|
|
547
|
+
else if (res.count === 0) process.stdout.write('No tasks found.\n');
|
|
548
|
+
else {
|
|
549
|
+
for (const t of res.tasks) {
|
|
550
|
+
process.stdout.write(`${t.request_id} ${pad(t.status, 10)} ${pad(t.to_handle, 18)} ${t.title || '-'}\n`);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
return 0;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (cmd === 'workflow') {
|
|
557
|
+
const sub = positionals[1] || 'list';
|
|
558
|
+
if (sub === 'cross-review') {
|
|
559
|
+
const artifacts =
|
|
560
|
+
typeof flags.artifact === 'string'
|
|
561
|
+
? flags.artifact.split(',').map((s) => s.trim()).filter(Boolean)
|
|
562
|
+
: [];
|
|
563
|
+
const timeoutMs = flags.timeout ? Number(flags.timeout) : 300_000;
|
|
564
|
+
const res = await callRpc(
|
|
565
|
+
'workflow.run',
|
|
566
|
+
{
|
|
567
|
+
template: 'cross-review',
|
|
568
|
+
name: typeof flags.name === 'string' ? flags.name : undefined,
|
|
569
|
+
author: flags.author,
|
|
570
|
+
reviewer: flags.reviewer,
|
|
571
|
+
prompt: flags.prompt || flags.p || positionals.slice(2).join(' '),
|
|
572
|
+
max_rounds: flags.rounds ? Number(flags.rounds) : 2,
|
|
573
|
+
expected_artifacts: artifacts,
|
|
574
|
+
require_artifacts: Boolean(flags['require-artifacts']),
|
|
575
|
+
coordinator: typeof flags.coordinator === 'string' ? flags.coordinator : undefined,
|
|
576
|
+
notify_on_finish: !flags['no-notify'],
|
|
577
|
+
async: Boolean(flags.async),
|
|
578
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : process.cwd(),
|
|
579
|
+
timeout_ms: timeoutMs,
|
|
580
|
+
},
|
|
581
|
+
{ timeoutMs: flags.async ? 30_000 : timeoutMs + 10_000 },
|
|
582
|
+
);
|
|
583
|
+
if (asJson) printJson(res);
|
|
584
|
+
else {
|
|
585
|
+
process.stdout.write(
|
|
586
|
+
`Workflow ${res.workflow_id} (cross-review): status=${res.status}, approved=${res.result?.approved ?? '-'}\n`,
|
|
587
|
+
);
|
|
588
|
+
}
|
|
589
|
+
return res.status === 'failed' ? 1 : 0;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (sub === 'fanout' || sub === 'fanout-join') {
|
|
593
|
+
let specObj = {};
|
|
594
|
+
if (typeof flags.spec === 'string') {
|
|
595
|
+
const rawSpec = fs.existsSync(flags.spec) ? fs.readFileSync(flags.spec, 'utf8') : flags.spec;
|
|
596
|
+
specObj = JSON.parse(rawSpec);
|
|
597
|
+
} else if (typeof flags.workers === 'string') {
|
|
598
|
+
const prompt = flags.prompt || flags.p || '';
|
|
599
|
+
specObj.tasks = flags.workers
|
|
600
|
+
.split(',')
|
|
601
|
+
.map((w) => w.trim())
|
|
602
|
+
.filter(Boolean)
|
|
603
|
+
.map((to, idx) => ({ label: `worker-${idx + 1}`, to, prompt }));
|
|
604
|
+
}
|
|
605
|
+
const timeoutMs = flags.timeout ? Number(flags.timeout) : 300_000;
|
|
606
|
+
const res = await callRpc(
|
|
607
|
+
'workflow.run',
|
|
608
|
+
{
|
|
609
|
+
...specObj,
|
|
610
|
+
template: 'fanout-join',
|
|
611
|
+
name: typeof flags.name === 'string' ? flags.name : specObj.name,
|
|
612
|
+
join_to: typeof flags.join === 'string' ? flags.join : specObj.join_to,
|
|
613
|
+
coordinator: typeof flags.coordinator === 'string' ? flags.coordinator : specObj.coordinator,
|
|
614
|
+
notify_on_finish: flags['no-notify'] ? false : specObj.notify_on_finish !== false,
|
|
615
|
+
async: Boolean(flags.async),
|
|
616
|
+
cwd: typeof flags.cwd === 'string' ? flags.cwd : specObj.cwd || process.cwd(),
|
|
617
|
+
timeout_ms: timeoutMs,
|
|
618
|
+
},
|
|
619
|
+
{ timeoutMs: flags.async ? 30_000 : timeoutMs + 10_000 },
|
|
620
|
+
);
|
|
621
|
+
if (asJson) printJson(res);
|
|
622
|
+
else {
|
|
623
|
+
process.stdout.write(
|
|
624
|
+
`Workflow ${res.workflow_id} (fanout-join): status=${res.status}, succeeded=${res.result?.succeeded ?? '-'}/${res.result?.total ?? '-'}\n`,
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
return res.status === 'failed' ? 1 : 0;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
if (sub === 'status') {
|
|
631
|
+
const res = await callRpc('workflow.get', { workflow_id: positionals[2] || flags.id });
|
|
632
|
+
if (asJson) printJson(res);
|
|
633
|
+
else process.stdout.write(`Workflow ${res.workflow_id} (${res.template}): ${res.status}\n`);
|
|
634
|
+
return 0;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (sub === 'wait') {
|
|
638
|
+
const timeoutMs = flags.timeout ? Number(flags.timeout) : 300_000;
|
|
639
|
+
const res = await callRpc(
|
|
640
|
+
'workflow.wait',
|
|
641
|
+
{ workflow_id: positionals[2] || flags.id, timeout_ms: timeoutMs },
|
|
642
|
+
{ timeoutMs: timeoutMs + 5_000 },
|
|
643
|
+
);
|
|
644
|
+
if (asJson) printJson(res);
|
|
645
|
+
else process.stdout.write(`Workflow ${res.workflow_id} finished: ${res.status}\n`);
|
|
646
|
+
return res.status === 'failed' ? 1 : 0;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
if (sub === 'cancel') {
|
|
650
|
+
const res = await callRpc('workflow.cancel', {
|
|
651
|
+
workflow_id: positionals[2] || flags.id,
|
|
652
|
+
reason: typeof flags.reason === 'string' ? flags.reason : undefined,
|
|
653
|
+
});
|
|
654
|
+
if (asJson) printJson(res);
|
|
655
|
+
else process.stdout.write(`Workflow ${res.workflow_id} cancelled.\n`);
|
|
656
|
+
return 0;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
const res = await callRpc('workflow.list', {
|
|
660
|
+
status: typeof flags.status === 'string' ? flags.status : undefined,
|
|
661
|
+
template: typeof flags.template === 'string' ? flags.template : undefined,
|
|
662
|
+
cwd: resolveCliScopeCwd(flags),
|
|
663
|
+
});
|
|
664
|
+
if (asJson) printJson(res);
|
|
665
|
+
else if (res.count === 0) process.stdout.write('No workflows found.\n');
|
|
666
|
+
else {
|
|
667
|
+
for (const w of res.workflows) {
|
|
668
|
+
process.stdout.write(`${w.workflow_id} ${pad(w.template, 14)} ${pad(w.status, 10)} ${w.name || '-'}\n`);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
return 0;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (cmd === 'install') {
|
|
675
|
+
const runtime = positionals[1];
|
|
676
|
+
if (!runtime) {
|
|
677
|
+
throw new Error(
|
|
678
|
+
'Usage: pbridge install <cc|agy|codex|gemini|all> [--project <dir> | --global] [--dry-run] [--json]',
|
|
679
|
+
);
|
|
680
|
+
}
|
|
681
|
+
const scope = flags.global ? 'global' : 'project';
|
|
682
|
+
const targetDir = typeof flags.project === 'string' ? flags.project : process.cwd();
|
|
683
|
+
const res = installAdapter({
|
|
684
|
+
runtime,
|
|
685
|
+
targetDir,
|
|
686
|
+
scope,
|
|
687
|
+
dryRun: Boolean(flags['dry-run']),
|
|
688
|
+
});
|
|
689
|
+
if (asJson) {
|
|
690
|
+
printJson(res);
|
|
691
|
+
} else {
|
|
692
|
+
const items = runtime === 'all' ? [res.agy, res.cc, res.codex, res.gemini] : [res];
|
|
693
|
+
for (const item of items) {
|
|
694
|
+
process.stdout.write(
|
|
695
|
+
`Installed ${item.runtime} adapter (${item.scope}${item.dry_run ? ', dry-run' : ''}): ${item.files.join(', ')}\n`,
|
|
696
|
+
);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return 0;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (cmd === 'skills') {
|
|
703
|
+
const sub = positionals[1] || 'status';
|
|
704
|
+
if (sub === 'install') {
|
|
705
|
+
const res = installGlobalSkills({
|
|
706
|
+
includeAll: Boolean(flags.all),
|
|
707
|
+
dryRun: Boolean(flags['dry-run']),
|
|
708
|
+
});
|
|
709
|
+
if (asJson) {
|
|
710
|
+
printJson(res);
|
|
711
|
+
} else {
|
|
712
|
+
for (const p of res.installed) {
|
|
713
|
+
process.stdout.write(`Installed skill${res.dry_run ? ' (dry-run)' : ''}: ${p}\n`);
|
|
714
|
+
}
|
|
715
|
+
for (const s of res.skipped) {
|
|
716
|
+
process.stdout.write(`Skipped (${s.reason}): ${s.path}\n`);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
return 0;
|
|
720
|
+
}
|
|
721
|
+
if (sub === 'uninstall' || sub === 'remove') {
|
|
722
|
+
const res = uninstallGlobalSkills({ dryRun: Boolean(flags['dry-run']) });
|
|
723
|
+
if (asJson) {
|
|
724
|
+
printJson(res);
|
|
725
|
+
} else {
|
|
726
|
+
if (!res.removed.length) process.stdout.write('No managed peer-bridge skills found.\n');
|
|
727
|
+
for (const p of res.removed) {
|
|
728
|
+
process.stdout.write(`Removed skill${res.dry_run ? ' (dry-run)' : ''}: ${p}\n`);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return 0;
|
|
732
|
+
}
|
|
733
|
+
const res = getGlobalSkillsStatus();
|
|
734
|
+
if (asJson) {
|
|
735
|
+
printJson(res);
|
|
736
|
+
} else {
|
|
737
|
+
for (const s of res.skills) {
|
|
738
|
+
const state = s.installed ? (s.managed ? 'installed (managed)' : 'installed (custom)') : 'not installed';
|
|
739
|
+
process.stdout.write(`${pad(s.runtime, 8)} ${pad(state, 22)} ${s.path}\n`);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return 0;
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
if (cmd === 'tui' || cmd === 'agents') {
|
|
746
|
+
const res = await runTuiViewer({
|
|
747
|
+
config: getConfig(),
|
|
748
|
+
runtime: typeof flags.runtime === 'string' ? flags.runtime : 'all',
|
|
749
|
+
cwd:
|
|
750
|
+
typeof flags.cwd === 'string'
|
|
751
|
+
? flags.cwd
|
|
752
|
+
: typeof flags.project === 'string'
|
|
753
|
+
? flags.project
|
|
754
|
+
: null,
|
|
755
|
+
allProjects: Boolean(flags.all || flags.A),
|
|
756
|
+
brokerOnly: Boolean(flags['broker-only']),
|
|
757
|
+
hideStopped: Boolean(flags.active),
|
|
758
|
+
once: Boolean(flags.once),
|
|
759
|
+
json: asJson,
|
|
760
|
+
noDaemon: Boolean(flags['no-daemon']),
|
|
761
|
+
tmuxSplit: Boolean(flags['tmux-split']),
|
|
762
|
+
tmuxPopup: Boolean(flags['tmux-popup']),
|
|
763
|
+
width: flags.width ? Number(flags.width) : undefined,
|
|
764
|
+
});
|
|
765
|
+
return res?.ok === false ? 1 : 0;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
throw new Error(`Unknown command "${cmd}". Run "pbridge --help".`);
|
|
769
|
+
} catch (err) {
|
|
770
|
+
if (asJson) {
|
|
771
|
+
printJson({
|
|
772
|
+
ok: false,
|
|
773
|
+
error: {
|
|
774
|
+
code: err instanceof RpcError ? err.code : 'CLI_ERROR',
|
|
775
|
+
message: err.message,
|
|
776
|
+
...(err instanceof RpcError && err.data ? { data: err.data } : {}),
|
|
777
|
+
},
|
|
778
|
+
});
|
|
779
|
+
} else {
|
|
780
|
+
const code = err instanceof RpcError ? `[${err.code}] ` : '';
|
|
781
|
+
process.stderr.write(`Error: ${code}${err.message}\n`);
|
|
782
|
+
}
|
|
783
|
+
return 1;
|
|
784
|
+
}
|
|
785
|
+
}
|