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.
- package/LICENSE +21 -0
- package/README.ko.md +134 -0
- package/README.md +161 -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 +18 -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 +42 -4
- 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 +729 -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 +53 -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/storage/db.mjs +704 -0
- package/src/tui/render.mjs +472 -0
- package/src/tui/viewer.mjs +443 -0
package/src/protocol.mjs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import crypto from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
export const RUNTIMES = new Set(['cc', 'agy', 'codex', 'gemini', 'paseo', 'cli', 'custom']);
|
|
6
|
+
export const ORIGINS = new Set(['spawned', 'attached']);
|
|
7
|
+
export const EXEC_MODES = new Set(['headless', 'pane', 'interactive', 'external']);
|
|
8
|
+
export const CLOSE_POLICIES = new Set(['graceful', 'archive', 'delete', 'detach']);
|
|
9
|
+
export const MESSAGE_KINDS = new Set(['prompt', 'reply', 'ack', 'system']);
|
|
10
|
+
export const TASK_STATUSES = new Set(['pending', 'running', 'completed', 'failed', 'cancelled']);
|
|
11
|
+
export const WORKFLOW_TEMPLATES = new Set(['cross-review', 'fanout-join']);
|
|
12
|
+
|
|
13
|
+
export function makeId(prefix) {
|
|
14
|
+
const ts = Date.now().toString(36).padStart(9, '0');
|
|
15
|
+
const rand = crypto.randomBytes(5).toString('hex');
|
|
16
|
+
return `${prefix}_${ts}${rand}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function nowIso() {
|
|
20
|
+
return new Date().toISOString();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function makeHandle(peer) {
|
|
24
|
+
return `${peer.runtime}:${peer.name}`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function parseAddress(raw) {
|
|
28
|
+
const input = String(raw || '').trim();
|
|
29
|
+
if (!input) return { raw: '', runtime: null, query: '' };
|
|
30
|
+
const idx = input.indexOf(':');
|
|
31
|
+
if (idx > 0) {
|
|
32
|
+
const prefix = input.slice(0, idx).toLowerCase();
|
|
33
|
+
const rest = input.slice(idx + 1).trim();
|
|
34
|
+
if (RUNTIMES.has(prefix) && rest) {
|
|
35
|
+
return { raw: input, runtime: prefix, query: rest };
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { raw: input, runtime: null, query: input };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function escapeXmlAttr(value) {
|
|
42
|
+
return String(value ?? '')
|
|
43
|
+
.replace(/&/g, '&')
|
|
44
|
+
.replace(/"/g, '"')
|
|
45
|
+
.replace(/</g, '<')
|
|
46
|
+
.replace(/>/g, '>');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function formatPeerMessageXml(envelope) {
|
|
50
|
+
const fromHandle =
|
|
51
|
+
envelope.from?.runtime && envelope.from?.name
|
|
52
|
+
? `${envelope.from.runtime}:${envelope.from.name}`
|
|
53
|
+
: envelope.from?.name || envelope.from?.id || 'external';
|
|
54
|
+
const shortId = envelope.from?.id ? ` (${String(envelope.from.id).slice(0, 8)})` : '';
|
|
55
|
+
const attrs = [
|
|
56
|
+
`msg-id="${escapeXmlAttr(envelope.msg_id)}"`,
|
|
57
|
+
`thread-id="${escapeXmlAttr(envelope.thread_id)}"`,
|
|
58
|
+
`from="${escapeXmlAttr(fromHandle + shortId)}"`,
|
|
59
|
+
`reply-to="${escapeXmlAttr(fromHandle)}"`,
|
|
60
|
+
`kind="${escapeXmlAttr(envelope.kind || 'prompt')}"`,
|
|
61
|
+
`reply-expected="${envelope.reply_expected ? 'true' : 'false'}"`,
|
|
62
|
+
`hop="${escapeXmlAttr(`${envelope.hop_count}/${envelope.max_hops}`)}"`,
|
|
63
|
+
];
|
|
64
|
+
const contract = envelope.contract;
|
|
65
|
+
if (contract?.request_id) {
|
|
66
|
+
attrs.push(`request-id="${escapeXmlAttr(contract.request_id)}"`);
|
|
67
|
+
attrs.push(`notify-on-finish="${contract.notify_on_finish !== false ? 'true' : 'false'}"`);
|
|
68
|
+
}
|
|
69
|
+
let bodyContent = String(envelope.body ?? '');
|
|
70
|
+
if (contract?.request_id) {
|
|
71
|
+
const cAttrs = [
|
|
72
|
+
`request-id="${escapeXmlAttr(contract.request_id)}"`,
|
|
73
|
+
`require-artifacts="${contract.require_artifacts ? 'true' : 'false'}"`,
|
|
74
|
+
];
|
|
75
|
+
if (contract.callback_to) {
|
|
76
|
+
cAttrs.push(`callback-to="${escapeXmlAttr(contract.callback_to)}"`);
|
|
77
|
+
}
|
|
78
|
+
const lines = [];
|
|
79
|
+
if (contract.title) lines.push(`Title: ${contract.title}`);
|
|
80
|
+
if (Array.isArray(contract.expected_artifacts) && contract.expected_artifacts.length > 0) {
|
|
81
|
+
lines.push(`Expected Artifacts:\n${contract.expected_artifacts.map((p) => `- ${p}`).join('\n')}`);
|
|
82
|
+
}
|
|
83
|
+
if (Array.isArray(contract.acceptance_criteria) && contract.acceptance_criteria.length > 0) {
|
|
84
|
+
lines.push(`Acceptance Criteria:\n${contract.acceptance_criteria.map((c) => `- ${c}`).join('\n')}`);
|
|
85
|
+
}
|
|
86
|
+
lines.push(
|
|
87
|
+
`Completion: When finished, interactive peers should call complete_task(request_id="${contract.request_id}", summary="...") or run \`pbridge task complete ${contract.request_id} "<summary>"\`.`,
|
|
88
|
+
);
|
|
89
|
+
bodyContent = `<task-contract ${cAttrs.join(' ')}>\n${lines.join('\n')}\n</task-contract>\n\n${bodyContent}`;
|
|
90
|
+
}
|
|
91
|
+
return `<peer-message ${attrs.join(' ')}>\n${bodyContent}\n</peer-message>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function verifyArtifacts(expectedArtifacts = [], baseCwd = process.cwd()) {
|
|
95
|
+
const list = Array.isArray(expectedArtifacts)
|
|
96
|
+
? expectedArtifacts.map((p) => String(p || '').trim()).filter(Boolean)
|
|
97
|
+
: [];
|
|
98
|
+
const present = [];
|
|
99
|
+
const missing = [];
|
|
100
|
+
for (const rel of list) {
|
|
101
|
+
const absPath = path.isAbsolute(rel) ? rel : path.resolve(baseCwd || process.cwd(), rel);
|
|
102
|
+
try {
|
|
103
|
+
const st = fs.statSync(absPath);
|
|
104
|
+
if (st.isFile() || st.isDirectory()) {
|
|
105
|
+
present.push({ path: rel, abs_path: absPath, size: st.size });
|
|
106
|
+
} else {
|
|
107
|
+
missing.push(rel);
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
missing.push(rel);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
verified: missing.length === 0,
|
|
115
|
+
expected: list,
|
|
116
|
+
present,
|
|
117
|
+
missing,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export function formatTaskCallbackXml(task) {
|
|
122
|
+
const verified = task.artifact_report ? Boolean(task.artifact_report.verified) : true;
|
|
123
|
+
const attrs = [
|
|
124
|
+
`request-id="${escapeXmlAttr(task.request_id)}"`,
|
|
125
|
+
`status="${escapeXmlAttr(task.status)}"`,
|
|
126
|
+
`from="${escapeXmlAttr(task.to_handle || task.to_peer_id)}"`,
|
|
127
|
+
`artifacts-verified="${verified ? 'true' : 'false'}"`,
|
|
128
|
+
];
|
|
129
|
+
if (task.workflow_id) {
|
|
130
|
+
attrs.push(`workflow-id="${escapeXmlAttr(task.workflow_id)}"`);
|
|
131
|
+
}
|
|
132
|
+
const parts = [];
|
|
133
|
+
if (task.title) parts.push(`Title: ${task.title}`);
|
|
134
|
+
if (task.result_summary) parts.push(`Summary: ${task.result_summary}`);
|
|
135
|
+
if (task.error) parts.push(`Error: ${task.error}`);
|
|
136
|
+
if (task.artifact_report?.present?.length) {
|
|
137
|
+
parts.push(
|
|
138
|
+
`Present Artifacts:\n${task.artifact_report.present.map((a) => `- ${a.path} (${a.size}B)`).join('\n')}`,
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (task.artifact_report?.missing?.length) {
|
|
142
|
+
parts.push(`Missing Artifacts:\n${task.artifact_report.missing.map((m) => `- ${m}`).join('\n')}`);
|
|
143
|
+
}
|
|
144
|
+
return `<task-result ${attrs.join(' ')}>\n${parts.join('\n') || 'Completed.'}\n</task-result>`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const AGY_MODEL_MAP = {
|
|
148
|
+
flash: 'gemini-4-hydrogen-low',
|
|
149
|
+
fast: 'gemini-4-hydrogen-low',
|
|
150
|
+
pro: 'gemini-4-hydrogen-medium',
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
export function resolveAgyModels(requested) {
|
|
154
|
+
const val = String(requested || 'flash').trim();
|
|
155
|
+
if (AGY_MODEL_MAP[val]) {
|
|
156
|
+
return { apiModel: val, cliModel: AGY_MODEL_MAP[val] };
|
|
157
|
+
}
|
|
158
|
+
return { apiModel: 'flash', cliModel: val };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function encodeFrame(obj) {
|
|
162
|
+
return `${JSON.stringify(obj)}\n`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function createLineSplitter(onLine) {
|
|
166
|
+
let buf = '';
|
|
167
|
+
return (chunk) => {
|
|
168
|
+
buf += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
169
|
+
let nl;
|
|
170
|
+
while ((nl = buf.indexOf('\n')) !== -1) {
|
|
171
|
+
const line = buf.slice(0, nl).trim();
|
|
172
|
+
buf = buf.slice(nl + 1);
|
|
173
|
+
if (line) onLine(line);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export class RpcError extends Error {
|
|
179
|
+
constructor(code, message, data = undefined) {
|
|
180
|
+
super(message);
|
|
181
|
+
this.name = 'RpcError';
|
|
182
|
+
this.code = code;
|
|
183
|
+
this.data = data;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function cleanSummary(text, maxLen = 120, { preferLast = false } = {}) {
|
|
188
|
+
if (!text) return '';
|
|
189
|
+
let s = String(text);
|
|
190
|
+
// Strip peer-bridge XML wrapper tags while preserving inner text
|
|
191
|
+
s = s.replace(/<\/?(?:peer-message|task-contract|task-result|workflow-result|expected-artifacts|acceptance-criteria)(?:\s[^>]*)?>/gi, ' ');
|
|
192
|
+
const lines = s
|
|
193
|
+
.split(/\r?\n/)
|
|
194
|
+
.map((line) => line.replace(/\s+/g, ' ').trim())
|
|
195
|
+
.filter((line) => line.length > 0 && !/^[-=`*#]{3,}$/.test(line));
|
|
196
|
+
if (!lines.length) return '';
|
|
197
|
+
let chosen = preferLast ? lines[lines.length - 1] : lines[0];
|
|
198
|
+
chosen = chosen.replace(/\s+/g, ' ').trim();
|
|
199
|
+
if (chosen.length > maxLen) {
|
|
200
|
+
return `${chosen.slice(0, Math.max(1, maxLen - 3)).trimEnd()}...`;
|
|
201
|
+
}
|
|
202
|
+
return chosen;
|
|
203
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export class ConversationApi {
|
|
2
|
+
constructor({ lsAddress, csrfToken, projectId } = {}) {
|
|
3
|
+
this.lsAddress = lsAddress || process.env.ANTIGRAVITY_LS_ADDRESS || null;
|
|
4
|
+
this.csrfToken = csrfToken || process.env.ANTIGRAVITY_CSRF_TOKEN || null;
|
|
5
|
+
this.projectId = projectId || process.env.ANTIGRAVITY_PROJECT_ID || 'default-cli-project';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
isConfigured() {
|
|
9
|
+
return Boolean(this.lsAddress && this.csrfToken);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async call(method, body) {
|
|
13
|
+
if (!this.isConfigured()) {
|
|
14
|
+
throw new Error('Missing Antigravity LS credentials (lsAddress / csrfToken)');
|
|
15
|
+
}
|
|
16
|
+
const url = `http://${this.lsAddress}/product.v1.ConversationService/${method}`;
|
|
17
|
+
const res = await fetch(url, {
|
|
18
|
+
method: 'POST',
|
|
19
|
+
headers: {
|
|
20
|
+
'Content-Type': 'application/json',
|
|
21
|
+
'Connect-Protocol-Version': '1',
|
|
22
|
+
'x-antigravity-csrf-token': this.csrfToken,
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify(body),
|
|
25
|
+
});
|
|
26
|
+
const text = await res.text();
|
|
27
|
+
let json;
|
|
28
|
+
try {
|
|
29
|
+
json = JSON.parse(text);
|
|
30
|
+
} catch {
|
|
31
|
+
json = { raw: text };
|
|
32
|
+
}
|
|
33
|
+
if (!res.ok) {
|
|
34
|
+
throw new Error(`ConversationService/${method} HTTP ${res.status}: ${text.slice(0, 300)}`);
|
|
35
|
+
}
|
|
36
|
+
return json;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async createConversation({ title, model = 'flash', tags = ['peer-bridge'], prompt, projectId } = {}) {
|
|
40
|
+
const payload = {
|
|
41
|
+
projectId: projectId || this.projectId,
|
|
42
|
+
title,
|
|
43
|
+
model,
|
|
44
|
+
tags,
|
|
45
|
+
};
|
|
46
|
+
if (prompt) payload.prompt = prompt;
|
|
47
|
+
return this.call('CreateConversation', payload);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async getConversation(conversationId) {
|
|
51
|
+
return this.call('GetConversation', { conversationId });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async listConversations(opts = {}) {
|
|
55
|
+
return this.call('ListConversations', opts);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async updateConversation(conversationId, annotations) {
|
|
59
|
+
return this.call('UpdateConversation', { conversationId, annotations });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
static isPeerBridgeOwned(payload) {
|
|
63
|
+
const c = payload?.conversation || payload || {};
|
|
64
|
+
const metaTags = Array.isArray(c.metadata?.tags) ? c.metadata.tags : [];
|
|
65
|
+
const annTags = Array.isArray(c.annotations?.tags) ? c.annotations.tags : [];
|
|
66
|
+
const title = String(c.annotations?.title || c.title || '');
|
|
67
|
+
return (
|
|
68
|
+
metaTags.includes('peer-bridge') ||
|
|
69
|
+
metaTags.includes('peer-bridge-poc') ||
|
|
70
|
+
annTags.includes('peer-bridge') ||
|
|
71
|
+
annTags.includes('peer-bridge-poc') ||
|
|
72
|
+
title.startsWith('peer-bridge:')
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async deleteConversation(conversationId, { force = false } = {}) {
|
|
77
|
+
if (!conversationId) {
|
|
78
|
+
throw new Error('INVALID_CONVERSATION_ID: conversationId is required');
|
|
79
|
+
}
|
|
80
|
+
const protectedIds = new Set(
|
|
81
|
+
[
|
|
82
|
+
process.env.ANTIGRAVITY_CONVERSATION_ID,
|
|
83
|
+
process.env.PBRIDGE_PROTECTED_CONVERSATION_ID,
|
|
84
|
+
].filter(Boolean),
|
|
85
|
+
);
|
|
86
|
+
if (protectedIds.has(conversationId)) {
|
|
87
|
+
throw new Error(
|
|
88
|
+
`SELF_DELETE_BLOCKED: Refusing to delete active/protected conversation ${conversationId}`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
if (!force) {
|
|
92
|
+
const existing = await this.getConversation(conversationId);
|
|
93
|
+
if (!ConversationApi.isPeerBridgeOwned(existing)) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`OWNERSHIP_MISMATCH: Refusing to delete conversation ${conversationId} without peer-bridge metadata tags (pass force=true to override)`,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return this.call('DeleteConversation', { conversationId });
|
|
100
|
+
}
|
|
101
|
+
}
|