@ancha-labs/cli 0.4.14 → 0.4.16

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.
@@ -75,6 +75,8 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
75
75
 
76
76
  `ancha agent upload` (also `ancha doctor --on cloud`) checks the agent where its tests run, before any test exists. A fresh machine installs the project's dependencies and starts the agent once with a task, through the same launcher and variables as an attempt. An agent that uses NetSuite has 90 seconds to find one customer in NetSuite and reply with its name; any other agent has 20 seconds, and exiting 0 or showing any work in that time makes it ready. The result says what happened in one sentence: the NetSuite calls it made and the answer it gave, or what stopped it (credentials NetSuite refused, a NetSuite host outside Ancha, a model key its provider refused, an answer missing where your tests read it, no output at all) with the change that fixes it. One that exits with an error shows its exit code, the end of its log and, when the log names where it looks for its task, the `ancha.yaml` line that gives it there. An agent served over HTTP (`agent.url`) starts and answers its ready check. That marks the agent uploaded in the workspace's first steps, and the command prints the link to the upload.
77
77
 
78
+ The task's world includes tools found in your agent and the `twins` in the tests matched by your project's `scenes` globs, up to six tools with the agent's tools first. The result lists each tool and its call count. A tool with no calls gets a warning. If the check gave the agent no tools, name them with `ancha init --tools <tools>` or your tests' `twins`.
79
+
78
80
  The install follows the project's own files, Node and Python alike: a Node lockfile installs exactly what it locks, with its package manager, and a `package.json` without one runs `npm install`; `uv.lock` and `pyproject.toml` run `uv sync`, and `requirements.txt` installs with pip into `.venv`. `agent.install` in `ancha.yaml` sets the command instead, for example `agent: { install: "npm ci && npm run build" }`. The machine has Node 24 and Python 3.12 with their package managers. The install runs as its own user with public internet; the agent then runs as another, and its network reaches only its tools and its model providers.
79
81
 
80
82
  ## Run tests in the cloud
@@ -29,7 +29,7 @@ A version 2 test names a world (`ancha/worlds/<id>.yaml`: the company, its peopl
29
29
 
30
30
  ## Checks on the final answer
31
31
 
32
- An `answer` check reads the agent's final answer: what it posts to `ANCHA_DONE_URL` as `{"output": …}` (`entry()` in `@ancha-labs/tools` posts what the agent returns), else an HTTP agent's reply, else the last block it prints on stdout (after its last blank line); `agent.answer` in `ancha.yaml` picks one. A JSON answer is read as `key: value` lines. Ancha grades it with no model, on this computer and in the cloud, so it uses no model credit.
32
+ An `answer` check reads the agent's final answer: what it posts to `ANCHA_DONE_URL` as `{"output": …}` (`entry()` in `@ancha-labs/tools` posts what the agent returns), else an HTTP agent's reply, else what it prints on stdout (its logs go to stderr); `agent.answer` in `ancha.yaml` picks one. A JSON answer is read as `key: value` lines. Ancha grades it with no model, on this computer and in the cloud, so it uses no model credit.
33
33
 
34
34
  ```yaml
35
35
  checks:
@@ -76413,7 +76413,7 @@ var AnswerCheckSchema = external_exports.strictObject({
76413
76413
  not_contains: texts.optional().describe("Text the final answer must not contain"),
76414
76414
  numbers: external_exports.array(AnswerNumberSchema).min(1).optional().describe("Numbers the final answer must state, each within its tolerance; thousands separators, currency codes and symbols, minus signs and parentheses for negatives are read"),
76415
76415
  case: external_exports.enum(["insensitive", "sensitive"]).optional().describe("How contains and not_contains compare letters; default insensitive")
76416
- }).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or the last block it prints on stdout): the text and numbers it states");
76416
+ }).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or what it prints on stdout): the text and numbers it states");
76417
76417
  function expectedNumber(number7) {
76418
76418
  const read6 = typeof number7.value === "number" ? { value: number7.value, decimals: decimalsOf(number7.value) } : readNumbers(number7.value)[0];
76419
76419
  return { value: read6.value, tolerance: number7.tolerance ?? 0.5 * 10 ** -read6.decimals };
@@ -91104,8 +91104,10 @@ var ANSWER_QUOTE = 300;
91104
91104
  function finalAnswer(trace) {
91105
91105
  const entry2 = trace.findLast((e) => e.source === "agent" && e.service === "agent" && e.path === "/done");
91106
91106
  if (!entry2) return void 0;
91107
- const output2 = typeof entry2.request === "string" ? entry2.request : entry2.request?.output;
91108
- return { text: answerText(output2), seq: entry2.seq };
91107
+ const request4 = typeof entry2.request === "object" && entry2.request !== null ? entry2.request : void 0;
91108
+ const output2 = typeof entry2.request === "string" ? entry2.request : request4?.output;
91109
+ const source = request4?.source === "reply" || request4?.source === "stdout" ? request4.source : "done";
91110
+ return { text: answerText(output2), seq: entry2.seq, source, ...typeof request4?.printed === "number" && { printed: request4.printed } };
91109
91111
  }
91110
91112
  function evaluateAnswer(check3, trace) {
91111
91113
  const contains3 = asList(check3.contains), absent = asList(check3.not_contains), sensitive = check3.case === "sensitive";
@@ -91117,13 +91119,22 @@ function evaluateAnswer(check3, trace) {
91117
91119
  ];
91118
91120
  const expected = parts3.length ? `the final answer ${parts3.join("; ")}` : "a final answer";
91119
91121
  const answer = finalAnswer(trace);
91122
+ if (answer?.printed !== void 0) {
91123
+ return {
91124
+ passed: false,
91125
+ expected,
91126
+ actual: `${answer.printed.toLocaleString("en-US")} characters on stdout`,
91127
+ evidence: [answer.seq],
91128
+ explanation: `The agent printed ${answer.printed.toLocaleString("en-US")} characters on stdout, more than an answer can be, so it gave no final answer. An agent prints its logs on stderr, or posts its answer to ANCHA_DONE_URL, body {"output": <its answer>}.`
91129
+ };
91130
+ }
91120
91131
  if (!answer || answer.text.trim() === "") {
91121
91132
  return {
91122
91133
  passed: false,
91123
91134
  expected,
91124
91135
  actual: answer ? "an empty final answer" : "no final answer",
91125
91136
  evidence: answer ? [answer.seq] : [],
91126
- explanation: `The agent gave ${answer ? "an empty" : "no"} final answer. An agent answers with a POST to ANCHA_DONE_URL, body {"output": <its answer>}, or by printing it last on stdout.`
91137
+ explanation: `The agent gave ${answer ? "an empty" : "no"} final answer. An agent answers with a POST to ANCHA_DONE_URL, body {"output": <its answer>}, or by printing it on stdout.`
91127
91138
  };
91128
91139
  }
91129
91140
  const text23 = comparableText(answer.text, sensitive);
@@ -91140,7 +91151,8 @@ function evaluateAnswer(check3, trace) {
91140
91151
  const explanation = [
91141
91152
  ...missing6.length ? [`The final answer does not contain ${quoted2(missing6)}.`] : [],
91142
91153
  ...unstated.length ? [`It states no number within ${unstated.map((n2) => `${plainNumber(n2.tolerance)} of ${n2.written}`).join(", nor within ")}: ${said}.`] : [],
91143
- ...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : []
91154
+ ...present2.length ? [`It contains ${quoted2(present2)}, which it must not.`] : [],
91155
+ ...answer.source === "stdout" ? ["Its answer is everything it printed on stdout."] : answer.source === "reply" ? ["Its answer is its HTTP reply."] : []
91144
91156
  ].join(" ");
91145
91157
  return { passed: false, expected, actual, explanation, evidence: [answer.seq] };
91146
91158
  }
@@ -151043,7 +151055,8 @@ function record8(ctx, args) {
151043
151055
  }
151044
151056
  function unchanged(ctx, args) {
151045
151057
  const changes = sql(ctx).prepare("SELECT recordtype, id, operation FROM ns_history ORDER BY ordinal").all().filter((row2) => args.types.includes(row2.recordtype));
151046
- return checkOutcome(changes.length === 0, `no writes to ${args.types.join(", ")}`, changes.length ? JSON.stringify(changes) : "no committed writes");
151058
+ const types = args.types.length >= netsuiteRecordTypes.length && netsuiteRecordTypes.every((type) => args.types.includes(type)) ? "NetSuite records" : args.types.length > 4 ? `${args.types.slice(0, 3).join(", ")} and ${args.types.length - 3} more record types` : args.types.join(", ");
151059
+ return checkOutcome(changes.length === 0, `no writes to ${types}`, changes.length ? JSON.stringify(changes) : "no committed writes");
151047
151060
  }
151048
151061
  function count3(ctx, args) {
151049
151062
  const actual = recordIds(ctx, args.type).length;
@@ -152550,8 +152563,9 @@ var TrialSessions = class {
152550
152563
  });
152551
152564
  }
152552
152565
  /**
152553
- * The runner records the agent's answer for it when the agent posted none (SPEC-053 F2): an HTTP agent's reply, or the
152554
- * final block of its stdout. The same `POST /done` entry, with that source; never a second answer.
152566
+ * The runner records the agent's answer for it when the agent posted none (SPEC-053 F2): an HTTP agent's reply, or its
152567
+ * stdout (SPEC-056 A), or how much it printed when that is too long to be an answer. The same `POST /done` entry, with
152568
+ * that source; never a second answer.
152555
152569
  */
152556
152570
  answer(env, id14, answer) {
152557
152571
  return env.serialize(() => {
@@ -152559,7 +152573,7 @@ var TrialSessions = class {
152559
152573
  if (state2 === "prepared") throw new AnchaError("SESSION_CONFLICT", "session has not started");
152560
152574
  if (state2 === "finished") throw new AnchaError("SESSION_CONFLICT", "session has finished");
152561
152575
  if (env.trace.list().some((entry2) => entry2.service === "agent" && entry2.path === "/done")) return { recorded: false };
152562
- env.trace.record({ source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: answer.output, source: answer.source } });
152576
+ env.trace.record({ source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: answer.output, source: answer.source, ...answer.printed !== void 0 && { printed: answer.printed } } });
152563
152577
  return { recorded: true };
152564
152578
  });
152565
152579
  }
@@ -152874,7 +152888,7 @@ function parseStartOptions(value4) {
152874
152888
  if (input4.delivery !== void 0) parseOptions({ mode: "endpoint", delivery: input4.delivery });
152875
152889
  return input4;
152876
152890
  }
152877
- var MAX_ANSWER_CHARS = 16e3;
152891
+ var MAX_ANSWER_CHARS = 64 * 1024;
152878
152892
  function sessionRoutes(opts, sessions) {
152879
152893
  const app2 = new Hono3();
152880
152894
  const token4 = (header3) => /^Bearer\s+(\S+)\s*$/i.exec(header3 ?? "")?.[1];
@@ -152908,10 +152922,13 @@ function sessionRoutes(opts, sessions) {
152908
152922
  } catch {
152909
152923
  throw new AnchaError("USAGE", "request must be a JSON object");
152910
152924
  }
152911
- fields10(input4, ["output", "source"]);
152925
+ fields10(input4, ["output", "source", "printed"]);
152912
152926
  if (typeof input4.output !== "string" || input4.output.length > MAX_ANSWER_CHARS) throw new AnchaError("USAGE", `output must be a string of at most ${MAX_ANSWER_CHARS} characters`);
152913
152927
  if (input4.source !== "reply" && input4.source !== "stdout") throw new AnchaError("USAGE", "source must be reply or stdout");
152914
- return c.json(await sessions.answer(opts.manager.get(c.req.param("id")), c.req.param("sid"), { output: input4.output, source: input4.source }));
152928
+ if (input4.printed !== void 0 && (input4.source !== "stdout" || input4.output !== "" || typeof input4.printed !== "number" || !Number.isSafeInteger(input4.printed) || input4.printed <= 0)) {
152929
+ throw new AnchaError("USAGE", "printed is how many characters stdout held, with source stdout and an empty output");
152930
+ }
152931
+ return c.json(await sessions.answer(opts.manager.get(c.req.param("id")), c.req.param("sid"), { output: input4.output, source: input4.source, ...input4.printed !== void 0 && { printed: input4.printed } }));
152915
152932
  });
152916
152933
  app2.post("/envs/:id/trials/:sid/agent", async (c) => {
152917
152934
  let input4;
@@ -170938,8 +170955,30 @@ import { lookup as lookup5 } from "node:dns/promises";
170938
170955
  import { createServer, request } from "node:http";
170939
170956
  import { request as secureRequest } from "node:https";
170940
170957
  import { isIP as isIP2 } from "node:net";
170958
+ import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
170941
170959
  var BODY_LIMIT = 8 * 1024 * 1024;
170942
170960
  var HOP_HEADERS = /* @__PURE__ */ new Set(["connection", "proxy-connection", "proxy-authenticate", "proxy-authorization", "keep-alive", "te", "trailer", "transfer-encoding", "upgrade"]);
170961
+ var MODEL_REFUSALS = /* @__PURE__ */ new Set([401, 402, 403, 429]);
170962
+ var REFUSAL_BYTES = 4096;
170963
+ function refusalMessage(body6, encoding) {
170964
+ let text23;
170965
+ try {
170966
+ const raw3 = encoding === "gzip" || encoding === "x-gzip" ? gunzipSync(body6) : encoding === "deflate" ? inflateSync(body6) : encoding === "br" ? brotliDecompressSync(body6) : !encoding || encoding === "identity" ? body6 : void 0;
170967
+ if (raw3 === void 0) return void 0;
170968
+ text23 = raw3.toString("utf8");
170969
+ } catch {
170970
+ return void 0;
170971
+ }
170972
+ let message8 = text23;
170973
+ try {
170974
+ const json33 = JSON.parse(text23);
170975
+ const error64 = json33?.error;
170976
+ message8 = typeof error64 === "string" ? error64 : typeof error64?.message === "string" ? error64.message : typeof json33?.message === "string" ? json33.message : typeof json33?.detail === "string" ? json33.detail : typeof error64?.type === "string" ? error64.type : typeof error64?.code === "string" ? error64.code : text23;
170977
+ } catch {
170978
+ }
170979
+ const line2 = String(message8).replace(/\b(sk|rk|pk)-[\w*-]{4,}/g, "$1-\u2026").replace(/\s+/g, " ").trim();
170980
+ return line2 === "" ? void 0 : line2.length > 300 ? `${line2.slice(0, 299)}\u2026` : line2;
170981
+ }
170943
170982
  function loopbackOrigin(value4) {
170944
170983
  const url4 = new URL(value4);
170945
170984
  if (url4.protocol !== "http:" || !["127.0.0.1", "localhost", "[::1]"].includes(url4.hostname) || url4.username || url4.password) throw new Error("Isolation gateway requires a local HTTP tool server");
@@ -171080,11 +171119,30 @@ async function startIsolationGateway(options3) {
171080
171119
  agent: false,
171081
171120
  ...modelHost && { servername: modelHost, rejectUnauthorized: true, family: modelAddress.family }
171082
171121
  }, (reply5) => {
171083
- if (modelHost !== void 0 && reply5.statusCode !== void 0) {
171122
+ const observe2 = (host, status4, message8) => {
171084
171123
  try {
171085
- options3.onModelReply?.(modelHost, reply5.statusCode);
171124
+ options3.onModelReply?.(host, status4, message8);
171086
171125
  } catch {
171087
171126
  }
171127
+ };
171128
+ if (modelHost !== void 0 && reply5.statusCode !== void 0) {
171129
+ const host = modelHost, status4 = reply5.statusCode;
171130
+ if (!MODEL_REFUSALS.has(status4)) observe2(host, status4);
171131
+ else {
171132
+ const chunks2 = [];
171133
+ let size3 = 0, told = false;
171134
+ const tell = () => {
171135
+ if (told) return;
171136
+ told = true;
171137
+ observe2(host, status4, size3 <= REFUSAL_BYTES ? refusalMessage(Buffer.concat(chunks2), reply5.headers["content-encoding"]?.toLowerCase()) : void 0);
171138
+ };
171139
+ reply5.on("data", (chunk) => {
171140
+ size3 += chunk.length;
171141
+ if (size3 <= REFUSAL_BYTES) chunks2.push(chunk);
171142
+ });
171143
+ reply5.once("end", tell);
171144
+ reply5.once("close", tell);
171145
+ }
171088
171146
  }
171089
171147
  if (reply5.statusCode && reply5.statusCode >= 300 && reply5.statusCode < 400) {
171090
171148
  reply5.destroy();
package/lib/mcp-entry.mjs CHANGED
@@ -57475,7 +57475,7 @@ var AnswerCheckSchema = external_exports.strictObject({
57475
57475
  not_contains: texts.optional().describe("Text the final answer must not contain"),
57476
57476
  numbers: external_exports.array(AnswerNumberSchema).min(1).optional().describe("Numbers the final answer must state, each within its tolerance; thousands separators, currency codes and symbols, minus signs and parentheses for negatives are read"),
57477
57477
  case: external_exports.enum(["insensitive", "sensitive"]).optional().describe("How contains and not_contains compare letters; default insensitive")
57478
- }).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or the last block it prints on stdout): the text and numbers it states");
57478
+ }).describe("Checks the agent's final answer (what it posts to ANCHA_DONE_URL, its HTTP reply, or what it prints on stdout): the text and numbers it states");
57479
57479
 
57480
57480
  // packages/core/src/duration.ts
57481
57481
  var DURATION_RE = /^(-?)(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?(?:(\d+)ms)?$/;