@ancha-labs/cli 0.4.22 → 0.4.24

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.
@@ -2,6 +2,42 @@
2
2
 
3
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
4
 
5
+ ## Slack Bolt apps
6
+
7
+ `ancha init` detects Python `slack_bolt` and JavaScript `@slack/bolt` apps and writes their command and Slack transport. `ancha agent upload` installs the app and checks its connection. `ancha run --on cloud` starts it in a fresh machine for each attempt; `ancha run --on local` uses the same tests on this computer. The app runs until the trial ends, then Ancha stops it and grades the world.
8
+
9
+ For Socket Mode:
10
+
11
+ ```yaml
12
+ agent:
13
+ command: python app.py
14
+ slack_transport: socket
15
+ env:
16
+ SLACK_APP_TOKEN: "{{slack.app_token}}"
17
+ SLACK_BOT_TOKEN: "{{slack.token}}"
18
+ SLACK_API_URL: "{{slack.url}}"
19
+ ```
20
+
21
+ Point both the Bolt Web API client and its Socket Mode client's API URL at `SLACK_API_URL`; `ancha connect slack` prints SDK settings. The connection check passes when the app opens its WebSocket. Each test's Slack trigger arrives as a native Slack event, including its Socket Mode envelope and acknowledgement.
22
+
23
+ For the HTTP Events API:
24
+
25
+ ```yaml
26
+ agent:
27
+ command: node app.mjs
28
+ slack_transport: http
29
+ url: "http://127.0.0.1:{{agent.port}}/slack/events"
30
+ env:
31
+ PORT: "{{agent.port}}"
32
+ SLACK_SIGNING_SECRET: "{{slack.signing_secret}}"
33
+ SLACK_BOT_TOKEN: "{{slack.token}}"
34
+ SLACK_API_URL: "{{slack.url}}"
35
+ ```
36
+
37
+ The app reads `PORT` when it starts. An app with a fixed port uses that port in `agent.url`, for example `http://127.0.0.1:3000/slack/events`, with `parallel: 1` for local trials. The events URL answers Slack's signed URL verification challenge before the test starts. Keep Bolt's signature verification enabled and map the variable names your app reads under `agent.env`.
38
+
39
+ `ancha agent upload` reports the connection result and configuration to check when the app needs its app token, signing secret or port. Cloud apps use a loopback events URL and a launch command. `agent.start` remains available for existing app configurations with a health route.
40
+
5
41
  ## ancha.yaml
6
42
 
7
43
  ```yaml
@@ -127,6 +127,8 @@ A run on this computer stays in `.ancha/runs/`; `ancha run --on local --upload`
127
127
 
128
128
  ## Secrets
129
129
 
130
+ The Agent page shows **Code**, the project's Git repository, and **Model key**, the provider key names stored in the workspace or configured under `agent.env`. Key values stay private. With no model key, it shows `ancha secrets set OPENAI_API_KEY`.
131
+
130
132
  The agent's own keys, its model provider's for one, live in the workspace:
131
133
 
132
134
  ```sh
@@ -165,3 +167,44 @@ In a cloud run, the people in a world use the workspace's model credit. On this
165
167
  - `AUTH_INVALID` (exit 2): the server rejected or needs an API key. Run `ancha login` again, or set `ANCHA_API_KEY` to a key from https://app.ancha.io/account. The hosted control API answers 401 to any request without a valid key.
166
168
  - `CONFIG_INVALID` (exit 2) naming a workspace secret: the agent needs a key the workspace lacks. Run the `ancha secrets set` command in the hint.
167
169
  - `SERVER_UNREACHABLE` (exit 3): DNS, connection or timeout failure, or an address that isn't an Ancha server. Check `--server-url` or `ANCHA_SERVER_URL`; `ancha whoami` shows the saved server.
170
+
171
+ ## Run stored inputs again
172
+
173
+ ```sh
174
+ ancha runs again <run id>
175
+ ancha runs again <run id> --failed --attempts 5
176
+ ancha runs again <run id> --detach --json
177
+ ```
178
+
179
+ `runs again` starts a new cloud run from a finished run's stored project bundle, tests and options; name the run by its number (`42`) or its `run_cloud_…` ID. `--failed` selects tests with a failed, invalid or ungraded attempt. `--attempts` sets the number of attempts per selected test. The command follows the new run to its result; `--detach` returns its id and result link immediately. Use `--idempotency-key <key>` to retry the same submission safely.
180
+
181
+ In the console, **Run again** and **Rerun failed** start these same runs. **Run x5** on a test runs five attempts using the bundle from its latest cloud run for that agent. The new run's Details link back to its source. Each run uses the workspace's usual cloud hours and concurrency settings.
182
+
183
+ When the page asks for the project, run `ancha run --on cloud` from that project to upload its inputs and start a run.
184
+
185
+ ## Run numbers and Started by
186
+
187
+ Workspace runs have a stable number such as `#412`. The Runs list, run title and recent runs use the same number. Open `/runs/412` in your workspace, or read it from the CLI:
188
+
189
+ ```bash
190
+ ancha runs list
191
+ ancha runs show 412
192
+ ancha runs show '#412' --json
193
+ ```
194
+
195
+ The JSON keeps the full run id alongside `runNumber`. A retry with the same idempotency key and a repeated upload keep the run's number. Historical runs keep their short ids.
196
+
197
+ **Started by** shows the signed-in person's email for console submissions, or the API key owner's email with **CLI**. In GitHub Actions, the CLI records **GitHub Actions**, the repository and a link to the workflow run from `GITHUB_ACTIONS`, `GITHUB_REPOSITORY`, `GITHUB_RUN_ID` and `GITHUB_SERVER_URL`.
198
+
199
+ ## Edit a test in the console
200
+
201
+ On a test's page, **Edit** opens its YAML from the selected cloud run. **Save and run x5** validates the test and starts five attempts with that edit and the same agent bundle. The edit belongs to the new run. Its Details show **Edited in console** and a YAML download.
202
+
203
+ Bring the edited file into your project:
204
+
205
+ ```sh
206
+ ancha test pull <run-id> --json
207
+ ancha test pull <run-id> --test <name> --json
208
+ ```
209
+
210
+ The command writes the test to its original project path. If your local file changed since the bundle was uploaded, keep your changes or add `--force` to replace it. Run `ancha test validate <path> --json` to check the saved file with the project's world data. Console edits accept up to 64 KiB of UTF-8 YAML and keep the test's `id`.
@@ -98,3 +98,17 @@ ancha world down --env <envId>
98
98
  Check `ancha twins coverage <tool>` and `ancha connect <tool>`. Keep provider keys out of tests and saved configuration.
99
99
 
100
100
  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.
101
+
102
+ ## Run numbers and Started by
103
+
104
+ Workspace runs have a stable number such as `#412`. The Runs list, run title and recent runs use the same number. Open `/runs/412` in your workspace, or read it from the CLI:
105
+
106
+ ```bash
107
+ ancha runs list
108
+ ancha runs show 412
109
+ ancha runs show '#412' --json
110
+ ```
111
+
112
+ The JSON keeps the full run id alongside `runNumber`. A retry with the same idempotency key and a repeated upload keep the run's number. Historical runs keep their short ids.
113
+
114
+ **Started by** shows the signed-in person's email for console submissions, or the API key owner's email with **CLI**. In GitHub Actions, the CLI records **GitHub Actions**, the repository and a link to the workflow run from `GITHUB_ACTIONS`, `GITHUB_REPOSITORY`, `GITHUB_RUN_ID` and `GITHUB_SERVER_URL`.
@@ -94,6 +94,80 @@ All supplied filters match the same record. Choose `count_eq` for an exact count
94
94
 
95
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
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`.
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`; order items accept per-unit `tax`, and invoice items 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
98
 
99
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.
100
+
101
+ PayPal order responses retain each item's `tax` (Money), `description`, `url`, `image_url` and `upc` on create, GET and capture. Item tax uses the purchase unit's currency. When any item specifies `tax`, `amount.breakdown.tax_total` is required and equals the sum of item tax × quantity; PayPal returns `TAX_TOTAL_REQUIRED` or `TAX_TOTAL_MISMATCH` with status 422 when this rule is violated. Order state checks compare each item's per-unit tax as a decimal string, for example `items: [{ name: Review, quantity: "2", tax: "1.23" }]`.
102
+
103
+ ## Stripe state checks
104
+
105
+ Customer cards accept `fingerprint` to identify the same card across customer records. Customer `cash_balance` seeds set `available` amounts by currency and a `reconciliation_mode`. Optional `credit_notes` seed paid-invoice credits by `invoice`, `amount` and `created`; optional `disputes` seed card inquiries by `payment` and `created`, with `warning_needs_response`, `warning_under_review` or `warning_closed` status. Credit notes add customer balance transactions, and API changes appear in `/v1/events`.
106
+
107
+ Stripe worlds default to a live account (`livemode: true`) with a stored card for each seeded customer. Payments using that card share its payment method ID and fingerprint. Supply `customers[].card` to choose the brand, last four digits, expiration and decline behavior. Set `seed.stripe.livemode: false` for a test account with Stripe test tokens such as `pm_card_visa`.
108
+
109
+ ```yaml
110
+ checks:
111
+ - id: duplicate_refunded
112
+ state: { stripe.refunds: { charge: $summit_duplicate, count: 1, amount: 120000 } }
113
+ - id: deposit_preserved
114
+ state: { stripe.refunds: { payment_intent: $pinecrest_deposit, count: 0, amount: 0 } }
115
+ - id: customer_balance
116
+ state: { stripe.balance: { customer: $pinecrest, balance: 0 } }
117
+ - id: subscription_preserved
118
+ state: { stripe.unchanged: { objects: [{ type: subscription, id: $pinecrest_seats }] } }
119
+ ```
120
+
121
+ `stripe.refunds` selects exactly one `charge` or `payment_intent` and compares successful refunds against an exact `count`, summed `amount`, or both. Amounts are integer minor units: `120000` is $1,200.00 USD. Seeded history is included; `after_start: true` selects refunds created at or after the attempt's start time. A missing payment fails even when the expected count is zero.
122
+
123
+ `stripe.balance` compares the named customer's balance: negative for credit, positive for debt. `stripe.unchanged` compares every native field of each named object with its state after seeding. Objects must exist both at seeding and evaluation; deletion fails. This checks final state, so restoring all original field values passes. Types are `customer`, `payment_method`, `product`, `price`, `subscription`, `invoice`, `invoiceitem`, `payment_intent`, `charge` and `refund`.
124
+
125
+ Use a native Stripe ID or a tool-local `$ref` (also `$type.ref`). Payment and paid-invoice refs identify their charge or PaymentIntent; customer refs identify customers or their stored payment methods. Other refs identify their seeded object type; invoice items use native IDs. `ancha twins seed stripe --json` prints validated examples. `ancha explain --json` reports the expected and actual state for each check.
126
+
127
+ ## Zendesk ticket checks
128
+
129
+ Use `zendesk.ticket` to check one ticket by numeric `id` or exact `subject`. All supplied conditions apply to that ticket. A subject identifies exactly one ticket; use its `id` when subjects repeat.
130
+
131
+ ```yaml
132
+ checks:
133
+ - id: export_resolved
134
+ state:
135
+ zendesk.ticket:
136
+ subject: CSV export times out for large files
137
+ status: solved
138
+ tags: { has: [export_fixed], lacks: [legal_hold] }
139
+ assignee: mike@acme.example
140
+ priority: high
141
+ group: Support
142
+ public_comment: { contains: Try the export again }
143
+ - id: hold_preserved
144
+ state:
145
+ zendesk.ticket:
146
+ subject: Audit log export for Q2
147
+ status_not_in: [solved, closed]
148
+ - id: other_customer_kept
149
+ state:
150
+ zendesk.unchanged:
151
+ tickets: [{ subject: Invoice copy request }]
152
+ ```
153
+
154
+ Choose `status` for one value, `status_in` for any listed value, or `status_not_in` to exclude listed values. `tags.has` requires every listed tag; `tags.lacks` excludes every listed tag. `assignee` accepts an email, numeric user id or `null`; `group` accepts a name, numeric group id or `null`; `priority: null` checks an unset priority.
155
+
156
+ `public_comment: true` requires a public comment added during the attempt. `public_comment: { contains: "text" }` also requires that exact, case-sensitive text in the new comment. Seeded comments are starting history, including those at `start_time`.
157
+
158
+ `zendesk.unchanged` requires each named ticket to exist and keep its state throughout the attempt. It checks committed audits and deletion, so a change followed by a reversal still fails. Subjects identify the original tickets even if the agent renames them. Failed requests and updates that change no fields leave this check passing.
159
+
160
+ `ancha twins seed zendesk --json` includes both check examples. Organization seeds accept `externalId`; `brands` accepts `name`, `subdomain`, `default`, `active` and `created`, with exactly one active default brand. When `brands` is omitted, the world's account supplies its default brand. Organization search matches an exact name or external id; autocomplete returns up to ten name-prefix matches. Ticket search accepts `organization_id`, `requester_id`, `assignee_id` and `group_id`, and `order_by:updated_at` orders results by update time.
161
+
162
+ ## Edit a test in the console
163
+
164
+ On a test's page, **Edit** opens its YAML from the selected cloud run. **Save and run x5** validates the test and starts five attempts with that edit and the same agent bundle. The edit belongs to the new run. Its Details show **Edited in console** and a YAML download.
165
+
166
+ Bring the edited file into your project:
167
+
168
+ ```sh
169
+ ancha test pull <run-id> --json
170
+ ancha test pull <run-id> --test <name> --json
171
+ ```
172
+
173
+ The command writes the test to its original project path. If your local file changed since the bundle was uploaded, keep your changes or add `--force` to replace it. Run `ancha test validate <path> --json` to check the saved file with the project's world data. Console edits accept up to 64 KiB of UTF-8 YAML and keep the test's `id`.
@@ -1,4 +1,43 @@
1
- # Explore tools without a scenario
1
+ # Function tools
2
+
3
+ Run `ancha init` to find function tools in your Python or JavaScript project. It prints their names and a wiring step, and writes that step into the project's `AGENTS.md`.
4
+
5
+ Wrap the final collection you pass to the framework. Python functions, LangChain tools and OpenAI Agents SDK function tools use:
6
+
7
+ ```python
8
+ import ancha
9
+
10
+ tools = ancha.wrap_tools([write_email, schedule_meeting, check_calendar_availability])
11
+ # Pass tools to bind_tools, create_react_agent, or Agent(tools=tools).
12
+ # run is your task entrypoint and receives a dict containing task.
13
+ ancha.entry(run)
14
+ ```
15
+
16
+ JavaScript functions, LangChain tools and OpenAI Agents SDK tools use:
17
+
18
+ ```javascript
19
+ import { wrapTools, entry } from '@ancha-labs/tools';
20
+
21
+ const tools = wrapTools([write_email, schedule_meeting, check_calendar_availability]);
22
+ // Pass tools to your framework. run receives an object containing task.
23
+ await entry(run);
24
+ ```
25
+
26
+ For the AI SDK, keep the named object: `const tools = wrapTools({ write_email, schedule_meeting, check_calendar_availability });` and pass it to `generateText({ model, tools, ... })`. Python's `@ancha.tool` and JavaScript's `wrapTool(name, fn)` also register individual functions. Choose one wrapping point for each function.
27
+
28
+ `entry` finishes tool registration before handing the task to your agent. Ancha records registration separately from calls and their completed results. `ancha doctor --on local --json` verifies registration even when the diagnostic task leaves a function unused. Each attempt captures these facts in `state.json` under `tools.observation`.
29
+
30
+ Import your orchestration checks with `ancha test import evals.json --world mail --judge never`:
31
+
32
+ ```json
33
+ [{"question":"Reply to the email without booking a meeting","must_call":["write_email"],"must_not_call":["schedule_meeting"]}]
34
+ ```
35
+
36
+ Declared function names become `trace.called` and `trace.not_called` checks. Other bare names retain MCP interpretation; the import notes list the detected function names. The generated test's `function_tools` uses `unrecorded: run`, which executes your wrapped functions and records their outcomes. Configure their native clients with the attempt's Ancha connections before running. Edit the test's policies and recorded responses to replay imported production calls. A recorded `null` is a result; replay requires a recorded result or error for the selected call.
37
+
38
+ Required function checks verify wiring before grading. Complete the registration step named in an invalid attempt's diagnostic, then run the test again. Tool names detected during setup are candidates; the eval's explicit checks decide what must happen.
39
+
40
+ ## Explore tools without a scenario
2
41
 
3
42
  Run `ancha ui` in your project folder. Open **Tools**, choose **Create sandbox**, and select individual tools or an operations/revenue workspace preset. Every sandbox receives its own copy of the selected data. No scenario or pass/fail grade is required.
4
43