@cogitator-ai/bridge 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -35
- package/dist/adapter.d.ts +34 -2
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapters/claude.d.ts +95 -2
- package/dist/adapters/claude.d.ts.map +1 -1
- package/dist/adapters/claude.js +207 -3
- package/dist/adapters/claude.js.map +1 -1
- package/dist/adapters/hosted.d.ts +38 -5
- package/dist/adapters/hosted.d.ts.map +1 -1
- package/dist/adapters/hosted.js +190 -10
- package/dist/adapters/hosted.js.map +1 -1
- package/dist/client.d.ts +26 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +38 -1
- package/dist/client.js.map +1 -1
- package/dist/dispatcher.d.ts +145 -3
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +602 -24
- package/dist/dispatcher.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/guards.d.ts +3 -2
- package/dist/guards.d.ts.map +1 -1
- package/dist/guards.js +4 -3
- package/dist/guards.js.map +1 -1
- package/dist/host.d.ts +9 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +16 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -4
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +100 -1
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +35 -1
- package/dist/inputs.js.map +1 -1
- package/dist/job-record.d.ts +1 -0
- package/dist/job-record.d.ts.map +1 -1
- package/dist/job-record.js +1 -0
- package/dist/job-record.js.map +1 -1
- package/dist/letters.d.ts.map +1 -1
- package/dist/letters.js +23 -1
- package/dist/letters.js.map +1 -1
- package/dist/permit.d.ts +43 -0
- package/dist/permit.d.ts.map +1 -0
- package/dist/permit.js +118 -0
- package/dist/permit.js.map +1 -0
- package/dist/person-channel.d.ts +45 -0
- package/dist/person-channel.d.ts.map +1 -0
- package/dist/person-channel.js +160 -0
- package/dist/person-channel.js.map +1 -0
- package/dist/person-inbox.d.ts +31 -0
- package/dist/person-inbox.d.ts.map +1 -0
- package/dist/person-inbox.js +69 -0
- package/dist/person-inbox.js.map +1 -0
- package/dist/person.d.ts +65 -0
- package/dist/person.d.ts.map +1 -0
- package/dist/person.js +31 -0
- package/dist/person.js.map +1 -0
- package/dist/protocol.d.ts +8 -1
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +7 -1
- package/dist/protocol.js.map +1 -1
- package/dist/rights/index.d.ts +36 -0
- package/dist/rights/index.d.ts.map +1 -0
- package/dist/rights/index.js +186 -0
- package/dist/rights/index.js.map +1 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +11 -0
- package/dist/server.js.map +1 -1
- package/dist/setup/claude.d.ts +4 -2
- package/dist/setup/claude.d.ts.map +1 -1
- package/dist/setup/claude.js +9 -3
- package/dist/setup/claude.js.map +1 -1
- package/dist/store/sqlite.d.ts +6 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +74 -18
- package/dist/store/sqlite.js.map +1 -1
- package/dist/store/store.d.ts +6 -2
- package/dist/store/store.d.ts.map +1 -1
- package/dist/testing/fake-harnesses.d.ts +15 -2
- package/dist/testing/fake-harnesses.d.ts.map +1 -1
- package/dist/testing/fake-harnesses.js +17 -2
- package/dist/testing/fake-harnesses.js.map +1 -1
- package/dist/tools/guidance.d.ts.map +1 -1
- package/dist/tools/guidance.js +1 -0
- package/dist/tools/guidance.js.map +1 -1
- package/dist/tools/tools.d.ts.map +1 -1
- package/dist/tools/tools.js +27 -4
- package/dist/tools/tools.js.map +1 -1
- package/dist/types.d.ts +87 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +31 -0
- package/dist/types.js.map +1 -1
- package/fakes/claude.mjs +175 -8
- package/fakes/lib.mjs +58 -7
- package/fakes/mcp.mjs +5 -1
- package/package.json +6 -1
package/fakes/lib.mjs
CHANGED
|
@@ -467,7 +467,13 @@ export function abandonWork() {
|
|
|
467
467
|
for (const file of [...heldLocks]) unlock(file);
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
-
/**
|
|
470
|
+
/**
|
|
471
|
+
* A command of a turn. `denied` marks one that never ran because leave for it was refused, with
|
|
472
|
+
* the refusal in `stderr`
|
|
473
|
+
* @typedef {{ command: string, code: number | null, stdout: string, stderr: string, denied?: boolean }} CommandRun
|
|
474
|
+
*/
|
|
475
|
+
|
|
476
|
+
/** @typedef {(call: { tool: string, input: Record<string, unknown> }) => Promise<{ allowed: boolean, message?: string }>} LeaveAsker */
|
|
471
477
|
|
|
472
478
|
/**
|
|
473
479
|
* A tool call of a turn: `args` as the model wrote them, `sent` as they reached the server when
|
|
@@ -482,11 +488,11 @@ export function abandonWork() {
|
|
|
482
488
|
/**
|
|
483
489
|
* The directives of an input, in the order of its lines. A line counts after its leading
|
|
484
490
|
* whitespace is trimmed, a quoted line (`> run: ...`) is not a directive.
|
|
485
|
-
* @returns {{ kind: 'run' | 'sleep' | 'say' | 'tool', value: string }[]}
|
|
491
|
+
* @returns {{ kind: 'run' | 'bash' | 'edit' | 'sleep' | 'say' | 'tool', value: string }[]}
|
|
486
492
|
*/
|
|
487
493
|
function directives(input) {
|
|
488
494
|
return input.split(/\r?\n/).flatMap((line) => {
|
|
489
|
-
const match = /^(run|sleep|say|tool): (.+)$/.exec(line.trimStart());
|
|
495
|
+
const match = /^(run|bash|edit|sleep|say|tool): (.+)$/.exec(line.trimStart());
|
|
490
496
|
if (!match) return [];
|
|
491
497
|
const [, kind, text] = match;
|
|
492
498
|
const value = text.trim();
|
|
@@ -527,23 +533,68 @@ async function runTool(value, callTool) {
|
|
|
527
533
|
}
|
|
528
534
|
|
|
529
535
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
532
|
-
*
|
|
536
|
+
* A `bash:` directive: a command the session's own shell tool runs, which the session needs
|
|
537
|
+
* leave for the way its harness decides. A refused one does not run.
|
|
538
|
+
* @param {string} command
|
|
539
|
+
* @param {LeaveAsker | undefined} askLeave
|
|
540
|
+
* @returns {Promise<CommandRun>}
|
|
541
|
+
*/
|
|
542
|
+
async function runWithLeave(command, cwd, env, askLeave) {
|
|
543
|
+
const leave = askLeave ? await askLeave({ tool: 'Bash', input: { command } }) : { allowed: true };
|
|
544
|
+
if (leave.allowed) return runCommand(command, cwd, env);
|
|
545
|
+
return { command, code: null, stdout: '', stderr: leave.message ?? 'denied', denied: true };
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* An `edit:` directive: a file the session's own edit tool changes, by adding a line to it,
|
|
550
|
+
* which the session needs leave for the way its harness decides. It is in the turn as a command
|
|
551
|
+
* `edit <path>`, refused or done. A harness that imitates no edit tool of its own fails it.
|
|
552
|
+
* @param {string} path as the model wrote it, relative to the folder of the session or absolute
|
|
553
|
+
* @param {LeaveAsker | undefined} askLeave
|
|
554
|
+
* @returns {Promise<CommandRun>}
|
|
555
|
+
*/
|
|
556
|
+
async function editWithLeave(path, cwd, askLeave) {
|
|
557
|
+
const file = resolve(cwd, path);
|
|
558
|
+
const command = `edit ${path}`;
|
|
559
|
+
if (!askLeave) {
|
|
560
|
+
return { command, code: 1, stdout: '', stderr: 'this stand-in has no edit tool of its own' };
|
|
561
|
+
}
|
|
562
|
+
const leave = await askLeave({ tool: 'Edit', input: { file_path: file } });
|
|
563
|
+
if (!leave.allowed) {
|
|
564
|
+
return { command, code: null, stdout: '', stderr: leave.message ?? 'denied', denied: true };
|
|
565
|
+
}
|
|
566
|
+
try {
|
|
567
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
568
|
+
appendFileSync(file, 'edited\n');
|
|
569
|
+
return { command, code: 0, stdout: '', stderr: '' };
|
|
570
|
+
} catch (error) {
|
|
571
|
+
return { command, code: 1, stdout: '', stderr: error.message };
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* The scripted model: runs every `run: <command>` line with `sh -c`, asks leave for and then
|
|
577
|
+
* runs every `bash: <command>` line, asks leave for and then changes the file of every
|
|
578
|
+
* `edit: <path>` line, calls the tool of every `tool: <server>.<tool> {json}` line and waits
|
|
579
|
+
* out every `sleep: <ms>` line, one after another, and answers with the last `say: <text>`
|
|
580
|
+
* line, or `ok`.
|
|
533
581
|
* @param {object} turn
|
|
534
582
|
* @param {string} turn.input
|
|
535
583
|
* @param {string} turn.cwd where the commands run
|
|
536
584
|
* @param {NodeJS.ProcessEnv} turn.env what the commands see
|
|
537
585
|
* @param {ToolCaller} [turn.callTool] how the session calls a tool of one of its MCP servers
|
|
586
|
+
* @param {LeaveAsker} [turn.askLeave] how the session gets leave for a call of its own tools
|
|
538
587
|
* @returns {Promise<TurnOutcome>}
|
|
539
588
|
*/
|
|
540
|
-
export async function performTurn({ input, cwd, env, callTool }) {
|
|
589
|
+
export async function performTurn({ input, cwd, env, callTool, askLeave }) {
|
|
541
590
|
const at = new Date().toISOString();
|
|
542
591
|
const ran = [];
|
|
543
592
|
const tools = [];
|
|
544
593
|
let answer = 'ok';
|
|
545
594
|
for (const { kind, value } of directives(input)) {
|
|
546
595
|
if (kind === 'run') ran.push(await runCommand(value, cwd, env));
|
|
596
|
+
else if (kind === 'bash') ran.push(await runWithLeave(value, cwd, env, askLeave));
|
|
597
|
+
else if (kind === 'edit') ran.push(await editWithLeave(value, cwd, askLeave));
|
|
547
598
|
else if (kind === 'tool') tools.push(await runTool(value, callTool));
|
|
548
599
|
else if (kind === 'sleep') await sleep(Number(value));
|
|
549
600
|
else answer = value;
|
package/fakes/mcp.mjs
CHANGED
|
@@ -5,7 +5,11 @@
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
import { createInterface } from 'node:readline';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* A server of tools is a process that loads the whole runtime before it answers its first
|
|
10
|
+
* request: on a busy CI runner that took over fifteen seconds, so a request waits a minute
|
|
11
|
+
*/
|
|
12
|
+
const REQUEST_TIMEOUT_MS = 60_000;
|
|
9
13
|
const PROTOCOL_VERSION = '2025-06-18';
|
|
10
14
|
|
|
11
15
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Agent bridge for Cogitator: Claude Code, Codex and other agents hand each other jobs, ask questions and report back, each in its own window (experimental)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cogitator",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"import": "./dist/tools/index.js",
|
|
29
29
|
"default": "./dist/tools/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./rights": {
|
|
32
|
+
"types": "./dist/rights/index.d.ts",
|
|
33
|
+
"import": "./dist/rights/index.js",
|
|
34
|
+
"default": "./dist/rights/index.js"
|
|
35
|
+
},
|
|
31
36
|
"./testing": {
|
|
32
37
|
"types": "./dist/testing/index.d.ts",
|
|
33
38
|
"import": "./dist/testing/index.js",
|