@ancha-labs/cli 0.4.10 → 0.4.12
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 +10 -10
- package/lib/ancha.mjs +8991 -5469
- package/lib/assets/SKILL.md +30 -27
- package/lib/assets/agents-section.md +21 -19
- package/lib/assets/docs/apps.md +8 -8
- package/lib/assets/docs/cloud.md +35 -32
- package/lib/assets/docs/compare.md +3 -3
- package/lib/assets/docs/explain.md +8 -6
- package/lib/assets/docs/run.md +13 -13
- package/lib/assets/docs/scenes.md +4 -4
- package/lib/assets/docs/setup.md +26 -24
- package/lib/assets/docs/traces.md +8 -7
- package/lib/assets/harbor/companion.mjs +19 -19
- package/lib/assets/llms.txt +6 -6
- package/lib/assets/ui/app.js +110 -35
- package/lib/assets/ui/style.css +5 -2
- package/lib/mcp-entry.mjs +15 -15
- package/lib/worker.mjs +704 -331
- package/lib/world-server.mjs +19 -19
- package/package.json +1 -1
package/lib/assets/docs/run.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Run the agent
|
|
2
2
|
|
|
3
|
-
`ancha run
|
|
3
|
+
`ancha run` loads `ancha.yaml` and runs the configured agent against every test its `scenes:` globs match (`scenes/**/scene.yaml` by default), `trials` times each, in fresh worlds. Pass test files (`scene.yaml`) to run only those; `--json` prints the run as NDJSON events. `--agent "<command>"` overrides `agent.command`; `-n 1 --parallel 1` runs one diagnostic trial; `--out <dir>` chooses where results go (use the same `--out` for `explain`, `report` and `compare`). Paths are relative to the directory you run `ancha` from.
|
|
4
4
|
|
|
5
|
-
`ancha run --dry-run` checks `ancha.yaml` and every
|
|
5
|
+
`ancha run --dry-run` checks `ancha.yaml` and every test, prints the tests, trials and parallelism, and starts nothing: no server, no agent, no trial.
|
|
6
6
|
|
|
7
|
-
The run says where it runs. A cloud run announces acceptance with `run_submitted` (`run_detached` with `--detach`); both carry `target: "cloud"` and add `defaulted: true` when the saved login chose cloud. A run on this computer starts its NDJSON with `run_started`, which carries `workspace` and `target`. A completed run ends with `run_finished`. Without `--json`, each finished trial prints one line, such as `trial 2 ✗ 3m02s · 3 checks failed`, before the summary. The agent's exit code and the checks are independent: a clean exit with failed checks is a failure. Exits: 0 success; 1 failed checks, threshold or regression; 2 usage, config,
|
|
7
|
+
The run says where it runs. A cloud run announces acceptance with `run_submitted` (`run_detached` with `--detach`); both carry `target: "cloud"` and add `defaulted: true` when the saved login chose cloud. A run on this computer starts its NDJSON with `run_started`, which carries `workspace` and `target`. A completed run ends with `run_finished`. Without `--json`, each finished trial prints one line, such as `trial 2 ✗ 3m02s · 3 checks failed`, before the summary. The agent's exit code and the checks are independent: a clean exit with failed checks is a failure. Exits: 0 success; 1 failed checks, threshold or regression; 2 usage, config, test file or authentication error; 3 infrastructure or a trial the harness couldn't complete; 4 an endpoint coverage error or a verdict using simulated tool answers under `--strict`. The summary names the tests, trials and evaluated checks using those answers. Exit-code precedence is 3, 2, 4, then 1.
|
|
8
8
|
|
|
9
9
|
## What the agent gets
|
|
10
10
|
|
|
11
|
-
New run summaries use `verdictVersion: 2`. Each
|
|
11
|
+
New run summaries use `verdictVersion: 2`. Each test (an entry of `scenes`) has `counts.requested`, `completed`, `valid`, `passed`, `invalid` and `skipped`. The pass-rate denominator is the requested count, including invalid, skipped and unfinished trials. “Pass all k” requires all k requested trials to complete validly and pass. HTML and the console show invalid attempts separately. Older reports stay readable; comparison with an old baseline lacking these counts exits 2 and asks you to rerun the reference and save a fresh baseline.
|
|
12
12
|
|
|
13
|
-
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK
|
|
13
|
+
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK` and `ANCHA_TASK_FILE` (a file holding the task), `ANCHA_ATTEMPT_ID`, `ANCHA_STATE_DIR` (keep memory there, so trials stay independent), `ANCHA_EVENTS_URL`, `ANCHA_EVENTS_TOKEN` and `ANCHA_DONE_URL` for agents that receive events or finish explicitly, and `ANCHA_AGENT_PORT` for HTTP agents. No SDK is installed and no paid AI call is made for you. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: "{{task}}" }` (`{{task_file}}` for the file's path); `ancha init` writes that line when it finds the name in the agent's code or usage text.
|
|
14
14
|
|
|
15
15
|
With `--on local`, the agent runs as a process on this computer. It is not sealed: it can reach this computer's network. Its environment is limited to a base set from this shell (`PATH`, `HOME`, `USER`, `LOGNAME`, `SHELL`, `LANG`, `LC_*`, `TERM`, `TMPDIR`, `TZ`, `NODE_EXTRA_CA_CERTS`, `SSL_CERT_FILE`, `VIRTUAL_ENV`, `CONDA_PREFIX`, `PYTHONPATH`) plus Ancha's and the tools' variables. Real credentials in your shell, such as `GITHUB_TOKEN` or `DD_API_KEY`, never reach it unless you name them:
|
|
16
16
|
|
|
@@ -20,13 +20,13 @@ agent:
|
|
|
20
20
|
pass_env: [OPENAI_API_KEY] # names only; values come from this shell at run time
|
|
21
21
|
```
|
|
22
22
|
|
|
23
|
-
`--pass-env NAME` (repeatable) adds names for one run. `--inherit-env` passes the whole shell environment, as before 0.1.2, and prints a warning. The run's first line says what the agent got: `running locally; agent not sealed (network open, <n> variables from this shell)`. When an agent crashes (it exits non-zero on its own), its trial fails whatever its checks say, and the summary quotes the end of its log, and if the log names a variable this shell has but the agent didn't get, it says so: `OPENROUTER_API_KEY is set in this shell but was withheld from the agent: pass it with --pass-env OPENROUTER_API_KEY or list it under agent.pass_env in ancha.yaml`.
|
|
23
|
+
`--pass-env NAME` (repeatable) adds names for one run. `--inherit-env` passes the whole shell environment, as before 0.1.2, and prints a warning. The run's first line says what the agent got: `running locally; agent not sealed (network open, <n> variables from this shell)`. When an agent crashes (it exits non-zero on its own), its trial fails whatever its checks say, and the summary quotes the end of its log, and if the log names a variable this shell has but the agent didn't get, it says so: `OPENROUTER_API_KEY is set in this shell but was withheld from the agent: pass it with --pass-env OPENROUTER_API_KEY or list it under agent.pass_env in ancha.yaml`. When every attempt ended before the agent did anything (an error exit within 5 seconds without a call, or a command that could not start), the summary says that first, "Your agent didn't run: it exited with code 1 within 96 ms in all 3 attempts", with the end of its log once, the likely fix read from the log and the command to run again; the checks that failed because of it are one line, and `ancha explain <run id> --all` lists them.
|
|
24
24
|
|
|
25
25
|
## Agents that wait for people
|
|
26
26
|
|
|
27
|
-
By default the agent runs once per attempt with the task in `ANCHA_TASK`. Imported customer conversations set `agent_input: per_event` in the test, which takes precedence over `agent.input` in `ancha.yaml`. Bind your existing reply function with `chat(reply)` from `@ancha-labs/tools` or `ancha.chat(reply)` in Python (`ancha docs traces` has the snippets). For other
|
|
27
|
+
By default the agent runs once per attempt with the task in `ANCHA_TASK`. Imported customer conversations set `agent_input: per_event` in the test, which takes precedence over `agent.input` in `ancha.yaml`. Bind your existing reply function with `chat(reply)` from `@ancha-labs/tools` or `ancha.chat(reply)` in Python (`ancha docs traces` has the snippets). For other tests with people who reply later, set `agent.input: per_event`: Ancha runs the command once per event addressed to the agent (a DM, a mention, a thread it is in), with the event in `ANCHA_EVENT_JSON` and a one-line summary in `ANCHA_TASK`, one conversation at a time. Simulated time skips ahead while nobody is working, and the attempt ends when the world is quiet with nothing scheduled before the deadline.
|
|
28
28
|
|
|
29
|
-
`per_event`
|
|
29
|
+
`per_event` runs in the local runner, including local container execution. Managed/Harbor execution rejects `per_event` and `events` with `CONFIG_INVALID` (exit 2). It never substitutes a one-shot command.
|
|
30
30
|
|
|
31
31
|
## Where the agent runs
|
|
32
32
|
|
|
@@ -50,7 +50,7 @@ agent:
|
|
|
50
50
|
modelHosts: [api.openai.com] # the only model hosts it may reach, over HTTPS
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
Each trial then runs in a fresh container: no host environment except the `env` names, no network except the tools and the `modelHosts`, a read-only copy of the project (without `node_modules`, `venv`, dotfiles, credential files and Ancha's own files: `ancha.yaml`, `ancha/`,
|
|
53
|
+
Each trial then runs in a fresh container: no host environment except the `env` names, no network except the tools and the `modelHosts`, a read-only copy of the project (without `node_modules`, `venv`, dotfiles, credential files and Ancha's own files: `ancha.yaml`, `ancha/`, test folders and the run's test files) at `/workspace`, and a 512 MB, 1-CPU, 128-process limit (`memoryMb`, `cpus`, `pids`; `files` picks which project paths to copy). The image must contain the agent's runtime and dependencies; for Node, install them at `/opt/ancha/node_modules`, which each trial links into `/workspace`, for example:
|
|
54
54
|
|
|
55
55
|
```dockerfile
|
|
56
56
|
FROM node:24-slim
|
|
@@ -64,11 +64,11 @@ Container mode needs Docker (`ancha execution doctor`). It never falls back to r
|
|
|
64
64
|
|
|
65
65
|
## Retrying a run
|
|
66
66
|
|
|
67
|
-
A caller whose command can time out passes `--idempotency-key <key>` (1 to 200 visible ASCII characters). Running again with the same key and the same
|
|
67
|
+
A caller whose command can time out passes `--idempotency-key <key>` (1 to 200 visible ASCII characters). Running again with the same key and the same tests, agent and options returns the original run instead of starting another: its finished summary and exit code, or, while it is still going, an error whose hint is `ancha wait <id>` (with `--detach`, its `run_detached` event again). Reusing a key for a different run is a usage error.
|
|
68
68
|
|
|
69
69
|
## Timeouts and stopping
|
|
70
70
|
|
|
71
|
-
A trial ends when the agent exits, finishes explicitly, goes idle (event and HTTP agents), or reaches the
|
|
71
|
+
A trial ends when the agent exits, finishes explicitly, goes idle (event and HTTP agents), or reaches the test's `timeout`. At the timeout the agent's whole process group gets SIGTERM, then SIGKILL 2 seconds later, and the trial is recorded as a timeout with the end of `agent.log`. Ctrl-C stops the run the same way and keeps the evidence collected so far.
|
|
72
72
|
|
|
73
73
|
## Background runs
|
|
74
74
|
|
|
@@ -81,7 +81,7 @@ A trial ends when the agent exits, finishes explicitly, goes idle (event and HTT
|
|
|
81
81
|
```bash
|
|
82
82
|
ancha world up --scene scenes/support-reply/scene.yaml --json # envId, and env: the tools' URLs and fake credentials
|
|
83
83
|
# run your agent with exactly the variables in env; they never include the world's control URL
|
|
84
|
-
ancha check --env <envId> --json # the
|
|
84
|
+
ancha check --env <envId> --json # the test's checks, as ancha run grades them; exit 1 when a required one fails
|
|
85
85
|
ancha world down --env <envId>
|
|
86
86
|
```
|
|
87
87
|
|
|
@@ -93,6 +93,6 @@ ancha world down --env <envId>
|
|
|
93
93
|
|
|
94
94
|
`ancha agent add` saves a reusable agent profile that the local console (`ancha ui`) and the CLI share, for scenarios and playgrounds: `ancha agent verify ID --scene KEY`, `ancha agent run ID --scene KEY -n 1`, `ancha explain RUN_ID`, `ancha agent rerun RUN_ID`, and `ancha test save RUN_ID --name NAME` for a reusable test. See `ancha docs playgrounds` for running saved agents in containers with plain-language tasks.
|
|
95
95
|
|
|
96
|
-
Check `ancha twins coverage <tool>` and `ancha connect <tool>`. Keep provider keys out of
|
|
96
|
+
Check `ancha twins coverage <tool>` and `ancha connect <tool>`. Keep provider keys out of tests and saved configuration.
|
|
97
97
|
|
|
98
98
|
For managed `runs start`, invalid harness captures exit 3, failed/skipped/incomplete grading exits 1, and a stopped run exits 2. The grade line uses requested attempts and names invalid/skipped counts.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Create and validate
|
|
1
|
+
# Create and validate tests
|
|
2
2
|
|
|
3
3
|
## Tests with people (version 2)
|
|
4
4
|
|
|
@@ -6,15 +6,15 @@ A version 2 test names a world (`ancha/worlds/<id>.yaml`: the company, its peopl
|
|
|
6
6
|
|
|
7
7
|
- `ancha world gen "<company and scenario>" --json` writes a world. `ancha init --intent "<…>"` does that while setting up the project, and drafts a first test for it.
|
|
8
8
|
- `ancha test new "<the test in one sentence>" --json` drafts a test for the project's world (`--world <id>` when there are several) into `ancha/tests/<id>.yaml`, with a `.gen.json` record of the prompt. The draft is validated against the world (every ref exists, every check can be evaluated) before it is written. Read its checks before you run it: each should pass for an agent that does the job and fail for one that doesn't.
|
|
9
|
-
- Run it like
|
|
9
|
+
- Run it like any test: `ancha run ancha/tests/<id>.yaml`. Both commands use a model: your `OPENROUTER_API_KEY`, or your workspace's credit when you're logged in.
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Tests from a template
|
|
12
12
|
|
|
13
13
|
`ancha scene new my-scene --twins slack,okta` creates scene.yaml with a seed for every requested tool (the packaged template's for Slack, GitHub, Datadog and PagerDuty, the tool's example otherwise) and an access check where the reference companion can read the tool, plus oracle.ts/null.ts and dependency-free Node companions oracle.mjs/null.mjs. Choose a path-safe lowercase id. Unknown/duplicate twins and existing destinations are rejected. Scenes are strict YAML, not runtime includes.
|
|
14
14
|
|
|
15
15
|
## Seeds
|
|
16
16
|
|
|
17
|
-
`ancha twins seed <tool>` prints what `seed.<tool>` takes: the fields with their types and defaults, an example cut from the tool's starter data that validates as written, the state checks and scripted events a
|
|
17
|
+
`ancha twins seed <tool>` prints what `seed.<tool>` takes: the fields with their types and defaults, an example cut from the tool's starter data that validates as written, the state checks and scripted events a test can use on the tool, the variables the agent gets and the SDK settings. `--json` prints the same as data (the fields as JSON Schema); `--full` uses the complete starter data as the example. A test whose seed has an unknown, missing or mistyped field fails validation with a hint that names this command.
|
|
18
18
|
|
|
19
19
|
Validate with `ancha scene validate scenes/my-scene/scene.yaml --json`. Reference checks: run `ancha run scenes/my-scene/scene.yaml --agent "node scenes/my-scene/oracle.mjs" -n 1 --parallel 1 --json` and repeat with null.mjs. Oracle should pass; null should exit cleanly while business checks fail. Test validity, business outcome and process completion independently. The starter checks read access; replace its task and trace checks with your own business checks.
|
|
20
20
|
|
package/lib/assets/docs/setup.md
CHANGED
|
@@ -12,46 +12,48 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
12
12
|
ancha --version || npm install -g @ancha-labs/cli
|
|
13
13
|
ancha login
|
|
14
14
|
```
|
|
15
|
-
2. **
|
|
15
|
+
2. **Set up the project.** Run it in the agent's project: it finds the command that starts the agent and how the agent takes its task, and writes both to `ancha.yaml`. It installs and runs nothing.
|
|
16
16
|
```sh
|
|
17
|
-
ancha init
|
|
17
|
+
ancha init
|
|
18
18
|
```
|
|
19
|
-
|
|
19
|
+
- To name the command yourself: `ancha init --agent "<the command that starts your agent>"`.
|
|
20
|
+
3. **Store the key it needs.** The agent's own model key, read from your shell, never from an argument: it is stored in your workspace and named under `agent.pass_env` in `ancha.yaml`, so the agent gets it in every cloud attempt.
|
|
20
21
|
```sh
|
|
21
|
-
ancha secrets set
|
|
22
|
+
ancha secrets set ANTHROPIC_API_KEY
|
|
22
23
|
```
|
|
23
|
-
4. **
|
|
24
|
+
4. **Upload your agent.** A fresh machine in the cloud installs the project's dependencies and starts the agent once with a task. It says the agent is ready, or shows the end of its log.
|
|
24
25
|
```sh
|
|
25
|
-
ancha
|
|
26
|
+
ancha agent upload
|
|
26
27
|
```
|
|
27
28
|
- The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.
|
|
28
|
-
5. **
|
|
29
|
+
5. **Upload traces.** A file or a folder of traces, runs that went fine and runs that failed: each trace becomes a test, in `scenes/from-traces/` and in your workspace.
|
|
29
30
|
```sh
|
|
30
|
-
ancha
|
|
31
|
+
ancha traces upload ./traces
|
|
31
32
|
```
|
|
32
|
-
-
|
|
33
|
-
- A trace
|
|
34
|
-
-
|
|
33
|
+
- From Langfuse or LangSmith, with your keys on this computer: `ancha traces upload --from langfuse --limit 50`, or `--from langsmith`.
|
|
34
|
+
- A trace of a run that went wrong can say what went wrong: `ancha traces upload <trace file> --expect "<what went wrong>"`, or for a test already made, `ancha pull <test id> --expect "<what went wrong>"`.
|
|
35
|
+
- Traces your agent already sent to your workspace: `ancha traces`, then `ancha pull <trace id>`.
|
|
36
|
+
- A test lists what one trace cannot settle: answer with `ancha pull <test id> --answer <question>=<answer>`.
|
|
35
37
|
6. **Point the agent at the test's tools.** In a test, the agent calls Ancha instead of production:
|
|
36
38
|
- Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.
|
|
37
39
|
- Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.
|
|
38
|
-
7. **Run
|
|
40
|
+
7. **Run your tests.** Every test, each attempt on a fresh machine. The run grades each attempt check by check and ends with the link to its result.
|
|
39
41
|
```sh
|
|
40
|
-
ancha run
|
|
42
|
+
ancha run
|
|
41
43
|
```
|
|
42
44
|
- Your agent and its worlds run in the cloud, each attempt on a fresh machine of its own; a run keeps going when your laptop closes, and its results land in Runs.
|
|
43
|
-
- `--
|
|
45
|
+
- `--attempts <n>` sets how many attempts each test gets, `--concurrency <n>` how many run at once.
|
|
44
46
|
- `ancha wait <run id>` follows a run again from any terminal; `ancha explain <run id>` shows why a check failed.
|
|
45
|
-
- `ancha status
|
|
47
|
+
- `ancha status` shows which of these steps your workspace has done.
|
|
46
48
|
8. **Fix the agent and keep the test.** Keep the failing run as the reference, fix the agent, and run again: exit 0 means every check passes and nothing regressed.
|
|
47
49
|
```sh
|
|
48
50
|
ancha baseline save before --from <run id>
|
|
49
|
-
ancha run --
|
|
51
|
+
ancha run --compare before
|
|
50
52
|
```
|
|
51
53
|
- Commit `scenes/from-traces/` so every run, in CI too, keeps it fixed.
|
|
52
54
|
9. **Run it on this computer.** While you develop, `ancha run --on local` runs the agent and its worlds on this computer, with the same checks.
|
|
53
55
|
```sh
|
|
54
|
-
ancha run --on local
|
|
56
|
+
ancha run --on local --attempts 1
|
|
55
57
|
```
|
|
56
58
|
- Here the agent gets the keys in `agent.pass_env` from your shell, and model-graded checks need `OPENROUTER_API_KEY`.
|
|
57
59
|
<!-- /ancha:first-steps -->
|
|
@@ -59,22 +61,22 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
59
61
|
## What init writes
|
|
60
62
|
|
|
61
63
|
`ancha init --agent "node agent.mjs"`, with your own start command, writes:
|
|
62
|
-
- `ancha.yaml`: how to start the agent, how many trials, which
|
|
63
|
-
- `scenes/starter/`: a starter
|
|
64
|
+
- `ancha.yaml`: how to start the agent, how many trials, which tests;
|
|
65
|
+
- `scenes/starter/`: a starter test that checks the agent reaches each tool, with two reference companions (`oracle.mjs` passes, `null.mjs` makes no calls);
|
|
64
66
|
- `.claude/skills/ancha/SKILL.md` and an Ancha section in `AGENTS.md`, for coding agents;
|
|
65
67
|
- `.ancha/` in `.gitignore`: run history, traces and fake tokens never belong in git.
|
|
66
68
|
|
|
67
|
-
Init installs nothing, runs nothing and keeps every existing file. It reads `package.json`, `requirements.txt`, `pyproject.toml` and `Pipfile` to report the SDKs it recognizes. Without `--agent`,
|
|
69
|
+
Init installs nothing, runs nothing and keeps every existing file. It reads `package.json`, `requirements.txt`, `pyproject.toml` and `Pipfile` to report the SDKs it recognizes. Without `--agent`, it finds the command that starts the agent and how the agent takes its task, and writes both to `ancha.yaml`. Your production traces make the tests for the agent's real job (`ancha traces upload ./traces`, `ancha docs traces`); `ancha docs scenes` writes more.
|
|
68
70
|
|
|
69
71
|
`ancha run` runs tests in files; `ancha test run <id>` runs a saved test. `ancha test` lists its subcommands and these run commands, then exits 1; with `--json` it returns a `USAGE` error with the same guidance.
|
|
70
72
|
|
|
71
73
|
If the AI feature lives inside an app (a web app or API server with its database, workers and scheduled jobs), Ancha starts the app for each trial instead of a command: `ancha docs apps`.
|
|
72
74
|
|
|
73
|
-
Fix the agent, not the
|
|
75
|
+
Fix the agent, not the tests or checks. The exception is a check that is wrong for the real API; then say so and show the evidence (the call the official SDK makes, and the vendor's documentation).
|
|
74
76
|
|
|
75
77
|
## On this computer
|
|
76
78
|
|
|
77
|
-
`ancha run --on local
|
|
79
|
+
`ancha run --on local` runs the tests on this computer; so does `ancha run` without `--on` when no login is saved. `ancha doctor` checks the agent here first: it validates the config and every test, then runs the agent once (10 s by default, `--timeout` up to 30s) and reports which tools it reached. For model-graded checks it lists a separate `judge` item: `OPENROUTER_API_KEY` set passes; a missing key is an error if any test lists a judge check in `pass`, otherwise a warning. Set the key in the shell running Ancha. A tool the agent didn't call is a warning, not a failure: doctor exits 0 when only warnings remain. Then `ancha run --on local --json`, `ancha explain latest --json`, `ancha baseline save before`, and after the fix `ancha run --on local --compare before --json`.
|
|
78
80
|
|
|
79
81
|
## Where things run
|
|
80
82
|
|
|
@@ -85,9 +87,9 @@ Fix the agent, not the scenes or checks. The exception is a check that is wrong
|
|
|
85
87
|
|
|
86
88
|
## Exit codes
|
|
87
89
|
|
|
88
|
-
0 pass; 1 a check failed, the pass rate is below `min_pass_rate`, a comparison regressed, or `ancha test` needs a subcommand; 2 usage, config,
|
|
90
|
+
0 pass; 1 a check failed, the pass rate is below `min_pass_rate`, a comparison regressed, or `ancha test` needs a subcommand; 2 usage, config, test file or authentication error; 3 infrastructure, or a trial the harness couldn't complete; 4 an endpoint coverage error or a verdict using simulated tool answers, with `--strict`. A harness failure takes precedence over the others.
|
|
89
91
|
|
|
90
|
-
Add `--json` for machine-readable results. Runs
|
|
92
|
+
Add `--json` for machine-readable results. Runs emit NDJSON; `env list` and `sandbox list` return arrays. Read the command-specific result fields with `ancha schema` and `ancha docs traces`. Errors carry `code` and `message`; `hint` names the next action.
|
|
91
93
|
|
|
92
94
|
## Topics
|
|
93
95
|
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# Tests from production traces
|
|
2
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.
|
|
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. Runs that went fine and runs that failed both make tests, one per conversation.
|
|
4
4
|
|
|
5
5
|
## Make the tests
|
|
6
6
|
|
|
7
|
-
- `ancha
|
|
8
|
-
- `ancha
|
|
9
|
-
-
|
|
10
|
-
-
|
|
7
|
+
- After `ancha login`, `ancha traces upload <file|folder|glob>...` sends traces to the workspace, which makes a test from each and writes it here, under `scenes/from-traces/`. A file is OTLP JSON, a Langfuse or LangSmith export, or Ancha Trace IR; a folder is searched for `.json` and `.jsonl` files. A trace that makes no test is listed with the reason, and the upload goes on with the rest.
|
|
8
|
+
- `ancha traces upload --from langfuse --limit 50` (or `--from langsmith`) takes the newest traces there with the keys in this shell (`LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_HOST`; `LANGSMITH_API_KEY`, `LANGSMITH_ENDPOINT`); `--since 7d` and `--name <trace name>` choose which.
|
|
9
|
+
- `ancha import <trace file>` uploads one file the same way, and `ancha import --from langfuse <trace id>` one trace. `ancha import --offline <trace file>` makes the tests on this computer and uploads nothing.
|
|
10
|
+
- When the agent sends its traces to the workspace, each becomes a test there: `ancha pull --all` writes every test that is turned on (`--agent <name>` for one agent's), `ancha traces --failed` lists the runs where production failed a check, `ancha traces show <id>` previews a test and `ancha pull <id>` writes one.
|
|
11
|
+
- For one trace, `--expect "<what went wrong>"` adds a check for it, `--dest <dir>` sets the folder (default `scenes/from-traces`) and `--force` replaces a `scene.yaml` that is already there; with `--offline`, `--conversation <id>` takes one conversation of the file.
|
|
11
12
|
|
|
12
13
|
Each test has its own folder under `scenes/from-traces/`: `scene.yaml`, `production.jsonl` (the invocation, native API calls, events and function calls), `production.json` (check verdicts), `provenance.json` and `questions.json`. Function tools also write `observations.jsonl` for replay. Offline imports keep your answers in `answers.json` and merge the tools' initial records into `records.jsonl` beside the test folders.
|
|
13
14
|
|
|
@@ -65,7 +66,7 @@ ancha.chat(reply)
|
|
|
65
66
|
|
|
66
67
|
## Run them
|
|
67
68
|
|
|
68
|
-
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
|
|
69
|
+
In a project without `ancha.yaml`, run `ancha init --agent "<the command that starts the agent>"` first; with tests already in `scenes/`, or signed in to a workspace, it writes no starter test. Then:
|
|
69
70
|
|
|
70
71
|
`ancha run scenes/from-traces/*/scene.yaml --json`
|
|
71
72
|
|
|
@@ -94,7 +95,7 @@ compared with production (trace 7d2f91c4a0e6): trace-2760b5c5
|
|
|
94
95
|
refund_order production: called this run: 3 of 3 trials
|
|
95
96
|
```
|
|
96
97
|
|
|
97
|
-
When a test doesn't fail the way production did, `ancha traces diff <trace file> latest/trial-<
|
|
98
|
+
When a test doesn't fail the way production did, `ancha traces diff <trace file> latest/trial-<test>-1` compares service, method, path, query parameters, arguments and request bodies. It lists requests unique to each side and the first differing request. IDs tied to the same observed reference in the test compare across worlds; other IDs keep their values. Credentials are redacted in the comparison.
|
|
98
99
|
|
|
99
100
|
|
|
100
101
|
`ancha runs export <run> --json` writes one IR trace per attempt, including the saved task, agent identity, test definition, outcome and check evidence. Reimporting uses those saved criteria and production verdicts.
|
|
@@ -78156,7 +78156,7 @@ var when = external_exports.string().refine((value4) => {
|
|
|
78156
78156
|
} catch {
|
|
78157
78157
|
return false;
|
|
78158
78158
|
}
|
|
78159
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
78159
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -35m");
|
|
78160
78160
|
var ref7 = external_exports.string().regex(/^[A-Za-z0-9_-]{1,80}$/);
|
|
78161
78161
|
var attachment = external_exports.strictObject({
|
|
78162
78162
|
filename: external_exports.string().min(1).max(255),
|
|
@@ -78525,7 +78525,7 @@ var when2 = external_exports.string().refine((value4) => {
|
|
|
78525
78525
|
} catch {
|
|
78526
78526
|
return false;
|
|
78527
78527
|
}
|
|
78528
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
78528
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -2h");
|
|
78529
78529
|
var zone3 = external_exports.string().max(100).refine((value4) => {
|
|
78530
78530
|
try {
|
|
78531
78531
|
new Intl.DateTimeFormat("en", { timeZone: value4 });
|
|
@@ -79058,11 +79058,11 @@ var isDuration = (value4) => {
|
|
|
79058
79058
|
};
|
|
79059
79059
|
var past = external_exports.string().refine(
|
|
79060
79060
|
(value4) => external_exports.iso.datetime({ offset: true }).safeParse(value4).success ? Number.isFinite(Date.parse(value4)) : isDuration(value4) && parseDuration(value4) <= 0,
|
|
79061
|
-
"expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
79061
|
+
"expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -720h"
|
|
79062
79062
|
);
|
|
79063
79063
|
var moment = external_exports.string().refine(
|
|
79064
79064
|
(value4) => external_exports.iso.datetime({ offset: true }).safeParse(value4).success ? Number.isFinite(Date.parse(value4)) : isDuration(value4),
|
|
79065
|
-
"expected an ISO 8601 time with a timezone, or an offset from the
|
|
79065
|
+
"expected an ISO 8601 time with a timezone, or an offset from the start of the test such as 72h or -24h"
|
|
79066
79066
|
);
|
|
79067
79067
|
var StripeSeedSchema = external_exports.strictObject({
|
|
79068
79068
|
account: external_exports.strictObject({ name: text8, currency: external_exports.enum(["usd", "eur", "gbp", "cad", "aud"]).default("usd"), statement_descriptor: external_exports.string().regex(/^[A-Za-z0-9 .-]{5,22}$/).optional() }),
|
|
@@ -79592,7 +79592,7 @@ var when3 = external_exports.string().refine((value4) => {
|
|
|
79592
79592
|
} catch {
|
|
79593
79593
|
return false;
|
|
79594
79594
|
}
|
|
79595
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
79595
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -8h");
|
|
79596
79596
|
var day2 = external_exports.string().regex(/^\d{4}-\d{2}-\d{2}$/);
|
|
79597
79597
|
var block = external_exports.lazy(() => external_exports.strictObject({
|
|
79598
79598
|
type: external_exports.enum(NOTION_BLOCK_TYPES),
|
|
@@ -79897,7 +79897,7 @@ var when4 = external_exports.string().refine((value4) => {
|
|
|
79897
79897
|
} catch {
|
|
79898
79898
|
return false;
|
|
79899
79899
|
}
|
|
79900
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
79900
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
79901
79901
|
var attribute = external_exports.strictObject({
|
|
79902
79902
|
api_slug: slug,
|
|
79903
79903
|
title: external_exports.string().min(1).max(100),
|
|
@@ -80159,7 +80159,7 @@ var isDuration2 = (value4) => {
|
|
|
80159
80159
|
};
|
|
80160
80160
|
var past2 = external_exports.string().refine(
|
|
80161
80161
|
(v) => external_exports.iso.datetime({ offset: true }).safeParse(v).success ? Number.isFinite(Date.parse(v)) : isDuration2(v) && parseDuration(v) <= 0,
|
|
80162
|
-
"expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
80162
|
+
"expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -26h"
|
|
80163
80163
|
);
|
|
80164
80164
|
var moment2 = external_exports.string().refine((v) => external_exports.iso.datetime({ offset: true }).safeParse(v).success ? Number.isFinite(Date.parse(v)) : isDuration2(v), "expected an ISO 8601 time or an offset such as 24h");
|
|
80165
80165
|
var ResendSeedSchema = external_exports.strictObject({
|
|
@@ -80513,7 +80513,7 @@ var past3 = external_exports.string().refine((value4) => {
|
|
|
80513
80513
|
} catch {
|
|
80514
80514
|
return false;
|
|
80515
80515
|
}
|
|
80516
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
80516
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
80517
80517
|
var address3 = external_exports.strictObject({
|
|
80518
80518
|
first_name: external_exports.string().max(100).optional(),
|
|
80519
80519
|
last_name: external_exports.string().max(100).optional(),
|
|
@@ -81260,7 +81260,7 @@ var past4 = external_exports.string().refine((value4) => {
|
|
|
81260
81260
|
} catch {
|
|
81261
81261
|
return false;
|
|
81262
81262
|
}
|
|
81263
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
81263
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
81264
81264
|
var person = external_exports.strictObject({ first_name: external_exports.string().min(1).max(140), last_name: external_exports.string().min(1).max(140), email: external_exports.string().regex(EMAIL8) });
|
|
81265
81265
|
var PayPalSeedSchema = external_exports.strictObject({
|
|
81266
81266
|
account: external_exports.strictObject({
|
|
@@ -81465,7 +81465,7 @@ var time3 = (future = false) => external_exports.string().refine((value4) => {
|
|
|
81465
81465
|
} catch {
|
|
81466
81466
|
return false;
|
|
81467
81467
|
}
|
|
81468
|
-
}, future ? "expected an ISO 8601 time with a timezone, or an offset from the
|
|
81468
|
+
}, future ? "expected an ISO 8601 time with a timezone, or an offset from the start of the test such as 7d" : "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
81469
81469
|
var past5 = time3();
|
|
81470
81470
|
var moment3 = time3(true);
|
|
81471
81471
|
var JiraSeedSchema = external_exports.strictObject({
|
|
@@ -82010,7 +82010,7 @@ var time4 = (future = false) => external_exports.string().refine((value4) => {
|
|
|
82010
82010
|
} catch {
|
|
82011
82011
|
return false;
|
|
82012
82012
|
}
|
|
82013
|
-
}, future ? "expected an ISO 8601 time with a timezone, or an offset from the
|
|
82013
|
+
}, future ? "expected an ISO 8601 time with a timezone, or an offset from the start of the test such as 1d" : "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
82014
82014
|
var past6 = time4();
|
|
82015
82015
|
var moment4 = time4(true);
|
|
82016
82016
|
var IntercomSeedSchema = external_exports.strictObject({
|
|
@@ -82537,7 +82537,7 @@ var offsetOk = (value4, future) => {
|
|
|
82537
82537
|
};
|
|
82538
82538
|
var time5 = (future) => external_exports.string().refine(
|
|
82539
82539
|
(v) => external_exports.iso.datetime({ offset: true }).safeParse(v).success ? Number.isFinite(Date.parse(v)) : offsetOk(v, future),
|
|
82540
|
-
future ? "expected an ISO 8601 time with an offset, or an offset from the
|
|
82540
|
+
future ? "expected an ISO 8601 time with an offset, or an offset from the start of the test such as 26h" : "expected an ISO 8601 time with an offset, or a nonpositive offset such as -30h"
|
|
82541
82541
|
);
|
|
82542
82542
|
var past7 = time5(false);
|
|
82543
82543
|
var moment5 = time5(true);
|
|
@@ -83271,7 +83271,7 @@ var past8 = external_exports.string().refine((value4) => {
|
|
|
83271
83271
|
} catch {
|
|
83272
83272
|
return false;
|
|
83273
83273
|
}
|
|
83274
|
-
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the
|
|
83274
|
+
}, "expected an ISO 8601 time with a timezone, or a nonpositive offset from the start of the test such as -30h");
|
|
83275
83275
|
var spacing = external_exports.string().refine((value4) => {
|
|
83276
83276
|
try {
|
|
83277
83277
|
return parseDuration(value4) > 0;
|
|
@@ -85136,7 +85136,7 @@ var money6 = external_exports.number().finite().refine((value4) => Math.round(va
|
|
|
85136
85136
|
var positive = money6.refine((value4) => value4 > 0, "must be more than 0");
|
|
85137
85137
|
var day5 = external_exports.string().refine(
|
|
85138
85138
|
(value4) => /^-?\d+d$/.test(value4) || /^\d{4}-\d{2}-\d{2}$/.test(value4) && (/* @__PURE__ */ new Date(`${value4}T00:00:00Z`)).toISOString().slice(0, 10) === value4,
|
|
85139
|
-
"expected YYYY-MM-DD or an offset in days from the
|
|
85139
|
+
"expected YYYY-MM-DD or an offset in days from the start of the test, e.g. -30d"
|
|
85140
85140
|
);
|
|
85141
85141
|
var external = text11.optional();
|
|
85142
85142
|
var custom2 = external_exports.record(external_exports.string().regex(/^cust(?:entity|body|col|item)[a-z0-9_]+$/), external_exports.union([external_exports.string().max(4e3), external_exports.number(), external_exports.boolean(), external_exports.null()])).optional();
|
|
@@ -86212,7 +86212,7 @@ var ToolExampleSchema = external_exports.strictObject({
|
|
|
86212
86212
|
});
|
|
86213
86213
|
var SceneToolSchema = external_exports.strictObject({
|
|
86214
86214
|
/** A JSON lines file next to the scene, one recorded call per line (`ancha run` reads it into `recorded`). */
|
|
86215
|
-
observations: external_exports.string().regex(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/, "a path relative to the
|
|
86215
|
+
observations: external_exports.string().regex(/^(?!\/)(?!.*(?:^|\/)\.\.(?:\/|$))[^\0]+$/, "a path relative to the test file (scene.yaml), without ..").optional(),
|
|
86216
86216
|
recorded: external_exports.array(ToolObservationSchema).optional(),
|
|
86217
86217
|
/** Calls from other traces of this agent, so a simulated answer can follow how the tool behaved there. */
|
|
86218
86218
|
examples: external_exports.array(ToolExampleSchema).optional(),
|
|
@@ -87406,7 +87406,7 @@ function toolIssues(scene2) {
|
|
|
87406
87406
|
if (tool.unrecorded === "twin" && tool.twin === void 0) issues.push({ path: `${path4}.unrecorded`, message: "unrecorded: twin needs the twin that answers", hint: `set ${path4}.twin, e.g. twin: slack` });
|
|
87407
87407
|
if (tool.pure && tool.write) issues.push({ path: `${path4}.pure`, message: "a tool that changes something is not pure", hint: `remove ${path4}.pure, or ${path4}.write if it only computes from its arguments` });
|
|
87408
87408
|
if (tool.observations !== void 0 && tool.recorded === void 0) {
|
|
87409
|
-
issues.push({ path: `${path4}.observations`, message: `${tool.observations} was not read`, hint: "load the
|
|
87409
|
+
issues.push({ path: `${path4}.observations`, message: `${tool.observations} was not read`, hint: "load the test from its file (ancha run, ancha scene validate), which reads the recorded calls next to it" });
|
|
87410
87410
|
}
|
|
87411
87411
|
tool.recorded?.forEach((o, i) => {
|
|
87412
87412
|
if (o.tool !== name5) issues.push({ path: `${path4}.recorded[${i}].tool`, message: `a call to ${o.tool} recorded under ${name5}` });
|
|
@@ -87419,7 +87419,7 @@ function toolIssues(scene2) {
|
|
|
87419
87419
|
const patterns = check3.trace[key4] === void 0 ? [] : [].concat(check3.trace[key4]);
|
|
87420
87420
|
patterns.forEach((pattern) => {
|
|
87421
87421
|
const bare = /^([A-Za-z_][\w.-]{0,127})(?:\s+\{.*\})?$/s.exec(pattern.trim());
|
|
87422
|
-
if (bare && !scene2.tools[bare[1]]) issues.push({ path: `checks[${i}].trace.${key4}`, message: `${bare[1]} is not one of this
|
|
87422
|
+
if (bare && !scene2.tools[bare[1]]) issues.push({ path: `checks[${i}].trace.${key4}`, message: `${bare[1]} is not one of this test's tools`, hint: `the tools are ${Object.keys(scene2.tools).join(", ")}; an API call is "<METHOD> <PATH>"` });
|
|
87423
87423
|
});
|
|
87424
87424
|
}
|
|
87425
87425
|
});
|
|
@@ -87743,7 +87743,7 @@ function ruleIssues(scene2) {
|
|
|
87743
87743
|
if (scene2.world === "static" && scene2.world_rules !== void 0) {
|
|
87744
87744
|
issues.push({
|
|
87745
87745
|
path: "world_rules",
|
|
87746
|
-
message: "static
|
|
87746
|
+
message: "static tests cannot declare world rules",
|
|
87747
87747
|
hint: "set world: living, or remove world_rules"
|
|
87748
87748
|
});
|
|
87749
87749
|
}
|
|
@@ -87883,7 +87883,7 @@ function parseSceneYaml(text23) {
|
|
|
87883
87883
|
return { path: `line ${line2}, column ${col2}`, message: e.message };
|
|
87884
87884
|
});
|
|
87885
87885
|
const atError = doc.errors.findIndex((e) => text23[e.pos[0]] === "@");
|
|
87886
|
-
if (atError >= 0) issues[atError].hint = "
|
|
87886
|
+
if (atError >= 0) issues[atError].hint = "refs in a test use $, e.g. $alice \u2014 YAML reserves @";
|
|
87887
87887
|
throw sceneError(issues, doc.errors[0]);
|
|
87888
87888
|
}
|
|
87889
87889
|
const cut = cutProseIssues(doc, text23, lineCounter);
|
package/lib/assets/llms.txt
CHANGED
|
@@ -19,11 +19,11 @@ Your agent and its worlds run in the cloud, each attempt on a fresh machine of i
|
|
|
19
19
|
```sh
|
|
20
20
|
npm install -g @ancha-labs/cli
|
|
21
21
|
ancha login
|
|
22
|
-
ancha init
|
|
23
|
-
ancha secrets set
|
|
24
|
-
ancha
|
|
25
|
-
ancha
|
|
26
|
-
ancha run
|
|
22
|
+
ancha init
|
|
23
|
+
ancha secrets set ANTHROPIC_API_KEY
|
|
24
|
+
ancha agent upload
|
|
25
|
+
ancha traces upload ./traces
|
|
26
|
+
ancha run
|
|
27
27
|
```
|
|
28
28
|
<!-- /ancha:first-steps -->
|
|
29
29
|
|
|
@@ -33,6 +33,6 @@ ancha run --on cloud scenes/from-traces/<test>/scene.yaml --attempts 3 --concurr
|
|
|
33
33
|
|
|
34
34
|
- [Sign in](https://app.ancha.io/login): the console shows agents, tests, runs, attempts and every check with its evidence.
|
|
35
35
|
- `ancha login` asks the engineer to approve this computer once in the browser, then saves an API key for the workspace, app.ancha.io/t/<workspace>. `ancha run --on cloud` runs each attempt there on a fresh machine, and its result is at app.ancha.io/runs/<run id>. `ancha whoami --json` shows the workspace.
|
|
36
|
-
- CI needs no login: set `ANCHA_SERVER_URL` (the workspace, shown in the console's Settings and by `ancha whoami`) and `ANCHA_API_KEY` (created in Settings, shown once), then `ancha run --on cloud --
|
|
36
|
+
- CI needs no login: set `ANCHA_SERVER_URL` (the workspace, shown in the console's Settings and by `ancha whoami`) and `ANCHA_API_KEY` (created in Settings, shown once), then `ancha run --on cloud --json`.
|
|
37
37
|
- `ancha secrets set NAME` copies a key from this shell into the workspace, for the agent's cloud runs; `agent.pass_env` in `ancha.yaml` names the ones the agent gets. Values never go in arguments, tasks or files.
|
|
38
38
|
- The workspace's API and `ancha secrets` require the key. A key the server rejects gives `AUTH_INVALID` and exit 2: run `ancha login` again.
|