@ancha-labs/cli 0.4.20 → 0.4.22
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/bin/ancha.mjs +15 -1
- package/lib/ancha.mjs +37468 -34887
- package/lib/assets/docs/apps.md +1 -1
- package/lib/assets/docs/compare.md +2 -0
- package/lib/assets/docs/explain.md +3 -0
- package/lib/assets/docs/run.md +3 -1
- package/lib/assets/docs/scenes.md +39 -0
- package/lib/assets/docs/setup.md +1 -1
- package/lib/assets/docs/tools.md +44 -0
- package/lib/assets/harbor/companion.mjs +9574 -8019
- package/lib/assets/templates/starter/scene.yaml +1 -1
- package/lib/assets/ui/app.js +84 -55
- package/lib/mcp-entry.mjs +127 -6
- package/lib/worker.mjs +37887 -35628
- package/lib/world-server.mjs +9508 -7953
- package/package.json +1 -1
package/lib/assets/docs/apps.md
CHANGED
|
@@ -10,7 +10,7 @@ agent:
|
|
|
10
10
|
url: "http://127.0.0.1:{{agent.port}}/api/slack/events" # where the app receives the tools' events (webhooks, push)
|
|
11
11
|
ready_url: "http://127.0.0.1:{{agent.port}}/api/health" # answers 2xx once the app is up
|
|
12
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
|
|
13
|
+
idle: 20s # how long the app may look quiet while it still works; skip_idle jumps the clock only after this much quiet
|
|
14
14
|
setup_calls: true # the app may call the world while it starts (subscriptions, lookups), before time starts
|
|
15
15
|
clock: node # Date in the app's Node processes follows the world's clock, for flows that wait days
|
|
16
16
|
env: # rendered per trial: {{slack.url}}, {{slack.token}}, {{gmail.url}}, {{gmail.token}} …
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Compare agent changes
|
|
2
2
|
|
|
3
|
+
Baseline saving checks that every reference trial finished with a valid harness and that the test fingerprints are verified. For invalid harness trials, run `ancha explain <runId> --json`, fix the setup it names and rerun the affected tests before saving. Rerun skipped or unfinished reference trials before saving as well. A valid agent failure can be saved as the reference for an improvement.
|
|
4
|
+
|
|
3
5
|
Run `ancha run --json`, then `ancha baseline save before` to freeze a completed reference. Inspect `ancha explain latest --json`, edit the agent and run `ancha run --compare before --json`. Use the same --out directory when you set one. Consult `ancha baseline --help --json` and `ancha run --help --json` for installed reference options.
|
|
4
6
|
|
|
5
7
|
`ancha baseline save <name> [--from <runId|latest>] [--force] [--out <runs-dir>]` defaults to the most recent run from this project, on this computer or in the workspace; `--from run_cloud_…` takes a cloud run's summary from the workspace. It copies the summary into `.ancha/baselines/<name>.json`, or a baselines directory next to a custom runs directory. Later changes to latest leave the snapshot intact. Saving an existing name requires --force. Names use 1–64 letters, digits, hyphens or underscores; latest and names beginning with run_ are reserved. `ancha run --compare <runId|baseline-name>` resolves its reference before starting agents or updating latest.
|
|
@@ -25,3 +25,6 @@ Fix the agent after reading the evidence, then prove the fix with `ancha run --c
|
|
|
25
25
|
It reports whether the agent acted differently and where: the first of its writes that differs from the attempt (`diverged`, with the recorded and the new call), then every check against the attempt's outcome (`was`). With the same agent, nothing diverges and no model is called. Once the agent acts differently, people answer live with `--people live` (your `OPENROUTER_API_KEY`, or the workspace's model credit after `ancha login`), or the replay stops there with `--people strict`, the default when there is no model. A replay stopped that way is invalid (exit 3, `invalidReason: "diverged"`): its checks say nothing about the agent. `ancha schema replay_finished` describes the JSON.
|
|
26
26
|
|
|
27
27
|
For wrapped functions, `ancha explain` shows the actual return value or exception type and message. Each function call counts once. It identifies an unconfirmed outcome when the function's completion report was absent at capture.
|
|
28
|
+
## Invalid setup before comparison
|
|
29
|
+
|
|
30
|
+
When a run has invalid harness attempts, `ancha explain <runId> --json` puts their setup reasons in `next`, followed by the rerun command. Fix those reasons and rerun the tests before saving a baseline. `harnessIssues` keeps the affected test, trial and diagnostic separate from agent failures.
|
package/lib/assets/docs/run.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
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 test, prints the tests, trials and parallelism, and starts nothing: no server, no agent, no trial.
|
|
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. It lists each model-graded check and whether it is required. Dry runs work without a judge key; grading in a real run uses `OPENROUTER_API_KEY` on this computer or the workspace's model key in a cloud run. With `--json`, `judge.checks`, `judge.keySet` and `judge.requirement` carry these details.
|
|
6
6
|
|
|
7
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
|
|
|
@@ -12,6 +12,8 @@ New run summaries use `verdictVersion: 3`. Each test (an entry of `scenes`) has
|
|
|
12
12
|
|
|
13
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
|
+
Map your agent's tool settings with `agent.env`: `{{<tool>.url}}`, `{{<tool>.host_url}}` and `{{<tool>.token}}` use that tool's connection. Jira also offers `{{jira.email}}` (the login email, also `{{jira.access_key}}`) and `{{jira.access_key_secret}}` (the API token). For example, `env: { JIRA_USERNAME: "{{jira.email}}", JIRA_INSTANCE_URL: "{{jira.url}}"` gives an agent its own names for Jira's email and URL; `JIRA_API_TOKEN` is supplied automatically. An unknown template produces `CONFIG_INVALID` with the available template names before a run or upload check starts the agent.
|
|
16
|
+
|
|
15
17
|
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
18
|
|
|
17
19
|
```yaml
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Create and validate tests
|
|
2
2
|
|
|
3
|
+
`ancha test list --json` lists project test files and saved setups. `ancha test show <file or id> --json` shows a file's world, task and checks, or a saved setup's agent and pinned scenarios; `kind` identifies `file` or `saved`. A file's declared id also works. `ancha test validate <files...> --json` validates tests and world files with the same rules as `ancha scene validate`. Read this topic with `ancha docs tests` or `ancha docs scenes`.
|
|
4
|
+
|
|
5
|
+
## Reuse a scene's world
|
|
6
|
+
|
|
7
|
+
For the default starter, `ancha init --on local` also writes `ancha/worlds/starter.yaml`, using the same tools and starting data. `ancha test import evals.jsonl --json` uses that world automatically. `ancha test new "Reply to the customer" --json` drafts a test for it with a model.
|
|
8
|
+
|
|
9
|
+
For a project with existing scenes, save a reusable world directly:
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
ancha world from scenes/starter/scene.yaml --json
|
|
13
|
+
ancha test import evals.jsonl --world starter --json
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`ancha world from <scene> [--id <id>]` writes `ancha/worlds/<id>.yaml` from the scene's native tools, seed, simulation start time, time scale, rules and people. It needs no model. The default id is the scene's id; choose another with `--id` when a world file already exists. The scene keeps its task, checks and deadline and continues to run as before.
|
|
17
|
+
|
|
3
18
|
## Tests with people (version 2)
|
|
4
19
|
|
|
5
20
|
A version 2 test names a world (`ancha/worlds/<id>.yaml`: the company, its people with what they know and decide, and the tools' history) and says what starts an attempt, when it ends, and the checks: on what people learned, decided and were told, and on the tools.
|
|
@@ -58,3 +73,27 @@ Validate with `ancha scene validate scenes/my-scene/scene.yaml --json`. Referenc
|
|
|
58
73
|
`ancha init --template incidents` copies the complete versioned incident pack when included in your distribution, with all listed companions/fixtures. Missing or unsafe pack assets fail before config creation. No runtime includes or fabricated incident fixtures are generated.
|
|
59
74
|
|
|
60
75
|
Never give oracle/null companions, private checks, seeds or control-plane state to the tested AI agent. Use a separate tested-agent working directory/context when the coding agent would otherwise index those fixtures.
|
|
76
|
+
|
|
77
|
+
## Jira and PayPal end-state checks
|
|
78
|
+
|
|
79
|
+
Grade the records the agent leaves in the world with `jira.issue`, `jira.comment`, `jira.transition`, `paypal.invoice`, `paypal.order` and `paypal.payment`. `ancha twins seed jira --json` and `ancha twins seed paypal --json` include examples.
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
checks:
|
|
83
|
+
- id: five_new_tickets
|
|
84
|
+
state: { jira.issue: { project: OPS, after_start: true, count_eq: 5 } }
|
|
85
|
+
- id: checkout_bug
|
|
86
|
+
state: { jira.issue: { project: OPS, type: Bug, summary_contains: checkout, description_contains: Acceptance criteria, after_start: true } }
|
|
87
|
+
- id: correct_order_total
|
|
88
|
+
state: { paypal.order: { currency: USD, total: "466.40", tax: "131.40", after_start: true, count_eq: 1 } }
|
|
89
|
+
- id: invoice_sent
|
|
90
|
+
state: { paypal.invoice: { recipient: buyer@example.test, total: "276.60", tax: "84.60", sent: true, after_start: true } }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
All supplied filters match the same record. Choose `count_eq` for an exact count, `count_gte` for a minimum, or `exists: false` for none; without these, one match is enough. `after_start: true` selects records created during the attempt. The default includes seeded history.
|
|
94
|
+
|
|
95
|
+
Jira issues accept `issue`, `project`, `type`, `summary_contains`, `description_contains`, `labels`, `assignee`, `status` and `parent` (an epic for standard issues). Use `assignee: null` for unassigned issues and `parent: null` for no parent. Comments accept `issue`, `author` and `text_contains`; transitions accept `issue`, `from`, `to` and `author`. Text containment accepts a string or an all-required list and ignores case. Issue refs (`$issue.ops_slow`) and user refs (`$user.rachel`) belong to `seed.jira`; native issue keys and account ids also work.
|
|
96
|
+
|
|
97
|
+
PayPal orders accept `id`, `status`, `intent`, `payer_email`, `description_contains`, `invoice_id`, `currency`, `total`, `tax` and `items`. Invoice checks accept `id`, `status`, `recipient`, `currency`, `total`, `tax`, `sent` and `items`. Items have an exact `name` and optional `quantity` and `unit_amount`; invoice items also accept `tax_percent` and computed line `tax`. Quote amounts and quantities as decimal strings. Each requested item matches a distinct item; extra items are allowed. Payment checks accept `id`, `order`, `status`, `payer_email`, `invoice_id`, `currency`, `amount` and `refunded`. Order `id` and payment `order` can name a seed order as `$order.ref`.
|
|
98
|
+
|
|
99
|
+
Invoice item tax is computed on quantity × unit amount after item discount, rounded to cents. For 1.5 units at $120.00, a 10% item discount and 50% tax, the item tax is $81.00. Invoice responses include each item's computed `tax.amount`, and captured checks compare it directly. `ancha explain --json` shows expected filters and actual records with their amounts and statuses.
|
package/lib/assets/docs/setup.md
CHANGED
|
@@ -67,7 +67,7 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
67
67
|
|
|
68
68
|
`ancha init --agent "node agent.mjs"`, with your own start command, writes:
|
|
69
69
|
- `ancha.yaml`: how to start the agent, how many trials, which tests;
|
|
70
|
-
- `scenes/starter/`: a starter test that checks the agent reaches each tool, with two reference companions (`oracle.mjs` passes, `null.mjs` makes no calls);
|
|
70
|
+
- `scenes/starter/`: a starter test that checks the agent reaches each tool, with a 60-second timeout for startup and model calls, and two reference companions (`oracle.mjs` passes, `null.mjs` makes no calls);
|
|
71
71
|
- for an agent that uses NetSuite, in a project with no tests and no `traces/` folder: `ancha/worlds/netsuite-pe-m.yaml`, the NetSuite books of a private-equity portfolio company, and 25 tests in `ancha/tests/`: 10 read tasks and 15 write workflows (their evals in `ancha/evals/`). `--data netsuite-pe:s` or `--data netsuite-pe:l` writes another size, `--data none` leaves them out;
|
|
72
72
|
- `.claude/skills/ancha/SKILL.md` and an Ancha section in `AGENTS.md`, for coding agents;
|
|
73
73
|
- `.ancha/` in `.gitignore`: run history, traces and fake tokens never belong in git.
|
package/lib/assets/docs/tools.md
CHANGED
|
@@ -74,3 +74,47 @@ To run an agent in a sealed container against these tools, with tasks and graded
|
|
|
74
74
|
Offline trace import generates a records adapter for tools answered with `tools.run` (`ancha docs traces`). Bind the actual store, then open it before constructing tools. TypeScript exports `readRecords`, `Records`, `mappingStore` and `openRecordsStore` from `@ancha-labs/tools/records`; Python exports `read_records`, `Records`, `mapping_store` and `open_records_store` from `ancha.records`.
|
|
75
75
|
|
|
76
76
|
`Records.types()` lists sorted type names; `all(type)`, `get(type, id)` and `require(type, id)` return independent copies of business records. `entries()` returns `{type,id,record}` envelopes for store bindings. IDs remain strings. Invalid JSONL and duplicate identities identify the source file and line. A binding loads, clears, snapshots and probes the same store the tools use. `ancha doctor` reports its verification as `records-adapter`.
|
|
77
|
+
|
|
78
|
+
## GitHub issue search
|
|
79
|
+
|
|
80
|
+
`GET /search/issues` serves Octokit's `search.issuesAndPullRequests`:
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
const page = await github.search.issuesAndPullRequests({
|
|
84
|
+
q: 'repo:acme/orders is:issue state:open created:<2026-11-01T00:00:00Z',
|
|
85
|
+
sort: 'created', order: 'asc', per_page: 100, page: 1,
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use `repo:`, `is:issue`, `is:pr`, `type:`, `state:`, `is:open`, `is:closed`, `label:`, `author:`, `assignee:`, `mentions:`, `no:label`, and `no:assignee`. Repeat `label:` to require every label; quote names containing spaces, such as `label:"needs review"`. Combine words with `in:title` or `in:body`. `created:`, `updated:` and `closed:` accept dates or timestamps with `<`, `<=`, `>`, `>=` and inclusive `start..end` ranges. `comments:` accepts counts, comparisons and ranges. Sort by `created`, `updated` or `comments`, with `order: 'asc'` or `'desc'`.
|
|
90
|
+
|
|
91
|
+
The response carries `total_count`, `incomplete_results: false` and `items`; pull request items include `pull_request`. Follow the `Link` header for further pages. `advanced_search: 'true'` is accepted. Public repositories are searchable; private repositories require the token's user to own the repository, belong to its organization, or be a collaborator. The starter bot has explicit collaborator access. Seed issue and pull request assignments with `assignees: [$github_ben]`.
|
|
92
|
+
|
|
93
|
+
## Slack assistant threads and streaming
|
|
94
|
+
|
|
95
|
+
`assistant.threads.setStatus`, `assistant.threads.setSuggestedPrompts` and `assistant.threads.setTitle` use a bot token with `assistant:write`. Supply `channel_id` and `thread_ts`. Status accepts `loading_messages`; prompts are an array of up to four `{title, message}` objects with an optional heading `title`. A reply clears the thread's status. Current values appear in the world's `assistant_threads` state.
|
|
96
|
+
|
|
97
|
+
`chat.postEphemeral` takes `channel`, `user`, `text` or `blocks`, and an optional `thread_ts`. Its `message_ts` identifies a message visible to the named recipient; ephemeral messages stay separate from conversation history and replies.
|
|
98
|
+
|
|
99
|
+
Use `chat.startStream`, `chat.appendStream` and `chat.stopStream` with a bot token and `chat:write`:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const stream = await slack.chat.startStream({
|
|
103
|
+
channel, thread_ts, recipient_user_id, recipient_team_id,
|
|
104
|
+
markdown_text: 'Export ',
|
|
105
|
+
});
|
|
106
|
+
await slack.chat.appendStream({ channel, ts: stream.ts!, markdown_text: 'complete' });
|
|
107
|
+
await slack.chat.stopStream({ channel, ts: stream.ts! });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Provide the recipient's user and team IDs when starting outside a DM. Each call updates the same message; `conversations.replies` reads its current text. Chunks accept `markdown_text`, `blocks`, `plan_update` and `task_update` objects. `stopStream` can append final text, chunks and blocks. Check the reply with the existing state check:
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
id: export_answered
|
|
114
|
+
state:
|
|
115
|
+
slack.message:
|
|
116
|
+
channel: $slack_support
|
|
117
|
+
from: $slack_bot
|
|
118
|
+
in_thread_of: $slack_question
|
|
119
|
+
text_contains: Export complete
|
|
120
|
+
```
|