@ancha-labs/cli 0.4.46 → 0.4.48
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 +1 -1
- package/lib/ancha.mjs +662 -377
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/agents-section.md +1 -1
- package/lib/assets/docs/cloud.md +1 -1
- package/lib/assets/docs/setup.md +1 -1
- package/lib/assets/harbor/companion.mjs +23 -2
- package/lib/assets/ui/app.js +1 -1
- package/lib/mcp-entry.mjs +20 -0
- package/lib/worker.mjs +66 -14
- package/lib/world-server.mjs +23 -2
- package/package.json +1 -1
package/lib/assets/SKILL.md
CHANGED
|
@@ -18,7 +18,7 @@ Add `--json` to every command. Runs print NDJSON events that end with `run_finis
|
|
|
18
18
|
<!-- ancha:first-steps -->
|
|
19
19
|
1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.
|
|
20
20
|
```sh
|
|
21
|
-
|
|
21
|
+
npm install -g @ancha-labs/cli
|
|
22
22
|
ancha login
|
|
23
23
|
```
|
|
24
24
|
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.
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.
|
|
5
5
|
```sh
|
|
6
|
-
|
|
6
|
+
npm install -g @ancha-labs/cli
|
|
7
7
|
ancha login
|
|
8
8
|
```
|
|
9
9
|
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.
|
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -11,7 +11,7 @@ Without `--on`, a project with `ancha.yaml` (or `--config`) runs in the workspac
|
|
|
11
11
|
<!-- ancha:first-steps -->
|
|
12
12
|
1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.
|
|
13
13
|
```sh
|
|
14
|
-
|
|
14
|
+
npm install -g @ancha-labs/cli
|
|
15
15
|
ancha login
|
|
16
16
|
```
|
|
17
17
|
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.
|
package/lib/assets/docs/setup.md
CHANGED
|
@@ -9,7 +9,7 @@ Requirements: Node 24 or newer. Install once with `npm install -g @ancha-labs/cl
|
|
|
9
9
|
<!-- ancha:first-steps -->
|
|
10
10
|
1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.
|
|
11
11
|
```sh
|
|
12
|
-
|
|
12
|
+
npm install -g @ancha-labs/cli
|
|
13
13
|
ancha login
|
|
14
14
|
```
|
|
15
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.
|
|
@@ -76192,26 +76192,47 @@ function date4(params10) {
|
|
|
76192
76192
|
}
|
|
76193
76193
|
|
|
76194
76194
|
// packages/core/src/errors.ts
|
|
76195
|
+
var KIND_OF = {
|
|
76196
|
+
USAGE: "fix",
|
|
76197
|
+
CONFIG_INVALID: "fix",
|
|
76198
|
+
SCENE_INVALID: "fix",
|
|
76199
|
+
AUTH_INVALID: "fix",
|
|
76200
|
+
AGENT_SPAWN_FAILED: "fix",
|
|
76201
|
+
AGENT_UNREACHABLE: "fix",
|
|
76202
|
+
ENV_NOT_FOUND: "fix",
|
|
76203
|
+
SESSION_UNAUTHORIZED: "fix",
|
|
76204
|
+
CHECKS_FAILED: "fix",
|
|
76205
|
+
SERVER_UNREACHABLE: "retry",
|
|
76206
|
+
SERVER_START_FAILED: "retry",
|
|
76207
|
+
SESSION_CONFLICT: "retry",
|
|
76208
|
+
UNIMPLEMENTED_ENDPOINT: "ours",
|
|
76209
|
+
INTERNAL: "ours"
|
|
76210
|
+
};
|
|
76195
76211
|
var AnchaError = class extends Error {
|
|
76196
76212
|
code;
|
|
76213
|
+
kind;
|
|
76214
|
+
reference;
|
|
76197
76215
|
hint;
|
|
76198
76216
|
docs;
|
|
76199
76217
|
constructor(code2, message9, opts = {}) {
|
|
76200
76218
|
super(message9, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
76201
76219
|
this.name = "AnchaError";
|
|
76202
76220
|
this.code = code2;
|
|
76221
|
+
this.kind = opts.kind ?? KIND_OF[code2];
|
|
76222
|
+
if (opts.reference !== void 0) this.reference = opts.reference;
|
|
76203
76223
|
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
76204
76224
|
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
76205
76225
|
}
|
|
76206
76226
|
};
|
|
76207
76227
|
function toErrorJson(e) {
|
|
76208
76228
|
if (e instanceof AnchaError) {
|
|
76209
|
-
const out = { code: e.code, message: e.message };
|
|
76229
|
+
const out = { code: e.code, kind: e.kind, message: e.message };
|
|
76230
|
+
if (e.reference !== void 0) out.reference = e.reference;
|
|
76210
76231
|
if (e.hint !== void 0) out.hint = e.hint;
|
|
76211
76232
|
if (e.docs !== void 0) out.docs = e.docs;
|
|
76212
76233
|
return out;
|
|
76213
76234
|
}
|
|
76214
|
-
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
76235
|
+
return { code: "INTERNAL", kind: "ours", message: e instanceof Error ? e.message : String(e) };
|
|
76215
76236
|
}
|
|
76216
76237
|
|
|
76217
76238
|
// packages/core/src/agent-routes.ts
|
package/lib/assets/ui/app.js
CHANGED
|
@@ -22222,7 +22222,7 @@ function starterCount(tool, key, state) {
|
|
|
22222
22222
|
}
|
|
22223
22223
|
|
|
22224
22224
|
// frontend/src/generated/coding-agent-skill.ts
|
|
22225
|
-
var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, built from its production traces, and prove a fix with graded runs in the cloud. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company or rebuilt from a production trace, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself. `ancha run --on cloud` runs each attempt on a fresh machine of its own in Ancha's cloud.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; `ancha traces upload` prints the tests it made. `env list` and `sandbox list` return arrays; trace commands use the fields described in `ancha docs traces`. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, test files (`scene.yaml`) and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## First steps\n\n<!-- ancha:first-steps -->\n1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.\n ```sh\n ancha --version || npm install -g @ancha-labs/cli\n ancha login\n ```\n2. **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.\n ```sh\n ancha init\n ```\n - To name the command yourself: `ancha init --agent \"<the command that starts your agent>\"`.\n - To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.\n - **Composio agents.** Init detects Python `composio` / `composio_client` and TypeScript `@composio/core`, and finds tools from explicit toolkit lists and tool slugs. It writes each available Composio route under `agent.routes` and adds `COMPOSIO_API_KEY` to `agent.pass_env`, preserving existing settings. The world of each test decides which routed tools answer there.\n - When init asks which tools the agent reaches through Composio, ask the user which tools they use. Set `agent.routes.<tool>: composio` for each routed tool (for example, `agent.routes.quickbooks: composio`) and add `COMPOSIO_API_KEY` to `agent.pass_env` in `ancha.yaml`. Configure the Composio client to read `COMPOSIO_BASE_URL` from the attempt environment.\n - For a routed agent with no tests or traces, init writes a starter test that reads from each routed tool, plus the QuickBooks examples when the agent uses QuickBooks. Routed tests run in the cloud: with `COMPOSIO_API_KEY` in your shell, the steps below store it, upload the agent and run the tests.\n3. **Point the agent at Ancha's tools.** In a test, the agent calls Ancha instead of production:\n - Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.\n - Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.\n4. **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.\n ```sh\n ancha secrets set ANTHROPIC_API_KEY\n ```\n5. **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.\n ```sh\n ancha agent upload\n ```\n - The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.\n6. **Without production traces.** For an agent that calls NetSuite directly, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows. For an agent that uses QuickBooks, it writes Pellmont Building Services' 2025 books and two tests: `pellmont-duplicates` reports the duplicate vendors, the invoices and bills entered twice and the money at stake without changing the books, and `pellmont-approved-merge` merges the three duplicate vendor pairs as approved and changes nothing else.\n - Variants: once `pellmont-duplicates` passes, `ancha test vary ancha/tests/pellmont-duplicates.yaml` writes ten variants of it, each changing one thing in the books with the expected findings recalculated; run them with the command it prints.\n - Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.\n - Your evals: `ancha test import <file>` (JSONL, JSON, CSV or YAML with a question and an expected answer) writes tests for the only world in `ancha/worlds/`, or the one `--world <id>` names; with none, `ancha init --on local --template starter` adds one.\n - One test from a sentence: `ancha test new \"<sentence>\" --world <id>`.\n7. **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.\n ```sh\n ancha traces upload ./traces\n ```\n - From Langfuse or LangSmith, with your keys on this computer: `ancha traces upload --from langfuse --limit 50`, or `--from langsmith`.\n - 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>\"`.\n - Traces your agent already sent to your workspace: `ancha traces`, then `ancha pull <trace id>`.\n - A test lists what one trace cannot settle: answer with `ancha pull <test id> --answer <question>=<answer>`.\n - A check marked `(optional)` is graded and shown, and the required checks decide the test; `ancha pull <test id> --answer checks.success=\"<end state>\"` makes completing the request decide it too.\n8. **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.\n ```sh\n ancha run\n ```\n - 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.\n - `--attempts <n>` sets how many attempts each test gets, `--concurrency <n>` how many run at once.\n - `ancha wait <run id>` follows a run again from any terminal; `ancha explain <run id>` shows why a check failed.\n - `ancha status` shows which of these steps your workspace has done.\n9. **Fix the agent and keep the test.** Keep the failing run as the reference, fix the agent, and run again: exit 0 means every required check passes and nothing regressed.\n ```sh\n ancha baseline save before --from <run id>\n ancha run --compare before\n ```\n - Commit `scenes/from-traces/` so every run, in CI too, keeps it fixed.\n10. **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.\n ```sh\n ancha run --on local --attempts 1\n ```\n - Here the agent gets the keys in `agent.pass_env` from your shell, and model-graded checks need `OPENROUTER_API_KEY`.\n<!-- /ancha:first-steps -->\n\n## Cloud runs\n\n- `ancha run --on cloud` sends the project as one bundle: the agent's files, without hidden directories, dependencies or credential-like files, and its tests with their worlds and checks, which stay with the grader and never reach the agent. Each attempt's machine installs the dependencies, runs the agent and grades it with the same engine as a run on this computer. `--attempts <n>` sets the attempts per test, `--concurrency <n>` how many run at once.\n- The agent gets the workspace's secrets for the names in `agent.pass_env`, and its network reaches its tools and its model providers. Model-graded checks and the people in a world run on the workspace's model credit.\n- The `run_finished` event carries `url` (the result in the workspace) and `summary`, with `counts` of the attempts: requested, completed, invalid, skipped and cancelled. Interrupting the command stops the following, never the run: `ancha wait <run id>` follows it again, and `--detach` returns once the run is accepted.\n- `ancha explain <run id> --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n- When every attempt ended before the agent did anything (it exited within seconds without a call, or its command could not start), the run, `ancha wait` and `ancha explain` say that first: \"Your agent didn't run\", the end of its log once, and the likely fix read from it, such as the `agent.env` line that gives the agent its task under the name it reads. `agentNeverRan` in the JSON carries the same. Make that fix first: the failed checks follow from it, and `ancha explain <run id> --all` lists them.\n- `ancha status --json` shows the workspace's three steps (agent uploaded, tests added, tests run in the cloud) and the next command. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login. More: `ancha docs cloud`.\n\n## An app, not a command\n\nIf 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 attempt 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 attempt: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## More from production traces\n\n`ancha traces upload <file or folder> --json` sends the traces to the workspace, which rebuilds each one's world and checks, and writes each test to `scenes/from-traces/<name>/scene.yaml`: runs that went fine and runs that failed. `--from langfuse` or `--from langsmith` takes the newest traces there instead (`--limit`, `--since`), with the keys in this shell. For one trace of a failure, `--expect \"<what went wrong>\"` adds a check for it. A test lists the questions one trace cannot settle, each with the default it uses. Ask the user for the answers; don't guess them. Pass them with `ancha pull <test id> --answer <question>=<value>`. `ancha import --offline <trace file> --json` makes the tests on this computer instead, one per conversation, and uploads nothing; there, `--answer` and `--force` go on the import.\n\nA test from a run that failed should fail the same way production did. If it doesn't, run it on this computer: `ancha traces diff <trace file> latest` shows the calls production made and the attempt didn't, and the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `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` writes one, 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. More: `ancha docs traces`.\n\n## Other tests\n\nThe starter test `ancha init` writes when `scenes/` holds no tests only proves that the agent reaches each tool. For the agent's real job beyond its traces, `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 test can make on it. More: `ancha docs scenes`.\n\n## The rule\n\nFix the agent, not the tests or their checks. `ancha.yaml` says how to start the agent and give it its task and keys: change it for that, never to make a check pass. 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.\n\nNever give the agent under test the tests, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach attempt gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task, and `ANCHA_TASK_FILE` names a file holding it. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: \"{{task}}\" }` (`{{task_file}}` for the file); `ancha init` writes that line when it finds the name.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\nThe agent's own keys are the names in `agent.pass_env` in `ancha.yaml`, such as `agent.pass_env: [OPENAI_API_KEY]`, and `agent.env` sets fixed values, such as the path of a key file. In the cloud each name comes from the workspace's secrets (`ancha secrets set NAME`). `ancha run --on local` starts the agent on this computer instead, with this computer's network and those names from this shell (or `--pass-env NAME`); `--on docker` seals it in a container (`agent.execution: { mode: container, image: node:24-slim }`, which needs Docker). An agent without its model key stops at its first model call.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain <run id> --json`.\n- Exit 2: usage, config, test file or authentication error, or a cancelled cloud run. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`; `CONFIG_INVALID` naming a workspace secret means `ancha secrets set NAME`. Read the `hint`.\n- Exit 3: infrastructure, or an attempt the harness couldn't run or grade. It counts as invalid, never as a failed check, so it's not the agent's fault; run again, and `ancha agent upload --json` if it repeats.\n- Exit 4, only with `--strict`: an endpoint coverage error or a verdict using simulated tool answers. The summary names the tests, trials and evaluated checks using those answers. `ancha explain` lists endpoint errors; `ancha twins coverage <tool>` shows the endpoint inventory.\n\nRead the error's stable `code` and `message`, then follow its `hint` when provided. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.\n\nTell the user what you ran, where it ran, the pass rate, the evidence and the result link. Never claim a fix until `ancha run --compare` exits 0.\n";
|
|
22225
|
+
var codingAgentSkill = "---\nname: ancha\ndescription: Test, debug and fix an AI agent (a Slack bot, a support or on-call agent) against stateful replicas of the tools it uses, built from its production traces, and prove a fix with graded runs in the cloud. Use when asked to test an agent with Ancha, or in a repository that has ancha.yaml.\n---\n\n# Ancha\n\nAncha gives an AI agent the other side of its job: stateful replicas of the tools it uses (Slack, GitHub, Datadog, PagerDuty and more), seeded with one fictional company or rebuilt from a production trace, and checks that grade every attempt from the agent's calls and the world's end state. The verdict comes from the world, not from mocks you wrote yourself. `ancha run --on cloud` runs each attempt on a fresh machine of its own in Ancha's cloud.\n\n## Run the CLI\n\nBefore the CLI is installed, run every command as `npx -y @ancha-labs/cli <command>`. After `npm install -g @ancha-labs/cli` (Node 24 or newer), run `ancha <command>`. Never run `npx` with the bare name `ancha`: that npm name is not this package.\n\nAdd `--json` to every command. Runs print NDJSON events that end with `run_finished`; `ancha traces upload` prints the tests it made. `env list` and `sandbox list` return arrays; trace commands use the fields described in `ancha docs traces`. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, test files (`scene.yaml`) and these outputs. If your command can time out, give `ancha run` an `--idempotency-key <key>`: running it again with the same key returns the same run instead of starting another.\n\n## First steps\n\n<!-- ancha:first-steps -->\n1. **Install the CLI and sign in.** It needs Node 24 or newer. Approve this computer in the browser, once.\n ```sh\n npm install -g @ancha-labs/cli\n ancha login\n ```\n2. **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.\n ```sh\n ancha init\n ```\n - To name the command yourself: `ancha init --agent \"<the command that starts your agent>\"`.\n - To name its tools yourself (NetSuite, Slack, ...): `ancha init --tools netsuite,slack`.\n - **Composio agents.** Init detects Python `composio` / `composio_client` and TypeScript `@composio/core`, and finds tools from explicit toolkit lists and tool slugs. It writes each available Composio route under `agent.routes` and adds `COMPOSIO_API_KEY` to `agent.pass_env`, preserving existing settings. The world of each test decides which routed tools answer there.\n - When init asks which tools the agent reaches through Composio, ask the user which tools they use. Set `agent.routes.<tool>: composio` for each routed tool (for example, `agent.routes.quickbooks: composio`) and add `COMPOSIO_API_KEY` to `agent.pass_env` in `ancha.yaml`. Configure the Composio client to read `COMPOSIO_BASE_URL` from the attempt environment.\n - For a routed agent with no tests or traces, init writes a starter test that reads from each routed tool, plus the QuickBooks examples when the agent uses QuickBooks. Routed tests run in the cloud: with `COMPOSIO_API_KEY` in your shell, the steps below store it, upload the agent and run the tests.\n3. **Point the agent at Ancha's tools.** In a test, the agent calls Ancha instead of production:\n - Its clients for Slack, GitHub and the other tools Ancha replicates take the URLs and credentials Ancha supplies: `ancha connect <tool>` prints the settings.\n - Its own functions: wrap them with `wrapTools` from `@ancha-labs/tools` (`ancha.wrap_tools` in Python), or serve them over MCP.\n4. **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.\n ```sh\n ancha secrets set ANTHROPIC_API_KEY\n ```\n5. **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.\n ```sh\n ancha agent upload\n ```\n - The install follows the project's own manifests and lockfiles; `agent.install` in `ancha.yaml` sets the command instead.\n6. **Without production traces.** For an agent that calls NetSuite directly, `ancha init` writes a NetSuite world of a private-equity portfolio company (four subsidiaries, two currencies, thousands of transactions) and 25 tests: 10 read tasks and 15 write workflows. For an agent that uses QuickBooks, it writes Pellmont Building Services' 2025 books and two tests: `pellmont-duplicates` reports the duplicate vendors, the invoices and bills entered twice and the money at stake without changing the books, and `pellmont-approved-merge` merges the three duplicate vendor pairs as approved and changes nothing else.\n - Variants: once `pellmont-duplicates` passes, `ancha test vary ancha/tests/pellmont-duplicates.yaml` writes ten variants of it, each changing one thing in the books with the expected findings recalculated; run them with the command it prints.\n - Your data: `ancha world import netsuite <your exports> --id <id>` reads REST record JSON, SuiteQL results and saved search CSV into `ancha/worlds/<id>.yaml`; check it with `ancha world validate`. To write the seed yourself, `ancha twins seed netsuite` lists its fields.\n - Your evals: `ancha test import <file>` (JSONL, JSON, CSV or YAML with a question and an expected answer) writes tests for the only world in `ancha/worlds/`, or the one `--world <id>` names; with none, `ancha init --on local --template starter` adds one.\n - One test from a sentence: `ancha test new \"<sentence>\" --world <id>`.\n7. **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.\n ```sh\n ancha traces upload ./traces\n ```\n - From Langfuse or LangSmith, with your keys on this computer: `ancha traces upload --from langfuse --limit 50`, or `--from langsmith`.\n - 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>\"`.\n - Traces your agent already sent to your workspace: `ancha traces`, then `ancha pull <trace id>`.\n - A test lists what one trace cannot settle: answer with `ancha pull <test id> --answer <question>=<answer>`.\n - A check marked `(optional)` is graded and shown, and the required checks decide the test; `ancha pull <test id> --answer checks.success=\"<end state>\"` makes completing the request decide it too.\n8. **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.\n ```sh\n ancha run\n ```\n - 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.\n - `--attempts <n>` sets how many attempts each test gets, `--concurrency <n>` how many run at once.\n - `ancha wait <run id>` follows a run again from any terminal; `ancha explain <run id>` shows why a check failed.\n - `ancha status` shows which of these steps your workspace has done.\n9. **Fix the agent and keep the test.** Keep the failing run as the reference, fix the agent, and run again: exit 0 means every required check passes and nothing regressed.\n ```sh\n ancha baseline save before --from <run id>\n ancha run --compare before\n ```\n - Commit `scenes/from-traces/` so every run, in CI too, keeps it fixed.\n10. **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.\n ```sh\n ancha run --on local --attempts 1\n ```\n - Here the agent gets the keys in `agent.pass_env` from your shell, and model-graded checks need `OPENROUTER_API_KEY`.\n<!-- /ancha:first-steps -->\n\n## Cloud runs\n\n- `ancha run --on cloud` sends the project as one bundle: the agent's files, without hidden directories, dependencies or credential-like files, and its tests with their worlds and checks, which stay with the grader and never reach the agent. Each attempt's machine installs the dependencies, runs the agent and grades it with the same engine as a run on this computer. `--attempts <n>` sets the attempts per test, `--concurrency <n>` how many run at once.\n- The agent gets the workspace's secrets for the names in `agent.pass_env`, and its network reaches its tools and its model providers. Model-graded checks and the people in a world run on the workspace's model credit.\n- The `run_finished` event carries `url` (the result in the workspace) and `summary`, with `counts` of the attempts: requested, completed, invalid, skipped and cancelled. Interrupting the command stops the following, never the run: `ancha wait <run id>` follows it again, and `--detach` returns once the run is accepted.\n- `ancha explain <run id> --json` shows each failed check: what was expected, what happened, and the calls and world events behind it. Read it before guessing from the code; many bugs only show up with the world's data and timing.\n- When every attempt ended before the agent did anything (it exited within seconds without a call, or its command could not start), the run, `ancha wait` and `ancha explain` say that first: \"Your agent didn't run\", the end of its log once, and the likely fix read from it, such as the `agent.env` line that gives the agent its task under the name it reads. `agentNeverRan` in the JSON carries the same. Make that fix first: the failed checks follow from it, and `ancha explain <run id> --all` lists them.\n- `ancha status --json` shows the workspace's three steps (agent uploaded, tests added, tests run in the cloud) and the next command. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login. More: `ancha docs cloud`.\n\n## An app, not a command\n\nIf 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 attempt 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 attempt: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## More from production traces\n\n`ancha traces upload <file or folder> --json` sends the traces to the workspace, which rebuilds each one's world and checks, and writes each test to `scenes/from-traces/<name>/scene.yaml`: runs that went fine and runs that failed. `--from langfuse` or `--from langsmith` takes the newest traces there instead (`--limit`, `--since`), with the keys in this shell. For one trace of a failure, `--expect \"<what went wrong>\"` adds a check for it. A test lists the questions one trace cannot settle, each with the default it uses. Ask the user for the answers; don't guess them. Pass them with `ancha pull <test id> --answer <question>=<value>`. `ancha import --offline <trace file> --json` makes the tests on this computer instead, one per conversation, and uploads nothing; there, `--answer` and `--force` go on the import.\n\nA test from a run that failed should fail the same way production did. If it doesn't, run it on this computer: `ancha traces diff <trace file> latest` shows the calls production made and the attempt didn't, and the import also lists the app's own setup calls, which the start script or an `app_call` has to make.\n\nIf the user's workspace takes traces (their agents send them to it), each trace becomes a test there: `ancha pull --all --json` writes every test that is turned on (`--agent <name>` for one agent's), `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` writes one, 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. More: `ancha docs traces`.\n\n## Other tests\n\nThe starter test `ancha init` writes when `scenes/` holds no tests only proves that the agent reaches each tool. For the agent's real job beyond its traces, `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 test can make on it. More: `ancha docs scenes`.\n\n## The rule\n\nFix the agent, not the tests or their checks. `ancha.yaml` says how to start the agent and give it its task and keys: change it for that, never to make a check pass. 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.\n\nNever give the agent under test the tests, checks, seeds or reference companions (`oracle.mjs`, `null.mjs`), and never point it at a real SaaS API.\n\n## What the agent gets\n\nEach attempt gives the agent its tools as environment variables, with fake credentials that only work against the replicas:\n\n- Slack: `SLACK_API_URL` (ends in `/api/`), `SLACK_BOT_TOKEN`\n- GitHub: `GITHUB_API_URL`, `GITHUB_TOKEN`\n- Datadog: `DATADOG_API_URL`, `DD_API_KEY`, `DD_APP_KEY`\n- PagerDuty: `PAGERDUTY_API_URL`, `PAGERDUTY_API_TOKEN`, `PAGERDUTY_FROM_EMAIL`, `PAGERDUTY_ROUTING_KEY`\n- the same pattern for the other tools in the world; `ANCHA_TASK` carries a command-line task, and `ANCHA_TASK_FILE` names a file holding it. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: \"{{task}}\" }` (`{{task_file}}` for the file); `ancha init` writes that line when it finds the name.\n\n`ancha connect <tool> --lang ts|py` prints the SDK settings. `ancha twins coverage <tool>` lists the endpoints each replica implements.\n\nGoogle clients (`googleapis`, `@googleapis/*`) take the replica's URL in each call's options: `drive.files.list(params, { rootUrl: process.env.GOOGLE_DRIVE_API_URL + '/' })`. A `rootUrl` set on the client keeps only the host; Ancha still routes those calls by their token, but the client sends file uploads to www.googleapis.com.\n\nThe agent's own keys are the names in `agent.pass_env` in `ancha.yaml`, such as `agent.pass_env: [OPENAI_API_KEY]`, and `agent.env` sets fixed values, such as the path of a key file. In the cloud each name comes from the workspace's secrets (`ancha secrets set NAME`). `ancha run --on local` starts the agent on this computer instead, with this computer's network and those names from this shell (or `--pass-env NAME`); `--on docker` seals it in a container (`agent.execution: { mode: container, image: node:24-slim }`, which needs Docker). An agent without its model key stops at its first model call.\n\n## When something fails\n\n- Exit 1: a check failed or the comparison regressed (a single check's drop counts, see `comparison.droppedChecks`). Run `ancha explain <run id> --json`.\n- Exit 2: usage, config, test file or authentication error, or a cancelled cloud run. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`; `CONFIG_INVALID` naming a workspace secret means `ancha secrets set NAME`. Read the `hint`.\n- Exit 3: infrastructure, or an attempt the harness couldn't run or grade. It counts as invalid, never as a failed check, so it's not the agent's fault; run again, and `ancha agent upload --json` if it repeats.\n- Exit 4, only with `--strict`: an endpoint coverage error or a verdict using simulated tool answers. The summary names the tests, trials and evaluated checks using those answers. `ancha explain` lists endpoint errors; `ancha twins coverage <tool>` shows the endpoint inventory.\n\nRead the error's stable `code` and `message`, then follow its `hint` when provided. More: `ancha docs`, `ancha docs <topic>` for setup, run, traces, explain, compare, scenes, integrations, cloud and playgrounds, and https://docs.ancha.io/coding-agents.\n\nTell the user what you ran, where it ran, the pass rate, the evidence and the result link. Never claim a fix until `ancha run --compare` exits 0.\n";
|
|
22226
22226
|
|
|
22227
22227
|
// frontend/src/workspace-pages.ts
|
|
22228
22228
|
var startSentence = "Set up Ancha for this agent: read https://app.ancha.io/llms.txt and follow its first steps.";
|
package/lib/mcp-entry.mjs
CHANGED
|
@@ -57300,14 +57300,34 @@ var StdioServerTransport = class {
|
|
|
57300
57300
|
};
|
|
57301
57301
|
|
|
57302
57302
|
// packages/core/src/errors.ts
|
|
57303
|
+
var KIND_OF = {
|
|
57304
|
+
USAGE: "fix",
|
|
57305
|
+
CONFIG_INVALID: "fix",
|
|
57306
|
+
SCENE_INVALID: "fix",
|
|
57307
|
+
AUTH_INVALID: "fix",
|
|
57308
|
+
AGENT_SPAWN_FAILED: "fix",
|
|
57309
|
+
AGENT_UNREACHABLE: "fix",
|
|
57310
|
+
ENV_NOT_FOUND: "fix",
|
|
57311
|
+
SESSION_UNAUTHORIZED: "fix",
|
|
57312
|
+
CHECKS_FAILED: "fix",
|
|
57313
|
+
SERVER_UNREACHABLE: "retry",
|
|
57314
|
+
SERVER_START_FAILED: "retry",
|
|
57315
|
+
SESSION_CONFLICT: "retry",
|
|
57316
|
+
UNIMPLEMENTED_ENDPOINT: "ours",
|
|
57317
|
+
INTERNAL: "ours"
|
|
57318
|
+
};
|
|
57303
57319
|
var AnchaError = class extends Error {
|
|
57304
57320
|
code;
|
|
57321
|
+
kind;
|
|
57322
|
+
reference;
|
|
57305
57323
|
hint;
|
|
57306
57324
|
docs;
|
|
57307
57325
|
constructor(code2, message4, opts = {}) {
|
|
57308
57326
|
super(message4, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
57309
57327
|
this.name = "AnchaError";
|
|
57310
57328
|
this.code = code2;
|
|
57329
|
+
this.kind = opts.kind ?? KIND_OF[code2];
|
|
57330
|
+
if (opts.reference !== void 0) this.reference = opts.reference;
|
|
57311
57331
|
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
57312
57332
|
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
57313
57333
|
}
|
package/lib/worker.mjs
CHANGED
|
@@ -20459,6 +20459,9 @@ var init_zod = __esm({
|
|
|
20459
20459
|
function isErrorCode(value5) {
|
|
20460
20460
|
return typeof value5 === "string" && ERROR_CODES.includes(value5);
|
|
20461
20461
|
}
|
|
20462
|
+
function isErrorKind(value5) {
|
|
20463
|
+
return typeof value5 === "string" && ERROR_KINDS.includes(value5);
|
|
20464
|
+
}
|
|
20462
20465
|
function exitCodeFor(code2) {
|
|
20463
20466
|
switch (code2) {
|
|
20464
20467
|
case "CHECKS_FAILED":
|
|
@@ -20488,14 +20491,15 @@ function exitCodeFor(code2) {
|
|
|
20488
20491
|
}
|
|
20489
20492
|
function toErrorJson(e) {
|
|
20490
20493
|
if (e instanceof AnchaError) {
|
|
20491
|
-
const out = { code: e.code, message: e.message };
|
|
20494
|
+
const out = { code: e.code, kind: e.kind, message: e.message };
|
|
20495
|
+
if (e.reference !== void 0) out.reference = e.reference;
|
|
20492
20496
|
if (e.hint !== void 0) out.hint = e.hint;
|
|
20493
20497
|
if (e.docs !== void 0) out.docs = e.docs;
|
|
20494
20498
|
return out;
|
|
20495
20499
|
}
|
|
20496
|
-
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
20500
|
+
return { code: "INTERNAL", kind: "ours", message: e instanceof Error ? e.message : String(e) };
|
|
20497
20501
|
}
|
|
20498
|
-
var ERROR_CODES, AnchaError;
|
|
20502
|
+
var ERROR_CODES, ERROR_KINDS, KIND_OF, AnchaError;
|
|
20499
20503
|
var init_errors3 = __esm({
|
|
20500
20504
|
"packages/core/src/errors.ts"() {
|
|
20501
20505
|
"use strict";
|
|
@@ -20515,14 +20519,35 @@ var init_errors3 = __esm({
|
|
|
20515
20519
|
"UNIMPLEMENTED_ENDPOINT",
|
|
20516
20520
|
"INTERNAL"
|
|
20517
20521
|
];
|
|
20522
|
+
ERROR_KINDS = ["fix", "retry", "ours"];
|
|
20523
|
+
KIND_OF = {
|
|
20524
|
+
USAGE: "fix",
|
|
20525
|
+
CONFIG_INVALID: "fix",
|
|
20526
|
+
SCENE_INVALID: "fix",
|
|
20527
|
+
AUTH_INVALID: "fix",
|
|
20528
|
+
AGENT_SPAWN_FAILED: "fix",
|
|
20529
|
+
AGENT_UNREACHABLE: "fix",
|
|
20530
|
+
ENV_NOT_FOUND: "fix",
|
|
20531
|
+
SESSION_UNAUTHORIZED: "fix",
|
|
20532
|
+
CHECKS_FAILED: "fix",
|
|
20533
|
+
SERVER_UNREACHABLE: "retry",
|
|
20534
|
+
SERVER_START_FAILED: "retry",
|
|
20535
|
+
SESSION_CONFLICT: "retry",
|
|
20536
|
+
UNIMPLEMENTED_ENDPOINT: "ours",
|
|
20537
|
+
INTERNAL: "ours"
|
|
20538
|
+
};
|
|
20518
20539
|
AnchaError = class extends Error {
|
|
20519
20540
|
code;
|
|
20541
|
+
kind;
|
|
20542
|
+
reference;
|
|
20520
20543
|
hint;
|
|
20521
20544
|
docs;
|
|
20522
20545
|
constructor(code2, message8, opts = {}) {
|
|
20523
20546
|
super(message8, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
20524
20547
|
this.name = "AnchaError";
|
|
20525
20548
|
this.code = code2;
|
|
20549
|
+
this.kind = opts.kind ?? KIND_OF[code2];
|
|
20550
|
+
if (opts.reference !== void 0) this.reference = opts.reference;
|
|
20526
20551
|
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
20527
20552
|
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
20528
20553
|
}
|
|
@@ -71463,6 +71488,9 @@ import { createServer, request } from "node:http";
|
|
|
71463
71488
|
import { request as secureRequest } from "node:https";
|
|
71464
71489
|
import { isIP } from "node:net";
|
|
71465
71490
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
71491
|
+
function modelFailure(status5) {
|
|
71492
|
+
return status5 === 429 ? { code: "MODEL_RATE_LIMITED", kind: "retry", outcome: "The model provider rate-limited the key", did: "rate-limited the agent's model key", fix: "Wait a little, then run the same command again." } : status5 === 402 ? { code: "MODEL_CREDITS_EXHAUSTED", kind: "fix", outcome: "The model key is out of credits", did: "says the agent's model key is out of credits", fix: "Add credits in the model provider account, then run again." } : { code: "MODEL_KEY_REFUSED", kind: "fix", outcome: "The model key was refused", did: "refused the agent's model key", fix: void 0 };
|
|
71493
|
+
}
|
|
71466
71494
|
function refusalMessage(body7, encoding) {
|
|
71467
71495
|
let text26;
|
|
71468
71496
|
try {
|
|
@@ -72075,6 +72103,7 @@ var init_runtime = __esm({
|
|
|
72075
72103
|
concurrency: external_exports.number().int().positive(),
|
|
72076
72104
|
seed: text13.nullable(),
|
|
72077
72105
|
strict: external_exports.boolean(),
|
|
72106
|
+
simulatedAnswers: external_exports.enum(["allow", "fail"]).optional(),
|
|
72078
72107
|
minPassRate: external_exports.number().min(0).max(1),
|
|
72079
72108
|
allowUnwrapped: external_exports.array(text13),
|
|
72080
72109
|
agentCommand: text13.nullable(),
|
|
@@ -87521,8 +87550,8 @@ function buildWwwAuthenticateHeader(errorCode, description2, requiredScopes, res
|
|
|
87521
87550
|
function bearerAuthChallengeResponse(error64, options5) {
|
|
87522
87551
|
const { requiredScopes = [], resourceMetadataUrl } = options5 ?? {};
|
|
87523
87552
|
if (!(error64 instanceof OAuthError2)) {
|
|
87524
|
-
const
|
|
87525
|
-
return Response.json(
|
|
87553
|
+
const serverError2 = new OAuthError2(OAuthErrorCode.ServerError, "Internal Server Error");
|
|
87554
|
+
return Response.json(serverError2.toResponseObject(), { status: 500 });
|
|
87526
87555
|
}
|
|
87527
87556
|
switch (error64.code) {
|
|
87528
87557
|
case OAuthErrorCode.InvalidToken: {
|
|
@@ -225863,12 +225892,13 @@ async function recordAnswer(backend, envId, sessionId, output2, source, printed)
|
|
|
225863
225892
|
}
|
|
225864
225893
|
}
|
|
225865
225894
|
function modelKeyIssue(refusal, given2) {
|
|
225895
|
+
const failure5 = modelFailure(refusal.status);
|
|
225866
225896
|
return {
|
|
225867
225897
|
kind: "model",
|
|
225868
225898
|
owner: "harness",
|
|
225869
225899
|
service: refusal.host,
|
|
225870
|
-
code:
|
|
225871
|
-
message: `${refusal.host}
|
|
225900
|
+
code: failure5.code,
|
|
225901
|
+
message: `${refusal.host} ${failure5.did} (${refusal.status}${refusal.message ? `: ${refusal.message}` : ""}), so the attempt tested nothing. ${failure5.fix ?? `Give the agent a working ${modelKeyName(refusal.host, given2)} and run again.`}`
|
|
225872
225902
|
};
|
|
225873
225903
|
}
|
|
225874
225904
|
function recordStdout(backend, envId, sessionId, output2) {
|
|
@@ -226041,6 +226071,7 @@ var EXIT_COMMAND_NOT_FOUND2, unknownRoute18;
|
|
|
226041
226071
|
var init_trial = __esm({
|
|
226042
226072
|
"backend/src/runner/trial.ts"() {
|
|
226043
226073
|
"use strict";
|
|
226074
|
+
init_gateway();
|
|
226044
226075
|
init_routed_trial();
|
|
226045
226076
|
init_slack_app();
|
|
226046
226077
|
init_src();
|
|
@@ -226615,6 +226646,25 @@ init_backend();
|
|
|
226615
226646
|
init_src();
|
|
226616
226647
|
init_credentials2();
|
|
226617
226648
|
|
|
226649
|
+
// packages/cli/src/server-error.ts
|
|
226650
|
+
init_src();
|
|
226651
|
+
function serverError(status5, body7, fallback) {
|
|
226652
|
+
const value5 = body7 && typeof body7 === "object" ? body7.error : void 0;
|
|
226653
|
+
const error64 = value5 && typeof value5 === "object" ? value5 : {};
|
|
226654
|
+
const unauthorized = status5 === 401 && error64.code !== "AUTH_INVALID";
|
|
226655
|
+
const code2 = status5 === 401 ? "AUTH_INVALID" : isErrorCode(error64.code) ? error64.code : status5 === 403 ? "AUTH_INVALID" : status5 === 500 ? "INTERNAL" : status5 >= 502 && status5 <= 504 ? "SERVER_UNREACHABLE" : fallback.code ?? (status5 === 409 ? "SESSION_CONFLICT" : status5 === 422 ? "CONFIG_INVALID" : "USAGE");
|
|
226656
|
+
const opts = {};
|
|
226657
|
+
const hint = typeof error64.hint === "string" && !unauthorized ? error64.hint : fallback.hint ?? (typeof error64.hint === "string" ? error64.hint : void 0);
|
|
226658
|
+
if (hint !== void 0) opts.hint = hint;
|
|
226659
|
+
if (isErrorKind(error64.kind) && !unauthorized) opts.kind = error64.kind;
|
|
226660
|
+
else if (status5 === 429 || status5 >= 502 && status5 <= 504) opts.kind = "retry";
|
|
226661
|
+
else if (status5 === 500) opts.kind = "ours";
|
|
226662
|
+
if (typeof error64.reference === "string") opts.reference = error64.reference;
|
|
226663
|
+
const said = unauthorized ? void 0 : typeof error64.message === "string" ? error64.message : typeof value5 === "string" ? value5 : void 0;
|
|
226664
|
+
const result = new AnchaError(code2, said ?? fallback.message, opts);
|
|
226665
|
+
return typeof error64.step === "string" ? Object.assign(result, { step: error64.step }) : result;
|
|
226666
|
+
}
|
|
226667
|
+
|
|
226618
226668
|
// packages/cli/src/run-upload.ts
|
|
226619
226669
|
init_run_metadata();
|
|
226620
226670
|
init_src();
|
|
@@ -226669,13 +226719,11 @@ async function uploadRun(ctx, workspace3, run5) {
|
|
|
226669
226719
|
} catch (error64) {
|
|
226670
226720
|
throw new AnchaError("SERVER_UNREACHABLE", `${workspace3} did not answer the upload`, { hint: `check the network, then ancha runs upload ${run5.runId}`, cause: error64 });
|
|
226671
226721
|
}
|
|
226672
|
-
if (response6.status === 401) throw authError3(workspace3, { status: 401, keySent: key5 !== void 0 });
|
|
226673
226722
|
if (!response6.ok) {
|
|
226674
226723
|
const body7 = await response6.json().catch(() => void 0);
|
|
226675
|
-
|
|
226724
|
+
if (response6.status === 401) throw serverError(response6.status, body7, authError3(workspace3, { status: 401, keySent: key5 !== void 0 }));
|
|
226676
226725
|
if (response6.status === 404) throw new AnchaError("USAGE", `${workspace3} doesn't take run uploads`, { hint: "upload to your hosted workspace: ancha login, or set ANCHA_SERVER_URL and ANCHA_API_KEY" });
|
|
226677
|
-
|
|
226678
|
-
throw new AnchaError(code2, error64.message ?? `the upload was refused (HTTP ${response6.status})`, { hint: error64.hint ?? `ancha runs upload ${run5.runId}` });
|
|
226726
|
+
throw serverError(response6.status, body7, { message: `the upload was refused (HTTP ${response6.status})`, hint: `ancha runs upload ${run5.runId}` });
|
|
226679
226727
|
}
|
|
226680
226728
|
const answer = await response6.json().catch(() => void 0);
|
|
226681
226729
|
return { ...runNumberOf(answer?.runNumber) && { runNumber: runNumberOf(answer?.runNumber) }, url: httpUrl4(answer?.url) ?? `${new URL(workspace3).origin}/runs/${encodeURIComponent(run5.runId)}`, bytes: archive.length, files: manifest.files.length, ...answer?.replaced === true && { replaced: true } };
|
|
@@ -226757,6 +226805,10 @@ init_report();
|
|
|
226757
226805
|
|
|
226758
226806
|
// packages/cli/src/output.ts
|
|
226759
226807
|
init_src();
|
|
226808
|
+
function errorAction(error64) {
|
|
226809
|
+
const hint = error64.hint ?? (error64.kind === "retry" ? "nothing to change; run the same command again" : error64.kind === "ours" ? "this failed on Ancha's side, not in your setup" : "check the command and configuration, then run it again");
|
|
226810
|
+
return `${error64.kind}: ${hint.replaceAll("\n", "\n ")}${error64.reference ? ` (reference ${error64.reference})` : ""}`;
|
|
226811
|
+
}
|
|
226760
226812
|
function terse(value5) {
|
|
226761
226813
|
if (typeof value5 === "string") return /^[^\s"]+$/.test(value5) ? value5 : JSON.stringify(value5);
|
|
226762
226814
|
return JSON.stringify(value5) ?? "undefined";
|
|
@@ -226853,7 +226905,7 @@ var Output = class {
|
|
|
226853
226905
|
`);
|
|
226854
226906
|
} else {
|
|
226855
226907
|
const lines = [`error[${err2.code}]: ${err2.message.replaceAll("\n", "\n ")}`];
|
|
226856
|
-
|
|
226908
|
+
lines.push(errorAction(e instanceof AnchaError ? err2 : { ...err2, hint: "a bug in the Ancha CLI, not in your setup" }));
|
|
226857
226909
|
if (err2.docs !== void 0) lines.push(`docs: ${err2.docs}`);
|
|
226858
226910
|
this.#io.stderr.write(`${lines.join("\n")}
|
|
226859
226911
|
`);
|
|
@@ -227172,7 +227224,7 @@ hint: ${json37.hint}` : ""}`);
|
|
|
227172
227224
|
}
|
|
227173
227225
|
function keptUpload(upload6, runId) {
|
|
227174
227226
|
if (!("error" in upload6)) return upload6;
|
|
227175
|
-
return { error: { code: upload6.error.code, message: `the run finished, but its upload failed (${upload6.error.code})`, hint: `ancha runs upload ${runId} tries again and says why` }, ...upload6.required && { required: true } };
|
|
227227
|
+
return { error: { kind: upload6.error.kind, ...upload6.error.reference && { reference: upload6.error.reference }, code: upload6.error.code, message: `the run finished, but its upload failed (${upload6.error.code})`, hint: `ancha runs upload ${runId} tries again and says why` }, ...upload6.required && { required: true } };
|
|
227176
227228
|
}
|
|
227177
227229
|
async function executePreparedRun(ctx, input5, initial, ready3) {
|
|
227178
227230
|
const writer = stateWriter(input5.outDir, initial);
|
|
@@ -227232,7 +227284,7 @@ async function executePreparedRun(ctx, input5, initial, ready3) {
|
|
|
227232
227284
|
await writer.finish({
|
|
227233
227285
|
state: interrupted2 ? "interrupted" : "failed",
|
|
227234
227286
|
exitCode: exitCodeFor(code2),
|
|
227235
|
-
error: { code: code2, message: interrupted2 ? "run interrupted" : `run failed (${code2}); partial artifacts may be available` }
|
|
227287
|
+
error: { kind: toErrorJson(error64).kind, code: code2, message: interrupted2 ? "run interrupted" : `run failed (${code2}); partial artifacts may be available` }
|
|
227236
227288
|
});
|
|
227237
227289
|
throw error64;
|
|
227238
227290
|
}
|
package/lib/world-server.mjs
CHANGED
|
@@ -91877,26 +91877,47 @@ function createMcpHandler(factory, options4 = {}) {
|
|
|
91877
91877
|
}
|
|
91878
91878
|
|
|
91879
91879
|
// packages/core/src/errors.ts
|
|
91880
|
+
var KIND_OF = {
|
|
91881
|
+
USAGE: "fix",
|
|
91882
|
+
CONFIG_INVALID: "fix",
|
|
91883
|
+
SCENE_INVALID: "fix",
|
|
91884
|
+
AUTH_INVALID: "fix",
|
|
91885
|
+
AGENT_SPAWN_FAILED: "fix",
|
|
91886
|
+
AGENT_UNREACHABLE: "fix",
|
|
91887
|
+
ENV_NOT_FOUND: "fix",
|
|
91888
|
+
SESSION_UNAUTHORIZED: "fix",
|
|
91889
|
+
CHECKS_FAILED: "fix",
|
|
91890
|
+
SERVER_UNREACHABLE: "retry",
|
|
91891
|
+
SERVER_START_FAILED: "retry",
|
|
91892
|
+
SESSION_CONFLICT: "retry",
|
|
91893
|
+
UNIMPLEMENTED_ENDPOINT: "ours",
|
|
91894
|
+
INTERNAL: "ours"
|
|
91895
|
+
};
|
|
91880
91896
|
var AnchaError = class extends Error {
|
|
91881
91897
|
code;
|
|
91898
|
+
kind;
|
|
91899
|
+
reference;
|
|
91882
91900
|
hint;
|
|
91883
91901
|
docs;
|
|
91884
91902
|
constructor(code2, message8, opts = {}) {
|
|
91885
91903
|
super(message8, opts.cause === void 0 ? void 0 : { cause: opts.cause });
|
|
91886
91904
|
this.name = "AnchaError";
|
|
91887
91905
|
this.code = code2;
|
|
91906
|
+
this.kind = opts.kind ?? KIND_OF[code2];
|
|
91907
|
+
if (opts.reference !== void 0) this.reference = opts.reference;
|
|
91888
91908
|
if (opts.hint !== void 0) this.hint = opts.hint;
|
|
91889
91909
|
if (opts.docs !== void 0) this.docs = opts.docs;
|
|
91890
91910
|
}
|
|
91891
91911
|
};
|
|
91892
91912
|
function toErrorJson(e) {
|
|
91893
91913
|
if (e instanceof AnchaError) {
|
|
91894
|
-
const out = { code: e.code, message: e.message };
|
|
91914
|
+
const out = { code: e.code, kind: e.kind, message: e.message };
|
|
91915
|
+
if (e.reference !== void 0) out.reference = e.reference;
|
|
91895
91916
|
if (e.hint !== void 0) out.hint = e.hint;
|
|
91896
91917
|
if (e.docs !== void 0) out.docs = e.docs;
|
|
91897
91918
|
return out;
|
|
91898
91919
|
}
|
|
91899
|
-
return { code: "INTERNAL", message: e instanceof Error ? e.message : String(e) };
|
|
91920
|
+
return { code: "INTERNAL", kind: "ours", message: e instanceof Error ? e.message : String(e) };
|
|
91900
91921
|
}
|
|
91901
91922
|
|
|
91902
91923
|
// packages/core/src/agent-routes.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.48",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, each attempt on a fresh cloud machine in your app.ancha.io workspace, or on your computer.",
|
|
6
6
|
"bugs": {
|