@ancha-labs/cli 0.4.1 → 0.4.2

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/README.md CHANGED
@@ -56,11 +56,11 @@ In CI, set `ANCHA_SERVER_URL` and `ANCHA_API_KEY` (both from the Settings page o
56
56
 
57
57
  ## Links
58
58
 
59
- - Docs: https://ancha.mintlify.app (for coding agents: https://ancha.mintlify.app/coding-agents)
59
+ - Docs: https://docs.ancha.io (for coding agents: https://docs.ancha.io/coding-agents)
60
60
  - Machine-readable: https://app.ancha.io/llms.txt
61
61
  - Console: https://app.ancha.io
62
62
  - Website: https://ancha.io
63
63
 
64
64
  ## Support
65
65
 
66
- patrick@ancha.io · Docs: https://ancha.mintlify.app
66
+ patrick@ancha.io · Docs: https://docs.ancha.io
package/lib/ancha.mjs CHANGED
@@ -177730,60 +177730,13 @@ function httpUrl2(value5) {
177730
177730
  }
177731
177731
 
177732
177732
  // packages/cli/src/reproduction.ts
177733
- import { readFile as readFile17 } from "node:fs/promises";
177734
- import { dirname as dirname10, join as join21, resolve as resolve18 } from "node:path";
177735
- async function reproductionOf(summary, scenePaths, cwd, runDir) {
177736
- const out = [];
177737
- const answers = runDir === void 0 ? [] : await toolAnswers(runDir, summary, {});
177738
- for (const scene2 of summary.scenes) {
177739
- const path6 = scenePaths[scene2.sceneId];
177740
- if (path6 === void 0) continue;
177741
- const production3 = await readFile17(join21(dirname10(resolve18(cwd, path6)), "production.json"), "utf8").then((text24) => JSON.parse(text24), () => void 0);
177742
- if (production3?.checks === void 0) continue;
177743
- const checks = Object.entries(production3.checks).flatMap(([check4, result]) => {
177744
- const here = scene2.checks[check4];
177745
- return here === void 0 ? [] : [{ check: check4, production: result, failed: here.total - here.passed, total: here.total }];
177746
- });
177747
- const failedThere = checks.filter((c) => c.production === "failed");
177748
- const verdict = failedThere.length > 0 ? failedThere.every((c) => c.failed * 2 > c.total) ? "reproduced" : failedThere.some((c) => c.failed > 0) ? "partly" : "not-reproduced" : checks.some((c) => c.production === "passed" && c.failed > 0) ? "differs" : checks.some((c) => c.production === "passed") ? "matches" : "unknown";
177749
- const added = Object.keys(scene2.checks).filter((check4) => !(check4 in production3.checks));
177750
- const counts = {};
177751
- for (const a of answers.filter((x) => x.scene === scene2.sceneId)) for (const [source, n] of Object.entries(a.counts)) counts[source] = (counts[source] ?? 0) + n;
177752
- out.push({ sceneId: scene2.sceneId, ...production3.trace !== void 0 && { trace: production3.trace }, verdict, checks, added, ...Object.keys(counts).length && { answers: counts } });
177753
- }
177754
- return out;
177755
- }
177756
- var SAY = {
177757
- reproduced: "production's failure happens here too",
177758
- partly: "production's failure happens here in part",
177759
- "not-reproduced": "production's failure did not happen here: the agent is fixed, or the world differs from production (see questions.json next to the scene)",
177760
- matches: "this run matches production, which passed these checks",
177761
- differs: "checks production passed failed here: a regression, or the world differs from production (see questions.json)",
177762
- unknown: "set OPENROUTER_API_KEY and run again: a model grades these checks on production's record and on this run"
177763
- };
177764
- function renderReproduction(reproductions) {
177765
- return reproductions.map((r) => {
177766
- const width = Math.max(...r.checks.map((c) => c.check.length));
177767
- const rows33 = r.checks.map((c) => ` ${c.check.padEnd(width)} ${c.production} in production \xB7 ${c.total === 0 ? "not run" : `failed ${c.failed}/${c.total} here`}`);
177768
- const also = r.verdict !== "differs" ? r.checks.filter((c) => c.production === "passed" && c.failed > 0).map((c) => c.check) : [];
177769
- return [
177770
- `compared with production${r.trace === void 0 ? "" : ` (trace ${r.trace.slice(0, 12)})`}: ${r.sceneId}`,
177771
- ...rows33,
177772
- `=> ${SAY[r.verdict]}`,
177773
- ...also.length > 0 ? [` also failing here, though production passed: ${also.join(", ")}`] : [],
177774
- // A failure here on a check production is not graded on yet is neither a match nor a regression: say how to grade both.
177775
- ...r.verdict !== "unknown" && r.checks.some((c) => c.production === "unknown" && c.failed > 0) ? [` set OPENROUTER_API_KEY to grade ${r.checks.filter((c) => c.production === "unknown" && c.failed > 0).map((c) => c.check).join(", ")} on production's record and here`] : [],
177776
- ...r.added.length > 0 ? [` checks added after saving, with no production result: ${r.added.join(", ")}`] : [],
177777
- // How much of the run stood on production's own answers (TRACE_PLAN_V2 §8.6).
177778
- ...r.answers ? [` answers to the agent's tools: ${["replayed", "replayed-elsewhere", "twin", "ran", "simulated", "failed"].filter((s) => r.answers[s]).map((s) => `${r.answers[s]} ${s}`).join(", ")}${r.answers.simulated ? "; simulated answers took the agent where production never went (ancha explain lists them)" : ""}`] : []
177779
- ].join("\n");
177780
- }).join("\n\n");
177781
- }
177733
+ import { readFile as readFile18 } from "node:fs/promises";
177734
+ import { dirname as dirname11, join as join22, resolve as resolve18 } from "node:path";
177782
177735
 
177783
177736
  // backend/src/production.ts
177784
177737
  import { createHash as createHash57 } from "node:crypto";
177785
- import { readFile as readFile18, writeFile as writeFile10 } from "node:fs/promises";
177786
- import { dirname as dirname11, join as join22 } from "node:path";
177738
+ import { readFile as readFile17, writeFile as writeFile10 } from "node:fs/promises";
177739
+ import { dirname as dirname10, join as join21 } from "node:path";
177787
177740
 
177788
177741
  // node_modules/.pnpm/openai@7.43.0_@aws-sdk+credential-provider-node@3.972.91_@smithy+signature-v4@5.7.5_undici@8.12.3_ws@8.22.0_zod@4.6.7/node_modules/openai/internal/tslib.mjs
177789
177742
  function __classPrivateFieldSet(receiver, state3, value5, kind, f) {
@@ -201288,13 +201241,17 @@ function productionTrace(lines) {
201288
201241
  if (invocation?.output !== void 0) entries2.push({ seq: ++seq2, tSim: "", tReal: 0, source: "agent", service: "agent", method: "POST", path: "/done", status: 200, request: { output: invocation.output } });
201289
201242
  return entries2;
201290
201243
  }
201244
+ async function productionRecord(dir2) {
201245
+ const text24 = await readFile17(join21(dir2, "production.jsonl"), "utf8").catch(() => void 0);
201246
+ return text24 === void 0 ? void 0 : productionTrace(text24.split("\n").filter(Boolean).map((line2) => JSON.parse(line2)));
201247
+ }
201291
201248
  async function completeProduction(scenePath, scene2, judge) {
201292
- const dir2 = dirname11(scenePath);
201293
- const text24 = await readFile18(join22(dir2, "production.jsonl"), "utf8").catch(() => void 0);
201249
+ const dir2 = dirname10(scenePath);
201250
+ const text24 = await readFile17(join21(dir2, "production.jsonl"), "utf8").catch(() => void 0);
201294
201251
  if (text24 === void 0) return [];
201295
201252
  const lines = text24.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
201296
- const file3 = join22(dir2, "production.json");
201297
- const known2 = await readFile18(file3, "utf8").then((t) => JSON.parse(t), () => ({}));
201253
+ const file3 = join21(dir2, "production.json");
201254
+ const known2 = await readFile17(file3, "utf8").then((t) => JSON.parse(t), () => ({}));
201298
201255
  const checks = { ...known2.checks }, signatures = { ...known2.signatures };
201299
201256
  const sign2 = (check4) => createHash57("sha256").update(JSON.stringify(check4)).digest("hex").slice(0, 12);
201300
201257
  const missing6 = scene2.checks.filter((check4) => checks[check4.id] === void 0 || checks[check4.id] === "unknown" || signatures[check4.id] !== void 0 && signatures[check4.id] !== sign2(check4));
@@ -201323,6 +201280,80 @@ async function completeProduction(scenePath, scene2, judge) {
201323
201280
  return missing6.map((check4) => check4.id);
201324
201281
  }
201325
201282
 
201283
+ // packages/cli/src/reproduction.ts
201284
+ async function reproductionOf(summary, scenePaths, cwd, runDir, scenes = []) {
201285
+ const out = [];
201286
+ const answers = runDir === void 0 ? [] : await toolAnswers(runDir, summary, {});
201287
+ for (const scene2 of summary.scenes) {
201288
+ const path6 = scenePaths[scene2.sceneId];
201289
+ if (path6 === void 0) continue;
201290
+ const production3 = await readFile18(join22(dirname11(resolve18(cwd, path6)), "production.json"), "utf8").then((text24) => JSON.parse(text24), () => void 0);
201291
+ if (production3?.checks === void 0) continue;
201292
+ const checks = Object.entries(production3.checks).flatMap(([check4, result]) => {
201293
+ const here = scene2.checks[check4];
201294
+ return here === void 0 ? [] : [{ check: check4, production: result, failed: here.total - here.passed, total: here.total }];
201295
+ });
201296
+ const failedThere = checks.filter((c) => c.production === "failed");
201297
+ const verdict = failedThere.length > 0 ? failedThere.every((c) => c.failed * 2 > c.total) ? "reproduced" : failedThere.some((c) => c.failed > 0) ? "partly" : "not-reproduced" : checks.some((c) => c.production === "passed" && c.failed > 0) ? "differs" : checks.some((c) => c.production === "passed") ? "matches" : "unknown";
201298
+ const added = Object.keys(scene2.checks).filter((check4) => !(check4 in production3.checks));
201299
+ const counts = {};
201300
+ for (const a of answers.filter((x) => x.scene === scene2.sceneId)) for (const [source, n] of Object.entries(a.counts)) counts[source] = (counts[source] ?? 0) + n;
201301
+ const defined = scenes.find((s) => s.id === scene2.sceneId);
201302
+ const writes2 = defined === void 0 || runDir === void 0 || !writeTools(defined).size ? void 0 : await writesOf(defined, dirname11(resolve18(cwd, path6)), runDir, scene2);
201303
+ out.push({ sceneId: scene2.sceneId, ...production3.trace !== void 0 && { trace: production3.trace }, verdict, checks, added, ...Object.keys(counts).length && { answers: counts }, ...writes2 !== void 0 && { writes: writes2 } });
201304
+ }
201305
+ return out;
201306
+ }
201307
+ async function writesOf(scene2, dir2, runDir, ran) {
201308
+ const record23 = await productionRecord(dir2);
201309
+ if (record23 === void 0) return void 0;
201310
+ const made = /* @__PURE__ */ new Map(), here = /* @__PURE__ */ new Map();
201311
+ for (const action of actionsOf(scene2, record23)) made.set(action.tool, (made.get(action.tool) ?? 0) + 1);
201312
+ const trials = (ran.trialsDetail ?? []).filter((t) => t.valid !== false);
201313
+ for (const { trial } of trials) {
201314
+ const text24 = await readFile18(join22(runDir, `trial-${ran.sceneId}-${trial}`, "trace.jsonl"), "utf8").catch(() => "");
201315
+ const trace = text24.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
201316
+ for (const tool of new Set(actionsOf(scene2, trace).map((action) => action.tool))) here.set(tool, (here.get(tool) ?? 0) + 1);
201317
+ }
201318
+ const tools2 = [...made.keys(), ...[...here.keys()].filter((tool) => !made.has(tool)).sort()];
201319
+ return { of: trials.length, tools: tools2.map((tool) => ({ tool, production: made.get(tool) ?? 0, trials: here.get(tool) ?? 0 })) };
201320
+ }
201321
+ function renderWrites(writes2) {
201322
+ const of = `${writes2.of} ${writes2.of === 1 ? "trial" : "trials"}`;
201323
+ if (!writes2.tools.length) return [` writes compared with production: none in production, none in this run's ${of}`];
201324
+ const called = (n) => n === 0 ? "not called" : n === 1 ? "called" : `called ${n} times`;
201325
+ const width = Math.max(...writes2.tools.map((w) => w.tool.length)), said = Math.max(...writes2.tools.map((w) => called(w.production).length));
201326
+ return [" writes compared with production:", ...writes2.tools.map((w) => ` ${w.tool.padEnd(width)} production: ${called(w.production).padEnd(said)} this run: ${w.trials} of ${of}`)];
201327
+ }
201328
+ var SAY = {
201329
+ reproduced: "production's failure happens here too",
201330
+ partly: "production's failure happens here in part",
201331
+ "not-reproduced": "production's failure did not happen here: the agent is fixed, or the world differs from production (see questions.json next to the scene)",
201332
+ matches: "this run matches production, which passed these checks",
201333
+ differs: "checks production passed failed here: a regression, or the world differs from production (see questions.json)",
201334
+ unknown: "set OPENROUTER_API_KEY and run again: a model grades these checks on production's record and on this run"
201335
+ };
201336
+ function renderReproduction(reproductions) {
201337
+ return reproductions.map((r) => {
201338
+ const width = Math.max(...r.checks.map((c) => c.check.length));
201339
+ const rows33 = r.checks.map((c) => ` ${c.check.padEnd(width)} ${c.production} in production \xB7 ${c.total === 0 ? "not run" : `failed ${c.failed}/${c.total} here`}`);
201340
+ const also = r.verdict !== "differs" ? r.checks.filter((c) => c.production === "passed" && c.failed > 0).map((c) => c.check) : [];
201341
+ return [
201342
+ `compared with production${r.trace === void 0 ? "" : ` (trace ${r.trace.slice(0, 12)})`}: ${r.sceneId}`,
201343
+ ...rows33,
201344
+ `=> ${SAY[r.verdict]}`,
201345
+ ...also.length > 0 ? [` also failing here, though production passed: ${also.join(", ")}`] : [],
201346
+ // A failure here on a check production is not graded on yet is neither a match nor a regression: say how to grade both.
201347
+ ...r.verdict !== "unknown" && r.checks.some((c) => c.production === "unknown" && c.failed > 0) ? [` set OPENROUTER_API_KEY to grade ${r.checks.filter((c) => c.production === "unknown" && c.failed > 0).map((c) => c.check).join(", ")} on production's record and here`] : [],
201348
+ ...r.added.length > 0 ? [` checks added after saving, with no production result: ${r.added.join(", ")}`] : [],
201349
+ // How much of the run stood on production's own answers (TRACE_PLAN_V2 §8.6).
201350
+ ...r.answers ? [` answers to the agent's tools: ${["replayed", "replayed-elsewhere", "twin", "ran", "simulated", "failed"].filter((s) => r.answers[s]).map((s) => `${r.answers[s]} ${s}`).join(", ")}${r.answers.simulated ? "; simulated answers took the agent where production never went (ancha explain lists them)" : ""}`] : [],
201351
+ // What the agent changed, next to what production changed: an answer that needs no model (SPEC-020 R1).
201352
+ ...r.writes !== void 0 && r.writes.of > 0 ? renderWrites(r.writes) : []
201353
+ ].join("\n");
201354
+ }).join("\n\n");
201355
+ }
201356
+
201326
201357
  // backend/src/runner/run.ts
201327
201358
  init_src();
201328
201359
  import { randomInt } from "node:crypto";
@@ -203030,7 +203061,7 @@ async function executePreparedRun(ctx, input2, initial, ready2) {
203030
203061
  const upload3 = await uploadFinished(ctx, input2, summary.runId);
203031
203062
  await writer.finish({ state: "finished", exitCode: ctx.exitCode, ...upload3 !== void 0 && { upload: keptUpload(upload3, summary.runId) } });
203032
203063
  if (ctx.exitCode === EXIT_STRICT_GAP) ctx.out.info("--strict: the agent hit an endpoint Ancha does not implement (see coverage gaps)");
203033
- emitFinished(ctx, summary, input2.out, upload3, input2.uploadHint, await reproductionOf(summary, input2.scenePaths, ctx.io.cwd, join31(resolve23(ctx.io.cwd, input2.out ?? DEFAULT_RUNS_DIR), summary.runId)));
203064
+ emitFinished(ctx, summary, input2.out, upload3, input2.uploadHint, await reproductionOf(summary, input2.scenePaths, ctx.io.cwd, join31(resolve23(ctx.io.cwd, input2.out ?? DEFAULT_RUNS_DIR), summary.runId), input2.scenes));
203034
203065
  } catch (error64) {
203035
203066
  const code4 = toErrorJson(error64).code;
203036
203067
  const interrupted2 = error64 instanceof AnchaError && error64.code === "USAGE" && error64.message === "run interrupted";
@@ -203786,12 +203817,12 @@ function registerSimulate(sceneCommand, ctx) {
203786
203817
  }
203787
203818
 
203788
203819
  // packages/cli/src/kit/init.ts
203789
- var import_yaml13 = __toESM(require_dist(), 1);
203790
- init_src();
203791
203820
  import { constants as constants5 } from "node:fs";
203792
203821
  import { lstat as lstat6, mkdir as mkdir18, open as open5, readFile as readFile31, rm as rm9, writeFile as writeFile18 } from "node:fs/promises";
203793
203822
  import { join as join42 } from "node:path";
203794
203823
  import { Writable } from "node:stream";
203824
+ var import_yaml13 = __toESM(require_dist(), 1);
203825
+ init_src();
203795
203826
 
203796
203827
  // packages/cli/src/kit/seeds.ts
203797
203828
  var import_yaml9 = __toESM(require_dist(), 1);
@@ -205025,7 +205056,7 @@ function registerTestNew(tests, ctx) {
205025
205056
  init_src();
205026
205057
  init_assets();
205027
205058
  import { readFile as readFile30 } from "node:fs/promises";
205028
- var DOC_TOPICS = ["setup", "apps", "run", "explain", "compare", "scenes", "integrations", "cloud", "playgrounds", "cli-quickstart", "tools"];
205059
+ var DOC_TOPICS = ["setup", "apps", "run", "traces", "explain", "compare", "scenes", "integrations", "cloud", "playgrounds", "cli-quickstart", "tools"];
205029
205060
  async function loadDoc(topic = "setup") {
205030
205061
  if (!DOC_TOPICS.includes(topic)) throw new AnchaError("USAGE", `unknown docs topic: ${topic}`, { hint: `available topics: ${DOC_TOPICS.join(", ")}` });
205031
205062
  return { topics: [...DOC_TOPICS], topic, markdown: await readFile30(new URL(`docs/${topic}.md`, assetRoot()), "utf8") };
@@ -205161,7 +205192,7 @@ async function addExampleSeeds(file3, twins) {
205161
205192
  return { added, skipped };
205162
205193
  }
205163
205194
  function registerKit(program2, ctx) {
205164
- program2.command("init").description("set up agent tests in this project: ancha.yaml, a starter scene for the tools it uses, coding-agent instructions; installs and runs nothing").option("--agent <command>", "the command that starts your agent (default: package.json scripts.start, a Procfile, pyproject.toml [project.scripts] or the Dockerfile CMD)").option("--template <template>", "starter or incidents", "starter").option("--intent <description>", "also generate a world (company, people, tool history) from this description and draft a first test with people for it (uses a model)").option("--idempotency-key <key>", "with --intent: return the first world and test for a repeated request instead of generating again").action(async (opts) => {
205195
+ program2.command("init").description("set up agent tests in this project: ancha.yaml, a starter scene for the tools it uses, coding-agent instructions; installs and runs nothing").option("--agent <command>", "the command that starts your agent (default: package.json scripts.start, a Procfile, pyproject.toml [project.scripts] or the Dockerfile CMD)").option("--template <template>", "starter or incidents", "starter").option("--intent <description>", "also generate a world (company, people, tool history) from this description and draft a first test with people for it (uses a model)").option("--idempotency-key <key>", "with --intent: return the first world and test for a repeated request instead of generating again").action(async (opts, command) => {
205165
205196
  if (opts.template !== "starter" && opts.template !== "incidents") throw new AnchaError("USAGE", `unknown template: ${opts.template}`, { hint: "available templates: starter, incidents" });
205166
205197
  if (opts.intent !== void 0 && !(ctx.io.env.ANCHA_PEOPLE_BASE_URL && ctx.io.env.ANCHA_PEOPLE_API_KEY) && (await modelAccess(ctx.io.env)).kind === "none") {
205167
205198
  throw new AnchaError("CONFIG_INVALID", "init --intent needs a model key", { hint: "set OPENROUTER_API_KEY, or log in to your workspace with ancha login; or run ancha init without --intent" });
@@ -205170,7 +205201,9 @@ function registerKit(program2, ctx) {
205170
205201
  const used = detection.sdks;
205171
205202
  const twins = used.length > 0 ? [...used] : [...STARTER_TWINS];
205172
205203
  const unchecked = twins.filter((twin) => !hasAccessCheck(twin));
205173
- const templates = opts.template === "starter" ? (await starterPack("starter", `Reach ${twins.map(toolName).join(", ")}`, twins)).filter((file3) => ["scene.yaml", "oracle.mjs", "null.mjs"].includes(file3.relativePath)) : await templateFiles(opts.template);
205204
+ const existing2 = opts.template === "starter" && command.getOptionValueSource("template") !== "cli" ? (await glob3("scenes/**/scene.yaml", { cwd: ctx.io.cwd, onlyFiles: true, followSymbolicLinks: false })).sort() : [];
205205
+ const starter = opts.template === "starter" && existing2.length === 0;
205206
+ const templates = existing2.length > 0 ? [] : opts.template === "starter" ? (await starterPack("starter", `Reach ${twins.map(toolName).join(", ")}`, twins)).filter((file3) => ["scene.yaml", "oracle.mjs", "null.mjs"].includes(file3.relativePath)) : await templateFiles(opts.template);
205174
205207
  const files2 = [
205175
205208
  { relativePath: "ancha.yaml", content: `${detection.agent === null ? "# Set agent.command to the command that starts your agent.\n" : (0, import_yaml13.stringify)({ agent: { command: detection.agent } })}scenes: [scenes/**/scene.yaml${opts.intent !== void 0 ? ", ancha/tests/*.yaml" : ""}]
205176
205209
  trials: 1
@@ -205204,14 +205237,15 @@ min_pass_rate: 1
205204
205237
  result.created.push(...world5.files, test3.file, test3.record);
205205
205238
  }
205206
205239
  const next2 = detection.agent === null ? ["set agent.command in ancha.yaml", "ancha run"] : generated ? [`ancha run ${generated.test.file} --json`] : ["ancha run"];
205207
- const output2 = { ...result, updated, detection, template: opts.template, ...opts.template === "starter" && { tools: twins, ...unchecked.length > 0 && { unchecked } }, ...generated, next: next2 };
205240
+ const output2 = { ...result, updated, detection, template: opts.template, ...starter && { tools: twins, ...unchecked.length > 0 && { unchecked } }, ...existing2.length > 0 && { scenes: existing2 }, ...generated, next: next2 };
205208
205241
  const agent = detection.agent === null ? "no start command found (package.json scripts.start, Procfile, pyproject.toml, Dockerfile)" : `${detection.agent}${detection.agentSource === "explicit" ? "" : ` (from ${detection.agentSource})`}`;
205209
205242
  const names3 = (list16) => list16.map(toolName).join(", ");
205210
205243
  ctx.out.result(output2, () => [
205211
205244
  `Created ${result.created.length} files; updated ${updated.length}; preserved ${result.skipped.length}.`,
205212
205245
  `agent: ${agent}`,
205213
- ...opts.template === "starter" ? [`starter: ${names3(twins)}${used.length > 0 ? "" : " (no tool SDK recognized in the dependencies)"}`] : [],
205214
- ...opts.template === "starter" && unchecked.length > 0 ? [` ${names3(unchecked)}: seeded; no access check, since ${unchecked.length === 1 ? "its" : "their"} requests need signing or a token exchange; add checks of your own`] : [],
205246
+ ...starter ? [`starter: ${names3(twins)}${used.length > 0 ? "" : " (no tool SDK recognized in the dependencies)"}`] : [],
205247
+ ...existing2.length > 0 ? [`scenes: ${existing2.length} already in scenes/ (${existing2.slice(0, 2).join(", ")}${existing2.length > 2 ? ", \u2026" : ""})${result.created.includes("ancha.yaml") ? "; ancha.yaml runs them" : ""}; ancha init --template starter adds the starter scene`] : [],
205248
+ ...starter && unchecked.length > 0 ? [` ${names3(unchecked)}: seeded; no access check, since ${unchecked.length === 1 ? "its" : "their"} requests need signing or a token exchange; add checks of your own`] : [],
205215
205249
  ...generated ? [`world: ${generated.world.file} (people: ${generated.world.people.join(", ") || "none"})`] : [],
205216
205250
  ...notGenerated?.added.length ? [` world gen populates ${gen_exports.GENERATED_TOOLS.join(", ")}; ${names3(notGenerated.added)} got ${notGenerated.added.length === 1 ? "its" : "their"} example data instead (ancha twins seed <tool> shows the fields)`] : [],
205217
205251
  ...notGenerated?.skipped.length ? [` ${names3(notGenerated.skipped)}: not in the world (the example data clashes with it); add a seed by hand (ancha twins seed <tool>)`] : [],
@@ -15,7 +15,7 @@ Add `--json` to every command. Runs print NDJSON events that end with `run_finis
15
15
 
16
16
  ## The loop
17
17
 
18
- 1. `ancha init --agent "<the command that starts the agent>"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/`, the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.
18
+ 1. `ancha init --agent "<the command that starts the agent>"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/` (when `scenes/` holds no tests yet), the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.
19
19
  2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.
20
20
  3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.
21
21
  4. `ancha explain latest --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.
@@ -23,6 +23,8 @@ Add `--json` to every command. Runs print NDJSON events that end with `run_finis
23
23
  6. Fix the agent's code.
24
24
  7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.
25
25
 
26
+ With production traces (an export from the user's tracing), `ancha import --offline <trace file> --json` writes one test per conversation under `scenes/from-traces/`, and `ancha run scenes/from-traces/*/scene.yaml --json` runs them. More: `ancha docs traces`.
27
+
26
28
  The starter scene only proves that the agent reaches each tool. For the agent's real job, `ancha test new "<the test in one sentence>" --json` drafts a test with people for the project's world (`ancha init --intent "<company and scenario>"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a scene can make on it. More: `ancha docs scenes`.
27
29
 
28
30
  ## An app, not a command
@@ -37,7 +39,7 @@ A production run that went wrong becomes a test here. With a trace file (an expo
37
39
  2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).
38
40
  3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; the import also lists the app's own setup calls, which the start script or an `app_call` has to make.
39
41
 
40
- If the user's workspace takes traces (their agents send them to it), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` saves it, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. A workspace that doesn't take traces says so; use the file.
42
+ If the user's workspace takes traces (their agents send them to it), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` saves it, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. A workspace that doesn't take traces says so; use the file. More: `ancha docs traces`.
41
43
 
42
44
  ## The rule
43
45
 
@@ -74,6 +76,6 @@ Running the agent itself in the cloud is a console flow at https://app.ancha.io:
74
76
  - Exit 3: infrastructure, or a trial the harness couldn't complete. That's not the agent's fault; run again, and `ancha doctor --json` if it repeats.
75
77
  - Exit 4, only with `--strict`: the agent called an endpoint a replica doesn't implement. `ancha explain` lists these coverage gaps even without `--strict`; check `ancha twins coverage <tool>` before changing the agent.
76
78
 
77
- Every error has a stable `code` and a `hint` that names the next command. More: `ancha docs`, `ancha docs <topic>` for setup, run, explain, compare, scenes, integrations, cloud and playgrounds, and https://ancha.mintlify.app/coding-agents.
79
+ Every error has a stable `code` and a `hint` that names the next command. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.
78
80
 
79
81
  Tell the user what you ran, the pass rate and the evidence. Never claim a fix until `ancha run --compare` exits 0.
@@ -1,7 +1,7 @@
1
1
  <!-- ancha:begin -->
2
2
  ## Ancha agent tests
3
3
 
4
- 1. `ancha init --agent "<the command that starts the agent>"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/`, the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.
4
+ 1. `ancha init --agent "<the command that starts the agent>"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/` (when `scenes/` holds no tests yet), the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.
5
5
  2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.
6
6
  3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.
7
7
  4. `ancha explain latest --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.
@@ -9,6 +9,8 @@
9
9
  6. Fix the agent's code.
10
10
  7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.
11
11
 
12
+ With production traces (an export from the user's tracing), `ancha import --offline <trace file> --json` writes one test per conversation under `scenes/from-traces/`, and `ancha run scenes/from-traces/*/scene.yaml --json` runs them. More: `ancha docs traces`.
13
+
12
14
  The starter scene only proves that the agent reaches each tool. For the agent's real job, `ancha test new "<the test in one sentence>" --json` drafts a test with people for the project's world (`ancha init --intent "<company and scenario>"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a scene can make on it. More: `ancha docs scenes`.
13
15
 
14
16
  Fix the agent, not `ancha.yaml`, the scenes or their checks. The exception is a check that is wrong for the real API, such as a method the official SDK never sends. Then don't quietly edit it: tell the user, show the evidence (the call from `ancha explain`, the vendor's documentation), and change it only with their agreement.
@@ -39,4 +39,4 @@ Add `--json` to any command for one JSON object, or NDJSON events for runs. Erro
39
39
 
40
40
  ## Topics
41
41
 
42
- `ancha docs <topic>`: `setup` (this page), `apps` (an app with its database and scheduled jobs, and traces made into tests on this computer), `run`, `explain`, `compare`, `scenes`, `integrations` (SDK settings per tool), `cloud` (login, CI, secrets), `playgrounds` and `cli-quickstart` (agents in containers, tasks, attempts), `tools` (seeded tools without a scene).
42
+ `ancha docs <topic>`: `setup` (this page), `apps` (an app with its database and scheduled jobs, and traces made into tests on this computer), `run`, `traces` (tests from production traces, and a run compared with production), `explain`, `compare`, `scenes`, `integrations` (SDK settings per tool), `cloud` (login, CI, secrets), `playgrounds` and `cli-quickstart` (agents in containers, tasks, attempts), `tools` (seeded tools without a scene).
@@ -0,0 +1,43 @@
1
+ # Tests from production traces
2
+
3
+ A run of the agent in production becomes a test: the conversation it had, the calls it made with their answers, and how it ended. `ancha import` makes one test per conversation in a trace file.
4
+
5
+ ## Make the tests
6
+
7
+ - `ancha import --offline <trace file> --json` makes them on this computer and uploads nothing. A file is OTLP JSON, a Langfuse or LangSmith export, or Ancha Trace IR.
8
+ - `ancha import --from langfuse <trace id>` and `ancha import --from langsmith <trace id>` fetch the trace with the keys in this shell (`LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_HOST`; `LANGSMITH_API_KEY`, `LANGSMITH_ENDPOINT`).
9
+ - After `ancha login`, `ancha import <trace file>` sends the trace to the workspace, which saves the test and writes it here. When the agent sends its traces to the workspace, `ancha traces --failed --json` lists the runs where production failed a check, `ancha traces show <id> --json` previews a test and `ancha pull <id> --json` saves it.
10
+ - `--expect "<what went wrong>"` adds a check for it, `--conversation <id>` takes one conversation of the file, `--dest <dir>` sets the folder (default `scenes/from-traces`) and `--force` replaces a `scene.yaml` that is already there.
11
+
12
+ Each test is a folder, `scenes/from-traces/trace-<id>/`: `scene.yaml` (the trigger or the customer, the tools, the checks), `observations.jsonl` (production's calls with their answers), `production.jsonl` (production's run), `production.json` (each check's result in production), `provenance.json` and `questions.json`.
13
+
14
+ ## Answer its questions
15
+
16
+ The import lists the questions the trace leaves open, each with the default the test uses. Ask the user, then import again with the answers:
17
+
18
+ `ancha import --offline <trace file> --force --answer tools.mcp=lookup_order --answer tools.simulate_writes=none`
19
+
20
+ - `tools.mcp`: the tools the agent reaches over MCP, served at `{{tools.mcp_url}}`. The agent wraps the others: `wrapTools` from `@ancha-labs/tools`, `ancha.wrap_tools` in Python.
21
+ - `tools.simulate_writes`: the writes a test simulates when the agent makes one production never made; the others fail.
22
+ - `tools.pure`: tools that only compute from their arguments; a test runs them itself.
23
+ - `checks.success`: what the agent should have done, when nothing in the trace says what went wrong.
24
+
25
+ ## Run them
26
+
27
+ In a project without `ancha.yaml`, run `ancha init --agent "<the command that starts the agent>"` first; with tests already in `scenes/`, it writes no starter scene. Then:
28
+
29
+ `ancha run scenes/from-traces/*/scene.yaml --json`
30
+
31
+ Before the trials, `ancha run` computes production's result for each check from `production.jsonl`. After them, it compares the run with production check by check and says whether production's failure happened again. Checks a model grades need `OPENROUTER_API_KEY`. The agent's writes are compared by tool, with no model. A run of `node -e 0` as the agent:
32
+
33
+ ```text
34
+ compared with production (trace 10a33ccbbbbc): trace-db5e4ace-10a33ccb
35
+ resolves_the_request unknown in production · failed 1/1 here
36
+ => set OPENROUTER_API_KEY and run again: a model grades these checks on production's record and on this run
37
+ writes compared with production:
38
+ add_emoji_reaction production: called 3 times this run: 0 of 1 trial
39
+ create_support_ticket production: called this run: 0 of 1 trial
40
+ mark_resolved production: called this run: 0 of 1 trial
41
+ ```
42
+
43
+ When a test doesn't fail the way production did, `ancha traces diff <trace file> latest/trial-<scene>-1` lists the calls only production made, the calls only the trial made, and the first call where they part.
@@ -2,14 +2,14 @@
2
2
 
3
3
  > Simulation playgrounds for agents: stateful replicas of the tools an agent uses (Slack, GitHub, Datadog, PagerDuty and more), seeded worlds of one fictional company, and attempts graded by checks on the agent's calls and the world's end state. A coding agent drives everything from the CLI with --json.
4
4
 
5
- This file adds only what is specific to app.ancha.io, the hosted workspace; the documentation lives at https://ancha.mintlify.app and its pages are listed below. The package is `@ancha-labs/cli` and its command is `ancha`; never run `npx` with the bare package name `ancha`, which is not this package.
5
+ This file adds only what is specific to app.ancha.io, the hosted workspace; the documentation lives at https://docs.ancha.io and its pages are listed below. The package is `@ancha-labs/cli` and its command is `ancha`; never run `npx` with the bare package name `ancha`, which is not this package.
6
6
 
7
7
  ## Docs
8
8
 
9
- - [Docs for agents](https://ancha.mintlify.app/llms.txt): every page, machine-readable
10
- - [Everything in one file](https://ancha.mintlify.app/llms-full.txt)
11
- - [For coding agents](https://ancha.mintlify.app/coding-agents): the page to read first
12
- - [Quickstart](https://ancha.mintlify.app/quickstart): install, init and the first run
9
+ - [Docs for agents](https://docs.ancha.io/llms.txt): every page, machine-readable
10
+ - [Everything in one file](https://docs.ancha.io/llms-full.txt)
11
+ - [For coding agents](https://docs.ancha.io/coding-agents): the page to read first
12
+ - [Quickstart](https://docs.ancha.io/quickstart): install, init and the first run
13
13
 
14
14
  ## Start
15
15
 
@@ -1639,7 +1639,7 @@ function starterCount(tool, key, state) {
1639
1639
  }
1640
1640
 
1641
1641
  // frontend/src/generated/coding-agent-skill.ts
1642
- var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, and prove a fix with graded runs. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; everything else prints one JSON object. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, scene files and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## The loop\n\n1. `ancha init --agent \"<the command that starts the agent>\"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/`, the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.\n2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.\n3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.\n4. `ancha explain latest --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n5. `ancha baseline save before` keeps the failing run as the reference.\n6. Fix the agent's code.\n7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.\n\nThe starter scene only proves that the agent reaches each tool. For the agent's real job, `ancha test new \"<the test in one sentence>\" --json` drafts a test with people for the project's world (`ancha init --intent \"<company and scenario>\"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a scene can make on it. More: `ancha docs scenes`.\n\n## An app, not a command\n\nIf the AI feature lives inside an app (a web app or API server with its database, workers and scheduled jobs), don't wrap it in `agent.command`. Ancha starts the app once per trial with `agent.start`, waits for `agent.ready_url`, delivers the tools' events to `agent.url`, and a scene's `world_rules.app_calls` call the app's own routes, such as its cron jobs, at a time. Read `ancha docs apps` before writing `ancha.yaml`. The start script gives the app a clean database, cache and seed every trial: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## From a production failure\n\nA production run that went wrong becomes a test here. With a trace file (an export from the user's tracing):\n\n1. `ancha import --offline <trace file> --json` makes the test on this computer and uploads nothing. It writes `scenes/from-traces/<name>/scene.yaml` and lists the questions one trace cannot settle, each with the default the test uses.\n2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).\n3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` saves it, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. A workspace that doesn't take traces says so; use the file.\n\n## The rule\n\nFix the agent, not `ancha.yaml`, the scenes or their checks. The exception is a check that is wrong for the real API, such as a method the official SDK never sends. Then don't quietly edit it: tell the user, show the evidence (the call from `ancha explain`, the vendor's documentation), and change it only with their agreement.\n\nNever give the agent under test the scenes, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach trial gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\n`ancha run` starts the agent on this computer. It has this computer's network, and an environment limited to Ancha's variables, the tools' variables and the names allowed in `agent.pass_env` in `ancha.yaml` (or `--pass-env NAME`). The agent's own model key is one of those names: `agent.pass_env: [OPENROUTER_API_KEY]` passes it from this shell, and `agent.env` sets fixed values, such as the path of a key file. Without it, an agent that calls a model stops at its first call. For a sealed run, set `agent.execution: { mode: container, image: node:24-slim }` in `ancha.yaml`; it needs Docker.\n\n## Hosted workspace\n\nIf the user has an Ancha workspace, `ancha login` asks them to approve this computer once in the browser; ask them to do it. After that, `ancha run` still runs its worlds on this computer; `ancha run --upload --json` sends the finished run to their workspace, where the console shows it (`upload.url` in the JSON). `ancha whoami --json` shows the workspace and where runs put their worlds. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login: `ancha run --local --upload --json`. `ancha secrets set NAME` copies a provider key from this shell into the workspace for agents that run there.\n\nRunning the agent itself in the cloud is a console flow at https://app.ancha.io: Bring your agent, Connect, tasks with checks, Run. Send the user there for it.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain latest --json`.\n- Exit 2: usage, config, scene or authentication error. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`. Read the `hint`.\n- Exit 3: infrastructure, or a trial the harness couldn't complete. That's not the agent's fault; run again, and `ancha doctor --json` if it repeats.\n- Exit 4, only with `--strict`: the agent called an endpoint a replica doesn't implement. `ancha explain` lists these coverage gaps even without `--strict`; check `ancha twins coverage <tool>` before changing the agent.\n\nEvery error has a stable `code` and a `hint` that names the next command. More: `ancha docs`, `ancha docs <topic>` for setup, run, explain, compare, scenes, integrations, cloud and playgrounds, and https://ancha.mintlify.app/coding-agents.\n\nTell the user what you ran, the pass rate and the evidence. Never claim a fix until `ancha run --compare` exits 0.\n";
1642
+ var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, and prove a fix with graded runs. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; everything else prints one JSON object. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, scene files and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## The loop\n\n1. `ancha init --agent \"<the command that starts the agent>\"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/` (when `scenes/` holds no tests yet), the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.\n2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.\n3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.\n4. `ancha explain latest --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n5. `ancha baseline save before` keeps the failing run as the reference.\n6. Fix the agent's code.\n7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.\n\nWith production traces (an export from the user's tracing), `ancha import --offline <trace file> --json` writes one test per conversation under `scenes/from-traces/`, and `ancha run scenes/from-traces/*/scene.yaml --json` runs them. More: `ancha docs traces`.\n\nThe starter scene only proves that the agent reaches each tool. For the agent's real job, `ancha test new \"<the test in one sentence>\" --json` drafts a test with people for the project's world (`ancha init --intent \"<company and scenario>\"` makes the world and a first test). Review its checks before you run it. To write a seed yourself, `ancha twins seed <tool> --json` prints the tool's fields, an example that validates as written, and the checks a scene can make on it. More: `ancha docs scenes`.\n\n## An app, not a command\n\nIf the AI feature lives inside an app (a web app or API server with its database, workers and scheduled jobs), don't wrap it in `agent.command`. Ancha starts the app once per trial with `agent.start`, waits for `agent.ready_url`, delivers the tools' events to `agent.url`, and a scene's `world_rules.app_calls` call the app's own routes, such as its cron jobs, at a time. Read `ancha docs apps` before writing `ancha.yaml`. The start script gives the app a clean database, cache and seed every trial: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## From a production failure\n\nA production run that went wrong becomes a test here. With a trace file (an export from the user's tracing):\n\n1. `ancha import --offline <trace file> --json` makes the test on this computer and uploads nothing. It writes `scenes/from-traces/<name>/scene.yaml` and lists the questions one trace cannot settle, each with the default the test uses.\n2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).\n3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), `ancha traces --failed --json` lists the ones where production failed a check, `ancha traces show <id> --json` previews the test, and `ancha pull <id> --json` saves it, with `--answer` for its questions. Checks you add to a pulled `scene.yaml` stay when you pull a newer version; any other edit stops the pull. A workspace that doesn't take traces says so; use the file. More: `ancha docs traces`.\n\n## The rule\n\nFix the agent, not `ancha.yaml`, the scenes or their checks. The exception is a check that is wrong for the real API, such as a method the official SDK never sends. Then don't quietly edit it: tell the user, show the evidence (the call from `ancha explain`, the vendor's documentation), and change it only with their agreement.\n\nNever give the agent under test the scenes, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach trial gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\n`ancha run` starts the agent on this computer. It has this computer's network, and an environment limited to Ancha's variables, the tools' variables and the names allowed in `agent.pass_env` in `ancha.yaml` (or `--pass-env NAME`). The agent's own model key is one of those names: `agent.pass_env: [OPENROUTER_API_KEY]` passes it from this shell, and `agent.env` sets fixed values, such as the path of a key file. Without it, an agent that calls a model stops at its first call. For a sealed run, set `agent.execution: { mode: container, image: node:24-slim }` in `ancha.yaml`; it needs Docker.\n\n## Hosted workspace\n\nIf the user has an Ancha workspace, `ancha login` asks them to approve this computer once in the browser; ask them to do it. After that, `ancha run` still runs its worlds on this computer; `ancha run --upload --json` sends the finished run to their workspace, where the console shows it (`upload.url` in the JSON). `ancha whoami --json` shows the workspace and where runs put their worlds. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login: `ancha run --local --upload --json`. `ancha secrets set NAME` copies a provider key from this shell into the workspace for agents that run there.\n\nRunning the agent itself in the cloud is a console flow at https://app.ancha.io: Bring your agent, Connect, tasks with checks, Run. Send the user there for it.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain latest --json`.\n- Exit 2: usage, config, scene or authentication error. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`. Read the `hint`.\n- Exit 3: infrastructure, or a trial the harness couldn't complete. That's not the agent's fault; run again, and `ancha doctor --json` if it repeats.\n- Exit 4, only with `--strict`: the agent called an endpoint a replica doesn't implement. `ancha explain` lists these coverage gaps even without `--strict`; check `ancha twins coverage <tool>` before changing the agent.\n\nEvery error has a stable `code` and a `hint` that names the next command. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.\n\nTell the user what you ran, the pass rate and the evidence. Never claim a fix until `ancha run --compare` exits 0.\n";
1643
1643
 
1644
1644
  // frontend/src/workspace-pages.ts
1645
1645
  var startSentence = "Test our agent with Ancha. Start with: npx -y @ancha-labs/cli init, then read https://app.ancha.io/llms.txt";