@koda-sl/baker-bridge 0.194.0 → 0.195.0-dev.a2270c74d

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 (54) hide show
  1. package/README.md +43 -35
  2. package/dist/hono/bridge-job.d.ts +10 -0
  3. package/dist/hono/bridge-job.d.ts.map +1 -1
  4. package/dist/hono/bridge-job.js +55 -19
  5. package/dist/hono/bridge-job.js.map +1 -1
  6. package/dist/hono/bridge-job.test.js +27 -226
  7. package/dist/hono/bridge-job.test.js.map +1 -1
  8. package/dist/hono/chat-language.d.ts +34 -0
  9. package/dist/hono/chat-language.d.ts.map +1 -0
  10. package/dist/hono/chat-language.js +152 -0
  11. package/dist/hono/chat-language.js.map +1 -0
  12. package/dist/hono/chat-language.test.d.ts +2 -0
  13. package/dist/hono/chat-language.test.d.ts.map +1 -0
  14. package/dist/hono/chat-language.test.js +136 -0
  15. package/dist/hono/chat-language.test.js.map +1 -0
  16. package/dist/hono/jev.d.ts +16 -0
  17. package/dist/hono/jev.d.ts.map +1 -1
  18. package/dist/hono/jev.js +44 -21
  19. package/dist/hono/jev.js.map +1 -1
  20. package/dist/hono/model-capabilities.js +3 -3
  21. package/dist/hono/model-capabilities.js.map +1 -1
  22. package/dist/hono/progress-note.d.ts +0 -3
  23. package/dist/hono/progress-note.d.ts.map +1 -1
  24. package/dist/hono/progress-note.js +0 -8
  25. package/dist/hono/progress-note.js.map +1 -1
  26. package/dist/hono/publish-handoff.d.ts +6 -26
  27. package/dist/hono/publish-handoff.d.ts.map +1 -1
  28. package/dist/hono/publish-handoff.js +10 -118
  29. package/dist/hono/publish-handoff.js.map +1 -1
  30. package/dist/hono/publish-handoff.test.js +31 -172
  31. package/dist/hono/publish-handoff.test.js.map +1 -1
  32. package/dist/hono/skill-language.d.ts +16 -40
  33. package/dist/hono/skill-language.d.ts.map +1 -1
  34. package/dist/hono/skill-language.js +39 -172
  35. package/dist/hono/skill-language.js.map +1 -1
  36. package/dist/hono/skill-language.test.js +36 -89
  37. package/dist/hono/skill-language.test.js.map +1 -1
  38. package/dist/hono/subagent-route.test.js +29 -5
  39. package/dist/hono/subagent-route.test.js.map +1 -1
  40. package/dist/review/digest.d.ts +0 -5
  41. package/dist/review/digest.d.ts.map +1 -1
  42. package/dist/review/digest.js +33 -28
  43. package/dist/review/digest.js.map +1 -1
  44. package/dist/review/digest.test.js +11 -248
  45. package/dist/review/digest.test.js.map +1 -1
  46. package/dist/review/evidence-block.js +1 -1
  47. package/dist/review/evidence-block.js.map +1 -1
  48. package/dist/review/reply-language.d.ts +8 -33
  49. package/dist/review/reply-language.d.ts.map +1 -1
  50. package/dist/review/reply-language.js +23 -168
  51. package/dist/review/reply-language.js.map +1 -1
  52. package/dist/review/reply-language.test.js +10 -75
  53. package/dist/review/reply-language.test.js.map +1 -1
  54. package/package.json +1 -2
@@ -272,8 +272,17 @@ function createExecutor(options) {
272
272
  }),
273
273
  // Never the network: a turn nobody judges runs on the default model and effort.
274
274
  routeJudge: options.routeJudge ?? (async () => null),
275
+ readLanguage: fakeChatLanguage,
275
276
  });
276
277
  }
278
+ /** Jev's language decision, faked for the tests' own lines: whichever of Spanish or English has more of its words. */
279
+ function fakeReading(text) {
280
+ const count = (words) => text.toLowerCase().match(words)?.length ?? 0;
281
+ const spanish = count(/\b(el|la|los|las|de|que|ya|está|en|una|reviso|antes|hecho|nuevos|cuatro|para)\b/g);
282
+ const english = count(/\b(the|and|your|then|keep|both|now|in|order|isn't|add|different|a)\b/g);
283
+ return spanish === english ? undefined : spanish > english ? "Spanish" : "English";
284
+ }
285
+ const fakeChatLanguage = ({ text }) => Promise.resolve(fakeReading(text));
277
286
  /** The executor's optional dependencies a test set, so an unset one keeps the executor's default. */
278
287
  function definedOnly(deps) {
279
288
  return Object.fromEntries(Object.entries(deps).filter(([, value]) => value !== undefined));
@@ -1212,6 +1221,21 @@ describe("BridgeJobExecutor", () => {
1212
1221
  // would resume a transcript holding one `/publish` and nothing else.
1213
1222
  expect(savedBoundaries).toEqual([]);
1214
1223
  });
1224
+ // BAKER-4674: a note between publish steps reached a Spanish chat in English, naming main.
1225
+ it("shows the marketer only a publish turn's last message, the outcome", async () => {
1226
+ const relay = recordingRelay();
1227
+ const executor = createExecutor({
1228
+ relay,
1229
+ queryResults: [
1230
+ scriptedMessages(assistantMessage("a1", "The chat's version already contains everything main has.", "session_publish_own"), toolUseAssistantMessage("Bash", { command: "git rebase --continue" }), assistantMessage("a2", "Publicado: tu página estará en línea en unos minutos.", "session_publish_own"), resultMessage(0.3, "session_publish_own")),
1231
+ ],
1232
+ });
1233
+ await executor.execute({ threadId: "thread_publish", turnId: "turn_publish", prompt: "/publish", history: history([]) }, activeControls());
1234
+ const said = relay.assistantEvents.flatMap((e) => e.event.message.content
1235
+ .filter((block) => block.type === "text")
1236
+ .map((block) => block.text));
1237
+ expect(said).toEqual(["Publicado: tu página estará en línea en unos minutos."]);
1238
+ });
1215
1239
  it("settles the chat's Publish once a publish turn ends, and never after a chat turn", async () => {
1216
1240
  let settled = 0;
1217
1241
  const settleAfterPublish = () => {
@@ -1556,7 +1580,7 @@ describe("BridgeJobExecutor", () => {
1556
1580
  await executor.execute({ threadId: "thread_untitled", turnId: "turn_untitled", prompt: "Build a landing", history: history([]) }, activeControls());
1557
1581
  expect(queryInputs[0]?.options.env).toMatchObject({ CLAUDE_CODE_DISABLE_TERMINAL_TITLE: "1" });
1558
1582
  });
1559
- it("silences the CLI task reminders and ANSI colour in the agent subprocess", async () => {
1583
+ it("silences the CLI task and silent-turn reminders and ANSI colour in the agent subprocess", async () => {
1560
1584
  const queryInputs = [];
1561
1585
  const executor = createExecutor({
1562
1586
  queryInputs,
@@ -1565,6 +1589,8 @@ describe("BridgeJobExecutor", () => {
1565
1589
  await executor.execute({ threadId: "thread_quiet", turnId: "turn_quiet", prompt: "Build a landing", history: history([]) }, activeControls());
1566
1590
  expect(queryInputs[0]?.options.env).toMatchObject({
1567
1591
  CLAUDE_CODE_ENABLE_TASKS: "0",
1592
+ CLAUDE_CODE_SILENT_TURN_REMINDER: "0",
1593
+ CLAUDE_CODE_WEBSEARCH_CITATIONS: "1",
1568
1594
  NO_COLOR: "1",
1569
1595
  });
1570
1596
  });
@@ -5499,231 +5525,6 @@ describe("BridgeJobExecutor review mode", () => {
5499
5525
  throw new Error("expected the turn to start one query");
5500
5526
  expect((await contextAfterSkillLoad(options))?.startsWith("Baker: the language of this chat.")).toBe(true);
5501
5527
  });
5502
- /** Every PostToolUse note the model reads after `toolName` returns, as the CLI joins them. */
5503
- async function contextAfterTool(options, toolName, extras = {}) {
5504
- const input = {
5505
- hook_event_name: "PostToolUse",
5506
- tool_name: toolName,
5507
- tool_input: {},
5508
- tool_response: "ok",
5509
- tool_use_id: "t2",
5510
- session_id: "s",
5511
- transcript_path: "",
5512
- cwd: "/",
5513
- ...extras,
5514
- };
5515
- const hooks = (options.hooks?.PostToolUse ?? [])
5516
- .filter((matcher) => matcher.matcher === undefined || new RegExp(`^(?:${matcher.matcher})$`).test(toolName))
5517
- .flatMap((matcher) => matcher.hooks);
5518
- const notes = [];
5519
- for (const hook of hooks) {
5520
- const output = await hook(input, "t2", { signal: new AbortController().signal });
5521
- const specific = "hookSpecificOutput" in output ? output.hookSpecificOutput : undefined;
5522
- if (specific?.hookEventName === "PostToolUse" && specific.additionalContext)
5523
- notes.push(specific.additionalContext);
5524
- }
5525
- return notes.length > 0 ? notes.join("\n") : undefined;
5526
- }
5527
- // BAKER-305: in a Spanish chat the marketer read "Now the definition, then a live test." between tool calls.
5528
- it("restates a Spanish chat's language on the next tool result after a line to the marketer drifts into English", async () => {
5529
- const queryInputs = [];
5530
- const executor = createExecutor({
5531
- queryInputs,
5532
- queryResults: [
5533
- scriptedMessages(assistantMessage("a1", "Now the definition, then a live test."), resultMessage(0, "session_next")),
5534
- ],
5535
- });
5536
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5537
- const options = queryInputs[0]?.options;
5538
- if (!options)
5539
- throw new Error("expected the turn to start one query");
5540
- const context = await contextAfterTool(options, "Bash");
5541
- expect(context?.startsWith("Baker: the language of this chat.")).toBe(true);
5542
- expect(context).toContain("Write every line you send the user in Spanish");
5543
- });
5544
- async function spanishTurnAfter(...messages) {
5545
- const queryInputs = [];
5546
- const executor = createExecutor({
5547
- queryInputs,
5548
- queryResults: [scriptedMessages(...messages, resultMessage(0, "session_next"))],
5549
- });
5550
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5551
- const options = queryInputs[0]?.options;
5552
- if (!options)
5553
- throw new Error("expected the turn to start one query");
5554
- return options;
5555
- }
5556
- // A publish starts with `/publish`, so the marketer's language comes from the chat's history.
5557
- it("restates the language on a publish's next tool result after its conflict note drifts into English", async () => {
5558
- const queryInputs = [];
5559
- const executor = createExecutor({
5560
- queryInputs,
5561
- queryResults: [
5562
- scriptedMessages(assistantMessage("a1", "Both sides add different dated lines — keep both in order."), resultMessage(0, "session_publish_drift")),
5563
- ],
5564
- });
5565
- await executor.execute({
5566
- threadId: "thread_publish_drift",
5567
- turnId: "turn_publish_drift",
5568
- prompt: "/publish",
5569
- history: history([
5570
- { role: "user", text: "Añade la nueva oferta de octubre a la landing de conductores", createdAt: 1 },
5571
- { role: "assistant", text: "Hecho: la oferta ya está en la landing.", createdAt: 2 },
5572
- { role: "user", text: "/publish", createdAt: 3 },
5573
- ]),
5574
- }, activeControls());
5575
- const options = queryInputs[0]?.options;
5576
- if (!options)
5577
- throw new Error("expected the publish to start one query");
5578
- const context = await contextAfterTool(options, "Bash");
5579
- expect(context).toContain("Your last line to the user was not in Spanish.");
5580
- expect(context).not.toContain("Añade la nueva oferta de octubre");
5581
- });
5582
- // BAKER-3389: a publish that reads the marketer's quoted words takes them as feedback it still owes.
5583
- it("restates the language after a publish's subagent report without quoting the marketer", async () => {
5584
- const queryInputs = [];
5585
- const executor = createExecutor({
5586
- queryInputs,
5587
- queryResults: [
5588
- scriptedMessages(assistantMessage("a1", "Reviso los cambios antes de publicar."), resultMessage(0, "session_publish_report")),
5589
- ],
5590
- });
5591
- await executor.execute({
5592
- threadId: "thread_publish_report",
5593
- turnId: "turn_publish_report",
5594
- prompt: "/publish",
5595
- history: history([
5596
- { role: "user", text: "Añade la nueva oferta de octubre a la landing de conductores", createdAt: 1 },
5597
- { role: "assistant", text: "Hecho: la oferta ya está en la landing.", createdAt: 2 },
5598
- { role: "user", text: "/publish", createdAt: 3 },
5599
- ]),
5600
- }, activeControls());
5601
- const options = queryInputs[0]?.options;
5602
- if (!options)
5603
- throw new Error("expected the publish to start one query");
5604
- const context = await contextAfterTool(options, "Agent");
5605
- expect(context).toContain("The agent's report you just read is written for you.");
5606
- expect(context).not.toContain("Añade la nueva oferta de octubre");
5607
- });
5608
- it("adds no note after Spanish lines to the marketer or a subagent's English", async () => {
5609
- const options = await spanishTurnAfter(assistantMessage("a1", "Ahora reviso el banner de las cuatro landings de verano."), assistantMessage("a2", "Now insert it into the four pages and add the hero hook.", undefined, {
5610
- parent_tool_use_id: "toolu_agent",
5611
- }));
5612
- expect(await contextAfterTool(options, "Bash")).toBeUndefined();
5613
- });
5614
- it("adds no note after a provider error the marketer never saw", async () => {
5615
- const options = await spanishTurnAfter(apiErrorMessage("a1", "API Error: Server error mid-response. The response above may be incomplete.", "server_error"), assistantMessage("a2", "Ahora reviso el banner de las cuatro landings de verano."));
5616
- expect(await contextAfterTool(options, "Read")).toBeUndefined();
5617
- });
5618
- it("names the drift in a progress note Opus 5.5 returned as a thinking block", async () => {
5619
- const options = await spanishTurnAfter({
5620
- type: "assistant",
5621
- uuid: "a1",
5622
- parent_tool_use_id: null,
5623
- message: {
5624
- role: "assistant",
5625
- model: "claude-opus-5-5",
5626
- content: [
5627
- { type: "thinking", thinking: "", signature: "AAAA" },
5628
- { type: "thinking", thinking: "Found the campaign, now checking its budget.", signature: "BBBB" },
5629
- ],
5630
- stop_reason: "tool_use",
5631
- },
5632
- });
5633
- expect(await contextAfterTool(options, "Read")).toContain("Your last line to the user was not in Spanish.");
5634
- });
5635
- it("names the drift to the main thread, not to a subagent's own tool call", async () => {
5636
- const options = await spanishTurnAfter(assistantMessage("a1", "Now the definition, then a live test."));
5637
- expect(await contextAfterTool(options, "Read", { agent_id: "agent_1" })).toBeUndefined();
5638
- expect(await contextAfterTool(options, "Read")).toContain("Your last line to the user was not in Spanish.");
5639
- expect(await contextAfterTool(options, "Read")).toBeUndefined();
5640
- });
5641
- // A subagent reports in English for the model, and the next line went out in English.
5642
- it("restates the language after every subagent's report, drift or not", async () => {
5643
- const options = await spanishTurnAfter(assistantMessage("a1", "Ahora reviso el banner de las landings."));
5644
- expect(await contextAfterTool(options, "Agent")).toContain("The agent's report you just read is written for you.");
5645
- expect(await contextAfterTool(options, "Agent")).toContain("in Spanish");
5646
- });
5647
- // The landing and creative skills start their subagents with `run_in_background: true`.
5648
- it("restates the language after a background subagent's report arrives, not when it starts", async () => {
5649
- const queryInputs = [];
5650
- const notes = [];
5651
- const executor = createExecutor({
5652
- queryInputs,
5653
- queryResults: [
5654
- {
5655
- async *[Symbol.asyncIterator]() {
5656
- await Promise.resolve();
5657
- const options = queryInputs[0]?.options;
5658
- if (!options)
5659
- throw new Error("expected the turn to start one query");
5660
- yield {
5661
- type: "assistant",
5662
- uuid: "a1",
5663
- message: {
5664
- role: "assistant",
5665
- content: [{ type: "tool_use", id: "t2", name: "Agent", input: { run_in_background: true } }],
5666
- stop_reason: "tool_use",
5667
- },
5668
- };
5669
- notes.push(await contextAfterTool(options, "Agent", { tool_input: { run_in_background: true } }));
5670
- yield {
5671
- type: "system",
5672
- subtype: "task_notification",
5673
- task_id: "task_1",
5674
- tool_use_id: "t2",
5675
- status: "completed",
5676
- output_file: "",
5677
- summary: "Built the four landings.",
5678
- uuid: "n1",
5679
- session_id: "s",
5680
- };
5681
- yield assistantMessage("a2", "Ya están las cuatro landings.");
5682
- notes.push(await contextAfterTool(options, "Read"));
5683
- yield resultMessage(0, "session_next");
5684
- },
5685
- },
5686
- ],
5687
- });
5688
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5689
- expect(notes[0]).toBeUndefined();
5690
- expect(notes[1]).toContain("The agent's report you just read is written for you.");
5691
- });
5692
- // In a dev Session the CLI asked for the PostToolUse hook of a fast `ls` before
5693
- // the bridge had read the line "Let me check the source folder before I answer."
5694
- // off the stream, so the drift was never named.
5695
- it("names a drift whose line the bridge reads off the stream after the tool already returned", async () => {
5696
- const queryInputs = [];
5697
- let context;
5698
- const executor = createExecutor({
5699
- queryInputs,
5700
- queryResults: [
5701
- {
5702
- async *[Symbol.asyncIterator]() {
5703
- await Promise.resolve();
5704
- const options = queryInputs[0]?.options;
5705
- if (!options)
5706
- throw new Error("expected the turn to start one query");
5707
- context = contextAfterTool(options, "Bash");
5708
- yield assistantMessage("a1", "Let me check the source folder before I answer.");
5709
- yield {
5710
- type: "assistant",
5711
- uuid: "a2",
5712
- message: {
5713
- role: "assistant",
5714
- content: [{ type: "tool_use", id: "t2", name: "Bash", input: { command: "ls src" } }],
5715
- stop_reason: "tool_use",
5716
- },
5717
- };
5718
- await context;
5719
- yield resultMessage(0, "session_next");
5720
- },
5721
- },
5722
- ],
5723
- });
5724
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5725
- expect(await context).toContain("Your last line to the user was not in Spanish.");
5726
- });
5727
5528
  it("adds no language note to a review, which loads no skill and writes to nobody", async () => {
5728
5529
  const queryInputs = [];
5729
5530
  const executor = createExecutor({ queryInputs });