@ancha-labs/cli 0.4.51 → 0.4.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/ancha.mjs CHANGED
@@ -231502,13 +231502,16 @@ function validateComposio(method2, target6, apiKey, body8, contentType, route15,
231502
231502
  }
231503
231503
  const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
231504
231504
  if (mcp) {
231505
- if (method2 !== "POST") refuse("METHOD");
231506
231505
  if (!identifier4.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
231507
231506
  noQuery();
231507
+ if (method2 === "GET" || method2 === "DELETE") {
231508
+ empty3();
231509
+ return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
231510
+ }
231511
+ if (method2 !== "POST") refuse("METHOD");
231508
231512
  const forwarded2 = protocolHeaders(headers), json40 = jsonBody3(body8, contentType);
231509
231513
  if (Array.isArray(json40)) refuse("MCP_BATCH");
231510
231514
  const value6 = parsed3(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record26.optional() }), json40);
231511
- if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value6.method)) refuse("MCP_METHOD");
231512
231515
  if (value6.method === "tools/call") {
231513
231516
  const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record26.optional(), account: external_exports.unknown().optional(), _meta: record26.optional() }), value6.params);
231514
231517
  const call4 = toolArguments(route15, params10.name, params10.arguments);
@@ -231682,6 +231685,12 @@ function nextRouteId(route15, kind2) {
231682
231685
  return `${kind2}_${ids3.fork(kind2).alnumUpper(16)}`;
231683
231686
  }
231684
231687
  async function executeLocalComposio(call4, route15, origin, fetcher = fetch, signal) {
231688
+ if (call4.local === "mcp") return call4.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
231689
+ error: "method_not_allowed",
231690
+ message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
231691
+ allowed_methods: ["POST"],
231692
+ docs: "https://docs.composio.dev/mcp"
231693
+ } } : { status: 405 };
231685
231694
  if (call4.local === "session") {
231686
231695
  route15.narrowed(call4.narrowed ?? []);
231687
231696
  if (call4.response === "session-delete") {
@@ -231974,7 +231983,7 @@ async function startIsolationGateway(options5) {
231974
231983
  reached = result.reached;
231975
231984
  invalidArguments = result.invalidArguments === true;
231976
231985
  if (!res.destroyed) {
231977
- res.writeHead(result.status, { "content-type": "application/json" });
231986
+ res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
231978
231987
  res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
231979
231988
  }
231980
231989
  } catch {
@@ -233100,7 +233109,6 @@ var init_ingress_client = __esm({
233100
233109
  TOOL: "execute a QUICKBOOKS_ tool",
233101
233110
  META_TOOL: "use COMPOSIO_MULTI_EXECUTE_TOOL, COMPOSIO_SEARCH_TOOLS or COMPOSIO_GET_TOOL_SCHEMAS; multi-execute items must be QUICKBOOKS_ tools",
233102
233111
  ACCOUNT: "list the route connected accounts and use the returned test connection",
233103
- MCP_METHOD: "use initialize, notifications/initialized, notifications/cancelled, ping, tools/list or tools/call",
233104
233112
  MCP_BATCH: "send one JSON-RPC object per MCP request"
233105
233113
  };
233106
233114
  unreachedDetail = (status6) => status6 === 401 || status6 === 403 ? `Composio answered ${status6} without calling the world: check the workspace secret COMPOSIO_API_KEY.` : status6 >= 500 ? `Composio answered ${status6} without calling the world; run again.` : `Composio answered ${status6} without calling the world: check the QuickBooks tool arguments and use the connection supplied by the route.`;
@@ -235686,6 +235694,9 @@ function missingFix(text31, context3) {
235686
235694
  function likelyFix(logTail3, context3 = {}) {
235687
235695
  const task2 = taskFix(logTail3.join("\n"), context3.command);
235688
235696
  if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
235697
+ if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
235698
+ return `Claude Code had no key (its /login stays on your computer): through OpenRouter, start agent.command with ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" and set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env; with an Anthropic key, ${context3.target === "cloud" ? "run ancha secrets set ANTHROPIC_API_KEY in the project" : "set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml"}`;
235699
+ }
235689
235700
  const errors3 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
235690
235701
  for (const lines2 of [errors3, logTail3]) {
235691
235702
  const fix = lines2.length === 0 ? void 0 : keyFix(lines2, context3) ?? missingFix(lines2.join("\n"), context3);
@@ -243592,6 +243603,7 @@ __export(vm_connection_exports, {
243592
243603
  NETSUITE_PROBE_TASK: () => NETSUITE_PROBE_TASK,
243593
243604
  PROBE_MS: () => PROBE_MS,
243594
243605
  PROBE_TASK: () => PROBE_TASK,
243606
+ executable: () => executable,
243595
243607
  probeTwins: () => probeTwins,
243596
243608
  probeVmConnection: () => probeVmConnection,
243597
243609
  taskFixFromLog: () => taskFixFromLog
@@ -243602,9 +243614,12 @@ import { createServer as createServer5 } from "node:net";
243602
243614
  import { join as join44 } from "node:path";
243603
243615
  import { setTimeout as sleep11 } from "node:timers/promises";
243604
243616
  function executable(command) {
243605
- let text31 = command.trimStart();
243617
+ const name5 = "start it with the executable's name, such as ./agent.sh or node";
243618
+ const invalid42 = (problem, fix = name5) => new AnchaError("CONFIG_INVALID", `agent.command ${problem}: ${fix}.`);
243619
+ const shown4 = (word2) => word2.length > 60 ? `${word2.slice(0, 57)}...` : word2;
243620
+ let text31 = command.trimStart(), assigned = false;
243606
243621
  for (; ; ) {
243607
- let word2 = "", quote6 = "", started = false, i = 0;
243622
+ let word2 = "", quote6 = "", started = false, expands = false, i = 0;
243608
243623
  for (; i < text31.length; i++) {
243609
243624
  const char = text31[i];
243610
243625
  if (!quote6 && /\s|[;&|<>]/.test(char)) break;
@@ -243622,12 +243637,28 @@ function executable(command) {
243622
243637
  word2 += text31[++i];
243623
243638
  continue;
243624
243639
  }
243625
- if (quote6 !== "'" && /[$`]/.test(char)) throw new AnchaError("CONFIG_INVALID", "Start the agent command with its executable name.");
243640
+ if (quote6 !== "'" && (char === "`" || char === "$" && text31[i + 1] === "(")) throw invalid42("runs a command substitution before its executable", "move it into a script that agent.command runs");
243641
+ if (quote6 !== "'" && char === "$") {
243642
+ expands = true;
243643
+ const end = text31[i + 1] === "{" ? text31.indexOf("}", i + 2) : i;
243644
+ if (end < 0) throw invalid42("has an unclosed ${", "close it with }");
243645
+ word2 += text31.slice(i, end + 1);
243646
+ i = end;
243647
+ continue;
243648
+ }
243626
243649
  word2 += char;
243627
243650
  }
243628
- if (!started || !word2 || quote6 || word2.startsWith("-") || /[\0\r\n]/.test(word2)) throw new AnchaError("CONFIG_INVALID", "Start the agent command with its executable name.");
243629
- if (!/^[A-Za-z_][A-Za-z0-9_]*=/.test(word2)) return word2;
243630
- text31 = text31.slice(i).trimStart();
243651
+ if (quote6) throw invalid42(`has an unclosed ${quote6 === '"' ? "double" : "single"} quote`, "close it");
243652
+ if (!started || !word2) throw text31 ? invalid42(`starts with ${text31[0]}`) : assigned ? invalid42("sets variables but names no executable", "add the executable after them, such as ./agent.sh or node") : invalid42("is empty");
243653
+ if (/^[A-Za-z_][A-Za-z0-9_]*=/.test(word2)) {
243654
+ text31 = text31.slice(i).trimStart();
243655
+ assigned = true;
243656
+ continue;
243657
+ }
243658
+ if (expands) throw invalid42(`starts with ${shown4(word2)}, which the shell expands`);
243659
+ if (word2.startsWith("-")) throw invalid42(`starts with the option ${shown4(word2)}`);
243660
+ if (/[\0\r\n]/.test(word2)) throw invalid42("has a line break in its first word");
243661
+ return word2;
243631
243662
  }
243632
243663
  }
243633
243664
  async function freePort() {
@@ -181,7 +181,7 @@ ancha run --on cloud
181
181
  - Declare either route or both. Each test's world decides which routed tools it answers. QuickBooks-only and NetSuite-only tests can use the same agent configuration. A call to a declared tool that the world lacks returns `403 COMPOSIO_ROUTE_REFUSED` with reason `NO_WORLD` and a fix to add the tool to the world or run the call in a test whose world has it. The agent gets that answer and the attempt is graded as usual, as it is when a SuiteQL call's arguments are invalid. A call to a QuickBooks or NetSuite tool whose toolkit is not under `agent.routes` returns reason `NOT_ROUTED` with the line to add, such as `quickbooks: composio`; the attempt is invalid until the route is declared.
182
182
  - The agent keeps its Composio code. Each attempt sets `COMPOSIO_BASE_URL` to Composio's API through the attempt's gateway (the Composio SDKs read it; a client built with an explicit base URL takes this value) and `COMPOSIO_API_KEY` to a key for this attempt; the gateway sends the project's key to Composio for QuickBooks calls. `QUICKBOOKS_PUBLIC_URL` is this world's QuickBooks at an address Composio reaches for this attempt only; `QUICKBOOKS_ACCESS_TOKEN` and `QUICKBOOKS_REALM_ID` are the world's, as in any test with QuickBooks.
183
183
  - QuickBooks direct executions (`tools.execute`) reach the world whatever user ID or connected account the agent names: the gateway supplies the world's address and credentials on each call. An agent that already passes `custom_auth_params` keeps them: `base_url` is `QUICKBOOKS_PUBLIC_URL` with the world's `Authorization` and `x-quickbooks-realm-id` headers.
184
- - When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. When the attempt ends it deletes the sessions, the connection and its auth config.
184
+ - When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. MCP clients such as Claude Code connect as they do to Composio: their tool calls reach the world, and every other request goes to Composio as sent. When the attempt ends it deletes the sessions, the connection and its auth config.
185
185
  - NetSuite calls use `NETSUITE_RUN_SUITEQL_QUERY`, its SuiteQL query in `q` and optional paging arguments, through `session.execute` or `tools.execute`. The gateway supplies the world's NetSuite credentials and returns the SuiteQL REST body in the Composio response. When QuickBooks is inactive in the test, sessions are created, read and deleted in the gateway; when both routes are active, the gateway handles NetSuite reads and Composio handles QuickBooks.
186
186
  - Before an agent with an active QuickBooks route starts, the attempt checks that `QUICKBOOKS_PUBLIC_URL` answers from outside.
187
187
  - The gateway keeps every call on the world: a call that names another toolkit's tools, changes a session's connection, proxies a request or reaches another attempt's session gets `403 COMPOSIO_ROUTE_REFUSED` with a `reason`, and the attempt is invalid with `ROUTE_REFUSED`, so every result rests on calls inside the world.
@@ -187139,13 +187139,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
187139
187139
  }
187140
187140
  const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
187141
187141
  if (mcp) {
187142
- if (method2 !== "POST") refuse("METHOD");
187143
187142
  if (!identifier4.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
187144
187143
  noQuery();
187144
+ if (method2 === "GET" || method2 === "DELETE") {
187145
+ empty2();
187146
+ return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
187147
+ }
187148
+ if (method2 !== "POST") refuse("METHOD");
187145
187149
  const forwarded = protocolHeaders(headers), json37 = jsonBody3(body7, contentType);
187146
187150
  if (Array.isArray(json37)) refuse("MCP_BATCH");
187147
187151
  const value5 = parsed3(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record10.optional() }), json37);
187148
- if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
187149
187152
  if (value5.method === "tools/call") {
187150
187153
  const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
187151
187154
  const call2 = toolArguments(route15, params10.name, params10.arguments);
@@ -187321,6 +187324,12 @@ function nextRouteId(route15, kind) {
187321
187324
  }
187322
187325
  var suiteqlArguments = external_exports.strictObject({ q: external_exports.string(), limit: external_exports.number().int().min(1).optional(), offset: external_exports.number().int().min(0).optional() });
187323
187326
  async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
187327
+ if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
187328
+ error: "method_not_allowed",
187329
+ message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
187330
+ allowed_methods: ["POST"],
187331
+ docs: "https://docs.composio.dev/mcp"
187332
+ } } : { status: 405 };
187324
187333
  if (call2.local === "session") {
187325
187334
  route15.narrowed(call2.narrowed ?? []);
187326
187335
  if (call2.response === "session-delete") {
@@ -187552,7 +187561,7 @@ async function startIsolationGateway(options4) {
187552
187561
  reached = result.reached;
187553
187562
  invalidArguments = result.invalidArguments === true;
187554
187563
  if (!res.destroyed) {
187555
- res.writeHead(result.status, { "content-type": "application/json" });
187564
+ res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
187556
187565
  res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
187557
187566
  }
187558
187567
  } catch {
package/lib/worker.mjs CHANGED
@@ -71166,13 +71166,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
71166
71166
  }
71167
71167
  const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
71168
71168
  if (mcp) {
71169
- if (method2 !== "POST") refuse("METHOD");
71170
71169
  if (!identifier.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
71171
71170
  noQuery();
71171
+ if (method2 === "GET" || method2 === "DELETE") {
71172
+ empty2();
71173
+ return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
71174
+ }
71175
+ if (method2 !== "POST") refuse("METHOD");
71172
71176
  const forwarded2 = protocolHeaders(headers), json37 = jsonBody(body7, contentType);
71173
71177
  if (Array.isArray(json37)) refuse("MCP_BATCH");
71174
71178
  const value5 = parsed2(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record7.optional() }), json37);
71175
- if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
71176
71179
  if (value5.method === "tools/call") {
71177
71180
  const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params);
71178
71181
  const call2 = toolArguments(route15, params10.name, params10.arguments);
@@ -71346,6 +71349,12 @@ function nextRouteId(route15, kind) {
71346
71349
  return `${kind}_${ids3.fork(kind).alnumUpper(16)}`;
71347
71350
  }
71348
71351
  async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
71352
+ if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
71353
+ error: "method_not_allowed",
71354
+ message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
71355
+ allowed_methods: ["POST"],
71356
+ docs: "https://docs.composio.dev/mcp"
71357
+ } } : { status: 405 };
71349
71358
  if (call2.local === "session") {
71350
71359
  route15.narrowed(call2.narrowed ?? []);
71351
71360
  if (call2.response === "session-delete") {
@@ -71638,7 +71647,7 @@ async function startIsolationGateway(options5) {
71638
71647
  reached = result.reached;
71639
71648
  invalidArguments = result.invalidArguments === true;
71640
71649
  if (!res.destroyed) {
71641
- res.writeHead(result.status, { "content-type": "application/json" });
71650
+ res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
71642
71651
  res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
71643
71652
  }
71644
71653
  } catch {
@@ -72705,7 +72714,6 @@ var init_ingress_client = __esm({
72705
72714
  TOOL: "execute a QUICKBOOKS_ tool",
72706
72715
  META_TOOL: "use COMPOSIO_MULTI_EXECUTE_TOOL, COMPOSIO_SEARCH_TOOLS or COMPOSIO_GET_TOOL_SCHEMAS; multi-execute items must be QUICKBOOKS_ tools",
72707
72716
  ACCOUNT: "list the route connected accounts and use the returned test connection",
72708
- MCP_METHOD: "use initialize, notifications/initialized, notifications/cancelled, ping, tools/list or tools/call",
72709
72717
  MCP_BATCH: "send one JSON-RPC object per MCP request"
72710
72718
  };
72711
72719
  unreachedDetail = (status5) => status5 === 401 || status5 === 403 ? `Composio answered ${status5} without calling the world: check the workspace secret COMPOSIO_API_KEY.` : status5 >= 500 ? `Composio answered ${status5} without calling the world; run again.` : `Composio answered ${status5} without calling the world: check the QuickBooks tool arguments and use the connection supplied by the route.`;
@@ -73576,6 +73584,9 @@ function missingFix(text26, context3) {
73576
73584
  function likelyFix(logTail3, context3 = {}) {
73577
73585
  const task2 = taskFix(logTail3.join("\n"), context3.command);
73578
73586
  if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
73587
+ if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
73588
+ return `Claude Code had no key (its /login stays on your computer): through OpenRouter, start agent.command with ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" and set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env; with an Anthropic key, ${context3.target === "cloud" ? "run ancha secrets set ANTHROPIC_API_KEY in the project" : "set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml"}`;
73589
+ }
73579
73590
  const errors2 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
73580
73591
  for (const lines of [errors2, logTail3]) {
73581
73592
  const fix = lines.length === 0 ? void 0 : keyFix(lines, context3) ?? missingFix(lines.join("\n"), context3);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancha-labs/cli",
3
- "version": "0.4.51",
3
+ "version": "0.4.52",
4
4
  "type": "module",
5
5
  "description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, each attempt on a fresh cloud machine in your app.ancha.io workspace, or on your computer.",
6
6
  "bugs": {