@ancha-labs/cli 0.4.14 → 0.4.15

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
@@ -44474,9 +44474,11 @@ function projectToolCalls(trace) {
44474
44474
  };
44475
44475
  });
44476
44476
  }
44477
+ var isAgentAnswer;
44477
44478
  var init_tool_call_trace = __esm({
44478
44479
  "packages/core/src/tool-call-trace.ts"() {
44479
44480
  "use strict";
44481
+ isAgentAnswer = (entry3) => entry3.source === "agent" && entry3.service === "agent" && entry3.path === "/done";
44480
44482
  }
44481
44483
  });
44482
44484
 
@@ -44566,6 +44568,9 @@ function worldToSceneInput(world5, test3 = {}) {
44566
44568
  pass: test3.pass
44567
44569
  }).filter(([, value5]) => value5 !== void 0));
44568
44570
  }
44571
+ function worldToScene(world5, test3 = {}) {
44572
+ return parseScene(worldToSceneInput(world5, test3));
44573
+ }
44569
44574
  function worldError(issues) {
44570
44575
  return new AnchaError("SCENE_INVALID", issues.map((issue6) => `${issue6.path}: ${issue6.message}`).join("\n"), {
44571
44576
  ...issues.some((issue6) => issue6.hint) && { hint: issues.filter((issue6) => issue6.hint).map((issue6) => issues.length === 1 ? issue6.hint : `${issue6.path}: ${issue6.hint}`).join("\n") }
@@ -215680,6 +215685,11 @@ async function worldFile(cwd, test3, id14) {
215680
215685
  hint: `put the world at ancha/worlds/${id14}.yaml, or generate one: ancha world gen "<the company and the scenario>" --id ${id14}`
215681
215686
  });
215682
215687
  }
215688
+ async function loadWorldFile(cwd, ref22) {
215689
+ const exists7 = (path8) => access3(path8).then(() => true, () => false);
215690
+ const path7 = /\.ya?ml$/.test(ref22) && await exists7(resolve12(cwd, ref22)) ? resolve12(cwd, ref22) : join15(cwd, "ancha", "worlds", `${ref22}.yaml`);
215691
+ return await exists7(path7) ? { path: path7, world: await readWorldFile(cwd, path7) } : void 0;
215692
+ }
215683
215693
  async function readWorldFile(cwd, path7) {
215684
215694
  try {
215685
215695
  const text29 = await readFile5(path7, "utf8"), kept = parsedWorlds.get(path7);
@@ -216609,7 +216619,7 @@ function summarizeScene(sceneId, trials, requestedTrials = trials.length) {
216609
216619
  }
216610
216620
  }
216611
216621
  for (const e of projectToolCalls(t.trace)) {
216612
- if (e.source === "agent") agentCalls2++;
216622
+ if (e.source === "agent" && !isAgentAnswer(e)) agentCalls2++;
216613
216623
  if (e.gap === true) {
216614
216624
  const key4 = JSON.stringify([e.service, e.method, e.path]);
216615
216625
  const gap6 = gaps2.get(key4);
@@ -221270,13 +221280,13 @@ function endedSentence(view3) {
221270
221280
  return view3.exitCode === null ? `The agent stopped on a signal after ${view3.realMs} ms.` : `The agent exited with code ${view3.exitCode} after ${view3.realMs} ms.`;
221271
221281
  }
221272
221282
  function attemptOutcome(view3, ctx) {
221273
- const calls2 = view3.trace.filter((entry3) => entry3.source === "agent" && !isAnswer(entry3));
221283
+ const calls2 = view3.trace.filter((entry3) => entry3.source === "agent" && !isAgentAnswer(entry3));
221274
221284
  const netsuite = calls2.filter((entry3) => entry3.service === "netsuite");
221275
221285
  const unserved = netsuite.filter((entry3) => entry3.gap === true || kindOf2(entry3.path) === "restlet" || kindOf2(entry3.path) === "soap");
221276
221286
  const used = netsuite.filter((entry3) => !unserved.includes(entry3)), data5 = used.filter((entry3) => kindOf2(entry3.path) !== "auth");
221277
221287
  const served = used.filter((entry3) => entry3.status !== void 0 && entry3.status < 400);
221278
221288
  const hosts = netsuiteHosts(view3.log);
221279
- const done = view3.trace.findLast(isAnswer), answer = done === void 0 ? void 0 : answerOf(done);
221289
+ const done = view3.trace.findLast(isAgentAnswer), answer = done === void 0 ? void 0 : answerOf(done);
221280
221290
  const byStatus = {};
221281
221291
  for (const entry3 of calls2) if (entry3.status !== void 0) byStatus[String(entry3.status)] = (byStatus[String(entry3.status)] ?? 0) + 1;
221282
221292
  const gaps2 = [...new Set(calls2.filter((entry3) => entry3.gap === true || unserved.includes(entry3)).map((entry3) => `${entry3.method} ${entry3.path}`))];
@@ -221322,13 +221332,12 @@ function attemptOutcome(view3, ctx) {
221322
221332
  }
221323
221333
  return out({ code: "answered", level: "pass", message: `It answered ${quoted3(answer.text)}.` });
221324
221334
  }
221325
- var isAnswer, oneLine4, quoted3, times, list17, NETSUITE_HOST, netsuiteHosts, customers2, words6, PROVIDER_KEYS, SIGN, OUTSIDE, SERVED, NO_ANSWER, POST_ANSWER;
221335
+ var oneLine4, quoted3, times, list17, NETSUITE_HOST, netsuiteHosts, customers2, words6, PROVIDER_KEYS, SIGN, OUTSIDE, SERVED, NO_ANSWER, POST_ANSWER;
221326
221336
  var init_agent_outcome = __esm({
221327
221337
  "backend/src/agent-outcome.ts"() {
221328
221338
  "use strict";
221329
221339
  init_src();
221330
221340
  init_agent_fix();
221331
- isAnswer = (entry3) => entry3.source === "agent" && entry3.service === "agent" && entry3.path === "/done";
221332
221341
  oneLine4 = (text29) => text29.replace(/\s+/g, " ").trim();
221333
221342
  quoted3 = (text29) => {
221334
221343
  const line2 = oneLine4(text29);
@@ -232168,7 +232177,7 @@ var PlaygroundService = class {
232168
232177
  if (event3.error !== void 0) attempt.error = event3.error.slice(0, 4e3);
232169
232178
  const previous = await this.store.evidence(run6.id, attempt.id);
232170
232179
  const trace = event3.trace ?? previous?.trace ?? [];
232171
- attempt.toolCalls = trace.length;
232180
+ attempt.toolCalls = trace.filter((entry3) => !isAgentAnswer(entry3)).length;
232172
232181
  const snapshot = event3.snapshot;
232173
232182
  const state3 = snapshot ? snapshot.state ?? snapshot : previous?.state;
232174
232183
  const harnessIssues = snapshot?.harnessIssues ?? event3.harnessIssues ?? previous?.harnessIssues;
@@ -238909,7 +238918,15 @@ var CliRuns = class {
238909
238918
  const raw3 = JSON.parse(rawChecks);
238910
238919
  checks2 = Array.isArray(raw3) ? raw3 : Array.isArray(raw3?.checks) ? raw3.checks : [];
238911
238920
  }
238912
- const toolCalls = (await optional2("trace.jsonl", 12e6) ?? "").split("\n").filter((line2) => line2.includes('"source":"agent"')).length;
238921
+ const toolCalls = (await optional2("trace.jsonl", 12e6) ?? "").split("\n").filter((line2) => {
238922
+ if (!line2.trim()) return false;
238923
+ try {
238924
+ const entry3 = JSON.parse(line2);
238925
+ return entry3?.source === "agent" && !isAgentAnswer(entry3);
238926
+ } catch {
238927
+ return false;
238928
+ }
238929
+ }).length;
238913
238930
  let response5;
238914
238931
  try {
238915
238932
  const text29 = await optional2("result.json", 4e6);
@@ -257226,14 +257243,23 @@ function agentVariables(info, scene2) {
257226
257243
  return { ...toolConnectionEnvironment(info.services), ...mcpConnectionEnvironment(info.mcp), ANCHA_ENV_ID: info.id, ...scene2 !== void 0 && { ANCHA_SCENE_ID: scene2.id, ANCHA_TASK: scene2.task } };
257227
257244
  }
257228
257245
  function registerWorldLifecycle(world5, ctx) {
257229
- world5.command("up").description("start a fresh world for your own harness: prints its tools' URLs and fake credentials").option("--scene <file>", "test file (scene.yaml) to start (default: the one test ancha.yaml names)").option("--test <file>", "test file to start; same as --scene").option("--world <id>", "a saved world from ancha world list").option("--on <where>", "local (this computer) or cloud (your workspace); default: the server --server-url, server.url or ANCHA_SERVER_URL names, else this computer").option("--seed <seed>", 'seed for ids and data (default: "<test id>:1")').option("--ttl <duration>", "remove the world after this long with no call from the agent and no ancha world or ancha check command on it", DEFAULT_TTL).action(async (opts) => {
257246
+ world5.command("up").description("start a fresh world for your own harness: prints its tools' URLs and fake credentials").option("--scene <file>", "test file (scene.yaml) to start (default: the one test ancha.yaml names)").option("--test <file>", "test file to start; same as --scene").option("--world <id>", "a world file (ancha/worlds/<id>.yaml) by id or path, or a saved world from ancha world list").option("--on <where>", "local (this computer) or cloud (your workspace); default: the server --server-url, server.url or ANCHA_SERVER_URL names, else this computer").option("--seed <seed>", 'seed for ids and data (default: "<test id>:1")').option("--ttl <duration>", "remove the world after this long with no call from the agent and no ancha world or ancha check command on it", DEFAULT_TTL).action(async (opts) => {
257230
257247
  if ([opts.scene, opts.test, opts.world].filter((value5) => value5 !== void 0).length > 1) throw new AnchaError("USAGE", "choose one of --scene, --test or --world");
257231
257248
  const ttlMs = ttl(opts.ttl);
257249
+ const fileWorld = opts.world !== void 0 ? await loadWorldFile(ctx.io.cwd, opts.world) : void 0;
257232
257250
  const where3 = await target4(ctx, opts.on);
257233
257251
  let scene2, scenePath, configuration, definition3;
257234
- if (opts.world !== void 0) {
257252
+ if (fileWorld !== void 0) {
257253
+ scene2 = worldToScene(fileWorld.world);
257254
+ definition3 = { scene: scene2 };
257255
+ } else if (opts.world !== void 0) {
257235
257256
  let saved;
257236
257257
  if (where3.local || isLoopbackUrl(where3.serverUrl)) {
257258
+ if (!/^world_[a-f0-9-]{36}$/.test(opts.world)) {
257259
+ throw new AnchaError("USAGE", `no world ${opts.world}: no ancha/worlds/${opts.world}.yaml, and ${opts.world} is not a saved world id (world_\u2026)`, {
257260
+ hint: "ancha world list shows saved worlds; world files are in ancha/worlds/ (ancha world gen --dataset netsuite-pe writes one)"
257261
+ });
257262
+ }
257237
257263
  saved = await withService(ctx, (service) => service.world(opts.world));
257238
257264
  } else {
257239
257265
  const key4 = await apiKeyFor(where3.serverUrl, ctx.io.env);
@@ -257254,7 +257280,7 @@ function registerWorldLifecycle(world5, ctx) {
257254
257280
  ctx.out.notice(where3.line);
257255
257281
  const backend = await openBackend({ serverUrl: where3.serverUrl, ...where3.controlToken !== void 0 && { controlToken: where3.controlToken } });
257256
257282
  try {
257257
- const seed43 = opts.seed ?? (opts.world !== void 0 ? "world-1" : void 0);
257283
+ const seed43 = opts.seed ?? (opts.world !== void 0 && fileWorld === void 0 ? "world-1" : void 0);
257258
257284
  const info = scene2 !== void 0 ? await backend.createEnv(scene2, seed43, { ttlMs }) : await backend.createSandbox(configuration, seed43, { ttlMs });
257259
257285
  await recordWorld(ctx.io.cwd, info.id, { serverUrl: where3.serverUrl, workspace: where3.workspace, local: where3.local, ...scenePath !== void 0 && { scene: scenePath }, definition: definition3, createdAt: (/* @__PURE__ */ new Date()).toISOString() });
257260
257286
  const lease = await backend.renewEnv(info.id);
@@ -259569,7 +259595,7 @@ function artifacts(record28, runDir) {
259569
259595
  if (excluded2(attempt.outcome)) scene2.warnings.push({ trial: attempt.number, check: "pytest", message: `${attempt.outcome}: excluded from grading` });
259570
259596
  if (observed.length > 1) scene2.warnings.push({ trial: attempt.number, check: "pytest", message: "This attempt used multiple worlds; state.json and trace.jsonl show the first captured world. All captures are in world-observations.json." });
259571
259597
  const trace = Array.isArray(primary3?.trace) ? primary3.trace : [];
259572
- scene2.agentCalls += attempt.worlds.reduce((sum6, world5) => sum6 + (Array.isArray(world5.capture?.observation.trace) ? world5.capture.observation.trace.filter((entry3) => entry3?.source === "agent").length : 0), 0);
259598
+ scene2.agentCalls += attempt.worlds.reduce((sum6, world5) => sum6 + (Array.isArray(world5.capture?.observation.trace) ? world5.capture.observation.trace.filter((entry3) => entry3?.source === "agent" && !isAgentAnswer(entry3)).length : 0), 0);
259573
259599
  files2.set(`${base3}/checks.json`, json34(checks2));
259574
259600
  files2.set(`${base3}/result.json`, json34({ source: "pytest", outcome: attempt.outcome, reportedOutcome: record28.attempts.find((item2) => item2.number === attempt.number).outcome, startedAt: attempt.startedAt, finishedAt: attempt.finishedAt, errors: attemptErrors(attempt), capture: primary3 ? "observation" : "none" }));
259575
259601
  files2.set(`${base3}/world-observations.json`, json34(attempt.worlds));
@@ -260188,7 +260214,7 @@ var vendorBase = (service) => VENDOR_API_BASES[service] ?? `https://${service}.i
260188
260214
  function attemptToIr(entries4, traceId, agent, saved) {
260189
260215
  const records4 = [];
260190
260216
  for (const e of projectToolCalls(entries4)) {
260191
- if (e.source === "agent" && e.service === "agent" && e.path === "/done") continue;
260217
+ if (isAgentAnswer(e)) continue;
260192
260218
  if (e.source === "agent" && e.service === "tools" && e.path.startsWith("/tools/")) {
260193
260219
  const response5 = e.response;
260194
260220
  records4.push({
package/lib/worker.mjs CHANGED
@@ -40541,9 +40541,11 @@ function projectToolCalls(trace) {
40541
40541
  };
40542
40542
  });
40543
40543
  }
40544
+ var isAgentAnswer;
40544
40545
  var init_tool_call_trace = __esm({
40545
40546
  "packages/core/src/tool-call-trace.ts"() {
40546
40547
  "use strict";
40548
+ isAgentAnswer = (entry2) => entry2.source === "agent" && entry2.service === "agent" && entry2.path === "/done";
40547
40549
  }
40548
40550
  });
40549
40551
 
@@ -203703,7 +203705,7 @@ function summarizeScene(sceneId, trials, requestedTrials = trials.length) {
203703
203705
  }
203704
203706
  }
203705
203707
  for (const e of projectToolCalls(t.trace)) {
203706
- if (e.source === "agent") agentCalls2++;
203708
+ if (e.source === "agent" && !isAgentAnswer(e)) agentCalls2++;
203707
203709
  if (e.gap === true) {
203708
203710
  const key4 = JSON.stringify([e.service, e.method, e.path]);
203709
203711
  const gap6 = gaps2.get(key4);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancha-labs/cli",
3
- "version": "0.4.14",
3
+ "version": "0.4.15",
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": {