Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: accept _1PASSWORD_* tool names for underscore-prefixed toolkits
Ooi Pin Jund7f90c5bee85
diff --git a/packages/phone-protocol/src/connector-scopes.ts b/packages/phone-protocol/src/connector-scopes.tsindex 131e180666..51f15a6f3a 100644--- a/packages/phone-protocol/src/connector-scopes.ts+++ b/packages/phone-protocol/src/connector-scopes.ts@@ -25,10 +25,12 @@ const TOOLKIT_SLUG = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,63}$/;const ACCOUNT_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;/** The toolkit a Composio slug belongs to: the part before the first- * underscore, lower-cased. A workbench API proxy belongs to no app. */+ * underscore, lower-cased. A leading underscore is part of the toolkit+ * (`_1PASSWORD_GET_ITEM` → `_1password`). A workbench API proxy belongs to no app. */export function toolkitOf(slug: string): string {- const cut = slug.indexOf("_");- return (cut > 0 ? slug.slice(0, cut) : slug).toLowerCase();+ const start = slug.startsWith("_") ? 1 : 0;+ const cut = slug.indexOf("_", start);+ return (cut > start ? slug.slice(0, cut) : slug).toLowerCase();}/** Toolkits whose actions name a one-word resource before the verb@@ -42,7 +44,7 @@ export function isReadOnlyAction(slug: string, toolkit?: string): boolean {if (slug === "COMPOSIO_PROXY_EXECUTE") return false;if (KNOWN_READ_SLUGS.has(slug)) return true;const resourceFirst = RESOURCE_FIRST_TOOLKITS.find((candidate) => (toolkit ?? candidate) === candidate && slug.startsWith(candidate.toUpperCase() + "_"));- const cut = resourceFirst ? resourceFirst.length : toolkit ? toolkit.length : slug.indexOf("_");+ const cut = resourceFirst ? resourceFirst.length : toolkit ? toolkit.length : toolkitOf(slug).length;const action = cut > 0 ? slug.slice(cut + 1) : "";const verb = action.toUpperCase().split(/[^A-Z0-9]+/).filter(Boolean)[resourceFirst ? 1 : 0];return verb !== undefined && READ_VERBS.has(verb);diff --git a/packages/phone-protocol/src/outbound.ts b/packages/phone-protocol/src/outbound.tsindex aa6d7b6752..b32d1bb481 100644--- a/packages/phone-protocol/src/outbound.ts+++ b/packages/phone-protocol/src/outbound.ts@@ -67,8 +67,9 @@ function actionTokens(name: string): string[] {const [, server = "", ...rest] = name.split("__");action = rest.join("_");if (isConnectedAppsServer(server)) return actionTokens(action);- } else if (/^[A-Z][A-Z0-9]*_[A-Z0-9_]+$/.test(name)) {- action = name.slice(name.indexOf("_") + 1);+ } else if (/^(?:[A-Z][A-Z0-9]*|_[A-Z0-9]+)_[A-Z0-9_]+$/.test(name)) {+ const start = name.startsWith("_") ? 1 : 0;+ action = name.slice(name.indexOf("_", start) + 1);}return action.replace(/([a-z0-9])([A-Z])/g, "$1_$2")diff --git a/packages/phone-protocol/src/wire.ts b/packages/phone-protocol/src/wire.tsindex 1d132f6c8d..72e6c08b0b 100644--- a/packages/phone-protocol/src/wire.ts+++ b/packages/phone-protocol/src/wire.ts@@ -252,8 +252,10 @@ export interface ConnectorToolGrant {/** Lowercased Composio service slug, e.g. `gmail`. */export const CONNECTOR_SLUG_PATTERN = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,80}$/;-/** Composio tool names are upper-snake, e.g. `GMAIL_SEND_EMAIL`. */-export const CONNECTOR_TOOL_NAME_PATTERN = /^[A-Z][A-Z0-9_]{0,127}$/;+/** Composio tool names are upper-snake, e.g. `GMAIL_SEND_EMAIL`. A toolkit+ * whose slug starts with `_` (such as `_1password`) names its tools the same+ * way: `_1PASSWORD_GET_ITEM`. */+export const CONNECTOR_TOOL_NAME_PATTERN = /^(?:[A-Z][A-Z0-9_]{0,127}|_[A-Z0-9][A-Z0-9_]{0,126})$/;/** Fails closed: only an absent switch or a strict true allows the helper model; a hand-edited "false" or 0 reads as never. */export const helperModelAllowed = (bot: { helperModel?: unknown }): boolean => bot.helperModel === undefined || bot.helperModel === true;diff --git a/server/connector-advertisement.test.ts b/server/connector-advertisement.test.tsindex e296c69b31..b23caa10ea 100644--- a/server/connector-advertisement.test.ts+++ b/server/connector-advertisement.test.ts@@ -157,6 +157,14 @@ it.each(["_1password", "_" + "a".repeat(80)])("round-trips connector grants forconst record = grants({ [slug]: { tools: "*" } });expect(parseConnectorAllowedToolsEnv(serializeConnectorAllowedTools(record).env)).toEqual(record);});+it("round-trips and advertises a leading-underscore toolkit's own tool names", () => {+ const record = grants({ _1password: { tools: ["_1PASSWORD_GET_ITEM", "_1PASSWORD_LIST_VAULTS"] } });+ expect(parseConnectorAllowedToolsEnv(serializeConnectorAllowedTools(record).env)).toEqual(record);+ expect(connectorToolAdvertised("_1PASSWORD_GET_ITEM", record)).toBe(true);+ expect(connectorToolAdvertised("_1PASSWORD_LIST_VAULTS", record)).toBe(true);+ expect(connectorToolAdvertised("_1PASSWORD_DELETE_ITEM", record)).toBe(false);+ expect(connectorToolAdvertised("_1PASSWORD_GET_ITEM", grants({ _1password: { tools: "*" } }))).toBe(true);+});it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(82)])("rejects invalid connector grant slug %s", (slug) => {expect(parseConnectorAllowedToolsEnv(JSON.stringify({ [slug]: { tools: "*" } }))).toBeNull();});diff --git a/server/connector-verdict.test.ts b/server/connector-verdict.test.tsindex 429d37fa73..d7456b8b04 100644--- a/server/connector-verdict.test.ts+++ b/server/connector-verdict.test.ts@@ -40,6 +40,8 @@ describe("connectorCallFromFrame", () => {it("reads a direct per-toolkit call", () => {expect(connectorCallFromFrame(toolsCall("GMAIL_SEND_EMAIL", { to: "[email protected]" }))).toEqual({ kind: "tools", invoked: "GMAIL_SEND_EMAIL", names: ["GMAIL_SEND_EMAIL"] });+ expect(connectorCallFromFrame(toolsCall("_1PASSWORD_GET_ITEM", { item_id: "i1" })))+ .toEqual({ kind: "tools", invoked: "_1PASSWORD_GET_ITEM", names: ["_1PASSWORD_GET_ITEM"] });});it("reads every target from MULTI_EXECUTE, single and batched", () => {@@ -113,6 +115,7 @@ describe("serviceSlugFor", () => {it("maps a tool name to its service slug", () => {expect(serviceSlugFor("GMAIL_SEND_EMAIL")).toBe("gmail");expect(serviceSlugFor("SLACK_POST_MESSAGE")).toBe("slack");+ expect(serviceSlugFor("_1PASSWORD_GET_ITEM")).toBe("_1password");expect(serviceSlugFor("GMAIL")).toBeNull();expect(serviceSlugFor("_SEND")).toBeNull();});@@ -122,6 +125,7 @@ describe("serviceSlugForCandidates", () => {it("prefers the longest known slug across an underscore boundary", () => {expect(serviceSlugForCandidates("BLAND_AI_MAKE_CALL", ["bland", "bland_ai"])).toBe("bland_ai");expect(serviceSlugForCandidates("GITHUB_CREATE_ISSUE", ["git", "github"])).toBe("github");+ expect(serviceSlugForCandidates("_1PASSWORD_GET_ITEM", ["_1password", "password"])).toBe("_1password");});it("matches whole slug segments only and reports no match for the caller's fallback", () => {@@ -172,6 +176,10 @@ describe("evaluateConnectorTools", () => {const grants: Record<string, ConnectorToolGrant> = { gmail: { tools: "*" } };expect(evaluateConnectorTools(["GMAIL_SEND_EMAIL", "GMAIL_FETCH_EMAILS"], grants).allowed).toBe(true);expect(evaluateConnectorTools(["SLACK_POST_MESSAGE"], grants).allowed).toBe(false);+ const onePassword: Record<string, ConnectorToolGrant> = { _1password: { tools: "*" } };+ expect(evaluateConnectorTools(["_1PASSWORD_GET_ITEM", "_1PASSWORD_LIST_VAULTS"], onePassword).allowed).toBe(true);+ expect(evaluateConnectorTools(["_1PASSWORD_GET_ITEM"], { _1password: { tools: ["_1PASSWORD_GET_ITEM"] } }).allowed).toBe(true);+ expect(evaluateConnectorTools(["_1PASSWORD_DELETE_ITEM"], { _1password: { tools: ["_1PASSWORD_GET_ITEM"] } }).allowed).toBe(false);});it("keeps an underscored service's tools under its own grant", () => {diff --git a/server/connector-verdict.ts b/server/connector-verdict.tsindex 8cd3348b92..5669c92394 100644--- a/server/connector-verdict.ts+++ b/server/connector-verdict.ts@@ -62,10 +62,12 @@ export interface ConnectorVerdict {rule: string;}-/** Composio's upper-snake prefix before the first underscore, lowercased (GMAIL_SEND_EMAIL → gmail); no underscore, no service. */+/** Composio's upper-snake prefix before the first underscore, lowercased (GMAIL_SEND_EMAIL → gmail); no underscore, no service.+ * A leading underscore is part of the slug (`_1PASSWORD_GET_ITEM` → `_1password`). */export function serviceSlugFor(tool: string): string | null {- const underscore = tool.indexOf("_");- if (underscore <= 0) return null;+ const start = tool.startsWith("_") ? 1 : 0;+ const underscore = tool.indexOf("_", start);+ if (underscore <= start) return null;return tool.slice(0, underscore).toLowerCase();}diff --git a/shared/connector-scopes.test.ts b/shared/connector-scopes.test.tsindex 31ea96570c..c8367fbf08 100644--- a/shared/connector-scopes.test.ts+++ b/shared/connector-scopes.test.ts@@ -15,6 +15,7 @@ describe("toolkitOf", () => {expect(toolkitOf("GMAIL_SEND_EMAIL")).toBe("gmail");expect(toolkitOf("GOOGLESHEETS_BATCH_UPDATE")).toBe("googlesheets");expect(toolkitOf("COMPOSIO_PROXY_EXECUTE")).toBe("composio");+ expect(toolkitOf("_1PASSWORD_GET_ITEM")).toBe("_1password");});});@@ -27,6 +28,9 @@ describe("isReadOnlyAction", () => {expect(isReadOnlyAction("GOOGLESHEETS_BATCH_UPDATE")).toBe(false);expect(isReadOnlyAction("GMAIL_CREATE_EMAIL_DRAFT")).toBe(false);expect(isReadOnlyAction("COMPOSIO_PROXY_EXECUTE")).toBe(false);+ expect(isReadOnlyAction("_1PASSWORD_GET_ITEM")).toBe(true);+ expect(isReadOnlyAction("_1PASSWORD_LIST_ITEMS")).toBe(true);+ expect(isReadOnlyAction("_1PASSWORD_CREATE_ITEM")).toBe(false);});it("takes the second word as the verb only for toolkits that name the resource first", () => {@@ -90,6 +94,13 @@ describe("connectorAccessDecision", () => {toolkit: "gmail",reason: "write",});+ expect(connectorAccessDecision({ apps: { _1password: "read" } }, calls("_1PASSWORD_GET_ITEM"))).toEqual({ ok: true });+ expect(connectorAccessDecision({ apps: { _1password: "read" } }, calls("_1PASSWORD_CREATE_ITEM"))).toEqual({+ ok: false,+ slug: "_1PASSWORD_CREATE_ITEM",+ toolkit: "_1password",+ reason: "write",+ });});it("reads HighLevel MCP actions, which name the resource before the verb, on a read-only grant", () => {diff --git a/shared/outbound.test.ts b/shared/outbound.test.tsindex 5a17828a40..83e65415d2 100644--- a/shared/outbound.test.ts+++ b/shared/outbound.test.ts@@ -91,6 +91,8 @@ describe("isReadOnlyTool", () => {"mcp__linear__get_issue","GMAIL_SEARCH_MESSAGES","mcp__agents__check_app_hosting",+ "_1PASSWORD_GET_ITEM",+ "_1PASSWORD_LIST_ITEMS",]) expect(isReadOnlyTool(name), name).toBe(true);for (const name of [@@ -99,6 +101,7 @@ describe("isReadOnlyTool", () => {"mcp__linear__create_comment","mcp__computer__click","Bash",+ "_1PASSWORD_CREATE_ITEM",]) expect(isReadOnlyTool(name), name).toBe(false);});});diff --git a/src/lib/connector-grants.test.ts b/src/lib/connector-grants.test.tsindex 26d147a27e..ab62d569a3 100644--- a/src/lib/connector-grants.test.ts+++ b/src/lib/connector-grants.test.ts@@ -12,7 +12,9 @@ describe("connector grant shapes", () => {it("accepts the wildcard and explicit well-formed name lists only", () => {expect(isConnectorToolGrantShape({ tools: "*" })).toBe(true);expect(isConnectorToolGrantShape({ tools: ["GMAIL_SEND_EMAIL", "SLACK_POST_MESSAGE"] })).toBe(true);+ expect(isConnectorToolGrantShape({ tools: ["_1PASSWORD_GET_ITEM"] })).toBe(true);expect(isConnectorToolGrantShape({ tools: [] })).toBe(false);+ expect(isConnectorToolGrantShape({ tools: ["__PROTO__"] })).toBe(false);expect(isConnectorToolGrantShape({ tools: ["gmail_send_email"] })).toBe(false);expect(isConnectorToolGrantShape({ tools: "GMAIL_SEND_EMAIL" })).toBe(false);expect(isConnectorToolGrantShape(null)).toBe(false);@@ -25,6 +27,7 @@ describe("verb classes for tool names", () => {expect(classifyConnectorTool("SLACK_DELETE_MESSAGE")).toBe("delete");expect(classifyConnectorTool("NOTION_CREATE_PAGE")).toBe("draft");expect(classifyConnectorTool("GMAIL_FETCH_EMAILS")).toBe("read");+ expect(classifyConnectorTool("_1PASSWORD_GET_ITEM")).toBe("read");expect(classifyConnectorTool("SLACK_UPDATE_MESSAGE")).toBe("modify");});