@koda-sl/baker-bridge 0.194.0-dev.8f5bcdb0e → 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 (67) hide show
  1. package/README.md +66 -28
  2. package/dist/hono/agent.d.ts.map +1 -1
  3. package/dist/hono/agent.js +4 -1
  4. package/dist/hono/agent.js.map +1 -1
  5. package/dist/hono/bridge-job.d.ts +27 -0
  6. package/dist/hono/bridge-job.d.ts.map +1 -1
  7. package/dist/hono/bridge-job.js +93 -19
  8. package/dist/hono/bridge-job.js.map +1 -1
  9. package/dist/hono/bridge-job.test.js +99 -226
  10. package/dist/hono/bridge-job.test.js.map +1 -1
  11. package/dist/hono/chat-language.d.ts +34 -0
  12. package/dist/hono/chat-language.d.ts.map +1 -0
  13. package/dist/hono/chat-language.js +152 -0
  14. package/dist/hono/chat-language.js.map +1 -0
  15. package/dist/hono/chat-language.test.d.ts +2 -0
  16. package/dist/hono/chat-language.test.d.ts.map +1 -0
  17. package/dist/hono/chat-language.test.js +136 -0
  18. package/dist/hono/chat-language.test.js.map +1 -0
  19. package/dist/hono/jev.d.ts +16 -0
  20. package/dist/hono/jev.d.ts.map +1 -1
  21. package/dist/hono/jev.js +44 -21
  22. package/dist/hono/jev.js.map +1 -1
  23. package/dist/hono/model-capabilities.js +3 -3
  24. package/dist/hono/model-capabilities.js.map +1 -1
  25. package/dist/hono/progress-note.d.ts +0 -3
  26. package/dist/hono/progress-note.d.ts.map +1 -1
  27. package/dist/hono/progress-note.js +0 -8
  28. package/dist/hono/progress-note.js.map +1 -1
  29. package/dist/hono/publish-handoff.d.ts +6 -17
  30. package/dist/hono/publish-handoff.d.ts.map +1 -1
  31. package/dist/hono/publish-handoff.js +17 -67
  32. package/dist/hono/publish-handoff.js.map +1 -1
  33. package/dist/hono/publish-handoff.test.js +34 -63
  34. package/dist/hono/publish-handoff.test.js.map +1 -1
  35. package/dist/hono/scripted-publish.d.ts +19 -0
  36. package/dist/hono/scripted-publish.d.ts.map +1 -0
  37. package/dist/hono/scripted-publish.js +219 -0
  38. package/dist/hono/scripted-publish.js.map +1 -0
  39. package/dist/hono/scripted-publish.test.d.ts +2 -0
  40. package/dist/hono/scripted-publish.test.d.ts.map +1 -0
  41. package/dist/hono/scripted-publish.test.js +212 -0
  42. package/dist/hono/scripted-publish.test.js.map +1 -0
  43. package/dist/hono/skill-language.d.ts +16 -40
  44. package/dist/hono/skill-language.d.ts.map +1 -1
  45. package/dist/hono/skill-language.js +39 -168
  46. package/dist/hono/skill-language.js.map +1 -1
  47. package/dist/hono/skill-language.test.js +48 -50
  48. package/dist/hono/skill-language.test.js.map +1 -1
  49. package/dist/hono/subagent-route.test.js +29 -5
  50. package/dist/hono/subagent-route.test.js.map +1 -1
  51. package/dist/hono/types.d.ts +9 -0
  52. package/dist/hono/types.d.ts.map +1 -1
  53. package/dist/review/digest.d.ts +6 -5
  54. package/dist/review/digest.d.ts.map +1 -1
  55. package/dist/review/digest.js +34 -28
  56. package/dist/review/digest.js.map +1 -1
  57. package/dist/review/digest.test.js +42 -177
  58. package/dist/review/digest.test.js.map +1 -1
  59. package/dist/review/evidence-block.js +2 -2
  60. package/dist/review/evidence-block.js.map +1 -1
  61. package/dist/review/reply-language.d.ts +12 -30
  62. package/dist/review/reply-language.d.ts.map +1 -1
  63. package/dist/review/reply-language.js +97 -162
  64. package/dist/review/reply-language.js.map +1 -1
  65. package/dist/review/reply-language.test.js +67 -75
  66. package/dist/review/reply-language.test.js.map +1 -1
  67. package/package.json +1 -2
@@ -268,11 +268,21 @@ function createExecutor(options) {
268
268
  holdsNoWork: options.holdsNoWork,
269
269
  routeModels: options.routeModels,
270
270
  settleAfterPublish: options.settleAfterPublish,
271
+ scriptedPublish: options.scriptedPublish,
271
272
  }),
272
273
  // Never the network: a turn nobody judges runs on the default model and effort.
273
274
  routeJudge: options.routeJudge ?? (async () => null),
275
+ readLanguage: fakeChatLanguage,
274
276
  });
275
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));
276
286
  /** The executor's optional dependencies a test set, so an unset one keeps the executor's default. */
277
287
  function definedOnly(deps) {
278
288
  return Object.fromEntries(Object.entries(deps).filter(([, value]) => value !== undefined));
@@ -1211,6 +1221,21 @@ describe("BridgeJobExecutor", () => {
1211
1221
  // would resume a transcript holding one `/publish` and nothing else.
1212
1222
  expect(savedBoundaries).toEqual([]);
1213
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
+ });
1214
1239
  it("settles the chat's Publish once a publish turn ends, and never after a chat turn", async () => {
1215
1240
  let settled = 0;
1216
1241
  const settleAfterPublish = () => {
@@ -1230,6 +1255,77 @@ describe("BridgeJobExecutor", () => {
1230
1255
  await chatting.execute({ threadId: "thread_chat", turnId: "turn_chat", prompt: "hello" }, activeControls());
1231
1256
  expect([afterPublish, settled]).toEqual([1, 1]);
1232
1257
  });
1258
+ // BAKER-231: a run's Auto publish started a second agent session — every
1259
+ // SessionStart probe again and a cold model turn — only to run the publish
1260
+ // skill's scripts and say "I'll publish now." to a marketer nobody asked.
1261
+ it("publishes a run Auto publish authorized without starting the agent, and settles it", async () => {
1262
+ const queryInputs = [];
1263
+ const relay = recordingRelay();
1264
+ let settled = 0;
1265
+ const executor = createExecutor({
1266
+ relay,
1267
+ queryInputs,
1268
+ settleAfterPublish: () => {
1269
+ settled += 1;
1270
+ return Promise.resolve();
1271
+ },
1272
+ scriptedPublish: () => Promise.resolve({ kind: "finished" }),
1273
+ });
1274
+ const outcome = await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, activeControls());
1275
+ expect({ queries: queryInputs.length, said: relay.assistantEvents.length, settled, kind: outcome.kind }).toEqual({
1276
+ queries: 0,
1277
+ said: 0,
1278
+ settled: 1,
1279
+ kind: "completed",
1280
+ });
1281
+ });
1282
+ // Its steps together outlast the session watchdog's idle window, though each
1283
+ // stays within its own timeout: the turn has to say it is working.
1284
+ it("holds the turn as working while the Auto publish scripts run", async () => {
1285
+ const reported = [];
1286
+ const workingDuringScripts = [];
1287
+ const executor = createExecutor({
1288
+ scriptedPublish: () => {
1289
+ workingDuringScripts.push(reported.at(-1) === true);
1290
+ return Promise.resolve({ kind: "finished" });
1291
+ },
1292
+ });
1293
+ const controls = {
1294
+ ...activeControls(),
1295
+ setWorkInFlight: (inFlight) => {
1296
+ reported.push(inFlight);
1297
+ },
1298
+ };
1299
+ await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, controls);
1300
+ expect({ workingDuringScripts, last: reported.at(-1) }).toEqual({ workingDuringScripts: [true], last: false });
1301
+ });
1302
+ it("hands an Auto publish whose scripts stopped to the agent, which publishes as it always has", async () => {
1303
+ const queryInputs = [];
1304
+ const executor = createExecutor({
1305
+ queryInputs,
1306
+ queryResults: [scriptedMessages(resultMessage(0.3, "session_publish_own"))],
1307
+ scriptedPublish: () => Promise.resolve({ kind: "handOff", step: "rebase" }),
1308
+ });
1309
+ await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, activeControls());
1310
+ expect(queryInputs.map((input) => input.prompt)).toEqual(["/publish"]);
1311
+ });
1312
+ it("leaves a Publish a person pressed to the agent", async () => {
1313
+ const queryInputs = [];
1314
+ let scripted = 0;
1315
+ const executor = createExecutor({
1316
+ queryInputs,
1317
+ queryResults: [scriptedMessages(resultMessage(0.3, "session_publish_own"))],
1318
+ scriptedPublish: () => {
1319
+ scripted += 1;
1320
+ return Promise.resolve({ kind: "finished" });
1321
+ },
1322
+ });
1323
+ await executor.execute({ threadId: "thread_pressed", turnId: "turn_pressed", prompt: "/publish", history: history([]) }, activeControls());
1324
+ expect({ scripted, prompts: queryInputs.map((input) => input.prompt) }).toEqual({
1325
+ scripted: 0,
1326
+ prompts: ["/publish"],
1327
+ });
1328
+ });
1233
1329
  it("leaves the chat's session alone when a publish fails", async () => {
1234
1330
  const clearCalls = [];
1235
1331
  const executor = createExecutor({
@@ -1484,7 +1580,7 @@ describe("BridgeJobExecutor", () => {
1484
1580
  await executor.execute({ threadId: "thread_untitled", turnId: "turn_untitled", prompt: "Build a landing", history: history([]) }, activeControls());
1485
1581
  expect(queryInputs[0]?.options.env).toMatchObject({ CLAUDE_CODE_DISABLE_TERMINAL_TITLE: "1" });
1486
1582
  });
1487
- 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 () => {
1488
1584
  const queryInputs = [];
1489
1585
  const executor = createExecutor({
1490
1586
  queryInputs,
@@ -1493,6 +1589,8 @@ describe("BridgeJobExecutor", () => {
1493
1589
  await executor.execute({ threadId: "thread_quiet", turnId: "turn_quiet", prompt: "Build a landing", history: history([]) }, activeControls());
1494
1590
  expect(queryInputs[0]?.options.env).toMatchObject({
1495
1591
  CLAUDE_CODE_ENABLE_TASKS: "0",
1592
+ CLAUDE_CODE_SILENT_TURN_REMINDER: "0",
1593
+ CLAUDE_CODE_WEBSEARCH_CITATIONS: "1",
1496
1594
  NO_COLOR: "1",
1497
1595
  });
1498
1596
  });
@@ -5427,231 +5525,6 @@ describe("BridgeJobExecutor review mode", () => {
5427
5525
  throw new Error("expected the turn to start one query");
5428
5526
  expect((await contextAfterSkillLoad(options))?.startsWith("Baker: the language of this chat.")).toBe(true);
5429
5527
  });
5430
- /** Every PostToolUse note the model reads after `toolName` returns, as the CLI joins them. */
5431
- async function contextAfterTool(options, toolName, extras = {}) {
5432
- const input = {
5433
- hook_event_name: "PostToolUse",
5434
- tool_name: toolName,
5435
- tool_input: {},
5436
- tool_response: "ok",
5437
- tool_use_id: "t2",
5438
- session_id: "s",
5439
- transcript_path: "",
5440
- cwd: "/",
5441
- ...extras,
5442
- };
5443
- const hooks = (options.hooks?.PostToolUse ?? [])
5444
- .filter((matcher) => matcher.matcher === undefined || new RegExp(`^(?:${matcher.matcher})$`).test(toolName))
5445
- .flatMap((matcher) => matcher.hooks);
5446
- const notes = [];
5447
- for (const hook of hooks) {
5448
- const output = await hook(input, "t2", { signal: new AbortController().signal });
5449
- const specific = "hookSpecificOutput" in output ? output.hookSpecificOutput : undefined;
5450
- if (specific?.hookEventName === "PostToolUse" && specific.additionalContext)
5451
- notes.push(specific.additionalContext);
5452
- }
5453
- return notes.length > 0 ? notes.join("\n") : undefined;
5454
- }
5455
- // BAKER-305: in a Spanish chat the marketer read "Now the definition, then a live test." between tool calls.
5456
- it("restates a Spanish chat's language on the next tool result after a line to the marketer drifts into English", async () => {
5457
- const queryInputs = [];
5458
- const executor = createExecutor({
5459
- queryInputs,
5460
- queryResults: [
5461
- scriptedMessages(assistantMessage("a1", "Now the definition, then a live test."), resultMessage(0, "session_next")),
5462
- ],
5463
- });
5464
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5465
- const options = queryInputs[0]?.options;
5466
- if (!options)
5467
- throw new Error("expected the turn to start one query");
5468
- const context = await contextAfterTool(options, "Bash");
5469
- expect(context?.startsWith("Baker: the language of this chat.")).toBe(true);
5470
- expect(context).toContain("Write every line you send the user in Spanish");
5471
- });
5472
- async function spanishTurnAfter(...messages) {
5473
- const queryInputs = [];
5474
- const executor = createExecutor({
5475
- queryInputs,
5476
- queryResults: [scriptedMessages(...messages, resultMessage(0, "session_next"))],
5477
- });
5478
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5479
- const options = queryInputs[0]?.options;
5480
- if (!options)
5481
- throw new Error("expected the turn to start one query");
5482
- return options;
5483
- }
5484
- // A publish starts with `/publish`, so the marketer's language comes from the chat's history.
5485
- it("restates the language on a publish's next tool result after its conflict note drifts into English", async () => {
5486
- const queryInputs = [];
5487
- const executor = createExecutor({
5488
- queryInputs,
5489
- queryResults: [
5490
- scriptedMessages(assistantMessage("a1", "Both sides add different dated lines — keep both in order."), resultMessage(0, "session_publish_drift")),
5491
- ],
5492
- });
5493
- await executor.execute({
5494
- threadId: "thread_publish_drift",
5495
- turnId: "turn_publish_drift",
5496
- prompt: "/publish",
5497
- history: history([
5498
- { role: "user", text: "Añade la nueva oferta de octubre a la landing de conductores", createdAt: 1 },
5499
- { role: "assistant", text: "Hecho: la oferta ya está en la landing.", createdAt: 2 },
5500
- { role: "user", text: "/publish", createdAt: 3 },
5501
- ]),
5502
- }, activeControls());
5503
- const options = queryInputs[0]?.options;
5504
- if (!options)
5505
- throw new Error("expected the publish to start one query");
5506
- const context = await contextAfterTool(options, "Bash");
5507
- expect(context).toContain("Your last line to the user was not in Spanish.");
5508
- expect(context).not.toContain("Añade la nueva oferta de octubre");
5509
- });
5510
- // BAKER-3389: a publish that reads the marketer's quoted words takes them as feedback it still owes.
5511
- it("restates the language after a publish's subagent report without quoting the marketer", async () => {
5512
- const queryInputs = [];
5513
- const executor = createExecutor({
5514
- queryInputs,
5515
- queryResults: [
5516
- scriptedMessages(assistantMessage("a1", "Reviso los cambios antes de publicar."), resultMessage(0, "session_publish_report")),
5517
- ],
5518
- });
5519
- await executor.execute({
5520
- threadId: "thread_publish_report",
5521
- turnId: "turn_publish_report",
5522
- prompt: "/publish",
5523
- history: history([
5524
- { role: "user", text: "Añade la nueva oferta de octubre a la landing de conductores", createdAt: 1 },
5525
- { role: "assistant", text: "Hecho: la oferta ya está en la landing.", createdAt: 2 },
5526
- { role: "user", text: "/publish", createdAt: 3 },
5527
- ]),
5528
- }, activeControls());
5529
- const options = queryInputs[0]?.options;
5530
- if (!options)
5531
- throw new Error("expected the publish to start one query");
5532
- const context = await contextAfterTool(options, "Agent");
5533
- expect(context).toContain("The agent's report you just read is written for you.");
5534
- expect(context).not.toContain("Añade la nueva oferta de octubre");
5535
- });
5536
- it("adds no note after Spanish lines to the marketer or a subagent's English", async () => {
5537
- 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, {
5538
- parent_tool_use_id: "toolu_agent",
5539
- }));
5540
- expect(await contextAfterTool(options, "Bash")).toBeUndefined();
5541
- });
5542
- it("adds no note after a provider error the marketer never saw", async () => {
5543
- 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."));
5544
- expect(await contextAfterTool(options, "Read")).toBeUndefined();
5545
- });
5546
- it("names the drift in a progress note Opus 5.5 returned as a thinking block", async () => {
5547
- const options = await spanishTurnAfter({
5548
- type: "assistant",
5549
- uuid: "a1",
5550
- parent_tool_use_id: null,
5551
- message: {
5552
- role: "assistant",
5553
- model: "claude-opus-5-5",
5554
- content: [
5555
- { type: "thinking", thinking: "", signature: "AAAA" },
5556
- { type: "thinking", thinking: "Found the campaign, now checking its budget.", signature: "BBBB" },
5557
- ],
5558
- stop_reason: "tool_use",
5559
- },
5560
- });
5561
- expect(await contextAfterTool(options, "Read")).toContain("Your last line to the user was not in Spanish.");
5562
- });
5563
- it("names the drift to the main thread, not to a subagent's own tool call", async () => {
5564
- const options = await spanishTurnAfter(assistantMessage("a1", "Now the definition, then a live test."));
5565
- expect(await contextAfterTool(options, "Read", { agent_id: "agent_1" })).toBeUndefined();
5566
- expect(await contextAfterTool(options, "Read")).toContain("Your last line to the user was not in Spanish.");
5567
- expect(await contextAfterTool(options, "Read")).toBeUndefined();
5568
- });
5569
- // A subagent reports in English for the model, and the next line went out in English.
5570
- it("restates the language after every subagent's report, drift or not", async () => {
5571
- const options = await spanishTurnAfter(assistantMessage("a1", "Ahora reviso el banner de las landings."));
5572
- expect(await contextAfterTool(options, "Agent")).toContain("The agent's report you just read is written for you.");
5573
- expect(await contextAfterTool(options, "Agent")).toContain("in Spanish");
5574
- });
5575
- // The landing and creative skills start their subagents with `run_in_background: true`.
5576
- it("restates the language after a background subagent's report arrives, not when it starts", async () => {
5577
- const queryInputs = [];
5578
- const notes = [];
5579
- const executor = createExecutor({
5580
- queryInputs,
5581
- queryResults: [
5582
- {
5583
- async *[Symbol.asyncIterator]() {
5584
- await Promise.resolve();
5585
- const options = queryInputs[0]?.options;
5586
- if (!options)
5587
- throw new Error("expected the turn to start one query");
5588
- yield {
5589
- type: "assistant",
5590
- uuid: "a1",
5591
- message: {
5592
- role: "assistant",
5593
- content: [{ type: "tool_use", id: "t2", name: "Agent", input: { run_in_background: true } }],
5594
- stop_reason: "tool_use",
5595
- },
5596
- };
5597
- notes.push(await contextAfterTool(options, "Agent", { tool_input: { run_in_background: true } }));
5598
- yield {
5599
- type: "system",
5600
- subtype: "task_notification",
5601
- task_id: "task_1",
5602
- tool_use_id: "t2",
5603
- status: "completed",
5604
- output_file: "",
5605
- summary: "Built the four landings.",
5606
- uuid: "n1",
5607
- session_id: "s",
5608
- };
5609
- yield assistantMessage("a2", "Ya están las cuatro landings.");
5610
- notes.push(await contextAfterTool(options, "Read"));
5611
- yield resultMessage(0, "session_next");
5612
- },
5613
- },
5614
- ],
5615
- });
5616
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5617
- expect(notes[0]).toBeUndefined();
5618
- expect(notes[1]).toContain("The agent's report you just read is written for you.");
5619
- });
5620
- // In a dev Session the CLI asked for the PostToolUse hook of a fast `ls` before
5621
- // the bridge had read the line "Let me check the source folder before I answer."
5622
- // off the stream, so the drift was never named.
5623
- it("names a drift whose line the bridge reads off the stream after the tool already returned", async () => {
5624
- const queryInputs = [];
5625
- let context;
5626
- const executor = createExecutor({
5627
- queryInputs,
5628
- queryResults: [
5629
- {
5630
- async *[Symbol.asyncIterator]() {
5631
- await Promise.resolve();
5632
- const options = queryInputs[0]?.options;
5633
- if (!options)
5634
- throw new Error("expected the turn to start one query");
5635
- context = contextAfterTool(options, "Bash");
5636
- yield assistantMessage("a1", "Let me check the source folder before I answer.");
5637
- yield {
5638
- type: "assistant",
5639
- uuid: "a2",
5640
- message: {
5641
- role: "assistant",
5642
- content: [{ type: "tool_use", id: "t2", name: "Bash", input: { command: "ls src" } }],
5643
- stop_reason: "tool_use",
5644
- },
5645
- };
5646
- await context;
5647
- yield resultMessage(0, "session_next");
5648
- },
5649
- },
5650
- ],
5651
- });
5652
- await executor.execute({ threadId: "t", turnId: "turn_1", prompt: spanishTurn, currentSender: { name: "Fernando" } }, activeControls());
5653
- expect(await context).toContain("Your last line to the user was not in Spanish.");
5654
- });
5655
5528
  it("adds no language note to a review, which loads no skill and writes to nobody", async () => {
5656
5529
  const queryInputs = [];
5657
5530
  const executor = createExecutor({ queryInputs });