@ancha-labs/cli 0.4.53 → 0.4.54
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/lib/ancha.mjs +615 -697
- package/lib/assets/docs/cloud.md +4 -2
- package/lib/worker.mjs +19 -4
- package/package.json +1 -1
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -94,7 +94,7 @@ agent:
|
|
|
94
94
|
AGENT_TASK: '{"task": {{task_json}}}'
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
`{{task_json}}` encodes the task as a JSON string, including quotes and newlines. The CLI, `ancha agent upload --json` and the console’s
|
|
97
|
+
`{{task_json}}` encodes the task as a JSON string, including quotes and newlines. The CLI, `ancha agent upload --json` and the console’s upload result show the same explanation and mapping. Apply the mapping, then run `ancha agent upload` again.
|
|
98
98
|
|
|
99
99
|
## Run tests in the cloud
|
|
100
100
|
|
|
@@ -114,6 +114,8 @@ ancha run --on cloud
|
|
|
114
114
|
- `--agent`, `--seed`, `--strict`, `--allow-simulated`, `--min-pass-rate`, `--allow-unwrapped` and `--idempotency-key` mean what they mean on this computer. `--compare <baseline>` compares with a saved baseline: `ancha baseline save before --from <run id>`, fix the agent, then `--compare before`. A cloud run's keys come from the workspace, so `--pass-env` and `--inherit-env` belong to runs on this computer, and its results live in the workspace, so it takes no `--out` or `--upload`.
|
|
115
115
|
- With `--json` the run announces acceptance with `run_submitted` (`run_detached` with `--detach`), carrying `target: "cloud"` and adding `defaulted: true` when the saved login chose cloud. A followed run prints NDJSON events and ends with `run_finished`: `url` is the result, `summary` the verdict with the attempt and check counts, and `next` the commands to run next. The exit codes are `ancha run`'s: 0 when every check passes, 1 when a check failed, 3 when an attempt could not run or be graded, 4 for an endpoint coverage error with `--strict`, or a verdict using simulated tool answers with `--strict` or in CI, and 2 for a cancelled run.
|
|
116
116
|
|
|
117
|
+
In a cloud attempt, each provider base URL points at the attempt's model gateway; `ANCHA_MODEL_URLS` maps each provider host to its gateway URL, so compare hosts rather than whole URLs. With `OPENROUTER_API_KEY`, Ancha fills `ANTHROPIC_AUTH_TOKEN` and `OPENAI_API_KEY` when the agent routes those clients to OpenRouter and holds no key of its own.
|
|
118
|
+
|
|
117
119
|
## Follow a run from anywhere
|
|
118
120
|
|
|
119
121
|
A run keeps going when the command stops: Ctrl-C or a dropped connection ends only the following, and the command prints the `ancha wait` line to pick it up. `--detach` returns as soon as the run is accepted, with its id and link.
|
|
@@ -127,7 +129,7 @@ ancha runs show <run id> # the run and its attempts
|
|
|
127
129
|
|
|
128
130
|
## The first steps, done or not
|
|
129
131
|
|
|
130
|
-
`ancha status` prints the workspace's three steps
|
|
132
|
+
`ancha status` prints the workspace's three steps and the next command:
|
|
131
133
|
|
|
132
134
|
- **Agent uploaded**: `ancha agent upload` started this project's agent with a task, or a cloud run graded it.
|
|
133
135
|
- **Tests added**: the workspace holds a trace or a test made from one, or a cloud run ran this project's tests.
|
package/lib/worker.mjs
CHANGED
|
@@ -71497,7 +71497,14 @@ import { createServer, request } from "node:http";
|
|
|
71497
71497
|
import { request as secureRequest } from "node:https";
|
|
71498
71498
|
import { isIP } from "node:net";
|
|
71499
71499
|
import { brotliDecompressSync, gunzipSync, inflateSync } from "node:zlib";
|
|
71500
|
-
function modelFailure(status5) {
|
|
71500
|
+
function modelFailure(status5, message8) {
|
|
71501
|
+
if (status5 === 402 && /in-flight/i.test(message8 ?? "")) return {
|
|
71502
|
+
code: "MODEL_CREDITS_EXHAUSTED",
|
|
71503
|
+
kind: "fix",
|
|
71504
|
+
outcome: "The model key's credits do not cover the requests running at once",
|
|
71505
|
+
did: "says the model key's credits do not cover the requests running at once",
|
|
71506
|
+
fix: "Add credits in the model provider account, or run fewer attempts at once (ancha run --concurrency 1, or parallel: 1 in ancha.yaml)."
|
|
71507
|
+
};
|
|
71501
71508
|
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 };
|
|
71502
71509
|
}
|
|
71503
71510
|
function refusalMessage(body7, encoding) {
|
|
@@ -73613,8 +73620,10 @@ function likelyFix(logTail3, context3 = {}) {
|
|
|
73613
73620
|
const task2 = taskFix(logTail3.join("\n"), context3.command);
|
|
73614
73621
|
if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
|
|
73615
73622
|
if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
|
|
73616
|
-
return
|
|
73623
|
+
return context3.target === "cloud" ? "Claude Code had no key (its /login stays on your computer): through OpenRouter, set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env and run ancha secrets set OPENROUTER_API_KEY in the project (Claude Code gets it as ANTHROPIC_AUTH_TOKEN); with an Anthropic key, run ancha secrets set ANTHROPIC_API_KEY in the project" : 'Claude Code had no key (its /login stays on your computer): through OpenRouter, start agent.command with ANTHROPIC_AUTH_TOKEN="$OPENROUTER_API_KEY" and set ANTHROPIC_BASE_URL: https://openrouter.ai/api under agent.env; with an Anthropic key, set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml';
|
|
73617
73624
|
}
|
|
73625
|
+
const model = logTail3.map((line2) => MODEL_ID_REFUSED.map((pattern) => pattern.exec(line2)?.[1]).find(Boolean)).find(Boolean);
|
|
73626
|
+
if (model !== void 0) return `its model ${model} is not a model id the provider serves: use an id from the provider's model list (openrouter.ai/models for OpenRouter) where the agent sets its model: agent.env, agent.command or its code`;
|
|
73618
73627
|
const errors2 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
|
|
73619
73628
|
for (const lines of [errors2, logTail3]) {
|
|
73620
73629
|
const fix = lines.length === 0 ? void 0 : keyFix(lines, context3) ?? missingFix(lines.join("\n"), context3);
|
|
@@ -73622,7 +73631,7 @@ function likelyFix(logTail3, context3 = {}) {
|
|
|
73622
73631
|
}
|
|
73623
73632
|
return void 0;
|
|
73624
73633
|
}
|
|
73625
|
-
var TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2;
|
|
73634
|
+
var TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape2, MODEL_ID_REFUSED;
|
|
73626
73635
|
var init_agent_fix = __esm({
|
|
73627
73636
|
"backend/src/agent-fix.ts"() {
|
|
73628
73637
|
"use strict";
|
|
@@ -73634,6 +73643,7 @@ var init_agent_fix = __esm({
|
|
|
73634
73643
|
CREDENTIAL = /(?<![A-Za-z0-9_])([A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*_(?:KEY|TOKEN|SECRET|PASSWORD))(?![A-Za-z0-9_])/g;
|
|
73635
73644
|
MISSING = /missing|not set|unset|undefined|required|must be set|no .*(?:key|token)|KeyError|not found|empty|expected/i;
|
|
73636
73645
|
escape2 = (text26) => text26.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
73646
|
+
MODEL_ID_REFUSED = [/([\w.:/@-]+)['"`]? is not a valid model ID/i, /The model [`'"]?([\w.:/@-]+)[`'"]? does not exist/i, /not_found_error\W+(?:message\W+)?model: ([\w.:/@-]+)/i];
|
|
73637
73647
|
}
|
|
73638
73648
|
});
|
|
73639
73649
|
|
|
@@ -224049,6 +224059,11 @@ function containedEnvironment(input5) {
|
|
|
224049
224059
|
if (openRouter && !values3.OPENAI_API_KEY && (values3.OPENROUTER_API_KEY || !openAi)) values3.OPENAI_BASE_URL ??= openRouter + "/api/v1";
|
|
224050
224060
|
if (openAi) values3.OPENAI_BASE_URL ??= openAi + "/v1";
|
|
224051
224061
|
if (mapped.modelUrls["api.anthropic.com"]) values3.ANTHROPIC_BASE_URL ??= mapped.modelUrls["api.anthropic.com"];
|
|
224062
|
+
if (openRouter && values3.OPENROUTER_API_KEY) {
|
|
224063
|
+
const routed = (value5) => value5 === openRouter || value5?.startsWith(openRouter + "/") || value5?.startsWith(openRouter + "?") || value5?.startsWith(openRouter + "#");
|
|
224064
|
+
if (routed(values3.ANTHROPIC_BASE_URL) && !values3.ANTHROPIC_AUTH_TOKEN && !values3.ANTHROPIC_API_KEY) values3.ANTHROPIC_AUTH_TOKEN = values3.OPENROUTER_API_KEY;
|
|
224065
|
+
if (routed(values3.OPENAI_BASE_URL) && !values3.OPENAI_API_KEY) values3.OPENAI_API_KEY = values3.OPENROUTER_API_KEY;
|
|
224066
|
+
}
|
|
224052
224067
|
for (const [base6, api4] of [["OPENROUTER_BASE_URL", "OPENROUTER_API_BASE"], ["OPENAI_BASE_URL", "OPENAI_API_BASE"], ["ANTHROPIC_BASE_URL", "ANTHROPIC_API_BASE"]]) {
|
|
224053
224068
|
if (values3[base6]) values3[api4] ??= values3[base6];
|
|
224054
224069
|
}
|
|
@@ -225989,7 +226004,7 @@ async function recordAnswer(backend, envId, sessionId, output2, source, printed)
|
|
|
225989
226004
|
}
|
|
225990
226005
|
}
|
|
225991
226006
|
function modelKeyIssue(refusal, given2) {
|
|
225992
|
-
const failure5 = modelFailure(refusal.status);
|
|
226007
|
+
const failure5 = modelFailure(refusal.status, refusal.message);
|
|
225993
226008
|
return {
|
|
225994
226009
|
kind: "model",
|
|
225995
226010
|
owner: "harness",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.54",
|
|
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": {
|