@ancha-labs/cli 0.2.0 → 0.2.1
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 +125 -20
- package/lib/assets/SKILL.md +1 -1
- package/lib/assets/docs/apps.md +7 -5
- package/lib/assets/docs/integrations.md +1 -1
- package/lib/assets/docs/run.md +2 -0
- package/lib/assets/harbor/companion.mjs +25 -4
- package/lib/assets/ui/app.js +1 -1
- package/lib/worker.mjs +27 -6
- package/lib/world-server.mjs +23 -2
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -43733,7 +43733,7 @@ function toolConnectionEnvironment(services2) {
|
|
|
43733
43733
|
break;
|
|
43734
43734
|
// the official client's rootUrl is this URL plus '/'
|
|
43735
43735
|
case "gmail":
|
|
43736
|
-
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token });
|
|
43736
|
+
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token, GMAIL_ADDRESS: s.address });
|
|
43737
43737
|
break;
|
|
43738
43738
|
case "amazon-s3":
|
|
43739
43739
|
add({ AWS_ENDPOINT_URL_S3: s.url, AWS_ACCESS_KEY_ID: s.accessKey, AWS_SECRET_ACCESS_KEY: s.accessKeySecret, AWS_REGION: "us-east-1" });
|
|
@@ -95034,7 +95034,7 @@ function agentTemplateVars(envId, services2, task2, trial, session, runtime2) {
|
|
|
95034
95034
|
if (s.tlsRootCertificate !== void 0) vars[`${twin}.tls_root_certificate`] = s.tlsRootCertificate;
|
|
95035
95035
|
if (s.accessKey !== void 0) vars[`${twin}.access_key`] = s.accessKey;
|
|
95036
95036
|
if (s.accessKeySecret !== void 0) vars[`${twin}.access_key_secret`] = s.accessKeySecret;
|
|
95037
|
-
const nativeFields = twin === "datadog" ? [["api_key", s.apiKey], ["app_key", s.appKey], ["webhook_token", s.webhookToken]] : twin === "pagerduty" ? [["from_email", s.fromEmail], ["routing_key", s.routingKey]] : [];
|
|
95037
|
+
const nativeFields = twin === "datadog" ? [["api_key", s.apiKey], ["app_key", s.appKey], ["webhook_token", s.webhookToken]] : twin === "pagerduty" ? [["from_email", s.fromEmail], ["routing_key", s.routingKey]] : twin === "gmail" ? [["address", s.address]] : [];
|
|
95038
95038
|
for (const [field4, value5] of nativeFields) {
|
|
95039
95039
|
if (value5 !== void 0) vars[`${twin}.${field4}`] = value5;
|
|
95040
95040
|
}
|
|
@@ -95098,7 +95098,7 @@ function agentSetupPayload(env2, scene2, agent, trial, session, runtime2) {
|
|
|
95098
95098
|
function validateAgentEnv(scene2, agent) {
|
|
95099
95099
|
if (agent.taskInput) parseTaskInput(agent.taskInput);
|
|
95100
95100
|
const services2 = {};
|
|
95101
|
-
for (const twin of scene2.twins) services2[twin] = { url: "http://localhost", hostUrl: "http://localhost", token: "", signingSecret: "", ...twin === "slack" ? { appToken: "" } : {}, ...twin === "datadog" ? { apiKey: "", appKey: "", webhookToken: "" } : {}, ...twin === "pagerduty" ? { fromEmail: "", routingKey: "", routingKeys: {} } : {}, ...twin === "gong" ? { accessKey: "", accessKeySecret: "" } : {}, ...twin === "google-ads" ? { grpcEndpoint: "localhost:1", tlsRootCertificate: "" } : {} };
|
|
95101
|
+
for (const twin of scene2.twins) services2[twin] = { url: "http://localhost", hostUrl: "http://localhost", token: "", signingSecret: "", ...twin === "slack" ? { appToken: "" } : {}, ...twin === "gmail" ? { address: "" } : {}, ...twin === "datadog" ? { apiKey: "", appKey: "", webhookToken: "" } : {}, ...twin === "pagerduty" ? { fromEmail: "", routingKey: "", routingKeys: {} } : {}, ...twin === "gong" ? { accessKey: "", accessKeySecret: "" } : {}, ...twin === "google-ads" ? { grpcEndpoint: "localhost:1", tlsRootCertificate: "" } : {} };
|
|
95102
95102
|
const session = { id: "", token: "", envId: "", eventsUrl: "http://localhost/events", doneUrl: "http://localhost/done", contextUrl: "http://localhost/context", state: "prepared" };
|
|
95103
95103
|
const runtime2 = { ...(agent.mode === "endpoint" && agent.start !== void 0 || agent.taskInput?.kind === "http") && { port: 34567 }, attempt: { id: "validation", caseId: scene2.id, stateDir: "/ancha/validation/agent-state", seed: "validation" } };
|
|
95104
95104
|
const vars = agentTemplateVars("", services2, "", 0, session, runtime2);
|
|
@@ -95118,7 +95118,7 @@ var init_agent_env = __esm({
|
|
|
95118
95118
|
init_agent_input();
|
|
95119
95119
|
BASE_ENV = ["PATH", "HOME", "USER", "LOGNAME", "SHELL", "LANG", "TERM", "TMPDIR", "TZ", "NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "VIRTUAL_ENV", "CONDA_PREFIX", "PYTHONPATH", "SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT"];
|
|
95120
95120
|
baseEnv = new Set(BASE_ENV);
|
|
95121
|
-
ANY_SERVICE = { url: "x", hostUrl: "x", token: "x", signingSecret: "x", appToken: "x", apiKey: "x", appKey: "x", webhookToken: "x", fromEmail: "x", routingKey: "x", routingKeys: {}, accessKey: "x", accessKeySecret: "x", clientSecret: "x", grpcEndpoint: "x", tlsRootCertificate: "x" };
|
|
95121
|
+
ANY_SERVICE = { url: "x", hostUrl: "x", token: "x", signingSecret: "x", appToken: "x", apiKey: "x", appKey: "x", webhookToken: "x", fromEmail: "x", address: "x", routingKey: "x", routingKeys: {}, accessKey: "x", accessKeySecret: "x", clientSecret: "x", grpcEndpoint: "x", tlsRootCertificate: "x" };
|
|
95122
95122
|
}
|
|
95123
95123
|
});
|
|
95124
95124
|
|
|
@@ -96891,6 +96891,9 @@ function mergeIr(stored, fresh) {
|
|
|
96891
96891
|
const records3 = [...kept, ...fresh.filter((l) => !l.ir && !(l.id && ids2.has(l.id)))].sort((a, b) => Date.parse(a.t) - Date.parse(b.t));
|
|
96892
96892
|
return [{ ...header4, ...records3.length && { started_at: records3[0].t } }, ...records3];
|
|
96893
96893
|
}
|
|
96894
|
+
function callKey(item2) {
|
|
96895
|
+
return `${item2.service} ${item2.method} ${item2.path.split("/").map((segment2) => RECORD_SEGMENT.test(segment2) ? ":id" : segment2).join("/")}`;
|
|
96896
|
+
}
|
|
96894
96897
|
function itemsOf(records3) {
|
|
96895
96898
|
const items = [];
|
|
96896
96899
|
for (const r of records3) {
|
|
@@ -96929,7 +96932,7 @@ function itemsOf(records3) {
|
|
|
96929
96932
|
}
|
|
96930
96933
|
return items.sort((a, b) => a.ms - b.ms);
|
|
96931
96934
|
}
|
|
96932
|
-
var VENDOR_API_BASES2, HOSTS, IrError;
|
|
96935
|
+
var VENDOR_API_BASES2, HOSTS, IrError, RECORD_SEGMENT;
|
|
96933
96936
|
var init_ir = __esm({
|
|
96934
96937
|
"cloud/rebuild/ir.mjs"() {
|
|
96935
96938
|
"use strict";
|
|
@@ -96953,6 +96956,7 @@ var init_ir = __esm({
|
|
|
96953
96956
|
HOSTS = new Map(Object.entries(VENDOR_API_BASES2).map(([service, base3]) => [new URL(base3).host, service]));
|
|
96954
96957
|
IrError = class extends Error {
|
|
96955
96958
|
};
|
|
96959
|
+
RECORD_SEGMENT = /^(?:[0-9a-f]{8,}|\d{3,}|[0-9a-f-]{36}|Label_\d+|[^/]*(?:@|%40)[^/]*|(?=[\w-]*\d)[\w-]{16,})$/i;
|
|
96956
96960
|
}
|
|
96957
96961
|
});
|
|
96958
96962
|
|
|
@@ -97479,7 +97483,7 @@ function readGmail(cx) {
|
|
|
97479
97483
|
function readAppCalls(cx) {
|
|
97480
97484
|
const inbound = cx.inbound("app").filter((i) => i.route);
|
|
97481
97485
|
if (!inbound.length) return;
|
|
97482
|
-
cx.ask("app.auth", "What Authorization header do the app's own scheduled calls carry in tests?
|
|
97486
|
+
cx.ask("app.auth", "What Authorization header do the app's own scheduled calls carry in tests? The trace never records headers; answer with the whole value, such as Bearer <test secret>.", ["none", "Bearer <test secret>"]);
|
|
97483
97487
|
const auth2 = cx.answers["app.auth"];
|
|
97484
97488
|
(cx.rules.app_calls ??= []).push(...inbound.map((i) => ({
|
|
97485
97489
|
at: cx.dur(i.ms - cx.start),
|
|
@@ -100316,9 +100320,11 @@ var rebuild_exports = {};
|
|
|
100316
100320
|
__export(rebuild_exports, {
|
|
100317
100321
|
REBUILT: () => REBUILT,
|
|
100318
100322
|
answerErrors: () => answerErrors,
|
|
100323
|
+
callKey: () => callKey,
|
|
100319
100324
|
decodeOtlpProto: () => decodeOtlpProto,
|
|
100320
100325
|
fileToIr: () => fileToIr,
|
|
100321
100326
|
intakeOf: () => intakeOf,
|
|
100327
|
+
itemsOf: () => itemsOf,
|
|
100322
100328
|
mergeIr: () => mergeIr,
|
|
100323
100329
|
otlpToIr: () => otlpToIr,
|
|
100324
100330
|
parseIr: () => parseIr,
|
|
@@ -100330,7 +100336,7 @@ function rebuild(ir, { id: id12 = "rebuilt-from-trace", title, task: task2, answ
|
|
|
100330
100336
|
const { header: header4, records: records3 } = typeof ir === "string" ? parseIr(ir) : { header: ir.find((l) => l.ir), records: ir.filter((l) => !l.ir) };
|
|
100331
100337
|
const cx = createContext(itemsOf(records3));
|
|
100332
100338
|
cx.answers = answers ?? {};
|
|
100333
|
-
if (!cx.items.length) throw new Error("the trace has no API calls or webhooks Ancha can read");
|
|
100339
|
+
if (!cx.items.length) throw Object.assign(new Error("the trace has no API calls or webhooks Ancha can read"), { code: "NO_CALLS" });
|
|
100334
100340
|
task2 ??= inferTask(cx, records3);
|
|
100335
100341
|
const slack2 = readSlack(cx), github2 = readGitHub(cx), datadog2 = readDatadog(cx), pagerduty = readPagerDuty(cx);
|
|
100336
100342
|
readGmail(cx);
|
|
@@ -100353,6 +100359,8 @@ function rebuild(ir, { id: id12 = "rebuilt-from-trace", title, task: task2, answ
|
|
|
100353
100359
|
for (const service of read6) if (!cx.seed[service]) cx.note("missing", `seed.${service}`, `calls to ${service} were seen, but Ancha cannot rebuild ${service} yet`);
|
|
100354
100360
|
const lastMs = Math.max(0, ...[...cx.rules.actors ?? [], ...cx.rules.app_calls ?? []].filter((r) => "at" in r).map((r) => parseMs(r.at)));
|
|
100355
100361
|
const long = lastMs > 10 * 6e4;
|
|
100362
|
+
const firstMs = Math.min(...[...cx.rules.actors ?? [], ...cx.rules.app_calls ?? []].filter((r) => "at" in r).map((r) => parseMs(r.at)));
|
|
100363
|
+
const setup2 = cx.rules.app_calls?.length ? cx.items.filter((i) => i.kind === "call" && i.ms - cx.start < firstMs).map(callKey) : [];
|
|
100356
100364
|
const scene2 = {
|
|
100357
100365
|
id: id12,
|
|
100358
100366
|
title: title ?? `Rebuilt from trace ${header4?.trace_id ?? ""}`.trim(),
|
|
@@ -100373,6 +100381,7 @@ function rebuild(ir, { id: id12 = "rebuilt-from-trace", title, task: task2, answ
|
|
|
100373
100381
|
provenance: cx.provenance,
|
|
100374
100382
|
questions: cx.questions,
|
|
100375
100383
|
production: cx.production,
|
|
100384
|
+
setup: setup2,
|
|
100376
100385
|
summary: { trace: header4?.trace_id, agent: header4?.agent, records: records3.length, observed: count3("observed"), inferred: count3("inferred"), missing: count3("missing"), questions: cx.questions.length, production: cx.production }
|
|
100377
100386
|
};
|
|
100378
100387
|
}
|
|
@@ -138759,7 +138768,7 @@ function seed15(ctx) {
|
|
|
138759
138768
|
function credentials14(ctx) {
|
|
138760
138769
|
const agent = ctx.scene.seed.gmail?.agent ?? ctx.store.db.prepare("SELECT address FROM gmail_mailboxes ORDER BY ordinal LIMIT 1").get().address;
|
|
138761
138770
|
const row = ctx.store.db.prepare("SELECT token FROM gmail_tokens WHERE mailbox = ?").get(agent);
|
|
138762
|
-
return { token: row.token };
|
|
138771
|
+
return { token: row.token, address: agent };
|
|
138763
138772
|
}
|
|
138764
138773
|
|
|
138765
138774
|
// packages/server/src/twins/gmail/state.ts
|
|
@@ -138811,11 +138820,32 @@ ${m.thread_id}`;
|
|
|
138811
138820
|
}
|
|
138812
138821
|
|
|
138813
138822
|
// packages/server/src/twins/gmail/index.ts
|
|
138814
|
-
var
|
|
138823
|
+
var GOOGLE_OPENID_CONFIGURATION = {
|
|
138824
|
+
issuer: "https://accounts.google.com",
|
|
138825
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
138826
|
+
device_authorization_endpoint: "https://oauth2.googleapis.com/device/code",
|
|
138827
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
138828
|
+
userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo",
|
|
138829
|
+
revocation_endpoint: "https://oauth2.googleapis.com/revoke",
|
|
138830
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
138831
|
+
response_types_supported: ["code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token", "none"],
|
|
138832
|
+
subject_types_supported: ["public"],
|
|
138833
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
138834
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
138835
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
|
138836
|
+
claims_supported: ["aud", "email", "email_verified", "exp", "family_name", "given_name", "iat", "iss", "name", "picture", "sub"],
|
|
138837
|
+
code_challenge_methods_supported: ["plain", "S256"],
|
|
138838
|
+
grant_types_supported: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "urn:ietf:params:oauth:grant-type:jwt-bearer"]
|
|
138839
|
+
};
|
|
138840
|
+
var gmailCoverage = [
|
|
138841
|
+
...gmailRoutes.map(({ method: method2, path: path6, coverage: coverage4 }) => ({ method: method2, path: path6, ...coverage4 })),
|
|
138842
|
+
{ method: "GET", path: "/.well-known/openid-configuration", status: "supported", notes: "Google's discovery document; the endpoints it names are Google's" }
|
|
138843
|
+
];
|
|
138815
138844
|
function gmailTwin() {
|
|
138816
138845
|
const app2 = new Hono3();
|
|
138817
138846
|
for (const route11 of gmailRoutes) app2.on(route11.method, route11.path, handle(route11));
|
|
138818
138847
|
app2.post("/batch/gmail/v1", batchHandler(app2));
|
|
138848
|
+
app2.get("/.well-known/openid-configuration", (c) => c.json(GOOGLE_OPENID_CONFIGURATION));
|
|
138819
138849
|
app2.all("*", unknownRoute3);
|
|
138820
138850
|
return { name: "gmail", basePath: "", unprefixedPaths: /^\/(?:(?:(?:upload|batch)\/)?gmail\/v1(?:\/|$)|oauth2\/v2\/userinfo$)/, app: app2, migrate: migrate5, seed: seed15, credentials: credentials14, actions: gmailActions, checks: { thread }, dumpState: dumpState14, coverage: gmailCoverage };
|
|
138821
138851
|
}
|
|
@@ -201309,12 +201339,13 @@ async function interruptible(ctx, fn) {
|
|
|
201309
201339
|
}
|
|
201310
201340
|
}
|
|
201311
201341
|
function registerRun(program2, ctx) {
|
|
201312
|
-
program2.command("run").description("run an agent against scenes N times and summarize how often it passes (starts its own server unless one is configured)").argument("[scenes...]", "scene YAML files (default: the globs in scenes: of ancha.yaml)").option("--agent <cmd>", "shell command that runs the agent (default: agent.command in ancha.yaml)").option("--agent-url <url>", "endpoint URL (overrides agent.url; requires endpoint setup/start configuration)").option("-n, --trials <n>", "trials per scene (default: trials in ancha.yaml, else 5)").option("--parallel <n>", "trials running at once (default: parallel in ancha.yaml, else command 2 / endpoint 1)").option("--min-pass-rate <r>", "fraction of trials that must pass, 0 to 1 (default: min_pass_rate in ancha.yaml, else 1)").option("--seed <seed>", "seed for ids and randomness").option("--out <dir>", "where run directories go (default: .ancha/runs)").option("--strict", "exit 4 if the agent hit an endpoint Ancha does not implement").option("--detach", "continue in a private worker after this command exits; observe with status/wait").option("--compare <reference>", "compare against a completed run id or saved baseline; any per-scene decrease fails").option("--pass-env <name>", "give the agent this variable from this shell (repeatable); it otherwise gets only a base set (PATH, HOME, locale\u2026) plus Ancha's and the tools' variables", (name5, names3) => [...names3, name5], []).option("--inherit-env", "give the agent this shell's whole environment, including any real credentials (the behavior before 0.1.2)").option("--on <target>", "where the agent runs: local (a process on this computer), docker (a sealed container; needs agent.execution with an image in ancha.yaml) or cloud (scene/test import is currently unsupported; use local/CI or an explicit saved-world task via runs start). Default: what ancha.yaml says").option("--idempotency-key <key>", "retry safely: the same key and the same run definition return the original run instead of starting another").option("--upload", "send the finished run to your workspace, where the console shows it (also ANCHA_UPLOAD=1); a failed upload is a warning").option("--upload-required", "like --upload, but a failed upload fails the command").action(async (sceneArgs, opts, command) => {
|
|
201342
|
+
program2.command("run").description("run an agent against scenes N times and summarize how often it passes (starts its own server unless one is configured)").argument("[scenes...]", "scene YAML files (default: the globs in scenes: of ancha.yaml)").option("--agent <cmd>", "shell command that runs the agent (default: agent.command in ancha.yaml)").option("--agent-url <url>", "endpoint URL (overrides agent.url; requires endpoint setup/start configuration)").option("-n, --trials <n>", "trials per scene (default: trials in ancha.yaml, else 5)").option("--parallel <n>", "trials running at once (default: parallel in ancha.yaml, else command 2 / endpoint 1)").option("--min-pass-rate <r>", "fraction of trials that must pass, 0 to 1 (default: min_pass_rate in ancha.yaml, else 1)").option("--seed <seed>", "seed for ids and randomness").option("--out <dir>", "where run directories go (default: .ancha/runs)").option("--strict", "exit 4 if the agent hit an endpoint Ancha does not implement").option("--detach", "continue in a private worker after this command exits; observe with status/wait").option("--compare <reference>", "compare against a completed run id or saved baseline; any per-scene decrease fails").option("--pass-env <name>", "give the agent this variable from this shell (repeatable); it otherwise gets only a base set (PATH, HOME, locale\u2026) plus Ancha's and the tools' variables", (name5, names3) => [...names3, name5], []).option("--inherit-env", "give the agent this shell's whole environment, including any real credentials (the behavior before 0.1.2)").option("--on <target>", "where the agent runs: local (a process on this computer), docker (a sealed container; needs agent.execution with an image in ancha.yaml) or cloud (scene/test import is currently unsupported; use local/CI or an explicit saved-world task via runs start). Default: what ancha.yaml says").option("--idempotency-key <key>", "retry safely: the same key and the same run definition return the original run instead of starting another").option("--upload", "send the finished run to your workspace, where the console shows it (also ANCHA_UPLOAD=1); a failed upload is a warning").option("--upload-required", "like --upload, but a failed upload fails the command").option("--dry-run", "check ancha.yaml and every scene, print what would run, and stop: no server, no agent, no trial").action(async (sceneArgs, opts, command) => {
|
|
201313
201343
|
const { cwd } = ctx.io;
|
|
201314
201344
|
if (opts.agent === void 0 && opts.agentUrl === void 0 && ctx.globals().config === void 0 && !await access4(resolve23(cwd, "ancha.yaml")).then(() => true, () => false)) {
|
|
201315
201345
|
throw new AnchaError("USAGE", "no ancha.yaml here", { hint: 'run `ancha init` in your agent\'s project, or pass --agent "<command>"' });
|
|
201316
201346
|
}
|
|
201317
201347
|
const config9 = await ctx.loadConfig();
|
|
201348
|
+
if (opts.dryRun && opts.on === "cloud") throw new AnchaError("USAGE", "--dry-run checks a run on this computer", { hint: "leave out --on cloud" });
|
|
201318
201349
|
if (opts.on === "cloud") {
|
|
201319
201350
|
const issues = command.options.flatMap((option3) => {
|
|
201320
201351
|
const key3 = option3.attributeName();
|
|
@@ -201368,6 +201399,15 @@ function registerRun(program2, ctx) {
|
|
|
201368
201399
|
if (baseline !== void 0) {
|
|
201369
201400
|
assertComparableSummaries(summarize({ runId: "", dir: "", startedAt: "", finishedAt: "", results: new Map(scenes.map((scene2) => [scene2.id, { scene: scene2, trials: [] }])) }, "", minPassRate), baseline);
|
|
201370
201401
|
}
|
|
201402
|
+
if (opts.dryRun) {
|
|
201403
|
+
const plan3 = { dryRun: true, scenes: loaded.map((s) => ({ id: s.scene.id, path: s.path })), trials, parallel, minPassRate };
|
|
201404
|
+
ctx.out.result(plan3, () => [
|
|
201405
|
+
`${plan3.scenes.length} scene${plan3.scenes.length === 1 ? "" : "s"}, ${trials} trial${trials === 1 ? "" : "s"} each, ${parallel} at a time; ancha.yaml and every scene are valid`,
|
|
201406
|
+
...plan3.scenes.map((s) => ` ${s.id} ${s.path}`),
|
|
201407
|
+
"nothing was started (--dry-run)"
|
|
201408
|
+
].join("\n"));
|
|
201409
|
+
return;
|
|
201410
|
+
}
|
|
201371
201411
|
const choice4 = await worldServerChoice(ctx);
|
|
201372
201412
|
const serverUrl3 = choice4.url;
|
|
201373
201413
|
const workspace3 = workspaceOf(choice4.url, cwd);
|
|
@@ -202369,7 +202409,7 @@ var env = {
|
|
|
202369
202409
|
"chatgpt-ads": ["OPENAI_ADS_API_URL", "OPENAI_ADS_API_KEY"],
|
|
202370
202410
|
hubspot: ["HUBSPOT_API_URL", "HUBSPOT_ACCESS_TOKEN", "HUBSPOT_CLIENT_SECRET"],
|
|
202371
202411
|
ga4: ["GA4_API_URL", "GA4_ACCESS_TOKEN"],
|
|
202372
|
-
gmail: ["GMAIL_API_URL", "GMAIL_ACCESS_TOKEN"],
|
|
202412
|
+
gmail: ["GMAIL_API_URL", "GMAIL_ACCESS_TOKEN", "GMAIL_ADDRESS"],
|
|
202373
202413
|
"google-drive": ["GOOGLE_DRIVE_API_URL", "GOOGLE_DRIVE_ACCESS_TOKEN"],
|
|
202374
202414
|
"amazon-s3": ["AWS_ENDPOINT_URL_S3", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_REGION"],
|
|
202375
202415
|
linear: ["LINEAR_API_URL", "LINEAR_API_KEY"],
|
|
@@ -224729,15 +224769,20 @@ var import_yaml16 = __toESM(require_dist(), 1);
|
|
|
224729
224769
|
init_src();
|
|
224730
224770
|
var WorkspaceError = class extends AnchaError {
|
|
224731
224771
|
status;
|
|
224732
|
-
|
|
224772
|
+
noTraces;
|
|
224773
|
+
constructor(status5, message5, hint, noTraces = false) {
|
|
224733
224774
|
super("USAGE", message5, hint === void 0 ? {} : { hint });
|
|
224734
224775
|
this.status = status5;
|
|
224776
|
+
this.noTraces = noTraces;
|
|
224735
224777
|
}
|
|
224736
224778
|
};
|
|
224737
224779
|
function workspaceError(status5, body6, path6) {
|
|
224738
|
-
if (status5 === 404 && body6.error === void 0) return new WorkspaceError(404, "this workspace does not take traces yet", "ancha import --offline <trace file> makes the test on this computer; nothing is uploaded");
|
|
224780
|
+
if (status5 === 404 && body6.error === void 0) return new WorkspaceError(404, "this workspace does not take traces yet", "ancha import --offline <trace file> makes the test on this computer; nothing is uploaded", true);
|
|
224739
224781
|
return new WorkspaceError(status5, String(body6.error ?? `${path6}: HTTP ${status5}`));
|
|
224740
224782
|
}
|
|
224783
|
+
function notInWorkspace(error64) {
|
|
224784
|
+
return error64 instanceof WorkspaceError && error64.status === 404 && !error64.noTraces;
|
|
224785
|
+
}
|
|
224741
224786
|
async function workspaceApi(ctx) {
|
|
224742
224787
|
const workspace3 = await uploadWorkspace(ctx);
|
|
224743
224788
|
const key3 = await apiKeyFor(workspace3, ctx.io.env);
|
|
@@ -224925,7 +224970,7 @@ function registerTraces(program2, ctx) {
|
|
|
224925
224970
|
traces.command("show").argument("<id>", "a trace: its id, its first 8 characters, or the trace id your tracing tool shows").description("what a trace holds and the test it makes: what the agent is told, the world, the checks with what production did, the questions").action(async (id12) => {
|
|
224926
224971
|
const api3 = await workspaceApi(ctx);
|
|
224927
224972
|
const { trace, world: test3 } = await api3(`/v1/traces/${encodeURIComponent(id12)}`).catch((error64) => {
|
|
224928
|
-
if (error64
|
|
224973
|
+
if (notInWorkspace(error64)) throw new AnchaError("USAGE", `no trace ${id12} in your workspace`, { hint: "ancha traces lists them" });
|
|
224929
224974
|
throw error64;
|
|
224930
224975
|
});
|
|
224931
224976
|
const made = await api3(`/v1/traces/${trace.id}/preview`).then((body6) => ({ preview: body6.preview, world: body6.world }), (error64) => {
|
|
@@ -224964,6 +225009,33 @@ function registerTraces(program2, ctx) {
|
|
|
224964
225009
|
return lines.filter(Boolean).join("\n");
|
|
224965
225010
|
});
|
|
224966
225011
|
});
|
|
225012
|
+
traces.command("diff").argument("<trace>", "a production trace file: Ancha Trace IR (.jsonl) or an OTLP JSON export").argument("[attempt]", "an attempt of a finished run: <run id or latest>/<trial directory>, or a run (its first attempt)", "latest").option("--out <dir>", "where run directories are (default: .ancha/runs)").description("compare production's calls with an attempt's: calls only in one of them, and the first call where their order parts").action(async (file3, attempt, options3) => {
|
|
225013
|
+
const production3 = (await traceFileItems(ctx, file3)).filter((item2) => item2.kind === "call");
|
|
225014
|
+
const slash = attempt.indexOf("/"), trial = slash < 0 ? void 0 : attempt.slice(slash + 1);
|
|
225015
|
+
const summary = await loadRunSummary(ctx.io.cwd, slash < 0 ? attempt : attempt.slice(0, slash), options3.out);
|
|
225016
|
+
const dirs = summary.scenes.flatMap((scene2) => scene2.trialsDetail.map((detail2) => resolve40(ctx.io.cwd, detail2.dir)));
|
|
225017
|
+
const dir2 = trial === void 0 ? dirs[0] : dirs.find((path6) => basename12(path6) === trial);
|
|
225018
|
+
if (dir2 === void 0) throw new AnchaError("USAGE", trial === void 0 ? `run ${summary.runId} has no attempts` : `no attempt ${trial} in run ${summary.runId}`, { hint: `its attempts: ${dirs.map((path6) => basename12(path6)).join(", ") || "none"}` });
|
|
225019
|
+
const { callKey: callKey2, itemsOf: itemsOf2 } = await Promise.resolve().then(() => (init_rebuild(), rebuild_exports));
|
|
225020
|
+
const attemptCalls = itemsOf2(attemptToIr(await readAttemptTrace(dir2), basename12(dir2))).filter((item2) => item2.kind === "call");
|
|
225021
|
+
const result = {
|
|
225022
|
+
production: { file: file3, calls: production3.length },
|
|
225023
|
+
attempt: { id: `${summary.runId}/${basename12(dir2)}`, calls: attemptCalls.length },
|
|
225024
|
+
...diffCalls(production3.map(callKey2), attemptCalls.map(callKey2))
|
|
225025
|
+
};
|
|
225026
|
+
ctx.out.result(result, () => {
|
|
225027
|
+
const list16 = (calls2) => calls2.length ? calls2.map((c) => ` ${c.call}${c.count > 1 ? ` \xD7${c.count}` : ""}`) : [" none"];
|
|
225028
|
+
const first = result.firstDifference;
|
|
225029
|
+
return [
|
|
225030
|
+
`production ${basename12(file3)}: ${plural5(production3.length, "call")}; attempt ${result.attempt.id}: ${plural5(attemptCalls.length, "call")}`,
|
|
225031
|
+
"only in production:",
|
|
225032
|
+
...list16(result.onlyInProduction),
|
|
225033
|
+
"only in the attempt:",
|
|
225034
|
+
...list16(result.onlyInAttempt),
|
|
225035
|
+
first === null ? "the attempt made the same calls as production, in the same order" : `the order parts at call ${first.index}: production ${first.production ?? "(no more calls)"}; the attempt ${first.attempt ?? "(no more calls)"}`
|
|
225036
|
+
].join("\n");
|
|
225037
|
+
});
|
|
225038
|
+
});
|
|
224967
225039
|
program2.command("import").argument("<file>", "a trace: Ancha Trace IR (.jsonl) or an OTLP JSON export").option("--dest <dir>", "where the tests go", "scenes/from-traces").option("--force", "overwrite a scene.yaml already here even if it has changes besides checks you added").option("--offline", "turn the trace into a test on this computer; nothing is uploaded").option("--answer <question=value>", "with --offline: answer one of the test's questions; repeat for more", (value5, all8) => [...all8, value5], []).description("send a production trace to your workspace and save the test it makes (or, with --offline, make it here); writes the test here").action(async (file3, options3) => {
|
|
224968
225040
|
if (options3.offline) {
|
|
224969
225041
|
const made = await importLocally(ctx, file3, options3);
|
|
@@ -224984,7 +225056,7 @@ function registerTraces(program2, ctx) {
|
|
|
224984
225056
|
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("--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").description("write a test saved from a production trace into this project; a trace with no saved test gets one").action(async (id12, options3) => {
|
|
224985
225057
|
const api3 = await workspaceApi(ctx);
|
|
224986
225058
|
const found = (path6) => api3(path6).catch((error64) => {
|
|
224987
|
-
if (error64
|
|
225059
|
+
if (notInWorkspace(error64)) return null;
|
|
224988
225060
|
throw error64;
|
|
224989
225061
|
});
|
|
224990
225062
|
const ref20 = encodeURIComponent(id12);
|
|
@@ -225005,25 +225077,52 @@ function registerTraces(program2, ctx) {
|
|
|
225005
225077
|
await report6(ctx, world5, await writeWorld(ctx, world5, options3.dest, changes));
|
|
225006
225078
|
});
|
|
225007
225079
|
}
|
|
225008
|
-
async function
|
|
225080
|
+
async function traceFileLines(ctx, file3) {
|
|
225009
225081
|
const text24 = await readFile38(resolve40(ctx.io.cwd, file3), "utf8").catch(() => {
|
|
225010
225082
|
throw new AnchaError("USAGE", `cannot read ${file3}`);
|
|
225011
225083
|
});
|
|
225012
|
-
const { fileToIr: fileToIr2, mergeIr: mergeIr2
|
|
225084
|
+
const { fileToIr: fileToIr2, mergeIr: mergeIr2 } = await Promise.resolve().then(() => (init_rebuild(), rebuild_exports));
|
|
225013
225085
|
let docs2;
|
|
225014
225086
|
try {
|
|
225015
225087
|
docs2 = fileToIr2(text24, basename12(file3));
|
|
225016
225088
|
} catch (error64) {
|
|
225017
225089
|
throw new AnchaError("USAGE", `${file3}: ${error64 instanceof Error ? error64.message : String(error64)}`);
|
|
225018
225090
|
}
|
|
225019
|
-
|
|
225091
|
+
return { text: text24, lines: docs2.map((doc) => doc.lines).reduce((merged, next2) => mergeIr2(merged, next2)) };
|
|
225092
|
+
}
|
|
225093
|
+
async function traceFileItems(ctx, file3) {
|
|
225094
|
+
const { itemsOf: itemsOf2 } = await Promise.resolve().then(() => (init_rebuild(), rebuild_exports));
|
|
225095
|
+
return itemsOf2((await traceFileLines(ctx, file3)).lines);
|
|
225096
|
+
}
|
|
225097
|
+
function diffCalls(production3, attempt) {
|
|
225098
|
+
const counts = (calls2) => calls2.reduce((all8, call2) => all8.set(call2, (all8.get(call2) ?? 0) + 1), /* @__PURE__ */ new Map());
|
|
225099
|
+
const mine = counts(production3), theirs = counts(attempt);
|
|
225100
|
+
const extra = (a, b) => [...a].flatMap(([call2, n]) => n > (b.get(call2) ?? 0) ? [{ call: call2, count: n - (b.get(call2) ?? 0) }] : []);
|
|
225101
|
+
const parted = production3.findIndex((call2, i) => call2 !== attempt[i]);
|
|
225102
|
+
const at3 = parted >= 0 ? parted : attempt.length > production3.length ? production3.length : -1;
|
|
225103
|
+
return {
|
|
225104
|
+
onlyInProduction: extra(mine, theirs),
|
|
225105
|
+
onlyInAttempt: extra(theirs, mine),
|
|
225106
|
+
firstDifference: at3 < 0 ? null : { index: at3 + 1, production: production3[at3] ?? null, attempt: attempt[at3] ?? null }
|
|
225107
|
+
};
|
|
225108
|
+
}
|
|
225109
|
+
async function importLocally(ctx, file3, options3) {
|
|
225110
|
+
const { text: text24, lines } = await traceFileLines(ctx, file3);
|
|
225111
|
+
const { rebuild: rebuild2 } = await Promise.resolve().then(() => (init_rebuild(), rebuild_exports));
|
|
225020
225112
|
const answers = Object.fromEntries(options3.answer.map((pair) => {
|
|
225021
225113
|
const at3 = pair.indexOf("=");
|
|
225022
225114
|
if (at3 < 1) throw new AnchaError("USAGE", `--answer needs question=value, got ${pair}`);
|
|
225023
225115
|
return [pair.slice(0, at3), pair.slice(at3 + 1)];
|
|
225024
225116
|
}));
|
|
225025
225117
|
const id12 = `trace-${createHash67("sha256").update(text24).digest("hex").slice(0, 8)}`;
|
|
225026
|
-
|
|
225118
|
+
let made;
|
|
225119
|
+
try {
|
|
225120
|
+
made = rebuild2(lines, { id: id12, answers });
|
|
225121
|
+
} catch (error64) {
|
|
225122
|
+
if (error64.code === "NO_CALLS") throw new AnchaError("USAGE", error64.message, { hint: "an import needs spans that carry the HTTP requests and responses of the agent's calls to its tools; model calls and tool-call spans alone make no test (ancha docs apps)" });
|
|
225123
|
+
throw error64;
|
|
225124
|
+
}
|
|
225125
|
+
const setup2 = [...made.setup.reduce((all8, call2) => all8.set(call2, (all8.get(call2) ?? 0) + 1), /* @__PURE__ */ new Map())].map(([call2, count3]) => ({ call: call2, count: count3 }));
|
|
225027
225126
|
const dir2 = resolve40(ctx.io.cwd, options3.dest, id12), path6 = join53(dir2, "scene.yaml");
|
|
225028
225127
|
if (!options3.force && await readFile38(path6, "utf8").then(() => true, () => false)) throw new AnchaError("USAGE", `${relative12(ctx.io.cwd, path6)} exists; --force replaces it`);
|
|
225029
225128
|
await mkdir26(dir2, { recursive: true });
|
|
@@ -225039,7 +225138,13 @@ async function importLocally(ctx, file3, options3) {
|
|
|
225039
225138
|
lines2.push(" questions (answer with --answer <id>=<value>, then import again with --force; a default repeats what production did, so answer the ones about what went wrong):");
|
|
225040
225139
|
for (const q of made.questions) lines2.push(` ${q.id}: ${q.question}`, ` ${q.answer === void 0 ? `default: ${q.default}` : `answered: ${q.answer}`}`);
|
|
225041
225140
|
}
|
|
225042
|
-
|
|
225141
|
+
if (setup2.length) {
|
|
225142
|
+
lines2.push(
|
|
225143
|
+
` warning: ${plural5(made.setup.length, "call")} came before the first event the test replays, the app's own setup: ${setup2.map((c) => `${c.call}${c.count > 1 ? ` \xD7${c.count}` : ""}`).join(", ")}`,
|
|
225144
|
+
" the test has them only if the app makes them when it starts, or the start script or an app_calls entry does (ancha docs apps)"
|
|
225145
|
+
);
|
|
225146
|
+
}
|
|
225147
|
+
return { result: { scene: relative12(ctx.io.cwd, path6), summary: made.summary, questions: made.questions, setup: setup2 }, text: lines2.join("\n") };
|
|
225043
225148
|
}
|
|
225044
225149
|
|
|
225045
225150
|
// packages/cli/src/main.ts
|
package/lib/assets/SKILL.md
CHANGED
|
@@ -35,7 +35,7 @@ A production run that went wrong becomes a test here. With a trace file (an expo
|
|
|
35
35
|
|
|
36
36
|
1. `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.
|
|
37
37
|
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`).
|
|
38
|
-
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.
|
|
38
|
+
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.
|
|
39
39
|
|
|
40
40
|
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` saves it, 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.
|
|
41
41
|
|
package/lib/assets/docs/apps.md
CHANGED
|
@@ -19,12 +19,14 @@ scenes: [ancha/scenes/*.yaml]
|
|
|
19
19
|
trials: 3
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
`ancha run --dry-run` checks this file and every scene and starts nothing.
|
|
23
|
+
|
|
22
24
|
- `{{agent.port}}` is reserved for the trial, so the health route and the event routes need nothing Ancha-specific.
|
|
23
25
|
- `clock: node` needs `start`. Apps in other runtimes keep real time: give them short thresholds in their seeded settings instead.
|
|
24
26
|
|
|
25
27
|
## The start script
|
|
26
28
|
|
|
27
|
-
-
|
|
29
|
+
- From your shell it gets only a base set (`PATH`, `HOME`, the locale and the like). It also gets Ancha's variables (`ANCHA_AGENT_PORT`, `ANCHA_TRIAL` …), the variables of every tool in the scene (`ancha connect <tool> --json` lists them) and `agent.env`. Set database and cache URLs and the app's test secrets in the script. A real key, such as the app's model key, goes in `agent.pass_env` by name (or `ancha run --pass-env NAME`): its value stays in your shell, not in a script you commit.
|
|
28
30
|
- Every trial is a new world with new URLs and tokens, so every trial starts the app clean:
|
|
29
31
|
1. restore the database from a template copy (`CREATE DATABASE app_trial TEMPLATE app_base`, with `app_base` migrated once);
|
|
30
32
|
2. flush caches and queues the tests own;
|
|
@@ -39,7 +41,7 @@ trials: 3
|
|
|
39
41
|
|
|
40
42
|
- Use the app's base-URL setting if it has one; `ancha connect <tool> --lang ts|py` prints the SDK settings. If the SDK has none, add a development-only initializer that reads the tool's variable and does nothing when it is unset. Keep app changes that small and say why in a comment.
|
|
41
43
|
- Google clients keep only the host of a `rootUrl` set on the client; Ancha routes those calls by their token.
|
|
42
|
-
- Gmail reaches an app the way it does in production: the app calls `users.watch`, and the world then pushes Pub/Sub notifications to `agent.url`. If the app registers its watch on a schedule, call that route with an `app_call` early in the scene. The world gives `GMAIL_API_URL` and `
|
|
44
|
+
- Gmail reaches an app the way it does in production: the app calls `users.watch`, and the world then pushes Pub/Sub notifications to `agent.url`. If the app registers its watch on a schedule, call that route with an `app_call` early in the scene. The world gives `GMAIL_API_URL`, `GMAIL_ACCESS_TOKEN` and `GMAIL_ADDRESS`, the mailbox's address (`{{gmail.url}}`, `{{gmail.token}}`, `{{gmail.address}}`); `GET /gmail/v1/users/me/profile` answers the same address, as in Gmail. `ancha connect gmail --lang ts` prints the client settings.
|
|
43
45
|
- Identifiers a scene relies on (an inbox token, a cron secret, an API key the world sends) should be fixed values your seed creates, because a scene is static.
|
|
44
46
|
|
|
45
47
|
## Scenes for an app
|
|
@@ -75,7 +77,7 @@ checks:
|
|
|
75
77
|
|
|
76
78
|
- `app_calls` take `at`, `method` (default GET), `path`, `headers` and `body`; they go to the origin of `ready_url`.
|
|
77
79
|
- `gmail.send` takes `from`, `to`, `cc`, `subject`, `body`, `in_reply_to` and `ref`. The `gmail.thread` check takes `of` (a message ref), `label` with `present`, `drafts_gte`, `drafts_lte` and `messages_gte`.
|
|
78
|
-
- People who answer like a person
|
|
80
|
+
- People who answer like a person go in the scene's `people:` (`ancha schema scene` lists every field). One with a Gmail account reads the mail delivered to that mailbox, which must be in `seed.gmail.mailboxes`, and replies in the thread: `{ ref: tom, name: Tom, role: a client who answers email himself within a day or two, accounts: { gmail: tom@client.example }, replies_after: 1d..2d }`. People call a model with your `OPENROUTER_API_KEY`, or `ANCHA_PEOPLE_BASE_URL` and `ANCHA_PEOPLE_API_KEY` (`ancha docs cloud`). `ancha twins seed <tool> --json` prints each tool's seed fields and checks.
|
|
79
81
|
- Make every check able to fail. Run a scene once against a build with the feature broken, or also check the state in between (the label the app should have removed). A check can pass for the wrong reason: a reminder that never comes because the scheduled call ran too early proves nothing.
|
|
80
82
|
|
|
81
83
|
## From a production trace, on this computer
|
|
@@ -84,5 +86,5 @@ checks:
|
|
|
84
86
|
2. It lists the questions one trace cannot settle, each with the default the test uses. Examples: should a label the app added still be on the thread at the end, and what header do the app's scheduled calls carry? Ask the user, then import again with `--answer <id>=<value>` for each and `--force`.
|
|
85
87
|
3. Run the scene against the build that failed in production. It should fail the way production did. Then fix the app and run again.
|
|
86
88
|
|
|
87
|
-
- A trace holds the app's calls, not what started each one.
|
|
88
|
-
- When a test does not fail the way production did,
|
|
89
|
+
- A trace holds the app's calls, not what started each one. The import lists the calls production made before the first event the test replays: the app's own setup, such as a watch or its labels. The test has them only if the app makes them when it starts, or the start script or an `app_call` does.
|
|
90
|
+
- When a test does not fail the way production did, `ancha traces diff <trace file> <run>/<trial>` lists the calls only production made, the ones only the trial made, and the first call where their orders part. A call production made and the trial didn't (labels created at setup, a settings read) usually points at what the seed lacks.
|
|
@@ -8,6 +8,6 @@ Slack WebClient uses slackApiUrl. With Bolt Socket Mode configure both App clien
|
|
|
8
8
|
|
|
9
9
|
PagerDuty PDJS requires a full local url for every REST request; its server option assumes production HTTPS. Use response.data and next(); resource/all and Events convenience helpers have production-host assumptions. Use fetch to the local /v2/enqueue with a native Events v2 payload and a service routing key. REST tokens, routing keys, From identity and webhook signing secrets have separate roles.
|
|
10
10
|
|
|
11
|
-
Gmail: Ancha supplies GMAIL_API_URL/GMAIL_ACCESS_TOKEN (`ancha connect gmail --lang ts`). Google clients take the URL as each call's `rootUrl` (`GMAIL_API_URL + '/'`) or the app's own base-URL setting; push to the app follows its `users.watch` call (`ancha docs apps`).
|
|
11
|
+
Gmail: Ancha supplies GMAIL_API_URL/GMAIL_ACCESS_TOKEN and GMAIL_ADDRESS, the mailbox's address (`ancha connect gmail --lang ts`). Google clients take the URL as each call's `rootUrl` (`GMAIL_API_URL + '/'`) or the app's own base-URL setting; push to the app follows its `users.watch` call (`ancha docs apps`).
|
|
12
12
|
|
|
13
13
|
Verify webhook signatures against exact raw request bytes before JSON parsing. Slack uses its signing secret, GitHub its webhook secret, PagerDuty its signing secret; Datadog's declared custom webhook profile uses a bearer token. Native route support and delivery/retry policies are a bounded subset, not full vendor parity.
|
package/lib/assets/docs/run.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
`ancha run --json` loads `ancha.yaml` and runs the configured agent against every scene its `scenes:` globs match, `trials` times each, in fresh worlds. Pass scene files to run only those. `--agent "<command>"` overrides `agent.command`; `-n 1 --parallel 1` runs one diagnostic trial; `--out <dir>` chooses where results go (use the same `--out` for `explain`, `report` and `compare`). Paths are relative to the directory you run `ancha` from.
|
|
4
4
|
|
|
5
|
+
`ancha run --dry-run` checks `ancha.yaml` and every scene, prints the scenes, trials and parallelism, and starts nothing: no server, no agent, no trial.
|
|
6
|
+
|
|
5
7
|
The first line says where the worlds run: locally, or on the hosted workspace you signed in to (`--local` keeps them on this computer). NDJSON starts with `run_started`, which carries `workspace` and `target`, and ends with `run_finished` after a completed run. Without `--json`, each finished trial prints one line, such as `trial 2 ✗ 3m02s · 3 checks failed`, before the summary. The agent's exit code and the checks are independent: a clean exit with failed checks is a failure. Exits: 0 success; 1 failed checks, threshold or regression; 2 usage, config, scene or authentication error; 3 infrastructure or a trial the harness couldn't complete; 4 an unimplemented endpoint under `--strict`. A harness failure takes precedence over thresholds and strict gaps.
|
|
6
8
|
|
|
7
9
|
## What the agent gets
|
|
@@ -87202,7 +87202,7 @@ function toolConnectionEnvironment(services2) {
|
|
|
87202
87202
|
break;
|
|
87203
87203
|
// the official client's rootUrl is this URL plus '/'
|
|
87204
87204
|
case "gmail":
|
|
87205
|
-
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token });
|
|
87205
|
+
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token, GMAIL_ADDRESS: s.address });
|
|
87206
87206
|
break;
|
|
87207
87207
|
case "amazon-s3":
|
|
87208
87208
|
add({ AWS_ENDPOINT_URL_S3: s.url, AWS_ACCESS_KEY_ID: s.accessKey, AWS_SECRET_ACCESS_KEY: s.accessKeySecret, AWS_REGION: "us-east-1" });
|
|
@@ -108222,7 +108222,7 @@ function seed15(ctx) {
|
|
|
108222
108222
|
function credentials14(ctx) {
|
|
108223
108223
|
const agent = ctx.scene.seed.gmail?.agent ?? ctx.store.db.prepare("SELECT address FROM gmail_mailboxes ORDER BY ordinal LIMIT 1").get().address;
|
|
108224
108224
|
const row = ctx.store.db.prepare("SELECT token FROM gmail_tokens WHERE mailbox = ?").get(agent);
|
|
108225
|
-
return { token: row.token };
|
|
108225
|
+
return { token: row.token, address: agent };
|
|
108226
108226
|
}
|
|
108227
108227
|
|
|
108228
108228
|
// packages/server/src/twins/gmail/state.ts
|
|
@@ -108274,11 +108274,32 @@ ${m.thread_id}`;
|
|
|
108274
108274
|
}
|
|
108275
108275
|
|
|
108276
108276
|
// packages/server/src/twins/gmail/index.ts
|
|
108277
|
-
var
|
|
108277
|
+
var GOOGLE_OPENID_CONFIGURATION = {
|
|
108278
|
+
issuer: "https://accounts.google.com",
|
|
108279
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
108280
|
+
device_authorization_endpoint: "https://oauth2.googleapis.com/device/code",
|
|
108281
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
108282
|
+
userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo",
|
|
108283
|
+
revocation_endpoint: "https://oauth2.googleapis.com/revoke",
|
|
108284
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
108285
|
+
response_types_supported: ["code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token", "none"],
|
|
108286
|
+
subject_types_supported: ["public"],
|
|
108287
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
108288
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
108289
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
|
108290
|
+
claims_supported: ["aud", "email", "email_verified", "exp", "family_name", "given_name", "iat", "iss", "name", "picture", "sub"],
|
|
108291
|
+
code_challenge_methods_supported: ["plain", "S256"],
|
|
108292
|
+
grant_types_supported: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "urn:ietf:params:oauth:grant-type:jwt-bearer"]
|
|
108293
|
+
};
|
|
108294
|
+
var gmailCoverage = [
|
|
108295
|
+
...gmailRoutes.map(({ method: method2, path: path4, coverage: coverage4 }) => ({ method: method2, path: path4, ...coverage4 })),
|
|
108296
|
+
{ method: "GET", path: "/.well-known/openid-configuration", status: "supported", notes: "Google's discovery document; the endpoints it names are Google's" }
|
|
108297
|
+
];
|
|
108278
108298
|
function gmailTwin() {
|
|
108279
108299
|
const app2 = new Hono3();
|
|
108280
108300
|
for (const route11 of gmailRoutes) app2.on(route11.method, route11.path, handle(route11));
|
|
108281
108301
|
app2.post("/batch/gmail/v1", batchHandler(app2));
|
|
108302
|
+
app2.get("/.well-known/openid-configuration", (c) => c.json(GOOGLE_OPENID_CONFIGURATION));
|
|
108282
108303
|
app2.all("*", unknownRoute3);
|
|
108283
108304
|
return { name: "gmail", basePath: "", unprefixedPaths: /^\/(?:(?:(?:upload|batch)\/)?gmail\/v1(?:\/|$)|oauth2\/v2\/userinfo$)/, app: app2, migrate: migrate5, seed: seed15, credentials: credentials14, actions: gmailActions, checks: { thread }, dumpState: dumpState14, coverage: gmailCoverage };
|
|
108284
108305
|
}
|
|
@@ -156817,7 +156838,7 @@ function createAttemptConnectionManifest(env, options3 = {}) {
|
|
|
156817
156838
|
const scoped = env.mcp?.[id12];
|
|
156818
156839
|
const mcp = scoped && capability.mcp ? { transport: "http", endpoint: scoped.url, profile: capability.mcp.profile, headers: { Authorization: `Bearer ${scoped.token}` } } : void 0;
|
|
156819
156840
|
const credentials39 = {};
|
|
156820
|
-
for (const key3 of ["token", "apiKey", "appKey", "webhookToken", "signingSecret", "appToken", "fromEmail", "routingKey", "routingKeys", "accessKey", "accessKeySecret"]) {
|
|
156841
|
+
for (const key3 of ["token", "apiKey", "appKey", "webhookToken", "signingSecret", "appToken", "fromEmail", "address", "routingKey", "routingKeys", "accessKey", "accessKeySecret"]) {
|
|
156821
156842
|
const value4 = service[key3];
|
|
156822
156843
|
if (typeof value4 === "string" || Array.isArray(value4) && value4.every((item2) => typeof item2 === "string")) credentials39[key3] = value4;
|
|
156823
156844
|
else if (value4 && typeof value4 === "object" && !Array.isArray(value4) && Object.values(value4).every((item2) => typeof item2 === "string")) credentials39[key3] = value4;
|
package/lib/assets/ui/app.js
CHANGED
|
@@ -1639,7 +1639,7 @@ function starterCount(tool, key, state) {
|
|
|
1639
1639
|
}
|
|
1640
1640
|
|
|
1641
1641
|
// 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/`, 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\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.\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` saves it, 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.\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, explain, compare, scenes, integrations, cloud and playgrounds, and https://ancha.mintlify.app/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";
|
|
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/`, 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\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` saves it, 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.\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, explain, compare, scenes, integrations, cloud and playgrounds, and https://ancha.mintlify.app/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
1643
|
|
|
1644
1644
|
// frontend/src/workspace-pages.ts
|
|
1645
1645
|
var startSentence = "Test our agent with Ancha. Start with: npx -y @ancha-labs/cli init, then read https://app.ancha.io/llms.txt";
|
package/lib/worker.mjs
CHANGED
|
@@ -86685,7 +86685,7 @@ function toolConnectionEnvironment(services2) {
|
|
|
86685
86685
|
break;
|
|
86686
86686
|
// the official client's rootUrl is this URL plus '/'
|
|
86687
86687
|
case "gmail":
|
|
86688
|
-
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token });
|
|
86688
|
+
add({ GMAIL_API_URL: s.url, GMAIL_ACCESS_TOKEN: s.token, GMAIL_ADDRESS: s.address });
|
|
86689
86689
|
break;
|
|
86690
86690
|
case "amazon-s3":
|
|
86691
86691
|
add({ AWS_ENDPOINT_URL_S3: s.url, AWS_ACCESS_KEY_ID: s.accessKey, AWS_SECRET_ACCESS_KEY: s.accessKeySecret, AWS_REGION: "us-east-1" });
|
|
@@ -124918,7 +124918,7 @@ function seed15(ctx) {
|
|
|
124918
124918
|
function credentials14(ctx) {
|
|
124919
124919
|
const agent = ctx.scene.seed.gmail?.agent ?? ctx.store.db.prepare("SELECT address FROM gmail_mailboxes ORDER BY ordinal LIMIT 1").get().address;
|
|
124920
124920
|
const row = ctx.store.db.prepare("SELECT token FROM gmail_tokens WHERE mailbox = ?").get(agent);
|
|
124921
|
-
return { token: row.token };
|
|
124921
|
+
return { token: row.token, address: agent };
|
|
124922
124922
|
}
|
|
124923
124923
|
|
|
124924
124924
|
// packages/server/src/twins/gmail/state.ts
|
|
@@ -124970,11 +124970,32 @@ ${m.thread_id}`;
|
|
|
124970
124970
|
}
|
|
124971
124971
|
|
|
124972
124972
|
// packages/server/src/twins/gmail/index.ts
|
|
124973
|
-
var
|
|
124973
|
+
var GOOGLE_OPENID_CONFIGURATION = {
|
|
124974
|
+
issuer: "https://accounts.google.com",
|
|
124975
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
124976
|
+
device_authorization_endpoint: "https://oauth2.googleapis.com/device/code",
|
|
124977
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
124978
|
+
userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo",
|
|
124979
|
+
revocation_endpoint: "https://oauth2.googleapis.com/revoke",
|
|
124980
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
124981
|
+
response_types_supported: ["code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token", "none"],
|
|
124982
|
+
subject_types_supported: ["public"],
|
|
124983
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
124984
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
124985
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
|
124986
|
+
claims_supported: ["aud", "email", "email_verified", "exp", "family_name", "given_name", "iat", "iss", "name", "picture", "sub"],
|
|
124987
|
+
code_challenge_methods_supported: ["plain", "S256"],
|
|
124988
|
+
grant_types_supported: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "urn:ietf:params:oauth:grant-type:jwt-bearer"]
|
|
124989
|
+
};
|
|
124990
|
+
var gmailCoverage = [
|
|
124991
|
+
...gmailRoutes.map(({ method: method2, path: path6, coverage: coverage4 }) => ({ method: method2, path: path6, ...coverage4 })),
|
|
124992
|
+
{ method: "GET", path: "/.well-known/openid-configuration", status: "supported", notes: "Google's discovery document; the endpoints it names are Google's" }
|
|
124993
|
+
];
|
|
124974
124994
|
function gmailTwin() {
|
|
124975
124995
|
const app2 = new Hono3();
|
|
124976
124996
|
for (const route11 of gmailRoutes) app2.on(route11.method, route11.path, handle(route11));
|
|
124977
124997
|
app2.post("/batch/gmail/v1", batchHandler(app2));
|
|
124998
|
+
app2.get("/.well-known/openid-configuration", (c) => c.json(GOOGLE_OPENID_CONFIGURATION));
|
|
124978
124999
|
app2.all("*", unknownRoute3);
|
|
124979
125000
|
return { name: "gmail", basePath: "", unprefixedPaths: /^\/(?:(?:(?:upload|batch)\/)?gmail\/v1(?:\/|$)|oauth2\/v2\/userinfo$)/, app: app2, migrate: migrate5, seed: seed15, credentials: credentials14, actions: gmailActions, checks: { thread }, dumpState: dumpState14, coverage: gmailCoverage };
|
|
124980
125001
|
}
|
|
@@ -157417,7 +157438,7 @@ function agentTemplateVars(envId, services2, task2, trial, session, runtime2) {
|
|
|
157417
157438
|
if (s.tlsRootCertificate !== void 0) vars[`${twin}.tls_root_certificate`] = s.tlsRootCertificate;
|
|
157418
157439
|
if (s.accessKey !== void 0) vars[`${twin}.access_key`] = s.accessKey;
|
|
157419
157440
|
if (s.accessKeySecret !== void 0) vars[`${twin}.access_key_secret`] = s.accessKeySecret;
|
|
157420
|
-
const nativeFields = twin === "datadog" ? [["api_key", s.apiKey], ["app_key", s.appKey], ["webhook_token", s.webhookToken]] : twin === "pagerduty" ? [["from_email", s.fromEmail], ["routing_key", s.routingKey]] : [];
|
|
157441
|
+
const nativeFields = twin === "datadog" ? [["api_key", s.apiKey], ["app_key", s.appKey], ["webhook_token", s.webhookToken]] : twin === "pagerduty" ? [["from_email", s.fromEmail], ["routing_key", s.routingKey]] : twin === "gmail" ? [["address", s.address]] : [];
|
|
157421
157442
|
for (const [field4, value4] of nativeFields) {
|
|
157422
157443
|
if (value4 !== void 0) vars[`${twin}.${field4}`] = value4;
|
|
157423
157444
|
}
|
|
@@ -157437,7 +157458,7 @@ function hostEnvironment(parent2, agent) {
|
|
|
157437
157458
|
const kept = names3.filter((name5) => !isPrivateAgentEnvironmentName(name5) && (agent.inheritEnv || agent.passEnv === void 0 || baseEnv.has(name5) || name5.startsWith("LC_") || declared.has(name5)));
|
|
157438
157459
|
return { env: Object.fromEntries(kept.map((name5) => [name5, parent2[name5]])), inherited: kept.length, withheld: names3.length - kept.length };
|
|
157439
157460
|
}
|
|
157440
|
-
var ANY_SERVICE = { url: "x", hostUrl: "x", token: "x", signingSecret: "x", appToken: "x", apiKey: "x", appKey: "x", webhookToken: "x", fromEmail: "x", routingKey: "x", routingKeys: {}, accessKey: "x", accessKeySecret: "x", clientSecret: "x", grpcEndpoint: "x", tlsRootCertificate: "x" };
|
|
157461
|
+
var ANY_SERVICE = { url: "x", hostUrl: "x", token: "x", signingSecret: "x", appToken: "x", apiKey: "x", appKey: "x", webhookToken: "x", fromEmail: "x", address: "x", routingKey: "x", routingKeys: {}, accessKey: "x", accessKeySecret: "x", clientSecret: "x", grpcEndpoint: "x", tlsRootCertificate: "x" };
|
|
157441
157462
|
function withheldNamedInLogs(parent2, agent, twins, logTails) {
|
|
157442
157463
|
const text21 = logTails.flat().join("\n");
|
|
157443
157464
|
if (text21 === "" || agent.inheritEnv || agent.passEnv === void 0) return [];
|
|
@@ -157484,7 +157505,7 @@ function agentSetupPayload(env, scene2, agent, trial, session, runtime2) {
|
|
|
157484
157505
|
function validateAgentEnv(scene2, agent) {
|
|
157485
157506
|
if (agent.taskInput) parseTaskInput(agent.taskInput);
|
|
157486
157507
|
const services2 = {};
|
|
157487
|
-
for (const twin of scene2.twins) services2[twin] = { url: "http://localhost", hostUrl: "http://localhost", token: "", signingSecret: "", ...twin === "slack" ? { appToken: "" } : {}, ...twin === "datadog" ? { apiKey: "", appKey: "", webhookToken: "" } : {}, ...twin === "pagerduty" ? { fromEmail: "", routingKey: "", routingKeys: {} } : {}, ...twin === "gong" ? { accessKey: "", accessKeySecret: "" } : {}, ...twin === "google-ads" ? { grpcEndpoint: "localhost:1", tlsRootCertificate: "" } : {} };
|
|
157508
|
+
for (const twin of scene2.twins) services2[twin] = { url: "http://localhost", hostUrl: "http://localhost", token: "", signingSecret: "", ...twin === "slack" ? { appToken: "" } : {}, ...twin === "gmail" ? { address: "" } : {}, ...twin === "datadog" ? { apiKey: "", appKey: "", webhookToken: "" } : {}, ...twin === "pagerduty" ? { fromEmail: "", routingKey: "", routingKeys: {} } : {}, ...twin === "gong" ? { accessKey: "", accessKeySecret: "" } : {}, ...twin === "google-ads" ? { grpcEndpoint: "localhost:1", tlsRootCertificate: "" } : {} };
|
|
157488
157509
|
const session = { id: "", token: "", envId: "", eventsUrl: "http://localhost/events", doneUrl: "http://localhost/done", contextUrl: "http://localhost/context", state: "prepared" };
|
|
157489
157510
|
const runtime2 = { ...(agent.mode === "endpoint" && agent.start !== void 0 || agent.taskInput?.kind === "http") && { port: 34567 }, attempt: { id: "validation", caseId: scene2.id, stateDir: "/ancha/validation/agent-state", seed: "validation" } };
|
|
157490
157511
|
const vars = agentTemplateVars("", services2, "", 0, session, runtime2);
|
package/lib/world-server.mjs
CHANGED
|
@@ -124584,7 +124584,7 @@ function seed15(ctx) {
|
|
|
124584
124584
|
function credentials14(ctx) {
|
|
124585
124585
|
const agent = ctx.scene.seed.gmail?.agent ?? ctx.store.db.prepare("SELECT address FROM gmail_mailboxes ORDER BY ordinal LIMIT 1").get().address;
|
|
124586
124586
|
const row = ctx.store.db.prepare("SELECT token FROM gmail_tokens WHERE mailbox = ?").get(agent);
|
|
124587
|
-
return { token: row.token };
|
|
124587
|
+
return { token: row.token, address: agent };
|
|
124588
124588
|
}
|
|
124589
124589
|
|
|
124590
124590
|
// packages/server/src/twins/gmail/state.ts
|
|
@@ -124636,11 +124636,32 @@ ${m.thread_id}`;
|
|
|
124636
124636
|
}
|
|
124637
124637
|
|
|
124638
124638
|
// packages/server/src/twins/gmail/index.ts
|
|
124639
|
-
var
|
|
124639
|
+
var GOOGLE_OPENID_CONFIGURATION = {
|
|
124640
|
+
issuer: "https://accounts.google.com",
|
|
124641
|
+
authorization_endpoint: "https://accounts.google.com/o/oauth2/v2/auth",
|
|
124642
|
+
device_authorization_endpoint: "https://oauth2.googleapis.com/device/code",
|
|
124643
|
+
token_endpoint: "https://oauth2.googleapis.com/token",
|
|
124644
|
+
userinfo_endpoint: "https://openidconnect.googleapis.com/v1/userinfo",
|
|
124645
|
+
revocation_endpoint: "https://oauth2.googleapis.com/revoke",
|
|
124646
|
+
jwks_uri: "https://www.googleapis.com/oauth2/v3/certs",
|
|
124647
|
+
response_types_supported: ["code", "token", "id_token", "code token", "code id_token", "token id_token", "code token id_token", "none"],
|
|
124648
|
+
subject_types_supported: ["public"],
|
|
124649
|
+
id_token_signing_alg_values_supported: ["RS256"],
|
|
124650
|
+
scopes_supported: ["openid", "email", "profile"],
|
|
124651
|
+
token_endpoint_auth_methods_supported: ["client_secret_post", "client_secret_basic"],
|
|
124652
|
+
claims_supported: ["aud", "email", "email_verified", "exp", "family_name", "given_name", "iat", "iss", "name", "picture", "sub"],
|
|
124653
|
+
code_challenge_methods_supported: ["plain", "S256"],
|
|
124654
|
+
grant_types_supported: ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code", "urn:ietf:params:oauth:grant-type:jwt-bearer"]
|
|
124655
|
+
};
|
|
124656
|
+
var gmailCoverage = [
|
|
124657
|
+
...gmailRoutes.map(({ method: method2, path: path4, coverage: coverage4 }) => ({ method: method2, path: path4, ...coverage4 })),
|
|
124658
|
+
{ method: "GET", path: "/.well-known/openid-configuration", status: "supported", notes: "Google's discovery document; the endpoints it names are Google's" }
|
|
124659
|
+
];
|
|
124640
124660
|
function gmailTwin() {
|
|
124641
124661
|
const app2 = new Hono3();
|
|
124642
124662
|
for (const route11 of gmailRoutes) app2.on(route11.method, route11.path, handle(route11));
|
|
124643
124663
|
app2.post("/batch/gmail/v1", batchHandler(app2));
|
|
124664
|
+
app2.get("/.well-known/openid-configuration", (c) => c.json(GOOGLE_OPENID_CONFIGURATION));
|
|
124644
124665
|
app2.all("*", unknownRoute3);
|
|
124645
124666
|
return { name: "gmail", basePath: "", unprefixedPaths: /^\/(?:(?:(?:upload|batch)\/)?gmail\/v1(?:\/|$)|oauth2\/v2\/userinfo$)/, app: app2, migrate: migrate5, seed: seed15, credentials: credentials14, actions: gmailActions, checks: { thread }, dumpState: dumpState14, coverage: gmailCoverage };
|
|
124646
124667
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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": {
|