@ancha-labs/cli 0.4.3 → 0.4.4
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 +102 -6
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/docs/traces.md +1 -1
- package/lib/assets/ui/app.js +37 -5
- package/lib/assets/ui/style.css +2 -0
- package/lib/worker.mjs +1 -0
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -43959,16 +43959,33 @@ function toolDataView(tool, raw3) {
|
|
|
43959
43959
|
add("Channels", state3.channels, (r) => ({ "Channel": text10(r.name), "ID": text10(r.id) }));
|
|
43960
43960
|
add("Messages", state3.messages, (r) => ({ "Channel": text10(where2(r.channel_id)), "From": text10(who2(r.user_id)), "Message": text10(r.text), "Time": text10(r.ts) }));
|
|
43961
43961
|
} else if (tool === "github") {
|
|
43962
|
+
const login2 = (id12) => list(state3.users).find((u) => u.id === id12)?.login ?? id12;
|
|
43962
43963
|
add("Repositories", state3.repos, (r) => ({ "Repository": text10(r.full_name), "Branch": text10(r.default_branch), "ID": text10(r.id) }));
|
|
43963
43964
|
add("Pull requests", state3.pulls, (r) => ({ "Number": text10(r.number), "State": text10(r.state), "Merged": text10(r.merged), "Title": text10(list(state3.issues).find((i) => i.repo_id === r.repo_id && i.number === r.number)?.title) }));
|
|
43964
43965
|
add("Commits", state3.commits, (r) => ({ "Message": text10(r.commit?.message), "SHA": text10(r.sha) }));
|
|
43966
|
+
add("People", state3.users, (r) => ({ "Login": text10(r.login), "Name": text10(r.name), "Email": text10(r.email) }));
|
|
43967
|
+
add("Organization members", state3.org_members, (r) => ({ "Organization": text10(list(state3.organizations).find((o) => o.id === r.org_id)?.login ?? r.org_id), "Person": text10(login2(r.user_id)), "Role": text10(r.role) }));
|
|
43968
|
+
add("Repository access", state3.collaborators, (r) => ({ "Repository": text10(list(state3.repos).find((p2) => p2.id === r.repo_id)?.full_name ?? r.repo_id), "Person": text10(login2(r.user_id)), "Permission": text10(r.permission) }));
|
|
43965
43969
|
} else if (tool === "datadog") {
|
|
43966
43970
|
add("Monitors", state3.monitors, (r) => ({ "Monitor": text10(r.name), "Status": text10(r.overall_state), "Query": text10(r.query) }));
|
|
43967
43971
|
add("Logs", state3.logs, (r) => ({ "Time": text10(r.at), "Service": text10(r.service), "Status": text10(r.status), "Message": text10(r.message) }));
|
|
43968
43972
|
} else if (tool === "pagerduty") {
|
|
43973
|
+
const person4 = (id12) => list(state3.users).find((u) => u.id === id12)?.name ?? id12;
|
|
43974
|
+
const schedule3 = (id12) => list(state3.schedules).find((s) => s.id === id12)?.name ?? id12;
|
|
43975
|
+
const time7 = (ms3) => typeof ms3 === "number" && Number.isFinite(ms3) ? new Date(ms3).toISOString().replace(".000Z", "Z") : "\u2014";
|
|
43976
|
+
const targets = (json32) => {
|
|
43977
|
+
try {
|
|
43978
|
+
return list(JSON.parse(String(json32))).map((t) => t.type === "schedule_reference" ? schedule3(t.id) : person4(t.id)).join(", ") || "\u2014";
|
|
43979
|
+
} catch {
|
|
43980
|
+
return "\u2014";
|
|
43981
|
+
}
|
|
43982
|
+
};
|
|
43969
43983
|
add("Incidents", state3.incidents, (r) => ({ "Incident": text10(r.title), "Status": text10(r.status), "ID": text10(r.id) }));
|
|
43970
43984
|
add("Services", state3.services, (r) => ({ "Service": text10(r.name), "ID": text10(r.id) }));
|
|
43971
43985
|
add("People", state3.users, (r) => ({ "Name": text10(r.name), "Email": text10(r.email) }));
|
|
43986
|
+
add("On-call schedule", state3.schedule_entries, (r) => ({ "Schedule": text10(schedule3(r.schedule_id)), "On call": text10(person4(r.user_id)), "From": time7(r.start_ms), "Until": time7(r.end_ms) }));
|
|
43987
|
+
add("Overrides", state3.overrides, (r) => ({ "Schedule": text10(schedule3(r.schedule_id)), "On call": text10(person4(r.user_id)), "From": time7(r.start_ms), "Until": time7(r.end_ms) }));
|
|
43988
|
+
add("Escalation policies", state3.escalation_rules, (r) => ({ "Policy": text10(list(state3.escalation_policies).find((p2) => p2.id === r.policy_id)?.name ?? r.policy_id), "Level": text10(r.level), "Notifies": targets(r.targets_json) }));
|
|
43972
43989
|
} else if (tool === "linkedin-ads") {
|
|
43973
43990
|
add("Campaigns", state3.campaigns, (r) => ({ "Campaign": text10(r.name), "Status": text10(r.status), "Daily budget": money6(r.dailyBudget), "Total budget": money6(r.totalBudget), "ID": text10(r.id) }));
|
|
43974
43991
|
add("Ad accounts", state3.accounts, (r) => ({ "Account": text10(r.name), "Status": text10(r.status), "Currency": text10(r.currency), "ID": text10(r.id) }));
|
|
@@ -174715,6 +174732,7 @@ function trialDuration(ms3) {
|
|
|
174715
174732
|
}
|
|
174716
174733
|
var plural4 = (n, one7, many = `${one7}s`) => `${n} ${n === 1 ? one7 : many}`;
|
|
174717
174734
|
function progressLine(e, scenes) {
|
|
174735
|
+
if (e.event === "trace_skipped" && typeof e.trace === "string" && typeof e.reason === "string") return `skipped trace ${e.trace.slice(0, 8)}: ${e.reason}`;
|
|
174718
174736
|
if (e.event === "run_started" && typeof e.runId === "string" && Array.isArray(e.scenes) && typeof e.trials === "number" && typeof e.parallel === "number") {
|
|
174719
174737
|
if (typeof e.replayOf === "string") return `${e.runId}: replay of ${e.replayOf}`;
|
|
174720
174738
|
const what = e.scenes.length === 1 ? `${plural4(e.trials, "trial")} of ${String(e.scenes[0])}` : `${plural4(e.trials, "trial")} each of ${e.scenes.length} scenes`;
|
|
@@ -176088,7 +176106,8 @@ var ScenarioCatalog = class {
|
|
|
176088
176106
|
this.workspace = workspace3;
|
|
176089
176107
|
this.configPath = configPath;
|
|
176090
176108
|
}
|
|
176091
|
-
|
|
176109
|
+
/** `workspaceOnly`: this folder's scene files alone (the configured globs and drafts), without the bundled library. */
|
|
176110
|
+
async list(options3 = {}) {
|
|
176092
176111
|
const scenes = [], errors3 = [];
|
|
176093
176112
|
const bundled = await builtinRoot();
|
|
176094
176113
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -176104,10 +176123,10 @@ var ScenarioCatalog = class {
|
|
|
176104
176123
|
errors3.push({ path: path6, message: error64 instanceof Error ? error64.message : String(error64) });
|
|
176105
176124
|
}
|
|
176106
176125
|
};
|
|
176107
|
-
for (const path6 of (await glob3("*/scene.yaml", { cwd: bundled, followSymbolicLinks: false })).sort()) await add(bundled, path6, "bundled");
|
|
176126
|
+
if (!options3.workspaceOnly) for (const path6 of (await glob3("*/scene.yaml", { cwd: bundled, followSymbolicLinks: false })).sort()) await add(bundled, path6, "bundled");
|
|
176108
176127
|
const packagedData = fileURLToPath3(new URL("test-data/", assetRoot()));
|
|
176109
176128
|
const dataRoot = await stat4(packagedData).then((s) => s.isDirectory(), () => false) ? packagedData : fileURLToPath3(new URL("../../../scenes/library/", import.meta.url));
|
|
176110
|
-
for (const file3 of (await glob3("*.json", { cwd: dataRoot, followSymbolicLinks: false })).sort()) {
|
|
176129
|
+
if (!options3.workspaceOnly) for (const file3 of (await glob3("*.json", { cwd: dataRoot, followSymbolicLinks: false })).sort()) {
|
|
176111
176130
|
try {
|
|
176112
176131
|
const library = parseTestDataLibrary(JSON.parse(await safeRead(dataRoot, file3)));
|
|
176113
176132
|
for (const scenario of library.scenarios) {
|
|
@@ -207686,6 +207705,21 @@ var ConsoleSandboxes = class {
|
|
|
207686
207705
|
}
|
|
207687
207706
|
};
|
|
207688
207707
|
|
|
207708
|
+
// backend/src/console/world-data.ts
|
|
207709
|
+
init_src();
|
|
207710
|
+
async function startingData(backend, world5, seed40) {
|
|
207711
|
+
const options3 = { paused: true, execution: "manual", ttlMs: 6e4 };
|
|
207712
|
+
const env2 = "scene" in world5 ? await backend.createEnv(world5.scene, seed40, options3) : await backend.createSandbox(world5.configuration, seed40, options3);
|
|
207713
|
+
try {
|
|
207714
|
+
await backend.beginInspection(env2.id);
|
|
207715
|
+
const state3 = (await backend.observeEnv(env2.id)).state ?? {};
|
|
207716
|
+
const tools2 = Object.keys(state3);
|
|
207717
|
+
return { state: state3, trace: [], simMs: 0, seedPreview: true, seed: seed40, tools: tools2, toolViews: Object.fromEntries(tools2.map((tool) => [tool, toolDataView(tool, state3[tool])])) };
|
|
207718
|
+
} finally {
|
|
207719
|
+
await backend.destroyEnv(env2.id);
|
|
207720
|
+
}
|
|
207721
|
+
}
|
|
207722
|
+
|
|
207689
207723
|
// backend/src/console/setups.ts
|
|
207690
207724
|
init_src();
|
|
207691
207725
|
init_assets();
|
|
@@ -208048,6 +208082,10 @@ async function startConsole(opts) {
|
|
|
208048
208082
|
const q = query10(url3, ["revision"]);
|
|
208049
208083
|
return send2(res, await playgrounds.world(id12, q.revision ? integer12(q.revision, "revision") : void 0));
|
|
208050
208084
|
}
|
|
208085
|
+
if (method2 === "GET" && parts3.length === 4 && parts3[3] === "data") {
|
|
208086
|
+
const q = query10(url3, ["revision"]), world5 = await playgrounds.world(id12, q.revision ? integer12(q.revision, "revision") : void 0);
|
|
208087
|
+
return send2(res, { world: { id: world5.id, name: world5.name, revision: world5.revision }, ...await startingData(backend, { configuration: world5.configuration }, "playground-1") });
|
|
208088
|
+
}
|
|
208051
208089
|
if (method2 === "POST" && parts3.length === 4 && parts3[3] === "update") {
|
|
208052
208090
|
shape5(data5, ["name", "tools", "configuration", "revision"]);
|
|
208053
208091
|
const { revision: revision2, ...patch } = data5;
|
|
@@ -208131,6 +208169,15 @@ async function startConsole(opts) {
|
|
|
208131
208169
|
}
|
|
208132
208170
|
}
|
|
208133
208171
|
if (parts3[1] === "scenarios") {
|
|
208172
|
+
if (method2 === "GET" && parts3.length === 3 && parts3[2] === "folder") {
|
|
208173
|
+
const { scenes, errors: errors3 } = await catalog.list({ workspaceOnly: true });
|
|
208174
|
+
return send2(res, { scenes: scenes.filter((s) => s.origin === "workspace").map((s) => ({ key: s.key, path: s.path, id: s.scene.id, title: s.scene.title, tools: s.scene.twins })), errors: errors3 });
|
|
208175
|
+
}
|
|
208176
|
+
if (method2 === "GET" && parts3.length === 3 && parts3[2] === "data") {
|
|
208177
|
+
const found = await catalog.get(query10(url3, ["key"]).key ?? "");
|
|
208178
|
+
if (found.origin !== "workspace") throw new AnchaError("USAGE", "only scenes in this folder have starting data here");
|
|
208179
|
+
return send2(res, { scene: { key: found.key, path: found.path, id: found.scene.id, title: found.scene.title }, ...await startingData(backend, { scene: found.scene }, `${found.scene.id}:1`) });
|
|
208180
|
+
}
|
|
208134
208181
|
if (method2 === "GET") return send2(res, await catalog.list());
|
|
208135
208182
|
if (parts3[2] === "validate") {
|
|
208136
208183
|
shape5(data5, ["yaml"]);
|
|
@@ -227088,6 +227135,39 @@ async function report6(ctx, world5, written) {
|
|
|
227088
227135
|
].join("\n")
|
|
227089
227136
|
);
|
|
227090
227137
|
}
|
|
227138
|
+
var OFF = "turned off in the workspace";
|
|
227139
|
+
async function pullAll(ctx, options3) {
|
|
227140
|
+
const api3 = await workspaceApi(ctx);
|
|
227141
|
+
const query11 = new URLSearchParams({ limit: "1000", ...options3.agent !== void 0 && { agent: options3.agent } });
|
|
227142
|
+
const { tests } = await api3(`/v1/tests?${query11}`);
|
|
227143
|
+
const written = [], skipped = [], paths2 = [];
|
|
227144
|
+
for (const test3 of tests) {
|
|
227145
|
+
if (test3.turned_off) {
|
|
227146
|
+
skipped.push({ id: test3.id, name: test3.name, reason: OFF });
|
|
227147
|
+
continue;
|
|
227148
|
+
}
|
|
227149
|
+
let changes;
|
|
227150
|
+
try {
|
|
227151
|
+
changes = await guard(ctx, resolve40(ctx.io.cwd, options3.dest, test3.name), options3.force);
|
|
227152
|
+
} catch (error64) {
|
|
227153
|
+
if (!(error64 instanceof AnchaError)) throw error64;
|
|
227154
|
+
skipped.push({ id: test3.id, name: test3.name, reason: error64.message });
|
|
227155
|
+
continue;
|
|
227156
|
+
}
|
|
227157
|
+
const { world: world5 } = await api3(`/v1/worlds/${encodeURIComponent(test3.id)}`);
|
|
227158
|
+
const done = await writeWorld(ctx, world5, options3.dest, changes);
|
|
227159
|
+
written.push({ id: world5.id, name: world5.name, version: world5.version ?? test3.version, scene: relative12(ctx.io.cwd, done.scene) || done.scene });
|
|
227160
|
+
paths2.push(done.scene);
|
|
227161
|
+
}
|
|
227162
|
+
const next2 = paths2.length ? await nextLines(ctx, paths2, options3.dest) : [];
|
|
227163
|
+
const from = options3.agent === void 0 ? "" : ` from ${options3.agent}`;
|
|
227164
|
+
ctx.out.result({ written, skipped, ...options3.agent !== void 0 && { agent: options3.agent } }, () => [
|
|
227165
|
+
written.length ? `wrote ${plural5(written.length, "test")}${from} to ${relative12(ctx.io.cwd, resolve40(ctx.io.cwd, options3.dest)) || "."}/` : tests.length ? `wrote no tests${from}` : `the workspace has no tests${from}; ancha traces lists what it received`,
|
|
227166
|
+
...skipped.map((s) => ` skipped ${s.name}: ${s.reason}`),
|
|
227167
|
+
...skipped.some((s) => s.reason !== OFF) ? [" move those changes into checks of your own, or pass --force to overwrite the files"] : [],
|
|
227168
|
+
...next2
|
|
227169
|
+
].join("\n"));
|
|
227170
|
+
}
|
|
227091
227171
|
async function nextLines(ctx, paths2, dest) {
|
|
227092
227172
|
const folder = relative12(ctx.io.cwd, resolve40(ctx.io.cwd, dest)) || ".", where2 = paths2.length === 1 ? relative12(ctx.io.cwd, paths2[0]) : `${folder}/*/scene.yaml`;
|
|
227093
227173
|
const configured = ctx.globals().config !== void 0 || await access7(resolve40(ctx.io.cwd, "ancha.yaml")).then(() => true, () => false);
|
|
@@ -227209,13 +227289,29 @@ function registerTraces(program2, ctx) {
|
|
|
227209
227289
|
}
|
|
227210
227290
|
const api3 = await workspaceApi(ctx, `ancha import --offline ${options3.from ? `--from ${options3.from} ` : ""}${trace} makes the tests on this computer; ancha login sends traces to your workspace`);
|
|
227211
227291
|
const { traces: imported } = await api3(`/v1/imports?name=${encodeURIComponent(source.name)}`, { method: "POST", headers: { "content-type": options3.from ? "application/json" : "application/x-ndjson" }, body: source.text });
|
|
227292
|
+
let saved = 0, first;
|
|
227212
227293
|
for (const { id: id12 } of imported) {
|
|
227213
227294
|
const changes = await guard(ctx, resolve40(ctx.io.cwd, options3.dest, `trace-${id12.slice(0, 8)}`), options3.force);
|
|
227214
|
-
const
|
|
227215
|
-
|
|
227295
|
+
const made = await api3(`/v1/traces/${id12}/tests`, { method: "POST" }).catch((error64) => {
|
|
227296
|
+
if (!(error64 instanceof WorkspaceError) || ![409, 422].includes(error64.status)) throw error64;
|
|
227297
|
+
first ??= error64;
|
|
227298
|
+
ctx.out.event({ event: "trace_skipped", trace: id12, reason: error64.message });
|
|
227299
|
+
return void 0;
|
|
227300
|
+
});
|
|
227301
|
+
if (made === void 0) continue;
|
|
227302
|
+
await report6(ctx, made.world, await writeWorld(ctx, made.world, options3.dest, changes));
|
|
227303
|
+
saved++;
|
|
227216
227304
|
}
|
|
227305
|
+
if (saved === 0 && first !== void 0) throw first;
|
|
227217
227306
|
});
|
|
227218
|
-
program2.command("pull").argument("
|
|
227307
|
+
program2.command("pull").argument("[id]", "a test or a trace: its id, its first 8 characters, or the trace id your tracing tool shows").option("--all", "write every test in the workspace that is turned on, each its latest version").option("--agent <name>", "with --all: only the tests made from this agent's traces").option("--dest <dir>", "where the tests go", "scenes/from-traces").option("--answer <question=value>", "answer one of the test's questions, saving a new version first; repeat for more (`ancha traces show <id>` lists them)", (value5, all8) => [...all8, value5], []).option("--force", "overwrite scene.yaml even if it has changes besides checks you added").option("--expect <what went wrong>", "say in a sentence what the agent did wrong in production; the new version gets a check for it").description("write tests made from production traces into this project: one test, or every test with --all; a trace with no saved test gets one").action(async (id12, options3) => {
|
|
227308
|
+
if (options3.all) {
|
|
227309
|
+
if (id12 !== void 0 || options3.answer.length || options3.expect !== void 0) throw new AnchaError("USAGE", "--all writes each test as the workspace saved it", { hint: "leave out the id, --answer and --expect, or pull one test: ancha pull <id>" });
|
|
227310
|
+
await pullAll(ctx, options3);
|
|
227311
|
+
return;
|
|
227312
|
+
}
|
|
227313
|
+
if (options3.agent !== void 0) throw new AnchaError("USAGE", "--agent goes with --all", { hint: "ancha pull --all --agent <name>" });
|
|
227314
|
+
if (id12 === void 0) throw new AnchaError("USAGE", "name a test or a trace to pull, or pass --all", { hint: "ancha traces lists the traces; ancha pull --all writes every test" });
|
|
227219
227315
|
const api3 = await workspaceApi(ctx);
|
|
227220
227316
|
const found = (path6) => api3(path6).catch((error64) => {
|
|
227221
227317
|
if (notInWorkspace(error64)) return null;
|
package/lib/assets/SKILL.md
CHANGED
|
@@ -39,7 +39,7 @@ A production run that went wrong becomes a test here. With a trace file (an expo
|
|
|
39
39
|
2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).
|
|
40
40
|
3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; the import also lists the app's own setup calls, which the start script or an `app_call` has to make.
|
|
41
41
|
|
|
42
|
-
If the user's workspace takes traces (their agents send them to it), `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`
|
|
42
|
+
If 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. A workspace that doesn't take traces says so; use the file. More: `ancha docs traces`.
|
|
43
43
|
|
|
44
44
|
## The rule
|
|
45
45
|
|
|
@@ -6,7 +6,7 @@ A run of the agent in production becomes a test: the conversation it had, the ca
|
|
|
6
6
|
|
|
7
7
|
- `ancha import --offline <trace file> --json` makes them on this computer and uploads nothing. A file is OTLP JSON, a Langfuse or LangSmith export, or Ancha Trace IR.
|
|
8
8
|
- `ancha import --from langfuse <trace id>` and `ancha import --from langsmith <trace id>` fetch the trace with the keys in this shell (`LANGFUSE_PUBLIC_KEY`, `LANGFUSE_SECRET_KEY`, `LANGFUSE_HOST`; `LANGSMITH_API_KEY`, `LANGSMITH_ENDPOINT`).
|
|
9
|
-
- After `ancha login`, `ancha import <trace file>` sends the trace to the workspace, which saves the test and writes it here. When the agent sends its traces to the workspace, `ancha traces --failed --json` lists the runs where production failed a check, `ancha traces show <id> --json` previews a test and `ancha pull <id> --json`
|
|
9
|
+
- After `ancha login`, `ancha import <trace file>` sends the trace to the workspace, which saves the test and writes it here; a conversation that makes no test is listed with the reason, and the import goes on with the rest. When the agent sends its traces to the workspace, each 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 runs where production failed a check, `ancha traces show <id> --json` previews a test and `ancha pull <id> --json` writes one.
|
|
10
10
|
- `--expect "<what went wrong>"` adds a check for it, `--conversation <id>` takes one conversation of the file, `--dest <dir>` sets the folder (default `scenes/from-traces`) and `--force` replaces a `scene.yaml` that is already there.
|
|
11
11
|
|
|
12
12
|
Each test is a folder, `scenes/from-traces/trace-<id>/`: `scene.yaml` (the trigger or the customer, the tools, the checks), `observations.jsonl` (production's calls with their answers), `production.jsonl` (production's run), `production.json` (each check's result in production), `provenance.json` and `questions.json`.
|
package/lib/assets/ui/app.js
CHANGED
|
@@ -729,6 +729,9 @@ function toolView(observation2, tool, options = {}) {
|
|
|
729
729
|
if (!observation2.state?.[tool]) return empty2(`${toolName(tool)} data is unavailable for this trial.`);
|
|
730
730
|
return renderers[tool](observation2, options);
|
|
731
731
|
}
|
|
732
|
+
function recordsView(observation2, tool, options = {}) {
|
|
733
|
+
return projectedTool(observation2, tool, options);
|
|
734
|
+
}
|
|
732
735
|
function projectedTool(o, tool, options) {
|
|
733
736
|
const view = o.toolViews?.[tool], tables = list2(view?.tables), conversations = list2(view?.conversations), active = tables.find((t) => t.title === options.resource) ?? tables[0];
|
|
734
737
|
if (!view) return empty2(`${toolName(tool)} records are not available in this capture.`);
|
|
@@ -1378,7 +1381,7 @@ function mountWorldWorkspace(node, options) {
|
|
|
1378
1381
|
function render() {
|
|
1379
1382
|
if (disposed) return;
|
|
1380
1383
|
const currentRuns = selected ? setupRuns(runs, selected) : [], run = currentRuns[0], attempts = run?.attempts ?? [], tasks = selected?.tasks ?? [], choices = worldSetups(tests, world.id, agentId);
|
|
1381
|
-
node.innerHTML = `<div class="ww-workspace"><header class="ww-header"><h1>${h(world.name)}</h1><div class="ww-world-actions"><label class="ww-agent-select">Agent<select data-ww-select="agent"><option value="" disabled>Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${a.id === agentId ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><button type="button" data-ww="configure">Configure</button>${selected ? options.runActions?.(selected.id) ?? button("Run tasks", "run-saved-test", selected.id, "primary") : ""}</div></header>${peopleSection(world)}<p class="ww-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</p>${errors.map((e) => `<p class="ww-error" role="alert">${h(e.message)}</p>`).join("")}${!loaded ? '<p role="status">Loading tasks\u2026</p>' : ""}${choices.length > 1 ? `<label class="ww-setup-select">Configuration<select data-ww-select="test">${!selected ? '<option value="" selected disabled>New configuration</option>' : ""}${choices.map((t) => `<option value="${h(t.id)}" ${t.id === selected?.id ? "selected" : ""}>${h(t.name)}</option>`).join("")}</select></label>` : ""}${loaded && configure ? configuration2() : loaded ? `${summaryWidgets(attempts, hasChecks(run?.tasks ?? tasks), run?.summary?.counts?.requested ?? attempts.length)}<div class="ww-section-heading"><h2>Tasks${tasks.length ? ` <span class="ww-task-count">${tasks.length}</span>` : ""}</h2><div class="actions">${worldHistory(runs, world.id, agentId || void 0).length || selected ? `<button type="button" data-ww="history" aria-expanded="${showHistory}">History</button>` : ""}<button type="button" data-ww="configure">${tasks.length ? "Edit tasks" : "Add tasks"}</button></div></div>${tasks.length ? `<section class="ww-task-table"><div class="ww-table-head"><span>Task</span><span>Result</span><span>Attempts</span><span>Median</span><span></span></div>${tasks.map((task, index) => {
|
|
1384
|
+
node.innerHTML = `<div class="ww-workspace"><header class="ww-header"><h1>${h(world.name)}</h1><div class="ww-world-actions"><label class="ww-agent-select">Agent<select data-ww-select="agent"><option value="" disabled>Choose agent</option>${agents.map((a) => `<option value="${h(a.id)}" ${a.id === agentId ? "selected" : ""}>${h(agentLabel(a, agents))}</option>`).join("")}</select></label><a data-nav class="button-link" href="${base}?data=1">View data</a><button type="button" data-ww="configure">Configure</button>${selected ? options.runActions?.(selected.id) ?? button("Run tasks", "run-saved-test", selected.id, "primary") : ""}</div></header>${peopleSection(world)}<p class="ww-error" role="alert" ${error ? "" : "hidden"}>${h(error)}</p>${errors.map((e) => `<p class="ww-error" role="alert">${h(e.message)}</p>`).join("")}${!loaded ? '<p role="status">Loading tasks\u2026</p>' : ""}${choices.length > 1 ? `<label class="ww-setup-select">Configuration<select data-ww-select="test">${!selected ? '<option value="" selected disabled>New configuration</option>' : ""}${choices.map((t) => `<option value="${h(t.id)}" ${t.id === selected?.id ? "selected" : ""}>${h(t.name)}</option>`).join("")}</select></label>` : ""}${loaded && configure ? configuration2() : loaded ? `${summaryWidgets(attempts, hasChecks(run?.tasks ?? tasks), run?.summary?.counts?.requested ?? attempts.length)}<div class="ww-section-heading"><h2>Tasks${tasks.length ? ` <span class="ww-task-count">${tasks.length}</span>` : ""}</h2><div class="actions">${worldHistory(runs, world.id, agentId || void 0).length || selected ? `<button type="button" data-ww="history" aria-expanded="${showHistory}">History</button>` : ""}<button type="button" data-ww="configure">${tasks.length ? "Edit tasks" : "Add tasks"}</button></div></div>${tasks.length ? `<section class="ww-task-table"><div class="ww-table-head"><span>Task</span><span>Result</span><span>Attempts</span><span>Median</span><span></span></div>${tasks.map((task, index) => {
|
|
1382
1385
|
const list4 = attempts.filter((a) => a.taskId === task.id), taskURL = run ? `/playgrounds/${enc(run.id)}?task=${enc(task.id)}${list4[0] ? "&attempt=" + enc(list4[0].id) : ""}` : "";
|
|
1383
1386
|
return `<article class="ww-task-row"><div class="ww-task-identity">${taskURL ? `<a data-nav class="ww-task-name" href="${taskURL}"><span class="ww-ordinal">${index + 1}</span><strong>${h(label(task, index))}</strong></a>` : `<strong class="ww-task-name"><span class="ww-ordinal">${index + 1}</span>${h(label(task, index))}</strong>`}<p class="ww-task-prompt" title="${h(task.prompt)}">${h(task.prompt)}</p></div>${(() => {
|
|
1384
1387
|
const o = taskOutcome(list4, hasChecks([task]), Number(task.attempts) || list4.length);
|
|
@@ -1536,6 +1539,19 @@ function worldHasActiveRuns(runs, worldId) {
|
|
|
1536
1539
|
return runs.some((run) => !terminal(run.status) && (run.entries?.length ? run.entries.some((entry) => entry.world?.id === worldId) : run.world?.id === worldId));
|
|
1537
1540
|
}
|
|
1538
1541
|
|
|
1542
|
+
// frontend/src/world-data.ts
|
|
1543
|
+
function worldDataPage(title2, context, back, data, base, query) {
|
|
1544
|
+
const tools = Array.isArray(data.tools) ? data.tools : [], tool = tools.includes(query.get("tool") ?? "") ? query.get("tool") : tools[0];
|
|
1545
|
+
const link = (name) => {
|
|
1546
|
+
const next = new URLSearchParams(base.split("?")[1]);
|
|
1547
|
+
next.set("tool", name);
|
|
1548
|
+
return `${base.split("?")[0]}?${next}`;
|
|
1549
|
+
};
|
|
1550
|
+
const tabs = tools.map((name) => `<a data-nav class="${name === tool ? "active" : ""}" href="${h(link(name))}" ${name === tool ? 'aria-current="page"' : ""}><span class="world-data-logo" aria-hidden="true">${toolLogo(name)}</span>${h(toolName(name))}</a>`).join("");
|
|
1551
|
+
const options = Object.fromEntries([...query].filter(([key]) => key === "resource" || key === "conversation"));
|
|
1552
|
+
return `<a data-nav class="back" href="${h(back.href)}">\u2190 ${h(back.label)}</a><header class="page-head"><div><h1>${h(title2)}</h1><p class="page-meta">${h(context)}</p></div></header><p class="world-data-note">Starting data, before any run. Read-only.</p>` + (tools.length ? `<nav class="tabs world-data-tabs" aria-label="Tools">${tabs}</nav>${recordsView(data, tool, { ...options, embedded: true, baseHref: link(tool) })}` : '<div class="quiet-empty">This world has no tools.</div>');
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1539
1555
|
// frontend/src/workspace-view.ts
|
|
1540
1556
|
var VIEW_SECTIONS = /* @__PURE__ */ new Set(["worlds", "agents", "playgrounds", "settings", "help", "tools"]);
|
|
1541
1557
|
var viewMode = (boot2) => boot2.mode === "view";
|
|
@@ -1639,7 +1655,7 @@ function starterCount(tool, key, state) {
|
|
|
1639
1655
|
}
|
|
1640
1656
|
|
|
1641
1657
|
// frontend/src/generated/coding-agent-skill.ts
|
|
1642
|
-
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, and prove a fix with graded runs. 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, 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.\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`; everything else prints one JSON object. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, scene files 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## The loop\n\n1. `ancha init --agent \"<the command that starts the agent>\"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/` (when `scenes/` holds no tests yet), the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.\n2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.\n3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.\n4. `ancha explain latest --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.\n5. `ancha baseline save before` keeps the failing run as the reference.\n6. Fix the agent's code.\n7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.\n\nWith production traces (an export from the user's tracing), `ancha import --offline <trace file> --json` writes one test per conversation under `scenes/from-traces/`, and `ancha run scenes/from-traces/*/scene.yaml --json` runs them. More: `ancha docs traces`.\n\nThe starter scene only proves that the agent reaches each tool. For the agent's real job, `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 scene can make on it. More: `ancha docs scenes`.\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 trial 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 trial: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## From a production failure\n\nA production run that went wrong becomes a test here. With a trace file (an export from the user's tracing):\n\n1. `ancha import --offline <trace file> --json` makes the test on this computer and uploads nothing. It writes `scenes/from-traces/<name>/scene.yaml` and lists the questions one trace cannot settle, each with the default the test uses.\n2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).\n3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; 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), `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`
|
|
1658
|
+
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, and prove a fix with graded runs. 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, 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.\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`; everything else prints one JSON object. `ancha schema <kind> --json` prints the JSON Schema of `ancha.yaml`, scene files 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## The loop\n\n1. `ancha init --agent \"<the command that starts the agent>\"`, once, in the agent's project, if it has no `ancha.yaml` yet. It writes `ancha.yaml`, `scenes/starter/` (when `scenes/` holds no tests yet), the coding-agent skill, and `.ancha/` in `.gitignore`. It installs and runs nothing.\n2. `ancha doctor --json` checks the config and scenes and runs the agent once. A tool the agent didn't call is a warning, not a failure.\n3. `ancha run --json` runs every scene in fresh worlds. Exit 1 means a check failed.\n4. `ancha explain latest --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.\n5. `ancha baseline save before` keeps the failing run as the reference.\n6. Fix the agent's code.\n7. `ancha run --compare before --json` proves the fix: exit 0 means every check passes and nothing regressed.\n\nWith production traces (an export from the user's tracing), `ancha import --offline <trace file> --json` writes one test per conversation under `scenes/from-traces/`, and `ancha run scenes/from-traces/*/scene.yaml --json` runs them. More: `ancha docs traces`.\n\nThe starter scene only proves that the agent reaches each tool. For the agent's real job, `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 scene can make on it. More: `ancha docs scenes`.\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 trial 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 trial: a new world has new URLs and tokens, and stale rows or sync cursors make an app silently do nothing.\n\n## From a production failure\n\nA production run that went wrong becomes a test here. With a trace file (an export from the user's tracing):\n\n1. `ancha import --offline <trace file> --json` makes the test on this computer and uploads nothing. It writes `scenes/from-traces/<name>/scene.yaml` and lists the questions one trace cannot settle, each with the default the test uses.\n2. Ask the user for the answers; don't guess them. Pass them with `--answer <question>=<value>` and import again with `--force` (`ancha docs apps`).\n3. `ancha run` on the `scene.yaml` against the version that failed in production should fail the same way. That is where the loop above starts. If it doesn't, `ancha traces diff <trace file> latest` shows the calls production made and the trial didn't; 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. A workspace that doesn't take traces says so; use the file. More: `ancha docs traces`.\n\n## The rule\n\nFix the agent, not `ancha.yaml`, the scenes or their checks. 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 scenes, 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 trial 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.\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\n`ancha run` starts the agent on this computer. It has this computer's network, and an environment limited to Ancha's variables, the tools' variables and the names allowed in `agent.pass_env` in `ancha.yaml` (or `--pass-env NAME`). The agent's own model key is one of those names: `agent.pass_env: [OPENROUTER_API_KEY]` passes it from this shell, and `agent.env` sets fixed values, such as the path of a key file. Without it, an agent that calls a model stops at its first call. For a sealed run, set `agent.execution: { mode: container, image: node:24-slim }` in `ancha.yaml`; it needs Docker.\n\n## Hosted workspace\n\nIf the user has an Ancha workspace, `ancha login` asks them to approve this computer once in the browser; ask them to do it. After that, `ancha run` still runs its worlds on this computer; `ancha run --upload --json` sends the finished run to their workspace, where the console shows it (`upload.url` in the JSON). `ancha whoami --json` shows the workspace and where runs put their worlds. In CI, `ANCHA_SERVER_URL` and `ANCHA_API_KEY` replace the login: `ancha run --local --upload --json`. `ancha secrets set NAME` copies a provider key from this shell into the workspace for agents that run there.\n\nRunning the agent itself in the cloud is a console flow at https://app.ancha.io: Bring your agent, Connect, tasks with checks, Run. Send the user there for it.\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 latest --json`.\n- Exit 2: usage, config, scene or authentication error. `AUTH_INVALID` means `ancha login` again or a valid `ANCHA_API_KEY`. Read the `hint`.\n- Exit 3: infrastructure, or a trial the harness couldn't complete. That's not the agent's fault; run again, and `ancha doctor --json` if it repeats.\n- Exit 4, only with `--strict`: the agent called an endpoint a replica doesn't implement. `ancha explain` lists these coverage gaps even without `--strict`; check `ancha twins coverage <tool>` before changing the agent.\n\nEvery error has a stable `code` and a `hint` that names the next command. 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, the pass rate and the evidence. Never claim a fix until `ancha run --compare` exits 0.\n";
|
|
1643
1659
|
|
|
1644
1660
|
// frontend/src/workspace-pages.ts
|
|
1645
1661
|
var startSentence = "Test our agent with Ancha. Start with: npx -y @ancha-labs/cli init, then read https://app.ancha.io/llms.txt";
|
|
@@ -2398,6 +2414,7 @@ var viewMode2 = () => viewMode(boot);
|
|
|
2398
2414
|
var viewBanner2 = () => viewBanner(boot);
|
|
2399
2415
|
var worldsAnswer = {};
|
|
2400
2416
|
var agentsAnswer = {};
|
|
2417
|
+
var worldData;
|
|
2401
2418
|
var startTimer;
|
|
2402
2419
|
function adoptBoot(next) {
|
|
2403
2420
|
const was = viewMode2();
|
|
@@ -2491,6 +2508,10 @@ function shell(section, content) {
|
|
|
2491
2508
|
const nav2 = (items) => items.map(([id, name]) => `<a href="/${id}" data-nav class="nav-item ${section === id ? "active" : ""}" ${section === id ? 'aria-current="page"' : ""}>${name}</a>`).join("");
|
|
2492
2509
|
root.innerHTML = `<aside class="sidebar"><a href="/worlds" class="brand" data-nav>ancha</a><nav class="app-nav" aria-label="Main navigation">${nav2([["worlds", "Worlds"], ["agents", "Agents"], ["playgrounds", "Runs"], ["tools", "Tools"]])}</nav><div class="workspace"><span id="connection" class="connection warn" role="status"${failedProbes < 2 ? " hidden" : ""}>${failedProbes < 2 ? "" : "Can\u2019t reach the server. Retrying\u2026"}</span><a href="/help" data-nav>Help</a><a href="/settings" data-nav>Settings</a></div></aside><main id="main" tabindex="-1">${viewMode2() && viewServes(section, path()[1]) ? viewBanner2() : ""}${content}</main>`;
|
|
2493
2510
|
}
|
|
2511
|
+
function folderScenes(scenes) {
|
|
2512
|
+
if (!scenes.length) return "";
|
|
2513
|
+
return `<section class="folder-scenes" aria-labelledby="folder-scenes-title"><div class="section-title"><div><h2 id="folder-scenes-title">Scenes in this folder</h2><p class="muted">Open one to see its starting data before any run.</p></div></div><div class="world-catalog">${scenes.map((scene) => `<a class="world-catalog-item" href="/worlds?scene=${enc2(String(scene.key))}" data-nav><h2>${h(String(scene.title || scene.id))}</h2><div class="world-tool-icons" role="group" aria-label="Tools: ${h((scene.tools ?? []).map(toolName).join(", "))}">${(scene.tools ?? []).map((tool) => `<span title="${h(toolName(tool))}" role="img" aria-label="${h(toolName(tool))}">${toolLogo(tool)}</span>`).join("")}</div><p>${h(String(scene.path))}</p></a>`).join("")}</div></section>`;
|
|
2514
|
+
}
|
|
2494
2515
|
function worldToolIcons(world) {
|
|
2495
2516
|
const tools = [...new Set((world.configuration?.preset?.datasets ?? []).map((dataset) => dataset.tool))];
|
|
2496
2517
|
return `<div class="world-tool-icons" role="group" aria-label="Tools: ${h(tools.map(toolName).join(", "))}">${tools.map((tool) => `<span title="${h(toolName(tool))}" role="img" aria-label="${h(toolName(tool))}">${toolLogo(tool)}</span>`).join("")}</div>`;
|
|
@@ -2560,7 +2581,18 @@ async function load() {
|
|
|
2560
2581
|
} else if (section === "help" || section === "settings") {
|
|
2561
2582
|
shell(section, head(section === "help" ? "Help" : "Settings") + (section === "help" ? helpPage() : boot.hosted ? `<section class="settings-page"><h2>Hosted workspace</h2><dl class="hosted-urls">${boot.hosted.tier ? `<dt>This workspace</dt><dd>${ownRunsOff() ? 'Free \xB7 <a href="/account#hosted">Request hosted runs</a>' : 'Hosted runs \xB7 <a href="/account#hosted">Machine time</a>'}</dd>` : ""}${boot.hosted.console ? `<dt>Console</dt><dd><a href="${h(boot.hosted.console)}">${h(boot.hosted.console)}</a></dd><dt>World server</dt><dd><code>${h(boot.hosted.worldServer)}</code></dd>` : ""}</dl><p class="muted">For CI, set <code>ANCHA_SERVER_URL</code> to the world server and <code>ANCHA_API_KEY</code> to a key from <a href="/account">Account settings</a>. On your computer, <code>ancha login</code> sets both.</p></section>` : `<section class="settings-page"><h2>Local workspace</h2><p class="workspace-path">${h(boot.workspace)}</p><p class="muted">Agents, worlds, tests and results are saved here.</p></section>`));
|
|
2562
2583
|
} else if (section === "worlds") {
|
|
2563
|
-
const
|
|
2584
|
+
const q = new URLSearchParams(location.search), sceneKey = p[1] ? null : q.get("scene"), revision = q.get("revision");
|
|
2585
|
+
if (!viewMode2() && (sceneKey !== null || !!p[1] && p[1] !== "new" && q.has("data"))) {
|
|
2586
|
+
const source = sceneKey !== null ? `/scenarios/data?key=${enc2(sceneKey)}` : `/worlds/${enc2(p[1])}/data${revision ? `?revision=${enc2(revision)}` : ""}`;
|
|
2587
|
+
const data = worldData?.source === source && Date.now() - worldData.at < 6e4 ? worldData.data : await api(source);
|
|
2588
|
+
if (thisGeneration !== generation) return;
|
|
2589
|
+
if (worldData?.source !== source) worldData = { source, at: Date.now(), data };
|
|
2590
|
+
current = {};
|
|
2591
|
+
if (sceneKey !== null) shell("worlds", worldDataPage(String(data.scene?.title || data.scene?.path || "Scene"), String(data.scene?.path ?? ""), { href: "/worlds", label: "Worlds" }, data, `/worlds?scene=${enc2(sceneKey)}`, q));
|
|
2592
|
+
else shell("worlds", worldDataPage(String(data.world?.name ?? "World"), `Revision ${data.world?.revision}`, { href: `/worlds/${enc2(p[1])}`, label: String(data.world?.name ?? "World") }, data, `/worlds/${enc2(p[1])}?data=1${revision ? `&revision=${enc2(revision)}` : ""}`, q));
|
|
2593
|
+
return;
|
|
2594
|
+
}
|
|
2595
|
+
const [result2, registry, definitions, folder] = await Promise.all([api("/worlds"), api("/agents"), api("/playground-tests"), !p[1] && !viewMode2() ? api("/scenarios/folder").catch(() => ({ scenes: [] })) : Promise.resolve({ scenes: [] })]);
|
|
2564
2596
|
if (thisGeneration !== generation) return;
|
|
2565
2597
|
worldsAnswer = result2;
|
|
2566
2598
|
worlds = result2.worlds ?? [];
|
|
@@ -2590,7 +2622,7 @@ async function load() {
|
|
|
2590
2622
|
const ownAgents = agentCatalog.filter((a) => !/(^|\/)sample-agent\/?$/.test(String(a.cwd ?? "")));
|
|
2591
2623
|
const sampleRun = !p[1] && !ownAgents.length ? ((await api("/playgrounds")).runs ?? []).slice().sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)))[0] : void 0;
|
|
2592
2624
|
if (thisGeneration !== generation) return;
|
|
2593
|
-
if (!p[1]) document.querySelector("#worlds-page").innerHTML = (ownAgents.length ? "" : startCard(sampleRun?.id)) + (worlds.length ? `<div class="world-catalog">${worlds.map((world) => `<a class="world-catalog-item" href="/worlds/${enc2(world.id)}" data-nav><h2>${h(world.name)}</h2>${worldToolIcons(world)}<p>${worldTaskCounts.get(world.id) ?? 0} ${worldTaskCounts.get(world.id) === 1 ? "task" : "tasks"}</p></a>`).join("")}</div>` : `<section class="empty"><h2>No worlds yet</h2><a href="/worlds/new" data-nav class="button-link primary">Create world</a></section>`);
|
|
2625
|
+
if (!p[1]) document.querySelector("#worlds-page").innerHTML = (ownAgents.length ? "" : startCard(sampleRun?.id)) + (worlds.length ? `<div class="world-catalog">${worlds.map((world) => `<a class="world-catalog-item" href="/worlds/${enc2(world.id)}" data-nav><h2>${h(world.name)}</h2>${worldToolIcons(world)}<p>${worldTaskCounts.get(world.id) ?? 0} ${worldTaskCounts.get(world.id) === 1 ? "task" : "tasks"}</p></a>`).join("")}</div>` : `<section class="empty"><h2>No worlds yet</h2><a href="/worlds/new" data-nav class="button-link primary">Create world</a></section>`) + folderScenes(folder.scenes ?? []);
|
|
2594
2626
|
else mountWorlds(document.querySelector("#worlds-page"), worlds, toolCatalog, p[1], api, go);
|
|
2595
2627
|
}
|
|
2596
2628
|
} else if (section === "tools") {
|
|
@@ -2882,7 +2914,7 @@ function renderTools(selected) {
|
|
|
2882
2914
|
if (!tool) {
|
|
2883
2915
|
const ordered2 = [...toolCatalog].sort((a, b) => (toolOrder.indexOf(a.name) + 99) % 99 - (toolOrder.indexOf(b.name) + 99) % 99);
|
|
2884
2916
|
const cliNote = boot.hosted ? '<p class="tools-cli-note">These replicas come with this workspace. To use all of them from your computer, update your CLI: <code>npm install -g @ancha-labs/cli@latest</code></p>' : "";
|
|
2885
|
-
shell("tools", head("Tools", "", "Replicas of the APIs agents call. Every attempt gets its own copy, seeded with the data shown on each tool.") + cliNote + `<div class="tools-grid">${ordered2.map((t) => {
|
|
2917
|
+
shell("tools", head("Tools", '<a class="button-link" href="mailto:patrick@ancha.io?subject=Tool%20request">Request a tool</a>', "Replicas of the APIs agents call. Every attempt gets its own copy, seeded with the data shown on each tool.") + cliNote + `<div class="tools-grid">${ordered2.map((t) => {
|
|
2886
2918
|
const d2 = t.descriptor ?? {}, endpoints2 = (t.coverage ?? []).length, version = String(d2.version ?? "");
|
|
2887
2919
|
const api2 = version && !/[A-Za-z]{3,}/.test(version.replace(/subset/g, "")) ? `API ${version}` : version;
|
|
2888
2920
|
return `<a class="tool-card" data-nav href="/tools/${enc2(t.name)}"><div class="tool-card-head">${toolLogo(t.name)}<div><strong>${h(toolName(t.name))}</strong><span>${h(toolCategory[t.name] ?? "Tool")}</span></div></div><p>${h(d2.description ?? toolDescription(t.name))}</p><div class="tool-card-foot"><span>${h(api2)}</span><span>${endpoints2} endpoint${endpoints2 === 1 ? "" : "s"}</span></div></a>`;
|
package/lib/assets/ui/style.css
CHANGED
|
@@ -513,3 +513,5 @@ body.navigating main{opacity:.55;transition:opacity .15s .25s;cursor:progress}
|
|
|
513
513
|
/* The console as a view of the workspace (hosting spec §3.4) */
|
|
514
514
|
.view-banner{display:flex;align-items:center;gap:16px;margin:0 0 24px;padding:16px 18px;border:1px solid var(--line);border-radius:10px;background:var(--raised,#fafaf8)}.view-banner>div{flex:1;min-width:0}.view-banner strong{display:block;font-weight:600}.view-banner p{margin:4px 0 0;color:var(--muted);font-size:13px}.view-banner button{flex:none}.view-note{color:var(--muted);font-size:13px}
|
|
515
515
|
@media (max-width:560px){.view-banner{flex-direction:column;align-items:flex-start}}
|
|
516
|
+
/* A world's starting data before any run (SPEC-027) */
|
|
517
|
+
.world-data-note{margin:-12px 0 20px;color:var(--muted);font-size:13px}.world-data-tabs{display:flex;flex-wrap:wrap;gap:4px 22px}.world-data-tabs a{gap:8px;align-items:center}.world-data-logo{display:inline-flex;width:16px;height:16px}.world-data-logo svg,.world-data-logo img{width:16px;height:16px}.folder-scenes{margin-top:36px}.folder-scenes .world-catalog-item p{overflow-wrap:anywhere;font-size:12px}.ww-world-actions .button-link{color:var(--ink)}
|
package/lib/worker.mjs
CHANGED
|
@@ -184932,6 +184932,7 @@ function trialDuration(ms) {
|
|
|
184932
184932
|
}
|
|
184933
184933
|
var plural4 = (n, one7, many = `${one7}s`) => `${n} ${n === 1 ? one7 : many}`;
|
|
184934
184934
|
function progressLine(e, scenes) {
|
|
184935
|
+
if (e.event === "trace_skipped" && typeof e.trace === "string" && typeof e.reason === "string") return `skipped trace ${e.trace.slice(0, 8)}: ${e.reason}`;
|
|
184935
184936
|
if (e.event === "run_started" && typeof e.runId === "string" && Array.isArray(e.scenes) && typeof e.trials === "number" && typeof e.parallel === "number") {
|
|
184936
184937
|
if (typeof e.replayOf === "string") return `${e.runId}: replay of ${e.replayOf}`;
|
|
184937
184938
|
const what = e.scenes.length === 1 ? `${plural4(e.trials, "trial")} of ${String(e.scenes[0])}` : `${plural4(e.trials, "trial")} each of ${e.scenes.length} scenes`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, locally or hosted at app.ancha.io.",
|
|
6
6
|
"bugs": {
|