@koda-sl/baker-bridge 0.192.0-dev.119a96955 → 0.192.0-dev.50a518bbd

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 +22 -16
  2. package/dist/broker/baker-api.d.ts +7 -0
  3. package/dist/broker/baker-api.d.ts.map +1 -1
  4. package/dist/broker/baker-api.js +6 -1
  5. package/dist/broker/baker-api.js.map +1 -1
  6. package/dist/broker/credential-text.d.ts +2 -0
  7. package/dist/broker/credential-text.d.ts.map +1 -1
  8. package/dist/broker/credential-text.js.map +1 -1
  9. package/dist/broker/proxy.d.ts.map +1 -1
  10. package/dist/broker/proxy.integration.test.js +57 -2
  11. package/dist/broker/proxy.integration.test.js.map +1 -1
  12. package/dist/broker/proxy.js +97 -6
  13. package/dist/broker/proxy.js.map +1 -1
  14. package/dist/broker/usage-reporter.d.ts +9 -5
  15. package/dist/broker/usage-reporter.d.ts.map +1 -1
  16. package/dist/broker/usage-reporter.js +25 -4
  17. package/dist/broker/usage-reporter.js.map +1 -1
  18. package/dist/broker/usage-reporter.test.js +82 -3
  19. package/dist/broker/usage-reporter.test.js.map +1 -1
  20. package/dist/hono/agent.d.ts.map +1 -1
  21. package/dist/hono/agent.js +4 -1
  22. package/dist/hono/agent.js.map +1 -1
  23. package/dist/hono/bridge-job.d.ts +17 -0
  24. package/dist/hono/bridge-job.d.ts.map +1 -1
  25. package/dist/hono/bridge-job.js +53 -35
  26. package/dist/hono/bridge-job.js.map +1 -1
  27. package/dist/hono/bridge-job.test.js +132 -96
  28. package/dist/hono/bridge-job.test.js.map +1 -1
  29. package/dist/hono/connection-input.d.ts.map +1 -1
  30. package/dist/hono/connection-input.js +6 -5
  31. package/dist/hono/connection-input.js.map +1 -1
  32. package/dist/hono/progress-note.d.ts +6 -0
  33. package/dist/hono/progress-note.d.ts.map +1 -0
  34. package/dist/hono/progress-note.js +25 -0
  35. package/dist/hono/progress-note.js.map +1 -0
  36. package/dist/hono/publish-handoff.d.ts +0 -5
  37. package/dist/hono/publish-handoff.d.ts.map +1 -1
  38. package/dist/hono/publish-handoff.js +6 -18
  39. package/dist/hono/publish-handoff.js.map +1 -1
  40. package/dist/hono/scripted-publish.d.ts +19 -0
  41. package/dist/hono/scripted-publish.d.ts.map +1 -0
  42. package/dist/hono/scripted-publish.js +219 -0
  43. package/dist/hono/scripted-publish.js.map +1 -0
  44. package/dist/hono/scripted-publish.test.d.ts +2 -0
  45. package/dist/hono/scripted-publish.test.d.ts.map +1 -0
  46. package/dist/hono/scripted-publish.test.js +212 -0
  47. package/dist/hono/scripted-publish.test.js.map +1 -0
  48. package/dist/hono/skill-language.d.ts +4 -3
  49. package/dist/hono/skill-language.d.ts.map +1 -1
  50. package/dist/hono/skill-language.js +14 -5
  51. package/dist/hono/skill-language.js.map +1 -1
  52. package/dist/hono/types.d.ts +7 -0
  53. package/dist/hono/types.d.ts.map +1 -1
  54. package/package.json +1 -1
@@ -268,6 +268,7 @@ 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),
@@ -510,6 +511,49 @@ describe("BridgeJobExecutor", () => {
510
511
  },
511
512
  ]);
512
513
  });
514
+ it("previews a progress note streamed as thinking, and not the empty reasoning", async () => {
515
+ const previewed = [];
516
+ const relay = { ...recordingRelay(), previewText: (_target, delta) => previewed.push(delta) };
517
+ const executor = createExecutor({
518
+ relay,
519
+ model: "claude-opus-5-5",
520
+ queryResults: [
521
+ scriptedMessages({ type: "stream_event", event: { type: "message_start" } }, {
522
+ type: "stream_event",
523
+ event: { type: "content_block_delta", index: 0, delta: { type: "thinking_delta", thinking: "" } },
524
+ }, {
525
+ type: "stream_event",
526
+ event: {
527
+ type: "content_block_delta",
528
+ index: 1,
529
+ delta: { type: "thinking_delta", thinking: "Found the campaign; checking its budget next." },
530
+ },
531
+ }, resultMessage(0, "session_next")),
532
+ ],
533
+ });
534
+ await executor.execute({ threadId: "thread_1", turnId: "turn_1", prompt: "Check it" }, activeControls());
535
+ expect(previewed).toEqual(["Found the campaign; checking its budget next."]);
536
+ });
537
+ it("previews no thinking from a model whose thinking is reasoning, not a note", async () => {
538
+ const previewed = [];
539
+ const relay = { ...recordingRelay(), previewText: (_target, delta) => previewed.push(delta) };
540
+ const executor = createExecutor({
541
+ relay,
542
+ model: "claude-haiku-5-5",
543
+ queryResults: [
544
+ scriptedMessages({ type: "stream_event", event: { type: "message_start" } }, {
545
+ type: "stream_event",
546
+ event: {
547
+ type: "content_block_delta",
548
+ index: 0,
549
+ delta: { type: "thinking_delta", thinking: "The user wants the budget, so first I should look up" },
550
+ },
551
+ }, resultMessage(0, "session_next")),
552
+ ],
553
+ });
554
+ await executor.execute({ threadId: "thread_1", turnId: "turn_1", prompt: "Check it" }, activeControls());
555
+ expect(previewed).toEqual([]);
556
+ });
513
557
  it("previews a step with the input it streamed, not the empty one it opened with", async () => {
514
558
  const relay = recordingRelay();
515
559
  const executor = createExecutor({
@@ -1187,6 +1231,77 @@ describe("BridgeJobExecutor", () => {
1187
1231
  await chatting.execute({ threadId: "thread_chat", turnId: "turn_chat", prompt: "hello" }, activeControls());
1188
1232
  expect([afterPublish, settled]).toEqual([1, 1]);
1189
1233
  });
1234
+ // BAKER-231: a run's Auto publish started a second agent session — every
1235
+ // SessionStart probe again and a cold model turn — only to run the publish
1236
+ // skill's scripts and say "I'll publish now." to a marketer nobody asked.
1237
+ it("publishes a run Auto publish authorized without starting the agent, and settles it", async () => {
1238
+ const queryInputs = [];
1239
+ const relay = recordingRelay();
1240
+ let settled = 0;
1241
+ const executor = createExecutor({
1242
+ relay,
1243
+ queryInputs,
1244
+ settleAfterPublish: () => {
1245
+ settled += 1;
1246
+ return Promise.resolve();
1247
+ },
1248
+ scriptedPublish: () => Promise.resolve({ kind: "finished" }),
1249
+ });
1250
+ const outcome = await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, activeControls());
1251
+ expect({ queries: queryInputs.length, said: relay.assistantEvents.length, settled, kind: outcome.kind }).toEqual({
1252
+ queries: 0,
1253
+ said: 0,
1254
+ settled: 1,
1255
+ kind: "completed",
1256
+ });
1257
+ });
1258
+ // Its steps together outlast the session watchdog's idle window, though each
1259
+ // stays within its own timeout: the turn has to say it is working.
1260
+ it("holds the turn as working while the Auto publish scripts run", async () => {
1261
+ const reported = [];
1262
+ const workingDuringScripts = [];
1263
+ const executor = createExecutor({
1264
+ scriptedPublish: () => {
1265
+ workingDuringScripts.push(reported.at(-1) === true);
1266
+ return Promise.resolve({ kind: "finished" });
1267
+ },
1268
+ });
1269
+ const controls = {
1270
+ ...activeControls(),
1271
+ setWorkInFlight: (inFlight) => {
1272
+ reported.push(inFlight);
1273
+ },
1274
+ };
1275
+ await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, controls);
1276
+ expect({ workingDuringScripts, last: reported.at(-1) }).toEqual({ workingDuringScripts: [true], last: false });
1277
+ });
1278
+ it("hands an Auto publish whose scripts stopped to the agent, which publishes as it always has", async () => {
1279
+ const queryInputs = [];
1280
+ const executor = createExecutor({
1281
+ queryInputs,
1282
+ queryResults: [scriptedMessages(resultMessage(0.3, "session_publish_own"))],
1283
+ scriptedPublish: () => Promise.resolve({ kind: "handOff", step: "rebase" }),
1284
+ });
1285
+ await executor.execute({ threadId: "thread_auto", turnId: "turn_auto", prompt: "/publish", autoPublish: true, history: history([]) }, activeControls());
1286
+ expect(queryInputs.map((input) => input.prompt)).toEqual(["/publish"]);
1287
+ });
1288
+ it("leaves a Publish a person pressed to the agent", async () => {
1289
+ const queryInputs = [];
1290
+ let scripted = 0;
1291
+ const executor = createExecutor({
1292
+ queryInputs,
1293
+ queryResults: [scriptedMessages(resultMessage(0.3, "session_publish_own"))],
1294
+ scriptedPublish: () => {
1295
+ scripted += 1;
1296
+ return Promise.resolve({ kind: "finished" });
1297
+ },
1298
+ });
1299
+ await executor.execute({ threadId: "thread_pressed", turnId: "turn_pressed", prompt: "/publish", history: history([]) }, activeControls());
1300
+ expect({ scripted, prompts: queryInputs.map((input) => input.prompt) }).toEqual({
1301
+ scripted: 0,
1302
+ prompts: ["/publish"],
1303
+ });
1304
+ });
1190
1305
  it("leaves the chat's session alone when a publish fails", async () => {
1191
1306
  const clearCalls = [];
1192
1307
  const executor = createExecutor({
@@ -1761,102 +1876,6 @@ describe("BridgeJobExecutor", () => {
1761
1876
  await executor.execute({ threadId: "thread_skills", turnId: "turn_skills", prompt: "Build a landing", history: history([]) }, activeControls());
1762
1877
  expect([...(queryInputs[0]?.options.skills ?? [])].sort()).toEqual(["brand-build", "docx", "landing"]);
1763
1878
  });
1764
- // Publish starts a session of its own, so everything it loads after the shared
1765
- // system prompt is written to the cache cold. It ran only Bash, Edit and Read in
1766
- // 52 production publishes: the other skills' listing and the company profile
1767
- // cost ~6k tokens there and were never used.
1768
- it("starts a publish told its language with only the publish skill and without the company profile", async () => {
1769
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-context-"));
1770
- await writeFile(join(workspace, "CLAUDE.md"), "# Project Instructions\n\n## Client Context\n\nOne client per repo. Everything known about them:\n\n@COMPANY.md\n\n## Rules\n\nStage, don't ask.\n");
1771
- for (const skill of ["landing", "publish", "docx"]) {
1772
- await mkdir(join(workspace, ".claude", "skills", skill), { recursive: true });
1773
- }
1774
- projectRootMock.value = workspace;
1775
- const queryInputs = [];
1776
- const executor = createExecutor({
1777
- queryInputs,
1778
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_context"))],
1779
- });
1780
- await executor.execute({
1781
- threadId: "thread_publish_context",
1782
- turnId: "turn_publish_context",
1783
- prompt: "/publish",
1784
- history: history([
1785
- {
1786
- role: "user",
1787
- text: "Crea una landing para la campaña de otoño con el formulario de contacto",
1788
- createdAt: 1,
1789
- },
1790
- ]),
1791
- }, activeControls());
1792
- const options = queryInputs[0]?.options;
1793
- expect(options.skills).toEqual(["publish"]);
1794
- expect(options.settings).toMatchObject({
1795
- claudeMdExcludes: [join(workspace, "CLAUDE.md"), join(instructionsDirMock.value, "CLAUDE.md")],
1796
- });
1797
- });
1798
- // A publish may edit a landing to get verify green, and the scaffold's hooks
1799
- // then tell it to spawn `visual-check`; a publish that denied it would be told
1800
- // to make a call it is sure to have refused.
1801
- it("leaves the workspace's own subagents spawnable in a publish", async () => {
1802
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-agents-"));
1803
- await mkdir(join(workspace, ".claude", "agents"), { recursive: true });
1804
- await writeFile(join(workspace, ".claude", "agents", "visual-check.md"), "---\nname: visual-check\ndescription: Looks at a page.\n---\n\nLook.\n");
1805
- projectRootMock.value = workspace;
1806
- const queryInputs = [];
1807
- const executor = createExecutor({
1808
- queryInputs,
1809
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_agents"))],
1810
- });
1811
- await executor.execute({ threadId: "thread_publish_agents", turnId: "turn_publish_agents", prompt: "/publish", history: history([]) }, activeControls());
1812
- expect(queryInputs[0]?.options.disallowedTools).not.toContain("Agent(visual-check)");
1813
- });
1814
- it("resumes a publish that outgrew its window with the same skills and without the company profile", async () => {
1815
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-resume-context-"));
1816
- await writeFile(join(workspace, "CLAUDE.md"), "# Project Instructions\n\n## Client Context\n\nOne client per repo. Everything known about them:\n\n@COMPANY.md\n\n## Rules\n\nStage, don't ask.\n");
1817
- for (const skill of ["landing", "publish", "docx"]) {
1818
- await mkdir(join(workspace, ".claude", "skills", skill), { recursive: true });
1819
- }
1820
- projectRootMock.value = workspace;
1821
- const queryInputs = [];
1822
- const executor = createExecutor({
1823
- queryInputs,
1824
- queryResults: [
1825
- contextOverflowQuery({ type: "system", subtype: "init", session_id: "session_publish_resume_live" }, assistantMessage("assistant_publish_resume", "Squashing your work…", "session_publish_resume_live")),
1826
- scriptedMessages(resultMessage(0.4, "session_publish_resume_live")),
1827
- ],
1828
- });
1829
- await executor.execute({
1830
- threadId: "thread_publish_resume_context",
1831
- turnId: "turn_publish_resume_context",
1832
- prompt: "/publish",
1833
- history: history([
1834
- {
1835
- role: "user",
1836
- text: "Crea una landing para la campaña de otoño con el formulario de contacto",
1837
- createdAt: 1,
1838
- },
1839
- ]),
1840
- }, activeControls());
1841
- const resumed = queryInputs[1]?.options;
1842
- expect(resumed.resume).toBe("session_publish_resume_live");
1843
- expect(resumed.skills).toEqual(["publish"]);
1844
- expect(resumed.settings).toMatchObject({
1845
- claudeMdExcludes: [join(workspace, "CLAUDE.md"), join(instructionsDirMock.value, "CLAUDE.md")],
1846
- });
1847
- });
1848
- it("keeps the company profile for a publish Baker could not tell its language", async () => {
1849
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-profile-"));
1850
- await writeFile(join(workspace, "CLAUDE.md"), "# Project Instructions\n\n## Client Context\n\nOne client per repo. Everything known about them:\n\n@COMPANY.md\n\n## Rules\n\nStage, don't ask.\n");
1851
- projectRootMock.value = workspace;
1852
- const queryInputs = [];
1853
- const executor = createExecutor({
1854
- queryInputs,
1855
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_profile"))],
1856
- });
1857
- await executor.execute({ threadId: "thread_publish_profile", turnId: "turn_publish_profile", prompt: "/publish", history: history([]) }, activeControls());
1858
- expect(queryInputs[0]?.options.settings).toMatchObject({ claudeMdExcludes: [join(workspace, "CLAUDE.md")] });
1859
- });
1860
1879
  it("keeps a typed skill command as the leading token so the SDK runs the skill", async () => {
1861
1880
  const workspace = await mkdtemp(join(tmpdir(), "baker-job-skill-command-"));
1862
1881
  await mkdir(join(workspace, ".claude", "skills", "audit-google-ads-account"), { recursive: true });
@@ -5596,6 +5615,23 @@ describe("BridgeJobExecutor review mode", () => {
5596
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."));
5597
5616
  expect(await contextAfterTool(options, "Read")).toBeUndefined();
5598
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
+ });
5599
5635
  it("names the drift to the main thread, not to a subagent's own tool call", async () => {
5600
5636
  const options = await spanishTurnAfter(assistantMessage("a1", "Now the definition, then a live test."));
5601
5637
  expect(await contextAfterTool(options, "Read", { agent_id: "agent_1" })).toBeUndefined();