@ancha-labs/cli 0.4.22 → 0.4.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ancha.mjs +1202 -476
- package/lib/assets/docs/apps.md +36 -0
- package/lib/assets/docs/cloud.md +30 -0
- package/lib/assets/docs/run.md +14 -0
- package/lib/assets/docs/tools.md +40 -1
- package/lib/assets/harbor/companion.mjs +155 -19
- package/lib/assets/ui/app.js +70 -11
- package/lib/mcp-entry.mjs +21 -3
- package/lib/worker.mjs +398 -79
- package/lib/world-server.mjs +95 -17
- package/package.json +1 -1
package/lib/world-server.mjs
CHANGED
|
@@ -91940,10 +91940,10 @@ var EXECUTION_SUPPORT = {
|
|
|
91940
91940
|
"agent.input.per_event": sceneOnly,
|
|
91941
91941
|
"agent.input.events": localOnly,
|
|
91942
91942
|
"agent.input.http": all,
|
|
91943
|
-
"agent.endpoint": localOnly,
|
|
91943
|
+
"agent.endpoint": { ...localOnly, "cloud-vm": true },
|
|
91944
91944
|
"agent.slack_transport.feed": sceneOnly,
|
|
91945
|
-
"agent.slack_transport.http": localOnly,
|
|
91946
|
-
"agent.slack_transport.socket": localOnly,
|
|
91945
|
+
"agent.slack_transport.http": { ...localOnly, "cloud-vm": true },
|
|
91946
|
+
"agent.slack_transport.socket": { ...localOnly, "cloud-vm": true },
|
|
91947
91947
|
"agent.env": sceneOnly,
|
|
91948
91948
|
"agent.pass_env": sceneOnly,
|
|
91949
91949
|
"agent.execution": sceneOnly,
|
|
@@ -104283,6 +104283,7 @@ var fields2 = {
|
|
|
104283
104283
|
};
|
|
104284
104284
|
var TestFileSchema = external_exports.strictObject({
|
|
104285
104285
|
...fields2,
|
|
104286
|
+
function_tools: SceneSchema.shape.tools,
|
|
104286
104287
|
world: external_exports.union([WorldId, external_exports.record(external_exports.string(), external_exports.unknown())], { error: WORLD_ERROR }),
|
|
104287
104288
|
until: external_exports.unknown().optional(),
|
|
104288
104289
|
checks: external_exports.array(external_exports.record(external_exports.string(), external_exports.unknown())).optional(),
|
|
@@ -104290,6 +104291,7 @@ var TestFileSchema = external_exports.strictObject({
|
|
|
104290
104291
|
});
|
|
104291
104292
|
var TestFileDocument = external_exports.strictObject({
|
|
104292
104293
|
...fields2,
|
|
104294
|
+
function_tools: SceneSchema.shape.tools,
|
|
104293
104295
|
world: external_exports.union([WorldId, WorldBodySchema]).describe("A world file's id (ancha/worlds/<id>.yaml), or the world inline"),
|
|
104294
104296
|
until: SceneSchema.shape.until,
|
|
104295
104297
|
checks: SceneSchema.shape.checks.optional(),
|
|
@@ -105012,6 +105014,46 @@ function toolErrorText(text24) {
|
|
|
105012
105014
|
return out;
|
|
105013
105015
|
}
|
|
105014
105016
|
|
|
105017
|
+
// packages/core/src/function-tool-observation.ts
|
|
105018
|
+
var functionToolObservationSchema = external_exports.strictObject({
|
|
105019
|
+
registered: external_exports.array(external_exports.string()),
|
|
105020
|
+
complete: external_exports.boolean(),
|
|
105021
|
+
protocol_version: external_exports.number().int().nonnegative().optional(),
|
|
105022
|
+
required: external_exports.array(external_exports.string()),
|
|
105023
|
+
missing: external_exports.array(external_exports.string()),
|
|
105024
|
+
tools: external_exports.array(external_exports.strictObject({
|
|
105025
|
+
name: external_exports.string(),
|
|
105026
|
+
registered: external_exports.boolean(),
|
|
105027
|
+
called: external_exports.number().int().nonnegative(),
|
|
105028
|
+
completed: external_exports.number().int().nonnegative(),
|
|
105029
|
+
pending: external_exports.number().int().nonnegative()
|
|
105030
|
+
}))
|
|
105031
|
+
});
|
|
105032
|
+
function requiredFunctionTools(scene2) {
|
|
105033
|
+
const names5 = Object.keys(scene2.tools ?? {}).filter((name5) => !scene2.tools[name5].mcp);
|
|
105034
|
+
const patterns = [];
|
|
105035
|
+
const visit4 = (value4) => {
|
|
105036
|
+
if (!value4 || typeof value4 !== "object") return;
|
|
105037
|
+
for (const [key4, item2] of Object.entries(value4)) {
|
|
105038
|
+
if (key4 === "called" || key4 === "not_called") patterns.push(...(Array.isArray(item2) ? item2 : [item2]).filter((p2) => typeof p2 === "string"));
|
|
105039
|
+
else visit4(item2);
|
|
105040
|
+
}
|
|
105041
|
+
};
|
|
105042
|
+
for (const check3 of scene2.checks) if (scene2.pass.includes(check3.id)) visit4(check3);
|
|
105043
|
+
return names5.filter((name5) => patterns.some((pattern) => {
|
|
105044
|
+
const p2 = pattern.trim();
|
|
105045
|
+
const bare = /^([A-Za-z_][\w.-]{0,127})(?:\s+\{.*\})?$/s.exec(p2);
|
|
105046
|
+
const [method2, path4] = p2.split(/\s+/);
|
|
105047
|
+
return p2 === "*" || bare?.[1] === name5 || (method2 === "POST" || method2 === "*") && (path4 === `/tools/${name5}` || path4 === "/tools/*");
|
|
105048
|
+
})).sort();
|
|
105049
|
+
}
|
|
105050
|
+
function functionWiringMessage(missing7) {
|
|
105051
|
+
return `Connect function tools: ${missing7.join(", ")}. Python: import ancha; pass ancha.wrap_tools([...]) to the framework and call ancha.entry(run). JavaScript: import { wrapTools, entry } from '@ancha-labs/tools'; pass wrapTools([...]) to the framework and call await entry(run). Register tools before the task starts.`;
|
|
105052
|
+
}
|
|
105053
|
+
function functionToolWiringIssues(observation) {
|
|
105054
|
+
return observation.missing.length ? [{ kind: "tools", owner: "harness", service: "tools", message: functionWiringMessage(observation.missing) }] : [];
|
|
105055
|
+
}
|
|
105056
|
+
|
|
105015
105057
|
// backend/src/mcp/vendor-http.ts
|
|
105016
105058
|
function mcpTextResult(text24, isError = false) {
|
|
105017
105059
|
return { isError, content: [{ type: "text", text: text24 }] };
|
|
@@ -117295,6 +117337,13 @@ function decide(ctx, name5, args) {
|
|
|
117295
117337
|
ctx.store.db.prepare("INSERT INTO agent_tool_calls (key, n) VALUES (?, 1) ON CONFLICT(key) DO UPDATE SET n=n+1").run(callKey);
|
|
117296
117338
|
const policy = tool?.unrecorded ?? (tool?.write ? "fail" : "simulate");
|
|
117297
117339
|
const reached = Number(getState(ctx, "reached") ?? 0);
|
|
117340
|
+
let selected2 = Math.min(n2, same3.length - 1);
|
|
117341
|
+
for (let i = same3.length - 1; i > selected2; i--) if (same3[i].atMs <= reached) {
|
|
117342
|
+
selected2 = i;
|
|
117343
|
+
break;
|
|
117344
|
+
}
|
|
117345
|
+
const observation = same3[selected2];
|
|
117346
|
+
if (observation && observation.result === void 0 && observation.error === void 0) return { source: "failed", error: `Recorded call to ${name5} needs a result or error. Capture its outcome and import the trace again.` };
|
|
117298
117347
|
const simulationKey = `${callKey} revision:${getState(ctx, "revision") ?? "0"}${tool?.schema ? ` schema:${schemaFingerprint(tool.schema)}` : ""}`;
|
|
117299
117348
|
if (policy === "run" && (tool?.write || getState(ctx, "run:changed") !== void 0 || n2 >= same3.length || same3[n2].atMs >= productionFirstWrite(ctx))) {
|
|
117300
117349
|
if (tool?.write) {
|
|
@@ -117310,14 +117359,14 @@ function decide(ctx, name5, args) {
|
|
|
117310
117359
|
index = i;
|
|
117311
117360
|
break;
|
|
117312
117361
|
}
|
|
117313
|
-
const
|
|
117314
|
-
if (tool.write &&
|
|
117315
|
-
setState(ctx, "reached", String(Math.max(reached,
|
|
117316
|
-
return { source: "replayed", error:
|
|
117362
|
+
const observation2 = n2 < same3.length ? same3[index] : void 0;
|
|
117363
|
+
if (tool.write && observation2?.error !== void 0) {
|
|
117364
|
+
setState(ctx, "reached", String(Math.max(reached, observation2.endMs)));
|
|
117365
|
+
return { source: "replayed", error: observation2.error, ...observation2.raw !== void 0 && { raw: observation2.raw, wrap: observation2.wrap } };
|
|
117317
117366
|
}
|
|
117318
|
-
if (
|
|
117367
|
+
if (observation2) setState(ctx, "reached", String(Math.max(reached, observation2.endMs)));
|
|
117319
117368
|
if (tool.write) setState(ctx, `twin:dirty:${linked2}`, "1");
|
|
117320
|
-
return { source: "twin", passthrough: true, ...
|
|
117369
|
+
return { source: "twin", passthrough: true, ...observation2 && { recording: observation2 } };
|
|
117321
117370
|
}
|
|
117322
117371
|
const cached2 = getState(ctx, `sim:${simulationKey}`);
|
|
117323
117372
|
if (cached2 !== void 0) {
|
|
@@ -117370,7 +117419,28 @@ function noteCall(ctx, name5, args, a) {
|
|
|
117370
117419
|
setState(ctx, "calls", JSON.stringify(calls2.slice(-50)));
|
|
117371
117420
|
}
|
|
117372
117421
|
function toolsToWrap(ctx) {
|
|
117373
|
-
return Object.entries(ctx.scene.tools ?? {}).filter(([, t]) => !t.mcp && (!t.pure || t.twin !== void 0) && !t.allow_unwrapped).map(([name5]) => name5).sort();
|
|
117422
|
+
return [.../* @__PURE__ */ new Set([...requiredFunctionTools(ctx.scene), ...Object.entries(ctx.scene.tools ?? {}).filter(([, t]) => !t.mcp && (!t.pure || t.twin !== void 0) && !t.allow_unwrapped).map(([name5]) => name5)])].sort();
|
|
117423
|
+
}
|
|
117424
|
+
function functionToolObservation(ctx) {
|
|
117425
|
+
const registered = JSON.parse(getState(ctx, "wrapped") ?? "[]");
|
|
117426
|
+
const required4 = toolsToWrap(ctx), calls2 = projectToolCalls(ctx.trace.list()).filter((e) => e.source === "agent" && e.service === "tools" && e.path.startsWith("/tools/"));
|
|
117427
|
+
const protocol = getState(ctx, "protocol");
|
|
117428
|
+
return {
|
|
117429
|
+
registered,
|
|
117430
|
+
complete: getState(ctx, "complete") === "1",
|
|
117431
|
+
...protocol !== void 0 && { protocol_version: Number(protocol) },
|
|
117432
|
+
required: required4,
|
|
117433
|
+
missing: required4.filter((name5) => !registered.includes(name5)),
|
|
117434
|
+
tools: [.../* @__PURE__ */ new Set([...Object.keys(ctx.scene.tools ?? {}), ...registered])].sort().map((name5) => {
|
|
117435
|
+
const own2 = calls2.filter((e) => decodeURIComponent(e.path.slice("/tools/".length)) === name5);
|
|
117436
|
+
const pending = own2.filter((e) => e.response?.execution_status === "unknown").length;
|
|
117437
|
+
const completed = own2.filter((e) => {
|
|
117438
|
+
const r2 = e.response;
|
|
117439
|
+
return r2?.execution_status === "succeeded" || r2?.execution_status === "failed" || !r2?.passthrough && ["replayed", "replayed-elsewhere", "simulated", "validated"].includes(String(r2?.source)) && (r2?.result !== void 0 || r2?.error !== void 0);
|
|
117440
|
+
}).length;
|
|
117441
|
+
return { name: name5, registered: registered.includes(name5), called: own2.length, completed, pending };
|
|
117442
|
+
})
|
|
117443
|
+
};
|
|
117374
117444
|
}
|
|
117375
117445
|
function registration(ctx, names5) {
|
|
117376
117446
|
const before = JSON.parse(getState(ctx, "wrapped") ?? "[]");
|
|
@@ -117403,7 +117473,7 @@ function agentToolsService() {
|
|
|
117403
117473
|
...t?.twin && { twin: t.twin },
|
|
117404
117474
|
...t?.write && { write: true }
|
|
117405
117475
|
};
|
|
117406
|
-
}), wrap: toolsToWrap(ctx) });
|
|
117476
|
+
}), wrap: toolsToWrap(ctx), observation: functionToolObservation(ctx) });
|
|
117407
117477
|
}));
|
|
117408
117478
|
app2.post("/register", bodyLimit({
|
|
117409
117479
|
maxSize: TOOL_REGISTRATION_BYTES,
|
|
@@ -117427,11 +117497,15 @@ function agentToolsService() {
|
|
|
117427
117497
|
}
|
|
117428
117498
|
for (const d of definitions3.values()) setState(c.env.ctx, `definition:${d.name}`, JSON.stringify(d));
|
|
117429
117499
|
const result = registration(c.env.ctx, [...definitions3.keys()]);
|
|
117430
|
-
if (body6.
|
|
117500
|
+
if (body6.protocol_version !== void 0) setState(c.env.ctx, "protocol", String(Math.min(body6.protocol_version, AGENT_TOOLS_PROTOCOL_VERSION)));
|
|
117501
|
+
if (body6.complete && !result.missing.length) {
|
|
117502
|
+
setState(c.env.ctx, "complete", "1");
|
|
117503
|
+
setState(c.env.ctx, "checked", "1");
|
|
117504
|
+
}
|
|
117431
117505
|
return result;
|
|
117432
117506
|
});
|
|
117433
117507
|
const protocol_version = AGENT_TOOLS_PROTOCOL_VERSION;
|
|
117434
|
-
if (body6.complete && missing7.length) return c.json({ protocol_version, error: unwrappedMessage(missing7, wrapped.length === 0), wrapped, missing: missing7, stop: true }, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
117508
|
+
if (body6.complete && missing7.length) return c.json({ protocol_version, error: requiredFunctionTools(c.env.ctx.scene).some((name5) => missing7.includes(name5)) ? functionWiringMessage(missing7) : unwrappedMessage(missing7, wrapped.length === 0), wrapped, missing: missing7, stop: true }, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
117435
117509
|
return c.json({ protocol_version, wrapped, missing: missing7 });
|
|
117436
117510
|
} catch (error64) {
|
|
117437
117511
|
const message7 = error64 instanceof Error ? error64.message : String(error64);
|
|
@@ -117483,9 +117557,9 @@ function agentToolsService() {
|
|
|
117483
117557
|
const body6 = await c.req.json().catch(() => ({}));
|
|
117484
117558
|
const stop = withMutation(c.env.ctx, () => {
|
|
117485
117559
|
if (getState(c.env.ctx, "checked")) return void 0;
|
|
117486
|
-
setState(c.env.ctx, "checked", "1");
|
|
117487
117560
|
const { wrapped, missing: missing7 } = registration(c.env.ctx, []);
|
|
117488
|
-
|
|
117561
|
+
if (!missing7.length) setState(c.env.ctx, "checked", "1");
|
|
117562
|
+
return missing7.length ? { error: requiredFunctionTools(c.env.ctx.scene).some((name6) => missing7.includes(name6)) ? functionWiringMessage(missing7) : unwrappedMessage(missing7, wrapped.length === 0), wrapped, missing: missing7, stop: true } : void 0;
|
|
117489
117563
|
});
|
|
117490
117564
|
if (stop) return c.json(stop, 409, { [SETUP_ISSUE_HEADER]: "1" });
|
|
117491
117565
|
const ctx = c.env.ctx, args = body6.args ?? {};
|
|
@@ -117539,7 +117613,7 @@ function agentToolsService() {
|
|
|
117539
117613
|
credentials: (ctx) => ({ token: `ancha-tools-${ctx.secrets.hex(32)}` }),
|
|
117540
117614
|
actions: {},
|
|
117541
117615
|
checks: {},
|
|
117542
|
-
dumpState: (ctx) => ({ calls: ctx.store.db.prepare("SELECT key, n FROM agent_tool_calls ORDER BY key").all(), wrapped: JSON.parse(getState(ctx, "wrapped") ?? "[]"), definitions: ctx.store.db.prepare("SELECT k, v FROM agent_tool_state WHERE k LIKE 'definition:%' ORDER BY k").all() }),
|
|
117616
|
+
dumpState: (ctx) => ({ observation: functionToolObservation(ctx), calls: ctx.store.db.prepare("SELECT key, n FROM agent_tool_calls ORDER BY key").all(), wrapped: JSON.parse(getState(ctx, "wrapped") ?? "[]"), definitions: ctx.store.db.prepare("SELECT k, v FROM agent_tool_state WHERE k LIKE 'definition:%' ORDER BY k").all() }),
|
|
117543
117617
|
coverage: []
|
|
117544
117618
|
};
|
|
117545
117619
|
}
|
|
@@ -118038,7 +118112,7 @@ var Environment = class _Environment {
|
|
|
118038
118112
|
trace,
|
|
118039
118113
|
state: state2,
|
|
118040
118114
|
simMs: this.clock.elapsedMs(),
|
|
118041
|
-
harnessIssues: collectHarnessIssues(trace, checks2),
|
|
118115
|
+
harnessIssues: [...collectHarnessIssues(trace, checks2), ...Object.keys(this.scene.tools ?? {}).length > 0 ? functionToolWiringIssues(functionToolObservation(this.ctxFor("tools"))) : []],
|
|
118042
118116
|
...people3.length && { people: people3 },
|
|
118043
118117
|
...replay && { peopleReplay: { replayed: replay.replayed, live: replay.live, divergence: replay.divergence ?? null } },
|
|
118044
118118
|
...explanations.length && { explanations },
|
|
@@ -169752,6 +169826,9 @@ var SocketDelivery = class {
|
|
|
169752
169826
|
get pendingCount() {
|
|
169753
169827
|
return this.#pending.size;
|
|
169754
169828
|
}
|
|
169829
|
+
get connected() {
|
|
169830
|
+
return this.#live() && this.#socket?.readyState === import_websocket.default.OPEN;
|
|
169831
|
+
}
|
|
169755
169832
|
isCurrent(env) {
|
|
169756
169833
|
return env === this.#env && this.#live();
|
|
169757
169834
|
}
|
|
@@ -170314,6 +170391,7 @@ var TrialSessions = class {
|
|
|
170314
170391
|
pendingJobs,
|
|
170315
170392
|
pendingBlockingJobs,
|
|
170316
170393
|
pendingDeliveries,
|
|
170394
|
+
...record9.socket && { socketConnected: record9.socket.connected },
|
|
170317
170395
|
quiet: session2.state === "running" && quietNow(env, record9.busy > 0),
|
|
170318
170396
|
nextDueMs: nextDue,
|
|
170319
170397
|
...untilMs !== void 0 && { untilMs }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.23",
|
|
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": {
|