@ancha-labs/cli 0.1.5 → 0.2.0

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.
@@ -25,6 +25,20 @@ Add `--json` to every command. Runs print NDJSON events that end with `run_finis
25
25
 
26
26
  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
27
 
28
+ ## An app, not a command
29
+
30
+ If 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.
31
+
32
+ ## From a production failure
33
+
34
+ A production run that went wrong becomes a test here. With a trace file (an export from the user's tracing):
35
+
36
+ 1. `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.
37
+ 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
+ 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.
39
+
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.
41
+
28
42
  ## The rule
29
43
 
30
44
  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.
@@ -0,0 +1,88 @@
1
+ # Test an app
2
+
3
+ Use this when the AI feature lives inside an app (a web app, an API server and its workers) rather than in one command. `ancha run` starts the app once per trial against a fresh world. The world drives it: people send mail and messages, the app's own scheduled routes are called, and time passes. The checks read the world's end state and the calls the app made.
4
+
5
+ ## ancha.yaml
6
+
7
+ ```yaml
8
+ agent:
9
+ start: ./ancha/start.sh # once per trial; it starts the app on $ANCHA_AGENT_PORT
10
+ url: "http://127.0.0.1:{{agent.port}}/api/slack/events" # where the app receives the tools' events (webhooks, push)
11
+ ready_url: "http://127.0.0.1:{{agent.port}}/api/health" # answers 2xx once the app is up
12
+ startup_timeout: 180s # the start script's whole budget: reset, seed, boot
13
+ idle: 20s # how long the app may look quiet while it still works (Ancha can't see its model calls); skip_idle jumps the clock only after this much quiet
14
+ setup_calls: true # the app may call the world while it starts (subscriptions, lookups), before time starts
15
+ clock: node # Date in the app's Node processes follows the world's clock, for flows that wait days
16
+ env: # rendered per trial: {{slack.url}}, {{slack.token}}, {{gmail.url}}, {{gmail.token}} …
17
+ APP_SLACK_TOKEN: "{{slack.token}}"
18
+ scenes: [ancha/scenes/*.yaml]
19
+ trials: 3
20
+ ```
21
+
22
+ - `{{agent.port}}` is reserved for the trial, so the health route and the event routes need nothing Ancha-specific.
23
+ - `clock: node` needs `start`. Apps in other runtimes keep real time: give them short thresholds in their seeded settings instead.
24
+
25
+ ## The start script
26
+
27
+ - It gets only `PATH`, `HOME`, the locale, `ANCHA_AGENT_PORT`, `ANCHA_TRIAL`, the variables of every tool in the scene (`ancha connect <tool> --json` lists them) and `agent.env`. Set everything else in the script: database and cache URLs, the app's own secrets, its model key.
28
+ - Every trial is a new world with new URLs and tokens, so every trial starts the app clean:
29
+ 1. restore the database from a template copy (`CREATE DATABASE app_trial TEMPLATE app_base`, with `app_base` migrated once);
30
+ 2. flush caches and queues the tests own;
31
+ 3. seed what the flow needs with the app's own seeds, factories or test helpers, storing the world's token where the app keeps its OAuth tokens;
32
+ 4. `exec` the server. Start workers (job queues) from the same script; Ancha stops the whole process group after the trial.
33
+ - Old rows, caches and sync cursors (a stored history id, a last-seen timestamp) make an app silently do nothing in a new world.
34
+ - A world's ids repeat from trial to trial, as its seed does. Clear the app's dedupe keys and locks (keyed by message or event ids) at the start of every trial, and run trials one at a time (`parallel: 1`) unless each trial gets its own database and cache namespace.
35
+ - Seed what a real account has, through the app's own functions: the rules and settings its onboarding or settings page creates, not rows a test helper writes by hand. A helper's shortcut (a missing default rule, a rule without the id the settings page would store) changes what the app does.
36
+ - A production build boots faster than a development server, and boot time counts against `startup_timeout`. `.ancha/runs/<run>/trial-*/agent.log` has the script's and the app's output.
37
+
38
+ ## Point the app at the tools
39
+
40
+ - Use the app's base-URL setting if it has one; `ancha connect <tool> --lang ts|py` prints the SDK settings. If the SDK has none, add a development-only initializer that reads the tool's variable and does nothing when it is unset. Keep app changes that small and say why in a comment.
41
+ - Google clients keep only the host of a `rootUrl` set on the client; Ancha routes those calls by their token.
42
+ - Gmail reaches an app the way it does in production: the app calls `users.watch`, and the world then pushes Pub/Sub notifications to `agent.url`. If the app registers its watch on a schedule, call that route with an `app_call` early in the scene. The world gives `GMAIL_API_URL` and `GMAIL_ACCESS_TOKEN` (`{{gmail.url}}`, `{{gmail.token}}`); the mailbox's address is what `GET /gmail/v1/users/me/profile` answers, as in Gmail. `ancha connect gmail --lang ts` prints the client settings.
43
+ - Identifiers a scene relies on (an inbox token, a cron secret, an API key the world sends) should be fixed values your seed creates, because a scene is static.
44
+
45
+ ## Scenes for an app
46
+
47
+ ```yaml
48
+ id: stale-question
49
+ title: A customer's question gets an answer in the thread, and a reminder two days later if nobody resolved it
50
+ twins: [slack]
51
+ start_time: 2026-11-02T15:00:00Z # a Monday, for apps that count business days
52
+ timeout: 3d
53
+ skip_idle: true # jump the clock while the app and the world are quiet
54
+ seed:
55
+ slack:
56
+ users:
57
+ - { ref: bot, name: support-bot, is_bot: true }
58
+ - { ref: dan, name: dan, real_name: Dan Ito }
59
+ channels:
60
+ - { ref: support, name: support, members: [$bot, $dan] }
61
+ world_rules:
62
+ actors: # people acting in a tool at a time: slack.post, gmail.send, github.comment …
63
+ - at: 5s
64
+ slack.post: { ref: question, channel: $support, user: $dan, text: "How do I export my invoices?" }
65
+ app_calls: # the world calling the app: its cron routes, or a customer message into its API
66
+ - at: 2d1h
67
+ path: /api/cron/stale-questions
68
+ headers: { authorization: Bearer test-cron-secret }
69
+ checks:
70
+ - id: answered_in_thread
71
+ state: { slack.message: { channel: $support, from: $bot, in_thread_of: $question } }
72
+ - id: no_deletes
73
+ trace: { not_called: "* /api/chat.delete" }
74
+ ```
75
+
76
+ - `app_calls` take `at`, `method` (default GET), `path`, `headers` and `body`; they go to the origin of `ready_url`.
77
+ - `gmail.send` takes `from`, `to`, `cc`, `subject`, `body`, `in_reply_to` and `ref`. The `gmail.thread` check takes `of` (a message ref), `label` with `present`, `drafts_gte`, `drafts_lte` and `messages_gte`.
78
+ - People who answer like a person: `ancha test new "<the test in one sentence>"` drafts them. They call a model with your `OPENROUTER_API_KEY`, or `ANCHA_PEOPLE_BASE_URL` and `ANCHA_PEOPLE_API_KEY` (`ancha docs cloud`). `ancha twins seed <tool> --json` prints each tool's seed fields and checks.
79
+ - Make every check able to fail. Run a scene once against a build with the feature broken, or also check the state in between (the label the app should have removed). A check can pass for the wrong reason: a reminder that never comes because the scheduled call ran too early proves nothing.
80
+
81
+ ## From a production trace, on this computer
82
+
83
+ 1. `ancha import --offline <trace file> --json` reads an Ancha Trace IR file, or an OTLP JSON export whose spans carry the bodies of the app's calls to its tools. It writes `scenes/from-traces/trace-<id>/scene.yaml` and `provenance.json`; nothing is uploaded.
84
+ 2. It lists the questions one trace cannot settle, each with the default the test uses. Examples: should a label the app added still be on the thread at the end, and what header do the app's scheduled calls carry? Ask the user, then import again with `--answer <id>=<value>` for each and `--force`.
85
+ 3. Run the scene against the build that failed in production. It should fail the way production did. Then fix the app and run again.
86
+
87
+ - A trace holds the app's calls, not what started each one. Calls the app makes on its own at startup or on a timer (a watch, a sync) are not in the test: check that the start script or an `app_call` makes them.
88
+ - When a test does not fail the way production did, compare the trial's calls (`.ancha/runs/<run>/trial-*/trace.jsonl`) with production's, from the start: a call production made and the trial didn't (labels created at setup, a settings read) usually points at what the seed lacks.
@@ -12,17 +12,17 @@ The first line of every `ancha run` says where its worlds run and what the agent
12
12
 
13
13
  ## What runs where
14
14
 
15
- - `ancha run`, `ancha doctor`, `ancha world up`, `ancha env`, `ancha sandbox` and `ancha replay` create their worlds on this computer, also when you're logged in. `--server-url`, `server.url` in `ancha.yaml` or `ANCHA_SERVER_URL` put them on that server instead, for example the hosted world server `https://app.ancha.io/t/<workspace>` (your agent still runs here; its tool URLs point at `…/t/<workspace>/e/<environment>/<tool>/…`). `--on cloud` runs the agent in the workspace too (below).
15
+ - `ancha run`, `ancha doctor`, `ancha world up`, `ancha env`, `ancha sandbox` and `ancha replay` create their worlds on this computer, also when you're logged in. `--server-url`, `server.url` in `ancha.yaml` or `ANCHA_SERVER_URL` put them on that server instead, for example the hosted world server `https://app.ancha.io/t/<workspace>` (your agent still runs here; its tool URLs point at `…/t/<workspace>/e/<environment>/<tool>/…`). Local scene/test import through `--on cloud` is currently rejected before remote work because its world and grading semantics cannot be preserved.
16
16
  - `ancha agent` (except `agent detect`), `ancha world list|show|create|update|archive`, `ancha test`, `ancha runs`, `ancha attempt` and `ancha explain <play_…>` run in the hosted workspace: they list and change the same agents, worlds, tests and runs as the console, and every JSON object they print names its `workspace`. `--local` keeps them on this project's `.ancha/`. `ancha playground` stays on this computer.
17
17
  - `ancha agent add|update --cwd <dir>` uploads the folder first: the files git tracks or would add, without `.anchaignore` patterns, hidden files, dependencies or credential-like files, at most 200 MB.
18
18
 
19
19
  ## Run the agent in the workspace
20
20
 
21
21
  ```sh
22
- ancha run --on cloud --json # every test or scene ancha.yaml names; or pass files
22
+ ancha runs start --agent <id> --world <saved-world> --test task.yaml --json
23
23
  ```
24
24
 
25
- This uploads the project, registers its agent under the project folder's name (updating it the next time), connects it (the workspace builds its image once per code version), and runs each test there as its own run, streaming `run_started`, each attempt and `run_finished` with the grade. The exit code is the worst of the runs: 0 every attempt passed, 1 an attempt failed, 2 stopped, 3 error. The workspace's console owns each run, so a dropped connection doesn't stop it: `ancha runs show <id>` and `ancha explain <id> --json` pick it up. A test for the workspace gives the agent a task (`start.task` in a version 2 test, or `task` in a scene). `ancha runs start --agent <id> --test <file>` runs one test with an agent that is already there.
25
+ This runs an already connected agent against an explicitly selected saved world. `task.yaml` uses `version: 2`, `id`, `start.task`, and optional `attempts`, real-time `timeout` and supported native/process checks. Scene seeds, people, world rules, `until`, `deadline`, selective `pass` lists and judge checks are rejected by file/field with `CONFIG_INVALID` (exit 2), rather than discarded. `ancha run --on cloud` also rejects local scene/test imports and unsupported options before network requests, uploads or registration. Run full scenes/tests locally or in CI. The workspace's console owns accepted managed runs, so a dropped connection does not stop them; `ancha runs show <id>` and `ancha explain <id> --json` resume inspection.
26
26
 
27
27
  ## Results in the workspace
28
28
 
@@ -35,7 +35,7 @@ ancha runs upload latest # a run that already finished (also a run i
35
35
 
36
36
  ## People and world generation
37
37
 
38
- The people in a world and `ancha world gen` call a language model. With `OPENROUTER_API_KEY` set they use your key. Logged in to a workspace without one, they use the workspace's model credit through its relay (`https://app.ancha.io/t/<workspace>/_relay/v1`, authorized by the workspace's API key; your own key never goes there). Those calls go through the hosted workspace and wake its machine, which can take up to a minute after it sleeps. The relay serves its own model list, takes requests up to 256 KB and about 120 a minute per workspace, and says when the workspace is out of credit or has model calls turned off; the error names the next step, and setting `OPENROUTER_API_KEY` always works.
38
+ The people in a world and `ancha world gen` call a language model. With `OPENROUTER_API_KEY` set they use your key. For another OpenAI-compatible endpoint, set `ANCHA_PEOPLE_BASE_URL` (ending in `/v1`) and `ANCHA_PEOPLE_API_KEY` instead; it must serve OpenRouter's model names. Logged in to a workspace without one, they use the workspace's model credit through its relay (`https://app.ancha.io/t/<workspace>/_relay/v1`, authorized by the workspace's API key; your own key never goes there). Those calls go through the hosted workspace and wake its machine, which can take up to a minute after it sleeps. The relay serves its own model list, takes requests up to 256 KB and about 120 a minute per workspace, and says when the workspace is out of credit or has model calls turned off; the error names the next step, and setting `OPENROUTER_API_KEY` always works.
39
39
 
40
40
  ## CI
41
41
 
@@ -8,4 +8,6 @@ Slack WebClient uses slackApiUrl. With Bolt Socket Mode configure both App clien
8
8
 
9
9
  PagerDuty PDJS requires a full local url for every REST request; its server option assumes production HTTPS. Use response.data and next(); resource/all and Events convenience helpers have production-host assumptions. Use fetch to the local /v2/enqueue with a native Events v2 payload and a service routing key. REST tokens, routing keys, From identity and webhook signing secrets have separate roles.
10
10
 
11
+ Gmail: Ancha supplies GMAIL_API_URL/GMAIL_ACCESS_TOKEN (`ancha connect gmail --lang ts`). Google clients take the URL as each call's `rootUrl` (`GMAIL_API_URL + '/'`) or the app's own base-URL setting; push to the app follows its `users.watch` call (`ancha docs apps`).
12
+
11
13
  Verify webhook signatures against exact raw request bytes before JSON parsing. Slack uses its signing secret, GitHub its webhook secret, PagerDuty its signing secret; Datadog's declared custom webhook profile uses a bearer token. Native route support and delivery/retry policies are a bounded subset, not full vendor parity.
@@ -6,6 +6,8 @@ The first line says where the worlds run: locally, or on the hosted workspace yo
6
6
 
7
7
  ## What the agent gets
8
8
 
9
+ New run summaries use `verdictVersion: 2`. Each scene 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.
10
+
9
11
  Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_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.
10
12
 
11
13
  By default 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:
@@ -22,9 +24,11 @@ agent:
22
24
 
23
25
  By default the agent runs once per attempt with the task in `ANCHA_TASK`. When the world has 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.
24
26
 
27
+ `per_event` is supported by the local scene runner, including local container execution. Managed/Harbor execution rejects `per_event` and `events` with `CONFIG_INVALID` (exit 2); its driver does not implement per-event invocations. It never substitutes a one-shot command.
28
+
25
29
  ## Where the agent runs
26
30
 
27
- `--on local` starts it as a process on this computer, `--on docker` in the sealed container below (never a process instead), and `--on cloud` in your hosted workspace (`ancha docs cloud`). Without `--on`, `ancha.yaml` decides.
31
+ `--on local` starts it as a process on this computer; `--on docker` uses the sealed container below (never a process instead). Without `--on`, `ancha.yaml` decides. `--on cloud` currently rejects local scene and version 2 test imports with `CONFIG_INVALID` (exit 2): their world data, timing and checks cannot be preserved by that adapter. It names unsupported files, fields and options before any upload or registration. Run these tests locally or in CI. Explicit saved-world tasks use `ancha runs start`; that is a separate managed-task contract, not equivalent scene import.
28
32
 
29
33
  `--upload` (or `ANCHA_UPLOAD=1`) sends the finished run to your workspace, where the console shows it; `ancha runs upload <run id | latest>` does that later. A failed upload is a warning unless `--upload-required`. `ancha docs cloud` says what is sent and what is redacted.
30
34
 
@@ -84,3 +88,5 @@ ancha world down --env <envId>
84
88
  `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.
85
89
 
86
90
  Native SDK methods may go beyond what a tool replica implements: check `ancha twins coverage <tool>` and `ancha connect <tool>`. Keep provider keys out of scenes and saved configuration.
91
+
92
+ 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.
@@ -20,6 +20,8 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
20
20
 
21
21
  The starter only proves the agent reaches its tools. Replace it with scenes for the agent's real job: `ancha docs scenes`.
22
22
 
23
+ 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`.
24
+
23
25
  Fix the agent, not the scenes 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).
24
26
 
25
27
  ## Where things run
@@ -37,4 +39,4 @@ Add `--json` to any command for one JSON object, or NDJSON events for runs. Erro
37
39
 
38
40
  ## Topics
39
41
 
40
- `ancha docs <topic>`: `setup` (this page), `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`, `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).