Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Antigravity CLI: fit OpenMausBot's own tools under the CLI's size budget so none are dropped (#7578)
Milind Soni09a4d73cb8f6
diff --git a/server/advertised-schema.test.ts b/server/advertised-schema.test.tsnew file mode 100644index 0000000000..70d3f25a21--- /dev/null+++ b/server/advertised-schema.test.ts@@ -0,0 +1,62 @@+import { describe, expect, it } from "vitest";++import { compactAdvertisedSchema } from "./advertised-schema.ts";++describe("a schema as a model is shown it", () => {+ it("leaves out additionalProperties: true, and keeps false", () => {+ expect(compactAdvertisedSchema({ type: "object", additionalProperties: true, properties: { a: { type: "object", additionalProperties: true } } }))+ .toEqual({ type: "object", properties: { a: { type: "object" } } });+ expect(compactAdvertisedSchema({ type: "object", additionalProperties: false })).toEqual({ type: "object", additionalProperties: false });+ expect(compactAdvertisedSchema({ type: "object", additionalProperties: { type: "string" } })).toEqual({ type: "object", additionalProperties: { type: "string" } });+ });++ it("leaves out bounds at the safe-integer limits, and keeps every other bound", () => {+ const count = { type: "integer", minimum: Number.MIN_SAFE_INTEGER, maximum: Number.MAX_SAFE_INTEGER };+ expect(compactAdvertisedSchema({ type: "object", properties: { count } })).toEqual({ type: "object", properties: { count: { type: "integer" } } });+ expect(compactAdvertisedSchema({ type: "integer", minimum: 0, maximum: 9_007_199_254_740_990 })).toEqual({ type: "integer", minimum: 0, maximum: 9_007_199_254_740_990 });+ });++ it("flattens an anyOf nested in an anyOf", () => {+ expect(compactAdvertisedSchema({ anyOf: [{ anyOf: [{ type: "string" }, { type: "number" }] }, { type: "boolean" }] }))+ .toEqual({ anyOf: [{ type: "string" }, { type: "number" }, { type: "boolean" }] });+ });++ it("leaves out a JSON-text fallback beside the shape it stands for, and keeps a JSON-text value that is the only one", () => {+ const shape = { type: "object", properties: { a: { type: "string" } } };+ expect(compactAdvertisedSchema({ anyOf: [shape, { type: "string", contentMediaType: "application/json" }] })).toEqual(shape);+ const only = { type: "string", contentMediaType: "application/json" };+ expect(compactAdvertisedSchema({ anyOf: [only] })).toEqual(only);+ });++ it("leaves out the null branch of a property that may be left out, and keeps it on a required one", () => {+ const nullable = { anyOf: [{ type: "string", maxLength: 10 }, { type: "null" }], description: "A note." };+ expect(compactAdvertisedSchema({ type: "object", properties: { optional: nullable, needed: nullable }, required: ["needed"] })).toEqual({+ type: "object", required: ["needed"],+ properties: { optional: { type: "string", maxLength: 10, description: "A note." }, needed: { anyOf: [{ type: "string", maxLength: 10 }, { type: "null" }], description: "A note." } },+ });+ });++ it("makes a tagged union of objects one object: the tag lists every value, and only what every branch requires stays required", () => {+ const schema = { anyOf: [+ { type: "object", properties: { kind: { const: "file" }, path: { type: "string" }, mode: { type: "string" } }, required: ["kind", "path", "mode"] },+ { type: "object", properties: { kind: { type: "string", enum: ["url"] }, url: { type: "string" }, mode: { type: "number" } }, required: ["kind", "url", "mode"] },+ ] };+ expect(compactAdvertisedSchema(schema)).toEqual({ type: "object", required: ["kind", "mode"], properties: {+ kind: { type: "string", enum: ["file", "url"] }, path: { type: "string" }, mode: { anyOf: [{ type: "string" }, { type: "number" }] }, url: { type: "string" },+ } });+ });++ it("keeps a union that is not tagged, and every value, enum and required field as written", () => {+ const untagged = { anyOf: [{ type: "object", properties: { a: { type: "string" } } }, { type: "object", properties: { b: { type: "string" } } }] };+ expect(compactAdvertisedSchema(untagged)).toEqual(untagged);+ const values = { type: "object", required: ["mode"], properties: { mode: { type: "string", enum: ["a", "b"], default: "a", examples: [{ additionalProperties: true }] } } };+ expect(compactAdvertisedSchema(values)).toEqual(values);+ });++ it("does not change the schema it was given", () => {+ const schema = { type: "object", additionalProperties: true, properties: { a: { anyOf: [{ type: "string" }, { type: "null" }] } } };+ const copy = structuredClone(schema);+ compactAdvertisedSchema(schema);+ expect(schema).toEqual(copy);+ });+});diff --git a/server/advertised-schema.ts b/server/advertised-schema.tsnew file mode 100644index 0000000000..cc115e7d62--- /dev/null+++ b/server/advertised-schema.ts@@ -0,0 +1,90 @@+// A tool's input schema as a model is shown it, with the JSON that says nothing to the model left out. Calls are still+// checked against the tool's own full schema, so every rule here either keeps what the schema accepts or only leaves out+// a form the handler still takes:+// - `additionalProperties: true` is the default;+// - a `minimum`/`maximum` at JavaScript's safe-integer limit bounds nothing a model would send;+// - an `anyOf` whose only key is `anyOf`, inside another, is the same choice flattened;+// - a string branch marked `contentMediaType: application/json` beside other branches is the same value written as JSON+// text: offered to a model, it invites stringified input;+// - the `{"type":"null"}` branch of a property the schema does not require: leaving the property out says the same;+// - an `anyOf` left with one branch is that branch;+// - objects told apart by one property with a single fixed value each (a tagged union) become one object: the tag lists+// every value, each other property is offered once, and only what every branch requires stays required. Each tag's own+// required fields are then checked by the handler, not shown.+type Json = Record<string, unknown>;++function isObject(value: unknown): value is Json {+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);+}++const onlyKey = (node: Json, key: string) => Object.keys(node).length === 1 && key in node;+const isNullBranch = (node: unknown) => isObject(node) && node.type === "null" && onlyKey(node, "type");+const isBareAnyOf = (node: unknown): node is { anyOf: unknown[] } => isObject(node) && Array.isArray(node.anyOf) && onlyKey(node, "anyOf");+const isJsonText = (node: unknown) => isObject(node) && node.type === "string" && node.contentMediaType === "application/json";+const SAFE_BOUNDS: Record<string, number> = { maximum: Number.MAX_SAFE_INTEGER, minimum: Number.MIN_SAFE_INTEGER };++/** The single fixed value `branch` gives property `key` (`const`, or an `enum` of one), else undefined. */+function tagOf(branch: Json, key: string): unknown {+ const property = isObject(branch.properties) ? branch.properties[key] : undefined;+ if (!isObject(property)) return undefined;+ if (Array.isArray(property.enum) && property.enum.length === 1) return property.enum[0];+ return "const" in property ? property.const : undefined;+}++const same = (a: unknown, b: unknown) => JSON.stringify(a) === JSON.stringify(b);++/** One object for objects told apart by one property with a distinct fixed string value each; undefined otherwise. */+function mergedTaggedObjects(branches: readonly unknown[]): Json | undefined {+ if (branches.length < 2) return undefined;+ const objects = branches.filter((branch): branch is Json & { properties: Json } => isObject(branch) && branch.type === "object" && isObject(branch.properties));+ if (objects.length !== branches.length) return undefined;+ const tag = Object.keys(objects[0]!.properties).find((key) => {+ const values = objects.map((object) => tagOf(object, key));+ return values.every((value) => typeof value === "string") && new Set(values).size === values.length;+ });+ if (tag === undefined) return undefined;+ const properties: Json = { [tag]: { type: "string", enum: objects.map((object) => tagOf(object, tag)) } };+ for (const object of objects) {+ for (const [name, property] of Object.entries(object.properties)) {+ if (name === tag) continue;+ const seen = properties[name];+ if (seen === undefined) { properties[name] = property; continue; }+ const options = isBareAnyOf(seen) ? seen.anyOf : [seen];+ if (!options.some((option) => same(option, property))) properties[name] = { anyOf: [...options, property] };+ }+ }+ const [first = [], ...others] = objects.map((object) => (Array.isArray(object.required) ? object.required : []));+ const required = first.filter((name) => name !== tag && others.every((list) => list.includes(name)));+ return { type: "object", properties, required: [tag, ...required] };+}++function compact(node: unknown, optional: boolean): unknown {+ if (Array.isArray(node)) return node.map((item) => compact(item, false));+ if (!isObject(node)) return node;+ const required = new Set(Array.isArray(node.required) ? node.required : []);+ let result: Json = {};+ for (const [key, value] of Object.entries(node)) {+ if (key === "additionalProperties" && value === true) continue;+ if (SAFE_BOUNDS[key] === value) continue;+ // Values, not schemas: copied as they are.+ if (key === "enum" || key === "const" || key === "default" || key === "examples" || key === "required") result[key] = value;+ else if (key === "properties" && isObject(value)) {+ result[key] = Object.fromEntries(Object.entries(value).map(([name, property]) => [name, compact(property, !required.has(name))]));+ } else result[key] = compact(value, false);+ }+ if (Array.isArray(result.anyOf)) {+ const branches = result.anyOf+ .flatMap((branch) => (isBareAnyOf(branch) ? branch.anyOf : [branch]))+ .filter((branch) => !(optional && isNullBranch(branch)));+ const kept = branches.length > 1 && branches.some((branch) => !isJsonText(branch)) ? branches.filter((branch) => !isJsonText(branch)) : branches;+ const { anyOf: _anyOf, ...rest } = result;+ const only = kept.length === 1 ? kept[0] : mergedTaggedObjects(kept);+ result = isObject(only) ? { ...only, ...rest } : { ...rest, anyOf: kept };+ }+ return result;+}++/** `schema` with the rules above applied at every level; a new object, `schema` untouched. */+export function compactAdvertisedSchema(schema: Json): Json {+ return compact(schema, false) as Json;+}diff --git a/server/drivers/acp/core.ts b/server/drivers/acp/core.tsindex b8f4516f39..59e4d22732 100644--- a/server/drivers/acp/core.ts+++ b/server/drivers/acp/core.ts@@ -205,7 +205,7 @@ export interface AcpSupport extends AcpDriverHooks {/** Made once per process: rewrites a session/update before the turn reads it, or drops it by returning null; `calls` is this session's tool-call record, shared with permissionRequest. */updateFilter?(calls: Map<string, Record<string, any>>): (update: Record<string, any>) => Record<string, any> | null; /** Rewrites a session/request_permission's params (its options and tool call) before the card is built, with the tool calls this session's filter recorded. */ permissionRequest?(params: Record<string, any>, calls: ReadonlyMap<string, Record<string, any>>): Record<string, any>;/** OpenMausBot's own MCP servers as this server's endpoints, no process each: always, or in each session whose agent's `initialize` says it reaches MCP servers by URL. */- ownMcpOverHttp?: boolean | "advertised"; /** Under `ownMcpOverHttp: "advertised"`, whether an agent whose `initialize` advertises no MCP transport reaches MCP servers by URL anyway. */ takesUnadvertisedHttpMcp?(init: unknown): boolean;+ ownMcpOverHttp?: boolean | "advertised"; /** Under `ownMcpOverHttp: "advertised"`, whether an agent whose `initialize` advertises no MCP transport reaches MCP servers by URL anyway. */ takesUnadvertisedHttpMcp?(init: unknown): boolean; /** The agent's budget in bytes for all of a session's MCP tool definitions, by its `initialize` answer: OpenMausBot's own servers share it out. */ sessionToolBudget?(init: unknown): number | undefined;/** How many tools the agent lists of its own beside the MCP servers', counted against a provider's tool limit. */engineTools?: number;/** The agent's own debug log, read while a prompt is quiet: a new line proves it alive and `parse`@@ -1136,7 +1136,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>link: session.acp, sessionId: cursor, quietMs: support.loadReplayQuietMs?.(turn), replayed: () => session.sessionConfigResult ?? {},send: (receive) => request(support.resumeMethod === "resume" ? "session/resume" : "session/load",- { sessionId: cursor, cwd, mcpServers: support.mcpServersFromLaunch ? [] : acpSessionMcpServers(mcpServers, ownMcp, init, support.takesUnadvertisedHttpMcp), ...selectionParams, ...support.sessionSetupParams?.(init, heldSystem()) },+ { sessionId: cursor, cwd, mcpServers: support.mcpServersFromLaunch ? [] : acpSessionMcpServers(mcpServers, ownMcp, init, support.takesUnadvertisedHttpMcp, support.sessionToolBudget), ...selectionParams, ...support.sessionSetupParams?.(init, heldSystem()) },support.sessionSetupTimeoutMs ?? LOAD_SESSION_TIMEOUT, receive),receive: (result) => {if (result) {@@ -1179,7 +1179,7 @@ export function createAcpDriver(support: AcpSupport): ProviderDriver<AcpConfig>promptTurn = { ...turn, text: recovery.text };rebuiltFromReplay = recovery.replayed;}- await sessionNewRetried(() => request("session/new", { cwd, mcpServers: support.mcpServersFromLaunch ? [] : acpSessionMcpServers(mcpServers, ownMcp, init, support.takesUnadvertisedHttpMcp), ...selectionParams, ...support.sessionSetupParams?.(init, heldSystem()) }, support.sessionSetupTimeoutMs ?? NEW_SESSION_TIMEOUT, (result) => {+ await sessionNewRetried(() => request("session/new", { cwd, mcpServers: support.mcpServersFromLaunch ? [] : acpSessionMcpServers(mcpServers, ownMcp, init, support.takesUnadvertisedHttpMcp, support.sessionToolBudget), ...selectionParams, ...support.sessionSetupParams?.(init, heldSystem()) }, support.sessionSetupTimeoutMs ?? NEW_SESSION_TIMEOUT, (result) => {session.sessionId = typeof result?.sessionId === "string" ? result.sessionId : null;session.sessionKey = liveSessionKey(sessionKey, heldSystem());receiveModelVariants(result, true);diff --git a/server/drivers/agents-catalog-goldens/antigravity-cli.tools-list.json b/server/drivers/agents-catalog-goldens/antigravity-cli.tools-list.jsonnew file mode 100644index 0000000000..9210e45e5c--- /dev/null+++ b/server/drivers/agents-catalog-goldens/antigravity-cli.tools-list.json@@ -0,0 +1,2743 @@+{+ "agents": [+ {+ "name": "tool_result_read",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "id": {+ "type": "string"+ },+ "offset": {+ "type": "integer"+ }+ },+ "required": [+ "id"+ ]+ }+ },+ {+ "name": "list_room_targets",+ "inputSchema": {+ "type": "object",+ "properties": {},+ "additionalProperties": false+ }+ },+ {+ "name": "coordinate_bots",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "group_id": {+ "type": "string"+ },+ "bot_ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "message": {+ "type": "string"+ },+ "reason": {+ "type": "string"+ },+ "rework": {+ "type": "boolean"+ },+ "thread": {+ "type": "string"+ },+ "title": {+ "type": "string",+ "maxLength": 80+ },+ "in_my_folder": {+ "type": "boolean"+ },+ "reply": {+ "type": "string",+ "enum": [+ "resume",+ "none"+ ]+ },+ "consult": {+ "type": "boolean"+ },+ "done_when": {+ "type": "string"+ },+ "answers": {+ "type": "string"+ },+ "files": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "maxItems": 5+ }+ },+ "required": [+ "bot_ids",+ "message"+ ]+ }+ },+ {+ "name": "assignment_status",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "id": {+ "type": "string"+ },+ "wait_ms": {+ "type": "integer"+ }+ }+ }+ },+ {+ "name": "list_bots",+ "inputSchema": {+ "type": "object",+ "properties": {}+ }+ },+ {+ "name": "usage_limits",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "scope": {+ "type": "string",+ "enum": [+ "subscription",+ "bot"+ ],+ "default": "subscription"+ },+ "period": {+ "type": "string",+ "enum": [+ "today",+ "month"+ ]+ },+ "thread": {+ "type": "string",+ "enum": [+ "this"+ ]+ }+ }+ }+ },+ {+ "name": "list_rooms",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {}+ }+ },+ {+ "name": "select_computer",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "surface": {+ "type": "string",+ "enum": [+ "auto",+ "cloud",+ "vm",+ "local",+ "browser"+ ]+ }+ }+ }+ },+ {+ "name": "list_threads",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "page": {+ "type": "integer"+ }+ }+ }+ },+ {+ "name": "close_thread",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "thread_id": {+ "type": "string"+ }+ },+ "required": [+ "thread_id"+ ]+ }+ },+ {+ "name": "rename_thread",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "title": {+ "type": "string"+ }+ },+ "required": [+ "title"+ ]+ }+ },+ {+ "name": "run_workflow",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "name": {+ "type": "string",+ "maxLength": 64+ },+ "args": {+ "type": "object"+ },+ "resume": {+ "type": "string",+ "maxLength": 64+ },+ "response": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "workflow_edit",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "name": {+ "type": "string",+ "maxLength": 64+ },+ "action": {+ "type": "string",+ "enum": [+ "add_case",+ "remove_case",+ "set_when",+ "undo"+ ]+ },+ "decide": {},+ "case": {+ "type": "string",+ "maxLength": 40+ },+ "steps": {+ "type": "array",+ "maxItems": 20,+ "items": {+ "type": "object"+ }+ },+ "step": {+ "type": "string"+ },+ "when": {},+ "undo": {+ "type": "string",+ "maxLength": 64+ }+ },+ "required": [+ "name",+ "action"+ ]+ }+ },+ {+ "name": "start_thread",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "title": {+ "type": "string"+ },+ "message": {+ "type": "string"+ },+ "folder": {+ "type": "string"+ },+ "model_selection": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "instanceId": {+ "type": "string"+ },+ "model": {+ "type": "string"+ },+ "effort": {+ "type": "string"+ }+ },+ "required": [+ "instanceId",+ "model"+ ]+ },+ "report_back": {+ "type": "boolean"+ }+ },+ "required": [+ "title",+ "message"+ ]+ }+ },+ {+ "name": "burst",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "task": {+ "type": "string"+ },+ "instructions": {+ "type": "string"+ },+ "items": {+ "type": "array",+ "items": {+ "type": "string"+ },+ "minItems": 2+ }+ },+ "required": [+ "task",+ "instructions",+ "items"+ ]+ }+ },+ {+ "name": "list_models",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "search": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "vm_exec",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "command": {+ "type": "string"+ },+ "timeout_seconds": {+ "type": "integer"+ }+ },+ "required": [+ "command"+ ]+ }+ },+ {+ "name": "attach_file",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "path": {+ "type": "string"+ },+ "name": {+ "type": "string"+ }+ },+ "required": [+ "path"+ ]+ }+ },+ {+ "name": "show_widget",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "widget": {+ "type": "object"+ },+ "fallback_text": {+ "type": "string"+ },+ "widget_id": {+ "type": "string"+ }+ },+ "required": [+ "widget"+ ]+ }+ },+ {+ "name": "show_html",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "html": {+ "type": "string"+ },+ "jsx": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "title": {+ "type": "string"+ },+ "height": {+ "type": "number"+ },+ "fallback_text": {+ "type": "string"+ },+ "frameless": {+ "type": "boolean"+ },+ "live": {+ "type": "boolean"+ },+ "app_id": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "publish_page",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "path": {+ "type": "string"+ },+ "title": {+ "type": "string"+ },+ "page_id": {+ "type": "string",+ "pattern": "^[a-z0-9]{20,63}$"+ },+ "live": {+ "type": "boolean"+ }+ },+ "required": [+ "path",+ "title"+ ]+ }+ },+ {+ "name": "unpublish_page",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "page_id": {+ "type": "string",+ "pattern": "^[a-z0-9]{20,63}$"+ },+ "path": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "post_to_room",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "group_id": {+ "type": "string"+ },+ "message": {+ "type": "string"+ },+ "attach_voice_note": {+ "type": "boolean"+ },+ "mention_ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ },+ "required": [+ "group_id",+ "message"+ ]+ }+ },+ {+ "name": "post_to_thread",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "thread_id": {+ "type": "string"+ },+ "message": {+ "type": "string"+ },+ "wake": {+ "type": "boolean"+ },+ "delivery_id": {+ "type": "string",+ "maxLength": 100+ }+ },+ "required": [+ "thread_id",+ "message"+ ]+ }+ },+ {+ "name": "create_bot",+ "inputSchema": {+ "type": "object",+ "properties": {+ "name": {+ "type": "string"+ },+ "role": {+ "type": "string"+ },+ "instructions": {+ "type": "string"+ },+ "copy_from_bot_id": {+ "type": "string"+ },+ "modelSelection": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "instanceId": {+ "type": "string"+ },+ "model": {+ "type": "string"+ },+ "effort": {+ "type": "string"+ },+ "variant": {+ "type": "string"+ }+ },+ "required": [+ "instanceId",+ "model"+ ]+ },+ "cwd": {+ "type": "string"+ }+ },+ "required": [+ "name"+ ]+ }+ },+ {+ "name": "list_team_setup",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {}+ }+ },+ {+ "name": "list_team_library",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {}+ }+ },+ {+ "name": "propose_team_setup",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "reason": {+ "type": "string"+ },+ "newTeams": {+ "type": "array",+ "items": {+ "type": "string",+ "maxLength": 60+ }+ },+ "operations": {+ "type": "array",+ "items": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "create",+ "update"+ ]+ },+ "key": {+ "type": "string"+ },+ "botId": {+ "type": "string"+ },+ "fields": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "name": {+ "type": "string",+ "maxLength": 100+ },+ "title": {+ "type": "string"+ },+ "chiefOfStaff": {+ "type": "boolean"+ },+ "description": {+ "type": "string"+ },+ "soul": {+ "type": "string"+ },+ "soulAppend": {+ "type": "string"+ },+ "cwd": {+ "type": "string"+ },+ "section": {+ "type": "string",+ "maxLength": 60+ },+ "modelSelection": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "instanceId": {+ "type": "string"+ },+ "model": {+ "type": "string"+ },+ "effort": {+ "type": "string"+ },+ "variant": {+ "type": "string"+ }+ },+ "required": [+ "instanceId",+ "model"+ ]+ },+ "mcpServers": {+ "type": "array",+ "maxItems": 20,+ "items": {+ "type": "string"+ }+ }+ }+ }+ },+ "required": [+ "action",+ "fields"+ ]+ }+ }+ },+ "required": [+ "reason",+ "operations"+ ]+ }+ },+ {+ "name": "propose_bot_deletion",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "bot_id": {+ "type": "string"+ },+ "reason": {+ "type": "string"+ }+ },+ "required": [+ "bot_id",+ "reason"+ ]+ }+ },+ {+ "name": "manage_room",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "create",+ "add_members",+ "remove_members",+ "set_members",+ "rename",+ "set_bulletin",+ "new_thread"+ ]+ },+ "room_id": {+ "type": "string"+ },+ "name": {+ "type": "string",+ "maxLength": 100+ },+ "member_bot_ids": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "bulletin": {+ "type": "string"+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "request_credential",+ "inputSchema": {+ "type": "object",+ "properties": {+ "credential_id": {+ "type": "string",+ "enum": [+ "xaiApiKey",+ "boxToken",+ "opencodeGoApiKey",+ "ttsKey",+ "geminiTtsKey",+ "fishAudioKey",+ "openaiImageApiKey",+ "onePasswordToken",+ "composioApiKey",+ "openaiApiKey",+ "anthropicApiKey",+ "openrouterApiKey",+ "mistralApiKey",+ "cerebrasApiKey",+ "groqApiKey",+ "greenferenceApiKey",+ "modelgoApiKey",+ "metaApiKey",+ "deepseekApiKey",+ "email"+ ]+ },+ "address": {+ "type": "string"+ },+ "label": {+ "type": "string"+ },+ "reason": {+ "type": "string"+ },+ "placeholder": {+ "type": "string"+ },+ "delivery": {+ "type": "string",+ "enum": [+ "ref",+ "file"+ ]+ },+ "replace": {+ "type": "boolean"+ }+ }+ }+ },+ {+ "name": "request_sign_in",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "instruction": {+ "type": "string"+ },+ "kind": {+ "type": "string",+ "enum": [+ "sign_in",+ "captcha",+ "payment",+ "approval",+ "other"+ ]+ },+ "target": {+ "type": "string",+ "enum": [+ "browser",+ "computer"+ ]+ },+ "site": {+ "type": "string"+ }+ },+ "required": [+ "instruction",+ "kind"+ ]+ }+ },+ {+ "name": "fill_login",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "username": {+ "type": "string"+ },+ "email": {+ "type": "string"+ },+ "submit": {+ "type": "boolean"+ }+ }+ }+ },+ {+ "name": "decide",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "state": {+ "type": "string"+ },+ "questions": {+ "type": "object",+ "additionalProperties": {+ "type": "object"+ }+ }+ },+ "required": [+ "state",+ "questions"+ ]+ }+ },+ {+ "name": "extract",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "fields": {+ "type": "object",+ "additionalProperties": {+ "type": "object"+ }+ },+ "text": {+ "type": "string"+ },+ "file": {+ "type": "string"+ }+ },+ "required": [+ "fields"+ ]+ }+ },+ {+ "name": "what_changed",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "original_file": {+ "type": "string"+ },+ "edited_file": {+ "type": "string"+ },+ "original_text": {+ "type": "string"+ },+ "edited_text": {+ "type": "string"+ },+ "start": {+ "type": "integer"+ }+ }+ }+ },+ {+ "name": "message_person",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "to": {+ "type": "string"+ },+ "message": {+ "type": "string"+ }+ },+ "required": [+ "message"+ ]+ }+ },+ {+ "name": "report_bug",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "went_wrong": {+ "type": "string"+ },+ "you_saw": {+ "type": "string"+ },+ "steps": {+ "type": "string"+ }+ },+ "required": [+ "went_wrong"+ ]+ }+ },+ {+ "name": "share",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "export",+ "publish",+ "publish_to_repo",+ "add_to_team_library",+ "import",+ "list_team_library",+ "import_from_team_library"+ ]+ },+ "department": {+ "type": "boolean"+ },+ "url": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "slug": {+ "type": "string"+ },+ "repo": {+ "type": "string"+ },+ "direct": {+ "type": "boolean"+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "memory_update",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "append",+ "replace",+ "remove",+ "supersede",+ "forget",+ "prefer"+ ]+ },+ "text": {+ "type": "string"+ },+ "old_text": {+ "type": "string"+ },+ "until": {+ "type": "string",+ "pattern": "^\\d{4}-\\d{2}-\\d{2}$"+ },+ "scope": {+ "type": "string",+ "enum": [+ "thread",+ "everywhere"+ ]+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "retry_thread",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "bot_id": {+ "type": "string"+ },+ "thread_id": {+ "type": "string"+ },+ "note": {+ "type": "string"+ }+ },+ "required": [+ "bot_id",+ "thread_id"+ ]+ }+ },+ {+ "name": "memory_log",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "text": {+ "type": "string"+ }+ },+ "required": [+ "text"+ ]+ }+ },+ {+ "name": "session_search",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "query": {+ "type": "string"+ },+ "since": {+ "type": "string"+ },+ "until": {+ "type": "string"+ },+ "limit": {+ "type": "integer"+ },+ "scope": {+ "type": "string",+ "enum": [+ "all",+ "conversations",+ "memory",+ "team",+ "threads"+ ]+ },+ "thread_id": {+ "type": "string"+ },+ "message_id": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "trigger_info",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "list",+ "events"+ ]+ },+ "trigger_id": {+ "type": "string"+ },+ "include_address": {+ "type": "boolean"+ },+ "for_bot_id": {+ "type": "string"+ },+ "app": {+ "type": "string"+ },+ "search": {+ "type": "string"+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "trigger",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "create",+ "update",+ "pause",+ "resume",+ "run_now"+ ]+ },+ "trigger_id": {+ "type": "string"+ },+ "when": {+ "type": "string",+ "enum": [+ "schedule",+ "app_event",+ "webhook",+ "limit_reset"+ ]+ },+ "name": {+ "type": "string",+ "maxLength": 80+ },+ "instructions": {+ "type": "string"+ },+ "schedule": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "type": {+ "type": "string",+ "enum": [+ "once",+ "weekly",+ "daily",+ "interval",+ "cron"+ ]+ },+ "expression": {+ "type": "string"+ },+ "timeZone": {+ "type": "string",+ "maxLength": 128+ },+ "at": {+ "type": "string"+ },+ "time": {+ "type": "string"+ },+ "weekdays": {+ "type": "array",+ "items": {+ "type": "string",+ "enum": [+ "monday",+ "tuesday",+ "wednesday",+ "thursday",+ "friday",+ "saturday",+ "sunday"+ ]+ }+ },+ "every_minutes": {+ "type": "integer"+ },+ "starts_at": {+ "type": "string"+ },+ "window_start": {+ "type": "string"+ },+ "window_end": {+ "type": "string"+ },+ "ends_at": {+ "type": "string"+ },+ "every_day": {+ "type": "boolean"+ },+ "all_day": {+ "type": "boolean"+ },+ "never_ends": {+ "type": "boolean"+ }+ },+ "required": [+ "type"+ ]+ },+ "webhook_event_types": {+ "type": "array",+ "maxItems": 20,+ "items": {+ "type": "string"+ }+ },+ "webhook_payload_filter": {+ "type": "object",+ "maxProperties": 10,+ "additionalProperties": {+ "type": "string"+ }+ },+ "filter": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "from": {+ "type": "string"+ },+ "subject_contains": {+ "type": "string"+ },+ "label": {+ "type": "string"+ },+ "contains": {+ "type": "string"+ }+ }+ },+ "event_config": {+ "type": "object"+ },+ "run_on": {+ "type": "string",+ "enum": [+ "maus",+ "box"+ ]+ },+ "timeout_minutes": {+ "type": "integer"+ },+ "clear_timeout": {+ "type": "boolean"+ },+ "same_conversation": {+ "type": "boolean"+ },+ "continuity": {+ "type": "boolean"+ },+ "overlap": {+ "type": "string",+ "enum": [+ "skip",+ "queue"+ ]+ },+ "run_on_startup": {+ "type": "boolean"+ },+ "app": {+ "type": "string"+ },+ "event": {+ "type": "string"+ },+ "account": {+ "type": "string"+ },+ "engine": {+ "type": "string"+ },+ "repeat": {+ "type": "string",+ "enum": [+ "once",+ "every_reset"+ ]+ },+ "for_bot_id": {+ "type": "string"+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "delete_trigger",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "trigger_id": {+ "type": "string"+ },+ "for_bot_id": {+ "type": "string"+ }+ },+ "required": [+ "trigger_id"+ ]+ }+ },+ {+ "name": "wait_until",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "label": {+ "type": "string",+ "maxLength": 120+ },+ "kind": {+ "type": "string",+ "enum": [+ "url_contains",+ "url_missing",+ "file_exists",+ "file_missing",+ "file_changed",+ "process_running",+ "process_gone",+ "bot_idle"+ ]+ },+ "url": {+ "type": "string"+ },+ "text": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "process": {+ "type": "string"+ },+ "bot": {+ "type": "string"+ },+ "follow_up": {+ "type": "string"+ },+ "hours": {+ "type": "integer"+ }+ },+ "required": [+ "label",+ "kind"+ ]+ }+ },+ {+ "name": "list_waits",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {}+ }+ },+ {+ "name": "cancel_wait",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "id": {+ "type": "string"+ }+ },+ "required": [+ "id"+ ]+ }+ },+ {+ "name": "check_back",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "when": {+ "type": "string"+ },+ "note": {+ "type": "string"+ },+ "if": {+ "type": "string"+ },+ "cancel": {+ "type": "string"+ }+ }+ }+ },+ {+ "name": "propose_profile",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "name": {+ "type": "string",+ "maxLength": 100+ },+ "title": {+ "type": "string"+ },+ "description": {+ "type": "string"+ },+ "soul": {+ "type": "string"+ },+ "cwd": {+ "type": "string"+ },+ "notifications": {+ "type": "boolean"+ },+ "speakReplies": {+ "type": "boolean"+ },+ "browserProfile": {+ "type": "string",+ "maxLength": 100+ },+ "reason": {+ "type": "string"+ },+ "for_bot_id": {+ "type": "string"+ }+ },+ "required": [+ "reason"+ ]+ }+ },+ {+ "name": "propose_model",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "model_selection": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "instanceId": {+ "type": "string"+ },+ "model": {+ "type": "string"+ },+ "effort": {+ "type": "string"+ },+ "variant": {+ "type": "string"+ }+ },+ "required": [+ "instanceId",+ "model"+ ]+ },+ "reason": {+ "type": "string"+ },+ "for_bot_id": {+ "type": "string"+ }+ },+ "required": [+ "model_selection",+ "reason"+ ]+ }+ },+ {+ "name": "propose_team_memory",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "kind": {+ "type": "string",+ "enum": [+ "person",+ "place",+ "decision",+ "term"+ ]+ },+ "name": {+ "type": "string",+ "maxLength": 120+ },+ "detail": {+ "type": "string"+ },+ "aliases": {+ "type": "array",+ "maxItems": 8,+ "items": {+ "type": "string",+ "maxLength": 120+ }+ },+ "key": {+ "type": "string"+ }+ },+ "required": [+ "kind",+ "name",+ "detail"+ ]+ }+ },+ {+ "name": "mcp_server",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "list",+ "add",+ "update",+ "enable",+ "disable",+ "restart",+ "test",+ "sign_in",+ "sign_out",+ "remove"+ ]+ },+ "name": {+ "type": "string"+ },+ "command": {+ "type": "string"+ },+ "args": {+ "type": "array",+ "items": {+ "type": "string"+ }+ },+ "env": {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ "url": {+ "type": "string"+ },+ "type": {+ "type": "string",+ "enum": [+ "http",+ "sse"+ ]+ },+ "headers": {+ "type": "object",+ "additionalProperties": {+ "type": "string"+ }+ },+ "oauth": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "clientId": {+ "type": "string"+ },+ "clientSecret": {+ "type": "string"+ },+ "scopes": {+ "type": "array",+ "items": {+ "type": "string"+ }+ }+ },+ "required": [+ "clientId"+ ]+ }+ },+ "required": [+ "action"+ ]+ }+ },+ {+ "name": "app_settings",+ "inputSchema": {+ "type": "object",+ "additionalProperties": false,+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "find",+ "get",+ "set",+ "show_card",+ "places",+ "theme",+ "set_theme",+ "add_theme_asset",+ "theme_history",+ "undo_theme"+ ]+ },+ "query": {+ "type": "string"+ },+ "id": {+ "type": "string",+ "maxLength": 80+ },+ "value": {+ "type": "string"+ },+ "reason": {+ "type": "string"+ },+ "card": {+ "type": "string",+ "enum": [+ "other-computers",+ "ai-sign-in"+ ]+ },+ "theme": {+ "type": "string"+ },+ "path": {+ "type": "string"+ },+ "steps": {+ "type": "integer"+ },+ "index": {+ "type": "integer"+ }+ },+ "required": [+ "action"+ ]+ }+ }+ ],+ "browser": [+ {+ "name": "agent_browser_status",+ "inputSchema": {+ "type": "object",+ "properties": {+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_open",+ "inputSchema": {+ "type": "object",+ "properties": {+ "url": {+ "type": "string",+ "maxLength": 8192+ },+ "tab": {+ "type": "string",+ "pattern": "^(?:new|t[1-9]\\d{0,8})$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_navigate",+ "inputSchema": {+ "type": "object",+ "properties": {+ "url": {+ "type": "string",+ "maxLength": 8192+ },+ "action": {+ "type": "string",+ "enum": [+ "back",+ "forward",+ "reload"+ ]+ },+ "readiness": {+ "type": "string",+ "enum": [+ "load",+ "domcontentloaded",+ "networkidle",+ "none"+ ]+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_snapshot",+ "inputSchema": {+ "type": "object",+ "properties": {+ "includeImage": {+ "type": "boolean"+ },+ "save": {+ "type": "boolean"+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_read",+ "inputSchema": {+ "type": "object",+ "properties": {+ "url": {+ "type": "string",+ "maxLength": 8192+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "offset": {+ "type": "integer",+ "minimum": 0,+ "maximum": 10000000+ },+ "maxChars": {+ "type": "integer",+ "minimum": 1,+ "maximum": 40000+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_screenshot",+ "inputSchema": {+ "type": "object",+ "properties": {+ "fullPage": {+ "type": "boolean"+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_click",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "x": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "y": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "button": {+ "type": "string",+ "enum": [+ "left",+ "right",+ "middle"+ ]+ },+ "clickCount": {+ "type": "integer",+ "minimum": 1,+ "maximum": 3+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_fill",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "text": {+ "type": "string",+ "maxLength": 100000+ },+ "submit": {+ "type": "boolean"+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "text"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_type",+ "inputSchema": {+ "type": "object",+ "properties": {+ "text": {+ "type": "string",+ "maxLength": 100000+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "clear": {+ "type": "boolean"+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "text"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_press",+ "inputSchema": {+ "type": "object",+ "properties": {+ "key": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "modifiers": {+ "maxItems": 4,+ "type": "array",+ "items": {+ "type": "string",+ "enum": [+ "Alt",+ "Control",+ "Meta",+ "Shift",+ "ControlOrMeta"+ ]+ }+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "key"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_select",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "values": {+ "minItems": 1,+ "maxItems": 100,+ "type": "array",+ "items": {+ "type": "string",+ "maxLength": 1000+ }+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "values"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_check",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "checked": {+ "type": "boolean"+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_hover",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "x": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "y": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_drag",+ "inputSchema": {+ "type": "object",+ "properties": {+ "from": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "x": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "y": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ }+ },+ "additionalProperties": false+ },+ "to": {+ "type": "object",+ "properties": {+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "x": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ },+ "y": {+ "type": "number",+ "minimum": 0,+ "maximum": 16384+ }+ },+ "additionalProperties": false+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "from",+ "to"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_scroll",+ "inputSchema": {+ "type": "object",+ "properties": {+ "dx": {+ "type": "number",+ "minimum": -100000,+ "maximum": 100000+ },+ "dy": {+ "type": "number",+ "minimum": -100000,+ "maximum": 100000+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_upload",+ "inputSchema": {+ "type": "object",+ "properties": {+ "files": {+ "minItems": 1,+ "maxItems": 10,+ "type": "array",+ "items": {+ "type": "string",+ "minLength": 1,+ "maxLength": 4096+ }+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "files"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_wait",+ "inputSchema": {+ "type": "object",+ "properties": {+ "ms": {+ "type": "integer",+ "minimum": 0,+ "maximum": 60000+ },+ "text": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2000+ },+ "ref": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64+ },+ "selector": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "gone": {+ "type": "boolean"+ },+ "urlIncludes": {+ "type": "string",+ "minLength": 1,+ "maxLength": 2048+ },+ "load": {+ "type": "string",+ "enum": [+ "load",+ "domcontentloaded",+ "networkidle"+ ]+ },+ "timeoutMs": {+ "type": "integer",+ "minimum": 0,+ "maximum": 60000+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_eval",+ "inputSchema": {+ "type": "object",+ "properties": {+ "expression": {+ "type": "string",+ "minLength": 1,+ "maxLength": 64000+ },+ "world": {+ "type": "string",+ "enum": [+ "isolated",+ "page"+ ]+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "expression"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_dialog",+ "inputSchema": {+ "type": "object",+ "properties": {+ "accept": {+ "type": "boolean"+ },+ "promptText": {+ "type": "string",+ "maxLength": 4000+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "accept"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_tabs",+ "inputSchema": {+ "type": "object",+ "properties": {+ "action": {+ "type": "string",+ "enum": [+ "list",+ "new",+ "switch",+ "close"+ ]+ },+ "url": {+ "type": "string",+ "maxLength": 8192+ },+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "required": [+ "action"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "agent_browser_close",+ "inputSchema": {+ "type": "object",+ "properties": {+ "tab": {+ "type": "string",+ "pattern": "^t[1-9]\\d{0,8}$"+ }+ },+ "additionalProperties": false+ }+ },+ {+ "name": "restart_browser",+ "inputSchema": {+ "type": "object",+ "properties": {},+ "additionalProperties": false+ }+ }+ ],+ "data": [+ {+ "name": "data_load",+ "inputSchema": {+ "type": "object",+ "properties": {+ "source": {+ "type": "string",+ "minLength": 1,+ "maxLength": 4000+ },+ "name": {+ "type": "string",+ "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,62}$"+ },+ "kind": {+ "type": "string",+ "enum": [+ "auto",+ "csv",+ "tsv",+ "parquet",+ "json",+ "xlsx",+ "sqlite",+ "folder",+ "url",+ "postgres",+ "mysql",+ "gsheet"+ ]+ },+ "sheet": {+ "type": "string",+ "maxLength": 200+ },+ "replace": {+ "type": "boolean"+ },+ "options": {+ "type": "object",+ "properties": {+ "header": {+ "type": "boolean"+ },+ "delimiter": {+ "type": "string",+ "minLength": 1,+ "maxLength": 4+ },+ "union_by_name": {+ "type": "boolean"+ },+ "all_varchar": {+ "type": "boolean"+ },+ "ignore_errors": {+ "type": "boolean"+ },+ "sample_size": {+ "type": "integer",+ "minimum": -1,+ "maximum": 10000000+ }+ },+ "additionalProperties": false+ }+ },+ "required": [+ "source"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "data_describe",+ "inputSchema": {+ "type": "object",+ "properties": {+ "target": {+ "type": "string",+ "minLength": 1,+ "maxLength": 20000+ },+ "id": {+ "type": "string",+ "pattern": "^c_[0-9]+$"+ }+ },+ "required": [],+ "additionalProperties": false+ }+ },+ {+ "name": "data_sql",+ "inputSchema": {+ "type": "object",+ "properties": {+ "sql": {+ "type": "string",+ "minLength": 1,+ "maxLength": 100000+ },+ "limit": {+ "type": "integer",+ "minimum": 1,+ "maximum": 500+ },+ "name": {+ "type": "string",+ "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,62}$"+ }+ },+ "required": [+ "sql"+ ],+ "additionalProperties": false+ }+ },+ {+ "name": "data_show",+ "inputSchema": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string",+ "pattern": "^c_[0-9]+$"+ },+ "title": {+ "type": "string",+ "maxLength": 200+ },+ "sql": {+ "type": "string",+ "minLength": 1,+ "maxLength": 100000+ },+ "table": {+ "type": "string",+ "minLength": 1,+ "maxLength": 300+ },+ "kind": {+ "type": "string",+ "enum": [+ "table",+ "chart"+ ]+ },+ "chart": {+ "type": "object",+ "properties": {+ "type": {+ "type": "string",+ "enum": [+ "bar",+ "line",+ "area",+ "scatter",+ "histogram",+ "pie",+ "heatmap"+ ]+ },+ "x": {+ "type": "string",+ "maxLength": 200+ },+ "y": {+ "type": "string",+ "maxLength": 200+ },+ "color": {+ "type": "string",+ "maxLength": 200+ },+ "agg": {+ "type": "string",+ "enum": [+ "count",+ "sum",+ "avg",+ "min",+ "max",+ "median"+ ]+ },+ "sort": {+ "type": "string",+ "enum": [+ "x",+ "-x",+ "y",+ "-y"+ ]+ },+ "limit": {+ "type": "integer",+ "minimum": 1,+ "maximum": 1000+ },+ "stack": {+ "type": "boolean"+ },+ "timeUnit": {+ "type": "string",+ "enum": [+ "hour",+ "day",+ "week",+ "month",+ "quarter",+ "year"+ ]+ },+ "bins": {+ "type": "integer",+ "minimum": 2,+ "maximum": 500+ },+ "size": {+ "type": "string",+ "maxLength": 200+ }+ },+ "required": [+ "type",+ "x"+ ],+ "additionalProperties": false+ },+ "vegaLite": {+ "type": "object"+ },+ "limit": {+ "type": "integer",+ "minimum": 1,+ "maximum": 1000000+ }+ },+ "required": [],+ "additionalProperties": false+ }+ },+ {+ "name": "data_export",+ "inputSchema": {+ "type": "object",+ "properties": {+ "id": {+ "type": "string",+ "pattern": "^c_[0-9]+$"+ },+ "table": {+ "type": "string",+ "minLength": 1,+ "maxLength": 300+ },+ "sql": {+ "type": "string",+ "minLength": 1,+ "maxLength": 100000+ },+ "format": {+ "type": "string",+ "enum": [+ "csv",+ "parquet",+ "xlsx",+ "png",+ "svg"+ ]+ },+ "path": {+ "type": "string",+ "minLength": 1,+ "maxLength": 4000+ }+ },+ "required": [+ "format"+ ],+ "additionalProperties": false+ }+ }+ ]+}diff --git a/server/drivers/agents-mcp.ts b/server/drivers/agents-mcp.tsindex ecf6b49d9a..abed523dec 100644--- a/server/drivers/agents-mcp.ts+++ b/server/drivers/agents-mcp.ts@@ -2,6 +2,8 @@// harness sets for it (see agents-proxy.ts): the stdio proxy an engine starts and the HTTP endpoint an engine reaches// both answer through it.import { resolveAgentsCall } from "../../shared/agents-tool-names.ts";+import { TOOL_SCHEMA_PROFILE_ENV } from "../tool-schema-profile.ts";+import { toolsForShareProfile, type ListedTool } from "../tool-list-budget.ts";import { TOOL_BRIDGE_ENV, createToolBridge } from "./agents-bridge.ts";import { availableTools, catalogProfileFromEnv } from "./agents-catalog.ts";import { DEFER_TOOLS_ENV, withDeferMarks } from "./agents-claude-defer.ts";@@ -16,7 +18,9 @@ export function agentsToolList(env: NodeJS.ProcessEnv) {const profile = catalogProfileFromEnv(env);const available = availableTools(profile);const bridge = env[TOOL_BRIDGE_ENV] === "1" ? createToolBridge(available) : undefined;- return { available, bridge, listed: bridge ? bridge.listed : env[DEFER_TOOLS_ENV] === "1" ? withDeferMarks(available, profile.chief) : available };+ const listed = bridge ? bridge.listed : env[DEFER_TOOLS_ENV] === "1" ? withDeferMarks(available, profile.chief) : available;+ // A share of the session's tool budget fits only what is shown; calls are checked against `available` as they are.+ return { available, bridge, listed: toolsForShareProfile(listed as readonly ListedTool[], env[TOOL_SCHEMA_PROFILE_ENV], (line) => console.warn(`[agents] ${line}`)) as typeof listed };}export function agentsMcp(env: NodeJS.ProcessEnv): (msg: Json) => Promise<Json | undefined> {diff --git a/server/drivers/antigravity-acp.ts b/server/drivers/antigravity-acp.tsindex 89173d8fed..5bb00688d6 100644--- a/server/drivers/antigravity-acp.ts+++ b/server/drivers/antigravity-acp.ts@@ -32,6 +32,7 @@ import { delimiter, isAbsolute, join, resolve } from "node:path";import { DATA_DIR, stripWorkspaceCredentialEnv } from "../config.ts";import { writeFileAtomic } from "../atomic.ts";+import { ANTIGRAVITY_CLI_TOOL_BUDGET } from "../tool-list-budget.ts";import { killCliTree, spawnCli } from "../procs.ts";import { BOX_SSH_CONNECTION } from "../bot-box/env.ts";import type { BoxRelay } from "../bot-box/relay.ts";@@ -789,6 +790,12 @@ export function antigravityCliTakesHttpMcp(initialized: unknown): boolean {return (initialized as { agentInfo?: { name?: unknown } } | null | undefined)?.agentInfo?.name === "Antigravity ACP Server";}+/** The native CLI shows the model every MCP tool of a session and, past one budget for all their definitions, leaves out+ * the largest silently (google-antigravity/antigravity-cli#1530); agy_acp_server lists them lazily and has none. */+export function antigravityCliToolBudget(initialized: unknown): number | undefined {+ return antigravityCliTakesHttpMcp(initialized) ? ANTIGRAVITY_CLI_TOOL_BUDGET : undefined;+}+/** The agy CLI has no harness sibling and serves ACP through its `acp` subcommand. It joins `--app-data-dir` beneath* `--gemini-dir`, including when the value is absolute. */export function antigravityLaunchArgs(runtime: Pick<AntigravityRuntime, "harnessPath">, profileDirectory: string, platform: NodeJS.Platform = process.platform): string[] {diff --git a/server/drivers/antigravity-native-cli.test.ts b/server/drivers/antigravity-native-cli.test.tsindex 9cbc548ac6..aa4458ba4c 100644--- a/server/drivers/antigravity-native-cli.test.ts+++ b/server/drivers/antigravity-native-cli.test.ts@@ -506,10 +506,13 @@ describe.skipIf(WINDOWS)("a native CLI set as the engine's own path", () => {const byName = Object.fromEntries(sent.map((server) => [server.name, server])) as Record<string, { command?: string; args?: string[]; env?: Array<{ name: string; value: string }> }>;if (own === "url") {expect(byName.agents).toMatchObject({ type: "http", url: `${harness}/api/internal/mcp-http/agents` });- expect(byName.browser).toEqual({ type: "http", name: "browser", url: `${harness}/api/internal/mcp-http/browser`, headers: [{ name: "authorization", value: "Bearer synthetic-browser-capability" }] });+ // With its share of the CLI's session-wide tool budget.+ expect(byName.browser).toEqual({ type: "http", name: "browser", url: `${harness}/api/internal/mcp-http/browser`,+ headers: [{ name: "authorization", value: "Bearer synthetic-browser-capability" }, { name: "x-omb-tool-share", value: expect.stringMatching(/^listShare:\d+$/) }] });} else {expect(byName.agents).toMatchObject({ command: process.execPath, args: agents.args });expect(byName.browser).toMatchObject({ command: process.execPath, args: browser.args });+ expect(JSON.stringify([byName.agents, byName.browser])).not.toContain("listShare:");}expect(byName.composio).toMatchObject({ command: process.execPath, args: composio.args });expect(byName.notes!.command).toBe(process.execPath);diff --git a/server/drivers/antigravity.ts b/server/drivers/antigravity.tsindex a1e20759cc..a09e620273 100644--- a/server/drivers/antigravity.ts+++ b/server/drivers/antigravity.ts@@ -21,6 +21,7 @@ import { classifyError } from "./retry.ts";import {antigravityCliSessionMode,antigravityCliTakesHttpMcp,+ antigravityCliToolBudget,antigravityClientInfo,antigravityLaunchArgs,antigravityProfileAuthenticated,@@ -213,6 +214,7 @@ const support: AcpSupport = {// Only the native CLI takes them; agy_acp_server keeps its stdio proxies.ownMcpOverHttp: "advertised",takesUnadvertisedHttpMcp: antigravityCliTakesHttpMcp,+ sessionToolBudget: antigravityCliToolBudget,clientReadRoots: (turn) => (turn.skillFiles ?? []).map(dirname),sanitizeToolPayload: true,updateFilter: antigravityUpdateFilter,diff --git a/server/drivers/own-mcp-http.ts b/server/drivers/own-mcp-http.tsindex 2a79c1ff32..b35ac74ecd 100644--- a/server/drivers/own-mcp-http.ts+++ b/server/drivers/own-mcp-http.ts@@ -7,6 +7,7 @@// port is the box's bridge to the harness gate (bot-box/harness-gate.ts), which passes /api/internal/ only, and the box// keeps loopback out of its egress proxy (NO_PROXY).import { botBox } from "../bot-box/box.ts";+import { withSessionToolShares } from "./own-mcp-session-budget.ts";import { acpOwnServersOverHttp, ownMcpOverHttp, type AcpMcpServer } from "./turn-mcp.ts";/** "1" turns the URL form on for every engine that can take it; "0" keeps every engine on stdio proxies, the ACP agents@@ -76,8 +77,12 @@ export function acpAgentTakesHttpMcp(init: unknown): boolean {/** The servers a session/new or session/load sends: under `advertised`, OpenMausBot's own as this server's endpoints when* the session's agent takes them, by its `initialize` answer or, for an agent that takes them without saying so, by- * `takesUnadvertised`. Deciding here, after `initialize`, lets an agent's first session use the URL form too. */+ * `takesUnadvertised`. Deciding here, after `initialize`, lets an agent's first session use the URL form too. An agent+ * with a session-wide budget for tool definitions (`toolBudget`, by its `initialize` answer) has OpenMausBot's own servers+ * share it out, by URL or stdio alike. */export function acpSessionMcpServers(servers: AcpMcpServer[], transport: AcpOwnMcpTransport, init: unknown,- takesUnadvertised?: (init: unknown) => boolean): AcpMcpServer[] {- return transport === "advertised" && (acpAgentTakesHttpMcp(init) || takesUnadvertised?.(init) === true) ? acpOwnServersOverHttp(servers) : servers;+ takesUnadvertised?: (init: unknown) => boolean, toolBudget?: (init: unknown) => number | undefined): AcpMcpServer[] {+ const budget = toolBudget?.(init);+ const shared = budget === undefined ? servers : withSessionToolShares(servers, budget);+ return transport === "advertised" && (acpAgentTakesHttpMcp(init) || takesUnadvertised?.(init) === true) ? acpOwnServersOverHttp(shared) : shared;}diff --git a/server/drivers/own-mcp-session-budget.test.ts b/server/drivers/own-mcp-session-budget.test.tsnew file mode 100644index 0000000000..fca706146b--- /dev/null+++ b/server/drivers/own-mcp-session-budget.test.ts@@ -0,0 +1,245 @@+// The native Antigravity CLI's session budget over OpenMausBot's own tools. The golden pins the tool names and schemas,+// descriptions left out, that a default Chief of Staff's session with agents, browser and data shows that CLI; the+// budget itself is held by the tests, so rewording a description needs no new golden.+import { readFileSync, writeFileSync } from "node:fs";+import { dirname, join } from "node:path";+import { fileURLToPath } from "node:url";+import { describe, expect, it } from "vitest";++import { TOOL_LIST as BROWSER_TOOLS } from "../browser/tools.ts";+import { CLOUD_COMPUTER_TOOLS } from "../cloud-computer-tools.ts";+import { DATA_TOOLS } from "../data/tools.ts";+import { EMAIL_TOOLS } from "../email/tools.ts";+import { PHONE_TOOLS } from "../phones/tools.ts";+import { SPAWNED_PROXIES } from "../proxy-paths.ts";+import { AGENTS_ENV_HEADER, TOOL_SHARE_HEADER } from "../routes/own-mcp-http-path.ts";+import { cliDrops } from "../testing/cli-tool-drop.ts";+import {+ ANTIGRAVITY_CLI_TOOL_BUDGET, definitionListBytes, fitToolListToShare, PROTECTED_TOOLS, toolListShare, toolListShareProfile, type ListedTool,+} from "../tool-list-budget.ts";+import { fitToolListForBudget, TOOL_SCHEMA_PROFILE_ENV, toolSchemaProfileFromEnv } from "../tool-schema-profile.ts";+import type { SendTurnInput } from "../contracts.ts";+import { agentsToolList } from "./agents-mcp.ts";+import { antigravityCliToolBudget } from "./antigravity-acp.ts";+import { acpSessionMcpServers } from "./own-mcp-http.ts";+import { sessionToolShares, withSessionToolShares } from "./own-mcp-session-budget.ts";+import { acpMcpServers, type AcpMcpServer } from "./turn-mcp.ts";++const GOLDEN = join(dirname(fileURLToPath(import.meta.url)), "agents-catalog-goldens", "antigravity-cli.tools-list.json");+const UPDATE = process.env.UPDATE_AGENTS_CATALOG_GOLDENS === "1";+/** Where the CLI starts leaving out a session's ~80 tools: kept 58,699 bytes on 1.5.17, between 58,700 and 60,600 on 1.5.16. */+const CLI_DROP_FLOOR = 58_700;++const HARNESS = "http://127.0.0.1:8799";+const CHIEF = { OMB_CHIEF_OF_STAFF: "1", OMB_COMPUTER_SELECTION: "1" };+const NON_CHIEF = { OMB_CHIEF_OF_STAFF: "0", OMB_COMPUTER_SELECTION: "1" };+const FULLEST = { ...CHIEF, OMB_SKILL_AUTHORING_ENABLED: "1", OMB_SHARED_COMPUTERS_ENABLED: "1", OMB_VOICE_NOTES: "1", OMB_X_RESEARCH: "1",+ OMB_RESEARCH: "1", OMB_TEAM_PEOPLE: "1", OMB_IMAGE_GENERATION: "1", OMB_APP_HOSTING: "1" };+const agentsList = (env: Record<string, string>) => agentsToolList(env).listed as ListedTool[];+const catalog = (tools: unknown) => tools as readonly ListedTool[];++/** The lists a session shows the CLI: each fitted into the share the session gave it. */+function shown(lists: ReadonlyArray<readonly ListedTool[]>) {+ const { shares, fits } = sessionToolShares(lists, ANTIGRAVITY_CLI_TOOL_BUDGET);+ return { fits, lists: lists.map((tools, index) => fitToolListToShare(tools, shares[index]!)) };+}++const pairs = (record: Record<string, string>) => Object.entries(record).map(([name, value]) => ({ name, value }));+const agentsServer = (settings: Record<string, string>): AcpMcpServer => ({ name: "agents", command: process.execPath, args: [SPAWNED_PROXIES.agents],+ env: pairs({ OMB_HARNESS_URL: HARNESS, OMB_COMMS_TOKEN: "comms", OMB_BOT_ID: "b1", OMB_THREAD_ID: "t1", ...settings }) });+const harnessServer = (kind: string): AcpMcpServer => ({ name: kind, command: process.execPath, args: [SPAWNED_PROXIES.harnessMcp, kind],+ env: pairs({ OMB_HARNESS_URL: HARNESS, [`OMB_MCP_TOKEN_${kind.toUpperCase()}`]: `${kind}-capability` }) });+const notes: AcpMcpServer = { name: "notes", command: "npx", args: ["notes"], env: [] };+const nativeCli = { agentInfo: { name: "Antigravity ACP Server" } };+const oldRuntime = { agentInfo: { name: "antigravity-acp" } };+/** Every description in a schema, and the schema with none of them. */+function descriptionsIn(node: unknown): string[] {+ if (Array.isArray(node)) return node.flatMap(descriptionsIn);+ if (!node || typeof node !== "object") return [];+ return Object.entries(node).flatMap(([key, value]) => (key === "description" && typeof value === "string" ? [value] : descriptionsIn(value)));+}+function withoutDescriptions(node: unknown): unknown {+ if (Array.isArray(node)) return node.map(withoutDescriptions);+ if (!node || typeof node !== "object") return node;+ return Object.fromEntries(Object.entries(node).filter(([key, value]) => !(key === "description" && typeof value === "string")).map(([key, value]) => [key, withoutDescriptions(value)]));+}+const envOf = (server: AcpMcpServer) => ("env" in server ? Object.fromEntries(server.env.map(({ name, value }) => [name, value])) : {});++describe("a native Antigravity CLI session's own tools", () => {+ const cases: Array<[string, Record<string, string>, string[]]> = [];+ for (const [who, env] of [["non-Chief", NON_CHIEF], ["Chief", CHIEF], ["fullest Chief", FULLEST]] as const) {+ cases.push([`${who}: agents`, env, []], [`${who}: agents + browser`, env, ["browser"]], [`${who}: agents + browser + data`, env, ["browser", "data"]],+ [`${who}: agents + browser + data + cloud computer`, env, ["browser", "data", "computer"]]);+ }+ const catalogs: Record<string, readonly ListedTool[]> = { browser: catalog(BROWSER_TOOLS), data: catalog(DATA_TOOLS), computer: catalog(CLOUD_COMPUTER_TOOLS) };++ it.each(cases)("all reach the model, within the budget: %s", (_name, env, others) => {+ const lists = [agentsList(env), ...others.map((kind) => catalogs[kind]!)];+ const session = shown(lists);+ expect(session.fits).toBe(true);+ const tools = session.lists.flatMap((list) => list.tools);+ expect(definitionListBytes(tools)).toBeLessThanOrEqual(ANTIGRAVITY_CLI_TOOL_BUDGET);+ expect(cliDrops(tools, CLI_DROP_FLOOR)).toEqual([]);+ expect(tools.map((tool) => tool.name)).toEqual(lists.flat().map((tool) => tool.name));+ });++ // The guard that would have caught the bug: these lists as they were sent lose coordinate_bots, and a tool that pushes+ // the default Chief's session past what shortening can absorb fails here before it reaches anyone.+ it("a default Chief of Staff with browser and data loses tools to the CLI unfitted, and keeps every one fitted", () => {+ const lists = [agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)];+ expect(cliDrops(lists.flat(), CLI_DROP_FLOOR)).toContain("coordinate_bots");+ const session = shown(lists);+ expect(session.fits).toBe(true);+ expect(cliDrops(session.lists.flatMap((list) => list.tools), CLI_DROP_FLOOR)).toEqual([]);+ // Every tool description of 500 characters or less still whole: shorter means the lists grew; look before lowering.+ expect(session.lists[0]!.level.tools).toBeGreaterThanOrEqual(500);+ });++ it("even with every own server and the fullest Chief, the CLI's largest-first drop never takes a protected tool", () => {+ const lists = [agentsList(FULLEST), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS), catalog(CLOUD_COMPUTER_TOOLS), catalog(EMAIL_TOOLS), catalog(PHONE_TOOLS)];+ const tools = shown(lists).lists.flatMap((list) => list.tools);+ expect(tools.map((tool) => tool.name)).toEqual(lists.flat().map((tool) => tool.name));+ expect(cliDrops(tools, CLI_DROP_FLOOR).filter((name) => PROTECTED_TOOLS.includes(name))).toEqual([]);+ });++ it("matches the golden: a default Chief of Staff's agents, browser and data as the CLI is shown them, words aside", () => {+ const lists = [agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)];+ const { shares } = sessionToolShares(lists, ANTIGRAVITY_CLI_TOOL_BUDGET);+ // The agents list as its endpoint serves it under its share, the others as theirs fit their catalogs.+ const served = [agentsList({ ...CHIEF, [TOOL_SCHEMA_PROFILE_ENV]: toolListShareProfile(shares[0]!) }),+ fitToolListToShare(lists[1]!, shares[1]!).tools, fitToolListToShare(lists[2]!, shares[2]!).tools];+ // Every description shown is the start of the tool's own, cut at a sentence or a word.+ served.forEach((tools, index) => tools.forEach((tool, at) => {+ const original = lists[index]![at]!;+ expect(tool.name).toBe(original.name);+ const kept = (tool.description ?? "").replace(/…$/, "");+ expect(original.description?.startsWith(kept), tool.name).toBe(true);+ for (const text of descriptionsIn(tool.inputSchema)) expect(descriptionsIn(original.inputSchema).some((whole) => whole.startsWith(text.replace(/…$/, ""))), tool.name).toBe(true);+ }));+ // Pinned: each tool's name and schema, descriptions left out, so rewording a description never touches it.+ const pinned = Object.fromEntries(["agents", "browser", "data"].map((server, index) =>+ [server, served[index]!.map((tool) => ({ name: tool.name, inputSchema: withoutDescriptions(tool.inputSchema) }))]));+ const text = `${JSON.stringify(pinned, null, 2)}\n`;+ if (UPDATE) writeFileSync(GOLDEN, text);+ expect(text, "The native Antigravity CLI's tool schemas changed. If on purpose, regenerate the golden with "+ + "UPDATE_AGENTS_CATALOG_GOLDENS=1 ./node_modules/.bin/vitest run server/drivers/own-mcp-session-budget.test.ts and review its diff.")+ .toBe(readFileSync(GOLDEN, "utf8").replace(/\r\n/g, "\n"));+ });+});++describe("sharing out a session's budget", () => {+ it("gives each list what it comes to at one cut for all, plus its part of what is left, within the budget", () => {+ const lists = [agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)];+ const { shares, bytes, fits } = sessionToolShares(lists, ANTIGRAVITY_CLI_TOOL_BUDGET);+ expect(fits).toBe(true);+ expect(bytes).toBeLessThanOrEqual(ANTIGRAVITY_CLI_TOOL_BUDGET);+ expect(shares.reduce((sum, share) => sum + share, 0)).toBeLessThanOrEqual(ANTIGRAVITY_CLI_TOOL_BUDGET);+ expect(shares.every((share, index) => fitToolListToShare(lists[index]!, share).fits)).toBe(true);+ });++ it("gives lists that fit whole more than they need, and splits a budget they cannot fit by size", () => {+ const small = [{ name: "a", description: "x".repeat(100) }, { name: "b", description: "y".repeat(300) }];+ const { shares, fits } = sessionToolShares([small.slice(0, 1), small.slice(1)], 10_000);+ expect(fits).toBe(true);+ expect(shares[0]! + shares[1]!).toBeLessThanOrEqual(10_000);+ expect(shares[1]! / shares[0]!).toBeCloseTo(definitionListBytes(small.slice(1)) / definitionListBytes(small.slice(0, 1)), 1);+ const over = sessionToolShares([agentsList(FULLEST)], 10_000);+ expect(over).toMatchObject({ fits: false, shares: [10_000] });+ });++ it("sets OpenMausBot's own servers' shares in OMB_TOOL_SCHEMA_PROFILE, any earlier profile replaced, and leaves the person's servers alone", () => {+ const servers = [agentsServer({ ...CHIEF, [TOOL_SCHEMA_PROFILE_ENV]: "gemini" }), harnessServer("browser"), harnessServer("data"), notes];+ const shared = withSessionToolShares(servers, ANTIGRAVITY_CLI_TOOL_BUDGET);+ expect(shared[3]).toBe(notes);+ const shares = shared.slice(0, 3).map((server) => toolListShare(envOf(server)[TOOL_SCHEMA_PROFILE_ENV]));+ expect(shares).toEqual(sessionToolShares([agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)], ANTIGRAVITY_CLI_TOOL_BUDGET).shares);+ expect(shared.slice(0, 3).map((server) => ("env" in server ? server.env.filter(({ name }) => name === TOOL_SCHEMA_PROFILE_ENV).length : 0))).toEqual([1, 1, 1]);+ });++ it("logs one line when the session cannot fit, by how much, and which servers it did not count", () => {+ const logged: string[] = [];+ withSessionToolShares([agentsServer(FULLEST), ...["browser", "data", "computer", "email", "device"].map(harnessServer), notes], 40_000, (line) => logged.push(line));+ expect(logged).toEqual([expect.stringMatching(/^\[mcp\] this session's own MCP tools \(agents, browser, data, computer, email, device\) come to (\d+) bytes at their shortest, \d+ over the 40000-byte tool budget; the engine leaves out its largest tools first \(notes not counted\)$/)]);+ expect(withSessionToolShares([notes], 40_000, (line) => logged.push(line))).toEqual([notes]);+ expect(logged).toHaveLength(1);+ });+});++describe("which sessions share a budget", () => {+ const servers = [agentsServer(CHIEF), harnessServer("browser"), harnessServer("data"), notes];+ const takesUrls = () => true;++ it("only the native CLI's: the pinned runtime and every other agent send their servers as before", () => {+ expect(antigravityCliToolBudget(nativeCli)).toBe(ANTIGRAVITY_CLI_TOOL_BUDGET);+ for (const init of [oldRuntime, {}, null, { agentInfo: { name: "Google Antigravity" } }]) expect(antigravityCliToolBudget(init)).toBeUndefined();+ expect(acpSessionMcpServers(servers, "advertised", oldRuntime, takesUrls, antigravityCliToolBudget))+ .toEqual(acpSessionMcpServers(servers, "advertised", oldRuntime, takesUrls));+ expect(acpSessionMcpServers(servers, "stdio", oldRuntime, takesUrls, antigravityCliToolBudget)).toBe(servers);+ });++ it("reaches each own server by URL: the agents share in its settings header, each harness server's in its own header", () => {+ const sent = acpSessionMcpServers(servers, "advertised", nativeCli, takesUrls, antigravityCliToolBudget);+ const header = (server: AcpMcpServer, name: string) => ("headers" in server ? server.headers.find((entry) => entry.name === name)?.value : undefined);+ const agentsSettings = JSON.parse(Buffer.from(header(sent[0]!, AGENTS_ENV_HEADER)!, "base64url").toString("utf8")) as Record<string, string>;+ const expected = sessionToolShares([agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)], ANTIGRAVITY_CLI_TOOL_BUDGET).shares;+ expect(toolListShare(agentsSettings[TOOL_SCHEMA_PROFILE_ENV])).toBe(expected[0]);+ expect([header(sent[1]!, TOOL_SHARE_HEADER), header(sent[2]!, TOOL_SHARE_HEADER)].map(toolListShare)).toEqual(expected.slice(1));+ expect(sent[3]).toBe(notes);+ });++ it("reaches each own server as a stdio proxy too, with OMB_OWN_MCP_HTTP=0", () => {+ const sent = acpSessionMcpServers(servers, "stdio", nativeCli, takesUrls, antigravityCliToolBudget);+ expect(sent.slice(0, 3).map((server) => toolListShare(envOf(server)[TOOL_SCHEMA_PROFILE_ENV]))).toEqual(+ sessionToolShares([agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)], ANTIGRAVITY_CLI_TOOL_BUDGET).shares);+ });+});++describe("on Antigravity, beside the Gemini engines' schema profile", () => {+ // As the ACP driver builds an Antigravity turn's servers: every one carries the gemini profile, and the person's stdio+ // server goes through the MCP gate, which fits each of its tools.+ const turn = {+ threadId: "t1", text: "x",+ integrations: {+ agents: { command: process.execPath, args: [SPAWNED_PROXIES.agents], env: { OMB_HARNESS_URL: HARNESS, OMB_COMMS_TOKEN: "comms", OMB_BOT_ID: "b1", OMB_THREAD_ID: "t1", ...CHIEF } },+ browser: { command: process.execPath, args: [SPAWNED_PROXIES.harnessMcp, "browser"], env: { OMB_HARNESS_URL: HARNESS, OMB_MCP_TOKEN_BROWSER: "browser-capability" } },+ data: { command: process.execPath, args: [SPAWNED_PROXIES.harnessMcp, "data"], env: { OMB_HARNESS_URL: HARNESS, OMB_MCP_TOKEN_DATA: "data-capability" } },+ custom: { notes: { command: "npx", args: ["-y", "notes-mcp"], env: {} } },+ },+ } as SendTurnInput;+ const built = acpMcpServers(turn, { engine: "antigravityAgent" });+ const header = (server: AcpMcpServer, name: string) => ("headers" in server ? server.headers.find((entry) => entry.name === name)?.value : undefined);+ const settingsOf = (server: AcpMcpServer) => JSON.parse(Buffer.from(header(server, AGENTS_ENV_HEADER)!, "base64url").toString("utf8")) as Record<string, string>;++ it("starts from the gemini profile on every server, the person's behind the gate", () => {+ expect(built.map((server) => envOf(server)[TOOL_SCHEMA_PROFILE_ENV])).toEqual(["gemini", "gemini", "gemini", "gemini"]);+ expect((built[3] as { args: string[] }).args[0]).toBe(SPAWNED_PROXIES.mcpGate);+ });++ it("the native CLI: one trim of OpenMausBot's own servers, the session's shares in place of gemini, and the person's gate as it was", () => {+ const logged: string[] = [];+ const sent = acpSessionMcpServers(built, "advertised", nativeCli, () => true, antigravityCliToolBudget);+ const shares = sessionToolShares([agentsList(CHIEF), catalog(BROWSER_TOOLS), catalog(DATA_TOOLS)], ANTIGRAVITY_CLI_TOOL_BUDGET).shares;+ const agentsSettings = settingsOf(sent[0]!);+ expect(toolListShare(agentsSettings[TOOL_SCHEMA_PROFILE_ENV])).toBe(shares[0]);+ expect([header(sent[1]!, TOOL_SHARE_HEADER), header(sent[2]!, TOOL_SHARE_HEADER)].map(toolListShare)).toEqual(shares.slice(1));+ expect(JSON.stringify(sent.slice(0, 3))).not.toContain("gemini");+ expect(sent[3]).toBe(built[3]);+ // The agents endpoint under that share serves exactly the session's fit: gemini's own list budget does not run on top.+ const env = { ...agentsSettings, OMB_HARNESS_URL: HARNESS, OMB_COMMS_TOKEN: "comms" };+ const served = agentsToolList(env).listed as ListedTool[];+ expect(toolSchemaProfileFromEnv(env)).toBeUndefined();+ expect(fitToolListForBudget(served, toolSchemaProfileFromEnv(env), (line) => logged.push(line))).toEqual(served);+ expect(logged).toEqual([]);+ expect(definitionListBytes(served)).toBeLessThanOrEqual(shares[0]!);+ expect(served.map((tool) => tool.name)).toEqual(agentsList(CHIEF).map((tool) => tool.name));+ });++ it("the pinned runtime: every server keeps the gemini profile, and the agents list is gemini's fit alone", () => {+ const sent = acpSessionMcpServers(built, "advertised", oldRuntime, () => false, antigravityCliToolBudget);+ expect(sent).toBe(built);+ const env = envOf(sent[0]!);+ expect(agentsToolList(env).listed).toEqual(agentsToolList({ ...env, [TOOL_SCHEMA_PROFILE_ENV]: "" }).listed);+ expect(toolSchemaProfileFromEnv(env)?.id).toBe("gemini");+ });+});+diff --git a/server/drivers/own-mcp-session-budget.ts b/server/drivers/own-mcp-session-budget.tsnew file mode 100644index 0000000000..74b9fd1aa3--- /dev/null+++ b/server/drivers/own-mcp-session-budget.ts@@ -0,0 +1,76 @@+// One session's MCP tool budget shared out among OpenMausBot's own servers in it: the least cut that+// brings all of them under the budget together is found here, when the session's servers are sent, and each server gets+// what its list comes to at that cut plus its part of what is left, as its OMB_TOOL_SCHEMA_PROFILE. Each server then fits+// the list it really serves into that share: a browser engine listing more than the estimate here only cuts its own.+// The agents list is sized exactly; the others by the catalogs their endpoints serve (email and phone show fewer when+// the bot may use fewer, and agent-browser's own list replaces the browser catalog). The person's servers and the+// connected-apps server are not ours to trim and are not sized: their lists are only known once they answer.+import { TOOL_LIST as BROWSER_TOOLS } from "../browser/tools.ts";+import { CLOUD_COMPUTER_TOOLS } from "../cloud-computer-tools.ts";+import { DATA_TOOLS } from "../data/tools.ts";+import { EMAIL_TOOLS } from "../email/tools.ts";+import { PHONE_TOOLS } from "../phones/tools.ts";+import type { HarnessMcpKind } from "../harness-mcp-request.ts";+import { TOOL_SCHEMA_PROFILE_ENV } from "../tool-schema-profile.ts";+import {+ definitionListBytes, descriptionLevelFor, toolListShareProfile, withCompactSchemas, withDescriptionLevel, type ListedTool,+} from "../tool-list-budget.ts";+import { agentsToolList } from "./agents-mcp.ts";+import { ownMcpOverHttp, type AcpMcpServer } from "./turn-mcp.ts";++type OwnKind = "agents" | HarnessMcpKind;++const CATALOGS: Record<HarnessMcpKind, readonly ListedTool[]> = {+ browser: BROWSER_TOOLS, data: DATA_TOOLS as readonly ListedTool[], computer: CLOUD_COMPUTER_TOOLS as readonly ListedTool[],+ email: EMAIL_TOOLS as readonly ListedTool[], device: PHONE_TOOLS as readonly ListedTool[],+};++export interface SessionShares {+ /** Each list's share of the budget, in bytes, in the order given. */+ shares: number[];+ /** What the lists come to together at the cut found, and whether that is within the budget. */+ bytes: number;+ fits: boolean;+}++/** Shares of `budget` for `lists`: each list's bytes at the least cut that fits them all, plus its part of the rest. With+ * no cut that fits, each gets its part of the budget by its size at its shortest, and fits what it can. */+export function sessionToolShares(lists: ReadonlyArray<readonly ListedTool[]>, budget: number): SessionShares {+ const compacted = lists.map((tools) => withCompactSchemas(tools));+ const { level, fits } = descriptionLevelFor(compacted.flat(), budget);+ const sizes = compacted.map((tools) => definitionListBytes(withDescriptionLevel(tools, level)));+ const bytes = sizes.reduce((sum, size) => sum + size, 0);+ if (bytes === 0) return { shares: sizes, bytes, fits };+ const room = fits ? budget - bytes : budget;+ const shares = sizes.map((size) => Math.floor((fits ? size : 0) + room * (size / bytes)));+ return { shares, bytes, fits };+}++const pairsToRecord = (env: Array<{ name: string; value: string }>) => Object.fromEntries(env.map(({ name, value }) => [name, value]));++function ownKind(server: AcpMcpServer): { kind: OwnKind; env: Record<string, string> } | null {+ if (!("command" in server)) return null;+ const env = pairsToRecord(server.env);+ const url = ownMcpOverHttp({ ...server, env })?.url;+ const kind = url?.slice(url.lastIndexOf("/") + 1);+ return kind === "agents" || (kind !== undefined && kind in CATALOGS) ? { kind: kind as OwnKind, env } : null;+}++/** `servers` with each of OpenMausBot's own servers given its share of `budget`; every other server as it was. */+export function withSessionToolShares(servers: AcpMcpServer[], budget: number, log: (line: string) => void = (line) => console.warn(line)): AcpMcpServer[] {+ const own = servers.map((server) => ({ server, own: ownKind(server) })).filter((entry) => entry.own !== null);+ if (!own.length) return servers;+ const lists = own.map(({ own: found }) => (found!.kind === "agents" ? agentsToolList({ ...found!.env, [TOOL_SCHEMA_PROFILE_ENV]: undefined }).listed as ListedTool[] : CATALOGS[found!.kind as HarnessMcpKind]));+ const { shares, bytes, fits } = sessionToolShares(lists, budget);+ if (!fits) {+ const others = servers.filter((server) => !own.some((entry) => entry.server === server)).map((server) => server.name);+ log(`[mcp] this session's own MCP tools (${own.map(({ own: found }) => found!.kind).join(", ")}) come to ${bytes} bytes at their shortest, ${bytes - budget} over the ${budget}-byte tool budget; the engine leaves out its largest tools first${others.length ? ` (${others.join(", ")} not counted)` : ""}`);+ }+ const shareOf = new Map(own.map(({ server }, index) => [server, shares[index]!]));+ return servers.map((server) => {+ const share = shareOf.get(server);+ if (share === undefined || !("command" in server)) return server;+ const env = server.env.filter(({ name }) => name !== TOOL_SCHEMA_PROFILE_ENV);+ return { ...server, env: [...env, { name: TOOL_SCHEMA_PROFILE_ENV, value: toolListShareProfile(share) }] };+ });+}diff --git a/server/drivers/turn-mcp.ts b/server/drivers/turn-mcp.tsindex cd13bd6418..1182f860bf 100644--- a/server/drivers/turn-mcp.ts+++ b/server/drivers/turn-mcp.ts@@ -4,7 +4,8 @@ import type { SendTurnInput } from "../contracts.ts";import { canUseMcpServer } from "../../shared/tool-scope.ts";import { harnessMcpTokenEnv } from "../harness-mcp-token.ts";import { appMountFor, gateServer, mcpStdioServer, type AppMount } from "../mcp-gate-config.ts";-import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH } from "../routes/own-mcp-http-path.ts";+import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH, TOOL_SHARE_HEADER } from "../routes/own-mcp-http-path.ts";+import { toolListShare } from "../tool-list-budget.ts";import { TOOL_SCHEMA_PROFILE_ENV, toolSchemaProfileFor, type ToolSchemaProfileId } from "../tool-schema-profile.ts";import { AGENTS_MCP_ENV } from "./agents-mcp-env.ts";import { OWN_APPS_SERVER } from "../../shared/own-apps.ts";@@ -103,8 +104,9 @@ export function ownMcpOverHttp(server: TurnStdioMcpServer): { url: string; headeconst kind = HARNESS_KINDS.find((candidate) => candidate === server.args[script + 1]);const token = kind && server.env[harnessMcpTokenEnv(kind)];const limit = server.env[TOOL_LIMIT_ENV];+ const share = toolListShare(server.env[TOOL_SCHEMA_PROFILE_ENV]) === undefined ? undefined : server.env[TOOL_SCHEMA_PROFILE_ENV];return kind && token ? { url: `${harness}${OWN_MCP_HTTP_PATH}${kind}`,- headers: { authorization: `Bearer ${token}`, ...(limit === undefined ? {} : { [TOOL_LIMIT_HEADER]: limit }) } } : null;+ headers: { authorization: `Bearer ${token}`, ...(limit === undefined ? {} : { [TOOL_LIMIT_HEADER]: limit }), ...(share === undefined ? {} : { [TOOL_SHARE_HEADER]: share }) } } : null;}/** The turn's MCP servers as ACP session/new takes them. stdio is the baseline every ACP agent supports; an agent thatdiff --git a/server/harness-mcp-proxy.test.ts b/server/harness-mcp-proxy.test.tsindex d4dda53d46..cee7afad95 100644--- a/server/harness-mcp-proxy.test.ts+++ b/server/harness-mcp-proxy.test.ts@@ -48,6 +48,18 @@ describe("harness MCP capability proxy", () => {await expect(harnessMcpRequest(frame("tools/call", { name: "agent_browser_snapshot" }), connection())).resolves.toMatchObject({ result: { content: [{ type: "image", data: "jpeg" }] } });});+ it("fits the listed tools into the session's share it was given, and only then; calls are relayed as they are", async () => {+ status = 200;+ const tool = { name: "data_sql", description: "Run SQL. It reads the bot's tables.", inputSchema: { type: "object", additionalProperties: true, properties: { sql: { type: "string", description: "One statement." } } } };+ payload = { result: { tools: [tool], instructions: "DuckDB" } };+ await expect(harnessMcpRequest(frame("tools/list"), { ...connection("data"), schemaProfile: "moonshot" })).resolves.toEqual({ jsonrpc: "2.0", id: 1, result: { tools: [tool], instructions: "DuckDB" } });+ await expect(harnessMcpRequest(frame("tools/list"), { ...connection("data"), schemaProfile: "listShare:100" })).resolves.toEqual({ jsonrpc: "2.0", id: 1, result: {+ instructions: "DuckDB", tools: [{ name: "data_sql", description: tool.description, inputSchema: { type: "object", properties: { sql: { type: "string" } } } }] } });+ payload = { result: { content: [{ type: "text", text: "1 row" }] } };+ await expect(harnessMcpRequest(frame("tools/call", { name: "data_sql", arguments: { sql: "select 1" } }), { ...connection("data"), schemaProfile: "listShare:100" }))+ .resolves.toEqual({ jsonrpc: "2.0", id: 1, result: { content: [{ type: "text", text: "1 row" }] } });+ });+it("sends Email calls to their own harness route with the Email instructions", async () => {status = 200;payload = { result: { tools: [{ name: "EMAIL_READ_MESSAGE" }], instructions: "mail" } };diff --git a/server/harness-mcp-proxy.ts b/server/harness-mcp-proxy.tsindex 31b34a6bb9..15902fc8df 100644--- a/server/harness-mcp-proxy.ts+++ b/server/harness-mcp-proxy.ts@@ -4,13 +4,15 @@ import { pathToFileURL } from "node:url";import { failure, harnessMcpRequest, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, parseHarnessMcpKind, type HarnessMcpKind, type RpcId } from "./harness-mcp-request.ts";import { harnessMcpTokenEnv } from "./harness-mcp-token.ts";import { toolLimitFromEnv } from "./tool-count-limit.ts";+import { TOOL_SCHEMA_PROFILE_ENV } from "./tool-schema-profile.ts";export { harnessMcpRequest } from "./harness-mcp-request.ts";const MAX_PENDING = 16;function run(kind: HarnessMcpKind): void {- const connection = { url: process.env.OMB_HARNESS_URL ?? "", token: process.env[harnessMcpTokenEnv(kind)] ?? "", kind, toolLimit: toolLimitFromEnv() };+ const connection = { url: process.env.OMB_HARNESS_URL ?? "", token: process.env[harnessMcpTokenEnv(kind)] ?? "", kind, toolLimit: toolLimitFromEnv(),+ schemaProfile: process.env[TOOL_SCHEMA_PROFILE_ENV] };let input = Buffer.alloc(0);let pending = 0;const output = (message: unknown) => {diff --git a/server/harness-mcp-request.ts b/server/harness-mcp-request.tsindex 3de4e89fd4..c1902d78ba 100644--- a/server/harness-mcp-request.ts+++ b/server/harness-mcp-request.ts@@ -5,6 +5,7 @@ import { EMAIL_INSTRUCTIONS } from "./email/instructions.ts";import { PHONE_INSTRUCTIONS, PHONE_RECOVERY } from "./phones/instructions.ts";import { HARNESS_PROXY_TIMEOUT_MS, HARNESS_PROXY_TIMEOUTS_MS } from "./harness-budget.ts";import { capToolListResult } from "./tool-count-limit.ts";+import { toolsListResultForShareProfile } from "./tool-list-budget.ts";export const MAX_INPUT_BYTES = 1_048_576;export const MAX_OUTPUT_BYTES = 16_777_216;@@ -63,7 +64,7 @@ async function boundedJson(response: Response, name: string): Promise<unknown> {export async function harnessMcpRequest(frame: unknown,- connection: { url: string; token: string; kind: HarnessMcpKind; toolLimit?: number },+ connection: { url: string; token: string; kind: HarnessMcpKind; toolLimit?: number; schemaProfile?: unknown },): Promise<unknown | undefined> {if (!frame || typeof frame !== "object" || Array.isArray(frame)) return failure(null, null, "Invalid request.", -32600);const message = frame as { id?: RpcId; jsonrpc?: unknown; method?: unknown; params?: unknown };@@ -96,8 +97,9 @@ export async function harnessMcpRequest(if (!response.ok || !payload || typeof payload !== "object" || !Object.hasOwn(payload, "result")) {throw new Error(typeof payload?.error === "string" ? payload.error.slice(0, 2_000) : `${name} server is unavailable. Start a new bot turn or try again.`);}+ const log = (line: string) => console.warn(`[${connection.kind}] ${line}`);const result = message.method === "tools/list"- ? capToolListResult(payload.result, connection.toolLimit, (line) => console.warn(`[${connection.kind}] ${line}`)) : payload.result;+ ? toolsListResultForShareProfile(capToolListResult(payload.result, connection.toolLimit, log), connection.schemaProfile, log) : payload.result;return { jsonrpc: "2.0", id, result };} catch (error) {return failure(id, message.method, unansweredText(error, name, HARNESS_PROXY_TIMEOUTS_MS[connection.kind] ?? HARNESS_PROXY_TIMEOUT_MS) + RECOVERY[connection.kind]);diff --git a/server/routes/own-mcp-http-path.ts b/server/routes/own-mcp-http-path.tsindex 5b4b7bcd4c..076fdefcc0 100644--- a/server/routes/own-mcp-http-path.ts+++ b/server/routes/own-mcp-http-path.ts@@ -1,3 +1,5 @@export const OWN_MCP_HTTP_PATH = "/api/internal/mcp-http/";/** The agents server's settings (AGENTS_MCP_ENV), base64url JSON. */export const AGENTS_ENV_HEADER = "x-omb-agents-env";+/** A harness server's share of the session's tool budget, as OMB_TOOL_SCHEMA_PROFILE carries it. */+export const TOOL_SHARE_HEADER = "x-omb-tool-share";diff --git a/server/routes/own-mcp-http.test.ts b/server/routes/own-mcp-http.test.tsindex bc9acec462..0e3f53fa6c 100644--- a/server/routes/own-mcp-http.test.ts+++ b/server/routes/own-mcp-http.test.ts@@ -11,7 +11,9 @@ import { json, readBody } from "../harness/http.ts";import type { RequestAuth } from "../request-auth.ts";import { createOwnMcpHttpRoutes, ownMcpHttpRoutes } from "./own-mcp-http.ts";import type { RouteHandler } from "./table.ts";-import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH } from "./own-mcp-http-path.ts";+import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH, TOOL_SHARE_HEADER } from "./own-mcp-http-path.ts";+import { definitionListBytes, toolListShareProfile, type ListedTool } from "../tool-list-budget.ts";+import { TOOL_SCHEMA_PROFILE_ENV } from "../tool-schema-profile.ts";import { TOOL_LIMIT_ENV, TOOL_LIMIT_HEADER } from "../tool-count-limit.ts";/** This server's own internal endpoints, as the stdio proxies reach them: the turn's capability is checked there. */@@ -121,6 +123,18 @@ describe("OpenMausBot's own MCP servers over HTTP", () => {const whole = await agents({ OMB_BOT_ID: "w2", OMB_THREAD_ID: "t2" });expect(await agents({ OMB_BOT_ID: "w2", OMB_THREAD_ID: "t2", [TOOL_LIMIT_ENV]: "3" })).toEqual(whole.slice(0, 3));});++ it("fits each server's list into its share of the session's tool budget, every tool kept", async () => {+ const agents = async (settings: Record<string, string>) =>+ ((await (await post("agents", { jsonrpc: "2.0", id: 8, method: "tools/list" }, agentsHeaders(settings))).json()) as { result: { tools: ListedTool[] } }).result.tools;+ const whole = await agents({ OMB_BOT_ID: "w2", OMB_THREAD_ID: "t2" });+ const shared = await agents({ OMB_BOT_ID: "w2", OMB_THREAD_ID: "t2", [TOOL_SCHEMA_PROFILE_ENV]: toolListShareProfile(definitionListBytes(whole) - 5_000) });+ expect(shared.map((tool) => tool.name)).toEqual(whole.map((tool) => tool.name));+ expect(definitionListBytes(shared)).toBeLessThanOrEqual(definitionListBytes(whole) - 5_000);+ const browser = await (await post("browser", { jsonrpc: "2.0", id: 9, method: "tools/list" },+ { authorization: "Bearer turn-capability", [TOOL_SHARE_HEADER]: toolListShareProfile(1) })).json();+ expect(browser).toEqual({ jsonrpc: "2.0", id: 9, result: { tools: [{ name: "agent_browser_open", inputSchema: { type: "object" } }] } });+ });});describe("a long tool call, and the stdio proxy's limits", () => {diff --git a/server/routes/own-mcp-http.ts b/server/routes/own-mcp-http.tsindex 80ac6cd6d2..d590393590 100644--- a/server/routes/own-mcp-http.ts+++ b/server/routes/own-mcp-http.ts@@ -12,7 +12,7 @@ import { failure, harnessMcpRequest, MAX_INPUT_BYTES, MAX_OUTPUT_BYTES, parseHarimport { parseToolLimit, TOOL_LIMIT_HEADER } from "../tool-count-limit.ts";import { PASS, type RouteContext, type RouteHandler } from "./table.ts";-import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH } from "./own-mcp-http-path.ts";+import { AGENTS_ENV_HEADER, OWN_MCP_HTTP_PATH, TOOL_SHARE_HEADER } from "./own-mcp-http-path.ts";/** As each stdio proxy allows (harness-mcp-proxy.ts). */const MAX_PENDING = 16;@@ -64,7 +64,8 @@ export function createOwnMcpHttpRoutes(options: { keepaliveMs?: number; maxPendiconst harness = `http://127.0.0.1:${req.socket.localPort}/`;const answer: (frame: Json) => Promise<unknown> = kind === "agents"? agentsMcp(agentsEnv(req.headers, token, harness.slice(0, -1)))- : (frame) => harnessMcpRequest(frame, { url: harness, token, kind, toolLimit: parseToolLimit(req.headers[TOOL_LIMIT_HEADER]) });+ : (frame) => harnessMcpRequest(frame, { url: harness, token, kind, toolLimit: parseToolLimit(req.headers[TOOL_LIMIT_HEADER]),+ schemaProfile: req.headers[TOOL_SHARE_HEADER] });const frames: Frame[] = Array.isArray(body) ? body : [body as Frame];const key = `${kind}\0${token}`;diff --git a/server/testing/cli-tool-drop.ts b/server/testing/cli-tool-drop.tsnew file mode 100644index 0000000000..aa466dff9f--- /dev/null+++ b/server/testing/cli-tool-drop.ts@@ -0,0 +1,15 @@+import { definitionBytes, type ListedTool } from "../tool-list-budget.ts";++/** What the native Antigravity CLI leaves out of a session's tools past `budget` bytes: the largest first, until the rest+ * fits (google-antigravity/antigravity-cli#1530). */+export function cliDrops(tools: readonly ListedTool[], budget: number): string[] {+ const sized = tools.map((tool) => ({ name: tool.name, bytes: definitionBytes(tool) })).sort((a, b) => b.bytes - a.bytes);+ let total = sized.reduce((sum, tool) => sum + tool.bytes, 0);+ const dropped: string[] = [];+ for (const tool of sized) {+ if (total <= budget) break;+ total -= tool.bytes;+ dropped.push(tool.name);+ }+ return dropped;+}diff --git a/server/tool-list-budget.test.ts b/server/tool-list-budget.test.tsnew file mode 100644index 0000000000..04a01f08e4--- /dev/null+++ b/server/tool-list-budget.test.ts@@ -0,0 +1,135 @@+import { describe, expect, it } from "vitest";++import fullAgents from "./drivers/agents-catalog-goldens/full.tools-list.json" with { type: "json" };+import { compactAdvertisedSchema } from "./advertised-schema.ts";+import { cliDrops } from "./testing/cli-tool-drop.ts";+import {+ cutText, definitionBytes, withCompactSchemas, withDescriptionLevel, definitionListBytes, fitToolListToShare, PROTECTED_TOOLS, TOOL_DESCRIPTION_FLOOR, toolListShare, toolListShareProfile,+ toolsForShareProfile, toolsListResultForShareProfile, type ListedTool,+} from "./tool-list-budget.ts";++type Json = Record<string, unknown>;+const agents = fullAgents.tools as ListedTool[];+const names = (tools: readonly ListedTool[]) => tools.map((tool) => tool.name);++/** Every description in a schema, and the schema with none of them. */+function descriptions(node: unknown): string[] {+ if (Array.isArray(node)) return node.flatMap(descriptions);+ if (!node || typeof node !== "object") return [];+ return Object.entries(node).flatMap(([key, value]) => (key === "description" && typeof value === "string" ? [value] : descriptions(value)));+}+function withoutDescriptions(node: unknown): unknown {+ if (Array.isArray(node)) return node.map(withoutDescriptions);+ if (!node || typeof node !== "object") return node;+ return Object.fromEntries(Object.entries(node).filter(([key, value]) => !(key === "description" && typeof value === "string")).map(([key, value]) => [key, withoutDescriptions(value)]));+}++describe("a tool's size as the CLI counts it", () => {+ it("is its definition file: name, description and parameters, compact, with <, > and & as six-byte escapes", () => {+ expect(definitionBytes({ name: "a", description: "x", inputSchema: { type: "object" } })).toBe(JSON.stringify({ name: "a", description: "x", parameters: { type: "object" } }).length);+ expect(definitionBytes({ name: "a", description: "<&>" })).toBe(JSON.stringify({ name: "a", description: "<&>", parameters: { type: "object" } }).length + 15);+ expect(definitionListBytes([{ name: "a" }, { name: "b" }])).toBe(2 * definitionBytes({ name: "a" }));+ });++ it("rides OMB_TOOL_SCHEMA_PROFILE as a share; any other profile is not one", () => {+ expect(toolListShare(toolListShareProfile(12_345.9))).toBe(12_345);+ for (const other of [undefined, "", "moonshot", "gemini", "listShare:", "listShare:-1", "listShare:1e3", "listShare:12345678901"]) expect(toolListShare(other)).toBeUndefined();+ });+});++describe("cutting a description", () => {+ const text = "First sentence here. Second one is longer, with more words. Third.";++ it("keeps whole sentences when one fits, else words with an ellipsis, and nothing at all at zero", () => {+ expect(cutText(text, 1_000)).toBe(text);+ expect(cutText(text, 25)).toBe("First sentence here.");+ expect(cutText(text, 14)).toBe("First…");+ expect(cutText(text, 0)).toBeUndefined();+ });++ it("never keeps less as the limit grows", () => {+ let previous = 0;+ for (let max = 0; max <= text.length; max += 1) {+ const kept = cutText(text, max)?.length ?? 0;+ expect(kept).toBeLessThanOrEqual(Math.max(max, 0));+ expect(kept).toBeGreaterThanOrEqual(previous - 1);+ previous = Math.max(previous, kept);+ }+ });+});++describe("fitting a list into its share", () => {+ const from = fitToolListToShare(agents, Number.MAX_SAFE_INTEGER).bytes;++ it("leaves a list that fits as compacted, every description whole", () => {+ const fitted = fitToolListToShare(agents, from);+ expect(fitted).toMatchObject({ fits: true, bytes: from, level: { parameters: Infinity, tools: Infinity } });+ expect(fitted.tools.map((tool) => tool.description)).toEqual(agents.map((tool) => tool.description));+ });++ it("shortens parameter descriptions before any tool description", () => {+ const fitted = fitToolListToShare(agents, from - 2_000);+ expect(fitted.fits).toBe(true);+ expect(fitted.bytes).toBeLessThanOrEqual(from - 2_000);+ expect(fitted.level.tools).toBe(Infinity);+ expect(fitted.level.parameters).toBeLessThan(Infinity);+ expect(fitted.tools.map((tool) => tool.description)).toEqual(agents.map((tool) => tool.description));+ });++ it("then shortens tool descriptions, longest first, never below the floor, and keeps every tool, field, type, enum and required field", () => {+ const share = 40_000;+ const fitted = fitToolListToShare(agents, share);+ expect(fitted.fits).toBe(true);+ expect(fitted.bytes).toBeLessThanOrEqual(share);+ expect(fitted.level.parameters).toBe(0);+ expect(fitted.level.tools).toBeGreaterThanOrEqual(TOOL_DESCRIPTION_FLOOR);+ expect(names(fitted.tools)).toEqual(names(agents));+ fitted.tools.forEach((tool, index) => {+ const original = agents[index]!;+ expect(withoutDescriptions(tool.inputSchema)).toEqual(withoutDescriptions(compactAdvertisedSchema(original.inputSchema as Json)));+ expect(descriptions(tool.inputSchema)).toEqual([]);+ expect(original.description!.startsWith((tool.description ?? "").replace(/…$/, ""))).toBe(true);+ if (original.description!.length <= fitted.level.tools) expect(tool.description).toBe(original.description);+ });+ });++ it("over its share even at its shortest, keeps every tool and shrinks the protected ones, so the CLI's largest-first drop takes others first", () => {+ const fitted = fitToolListToShare(agents, 25_000);+ expect(fitted.fits).toBe(false);+ expect(names(fitted.tools)).toEqual(names(agents));+ const shortest = withDescriptionLevel(withCompactSchemas(agents), { parameters: 0, tools: TOOL_DESCRIPTION_FLOOR });+ // Past the largest unprotected tool, trigger (23 named fields) is next: shrinking cannot take it lower without hiding fields.+ const overBy = 1_000;+ expect(cliDrops(shortest, definitionListBytes(shortest) - overBy).filter((name) => PROTECTED_TOOLS.includes(name))).not.toEqual([]);+ const dropped = cliDrops(fitted.tools, fitted.bytes - overBy);+ expect(dropped.length).toBeGreaterThan(0);+ expect(dropped.filter((name) => PROTECTED_TOOLS.includes(name))).toEqual([]);+ // Each protected tool still names every top-level field it takes, its type and choices, and what it requires.+ for (const name of PROTECTED_TOOLS) {+ const shown = fitted.tools.find((tool) => tool.name === name)!.inputSchema as Json;+ const original = agents.find((tool) => tool.name === name)!.inputSchema as Json;+ expect(Object.keys(shown.properties as Json)).toEqual(Object.keys(original.properties as Json));+ for (const [field, schema] of Object.entries(shown.properties as Json)) {+ const before = (original.properties as Record<string, Json>)[field]!;+ expect((schema as Json).type).toEqual(before.type);+ expect((schema as Json).enum).toEqual(before.enum);+ }+ expect(shown.required).toEqual(original.required);+ }+ });++ it("does nothing without a share, under another engine's profile, or to anything that is not a tool list", () => {+ expect(toolsForShareProfile(agents, undefined)).toBe(agents);+ expect(toolsForShareProfile(agents, "moonshot")).toBe(agents);+ const result = { tools: agents };+ expect(toolsListResultForShareProfile(result, "gemini")).toBe(result);+ expect(toolsListResultForShareProfile({ error: "x" }, toolListShareProfile(1))).toEqual({ error: "x" });+ const logged: string[] = [];+ const fitted = toolsListResultForShareProfile(result, toolListShareProfile(25_000), (line) => logged.push(line)) as { tools: ListedTool[] };+ expect(names(fitted.tools)).toEqual(names(agents));+ expect(logged).toEqual([expect.stringMatching(/^tool list is \d+ bytes at its shortest, \d+ over its 25000-byte share of the session's tool budget$/)]);+ // The same list under the same share again, as every request of a turn builds it: the fitted list reused, no second line.+ expect(toolsForShareProfile(structuredClone(agents), toolListShareProfile(25_000), (line) => logged.push(line))).toBe(fitted.tools);+ expect(logged).toHaveLength(1);+ });+});diff --git a/server/tool-list-budget.ts b/server/tool-list-budget.tsnew file mode 100644index 0000000000..c8b5051102--- /dev/null+++ b/server/tool-list-budget.ts@@ -0,0 +1,195 @@+// A byte budget over the MCP tool definitions an engine shows its model, for an engine that shows every tool eagerly and,+// past its budget, silently leaves out the largest tools first. Google's native Antigravity CLI (1.5.x over ACP) is one+// (google-antigravity/antigravity-cli#1530): it writes each tool to <app-data-dir>/mcp/<server>/<tool>.json as+// {name, description, parameters} and counts those files across every server of the session. On 1.5.16 the drop+// started between 58,700 and 60,600 bytes; on 1.5.17 one tool alone was kept up to 56,608 bytes, about 38 more per+// further tool and about 6 fewer per character of the profile's path. A session's own servers share out+// ANTIGRAVITY_CLI_TOOL_BUDGET and each fits its list into its share, least loss first: the schema compacted, then+// shorter parameter descriptions, then shorter tool descriptions. No tool is left out, and every call is still checked+// against the tool's own full schema.+import { compactAdvertisedSchema } from "./advertised-schema.ts";+import { schemaBytes } from "./tool-schema-profile.ts";++type Json = Record<string, unknown>;+export type ListedTool = { name: string; description?: string; inputSchema?: unknown } & Json;++/** Below the CLI's drop point, with room for its per-path overhead and the person's own servers. */+export const ANTIGRAVITY_CLI_TOOL_BUDGET = 55_000;++/** The value of OMB_TOOL_SCHEMA_PROFILE that gives a server its share of a session's budget, in bytes. */+const SHARE_PREFIX = "listShare:";++export function toolListShareProfile(bytes: number): string {+ return `${SHARE_PREFIX}${Math.max(0, Math.floor(bytes))}`;+}++export function toolListShare(profile: unknown): number | undefined {+ if (typeof profile !== "string" || !profile.startsWith(SHARE_PREFIX)) return undefined;+ const digits = profile.slice(SHARE_PREFIX.length);+ return /^\d{1,9}$/.test(digits) ? Number(digits) : undefined;+}++/** One tool as the CLI writes its definition file: compact JSON, `<`, `>` and `&` as six-byte escapes. */+export function definitionBytes(tool: ListedTool): number {+ return schemaBytes({ name: tool.name, description: tool.description ?? "", parameters: tool.inputSchema ?? { type: "object" } });+}++export function definitionListBytes(tools: readonly ListedTool[]): number {+ return tools.reduce((sum, tool) => sum + definitionBytes(tool), 0);+}++/** Tools never to be the ones the CLI leaves out, most important first. It drops the largest first, so when a list cannot+ * fit these are made smaller still. */+export const PROTECTED_TOOLS: readonly string[] = ["coordinate_bots", "start_thread", "show_html", "trigger", "memory_update", "attach_file"];++/** A tool description is never cut below this many characters while fitting; past it the list is over its share. */+export const TOOL_DESCRIPTION_FLOOR = 120;++/** `text` cut to at most `max` characters: at the last sentence end that fits, else at a word with an ellipsis; undefined+ * when nothing is left. The kept length never shrinks as `max` grows, so a search over `max` is sound. */+export function cutText(text: string, max: number): string | undefined {+ if (text.length <= max) return text;+ if (max <= 1) return undefined;+ let end = -1;+ for (const match of text.slice(0, max + 1).matchAll(/[.!?](?=\s|$)/g)) if (match.index + 1 <= max) end = match.index + 1;+ if (end > 0) return text.slice(0, end);+ const words = text.slice(0, max - 1).replace(/\s+\S*$/, "").trimEnd();+ return words ? `${words}…` : undefined;+}++/** Where a schema holds named subschemas, single subschemas, and lists of them. Everything else is a value. */+const SCHEMA_MAPS = new Set(["properties", "patternProperties", "$defs", "definitions", "dependentSchemas"]);+const SCHEMA_SLOTS = new Set(["items", "additionalProperties", "additionalItems", "contains", "propertyNames", "not", "if", "then", "else", "unevaluatedProperties", "unevaluatedItems"]);+const SCHEMA_LISTS = new Set(["anyOf", "oneOf", "allOf", "prefixItems", "items"]);++function isObject(value: unknown): value is Json {+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);+}++/** Every `description` inside a schema, at any depth, cut to `max` characters (gone at 0). */+function withParameterDescriptions(node: unknown, max: number): unknown {+ if (!isObject(node)) return node;+ const result: Json = {};+ for (const [key, value] of Object.entries(node)) {+ if (key === "description" && typeof value === "string") {+ const kept = cutText(value, max);+ if (kept !== undefined) result[key] = kept;+ } else if (SCHEMA_MAPS.has(key) && isObject(value)) {+ result[key] = Object.fromEntries(Object.entries(value).map(([name, child]) => [name, withParameterDescriptions(child, max)]));+ } else if (SCHEMA_LISTS.has(key) && Array.isArray(value)) result[key] = value.map((child) => withParameterDescriptions(child, max));+ else if (SCHEMA_SLOTS.has(key) && isObject(value)) result[key] = withParameterDescriptions(value, max);+ else result[key] = value;+ }+ return result;+}++/** How much of each description a list keeps, in characters; Infinity keeps all of it. */+export interface DescriptionLevel { parameters: number; tools: number }++export const FULL_DESCRIPTIONS: DescriptionLevel = { parameters: Infinity, tools: Infinity };++export function withDescriptionLevel<T extends ListedTool>(tools: readonly T[], level: DescriptionLevel): T[] {+ return tools.map((tool) => {+ const description = typeof tool.description === "string" ? cutText(tool.description, level.tools) ?? "" : tool.description;+ const inputSchema = level.parameters === Infinity ? tool.inputSchema : withParameterDescriptions(tool.inputSchema, level.parameters);+ return description === tool.description && inputSchema === tool.inputSchema ? tool : { ...tool, description, inputSchema };+ });+}++/** Each tool's schema as a model is shown it. */+export function withCompactSchemas<T extends ListedTool>(tools: readonly T[]): T[] {+ return tools.map((tool) => (isObject(tool.inputSchema) ? { ...tool, inputSchema: compactAdvertisedSchema(tool.inputSchema) } : tool));+}++function longest(tools: readonly ListedTool[], of: (tool: ListedTool) => string[]): number {+ return Math.max(0, ...tools.flatMap(of).map((text) => text.length));+}++function parameterDescriptions(node: unknown): string[] {+ if (!isObject(node)) return [];+ const own = typeof node.description === "string" ? [node.description] : [];+ return [...own, ...Object.entries(node).flatMap(([key, value]) => {+ if (SCHEMA_MAPS.has(key) && isObject(value)) return Object.values(value).flatMap(parameterDescriptions);+ if (SCHEMA_LISTS.has(key) && Array.isArray(value)) return value.flatMap(parameterDescriptions);+ return SCHEMA_SLOTS.has(key) ? parameterDescriptions(value) : [];+ })];+}++/** The largest value in [low, high] for which `fits` holds, given that it holds at `low`. */+function largestFitting(low: number, high: number, fits: (value: number) => boolean): number {+ while (low < high) {+ const middle = Math.ceil((low + high) / 2);+ if (fits(middle)) low = middle; else high = middle - 1;+ }+ return low;+}++/** The least cut that brings `tools` (already compacted) to `budget` bytes: parameter descriptions first, then tool+ * descriptions down to TOOL_DESCRIPTION_FLOOR. `fits` is false when even that is over. */+export function descriptionLevelFor(tools: readonly ListedTool[], budget: number): { level: DescriptionLevel; fits: boolean } {+ const bytesAt = (level: DescriptionLevel) => definitionListBytes(withDescriptionLevel(tools, level));+ if (bytesAt(FULL_DESCRIPTIONS) <= budget) return { level: FULL_DESCRIPTIONS, fits: true };+ const maxParameter = longest(tools, (tool) => parameterDescriptions(tool.inputSchema));+ if (bytesAt({ parameters: 0, tools: Infinity }) <= budget) {+ const parameters = largestFitting(0, maxParameter, (chars) => bytesAt({ parameters: chars, tools: Infinity }) <= budget);+ return { level: { parameters, tools: Infinity }, fits: true };+ }+ const floor = { parameters: 0, tools: TOOL_DESCRIPTION_FLOOR };+ if (bytesAt(floor) > budget) return { level: floor, fits: false };+ const maxTool = longest(tools, (tool) => (typeof tool.description === "string" ? [tool.description] : []));+ const chars = largestFitting(TOOL_DESCRIPTION_FLOOR, Math.max(TOOL_DESCRIPTION_FLOOR, maxTool), (max) => bytesAt({ parameters: 0, tools: max }) <= budget);+ return { level: { parameters: 0, tools: chars }, fits: true };+}++/** A protected tool as small as it gets while still naming every top-level field, its type and its choices: its first+ * sentence, and each nested object or list of objects as just its type. Only for a list that cannot fit otherwise; the+ * handler still checks every nested field and answers a wrong one with what it expects. */+function smallest<T extends ListedTool>(tool: T): T {+ const description = typeof tool.description === "string" ? cutText(tool.description.split(/(?<=[.!?])\s/)[0] ?? "", TOOL_DESCRIPTION_FLOOR) ?? "" : tool.description;+ const schema = tool.inputSchema;+ if (!isObject(schema) || !isObject(schema.properties)) return { ...tool, description };+ const properties = Object.fromEntries(Object.entries(schema.properties).map(([name, property]) => {+ if (!isObject(property)) return [name, property];+ const nested = isObject(property.properties) || (isObject(property.items) && isObject(property.items.properties)) || isObject(property.additionalProperties);+ return [name, nested ? Object.fromEntries(["type", "enum"].filter((key) => key in property).map((key) => [key, property[key]])) : property];+ }));+ return { ...tool, description, inputSchema: { ...schema, properties } };+}++export interface FittedToolList<T> { tools: T[]; bytes: number; from: number; level: DescriptionLevel; fits: boolean }++/** `tools` as this engine is shown them within `share` bytes. A list that cannot fit keeps every tool at its shortest,+ * with PROTECTED_TOOLS shrunk further, so the engine's largest-first drop takes others before them. */+export function fitToolListToShare<T extends ListedTool>(tools: readonly T[], share: number): FittedToolList<T> {+ const compacted = withCompactSchemas(tools);+ const from = definitionListBytes(compacted);+ const { level, fits } = descriptionLevelFor(compacted, share);+ let fitted = withDescriptionLevel(compacted, level);+ if (!fits) fitted = fitted.map((tool) => (PROTECTED_TOOLS.includes(tool.name) ? smallest(tool) : tool));+ return { tools: fitted, bytes: definitionListBytes(fitted), from, level, fits };+}++/** A tools/list `tools` array under OMB_TOOL_SCHEMA_PROFILE `profile`: fitted when the profile is a share, else as it came. */+export function toolsForShareProfile<T extends ListedTool>(tools: readonly T[], profile: unknown, log?: (line: string) => void): readonly T[] {+ const share = toolListShare(profile);+ if (share === undefined) return tools;+ // The agents server is built for every request of a turn, its calls included: a list already fitted is reused.+ const key = `${share}\0${JSON.stringify(tools)}`;+ const known = FITTED.get(key);+ if (known) return known as T[];+ const fitted = fitToolListToShare(tools, share);+ if (!fitted.fits) log?.(`tool list is ${fitted.bytes} bytes at its shortest, ${fitted.bytes - share} over its ${share}-byte share of the session's tool budget`);+ if (FITTED.size >= FITTED_KEPT) FITTED.delete(FITTED.keys().next().value!);+ FITTED.set(key, fitted.tools);+ return fitted.tools;+}++const FITTED_KEPT = 32;+const FITTED = new Map<string, readonly ListedTool[]>();++/** A tools/list result with its tools fitted the same way; anything else as it came. */+export function toolsListResultForShareProfile(result: unknown, profile: unknown, log?: (line: string) => void): unknown {+ if (toolListShare(profile) === undefined || !isObject(result) || !Array.isArray(result.tools)) return result;+ const tools = result.tools.filter((tool): tool is ListedTool => isObject(tool) && typeof tool.name === "string");+ return tools.length === result.tools.length ? { ...result, tools: toolsForShareProfile(tools, profile, log) } : result;+}