@ancha-labs/cli 0.4.0 → 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.
@@ -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";