@cogitator-ai/bridge 0.11.0 → 0.12.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 +41 -0
- package/dist/adapter.d.ts +16 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapters/claude.d.ts +44 -0
- package/dist/adapters/claude.d.ts.map +1 -1
- package/dist/adapters/claude.js +98 -2
- package/dist/adapters/claude.js.map +1 -1
- package/dist/adapters/codex.d.ts +8 -2
- package/dist/adapters/codex.d.ts.map +1 -1
- package/dist/adapters/codex.js +24 -5
- package/dist/adapters/codex.js.map +1 -1
- package/dist/adapters/hosted.d.ts +13 -1
- package/dist/adapters/hosted.d.ts.map +1 -1
- package/dist/adapters/hosted.js +25 -3
- package/dist/adapters/hosted.js.map +1 -1
- package/dist/client.d.ts +5 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8 -0
- package/dist/client.js.map +1 -1
- package/dist/dispatcher.d.ts +82 -3
- package/dist/dispatcher.d.ts.map +1 -1
- package/dist/dispatcher.js +327 -12
- 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/host.d.ts +3 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +1 -0
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +23 -1
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +4 -0
- package/dist/inputs.js.map +1 -1
- package/dist/job-record.d.ts +6 -0
- package/dist/job-record.d.ts.map +1 -1
- package/dist/job-record.js +3 -0
- package/dist/job-record.js.map +1 -1
- package/dist/letters.d.ts +1 -1
- package/dist/letters.d.ts.map +1 -1
- package/dist/letters.js +4 -0
- package/dist/letters.js.map +1 -1
- package/dist/limit.d.ts +37 -0
- package/dist/limit.d.ts.map +1 -0
- package/dist/limit.js +189 -0
- package/dist/limit.js.map +1 -0
- package/dist/protocol.d.ts +5 -0
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +3 -0
- package/dist/protocol.js.map +1 -1
- package/dist/recipes/steps.d.ts +4 -2
- package/dist/recipes/steps.d.ts.map +1 -1
- package/dist/recipes/steps.js +24 -9
- package/dist/recipes/steps.js.map +1 -1
- package/dist/scoreboard.d.ts +7 -0
- package/dist/scoreboard.d.ts.map +1 -1
- package/dist/scoreboard.js +17 -3
- package/dist/scoreboard.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +8 -1
- package/dist/server.js.map +1 -1
- package/dist/setup/claude.d.ts +3 -1
- package/dist/setup/claude.d.ts.map +1 -1
- package/dist/setup/claude.js +8 -2
- package/dist/setup/claude.js.map +1 -1
- package/dist/store/sqlite.d.ts +4 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +20 -1
- package/dist/store/sqlite.js.map +1 -1
- package/dist/store/store.d.ts +6 -1
- package/dist/store/store.d.ts.map +1 -1
- package/dist/types.d.ts +46 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -1
- package/fakes/claude.mjs +49 -0
- package/package.json +1 -1
package/fakes/claude.mjs
CHANGED
|
@@ -5,6 +5,11 @@
|
|
|
5
5
|
* and `__say` exist only here and play a person at an open window. The behaviour was measured
|
|
6
6
|
* on Claude Code 2.1.292 and 2.1.325.
|
|
7
7
|
*
|
|
8
|
+
* With FAKE_CLAUDE_TURN_ERROR set to an API error such as `rate_limit`, every turn of a session
|
|
9
|
+
* ends on that error: it does nothing, and the `StopFailure` hooks whose matcher fits the error
|
|
10
|
+
* run instead of the Stop hooks, with FAKE_CLAUDE_TURN_ERROR_TEXT as what Claude Code shows of
|
|
11
|
+
* it. This part follows the hooks reference of Claude Code and was not measured.
|
|
12
|
+
*
|
|
8
13
|
* MCP servers: a session has the servers of `--mcp-config` and of `mcp add` (local, project and
|
|
9
14
|
* user scope). A server is started once for the session, with the environment of the session
|
|
10
15
|
* and the id the session had then. Before a tool call the `PreToolUse` hooks whose matcher fits
|
|
@@ -362,6 +367,22 @@ async function runSession(argv) {
|
|
|
362
367
|
});
|
|
363
368
|
for (;;) {
|
|
364
369
|
const message = await nextMessage(files.spool);
|
|
370
|
+
const failure = turnError();
|
|
371
|
+
if (failure) {
|
|
372
|
+
recordTurn(
|
|
373
|
+
files.transcript,
|
|
374
|
+
{
|
|
375
|
+
at: new Date().toISOString(),
|
|
376
|
+
input: message.text,
|
|
377
|
+
ran: [],
|
|
378
|
+
tools: [],
|
|
379
|
+
answer: failure.shown,
|
|
380
|
+
},
|
|
381
|
+
message.wokenBy
|
|
382
|
+
);
|
|
383
|
+
await fireStopFailureHooks(session, failure);
|
|
384
|
+
continue;
|
|
385
|
+
}
|
|
365
386
|
setActivity(session, 'busy');
|
|
366
387
|
const outcome = await performTurn({
|
|
367
388
|
input: message.text,
|
|
@@ -794,6 +815,34 @@ async function fireStopHooks(session, answer, wokenByHook) {
|
|
|
794
815
|
}
|
|
795
816
|
}
|
|
796
817
|
|
|
818
|
+
/** The API error every turn ends on, when the environment names one, and what is shown of it */
|
|
819
|
+
function turnError() {
|
|
820
|
+
const error = process.env.FAKE_CLAUDE_TURN_ERROR?.trim();
|
|
821
|
+
if (!error) return undefined;
|
|
822
|
+
return { error, shown: process.env.FAKE_CLAUDE_TURN_ERROR_TEXT || `API Error: ${error}` };
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* Runs the StopFailure hooks whose matcher is the error a turn ended on. What they print and
|
|
827
|
+
* exit with changes nothing: the session waits for a plain hook and leaves an `async` one running.
|
|
828
|
+
*/
|
|
829
|
+
async function fireStopFailureHooks(session, failure) {
|
|
830
|
+
const { record, files } = session;
|
|
831
|
+
const payload = JSON.stringify({
|
|
832
|
+
session_id: record.sessionId,
|
|
833
|
+
transcript_path: files.transcript,
|
|
834
|
+
cwd: record.cwd,
|
|
835
|
+
hook_event_name: 'StopFailure',
|
|
836
|
+
error: failure.error,
|
|
837
|
+
last_assistant_message: failure.shown,
|
|
838
|
+
});
|
|
839
|
+
for (const { matcher, hook } of eventHooks(record, 'StopFailure')) {
|
|
840
|
+
if (matcher !== '.*' && !matcher.split('|').includes(failure.error)) continue;
|
|
841
|
+
const ended = runHook(session, hook, payload);
|
|
842
|
+
if (hook.async !== true) await ended;
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
797
846
|
/** The command hooks of the Stop event from `--settings` and the two project settings files */
|
|
798
847
|
function stopHooks(record) {
|
|
799
848
|
return settingsOf(record).flatMap((settings) => commandHooks(settings));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cogitator-ai/bridge",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.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",
|