@ancha-labs/cli 0.4.54 → 0.4.55

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.
@@ -187002,10 +187002,13 @@ function notRoutedMessage(toolkit) {
187002
187002
  var RouteRefusal = class extends Error {
187003
187003
  reason;
187004
187004
  toolkit;
187005
- constructor(reason2, toolkit) {
187006
- super(reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
187005
+ /** For SCHEMA: the field and what it held, as types (SPEC-104 F1). */
187006
+ detail;
187007
+ constructor(reason2, toolkit, detail3) {
187008
+ super(reason2 === "SCHEMA" && detail3 ? `The request does not match this endpoint's input schema: ${detail3}.` : reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
187007
187009
  this.reason = reason2;
187008
187010
  this.toolkit = toolkit;
187011
+ if (detail3) this.detail = detail3;
187009
187012
  }
187010
187013
  };
187011
187014
  var activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
@@ -187057,9 +187060,25 @@ var switchOf = (raw3, key5) => {
187057
187060
  };
187058
187061
  var connections2 = /* @__PURE__ */ new WeakMap();
187059
187062
  var bytes2 = (value5) => Buffer.from(JSON.stringify(value5));
187060
- function parsed3(schema2, value5) {
187061
- const result = schema2.safeParse(value5);
187062
- return result.success ? result.data : refuse("SCHEMA");
187063
+ function schemaDetail(issues, at4) {
187064
+ const issue9 = issues[0];
187065
+ if (!issue9) return void 0;
187066
+ const path6 = [...at4 ? [at4] : [], ...issue9.path].reduce((text25, key5) => typeof key5 === "number" ? `${text25}[${key5}]` : text25 ? `${text25}.${String(key5)}` : String(key5), "");
187067
+ const said = issue9.code === "invalid_type" ? `expected ${issue9.expected}, received ${issue9.input === null ? "null" : Array.isArray(issue9.input) ? "array" : typeof issue9.input}` : issue9.code === "unrecognized_keys" ? `unknown field${issue9.keys.length === 1 ? "" : "s"} ${issue9.keys.slice(0, 3).join(", ")}` : issue9.code === "too_small" ? `expected at least ${String(issue9.minimum)}${issue9.origin === "array" ? ` item${issue9.minimum === 1 ? "" : "s"}` : ""}` : issue9.code === "invalid_value" ? "not an accepted value" : issue9.code.replace(/_/g, " ");
187068
+ return `${path6 ? `${path6}: ` : ""}${said}`.slice(0, 160);
187069
+ }
187070
+ function jsonText(value5) {
187071
+ if (typeof value5 !== "string") return value5;
187072
+ try {
187073
+ return JSON.parse(value5);
187074
+ } catch {
187075
+ return value5;
187076
+ }
187077
+ }
187078
+ function parsed3(schema2, value5, at4) {
187079
+ const result = schema2.safeParse(value5, { reportInput: true });
187080
+ if (result.success) return result.data;
187081
+ throw new RouteRefusal("SCHEMA", void 0, schemaDetail(result.error.issues, at4));
187063
187082
  }
187064
187083
  function jsonBody3(body7, contentType) {
187065
187084
  if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
@@ -187076,7 +187095,7 @@ function toolArguments(route15, name5, value5 = {}, metaOnly = false) {
187076
187095
  if (!meta5.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
187077
187096
  const { account: _account, ...args } = value5;
187078
187097
  if (name5 === multi) {
187079
- const items = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record10.optional() }).passthrough()).min(1), args.tools);
187098
+ const items = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: external_exports.preprocess(jsonText, record10).optional() }).passthrough()).min(1), jsonText(args.tools), "tools");
187080
187099
  for (const item2 of items) requireWorld(item2.tool_slug, route15);
187081
187100
  args.tools = items.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
187082
187101
  if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
@@ -187150,7 +187169,7 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
187150
187169
  if (Array.isArray(json37)) refuse("MCP_BATCH");
187151
187170
  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);
187152
187171
  if (value5.method === "tools/call") {
187153
- const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
187172
+ const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params, "params");
187154
187173
  const call2 = toolArguments(route15, params10.name, params10.arguments);
187155
187174
  if (!qb) refuse("SESSION_ENDPOINT");
187156
187175
  const { account: _account, ...kept } = params10;
@@ -187309,9 +187328,9 @@ async function readComposioBody(req) {
187309
187328
  }
187310
187329
  return Buffer.concat(chunks);
187311
187330
  }
187312
- function refuseComposio(res, reason2, toolkit) {
187331
+ function refuseComposio(res, reason2, toolkit, detail3) {
187313
187332
  res.writeHead(403, { "content-type": "application/json", connection: "close" });
187314
- res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
187333
+ res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit, detail3).message } }));
187315
187334
  }
187316
187335
  var routeIds = /* @__PURE__ */ new WeakMap();
187317
187336
  function nextRouteId(route15, kind) {
@@ -187549,8 +187568,8 @@ async function startIsolationGateway(options4) {
187549
187568
  const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
187550
187569
  const toolkit = (error64 instanceof RouteRefusal ? error64.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
187551
187570
  const via = composioVia((req.url ?? "").slice("/_tool/composio".length));
187552
- route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
187553
- refuseComposio(res, reason2, toolkit);
187571
+ route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2, ...error64 instanceof RouteRefusal && error64.detail && { detail: error64.detail } });
187572
+ refuseComposio(res, reason2, toolkit, error64 instanceof RouteRefusal ? error64.detail : void 0);
187554
187573
  return;
187555
187574
  }
187556
187575
  }
package/lib/worker.mjs CHANGED
@@ -71084,9 +71084,25 @@ function requireWorld(name5, route15) {
71084
71084
  if (!(route15.toolkits ?? { quickbooks: "composio" })[toolkit]) throw new RouteRefusal("NOT_ROUTED", toolkit);
71085
71085
  if (!activeComposioToolkits(route15)[toolkit]) throw new RouteRefusal("NO_WORLD", toolkit);
71086
71086
  }
71087
- function parsed2(schema2, value5) {
71088
- const result = schema2.safeParse(value5);
71089
- return result.success ? result.data : refuse("SCHEMA");
71087
+ function schemaDetail(issues, at4) {
71088
+ const issue9 = issues[0];
71089
+ if (!issue9) return void 0;
71090
+ const path8 = [...at4 ? [at4] : [], ...issue9.path].reduce((text26, key5) => typeof key5 === "number" ? `${text26}[${key5}]` : text26 ? `${text26}.${String(key5)}` : String(key5), "");
71091
+ const said = issue9.code === "invalid_type" ? `expected ${issue9.expected}, received ${issue9.input === null ? "null" : Array.isArray(issue9.input) ? "array" : typeof issue9.input}` : issue9.code === "unrecognized_keys" ? `unknown field${issue9.keys.length === 1 ? "" : "s"} ${issue9.keys.slice(0, 3).join(", ")}` : issue9.code === "too_small" ? `expected at least ${String(issue9.minimum)}${issue9.origin === "array" ? ` item${issue9.minimum === 1 ? "" : "s"}` : ""}` : issue9.code === "invalid_value" ? "not an accepted value" : issue9.code.replace(/_/g, " ");
71092
+ return `${path8 ? `${path8}: ` : ""}${said}`.slice(0, 160);
71093
+ }
71094
+ function jsonText(value5) {
71095
+ if (typeof value5 !== "string") return value5;
71096
+ try {
71097
+ return JSON.parse(value5);
71098
+ } catch {
71099
+ return value5;
71100
+ }
71101
+ }
71102
+ function parsed2(schema2, value5, at4) {
71103
+ const result = schema2.safeParse(value5, { reportInput: true });
71104
+ if (result.success) return result.data;
71105
+ throw new RouteRefusal("SCHEMA", void 0, schemaDetail(result.error.issues, at4));
71090
71106
  }
71091
71107
  function jsonBody(body7, contentType) {
71092
71108
  if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
@@ -71103,7 +71119,7 @@ function toolArguments(route15, name5, value5 = {}, metaOnly = false) {
71103
71119
  if (!meta3.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
71104
71120
  const { account: _account, ...args } = value5;
71105
71121
  if (name5 === multi) {
71106
- const items = parsed2(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record7.optional() }).passthrough()).min(1), args.tools);
71122
+ const items = parsed2(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: external_exports.preprocess(jsonText, record7).optional() }).passthrough()).min(1), jsonText(args.tools), "tools");
71107
71123
  for (const item2 of items) requireWorld(item2.tool_slug, route15);
71108
71124
  args.tools = items.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
71109
71125
  if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
@@ -71177,7 +71193,7 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
71177
71193
  if (Array.isArray(json37)) refuse("MCP_BATCH");
71178
71194
  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);
71179
71195
  if (value5.method === "tools/call") {
71180
- const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params);
71196
+ const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params, "params");
71181
71197
  const call2 = toolArguments(route15, params10.name, params10.arguments);
71182
71198
  if (!qb) refuse("SESSION_ENDPOINT");
71183
71199
  const { account: _account, ...kept } = params10;
@@ -71336,9 +71352,9 @@ async function readComposioBody(req) {
71336
71352
  }
71337
71353
  return Buffer.concat(chunks);
71338
71354
  }
71339
- function refuseComposio(res, reason2, toolkit) {
71355
+ function refuseComposio(res, reason2, toolkit, detail3) {
71340
71356
  res.writeHead(403, { "content-type": "application/json", connection: "close" });
71341
- res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
71357
+ res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit, detail3).message } }));
71342
71358
  }
71343
71359
  function nextRouteId(route15, kind) {
71344
71360
  let ids3 = routeIds.get(route15);
@@ -71437,10 +71453,13 @@ var init_composio = __esm({
71437
71453
  RouteRefusal = class extends Error {
71438
71454
  reason;
71439
71455
  toolkit;
71440
- constructor(reason2, toolkit) {
71441
- super(reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
71456
+ /** For SCHEMA: the field and what it held, as types (SPEC-104 F1). */
71457
+ detail;
71458
+ constructor(reason2, toolkit, detail3) {
71459
+ super(reason2 === "SCHEMA" && detail3 ? `The request does not match this endpoint's input schema: ${detail3}.` : reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
71442
71460
  this.reason = reason2;
71443
71461
  this.toolkit = toolkit;
71462
+ if (detail3) this.detail = detail3;
71444
71463
  }
71445
71464
  };
71446
71465
  activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
@@ -71642,8 +71661,8 @@ async function startIsolationGateway(options5) {
71642
71661
  const reason2 = error64 instanceof RouteRefusal ? error64.reason : "JSON";
71643
71662
  const toolkit = (error64 instanceof RouteRefusal ? error64.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
71644
71663
  const via = composioVia((req.url ?? "").slice("/_tool/composio".length));
71645
- route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
71646
- refuseComposio(res, reason2, toolkit);
71664
+ route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2, ...error64 instanceof RouteRefusal && error64.detail && { detail: error64.detail } });
71665
+ refuseComposio(res, reason2, toolkit, error64 instanceof RouteRefusal ? error64.detail : void 0);
71647
71666
  return;
71648
71667
  }
71649
71668
  }
@@ -72479,7 +72498,8 @@ async function bounded(response6, cap) {
72479
72498
  }
72480
72499
  return Buffer.concat(chunks);
72481
72500
  }
72482
- function refusedDetail(reason2 = "REFUSED", toolkit) {
72501
+ function refusedDetail(reason2 = "REFUSED", toolkit, detail3) {
72502
+ if (reason2 === "SCHEMA" && detail3) return `a Composio call was refused (SCHEMA: ${detail3}): send the fields its input schema names; the route supplies the world connection.`;
72483
72503
  const fix = REFUSAL_FIX[reason2] ?? "use the declared QuickBooks route";
72484
72504
  return `a Composio call was refused (${reason2}): ${typeof fix === "function" ? fix(toolkit) : `${fix}.`}`;
72485
72505
  }
@@ -72677,7 +72697,7 @@ async function startIngressClient(options5) {
72677
72697
  if (reached) counts2[toolkit].reached++;
72678
72698
  }
72679
72699
  if (event3.op === "refused") counts2[toolkit].refused++;
72680
- record15({ ...event3, toolkit, relayHash: hash2(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached && event3.status === 401 && toolkit === "quickbooks" && (event3.via ?? "direct") === "direct" ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : event3.op === "catalog" && event3.via !== "mcp" && event3.status === 401 ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : void 0);
72700
+ record15({ ...event3, toolkit, relayHash: hash2(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit, event3.detail), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached && event3.status === 401 && toolkit === "quickbooks" && (event3.via ?? "direct") === "direct" ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : event3.op === "catalog" && event3.via !== "mcp" && event3.status === 401 ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : void 0);
72681
72701
  },
72682
72702
  summary: () => {
72683
72703
  const result = {};
@@ -73550,6 +73570,27 @@ var init_agent_env = __esm({
73550
73570
  });
73551
73571
 
73552
73572
  // backend/src/agent-fix.ts
73573
+ function modelBaseUrlFix(host) {
73574
+ const variable = host === "openrouter.ai" ? "OPENROUTER_BASE_URL" : host === "api.openai.com" ? "OPENAI_BASE_URL" : host === "api.anthropic.com" ? "ANTHROPIC_BASE_URL" : void 0;
73575
+ const prefix2 = "in Ancha a model provider is reached through its base URL variable: ";
73576
+ if (!variable && host) return `${prefix2}build the client from its ${host} entry in ANCHA_MODEL_URLS`;
73577
+ if (!variable) return `${prefix2}build the client from OPENROUTER_BASE_URL, OPENAI_BASE_URL or ANTHROPIC_BASE_URL for that provider, or its entry in ANCHA_MODEL_URLS`;
73578
+ return `${prefix2}build the client from ${variable} (${host === "api.anthropic.com" ? "Anthropic SDK" : "OpenAI SDK"}: baseURL: process.env.${variable}${host === "openrouter.ai" ? "; @openrouter/ai-sdk-provider: createOpenRouter({ baseURL: process.env.OPENROUTER_BASE_URL })" : ""})`;
73579
+ }
73580
+ function modelUnreachable(log2, requests2) {
73581
+ if (requests2 === void 0 || Object.values(requests2).some((count11) => count11.requests > 0)) return void 0;
73582
+ const sdk = SDK_CONNECTION.test(log2);
73583
+ if (!sdk && !NET_CONNECTION.test(log2)) return void 0;
73584
+ const named4 = (host2) => ({ host: host2, message: `It could not reach ${host2}: its model client calls https://${host2} directly.`, fix: modelBaseUrlFix(host2) });
73585
+ const failed2 = [...log2.matchAll(/getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)\s+([a-z0-9.-]+)|request to https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => (match3[1] ?? match3[2]).toLowerCase());
73586
+ if (failed2.length > 0) {
73587
+ const host2 = failed2.find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
73588
+ return host2 ? named4(host2) : void 0;
73589
+ }
73590
+ if (!sdk) return void 0;
73591
+ const host = [...log2.matchAll(/https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => match3[1].toLowerCase()).find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
73592
+ return host ? named4(host) : { message: "Its model client could not connect, and it made no model request through Ancha.", fix: modelBaseUrlFix() };
73593
+ }
73553
73594
  function givenByTwins(name5) {
73554
73595
  twinVariables ??= new Set(Object.keys(toolConnectionEnvironment(Object.fromEntries(SUPPORTED_TWINS.map((twin) => [twin, ANY_SERVICE])))));
73555
73596
  return twinVariables.has(name5);
@@ -73617,6 +73658,8 @@ function missingFix(text26, context3) {
73617
73658
  return void 0;
73618
73659
  }
73619
73660
  function likelyFix(logTail3, context3 = {}) {
73661
+ const unreachable = modelUnreachable(logTail3.join("\n"), context3.modelRequests);
73662
+ if (unreachable) return unreachable.fix;
73620
73663
  const task2 = taskFix(logTail3.join("\n"), context3.command);
73621
73664
  if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
73622
73665
  if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
@@ -73631,12 +73674,15 @@ function likelyFix(logTail3, context3 = {}) {
73631
73674
  }
73632
73675
  return void 0;
73633
73676
  }
73634
- var TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2, MODEL_ID_REFUSED;
73677
+ var SDK_CONNECTION, NET_CONNECTION, TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2, MODEL_ID_REFUSED;
73635
73678
  var init_agent_fix = __esm({
73636
73679
  "backend/src/agent-fix.ts"() {
73637
73680
  "use strict";
73638
73681
  init_src();
73639
73682
  init_agent_env();
73683
+ init_jobs_contract();
73684
+ SDK_CONNECTION = /APIConnectionError|Connection error\.|AI_RetryError|AI_APICallError|Cannot connect to API/;
73685
+ NET_CONNECTION = /getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)|request to https?:\/\/\S+\s+failed|Temporary failure in name resolution|httpx\.ConnectError|fetch failed/i;
73640
73686
  TASK_WORD = "(?:TASKS?|PROMPTS?|QUERY|QUERIES|INSTRUCTIONS?|MESSAGES?|REQUESTS?|INPUTS?)";
73641
73687
  TASK_NAME = new RegExp(`(?<![A-Za-z0-9_])((?:[A-Z][A-Z0-9]*_)*${TASK_WORD}(?:_[A-Z0-9]+)*)(?![A-Za-z0-9_])`, "g");
73642
73688
  TASK_FLAG = /(?<![\w-])(--(?:task|prompt|message|input|query|instructions?|request)(?:-file)?)(?![\w-])/g;
@@ -225987,7 +226033,7 @@ var init_agent_outcome = __esm({
225987
226033
  // backend/src/runner/trial.ts
225988
226034
  import { setTimeout as sleep9 } from "node:timers/promises";
225989
226035
  import { closeSync as closeSync6, openSync as openSync6, writeSync as writeSync6 } from "node:fs";
225990
- import { mkdir as mkdir11 } from "node:fs/promises";
226036
+ import { mkdir as mkdir11, readFile as readFile9 } from "node:fs/promises";
225991
226037
  import { join as join21 } from "node:path";
225992
226038
  function answersFrom(agent, source) {
225993
226039
  const mode = agent.answer ?? "auto";
@@ -226154,6 +226200,10 @@ async function runTrialInner(spec) {
226154
226200
  const capture3 = await captureTrialAfterFailure(failure5, backend, env.id, session2.id, dir, scene2, { ...spec.judge, ...signal !== void 0 && { signal } }, void 0, spec.onCaptured);
226155
226201
  const { checks: checks2, trace: trace2, simMs } = capture3, harnessIssues = [...capture3.harnessIssues, ...playOutIssues];
226156
226202
  if (output2?.modelRefusal !== void 0) harnessIssues.push(modelKeyIssue(output2.modelRefusal, Object.keys(agent.env ?? {})));
226203
+ if ((exit === "spawn_failed" || exit === "exited" && exitCode !== 0) && output2?.model && !output2.modelReplies?.length) {
226204
+ const unreachable = modelUnreachable(await readFile9(join21(dir, "agent.log"), "utf8").catch(() => ""), output2.model.requests);
226205
+ if (unreachable) harnessIssues.push({ kind: "model", owner: "harness", service: unreachable.host ?? "model", code: "MODEL_UNREACHABLE", message: `${unreachable.message} ${unreachable.fix.charAt(0).toUpperCase()}${unreachable.fix.slice(1)}.` });
226206
+ }
226157
226207
  if (failure5 !== void 0) throw failure5.error;
226158
226208
  signal?.throwIfAborted();
226159
226209
  return {
@@ -226200,6 +226250,7 @@ var init_trial = __esm({
226200
226250
  init_budget();
226201
226251
  init_agent_output();
226202
226252
  init_agent_outcome();
226253
+ init_agent_fix();
226203
226254
  init_agent_env();
226204
226255
  EXIT_COMMAND_NOT_FOUND2 = 127;
226205
226256
  unknownRoute18 = (error64) => error64 instanceof AnchaError && error64.code === "USAGE" && error64.message.startsWith("no such route");
@@ -226208,7 +226259,7 @@ var init_trial = __esm({
226208
226259
 
226209
226260
  // backend/src/runner/run.ts
226210
226261
  import { createHash as createHash61, randomInt } from "node:crypto";
226211
- import { access as access4, mkdir as mkdir12, readFile as readFile9, writeFile as writeFile11 } from "node:fs/promises";
226262
+ import { access as access4, mkdir as mkdir12, readFile as readFile10, writeFile as writeFile11 } from "node:fs/promises";
226212
226263
  import { dirname as dirname7, join as join22, relative as relative5, resolve as resolve12 } from "node:path";
226213
226264
  function interrupted(dir) {
226214
226265
  return new AnchaError("USAGE", "run interrupted", dir === void 0 ? {} : { hint: `partial results in ${dir}` });
@@ -226385,7 +226436,7 @@ async function executeRun(opts) {
226385
226436
  for (const [index, item2] of cases.entries()) {
226386
226437
  const source = await recordsFor(pathOf6(item2), opts.root);
226387
226438
  if (source === void 0) continue;
226388
- const text26 = await readFile9(source), copy = join22(dir, "records", `${index}.jsonl`);
226439
+ const text26 = await readFile10(source), copy = join22(dir, "records", `${index}.jsonl`);
226389
226440
  await mkdir12(dirname7(copy), { recursive: true });
226390
226441
  await writeFile11(copy, text26, { flag: "wx", mode: 384 });
226391
226442
  kept.set(item2.id, copy);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancha-labs/cli",
3
- "version": "0.4.54",
3
+ "version": "0.4.55",
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": {