convergedev 0.0.0-stage → 0.1.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.md +34 -0
- package/THIRD_PARTY_NOTICES.md +149 -0
- package/dist/agent-execution.js +103 -0
- package/dist/agent-process.js +70 -0
- package/dist/agent.js +2 -0
- package/dist/anchors.js +101 -0
- package/dist/applications.js +69 -0
- package/dist/apply-proposal.js +236 -0
- package/dist/bridge-health.js +57 -0
- package/dist/bridge.js +203 -0
- package/dist/change-proposals.js +51 -0
- package/dist/claude.js +277 -0
- package/dist/cli.js +278 -0
- package/dist/commands.js +80 -0
- package/dist/comment-file.js +41 -0
- package/dist/comment-host.js +96 -0
- package/dist/config.js +43 -0
- package/dist/converge.js +36 -0
- package/dist/exec.js +52 -0
- package/dist/follow-branch.js +70 -0
- package/dist/git.js +169 -0
- package/dist/hunks.js +558 -0
- package/dist/implementation-results.js +98 -0
- package/dist/implementation-runner.js +262 -0
- package/dist/queries/ecmascript.scm +35 -0
- package/dist/queries/javascript.scm +6 -0
- package/dist/queries/python.scm +10 -0
- package/dist/queries/typescript.scm +16 -0
- package/dist/relay.js +32 -0
- package/dist/runner.js +104 -0
- package/dist/sandbox.js +53 -0
- package/dist/session-state.js +36 -0
- package/dist/setup.js +328 -0
- package/dist/share-review.js +34 -0
- package/dist/shared.js +193 -0
- package/dist/skill/converge/SKILL.md +25 -0
- package/dist/skill/converge/converge.mjs +35 -0
- package/dist/skill-link.js +100 -0
- package/dist/worktree.js +231 -0
- package/grammars/SOURCES.json +22 -0
- package/grammars/tree-sitter-javascript.wasm +0 -0
- package/grammars/tree-sitter-python.wasm +0 -0
- package/grammars/tree-sitter-tsx.wasm +0 -0
- package/grammars/tree-sitter-typescript.wasm +0 -0
- package/package.json +45 -4
- package/README.md +0 -3
package/dist/setup.js
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
// First-run setup and diagnostics for the installed package (docs/review-room.md, decision 40). `converge` runs
|
|
2
|
+
// `initialize`: it checks what Converge needs on this machine, links the /converge skill into Claude Code (only once the
|
|
3
|
+
// developer agrees), and checks the relay; run again, it changes nothing. `converge doctor` runs `diagnose`: the same
|
|
4
|
+
// checks without changing anything, plus each saved room's access. Neither prints a token or a sign-in identity: a room
|
|
5
|
+
// is named by its title and id, a relay by its address.
|
|
6
|
+
//
|
|
7
|
+
// Everything outside this module (commands, the network, the prompt, where Claude Code keeps skills) comes in through
|
|
8
|
+
// `Machine`, so the tests can stand in for any of it.
|
|
9
|
+
import { execFileSync } from 'node:child_process';
|
|
10
|
+
import { existsSync, statSync, symlinkSync } from 'node:fs';
|
|
11
|
+
import { homedir } from 'node:os';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { createInterface } from 'node:readline/promises';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { BRIDGE_VERSION, describeConnectError } from './bridge-health.js';
|
|
16
|
+
import { CLAUDE_SETUP_DOCS, findClaude } from './claude.js';
|
|
17
|
+
import { configPath, loadConfig } from './config.js';
|
|
18
|
+
import { DEFAULT_RELAY } from './relay.js';
|
|
19
|
+
import { hasOsSandbox } from './sandbox.js';
|
|
20
|
+
import { linkSkill, skillPath, skillState } from './skill-link.js';
|
|
21
|
+
export { skillPath, skillState };
|
|
22
|
+
/** The oldest Node.js the package runs on (package.json engines). */
|
|
23
|
+
export const MIN_NODE_MAJOR = 20;
|
|
24
|
+
/** How long a relay may take to answer: a hosted relay that has gone to sleep takes up to about a minute to wake. */
|
|
25
|
+
export const RELAY_WAIT_MS = 60_000;
|
|
26
|
+
const COMMAND_WAIT_MS = 15_000;
|
|
27
|
+
/** This machine, as `converge` sees it when a developer runs it. */
|
|
28
|
+
export function thisMachine() {
|
|
29
|
+
return {
|
|
30
|
+
platform: process.platform,
|
|
31
|
+
nodeVersion: process.versions.node,
|
|
32
|
+
claudeDir: process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude'),
|
|
33
|
+
skillSource: fileURLToPath(new URL('./skill/converge', import.meta.url)),
|
|
34
|
+
relay: (process.env.AGENT_REVIEW_API_URL ?? DEFAULT_RELAY).replace(/\/$/, ''),
|
|
35
|
+
run: (command, args) => {
|
|
36
|
+
// An enclosing Claude Code session's marker would make `claude` refuse to start (claude.ts childEnv).
|
|
37
|
+
const { CLAUDECODE: _nested, ...env } = process.env;
|
|
38
|
+
try {
|
|
39
|
+
return { status: 0, stdout: execFileSync(command, args, { encoding: 'utf8', env, timeout: COMMAND_WAIT_MS, windowsHide: true, stdio: ['ignore', 'pipe', 'ignore'] }) };
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return { status: typeof err.status === 'number' ? err.status : null, stdout: String(err.stdout ?? '') };
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
claude: findClaude,
|
|
46
|
+
// A junction needs no administrator rights on Windows; Git Bash, where Claude Code runs the skill, reads the shebang.
|
|
47
|
+
link: (source, path) => symlinkSync(source, path, process.platform === 'win32' ? 'junction' : 'dir'),
|
|
48
|
+
fetch: (input, init) => fetch(input, init),
|
|
49
|
+
ask: async (question) => {
|
|
50
|
+
if (!process.stdin.isTTY)
|
|
51
|
+
return false;
|
|
52
|
+
const prompt = createInterface({ input: process.stdin, output: process.stdout });
|
|
53
|
+
try {
|
|
54
|
+
return !/^n/i.test((await prompt.question(`${question} [Y/n] `)).trim());
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
prompt.close();
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
out: (line) => console.log(line),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// ---- The checks ----
|
|
64
|
+
function runtime(m) {
|
|
65
|
+
const major = Number(m.nodeVersion.split('.')[0]);
|
|
66
|
+
const node = major >= MIN_NODE_MAJOR ? { status: 'ok', label: 'Node.js', detail: m.nodeVersion }
|
|
67
|
+
: { status: 'fix', label: 'Node.js', detail: `${m.nodeVersion} is too old`, fix: `Install Node.js ${MIN_NODE_MAJOR} or later (https://nodejs.org).` };
|
|
68
|
+
// The same rule that stops implementation requests on this platform (sandbox.ts); asking and reviewing work anywhere.
|
|
69
|
+
const sandbox = hasOsSandbox(m.platform) ? { status: 'ok', label: 'Implementing changes', detail: 'available (macOS sandbox)' }
|
|
70
|
+
: { status: 'note', label: 'Implementing changes', detail: 'needs macOS for now: on this platform your agent answers and reviews, and implementation requests fail' };
|
|
71
|
+
return [node, sandbox];
|
|
72
|
+
}
|
|
73
|
+
function git(m) {
|
|
74
|
+
const { status, stdout } = m.run('git', ['--version']);
|
|
75
|
+
if (status === 0)
|
|
76
|
+
return { status: 'ok', label: 'Git', detail: stdout.trim().replace(/^git version /, '') };
|
|
77
|
+
return { status: 'fix', label: 'Git', detail: 'not found', fix: 'Install Git (https://git-scm.com/downloads), then run converge again.' };
|
|
78
|
+
}
|
|
79
|
+
/** Claude Code, and whether it is signed in where this version can say (`claude auth status`). */
|
|
80
|
+
function claude(m) {
|
|
81
|
+
const cmd = m.claude();
|
|
82
|
+
if (!cmd)
|
|
83
|
+
return [{ status: 'fix', label: 'Claude Code', detail: 'not found', fix: `Install it as ${CLAUDE_SETUP_DOCS} describes, sign in, then run converge again.` }];
|
|
84
|
+
const version = m.run(cmd.command, [...cmd.prefix, '--version']);
|
|
85
|
+
if (version.status !== 0) {
|
|
86
|
+
return [{ status: 'fix', label: 'Claude Code', detail: `found at ${cmd.command} but it did not start`, fix: `Reinstall it as ${CLAUDE_SETUP_DOCS} describes.` }];
|
|
87
|
+
}
|
|
88
|
+
const found = { status: 'ok', label: 'Claude Code', detail: version.stdout.trim() };
|
|
89
|
+
// Only whether it is signed in: the answer also names the account, which is not this tool's to print.
|
|
90
|
+
let loggedIn;
|
|
91
|
+
try {
|
|
92
|
+
loggedIn = JSON.parse(m.run(cmd.command, [...cmd.prefix, 'auth', 'status']).stdout).loggedIn;
|
|
93
|
+
}
|
|
94
|
+
catch { /* older Claude Code */ }
|
|
95
|
+
const signIn = loggedIn === true ? { status: 'ok', label: 'Claude Code sign-in', detail: 'signed in' }
|
|
96
|
+
: loggedIn === false ? { status: 'fix', label: 'Claude Code sign-in', detail: 'not signed in', fix: 'Run claude and sign in (/login), then run converge again.' }
|
|
97
|
+
: { status: 'note', label: 'Claude Code sign-in', detail: "this version can't say; if Claude Code asks you to sign in, run /login" };
|
|
98
|
+
return [found, signIn];
|
|
99
|
+
}
|
|
100
|
+
function describeSkill(m, state) {
|
|
101
|
+
const where = skillPath(m);
|
|
102
|
+
const label = '/converge skill';
|
|
103
|
+
if (state.kind === 'linked')
|
|
104
|
+
return { status: 'ok', label, detail: `installed (${where})` };
|
|
105
|
+
if (state.kind === 'npx')
|
|
106
|
+
return { status: 'fix', label, detail: 'not installed from npx', fix: 'Install Converge with npm install -g convergedev, then run converge.' };
|
|
107
|
+
if (state.kind === 'foreign') {
|
|
108
|
+
return { status: 'fix', label, detail: `${where} is something else, so it was left alone`,
|
|
109
|
+
fix: `If it is an old copy of Converge's skill, remove it, then run converge again.` };
|
|
110
|
+
}
|
|
111
|
+
if (state.kind === 'other')
|
|
112
|
+
return { status: 'fix', label, detail: `links to another Converge (${state.target})`, fix: 'Run converge to point it at this installation.' };
|
|
113
|
+
if (state.kind === 'broken')
|
|
114
|
+
return { status: 'fix', label, detail: `its link to ${state.target} is broken (Converge was moved or uninstalled)`, fix: 'Run converge to repair it.' };
|
|
115
|
+
return { status: 'fix', label, detail: 'not installed', fix: 'Run converge to install it.' };
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* An address as setup and doctor may print it: scheme, host and path only. A user name, password, query or fragment
|
|
119
|
+
* can carry a secret (a token in `?token=`, credentials in `user:pass@`), so none of them is ever shown; text that
|
|
120
|
+
* isn't a URL at all is not shown either.
|
|
121
|
+
*/
|
|
122
|
+
export function displayUrl(address) {
|
|
123
|
+
try {
|
|
124
|
+
const url = new URL(address);
|
|
125
|
+
return `${url.protocol}//${url.host}${url.pathname === '/' ? '' : url.pathname}`;
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
return '(an address that is not a valid URL)';
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/** Every URL in `text`, as `displayUrl` shows it: the last guard on each line printed, whatever put a URL there. */
|
|
132
|
+
export const redactUrls = (text) => text.replace(/\b[a-z][a-z0-9+.-]*:\/\/[^\s"'<>()]+/gi, (url) => displayUrl(url.replace(/[.,;:]+$/, '')) + (url.match(/[.,;:]+$/)?.[0] ?? ''));
|
|
133
|
+
/** Why `url` can't be a relay's address, or null when it can: http(s), no credentials, query or fragment in it. */
|
|
134
|
+
export function relayUrlProblem(url) {
|
|
135
|
+
let parsed;
|
|
136
|
+
try {
|
|
137
|
+
parsed = new URL(url);
|
|
138
|
+
}
|
|
139
|
+
catch {
|
|
140
|
+
return 'not a URL';
|
|
141
|
+
}
|
|
142
|
+
if (parsed.protocol !== 'https:' && parsed.protocol !== 'http:')
|
|
143
|
+
return `${parsed.protocol} is not http or https`;
|
|
144
|
+
if (parsed.username || parsed.password)
|
|
145
|
+
return 'it has a user name or password in it';
|
|
146
|
+
if (parsed.search || parsed.hash)
|
|
147
|
+
return 'it has a query or fragment';
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A request to a relay that never follows a redirect: a room's token must reach only the relay that issued it
|
|
152
|
+
* (decision 13), and a relay that redirects is not answering as a relay. The response, or the reason there is none.
|
|
153
|
+
*/
|
|
154
|
+
async function ask(m, url, token) {
|
|
155
|
+
try {
|
|
156
|
+
const response = await m.fetch(url, { redirect: 'manual', signal: AbortSignal.timeout(RELAY_WAIT_MS),
|
|
157
|
+
headers: token ? { Authorization: `Bearer ${token}` } : {} });
|
|
158
|
+
if (response.status >= 300 && response.status < 400) {
|
|
159
|
+
// Where it points is shown without query or credentials: a redirect may carry a token in its Location.
|
|
160
|
+
const location = response.headers.get('location');
|
|
161
|
+
let to = '';
|
|
162
|
+
try {
|
|
163
|
+
if (location)
|
|
164
|
+
to = ` to ${displayUrl(new URL(location, url).href)}`;
|
|
165
|
+
}
|
|
166
|
+
catch { /* unreadable Location */ }
|
|
167
|
+
return { failed: `it redirects (HTTP ${response.status}${to}), which is not followed` };
|
|
168
|
+
}
|
|
169
|
+
return { response };
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
return { failed: err?.name === 'TimeoutError' ? `no answer within ${RELAY_WAIT_MS / 1000}s` : describeConnectError(err?.cause ?? err) };
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/** A JSON object from a response's body, or null for anything else (an HTML page, a bare value, nothing). */
|
|
176
|
+
async function jsonObject(response) {
|
|
177
|
+
try {
|
|
178
|
+
const value = JSON.parse(await response.text());
|
|
179
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
return null;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/** The relay answers as a Converge relay, and expects a bridge protocol this package speaks. */
|
|
186
|
+
async function relay(m) {
|
|
187
|
+
const label = 'Relay';
|
|
188
|
+
const shown = displayUrl(m.relay);
|
|
189
|
+
const bad = relayUrlProblem(m.relay);
|
|
190
|
+
if (bad)
|
|
191
|
+
return { status: 'fix', label, detail: `the relay address ${shown} can't be used: ${bad}`, fix: "Set AGENT_REVIEW_API_URL to the relay's https:// address, or unset it to use the hosted relay." };
|
|
192
|
+
const answer = await ask(m, `${m.relay}/version`);
|
|
193
|
+
if ('failed' in answer) {
|
|
194
|
+
return { status: 'fix', label, detail: `can't use ${shown}: ${answer.failed}`,
|
|
195
|
+
fix: 'Check your network connection and run converge again. For a relay of your own, set AGENT_REVIEW_API_URL to its own address.' };
|
|
196
|
+
}
|
|
197
|
+
const { response } = answer;
|
|
198
|
+
const body = await jsonObject(response);
|
|
199
|
+
if (response.status >= 500)
|
|
200
|
+
return { status: 'fix', label, detail: `${shown} answered ${response.status}`, fix: 'The relay has a problem; try again later.' };
|
|
201
|
+
// A relay from before GET /version answers FastAPI's own 404 ({"detail": ...}).
|
|
202
|
+
if (response.status === 404 && body && 'detail' in body) {
|
|
203
|
+
return { status: 'ok', label, detail: `${shown} reachable; it does not report its bridge protocol, so it is checked when your agent connects` };
|
|
204
|
+
}
|
|
205
|
+
const expected = response.ok ? body?.bridge_version : undefined;
|
|
206
|
+
if (typeof expected !== 'number') {
|
|
207
|
+
return { status: 'fix', label, detail: `${shown} answered (HTTP ${response.status}), but not as a Converge relay`,
|
|
208
|
+
fix: "Check AGENT_REVIEW_API_URL names the relay itself, not the room's web address or a proxy's sign-in page." };
|
|
209
|
+
}
|
|
210
|
+
if (expected > BRIDGE_VERSION) {
|
|
211
|
+
return { status: 'fix', label, detail: `${shown} expects bridge protocol ${expected}; this Converge speaks ${BRIDGE_VERSION}`,
|
|
212
|
+
fix: 'Update Converge: npm install -g convergedev@latest' };
|
|
213
|
+
}
|
|
214
|
+
return { status: 'ok', label, detail: `${shown} reachable, bridge protocol ${expected}` };
|
|
215
|
+
}
|
|
216
|
+
const REJOIN = 'Open the room, choose Connect Claude Code, and run the /converge join command it shows.';
|
|
217
|
+
/** One saved room's access, asked of the relay that issued it with its own token, which is never sent anywhere else. */
|
|
218
|
+
async function room(m, saved) {
|
|
219
|
+
const label = `Room ${saved.title} (${saved.roomId})`;
|
|
220
|
+
const bad = relayUrlProblem(saved.apiUrl);
|
|
221
|
+
if (bad)
|
|
222
|
+
return { status: 'fix', label, detail: `its saved relay address can't be used (${bad}), so its token was not sent`, fix: REJOIN };
|
|
223
|
+
const answer = await ask(m, `${saved.apiUrl}/agent-grants/self`, saved.agentToken);
|
|
224
|
+
if ('failed' in answer)
|
|
225
|
+
return { status: 'fix', label, detail: `can't use its relay ${displayUrl(saved.apiUrl)}: ${answer.failed}`, fix: 'Check your network connection.' };
|
|
226
|
+
const { response } = answer;
|
|
227
|
+
if (response.status === 401 || response.status === 403 || response.status === 404)
|
|
228
|
+
return { status: 'fix', label, detail: 'access revoked or expired', fix: REJOIN };
|
|
229
|
+
if (!response.ok)
|
|
230
|
+
return { status: 'fix', label, detail: `its relay answered ${response.status}`, fix: 'Try again later.' };
|
|
231
|
+
const s = await jsonObject(response);
|
|
232
|
+
if (!s || typeof s.online !== 'boolean') {
|
|
233
|
+
return { status: 'fix', label, detail: `its relay ${displayUrl(saved.apiUrl)} answered, but not as a Converge relay`, fix: 'Try again later; if it persists, rejoin the room.' };
|
|
234
|
+
}
|
|
235
|
+
const bridge = s.bridge && typeof s.bridge === 'object' ? s.bridge : null;
|
|
236
|
+
if (bridge?.outdated === true) {
|
|
237
|
+
return { status: 'fix', label, detail: `its agent runs an outdated bridge (protocol ${bridge.version}; the relay expects ${bridge.expected})`,
|
|
238
|
+
fix: `Update Converge, then in Claude Code run /converge join ${saved.roomId} to restart it; its access is kept.` };
|
|
239
|
+
}
|
|
240
|
+
if (!s.online)
|
|
241
|
+
return { status: 'note', label, detail: 'access active, agent not running', fix: `In Claude Code, run /converge join ${saved.roomId} to start it.` };
|
|
242
|
+
return { status: 'ok', label, detail: 'access active, agent connected' };
|
|
243
|
+
}
|
|
244
|
+
/** Each saved room's access, and whether the file holding their tokens is private. One room's failure never stops the rest. */
|
|
245
|
+
async function rooms(m) {
|
|
246
|
+
const path = configPath();
|
|
247
|
+
if (!existsSync(path))
|
|
248
|
+
return [{ status: 'ok', label: 'Rooms', detail: 'none joined on this machine yet' }];
|
|
249
|
+
const checks = [];
|
|
250
|
+
// The tokens are this machine's access to each room; config.ts writes the file 0600 in a 0700 folder.
|
|
251
|
+
if (m.platform !== 'win32' && statSync(path).mode & 0o077) {
|
|
252
|
+
checks.push({ status: 'fix', label: 'Saved credentials', detail: `${path} can be read by other users`, fix: `chmod 600 "${path}"` });
|
|
253
|
+
}
|
|
254
|
+
const saved = Object.values((await loadConfig()).rooms);
|
|
255
|
+
if (!saved.length)
|
|
256
|
+
checks.push({ status: 'ok', label: 'Rooms', detail: 'none joined on this machine' });
|
|
257
|
+
for (const one of saved) {
|
|
258
|
+
try {
|
|
259
|
+
checks.push(await room(m, one));
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
checks.push({ status: 'fix', label: `Room ${one?.title} (${one?.roomId})`, detail: `couldn't be checked: ${err?.message ?? err}`, fix: REJOIN });
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return checks;
|
|
266
|
+
}
|
|
267
|
+
// ---- The two commands ----
|
|
268
|
+
const MARKS = { ok: '✓', fix: '✗', note: '•' };
|
|
269
|
+
// The Windows console may not show those; plain letters always read.
|
|
270
|
+
const PLAIN_MARKS = { ok: 'ok', fix: '!!', note: '--' };
|
|
271
|
+
function report(m, c) {
|
|
272
|
+
m.out(redactUrls(` ${(m.platform === 'win32' ? PLAIN_MARKS : MARKS)[c.status]} ${c.label}: ${c.detail}`));
|
|
273
|
+
if (c.fix)
|
|
274
|
+
m.out(redactUrls(` ${c.fix}`));
|
|
275
|
+
}
|
|
276
|
+
const NEXT = 'In Claude Code, inside your repository:\n' +
|
|
277
|
+
' /converge review open a review room for this branch\n' +
|
|
278
|
+
' /converge build "<task>" open a development room for a task\n' +
|
|
279
|
+
' /converge join <room> ... paste the command a room shows under "Connect Claude Code"';
|
|
280
|
+
/**
|
|
281
|
+
* `converge`: checks this machine, links the skill if it is missing or stale (asking first, unless `yes`), checks the
|
|
282
|
+
* relay. Idempotent: a second run finds everything in place and changes nothing. Returns the exit code.
|
|
283
|
+
*/
|
|
284
|
+
export async function initialize(m, { yes = false } = {}) {
|
|
285
|
+
const checks = [...runtime(m), git(m), ...claude(m)];
|
|
286
|
+
checks.forEach((c) => report(m, c));
|
|
287
|
+
let state = skillState(m);
|
|
288
|
+
let linkError;
|
|
289
|
+
if (state.kind === 'missing' || state.kind === 'other' || state.kind === 'broken') {
|
|
290
|
+
const verb = state.kind === 'missing' ? 'Install' : 'Repair';
|
|
291
|
+
if (yes || await m.ask(`${verb} the /converge skill for Claude Code (a link at ${skillPath(m)})?`)) {
|
|
292
|
+
try {
|
|
293
|
+
linkSkill(m, state.kind !== 'missing');
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
linkError = err.message;
|
|
297
|
+
}
|
|
298
|
+
state = skillState(m);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
const skill = describeSkill(m, state);
|
|
302
|
+
if (linkError) {
|
|
303
|
+
skill.detail = `could not be linked (${linkError}); ${state.kind === 'missing' ? 'nothing was installed' : 'the earlier link is unchanged'}`;
|
|
304
|
+
skill.fix = `Check that ${dirname(skillPath(m))} is writable, then run converge again.`;
|
|
305
|
+
}
|
|
306
|
+
else if (skill.fix && (state.kind === 'missing' || state.kind === 'other' || state.kind === 'broken')) {
|
|
307
|
+
skill.fix = 'Run converge again and answer yes, or run converge --yes.';
|
|
308
|
+
}
|
|
309
|
+
report(m, skill);
|
|
310
|
+
m.out(` … checking the relay (a sleeping relay can take up to a minute)`);
|
|
311
|
+
const relayCheck = await relay(m);
|
|
312
|
+
report(m, relayCheck);
|
|
313
|
+
const all = [...checks, skill, relayCheck];
|
|
314
|
+
if (all.some((c) => c.status === 'fix')) {
|
|
315
|
+
m.out('\nConverge is not ready yet: fix the lines marked above, then run converge again.');
|
|
316
|
+
return 1;
|
|
317
|
+
}
|
|
318
|
+
m.out(`\nConverge is ready. ${NEXT}`);
|
|
319
|
+
return 0;
|
|
320
|
+
}
|
|
321
|
+
/** `converge doctor`: the same checks as `initialize` and each saved room's access, changing nothing. */
|
|
322
|
+
export async function diagnose(m) {
|
|
323
|
+
const all = [...runtime(m), git(m), ...claude(m), describeSkill(m, skillState(m)), await relay(m), ...await rooms(m)];
|
|
324
|
+
all.forEach((c) => report(m, c));
|
|
325
|
+
const problems = all.filter((c) => c.status === 'fix').length;
|
|
326
|
+
m.out(problems ? `\n${problems} problem${problems === 1 ? '' : 's'} found.` : '\nNo problems found.');
|
|
327
|
+
return problems ? 1 : 0;
|
|
328
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Shares committed work with a room: what `/converge update` sends (the checkout, which can point the room at another
|
|
2
|
+
// branch) and what the owner's background agent sends when the room's branch moves (docs/review-room.md decision 15).
|
|
3
|
+
// Git is only read, and only commits leave the machine.
|
|
4
|
+
import { loadConfig, saveRoom } from './config.js';
|
|
5
|
+
import { collectReview } from './git.js';
|
|
6
|
+
import { api, OWNER_ROLE } from './relay.js';
|
|
7
|
+
/** The branch a room's snapshot was taken from (a task room's starting branch before any). Null for a detached HEAD. */
|
|
8
|
+
export function roomBranch(session) {
|
|
9
|
+
const branch = session.review?.branch ?? session.repository?.branch;
|
|
10
|
+
return branch && branch !== 'HEAD' ? branch : null;
|
|
11
|
+
}
|
|
12
|
+
/** Shares `ref` (the checkout by default) with the room, and remembers the base and branch it was shared from. */
|
|
13
|
+
export async function shareReview(room, options = {}) {
|
|
14
|
+
const session = await api('/agent-grants/self', { token: room.agentToken, base: room.apiUrl });
|
|
15
|
+
// The relay refuses anyone else's snapshot too; checking first keeps a reviewer's diff on their machine. A relay
|
|
16
|
+
// older than the role field is left to refuse it.
|
|
17
|
+
if (session.role !== undefined && session.role !== OWNER_ROLE) {
|
|
18
|
+
throw new Error("Only the room owner's agent shares changes with the room.");
|
|
19
|
+
}
|
|
20
|
+
// A development session starts from the commit it was pinned to, even on the default branch, where detecting a base
|
|
21
|
+
// would find HEAD itself. A base given now or saved by an earlier share wins, so `update --base` lasts.
|
|
22
|
+
const pinned = session.kind === 'development' ? session.repository?.base_sha : undefined;
|
|
23
|
+
const collected = await collectReview(room.projectDir, options.base ?? room.baseRef ?? pinned, options.ref);
|
|
24
|
+
await api(`/rooms/${room.roomId}/review`, {
|
|
25
|
+
method: 'PUT', token: room.agentToken, base: room.apiUrl, body: JSON.stringify(collected.snapshot),
|
|
26
|
+
});
|
|
27
|
+
const { base_ref: baseRef, branch: shared } = collected.snapshot;
|
|
28
|
+
const branch = shared === 'HEAD' ? null : shared;
|
|
29
|
+
// Read again just before writing: another /converge command may have saved this room while the snapshot was taken.
|
|
30
|
+
const stored = (await loadConfig()).rooms[room.roomId] ?? room;
|
|
31
|
+
if (stored.baseRef !== baseRef || stored.branch !== branch)
|
|
32
|
+
await saveRoom({ ...stored, baseRef, branch });
|
|
33
|
+
return collected;
|
|
34
|
+
}
|
package/dist/shared.js
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { OWNER_ROLE } from './relay.js';
|
|
3
|
+
/**
|
|
4
|
+
* `stateBytes` stays under the relay's 2 MB cap on shared_state (apps/api/realtime.py). The content caps keep one
|
|
5
|
+
* comment's item well under the relay's 64 KB per op; the web cuts content to the same caps (review.ts CONTENT_LIMITS).
|
|
6
|
+
*/
|
|
7
|
+
export const LIMITS = {
|
|
8
|
+
comments: 1000, replies: 200, text: 4000, title: 120, batch: 50, reserved: 500, mentions: 20, stateBytes: 1_900_000,
|
|
9
|
+
contentRows: 100, contextRows: 3, contentChars: 300,
|
|
10
|
+
};
|
|
11
|
+
const isObj = (x) => typeof x === 'object' && x !== null && !Array.isArray(x);
|
|
12
|
+
const str = (x, max) => (typeof x === 'string' && x.length <= max ? x : undefined);
|
|
13
|
+
const text = (x, max) => { const s = typeof x === 'string' ? x.trim() : ''; return s && s.length <= max ? s : undefined; };
|
|
14
|
+
const int = (x) => (Number.isInteger(x) && x >= 0 ? x : undefined);
|
|
15
|
+
function lineRef(x) {
|
|
16
|
+
if (x === null || x === undefined)
|
|
17
|
+
return null;
|
|
18
|
+
if (!isObj(x))
|
|
19
|
+
return undefined;
|
|
20
|
+
const a = int(x.a), b = int(x.b), label = str(x.label, 60);
|
|
21
|
+
// A label is one short line ("Lines 47–52"): it goes into agent prompts (web/lib/prompts.ts), so no line breaks.
|
|
22
|
+
const oneLine = label !== undefined && !/[\u0000-\u001f\u007f]/.test(label);
|
|
23
|
+
return a !== undefined && b !== undefined && a <= b && label && oneLine ? { a, b, label } : undefined;
|
|
24
|
+
}
|
|
25
|
+
function rows(x, max) {
|
|
26
|
+
return Array.isArray(x) && x.length <= max && x.every((r) => str(r, LIMITS.contentChars) !== undefined) ? x : undefined;
|
|
27
|
+
}
|
|
28
|
+
/** Content over a cap or malformed is dropped, not the comment: it then stays on its hunk as before, by key. */
|
|
29
|
+
function content(x) {
|
|
30
|
+
if (!isObj(x))
|
|
31
|
+
return null;
|
|
32
|
+
const lines = rows(x.lines, LIMITS.contentRows), before = rows(x.before, LIMITS.contextRows), after = rows(x.after, LIMITS.contextRows);
|
|
33
|
+
return lines?.length && before && after ? { lines, before, after } : null;
|
|
34
|
+
}
|
|
35
|
+
function anchor(x) {
|
|
36
|
+
if (!isObj(x))
|
|
37
|
+
return undefined;
|
|
38
|
+
const path = str(x.path, 1000), hunk = str(x.hunk, 1500), head_sha = str(x.head_sha, 64), lines = lineRef(x.lines);
|
|
39
|
+
const cp = x.cp === undefined || x.cp === null ? null : str(x.cp, 32);
|
|
40
|
+
return path && hunk && head_sha !== undefined && lines !== undefined && cp !== undefined
|
|
41
|
+
? { path, hunk, head_sha, lines, content: content(x.content), cp } : undefined;
|
|
42
|
+
}
|
|
43
|
+
function resolution(x) {
|
|
44
|
+
if (!isObj(x))
|
|
45
|
+
return null;
|
|
46
|
+
const by = actorOf(x.by), at = str(x.at, 64);
|
|
47
|
+
return by && at ? { by, at } : null;
|
|
48
|
+
}
|
|
49
|
+
function mentions(x) {
|
|
50
|
+
return Array.isArray(x) ? [...new Set(x.filter((m) => typeof m === 'string' && m.length <= 64))].slice(0, LIMITS.mentions) : [];
|
|
51
|
+
}
|
|
52
|
+
function actorOf(x) {
|
|
53
|
+
if (!isObj(x))
|
|
54
|
+
return undefined;
|
|
55
|
+
const member_id = str(x.member_id, 64), name = str(x.name, 200), role = str(x.role, 20);
|
|
56
|
+
return member_id && name !== undefined && role ? { member_id, name, role } : undefined;
|
|
57
|
+
}
|
|
58
|
+
export class SharedStore {
|
|
59
|
+
now;
|
|
60
|
+
newId;
|
|
61
|
+
state = { rev: 0, next_num: 1, reserved: [], comments: [] };
|
|
62
|
+
constructor(now = () => new Date().toISOString(), newId = randomUUID) {
|
|
63
|
+
this.now = now;
|
|
64
|
+
this.newId = newId;
|
|
65
|
+
}
|
|
66
|
+
get() { return this.state; }
|
|
67
|
+
/** Applies one op from the relay. `actor` is the relay's word for who sent it; ops never name their own author.
|
|
68
|
+
* Returns whether the state changed. Malformed ops and ops over a limit change nothing. */
|
|
69
|
+
apply(op, actorRaw) {
|
|
70
|
+
const actor = actorOf(actorRaw);
|
|
71
|
+
if (!actor || !isObj(op))
|
|
72
|
+
return false;
|
|
73
|
+
const before = this.state;
|
|
74
|
+
const changed = op.kind === 'reserve' ? this.reserve(op, actor)
|
|
75
|
+
: op.kind === 'post' ? this.post(op, actor)
|
|
76
|
+
: op.kind === 'reply' ? this.reply(op, actor)
|
|
77
|
+
: op.kind === 'resolve' ? this.resolve(op, actor)
|
|
78
|
+
: false;
|
|
79
|
+
if (!changed)
|
|
80
|
+
return false;
|
|
81
|
+
// The relay drops a state over its size cap, so a change that would pass it is refused here instead.
|
|
82
|
+
if (Buffer.byteLength(JSON.stringify(this.state)) > LIMITS.stateBytes) {
|
|
83
|
+
this.state = before;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
this.state = { ...this.state, rev: this.state.rev + 1 };
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
reserve(op, actor) {
|
|
90
|
+
const client_id = str(op.client_id, 64);
|
|
91
|
+
if (!client_id)
|
|
92
|
+
return false;
|
|
93
|
+
const s = this.state;
|
|
94
|
+
if (s.reserved.some((r) => r.member_id === actor.member_id && r.client_id === client_id))
|
|
95
|
+
return false;
|
|
96
|
+
const reserved = [...s.reserved, { num: s.next_num, member_id: actor.member_id, client_id }].slice(-LIMITS.reserved);
|
|
97
|
+
this.state = { ...s, next_num: s.next_num + 1, reserved };
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
post(op, actor) {
|
|
101
|
+
if (!Array.isArray(op.items) || !op.items.length || op.items.length > LIMITS.batch)
|
|
102
|
+
return false;
|
|
103
|
+
let { next_num, reserved, comments } = this.state;
|
|
104
|
+
let changed = false;
|
|
105
|
+
for (const raw of op.items) {
|
|
106
|
+
if (!isObj(raw) || comments.length >= LIMITS.comments)
|
|
107
|
+
continue;
|
|
108
|
+
const body = text(raw.text, LIMITS.text), at = anchor(raw.anchor), client_id = str(raw.client_id, 64) ?? null;
|
|
109
|
+
const title = raw.title === null || raw.title === undefined ? null : text(raw.title, LIMITS.title) ?? null;
|
|
110
|
+
if (!body || !at)
|
|
111
|
+
continue;
|
|
112
|
+
// A retried post (same author, same draft) is not posted twice.
|
|
113
|
+
if (client_id && comments.some((c) => c.author.member_id === actor.member_id && c.client_id === client_id))
|
|
114
|
+
continue;
|
|
115
|
+
const mine = reserved.find((r) => r.member_id === actor.member_id && (r.num === raw.num || (client_id !== null && r.client_id === client_id)));
|
|
116
|
+
let num;
|
|
117
|
+
if (mine) {
|
|
118
|
+
num = mine.num;
|
|
119
|
+
reserved = reserved.filter((r) => r !== mine);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
num = next_num;
|
|
123
|
+
next_num += 1;
|
|
124
|
+
}
|
|
125
|
+
comments = [...comments, { id: this.newId(), num, client_id, title, text: body, at: this.now(), author: actor,
|
|
126
|
+
anchor: at, mentions: mentions(raw.mentions), replies: [], outdated: false, resolved: null }];
|
|
127
|
+
changed = true;
|
|
128
|
+
}
|
|
129
|
+
if (changed)
|
|
130
|
+
this.state = { ...this.state, next_num, reserved, comments };
|
|
131
|
+
return changed;
|
|
132
|
+
}
|
|
133
|
+
reply(op, actor) {
|
|
134
|
+
const id = str(op.comment_id, 64), body = text(op.text, LIMITS.text), lines = lineRef(op.lines);
|
|
135
|
+
const target = this.state.comments.find((c) => c.id === id);
|
|
136
|
+
if (!target || !body || lines === undefined || target.replies.length >= LIMITS.replies)
|
|
137
|
+
return false;
|
|
138
|
+
const reply = { id: this.newId(), author: actor, at: this.now(), text: body, lines, mentions: mentions(op.mentions) };
|
|
139
|
+
this.state = { ...this.state, comments: this.state.comments.map((c) => (c === target ? { ...c, replies: [...c.replies, reply] } : c)) };
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
/** The comment's author or the room owner marks a thread done, or opens it again. */
|
|
143
|
+
resolve(op, actor) {
|
|
144
|
+
const target = this.state.comments.find((c) => c.id === str(op.comment_id, 64));
|
|
145
|
+
if (!target || typeof op.resolved !== 'boolean')
|
|
146
|
+
return false;
|
|
147
|
+
if (actor.member_id !== target.author.member_id && actor.role !== OWNER_ROLE)
|
|
148
|
+
return false;
|
|
149
|
+
if (op.resolved === (target.resolved !== null))
|
|
150
|
+
return false;
|
|
151
|
+
const resolved = op.resolved ? { by: actor, at: this.now() } : null;
|
|
152
|
+
this.state = { ...this.state, comments: this.state.comments.map((c) => (c === target ? { ...c, resolved } : c)) };
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Starts from a state this store saved earlier (the comment file). Comments that do not hold up are dropped; ones
|
|
157
|
+
* saved before a field existed get its default. Returns whether anything was restored.
|
|
158
|
+
*/
|
|
159
|
+
restore(saved) {
|
|
160
|
+
if (!isObj(saved) || int(saved.rev) === undefined || int(saved.next_num) === undefined
|
|
161
|
+
|| !Array.isArray(saved.reserved) || !Array.isArray(saved.comments))
|
|
162
|
+
return false;
|
|
163
|
+
const comments = saved.comments.flatMap((raw) => {
|
|
164
|
+
if (!isObj(raw))
|
|
165
|
+
return [];
|
|
166
|
+
const at = anchor(raw.anchor), author = actorOf(raw.author);
|
|
167
|
+
if (!at || !author || !str(raw.id, 64) || int(raw.num) === undefined || !Array.isArray(raw.replies))
|
|
168
|
+
return [];
|
|
169
|
+
return [{ ...raw, author, anchor: at, outdated: raw.outdated === true, resolved: resolution(raw.resolved) }];
|
|
170
|
+
});
|
|
171
|
+
this.state = { rev: saved.rev, next_num: saved.next_num,
|
|
172
|
+
reserved: saved.reserved, comments };
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Puts the comments where anchors.ts found them in a new snapshot: the same comments, in the same order, with their
|
|
177
|
+
* anchors and outdated flags updated. Returns whether any of them moved.
|
|
178
|
+
*/
|
|
179
|
+
relocate(placed) {
|
|
180
|
+
const byId = new Map(placed.map((c) => [c.id, c]));
|
|
181
|
+
let changed = false;
|
|
182
|
+
const comments = this.state.comments.map((c) => {
|
|
183
|
+
const p = byId.get(c.id);
|
|
184
|
+
if (!p || (JSON.stringify(p.anchor) === JSON.stringify(c.anchor) && p.outdated === c.outdated))
|
|
185
|
+
return c;
|
|
186
|
+
changed = true;
|
|
187
|
+
return { ...c, anchor: p.anchor, outdated: p.outdated };
|
|
188
|
+
});
|
|
189
|
+
if (changed)
|
|
190
|
+
this.state = { ...this.state, rev: this.state.rev + 1, comments };
|
|
191
|
+
return changed;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: converge
|
|
3
|
+
description: Create a Converge review room for this branch or a development room for a task, or join, check, update or leave a room, with your own agent connected.
|
|
4
|
+
argument-hint: review [--title <t>] [--base <ref>] | build "<task>" | join <room-url> --code <code> | update | status | leave
|
|
5
|
+
disable-model-invocation: true
|
|
6
|
+
allowed-tools: Bash(${CLAUDE_SKILL_DIR}/converge.mjs:*)
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# /converge
|
|
10
|
+
|
|
11
|
+
Converge has already run with the user's arguments, before this prompt was sent. Its output:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
!`"${CLAUDE_SKILL_DIR}/converge.mjs" $ARGUMENTS 2>&1 || echo "[converge exited with an error]"`
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Relay that result to the user. Do not run any commands, and do not retry or "fix" anything yourself.
|
|
18
|
+
|
|
19
|
+
- **Success:** restate the key lines briefly.
|
|
20
|
+
- `review`, `build`: what is shared (the `Sharing committed changes:` line, or for `build` the `Starting a development session at` line), the room URL, the owner link, and whether the agent connected. Warn that the owner link grants owner access: keep it private and never paste it into the room or a commit.
|
|
21
|
+
- `join`, `status`, `update`, `leave`: summarize the output in a line or two.
|
|
22
|
+
- **Error:** quote the error line and its suggested fix, then stop. If the output says `Permission denied` or `not found` for `converge.mjs`, tell the user to run `converge` in a terminal, which repairs the skill (or `npm install -g convergedev` first if that command is missing), and `converge doctor` to see what else is wrong.
|
|
23
|
+
- **Usage text instead of a result:** show the commands available.
|
|
24
|
+
|
|
25
|
+
The room's agent is a separate, headless Claude Code session in this repository, running in read-only plan mode. It is not this conversation, and it keeps running in the background until `/converge leave`. Mention this once, after a successful `review`, `build` or `join`.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// What /converge runs: passes the developer's arguments to the bridge engine (apps/bridge/src/cli.ts). The skill is
|
|
3
|
+
// installed as a link to its folder, so the engine is found from this file's real path, in one of two places:
|
|
4
|
+
// - the installed package (npm install -g convergedev; `converge` links the skill): this folder is dist/skill/converge
|
|
5
|
+
// and the compiled engine is dist/cli.js, run by node directly;
|
|
6
|
+
// - a Converge checkout (a contributor links the skill by hand): the engine is apps/bridge/src/cli.ts, run through the
|
|
7
|
+
// bridge's own tsx.
|
|
8
|
+
// A copied skill finds neither and says so.
|
|
9
|
+
import { spawnSync } from 'node:child_process';
|
|
10
|
+
import { existsSync, realpathSync } from 'node:fs';
|
|
11
|
+
import { createRequire } from 'node:module';
|
|
12
|
+
import { dirname, join } from 'node:path';
|
|
13
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
14
|
+
|
|
15
|
+
const here = dirname(realpathSync(fileURLToPath(import.meta.url)));
|
|
16
|
+
const run = (args) => process.exit(spawnSync(process.execPath, [...args, ...process.argv.slice(2)], { stdio: 'inherit' }).status ?? 1);
|
|
17
|
+
|
|
18
|
+
const packaged = join(here, '..', '..', 'cli.js');
|
|
19
|
+
if (existsSync(packaged)) run([packaged]);
|
|
20
|
+
|
|
21
|
+
const bridge = join(here, '..', '..', '..', '..', 'apps', 'bridge');
|
|
22
|
+
const engine = join(bridge, 'src', 'cli.ts');
|
|
23
|
+
if (!existsSync(engine)) {
|
|
24
|
+
console.error('Error: /converge cannot find Converge. Run "converge" in a terminal to install or repair the skill ' +
|
|
25
|
+
'(npm install -g convergedev first if the command is missing).');
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
let tsx;
|
|
29
|
+
try {
|
|
30
|
+
tsx = pathToFileURL(createRequire(join(bridge, 'package.json')).resolve('tsx')).href;
|
|
31
|
+
} catch {
|
|
32
|
+
console.error(`Error: the bridge's dependencies are not installed. Run "npm install" in ${bridge}.`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
run(['--import', tsx, engine]);
|