@koda-sl/baker-bridge 0.191.0-dev.9e99fc957 → 0.192.0-dev.119a96955

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.
@@ -1761,6 +1761,102 @@ describe("BridgeJobExecutor", () => {
1761
1761
  await executor.execute({ threadId: "thread_skills", turnId: "turn_skills", prompt: "Build a landing", history: history([]) }, activeControls());
1762
1762
  expect([...(queryInputs[0]?.options.skills ?? [])].sort()).toEqual(["brand-build", "docx", "landing"]);
1763
1763
  });
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
+ });
1764
1860
  it("keeps a typed skill command as the leading token so the SDK runs the skill", async () => {
1765
1861
  const workspace = await mkdtemp(join(tmpdir(), "baker-job-skill-command-"));
1766
1862
  await mkdir(join(workspace, ".claude", "skills", "audit-google-ads-account"), { recursive: true });
@@ -5885,190 +5981,4 @@ describe("agentFeature", () => {
5885
5981
  expect(agentFeature({})).toBe("agent.turn");
5886
5982
  });
5887
5983
  });
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
- });
6074
5984
  //# sourceMappingURL=bridge-job.test.js.map