@ancha-labs/cli 0.4.50 → 0.4.51
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 +332 -296
- package/lib/assets/docs/run.md +1 -1
- package/lib/assets/docs/scenes.md +1 -1
- package/lib/assets/harbor/companion.mjs +12 -3
- package/lib/worker.mjs +32 -10
- package/lib/world-server.mjs +1 -0
- package/package.json +1 -1
package/lib/assets/docs/run.md
CHANGED
|
@@ -12,7 +12,7 @@ When `CI=true` or `CI=1` (case-insensitive), a verdict using simulated tool answ
|
|
|
12
12
|
|
|
13
13
|
New run summaries use `verdictVersion: 3`. Each test (an entry of `scenes`) has `counts.requested`, `completed`, `valid`, `passed`, `invalid` and `skipped`. The pass-rate denominator is the requested count, including invalid, skipped and unfinished trials. “Pass all k” requires all k requested trials to complete validly and pass. A test with no check evaluated is ungraded (`graded: false`); the run's verdict is `ungraded` when any test is ungraded and none failed. HTML and the console show invalid attempts separately. Older reports stay readable; comparison with an old baseline lacking these counts exits 2 and asks you to rerun the reference and save a fresh baseline.
|
|
14
14
|
|
|
15
|
-
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK` and `ANCHA_TASK_FILE` (a file holding the task), `ANCHA_ATTEMPT_ID`, `ANCHA_STATE_DIR` (keep memory there, so trials stay independent), `ANCHA_EVENTS_URL`, `ANCHA_EVENTS_TOKEN` and `ANCHA_DONE_URL` for agents that receive events or finish explicitly, and `ANCHA_AGENT_PORT` for HTTP agents. No SDK is installed and no paid AI call is made for you. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: "{{task}}" }` (`{{task_file}}` for the file's path, `{{task_json}}` for the task encoded as a JSON string); `ancha init` writes that line when it finds the name in the agent's code or usage text.
|
|
15
|
+
Each trial gets the tools' URLs and fake credentials (`ancha docs integrations`), `ANCHA_TASK` and `ANCHA_TASK_FILE` (a file holding the task), `ANCHA_ATTEMPT_ID`, `ANCHA_STATE_DIR` (keep memory there, so trials stay independent), `ANCHA_EVENTS_URL`, `ANCHA_EVENTS_TOKEN` and `ANCHA_DONE_URL` for agents that receive events or finish explicitly (each request with `Authorization: Bearer $ANCHA_TRIAL_TOKEN`), and `ANCHA_AGENT_PORT` for HTTP agents. No SDK is installed and no paid AI call is made for you. An agent that reads its task under another name gets it with `agent.env: { MY_TASK: "{{task}}" }` (`{{task_file}}` for the file's path, `{{task_json}}` for the task encoded as a JSON string); `ancha init` writes that line when it finds the name in the agent's code or usage text.
|
|
16
16
|
|
|
17
17
|
Map your agent's tool settings with `agent.env`: `{{<tool>.url}}`, `{{<tool>.host_url}}` and `{{<tool>.token}}` use that tool's connection. Jira also offers `{{jira.email}}` (the login email, also `{{jira.access_key}}`) and `{{jira.access_key_secret}}` (the API token). For example, `env: { JIRA_USERNAME: "{{jira.email}}", JIRA_INSTANCE_URL: "{{jira.url}}"` gives an agent its own names for Jira's email and URL; `JIRA_API_TOKEN` is supplied automatically. An unknown template produces `CONFIG_INVALID` with the available template names before a run or upload check starts the agent.
|
|
18
18
|
|
|
@@ -118,7 +118,7 @@ Include the check ID in `pass` to require it (by default, every check is require
|
|
|
118
118
|
|
|
119
119
|
## Checks on the final answer
|
|
120
120
|
|
|
121
|
-
An `answer` check reads the agent's final answer: what it posts to `ANCHA_DONE_URL` as `{"output": …}` (`entry()` in `@ancha-labs/tools` posts what the agent returns), else an HTTP agent's reply, else what it prints on stdout (its logs go to stderr); `agent.answer` in `ancha.yaml` picks one. Text and number checks read a JSON answer as `key: value` lines; `rows` checks read the original object or parse a JSON string. Ancha grades it with no model, on this computer and in the cloud, so it uses no model credit.
|
|
121
|
+
An `answer` check reads the agent's final answer: what it posts to `ANCHA_DONE_URL` as `{"output": …}` with `Authorization: Bearer $ANCHA_TRIAL_TOKEN` (`entry()` in `@ancha-labs/tools` posts what the agent returns), else an HTTP agent's reply, else what it prints on stdout (its logs go to stderr); `agent.answer` in `ancha.yaml` picks one. Text and number checks read a JSON answer as `key: value` lines; `rows` checks read the original object or parse a JSON string. Ancha grades it with no model, on this computer and in the cloud, so it uses no model credit.
|
|
122
122
|
|
|
123
123
|
```yaml
|
|
124
124
|
checks:
|
|
@@ -168263,6 +168263,7 @@ var TrialSessions = class {
|
|
|
168263
168263
|
});
|
|
168264
168264
|
}
|
|
168265
168265
|
authenticate(token5, allowFinished = false) {
|
|
168266
|
+
if (!token5) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability", { hint: "send Authorization: Bearer $ANCHA_TRIAL_TOKEN" });
|
|
168266
168267
|
const env = token5 ? this.#manager.list().find((env2) => this.#records.get(env2)?.session.token === token5) : void 0;
|
|
168267
168268
|
const record11 = env ? this.#records.get(env) : void 0;
|
|
168268
168269
|
if (!env || !record11 || record11.signal !== env.signal) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability");
|
|
@@ -187487,10 +187488,10 @@ async function startIsolationGateway(options4) {
|
|
|
187487
187488
|
roots.set(root3, upstream);
|
|
187488
187489
|
}
|
|
187489
187490
|
const sessionRoutes2 = /* @__PURE__ */ new Map();
|
|
187490
|
-
if (session2) for (const [field5, path6, method2] of [["eventsUrl", "/_ancha/events", "GET"], ["contextUrl", "/_ancha/context", "GET"], ["doneUrl", "/_ancha/done", "POST"]]) {
|
|
187491
|
+
if (session2) for (const [field5, path6, method2, name5] of [["eventsUrl", "/_ancha/events", "GET", "ANCHA_EVENTS_URL"], ["contextUrl", "/_ancha/context", "GET", "ANCHA_CONTEXT_URL"], ["doneUrl", "/_ancha/done", "POST", "ANCHA_DONE_URL"]]) {
|
|
187491
187492
|
const upstream = loopbackOrigin(session2[field5]);
|
|
187492
187493
|
if (upstream.pathname !== path6 || upstream.search || upstream.hash) throw new Error("Invalid trial session route");
|
|
187493
|
-
sessionRoutes2.set(path6, { method: method2, upstream });
|
|
187494
|
+
sessionRoutes2.set(path6, { name: name5, method: method2, upstream });
|
|
187494
187495
|
}
|
|
187495
187496
|
const socketGrants = /* @__PURE__ */ new Map();
|
|
187496
187497
|
const modelHosts = new Set((options4.modelHosts ?? []).map(normalizeModelHost));
|
|
@@ -187654,7 +187655,15 @@ async function startIsolationGateway(options4) {
|
|
|
187654
187655
|
}
|
|
187655
187656
|
if (!upstream) {
|
|
187656
187657
|
const route16 = sessionRoutes2.get(path6);
|
|
187657
|
-
if (!route16
|
|
187658
|
+
if (!route16) return reject2(res);
|
|
187659
|
+
const status4 = req.method !== route16.method ? 405 : req.headers.authorization !== `Bearer ${session2.token}` ? 401 : void 0;
|
|
187660
|
+
if (status4 !== void 0) {
|
|
187661
|
+
try {
|
|
187662
|
+
options4.onSessionRefused?.(route16.name, status4);
|
|
187663
|
+
} catch {
|
|
187664
|
+
}
|
|
187665
|
+
return reject2(res, status4, status4 === 405 ? `${route16.name} takes ${route16.method}.` : `${route16.name} takes Authorization: Bearer $ANCHA_TRIAL_TOKEN.`);
|
|
187666
|
+
}
|
|
187658
187667
|
upstream = route16.upstream;
|
|
187659
187668
|
if (path6 === "/_ancha/context") transform3 = "context";
|
|
187660
187669
|
}
|
package/lib/worker.mjs
CHANGED
|
@@ -71574,10 +71574,10 @@ async function startIsolationGateway(options5) {
|
|
|
71574
71574
|
roots.set(root3, upstream);
|
|
71575
71575
|
}
|
|
71576
71576
|
const sessionRoutes2 = /* @__PURE__ */ new Map();
|
|
71577
|
-
if (session2) for (const [field6, path8, method2] of [["eventsUrl", "/_ancha/events", "GET"], ["contextUrl", "/_ancha/context", "GET"], ["doneUrl", "/_ancha/done", "POST"]]) {
|
|
71577
|
+
if (session2) for (const [field6, path8, method2, name5] of [["eventsUrl", "/_ancha/events", "GET", "ANCHA_EVENTS_URL"], ["contextUrl", "/_ancha/context", "GET", "ANCHA_CONTEXT_URL"], ["doneUrl", "/_ancha/done", "POST", "ANCHA_DONE_URL"]]) {
|
|
71578
71578
|
const upstream = loopbackOrigin(session2[field6]);
|
|
71579
71579
|
if (upstream.pathname !== path8 || upstream.search || upstream.hash) throw new Error("Invalid trial session route");
|
|
71580
|
-
sessionRoutes2.set(path8, { method: method2, upstream });
|
|
71580
|
+
sessionRoutes2.set(path8, { name: name5, method: method2, upstream });
|
|
71581
71581
|
}
|
|
71582
71582
|
const socketGrants = /* @__PURE__ */ new Map();
|
|
71583
71583
|
const modelHosts = new Set((options5.modelHosts ?? []).map(normalizeModelHost));
|
|
@@ -71741,7 +71741,15 @@ async function startIsolationGateway(options5) {
|
|
|
71741
71741
|
}
|
|
71742
71742
|
if (!upstream) {
|
|
71743
71743
|
const route16 = sessionRoutes2.get(path8);
|
|
71744
|
-
if (!route16
|
|
71744
|
+
if (!route16) return reject2(res);
|
|
71745
|
+
const status5 = req.method !== route16.method ? 405 : req.headers.authorization !== `Bearer ${session2.token}` ? 401 : void 0;
|
|
71746
|
+
if (status5 !== void 0) {
|
|
71747
|
+
try {
|
|
71748
|
+
options5.onSessionRefused?.(route16.name, status5);
|
|
71749
|
+
} catch {
|
|
71750
|
+
}
|
|
71751
|
+
return reject2(res, status5, status5 === 405 ? `${route16.name} takes ${route16.method}.` : `${route16.name} takes Authorization: Bearer $ANCHA_TRIAL_TOKEN.`);
|
|
71752
|
+
}
|
|
71745
71753
|
upstream = route16.upstream;
|
|
71746
71754
|
if (path8 === "/_ancha/context") transform3 = "context";
|
|
71747
71755
|
}
|
|
@@ -220329,6 +220337,7 @@ var init_sessions5 = __esm({
|
|
|
220329
220337
|
});
|
|
220330
220338
|
}
|
|
220331
220339
|
authenticate(token5, allowFinished = false) {
|
|
220340
|
+
if (!token5) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability", { hint: "send Authorization: Bearer $ANCHA_TRIAL_TOKEN" });
|
|
220332
220341
|
const env = token5 ? this.#manager.list().find((env2) => this.#records.get(env2)?.session.token === token5) : void 0;
|
|
220333
220342
|
const record15 = env ? this.#records.get(env) : void 0;
|
|
220334
220343
|
if (!env || !record15 || record15.signal !== env.signal) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability");
|
|
@@ -223725,7 +223734,7 @@ function withoutScriptBanners(lines) {
|
|
|
223725
223734
|
function stdoutAnswer(stdout) {
|
|
223726
223735
|
return withoutScriptBanners(stdout.replace(ANSI, "").replace(/\r\n?/g, "\n").trimEnd().split("\n")).join("\n").trimEnd();
|
|
223727
223736
|
}
|
|
223728
|
-
var ANSWER_MAX_CHARS, STDOUT_MAX_CHARS, OutputTail, ModelReplies, ANSI, NPM_SCRIPT, NPM_COMMAND, YARN_RUN, YARN_COMMAND, YARN_DONE;
|
|
223737
|
+
var ANSWER_MAX_CHARS, STDOUT_MAX_CHARS, OutputTail, ModelReplies, SessionRefusals, ANSI, NPM_SCRIPT, NPM_COMMAND, YARN_RUN, YARN_COMMAND, YARN_DONE;
|
|
223729
223738
|
var init_agent_output = __esm({
|
|
223730
223739
|
"backend/src/runner/agent-output.ts"() {
|
|
223731
223740
|
"use strict";
|
|
@@ -223780,6 +223789,17 @@ var init_agent_output = __esm({
|
|
|
223780
223789
|
return this.#last !== void 0 && MODEL_REFUSALS.has(this.#last.status) ? { ...this.#last } : void 0;
|
|
223781
223790
|
}
|
|
223782
223791
|
};
|
|
223792
|
+
SessionRefusals = class {
|
|
223793
|
+
#counts = /* @__PURE__ */ new Map();
|
|
223794
|
+
add(name5, status5) {
|
|
223795
|
+
const key5 = `${name5} ${status5}`, refusal = this.#counts.get(key5);
|
|
223796
|
+
if (refusal) refusal.count++;
|
|
223797
|
+
else this.#counts.set(key5, { name: name5, status: status5, count: 1 });
|
|
223798
|
+
}
|
|
223799
|
+
list() {
|
|
223800
|
+
return [...this.#counts.values()].map((refusal) => ({ ...refusal }));
|
|
223801
|
+
}
|
|
223802
|
+
};
|
|
223783
223803
|
ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
223784
223804
|
NPM_SCRIPT = /^> (?:\S+@\S* )?[\w:.-]+(?: \/\S*)?$/;
|
|
223785
223805
|
NPM_COMMAND = /^> \S/;
|
|
@@ -224719,8 +224739,8 @@ async function startContainedAgent(command, opts) {
|
|
|
224719
224739
|
"exec sleep 86400"
|
|
224720
224740
|
]);
|
|
224721
224741
|
await run5(["start", relayName]);
|
|
224722
|
-
const replies = new ModelReplies();
|
|
224723
|
-
gateway2 = await startIsolationGateway({ env: opts.env, session: opts.session, modelHosts: policy.modelHosts, ...opts.onModelActivity && { onModelActivity: opts.onModelActivity }, onModelReply: (host, status6, message8) => replies.add(host, status6, message8) });
|
|
224742
|
+
const replies = new ModelReplies(), refusals = new SessionRefusals();
|
|
224743
|
+
gateway2 = await startIsolationGateway({ env: opts.env, session: opts.session, modelHosts: policy.modelHosts, ...opts.onModelActivity && { onModelActivity: opts.onModelActivity }, onModelReply: (host, status6, message8) => replies.add(host, status6, message8), onSessionRefused: (name5, status6) => refusals.add(name5, status6) });
|
|
224724
224744
|
const script2 = isolationRelayScript({ port: RELAY_PORT, ...opts.runtime?.port && { agentPort: opts.runtime.port } });
|
|
224725
224745
|
relayChild = spawn2("docker", ["--context", context3, "exec", "-i", relayName, "node", "-e", script2], { env: dockerEnvironment(), stdio: ["pipe", "pipe", "pipe"] });
|
|
224726
224746
|
relayChild.stderr.on("data", () => {
|
|
@@ -224812,7 +224832,7 @@ async function startContainedAgent(command, opts) {
|
|
|
224812
224832
|
return { pid: child3.pid, exited, async stop() {
|
|
224813
224833
|
await cleanup();
|
|
224814
224834
|
await exited;
|
|
224815
|
-
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
224835
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
224816
224836
|
} catch (error64) {
|
|
224817
224837
|
opts.signal?.removeEventListener("abort", abort);
|
|
224818
224838
|
await cleanup();
|
|
@@ -225031,7 +225051,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225031
225051
|
await chmod3(taskFile, 292);
|
|
225032
225052
|
await chmod3(directory, 457);
|
|
225033
225053
|
}
|
|
225034
|
-
const replies = new ModelReplies();
|
|
225054
|
+
const replies = new ModelReplies(), refusals = new SessionRefusals();
|
|
225035
225055
|
gateway2 = await (deps.gateway ?? startIsolationGateway)({
|
|
225036
225056
|
...composio && { composio },
|
|
225037
225057
|
env: opts.env,
|
|
@@ -225040,7 +225060,8 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225040
225060
|
port: unsafe ? 0 : 18991,
|
|
225041
225061
|
slackSocket: opts.agent.slackTransport === "socket",
|
|
225042
225062
|
...opts.onModelActivity && { onModelActivity: opts.onModelActivity },
|
|
225043
|
-
onModelReply: (host, status5, message8) => replies.add(host, status5, message8)
|
|
225063
|
+
onModelReply: (host, status5, message8) => replies.add(host, status5, message8),
|
|
225064
|
+
onSessionRefused: (name5, status5) => refusals.add(name5, status5)
|
|
225044
225065
|
});
|
|
225045
225066
|
const mapped = gateway2.rewrite(unsafe ? gateway2.url : VM_GATEWAY_ORIGIN);
|
|
225046
225067
|
const agentRuntime = { ...opts.runtime, ...taskFile !== void 0 && { taskFile }, ...opts.runtime?.attempt && { attempt: { ...opts.runtime.attempt, stateDir: paths3.state, records: records5 } } };
|
|
@@ -225168,7 +225189,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225168
225189
|
return { pid: child3.pid, exited, async stop() {
|
|
225169
225190
|
await cleanup();
|
|
225170
225191
|
await exited;
|
|
225171
|
-
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
225192
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
225172
225193
|
} catch (error64) {
|
|
225173
225194
|
await cleanup();
|
|
225174
225195
|
throw error64;
|
|
@@ -226070,6 +226091,7 @@ async function runTrialInner(spec) {
|
|
|
226070
226091
|
...playOut !== void 0 && playOut.toMs > playOut.fromMs && { playOut },
|
|
226071
226092
|
checks: checks2,
|
|
226072
226093
|
...output2?.modelReplies?.length && { modelReplies: output2.modelReplies },
|
|
226094
|
+
...output2?.sessionRefusals?.length && { sessionRefusals: output2.sessionRefusals },
|
|
226073
226095
|
logTail: exit === "idle" || exit === "done" || exit === "exited" && exitCode === 0 ? [] : await logTail(join21(dir, "agent.log")),
|
|
226074
226096
|
// An agent that exits non-zero or dies by a signal on its own fails its trial whatever the checks say, as a per_event
|
|
226075
226097
|
// invocation does: an agent that crashed before its first call would otherwise pass every not_called check.
|
package/lib/world-server.mjs
CHANGED
|
@@ -184486,6 +184486,7 @@ var TrialSessions = class {
|
|
|
184486
184486
|
});
|
|
184487
184487
|
}
|
|
184488
184488
|
authenticate(token5, allowFinished = false) {
|
|
184489
|
+
if (!token5) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability", { hint: "send Authorization: Bearer $ANCHA_TRIAL_TOKEN" });
|
|
184489
184490
|
const env = token5 ? this.#manager.list().find((env2) => this.#records.get(env2)?.session.token === token5) : void 0;
|
|
184490
184491
|
const record10 = env ? this.#records.get(env) : void 0;
|
|
184491
184492
|
if (!env || !record10 || record10.signal !== env.signal) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.51",
|
|
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": {
|