@cogitator-ai/cli 0.19.1 → 0.21.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/README.md +28 -3
- package/dist/commands/bridge-install.d.ts +53 -0
- package/dist/commands/bridge-install.d.ts.map +1 -0
- package/dist/commands/bridge-install.js +239 -0
- package/dist/commands/bridge-install.js.map +1 -0
- package/dist/commands/bridge-session.d.ts +93 -0
- package/dist/commands/bridge-session.d.ts.map +1 -0
- package/dist/commands/bridge-session.js +292 -0
- package/dist/commands/bridge-session.js.map +1 -0
- package/dist/commands/bridge-tools.d.ts +48 -0
- package/dist/commands/bridge-tools.d.ts.map +1 -0
- package/dist/commands/bridge-tools.js +103 -0
- package/dist/commands/bridge-tools.js.map +1 -0
- package/dist/commands/bridge.d.ts +7 -2
- package/dist/commands/bridge.d.ts.map +1 -1
- package/dist/commands/bridge.js +141 -7
- package/dist/commands/bridge.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/bridge-adapters.d.ts +60 -0
- package/dist/utils/bridge-adapters.d.ts.map +1 -0
- package/dist/utils/bridge-adapters.js +118 -0
- package/dist/utils/bridge-adapters.js.map +1 -0
- package/dist/utils/bridge-host.d.ts +4 -3
- package/dist/utils/bridge-host.d.ts.map +1 -1
- package/dist/utils/bridge-host.js +8 -4
- package/dist/utils/bridge-host.js.map +1 -1
- package/dist/utils/cli.d.ts +8 -0
- package/dist/utils/cli.d.ts.map +1 -1
- package/dist/utils/cli.js +14 -0
- package/dist/utils/cli.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cogitator bridge delegate | send | inbox | wait | doctor - the bridge as a session and a
|
|
3
|
+
* person at a terminal use it
|
|
4
|
+
*/
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import { resolve } from 'node:path';
|
|
7
|
+
import { BridgeClient, bridgePaths, callerFromEnv, isBridgeError, mailText, shellQuote, waitForMail, } from '@cogitator-ai/bridge';
|
|
8
|
+
import { CommandError, EXIT, printJson, reportFailure } from '../utils/cli.js';
|
|
9
|
+
import { bridgeAdapters, bridgeCommandOf } from '../utils/bridge-adapters.js';
|
|
10
|
+
async function pipedInput() {
|
|
11
|
+
if (process.stdin.isTTY)
|
|
12
|
+
return undefined;
|
|
13
|
+
const chunks = [];
|
|
14
|
+
for await (const chunk of process.stdin)
|
|
15
|
+
chunks.push(chunk);
|
|
16
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
17
|
+
}
|
|
18
|
+
const defaultContext = () => ({
|
|
19
|
+
print: (line) => console.log(line),
|
|
20
|
+
wake: (text) => process.stderr.write(`${text}\n`),
|
|
21
|
+
env: process.env,
|
|
22
|
+
cwd: process.cwd(),
|
|
23
|
+
stdin: pipedInput,
|
|
24
|
+
});
|
|
25
|
+
function pathsOf(flags, context) {
|
|
26
|
+
return bridgePaths({ ...(flags.home && { home: flags.home }), env: context.env });
|
|
27
|
+
}
|
|
28
|
+
function adaptersOf(flags, context) {
|
|
29
|
+
return (context.adapters ?? bridgeAdapters(context.env, { ...(flags.home && { home: flags.home }) }));
|
|
30
|
+
}
|
|
31
|
+
const NO_SESSION = new CommandError('This command runs inside a session of an agent', {
|
|
32
|
+
hints: [
|
|
33
|
+
'Run it from Claude Code or Codex: the session is known by CLAUDE_CODE_SESSION_ID or CODEX_THREAD_ID',
|
|
34
|
+
'See what goes on from a terminal: cogitator bridge status, cogitator bridge log',
|
|
35
|
+
],
|
|
36
|
+
});
|
|
37
|
+
async function connect(flags, context, caller) {
|
|
38
|
+
try {
|
|
39
|
+
return await BridgeClient.connect({ socketPath: pathsOf(flags, context).socket, caller });
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (isBridgeError(error) && error.code === 'not_running') {
|
|
43
|
+
throw new CommandError('No bridge dispatcher is running', {
|
|
44
|
+
hints: ['Start one: cogitator bridge serve'],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function asSession(flags, context, work) {
|
|
51
|
+
const caller = callerFromEnv(context.env, context.cwd);
|
|
52
|
+
if (!caller)
|
|
53
|
+
throw NO_SESSION;
|
|
54
|
+
const client = await connect(flags, context, caller);
|
|
55
|
+
try {
|
|
56
|
+
return await work(client);
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
await client.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The text of a command: its words, or what is piped in when there are none or they are `-` */
|
|
63
|
+
async function bodyOf(words, context) {
|
|
64
|
+
const typed = words.join(' ');
|
|
65
|
+
if (typed.trim() && typed.trim() !== '-')
|
|
66
|
+
return typed;
|
|
67
|
+
const piped = await context.stdin();
|
|
68
|
+
if (piped?.trim())
|
|
69
|
+
return piped;
|
|
70
|
+
throw new CommandError('Nothing to send: give the text as arguments or pipe it in');
|
|
71
|
+
}
|
|
72
|
+
/** cogitator bridge delegate <to> <text>: hands a job over and prints its number at once. */
|
|
73
|
+
export async function runBridgeDelegate(to, words, flags, context = defaultContext()) {
|
|
74
|
+
try {
|
|
75
|
+
const body = await bodyOf(words, context);
|
|
76
|
+
const { job } = await asSession(flags, context, (client) => client.createJob({
|
|
77
|
+
to,
|
|
78
|
+
body,
|
|
79
|
+
...(flags.title && { title: flags.title }),
|
|
80
|
+
...(flags.cwd && { cwd: flags.cwd }),
|
|
81
|
+
...(flags.check?.length && { checks: flags.check.map((command) => ({ command })) }),
|
|
82
|
+
...(flags.parent !== undefined && { parent: flags.parent }),
|
|
83
|
+
}));
|
|
84
|
+
if (flags.json)
|
|
85
|
+
printJson(job);
|
|
86
|
+
else {
|
|
87
|
+
context.print(`Job #${job.number} is with ${job.to} (${job.state}). Its answer arrives as a letter: nothing to wait for here`);
|
|
88
|
+
}
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return reportFailure(error, { json: flags.json ?? false });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export const SENDABLE_KINDS = ['question', 'answer', 'report', 'note', 'permission'];
|
|
96
|
+
/** cogitator bridge send --job N --kind K <text>: a letter on a job that exists. */
|
|
97
|
+
export async function runBridgeSend(words, flags, context = defaultContext()) {
|
|
98
|
+
try {
|
|
99
|
+
if (flags.failed && flags.kind !== 'report') {
|
|
100
|
+
throw new CommandError('--failed goes with --kind report');
|
|
101
|
+
}
|
|
102
|
+
const body = await bodyOf(words, context);
|
|
103
|
+
const sent = await asSession(flags, context, (client) => client.send({
|
|
104
|
+
job: flags.job,
|
|
105
|
+
kind: flags.kind,
|
|
106
|
+
body,
|
|
107
|
+
...(flags.replyTo && { inReplyTo: flags.replyTo }),
|
|
108
|
+
...(flags.failed && { outcome: 'failed' }),
|
|
109
|
+
}));
|
|
110
|
+
if (flags.json)
|
|
111
|
+
printJson(sent);
|
|
112
|
+
else {
|
|
113
|
+
context.print(`Sent the ${sent.letter.kind} ${sent.letter.id} to ${sent.letter.to}. Job #${sent.job.number} is ${sent.job.state}`);
|
|
114
|
+
}
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
return reportFailure(error, { json: flags.json ?? false });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** cogitator bridge inbox: the letters waiting for the session, each under its signature. */
|
|
122
|
+
export async function runBridgeInbox(flags, context = defaultContext()) {
|
|
123
|
+
try {
|
|
124
|
+
const letters = await asSession(flags, context, (client) => client.inbox({
|
|
125
|
+
...(flags.job !== undefined && { job: flags.job }),
|
|
126
|
+
...(flags.peek && { peek: true }),
|
|
127
|
+
...(flags.unhandled && { unhandled: true }),
|
|
128
|
+
}));
|
|
129
|
+
if (flags.json)
|
|
130
|
+
printJson(letters);
|
|
131
|
+
else if (letters.length === 0)
|
|
132
|
+
context.print('No letters wait for this session');
|
|
133
|
+
else
|
|
134
|
+
context.print(mailText(letters));
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return reportFailure(error, { json: flags.json ?? false });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* cogitator bridge cancel <job> [reason]: the session that handed a job over takes it back. The
|
|
143
|
+
* agent it was with is told to stop.
|
|
144
|
+
*/
|
|
145
|
+
export async function runBridgeCancel(job, words, flags, context = defaultContext()) {
|
|
146
|
+
try {
|
|
147
|
+
const reason = words.join(' ').trim();
|
|
148
|
+
const canceled = await asSession(flags, context, (client) => client.cancel(job, reason || undefined));
|
|
149
|
+
if (flags.json)
|
|
150
|
+
printJson(canceled);
|
|
151
|
+
else
|
|
152
|
+
context.print(`Job #${canceled.number} is ${canceled.state}, ${canceled.to} is told`);
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
return reportFailure(error, { json: flags.json ?? false });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* How a session without the bridge's tools answers a letter it was woken with: the command line
|
|
161
|
+
* as the session can run it, whatever its `PATH`.
|
|
162
|
+
*/
|
|
163
|
+
export function replyHint(bridgeCommand, home) {
|
|
164
|
+
return ('(The agent bridge woke this session with the mail above. Answer through it, not in this chat: ' +
|
|
165
|
+
`${bridgeCommand} send --job <number> --kind <answer|question|report|note> "<text>"` +
|
|
166
|
+
`${home ? ` --home ${shellQuote(home)}` : ''})`);
|
|
167
|
+
}
|
|
168
|
+
/** How a session with the bridge's tools answers a letter it was woken with. */
|
|
169
|
+
export const TOOLS_REPLY_HINT = '(The agent bridge woke this session with the mail above. Reply with the bridge tools, not only in this chat: ' +
|
|
170
|
+
'answer for a question, report for the result of a job handed to you, ask when whoever handed it over has to decide something.)';
|
|
171
|
+
/** What `wait` exits with when it has mail: the code that makes a harness wake its session. */
|
|
172
|
+
export const WAKE_EXIT_CODE = 2;
|
|
173
|
+
const DEFAULT_WAIT_S = 600;
|
|
174
|
+
/**
|
|
175
|
+
* cogitator bridge wait: waits for the session's mail and exits. With mail it writes the letters
|
|
176
|
+
* to stderr and exits with code 2, which is what wakes a Claude Code session whose background
|
|
177
|
+
* hook ran it. Without, it exits with 0 and says nothing. A failure exits with 1, never with 2:
|
|
178
|
+
* an error must not wake the session.
|
|
179
|
+
*/
|
|
180
|
+
export async function runBridgeWait(flags, context = defaultContext()) {
|
|
181
|
+
try {
|
|
182
|
+
let caller;
|
|
183
|
+
if (flags.hook) {
|
|
184
|
+
const harness = flags.hook.trim().toLowerCase();
|
|
185
|
+
const adapter = adaptersOf(flags, context).find((candidate) => candidate.harness === harness);
|
|
186
|
+
if (!adapter?.identify) {
|
|
187
|
+
throw new CommandError(`No adapter tells the sessions of "${flags.hook}" apart`);
|
|
188
|
+
}
|
|
189
|
+
const hookInput = await context.stdin();
|
|
190
|
+
caller = adapter.identify({
|
|
191
|
+
env: context.env,
|
|
192
|
+
cwd: context.cwd,
|
|
193
|
+
...(hookInput !== undefined && { hookInput }),
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
caller = callerFromEnv(context.env, context.cwd);
|
|
198
|
+
}
|
|
199
|
+
if (!caller)
|
|
200
|
+
throw NO_SESSION;
|
|
201
|
+
const waited = await waitForMail({
|
|
202
|
+
socketPath: pathsOf(flags, context).socket,
|
|
203
|
+
caller: { ...caller, ...(flags.agent && { agentName: flags.agent }) },
|
|
204
|
+
timeoutMs: (flags.timeout ?? DEFAULT_WAIT_S) * 1000,
|
|
205
|
+
...(context.signal && { signal: context.signal }),
|
|
206
|
+
});
|
|
207
|
+
if (waited.reason !== 'letters')
|
|
208
|
+
return 0;
|
|
209
|
+
const hint = flags.tools
|
|
210
|
+
? TOOLS_REPLY_HINT
|
|
211
|
+
: replyHint(bridgeCommandOf(context.env), flags.home);
|
|
212
|
+
context.wake(`${mailText(waited.letters)}\n\n${hint}`);
|
|
213
|
+
await waited.confirm().catch(() => undefined);
|
|
214
|
+
return WAKE_EXIT_CODE;
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
reportFailure(error, { json: false });
|
|
218
|
+
return EXIT.failed;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const MARKS = {
|
|
222
|
+
ok: chalk.green('✓'),
|
|
223
|
+
warn: chalk.yellow('!'),
|
|
224
|
+
fail: chalk.red('✗'),
|
|
225
|
+
};
|
|
226
|
+
async function dispatcherCheck(paths) {
|
|
227
|
+
let client;
|
|
228
|
+
try {
|
|
229
|
+
client = await BridgeClient.connect({ socketPath: paths.socket, timeoutMs: 5_000 });
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
if (!isBridgeError(error) || error.code !== 'not_running')
|
|
233
|
+
throw error;
|
|
234
|
+
return {
|
|
235
|
+
id: 'dispatcher',
|
|
236
|
+
title: 'Dispatcher',
|
|
237
|
+
status: 'fail',
|
|
238
|
+
detail: 'no bridge dispatcher is running: letters go nowhere',
|
|
239
|
+
fix: 'cogitator bridge serve',
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
const status = await client.status();
|
|
244
|
+
const waiting = status.waiting.length > 0
|
|
245
|
+
? `waiting for mail: ${status.waiting.join(', ')}`
|
|
246
|
+
: 'no session waits for mail right now';
|
|
247
|
+
return {
|
|
248
|
+
id: 'dispatcher',
|
|
249
|
+
title: 'Dispatcher',
|
|
250
|
+
status: 'ok',
|
|
251
|
+
detail: `runs (pid ${status.dispatcher.pid}, v${status.dispatcher.version}), adapters: ${status.adapters.join(', ') || 'none'}, ${waiting}`,
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
await client.close();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* cogitator bridge doctor: whether the bridge can reach the harnesses of this machine. Exits 1
|
|
260
|
+
* when something it needs is missing, 0 when at most warnings are left.
|
|
261
|
+
*/
|
|
262
|
+
export async function runBridgeDoctor(flags, context = defaultContext()) {
|
|
263
|
+
try {
|
|
264
|
+
const cwd = resolve(context.cwd, flags.cwd ?? '.');
|
|
265
|
+
const sections = [
|
|
266
|
+
{ harness: 'bridge', checks: [await dispatcherCheck(pathsOf(flags, context))] },
|
|
267
|
+
];
|
|
268
|
+
for (const adapter of adaptersOf(flags, context)) {
|
|
269
|
+
if (!adapter.health)
|
|
270
|
+
continue;
|
|
271
|
+
sections.push({ harness: adapter.harness, checks: await adapter.health({ cwd }) });
|
|
272
|
+
}
|
|
273
|
+
const failed = sections.some((section) => section.checks.some((check) => check.status === 'fail'));
|
|
274
|
+
if (flags.json) {
|
|
275
|
+
printJson({ ok: !failed, cwd, sections });
|
|
276
|
+
return failed ? 1 : 0;
|
|
277
|
+
}
|
|
278
|
+
for (const section of sections) {
|
|
279
|
+
context.print(chalk.bold(section.harness));
|
|
280
|
+
for (const check of section.checks) {
|
|
281
|
+
context.print(` ${MARKS[check.status]} ${check.title}${check.detail ? `: ${check.detail}` : ''}`);
|
|
282
|
+
if (check.fix)
|
|
283
|
+
context.print(chalk.dim(` ${check.fix}`));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return failed ? 1 : 0;
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
return reportFailure(error, { json: flags.json ?? false });
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=bridge-session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-session.js","sourceRoot":"","sources":["../../src/commands/bridge-session.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,YAAY,EACZ,WAAW,EACX,aAAa,EACb,aAAa,EACb,QAAQ,EACR,UAAU,EACV,WAAW,GAMZ,MAAM,sBAAsB,CAAC;AAC9B,O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,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CACpF,CAAC;gBACF,IAAI,KAAK,CAAC,GAAG;oBAAE,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YAC9D,CAAC;QACH,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,aAAa,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cogitator bridge mcp | caller - what a harness runs for a session to give it the bridge's
|
|
3
|
+
* tools: the server of the tools, and the hook that tells the tools which session calls
|
|
4
|
+
*/
|
|
5
|
+
import { type BridgeAdapter } from '@cogitator-ai/bridge';
|
|
6
|
+
import { MCPServer } from '@cogitator-ai/mcp';
|
|
7
|
+
/** The name the server gives itself. A harness knows it by the name it was registered under. */
|
|
8
|
+
export declare const BRIDGE_SERVER_NAME = "cogitator-bridge";
|
|
9
|
+
export interface BridgeMcpOptions {
|
|
10
|
+
/** The folder of the bridge's files, when it is not the default one */
|
|
11
|
+
home?: string;
|
|
12
|
+
env?: NodeJS.ProcessEnv;
|
|
13
|
+
/** The folder the session works in, the current one by default */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The server of the bridge's tools over stdio, for the session of the harness that started it.
|
|
18
|
+
* It holds no connection to the dispatcher: every tool call makes its own, so the server may be
|
|
19
|
+
* started before the dispatcher and lives through its restarts.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createBridgeMcpServer(options?: BridgeMcpOptions): MCPServer;
|
|
22
|
+
/**
|
|
23
|
+
* cogitator bridge mcp: serves the tools on stdin and stdout until the harness closes them, or
|
|
24
|
+
* the process is told to stop.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runBridgeMcp(flags: {
|
|
27
|
+
home?: string;
|
|
28
|
+
}): Promise<number>;
|
|
29
|
+
/** What the hook command works with */
|
|
30
|
+
export interface BridgeCallerContext {
|
|
31
|
+
/** Where the answer of the hook goes: the harness reads it from stdout */
|
|
32
|
+
write(text: string): void;
|
|
33
|
+
env: NodeJS.ProcessEnv;
|
|
34
|
+
cwd: string;
|
|
35
|
+
/** What the harness wrote to the hook */
|
|
36
|
+
stdin(): Promise<string | undefined>;
|
|
37
|
+
adapters?: readonly BridgeAdapter[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* cogitator bridge caller --hook <harness>: the hook a harness runs before a call of a bridge
|
|
41
|
+
* tool. It answers with the arguments of the call and the session that makes it, and with
|
|
42
|
+
* nothing when the input names no session: the call then goes on as it was. It never exits with
|
|
43
|
+
* 2, which a harness would read as a refusal of the tool call.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runBridgeCaller(flags: {
|
|
46
|
+
hook: string;
|
|
47
|
+
}, context?: BridgeCallerContext): Promise<number>;
|
|
48
|
+
//# sourceMappingURL=bridge-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-tools.d.ts","sourceRoot":"","sources":["../../src/commands/bridge-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI9C,gGAAgG;AAChG,eAAO,MAAM,kBAAkB,qBAAqB,CAAC;AASrD,MAAM,WAAW,gBAAgB;IAC/B,uEAAuE;IACvE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,kEAAkE;IAClE,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAiB/E;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAgB5E;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC,0EAA0E;IAC1E,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,yCAAyC;IACzC,KAAK,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACrC,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CACrC;AAgBD;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,EACvB,OAAO,GAAE,mBAA4C,GACpD,OAAO,CAAC,MAAM,CAAC,CAoBjB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* cogitator bridge mcp | caller - what a harness runs for a session to give it the bridge's
|
|
3
|
+
* tools: the server of the tools, and the hook that tells the tools which session calls
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { bridgePaths } from '@cogitator-ai/bridge';
|
|
7
|
+
import { BRIDGE_INSTRUCTIONS, bridgeTools } from '@cogitator-ai/bridge/tools';
|
|
8
|
+
import { MCPServer } from '@cogitator-ai/mcp';
|
|
9
|
+
import { bridgeAdapters } from '../utils/bridge-adapters.js';
|
|
10
|
+
import { CommandError, EXIT, reportFailure } from '../utils/cli.js';
|
|
11
|
+
/** The name the server gives itself. A harness knows it by the name it was registered under. */
|
|
12
|
+
export const BRIDGE_SERVER_NAME = 'cogitator-bridge';
|
|
13
|
+
function cliVersion() {
|
|
14
|
+
const manifest = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf-8'));
|
|
15
|
+
return manifest.version;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The server of the bridge's tools over stdio, for the session of the harness that started it.
|
|
19
|
+
* It holds no connection to the dispatcher: every tool call makes its own, so the server may be
|
|
20
|
+
* started before the dispatcher and lives through its restarts.
|
|
21
|
+
*/
|
|
22
|
+
export function createBridgeMcpServer(options = {}) {
|
|
23
|
+
const env = options.env ?? process.env;
|
|
24
|
+
const server = new MCPServer({
|
|
25
|
+
name: BRIDGE_SERVER_NAME,
|
|
26
|
+
version: cliVersion(),
|
|
27
|
+
transport: 'stdio',
|
|
28
|
+
logging: false,
|
|
29
|
+
instructions: BRIDGE_INSTRUCTIONS,
|
|
30
|
+
});
|
|
31
|
+
server.registerTools(bridgeTools({
|
|
32
|
+
socketPath: bridgePaths({ ...(options.home && { home: options.home }), env }).socket,
|
|
33
|
+
env,
|
|
34
|
+
...(options.cwd && { cwd: options.cwd }),
|
|
35
|
+
}));
|
|
36
|
+
return server;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* cogitator bridge mcp: serves the tools on stdin and stdout until the harness closes them, or
|
|
40
|
+
* the process is told to stop.
|
|
41
|
+
*/
|
|
42
|
+
export async function runBridgeMcp(flags) {
|
|
43
|
+
let server;
|
|
44
|
+
try {
|
|
45
|
+
server = createBridgeMcpServer({ ...(flags.home && { home: flags.home }) });
|
|
46
|
+
await server.start();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
return reportFailure(error, { json: false });
|
|
50
|
+
}
|
|
51
|
+
await new Promise((resolve) => {
|
|
52
|
+
process.once('SIGINT', resolve);
|
|
53
|
+
process.once('SIGTERM', resolve);
|
|
54
|
+
process.stdin.once('end', resolve);
|
|
55
|
+
process.stdin.once('close', resolve);
|
|
56
|
+
});
|
|
57
|
+
await server.stop().catch(() => undefined);
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
async function pipedInput() {
|
|
61
|
+
if (process.stdin.isTTY)
|
|
62
|
+
return undefined;
|
|
63
|
+
const chunks = [];
|
|
64
|
+
for await (const chunk of process.stdin)
|
|
65
|
+
chunks.push(chunk);
|
|
66
|
+
return Buffer.concat(chunks).toString('utf8');
|
|
67
|
+
}
|
|
68
|
+
const defaultCallerContext = () => ({
|
|
69
|
+
write: (text) => process.stdout.write(text),
|
|
70
|
+
env: process.env,
|
|
71
|
+
cwd: process.cwd(),
|
|
72
|
+
stdin: pipedInput,
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* cogitator bridge caller --hook <harness>: the hook a harness runs before a call of a bridge
|
|
76
|
+
* tool. It answers with the arguments of the call and the session that makes it, and with
|
|
77
|
+
* nothing when the input names no session: the call then goes on as it was. It never exits with
|
|
78
|
+
* 2, which a harness would read as a refusal of the tool call.
|
|
79
|
+
*/
|
|
80
|
+
export async function runBridgeCaller(flags, context = defaultCallerContext()) {
|
|
81
|
+
try {
|
|
82
|
+
const harness = flags.hook.trim().toLowerCase();
|
|
83
|
+
const adapters = context.adapters ?? bridgeAdapters(context.env);
|
|
84
|
+
const adapter = adapters.find((candidate) => candidate.harness === harness);
|
|
85
|
+
if (!adapter?.toolCallHook) {
|
|
86
|
+
throw new CommandError(`No adapter names the sessions of "${flags.hook}" to the tools`);
|
|
87
|
+
}
|
|
88
|
+
const hookInput = await context.stdin();
|
|
89
|
+
const answer = adapter.toolCallHook({
|
|
90
|
+
env: context.env,
|
|
91
|
+
cwd: context.cwd,
|
|
92
|
+
...(hookInput !== undefined && { hookInput }),
|
|
93
|
+
});
|
|
94
|
+
if (answer !== undefined)
|
|
95
|
+
context.write(answer);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
reportFailure(error, { json: false });
|
|
100
|
+
return EXIT.failed;
|
|
101
|
+
}
|
|
102
|
+
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C,GAAG;YAChB,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;SAC9C,CAAC,CAAC;QACH,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAChD,OAAO,CAAC,CAAC;IACX,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,aAAa,CAAC,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* cogitator bridge - the agent bridge of this machine: run its dispatcher, read its journal
|
|
3
3
|
*/
|
|
4
4
|
import { Command } from 'commander';
|
|
5
|
-
import { type JournalEntry } from '@cogitator-ai/bridge';
|
|
5
|
+
import { type BridgeAdapter, type JournalEntry } from '@cogitator-ai/bridge';
|
|
6
6
|
/** Where the commands print */
|
|
7
7
|
export interface BridgeIo {
|
|
8
8
|
print(line: string): void;
|
|
@@ -16,10 +16,15 @@ export interface BridgeContext {
|
|
|
16
16
|
signal?: AbortSignal;
|
|
17
17
|
/** How often `log --follow` looks for new entries, in ms */
|
|
18
18
|
pollMs?: number;
|
|
19
|
+
/** The adapters `serve` reaches sessions through, those of Claude Code and Codex by default */
|
|
20
|
+
adapters?: readonly BridgeAdapter[];
|
|
19
21
|
}
|
|
20
22
|
interface HomeFlags {
|
|
21
23
|
home?: string;
|
|
22
24
|
}
|
|
25
|
+
interface ServeFlags extends HomeFlags {
|
|
26
|
+
codexSandbox?: string;
|
|
27
|
+
}
|
|
23
28
|
/** What a journal entry says, without the time and the job number. */
|
|
24
29
|
export declare function describeJournalEntry(raw: JournalEntry): string;
|
|
25
30
|
/** A journal entry as one line of `cogitator bridge log`. */
|
|
@@ -41,7 +46,7 @@ export declare function runBridgeStatus(flags: HomeFlags & {
|
|
|
41
46
|
json?: boolean;
|
|
42
47
|
}, context?: BridgeContext): Promise<number>;
|
|
43
48
|
/** cogitator bridge serve: the dispatcher in the foreground, until Ctrl-C. */
|
|
44
|
-
export declare function runBridgeServe(flags:
|
|
49
|
+
export declare function runBridgeServe(flags: ServeFlags, context?: BridgeContext): Promise<number>;
|
|
45
50
|
export declare const bridgeCommand: Command;
|
|
46
51
|
export {};
|
|
47
52
|
//# sourceMappingURL=bridge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/commands/bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"bridge.d.ts","sourceRoot":"","sources":["../../src/commands/bridge.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAgC,MAAM,WAAW,CAAC;AAGlE,OAAO,EAOL,KAAK,aAAa,EAKlB,KAAK,YAAY,EAElB,MAAM,sBAAsB,CAAC;AA2B9B,+BAA+B;AAC/B,MAAM,WAAW,QAAQ;IACvB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED,+EAA+E;AAC/E,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,QAAQ,CAAC;IACb,GAAG,EAAE,MAAM,CAAC,UAAU,CAAC;IACvB,yDAAyD;IACzD,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+FAA+F;IAC/F,QAAQ,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;CACrC;AAOD,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,UAAU,UAAW,SAAQ,SAAS;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAkED,sEAAsE;AACtE,wBAAgB,oBAAoB,C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