@ancha-labs/cli 0.4.21 → 0.4.23

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,31 @@ 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`.
@@ -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.
@@ -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`.
@@ -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.
@@ -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
 
@@ -74,3 +113,47 @@ To run an agent in a sealed container against these tools, with tasks and graded
74
113
  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
114
 
76
115
  `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`.
116
+
117
+ ## GitHub issue search
118
+
119
+ `GET /search/issues` serves Octokit's `search.issuesAndPullRequests`:
120
+
121
+ ```ts
122
+ const page = await github.search.issuesAndPullRequests({
123
+ q: 'repo:acme/orders is:issue state:open created:<2026-11-01T00:00:00Z',
124
+ sort: 'created', order: 'asc', per_page: 100, page: 1,
125
+ });
126
+ ```
127
+
128
+ 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'`.
129
+
130
+ 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]`.
131
+
132
+ ## Slack assistant threads and streaming
133
+
134
+ `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.
135
+
136
+ `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.
137
+
138
+ Use `chat.startStream`, `chat.appendStream` and `chat.stopStream` with a bot token and `chat:write`:
139
+
140
+ ```ts
141
+ const stream = await slack.chat.startStream({
142
+ channel, thread_ts, recipient_user_id, recipient_team_id,
143
+ markdown_text: 'Export ',
144
+ });
145
+ await slack.chat.appendStream({ channel, ts: stream.ts!, markdown_text: 'complete' });
146
+ await slack.chat.stopStream({ channel, ts: stream.ts! });
147
+ ```
148
+
149
+ 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:
150
+
151
+ ```yaml
152
+ id: export_answered
153
+ state:
154
+ slack.message:
155
+ channel: $slack_support
156
+ from: $slack_bot
157
+ in_thread_of: $slack_question
158
+ text_contains: Export complete
159
+ ```