@koda-sl/baker-bridge 0.190.0-dev.dc95305f2 → 0.191.0-dev.9e99fc957

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 (32) hide show
  1. package/README.md +8 -12
  2. package/dist/hono/bridge-job.d.ts.map +1 -1
  3. package/dist/hono/bridge-job.js +9 -37
  4. package/dist/hono/bridge-job.js.map +1 -1
  5. package/dist/hono/bridge-job.test.js +236 -96
  6. package/dist/hono/bridge-job.test.js.map +1 -1
  7. package/dist/hono/credential-scrub.d.ts +6 -1
  8. package/dist/hono/credential-scrub.d.ts.map +1 -1
  9. package/dist/hono/credential-scrub.js +18 -13
  10. package/dist/hono/credential-scrub.js.map +1 -1
  11. package/dist/hono/credential-scrub.test.js +8 -0
  12. package/dist/hono/credential-scrub.test.js.map +1 -1
  13. package/dist/hono/publish-handoff.d.ts +0 -5
  14. package/dist/hono/publish-handoff.d.ts.map +1 -1
  15. package/dist/hono/publish-handoff.js +6 -18
  16. package/dist/hono/publish-handoff.js.map +1 -1
  17. package/dist/hono/tool-result-budget.d.ts +7 -0
  18. package/dist/hono/tool-result-budget.d.ts.map +1 -0
  19. package/dist/hono/tool-result-budget.js +180 -0
  20. package/dist/hono/tool-result-budget.js.map +1 -0
  21. package/dist/hono/workspace-instructions.d.ts +7 -0
  22. package/dist/hono/workspace-instructions.d.ts.map +1 -1
  23. package/dist/hono/workspace-instructions.js +104 -3
  24. package/dist/hono/workspace-instructions.js.map +1 -1
  25. package/dist/hono/workspace-instructions.test.js +57 -1
  26. package/dist/hono/workspace-instructions.test.js.map +1 -1
  27. package/dist/review/digest.d.ts.map +1 -1
  28. package/dist/review/digest.js +7 -1
  29. package/dist/review/digest.js.map +1 -1
  30. package/dist/review/digest.test.js +18 -0
  31. package/dist/review/digest.test.js.map +1 -1
  32. package/package.json +1 -1
@@ -1587,6 +1587,56 @@ describe("BridgeJobExecutor", () => {
1587
1587
  expect(options.env?.CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD).toBe("1");
1588
1588
  expect(await readFile(join(instructionsDirMock.value, "CLAUDE.md"), "utf8")).toBe(`@${join(workspace, "COMPANY.md")}\n`);
1589
1589
  });
1590
+ // On resume the CLI re-sends, whole, every instruction file that differs from
1591
+ // the copy already in the conversation. The scaffold's CLAUDE.md rides in the
1592
+ // system prompt instead, so a scaffold sync that rewords a paragraph of it
1593
+ // must leave every file the CLI loads as it was.
1594
+ it("re-sends no instruction file when a paragraph of the workspace's CLAUDE.md changes between turns", async () => {
1595
+ const workspace = await mkdtemp(join(tmpdir(), "baker-job-claude-md-edit-"));
1596
+ const claudeMd = (rules) => `# Project Instructions\n\n## Client Context\n\nOne client per repo. Everything known about them:\n\n@COMPANY.md\n\n## Rules\n\n${rules}\n`;
1597
+ await writeFile(join(workspace, "CLAUDE.md"), claudeMd("Stage, don't ask."));
1598
+ await writeFile(join(workspace, "COMPANY.md"), "# Company\n\n## Offer\n\nHeat pumps.\n\n## Tone\n\nWarm.\n");
1599
+ projectRootMock.value = workspace;
1600
+ const loadedFiles = async (options) => {
1601
+ const loaded = new Map();
1602
+ const load = async (file) => {
1603
+ const content = await readFile(file, "utf8");
1604
+ loaded.set(file, content);
1605
+ for (const [, imported] of content.matchAll(/^@(\/\S+)$/gm)) {
1606
+ if (imported && !loaded.has(imported)) {
1607
+ await load(imported);
1608
+ }
1609
+ }
1610
+ };
1611
+ const excluded = options.settings?.claudeMdExcludes ?? [];
1612
+ const rootClaudeMd = join(workspace, "CLAUDE.md");
1613
+ if (!excluded.includes(rootClaudeMd)) {
1614
+ await load(rootClaudeMd);
1615
+ }
1616
+ for (const dir of options.additionalDirectories ?? []) {
1617
+ await load(join(dir, "CLAUDE.md"));
1618
+ }
1619
+ return loaded;
1620
+ };
1621
+ const turn = async (turnId) => {
1622
+ const queryInputs = [];
1623
+ await createExecutor({
1624
+ queryInputs,
1625
+ queryResults: [scriptedMessages(resultMessage(0, "session_claude_md_edit"))],
1626
+ }).execute({ threadId: "thread_claude_md_edit", turnId, prompt: "Build a landing", history: history([]) }, activeControls());
1627
+ const options = queryInputs[0]?.options;
1628
+ if (!options) {
1629
+ throw new Error("the turn ran no query");
1630
+ }
1631
+ return loadedFiles(options);
1632
+ };
1633
+ const before = await turn("turn_claude_md_1");
1634
+ await writeFile(join(workspace, "CLAUDE.md"), claudeMd("Stage every change, and never ask for approval mid-turn."));
1635
+ const after = await turn("turn_claude_md_2");
1636
+ const resent = [...after].filter(([path, content]) => before.get(path) !== content);
1637
+ expect(after.size).toBeGreaterThan(1);
1638
+ expect(resent).toEqual([]);
1639
+ });
1590
1640
  // A task's system prompt is its own, and it replaces the one the shared
1591
1641
  // instructions would ride on: the task keeps loading CLAUDE.md as memory.
1592
1642
  it("leaves a task's workspace instructions in CLAUDE.md, under the task's own system prompt", async () => {
@@ -1711,102 +1761,6 @@ describe("BridgeJobExecutor", () => {
1711
1761
  await executor.execute({ threadId: "thread_skills", turnId: "turn_skills", prompt: "Build a landing", history: history([]) }, activeControls());
1712
1762
  expect([...(queryInputs[0]?.options.skills ?? [])].sort()).toEqual(["brand-build", "docx", "landing"]);
1713
1763
  });
1714
- // Publish starts a session of its own, so everything it loads after the shared
1715
- // system prompt is written to the cache cold. It ran only Bash, Edit and Read in
1716
- // 52 production publishes: the other skills' listing and the company profile
1717
- // cost ~6k tokens there and were never used.
1718
- it("starts a publish told its language with only the publish skill and without the company profile", async () => {
1719
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-context-"));
1720
- 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");
1721
- for (const skill of ["landing", "publish", "docx"]) {
1722
- await mkdir(join(workspace, ".claude", "skills", skill), { recursive: true });
1723
- }
1724
- projectRootMock.value = workspace;
1725
- const queryInputs = [];
1726
- const executor = createExecutor({
1727
- queryInputs,
1728
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_context"))],
1729
- });
1730
- await executor.execute({
1731
- threadId: "thread_publish_context",
1732
- turnId: "turn_publish_context",
1733
- prompt: "/publish",
1734
- history: history([
1735
- {
1736
- role: "user",
1737
- text: "Crea una landing para la campaña de otoño con el formulario de contacto",
1738
- createdAt: 1,
1739
- },
1740
- ]),
1741
- }, activeControls());
1742
- const options = queryInputs[0]?.options;
1743
- expect(options.skills).toEqual(["publish"]);
1744
- expect(options.settings).toMatchObject({
1745
- claudeMdExcludes: [join(workspace, "CLAUDE.md"), join(instructionsDirMock.value, "CLAUDE.md")],
1746
- });
1747
- });
1748
- // A publish may edit a landing to get verify green, and the scaffold's hooks
1749
- // then tell it to spawn `visual-check`; a publish that denied it would be told
1750
- // to make a call it is sure to have refused.
1751
- it("leaves the workspace's own subagents spawnable in a publish", async () => {
1752
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-agents-"));
1753
- await mkdir(join(workspace, ".claude", "agents"), { recursive: true });
1754
- await writeFile(join(workspace, ".claude", "agents", "visual-check.md"), "---\nname: visual-check\ndescription: Looks at a page.\n---\n\nLook.\n");
1755
- projectRootMock.value = workspace;
1756
- const queryInputs = [];
1757
- const executor = createExecutor({
1758
- queryInputs,
1759
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_agents"))],
1760
- });
1761
- await executor.execute({ threadId: "thread_publish_agents", turnId: "turn_publish_agents", prompt: "/publish", history: history([]) }, activeControls());
1762
- expect(queryInputs[0]?.options.disallowedTools).not.toContain("Agent(visual-check)");
1763
- });
1764
- it("resumes a publish that outgrew its window with the same skills and without the company profile", async () => {
1765
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-resume-context-"));
1766
- 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");
1767
- for (const skill of ["landing", "publish", "docx"]) {
1768
- await mkdir(join(workspace, ".claude", "skills", skill), { recursive: true });
1769
- }
1770
- projectRootMock.value = workspace;
1771
- const queryInputs = [];
1772
- const executor = createExecutor({
1773
- queryInputs,
1774
- queryResults: [
1775
- contextOverflowQuery({ type: "system", subtype: "init", session_id: "session_publish_resume_live" }, assistantMessage("assistant_publish_resume", "Squashing your work…", "session_publish_resume_live")),
1776
- scriptedMessages(resultMessage(0.4, "session_publish_resume_live")),
1777
- ],
1778
- });
1779
- await executor.execute({
1780
- threadId: "thread_publish_resume_context",
1781
- turnId: "turn_publish_resume_context",
1782
- prompt: "/publish",
1783
- history: history([
1784
- {
1785
- role: "user",
1786
- text: "Crea una landing para la campaña de otoño con el formulario de contacto",
1787
- createdAt: 1,
1788
- },
1789
- ]),
1790
- }, activeControls());
1791
- const resumed = queryInputs[1]?.options;
1792
- expect(resumed.resume).toBe("session_publish_resume_live");
1793
- expect(resumed.skills).toEqual(["publish"]);
1794
- expect(resumed.settings).toMatchObject({
1795
- claudeMdExcludes: [join(workspace, "CLAUDE.md"), join(instructionsDirMock.value, "CLAUDE.md")],
1796
- });
1797
- });
1798
- it("keeps the company profile for a publish Baker could not tell its language", async () => {
1799
- const workspace = await mkdtemp(join(tmpdir(), "baker-job-publish-profile-"));
1800
- 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");
1801
- projectRootMock.value = workspace;
1802
- const queryInputs = [];
1803
- const executor = createExecutor({
1804
- queryInputs,
1805
- queryResults: [scriptedMessages(resultMessage(0, "session_publish_profile"))],
1806
- });
1807
- await executor.execute({ threadId: "thread_publish_profile", turnId: "turn_publish_profile", prompt: "/publish", history: history([]) }, activeControls());
1808
- expect(queryInputs[0]?.options.settings).toMatchObject({ claudeMdExcludes: [join(workspace, "CLAUDE.md")] });
1809
- });
1810
1764
  it("keeps a typed skill command as the leading token so the SDK runs the skill", async () => {
1811
1765
  const workspace = await mkdtemp(join(tmpdir(), "baker-job-skill-command-"));
1812
1766
  await mkdir(join(workspace, ".claude", "skills", "audit-google-ads-account"), { recursive: true });
@@ -5931,4 +5885,190 @@ describe("agentFeature", () => {
5931
5885
  expect(agentFeature({})).toBe("agent.turn");
5932
5886
  });
5933
5887
  });
5888
+ describe("BridgeJobExecutor connected-app results", () => {
5889
+ /** What the model reads after `toolName` returns `response`: the last rewrite any PostToolUse hook made, as the SDK keeps it. */
5890
+ async function toolOutputTheModelReads(toolName, response, caller = {}, job = {}) {
5891
+ const queryInputs = [];
5892
+ const executor = createExecutor({ queryInputs });
5893
+ await executor.execute({ threadId: "t", turnId: "turn_1", prompt: "Read the thread", ...job }, activeControls());
5894
+ const options = queryInputs[0]?.options;
5895
+ if (!options)
5896
+ throw new Error("expected the turn to start one query");
5897
+ const toolUseId = `toolu_${Math.random().toString(36).slice(2)}`;
5898
+ const input = {
5899
+ hook_event_name: "PostToolUse",
5900
+ tool_name: toolName,
5901
+ tool_input: {},
5902
+ tool_response: response,
5903
+ tool_use_id: toolUseId,
5904
+ session_id: "s",
5905
+ transcript_path: "",
5906
+ cwd: "/",
5907
+ ...caller,
5908
+ };
5909
+ const hooks = (options.hooks?.PostToolUse ?? [])
5910
+ .filter((matcher) => matcher.matcher === undefined || new RegExp(`^(?:${matcher.matcher})$`).test(toolName))
5911
+ .flatMap((matcher) => matcher.hooks);
5912
+ let output = response;
5913
+ for (const hook of hooks) {
5914
+ const result = await hook(input, toolUseId, { signal: new AbortController().signal });
5915
+ const specific = "hookSpecificOutput" in result ? result.hookSpecificOutput : undefined;
5916
+ if (specific?.hookEventName === "PostToolUse" && specific.updatedToolOutput !== undefined) {
5917
+ output = specific.updatedToolOutput;
5918
+ }
5919
+ }
5920
+ return output;
5921
+ }
5922
+ function textTheModelReads(output) {
5923
+ return Array.isArray(output) ? output.map((block) => block.text ?? "").join("") : "";
5924
+ }
5925
+ /** The file the shortened answer points the agent to. */
5926
+ function savedAnswer(text) {
5927
+ const path = /\/\S+\.json/.exec(text)?.[0];
5928
+ if (!path)
5929
+ throw new Error(`expected the answer to name the file it was saved to: ${text.slice(0, 300)}`);
5930
+ return readFileSync(path, "utf8");
5931
+ }
5932
+ const searchResponse = () => JSON.parse(readFileSync(new URL("./composio-search-tools.test.json", import.meta.url), "utf8"));
5933
+ // BAKER-1855: one Slack tool search answered 17 KB of plans, pitfalls and schemas.
5934
+ it("hands the agent a connected app's tool search as an outline under 2 KB, the whole answer saved for it to read", async () => {
5935
+ const response = searchResponse();
5936
+ const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", response);
5937
+ const text = textTheModelReads(output);
5938
+ expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
5939
+ for (const slug of ["SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION", "SLACK_SEARCH_MESSAGES"]) {
5940
+ expect(text).toContain(slug);
5941
+ }
5942
+ expect(savedAnswer(text)).toBe(response[0]?.text);
5943
+ });
5944
+ it.each([
5945
+ ["a chat turn", {}],
5946
+ ["a scheduled agent's run", { unattended: true }],
5947
+ ["a Session review", { review: { threadIds: [], chatFacts: { chatId: "chat_1" } } }],
5948
+ [
5949
+ "a task",
5950
+ { unattended: true, builder: { runId: "run_1", title: "Summer landing", outputSchema: { type: "object" } } },
5951
+ ],
5952
+ ])("shortens a connected app's tool search in %s", async (_mode, job) => {
5953
+ const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", searchResponse(), {}, job);
5954
+ const text = textTheModelReads(output);
5955
+ expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
5956
+ expect(text).toContain("SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION");
5957
+ });
5958
+ it("shortens a connected app's tool search a subagent ran, as it does the Session's own", async () => {
5959
+ const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_SEARCH_TOOLS", searchResponse(), {
5960
+ agent_id: "agent_1",
5961
+ agent_type: "general-purpose",
5962
+ });
5963
+ expect(Buffer.byteLength(textTheModelReads(output))).toBeLessThanOrEqual(2048);
5964
+ });
5965
+ // BAKER-3344: a Slack send answered 16 KB, Slack's own rendering of the message the agent had just written.
5966
+ it("hands the agent a connected Slack send as an outline that keeps its receipt, under 2 KB", async () => {
5967
+ const written = "Daily summary: spend is up 12% week on week, and two ad sets are over budget.";
5968
+ const richText = Array.from({ length: 40 }, (_, line) => ({
5969
+ type: "rich_text_section",
5970
+ elements: [{ type: "text", text: `${written} (${line})`, style: { bold: line % 2 === 0 } }],
5971
+ }));
5972
+ const send = {
5973
+ successful: true,
5974
+ data: {
5975
+ results: [
5976
+ {
5977
+ response: {
5978
+ successful: true,
5979
+ data: {
5980
+ ok: true,
5981
+ channel: "C05CUQ8B7QB",
5982
+ ts: "1794645585.123456",
5983
+ message: {
5984
+ app_id: "A09DP8VR3DF",
5985
+ bot_id: "B09DP8VR3DF",
5986
+ type: "message",
5987
+ text: written,
5988
+ ts: "1794645585.123456",
5989
+ blocks: [{ type: "rich_text", block_id: "LZ3J/V", elements: richText }],
5990
+ },
5991
+ },
5992
+ },
5993
+ tool_slug: "SLACK_SEND_MESSAGE",
5994
+ index: 0,
5995
+ },
5996
+ ],
5997
+ total_count: 1,
5998
+ success_count: 1,
5999
+ error_count: 0,
6000
+ },
6001
+ error: null,
6002
+ log_id: "log_test",
6003
+ };
6004
+ const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", [
6005
+ { type: "text", text: JSON.stringify(send) },
6006
+ ]);
6007
+ const text = textTheModelReads(output);
6008
+ expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
6009
+ for (const receipt of ['"ok":true', '"channel":"C05CUQ8B7QB"', '"ts":"1794645585.123456"']) {
6010
+ expect(text).toContain(receipt);
6011
+ }
6012
+ expect(JSON.parse(savedAnswer(text))).toEqual(send);
6013
+ });
6014
+ it("shortens a large answer from any connected tool, not only the managed apps", async () => {
6015
+ const deals = Array.from({ length: 200 }, (_, n) => ({
6016
+ id: `deal_${n}`,
6017
+ name: `Spring renewal ${n}`,
6018
+ notes: "Call back. ".repeat(20),
6019
+ }));
6020
+ const output = await toolOutputTheModelReads("mcp__acme_crm__list_deals", [
6021
+ { type: "text", text: JSON.stringify({ deals, total: 200 }) },
6022
+ ]);
6023
+ const text = textTheModelReads(output);
6024
+ expect(Buffer.byteLength(text)).toBeLessThanOrEqual(2048);
6025
+ expect(text).toContain("deal_0");
6026
+ expect(JSON.parse(savedAnswer(text)).deals).toHaveLength(200);
6027
+ });
6028
+ it("keeps a provider's error message whole while shortening the rest of the answer", async () => {
6029
+ const providerMessage = `Slack API error: channel_not_found. ${"The channel may be archived or the app is not a member of it. ".repeat(12)}`;
6030
+ const batch = {
6031
+ successful: false,
6032
+ data: {
6033
+ results: [
6034
+ {
6035
+ response: {
6036
+ successful: true,
6037
+ data: {
6038
+ messages: Array.from({ length: 80 }, (_, n) => ({ ts: `${n}`, text: "Thread reply ".repeat(10) })),
6039
+ },
6040
+ },
6041
+ tool_slug: "SLACK_FETCH_MESSAGE_THREAD_FROM_A_CONVERSATION",
6042
+ index: 0,
6043
+ },
6044
+ { error: providerMessage, tool_slug: "SLACK_SEND_MESSAGE", index: 1 },
6045
+ ],
6046
+ total_count: 2,
6047
+ success_count: 1,
6048
+ error_count: 1,
6049
+ },
6050
+ error: "1 out of 2 tools failed",
6051
+ };
6052
+ const output = await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", [
6053
+ { type: "text", text: JSON.stringify(batch) },
6054
+ ]);
6055
+ const text = textTheModelReads(output);
6056
+ expect(Buffer.byteLength(text)).toBeLessThan(Buffer.byteLength(JSON.stringify(batch)) / 4);
6057
+ expect(text).toContain(JSON.stringify(providerMessage));
6058
+ expect(text).toContain('"error":"1 out of 2 tools failed"');
6059
+ });
6060
+ it("passes a short answer through as it came", async () => {
6061
+ const failure = [
6062
+ {
6063
+ type: "text",
6064
+ text: JSON.stringify({
6065
+ successful: false,
6066
+ data: { results: [{ error: "channel_not_found", tool_slug: "SLACK_SEND_MESSAGE", index: 0 }] },
6067
+ error: "1 out of 1 tools failed",
6068
+ }),
6069
+ },
6070
+ ];
6071
+ expect(await toolOutputTheModelReads("mcp__composio_company__COMPOSIO_MULTI_EXECUTE_TOOL", failure)).toEqual(failure);
6072
+ });
6073
+ });
5934
6074
  //# sourceMappingURL=bridge-job.test.js.map