@cogitator-ai/bridge 0.6.1 → 0.8.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 (84) hide show
  1. package/README.md +102 -19
  2. package/dist/adapters/claude.d.ts +13 -0
  3. package/dist/adapters/claude.d.ts.map +1 -1
  4. package/dist/adapters/claude.js +11 -1
  5. package/dist/adapters/claude.js.map +1 -1
  6. package/dist/board.d.ts +76 -0
  7. package/dist/board.d.ts.map +1 -0
  8. package/dist/board.js +19 -0
  9. package/dist/board.js.map +1 -0
  10. package/dist/checks.d.ts +31 -0
  11. package/dist/checks.d.ts.map +1 -0
  12. package/dist/checks.js +202 -0
  13. package/dist/checks.js.map +1 -0
  14. package/dist/client.d.ts +17 -1
  15. package/dist/client.d.ts.map +1 -1
  16. package/dist/client.js +29 -0
  17. package/dist/client.js.map +1 -1
  18. package/dist/dispatcher.d.ts +187 -2
  19. package/dist/dispatcher.d.ts.map +1 -1
  20. package/dist/dispatcher.js +930 -18
  21. package/dist/dispatcher.js.map +1 -1
  22. package/dist/errors.d.ts +1 -1
  23. package/dist/errors.d.ts.map +1 -1
  24. package/dist/errors.js.map +1 -1
  25. package/dist/handover.d.ts +72 -0
  26. package/dist/handover.d.ts.map +1 -0
  27. package/dist/handover.js +225 -0
  28. package/dist/handover.js.map +1 -0
  29. package/dist/host.d.ts +7 -0
  30. package/dist/host.d.ts.map +1 -1
  31. package/dist/host.js +1 -0
  32. package/dist/host.js.map +1 -1
  33. package/dist/index.d.ts +5 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +3 -0
  36. package/dist/index.js.map +1 -1
  37. package/dist/inputs.d.ts +166 -0
  38. package/dist/inputs.d.ts.map +1 -1
  39. package/dist/inputs.js +65 -0
  40. package/dist/inputs.js.map +1 -1
  41. package/dist/job-record.d.ts +42 -1
  42. package/dist/job-record.d.ts.map +1 -1
  43. package/dist/job-record.js +39 -1
  44. package/dist/job-record.js.map +1 -1
  45. package/dist/letters.d.ts +3 -1
  46. package/dist/letters.d.ts.map +1 -1
  47. package/dist/letters.js +38 -5
  48. package/dist/letters.js.map +1 -1
  49. package/dist/memory/index.d.ts +35 -0
  50. package/dist/memory/index.d.ts.map +1 -0
  51. package/dist/memory/index.js +192 -0
  52. package/dist/memory/index.js.map +1 -0
  53. package/dist/paths.d.ts +7 -0
  54. package/dist/paths.d.ts.map +1 -1
  55. package/dist/paths.js +9 -0
  56. package/dist/paths.js.map +1 -1
  57. package/dist/protocol.d.ts +6 -0
  58. package/dist/protocol.d.ts.map +1 -1
  59. package/dist/protocol.js +6 -0
  60. package/dist/protocol.js.map +1 -1
  61. package/dist/registry.d.ts +7 -2
  62. package/dist/registry.d.ts.map +1 -1
  63. package/dist/registry.js +8 -5
  64. package/dist/registry.js.map +1 -1
  65. package/dist/server.d.ts.map +1 -1
  66. package/dist/server.js +6 -0
  67. package/dist/server.js.map +1 -1
  68. package/dist/tools/guidance.d.ts.map +1 -1
  69. package/dist/tools/guidance.js +4 -0
  70. package/dist/tools/guidance.js.map +1 -1
  71. package/dist/tools/tools.d.ts.map +1 -1
  72. package/dist/tools/tools.js +292 -2
  73. package/dist/tools/tools.js.map +1 -1
  74. package/dist/types.d.ts +105 -5
  75. package/dist/types.d.ts.map +1 -1
  76. package/dist/types.js +27 -2
  77. package/dist/types.js.map +1 -1
  78. package/dist/worktree.d.ts +131 -0
  79. package/dist/worktree.d.ts.map +1 -0
  80. package/dist/worktree.js +278 -0
  81. package/dist/worktree.js.map +1 -0
  82. package/fakes/claude.mjs +53 -3
  83. package/fakes/lib.mjs +24 -9
  84. package/package.json +11 -1
package/fakes/lib.mjs CHANGED
@@ -549,26 +549,37 @@ async function runWithLeave(command, cwd, env, askLeave) {
549
549
  * An `edit:` directive: a file the session's own edit tool changes, by adding a line to it,
550
550
  * which the session needs leave for the way its harness decides. It is in the turn as a command
551
551
  * `edit <path>`, refused or done. A harness that imitates no edit tool of its own fails it.
552
+ * A harness may move the session before it edits, as Claude Code moves a background session
553
+ * into a worktree of its own: the leave then says where the session is now (`cwd`) and which
554
+ * file the edit means there (`file`).
552
555
  * @param {string} path as the model wrote it, relative to the folder of the session or absolute
553
556
  * @param {LeaveAsker | undefined} askLeave
554
- * @returns {Promise<CommandRun>}
557
+ * @returns {Promise<CommandRun & { movedTo?: string }>}
555
558
  */
556
559
  async function editWithLeave(path, cwd, askLeave) {
557
- const file = resolve(cwd, path);
558
560
  const command = `edit ${path}`;
559
561
  if (!askLeave) {
560
562
  return { command, code: 1, stdout: '', stderr: 'this stand-in has no edit tool of its own' };
561
563
  }
562
- const leave = await askLeave({ tool: 'Edit', input: { file_path: file } });
564
+ const leave = await askLeave({ tool: 'Edit', input: { file_path: resolve(cwd, path) } });
565
+ const moved = leave.cwd !== undefined && { movedTo: leave.cwd };
563
566
  if (!leave.allowed) {
564
- return { command, code: null, stdout: '', stderr: leave.message ?? 'denied', denied: true };
567
+ return {
568
+ command,
569
+ code: null,
570
+ stdout: '',
571
+ stderr: leave.message ?? 'denied',
572
+ denied: true,
573
+ ...moved,
574
+ };
565
575
  }
576
+ const file = leave.file ?? resolve(cwd, path);
566
577
  try {
567
578
  mkdirSync(dirname(file), { recursive: true });
568
579
  appendFileSync(file, 'edited\n');
569
- return { command, code: 0, stdout: '', stderr: '' };
580
+ return { command, code: 0, stdout: '', stderr: '', ...moved };
570
581
  } catch (error) {
571
- return { command, code: 1, stdout: '', stderr: error.message };
582
+ return { command, code: 1, stdout: '', stderr: error.message, ...moved };
572
583
  }
573
584
  }
574
585
 
@@ -586,16 +597,20 @@ async function editWithLeave(path, cwd, askLeave) {
586
597
  * @param {LeaveAsker} [turn.askLeave] how the session gets leave for a call of its own tools
587
598
  * @returns {Promise<TurnOutcome>}
588
599
  */
589
- export async function performTurn({ input, cwd, env, callTool, askLeave }) {
600
+ export async function performTurn({ input, cwd: startedIn, env, callTool, askLeave }) {
590
601
  const at = new Date().toISOString();
591
602
  const ran = [];
592
603
  const tools = [];
593
604
  let answer = 'ok';
605
+ let cwd = startedIn;
594
606
  for (const { kind, value } of directives(input)) {
595
607
  if (kind === 'run') ran.push(await runCommand(value, cwd, env));
596
608
  else if (kind === 'bash') ran.push(await runWithLeave(value, cwd, env, askLeave));
597
- else if (kind === 'edit') ran.push(await editWithLeave(value, cwd, askLeave));
598
- else if (kind === 'tool') tools.push(await runTool(value, callTool));
609
+ else if (kind === 'edit') {
610
+ const { movedTo, ...run } = await editWithLeave(value, cwd, askLeave);
611
+ if (movedTo !== undefined) cwd = movedTo;
612
+ ran.push(run);
613
+ } else if (kind === 'tool') tools.push(await runTool(value, callTool));
599
614
  else if (kind === 'sleep') await sleep(Number(value));
600
615
  else answer = value;
601
616
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cogitator-ai/bridge",
3
- "version": "0.6.1",
3
+ "version": "0.8.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",
@@ -37,6 +37,11 @@
37
37
  "types": "./dist/testing/index.d.ts",
38
38
  "import": "./dist/testing/index.js",
39
39
  "default": "./dist/testing/index.js"
40
+ },
41
+ "./memory": {
42
+ "types": "./dist/memory/index.d.ts",
43
+ "import": "./dist/memory/index.js",
44
+ "default": "./dist/memory/index.js"
40
45
  }
41
46
  },
42
47
  "sideEffects": false,
@@ -54,6 +59,7 @@
54
59
  "devDependencies": {
55
60
  "@cogitator-ai/core": "0.79.0",
56
61
  "@cogitator-ai/mcp": "19.12.0",
62
+ "@cogitator-ai/memory": "0.29.7",
57
63
  "@types/better-sqlite3": "^9.6.0",
58
64
  "@types/node": "^22.20.4",
59
65
  "better-sqlite3": "^13.0.3",
@@ -62,6 +68,7 @@
62
68
  },
63
69
  "peerDependencies": {
64
70
  "@cogitator-ai/core": ">=0.79.0",
71
+ "@cogitator-ai/memory": ">=0.29.7",
65
72
  "better-sqlite3": "^11.0.0 || ^12.0.0 || ^13.0.0"
66
73
  },
67
74
  "peerDependenciesMeta": {
@@ -70,6 +77,9 @@
70
77
  },
71
78
  "better-sqlite3": {
72
79
  "optional": true
80
+ },
81
+ "@cogitator-ai/memory": {
82
+ "optional": true
73
83
  }
74
84
  },
75
85
  "engines": {