Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

feat(agents): let bots read their AI accounts' usage limits (#4175)

Milind Soniedbae381f0fa
diff --git a/docs/runtime-contract.md b/docs/runtime-contract.md
index aa8505a8f5..b36473a879 100644
--- a/docs/runtime-contract.md
+++ b/docs/runtime-contract.md
@@ -122,6 +122,7 @@ Every turn that may hand work on, whatever started it, gets the same tools:
- `coordinate_bots(bot_ids, message, reason?, rework?, thread?: "standing" | "new" | "<thread id>", reply?: "resume" | "none", consult?: true, done_when?, answers?)`. `thread: "new"` opens a new thread on the teammate, and a thread id sends to a thread the sender opened on that teammate earlier (a receipt's `threadId`, or `list_threads`), refused with where ids come from for any other, except that a Chief that manages the teammate may name a thread it did not open where the teammate's turn waits on a question card to the person (in words, not one only the person can answer): the message answers it for the person, the turn runs on with `@<Chief> answered for the person: …`, the card names the Chief, and the person's own answer still replaces it. The Chief's turns list such questions (bot, thread id, question). A Chief turn with no person behind it (a webhook, a routine, a guest) neither lists nor answers them, and a question in work an outside event started stays the person's; `reply: "none"` is a one-way notice that is never awaited; `consult: true` asks a question that the teammate answers from what it knows, acting on nothing, and the asker is resumed with the answer. `answers: "<assignment id>"` makes the message the answer to that teammate work's open question (parked, or a question card its turn waits on) instead of new work, whoever sends it; refused, with the reason, when that work no longer asks. A message to a teammate from the very turn that was resumed with its question answers it too. **What the bot that handed work on sends to the thread that work runs in goes into that work**, outside a room, whatever its level and whichever of its turns sends it: where the work waits on a question (parked on `NEEDS INPUT:`, or a question card its turn waits on; never a sign-in or another card only the person can act on) the message answers it, and the work runs on with `@<bot> answered: "…"` and reports once, to the turn that handed it out; where the work is running, the message is handed to that running turn (`steer`), which reads it at its next step as a person's line sent mid-turn is, and is shown in that thread as the sender's; the work's one result still comes back once. Only when the engine cannot take a message mid-turn does it run next, as new work. Work handed out in the sending turn itself stays apart: a second assignment is its own. A consultation, and a message to a room, never go into other work. A parked question waits on its own clock, which never runs out unless a host sets one (§6): it is answered, or its work is stopped.
- `assignment_status(id?)`: read-only; one assignment's status, outcome and result, or everything this conversation still waits on. External runtimes long-poll it; it never blocks a bot.
- `raise_escalation(reason)` (only with `features.chiefEscalations` on): a bot parks itself on a gate only a person can lift and says so in one line; the Chief of Staff (or the person directly, `server/escalations.ts`) is told, the turn keeps running and the tool's answer says to end it and wait.
+- `usage_limits` reads each AI account's percent used, reset time and when that was checked, read-only: no credential, address or account id, an `unknown` status for no data and `unsupported` for an AI that reports no limits. A turn sees only accounts its audience may read, and a guest-driven turn is refused.
- `list_bots`, `start_thread` (on yourself), `list_threads`, `close_thread`, `post_to_room`, `list_rooms`, the Chief tools and `retry_thread` are unchanged.
Every turn of one conversation is listed the same tools, byte for byte, so the provider's cached prompt carries over from turn to turn; what a turn may not do it is told when it calls the tool. Only what is fixed for the conversation shapes the list: `select_computer` in a direct chat whose bot may pick where it works (`OMB_COMPUTER_SELECTION`: Works on is not Off and no team computer is its own), refused with the reason on any turn but a person's own message; no `show_widget`, `show_html` or wait tools in a room (`OMB_ROOM`), since a room refuses the first two and holds no wait; `wait_until`, `list_waits` and `cancel_wait` in every direct chat, with or without a wait (with none, the last two say there is nothing to list or cancel); the skill tools wherever skill authoring is on, refused in a room to every turn but the first answer to a person's message.
diff --git a/server/agent-tool-policy.test.ts b/server/agent-tool-policy.test.ts
index a0f431093f..3481a5ea5a 100644
--- a/server/agent-tool-policy.test.ts
+++ b/server/agent-tool-policy.test.ts
@@ -16,6 +16,7 @@ describe("built-in agent tool read policy", () => {
"list_waits",
"skills_list",
"list_unread_notifications",
+ "usage_limits",
]);
for (const name of READ_ONLY_AGENT_TOOL_NAMES) {
expect(isReadOnlyAgentTool(name)).toBe(true);
diff --git a/server/agent-tool-policy.ts b/server/agent-tool-policy.ts
index d7487571e5..8db8f57167 100644
--- a/server/agent-tool-policy.ts
+++ b/server/agent-tool-policy.ts
@@ -13,6 +13,7 @@ export const READ_ONLY_AGENT_TOOL_NAMES: ReadonlySet<string> = new Set([
"list_waits",
"skills_list",
"list_unread_notifications",
+ "usage_limits",
]);
export const READ_ONLY_ANNOTATIONS = Object.freeze({
diff --git a/server/agents-turn.test.ts b/server/agents-turn.test.ts
index c748065a7e..47cdbadb16 100644
--- a/server/agents-turn.test.ts
+++ b/server/agents-turn.test.ts
@@ -60,7 +60,7 @@ describe("one conversation's agents tools", () => {
const chat = await names(CHAT), room = await names(ROOM);
expect(chat).toEqual(expect.arrayContaining(["select_computer", "wait_until", "list_waits", "cancel_wait"]));
for (const tool of ["select_computer", "wait_until", "list_waits", "cancel_wait"]) expect(room).not.toContain(tool);
- for (const tools of [chat, room]) expect(tools).toEqual(expect.arrayContaining(["skills_list", "skill_manage"]));
+ for (const tools of [chat, room]) expect(tools).toEqual(expect.arrayContaining(["skills_list", "skill_manage", "usage_limits"]));
expect(await names({ ...CHAT, host: { ...HOST, skillAuthoring: false } })).not.toContain("skill_manage");
});
diff --git a/server/drivers/agents-bridge-wire.test.ts b/server/drivers/agents-bridge-wire.test.ts
index 2a168ff78a..c53c5435d3 100644
--- a/server/drivers/agents-bridge-wire.test.ts
+++ b/server/drivers/agents-bridge-wire.test.ts
@@ -88,7 +88,7 @@ const BUDGET_BASELINE: Record<string, number> = {
"skills": 16715,
"skills+voice": 17496,
"skills+shared": 16755,
- "skills+shared+voice": 17198,
+ "skills+shared+voice": 17550,
"non-chief": 16571,
"voice+non-chief": 17352,
"shared+non-chief": 16611,
@@ -99,12 +99,12 @@ const BUDGET_BASELINE: Record<string, number> = {
"skills+shared+voice+non-chief": 17419,
"skills+shared+voice+cloud-home": 17552,
"skills+shared+voice+non-chief+cloud-home": 17417,
- "skills+shared+voice+escalations": 17216,
- "skills+shared+voice+escalations+x": 17277,
- "skills+shared+voice+escalations+x+team": 17293,
+ "skills+shared+voice+escalations": 17568,
+ "skills+shared+voice+escalations+x": 17629,
+ "skills+shared+voice+escalations+x+team": 17645,
"default+legacy-switches": 16688,
"default+mausbot": 16740,
- "skills+shared+voice+mausbot": 17250,
+ "skills+shared+voice+mausbot": 17602,
"default+no-computer-pick": 15455,
"default+room": 15415,
"non-chief+room": 15298,
diff --git a/server/drivers/agents-call.ts b/server/drivers/agents-call.ts
index ce2d3658cd..927be37a9e 100644
--- a/server/drivers/agents-call.ts
+++ b/server/drivers/agents-call.ts
@@ -14,6 +14,7 @@ import { boundedAgentResult } from "./agents-result.ts";
import { outOfBounds } from "./agents-schema.ts";
import { callResearchTool, RESEARCH_TOOL_NAMES } from "./agents-research-tools.ts";
import { callHelperTool, HELPER_TOOL_NAMES } from "./agents-helper-tools.ts";
+import { callUsageLimitsTool, USAGE_LIMITS_TOOL } from "./agents-usage-tool.ts";
import { callWaitTool, WAIT_TOOL_NAMES } from "./agents-wait-tools.ts";
import { callComputerAskTool, COMPUTER_ASK_TOOL_NAMES } from "./agents-computer-ask-tool.ts";
import { callMausBotTool, MAUSBOT_TOOL_NAMES } from "./agents-mausbot-tools.ts";
@@ -220,6 +221,7 @@ export async function callTool(called: string, input: Json, context: ToolCallCon
if (DEVS_TOOL_NAMES.has(name)) return callDevsTool(name, args, context);
if (TRIGGER_TOOL_NAMES.has(name)) return callTriggerTool(name, args, context);
if (WAIT_TOOL_NAMES.has(name)) return callWaitTool(name, args, context);
+ if (name === USAGE_LIMITS_TOOL) return callUsageLimitsTool(context);
if (COMPUTER_ASK_TOOL_NAMES.has(name)) return callComputerAskTool(args, context);
// Second lock: with sharing off the catalog already omits these tools.
if (SHARED_COMPUTER_TOOL_NAMES.has(name) && !context.sharedComputers) {
diff --git a/server/drivers/agents-catalog-goldens/bridged.profiles.json b/server/drivers/agents-catalog-goldens/bridged.profiles.json
index 8d25fda228..d91e09f91e 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": 16680,
- "sha256": "f88f407def25ac4a0559fc83459e4a0dcc0bd80a2bce2df264887d21bf0953b1",
+ "bytes": 16694,
+ "sha256": "0061f3c42dbaee63a478355f6b33af47bc1a88de052ac91a012242e128206946",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -21,8 +21,8 @@
]
},
"voice": {
- "bytes": 17461,
- "sha256": "547f7ce70cd36f523704eb86bf2d43f4367c35a96848e399a34e6e2eee7a160d",
+ "bytes": 17475,
+ "sha256": "11f9264d608aa96af9464c3e402483491e444f2342ebb6f4c460ed331e64f878",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -43,8 +43,8 @@
]
},
"shared": {
- "bytes": 16720,
- "sha256": "2d1f629115c3840e50ed2912452cd058d7e48510372aade9801c105cb315c4c8",
+ "bytes": 16734,
+ "sha256": "e39e0867251d0967e6c78db08797b966a8033fd2b5cb5070a1ac82c4c1748d79",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -64,8 +64,8 @@
]
},
"shared+voice": {
- "bytes": 17501,
- "sha256": "54929a46aa771136c0c971f509060e2d934b6654b9e80c376ed971f078a20773",
+ "bytes": 17515,
+ "sha256": "a62e7532d0e9340952c03c248eadff590e04a76874dce891456b01e3613712e1",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -86,8 +86,8 @@
]
},
"skills": {
- "bytes": 16707,
- "sha256": "29df1e65957cce7039745d41c729fd0c008ba927fc3f8220f6473bf63986e4a2",
+ "bytes": 16721,
+ "sha256": "e3eb01065018efba30d206ae84dae984295763900e5d813014daada8e1015a23",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -107,8 +107,8 @@
]
},
"skills+voice": {
- "bytes": 17488,
- "sha256": "db0773ddf5ec8a538971be3d07bd1faad2afa63c57e59a921c89bd918649d107",
+ "bytes": 17502,
+ "sha256": "5797c1be636b6f85e15c90b2ffd22387ed101575960e6a0ab60d0141f9bb42cc",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -129,8 +129,8 @@
]
},
"skills+shared": {
- "bytes": 16747,
- "sha256": "feaa05221909e7905e4e3b2f35228b9e55ddf4731a13ea5fe0f8839202b716e7",
+ "bytes": 16761,
+ "sha256": "508c5a88482f7341a98c5b5fce53f831c0ede9d9d6527fcfcaf6fb5ecb651fe2",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -150,8 +150,8 @@
]
},
"skills+shared+voice": {
- "bytes": 17528,
- "sha256": "6b42fd97c9a037d25f5ceb313ddae483b9253ac58a4a79c144e821baaede77fc",
+ "bytes": 17542,
+ "sha256": "5ccbe6a68c09234a039a3db5866d0191e08a2611d035c7b4d625b9913b34dd30",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -172,8 +172,8 @@
]
},
"non-chief": {
- "bytes": 16563,
- "sha256": "1a3bf8b006d14ba7eab9ede7f7608e776a809bfa84feac5a3957bf8a430a3d5d",
+ "bytes": 16577,
+ "sha256": "3ef1b20f2bcfe9c5bb0e7cb11f0cb0f5494e7ec2a81cde875c110a78c2177e3d",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -193,8 +193,8 @@
]
},
"voice+non-chief": {
- "bytes": 17344,
- "sha256": "2228cae2cd83a32d033a173c913e727fc28a6f7c3c64600f2843cc8930982aa2",
+ "bytes": 17358,
+ "sha256": "60e367c736872a545592f1e94bb3655335ba1a6259a76ddf03b18cc0f042665c",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -215,8 +215,8 @@
]
},
"shared+non-chief": {
- "bytes": 16603,
- "sha256": "a14f8087a50d08b594fe2e1faa8739b5125c54ec3ed74cb9390b8acc47c149fe",
+ "bytes": 16617,
+ "sha256": "dcf86af7a68d484f382c687ec2744fdd5f066cfd23b3fca6edcdebb2a1e40a05",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -236,8 +236,8 @@
]
},
"shared+voice+non-chief": {
- "bytes": 17384,
- "sha256": "951f596bdd4d6d2201ad1bcb6a22bceacab8d6cd51957193b86d026edc2f978d",
+ "bytes": 17398,
+ "sha256": "e948ef50ad63e0490d5e82da25286125bad1a169d3601b32fe80ba0c78afe06c",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -258,8 +258,8 @@
]
},
"skills+non-chief": {
- "bytes": 16590,
- "sha256": "60beb466b9e774f99a5d306b28864731488e768a061ef7af10c9bbc2de8ccb36",
+ "bytes": 16604,
+ "sha256": "554a4aa640b0b502299613f224e42bedb5dda00133e4a6eb085aa3b491698c6c",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -279,8 +279,8 @@
]
},
"skills+voice+non-chief": {
- "bytes": 17371,
- "sha256": "d79eef916781a720a0ff036319b3886a2564ffba04c88fd2e3f0bd0dc4f84ff3",
+ "bytes": 17385,
+ "sha256": "2fbbec32535024dade4643e36f7e54edc5fc8dcacf0e660bc741cfc01dae5ef1",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -301,8 +301,8 @@
]
},
"skills+shared+non-chief": {
- "bytes": 16630,
- "sha256": "41b7b05874d8fd3b0068e1c391726edef4c1f537afffecd6acdd0fb0b6b64250",
+ "bytes": 16644,
+ "sha256": "826718ff694ee3ef9a1770230290d386b0f41140a5fb0d8ef89007e7bb821b45",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -322,8 +322,8 @@
]
},
"skills+shared+voice+non-chief": {
- "bytes": 17411,
- "sha256": "65107b3b69f044f8015ae4c9fba03c13339fab072a4006a6bde8898a180e95e6",
+ "bytes": 17425,
+ "sha256": "037982c1205ce14529a31ea1d2f3a33a9027f0945c22a831e6c24a383be6b7fd",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -344,8 +344,8 @@
]
},
"skills+shared+voice+cloud-home": {
- "bytes": 17544,
- "sha256": "9c9523d7c8a423a2dbcd09e6066743819c924d8adafa2d5215a241b8e209799d",
+ "bytes": 17558,
+ "sha256": "b15f6ad3b084788a4d420fff9179ab88cbab226395d4ce05a77da125a9599dff",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -366,8 +366,8 @@
]
},
"skills+shared+voice+non-chief+cloud-home": {
- "bytes": 17427,
- "sha256": "abf0acb7153b987197923c6e96aca96418a66177f5e13b927950536a579ee700",
+ "bytes": 17441,
+ "sha256": "db0090200f185bd0943d9c7972152ffac437e8b9029a7c76a4240c9b71574cf5",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -388,8 +388,8 @@
]
},
"skills+shared+voice+escalations": {
- "bytes": 17546,
- "sha256": "887b466c01bc593364351d4e3400c3f2ff1c96516ff79e63be55a27c3bd0b7ac",
+ "bytes": 17560,
+ "sha256": "9ca1f02a4d8c5827f60db8aba4984343c107ddc1c37f198d5da3a43f7b312405",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -410,8 +410,8 @@
]
},
"skills+shared+voice+escalations+x": {
- "bytes": 17607,
- "sha256": "7a520f40c2c16dafb2eefc6a143af49f34adc4be965546ea4b3355162dc292ba",
+ "bytes": 17621,
+ "sha256": "5a858b9040de414f2c586e490f6148b0434e392f616756531b8aae5df95cdd3e",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -432,8 +432,8 @@
]
},
"skills+shared+voice+escalations+x+team": {
- "bytes": 17623,
- "sha256": "1a8876e7bd7192be70f2cea5630f0109266ad83d4c369882e73df0f419539539",
+ "bytes": 17637,
+ "sha256": "5f127524edb629d118292b21a0c50df0768d04e1cc0f257e99e9b60c7399ce19",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -454,8 +454,8 @@
]
},
"default+legacy-switches": {
- "bytes": 16680,
- "sha256": "f88f407def25ac4a0559fc83459e4a0dcc0bd80a2bce2df264887d21bf0953b1",
+ "bytes": 16694,
+ "sha256": "0061f3c42dbaee63a478355f6b33af47bc1a88de052ac91a012242e128206946",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -475,8 +475,8 @@
]
},
"default+mausbot": {
- "bytes": 16732,
- "sha256": "852a35dbbbd68fc0c244cfbc1ffe571e5c749b7e3ce7bf028db3b7cdd19b5eaa",
+ "bytes": 16746,
+ "sha256": "2c5a49d6c626bcd3ac2aa1c6eff5cb11e538284a8d84b73e17cb3258037a847b",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -496,8 +496,8 @@
]
},
"skills+shared+voice+mausbot": {
- "bytes": 17580,
- "sha256": "29f1f26ffb1eaf4a93d6e3f735613682f5a79945d76dd595ddf599e30f2fab4b",
+ "bytes": 17594,
+ "sha256": "578e32e579d95890f9e21f977b6bfa0a314ac44e3a3c7c044e06bc21ff5d4259",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -518,8 +518,8 @@
]
},
"default+no-computer-pick": {
- "bytes": 15468,
- "sha256": "49f0dfdaa628bb6c27d84631bffb3be3ba16f129ad1a105cbfee641bbef3a0f3",
+ "bytes": 15482,
+ "sha256": "5fb13a618720b1ca5421b3565ae5dabaa30a7fd4c398b9885e2058dd08d482fa",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -538,8 +538,8 @@
]
},
"default+room": {
- "bytes": 15407,
- "sha256": "b3fc5f134d1f42ec1d30fb8a663cae8093aee79261ba28498ef03260c3ae4a24",
+ "bytes": 15421,
+ "sha256": "b7571cdcc0774cb62b5df40159bc721c8409fa4fc3ddb09ca3ba50fed988c2f1",
"tools": [
"tool_result_read",
"list_room_targets",
@@ -558,8 +558,8 @@
]
},
"non-chief+room": {
- "bytes": 15290,
- "sha256": "42a9d7c9aab1461244b1862a2d6c0c310e5de339fb14914e830a76a3da25bbd3",
+ "bytes": 15304,
+ "sha256": "11dd3a286189b3e8f47e4c378a4d22befecd069263d60caaf725bdfa98179371",
"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.json
index 24d0e184f7..b31e1ee972 100644
--- a/server/drivers/agents-catalog-goldens/bridged.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/bridged.tools-list.json
@@ -375,7 +375,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, raise_escalation, list_threads, close_thread, start_thread, 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, message_person, report_bug, retry_thread, memory_log, session_search, trigger_info, trigger, delete_trigger, wait_until, list_waits, cancel_wait, propose_profile, propose_model, propose_team_memory, skills_list, skill_manage, mcp_server.",
+ "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, raise_escalation, usage_limits, list_threads, close_thread, start_thread, 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, message_person, report_bug, retry_thread, memory_log, session_search, trigger_info, trigger, delete_trigger, wait_until, list_waits, cancel_wait, propose_profile, propose_model, propose_team_memory, skills_list, skill_manage, mcp_server.",
"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.json
index c7734825c7..9a0cc6f549 100644
--- a/server/drivers/agents-catalog-goldens/full.tools-list.json
+++ b/server/drivers/agents-catalog-goldens/full.tools-list.json
@@ -245,6 +245,21 @@
"openWorldHint": false
}
},
+ {
+ "name": "usage_limits",
+ "description": "Each AI account's usage limits: percent used, reset time, when checked. status: ok, unknown (no data now; see why) or unsupported.",
+ "inputSchema": {
+ "type": "object",
+ "additionalProperties": false,
+ "properties": {}
+ },
+ "annotations": {
+ "readOnlyHint": true,
+ "destructiveHint": false,
+ "idempotentHint": true,
+ "openWorldHint": false
+ }
+ },
{
"name": "list_rooms",
"description": "List the shared rooms (team channels) you belong to, with the other members of each. Call this before post_to_room. One-to-one bot channels are never listed; discover individual teammates with list_bots. A room you are in but cannot post into is named without an id, together with the reason, so you can tell the user why.",
diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.json
index badfccc60c..6d847e5eb1 100644
--- a/server/drivers/agents-catalog-goldens/profiles.json
+++ b/server/drivers/agents-catalog-goldens/profiles.json
@@ -1,13 +1,14 @@
{
"default": {
- "bytes": 57586,
- "sha256": "9f393198a518809174701391c0741f66d099f2f0f6be38a2893ca0dd51b4da70",
+ "bytes": 57938,
+ "sha256": "7ca92ef8f46a1e7874b44b1910237ce4022b02b62276aa1d9739b6967d5ee445",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -49,14 +50,15 @@
]
},
"voice": {
- "bytes": 58367,
- "sha256": "068a6298be6770276302819ae041d5e228cc93b41e68415097cb427e6d844ba9",
+ "bytes": 58719,
+ "sha256": "da7bec06f2b0c159e81eacc787ec2f1464816a47048240cb4679e148f6941c00",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -99,8 +101,8 @@
]
},
"shared": {
- "bytes": 59851,
- "sha256": "75a856c424ef2f935478e335c0d36751f72dfadef9114860e79a64025dea7fe8",
+ "bytes": 60203,
+ "sha256": "f08d417b0a3c3e39afb42a9c46727cb1e3813ff1d093f5775efc993dd32ab9d6",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -109,6 +111,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -150,8 +153,8 @@
]
},
"shared+voice": {
- "bytes": 60632,
- "sha256": "40f8972722a3e381491993112f45e80613e6939ac7722e4e77ba9c84016e5159",
+ "bytes": 60984,
+ "sha256": "bca42559afe6adc7c32ab40f22b31572dd366f064da9634cc3166f3029d35107",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -160,6 +163,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -202,14 +206,15 @@
]
},
"skills": {
- "bytes": 60405,
- "sha256": "cb79aa882cb9ee4dadaa9fb0ab84f5f0961b35ec20b704fbfcba68ce9d09d357",
+ "bytes": 60757,
+ "sha256": "73952770ab160dcfd7f5808d3c4fec0f56a620e64522533e4ecd4dd867f7bec4",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -253,14 +258,15 @@
]
},
"skills+voice": {
- "bytes": 61186,
- "sha256": "ee6e14f1aa7e62cecf15cae1b9a3e6409aae0ea9e8dee19a734205fd72632551",
+ "bytes": 61538,
+ "sha256": "670f34bebd3bd020e37ed247bf6b2a8a4158adb9067aa8f9387be354a7e65365",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -305,8 +311,8 @@
]
},
"skills+shared": {
- "bytes": 62670,
- "sha256": "95f5917c45a16e9454c3cadaf533c871dcb4f2e34d1301a6b85bb5b670861e97",
+ "bytes": 63022,
+ "sha256": "17dfaca8b2e0d81cefbf92a68dadef63ac6d19d69e0dfbf90fffcdcd6b2669bf",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -315,6 +321,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -358,8 +365,8 @@
]
},
"skills+shared+voice": {
- "bytes": 63451,
- "sha256": "03ba1ff8992daa58d8855b6abf68a15e89042627bba7bcf4a8b0086d6b0d2ec7",
+ "bytes": 63803,
+ "sha256": "12445af58fdb50d699b1fd679968f244f736c4a13c58c1d6cf10c88725a0d39e",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -368,6 +375,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -412,14 +420,15 @@
]
},
"non-chief": {
- "bytes": 48529,
- "sha256": "9c28dbcc772ffff752234f529a0191a7b10956b42567fb5487e733a6c5a2824b",
+ "bytes": 48881,
+ "sha256": "da6a2bb011eccd26a29ecef998888d918f486e603f76704a2ad4ac023a1da276",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -454,14 +463,15 @@
]
},
"voice+non-chief": {
- "bytes": 49310,
- "sha256": "e53bac21b93ac68cdf145fd08163612ebde92e3584e67438ca2c99a1724d0b0d",
+ "bytes": 49662,
+ "sha256": "5b68c70b676e58eb968cd8b9ad6feb3728aee996cf58d1700d9eb6cc608bfc8c",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -497,8 +507,8 @@
]
},
"shared+non-chief": {
- "bytes": 50794,
- "sha256": "9a41e44f736bf8414a637cf3a577ab396b95d7dc95a4245997ffd812ee7a9b7a",
+ "bytes": 51146,
+ "sha256": "3d5fe90343c19d4b66441c705ab1cfe4f7b61a9c4de4cd86955f803e4f3c3e28",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -507,6 +517,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -541,8 +552,8 @@
]
},
"shared+voice+non-chief": {
- "bytes": 51575,
- "sha256": "088e50edd9fdb9978f7f74fbf35ec948984d811ab43c64329548e0c207e16a45",
+ "bytes": 51927,
+ "sha256": "df1ebd2a44eb3f04cfa24736e95efd1dc2935ce687048578726a5e8256bc9734",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -551,6 +562,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -586,14 +598,15 @@
]
},
"skills+non-chief": {
- "bytes": 51348,
- "sha256": "58e0ac5358150928b796c818c66b8c9f628add5f14342183e2154f0f90608539",
+ "bytes": 51700,
+ "sha256": "4c55a5d30a20a06a9e15dda0a7cd0560bd70b463a27239cee74a912f01e103c2",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -630,14 +643,15 @@
]
},
"skills+voice+non-chief": {
- "bytes": 52129,
- "sha256": "a710427d1176cf4caaf63b5cfd47a6e03f5f4b051f9b0f24922bce07ac551884",
+ "bytes": 52481,
+ "sha256": "c98f87d94cb2400b84b9f9fb32e5eb7e4a7f5e1f60030f957ee128c5b96d0113",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -675,8 +689,8 @@
]
},
"skills+shared+non-chief": {
- "bytes": 53613,
- "sha256": "9831b71f034e63f3af2fc6c189f6a3e4b03ebc02af6e83cc3627824a76111970",
+ "bytes": 53965,
+ "sha256": "7845fa3c1f74551ecad07920d58433c93e94f18b00172883021198d817d6a805",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -685,6 +699,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -721,8 +736,8 @@
]
},
"skills+shared+voice+non-chief": {
- "bytes": 54394,
- "sha256": "74c1c460cd9874867a1d343d67ac920113b8cb2c6288fc0cd178d2cea2c6cd07",
+ "bytes": 54746,
+ "sha256": "f79aaa04238c9230ffa0cb0111d935e169d348f7818c35fb5e42abf91a3ae974",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -731,6 +746,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -768,8 +784,8 @@
]
},
"skills+shared+voice+cloud-home": {
- "bytes": 63217,
- "sha256": "872f90bd3165cc4264dc3eba1c93b2675e25ba1ac8626daaa552007ce962cd7e",
+ "bytes": 63569,
+ "sha256": "5dcde2673097933674811fc358a2f95374e785f751666c4f02c2e0728f614240",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -778,6 +794,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -822,8 +839,8 @@
]
},
"skills+shared+voice+non-chief+cloud-home": {
- "bytes": 54160,
- "sha256": "af3f37a7b28a19f905c2ef2b109046e51da4374f1f6b67722f09167c1aabbc9f",
+ "bytes": 54512,
+ "sha256": "67aa831874156decd18645038f2b6faa0baa89c2bddbb515af9f052a9734858b",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -832,6 +849,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -869,8 +887,8 @@
]
},
"skills+shared+voice+escalations": {
- "bytes": 64281,
- "sha256": "e5ceb5e42185a8a6435f83b6b456db54117e2c699ace4ddbb3c08d8a85ed362b",
+ "bytes": 64633,
+ "sha256": "888f55d01e03dcd1c4a2d7c28bdbbf8a1c3118767e54d79839ff71e5e6dda738",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -880,6 +898,7 @@
"assignment_status",
"raise_escalation",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -924,8 +943,8 @@
]
},
"skills+shared+voice+escalations+x": {
- "bytes": 68120,
- "sha256": "7f926640b9ed8463e6e267cf9e68de74819eed1b20146989700af83b5cbdd73c",
+ "bytes": 68472,
+ "sha256": "486e31068520eabef7a9e49f9a1ec32c01a7ab3abab0f54a9023d98135e7db12",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -935,6 +954,7 @@
"assignment_status",
"raise_escalation",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -983,8 +1003,8 @@
]
},
"skills+shared+voice+escalations+x+team": {
- "bytes": 68752,
- "sha256": "a80d741eb9366eaae7ce73344a2bbb59508897faef0735e6c487e18d96827ab7",
+ "bytes": 69104,
+ "sha256": "e9ead83e184d61ac243022ae8d8b105122090a8d35ac7485154db91bc5bd518d",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -994,6 +1014,7 @@
"assignment_status",
"raise_escalation",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -1043,14 +1064,15 @@
]
},
"default+legacy-switches": {
- "bytes": 57586,
- "sha256": "9f393198a518809174701391c0741f66d099f2f0f6be38a2893ca0dd51b4da70",
+ "bytes": 57938,
+ "sha256": "7ca92ef8f46a1e7874b44b1910237ce4022b02b62276aa1d9739b6967d5ee445",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -1092,14 +1114,15 @@
]
},
"default+mausbot": {
- "bytes": 58237,
- "sha256": "b50fb0917a9290897d98b6e9a8a630e1a7dbb764359d70a9c651968ebcfe877c",
+ "bytes": 58589,
+ "sha256": "9a02dba6be87f95da8fa4fd863f0ba677bbb47807b6fe6290b1ad374f0f67f41",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -1143,8 +1166,8 @@
]
},
"skills+shared+voice+mausbot": {
- "bytes": 64102,
- "sha256": "28bb7344753ced63cac6ad6c96a9da4f982471ed350e49049d975bc70fa2f79d",
+ "bytes": 64454,
+ "sha256": "fa47022976ec4278938efe8a91c5152249e8db4469f44c7884ebfd25e387759c",
"tools": [
"tool_result_read",
"list_shared_computers",
@@ -1153,6 +1176,7 @@
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -1199,14 +1223,15 @@
]
},
"default+no-computer-pick": {
- "bytes": 56374,
- "sha256": "91053156ec8057d6b573a40a78074feb448ac97555cd29478092999761e6fd16",
+ "bytes": 56726,
+ "sha256": "a973a741575231c6f48ca4435d466ca6421017fe019b69f66a5759823f207032",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"list_threads",
"close_thread",
@@ -1247,14 +1272,15 @@
]
},
"default+room": {
- "bytes": 49456,
- "sha256": "c5d79a9a8516ff61f6fe26d77c73374f5b1e1eb3a7e69de98658b4f9039c2e2a",
+ "bytes": 49808,
+ "sha256": "a5f89db395dcb6eacce88ca1e246d9e74178617d29ba7acccf46a92efb76cdf3",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"list_threads",
"close_thread",
@@ -1290,14 +1316,15 @@
]
},
"non-chief+room": {
- "bytes": 40399,
- "sha256": "37734627f3c9442469c765ca12e4d548f7430f9e85d51168bab445cec7015090",
+ "bytes": 40751,
+ "sha256": "71738678141ebe1780c0132ab27bc8dceb9369d3d03776d6aed92746b600cd26",
"tools": [
"tool_result_read",
"list_room_targets",
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"list_threads",
"close_thread",
diff --git a/server/drivers/agents-catalog-wire.test.ts b/server/drivers/agents-catalog-wire.test.ts
index 3977fe4f8c..7b4e873fa4 100644
--- a/server/drivers/agents-catalog-wire.test.ts
+++ b/server/drivers/agents-catalog-wire.test.ts
@@ -89,13 +89,13 @@ const BUDGET_BASELINE: Record<string, number> = {
"skills+voice": 60510,
"skills+shared": 61960,
"skills+shared+voice": 62741,
- "non-chief": 47853,
- "voice+non-chief": 48634,
- "shared+non-chief": 50084,
- "shared+voice+non-chief": 50865,
- "skills+non-chief": 50672,
+ "non-chief": 48881,
+ "voice+non-chief": 49662,
+ "shared+non-chief": 51146,
+ "shared+voice+non-chief": 51927,
+ "skills+non-chief": 51700,
"skills+voice+non-chief": 51453,
- "skills+shared+non-chief": 52903,
+ "skills+shared+non-chief": 53965,
"skills+shared+voice+non-chief": 53684,
"skills+shared+voice+cloud-home": 63096,
"skills+shared+voice+non-chief+cloud-home": 53961,
@@ -106,8 +106,8 @@ const BUDGET_BASELINE: Record<string, number> = {
"skills+shared+voice+escalations+x": 67410,
"skills+shared+voice+escalations+x+team": 68042,
"default+no-computer-pick": 55698,
- "default+room": 48780,
- "non-chief+room": 39723,
+ "default+room": 49808,
+ "non-chief+room": 40751,
};
const RPC_PREFIX = '{"jsonrpc":"2.0","id":1,"result":';
diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.ts
index 00d629c516..fc8ecd8e02 100644
--- a/server/drivers/agents-catalog.ts
+++ b/server/drivers/agents-catalog.ts
@@ -5,6 +5,7 @@ import { agentToolAnnotations } from "../agent-tool-policy.ts";
import { CHAT_CARD_TOOL_DEFINITIONS } from "./agents-chat-card-tools.ts";
import { DEVS_TOOL_DEFINITIONS } from "./agents-devs-tools.ts";
import { HELPER_TOOL_DEFINITIONS } from "./agents-helper-tools.ts";
+import { USAGE_LIMITS_TOOL_DEFINITION } from "./agents-usage-tool.ts";
import { WAIT_TOOL_DEFINITIONS, WAIT_TOOL_NAMES } from "./agents-wait-tools.ts";
import { COMPUTER_ASK_TOOL_DEFINITIONS, COMPUTER_ASK_TOOL_NAMES } from "./agents-computer-ask-tool.ts";
import { MAUSBOT_TOOL_DEFINITIONS } from "./agents-mausbot-tools.ts";
@@ -256,6 +257,7 @@ const TOOL_DEFINITIONS = [
"List every other bot (agent) you can contact, in every department, with its department, model and current status. Call this to discover exact teammate IDs before assigning work or asking advice with coordinate_bots.",
inputSchema: { type: "object", properties: {} },
},
+ USAGE_LIMITS_TOOL_DEFINITION,
{
name: "list_rooms",
description:
diff --git a/server/drivers/agents-proxy.test.ts b/server/drivers/agents-proxy.test.ts
index 740b52f23c..5ee7a5da80 100644
--- a/server/drivers/agents-proxy.test.ts
+++ b/server/drivers/agents-proxy.test.ts
@@ -628,6 +628,7 @@ describe("agents-proxy MCP surface", () => {
"coordinate_bots",
"assignment_status",
"list_bots",
+ "usage_limits",
"list_rooms",
"select_computer",
"list_threads",
@@ -748,7 +749,7 @@ describe("agents-proxy MCP surface", () => {
const readNames = [
"tool_result_read",
"list_shared_computers",
- "assignment_status", "list_bots", "list_rooms", "list_threads",
+ "assignment_status", "list_bots", "usage_limits", "list_rooms", "list_threads",
"list_team_setup",
"session_search", "trigger_info", "list_waits", "skills_list",
];
diff --git a/server/drivers/agents-usage-tool.test.ts b/server/drivers/agents-usage-tool.test.ts
new file mode 100644
index 0000000000..4dac3033d6
--- /dev/null
+++ b/server/drivers/agents-usage-tool.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it, vi } from "vitest";
+
+import { isReadOnlyAgentTool } from "../agent-tool-policy.ts";
+import { callTool, type ToolCallContext } from "./agents-call.ts";
+import { availableTools } from "./agents-catalog.ts";
+import { catalogProfileFromEnv } from "./agents-catalog-profile.ts";
+import { callUsageLimitsTool, USAGE_LIMITS_TOOL } from "./agents-usage-tool.ts";
+
+const context = (answer: { ok: boolean; body: Record<string, unknown> }) => ({ client: { apiResponse: vi.fn(async () => answer) } }) as unknown as ToolCallContext;
+
+describe("the usage_limits tool", () => {
+ it("is read-only and listed to every bot, Chief or not, in every conversation", () => {
+ expect(isReadOnlyAgentTool(USAGE_LIMITS_TOOL)).toBe(true);
+ for (const env of [{}, { OMB_CHIEF_OF_STAFF: "1" }, { OMB_ROOM_TURN: "1" }, { OMB_TEAM_PEOPLE: "1" }]) {
+ const tools = availableTools(catalogProfileFromEnv({ OMB_BOT_ID: "bot", ...env })).map((tool) => tool.name);
+ expect(tools).toContain(USAGE_LIMITS_TOOL);
+ }
+ });
+
+ it("reaches the route when a bot calls it by name", async () => {
+ const asked = context({ ok: true, body: { text: '{"accounts":[]}' } });
+ await expect(callTool(USAGE_LIMITS_TOOL, {}, asked)).resolves.toEqual({ text: '{"accounts":[]}' });
+ });
+
+ it("hands the bot the route's answer, and its refusal as an error", async () => {
+ const asked = context({ ok: true, body: { text: '{"accounts":[]}' } });
+ await expect(callUsageLimitsTool(asked)).resolves.toEqual({ text: '{"accounts":[]}' });
+ expect(asked.client.apiResponse).toHaveBeenCalledWith("/api/internal/engine-limits");
+ await expect(callUsageLimitsTool(context({ ok: false, body: { error: "not yours" } }))).resolves.toEqual({ text: "not yours", isError: true });
+ });
+});
diff --git a/server/drivers/agents-usage-tool.ts b/server/drivers/agents-usage-tool.ts
new file mode 100644
index 0000000000..6d1a717a4c
--- /dev/null
+++ b/server/drivers/agents-usage-tool.ts
@@ -0,0 +1,16 @@
+// The agents catalog's usage_limits tool: one read of the plan-usage data the app's own Usage page shows. The internal
+// route (server/routes/engine-limits.ts) decides which accounts this conversation may see.
+import type { ToolCallContext, ToolCallResult } from "./agents-call.ts";
+
+export const USAGE_LIMITS_TOOL = "usage_limits";
+
+export async function callUsageLimitsTool(context: ToolCallContext): Promise<ToolCallResult> {
+ const { ok, body } = await context.client.apiResponse("/api/internal/engine-limits");
+ return ok ? { text: String(body.text ?? "") } : { text: String(body.error ?? "Usage limits could not be read. Try again shortly."), isError: true };
+}
+
+export const USAGE_LIMITS_TOOL_DEFINITION = {
+ name: USAGE_LIMITS_TOOL,
+ description: "Each AI account's usage limits: percent used, reset time, when checked. status: ok, unknown (no data now; see why) or unsupported.",
+ inputSchema: { type: "object", additionalProperties: false, properties: {} },
+};
diff --git a/server/engine-limits.e2e.test.ts b/server/engine-limits.e2e.test.ts
new file mode 100644
index 0000000000..6f007401c2
--- /dev/null
+++ b/server/engine-limits.e2e.test.ts
@@ -0,0 +1,36 @@
+import { readFileSync, writeFileSync, mkdtempSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { expect, it } from "vitest";
+
+import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";
+import { removeTempDir } from "./testing/cleanup.ts";
+
+it("a bot's turn reads its accounts' usage limits through its own capability, and nothing else may", async () => {
+ const folder = mkdtempSync(join(tmpdir(), "omb-engine-limits-"));
+ const gate = join(folder, "finish");
+ const fixture = await launchVerificationServer({ FAKE_CLAUDE_MODE: "slow", FAKE_CLAUDE_SLOW_FINISH_GATE: gate });
+ try {
+ const request = (path: string, init: RequestInit = {}) => fetch(fixture.info.url + path, { ...init, headers: { "content-type": "application/json", origin: fixture.info.url, ...init.headers } });
+ const { bot } = await (await request("/api/bots", { method: "POST", body: JSON.stringify({ name: "Scout" }) })).json() as { bot: { id: string; threadId: string } };
+ await runControlOmb(["send", "--bot", bot.id, "--task", bot.threadId, "--text", "How much Claude is left?", "--url", fixture.info.url]);
+ let token = "";
+ await expect.poll(() => {
+ try { token = JSON.parse(readFileSync(fixture.fixtureDumpPath, "utf8")).mcpConfig.mcpServers.agents.env.OMB_COMMS_TOKEN; } catch { return false; }
+ return Boolean(token);
+ }, { timeout: 15_000 }).toBe(true);
+
+ expect((await request("/api/internal/engine-limits", { headers: { authorization: "Bearer wrong" } })).status).toBeGreaterThanOrEqual(400);
+ const answer = await request("/api/internal/engine-limits", { headers: { authorization: `Bearer ${token}` } });
+ expect(answer.status).toBe(200);
+ const { text } = await answer.json() as { text: string };
+ const accounts = JSON.parse(text).accounts as Array<{ engine: string; status: string; windows: unknown[]; why?: string }>;
+ const claude = accounts.find((account) => account.engine === "claudeAgent");
+ expect(claude, text).toMatchObject({ status: "unknown", windows: [] });
+ expect(claude!.why, text).toBeTruthy();
+ writeFileSync(gate, "finish");
+ } finally {
+ await fixture.close();
+ await removeTempDir(folder);
+ }
+});
diff --git a/server/engine-limits.test.ts b/server/engine-limits.test.ts
new file mode 100644
index 0000000000..a5b0b3a5df
--- /dev/null
+++ b/server/engine-limits.test.ts
@@ -0,0 +1,158 @@
+import { join } from "node:path";
+import { describe, expect, it, vi } from "vitest";
+
+import { memberAudience, roomAudience, TEAM_AUDIENCE } from "./audience.ts";
+import type { InstanceConfigMap, ProviderSnapshot } from "./contracts.ts";
+import { audienceHome } from "./engine-homes/layout.ts";
+import { accountReadableFrom, engineLimitsFor, type EngineLimitInstance } from "./engine-limits.ts";
+import type { PlanProviderRow, PlanUsageReport } from "./plan-usage.ts";
+import { createEngineLimitsRoutes, ENGINE_LIMITS_GUEST } from "./routes/engine-limits.ts";
+import { PASS } from "./routes/table.ts";
+
+const DATA = "/data";
+const AT = "2026-11-02T10:00:00.000Z";
+const closed = { available: false, remainingPercent: null, usedPercent: null, resetsAt: null };
+const open = (used: number, resetsAt: string | null = "2026-11-02T12:00:00.000Z") => ({ available: true, usedPercent: used, remainingPercent: 100 - used, resetsAt });
+const row = (id: string, extra: Partial<PlanProviderRow> = {}): PlanProviderRow => ({
+ id, name: id, driver: "claude", plan: "max", ok: true, error: null, fiveHour: open(40.25), weekly: open(70), extra: [], models: [], ...extra,
+});
+const instance = (instanceId: string, driverKind = "claudeAgent", displayName: string | undefined = "Claude", enabled = true): EngineLimitInstance => ({ instanceId, driverKind, displayName, enabled });
+const ready: ProviderSnapshot = { state: "available", authenticated: true, billing: "subscription" };
+const report = (...providers: PlanProviderRow[]): PlanUsageReport => ({ fetchedAt: AT, providers });
+const read = (input: Partial<Parameters<typeof engineLimitsFor>[0]> & { instances: EngineLimitInstance[] }) => engineLimitsFor({
+ configs: {}, status: () => ready, report: report(), turn: TEAM_AUDIENCE, dataDir: DATA, ...input,
+});
+
+describe("usage limits a bot reads", () => {
+ it("gives percent, reset and when it was checked, for every window the account reports", () => {
+ const [account] = read({
+ instances: [instance("claude")],
+ report: report(row("claude", {
+ extra: [{ label: "Extra Usage", usedPercent: 5, remainingPercent: 95, resetsAt: null }],
+ models: [{ name: "Opus", windows: [{ label: "Weekly", usedPercent: 80, remainingPercent: 20, resetsAt: AT }] }],
+ })),
+ });
+ expect(account).toEqual({
+ account: "Claude", engine: "claudeAgent", status: "ok", plan: "max", checkedAt: AT,
+ windows: [
+ { name: "5-hour", usedPercent: 40.3, resetsAt: "2026-11-02T12:00:00.000Z" },
+ { name: "weekly", usedPercent: 70, resetsAt: "2026-11-02T12:00:00.000Z" },
+ { name: "Extra Usage", usedPercent: 5, resetsAt: null },
+ { name: "Opus Weekly", usedPercent: 80, resetsAt: AT },
+ ],
+ });
+ });
+
+ it("tells unknown from unsupported", () => {
+ const accounts = read({
+ instances: [instance("signed-out", "claudeAgent", "Signed out"), instance("quiet", "codex", "Quiet"), instance("cursor", "cursorAgent", "Cursor"), instance("key", "claudeAgent", "Key")],
+ status: (id) => id === "key" ? { ...ready, billing: "metered" } : ready,
+ report: report(
+ row("signed-out", { ok: false, error: "Sign in again in Claude", fiveHour: closed, weekly: closed }),
+ row("quiet", { fiveHour: closed, weekly: closed, plan: null }),
+ row("key"),
+ ),
+ });
+ expect(accounts.map(({ account, status, checkedAt, windows, why }) => ({ account, status, checkedAt, windows: windows.length, why }))).toEqual([
+ { account: "Signed out", status: "unknown", checkedAt: AT, windows: 0, why: "Sign in again in Claude" },
+ { account: "Quiet", status: "unknown", checkedAt: AT, windows: 0, why: "The account answered but reported no usage windows." },
+ { account: "Cursor", status: "unsupported", checkedAt: null, windows: 0, why: "This AI does not report usage limits to this app." },
+ { account: "Key", status: "unsupported", checkedAt: null, windows: 0, why: "This AI does not report usage limits to this app." },
+ ]);
+ });
+
+ it("says unknown, not unsupported, when the read itself failed", () => {
+ expect(read({ instances: [instance("claude"), instance("cursor", "cursorAgent", "Cursor")], report: null }).map((account) => account.status)).toEqual(["unknown", "unsupported"]);
+ });
+
+ it("leaves out an engine that is off, not installed, or a signed-out one that reports nothing", () => {
+ const accounts = read({
+ instances: [instance("off", "claudeAgent", "Off", false), instance("missing"), instance("cursor", "cursorAgent", "Cursor")],
+ status: (id) => id === "missing" ? { state: "unavailable", reason: "no CLI" } : id === "cursor" ? { ...ready, authenticated: false } : ready,
+ report: report(row("off"), row("missing")),
+ });
+ expect(accounts).toEqual([]);
+ });
+
+ it("carries no credential, account id, sign-in folder or address", () => {
+ const secret = "sk-ant-oat01-secret";
+ const text = JSON.stringify(read({
+ instances: [instance("claude-5f1c9a", "claudeAgent", "[email protected]"), instance("second", "claudeAgent", "[email protected]")],
+ configs: { "claude-5f1c9a": { driver: "claudeAgent", environment: { ANTHROPIC_API_KEY: secret }, config: { configDir: "/home/ada/.claude-work" } } },
+ status: () => ({ ...ready, account: { email: "[email protected]", organization: "Acme" } }),
+ report: report(row("claude-5f1c9a"), row("second")),
+ }));
+ for (const leak of [secret, "claude-5f1c9a", ".claude-work", "@", "Acme"]) expect(text).not.toContain(leak);
+ expect(JSON.parse(text).map((account: { account: string }) => account.account)).toEqual(["claudeAgent", "claudeAgent 2"]);
+ });
+});
+
+describe("a Team Cloud's audience rule", () => {
+ const ada = memberAudience("ada"), bob = memberAudience("bob");
+ const adaHome = audienceHome(DATA, ada);
+ const inHome: InstanceConfigMap[string] = { driver: "claudeAgent", config: { configDir: join(adaHome, ".claude") } };
+ const inEnv: InstanceConfigMap[string] = { driver: "codex", environment: { CODEX_HOME: join(adaHome, ".codex") } };
+ const inPeople: InstanceConfigMap[string] = { driver: "claudeAgent", config: { configDir: join(DATA, "people", "ada", "claude") } };
+
+ it("a member's turn reads their own account and the team's, never another member's", () => {
+ for (const entry of [inHome, inEnv, inPeople]) {
+ expect(accountReadableFrom(entry, ada, DATA)).toBe(true);
+ expect(accountReadableFrom(entry, bob, DATA)).toBe(false);
+ expect(accountReadableFrom(entry, TEAM_AUDIENCE, DATA)).toBe(false);
+ expect(accountReadableFrom(entry, roomAudience("r1"), DATA)).toBe(false);
+ }
+ const team: InstanceConfigMap[string] = { driver: "claudeAgent", config: { configDir: join(audienceHome(DATA, TEAM_AUDIENCE), ".claude") } };
+ expect(accountReadableFrom(team, bob, DATA)).toBe(true);
+ expect(accountReadableFrom({ driver: "claudeAgent" }, bob, DATA)).toBe(true);
+ expect(accountReadableFrom(undefined, bob, DATA)).toBe(true);
+ });
+
+ it("leaves another member's account out of what a bot reads", () => {
+ const instances = [instance("ada", "claudeAgent", "Ada's Claude"), instance("team", "claudeAgent", "Team Claude")];
+ const configs = { ada: inHome, team: { driver: "claudeAgent" } } as InstanceConfigMap;
+ const input = { instances, configs, report: report(row("ada"), row("team")) };
+ expect(read({ ...input, turn: bob }).map((account) => account.account)).toEqual(["Team Claude"]);
+ expect(read({ ...input, turn: ada }).map((account) => account.account)).toEqual(["Ada's Claude", "Team Claude"]);
+ });
+});
+
+describe("the internal route", () => {
+ const route = (over: Partial<Parameters<typeof createEngineLimitsRoutes>[0]> = {}) => {
+ const load = vi.fn(async () => report(row("claude")));
+ const deps = { instances: () => [instance("claude")], configs: () => ({ claude: { driver: "claudeAgent" } }) as InstanceConfigMap, status: () => ready, load, audienceOf: () => TEAM_AUDIENCE, guestDriven: () => false, dataDir: DATA, ...over };
+ return { load, run: createEngineLimitsRoutes(deps) };
+ };
+ const call = async (run: ReturnType<typeof route>["run"], method = "GET", path = "/api/internal/engine-limits") => {
+ const json = vi.fn();
+ const passed = await run({ method, path, res: {} as never, json: json as never, threadId: "t" });
+ return { passed, status: json.mock.calls[0]?.[1], body: json.mock.calls[0]?.[2] as { text?: string; error?: string } | undefined };
+ };
+
+ it("answers the accounts as text the tool hands to the bot", async () => {
+ const { run, load } = route();
+ const { status, body } = await call(run);
+ expect(status).toBe(200);
+ expect(JSON.parse(body!.text!).accounts[0]).toMatchObject({ account: "Claude", status: "ok" });
+ expect(load).toHaveBeenCalledWith([expect.objectContaining({ id: "claude", driver: "claude" })]);
+ });
+
+ it("refuses a turn someone else started, without reading anything", async () => {
+ const { run, load } = route({ guestDriven: () => true });
+ const { status, body } = await call(run);
+ expect(status).toBe(403);
+ expect(body?.error).toBe(ENGINE_LIMITS_GUEST);
+ expect(load).not.toHaveBeenCalled();
+ });
+
+ it("a failed read still answers, as unknown", async () => {
+ const { run } = route({ load: async () => { throw new Error("offline"); } });
+ const { body } = await call(run);
+ expect(JSON.parse(body!.text!).accounts[0]).toMatchObject({ status: "unknown", checkedAt: null });
+ });
+
+ it("leaves other paths and methods alone", async () => {
+ const { run } = route();
+ expect((await call(run, "POST")).passed).toBe(PASS);
+ expect((await call(run, "GET", "/api/internal/other")).passed).toBe(PASS);
+ });
+});
diff --git a/server/engine-limits.ts b/server/engine-limits.ts
new file mode 100644
index 0000000000..d75c963e71
--- /dev/null
+++ b/server/engine-limits.ts
@@ -0,0 +1,117 @@
+// What a bot may read about the usage limits of the AI accounts it can run on: percent used, reset time and when that was
+// checked, per account. Rows are built field by field from the plan-usage report, so no token, account id, sign-in folder
+// or address can reach a model. Security: an account kept in another person's engine home is never listed to a turn.
+import { join, relative, isAbsolute } from "node:path";
+
+import { audienceMember, type Audience } from "./audience.ts";
+import type { InstanceConfig, InstanceConfigMap, ProviderSnapshot } from "./contracts.ts";
+import { audienceHomeKey, engineHomesRoot } from "./engine-homes/layout.ts";
+import type { PlanProviderRow, PlanUsageReport, PlanWindow } from "./plan-usage.ts";
+
+export interface EngineLimitWindow {
+ name: string;
+ usedPercent: number;
+ /** ISO time, or null when the account did not say. */
+ resetsAt: string | null;
+}
+
+/** `ok`: `windows` hold what the account reported. `unknown`: it reports limits, but there is no data right now (`why` says
+ * what to do). `unsupported`: this kind of account reports no limits to this app at all. */
+export interface EngineLimitAccount {
+ account: string;
+ engine: string;
+ status: "ok" | "unknown" | "unsupported";
+ plan?: string;
+ /** When the numbers were read from the provider; the same read may serve calls for up to a minute. Null when never asked. */
+ checkedAt: string | null;
+ windows: EngineLimitWindow[];
+ why?: string;
+}
+
+export interface EngineLimitInstance {
+ instanceId: string;
+ displayName?: string;
+ driverKind: string;
+ enabled: boolean;
+}
+
+const REPORTING_DRIVERS: ReadonlySet<string> = new Set(["claudeAgent", "codex", "grokAgent"]);
+const UNSUPPORTED_WHY = "This AI does not report usage limits to this app.";
+const NO_WINDOWS_WHY = "The account answered but reported no usage windows.";
+const NOT_CHECKED_WHY = "Usage could not be checked just now. Try again later.";
+
+function under(root: string, path: string): string | null {
+ const inside = relative(root, path);
+ return inside && !inside.startsWith("..") && !isAbsolute(inside) ? inside.split(/[\\/]/)[0]! : null;
+}
+
+function accountFolders(entry: InstanceConfig | undefined): string[] {
+ const configDir = (entry?.config as { configDir?: unknown } | undefined)?.configDir;
+ return [configDir, ...Object.values(entry?.environment ?? {})].filter((value): value is string => typeof value === "string" && isAbsolute(value));
+}
+
+/** Engine sign-ins on a Team Cloud are the team's: only an Admin saves one, and it serves every member. The one way an
+ * account is someone's own is its folder sitting in their engine home or person folder. */
+export function accountReadableFrom(entry: InstanceConfig | undefined, turn: Audience, dataDir: string): boolean {
+ const homes = engineHomesRoot(dataDir), people = join(dataDir, "people");
+ return accountFolders(entry).every((folder) => {
+ const home = under(homes, folder);
+ if (home !== null && home !== "team" && home !== audienceHomeKey(turn)) return false;
+ const person = under(people, folder);
+ return person === null || person === audienceMember(turn);
+ });
+}
+
+const percent = (value: number) => Math.round(value * 10) / 10;
+
+function rowWindows(row: PlanProviderRow): EngineLimitWindow[] {
+ const line = (name: string, window: PlanWindow): EngineLimitWindow[] => window.available && window.usedPercent !== null
+ ? [{ name, usedPercent: percent(window.usedPercent), resetsAt: window.resetsAt }] : [];
+ return [
+ ...line("5-hour", row.fiveHour),
+ ...line("weekly", row.weekly),
+ ...row.extra.map((extra) => ({ name: extra.label, usedPercent: percent(extra.usedPercent), resetsAt: extra.resetsAt })),
+ ...row.models.flatMap((model) => model.windows.map((entry) => ({ name: `${model.name} ${entry.label}`, usedPercent: percent(entry.usedPercent), resetsAt: entry.resetsAt }))),
+ ];
+}
+
+/** A person may have named an account after their address. */
+const shownName = (instance: EngineLimitInstance) => {
+ const name = instance.displayName?.trim();
+ return name && !name.includes("@") ? name : instance.driverKind;
+};
+
+export function engineLimitsFor(input: {
+ instances: readonly EngineLimitInstance[];
+ configs: InstanceConfigMap;
+ status: (instanceId: string) => ProviderSnapshot | undefined;
+ /** Null when the read failed. */
+ report: PlanUsageReport | null;
+ turn: Audience;
+ dataDir: string;
+}): EngineLimitAccount[] {
+ const { report } = input;
+ const seen = new Map<string, number>();
+ return input.instances.flatMap((instance): EngineLimitAccount[] => {
+ const snapshot = input.status(instance.instanceId);
+ if (!instance.enabled || snapshot?.state !== "available") return [];
+ if (!accountReadableFrom(input.configs[instance.instanceId], input.turn, input.dataDir)) return [];
+ const base = (() => {
+ const name = shownName(instance), count = (seen.get(name) ?? 0) + 1;
+ seen.set(name, count);
+ return { account: count > 1 ? `${name} ${count}` : name, engine: instance.driverKind };
+ })();
+ if (!REPORTING_DRIVERS.has(instance.driverKind) || snapshot.billing === "metered") {
+ return snapshot.authenticated === false ? [] : [{ ...base, status: "unsupported", checkedAt: null, windows: [], why: UNSUPPORTED_WHY }];
+ }
+ if (!report) return [{ ...base, status: "unknown", checkedAt: null, windows: [], why: NOT_CHECKED_WHY }];
+ const row = report.providers.find((candidate) => candidate.id === instance.instanceId);
+ if (!row) return [{ ...base, status: "unsupported", checkedAt: null, windows: [], why: UNSUPPORTED_WHY }];
+ if (!row.ok) return [{ ...base, status: "unknown", checkedAt: report.fetchedAt, windows: [], why: row.error ?? NOT_CHECKED_WHY }];
+ const windows = rowWindows(row);
+ const plan = row.plan ? { plan: row.plan } : {};
+ return [windows.length
+ ? { ...base, ...plan, status: "ok", checkedAt: report.fetchedAt, windows }
+ : { ...base, ...plan, status: "unknown", checkedAt: report.fetchedAt, windows: [], why: NO_WINDOWS_WHY }];
+ });
+}
diff --git a/server/index.ts b/server/index.ts
index f63fc70070..0321a9e742 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -453,7 +453,7 @@ import { screenFrameHash, screenSurfaceForTool, screenTouchingTool, settledFrame
import { asSchedule, RoutineRequestService } from "./routine-requests.ts"; import { ownerSpokeOnly } from "./cloud-routine-level.ts"; import { routineRunCard, routineRunFallbackText } from "./routine-run-card.ts";
import { activeRoutinesContext } from "./active-routines-context.ts";
import { automationContextText, createAutomationReports, newestAutomationLines } from "./automation-reports.ts"; import { createAutomationDestinations } from "./automation-destinations.ts"; import { createProactive } from "./host/proactive.ts"; import { createFirstHourHooks, startFirstHour, welcomeDonePatch } from "./host/first-hour-host.ts"; import { greetingMessage } from "./host/first-hour.ts"; import { READ_AND_DRAFT_PARTS, READ_AND_DRAFT_REFUSAL, READ_AND_DRAFT_TOOLS, recordsAnswer } from "./read-and-draft.ts"; import { createPresenceRoutes } from "./routes/presence.ts"; import { needsYouNow } from "./today.ts";
-import { engineLabel, LimitResetClock, nearLimitNote } from "./limit-resets.ts"; import { planAccountsFromInstances } from "./plan-usage.ts"; import { LimitFailovers, limitBackupAllowed } from "./limit-failover.ts"; import { createLimitResetRoutes } from "./routes/limit-resets.ts";
+import { engineLabel, LimitResetClock, nearLimitNote } from "./limit-resets.ts"; import { loadPlanUsage, planAccountsFromInstances } from "./plan-usage.ts"; import { LimitFailovers, limitBackupAllowed } from "./limit-failover.ts"; import { createLimitResetRoutes } from "./routes/limit-resets.ts";
import { parseTriggerRequest, triggerTarget } from "./trigger-tools.ts"; import { WebhookRequestError, WebhookRequestService } from "./webhook-requests.ts"; import { createAppTriggerHost } from "./app-trigger-host.ts";
import { appliesNow, directApply, UNDO_STALE, type DirectApply } from "./direct-apply.ts";
import { createTeamMemoryRequests } from "./team-memory-requests.ts";
@@ -12584,7 +12584,7 @@ ROUTES.push(createBrowserViewerRoutes({
restartRefusal: (session) => browserRestartRefusal(browserRuntime.interrupted(session), store.bots.filter((candidate) => candidate.busy
&& browserSessionsOf(candidate.id, candidate.browserProfile).includes(session)).map((candidate) => ({ waitingOnBrowser: computerControl.snapshot(candidate.id).help?.place === "browser" }))),
}));
-const internalToolRoutes = createInternalToolRoutes({ helpers: { decider, extractor }, notifications: { bot: (id) => store.bot(id), team: sharedMembership, broadcast }, xResearch: { credential: () => researchCredential(cfg.treg?.key), botEnabled: (botId) => store.bot(botId)?.xResearch !== false, cloudHome: CLOUD_HOME !== null, researchOff: () => researchAvailability.refused() } }); const waitRoutes = createWaitRoutes({ waits: botWaits, cloudHome: Boolean(CLOUD_HOME), sleeps: Boolean(CLOUD_HOME) && CLOUD_TEAM === null }); ROUTES.push(createXConnectorRoutes({ credential: () => researchCredential(cfg.treg?.key), included: () => xCredential(), unavailable: () => xResearchStatus().unavailable === true }));
+const internalToolRoutes = createInternalToolRoutes({ engineLimits: { instances: () => registry.instances(), configs: () => instanceConfigs(cfg), status: (instanceId) => registry.knownSnapshot(instanceId), load: (accounts) => loadPlanUsage({ accounts }), audienceOf: (threadId) => teamHost.audienceOf(threadId), guestDriven: cloudGuestDriven, dataDir: DATA_DIR }, helpers: { decider, extractor }, notifications: { bot: (id) => store.bot(id), team: sharedMembership, broadcast }, xResearch: { credential: () => researchCredential(cfg.treg?.key), botEnabled: (botId) => store.bot(botId)?.xResearch !== false, cloudHome: CLOUD_HOME !== null, researchOff: () => researchAvailability.refused() } }); const waitRoutes = createWaitRoutes({ waits: botWaits, cloudHome: Boolean(CLOUD_HOME), sleeps: Boolean(CLOUD_HOME) && CLOUD_TEAM === null }); ROUTES.push(createXConnectorRoutes({ credential: () => researchCredential(cfg.treg?.key), included: () => xCredential(), unavailable: () => xResearchStatus().unavailable === true }));
// Live calls: the client holds the WebRTC audio; the key never leaves the harness, which creates the session.
function liveBotFor(botId: string): LiveBot {
@@ -13160,7 +13160,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
throw Object.assign(new Error("the internal turn capability has expired"), { status: 401 });
}
};
- const botFolders = async () => ({ roots: messageFileRootsForThread(internalSender.id, internalCapability.threadId).filter((root) => root !== ATTACHMENTS_DIR), vmWorkspace: (await attachmentVmForTurn(internalCapability))?.workspaceDir ?? null }); if (await internalToolRoutes({ method, path, res, json, botId: internalSender.id, readBody: readInternalBody, folders: botFolders }) !== PASS || await waitRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, ...waitTurnChecks(internalCapability, internalSender) }) !== PASS || await teamMessages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || await devsReports.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || (computerAsks && await computerAsks.internal({ method, path, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS)) return; const pagesCall = new AbortController(); res.once("close", () => { if (!res.writableEnded) pagesCall.abort(); }); if (await publishedPages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, requireActive: requireActiveInternalCapability, signal: pagesCall.signal, folders: botFolders, post: (text, publishedPage, bundle) => { const source = connectorThread(internalSender.id, internalCapability.threadId); return !source ? null : (!source.group && bundle && publishedPages.show({ threadId: internalCapability.threadId, card: publishedPage, bundle })) || store.appendMessage(internalCapability.threadId, { role: "bot", kind: "text", text, publishedPage, ...(source.group ? { from: { botId: internalSender.id, name: internalSender.name, color: internalSender.color } } : {}) }).id; } }) !== PASS) return;
+ const botFolders = async () => ({ roots: messageFileRootsForThread(internalSender.id, internalCapability.threadId).filter((root) => root !== ATTACHMENTS_DIR), vmWorkspace: (await attachmentVmForTurn(internalCapability))?.workspaceDir ?? null }); if (await internalToolRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, folders: botFolders }) !== PASS || await waitRoutes({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, ...waitTurnChecks(internalCapability, internalSender) }) !== PASS || await teamMessages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || await devsReports.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody }) !== PASS || (computerAsks && await computerAsks.internal({ method, path, res, json, turn: internalCapability, readBody: readInternalBody }) !== PASS)) return; const pagesCall = new AbortController(); res.once("close", () => { if (!res.writableEnded) pagesCall.abort(); }); if (await publishedPages.internal({ method, path, res, json, botId: internalSender.id, threadId: internalCapability.threadId, readBody: readInternalBody, requireActive: requireActiveInternalCapability, signal: pagesCall.signal, folders: botFolders, post: (text, publishedPage, bundle) => { const source = connectorThread(internalSender.id, internalCapability.threadId); return !source ? null : (!source.group && bundle && publishedPages.show({ threadId: internalCapability.threadId, card: publishedPage, bundle })) || store.appendMessage(internalCapability.threadId, { role: "bot", kind: "text", text, publishedPage, ...(source.group ? { from: { botId: internalSender.id, name: internalSender.name, color: internalSender.color } } : {}) }).id; } }) !== PASS) return;
const delegatedThisTurn = (taskId: string) => {
(internalCapability.delegatedThisTurn ??= new Set()).add(taskId);
};
diff --git a/server/routes/engine-limits.ts b/server/routes/engine-limits.ts
new file mode 100644
index 0000000000..84f8f4a3d9
--- /dev/null
+++ b/server/routes/engine-limits.ts
@@ -0,0 +1,45 @@
+// The internal call behind the usage_limits tool. Runs inside index.ts's /api/internal/ block after the capability bearer
+// is checked; the conversation is the capability's. It only reads.
+import type { ServerResponse } from "node:http";
+
+import type { Audience } from "../audience.ts";
+import type { InstanceConfigMap, ProviderSnapshot } from "../contracts.ts";
+import { engineLimitsFor, type EngineLimitInstance } from "../engine-limits.ts";
+import type { json as sendJson } from "../harness/http.ts";
+import type { PlanAccount, PlanUsageReport } from "../plan-usage.ts";
+import { planAccountsFromInstances } from "../plan-usage.ts";
+import { PASS } from "./table.ts";
+
+const LIMITS = "/api/internal/engine-limits";
+
+export const ENGINE_LIMITS_GUEST = "Usage limits belong to the owner of this computer's AI accounts, and this conversation was started by someone else.";
+
+export interface EngineLimitsDeps {
+ instances(): readonly EngineLimitInstance[];
+ configs(): InstanceConfigMap;
+ status(instanceId: string): ProviderSnapshot | undefined;
+ /** Never a forced refresh: a bot calling in a loop is served the same read. */
+ load(accounts: PlanAccount[]): Promise<PlanUsageReport>;
+ audienceOf(threadId: string): Audience;
+ guestDriven(threadId: string): boolean;
+ dataDir: string;
+}
+
+export interface EngineLimitsContext {
+ method: string;
+ path: string;
+ res: ServerResponse;
+ json: typeof sendJson;
+ threadId: string;
+}
+
+export function createEngineLimitsRoutes(deps: EngineLimitsDeps) {
+ return async (ctx: EngineLimitsContext): Promise<typeof PASS | void> => {
+ if (ctx.method !== "GET" || ctx.path !== LIMITS) return PASS;
+ if (deps.guestDriven(ctx.threadId)) return void ctx.json(ctx.res, 403, { error: ENGINE_LIMITS_GUEST });
+ const configs = deps.configs();
+ const report = await deps.load(planAccountsFromInstances(configs)).catch(() => null);
+ const accounts = engineLimitsFor({ instances: deps.instances(), configs, status: deps.status, report, turn: deps.audienceOf(ctx.threadId), dataDir: deps.dataDir });
+ return void ctx.json(ctx.res, 200, { text: JSON.stringify({ accounts }) });
+ };
+}
diff --git a/server/routes/internal-tools.ts b/server/routes/internal-tools.ts
index a854abb27c..8e2a228902 100644
--- a/server/routes/internal-tools.ts
+++ b/server/routes/internal-tools.ts
@@ -1,14 +1,15 @@
-// The agents tools' internal calls that need only the capability's bot, its body and its folders: research, the helper
-// models' decide and extract, and MausBot's notifications. Runs inside index.ts's /api/internal/ block, after the
+// The agents tools' internal calls that need only the capability's bot and conversation, its body and its folders: research,
+// the helper models' decide and extract, MausBot's notifications and the usage limits. Runs inside index.ts's /api/internal/ block, after the
// capability bearer is checked; each route answers its own paths and passes the rest on.
+import { createEngineLimitsRoutes, type EngineLimitsDeps } from "./engine-limits.ts";
import { createHelperToolRoutes, type HelperToolContext, type HelperToolDeps } from "./helper-tools.ts";
import { createMausBotNotificationRoutes, type LiveNotificationsDeps } from "./mausbot-notifications.ts";
import { PASS } from "./table.ts";
import { createXResearchInternalRoutes, type XResearchDeps } from "./x-research.ts";
-export function createInternalToolRoutes(deps: { helpers: HelperToolDeps; xResearch: XResearchDeps; notifications: LiveNotificationsDeps }) {
- const routes = [createXResearchInternalRoutes(deps.xResearch), createHelperToolRoutes(deps.helpers), createMausBotNotificationRoutes(deps.notifications)];
- return async (ctx: HelperToolContext): Promise<typeof PASS | void> => {
+export function createInternalToolRoutes(deps: { helpers: HelperToolDeps; xResearch: XResearchDeps; notifications: LiveNotificationsDeps; engineLimits: EngineLimitsDeps }) {
+ const routes = [createXResearchInternalRoutes(deps.xResearch), createHelperToolRoutes(deps.helpers), createMausBotNotificationRoutes(deps.notifications), createEngineLimitsRoutes(deps.engineLimits)];
+ return async (ctx: HelperToolContext & { threadId: string }): Promise<typeof PASS | void> => {
for (const route of routes) if (await route(ctx) !== PASS) return;
return PASS;
};