Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
feat(agents): set_main_thread lets a bot set or clear its own main thread
AdityaUmalec7cee3fc0fc5
diff --git a/server/activity.ts b/server/activity.tsindex 16f598c786..b3d225d071 100644--- a/server/activity.ts+++ b/server/activity.ts@@ -87,6 +87,7 @@ const TEAM_ACTION_KEYS: Record<string, string> = {attach_file: "activity.tool.team.attachFile",close_thread: "activity.tool.team.closeThread",rename_thread: "activity.tool.team.renameThread",+ set_main_thread: "activity.tool.team.setMainThread",coordinate_bots: "activity.tool.team.coordinateBots",create_bot: "activity.tool.team.createBot",create_room: "activity.tool.team.createRoom",diff --git a/server/agent-tool-policy.test.ts b/server/agent-tool-policy.test.tsindex be4fef3e8c..e797c3f099 100644--- a/server/agent-tool-policy.test.ts+++ b/server/agent-tool-policy.test.ts@@ -32,7 +32,7 @@ describe("built-in agent tool read policy", () => {});it.each([- "shared_computer", "ask_bot", "delegate_bot", "check_delegation", "wait_delegation", "start_thread", "close_thread", "rename_thread", "post_to_room",+ "shared_computer", "ask_bot", "delegate_bot", "check_delegation", "wait_delegation", "start_thread", "close_thread", "rename_thread", "set_main_thread", "post_to_room",// These post into the chat: never read-only."attach_file", "show_widget", "update_widget", "show_html", "update_html","create_bot", "request_credential", "request_sign_in", "memory_update", "trigger", "delete_trigger", "create_trigger",diff --git a/server/direct-coordination.e2e.test.ts b/server/direct-coordination.e2e.test.tsindex 74d82fe25d..1d67394ac1 100644--- a/server/direct-coordination.e2e.test.ts+++ b/server/direct-coordination.e2e.test.ts@@ -550,6 +550,30 @@ it("lets a bot rename only the thread it is working in", () => fixture(async f =expect(renamed.title).not.toBe(before);}), 45_000);+it("lets a bot make one of its own threads its main thread, never a teammate's", () => fixture(async f => {+ const mainOf = async (botId: string) => (await f.api("/api/bots")).bots.find((bot: any) => bot.id === botId).mainThreadId;+ const leadMain = await mainOf(f.lead.id);+ const daily = (await f.api(`/api/bots/${f.chief.id}/tasks`, { title: "Daily brief 25 Nov" })).task.threadId;+ expect(await mainOf(f.chief.id)).not.toBe(daily);+ f.plan[f.chief.id] = {+ steps: [+ { tool: "set_main_thread", arguments: { thread_id: f.lead.activeTaskId }, expectError: true },+ { tool: "set_main_thread", arguments: { thread_id: daily } },+ ],+ reply: "Today's brief is the main thread",+ };+ f.save();+ await f.cli("send", "--bot", f.chief.id, "--task", f.chief.activeTaskId, "--text", "Make today's brief thread your main thread.");+ expect((await f.wait()).status).toBe("settled");+ const steps = f.evidence().at(-1).evidence.filter((entry: any) => entry.step?.tool === "set_main_thread");+ expect(steps).toHaveLength(2);+ expect(steps[0].response.result.isError).toBe(true);+ expect(steps[1].response.result.isError).toBeFalsy();+ expect(steps[1].response.result.content[0].text).toContain("#Daily brief 25 Nov is now your main thread");+ expect(await mainOf(f.chief.id)).toBe(daily);+ expect(await mainOf(f.lead.id)).toBe(leadMain);+}), 45_000);+it("does not treat self-opened work or an abandoned human branch as new human authority", () => fixture(async f => {await f.api("/api/config", { threads: { maxConcurrentPerBot: 1 } }, "PUT");const room = (await f.cli("new-channel", "--name", "Updates", "--members", f.chief.id, "--section", "Leadership")).channel;diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.tsindex 32a604bf67..e1c6884c12 100644--- a/server/drivers/agents-call.ts+++ b/server/drivers/agents-call.ts@@ -21,7 +21,7 @@ import { callResearchTool, RESEARCH_TOOL_NAMES } from "./agents-research-tools.timport { callHelperTool, HELPER_TOOL_NAMES } from "./agents-helper-tools.ts";import { callWhatChangedTool, WHAT_CHANGED_TOOL } from "./agents-what-changed-tool.ts";import { callUsageLimitsTool, USAGE_LIMITS_TOOL } from "./agents-usage-tool.ts";-import { callThreadPostTool, THREAD_POST_TOOL } from "./agents-thread-post-tool.ts"; import { callListThreadsTool, closedThreadText, LIST_THREADS_TOOL } from "./agents-list-threads-tool.ts"; import { callRenameThreadTool, RENAME_THREAD_TOOL } from "./agents-thread-title-tool.ts"; import { callWorkflowTool, WORKFLOW_TOOL_NAMES } from "./agents-workflow-tool.ts";+import { callThreadPostTool, THREAD_POST_TOOL } from "./agents-thread-post-tool.ts"; import { callListThreadsTool, closedThreadText, LIST_THREADS_TOOL } from "./agents-list-threads-tool.ts"; import { callSetMainThreadTool, SET_MAIN_THREAD_TOOL } from "./agents-main-thread-tool.ts"; import { callRenameThreadTool, RENAME_THREAD_TOOL } from "./agents-thread-title-tool.ts"; import { callWorkflowTool, WORKFLOW_TOOL_NAMES } from "./agents-workflow-tool.ts";import { callWaitTool, WAIT_TOOL_NAMES } from "./agents-wait-tools.ts"; import { callCheckBackTool, CHECK_BACK_TOOL_NAMES } from "./agents-check-back-tool.ts";import { callBurstTool } from "./agents-burst-tool.ts";import { callComputerAskTool, COMPUTER_ASK_TOOL_NAMES } from "./agents-computer-ask-tool.ts";@@ -411,6 +411,7 @@ export async function callTool(called: string, input: Json, context: ToolCallCon}if (name === THREAD_POST_TOOL) return callThreadPostTool(args, context);if (name === RENAME_THREAD_TOOL) return callRenameThreadTool(args, context);+ if (name === SET_MAIN_THREAD_TOOL) return callSetMainThreadTool(args, context);if (WORKFLOW_TOOL_NAMES.has(name)) return callWorkflowTool(name, args, context);if (name === "select_computer") {if (args.surface !== undefined && (typeof args.surface !== "string" || !["auto", "cloud", "vm", "local", "browser"].includes(args.surface))) {diff --git a/server/drivers/agents-catalog-goldens/bridged.profiles.json b/server/drivers/agents-catalog-goldens/bridged.profiles.jsonindex 8b5c573b78..3a77afbb0a 100644--- a/server/drivers/agents-catalog-goldens/bridged.profiles.json+++ b/server/drivers/agents-catalog-goldens/bridged.profiles.json@@ -1,7 +1,7 @@{"default": {- "bytes": 18101,- "sha256": "4fac091dcd0b272bd485e5aeb3fb8479d3c0acfc1e414d6427b902d1a06208fa",+ "bytes": 18118,+ "sha256": "ce628f9c8713c951d4c2826476622ae160d1ca0537c5804992ec6c16f79dcca3","tools": ["tool_result_read","list_room_targets",@@ -24,8 +24,8 @@]},"voice": {- "bytes": 18882,- "sha256": "f3e3e422c74829b516e21b5278db0443508a1e00e6df2901c030fc422805b98a",+ "bytes": 18899,+ "sha256": "7e9e41f0d54ea402ee29cdcf0eb68ba76a1d620ccbbd626322cd3d5abcb2777c","tools": ["tool_result_read","list_room_targets",@@ -49,8 +49,8 @@]},"shared": {- "bytes": 18141,- "sha256": "4f84e9f587861c245b471bc9f72d8b9c019d32878bb1656a1071744a781f35c3",+ "bytes": 18158,+ "sha256": "064125c8113b7d896e016ef6ae0a272940db8cdf8ec2706f5d6da4af2640be15","tools": ["tool_result_read","list_room_targets",@@ -73,8 +73,8 @@]},"shared+voice": {- "bytes": 18922,- "sha256": "13801b3ba4dadd63fdb084ca3d3abcb00a41526162c83c461afa616025ad4bbc",+ "bytes": 18939,+ "sha256": "94e7da2e4eae14eda662ce3c0bc718dad9c5043fa71b457c76cc33d658997e8d","tools": ["tool_result_read","list_room_targets",@@ -98,8 +98,8 @@]},"skills": {- "bytes": 18128,- "sha256": "fcb45a34022a83dd82e59fcddc42ab5c02f3a3e7a3cc074249092cdc5f1b641e",+ "bytes": 18145,+ "sha256": "cbc1dd10ca3c61f271ead5b49879a6ec8a0588667465d5d7e7e42725c9a6ff5f","tools": ["tool_result_read","list_room_targets",@@ -122,8 +122,8 @@]},"skills+voice": {- "bytes": 18909,- "sha256": "4814d6ee5493cbd78cbd772ca1acb7bdd3156aae5412055cf0e0a64b66ace0d2",+ "bytes": 18926,+ "sha256": "616fcf57d6f8a71c3e68233049372077937873e3d4b83a2cc385cb3270fda7d3","tools": ["tool_result_read","list_room_targets",@@ -147,8 +147,8 @@]},"skills+shared": {- "bytes": 18168,- "sha256": "8667307bad98f3fd329764303f5a1d3999d2089237c9d1be32d0c27e50c21d36",+ "bytes": 18185,+ "sha256": "d24c8a77b6e7aec6103b6ccd6eba14248e1378abdf1fdba7b3b75dd9c3f32344","tools": ["tool_result_read","list_room_targets",@@ -171,8 +171,8 @@]},"skills+shared+voice": {- "bytes": 18949,- "sha256": "cb2fb79bf1a40b3477f5ee5a7a9fd71c4df8e5e86477c6f9980859a5b9f91367",+ "bytes": 18966,+ "sha256": "e2f2ed5502d4bc9f6a9c5da2ca137d92da1108b8b1620aae2ca589838f4f59e4","tools": ["tool_result_read","list_room_targets",@@ -196,8 +196,8 @@]},"non-chief": {- "bytes": 17984,- "sha256": "559d805114b408f95a4ad47d7b8f046d8dd3dd782934e4a62f8d7c4c3f6dcb5f",+ "bytes": 18001,+ "sha256": "a448f6a0d1add84b89120445b1651abec8aab71a804a8f1d73c4140aeb8a759c","tools": ["tool_result_read","list_room_targets",@@ -220,8 +220,8 @@]},"voice+non-chief": {- "bytes": 18765,- "sha256": "70a5ad428af06aee25998b6945d9d51663e7f0a70bdb4a88da5e4b06194a71b7",+ "bytes": 18782,+ "sha256": "c716cdb10770f6838ee727f3b040ac3513bf4746d04e12f37720a6c15fa62dba","tools": ["tool_result_read","list_room_targets",@@ -245,8 +245,8 @@]},"shared+non-chief": {- "bytes": 18024,- "sha256": "6ae606c50d6e23cacb066fe558ed1ce8d8e04e0970af8b06e036d50b47afb890",+ "bytes": 18041,+ "sha256": "4696c81c9e0813083a38946ee256db003003b8bc34e4cc0464fab480f7eeab8e","tools": ["tool_result_read","list_room_targets",@@ -269,8 +269,8 @@]},"shared+voice+non-chief": {- "bytes": 18805,- "sha256": "72902dabb0c59ae79423cd28216e89adbf2d4403341babc7dcdc36f6791a4a43",+ "bytes": 18822,+ "sha256": "56761d956d689b301cd35a657d4a3908d41e070a6b3b1ac32e08cf66a8ac0920","tools": ["tool_result_read","list_room_targets",@@ -294,8 +294,8 @@]},"skills+non-chief": {- "bytes": 18011,- "sha256": "4c45896a68e4c856bf659be5227493bd82f4602bbb8aa4b49eba8a61b95c6aa1",+ "bytes": 18028,+ "sha256": "bf5ea6e3e7cefead78b02b961f53f75be8817b47aa9a929b02ade532553b7c6d","tools": ["tool_result_read","list_room_targets",@@ -318,8 +318,8 @@]},"skills+voice+non-chief": {- "bytes": 18792,- "sha256": "441bee9932f0c5b745c2edcb2466732dafc2f94af5881bd9582970ceb906fd6a",+ "bytes": 18809,+ "sha256": "9880b2cd217e8ad0ca5c42db8a55cced07331c7e41c044c9a9d4a4f16381d105","tools": ["tool_result_read","list_room_targets",@@ -343,8 +343,8 @@]},"skills+shared+non-chief": {- "bytes": 18051,- "sha256": "eb739fe9e39cbcc57e575c8e77d94b4c47bd5000e0e5f458ef7c4902dbc6ac0b",+ "bytes": 18068,+ "sha256": "d70c0dc8443c40b304806d67a612541d2736a31e47112bfc4296cfc858671722","tools": ["tool_result_read","list_room_targets",@@ -367,8 +367,8 @@]},"skills+shared+voice+non-chief": {- "bytes": 18832,- "sha256": "c8901768fb36729c9ea53031e69587792ac9220f70f835fa8b8ab7967cb41e6f",+ "bytes": 18849,+ "sha256": "e639aaf8275532310643a5ed3fe012a896a150cbcee6b1d0a9b742824f363871","tools": ["tool_result_read","list_room_targets",@@ -392,8 +392,8 @@]},"skills+shared+voice+cloud-home": {- "bytes": 18965,- "sha256": "3a1b365b5c5ae0bc32e53bc16d34bac2686d52f847398611d81cae6a6ecebcee",+ "bytes": 18982,+ "sha256": "48c6f3c4de5f5f936aa9e5debf12a7ce8d05f9ec26211a96c30865c8cccf70f8","tools": ["tool_result_read","list_room_targets",@@ -417,8 +417,8 @@]},"skills+shared+voice+non-chief+cloud-home": {- "bytes": 18848,- "sha256": "6e7d143f9f485f43bc237026d77af88239187cf84d6c18ba743fc82df5c5f0a6",+ "bytes": 18865,+ "sha256": "f20fdc1aac83921028578407b08389733ebfce33a754074ae22933b5a4c9416a","tools": ["tool_result_read","list_room_targets",@@ -442,8 +442,8 @@]},"skills+shared+voice+x": {- "bytes": 19010,- "sha256": "bae9a1e91a8e6600aab35389fa4af76954537c82ce76d2d781eb60057897fe2e",+ "bytes": 19027,+ "sha256": "1c40b6bbc30565809afe2b5e05d0b5c3677fdcbadc937e938396060cc26f7364","tools": ["tool_result_read","list_room_targets",@@ -467,8 +467,8 @@]},"skills+shared+voice+x+team": {- "bytes": 19010,- "sha256": "bae9a1e91a8e6600aab35389fa4af76954537c82ce76d2d781eb60057897fe2e",+ "bytes": 19027,+ "sha256": "1c40b6bbc30565809afe2b5e05d0b5c3677fdcbadc937e938396060cc26f7364","tools": ["tool_result_read","list_room_targets",@@ -492,8 +492,8 @@]},"skills+shared+voice+x+team+images": {- "bytes": 19038,- "sha256": "fdd88d3a0912fad7bc3fa45e040ac1832288e9e985bb57fbf9f076674d4acbcb",+ "bytes": 19055,+ "sha256": "24798312b6912582690ece8b995d61c4b55a93fb2e2bc332459d20d312b0661c","tools": ["tool_result_read","list_room_targets",@@ -517,8 +517,8 @@]},"default+legacy-switches": {- "bytes": 18101,- "sha256": "4fac091dcd0b272bd485e5aeb3fb8479d3c0acfc1e414d6427b902d1a06208fa",+ "bytes": 18118,+ "sha256": "ce628f9c8713c951d4c2826476622ae160d1ca0537c5804992ec6c16f79dcca3","tools": ["tool_result_read","list_room_targets",@@ -541,8 +541,8 @@]},"default+mausbot": {- "bytes": 18153,- "sha256": "da14e71c913492d74a764f38db64554af74d7eab62cc814be86b71d01f80733c",+ "bytes": 18170,+ "sha256": "8d9fa88fc8fbcee221cbc00f7d8a5d24d5860b77e8bde2e4cad8fdc5bce5e1ac","tools": ["tool_result_read","list_room_targets",@@ -565,8 +565,8 @@]},"skills+shared+voice+mausbot": {- "bytes": 19001,- "sha256": "627c6c4f0be1f86b61487b620ead43bed156f9a1b7e873ee803a0deb12197efd",+ "bytes": 19018,+ "sha256": "151570cfdfb822fd80d12daa36cd0c70330cc22cf82a8cdd4ddfd1832d8dbd90","tools": ["tool_result_read","list_room_targets",@@ -590,8 +590,8 @@]},"default+no-computer-pick": {- "bytes": 16889,- "sha256": "d2f171db7e8a6cba79d588b4d03188aa3ea77658ff1d8d6dceae3965ce6654b6",+ "bytes": 16906,+ "sha256": "62ef6c3bf0b8337e81d49b9deeea6cc27f85635fc912d0ec4fece39a5cc7e6c4","tools": ["tool_result_read","list_room_targets",@@ -659,8 +659,8 @@]},"default+images": {- "bytes": 18129,- "sha256": "15c6811f9a0d140fbf2548cd944a22967e0f3e2eb365f8969435d5a934104ebf",+ "bytes": 18146,+ "sha256": "cee6af5bc10aef27793213b93e0984a85cfc6ad9740752350b22cc320fe8f8de","tools": ["tool_result_read","list_room_targets",@@ -683,8 +683,8 @@]},"skills+shared+voice+x+team+images+hosting": {- "bytes": 20240,- "sha256": "2745125a29a3d69a858646ec5ca4966b368a31ab5d1c688e83673751209593d6",+ "bytes": 20257,+ "sha256": "831573e7669f3eb22346475bf065207268f3b1f0de467e2a7d1c368195eb5682","tools": ["tool_result_read","list_room_targets",@@ -709,8 +709,8 @@]},"default+hosting": {- "bytes": 19303,- "sha256": "ebd39065170c0d0e62fccd5ed5c5f9e71ae614ca9b58fd7f4df8328b66dc8f36",+ "bytes": 19320,+ "sha256": "8aeaf87759da63a189b23e6a7ffeb27ca7b56f710457f599a9b8dad87b6a050a","tools": ["tool_result_read","list_room_targets",@@ -734,8 +734,8 @@]},"default+tools-off": {- "bytes": 16444,- "sha256": "1b468d3464d21ab53160b2c7c06f3d9a2f9c2202c7715f3bec41a11ac8e2a15b",+ "bytes": 16461,+ "sha256": "a1639f3b69964f52839317d7ec2b48f8f73ebe2c92944ef7ecb79e4a45585921","tools": ["tool_result_read","list_room_targets",diff --git a/server/drivers/agents-catalog-goldens/bridged.tools-list.json b/server/drivers/agents-catalog-goldens/bridged.tools-list.jsonindex 5bf1265f1c..1b741cc0ef 100644--- a/server/drivers/agents-catalog-goldens/bridged.tools-list.json+++ b/server/drivers/agents-catalog-goldens/bridged.tools-list.json@@ -562,7 +562,7 @@},{"name": "find_tool",- "description": "Find an OpenMausBot tool that is not in your tool list. Say what you want to do in a few words, or give the tool's name. Each match comes back with its description and exact input schema; run one with use_tool. Tools reached this way: list_shared_computers, shared_computer, assignment_status, usage_limits, list_threads, close_thread, rename_thread, run_workflow, workflow_edit, start_thread, burst, list_models, vm_exec, show_widget, show_html, unpublish_page, create_bot, list_team_setup, list_team_library, propose_team_setup, propose_bot_deletion, manage_room, x_search, research_search, research_endpoint, research_call, decide, extract, what_changed, edit_image, generate_image, report_bug, check_app_hosting, retry_thread, memory_log, session_search, trigger_info, trigger, delete_trigger, wait_until, list_waits, cancel_wait, check_back, propose_profile, propose_model, propose_team_memory, skills_list, skill_manage, mcp_server, app_settings.",+ "description": "Find an OpenMausBot tool that is not in your tool list. Say what you want to do in a few words, or give the tool's name. Each match comes back with its description and exact input schema; run one with use_tool. Tools reached this way: list_shared_computers, shared_computer, assignment_status, usage_limits, list_threads, close_thread, rename_thread, set_main_thread, run_workflow, workflow_edit, start_thread, burst, list_models, vm_exec, show_widget, show_html, unpublish_page, create_bot, list_team_setup, list_team_library, propose_team_setup, propose_bot_deletion, manage_room, x_search, research_search, research_endpoint, research_call, decide, extract, what_changed, edit_image, generate_image, report_bug, check_app_hosting, retry_thread, memory_log, session_search, trigger_info, trigger, delete_trigger, wait_until, list_waits, cancel_wait, check_back, propose_profile, propose_model, propose_team_memory, skills_list, skill_manage, mcp_server, app_settings.","inputSchema": {"type": "object","additionalProperties": false,diff --git a/server/drivers/agents-catalog-goldens/full.tools-list.json b/server/drivers/agents-catalog-goldens/full.tools-list.jsonindex 89e949ef89..e003eaefa2 100644--- a/server/drivers/agents-catalog-goldens/full.tools-list.json+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json@@ -365,6 +365,24 @@]}},+ {+ "name": "set_main_thread",+ "description": "Set your main thread (where your automations and briefs report) to one of your own open threads, or clear it back to the default. Only when the person or your instructions ask. Not a teammate's, room's, automation run's or archived thread.",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "thread_id": {+ "type": "string",+ "description": "From list_threads or start_thread; default: this thread."+ },+ "clear": {+ "type": "boolean",+ "description": "true: clear the choice instead."+ }+ }+ }+ },{"name": "run_workflow","description": "Run a saved Skill Burger exactly, without redoing it by hand: when the person writes /<its-name> or asks for what one does. Fill args from their request. It hands back only steps that need your judgement; do them, then call again with resume and response.",diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.jsonindex 8e1d8c7f46..7972f62263 100644--- a/server/drivers/agents-catalog-goldens/profiles.json+++ b/server/drivers/agents-catalog-goldens/profiles.json@@ -1,7 +1,7 @@{"default": {- "bytes": 61786,- "sha256": "8fef28ec7f165f998038c3a8527d918f90451428fddde67b0ae99e27b0e1da81",+ "bytes": 62323,+ "sha256": "87d6882fb150c5869f158f13202eb26e29dd95c1bfd85e8fea8b7a6b76dbf949","tools": ["tool_result_read","list_room_targets",@@ -14,6 +14,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -61,8 +62,8 @@]},"voice": {- "bytes": 62567,- "sha256": "1948ed35962d65c153fc7b70fc10edfecc1bbe9656cb4936290a24ff4d778e8e",+ "bytes": 63104,+ "sha256": "7a19846ea64f40fcf91cc78bb10efc4f1be2752a793e2c9ed524e8ec080d6d54","tools": ["tool_result_read","list_room_targets",@@ -75,6 +76,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -123,8 +125,8 @@]},"shared": {- "bytes": 64051,- "sha256": "5fee3bb2f5bd2d4bd3bab89f271d6ace0974e079123e4f170a33e14601996658",+ "bytes": 64588,+ "sha256": "5c43ffa10b648a994c182154bec1e12213c1a9733a4e6adf3c4cc1578f8bf28d","tools": ["tool_result_read","list_shared_computers",@@ -139,6 +141,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -186,8 +189,8 @@]},"shared+voice": {- "bytes": 64832,- "sha256": "039c3f04aadb4effcfd6b64d78ecd9a36af2e225510946ba209d63cbdd59b78c",+ "bytes": 65369,+ "sha256": "fba0ae5823cc1d3402d7c6c2aab0b7e9cbbb08fab5eaeee00fc2c3ba14204d2a","tools": ["tool_result_read","list_shared_computers",@@ -202,6 +205,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -250,8 +254,8 @@]},"skills": {- "bytes": 64107,- "sha256": "0ad12e265ac85405907bd6d6104c5c20f9092214825bcb2dde2c0422a669909c",+ "bytes": 64644,+ "sha256": "fd4b07f0e7e145dceac494517c1471f8d9a2f4e940406e693f8812090a0365ff","tools": ["tool_result_read","list_room_targets",@@ -264,6 +268,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -313,8 +318,8 @@]},"skills+voice": {- "bytes": 64888,- "sha256": "e84aeed89ce0cdd04ea43737a998c0b55d8db4e7d9733aa5e27bb32b47b057e0",+ "bytes": 65425,+ "sha256": "f91c67e51d44316235a684ec22aed02c3054136366358e9773d8ad93e1257f00","tools": ["tool_result_read","list_room_targets",@@ -327,6 +332,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -377,8 +383,8 @@]},"skills+shared": {- "bytes": 66372,- "sha256": "e25daba241a351ae01af6302b5145e040aa671826ea9ef385cf5009298599d0c",+ "bytes": 66909,+ "sha256": "c275753bb34e402d6330f1f24bc3a79fa5c56bbeadcf0b21235cb4f238377ca5","tools": ["tool_result_read","list_shared_computers",@@ -393,6 +399,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -442,8 +449,8 @@]},"skills+shared+voice": {- "bytes": 67153,- "sha256": "caa48eaf2e1f91de824d9557dba3fe3f9cc25ccc59f4a8ae8c1228c7ff413299",+ "bytes": 67690,+ "sha256": "2b58e5ff03cdeb465a79955999a0cf12f38fb582702cff8a66f590fae7ff3057","tools": ["tool_result_read","list_shared_computers",@@ -458,6 +465,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -508,8 +516,8 @@]},"non-chief": {- "bytes": 53238,- "sha256": "11dcbe1b650b5594fcb8dee761821311d641a4f764db68d2359a6a516b1d753b",+ "bytes": 53775,+ "sha256": "bba69b5afe74a6dcf8f8ee72627dde842dc07b9994ba2148b287691bd9962242","tools": ["tool_result_read","list_room_targets",@@ -522,6 +530,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -562,8 +571,8 @@]},"voice+non-chief": {- "bytes": 54019,- "sha256": "fd0da22b8fb6e5bbb75598c4f4a95c948ce62afd002141633d019cbc18d318ff",+ "bytes": 54556,+ "sha256": "a7d4165e510a4a043c2af337e7fea14f631db51d96750b38c88102febd960e03","tools": ["tool_result_read","list_room_targets",@@ -576,6 +585,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -617,8 +627,8 @@]},"shared+non-chief": {- "bytes": 55503,- "sha256": "00c4719ede4cffa7021c6c0b0c3b46bcc9608039273d09771ec889eb26e07509",+ "bytes": 56040,+ "sha256": "8a49c4eb65c26e38f10a4b24dd04bf96ee1900e2a8f13b00f68fdfa917d30f63","tools": ["tool_result_read","list_shared_computers",@@ -633,6 +643,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -673,8 +684,8 @@]},"shared+voice+non-chief": {- "bytes": 56284,- "sha256": "7d92acda7ea804a5d65e19091a344fb4b344281e0effc820fbaf90e7362bc876",+ "bytes": 56821,+ "sha256": "cb486b2cd3818282f96b34ba9d649e5b2496e963033033b148352a65a3f395e0","tools": ["tool_result_read","list_shared_computers",@@ -689,6 +700,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -730,8 +742,8 @@]},"skills+non-chief": {- "bytes": 55559,- "sha256": "9d0db5a1281674176c149076c3ad9588c9f92c16d090a0f6a7506a5fe2a79fd4",+ "bytes": 56096,+ "sha256": "f649b1c22e94b7711dea938524ad7f88c01af5f8ff39991a772ef7e192e8e9ad","tools": ["tool_result_read","list_room_targets",@@ -744,6 +756,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -786,8 +799,8 @@]},"skills+voice+non-chief": {- "bytes": 56340,- "sha256": "bd714c1109b6f44e247357e3b8ec3670d92e733284d4c0571f839d6f227a7cdc",+ "bytes": 56877,+ "sha256": "c60775e81e9ad088bbcb8a8bff4c13e5401bb2d4c4f3a1217b8a1659c0c6653c","tools": ["tool_result_read","list_room_targets",@@ -800,6 +813,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -843,8 +857,8 @@]},"skills+shared+non-chief": {- "bytes": 57824,- "sha256": "40fcc5d467598658d14d0bc02680aedcf87feccc5c6359dfcd3f129b7a204377",+ "bytes": 58361,+ "sha256": "e7bb6da96836f059992e5bd313ac32d909839c3fcada3515afc3abdddb49465e","tools": ["tool_result_read","list_shared_computers",@@ -859,6 +873,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -901,8 +916,8 @@]},"skills+shared+voice+non-chief": {- "bytes": 58605,- "sha256": "9ff1c2fedb12487eafbf081e52952d011fa1242e3cb1f1767d40742d9db5a50c",+ "bytes": 59142,+ "sha256": "66e12c8aa2052703b94ccca1e6890ea04b46fd577da5a8c44ef91fc5a2ba8202","tools": ["tool_result_read","list_shared_computers",@@ -917,6 +932,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -960,8 +976,8 @@]},"skills+shared+voice+cloud-home": {- "bytes": 66909,- "sha256": "aac499d8fa351c6c1b5fbd0cb7eef61f0266d61b7e733b20fb029da40276e4f0",+ "bytes": 67446,+ "sha256": "7529c8150e31a02bab3674cb72c5dd64924aa979904b0b4c47978b5d21212504","tools": ["tool_result_read","list_shared_computers",@@ -976,6 +992,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1026,8 +1043,8 @@]},"skills+shared+voice+non-chief+cloud-home": {- "bytes": 58361,- "sha256": "ad318559aa2da3aa0a99ea8cdc203cdbf7dabfe6959872d601d1ef972c6b29e8",+ "bytes": 58898,+ "sha256": "6c5e2b1fa5d09ccb6b5f9280ac4aa25d61097d6c7921fcaa3132570337e11848","tools": ["tool_result_read","list_shared_computers",@@ -1042,6 +1059,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1085,8 +1103,8 @@]},"skills+shared+voice+x": {- "bytes": 70992,- "sha256": "62150dcc25e64723a1134bd24c7369b500a2c15d9d3250fb61f3ba6a50c1d42f",+ "bytes": 71529,+ "sha256": "a677404e0d6aeda64dcf9c2dc6886dc4036da85dfdf11af4ff8bb164498fea5f","tools": ["tool_result_read","list_shared_computers",@@ -1101,6 +1119,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1155,8 +1174,8 @@]},"skills+shared+voice+x+team": {- "bytes": 70992,- "sha256": "62150dcc25e64723a1134bd24c7369b500a2c15d9d3250fb61f3ba6a50c1d42f",+ "bytes": 71529,+ "sha256": "a677404e0d6aeda64dcf9c2dc6886dc4036da85dfdf11af4ff8bb164498fea5f","tools": ["tool_result_read","list_shared_computers",@@ -1171,6 +1190,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1225,8 +1245,8 @@]},"skills+shared+voice+x+team+images": {- "bytes": 72939,- "sha256": "1be4ad6cd3468c16fec6620a13cb13e7f5f812714312eac507d574866f08fcbf",+ "bytes": 73476,+ "sha256": "a51d586d5859f1ad2f60400258e049fbc4ab4d5e3d699b950569d5c3a5e3c4d9","tools": ["tool_result_read","list_shared_computers",@@ -1241,6 +1261,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1297,8 +1318,8 @@]},"default+legacy-switches": {- "bytes": 61786,- "sha256": "8fef28ec7f165f998038c3a8527d918f90451428fddde67b0ae99e27b0e1da81",+ "bytes": 62323,+ "sha256": "87d6882fb150c5869f158f13202eb26e29dd95c1bfd85e8fea8b7a6b76dbf949","tools": ["tool_result_read","list_room_targets",@@ -1311,6 +1332,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1358,8 +1380,8 @@]},"default+mausbot": {- "bytes": 62437,- "sha256": "e71818d3b029d88915f275d033efd65824bf856f10a42d416d70cb72deca109a",+ "bytes": 62974,+ "sha256": "a596e76529177e327b34025663edce9ef7d5f7cbc8d8b20e8de847bdd8ef7963","tools": ["tool_result_read","list_room_targets",@@ -1372,6 +1394,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1421,8 +1444,8 @@]},"skills+shared+voice+mausbot": {- "bytes": 67804,- "sha256": "cbc3d1a39e3f96cf3bcadc25091882f1380143ba2e3489678f8eb9eeb53e1b73",+ "bytes": 68341,+ "sha256": "0a46c85bf09acb2e29fc0ef8fb83383b47ab32cddae0fb8714368d33691e1f06","tools": ["tool_result_read","list_shared_computers",@@ -1437,6 +1460,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1489,8 +1513,8 @@]},"default+no-computer-pick": {- "bytes": 60574,- "sha256": "caea065b9d1c1136843b9af9e3262b0d1cb2e7577a7a73ce1ab1868e8fdae7b9",+ "bytes": 61111,+ "sha256": "11bb12373f54b5abee175005349d898cfa90ee21f3e32acda48f275bce119734","tools": ["tool_result_read","list_room_targets",@@ -1502,6 +1526,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1650,8 +1675,8 @@]},"default+images": {- "bytes": 63733,- "sha256": "55363deedcadebbfe935019cd4ffddb73fd9fa21bcc84eb4387e4fa106f8cbcd",+ "bytes": 64270,+ "sha256": "7378051b52449f37cbfadffc313983755b3b76cb89bf7426c7f5d25beae6a499","tools": ["tool_result_read","list_room_targets",@@ -1664,6 +1689,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1713,8 +1739,8 @@]},"skills+shared+voice+x+team+images+hosting": {- "bytes": 74802,- "sha256": "9b730076edcabd4b5b2a1faaa4a17fb89e1e1b627bb519a7d27acf934abd20b4",+ "bytes": 75339,+ "sha256": "bb276af9d330efa87f164cd515f4d3a4c42f2d86f2fd34a38dd99ab65e86452a","tools": ["tool_result_read","list_shared_computers",@@ -1729,6 +1755,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1787,8 +1814,8 @@]},"default+hosting": {- "bytes": 63649,- "sha256": "08f24e6b0483ffbe58c4b106a223d42df13a00e2765457e988eb5a2ea8c64e13",+ "bytes": 64186,+ "sha256": "e55c38b43eea7ebaf7bf642588af0a5ec5a14f1a5772724e85fea2715f239083","tools": ["tool_result_read","list_room_targets",@@ -1801,6 +1828,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",@@ -1850,8 +1878,8 @@]},"default+tools-off": {- "bytes": 57469,- "sha256": "1ff600e1d65c11cae40425671f6e35324a78c7eb7b8f74663ed8633c1ef03f6e",+ "bytes": 58006,+ "sha256": "7d8d22dd97dcce536346a75bc641184ec314d2d30b138924f04caa0562d7eb09","tools": ["tool_result_read","list_room_targets",@@ -1864,6 +1892,7 @@"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",diff --git a/server/drivers/agents-catalog-wire.test.ts b/server/drivers/agents-catalog-wire.test.tsindex 50db91e134..2d92d6c358 100644--- a/server/drivers/agents-catalog-wire.test.ts+++ b/server/drivers/agents-catalog-wire.test.ts@@ -354,7 +354,7 @@ describe("agents proxy tools/list golden", () => {const names = (name: string) => toolsOf(wires[name]!).map((tool) => tool.name);expect(names("default+no-computer-pick")).toEqual(names("default").filter((tool) => tool !== "select_computer"));for (const name of ["default", "non-chief"]) {- expect(names(`${name}+room`), name).toEqual(names(name).filter((tool) => !["select_computer", "wait_until", "list_waits", "cancel_wait", "check_back", "burst", "rename_thread"].includes(tool)));+ expect(names(`${name}+room`), name).toEqual(names(name).filter((tool) => !["select_computer", "wait_until", "list_waits", "cancel_wait", "check_back", "burst", "rename_thread", "set_main_thread"].includes(tool)));}for (const [name, profile] of Object.entries(PROFILES)) {expect(names(name).includes("select_computer"), name).toBe(profile.env.OMB_COMPUTER_SELECTION === "1");diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.tsindex 22ee6c2741..1f9f41a387 100644--- a/server/drivers/agents-catalog.ts+++ b/server/drivers/agents-catalog.ts@@ -12,6 +12,7 @@ import { USAGE_LIMITS_TOOL_DEFINITION } from "./agents-usage-tool.ts";import { APP_SETTINGS_TOOL_DEFINITION } from "./agents-app-settings-tool.ts";import { THREAD_POST_TOOL_DEFINITION } from "./agents-thread-post-tool.ts";import { RENAME_THREAD_TOOL_DEFINITION } from "./agents-thread-title-tool.ts";+import { SET_MAIN_THREAD_TOOL_DEFINITION } from "./agents-main-thread-tool.ts";import { WORKFLOW_TOOL_DEFINITIONS, WORKFLOW_TOOL_NAMES } from "./agents-workflow-tool.ts";import { WAIT_TOOL_DEFINITIONS, WAIT_TOOL_NAMES } from "./agents-wait-tools.ts"; import { CHECK_BACK_TOOL_DEFINITIONS, CHECK_BACK_TOOL_NAMES } from "./agents-check-back-tool.ts";import { COMPUTER_ASK_TOOL_DEFINITIONS, COMPUTER_ASK_TOOL_NAMES } from "./agents-computer-ask-tool.ts";@@ -254,6 +255,7 @@ const TOOL_DEFINITIONS = [},},RENAME_THREAD_TOOL_DEFINITION,+ SET_MAIN_THREAD_TOOL_DEFINITION,...WORKFLOW_TOOL_DEFINITIONS,{name: "start_thread",@@ -820,7 +822,7 @@ const WATCHER_TOOL_NAMES = new Set(["create_options_card"]);const LOCAL_VM_TOOL_NAMES = new Set(["vm_exec"]);/** Refused in a room's thread (routes/waits.ts), and list_waits, since a room holds no wait. */-const ROOM_REFUSED_TOOL_NAMES = new Set([...WAIT_TOOL_NAMES, ...CHECK_BACK_TOOL_NAMES, "burst", "rename_thread"]);+const ROOM_REFUSED_TOOL_NAMES = new Set([...WAIT_TOOL_NAMES, ...CHECK_BACK_TOOL_NAMES, "burst", "rename_thread", "set_main_thread"]);const CLOUD_HOME_SURFACE = {type: "string", enum: ["auto", "cloud", "browser"],description: "auto = suitable configured computer, cloud = the bot's cloud computer, browser = built-in browser. Omit to list. This server runs in the cloud: the user's own computer and a Local VM are not places here.",diff --git a/server/drivers/agents-claude-defer.test.ts b/server/drivers/agents-claude-defer.test.tsindex 7ed196ad99..8a12abef12 100644--- a/server/drivers/agents-claude-defer.test.ts+++ b/server/drivers/agents-claude-defer.test.ts@@ -23,9 +23,9 @@ const DEFER = { [DEFER_TOOLS_ENV]: "1" };/** Bytes Claude Code sends up front for the agents server when the budget was last set; each may move at most 2%. */const UP_FRONT_BASELINE: Record<string, { whole: number; deferred: number }> = {- default: { whole: 3896, deferred: 1331 },- specialist: { whole: 1495, deferred: 1159 },- fullest: { whole: 3896, deferred: 1692 },+ default: { whole: 3896, deferred: 1360 },+ specialist: { whole: 1495, deferred: 1188 },+ fullest: { whole: 3896, deferred: 1721 },};const listed = (env: Record<string, string>) => agentsToolList(env).listed as Array<{ name: string; description: string; inputSchema: unknown; _meta?: Record<string, unknown> }>;diff --git a/server/drivers/agents-main-thread-tool.ts b/server/drivers/agents-main-thread-tool.tsnew file mode 100644index 0000000000..02c41fa5c8--- /dev/null+++ b/server/drivers/agents-main-thread-tool.ts@@ -0,0 +1,33 @@+// The agents catalog's set_main_thread tool: a bot sets or clears its own main thread, as the person's "Set as main+// thread" does. The internal route (server/routes/internal-threads.ts) only takes the bot's own open conversations.+import type { Json } from "./agents-client.ts";+import type { ToolCallContext, ToolCallResult } from "./agents-call.ts";++export const SET_MAIN_THREAD_TOOL = "set_main_thread";++export async function callSetMainThreadTool(args: Json, context: ToolCallContext): Promise<ToolCallResult> {+ const clear = args.clear === true;+ const threadId = typeof args.thread_id === "string" ? args.thread_id.trim() : "";+ if (clear && threadId) return { text: "set_main_thread takes thread_id or clear, not both.", isError: true };+ const r = await context.client.api("/api/internal/main-thread", {+ method: "POST",+ body: JSON.stringify({ fromBotId: context.botId, fromThreadId: context.threadId, ...(clear ? { clear: true } : threadId ? { mainThreadId: threadId } : {}) }),+ });+ if (r.error) return { text: `Couldn't change your main thread: ${String(r.error)}`, isError: true };+ if (r.cleared) return { text: "Cleared your main thread choice: the app picks your main thread on its own again." };+ return { text: `#${String(r.title)} is now your main thread.` };+}++export const SET_MAIN_THREAD_TOOL_DEFINITION = {+ name: SET_MAIN_THREAD_TOOL,+ description:+ "Set your main thread (where your automations and briefs report) to one of your own open threads, or clear it back to the default. Only when the person or your instructions ask. Not a teammate's, room's, automation run's or archived thread.",+ inputSchema: {+ type: "object",+ additionalProperties: false,+ properties: {+ thread_id: { type: "string", description: "From list_threads or start_thread; default: this thread." },+ clear: { type: "boolean", description: "true: clear the choice instead." },+ },+ },+};diff --git a/server/drivers/agents-proxy.test.ts b/server/drivers/agents-proxy.test.tsindex 1f8f0b00e3..cbeb7cc4de 100644--- a/server/drivers/agents-proxy.test.ts+++ b/server/drivers/agents-proxy.test.ts@@ -654,6 +654,7 @@ describe("agents-proxy MCP surface", () => {"list_threads","close_thread","rename_thread",+ "set_main_thread","run_workflow","workflow_edit","start_thread",diff --git a/server/drivers/agents-tool-groups.ts b/server/drivers/agents-tool-groups.tsindex 00dd56f3cc..dc76d2a5ea 100644--- a/server/drivers/agents-tool-groups.ts+++ b/server/drivers/agents-tool-groups.ts@@ -28,7 +28,7 @@ export const OWN_SWITCH_TOOLS: Readonly<Record<"memory" | "research", ReadonlySeexport const CORE_TOOLS: ReadonlySet<string> = new Set(["tool_result_read", "list_shared_computers", "shared_computer", "ask_for_computer", "list_room_targets", "coordinate_bots","assignment_status", "list_bots", "usage_limits", "list_rooms", "select_computer", "reset_cloud_computer", "list_threads",- "close_thread", "rename_thread", "start_thread", "burst", "list_models", "vm_exec", "attach_file", "show_widget", "create_options_card",+ "close_thread", "rename_thread", "set_main_thread", "start_thread", "burst", "list_models", "vm_exec", "attach_file", "show_widget", "create_options_card","post_to_room", "post_to_thread", "create_bot", "list_team_setup", "list_team_library", "propose_team_setup","propose_bot_deletion", "manage_room", "request_credential", "request_sign_in", "fill_login", "send_voice_note", "decide","extract", "what_changed", "message_person", "report_bug", "retry_thread", "session_search", "trigger_info", "trigger", "delete_trigger",diff --git a/server/index.ts b/server/index.tsindex dcd5b026b2..3653131072 100644--- a/server/index.ts+++ b/server/index.ts@@ -13024,7 +13024,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {}if (await dispatchRoutes([createInternalThreadRoutes({store, coordinator, from: internalSender, fromThreadId: internalCapability.threadId,- ownsThread: (botId, threadId) => Boolean(connectorThread(botId, threadId)),+ ownsThread: (botId, threadId) => Boolean(connectorThread(botId, threadId)), mainThreadTasks,shown: (id) => !proactive.fence.confines(id) && !botApiThread(id) && (CLOUD_TEAM ? teamHost.readableFrom(internalCapability.threadId)(id) : cloudLendingView(internalCapability) ? cloudOwnerOnlyThread(id) : true),threadBusy, queuedThreadPosition, queuedReason: queuedStatus, readBody: readInternalBody,}), createToolTimingRoute(usageTrace, internalCapability.threadId)], { req, res, url, path, method, auth, json, readBody })) return;diff --git a/server/main-thread.ts b/server/main-thread.tsindex 702efbc980..d9110163d6 100644--- a/server/main-thread.ts+++ b/server/main-thread.ts@@ -30,6 +30,14 @@ export function mainThread(tasks: readonly MainThreadCandidate[], chosenId?: strreturn oldestThread(tasks.filter((task) => !task.openedBy && open(task))) ?? oldestThread(tasks);}+/** What saving `choice` as a bot's main thread writes: null clears it; a thread id must be one of `tasks` that can be+ * main (not an automation run, not archived), else null comes back and nothing is saved. */+export function mainThreadChoicePatch(tasks: readonly MainThreadCandidate[], choice: string | null): { mainThreadChoice: string | undefined; mainThreadKept: undefined } | null {+ if (choice === null) return { mainThreadChoice: undefined, mainThreadKept: undefined };+ const chosen = tasks.find((task) => task.threadId === choice);+ return chosen && open(chosen) ? { mainThreadChoice: chosen.threadId, mainThreadKept: undefined } : null;+}+/** The thread to save as a bot's choice so its main thread stays put: nothing while the saved one is open. A bot that* never had one keeps the thread it showed until now: the open one a person last wrote in, else the selected one, else* the oldest open one. One whose saved thread was archived or deleted moves to the oldest open conversation a persondiff --git a/server/routes/bot-patch.ts b/server/routes/bot-patch.tsindex 86c33ad33a..491039b3d8 100644--- a/server/routes/bot-patch.ts+++ b/server/routes/bot-patch.ts@@ -28,6 +28,7 @@ import type { hostedModelPolicy } from "../hosted-models.ts";import { heldFrom } from "../host/room-reads.ts";import { unreadTargetTask } from "../task-record.ts";import { MAX_MCP_SERVERS, mcpServerNameError } from "../mcp-registry.ts";+import { mainThreadChoicePatch } from "../main-thread.ts";import type { MemoryUpkeep } from "../memory-upkeep.ts";import { phoneAppsFor } from "../phones/access.ts";import { profileSnapshot } from "../profile-revision.ts";@@ -243,11 +244,9 @@ export function createBotPatchRoutes(deps: BotPatchRouteDeps): RouteHandler {// null clears the choice; otherwise an open conversation the main-thread resolver may pick, never a routine run or archived.// Same 400 for unknown and ineligible ids, so a private thread's existence is not revealed.if (body.mainThreadChoice !== undefined) {- const chosen = typeof body.mainThreadChoice === "string" ? deps.mainThreadTasks(m[1]).find((task) => task.threadId === body.mainThreadChoice) : null;- patch.mainThreadKept = undefined;- if (body.mainThreadChoice === null) patch.mainThreadChoice = undefined;- else if (chosen && !chosen.routineRunId && chosen.archivedAt === undefined) patch.mainThreadChoice = chosen.threadId;- else return json(res, 400, { error: "mainThreadChoice must be one of this bot's conversations" });+ const choice = body.mainThreadChoice === null || typeof body.mainThreadChoice === "string" ? mainThreadChoicePatch(deps.mainThreadTasks(m[1]), body.mainThreadChoice) : null;+ if (!choice) return json(res, 400, { error: "mainThreadChoice must be one of this bot's conversations" });+ Object.assign(patch, choice);}if (section !== undefined) patch.section = section ?? undefined;if (body.chiefOfStaff === false) patch.chiefOfStaff = false;diff --git a/server/routes/internal-threads.test.ts b/server/routes/internal-threads.test.tsindex d6a2a1e01d..e34b2011e2 100644--- a/server/routes/internal-threads.test.ts+++ b/server/routes/internal-threads.test.ts@@ -22,7 +22,7 @@ async function listThreads(from: BotRecord) {const route = createInternalThreadRoutes({store: { bot: (id: string) => [lead, ops].find((bot) => bot.id === id), bots: [lead, ops], tasks: (id: string) => tasks[id] ?? [] } as never,coordinator: { awaitingAnswer: () => false, parkedDirect: () => undefined, activeDirect: (threadId: string) => threadId === "t-ops-new" ? handoff : undefined, active: () => [handoff] } as never,- from, fromThreadId: "t-own", ownsThread: () => true, shown: () => true,+ from, fromThreadId: "t-own", ownsThread: () => true, shown: () => true, mainThreadTasks: () => [],threadBusy: (_bot, threadId) => threadId === "t-ops-busy", queuedThreadPosition: () => null,queuedReason: (node, showTitle) => `${node.id} waits${showTitle ? " (titles)" : ""}`,readBody: async () => ({}),@@ -60,7 +60,7 @@ describe("list_threads past the first 100", () => {const route = createInternalThreadRoutes({store: { bot: () => undefined, bots: [lead], tasks: (id: string) => id === lead.id ? many : [] } as never,coordinator: { awaitingAnswer: () => false, parkedDirect: () => undefined, activeDirect: () => undefined, active: () => [] } as never,- from: lead, fromThreadId: "t-own", ownsThread: () => true, shown: () => true,+ from: lead, fromThreadId: "t-own", ownsThread: () => true, shown: () => true, mainThreadTasks: () => [],threadBusy: () => false, queuedThreadPosition: () => null, queuedReason: () => "", readBody: async () => ({}),});let body: { threads: Array<{ threadId: string }>; total: number; page: number; pageSize: number } | undefined;@@ -92,7 +92,7 @@ describe("rename_thread on the conversation the turn speaks in", () => {renameTask: (botId: string, threadId: string, title: string) => { renamed.push([botId, threadId, title]); return { ...own, title }; },} as never,coordinator: {} as never,- from: lead, fromThreadId: "t-own", ownsThread: () => opts.owns ?? true, shown: () => true,+ from: lead, fromThreadId: "t-own", ownsThread: () => opts.owns ?? true, shown: () => true, mainThreadTasks: () => [],threadBusy: () => false, queuedThreadPosition: () => null, queuedReason: () => "",readBody: async () => body,});@@ -124,3 +124,56 @@ describe("rename_thread on the conversation the turn speaks in", () => {}});});++describe("set_main_thread on the sender's own threads", () => {+ const leadTasks = [+ task("t-own", "Today"),+ task("t-yesterday", "Yesterday"),+ { ...task("t-run", "Daily brief run"), routineRunId: "run-1" } as TaskRecord,+ { ...task("t-archived", "Old"), archivedAt: 3 } as TaskRecord,+ ];+ async function setMain(body: unknown, opts: { owns?: boolean } = {}) {+ const patched: Array<[string, Partial<BotRecord>]> = [];+ const route = createInternalThreadRoutes({+ store: {+ bot: () => lead, bots: [lead, ops], tasks: (id: string) => id === lead.id ? leadTasks : tasks[id] ?? [],+ taskByThread: (botId: string, threadId: string) => (botId === lead.id ? leadTasks : tasks[botId] ?? []).find((one) => one.threadId === threadId),+ patchBot: (botId: string, patch: Partial<BotRecord>) => { patched.push([botId, patch]); return lead; },+ } as never,+ coordinator: {} as never,+ from: lead, fromThreadId: "t-own", ownsThread: () => opts.owns ?? true, shown: () => true,+ mainThreadTasks: (botId: string) => botId === lead.id ? leadTasks : [],+ threadBusy: () => false, queuedThreadPosition: () => null, queuedReason: () => "",+ readBody: async () => body,+ });+ let status = 0;+ let answer: Record<string, unknown> | undefined;+ await route({ res: {}, path: "/api/internal/main-thread", method: "POST", json: (_res: unknown, code: number, value: never) => { status = code; answer = value; } } as never);+ return { status, answer: answer!, patched };+ }++ it("makes the thread it speaks in, or one of its own it names, its main thread", async () => {+ const here = await setMain({});+ expect(here.status).toBe(200);+ expect(here.patched).toEqual([["bot-lead", { mainThreadChoice: "t-own", mainThreadKept: undefined }]]);+ const named = await setMain({ mainThreadId: "t-yesterday" });+ expect(named.answer).toMatchObject({ threadId: "t-yesterday", title: "Yesterday" });+ expect(named.patched).toEqual([["bot-lead", { mainThreadChoice: "t-yesterday", mainThreadKept: undefined }]]);+ });++ it("clears its own choice so the main thread goes back to the default", async () => {+ const cleared = await setMain({ clear: true });+ expect(cleared.status).toBe(200);+ expect(cleared.patched).toEqual([["bot-lead", { mainThreadChoice: undefined, mainThreadKept: undefined }]]);+ });++ it("refuses a teammate's thread, an automation run, an archived thread and a sender that does not own its conversation", async () => {+ const teammate = await setMain({ mainThreadId: "t-ops-busy" });+ expect(teammate.status).toBe(404);+ expect((await setMain({ mainThreadId: "t-run" })).status).toBe(409);+ expect((await setMain({ mainThreadId: "t-archived" })).status).toBe(409);+ expect((await setMain({}, { owns: false })).status).toBe(403);+ expect((await setMain({ clear: true }, { owns: false })).patched).toEqual([]);+ for (const threadId of ["t-ops-busy", "t-run", "t-archived"]) expect((await setMain({ mainThreadId: threadId })).patched).toEqual([]);+ });+});diff --git a/server/routes/internal-threads.ts b/server/routes/internal-threads.tsindex 5057aee34a..75e96d2d05 100644--- a/server/routes/internal-threads.ts+++ b/server/routes/internal-threads.ts@@ -1,5 +1,6 @@import { chiefTidies } from "../chief-of-staff.ts";import type { Coordinator, HandoffView } from "../coordinator.ts";+import { mainThreadChoicePatch } from "../main-thread.ts";import { reachablePeers } from "../peer-roster.ts";import { threadTitleFrom, type BotRecord, type Store, type TaskRecord } from "../store.ts";import { PASS, type RouteHandler } from "./table.ts";@@ -22,11 +23,13 @@ interface ThreadRow {/** Only dispatch inside the internal capability gate: `from` and `fromThreadId` come from the caller's capability. */export function createInternalThreadRoutes(deps: {- store: Pick<Store, "bot" | "bots" | "tasks" | "taskByThread" | "appendMessage" | "patchTask" | "setTaskClosedBy" | "renameTask">;+ store: Pick<Store, "bot" | "bots" | "tasks" | "taskByThread" | "appendMessage" | "patchTask" | "setTaskClosedBy" | "renameTask" | "patchBot">;coordinator: Pick<Coordinator, "awaitingAnswer" | "parkedDirect" | "activeDirect" | "active">;from: BotRecord;fromThreadId: string;ownsThread(botId: string, threadId: string): boolean;+ /** The bot's threads that may be its main thread (server/index.ts mainThreadTasks), as the person's own choice uses. */+ mainThreadTasks(botId: string): TaskRecord[];/** A turn that may use the lent Mac sees only owner-only conversations: a title is words too. */shown(threadId: string): boolean;threadBusy(botId: string, threadId: string): boolean;@@ -108,6 +111,30 @@ export function createInternalThreadRoutes(deps: {if (!renamed) return json(res, 404, { error: "this conversation is not one of your own threads" });return json(res, 200, { renamed: true, title: renamed.title, previous });}+ // set_main_thread: a bot sets or clears its own main thread, as the person's "Set as main thread" does, under the same+ // rule (an open conversation, never an automation run or an archived one). Never a teammate's.+ if (method === "POST" && path === "/api/internal/main-thread") {+ if (!deps.ownsThread(from.id, fromThreadId)) {+ return json(res, 403, { error: "source conversation does not belong to sender" });+ }+ const body = await deps.readBody() as { mainThreadId?: unknown; clear?: unknown } | null;+ if (body?.clear === true) {+ store.patchBot(from.id, mainThreadChoicePatch([], null)!);+ return json(res, 200, { cleared: true });+ }+ const threadId = typeof body?.mainThreadId === "string" && body.mainThreadId.trim() ? body.mainThreadId.trim() : fromThreadId;+ const task = store.taskByThread(from.id, threadId);+ if (!task || !deps.shown(threadId)) {+ return json(res, 404, { error: "that is not one of your own threads (a room's thread or a teammate's cannot be your main thread) — call list_threads" });+ }+ const choice = mainThreadChoicePatch(deps.mainThreadTasks(from.id), threadId);+ if (!choice) {+ const why = task.routineRunId ? "it holds an automation run" : task.archivedAt !== undefined ? "it is archived" : "it is not one of your conversations that can be main";+ return json(res, 409, { error: `#${task.title} cannot be your main thread: ${why}` });+ }+ store.patchBot(from.id, choice);+ return json(res, 200, { threadId, title: task.title });+ }// close_thread folds a thread, never deletes it (a person's confirmed action), and never while it runs.const closeMatch = method === "POST" ? path.match(/^\/api\/internal\/threads\/([\w-]+)\/close$/) : null;if (!closeMatch) return PASS;diff --git a/src/locales/en.json b/src/locales/en.jsonindex 0efb4ccdd6..98544bd403 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -9592,6 +9592,7 @@"activity.tool.team.attachFile": "Attach file","activity.tool.team.closeThread": "Close thread","activity.tool.team.renameThread": "Rename thread",+ "activity.tool.team.setMainThread": "Set main thread","activity.tool.team.coordinateBots": "Coordinate bots","activity.tool.team.createBot": "Create bot","activity.tool.team.createRoom": "Create room",diff --git a/src/locales/it.json b/src/locales/it.jsonindex 57bf1dd39b..abc231ff0a 100644--- a/src/locales/it.json+++ b/src/locales/it.json@@ -9550,6 +9550,7 @@"activity.tool.team.attachFile": "Allega file","activity.tool.team.closeThread": "Chiudi conversazione","activity.tool.team.renameThread": "Rinomina conversazione",+ "activity.tool.team.setMainThread": "Imposta thread principale","activity.tool.team.coordinateBots": "Coordina bot","activity.tool.team.createBot": "Crea bot","activity.tool.team.createRoom": "Crea chat di gruppo",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 213b6cf5a9..80c1e37ed9 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -9513,6 +9513,7 @@"activity.tool.team.attachFile": "Anexar arquivo","activity.tool.team.closeThread": "Fechar conversa","activity.tool.team.renameThread": "Renomear conversa",+ "activity.tool.team.setMainThread": "Definir conversa principal","activity.tool.team.coordinateBots": "Coordenar bots","activity.tool.team.createBot": "Criar bot","activity.tool.team.createRoom": "Criar grupo",