@ancha-labs/cli 0.4.50 → 0.4.52
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 +373 -306
- package/lib/assets/docs/cloud.md +1 -1
- package/lib/assets/docs/run.md +1 -1
- package/lib/assets/docs/scenes.md +1 -1
- package/lib/assets/harbor/companion.mjs +24 -6
- package/lib/worker.mjs +47 -14
- package/lib/world-server.mjs +1 -0
- package/package.json +1 -1
package/lib/assets/docs/cloud.md
CHANGED
|
@@ -181,7 +181,7 @@ ancha run --on cloud
|
|
|
181
181
|
- Declare either route or both. Each test's world decides which routed tools it answers. QuickBooks-only and NetSuite-only tests can use the same agent configuration. A call to a declared tool that the world lacks returns `403 COMPOSIO_ROUTE_REFUSED` with reason `NO_WORLD` and a fix to add the tool to the world or run the call in a test whose world has it. The agent gets that answer and the attempt is graded as usual, as it is when a SuiteQL call's arguments are invalid. A call to a QuickBooks or NetSuite tool whose toolkit is not under `agent.routes` returns reason `NOT_ROUTED` with the line to add, such as `quickbooks: composio`; the attempt is invalid until the route is declared.
|
|
182
182
|
- The agent keeps its Composio code. Each attempt sets `COMPOSIO_BASE_URL` to Composio's API through the attempt's gateway (the Composio SDKs read it; a client built with an explicit base URL takes this value) and `COMPOSIO_API_KEY` to a key for this attempt; the gateway sends the project's key to Composio for QuickBooks calls. `QUICKBOOKS_PUBLIC_URL` is this world's QuickBooks at an address Composio reaches for this attempt only; `QUICKBOOKS_ACCESS_TOKEN` and `QUICKBOOKS_REALM_ID` are the world's, as in any test with QuickBooks.
|
|
183
183
|
- QuickBooks direct executions (`tools.execute`) reach the world whatever user ID or connected account the agent names: the gateway supplies the world's address and credentials on each call. An agent that already passes `custom_auth_params` keeps them: `base_url` is `QUICKBOOKS_PUBLIC_URL` with the world's `Authorization` and `x-quickbooks-realm-id` headers.
|
|
184
|
-
- When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
184
|
+
- When the world has routed QuickBooks, Tool Router sessions reach the world through a QuickBooks connection the attempt creates in the project for its own user (`ancha-…`). Sessions are pinned to it, and the session's MCP URL points at the gateway, so an MCP client in the agent's process reaches the same session. MCP clients such as Claude Code connect as they do to Composio: their tool calls reach the world, and every other request goes to Composio as sent. When the attempt ends it deletes the sessions, the connection and its auth config.
|
|
185
185
|
- NetSuite calls use `NETSUITE_RUN_SUITEQL_QUERY`, its SuiteQL query in `q` and optional paging arguments, through `session.execute` or `tools.execute`. The gateway supplies the world's NetSuite credentials and returns the SuiteQL REST body in the Composio response. When QuickBooks is inactive in the test, sessions are created, read and deleted in the gateway; when both routes are active, the gateway handles NetSuite reads and Composio handles QuickBooks.
|
|
186
186
|
- Before an agent with an active QuickBooks route starts, the attempt checks that `QUICKBOOKS_PUBLIC_URL` answers from outside.
|
|
187
187
|
- The gateway keeps every call on the world: a call that names another toolkit's tools, changes a session's connection, proxies a request or reaches another attempt's session gets `403 COMPOSIO_ROUTE_REFUSED` with a `reason`, and the attempt is invalid with `ROUTE_REFUSED`, so every result rests on calls inside the world.
|
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");
|
|
@@ -187138,13 +187139,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
187138
187139
|
}
|
|
187139
187140
|
const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
|
|
187140
187141
|
if (mcp) {
|
|
187141
|
-
if (method2 !== "POST") refuse("METHOD");
|
|
187142
187142
|
if (!identifier4.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
|
|
187143
187143
|
noQuery();
|
|
187144
|
+
if (method2 === "GET" || method2 === "DELETE") {
|
|
187145
|
+
empty2();
|
|
187146
|
+
return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
|
|
187147
|
+
}
|
|
187148
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
187144
187149
|
const forwarded = protocolHeaders(headers), json37 = jsonBody3(body7, contentType);
|
|
187145
187150
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
187146
187151
|
const value5 = parsed3(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record10.optional() }), json37);
|
|
187147
|
-
if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
|
|
187148
187152
|
if (value5.method === "tools/call") {
|
|
187149
187153
|
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record10.optional(), account: external_exports.unknown().optional(), _meta: record10.optional() }), value5.params);
|
|
187150
187154
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
@@ -187320,6 +187324,12 @@ function nextRouteId(route15, kind) {
|
|
|
187320
187324
|
}
|
|
187321
187325
|
var suiteqlArguments = external_exports.strictObject({ q: external_exports.string(), limit: external_exports.number().int().min(1).optional(), offset: external_exports.number().int().min(0).optional() });
|
|
187322
187326
|
async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
|
|
187327
|
+
if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
|
|
187328
|
+
error: "method_not_allowed",
|
|
187329
|
+
message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
|
|
187330
|
+
allowed_methods: ["POST"],
|
|
187331
|
+
docs: "https://docs.composio.dev/mcp"
|
|
187332
|
+
} } : { status: 405 };
|
|
187323
187333
|
if (call2.local === "session") {
|
|
187324
187334
|
route15.narrowed(call2.narrowed ?? []);
|
|
187325
187335
|
if (call2.response === "session-delete") {
|
|
@@ -187487,10 +187497,10 @@ async function startIsolationGateway(options4) {
|
|
|
187487
187497
|
roots.set(root3, upstream);
|
|
187488
187498
|
}
|
|
187489
187499
|
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"]]) {
|
|
187500
|
+
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
187501
|
const upstream = loopbackOrigin(session2[field5]);
|
|
187492
187502
|
if (upstream.pathname !== path6 || upstream.search || upstream.hash) throw new Error("Invalid trial session route");
|
|
187493
|
-
sessionRoutes2.set(path6, { method: method2, upstream });
|
|
187503
|
+
sessionRoutes2.set(path6, { name: name5, method: method2, upstream });
|
|
187494
187504
|
}
|
|
187495
187505
|
const socketGrants = /* @__PURE__ */ new Map();
|
|
187496
187506
|
const modelHosts = new Set((options4.modelHosts ?? []).map(normalizeModelHost));
|
|
@@ -187551,7 +187561,7 @@ async function startIsolationGateway(options4) {
|
|
|
187551
187561
|
reached = result.reached;
|
|
187552
187562
|
invalidArguments = result.invalidArguments === true;
|
|
187553
187563
|
if (!res.destroyed) {
|
|
187554
|
-
res.writeHead(result.status, { "content-type": "application/json" });
|
|
187564
|
+
res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
|
|
187555
187565
|
res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
|
|
187556
187566
|
}
|
|
187557
187567
|
} catch {
|
|
@@ -187654,7 +187664,15 @@ async function startIsolationGateway(options4) {
|
|
|
187654
187664
|
}
|
|
187655
187665
|
if (!upstream) {
|
|
187656
187666
|
const route16 = sessionRoutes2.get(path6);
|
|
187657
|
-
if (!route16
|
|
187667
|
+
if (!route16) return reject2(res);
|
|
187668
|
+
const status4 = req.method !== route16.method ? 405 : req.headers.authorization !== `Bearer ${session2.token}` ? 401 : void 0;
|
|
187669
|
+
if (status4 !== void 0) {
|
|
187670
|
+
try {
|
|
187671
|
+
options4.onSessionRefused?.(route16.name, status4);
|
|
187672
|
+
} catch {
|
|
187673
|
+
}
|
|
187674
|
+
return reject2(res, status4, status4 === 405 ? `${route16.name} takes ${route16.method}.` : `${route16.name} takes Authorization: Bearer $ANCHA_TRIAL_TOKEN.`);
|
|
187675
|
+
}
|
|
187658
187676
|
upstream = route16.upstream;
|
|
187659
187677
|
if (path6 === "/_ancha/context") transform3 = "context";
|
|
187660
187678
|
}
|
package/lib/worker.mjs
CHANGED
|
@@ -71166,13 +71166,16 @@ function validateComposio(method2, target5, apiKey, body7, contentType, route15,
|
|
|
71166
71166
|
}
|
|
71167
71167
|
const mcp = /^\/tool_router\/([^/]+)\/mcp$/.exec(url4.pathname);
|
|
71168
71168
|
if (mcp) {
|
|
71169
|
-
if (method2 !== "POST") refuse("METHOD");
|
|
71170
71169
|
if (!identifier.test(mcp[1]) || !route15.sessions.has(mcp[1])) refuse("SESSION");
|
|
71171
71170
|
noQuery();
|
|
71171
|
+
if (method2 === "GET" || method2 === "DELETE") {
|
|
71172
|
+
empty2();
|
|
71173
|
+
return { ...base6, local: "mcp", response: method2 === "GET" ? "mcp-get" : "mcp-delete" };
|
|
71174
|
+
}
|
|
71175
|
+
if (method2 !== "POST") refuse("METHOD");
|
|
71172
71176
|
const forwarded2 = protocolHeaders(headers), json37 = jsonBody(body7, contentType);
|
|
71173
71177
|
if (Array.isArray(json37)) refuse("MCP_BATCH");
|
|
71174
71178
|
const value5 = parsed2(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record7.optional() }), json37);
|
|
71175
|
-
if (!["initialize", "notifications/initialized", "notifications/cancelled", "ping", "tools/list", "tools/call"].includes(value5.method)) refuse("MCP_METHOD");
|
|
71176
71179
|
if (value5.method === "tools/call") {
|
|
71177
71180
|
const params10 = parsed2(external_exports.strictObject({ name: external_exports.string(), arguments: record7.optional(), account: external_exports.unknown().optional(), _meta: record7.optional() }), value5.params);
|
|
71178
71181
|
const call2 = toolArguments(route15, params10.name, params10.arguments);
|
|
@@ -71346,6 +71349,12 @@ function nextRouteId(route15, kind) {
|
|
|
71346
71349
|
return `${kind}_${ids3.fork(kind).alnumUpper(16)}`;
|
|
71347
71350
|
}
|
|
71348
71351
|
async function executeLocalComposio(call2, route15, origin, fetcher = fetch, signal) {
|
|
71352
|
+
if (call2.local === "mcp") return call2.response === "mcp-get" ? { status: 405, headers: { allow: "POST" }, body: {
|
|
71353
|
+
error: "method_not_allowed",
|
|
71354
|
+
message: "This MCP endpoint accepts POST requests. GET/SSE streaming is not supported on this transport.",
|
|
71355
|
+
allowed_methods: ["POST"],
|
|
71356
|
+
docs: "https://docs.composio.dev/mcp"
|
|
71357
|
+
} } : { status: 405 };
|
|
71349
71358
|
if (call2.local === "session") {
|
|
71350
71359
|
route15.narrowed(call2.narrowed ?? []);
|
|
71351
71360
|
if (call2.response === "session-delete") {
|
|
@@ -71574,10 +71583,10 @@ async function startIsolationGateway(options5) {
|
|
|
71574
71583
|
roots.set(root3, upstream);
|
|
71575
71584
|
}
|
|
71576
71585
|
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"]]) {
|
|
71586
|
+
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
71587
|
const upstream = loopbackOrigin(session2[field6]);
|
|
71579
71588
|
if (upstream.pathname !== path8 || upstream.search || upstream.hash) throw new Error("Invalid trial session route");
|
|
71580
|
-
sessionRoutes2.set(path8, { method: method2, upstream });
|
|
71589
|
+
sessionRoutes2.set(path8, { name: name5, method: method2, upstream });
|
|
71581
71590
|
}
|
|
71582
71591
|
const socketGrants = /* @__PURE__ */ new Map();
|
|
71583
71592
|
const modelHosts = new Set((options5.modelHosts ?? []).map(normalizeModelHost));
|
|
@@ -71638,7 +71647,7 @@ async function startIsolationGateway(options5) {
|
|
|
71638
71647
|
reached = result.reached;
|
|
71639
71648
|
invalidArguments = result.invalidArguments === true;
|
|
71640
71649
|
if (!res.destroyed) {
|
|
71641
|
-
res.writeHead(result.status, { "content-type": "application/json" });
|
|
71650
|
+
res.writeHead(result.status, { "content-type": "application/json", ...result.headers });
|
|
71642
71651
|
res.end(result.body === void 0 ? void 0 : JSON.stringify(result.body));
|
|
71643
71652
|
}
|
|
71644
71653
|
} catch {
|
|
@@ -71741,7 +71750,15 @@ async function startIsolationGateway(options5) {
|
|
|
71741
71750
|
}
|
|
71742
71751
|
if (!upstream) {
|
|
71743
71752
|
const route16 = sessionRoutes2.get(path8);
|
|
71744
|
-
if (!route16
|
|
71753
|
+
if (!route16) return reject2(res);
|
|
71754
|
+
const status5 = req.method !== route16.method ? 405 : req.headers.authorization !== `Bearer ${session2.token}` ? 401 : void 0;
|
|
71755
|
+
if (status5 !== void 0) {
|
|
71756
|
+
try {
|
|
71757
|
+
options5.onSessionRefused?.(route16.name, status5);
|
|
71758
|
+
} catch {
|
|
71759
|
+
}
|
|
71760
|
+
return reject2(res, status5, status5 === 405 ? `${route16.name} takes ${route16.method}.` : `${route16.name} takes Authorization: Bearer $ANCHA_TRIAL_TOKEN.`);
|
|
71761
|
+
}
|
|
71745
71762
|
upstream = route16.upstream;
|
|
71746
71763
|
if (path8 === "/_ancha/context") transform3 = "context";
|
|
71747
71764
|
}
|
|
@@ -72697,7 +72714,6 @@ var init_ingress_client = __esm({
|
|
|
72697
72714
|
TOOL: "execute a QUICKBOOKS_ tool",
|
|
72698
72715
|
META_TOOL: "use COMPOSIO_MULTI_EXECUTE_TOOL, COMPOSIO_SEARCH_TOOLS or COMPOSIO_GET_TOOL_SCHEMAS; multi-execute items must be QUICKBOOKS_ tools",
|
|
72699
72716
|
ACCOUNT: "list the route connected accounts and use the returned test connection",
|
|
72700
|
-
MCP_METHOD: "use initialize, notifications/initialized, notifications/cancelled, ping, tools/list or tools/call",
|
|
72701
72717
|
MCP_BATCH: "send one JSON-RPC object per MCP request"
|
|
72702
72718
|
};
|
|
72703
72719
|
unreachedDetail = (status5) => status5 === 401 || status5 === 403 ? `Composio answered ${status5} without calling the world: check the workspace secret COMPOSIO_API_KEY.` : status5 >= 500 ? `Composio answered ${status5} without calling the world; run again.` : `Composio answered ${status5} without calling the world: check the QuickBooks tool arguments and use the connection supplied by the route.`;
|
|
@@ -73568,6 +73584,9 @@ function missingFix(text26, context3) {
|
|
|
73568
73584
|
function likelyFix(logTail3, context3 = {}) {
|
|
73569
73585
|
const task2 = taskFix(logTail3.join("\n"), context3.command);
|
|
73570
73586
|
if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
|
|
73587
|
+
if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
|
|
73588
|
+
return `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, ${context3.target === "cloud" ? "run ancha secrets set ANTHROPIC_API_KEY in the project" : "set ANTHROPIC_API_KEY in this shell and list it under agent.pass_env in ancha.yaml"}`;
|
|
73589
|
+
}
|
|
73571
73590
|
const errors2 = logTail3.filter((line2) => /error|exception|fatal|panic|missing|required|usage|not set|not found|cannot|can't/i.test(line2));
|
|
73572
73591
|
for (const lines of [errors2, logTail3]) {
|
|
73573
73592
|
const fix = lines.length === 0 ? void 0 : keyFix(lines, context3) ?? missingFix(lines.join("\n"), context3);
|
|
@@ -220329,6 +220348,7 @@ var init_sessions5 = __esm({
|
|
|
220329
220348
|
});
|
|
220330
220349
|
}
|
|
220331
220350
|
authenticate(token5, allowFinished = false) {
|
|
220351
|
+
if (!token5) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability", { hint: "send Authorization: Bearer $ANCHA_TRIAL_TOKEN" });
|
|
220332
220352
|
const env = token5 ? this.#manager.list().find((env2) => this.#records.get(env2)?.session.token === token5) : void 0;
|
|
220333
220353
|
const record15 = env ? this.#records.get(env) : void 0;
|
|
220334
220354
|
if (!env || !record15 || record15.signal !== env.signal) throw new AnchaError("SESSION_UNAUTHORIZED", "invalid session capability");
|
|
@@ -223725,7 +223745,7 @@ function withoutScriptBanners(lines) {
|
|
|
223725
223745
|
function stdoutAnswer(stdout) {
|
|
223726
223746
|
return withoutScriptBanners(stdout.replace(ANSI, "").replace(/\r\n?/g, "\n").trimEnd().split("\n")).join("\n").trimEnd();
|
|
223727
223747
|
}
|
|
223728
|
-
var ANSWER_MAX_CHARS, STDOUT_MAX_CHARS, OutputTail, ModelReplies, ANSI, NPM_SCRIPT, NPM_COMMAND, YARN_RUN, YARN_COMMAND, YARN_DONE;
|
|
223748
|
+
var ANSWER_MAX_CHARS, STDOUT_MAX_CHARS, OutputTail, ModelReplies, SessionRefusals, ANSI, NPM_SCRIPT, NPM_COMMAND, YARN_RUN, YARN_COMMAND, YARN_DONE;
|
|
223729
223749
|
var init_agent_output = __esm({
|
|
223730
223750
|
"backend/src/runner/agent-output.ts"() {
|
|
223731
223751
|
"use strict";
|
|
@@ -223780,6 +223800,17 @@ var init_agent_output = __esm({
|
|
|
223780
223800
|
return this.#last !== void 0 && MODEL_REFUSALS.has(this.#last.status) ? { ...this.#last } : void 0;
|
|
223781
223801
|
}
|
|
223782
223802
|
};
|
|
223803
|
+
SessionRefusals = class {
|
|
223804
|
+
#counts = /* @__PURE__ */ new Map();
|
|
223805
|
+
add(name5, status5) {
|
|
223806
|
+
const key5 = `${name5} ${status5}`, refusal = this.#counts.get(key5);
|
|
223807
|
+
if (refusal) refusal.count++;
|
|
223808
|
+
else this.#counts.set(key5, { name: name5, status: status5, count: 1 });
|
|
223809
|
+
}
|
|
223810
|
+
list() {
|
|
223811
|
+
return [...this.#counts.values()].map((refusal) => ({ ...refusal }));
|
|
223812
|
+
}
|
|
223813
|
+
};
|
|
223783
223814
|
ANSI = /\x1b\[[0-9;?]*[ -/]*[@-~]/g;
|
|
223784
223815
|
NPM_SCRIPT = /^> (?:\S+@\S* )?[\w:.-]+(?: \/\S*)?$/;
|
|
223785
223816
|
NPM_COMMAND = /^> \S/;
|
|
@@ -224719,8 +224750,8 @@ async function startContainedAgent(command, opts) {
|
|
|
224719
224750
|
"exec sleep 86400"
|
|
224720
224751
|
]);
|
|
224721
224752
|
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) });
|
|
224753
|
+
const replies = new ModelReplies(), refusals = new SessionRefusals();
|
|
224754
|
+
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
224755
|
const script2 = isolationRelayScript({ port: RELAY_PORT, ...opts.runtime?.port && { agentPort: opts.runtime.port } });
|
|
224725
224756
|
relayChild = spawn2("docker", ["--context", context3, "exec", "-i", relayName, "node", "-e", script2], { env: dockerEnvironment(), stdio: ["pipe", "pipe", "pipe"] });
|
|
224726
224757
|
relayChild.stderr.on("data", () => {
|
|
@@ -224812,7 +224843,7 @@ async function startContainedAgent(command, opts) {
|
|
|
224812
224843
|
return { pid: child3.pid, exited, async stop() {
|
|
224813
224844
|
await cleanup();
|
|
224814
224845
|
await exited;
|
|
224815
|
-
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
224846
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
224816
224847
|
} catch (error64) {
|
|
224817
224848
|
opts.signal?.removeEventListener("abort", abort);
|
|
224818
224849
|
await cleanup();
|
|
@@ -225031,7 +225062,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225031
225062
|
await chmod3(taskFile, 292);
|
|
225032
225063
|
await chmod3(directory, 457);
|
|
225033
225064
|
}
|
|
225034
|
-
const replies = new ModelReplies();
|
|
225065
|
+
const replies = new ModelReplies(), refusals = new SessionRefusals();
|
|
225035
225066
|
gateway2 = await (deps.gateway ?? startIsolationGateway)({
|
|
225036
225067
|
...composio && { composio },
|
|
225037
225068
|
env: opts.env,
|
|
@@ -225040,7 +225071,8 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225040
225071
|
port: unsafe ? 0 : 18991,
|
|
225041
225072
|
slackSocket: opts.agent.slackTransport === "socket",
|
|
225042
225073
|
...opts.onModelActivity && { onModelActivity: opts.onModelActivity },
|
|
225043
|
-
onModelReply: (host, status5, message8) => replies.add(host, status5, message8)
|
|
225074
|
+
onModelReply: (host, status5, message8) => replies.add(host, status5, message8),
|
|
225075
|
+
onSessionRefused: (name5, status5) => refusals.add(name5, status5)
|
|
225044
225076
|
});
|
|
225045
225077
|
const mapped = gateway2.rewrite(unsafe ? gateway2.url : VM_GATEWAY_ORIGIN);
|
|
225046
225078
|
const agentRuntime = { ...opts.runtime, ...taskFile !== void 0 && { taskFile }, ...opts.runtime?.attempt && { attempt: { ...opts.runtime.attempt, stateDir: paths3.state, records: records5 } } };
|
|
@@ -225168,7 +225200,7 @@ async function startVmAgent(command, opts, deps = {}) {
|
|
|
225168
225200
|
return { pid: child3.pid, exited, async stop() {
|
|
225169
225201
|
await cleanup();
|
|
225170
225202
|
await exited;
|
|
225171
|
-
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), modelRefusal: replies.refusal() }) };
|
|
225203
|
+
}, output: () => ({ stdout: tail.text(), printed: tail.length(), modelReplies: replies.list(), sessionRefusals: refusals.list(), modelRefusal: replies.refusal() }) };
|
|
225172
225204
|
} catch (error64) {
|
|
225173
225205
|
await cleanup();
|
|
225174
225206
|
throw error64;
|
|
@@ -226070,6 +226102,7 @@ async function runTrialInner(spec) {
|
|
|
226070
226102
|
...playOut !== void 0 && playOut.toMs > playOut.fromMs && { playOut },
|
|
226071
226103
|
checks: checks2,
|
|
226072
226104
|
...output2?.modelReplies?.length && { modelReplies: output2.modelReplies },
|
|
226105
|
+
...output2?.sessionRefusals?.length && { sessionRefusals: output2.sessionRefusals },
|
|
226073
226106
|
logTail: exit === "idle" || exit === "done" || exit === "exited" && exitCode === 0 ? [] : await logTail(join21(dir, "agent.log")),
|
|
226074
226107
|
// 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
226108
|
// 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.52",
|
|
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": {
|