@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.
Files changed (81) hide show
  1. package/README.md +41 -0
  2. package/dist/adapter.d.ts +16 -1
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapters/claude.d.ts +44 -0
  5. package/dist/adapters/claude.d.ts.map +1 -1
  6. package/dist/adapters/claude.js +98 -2
  7. package/dist/adapters/claude.js.map +1 -1
  8. package/dist/adapters/codex.d.ts +8 -2
  9. package/dist/adapters/codex.d.ts.map +1 -1
  10. package/dist/adapters/codex.js +24 -5
  11. package/dist/adapters/codex.js.map +1 -1
  12. package/dist/adapters/hosted.d.ts +13 -1
  13. package/dist/adapters/hosted.d.ts.map +1 -1
  14. package/dist/adapters/hosted.js +25 -3
  15. package/dist/adapters/hosted.js.map +1 -1
  16. package/dist/client.d.ts +5 -1
  17. package/dist/client.d.ts.map +1 -1
  18. package/dist/client.js +8 -0
  19. package/dist/client.js.map +1 -1
  20. package/dist/dispatcher.d.ts +82 -3
  21. package/dist/dispatcher.d.ts.map +1 -1
  22. package/dist/dispatcher.js +327 -12
  23. package/dist/dispatcher.js.map +1 -1
  24. package/dist/errors.d.ts +1 -1
  25. package/dist/errors.d.ts.map +1 -1
  26. package/dist/errors.js.map +1 -1
  27. package/dist/host.d.ts +3 -1
  28. package/dist/host.d.ts.map +1 -1
  29. package/dist/host.js +1 -0
  30. package/dist/host.js.map +1 -1
  31. package/dist/index.d.ts +5 -4
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +2 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/inputs.d.ts +23 -1
  36. package/dist/inputs.d.ts.map +1 -1
  37. package/dist/inputs.js +4 -0
  38. package/dist/inputs.js.map +1 -1
  39. package/dist/job-record.d.ts +6 -0
  40. package/dist/job-record.d.ts.map +1 -1
  41. package/dist/job-record.js +3 -0
  42. package/dist/job-record.js.map +1 -1
  43. package/dist/letters.d.ts +1 -1
  44. package/dist/letters.d.ts.map +1 -1
  45. package/dist/letters.js +4 -0
  46. package/dist/letters.js.map +1 -1
  47. package/dist/limit.d.ts +37 -0
  48. package/dist/limit.d.ts.map +1 -0
  49. package/dist/limit.js +189 -0
  50. package/dist/limit.js.map +1 -0
  51. package/dist/protocol.d.ts +5 -0
  52. package/dist/protocol.d.ts.map +1 -1
  53. package/dist/protocol.js +3 -0
  54. package/dist/protocol.js.map +1 -1
  55. package/dist/recipes/steps.d.ts +4 -2
  56. package/dist/recipes/steps.d.ts.map +1 -1
  57. package/dist/recipes/steps.js +24 -9
  58. package/dist/recipes/steps.js.map +1 -1
  59. package/dist/scoreboard.d.ts +7 -0
  60. package/dist/scoreboard.d.ts.map +1 -1
  61. package/dist/scoreboard.js +17 -3
  62. package/dist/scoreboard.js.map +1 -1
  63. package/dist/server.d.ts.map +1 -1
  64. package/dist/server.js +8 -1
  65. package/dist/server.js.map +1 -1
  66. package/dist/setup/claude.d.ts +3 -1
  67. package/dist/setup/claude.d.ts.map +1 -1
  68. package/dist/setup/claude.js +8 -2
  69. package/dist/setup/claude.js.map +1 -1
  70. package/dist/store/sqlite.d.ts +4 -1
  71. package/dist/store/sqlite.d.ts.map +1 -1
  72. package/dist/store/sqlite.js +20 -1
  73. package/dist/store/sqlite.js.map +1 -1
  74. package/dist/store/store.d.ts +6 -1
  75. package/dist/store/store.d.ts.map +1 -1
  76. package/dist/types.d.ts +46 -1
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/types.js +14 -0
  79. package/dist/types.js.map +1 -1
  80. package/fakes/claude.mjs +49 -0
  81. 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.11.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",