@prplkane/roundtable 0.6.6 → 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/CHANGELOG.md +604 -565
- package/LICENSE +21 -21
- package/README.md +184 -195
- package/SECURITY.md +324 -318
- package/docs/workflow.md +1475 -1439
- package/package.json +2 -2
- package/scripts/agent.mjs +2 -2
- package/scripts/mcp.mjs +179 -177
- package/skills/roundtable/SKILL.md +62 -59
- package/src/adapters/acp.js +318 -201
- package/src/adapters/agy.js +7 -7
- package/src/adapters/catalogue.js +37 -18
- package/src/adapters/claude.js +6 -6
- package/src/adapters/codex.js +6 -6
- package/src/adapters/common.js +1 -1
- package/src/adapters/config.js +8 -9
- package/src/adapters/models.js +32 -19
- package/src/adapters/spawn.js +3 -1
- package/src/agent-client.js +131 -120
- package/src/cli.js +21 -3
- package/src/diagnostics.js +1 -0
- package/src/engine.js +9 -5
- package/src/export.js +307 -307
- package/src/local-http.js +2 -2
- package/src/local-server.js +110 -110
- package/src/preflight.js +26 -6
- package/src/review-view.js +11 -0
- package/src/seats.js +368 -287
- package/src/server.js +1010 -945
- package/src/ui/app.js +2142 -1977
- package/src/ui/design/app.css +2 -1
- package/src/ui/design/preset-dusk.css +91 -91
- package/src/ui/design/tokens.css +129 -129
- package/src/ui/index.html +276 -272
- package/src/validate.js +10 -3
package/src/adapters/acp.js
CHANGED
|
@@ -1,201 +1,318 @@
|
|
|
1
|
-
// Standard ACP v1 over stdio. AgentLink owns profiles/installations; Roundtable owns
|
|
2
|
-
// the review, fresh seat sessions, deadlines and denial of client-side tools.
|
|
3
|
-
import { spawn } from 'node:child_process';
|
|
4
|
-
import { mkdirSync, existsSync } from 'node:fs';
|
|
5
|
-
import path from 'node:path';
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
//
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
child
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (!
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
1
|
+
// Standard ACP v1 over stdio. AgentLink owns profiles/installations; Roundtable owns
|
|
2
|
+
// the review, fresh seat sessions, deadlines and denial of client-side tools.
|
|
3
|
+
import { spawn } from 'node:child_process';
|
|
4
|
+
import { mkdirSync, existsSync } from 'node:fs';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import { mkdtemp, rm } from 'node:fs/promises';
|
|
8
|
+
import { cleanEnv, resolveBinary, registerCall, killTree, runProcess } from './spawn.js';
|
|
9
|
+
import { agentLinkProfile } from '../seats.js';
|
|
10
|
+
import { VERSION } from '../version.js';
|
|
11
|
+
|
|
12
|
+
const LIMIT = 8 * 1024 * 1024;
|
|
13
|
+
const fault = (message, code = 'PROVIDER_PROTOCOL', kind = 'other') => Object.assign(new Error(message), { code, kind });
|
|
14
|
+
const policy = () => Object.assign(fault('ACP agent requested or reported prohibited tool activity. This seat is stopped for the review.', 'TOOL_POLICY', 'policy'), { usedTools: true });
|
|
15
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
16
|
+
|
|
17
|
+
// This local launch override is read only from the server's environment, never a
|
|
18
|
+
// review request. It supports source checkouts and avoids Windows .cmd execution.
|
|
19
|
+
export function agentLinkBinary(env = process.env) {
|
|
20
|
+
const script = env.ROUNDTABLE_AGENTLINK_CLI;
|
|
21
|
+
if (script) {
|
|
22
|
+
if (!path.isAbsolute(script) || !existsSync(script)) throw fault('ROUNDTABLE_AGENTLINK_CLI must name an existing absolute AgentLink CLI script.', 'ENOENT', 'missing');
|
|
23
|
+
return { file: process.execPath, prefix: [script] };
|
|
24
|
+
}
|
|
25
|
+
try { return resolveBinary('agentlink', ['@prplkane/agentlink', 'src/cli.mjs'], { env }); }
|
|
26
|
+
catch { throw fault('AgentLink is not installed. Run npm install -g @prplkane/agentlink@beta, or set ROUNDTABLE_AGENTLINK_CLI to its absolute src/cli.mjs path.', 'ENOENT', 'missing'); }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Publish only picker metadata. AgentLink's raw inventory can contain launch arguments and environment settings.
|
|
30
|
+
const optionId = (id) => typeof id === 'string' && id.length > 0 && id.length <= 200 && !/[\u0000-\u001f\u007f]/.test(id);
|
|
31
|
+
function savedDefaults(row) {
|
|
32
|
+
return Object.fromEntries(['model', 'effort'].filter((key) => optionId(row?.[key])).map((key) => [key, row[key]]));
|
|
33
|
+
}
|
|
34
|
+
export async function listProfiles(launch = {}) {
|
|
35
|
+
const env = cleanEnv(null, { source: launch.env || process.env });
|
|
36
|
+
const bin = launch.bin || agentLinkBinary(env);
|
|
37
|
+
const result = await runProcess(bin, ['list', '--json'], { env, timeoutMs: 5000, maxOutputBytes: 2 * 1024 * 1024 });
|
|
38
|
+
if (result.code !== 0) throw new Error('Could not list saved AgentLink profiles. Run agentlink list.');
|
|
39
|
+
const rows = JSON.parse(result.stdout);
|
|
40
|
+
if (!Array.isArray(rows)) throw new Error('AgentLink returned an unreadable profile list.');
|
|
41
|
+
return rows.filter((p) => p && !p.error).map((p) => {
|
|
42
|
+
const defaults = savedDefaults(p.defaults);
|
|
43
|
+
return { name: agentLinkProfile(p.name), provider: typeof p.provider === 'string' ? p.provider : null,
|
|
44
|
+
...(Object.keys(defaults).length ? { defaults } : {}) };
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Optional ACP end-turn usage is still experimental. Fresh sessions avoid the
|
|
49
|
+
// deployed turn-vs-session ambiguity. Context-window `used` is never spending.
|
|
50
|
+
// Accept inclusive or additive cache counts only when the reported total agrees.
|
|
51
|
+
export function promptUsage(value, cost, ms) {
|
|
52
|
+
if (!record(value)) return null;
|
|
53
|
+
const count = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
54
|
+
const { inputTokens: input, outputTokens: output, totalTokens: total } = value;
|
|
55
|
+
const cacheRead = value.cachedReadTokens ?? 0, cacheWrite = value.cachedWriteTokens ?? 0, thinking = value.thoughtTokens ?? 0;
|
|
56
|
+
if (![input, output, total, cacheRead, cacheWrite, thinking].every(count)) return null;
|
|
57
|
+
let uncached;
|
|
58
|
+
if (total === input + output && input >= cacheRead + cacheWrite) uncached = input - cacheRead - cacheWrite;
|
|
59
|
+
else if (total === input + output + cacheRead + cacheWrite) uncached = input;
|
|
60
|
+
else return null;
|
|
61
|
+
return { input: uncached, output, cacheRead, cacheWrite, thinking, cost, ms, usageVersion: 3 };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function connect(bin, profile, { cwd, env, signal, onUpdate }) {
|
|
65
|
+
const child = spawn(bin.file, [...bin.prefix, 'acp', profile], {
|
|
66
|
+
cwd, env, windowsHide: true, detached: process.platform !== 'win32', stdio: ['pipe', 'pipe', 'pipe'],
|
|
67
|
+
});
|
|
68
|
+
let next = 0, pendingText = '', bytes = 0, failure, closed = false, closing = false, sessionId;
|
|
69
|
+
const pending = new Map();
|
|
70
|
+
const send = (message) => { if (!closed && child.stdin.writable) child.stdin.write(JSON.stringify({ jsonrpc: '2.0', ...message }) + '\n'); };
|
|
71
|
+
const cancel = () => { if (sessionId) send({ method: 'session/cancel', params: { sessionId } }); };
|
|
72
|
+
const fail = (error) => {
|
|
73
|
+
if (failure) return;
|
|
74
|
+
failure = error;
|
|
75
|
+
cancel();
|
|
76
|
+
for (const p of pending.values()) p.reject(error);
|
|
77
|
+
pending.clear();
|
|
78
|
+
};
|
|
79
|
+
const aborted = () => fail(signal.reason || fault('ACP call cancelled.', 'KILLED', 'killed'));
|
|
80
|
+
const exit = new Promise((resolve) => child.once('close', () => {
|
|
81
|
+
closed = true;
|
|
82
|
+
if (pendingText.trim()) fail(fault('ACP stdout ended with an incomplete JSON-RPC frame.'));
|
|
83
|
+
if (!closing) fail(fault('ACP process exited before the call completed. Run agentlink check for this profile.', 'CLI_EXIT'));
|
|
84
|
+
resolve();
|
|
85
|
+
}));
|
|
86
|
+
child.on('error', (e) => fail(fault(`Could not launch AgentLink (${e.code || 'spawn error'}).`, e.code || 'CLI_EXIT', 'missing')));
|
|
87
|
+
child.stdin.on('error', () => { if (!closing) fail(fault('ACP input closed before the call completed.', 'CLI_EXIT')); });
|
|
88
|
+
function receive(message) {
|
|
89
|
+
if (!record(message) || message.jsonrpc !== '2.0') throw fault('Invalid ACP JSON-RPC envelope.');
|
|
90
|
+
if (Object.hasOwn(message, 'method')) {
|
|
91
|
+
if (typeof message.method !== 'string') throw fault('Invalid ACP method.');
|
|
92
|
+
if (Object.hasOwn(message, 'id')) {
|
|
93
|
+
if (message.method === 'session/request_permission') {
|
|
94
|
+
send({ id: message.id, result: { outcome: { outcome: 'cancelled' } } });
|
|
95
|
+
throw policy();
|
|
96
|
+
}
|
|
97
|
+
send({ id: message.id, error: { code: -32601, message: 'Roundtable does not provide client tools.' } });
|
|
98
|
+
if (/^(fs\/|terminal\/)/.test(message.method)) throw policy();
|
|
99
|
+
} else if (message.method === 'session/update') {
|
|
100
|
+
const { params } = message;
|
|
101
|
+
if (!record(params) || !record(params.update) || typeof params.sessionId !== 'string') throw fault('Invalid ACP session update.');
|
|
102
|
+
if (['tool_call', 'tool_call_update'].includes(params.update.sessionUpdate)) throw policy();
|
|
103
|
+
if (sessionId && params.sessionId !== sessionId) throw fault('ACP update belongs to another session.');
|
|
104
|
+
if (sessionId) onUpdate(params.update);
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (!Object.hasOwn(message, 'id') || Object.hasOwn(message, 'result') === Object.hasOwn(message, 'error')) throw fault('Invalid ACP response.');
|
|
109
|
+
const p = pending.get(message.id);
|
|
110
|
+
if (!p) throw fault('ACP response has an unknown request ID.');
|
|
111
|
+
pending.delete(message.id);
|
|
112
|
+
if (message.error) {
|
|
113
|
+
if (p.method === 'session/new' && ['OPTION_UNAVAILABLE', 'OPTION_UNCONFIRMED'].includes(message.error.data?.code)) {
|
|
114
|
+
p.reject(fault(`AgentLink could not apply a saved default for ${profile}. Inspect choices with agentlink models ${profile} and update them with agentlink defaults ${profile}.`, 'ACP_UNSUPPORTED'));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const auth = message.error.code === -32000;
|
|
118
|
+
p.reject(fault(auth ? 'ACP authentication is required. Sign in using the agent vendor login flow, then check the AgentLink profile.'
|
|
119
|
+
: `ACP request failed: ${String(message.error.message || 'unknown error').slice(0, 500)}`, 'CLI_FAILURE', auth ? 'auth' : 'other'));
|
|
120
|
+
} else if (!record(message.result)) p.reject(fault('ACP response result must be an object.'));
|
|
121
|
+
else {
|
|
122
|
+
// Bind at the receive boundary: the next frame can be in this same chunk,
|
|
123
|
+
// before the awaiting session/new caller gets a chance to resume.
|
|
124
|
+
if (p.method === 'session/new' && typeof message.result.sessionId === 'string') sessionId = message.result.sessionId;
|
|
125
|
+
p.resolve(message.result);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
const accountBytes = (d) => {
|
|
129
|
+
bytes += Buffer.byteLength(d);
|
|
130
|
+
if (bytes > LIMIT) { fail(fault('ACP output exceeded the local size limit.', 'OUTPUT_LIMIT')); return false; }
|
|
131
|
+
return !failure;
|
|
132
|
+
};
|
|
133
|
+
child.stderr.on('data', accountBytes); // diagnostics are bounded, never copied into review records
|
|
134
|
+
child.stdout.setEncoding('utf8').on('data', (d) => {
|
|
135
|
+
if (!accountBytes(d)) return;
|
|
136
|
+
pendingText += d;
|
|
137
|
+
try {
|
|
138
|
+
let i;
|
|
139
|
+
while ((i = pendingText.indexOf('\n')) >= 0) {
|
|
140
|
+
const line = pendingText.slice(0, i); pendingText = pendingText.slice(i + 1);
|
|
141
|
+
if (line.trim()) receive(JSON.parse(line));
|
|
142
|
+
if (failure) break;
|
|
143
|
+
}
|
|
144
|
+
} catch (e) { fail(e instanceof SyntaxError ? fault('ACP stdout contained invalid JSON.') : e); }
|
|
145
|
+
});
|
|
146
|
+
signal.addEventListener('abort', aborted, { once: true });
|
|
147
|
+
if (signal.aborted) aborted();
|
|
148
|
+
return {
|
|
149
|
+
setSession(id) { sessionId = id; },
|
|
150
|
+
check() { if (failure) throw failure; },
|
|
151
|
+
request(method, params) {
|
|
152
|
+
if (failure) return Promise.reject(failure);
|
|
153
|
+
const id = ++next;
|
|
154
|
+
return new Promise((resolve, reject) => { pending.set(id, { resolve, reject, method }); send({ id, method, params }); });
|
|
155
|
+
},
|
|
156
|
+
async close() {
|
|
157
|
+
closing = true;
|
|
158
|
+
signal.removeEventListener('abort', aborted);
|
|
159
|
+
if (!closed) {
|
|
160
|
+
child.stdin.end();
|
|
161
|
+
// Leave time for AgentLink's own bridge cleanup and lease release.
|
|
162
|
+
const timer = setTimeout(() => killTree(child), 2000);
|
|
163
|
+
try { await exit; } finally { clearTimeout(timer); }
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// A session's select-type config option by ACP category, or by id for an agent that labels
|
|
170
|
+
// none, and the values it offers (flat, or grouped). Roundtable never invents a value: a model or
|
|
171
|
+
// reasoning level is sent only when the agent advertised it for this session.
|
|
172
|
+
function configOption(session, category, ids) {
|
|
173
|
+
const selects = (Array.isArray(session.configOptions) ? session.configOptions : [])
|
|
174
|
+
.filter((o) => o?.type === 'select' && typeof (o.configId ?? o.id) === 'string');
|
|
175
|
+
return selects.find((o) => o.category === category) || selects.find((o) => !o.category && ids.includes(o.configId ?? o.id));
|
|
176
|
+
}
|
|
177
|
+
const optionValues = (option) => Array.isArray(option?.options) ? option.options.flatMap((o) => Array.isArray(o?.options) ? o.options : [o]).filter(record) : [];
|
|
178
|
+
const MODEL = { category: 'model', ids: ['model'], what: 'model' };
|
|
179
|
+
const EFFORT = { category: 'thought_level', ids: ['thought_level', 'effort', 'reasoning_effort', 'reasoning'], what: 'reasoning level' };
|
|
180
|
+
const advertised = (session, option) => optionValues(configOption(session, option.category, option.ids));
|
|
181
|
+
async function selectOption(connection, session, value, { category, ids, what }) {
|
|
182
|
+
const option = configOption(session, category, ids);
|
|
183
|
+
if (!option || !optionValues(option).some((o) => o.value === value)) throw fault(`The ACP agent did not advertise this ${what}. Use its default or an advertised ${what} ID.`, 'ACP_UNSUPPORTED');
|
|
184
|
+
if (option.currentValue === value) return;
|
|
185
|
+
const result = await connection.request('session/set_config_option', { sessionId: session.sessionId, configId: option.configId ?? option.id, value });
|
|
186
|
+
session.configOptions = result.configOptions;
|
|
187
|
+
if (configOption(session, category, ids)?.currentValue !== value) throw fault(`The ACP agent did not confirm the selected ${what}.`, 'ACP_UNSUPPORTED');
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function withProfile(prompt, previousSession, opts, { bin, env: suppliedEnv }, inspect) {
|
|
191
|
+
const profile = agentLinkProfile(opts.account);
|
|
192
|
+
if (!opts.allowLimitedIsolation) throw fault('ACP profiles control their own permissions and customization. Accept limited isolation before using this profile.', 'ISOLATION_REQUIRED', 'policy');
|
|
193
|
+
if (previousSession || opts.keepSession) throw fault('ACP seats currently require stateless memory; no previous session was loaded.', 'ACP_STATELESS_REQUIRED');
|
|
194
|
+
if (opts.research) throw fault('ACP seats do not support Roundtable web research.', 'ACP_UNSUPPORTED');
|
|
195
|
+
const cwd = opts.cwd;
|
|
196
|
+
if (!cwd || !path.isAbsolute(cwd)) throw fault('ACP seats need an absolute, isolated working directory.');
|
|
197
|
+
mkdirSync(cwd, { recursive: true });
|
|
198
|
+
const env = cleanEnv(null, { source: suppliedEnv || process.env });
|
|
199
|
+
const launch = bin || agentLinkBinary(env);
|
|
200
|
+
const call = registerCall(opts.tag);
|
|
201
|
+
const timeout = new AbortController();
|
|
202
|
+
const timer = setTimeout(() => timeout.abort(fault('ACP call timed out.', 'TIMEOUT', 'timeout')), opts.timeoutMs ?? 300_000);
|
|
203
|
+
const signal = AbortSignal.any([call.signal, timeout.signal, ...(opts.signal ? [opts.signal] : [])]);
|
|
204
|
+
const started = Date.now();
|
|
205
|
+
let text = '', cost = null, activePrompt = false;
|
|
206
|
+
let connection;
|
|
207
|
+
try {
|
|
208
|
+
if (signal.aborted) throw signal.reason;
|
|
209
|
+
connection = connect(launch, profile, { cwd, env, signal, onUpdate: (update) => {
|
|
210
|
+
if (!activePrompt) return;
|
|
211
|
+
if (update.sessionUpdate === 'agent_message_chunk') {
|
|
212
|
+
if (update.content?.type !== 'text' || typeof update.content.text !== 'string') throw fault('ACP review replies must contain text.');
|
|
213
|
+
text += update.content.text;
|
|
214
|
+
} else if (update.sessionUpdate === 'usage_update' && update.cost?.currency === 'USD' && Number.isFinite(update.cost.amount) && update.cost.amount >= 0) cost = update.cost.amount;
|
|
215
|
+
} });
|
|
216
|
+
const init = await connection.request('initialize', { protocolVersion: 1, clientCapabilities: {}, clientInfo: { name: 'roundtable', version: VERSION } });
|
|
217
|
+
if (init.protocolVersion !== 1) throw fault('This Roundtable client requires ACP v1; the agent negotiated an incompatible protocol.', 'ACP_UNSUPPORTED');
|
|
218
|
+
const session = await connection.request('session/new', { cwd, mcpServers: [] });
|
|
219
|
+
if (typeof session.sessionId !== 'string' || !session.sessionId) throw fault('ACP agent did not return a session ID.');
|
|
220
|
+
connection.setSession(session.sessionId);
|
|
221
|
+
const hasModel = advertised(session, MODEL).some((o) => o.value === opts.model);
|
|
222
|
+
if (opts.model && (!inspect || hasModel)) await selectOption(connection, session, opts.model, MODEL);
|
|
223
|
+
if (inspect) {
|
|
224
|
+
const models = advertised(session, MODEL).filter((o) => typeof o.value === 'string' && o.value.length <= 200)
|
|
225
|
+
.map((o) => ({ id: o.value, label: typeof o.name === 'string' ? o.name : o.value }));
|
|
226
|
+
const effortChoices = advertised(session, EFFORT).filter((o) => optionId(o.value))
|
|
227
|
+
.map((o) => ({ id: o.value, label: typeof o.name === 'string' ? o.name : o.value }));
|
|
228
|
+
await connection.close();
|
|
229
|
+
connection.check();
|
|
230
|
+
return { models, efforts: effortChoices.map((e) => e.id), effortChoices, effortModel: hasModel ? opts.model : '' };
|
|
231
|
+
}
|
|
232
|
+
if (opts.effort) await selectOption(connection, session, opts.effort, EFFORT);
|
|
233
|
+
if (opts.model && configOption(session, MODEL.category, MODEL.ids)?.currentValue !== opts.model) {
|
|
234
|
+
throw fault('The ACP agent changed the selected model while applying the reasoning level.', 'ACP_UNSUPPORTED');
|
|
235
|
+
}
|
|
236
|
+
activePrompt = true;
|
|
237
|
+
const result = await connection.request('session/prompt', { sessionId: session.sessionId, prompt: [{ type: 'text', text: prompt }] });
|
|
238
|
+
connection.check();
|
|
239
|
+
if (result.stopReason !== 'end_turn') throw fault(`ACP turn did not complete (${String(result.stopReason || 'missing stop reason')}).`, result.stopReason === 'cancelled' ? 'KILLED' : 'CLI_FAILURE', result.stopReason === 'cancelled' ? 'killed' : 'other');
|
|
240
|
+
if (!text.trim()) throw fault('ACP agent completed without a text answer.');
|
|
241
|
+
await connection.close();
|
|
242
|
+
connection.check();
|
|
243
|
+
const ms = Date.now() - started;
|
|
244
|
+
return { text, usage: promptUsage(result.usage, cost, ms), cost, ms, sessionId: session.sessionId, usedTools: false };
|
|
245
|
+
} catch (e) {
|
|
246
|
+
throw Object.assign(e, { usage: null, cost, ms: Date.now() - started });
|
|
247
|
+
} finally {
|
|
248
|
+
clearTimeout(timer);
|
|
249
|
+
try { await connection?.close(); } finally { call.release(); }
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export function makeAcpAdapter(launch = {}) {
|
|
254
|
+
return (prompt, previousSession = null, opts = {}) => withProfile(prompt, previousSession, opts, launch, false);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Explicit local setup action. The profile receives an empty workspace and no prompt.
|
|
258
|
+
export async function inspectProfileSession(account, model = '', launch = {}) {
|
|
259
|
+
agentLinkProfile(account);
|
|
260
|
+
if (typeof model !== 'string' || model.length > 200) throw new Error('Model ID must be at most 200 characters.');
|
|
261
|
+
const cwd = await mkdtemp(path.join(os.tmpdir(), 'roundtable-profile-'));
|
|
262
|
+
try {
|
|
263
|
+
return await withProfile(null, null, { account, model, cwd, timeoutMs: 20_000, allowLimitedIsolation: true }, launch, true);
|
|
264
|
+
} finally {
|
|
265
|
+
await rm(cwd, { recursive: true, force: true });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Unlike session/new, beta.3 management inspection ignores saved pins. A retired
|
|
270
|
+
// central default must not prevent the picker from showing its replacements.
|
|
271
|
+
async function modelReport(bin, env, account, model) {
|
|
272
|
+
const args = ['models', account, '--json'];
|
|
273
|
+
if (model) args.push('--model', model);
|
|
274
|
+
const result = await runProcess(bin, args, { env, timeoutMs: 20_000 });
|
|
275
|
+
if (result.code !== 0) {
|
|
276
|
+
if (!model && /^INVALID_ARGUMENT: Unknown command\. Run agentlink --help\.\s*$/.test(result.stderr)) return null; // beta.2
|
|
277
|
+
throw fault(`AgentLink could not inspect profile ${account}. Run agentlink models ${account} to check its connection.`, 'CLI_FAILURE');
|
|
278
|
+
}
|
|
279
|
+
let report;
|
|
280
|
+
try { report = JSON.parse(result.stdout); } catch {}
|
|
281
|
+
if (report?.name !== account || !['model', 'effort'].every((k) => report[k] === null || Array.isArray(report[k]?.choices))) {
|
|
282
|
+
throw fault('AgentLink returned an unreadable model report.');
|
|
283
|
+
}
|
|
284
|
+
return report;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function namedChoices(selector) {
|
|
288
|
+
return (selector?.choices || []).filter((o) => optionId(o?.id))
|
|
289
|
+
.map(({ id, name }) => ({ id, label: typeof name === 'string' && name ? name : id }));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export async function discoverProfile(account, model = '', launch = {}) {
|
|
293
|
+
account = agentLinkProfile(account);
|
|
294
|
+
if (model !== '' && !optionId(model)) throw new Error('Choose a model ID of at most 200 characters.');
|
|
295
|
+
const env = cleanEnv(null, { source: launch.env || process.env });
|
|
296
|
+
const bin = launch.bin || agentLinkBinary(env);
|
|
297
|
+
const base = await modelReport(bin, env, account);
|
|
298
|
+
if (!base) return inspectProfileSession(account, model, launch);
|
|
299
|
+
const defaults = savedDefaults(base.defaults);
|
|
300
|
+
const models = namedChoices(base.model);
|
|
301
|
+
const offers = (id) => models.some((m) => m.id === id);
|
|
302
|
+
const profileModel = defaults.model || (optionId(base.model?.current) ? base.model.current : '');
|
|
303
|
+
const effortModel = offers(model) ? model : '';
|
|
304
|
+
const selected = effortModel || (offers(profileModel) ? profileModel : '');
|
|
305
|
+
const detail = selected && selected !== base.model?.current ? await modelReport(bin, env, account, selected) : base;
|
|
306
|
+
const effortChoices = namedChoices(detail.effort);
|
|
307
|
+
const efforts = effortChoices.map((e) => e.id);
|
|
308
|
+
const inheritsModel = !effortModel || effortModel === profileModel;
|
|
309
|
+
const stale = defaults.model && !offers(defaults.model) || inheritsModel && defaults.effort && !efforts.includes(defaults.effort);
|
|
310
|
+
// The inspector bypasses saved pins. After a seat overrides a centrally configured
|
|
311
|
+
// model, only its actual session knows whether the provider retained or reset effort.
|
|
312
|
+
const observedEffort = optionId(detail.effort?.current) ? detail.effort.current : '';
|
|
313
|
+
const defaultEffort = inheritsModel ? defaults.effort || observedEffort : Object.keys(defaults).length ? '' : observedEffort;
|
|
314
|
+
return { models, efforts, effortChoices, effortModel, defaults, profileModel, defaultEffort,
|
|
315
|
+
...(stale ? { warning: `A saved AgentLink default is unavailable. Choose a replacement with agentlink defaults ${account} before starting a review.` } : {}) };
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export const run = makeAcpAdapter();
|
package/src/adapters/agy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// Antigravity CLI: `agy --output-format json -p=<prompt>`, `--conversation <id>` to resume.
|
|
2
|
-
// Quirks: `-p` needs its value attached (`-p=...`) and stdin is ignored in that mode; for long
|
|
3
|
-
// prompts common.js switches to --input-format stream-json, where each stdin line is
|
|
4
|
-
// {"event":"user","message":{"role":"user","content":...}} and the last stdout line is
|
|
5
|
-
// {"event":"result","result":{...same shape as --output-format json...}}. No cost reported.
|
|
6
|
-
import { makeAdapter } from './common.js';
|
|
7
|
-
export const run = makeAdapter('agy');
|
|
1
|
+
// Antigravity CLI: `agy --output-format json -p=<prompt>`, `--conversation <id>` to resume.
|
|
2
|
+
// Quirks: `-p` needs its value attached (`-p=...`) and stdin is ignored in that mode; for long
|
|
3
|
+
// prompts common.js switches to --input-format stream-json, where each stdin line is
|
|
4
|
+
// {"event":"user","message":{"role":"user","content":...}} and the last stdout line is
|
|
5
|
+
// {"event":"result","result":{...same shape as --output-format json...}}. No cost reported.
|
|
6
|
+
import { makeAdapter } from './common.js';
|
|
7
|
+
export const run = makeAdapter('agy');
|