@ancha-labs/cli 0.4.2 → 0.4.4

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.
@@ -39,7 +39,7 @@ A production run that went wrong becomes a test here. With a trace file (an expo
39
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`).
40
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.
41
41
 
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`.
42
+ If the user's workspace takes traces (their agents send them to it), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `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` writes one, 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`.
43
43
 
44
44
  ## The rule
45
45
 
@@ -6,7 +6,7 @@ A run of the agent in production becomes a test: the conversation it had, the ca
6
6
 
7
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
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.
9
+ - After `ancha login`, `ancha import <trace file>` sends the trace to the workspace, which saves the test and writes it here; a conversation that makes no test is listed with the reason, and the import goes on with the rest. When the agent sends its traces to the workspace, each becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `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` writes one.
10
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
11
 
12
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`.
@@ -21,6 +21,7 @@ The import lists the questions the trace leaves open, each with the default the
21
21
  - `tools.simulate_writes`: the writes a test simulates when the agent makes one production never made; the others fail.
22
22
  - `tools.pure`: tools that only compute from their arguments; a test runs them itself.
23
23
  - `checks.success`: what the agent should have done, when nothing in the trace says what went wrong.
24
+ - `github.members.<org>`: who was a member of the GitHub organization when the run started, as logins or `none`. The import asks when the agent removed someone's direct access to the organization's repositories; a member keeps read access to all of them.
24
25
 
25
26
  ## Run them
26
27
 
@@ -101491,13 +101491,14 @@ function removeMember(c) {
101491
101491
  });
101492
101492
  }
101493
101493
  var collaboratorRoutes = [
101494
- { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Direct collaborators, members of the owning organization and the owning user (affiliation all); other affiliations and the permission filter are gaps."), handler: (c) => {
101494
+ { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Everyone with access: direct collaborators, members of the owning organization and the owning user (affiliation all, the default); people with a direct grant (direct); people with a direct grant who are not members of the owning organization (outside)."), handler: (c) => {
101495
101495
  query(c, ["page", "per_page", "affiliation", "permission"]);
101496
- const affiliation = c.req.query("affiliation");
101497
- if (affiliation !== void 0 && affiliation !== "all") unsupported(`affiliation ${affiliation}`);
101496
+ const affiliation = c.req.query("affiliation") ?? "all";
101497
+ if (!["all", "direct", "outside"].includes(affiliation)) throw new GitHubError(422, "Validation Failed", [{ resource: "Collaborator", field: "affiliation", code: "invalid" }]);
101498
101498
  if (c.req.query("permission") !== void 0) unsupported("query parameter permission");
101499
- const ctx = c.env.ctx, repo4 = repository(c);
101500
- return paginate(c, withAccess(ctx, repo4).map((entry2) => collaboratorShape(ctx, entry2.user, entry2.permission)));
101499
+ const ctx = c.env.ctx, repo4 = repository(c), org5 = getOrganization(ctx, repo4.owner);
101500
+ const listed = withAccess(ctx, repo4).filter(({ user: user8 }) => affiliation === "all" || directPermission(ctx, repo4.id, user8.id) !== void 0 && (affiliation === "direct" || org5 === void 0 || orgMembership(ctx, org5.id, user8.id) === void 0));
101501
+ return paginate(c, listed.map((entry2) => collaboratorShape(ctx, entry2.user, entry2.permission)));
101501
101502
  } },
101502
101503
  { method: "GET", path: "/repos/:owner/:repo/collaborators/:username", coverage: partial3("204 when the user has any access, otherwise 404."), handler: (c) => {
101503
101504
  query(c, []);
@@ -729,6 +729,9 @@ function toolView(observation2, tool, options = {}) {
729
729
  if (!observation2.state?.[tool]) return empty2(`${toolName(tool)} data is unavailable for this trial.`);
730
730
  return renderers[tool](observation2, options);
731
731
  }
732
+ function recordsView(observation2, tool, options = {}) {
733
+ return projectedTool(observation2, tool, options);
734
+ }
732
735
  function projectedTool(o, tool, options) {
733
736
  const view = o.toolViews?.[tool], tables = list2(view?.tables), conversations = list2(view?.conversations), active = tables.find((t) => t.title === options.resource) ?? tables[0];
734
737
  if (!view) return empty2(`${toolName(tool)} records are not available in this capture.`);
@@ -1378,7 +1381,7 @@ function mountWorldWorkspace(node, options) {
1378
1381
  function render() {
1379
1382
  if (disposed) return;
1380
1383
  const currentRuns = selected ? setupRuns(runs, selected) : [], run = currentRuns[0], attempts = run?.attempts ?? [], tasks = selected?.tasks ?? [], choices = worldSetups(tests, world.id, agentId);
1381
- node.innerHTML = `<div class="ww-workspace"><header class="ww-header"><h1>${h(world.name)}</h1><div class="ww-world-actions"><label class="ww-agent-select">Agent<select data-ww-select="agent"><option value="" disabled>Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${a.id === agentId ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><button type="button" data-ww="configure">Configure</button>${selected ? options.runActions?.(selected.id) ?? button("Run tasks", "run-saved-test", selected.id, "primary") : ""}</div></header>${peopleSection(world)}<p class="ww-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</p>${errors.map((e) => `<p class="ww-error" role="alert">${h(e.message)}</p>`).join("")}${!loaded ? '<p role="status">Loading tasks\u2026</p>' : ""}${choices.length > 1 ? `<label class="ww-setup-select">Configuration<select data-ww-select="test">${!selected ? '<option value="" selected disabled>New configuration</option>' : ""}${choices.map((t) => `<option value="${h(t.id)}" ${t.id === selected?.id ? "selected" : ""}>${h(t.name)}</option>`).join("")}</select></label>` : ""}${loaded && configure ? configuration2() : loaded ? `${summaryWidgets(attempts, hasChecks(run?.tasks ?? tasks), run?.summary?.counts?.requested ?? attempts.length)}<div class="ww-section-heading"><h2>Tasks${tasks.length ? ` <span class="ww-task-count">${tasks.length}</span>` : ""}</h2><div class="actions">${worldHistory(runs, world.id, agentId || void 0).length || selected ? `<button type="button" data-ww="history" aria-expanded="${showHistory}">History</button>` : ""}<button type="button" data-ww="configure">${tasks.length ? "Edit tasks" : "Add tasks"}</button></div></div>${tasks.length ? `<section class="ww-task-table"><div class="ww-table-head"><span>Task</span><span>Result</span><span>Attempts</span><span>Median</span><span></span></div>${tasks.map((task, index) => {
1384
+ node.innerHTML = `<div class="ww-workspace"><header class="ww-header"><h1>${h(world.name)}</h1><div class="ww-world-actions"><label class="ww-agent-select">Agent<select data-ww-select="agent"><option value="" disabled>Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${a.id === agentId ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><a data-nav class="button-link" href="${base}?data=1">View data</a><button type="button" data-ww="configure">Configure</button>${selected ? options.runActions?.(selected.id) ?? button("Run tasks", "run-saved-test", selected.id, "primary") : ""}</div></header>${peopleSection(world)}<p class="ww-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</p>${errors.map((e) => `<p class="ww-error" role="alert">${h(e.message)}</p>`).join("")}${!loaded ? '<p role="status">Loading tasks\u2026</p>' : ""}${choices.length > 1 ? `<label class="ww-setup-select">Configuration<select data-ww-select="test">${!selected ? '<option value="" selected disabled>New configuration</option>' : ""}${choices.map((t) => `<option value="${h(t.id)}" ${t.id === selected?.id ? "selected" : ""}>${h(t.name)}</option>`).join("")}</select></label>` : ""}${loaded && configure ? configuration2() : loaded ? `${summaryWidgets(attempts, hasChecks(run?.tasks ?? tasks), run?.summary?.counts?.requested ?? attempts.length)}<div class="ww-section-heading"><h2>Tasks${tasks.length ? ` <span class="ww-task-count">${tasks.length}</span>` : ""}</h2><div class="actions">${worldHistory(runs, world.id, agentId || void 0).length || selected ? `<button type="button" data-ww="history" aria-expanded="${showHistory}">History</button>` : ""}<button type="button" data-ww="configure">${tasks.length ? "Edit tasks" : "Add tasks"}</button></div></div>${tasks.length ? `<section class="ww-task-table"><div class="ww-table-head"><span>Task</span><span>Result</span><span>Attempts</span><span>Median</span><span></span></div>${tasks.map((task, index) => {
1382
1385
  const list4 = attempts.filter((a) => a.taskId === task.id), taskURL = run ? `/playgrounds/${enc(run.id)}?task=${enc(task.id)}${list4[0] ? "&attempt=" + enc(list4[0].id) : ""}` : "";
1383
1386
  return `<article class="ww-task-row"><div class="ww-task-identity">${taskURL ? `<a data-nav class="ww-task-name" href="${taskURL}"><span class="ww-ordinal">${index + 1}</span><strong>${h(label(task, index))}</strong></a>` : `<strong class="ww-task-name"><span class="ww-ordinal">${index + 1}</span>${h(label(task, index))}</strong>`}<p class="ww-task-prompt" title="${h(task.prompt)}">${h(task.prompt)}</p></div>${(() => {
1384
1387
  const o = taskOutcome(list4, hasChecks([task]), Number(task.attempts) || list4.length);
@@ -1536,6 +1539,19 @@ function worldHasActiveRuns(runs, worldId) {
1536
1539
  return runs.some((run) => !terminal(run.status) && (run.entries?.length ? run.entries.some((entry) => entry.world?.id === worldId) : run.world?.id === worldId));
1537
1540
  }
1538
1541
 
1542
+ // frontend/src/world-data.ts
1543
+ function worldDataPage(title2, context, back, data, base, query) {
1544
+ const tools = Array.isArray(data.tools) ? data.tools : [], tool = tools.includes(query.get("tool") ?? "") ? query.get("tool") : tools[0];
1545
+ const link = (name) => {
1546
+ const next = new URLSearchParams(base.split("?")[1]);
1547
+ next.set("tool", name);
1548
+ return `${base.split("?")[0]}?${next}`;
1549
+ };
1550
+ const tabs = tools.map((name) => `<a data-nav class="${name === tool ? "active" : ""}" href="${h(link(name))}" ${name === tool ? 'aria-current="page"' : ""}><span class="world-data-logo" aria-hidden="true">${toolLogo(name)}</span>${h(toolName(name))}</a>`).join("");
1551
+ const options = Object.fromEntries([...query].filter(([key]) => key === "resource" || key === "conversation"));
1552
+ return `<a data-nav class="back" href="${h(back.href)}">\u2190 ${h(back.label)}</a><header class="page-head"><div><h1>${h(title2)}</h1><p class="page-meta">${h(context)}</p></div></header><p class="world-data-note">Starting data, before any run. Read-only.</p>` + (tools.length ? `<nav class="tabs world-data-tabs" aria-label="Tools">${tabs}</nav>${recordsView(data, tool, { ...options, embedded: true, baseHref: link(tool) })}` : '<div class="quiet-empty">This world has no tools.</div>');
1553
+ }
1554
+
1539
1555
  // frontend/src/workspace-view.ts
1540
1556
  var VIEW_SECTIONS = /* @__PURE__ */ new Set(["worlds", "agents", "playgrounds", "settings", "help", "tools"]);
1541
1557
  var viewMode = (boot2) => boot2.mode === "view";
@@ -1639,7 +1655,7 @@ function starterCount(tool, key, state) {
1639
1655
  }
1640
1656
 
1641
1657
  // 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/` (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";
1658
+ 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), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `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` writes one, 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
1659
 
1644
1660
  // frontend/src/workspace-pages.ts
1645
1661
  var startSentence = "Test our agent with Ancha. Start with: npx -y @ancha-labs/cli init, then read https://app.ancha.io/llms.txt";
@@ -2398,6 +2414,7 @@ var viewMode2 = () => viewMode(boot);
2398
2414
  var viewBanner2 = () => viewBanner(boot);
2399
2415
  var worldsAnswer = {};
2400
2416
  var agentsAnswer = {};
2417
+ var worldData;
2401
2418
  var startTimer;
2402
2419
  function adoptBoot(next) {
2403
2420
  const was = viewMode2();
@@ -2491,6 +2508,10 @@ function shell(section, content) {
2491
2508
  const nav2 = (items) => items.map(([id, name]) => `<a href="/${id}" data-nav class="nav-item ${section === id ? "active" : ""}" ${section === id ? 'aria-current="page"' : ""}>${name}</a>`).join("");
2492
2509
  root.innerHTML = `<aside class="sidebar"><a href="/worlds" class="brand" data-nav>ancha</a><nav class="app-nav" aria-label="Main navigation">${nav2([["worlds", "Worlds"], ["agents", "Agents"], ["playgrounds", "Runs"], ["tools", "Tools"]])}</nav><div class="workspace"><span id="connection" class="connection warn" role="status"${failedProbes < 2 ? " hidden" : ""}>${failedProbes < 2 ? "" : "Can\u2019t reach the server. Retrying\u2026"}</span><a href="/help" data-nav>Help</a><a href="/settings" data-nav>Settings</a></div></aside><main id="main" tabindex="-1">${viewMode2() && viewServes(section, path()[1]) ? viewBanner2() : ""}${content}</main>`;
2493
2510
  }
2511
+ function folderScenes(scenes) {
2512
+ if (!scenes.length) return "";
2513
+ return `<section class="folder-scenes" aria-labelledby="folder-scenes-title"><div class="section-title"><div><h2 id="folder-scenes-title">Scenes in this folder</h2><p class="muted">Open one to see its starting data before any run.</p></div></div><div class="world-catalog">${scenes.map((scene) => `<a class="world-catalog-item" href="/worlds?scene=${enc2(String(scene.key))}" data-nav><h2>${h(String(scene.title || scene.id))}</h2><div class="world-tool-icons" role="group" aria-label="Tools: ${h((scene.tools ?? []).map(toolName).join(", "))}">${(scene.tools ?? []).map((tool) => `<span title="${h(toolName(tool))}" role="img" aria-label="${h(toolName(tool))}">${toolLogo(tool)}</span>`).join("")}</div><p>${h(String(scene.path))}</p></a>`).join("")}</div></section>`;
2514
+ }
2494
2515
  function worldToolIcons(world) {
2495
2516
  const tools = [...new Set((world.configuration?.preset?.datasets ?? []).map((dataset) => dataset.tool))];
2496
2517
  return `<div class="world-tool-icons" role="group" aria-label="Tools: ${h(tools.map(toolName).join(", "))}">${tools.map((tool) => `<span title="${h(toolName(tool))}" role="img" aria-label="${h(toolName(tool))}">${toolLogo(tool)}</span>`).join("")}</div>`;
@@ -2560,7 +2581,18 @@ async function load() {
2560
2581
  } else if (section === "help" || section === "settings") {
2561
2582
  shell(section, head(section === "help" ? "Help" : "Settings") + (section === "help" ? helpPage() : boot.hosted ? `<section class="settings-page"><h2>Hosted workspace</h2><dl class="hosted-urls">${boot.hosted.tier ? `<dt>This workspace</dt><dd>${ownRunsOff() ? 'Free \xB7 <a href="/account#hosted">Request hosted runs</a>' : 'Hosted runs \xB7 <a href="/account#hosted">Machine time</a>'}</dd>` : ""}${boot.hosted.console ? `<dt>Console</dt><dd><a href="${h(boot.hosted.console)}">${h(boot.hosted.console)}</a></dd><dt>World server</dt><dd><code>${h(boot.hosted.worldServer)}</code></dd>` : ""}</dl><p class="muted">For CI, set <code>ANCHA_SERVER_URL</code> to the world server and <code>ANCHA_API_KEY</code> to a key from <a href="/account">Account settings</a>. On your computer, <code>ancha login</code> sets both.</p></section>` : `<section class="settings-page"><h2>Local workspace</h2><p class="workspace-path">${h(boot.workspace)}</p><p class="muted">Agents, worlds, tests and results are saved here.</p></section>`));
2562
2583
  } else if (section === "worlds") {
2563
- const [result2, registry, definitions] = await Promise.all([api("/worlds"), api("/agents"), api("/playground-tests")]);
2584
+ const q = new URLSearchParams(location.search), sceneKey = p[1] ? null : q.get("scene"), revision = q.get("revision");
2585
+ if (!viewMode2() && (sceneKey !== null || !!p[1] && p[1] !== "new" && q.has("data"))) {
2586
+ const source = sceneKey !== null ? `/scenarios/data?key=${enc2(sceneKey)}` : `/worlds/${enc2(p[1])}/data${revision ? `?revision=${enc2(revision)}` : ""}`;
2587
+ const data = worldData?.source === source && Date.now() - worldData.at < 6e4 ? worldData.data : await api(source);
2588
+ if (thisGeneration !== generation) return;
2589
+ if (worldData?.source !== source) worldData = { source, at: Date.now(), data };
2590
+ current = {};
2591
+ if (sceneKey !== null) shell("worlds", worldDataPage(String(data.scene?.title || data.scene?.path || "Scene"), String(data.scene?.path ?? ""), { href: "/worlds", label: "Worlds" }, data, `/worlds?scene=${enc2(sceneKey)}`, q));
2592
+ else shell("worlds", worldDataPage(String(data.world?.name ?? "World"), `Revision ${data.world?.revision}`, { href: `/worlds/${enc2(p[1])}`, label: String(data.world?.name ?? "World") }, data, `/worlds/${enc2(p[1])}?data=1${revision ? `&revision=${enc2(revision)}` : ""}`, q));
2593
+ return;
2594
+ }
2595
+ const [result2, registry, definitions, folder] = await Promise.all([api("/worlds"), api("/agents"), api("/playground-tests"), !p[1] && !viewMode2() ? api("/scenarios/folder").catch(() => ({ scenes: [] })) : Promise.resolve({ scenes: [] })]);
2564
2596
  if (thisGeneration !== generation) return;
2565
2597
  worldsAnswer = result2;
2566
2598
  worlds = result2.worlds ?? [];
@@ -2590,7 +2622,7 @@ async function load() {
2590
2622
  const ownAgents = agentCatalog.filter((a) => !/(^|\/)sample-agent\/?$/.test(String(a.cwd ?? "")));
2591
2623
  const sampleRun = !p[1] && !ownAgents.length ? ((await api("/playgrounds")).runs ?? []).slice().sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))[0] : void 0;
2592
2624
  if (thisGeneration !== generation) return;
2593
- if (!p[1]) document.querySelector("#worlds-page").innerHTML = (ownAgents.length ? "" : startCard(sampleRun?.id)) + (worlds.length ? `<div class="world-catalog">${worlds.map((world) => `<a class="world-catalog-item" href="/worlds/${enc2(world.id)}" data-nav><h2>${h(world.name)}</h2>${worldToolIcons(world)}<p>${worldTaskCounts.get(world.id) ?? 0} ${worldTaskCounts.get(world.id) === 1 ? "task" : "tasks"}</p></a>`).join("")}</div>` : `<section class="empty"><h2>No worlds yet</h2><a href="/worlds/new" data-nav class="button-link primary">Create world</a></section>`);
2625
+ if (!p[1]) document.querySelector("#worlds-page").innerHTML = (ownAgents.length ? "" : startCard(sampleRun?.id)) + (worlds.length ? `<div class="world-catalog">${worlds.map((world) => `<a class="world-catalog-item" href="/worlds/${enc2(world.id)}" data-nav><h2>${h(world.name)}</h2>${worldToolIcons(world)}<p>${worldTaskCounts.get(world.id) ?? 0} ${worldTaskCounts.get(world.id) === 1 ? "task" : "tasks"}</p></a>`).join("")}</div>` : `<section class="empty"><h2>No worlds yet</h2><a href="/worlds/new" data-nav class="button-link primary">Create world</a></section>`) + folderScenes(folder.scenes ?? []);
2594
2626
  else mountWorlds(document.querySelector("#worlds-page"), worlds, toolCatalog, p[1], api, go);
2595
2627
  }
2596
2628
  } else if (section === "tools") {
@@ -2882,7 +2914,7 @@ function renderTools(selected) {
2882
2914
  if (!tool) {
2883
2915
  const ordered2 = [...toolCatalog].sort((a, b) => (toolOrder.indexOf(a.name) + 99) % 99 - (toolOrder.indexOf(b.name) + 99) % 99);
2884
2916
  const cliNote = boot.hosted ? '<p class="tools-cli-note">These replicas come with this workspace. To use all of them from your computer, update your CLI: <code>npm install -g @ancha-labs/cli@latest</code></p>' : "";
2885
- shell("tools", head("Tools", "", "Replicas of the APIs agents call. Every attempt gets its own copy, seeded with the data shown on each tool.") + cliNote + `<div class="tools-grid">${ordered2.map((t) => {
2917
+ shell("tools", head("Tools", '<a class="button-link" href="mailto:patrick@ancha.io?subject=Tool%20request">Request a tool</a>', "Replicas of the APIs agents call. Every attempt gets its own copy, seeded with the data shown on each tool.") + cliNote + `<div class="tools-grid">${ordered2.map((t) => {
2886
2918
  const d2 = t.descriptor ?? {}, endpoints2 = (t.coverage ?? []).length, version = String(d2.version ?? "");
2887
2919
  const api2 = version && !/[A-Za-z]{3,}/.test(version.replace(/subset/g, "")) ? `API ${version}` : version;
2888
2920
  return `<a class="tool-card" data-nav href="/tools/${enc2(t.name)}"><div class="tool-card-head">${toolLogo(t.name)}<div><strong>${h(toolName(t.name))}</strong><span>${h(toolCategory[t.name] ?? "Tool")}</span></div></div><p>${h(d2.description ?? toolDescription(t.name))}</p><div class="tool-card-foot"><span>${h(api2)}</span><span>${endpoints2} endpoint${endpoints2 === 1 ? "" : "s"}</span></div></a>`;
@@ -513,3 +513,5 @@ body.navigating main{opacity:.55;transition:opacity .15s .25s;cursor:progress}
513
513
  /* The console as a view of the workspace (hosting spec §3.4) */
514
514
  .view-banner{display:flex;align-items:center;gap:16px;margin:0 0 24px;padding:16px 18px;border:1px solid var(--line);border-radius:10px;background:var(--raised,#fafaf8)}.view-banner>div{flex:1;min-width:0}.view-banner strong{display:block;font-weight:600}.view-banner p{margin:4px 0 0;color:var(--muted);font-size:13px}.view-banner button{flex:none}.view-note{color:var(--muted);font-size:13px}
515
515
  @media (max-width:560px){.view-banner{flex-direction:column;align-items:flex-start}}
516
+ /* A world's starting data before any run (SPEC-027) */
517
+ .world-data-note{margin:-12px 0 20px;color:var(--muted);font-size:13px}.world-data-tabs{display:flex;flex-wrap:wrap;gap:4px 22px}.world-data-tabs a{gap:8px;align-items:center}.world-data-logo{display:inline-flex;width:16px;height:16px}.world-data-logo svg,.world-data-logo img{width:16px;height:16px}.folder-scenes{margin-top:36px}.folder-scenes .world-catalog-item p{overflow-wrap:anywhere;font-size:12px}.ww-world-actions .button-link{color:var(--ink)}
package/lib/worker.mjs CHANGED
@@ -121227,13 +121227,14 @@ function removeMember(c) {
121227
121227
  });
121228
121228
  }
121229
121229
  var collaboratorRoutes = [
121230
- { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Direct collaborators, members of the owning organization and the owning user (affiliation all); other affiliations and the permission filter are gaps."), handler: (c) => {
121230
+ { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Everyone with access: direct collaborators, members of the owning organization and the owning user (affiliation all, the default); people with a direct grant (direct); people with a direct grant who are not members of the owning organization (outside)."), handler: (c) => {
121231
121231
  query2(c, ["page", "per_page", "affiliation", "permission"]);
121232
- const affiliation = c.req.query("affiliation");
121233
- if (affiliation !== void 0 && affiliation !== "all") unsupported(`affiliation ${affiliation}`);
121232
+ const affiliation = c.req.query("affiliation") ?? "all";
121233
+ if (!["all", "direct", "outside"].includes(affiliation)) throw new GitHubError(422, "Validation Failed", [{ resource: "Collaborator", field: "affiliation", code: "invalid" }]);
121234
121234
  if (c.req.query("permission") !== void 0) unsupported("query parameter permission");
121235
- const ctx = c.env.ctx, repo4 = repository(c);
121236
- return paginate(c, withAccess(ctx, repo4).map((entry3) => collaboratorShape(ctx, entry3.user, entry3.permission)));
121235
+ const ctx = c.env.ctx, repo4 = repository(c), org5 = getOrganization(ctx, repo4.owner);
121236
+ const listed = withAccess(ctx, repo4).filter(({ user: user8 }) => affiliation === "all" || directPermission(ctx, repo4.id, user8.id) !== void 0 && (affiliation === "direct" || org5 === void 0 || orgMembership(ctx, org5.id, user8.id) === void 0));
121237
+ return paginate(c, listed.map((entry3) => collaboratorShape(ctx, entry3.user, entry3.permission)));
121237
121238
  } },
121238
121239
  { method: "GET", path: "/repos/:owner/:repo/collaborators/:username", coverage: partial3("204 when the user has any access, otherwise 404."), handler: (c) => {
121239
121240
  query2(c, []);
@@ -184931,6 +184932,7 @@ function trialDuration(ms) {
184931
184932
  }
184932
184933
  var plural4 = (n, one7, many = `${one7}s`) => `${n} ${n === 1 ? one7 : many}`;
184933
184934
  function progressLine(e, scenes) {
184935
+ if (e.event === "trace_skipped" && typeof e.trace === "string" && typeof e.reason === "string") return `skipped trace ${e.trace.slice(0, 8)}: ${e.reason}`;
184934
184936
  if (e.event === "run_started" && typeof e.runId === "string" && Array.isArray(e.scenes) && typeof e.trials === "number" && typeof e.parallel === "number") {
184935
184937
  if (typeof e.replayOf === "string") return `${e.runId}: replay of ${e.replayOf}`;
184936
184938
  const what = e.scenes.length === 1 ? `${plural4(e.trials, "trial")} of ${String(e.scenes[0])}` : `${plural4(e.trials, "trial")} each of ${e.scenes.length} scenes`;
@@ -117875,13 +117875,14 @@ function removeMember(c) {
117875
117875
  });
117876
117876
  }
117877
117877
  var collaboratorRoutes = [
117878
- { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Direct collaborators, members of the owning organization and the owning user (affiliation all); other affiliations and the permission filter are gaps."), handler: (c) => {
117878
+ { method: "GET", path: "/repos/:owner/:repo/collaborators", coverage: partial3("Everyone with access: direct collaborators, members of the owning organization and the owning user (affiliation all, the default); people with a direct grant (direct); people with a direct grant who are not members of the owning organization (outside)."), handler: (c) => {
117879
117879
  query2(c, ["page", "per_page", "affiliation", "permission"]);
117880
- const affiliation = c.req.query("affiliation");
117881
- if (affiliation !== void 0 && affiliation !== "all") unsupported(`affiliation ${affiliation}`);
117880
+ const affiliation = c.req.query("affiliation") ?? "all";
117881
+ if (!["all", "direct", "outside"].includes(affiliation)) throw new GitHubError(422, "Validation Failed", [{ resource: "Collaborator", field: "affiliation", code: "invalid" }]);
117882
117882
  if (c.req.query("permission") !== void 0) unsupported("query parameter permission");
117883
- const ctx = c.env.ctx, repo4 = repository(c);
117884
- return paginate(c, withAccess(ctx, repo4).map((entry2) => collaboratorShape(ctx, entry2.user, entry2.permission)));
117883
+ const ctx = c.env.ctx, repo4 = repository(c), org5 = getOrganization(ctx, repo4.owner);
117884
+ const listed = withAccess(ctx, repo4).filter(({ user: user8 }) => affiliation === "all" || directPermission(ctx, repo4.id, user8.id) !== void 0 && (affiliation === "direct" || org5 === void 0 || orgMembership(ctx, org5.id, user8.id) === void 0));
117885
+ return paginate(c, listed.map((entry2) => collaboratorShape(ctx, entry2.user, entry2.permission)));
117885
117886
  } },
117886
117887
  { method: "GET", path: "/repos/:owner/:repo/collaborators/:username", coverage: partial3("204 when the user has any access, otherwise 404."), handler: (c) => {
117887
117888
  query2(c, []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ancha-labs/cli",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, locally or hosted at app.ancha.io.",
6
6
  "bugs": {