@ancha-labs/cli 0.4.43 → 0.4.45
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 +340 -251
- package/lib/assets/docs/cloud.md +1 -1
- package/lib/assets/ui/index.html +1 -1
- package/lib/worker.mjs +10 -7
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -204933,8 +204933,8 @@ function invalid35(message8) {
|
|
|
204933
204933
|
});
|
|
204934
204934
|
}
|
|
204935
204935
|
function excluded(name5) {
|
|
204936
|
-
const lower5 = name5.toLowerCase();
|
|
204937
|
-
return lower5.startsWith(".") || EXCLUDED_DIRECTORIES.has(lower5) || EXCLUDED_NAMES.has(
|
|
204936
|
+
const lower5 = name5.toLowerCase(), held = lower5.replace(/\.pending$/, "");
|
|
204937
|
+
return lower5.startsWith(".") || EXCLUDED_DIRECTORIES.has(lower5) || EXCLUDED_NAMES.has(held) || /\.(?:env|pem|key|p12|pfx|jks|keystore|pyc|pyo)$/.test(held);
|
|
204938
204938
|
}
|
|
204939
204939
|
function within(root3, candidate) {
|
|
204940
204940
|
const path9 = relative3(root3, candidate);
|
|
@@ -231293,7 +231293,7 @@ var init_jobs_contract = __esm({
|
|
|
231293
231293
|
CLOUD_MODEL_HOSTS = ["openrouter.ai", "api.openai.com", "api.anthropic.com", "generativelanguage.googleapis.com", "api.groq.com", "api.mistral.ai", "api.together.xyz", "api.fireworks.ai", "api.deepseek.com", "api.x.ai", "api.cohere.com"];
|
|
231294
231294
|
DEFAULT_MODEL_HOSTS = ["openrouter.ai", "api.openai.com", "api.anthropic.com"];
|
|
231295
231295
|
MODEL_KEY_NAMES = ["OPENAI_API_KEY", "ANTHROPIC_API_KEY", "GEMINI_API_KEY", "GOOGLE_API_KEY", "OPENROUTER_API_KEY", "AZURE_OPENAI_API_KEY", "MISTRAL_API_KEY", "GROQ_API_KEY", "DEEPSEEK_API_KEY", "XAI_API_KEY", "COHERE_API_KEY", "TOGETHER_API_KEY", "FIREWORKS_API_KEY"];
|
|
231296
|
-
PROBE_OUTCOMES = ["answered", "refused", "outside_host", "unserved", "crashed", "idle", "no_answer", "wrong_answer", "model_key", "missing_secret"];
|
|
231296
|
+
PROBE_OUTCOMES = ["answered", "refused", "outside_host", "unserved", "crashed", "idle", "no_answer", "wrong_answer", "model_key", "missing_secret", "route_key"];
|
|
231297
231297
|
ANSWER_SOURCES = ["done", "reply", "stdout"];
|
|
231298
231298
|
HEARTBEAT_MS = 1e4;
|
|
231299
231299
|
AGENT_UID = 10001;
|
|
@@ -232651,7 +232651,7 @@ var init_composio_connection = __esm({
|
|
|
232651
232651
|
status;
|
|
232652
232652
|
slug;
|
|
232653
232653
|
constructor(status6, slug16) {
|
|
232654
|
-
super(`Composio did not create the attempt's test connection (${status6} ${slug16}): check that the workspace secret COMPOSIO_API_KEY is a project API key that may create auth configs and connected accounts.`);
|
|
232654
|
+
super(status6 === 401 || status6 === 403 ? `Composio did not create the attempt's test connection (${status6} ${slug16}): check that the workspace secret COMPOSIO_API_KEY is a project API key that may create auth configs and connected accounts.` : `Composio did not create the attempt's test connection (${status6} ${slug16}); run again.`);
|
|
232655
232655
|
this.name = "ComposioConnectionError";
|
|
232656
232656
|
this.status = status6;
|
|
232657
232657
|
this.slug = slug16;
|
|
@@ -232879,7 +232879,7 @@ async function startIngressClient(options5) {
|
|
|
232879
232879
|
if (reached) counts2[toolkit].reached++;
|
|
232880
232880
|
}
|
|
232881
232881
|
if (event3.op === "refused") counts2[toolkit].refused++;
|
|
232882
|
-
record32({ ...event3, toolkit, relayHash: hash6(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : void 0);
|
|
232882
|
+
record32({ ...event3, toolkit, relayHash: hash6(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit), toolkit, event3.reason === "NO_WORLD" ? "agent" : "harness") : event3.op === "execute" && !reached && event3.reason === "ARGUMENTS" ? issue9("ROUTE_ARGUMENTS", "The agent's NETSUITE_RUN_SUITEQL_QUERY arguments were invalid; it got Composio's failure response.", toolkit, "agent") : event3.op === "execute" && !reached && event3.status === 401 && toolkit === "quickbooks" && (event3.via ?? "direct") === "direct" ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : event3.op === "execute" && !reached ? issue9("ROUTE_NOT_REACHED", toolkit === "netsuite" ? "The SuiteQL call did not reach the NetSuite world: check q, limit and offset, then run again." : unreachedDetail(event3.status), toolkit) : event3.op === "catalog" && event3.via !== "mcp" && event3.status === 401 ? issue9("ROUTE_KEY_REJECTED", KEY_REJECTED, toolkit) : void 0);
|
|
232883
232883
|
},
|
|
232884
232884
|
summary: () => {
|
|
232885
232885
|
const result = {};
|
|
@@ -232916,7 +232916,7 @@ async function startIngressClient(options5) {
|
|
|
232916
232916
|
}
|
|
232917
232917
|
};
|
|
232918
232918
|
}
|
|
232919
|
-
var headersSchema, requestSchema, batchSchema, bindSchema, forwarded, methods2, hash6, REFUSAL_FIX, unreachedDetail;
|
|
232919
|
+
var headersSchema, requestSchema, batchSchema, bindSchema, forwarded, methods2, hash6, REFUSAL_FIX, unreachedDetail, KEY_REJECTED;
|
|
232920
232920
|
var init_ingress_client = __esm({
|
|
232921
232921
|
"backend/src/execution/ingress-client.ts"() {
|
|
232922
232922
|
"use strict";
|
|
@@ -232954,6 +232954,7 @@ var init_ingress_client = __esm({
|
|
|
232954
232954
|
MCP_BATCH: "send one JSON-RPC object per MCP request"
|
|
232955
232955
|
};
|
|
232956
232956
|
unreachedDetail = (status6) => status6 === 401 || status6 === 403 ? `Composio answered ${status6} without calling the world: check the workspace secret COMPOSIO_API_KEY.` : status6 >= 500 ? `Composio answered ${status6} without calling the world; run again.` : `Composio answered ${status6} without calling the world: check the QuickBooks tool arguments and use the connection supplied by the route.`;
|
|
232957
|
+
KEY_REJECTED = "Composio answered 401 to the agent's call through the route: it does not accept the workspace secret COMPOSIO_API_KEY, which the route sends for the agent. Export the Composio project's API key as COMPOSIO_API_KEY, run ancha secrets set COMPOSIO_API_KEY, then run again.";
|
|
232957
232958
|
}
|
|
232958
232959
|
});
|
|
232959
232960
|
|
|
@@ -233021,13 +233022,15 @@ async function runRoutedTrial(spec, run7) {
|
|
|
233021
233022
|
return { ...result, routes: route15.summary(), ...result.harnessIssues.some((issue9) => issue9.owner === "harness" && issue9.code?.startsWith("ROUTE_")) && { valid: false, passed: false } };
|
|
233022
233023
|
} catch (error65) {
|
|
233023
233024
|
await route15.close();
|
|
233024
|
-
const
|
|
233025
|
+
const stopped = error65 instanceof AnchaError && error65.code === "AGENT_UNREACHABLE" ? error65 : void 0;
|
|
233026
|
+
const connectionIssue = route15.entries().find((entry3) => entry3.issue?.code === "ROUTE_CONNECTION_FAILED")?.issue ?? (stopped ? route15.entries().find((entry3) => entry3.issue?.code === "ROUTE_KEY_REJECTED")?.issue : void 0);
|
|
233025
233027
|
if (!route15.failed && !connectionIssue || spec.signal?.aborted) throw error65;
|
|
233026
|
-
const result = await invalidTrial({ scene: spec.scene, trial: spec.trial, dir: spec.dir, startedAt, envId: spec.env.id, ...sessionId && { sessionId }, ...captured && { capture: captured }, service: spec.agent.routes.quickbooks ? "quickbooks" : "netsuite", error: connectionIssue ? { code: "ROUTE_CONNECTION_FAILED", message: connectionIssue.message } : { code: "ROUTE_INGRESS_FAILED", message: "The Composio route could not be kept open." } });
|
|
233028
|
+
const result = await invalidTrial({ scene: spec.scene, trial: spec.trial, dir: spec.dir, startedAt, envId: spec.env.id, ...sessionId && { sessionId }, ...captured && { capture: captured }, service: spec.agent.routes.quickbooks ? "quickbooks" : "netsuite", error: connectionIssue ? { code: connectionIssue.code ?? "ROUTE_CONNECTION_FAILED", message: connectionIssue.message } : { code: "ROUTE_INGRESS_FAILED", message: "The Composio route could not be kept open." } });
|
|
233027
233029
|
if (!captured) {
|
|
233028
233030
|
result.trace = route15.entries().map((entry3, i) => ({ ...entry3, seq: i + 1 }));
|
|
233029
233031
|
result.harnessIssues = collectHarnessIssues(result.trace, []);
|
|
233030
233032
|
}
|
|
233033
|
+
if (stopped && connectionIssue?.code === "ROUTE_KEY_REJECTED") result.harnessIssues.push({ kind: "pipeline", owner: "agent", service: "agent", code: stopped.code, message: `${stopped.code}: ${stopped.message}`.slice(0, 500) });
|
|
233031
233034
|
await mkdir4(spec.dir, { recursive: true });
|
|
233032
233035
|
await writeFile3(join7(spec.dir, "trace.jsonl"), result.trace.map((entry3) => JSON.stringify(entry3) + "\n").join(""));
|
|
233033
233036
|
return { ...result, routes: route15.summary() };
|
|
@@ -243406,7 +243409,8 @@ function connectionRouteEvidence(routes2, summary, trace2, log3) {
|
|
|
243406
243409
|
const tools2 = routedTools(routes2);
|
|
243407
243410
|
if (!tools2.length) return { details: [] };
|
|
243408
243411
|
const counts2 = tools2.map((tool) => ({ tool, route: summary?.[tool] }));
|
|
243409
|
-
const details = counts2.map(({ tool, route: route15 }) => `${tool === "netsuite" ? "NetSuite" : "QuickBooks"} via Composio: ${route15?.executions ?? 0} executions, ${route15?.reached ?? 0} reached the world, ${route15?.refused ?? 0} refused${route15?.via ? ` \xB7 via direct ${route15.via.direct} / session ${route15.via.session} / MCP ${route15.via.mcp}` : ""}`);
|
|
243412
|
+
const details = counts2.map(({ tool, route: route15 }) => `${tool === "netsuite" ? "NetSuite" : "QuickBooks"} via Composio: ${route15?.executions ?? 0} execution${route15?.executions === 1 ? "" : "s"}, ${route15?.reached ?? 0} reached the world, ${route15?.refused ?? 0} refused${route15?.via ? ` \xB7 via direct ${route15.via.direct} / session ${route15.via.session} / MCP ${route15.via.mcp}` : ""}`);
|
|
243413
|
+
if (routeKeyRejected(trace2)) return { details, reason: { ...ROUTE_KEY_REASON } };
|
|
243410
243414
|
const refused2 = trace2.filter((entry3) => entry3.routeEvent?.leg === "platform" && entry3.routeEvent.op === "refused");
|
|
243411
243415
|
for (const entry3 of refused2.slice(0, 5)) {
|
|
243412
243416
|
const event3 = entry3.routeEvent;
|
|
@@ -243438,9 +243442,17 @@ function connectionRouteEvidence(routes2, summary, trace2, log3) {
|
|
|
243438
243442
|
if (counts2.some(({ route: route15 }) => !route15?.reached)) return { details };
|
|
243439
243443
|
return { details, reason: { code: "answered", level: "pass", message: "The agent\u2019s Composio executions reached each routed world." } };
|
|
243440
243444
|
}
|
|
243445
|
+
var ROUTE_KEY_REASON, routeKeyRejected;
|
|
243441
243446
|
var init_connection_route = __esm({
|
|
243442
243447
|
"backend/src/execution/connection-route.ts"() {
|
|
243443
243448
|
"use strict";
|
|
243449
|
+
ROUTE_KEY_REASON = {
|
|
243450
|
+
code: "route_key",
|
|
243451
|
+
level: "fail",
|
|
243452
|
+
message: "Composio did not accept the workspace secret COMPOSIO_API_KEY: it answered 401 to the agent\u2019s call through the route.",
|
|
243453
|
+
fix: "Export the Composio project\u2019s API key as COMPOSIO_API_KEY, run ancha secrets set COMPOSIO_API_KEY, then run ancha agent upload again."
|
|
243454
|
+
};
|
|
243455
|
+
routeKeyRejected = (entries4) => entries4.some((entry3) => entry3.issue?.code === "ROUTE_KEY_REJECTED");
|
|
243444
243456
|
}
|
|
243445
243457
|
});
|
|
243446
243458
|
|
|
@@ -243676,7 +243688,11 @@ async function runWithTask(descriptor3, agent, run7) {
|
|
|
243676
243688
|
const text31 = log3?.toString("utf8") ?? tail.join("\n");
|
|
243677
243689
|
const route15 = connectionRouteEvidence(agent.routes, trial.routes, trial.trace, text31);
|
|
243678
243690
|
if (route15.details.length) probe.routeDetails = route15.details;
|
|
243679
|
-
|
|
243691
|
+
if (route15.reason?.code === "route_key") {
|
|
243692
|
+
Object.assign(probe, { reason: route15.reason, logTail: tail.length > 0 ? tail : text31.trimEnd().split("\n").filter(Boolean).slice(-10) });
|
|
243693
|
+
return { state: "failed", probe, message: route15.reason.message };
|
|
243694
|
+
}
|
|
243695
|
+
const diagnosed = (code5) => code5 === "MODEL_KEY_REFUSED" || routed && (code5 === "ROUTE_REFUSED" || code5 === "ROUTE_NOT_REACHED" || code5 === "ROUTE_KEY_REJECTED");
|
|
243680
243696
|
const harnessIssue = trial.harnessIssues.some((issue9) => issue9.owner === "harness" && !diagnosed(issue9.code));
|
|
243681
243697
|
if (harnessIssue || !trial.valid && !trial.harnessIssues.some((issue9) => diagnosed(issue9.code))) {
|
|
243682
243698
|
Object.assign(probe, { logTail: tail, ...fix !== void 0 && { fix } });
|
|
@@ -243760,6 +243776,10 @@ async function probeSlackApp(descriptor3, agent, probe, deps) {
|
|
|
243760
243776
|
child3 = void 0;
|
|
243761
243777
|
const log3 = await readFile25(join44(descriptor3.outDir, "agent.log"), "utf8").catch(() => "");
|
|
243762
243778
|
probe.logTail = log3.trimEnd().split("\n").filter(Boolean).slice(-10);
|
|
243779
|
+
if (ingress && routeKeyRejected(ingress.entries())) {
|
|
243780
|
+
probe.reason = { ...ROUTE_KEY_REASON };
|
|
243781
|
+
return { state: "failed", probe, message: ROUTE_KEY_REASON.message };
|
|
243782
|
+
}
|
|
243763
243783
|
const fix = socket ? slackSocketFix : slackHttpFix;
|
|
243764
243784
|
return { state: "failed", probe, message: error65 instanceof AnchaError ? `${error65.message}${error65.hint ? ` ${error65.hint}` : ""}` : `The Slack app did not connect. ${fix}` };
|
|
243765
243785
|
} finally {
|
|
@@ -252281,7 +252301,7 @@ function registerEnv(program2, ctx) {
|
|
|
252281
252301
|
// packages/cli/src/commands/explain.ts
|
|
252282
252302
|
init_src();
|
|
252283
252303
|
init_src();
|
|
252284
|
-
import { readFile as
|
|
252304
|
+
import { readFile as readFile35, writeFile as writeFile24 } from "node:fs/promises";
|
|
252285
252305
|
import { join as join50, relative as relative19, resolve as resolve39 } from "node:path";
|
|
252286
252306
|
|
|
252287
252307
|
// packages/cli/src/numbers.ts
|
|
@@ -257262,7 +257282,9 @@ init_run_bundle();
|
|
|
257262
257282
|
// packages/cli/src/commands/login.ts
|
|
257263
257283
|
init_src();
|
|
257264
257284
|
import { spawn as spawn5 } from "node:child_process";
|
|
257285
|
+
import { chmod as chmod7, mkdir as mkdir23, readFile as readFile33, rm as rm12, writeFile as writeFile23 } from "node:fs/promises";
|
|
257265
257286
|
import { hostname as hostname4 } from "node:os";
|
|
257287
|
+
import { dirname as dirname21 } from "node:path";
|
|
257266
257288
|
init_credentials();
|
|
257267
257289
|
init_backend();
|
|
257268
257290
|
var DEFAULT_CLOUD_URL = "https://app.ancha.io";
|
|
@@ -257317,6 +257339,43 @@ var sleep12 = (ms2, signal) => new Promise((resolve63) => {
|
|
|
257317
257339
|
resolve63();
|
|
257318
257340
|
}, { once: true });
|
|
257319
257341
|
});
|
|
257342
|
+
var RESUME_HINT = "If this command stops before you approve, run ancha login again: it finishes this sign-in.";
|
|
257343
|
+
var pendingPath = (env2) => {
|
|
257344
|
+
const path9 = credentialsPath(env2);
|
|
257345
|
+
return path9 ? `${path9}.pending` : "";
|
|
257346
|
+
};
|
|
257347
|
+
async function readPending(env2, server) {
|
|
257348
|
+
const path9 = pendingPath(env2);
|
|
257349
|
+
if (!path9) return null;
|
|
257350
|
+
try {
|
|
257351
|
+
const p2 = JSON.parse(await readFile33(path9, "utf8"));
|
|
257352
|
+
if (p2.version !== 1 || p2.server !== server || typeof p2.deviceCode !== "string" || typeof p2.userCode !== "string" || typeof p2.verificationUrl !== "string" || typeof p2.expiresAt !== "string") return null;
|
|
257353
|
+
return p2;
|
|
257354
|
+
} catch {
|
|
257355
|
+
return null;
|
|
257356
|
+
}
|
|
257357
|
+
}
|
|
257358
|
+
async function writePending(env2, pending) {
|
|
257359
|
+
const path9 = pendingPath(env2);
|
|
257360
|
+
if (!path9) return false;
|
|
257361
|
+
try {
|
|
257362
|
+
await mkdir23(dirname21(path9), { recursive: true, mode: 448 });
|
|
257363
|
+
await writeFile23(path9, JSON.stringify(pending) + "\n", { mode: 384 });
|
|
257364
|
+
await chmod7(path9, 384).catch(() => {
|
|
257365
|
+
});
|
|
257366
|
+
return true;
|
|
257367
|
+
} catch {
|
|
257368
|
+
return false;
|
|
257369
|
+
}
|
|
257370
|
+
}
|
|
257371
|
+
async function dropPending(env2, deviceCode) {
|
|
257372
|
+
const path9 = pendingPath(env2);
|
|
257373
|
+
if (!path9) return;
|
|
257374
|
+
try {
|
|
257375
|
+
if (JSON.parse(await readFile33(path9, "utf8")).deviceCode === deviceCode) await rm12(path9, { force: true });
|
|
257376
|
+
} catch {
|
|
257377
|
+
}
|
|
257378
|
+
}
|
|
257320
257379
|
function registerLogin(program2, ctx, deps = {}) {
|
|
257321
257380
|
program2.command("login").description("sign in to your hosted workspace from this computer: ancha run runs your tests there, and import, pull and traces use it").option("--url <url>", "hosted Ancha address", DEFAULT_CLOUD_URL).option("--no-browser", "print the approval link instead of opening a browser").action(async (opts) => {
|
|
257322
257381
|
let base6;
|
|
@@ -257325,30 +257384,64 @@ function registerLogin(program2, ctx, deps = {}) {
|
|
|
257325
257384
|
} catch {
|
|
257326
257385
|
throw new AnchaError("USAGE", "invalid --url", { hint: `use an https address such as ${DEFAULT_CLOUD_URL}` });
|
|
257327
257386
|
}
|
|
257328
|
-
const
|
|
257329
|
-
|
|
257330
|
-
|
|
257331
|
-
|
|
257332
|
-
if (
|
|
257333
|
-
|
|
257334
|
-
|
|
257335
|
-
|
|
257387
|
+
const env2 = ctx.io.env, signal = ctx.io.abort;
|
|
257388
|
+
if (!credentialsPath(env2)) throw new AnchaError("USAGE", "set HOME or ANCHA_CREDENTIALS_FILE to save a sign-in");
|
|
257389
|
+
const poll = (deviceCode) => json38(`${base6}/cli/poll?device_code=${encodeURIComponent(deviceCode)}`, {}, deps.fetch);
|
|
257390
|
+
let pending = await readPending(env2, base6), resumed = false;
|
|
257391
|
+
if (pending) {
|
|
257392
|
+
const first2 = await poll(pending.deviceCode);
|
|
257393
|
+
if (first2.status === "approved") return finish2(first2, pending.deviceCode);
|
|
257394
|
+
if (first2.status === "pending" && Date.parse(pending.expiresAt) - Date.now() > 15e3) resumed = true;
|
|
257395
|
+
else {
|
|
257396
|
+
await dropPending(env2, pending.deviceCode);
|
|
257397
|
+
pending = null;
|
|
257398
|
+
}
|
|
257399
|
+
}
|
|
257400
|
+
let saved = resumed;
|
|
257401
|
+
if (!pending) {
|
|
257402
|
+
const start2 = await json38(`${base6}/cli/device`, { method: "POST", body: JSON.stringify({ name: hostname4() }) }, deps.fetch);
|
|
257403
|
+
pending = { version: 1, server: base6, deviceCode: start2.device_code, userCode: start2.user_code, verificationUrl: start2.verification_url, interval: start2.interval, window: start2.expires_in, expiresAt: new Date(Date.now() + start2.expires_in * 1e3).toISOString() };
|
|
257404
|
+
saved = await writePending(env2, pending);
|
|
257405
|
+
}
|
|
257406
|
+
const expiresIn = Math.max(1, Math.round((Date.parse(pending.expiresAt) - Date.now()) / 1e3));
|
|
257407
|
+
if (resumed) ctx.out.info("Finishing the sign-in an earlier ancha login started on this computer.");
|
|
257408
|
+
ctx.out.info(`Confirm this computer in your browser: ${pending.verificationUrl}`);
|
|
257409
|
+
ctx.out.info(`Code: ${pending.userCode}`);
|
|
257410
|
+
if (saved) ctx.out.info(RESUME_HINT);
|
|
257411
|
+
if (ctx.out.json) ctx.out.event({ event: "login_pending", verificationUrl: pending.verificationUrl, userCode: pending.userCode, expiresIn, ...resumed && { resumed: true }, ...saved && { hint: RESUME_HINT } });
|
|
257412
|
+
if (opts.browser && !resumed) openBrowser(pending.verificationUrl);
|
|
257413
|
+
const deadline3 = Date.parse(pending.expiresAt);
|
|
257414
|
+
const interval = Math.max(2, Math.min(15, pending.interval || 3)) * 1e3;
|
|
257336
257415
|
while (Date.now() < deadline3 && !signal?.aborted) {
|
|
257337
257416
|
await sleep12(interval, signal);
|
|
257338
257417
|
if (signal?.aborted) break;
|
|
257339
|
-
const
|
|
257340
|
-
if (
|
|
257341
|
-
if (
|
|
257342
|
-
|
|
257343
|
-
|
|
257344
|
-
|
|
257345
|
-
|
|
257346
|
-
|
|
257418
|
+
const result = await poll(pending.deviceCode);
|
|
257419
|
+
if (result.status === "pending") continue;
|
|
257420
|
+
if (result.status === "denied") {
|
|
257421
|
+
await dropPending(env2, pending.deviceCode);
|
|
257422
|
+
throw new AnchaError("USAGE", "sign-in was denied in the browser");
|
|
257423
|
+
}
|
|
257424
|
+
if (result.status === "expired") break;
|
|
257425
|
+
return finish2(result, pending.deviceCode);
|
|
257426
|
+
}
|
|
257427
|
+
if (signal?.aborted) throw new AnchaError("USAGE", "login interrupted");
|
|
257428
|
+
await dropPending(env2, pending.deviceCode);
|
|
257429
|
+
const minutes = Math.max(1, Math.round((pending.window || expiresIn) / 60));
|
|
257430
|
+
throw new AnchaError("USAGE", "the approval link expired", { hint: `run ancha login again and approve within ${minutes} minute${minutes === 1 ? "" : "s"}` });
|
|
257431
|
+
async function finish2(approved, deviceCode) {
|
|
257432
|
+
if (!approved.apiKey || !approved.serverUrl) {
|
|
257433
|
+
await dropPending(env2, deviceCode);
|
|
257434
|
+
throw new AnchaError("INTERNAL", `${base6} approved the sign-in without a key`);
|
|
257435
|
+
}
|
|
257436
|
+
const serverUrl3 = normalizeServerUrl(approved.serverUrl);
|
|
257437
|
+
const file3 = await readCredentials(env2);
|
|
257438
|
+
file3.servers[serverUrl3] = { apiKey: approved.apiKey, ...approved.email && { email: approved.email }, savedAt: (/* @__PURE__ */ new Date()).toISOString(), minted: "device" };
|
|
257347
257439
|
file3.default = serverUrl3;
|
|
257348
|
-
const path9 = await writeCredentials(file3,
|
|
257440
|
+
const path9 = await writeCredentials(file3, env2);
|
|
257441
|
+
await dropPending(env2, deviceCode);
|
|
257349
257442
|
let onboarding = null, unread2;
|
|
257350
257443
|
try {
|
|
257351
|
-
onboarding = await fetchOnboarding(ctx, { serverUrl: serverUrl3, apiKey:
|
|
257444
|
+
onboarding = await fetchOnboarding(ctx, { serverUrl: serverUrl3, apiKey: approved.apiKey });
|
|
257352
257445
|
} catch (e) {
|
|
257353
257446
|
unread2 = toErrorJson(e);
|
|
257354
257447
|
}
|
|
@@ -257356,20 +257449,16 @@ function registerLogin(program2, ctx, deps = {}) {
|
|
|
257356
257449
|
const { source } = await serverChoice(ctx).catch(() => ({ source: "login" }));
|
|
257357
257450
|
const runLine = source === "config" || source === "env" ? `${SERVER_SOURCE_LABEL[source]} chooses the server here, so ancha run keeps the target in ancha.yaml.` : loginRunLine(ctx);
|
|
257358
257451
|
ctx.out.result(
|
|
257359
|
-
{ serverUrl: serverUrl3, ...
|
|
257452
|
+
{ serverUrl: serverUrl3, ...approved.email && { email: approved.email }, credentials: path9, onboarding, ...next2 && { next: next2 }, ...unread2 && { onboardingError: unread2 } },
|
|
257360
257453
|
() => [
|
|
257361
|
-
`Signed in${
|
|
257454
|
+
`Signed in${approved.email ? ` as ${approved.email}` : ""}.`,
|
|
257362
257455
|
`Workspace: ${serverUrl3}`,
|
|
257363
257456
|
`Saved to ${path9}. ${runLine}`,
|
|
257364
257457
|
onboarding ? `
|
|
257365
257458
|
${renderOnboarding(onboarding, next2 ?? void 0)}` : `The onboarding checks could not be read: ${unread2?.message.replace(/\.$/, "")}. ancha status --on cloud shows them.`
|
|
257366
257459
|
].join("\n")
|
|
257367
257460
|
);
|
|
257368
|
-
return;
|
|
257369
257461
|
}
|
|
257370
|
-
if (signal?.aborted) throw new AnchaError("USAGE", "login interrupted");
|
|
257371
|
-
const minutes = Math.max(1, Math.round(start2.expires_in / 60));
|
|
257372
|
-
throw new AnchaError("USAGE", "the approval link expired", { hint: `run ancha login again and approve within ${minutes} minute${minutes === 1 ? "" : "s"}` });
|
|
257373
257462
|
});
|
|
257374
257463
|
program2.command("logout").description("sign out of a hosted Ancha and revoke the key that sign-in created").option("--url <url>", "hosted world server to forget (default: the saved default)").action(async (opts) => {
|
|
257375
257464
|
const file3 = await readCredentials(ctx.io.env);
|
|
@@ -257437,11 +257526,11 @@ ${worlds2 === "local" ? loginRunLine(ctx) : "This server override keeps the agen
|
|
|
257437
257526
|
// packages/cli/src/kit/trace-connection.ts
|
|
257438
257527
|
var import_yaml10 = __toESM(require_dist(), 1);
|
|
257439
257528
|
init_src();
|
|
257440
|
-
import { readFile as
|
|
257529
|
+
import { readFile as readFile34 } from "node:fs/promises";
|
|
257441
257530
|
import { relative as relative18 } from "node:path";
|
|
257442
257531
|
init_detect();
|
|
257443
257532
|
async function traceConnection(cwd, paths3, configured, target6, recordsAdapter, cloud = false) {
|
|
257444
|
-
const scenes = await Promise.all(paths3.map(async (path9) => ({ path: relative18(cwd, path9), scene: (0, import_yaml10.parse)(await
|
|
257533
|
+
const scenes = await Promise.all(paths3.map(async (path9) => ({ path: relative18(cwd, path9), scene: (0, import_yaml10.parse)(await readFile34(path9, "utf8")) })));
|
|
257445
257534
|
const tools2 = [...new Set(scenes.flatMap(({ scene: scene2 }) => (scene2.twins ?? []).filter((name5) => !(name5 === "slack" && scene2.agent_input === "per_event" && scene2.people?.length))))].map((name5) => ({
|
|
257446
257535
|
name: name5,
|
|
257447
257536
|
env: connectionGuide(name5, "ts").env,
|
|
@@ -257514,8 +257603,8 @@ async function toolAnswers(runDir, summary, filter4) {
|
|
|
257514
257603
|
const out = [];
|
|
257515
257604
|
for (const scene2 of summary.scenes) for (const { trial } of scene2.trialsDetail) {
|
|
257516
257605
|
if (filter4.scene !== void 0 && filter4.scene !== scene2.sceneId || filter4.trial !== void 0 && filter4.trial !== trial) continue;
|
|
257517
|
-
const text31 = await
|
|
257518
|
-
const state3 = await
|
|
257606
|
+
const text31 = await readFile35(join50(runDir, `trial-${scene2.sceneId}-${trial}`, "trace.jsonl"), "utf8").catch(() => "");
|
|
257607
|
+
const state3 = await readFile35(join50(runDir, `trial-${scene2.sceneId}-${trial}`, "state.json"), "utf8").then(JSON.parse).catch(() => void 0);
|
|
257519
257608
|
const trace2 = text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
257520
257609
|
const functionTools = projectFunctionTools(trace2, state3);
|
|
257521
257610
|
const logical = new Map(functionTools.calls.map((c) => [c.seq, c]));
|
|
@@ -257553,7 +257642,7 @@ function invalidSetupNext(summary, out, readDirectory) {
|
|
|
257553
257642
|
})];
|
|
257554
257643
|
}
|
|
257555
257644
|
async function trialOutcomes(runDir, summary, filter4) {
|
|
257556
|
-
const inputs2 = await
|
|
257645
|
+
const inputs2 = await readFile35(join50(runDir, "inputs.json"), "utf8").then((text31) => JSON.parse(text31), () => ({ cases: [] }));
|
|
257557
257646
|
const out = [];
|
|
257558
257647
|
for (const scene2 of summary.scenes) {
|
|
257559
257648
|
if (filter4.scene !== void 0 && filter4.scene !== scene2.sceneId) continue;
|
|
@@ -257562,15 +257651,15 @@ async function trialOutcomes(runDir, summary, filter4) {
|
|
|
257562
257651
|
for (const detail3 of scene2.trialsDetail) {
|
|
257563
257652
|
if (detail3.passed || detail3.outcome === "skipped" || detail3.outcome === "xfailed" || filter4.trial !== void 0 && filter4.trial !== detail3.trial) continue;
|
|
257564
257653
|
const dir2 = join50(runDir, `trial-${scene2.sceneId}-${detail3.trial}`);
|
|
257565
|
-
const trace2 = (await
|
|
257654
|
+
const trace2 = (await readFile35(join50(dir2, "trace.jsonl"), "utf8").catch(() => "")).split("\n").filter(Boolean).flatMap((line2) => {
|
|
257566
257655
|
try {
|
|
257567
257656
|
return [JSON.parse(line2)];
|
|
257568
257657
|
} catch {
|
|
257569
257658
|
return [];
|
|
257570
257659
|
}
|
|
257571
257660
|
});
|
|
257572
|
-
const result = await
|
|
257573
|
-
const log3 = (await
|
|
257661
|
+
const result = await readFile35(join50(dir2, "result.json"), "utf8").then((text31) => JSON.parse(text31), () => ({}));
|
|
257662
|
+
const log3 = (await readFile35(join50(dir2, "agent.log"), "utf8").catch(() => "")).slice(-1e6);
|
|
257574
257663
|
const { reason: reason2, calls: calls2 } = attemptOutcome(
|
|
257575
257664
|
{ exit: detail3.exit, exitCode: detail3.exitCode, realMs: detail3.realMs, trace: trace2, log: log3, ...result.logTail && { logTail: result.logTail }, modelReplies: result.modelReplies },
|
|
257576
257665
|
{ check: "test", answerChecked, target: "local" }
|
|
@@ -257781,7 +257870,7 @@ function registerExplain(program2, ctx) {
|
|
|
257781
257870
|
const outcomes = await trialOutcomes(join50(resolve39(ctx.io.cwd, opts.out ?? DEFAULT_RUNS_DIR), summary.runId), summary, filter4);
|
|
257782
257871
|
const out = opts.out === void 0 ? "" : ` --out ${shellArgument(opts.out)}`;
|
|
257783
257872
|
const baselinePath = join50(resolve39(ctx.io.cwd, opts.out ?? DEFAULT_RUNS_DIR), "..", "baselines", "before.json");
|
|
257784
|
-
const baselineText = await
|
|
257873
|
+
const baselineText = await readFile35(baselinePath, "utf8").catch(() => void 0);
|
|
257785
257874
|
const baseline = baselineText === void 0 ? void 0 : (() => {
|
|
257786
257875
|
try {
|
|
257787
257876
|
return normalizeSummary(JSON.parse(baselineText));
|
|
@@ -257835,7 +257924,7 @@ next: ${next2.join(", then ")}` : ""}`
|
|
|
257835
257924
|
const runDir = join50(runsDir, summary.runId), path9 = join50(runDir, "report.html");
|
|
257836
257925
|
const folder2 = relative19(ctx.io.cwd, runDir) || ".";
|
|
257837
257926
|
const records6 = await readRunRecords(runDir, summary, { folder: folder2, secrets: await bundleSecrets({ cwd: ctx.io.cwd, env: ctx.io.env }) });
|
|
257838
|
-
await
|
|
257927
|
+
await writeFile24(path9, renderHtmlReport(reportData(summary, records6)));
|
|
257839
257928
|
const opened = opts.open === true && openBrowser(path9);
|
|
257840
257929
|
ctx.out.result({ runId: summary.runId, path: path9, ...opts.open && { opened } }, () => path9);
|
|
257841
257930
|
return;
|
|
@@ -257856,7 +257945,7 @@ init_src();
|
|
|
257856
257945
|
init_report2();
|
|
257857
257946
|
init_run();
|
|
257858
257947
|
init_run_inputs();
|
|
257859
|
-
import { readdir as readdir9, readFile as
|
|
257948
|
+
import { readdir as readdir9, readFile as readFile36 } from "node:fs/promises";
|
|
257860
257949
|
import { join as join51, resolve as resolve40 } from "node:path";
|
|
257861
257950
|
var RUN_ID2 = /^[A-Za-z0-9_][\w.-]*$/;
|
|
257862
257951
|
var TRIAL_DIR = /^trial-[a-z0-9][a-z0-9_-]*-[1-9]\d*$/;
|
|
@@ -257882,7 +257971,7 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
257882
257971
|
const trialDir = ref23.slice(slash + 1);
|
|
257883
257972
|
if (runId2 === "latest") {
|
|
257884
257973
|
try {
|
|
257885
|
-
runId2 = (await
|
|
257974
|
+
runId2 = (await readFile36(join51(runs, "latest"), "utf8")).trim();
|
|
257886
257975
|
} catch (error65) {
|
|
257887
257976
|
if (missing9(error65)) throw new AnchaError("USAGE", `no runs found in ${out ?? DEFAULT_RUNS_DIR}`, { hint: "run `ancha run` first", cause: error65 });
|
|
257888
257977
|
throw error65;
|
|
@@ -257892,10 +257981,10 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
257892
257981
|
const runDir = join51(runs, runId2);
|
|
257893
257982
|
let inputs2;
|
|
257894
257983
|
try {
|
|
257895
|
-
inputs2 = JSON.parse(await
|
|
257984
|
+
inputs2 = JSON.parse(await readFile36(join51(runDir, "inputs.json"), "utf8"));
|
|
257896
257985
|
} catch (error65) {
|
|
257897
257986
|
if (!missing9(error65)) throw error65;
|
|
257898
|
-
const left = await
|
|
257987
|
+
const left = await readFile36(join51(runDir, "bundle.json"), "utf8").then((text31) => JSON.parse(text31).omitted?.find((item2) => item2.path === "inputs.json")).catch(() => void 0);
|
|
257899
257988
|
const mb = (bytes4) => `${(bytes4 / (1024 * 1024)).toFixed(1)} MB`;
|
|
257900
257989
|
if (left) throw new AnchaError("USAGE", `run ${runId2} came without its inputs.json (${mb(left.bytes)}, past the ${mb(left.cap)} its archive kept), so replay can't rebuild its worlds`, { hint: "a run started with ancha 0.4.14 or later keeps an inputs.json up to 12 MB: run the tests again, then replay the new run", cause: error65 });
|
|
257901
257990
|
throw new AnchaError("USAGE", `unknown run ${JSON.stringify(runId2)}`, { hint: `see ${out ?? DEFAULT_RUNS_DIR}/`, cause: error65 });
|
|
@@ -257909,7 +257998,7 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
257909
257998
|
const dir2 = join51(runDir, trialDir);
|
|
257910
257999
|
const read7 = async (name5, optional2 = false) => {
|
|
257911
258000
|
try {
|
|
257912
|
-
return await
|
|
258001
|
+
return await readFile36(join51(dir2, name5), "utf8");
|
|
257913
258002
|
} catch (error65) {
|
|
257914
258003
|
if (missing9(error65) && optional2) return "";
|
|
257915
258004
|
if (missing9(error65)) throw new AnchaError("USAGE", `attempt ${runId2}/${trialDir} has no ${name5}`, { hint: "it may have been interrupted before its world was captured; replay a finished attempt", cause: error65 });
|
|
@@ -257946,7 +258035,7 @@ async function replayAttempt(attempt2, opts) {
|
|
|
257946
258035
|
...opts.onEvent !== void 0 && { onEvent: opts.onEvent }
|
|
257947
258036
|
});
|
|
257948
258037
|
const trial = run7.results.get(attempt2.caseId).trials[0];
|
|
257949
|
-
const people4 = JSON.parse(await
|
|
258038
|
+
const people4 = JSON.parse(await readFile36(join51(trial.dir, "people-replay.json"), "utf8").catch(() => "null")) ?? { replayed: 0, live: 0, divergence: null };
|
|
257950
258039
|
const recorded2 = new Map(attempt2.checks.map((check4) => [check4.id, check4.passed]));
|
|
257951
258040
|
return {
|
|
257952
258041
|
replayOf: attempt2.id,
|
|
@@ -258093,7 +258182,7 @@ init_src();
|
|
|
258093
258182
|
init_report2();
|
|
258094
258183
|
init_run_store();
|
|
258095
258184
|
init_run_state();
|
|
258096
|
-
import { readFile as
|
|
258185
|
+
import { readFile as readFile37 } from "node:fs/promises";
|
|
258097
258186
|
import { join as join53, resolve as resolve42 } from "node:path";
|
|
258098
258187
|
import { setTimeout as sleep13 } from "node:timers/promises";
|
|
258099
258188
|
function registerStatus(program2, ctx) {
|
|
@@ -258174,7 +258263,7 @@ hint: ${state3.upload.error.hint}` : ""}`);
|
|
|
258174
258263
|
let printed = 0;
|
|
258175
258264
|
for (; ; ) {
|
|
258176
258265
|
const state3 = await readRunState(outDir, id15);
|
|
258177
|
-
const lines2 = (await
|
|
258266
|
+
const lines2 = (await readFile37(log3, "utf8").catch(() => "")).split("\n");
|
|
258178
258267
|
if (!terminal(state3)) lines2.pop();
|
|
258179
258268
|
const complete = lines2.filter(Boolean);
|
|
258180
258269
|
for (const line2 of complete.slice(printed)) ctx.out.event(JSON.parse(line2));
|
|
@@ -258200,8 +258289,8 @@ init_src();
|
|
|
258200
258289
|
// packages/cli/src/commands/simulate.ts
|
|
258201
258290
|
init_src();
|
|
258202
258291
|
init_backend();
|
|
258203
|
-
import { readFile as
|
|
258204
|
-
import { dirname as
|
|
258292
|
+
import { readFile as readFile38 } from "node:fs/promises";
|
|
258293
|
+
import { dirname as dirname22, join as join55, resolve as resolve43 } from "node:path";
|
|
258205
258294
|
init_config();
|
|
258206
258295
|
init_report2();
|
|
258207
258296
|
init_run();
|
|
@@ -258265,7 +258354,7 @@ function registerSimulate(sceneCommand, ctx) {
|
|
|
258265
258354
|
const config12 = await ctx.loadConfig();
|
|
258266
258355
|
let agent;
|
|
258267
258356
|
if (mode !== "world") {
|
|
258268
|
-
agent = withLocalEnvironment(resolveRunAgent(config12, ctx.io.cwd, { agent: await companionCommand(
|
|
258357
|
+
agent = withLocalEnvironment(resolveRunAgent(config12, ctx.io.cwd, { agent: await companionCommand(dirname22(resolve43(ctx.io.cwd, loaded.path)), mode), parallel: 1 }).agent, config12);
|
|
258269
258358
|
}
|
|
258270
258359
|
const serverUrl3 = await configuredWorldServerUrl(ctx);
|
|
258271
258360
|
const backend = await openBackend({ ...serverUrl3 !== void 0 && { serverUrl: serverUrl3 } });
|
|
@@ -258321,7 +258410,7 @@ function registerSimulate(sceneCommand, ctx) {
|
|
|
258321
258410
|
timeline: trial.trace,
|
|
258322
258411
|
checks: trial.checks,
|
|
258323
258412
|
harnessIssues: trial.harnessIssues,
|
|
258324
|
-
state: JSON.parse(await
|
|
258413
|
+
state: JSON.parse(await readFile38(join55(trial.dir, "state.json"), "utf8")),
|
|
258325
258414
|
runId: run7.runId,
|
|
258326
258415
|
dir: trial.dir
|
|
258327
258416
|
};
|
|
@@ -258340,7 +258429,7 @@ init_scenes();
|
|
|
258340
258429
|
|
|
258341
258430
|
// packages/cli/src/kit/init.ts
|
|
258342
258431
|
import { constants as constants12 } from "node:fs";
|
|
258343
|
-
import { lstat as lstat10, mkdir as
|
|
258432
|
+
import { lstat as lstat10, mkdir as mkdir26, open as open11, readFile as readFile43, rm as rm13, writeFile as writeFile27 } from "node:fs/promises";
|
|
258344
258433
|
import { join as join58 } from "node:path";
|
|
258345
258434
|
import { Writable } from "node:stream";
|
|
258346
258435
|
var import_yaml18 = __toESM(require_dist(), 1);
|
|
@@ -259629,10 +259718,10 @@ function netsuiteData(size2, options5 = {}) {
|
|
|
259629
259718
|
// backend/src/kit/quickbooks-examples.ts
|
|
259630
259719
|
var import_yaml14 = __toESM(require_dist(), 1);
|
|
259631
259720
|
init_assets();
|
|
259632
|
-
import { readFile as
|
|
259721
|
+
import { readFile as readFile39 } from "node:fs/promises";
|
|
259633
259722
|
var QUICKBOOKS_EXAMPLES = { world: "pellmont-building-services", tests: ["pellmont-duplicates", "pellmont-approved-merge"] };
|
|
259634
259723
|
async function quickbooksExamples() {
|
|
259635
|
-
const read7 = (name5) =>
|
|
259724
|
+
const read7 = (name5) => readFile39(new URL(`data/pellmont/${name5}.yaml`, assetRoot()), "utf8");
|
|
259636
259725
|
const world5 = `ancha/worlds/${QUICKBOOKS_EXAMPLES.world}.yaml`;
|
|
259637
259726
|
const tests = await Promise.all(QUICKBOOKS_EXAMPLES.tests.map(async (id15) => {
|
|
259638
259727
|
const content2 = await read7(id15);
|
|
@@ -259659,8 +259748,8 @@ var import_yaml15 = __toESM(require_dist(), 1);
|
|
|
259659
259748
|
init_src();
|
|
259660
259749
|
import { createHash as createHash75 } from "node:crypto";
|
|
259661
259750
|
import { existsSync as existsSync2 } from "node:fs";
|
|
259662
|
-
import { mkdir as
|
|
259663
|
-
import { dirname as
|
|
259751
|
+
import { mkdir as mkdir24, readFile as readFile40, writeFile as writeFile25 } from "node:fs/promises";
|
|
259752
|
+
import { dirname as dirname23, join as join56, relative as relative20, resolve as resolve45 } from "node:path";
|
|
259664
259753
|
async function model(ctx) {
|
|
259665
259754
|
const env2 = ctx.io.env;
|
|
259666
259755
|
if (env2.ANCHA_PEOPLE_BASE_URL && env2.ANCHA_PEOPLE_API_KEY) return { client: gen_exports.openRouterClient({ apiKey: env2.ANCHA_PEOPLE_API_KEY, baseUrl: env2.ANCHA_PEOPLE_BASE_URL, relay: true }), credit: "own" };
|
|
@@ -259690,14 +259779,14 @@ async function worldGenDataset(ctx, options5, description2) {
|
|
|
259690
259779
|
if (!["s", "m", "l"].includes(size2)) throw new AnchaError("USAGE", `--size must be s, m or l, got ${JSON.stringify(options5.size)}`, { hint: "e.g. --size s" });
|
|
259691
259780
|
const id15 = options5.id ?? `netsuite-pe-${size2}`;
|
|
259692
259781
|
if (!/^[a-z0-9-]+$/.test(id15)) throw new AnchaError("USAGE", "--id must match [a-z0-9-]+", { hint: "e.g. --id portfolio-books" });
|
|
259693
|
-
const outDir = resolve45(ctx.io.cwd, options5.out ?? "ancha/worlds"), worldPath = join56(outDir, `${id15}.yaml`), evalsPath = join56(
|
|
259782
|
+
const outDir = resolve45(ctx.io.cwd, options5.out ?? "ancha/worlds"), worldPath = join56(outDir, `${id15}.yaml`), evalsPath = join56(dirname23(outDir), "evals", `${id15}.jsonl`);
|
|
259694
259783
|
const taken2 = [worldPath, evalsPath].find((path9) => existsSync2(path9));
|
|
259695
259784
|
if (taken2 && !options5.force) throw exists4(taken2, ctx);
|
|
259696
259785
|
const { world: world5, evals, counts: counts2 } = generateNetsuitePe({ size: size2, id: id15, startTime: NETSUITE_PE_START_TIME });
|
|
259697
|
-
await
|
|
259698
|
-
await
|
|
259699
|
-
await
|
|
259700
|
-
await
|
|
259786
|
+
await mkdir24(outDir, { recursive: true });
|
|
259787
|
+
await mkdir24(dirname23(evalsPath), { recursive: true });
|
|
259788
|
+
await writeFile25(worldPath, worldFileYaml(world5));
|
|
259789
|
+
await writeFile25(evalsPath, netsuitePeJsonl(evals));
|
|
259701
259790
|
const rel = (path9) => relative20(ctx.io.cwd, path9) || ".";
|
|
259702
259791
|
const result = {
|
|
259703
259792
|
workspace: `local:${ctx.io.cwd}`,
|
|
@@ -259729,11 +259818,11 @@ async function worldGen(ctx, description2, options5) {
|
|
|
259729
259818
|
const request2 = { description: description2, id: options5.id ?? null, tools: tools2 ?? null, size: size2, variants, from: options5.from ?? null };
|
|
259730
259819
|
const keyFile = options5.idempotencyKey === void 0 ? void 0 : join56(ctx.io.cwd, ".ancha", "world-gen", `${createHash75("sha256").update(options5.idempotencyKey).digest("hex").slice(0, 32)}.json`);
|
|
259731
259820
|
if (keyFile && existsSync2(keyFile)) {
|
|
259732
|
-
const saved = JSON.parse(await
|
|
259821
|
+
const saved = JSON.parse(await readFile40(keyFile, "utf8"));
|
|
259733
259822
|
if (JSON.stringify(saved.request) !== JSON.stringify(request2)) throw new AnchaError("USAGE", "this --idempotency-key was used with different arguments", { hint: "use a new key for a new request" });
|
|
259734
259823
|
if (saved.result.files.every((file3) => existsSync2(resolve45(ctx.io.cwd, file3)))) return report5(ctx, { ...saved.result, reused: true });
|
|
259735
259824
|
}
|
|
259736
|
-
const from = options5.from === void 0 ? void 0 : parseWorldFile((0, import_yaml15.parse)(await
|
|
259825
|
+
const from = options5.from === void 0 ? void 0 : parseWorldFile((0, import_yaml15.parse)(await readFile40(resolve45(ctx.io.cwd, options5.from), "utf8")));
|
|
259737
259826
|
if (options5.id && !options5.force && existsSync2(join56(outDir, `${options5.id}.yaml`))) throw exists4(join56(outDir, `${options5.id}.yaml`), ctx);
|
|
259738
259827
|
const { client: client2, credit } = await model(ctx);
|
|
259739
259828
|
ctx.out.info(`generating a world from the description (size ${size2}${variants ? `, ${variants} variant${variants === 1 ? "" : "s"}` : ""})`);
|
|
@@ -259750,8 +259839,8 @@ async function worldGen(ctx, description2, options5) {
|
|
|
259750
259839
|
const paths3 = Object.keys(generated.files).map((name5) => join56(outDir, name5));
|
|
259751
259840
|
const taken2 = paths3.find((path9) => existsSync2(path9));
|
|
259752
259841
|
if (taken2 && !options5.force) throw exists4(taken2, ctx);
|
|
259753
|
-
await
|
|
259754
|
-
for (const [name5, text31] of Object.entries(generated.files)) await
|
|
259842
|
+
await mkdir24(outDir, { recursive: true });
|
|
259843
|
+
for (const [name5, text31] of Object.entries(generated.files)) await writeFile25(join56(outDir, name5), text31);
|
|
259755
259844
|
const rel = (path9) => relative20(ctx.io.cwd, path9) || ".";
|
|
259756
259845
|
const worldPath = rel(join56(outDir, `${generated.world.id}.yaml`));
|
|
259757
259846
|
const result = {
|
|
@@ -259771,8 +259860,8 @@ async function worldGen(ctx, description2, options5) {
|
|
|
259771
259860
|
next: [`ancha test new "<the test in one sentence>" --world ${generated.world.id}`]
|
|
259772
259861
|
};
|
|
259773
259862
|
if (keyFile) {
|
|
259774
|
-
await
|
|
259775
|
-
await
|
|
259863
|
+
await mkdir24(dirname23(keyFile), { recursive: true });
|
|
259864
|
+
await writeFile25(keyFile, `${JSON.stringify({ request: request2, result }, null, 2)}
|
|
259776
259865
|
`);
|
|
259777
259866
|
}
|
|
259778
259867
|
return report5(ctx, result);
|
|
@@ -259793,7 +259882,7 @@ function report5(ctx, result) {
|
|
|
259793
259882
|
var import_yaml17 = __toESM(require_dist(), 1);
|
|
259794
259883
|
import { createHash as createHash77 } from "node:crypto";
|
|
259795
259884
|
import { existsSync as existsSync3 } from "node:fs";
|
|
259796
|
-
import { mkdir as
|
|
259885
|
+
import { mkdir as mkdir25, readFile as readFile41, readdir as readdir10, writeFile as writeFile26 } from "node:fs/promises";
|
|
259797
259886
|
import { join as join57, relative as relative21, resolve as resolve46 } from "node:path";
|
|
259798
259887
|
init_src();
|
|
259799
259888
|
|
|
@@ -260203,7 +260292,7 @@ async function chooseWorld(ctx, id15, command = 'ancha test new "<sentence>"') {
|
|
|
260203
260292
|
const path9 = join57(dir2, `${chosen}.yaml`);
|
|
260204
260293
|
if (!existsSync3(path9)) throw new AnchaError("USAGE", `no world ${chosen} in ancha/worlds`, { hint: ids3.length ? `worlds: ${ids3.join(", ")}` : noWorldHint });
|
|
260205
260294
|
try {
|
|
260206
|
-
return parseWorldFile((0, import_yaml17.parse)(await
|
|
260295
|
+
return parseWorldFile((0, import_yaml17.parse)(await readFile41(path9, "utf8")));
|
|
260207
260296
|
} catch (error65) {
|
|
260208
260297
|
throw new AnchaError("SCENE_INVALID", `ancha/worlds/${chosen}.yaml: ${error65 instanceof Error ? error65.message : String(error65)}`, { hint: "run `ancha schema world` for the world file format" });
|
|
260209
260298
|
}
|
|
@@ -260238,7 +260327,7 @@ async function testNew(ctx, intent, options5) {
|
|
|
260238
260327
|
const request2 = { intent, world: world5.id, id: options5.id ?? null, out: relative21(ctx.io.cwd, outDir) };
|
|
260239
260328
|
const keyFile = options5.idempotencyKey === void 0 ? void 0 : join57(ctx.io.cwd, ".ancha", "test-new", `${createHash77("sha256").update(options5.idempotencyKey).digest("hex").slice(0, 32)}.json`);
|
|
260240
260329
|
if (keyFile && existsSync3(keyFile)) {
|
|
260241
|
-
const saved = JSON.parse(await
|
|
260330
|
+
const saved = JSON.parse(await readFile41(keyFile, "utf8"));
|
|
260242
260331
|
if (JSON.stringify(saved.request) !== JSON.stringify(request2)) throw new AnchaError("USAGE", "this --idempotency-key was used with different arguments", { hint: "use a new key for a new request" });
|
|
260243
260332
|
if ([saved.result.file, saved.result.record].every((file4) => existsSync3(resolve46(ctx.io.cwd, file4)))) return report6(ctx, { ...saved.result, reused: true });
|
|
260244
260333
|
}
|
|
@@ -260248,13 +260337,13 @@ async function testNew(ctx, intent, options5) {
|
|
|
260248
260337
|
const draft2 = await draftTest({ intent, world: world5, model: client2, ...options5.id && { id: options5.id }, onProgress: (line2) => ctx.out.info(` ${line2}`) });
|
|
260249
260338
|
const path9 = join57(outDir, `${draft2.test.id}.yaml`), recordPath = join57(outDir, `${draft2.test.id}.gen.json`);
|
|
260250
260339
|
if (existsSync3(path9) && !options5.force) throw exists5(ctx, path9);
|
|
260251
|
-
const before = existsSync3(path9) ? await
|
|
260340
|
+
const before = existsSync3(path9) ? await readFile41(path9, "utf8") : "";
|
|
260252
260341
|
const at6 = (/* @__PURE__ */ new Date()).toISOString();
|
|
260253
260342
|
const yaml = testYaml2({ ...draft2.test, generated: { by: "ancha test new", at: at6, from: intent, record: `${draft2.test.id}.gen.json` } }, intent);
|
|
260254
260343
|
const cost = Math.round(draft2.calls.reduce((sum6, call4) => sum6 + call4.costUsd, 0) * 1e6) / 1e6;
|
|
260255
|
-
await
|
|
260256
|
-
await
|
|
260257
|
-
await
|
|
260344
|
+
await mkdir25(outDir, { recursive: true });
|
|
260345
|
+
await writeFile26(path9, yaml);
|
|
260346
|
+
await writeFile26(recordPath, `${JSON.stringify({ generated: { by: "ancha test new", at: at6 }, request: { intent, world: world5.id }, prompt: draft2.prompt, calls: draft2.calls, cost_usd: cost }, null, 2)}
|
|
260258
260347
|
`);
|
|
260259
260348
|
const file3 = relative21(ctx.io.cwd, path9);
|
|
260260
260349
|
const people4 = [...new Set((draft2.test.checks ?? []).flatMap((check4) => JSON.stringify(check4).match(/"(?:to|from)":"([a-z][a-z0-9_-]*)"|\[\s*"([a-z][a-z0-9_-]*)"/g) ?? []).map((match3) => match3.replace(/^.*"([a-z][a-z0-9_-]*)"$/, "$1")))].filter((ref23) => (world5.people ?? []).some((person5) => person5.ref === ref23));
|
|
@@ -260273,8 +260362,8 @@ async function testNew(ctx, intent, options5) {
|
|
|
260273
260362
|
...credit === "workspace" && { modelCredit: "workspace" }
|
|
260274
260363
|
};
|
|
260275
260364
|
if (keyFile) {
|
|
260276
|
-
await
|
|
260277
|
-
await
|
|
260365
|
+
await mkdir25(join57(ctx.io.cwd, ".ancha", "test-new"), { recursive: true });
|
|
260366
|
+
await writeFile26(keyFile, `${JSON.stringify({ request: request2, result })}
|
|
260278
260367
|
`);
|
|
260279
260368
|
}
|
|
260280
260369
|
return report6(ctx, result);
|
|
@@ -260321,11 +260410,11 @@ init_scenes();
|
|
|
260321
260410
|
// packages/cli/src/kit/docs.ts
|
|
260322
260411
|
init_src();
|
|
260323
260412
|
init_assets();
|
|
260324
|
-
import { readFile as
|
|
260413
|
+
import { readFile as readFile42 } from "node:fs/promises";
|
|
260325
260414
|
var DOC_TOPICS = ["setup", "apps", "run", "traces", "explain", "compare", "tests", "scenes", "integrations", "cloud", "playgrounds", "cli-quickstart", "tools", "datasets", "company"];
|
|
260326
260415
|
async function loadDoc(topic = "setup") {
|
|
260327
260416
|
if (!DOC_TOPICS.includes(topic)) throw new AnchaError("USAGE", `unknown docs topic: ${topic}`, { hint: `available topics: ${DOC_TOPICS.join(", ")}` });
|
|
260328
|
-
return { topics: [...DOC_TOPICS], topic, markdown: await
|
|
260417
|
+
return { topics: [...DOC_TOPICS], topic, markdown: await readFile42(new URL(`docs/${topic === "tests" ? "scenes" : topic}.md`, assetRoot()), "utf8") };
|
|
260329
260418
|
}
|
|
260330
260419
|
function registerDocs(program2, ctx) {
|
|
260331
260420
|
program2.command("docs").description("read the bundled documentation: setup, the run loop, checks, SDK settings and the hosted workspace").argument("[topic]", `available: ${DOC_TOPICS.join(", ")}`).action(async (topic) => {
|
|
@@ -260346,7 +260435,7 @@ function step2(ctx) {
|
|
|
260346
260435
|
}
|
|
260347
260436
|
var BEGIN = "<!-- ancha:begin -->";
|
|
260348
260437
|
var END = "<!-- ancha:end -->";
|
|
260349
|
-
var managedSection = () =>
|
|
260438
|
+
var managedSection = () => readFile43(new URL("agents-section.md", assetRoot()), "utf8");
|
|
260350
260439
|
async function installAgents(cwd, tools2) {
|
|
260351
260440
|
const target6 = join58(cwd, "AGENTS.md");
|
|
260352
260441
|
const base6 = await managedSection();
|
|
@@ -260359,7 +260448,7 @@ Read \`ancha docs tools\` for function checks and registration.
|
|
|
260359
260448
|
const managed = base6.replace(END, wiring + END);
|
|
260360
260449
|
let original2;
|
|
260361
260450
|
try {
|
|
260362
|
-
original2 = await
|
|
260451
|
+
original2 = await readFile43(target6, "utf8");
|
|
260363
260452
|
} catch (error65) {
|
|
260364
260453
|
if (error65.code !== "ENOENT") throw error65;
|
|
260365
260454
|
const result = await applyScaffold(cwd, [{ relativePath: "AGENTS.md", content: managed }]);
|
|
@@ -260388,7 +260477,7 @@ async function ignoreAnchaDirectory(cwd) {
|
|
|
260388
260477
|
const target6 = join58(cwd, ".gitignore");
|
|
260389
260478
|
let original2;
|
|
260390
260479
|
try {
|
|
260391
|
-
original2 = await
|
|
260480
|
+
original2 = await readFile43(target6, "utf8");
|
|
260392
260481
|
} catch (error65) {
|
|
260393
260482
|
if (error65.code !== "ENOENT") throw error65;
|
|
260394
260483
|
const result = await applyScaffold(cwd, [{ relativePath: ".gitignore", content: ".ancha/\n" }]);
|
|
@@ -260472,7 +260561,7 @@ ${twins.map((twin) => (routed.includes(twin) ? ROUTED_TASKS[twin] : void 0) ?? t
|
|
|
260472
260561
|
}
|
|
260473
260562
|
var STARTER_FILES = ["scene.yaml", "oracle.mjs", "null.mjs"];
|
|
260474
260563
|
async function ownStarter(cwd) {
|
|
260475
|
-
const read7 = (name5) =>
|
|
260564
|
+
const read7 = (name5) => readFile43(join58(cwd, "scenes/starter", name5), "utf8").catch(() => void 0);
|
|
260476
260565
|
const scene2 = await read7("scene.yaml");
|
|
260477
260566
|
if (scene2 === void 0) return void 0;
|
|
260478
260567
|
let twins;
|
|
@@ -260503,7 +260592,7 @@ async function wireComposio(cwd, candidates2) {
|
|
|
260503
260592
|
const added = [], pending = [];
|
|
260504
260593
|
const result = { added, pending, passEnvAdded: false };
|
|
260505
260594
|
if (!candidates2.length) return result;
|
|
260506
|
-
const text31 = await
|
|
260595
|
+
const text31 = await readFile43(join58(cwd, "ancha.yaml"), "utf8");
|
|
260507
260596
|
let config12;
|
|
260508
260597
|
try {
|
|
260509
260598
|
config12 = parseConfigText(text31);
|
|
@@ -260553,7 +260642,7 @@ async function rewrite(cwd, relativePath, content2) {
|
|
|
260553
260642
|
}
|
|
260554
260643
|
}
|
|
260555
260644
|
async function listTests(cwd, tests) {
|
|
260556
|
-
const text31 = await
|
|
260645
|
+
const text31 = await readFile43(join58(cwd, "ancha.yaml"), "utf8");
|
|
260557
260646
|
let scenes;
|
|
260558
260647
|
try {
|
|
260559
260648
|
scenes = parseConfigText(text31).scenes;
|
|
@@ -260580,7 +260669,7 @@ async function listTests(cwd, tests) {
|
|
|
260580
260669
|
return true;
|
|
260581
260670
|
}
|
|
260582
260671
|
async function addExampleSeeds(file3, twins) {
|
|
260583
|
-
const doc = (0, import_yaml18.parseDocument)(await
|
|
260672
|
+
const doc = (0, import_yaml18.parseDocument)(await readFile43(file3, "utf8"));
|
|
260584
260673
|
const added = [], skipped = [];
|
|
260585
260674
|
for (const twin of twins) {
|
|
260586
260675
|
if (doc.hasIn(["seed", twin])) continue;
|
|
@@ -260596,7 +260685,7 @@ async function addExampleSeeds(file3, twins) {
|
|
|
260596
260685
|
doc.contents = before.contents;
|
|
260597
260686
|
}
|
|
260598
260687
|
}
|
|
260599
|
-
if (added.length > 0) await
|
|
260688
|
+
if (added.length > 0) await writeFile27(file3, doc.toString({ lineWidth: 0 }));
|
|
260600
260689
|
return { added, skipped };
|
|
260601
260690
|
}
|
|
260602
260691
|
var where2 = (mark) => `${mark.source}:${mark.line}`;
|
|
@@ -260655,7 +260744,7 @@ async function wireExistingConfig(cwd, fillMissing) {
|
|
|
260655
260744
|
const target6 = join58(cwd, "ancha.yaml");
|
|
260656
260745
|
let text31;
|
|
260657
260746
|
try {
|
|
260658
|
-
text31 = await
|
|
260747
|
+
text31 = await readFile43(target6, "utf8");
|
|
260659
260748
|
} catch {
|
|
260660
260749
|
return void 0;
|
|
260661
260750
|
}
|
|
@@ -260698,7 +260787,7 @@ function registerKit(program2, ctx) {
|
|
|
260698
260787
|
throw new AnchaError("CONFIG_INVALID", "init --intent needs a model key", { hint: "set OPENROUTER_API_KEY, or log in to your workspace with ancha login; or run ancha init without --intent" });
|
|
260699
260788
|
}
|
|
260700
260789
|
const detection = await detectProject(ctx.io.cwd, opts.agent);
|
|
260701
|
-
const configText = await
|
|
260790
|
+
const configText = await readFile43(join58(ctx.io.cwd, "ancha.yaml"), "utf8").catch(() => void 0);
|
|
260702
260791
|
const configured = configText !== void 0;
|
|
260703
260792
|
let task2 = configured || detection.slackApp !== void 0 || detection.agent === null ? void 0 : await taskSetup(ctx.io.cwd, detection.agent, { command: detection.agent });
|
|
260704
260793
|
const existingConfig = (() => {
|
|
@@ -260744,15 +260833,15 @@ min_pass_rate: 1
|
|
|
260744
260833
|
` },
|
|
260745
260834
|
...templates.map((file3) => ({ ...file3, relativePath: `scenes/${opts.template}/${file3.relativePath}` })),
|
|
260746
260835
|
...starterWorld ? [starterWorld] : [],
|
|
260747
|
-
{ relativePath: ".claude/skills/ancha/SKILL.md", content: await
|
|
260836
|
+
{ relativePath: ".claude/skills/ancha/SKILL.md", content: await readFile43(new URL("SKILL.md", assetRoot()), "utf8") },
|
|
260748
260837
|
...pe?.files ?? [],
|
|
260749
260838
|
...examples2?.files ?? []
|
|
260750
260839
|
];
|
|
260751
260840
|
await preflightFiles(ctx.io.cwd, [...files2, { relativePath: "AGENTS.md", content: "" }, { relativePath: ".gitignore", content: "" }]);
|
|
260752
260841
|
const updated = [];
|
|
260753
|
-
const rewritten = own2 === void 0 ? [] : await Promise.all(files2.filter((file3) => file3.relativePath.startsWith("scenes/starter/")).map(async (file3) => await
|
|
260842
|
+
const rewritten = own2 === void 0 ? [] : await Promise.all(files2.filter((file3) => file3.relativePath.startsWith("scenes/starter/")).map(async (file3) => await readFile43(join58(ctx.io.cwd, file3.relativePath), "utf8").catch(() => void 0) === file3.content ? void 0 : file3)).then((list19) => list19.filter((file3) => file3 !== void 0));
|
|
260754
260843
|
if (starterWorld && own2 !== void 0) {
|
|
260755
|
-
const before = await
|
|
260844
|
+
const before = await readFile43(join58(ctx.io.cwd, starterWorld.relativePath), "utf8").catch(() => void 0);
|
|
260756
260845
|
const previous = await loadSceneFile(join58(ctx.io.cwd, "scenes/starter/scene.yaml"));
|
|
260757
260846
|
if (before === worldFileYaml(sceneWorld(previous)) && before !== starterWorld.content) rewritten.push(starterWorld);
|
|
260758
260847
|
}
|
|
@@ -260798,7 +260887,7 @@ min_pass_rate: 1
|
|
|
260798
260887
|
}
|
|
260799
260888
|
const routeWiring = await wireComposio(ctx.io.cwd, routeTools);
|
|
260800
260889
|
if (routeWiring.added.length && !result.created.includes("ancha.yaml") && !updated.includes("ancha.yaml")) updated.push("ancha.yaml");
|
|
260801
|
-
const savedConfig = await
|
|
260890
|
+
const savedConfig = await readFile43(join58(ctx.io.cwd, "ancha.yaml"), "utf8").then((text31) => {
|
|
260802
260891
|
try {
|
|
260803
260892
|
return parseConfigText(text31);
|
|
260804
260893
|
} catch {
|
|
@@ -260873,9 +260962,9 @@ function registerSceneNew(scene2, ctx) {
|
|
|
260873
260962
|
} catch (error65) {
|
|
260874
260963
|
if (error65.code !== "ENOENT") throw error65;
|
|
260875
260964
|
}
|
|
260876
|
-
await
|
|
260965
|
+
await mkdir26(join58(ctx.io.cwd, "scenes"), { recursive: true });
|
|
260877
260966
|
try {
|
|
260878
|
-
await
|
|
260967
|
+
await mkdir26(target6);
|
|
260879
260968
|
} catch (cause) {
|
|
260880
260969
|
throw new AnchaError("USAGE", `cannot create scene destination: ${prefix2}`, { hint: "choose another id and remove unsafe symlinks", cause });
|
|
260881
260970
|
}
|
|
@@ -260883,7 +260972,7 @@ function registerSceneNew(scene2, ctx) {
|
|
|
260883
260972
|
const result = await applyScaffold(ctx.io.cwd, planned);
|
|
260884
260973
|
ctx.out.result({ id: id15, twins, ...result }, () => `Created ${prefix2}/scene.yaml and oracle/null companions. Validate: ancha scene validate ${prefix2}/scene.yaml`);
|
|
260885
260974
|
} catch (error65) {
|
|
260886
|
-
await
|
|
260975
|
+
await rm13(target6, { recursive: true, force: true });
|
|
260887
260976
|
throw error65;
|
|
260888
260977
|
}
|
|
260889
260978
|
});
|
|
@@ -261082,7 +261171,7 @@ async function suggestAgentProject(path9) {
|
|
|
261082
261171
|
import { realpathSync as realpathSync3 } from "node:fs";
|
|
261083
261172
|
init_src();
|
|
261084
261173
|
import { randomUUID as randomUUID20 } from "node:crypto";
|
|
261085
|
-
import { mkdir as
|
|
261174
|
+
import { mkdir as mkdir29, rm as rm17, writeFile as writeFile30 } from "node:fs/promises";
|
|
261086
261175
|
import { join as join62 } from "node:path";
|
|
261087
261176
|
init_assets();
|
|
261088
261177
|
|
|
@@ -261090,7 +261179,7 @@ init_assets();
|
|
|
261090
261179
|
init_src();
|
|
261091
261180
|
import { execFile as execFile9 } from "node:child_process";
|
|
261092
261181
|
import { createHash as createHash79, randomUUID as randomUUID18 } from "node:crypto";
|
|
261093
|
-
import { mkdir as
|
|
261182
|
+
import { mkdir as mkdir28, mkdtemp as mkdtemp10, readFile as readFile45, readdir as readdir12, rename as rename8, rm as rm15, writeFile as writeFile29 } from "node:fs/promises";
|
|
261094
261183
|
import { tmpdir as tmpdir9 } from "node:os";
|
|
261095
261184
|
import { join as join60 } from "node:path";
|
|
261096
261185
|
init_detect();
|
|
@@ -261101,7 +261190,7 @@ init_policy();
|
|
|
261101
261190
|
|
|
261102
261191
|
// backend/src/execution/runtime-cache.ts
|
|
261103
261192
|
import { createHash as createHash78, randomUUID as randomUUID17 } from "node:crypto";
|
|
261104
|
-
import { mkdir as
|
|
261193
|
+
import { mkdir as mkdir27, readFile as readFile44, readdir as readdir11, realpath as realpath13, rename as rename7, rm as rm14, writeFile as writeFile28 } from "node:fs/promises";
|
|
261105
261194
|
import { join as join59 } from "node:path";
|
|
261106
261195
|
init_assets();
|
|
261107
261196
|
async function runtimeCacheKey(source, project14, command, context3) {
|
|
@@ -261110,7 +261199,7 @@ async function runtimeCacheKey(source, project14, command, context3) {
|
|
|
261110
261199
|
for (const entry3 of (await readdir11(path9, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261111
261200
|
const relative31 = prefix2 + entry3.name;
|
|
261112
261201
|
if (entry3.isDirectory()) await visit4(join59(path9, entry3.name), relative31 + "/");
|
|
261113
|
-
else hash10.update(relative31).update("\0").update(await
|
|
261202
|
+
else hash10.update(relative31).update("\0").update(await readFile44(join59(path9, entry3.name))).update("\0");
|
|
261114
261203
|
}
|
|
261115
261204
|
}
|
|
261116
261205
|
await visit4(source);
|
|
@@ -261132,17 +261221,17 @@ async function rememberRuntime(workspace4, key5, image2) {
|
|
|
261132
261221
|
if (!/^sha256:[a-f0-9]{64}$/.test(image2)) throw new Error("Runtime must be pinned before caching");
|
|
261133
261222
|
const path9 = cachePath(key5), temporary = `${path9}.${randomUUID17()}.tmp`;
|
|
261134
261223
|
await preflightFiles(workspace4, [{ relativePath: path9, content: "" }, { relativePath: temporary, content: "" }]);
|
|
261135
|
-
await
|
|
261224
|
+
await mkdir27(join59(workspace4, ".ancha/agent-runtime-cache"), { recursive: true, mode: 448 });
|
|
261136
261225
|
try {
|
|
261137
|
-
await
|
|
261226
|
+
await writeFile28(join59(workspace4, temporary), JSON.stringify({ version: 1, image: image2 }), { flag: "wx", mode: 384 });
|
|
261138
261227
|
await rename7(join59(workspace4, temporary), join59(workspace4, path9));
|
|
261139
261228
|
} finally {
|
|
261140
|
-
await
|
|
261229
|
+
await rm14(join59(workspace4, temporary), { force: true });
|
|
261141
261230
|
}
|
|
261142
261231
|
}
|
|
261143
261232
|
|
|
261144
261233
|
// backend/src/execution/prepare-agent.ts
|
|
261145
|
-
var read6 = (directory, file3) =>
|
|
261234
|
+
var read6 = (directory, file3) => readFile45(join60(directory, file3), "utf8").catch((error65) => {
|
|
261146
261235
|
if (error65.code === "ENOENT") return void 0;
|
|
261147
261236
|
throw error65;
|
|
261148
261237
|
});
|
|
@@ -261278,13 +261367,13 @@ async function prepareAgent(workspace4, agentId2, options5 = {}) {
|
|
|
261278
261367
|
for (const entry3 of (await readdir12(path9, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261279
261368
|
const relative31 = prefix2 + entry3.name;
|
|
261280
261369
|
if (entry3.isDirectory()) await hashTree(join60(path9, entry3.name), relative31 + "/");
|
|
261281
|
-
else digest5.update(relative31).update("\0").update(await
|
|
261370
|
+
else digest5.update(relative31).update("\0").update(await readFile45(join60(path9, entry3.name))).update("\0");
|
|
261282
261371
|
}
|
|
261283
261372
|
}
|
|
261284
261373
|
await hashTree(source);
|
|
261285
261374
|
const fingerprint = digest5.digest("hex"), cacheRelative = `.ancha/agent-images/${fingerprint}.json`;
|
|
261286
261375
|
await preflightFiles(workspace4, [{ relativePath: cacheRelative, content: "" }]);
|
|
261287
|
-
const cached3 = await
|
|
261376
|
+
const cached3 = await readFile45(join60(workspace4, cacheRelative), "utf8").then((text31) => JSON.parse(text31)).catch(() => void 0);
|
|
261288
261377
|
let cachedImage;
|
|
261289
261378
|
if (cached3?.image && /^sha256:[a-f0-9]{64}$/.test(cached3.image)) {
|
|
261290
261379
|
try {
|
|
@@ -261301,7 +261390,7 @@ async function prepareAgent(workspace4, agentId2, options5 = {}) {
|
|
|
261301
261390
|
return { prepared: true, agent, runtime: plan4.kind, image: cachedImage.Id, reused: true, runtimeKey };
|
|
261302
261391
|
}
|
|
261303
261392
|
const dockerfile = join60(temporary, "Dockerfile");
|
|
261304
|
-
await
|
|
261393
|
+
await writeFile29(dockerfile, plan4.dockerfile, { mode: 384 });
|
|
261305
261394
|
options5.progress?.("Installing dependencies in an isolated runtime");
|
|
261306
261395
|
tags4.add(plan4.custom ? baseTag : tag3);
|
|
261307
261396
|
await runDocker(["build", "--tag", plan4.custom ? baseTag : tag3, "--file", dockerfile, source], runtime2.context, options5.signal);
|
|
@@ -261314,7 +261403,7 @@ async function prepareAgent(workspace4, agentId2, options5 = {}) {
|
|
|
261314
261403
|
USER root
|
|
261315
261404
|
RUN if [ -d ${quote3(nodeModules)} ] && [ ${quote3(nodeModules)} != '/opt/ancha/node_modules' ]; then mkdir -p /opt/ancha && cp -a ${quote3(nodeModules)} /opt/ancha/node_modules && chmod -R a+rX /opt/ancha/node_modules; fi
|
|
261316
261405
|
`;
|
|
261317
|
-
await
|
|
261406
|
+
await writeFile29(dockerfile, wrapper, { mode: 384 });
|
|
261318
261407
|
tags4.add(tag3);
|
|
261319
261408
|
await runDocker(["build", "--tag", tag3, "--file", dockerfile, source], runtime2.context, options5.signal);
|
|
261320
261409
|
image2 = inspect(await runDocker(["image", "inspect", tag3], runtime2.context, options5.signal));
|
|
@@ -261323,14 +261412,14 @@ RUN if [ -d ${quote3(nodeModules)} ] && [ ${quote3(nodeModules)} != '/opt/ancha/
|
|
|
261323
261412
|
const previous = resolved.execution?.mode === "container" ? resolved.execution : void 0;
|
|
261324
261413
|
const policy = parseExecutionPolicy({ memoryMb: 1024, ...previous ?? {}, mode: "container", preparation: "project", image: image2.Id });
|
|
261325
261414
|
if (JSON.stringify(await registry2.saved(agentId2)) !== JSON.stringify(saved)) invalid39("Agent settings changed while connecting. Connect again with the new settings.");
|
|
261326
|
-
await
|
|
261415
|
+
await mkdir28(join60(workspace4, ".ancha/agent-images"), { recursive: true });
|
|
261327
261416
|
const cacheTemp = cacheRelative + `.${randomUUID18()}.tmp`;
|
|
261328
261417
|
await preflightFiles(workspace4, [{ relativePath: cacheRelative, content: "" }, { relativePath: cacheTemp, content: "" }]);
|
|
261329
261418
|
try {
|
|
261330
|
-
await
|
|
261419
|
+
await writeFile29(join60(workspace4, cacheTemp), JSON.stringify({ image: image2.Id }), { flag: "wx", mode: 384 });
|
|
261331
261420
|
await rename8(join60(workspace4, cacheTemp), join60(workspace4, cacheRelative));
|
|
261332
261421
|
} finally {
|
|
261333
|
-
await
|
|
261422
|
+
await rm15(join60(workspace4, cacheTemp), { force: true });
|
|
261334
261423
|
}
|
|
261335
261424
|
checkSignal(options5.signal);
|
|
261336
261425
|
if (JSON.stringify(await registry2.saved(agentId2)) !== JSON.stringify(saved)) invalid39("Agent settings changed while connecting. Connect again with the new settings.");
|
|
@@ -261340,7 +261429,7 @@ RUN if [ -d ${quote3(nodeModules)} ] && [ ${quote3(nodeModules)} != '/opt/ancha/
|
|
|
261340
261429
|
} finally {
|
|
261341
261430
|
for (const image2 of tags4) if (!success2 || image2 === baseTag) await runDocker(["image", "rm", image2], runtime2.context).catch(() => {
|
|
261342
261431
|
});
|
|
261343
|
-
await
|
|
261432
|
+
await rm15(temporary, { recursive: true, force: true });
|
|
261344
261433
|
}
|
|
261345
261434
|
}
|
|
261346
261435
|
|
|
@@ -261352,7 +261441,7 @@ init_source();
|
|
|
261352
261441
|
init_workspace();
|
|
261353
261442
|
import { execFile as execFile10, spawn as spawn6 } from "node:child_process";
|
|
261354
261443
|
import { randomUUID as randomUUID19 } from "node:crypto";
|
|
261355
|
-
import { mkdtemp as mkdtemp11, rm as
|
|
261444
|
+
import { mkdtemp as mkdtemp11, rm as rm16 } from "node:fs/promises";
|
|
261356
261445
|
import { tmpdir as tmpdir10 } from "node:os";
|
|
261357
261446
|
import { join as join61 } from "node:path";
|
|
261358
261447
|
import { promisify as promisify9 } from "node:util";
|
|
@@ -261454,7 +261543,7 @@ async function probeAgentConnection(agent, signal, progress2, inheritedEnv = pro
|
|
|
261454
261543
|
if (remaining) failures.push(name5);
|
|
261455
261544
|
});
|
|
261456
261545
|
for (const child3 of children3) child3.kill("SIGKILL");
|
|
261457
|
-
await
|
|
261546
|
+
await rm16(temporary, { recursive: true, force: true });
|
|
261458
261547
|
if (failures.length) throw new AnchaError("INTERNAL", "The connection check finished but its temporary playground could not be fully removed. Check the local container runtime before retrying.");
|
|
261459
261548
|
}
|
|
261460
261549
|
}
|
|
@@ -261660,7 +261749,7 @@ var AgentConnectionService = class {
|
|
|
261660
261749
|
const finished = (/* @__PURE__ */ new Date()).toISOString();
|
|
261661
261750
|
Object.assign(value6, { state: "cancelled", phase: "finished", message: "Connect cancelled while queued.", finishedAt: finished, updatedAt: finished });
|
|
261662
261751
|
delete value6.blockedBy;
|
|
261663
|
-
await
|
|
261752
|
+
await rm17(join62(this.workspace, request2), { force: true });
|
|
261664
261753
|
await this.store.queueConnection(value6.agentId, value6);
|
|
261665
261754
|
}
|
|
261666
261755
|
async cancel(agentId2, operationId) {
|
|
@@ -261673,8 +261762,8 @@ var AgentConnectionService = class {
|
|
|
261673
261762
|
} else if (value6.state === "connecting" || value6.state === "queued") {
|
|
261674
261763
|
const request2 = `${this.path(agentId2)}.cancel`;
|
|
261675
261764
|
await preflightFiles(this.workspace, [{ relativePath: request2, content: "" }]);
|
|
261676
|
-
await
|
|
261677
|
-
await
|
|
261765
|
+
await mkdir29(join62(this.workspace, ".ancha/agent-connections"), { recursive: true, mode: 448 });
|
|
261766
|
+
await writeFile30(join62(this.workspace, request2), operationId, { mode: 384 });
|
|
261678
261767
|
}
|
|
261679
261768
|
return this.status(agentId2);
|
|
261680
261769
|
}
|
|
@@ -261739,7 +261828,7 @@ var AgentConnectionService = class {
|
|
|
261739
261828
|
value6.finishedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
261740
261829
|
value6.updatedAt = value6.finishedAt;
|
|
261741
261830
|
clearInterval(cancellation);
|
|
261742
|
-
await
|
|
261831
|
+
await rm17(join62(this.workspace, request2), { force: true });
|
|
261743
261832
|
await writes3;
|
|
261744
261833
|
await this.write(value6);
|
|
261745
261834
|
}
|
|
@@ -261753,7 +261842,7 @@ init_backend();
|
|
|
261753
261842
|
init_assets();
|
|
261754
261843
|
import { createServer as createServer6 } from "node:http";
|
|
261755
261844
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
261756
|
-
import { readFile as
|
|
261845
|
+
import { readFile as readFile46, realpath as realpath14, stat as stat15 } from "node:fs/promises";
|
|
261757
261846
|
import { isAbsolute as isAbsolute12 } from "node:path";
|
|
261758
261847
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
261759
261848
|
|
|
@@ -261765,7 +261854,7 @@ init_run_state();
|
|
|
261765
261854
|
init_report2();
|
|
261766
261855
|
init_baselines();
|
|
261767
261856
|
init_assets();
|
|
261768
|
-
import { readdir as readdir13, stat as stat14, writeFile as
|
|
261857
|
+
import { readdir as readdir13, stat as stat14, writeFile as writeFile31, rename as rename9, rm as rm18 } from "node:fs/promises";
|
|
261769
261858
|
import { createHash as createHash81, randomBytes as randomBytes9 } from "node:crypto";
|
|
261770
261859
|
import { join as join63 } from "node:path";
|
|
261771
261860
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
@@ -262260,10 +262349,10 @@ var ConsoleJobs = class {
|
|
|
262260
262349
|
const target6 = `.ancha/console-runs/${runId2}.events.json`, temporary = `${target6}.${randomBytes9(8).toString("hex")}.tmp`;
|
|
262261
262350
|
await preflightFiles(this.workspace, [{ relativePath: target6, content: "" }, { relativePath: temporary, content: "" }]);
|
|
262262
262351
|
try {
|
|
262263
|
-
await
|
|
262352
|
+
await writeFile31(join63(this.workspace, temporary), JSON.stringify(publicData(events3, this.secrets)), { flag: "wx", mode: 384 });
|
|
262264
262353
|
await rename9(join63(this.workspace, temporary), join63(this.workspace, target6));
|
|
262265
262354
|
} finally {
|
|
262266
|
-
await
|
|
262355
|
+
await rm18(join63(this.workspace, temporary), { force: true });
|
|
262267
262356
|
}
|
|
262268
262357
|
}
|
|
262269
262358
|
async savePublicAttempts(runId2, metadata8, events3, only5) {
|
|
@@ -262969,7 +263058,7 @@ init_world_data();
|
|
|
262969
263058
|
init_src();
|
|
262970
263059
|
init_assets();
|
|
262971
263060
|
import { randomUUID as randomUUID21 } from "node:crypto";
|
|
262972
|
-
import { readdir as readdir15, rm as
|
|
263061
|
+
import { readdir as readdir15, rm as rm19 } from "node:fs/promises";
|
|
262973
263062
|
import { join as join65 } from "node:path";
|
|
262974
263063
|
var setupPattern = /^setup_[a-f0-9-]{36}$/;
|
|
262975
263064
|
var runPattern = /^run_[A-Za-z0-9_-]{1,124}$/;
|
|
@@ -263067,7 +263156,7 @@ var SavedTestSetups = class {
|
|
|
263067
263156
|
async remove(id15) {
|
|
263068
263157
|
const relativePath = this.path(id15);
|
|
263069
263158
|
await preflightFiles(this.workspace, [{ relativePath, content: "" }]);
|
|
263070
|
-
await
|
|
263159
|
+
await rm19(join65(this.workspace, relativePath));
|
|
263071
263160
|
return { removed: true };
|
|
263072
263161
|
}
|
|
263073
263162
|
};
|
|
@@ -263122,12 +263211,12 @@ async function startConsole(opts) {
|
|
|
263122
263211
|
const files2 = /* @__PURE__ */ new Map();
|
|
263123
263212
|
if (opts.assets !== false) {
|
|
263124
263213
|
const assets = opts.assets ?? fileURLToPath7(new URL("ui/", assetRoot()));
|
|
263125
|
-
const html4 = await
|
|
263214
|
+
const html4 = await readFile46(`${assets}/index.html`).catch(() => {
|
|
263126
263215
|
throw new AnchaError("USAGE", "console assets are missing; reinstall Ancha with `npm install -g @ancha-labs/cli`");
|
|
263127
263216
|
});
|
|
263128
263217
|
files2.set("/", { body: html4, mime: "text/html; charset=utf-8" });
|
|
263129
|
-
files2.set("/app.js", { body: await
|
|
263130
|
-
files2.set("/style.css", { body: await
|
|
263218
|
+
files2.set("/app.js", { body: await readFile46(`${assets}/app.js`), mime: "text/javascript; charset=utf-8" });
|
|
263219
|
+
files2.set("/style.css", { body: await readFile46(`${assets}/style.css`), mime: "text/css; charset=utf-8" });
|
|
263131
263220
|
}
|
|
263132
263221
|
const backend = opts.backend ?? await openBackend();
|
|
263133
263222
|
const catalog3 = new ScenarioCatalog(workspace4, opts.configPath);
|
|
@@ -263682,8 +263771,8 @@ function registerConnection(program2, ctx) {
|
|
|
263682
263771
|
// packages/cli/src/commands/test-pull.ts
|
|
263683
263772
|
init_src();
|
|
263684
263773
|
import { createHash as createHash83, randomUUID as randomUUID22 } from "node:crypto";
|
|
263685
|
-
import { lstat as lstat11, mkdir as
|
|
263686
|
-
import { dirname as
|
|
263774
|
+
import { lstat as lstat11, mkdir as mkdir30, readFile as readFile47, realpath as realpath15, rename as rename10, rm as rm20, writeFile as writeFile32 } from "node:fs/promises";
|
|
263775
|
+
import { dirname as dirname24, join as join66 } from "node:path";
|
|
263687
263776
|
var hash8 = (text31) => createHash83("sha256").update(text31).digest("hex");
|
|
263688
263777
|
var safePath4 = (path9) => typeof path9 === "string" && path9.length > 0 && path9.length <= 1024 && !path9.startsWith("/") && !/[\\\x00-\x1f\x7f:]/.test(path9) && path9.split("/").every((p2) => p2 && !p2.startsWith("."));
|
|
263689
263778
|
async function writePulledTest(cwd, input5, force = false) {
|
|
@@ -263693,7 +263782,7 @@ async function writePulledTest(cwd, input5, force = false) {
|
|
|
263693
263782
|
let parent3 = root3;
|
|
263694
263783
|
for (const part of parts3.slice(0, -1)) {
|
|
263695
263784
|
parent3 = join66(parent3, part);
|
|
263696
|
-
await
|
|
263785
|
+
await mkdir30(parent3).catch((e) => {
|
|
263697
263786
|
if (e.code !== "EEXIST") throw e;
|
|
263698
263787
|
});
|
|
263699
263788
|
const info2 = await lstat11(parent3);
|
|
@@ -263707,18 +263796,18 @@ async function writePulledTest(cwd, input5, force = false) {
|
|
|
263707
263796
|
});
|
|
263708
263797
|
if (!info2) return null;
|
|
263709
263798
|
if (!info2.isFile() || info2.isSymbolicLink()) throw new AnchaError("USAGE", "The test path must be a regular file.");
|
|
263710
|
-
return
|
|
263799
|
+
return readFile47(target6, "utf8");
|
|
263711
263800
|
};
|
|
263712
263801
|
const before = await current();
|
|
263713
263802
|
if (!force && before !== null && before !== input5.yaml && hash8(before) !== input5.baseSha256 && hash8(before) !== input5.previousSha256)
|
|
263714
263803
|
throw new AnchaError("SESSION_CONFLICT", `${input5.path} changed since this run's bundle.`, { hint: "Keep your local edits, or repeat ancha test pull with --force to replace the file." });
|
|
263715
|
-
const temp = join66(
|
|
263804
|
+
const temp = join66(dirname24(target6), `.ancha-pull-${randomUUID22()}`);
|
|
263716
263805
|
try {
|
|
263717
|
-
await
|
|
263806
|
+
await writeFile32(temp, input5.yaml, { flag: "wx", mode: 384 });
|
|
263718
263807
|
if (await current() !== before) throw new AnchaError("SESSION_CONFLICT", `${input5.path} changed during the pull. Retry the command.`);
|
|
263719
263808
|
await rename10(temp, target6);
|
|
263720
263809
|
} finally {
|
|
263721
|
-
await
|
|
263810
|
+
await rm20(temp, { force: true });
|
|
263722
263811
|
}
|
|
263723
263812
|
return input5.path;
|
|
263724
263813
|
}
|
|
@@ -263740,8 +263829,8 @@ init_src();
|
|
|
263740
263829
|
init_scenes();
|
|
263741
263830
|
import { createHash as createHash84 } from "node:crypto";
|
|
263742
263831
|
import { constants as constants13 } from "node:fs";
|
|
263743
|
-
import { link as link8, lstat as lstat12, mkdir as
|
|
263744
|
-
import { dirname as
|
|
263832
|
+
import { link as link8, lstat as lstat12, mkdir as mkdir31, mkdtemp as mkdtemp12, open as open13, readFile as readFile48, readdir as readdir16, rename as rename11, rm as rm21, rmdir, unlink as unlink2, writeFile as writeFile33 } from "node:fs/promises";
|
|
263833
|
+
import { dirname as dirname25, join as join67, relative as relative22, resolve as resolve48 } from "node:path";
|
|
263745
263834
|
var sha2567 = (bytes4) => createHash84("sha256").update(bytes4).digest("hex");
|
|
263746
263835
|
var KEY_ORDER = ["version", "id", "title", "variant", "start", "attempts", "deadline", "timeout", "until", "checks", "pass", "world"];
|
|
263747
263836
|
var ordered4 = (test3) => Object.fromEntries([...KEY_ORDER.filter((key5) => key5 in test3), ...Object.keys(test3).filter((key5) => !KEY_ORDER.includes(key5)).sort()].map((key5) => [key5, test3[key5]]));
|
|
@@ -263786,9 +263875,9 @@ async function checkBytes(path9, bytes4) {
|
|
|
263786
263875
|
async function cleanupPublishedStage(path9) {
|
|
263787
263876
|
const target6 = await lstat12(path9);
|
|
263788
263877
|
if (target6.nlink === 1) return;
|
|
263789
|
-
for (const entry3 of await readdir16(
|
|
263878
|
+
for (const entry3 of await readdir16(dirname25(path9), { withFileTypes: true })) {
|
|
263790
263879
|
if (!entry3.isDirectory() || !/^\.vary-[a-zA-Z0-9]{6}$/.test(entry3.name)) continue;
|
|
263791
|
-
const folder2 = join67(
|
|
263880
|
+
const folder2 = join67(dirname25(path9), entry3.name), staged = join67(folder2, "test");
|
|
263792
263881
|
const info2 = await lstat12(staged).catch((error65) => {
|
|
263793
263882
|
if (error65.code === "ENOENT") return void 0;
|
|
263794
263883
|
throw error65;
|
|
@@ -263807,10 +263896,10 @@ async function createExclusive(path9, bytes4) {
|
|
|
263807
263896
|
await cleanupPublishedStage(path9);
|
|
263808
263897
|
return "reused";
|
|
263809
263898
|
}
|
|
263810
|
-
const temp = await mkdtemp12(join67(
|
|
263899
|
+
const temp = await mkdtemp12(join67(dirname25(path9), ".vary-"));
|
|
263811
263900
|
try {
|
|
263812
263901
|
const file3 = join67(temp, "test");
|
|
263813
|
-
await
|
|
263902
|
+
await writeFile33(file3, bytes4, { flag: "wx", mode: 384 });
|
|
263814
263903
|
try {
|
|
263815
263904
|
await link8(file3, path9);
|
|
263816
263905
|
return "written";
|
|
@@ -263821,14 +263910,14 @@ async function createExclusive(path9, bytes4) {
|
|
|
263821
263910
|
await cleanupPublishedStage(path9);
|
|
263822
263911
|
return "reused";
|
|
263823
263912
|
} finally {
|
|
263824
|
-
await
|
|
263913
|
+
await rm21(temp, { recursive: true, force: true });
|
|
263825
263914
|
}
|
|
263826
263915
|
}
|
|
263827
263916
|
async function atomicRecord(path9, bytes4, exclusive = false) {
|
|
263828
|
-
const temp = await mkdtemp12(join67(
|
|
263917
|
+
const temp = await mkdtemp12(join67(dirname25(path9), ".vary-"));
|
|
263829
263918
|
const file3 = join67(temp, "record");
|
|
263830
263919
|
try {
|
|
263831
|
-
await
|
|
263920
|
+
await writeFile33(file3, bytes4, { flag: "wx", mode: 384 });
|
|
263832
263921
|
if (!exclusive) await rename11(file3, path9);
|
|
263833
263922
|
else {
|
|
263834
263923
|
try {
|
|
@@ -263839,7 +263928,7 @@ async function atomicRecord(path9, bytes4, exclusive = false) {
|
|
|
263839
263928
|
}
|
|
263840
263929
|
}
|
|
263841
263930
|
} finally {
|
|
263842
|
-
await
|
|
263931
|
+
await rm21(temp, { recursive: true, force: true });
|
|
263843
263932
|
}
|
|
263844
263933
|
}
|
|
263845
263934
|
function prepare3(plan4, parent3, options5) {
|
|
@@ -263886,9 +263975,9 @@ async function mergeManifest(path9, next2) {
|
|
|
263886
263975
|
const entries4 = /* @__PURE__ */ new Map();
|
|
263887
263976
|
for (const entry3 of oldEntries) {
|
|
263888
263977
|
if (!record31(entry3) || !Number.isInteger(entry3.ordinal) || entry3.ordinal < 1 || entries4.has(entry3.ordinal) || !safeFile(entry3.file) || !hex5(entry3.sha256)) throw conflict4(path9);
|
|
263889
|
-
const bytes4 = await existing2(join67(
|
|
263978
|
+
const bytes4 = await existing2(join67(dirname25(path9), entry3.file));
|
|
263890
263979
|
const replacement = newEntries.find((item2) => item2.ordinal === entry3.ordinal);
|
|
263891
|
-
if (bytes4 === void 0 ? !replacement : sha2567(bytes4) !== entry3.sha256) throw conflict4(join67(
|
|
263980
|
+
if (bytes4 === void 0 ? !replacement : sha2567(bytes4) !== entry3.sha256) throw conflict4(join67(dirname25(path9), entry3.file));
|
|
263892
263981
|
entries4.set(entry3.ordinal, entry3);
|
|
263893
263982
|
}
|
|
263894
263983
|
for (const entry3 of newEntries) {
|
|
@@ -263903,7 +263992,7 @@ async function varyTestFiles(cwd, path9, options5 = {}, dependencies = {}) {
|
|
|
263903
263992
|
const source = resolve48(cwd, path9);
|
|
263904
263993
|
let test3;
|
|
263905
263994
|
try {
|
|
263906
|
-
test3 = parseSceneYaml(await
|
|
263995
|
+
test3 = parseSceneYaml(await readFile48(source, "utf8"));
|
|
263907
263996
|
} catch {
|
|
263908
263997
|
await loadSceneOrTest(cwd, source);
|
|
263909
263998
|
throw invalid40(`${path9}: cannot parse the parent test`);
|
|
@@ -263914,9 +264003,9 @@ async function varyTestFiles(cwd, path9, options5 = {}, dependencies = {}) {
|
|
|
263914
264003
|
path: relative22(cwd, source),
|
|
263915
264004
|
test: test3,
|
|
263916
264005
|
fingerprint: sceneFingerprint(loaded.scene),
|
|
263917
|
-
...loaded.world ? { world: parseSceneYaml(await
|
|
264006
|
+
...loaded.world ? { world: parseSceneYaml(await readFile48(loaded.world, "utf8")) } : {}
|
|
263918
264007
|
};
|
|
263919
|
-
const out = options5.out === void 0 ?
|
|
264008
|
+
const out = options5.out === void 0 ? dirname25(source) : resolve48(cwd, options5.out);
|
|
263920
264009
|
const keyPath = options5.idempotencyKey === void 0 ? void 0 : join67(resolve48(cwd), ".ancha", "test-variation", `${sha2567(options5.idempotencyKey)}.json`);
|
|
263921
264010
|
const inputHash = sceneFingerprint({ parent: parent3, options: resolved, out });
|
|
263922
264011
|
const keyConflict = () => new AnchaError("USAGE", "this idempotency key is already bound to different inputs or options", { hint: "repeat the original request, or choose another --idempotency-key" });
|
|
@@ -263942,10 +264031,10 @@ async function varyTestFiles(cwd, path9, options5 = {}, dependencies = {}) {
|
|
|
263942
264031
|
await mergeManifest(manifestPath, manifest2);
|
|
263943
264032
|
if (!options5.dryRun) {
|
|
263944
264033
|
if (keyPath) {
|
|
263945
|
-
await
|
|
264034
|
+
await mkdir31(dirname25(keyPath), { recursive: true });
|
|
263946
264035
|
await atomicRecord(keyPath, keyBytes, true);
|
|
263947
264036
|
}
|
|
263948
|
-
await
|
|
264037
|
+
await mkdir31(out, { recursive: true });
|
|
263949
264038
|
}
|
|
263950
264039
|
const variants = [];
|
|
263951
264040
|
for (const item2 of prepared) {
|
|
@@ -264013,8 +264102,8 @@ init_trace_import();
|
|
|
264013
264102
|
// packages/cli/src/commands/traces.ts
|
|
264014
264103
|
init_trace_import();
|
|
264015
264104
|
import { createHash as createHash85 } from "node:crypto";
|
|
264016
|
-
import { access as access13, readFile as
|
|
264017
|
-
import { basename as basename15, dirname as
|
|
264105
|
+
import { access as access13, readFile as readFile51, mkdir as mkdir32, stat as stat17, writeFile as writeFile34 } from "node:fs/promises";
|
|
264106
|
+
import { basename as basename15, dirname as dirname26, join as join69, relative as relative25, resolve as resolve50 } from "node:path";
|
|
264018
264107
|
import { isDeepStrictEqual as isDeepStrictEqual7 } from "node:util";
|
|
264019
264108
|
var import_yaml21 = __toESM(require_dist(), 1);
|
|
264020
264109
|
init_src();
|
|
@@ -264023,7 +264112,7 @@ init_run_store();
|
|
|
264023
264112
|
|
|
264024
264113
|
// backend/src/trace-ir.ts
|
|
264025
264114
|
init_src();
|
|
264026
|
-
import { readFile as
|
|
264115
|
+
import { readFile as readFile49 } from "node:fs/promises";
|
|
264027
264116
|
import { join as join68 } from "node:path";
|
|
264028
264117
|
var VENDOR_API_BASES2 = {
|
|
264029
264118
|
slack: "https://slack.com",
|
|
@@ -264096,7 +264185,7 @@ function attemptToIr(entries4, traceId, agent, saved) {
|
|
|
264096
264185
|
return [{ ir: "ancha.trace/v1", trace_id: traceId, ...agent !== void 0 && { agent }, source: "ancha-run", started_at: entries4[0]?.tSim ?? saved?.scene?.start_time, ...saved?.scene && { test: saved.scene, input: saved.scene.trigger?.input ?? { messages: [{ role: "user", content: saved.scene.task ?? saved.scene.trigger?.task ?? "" }] } }, ...output2?.output !== void 0 && { output: output2.output } }, ...records6];
|
|
264097
264186
|
}
|
|
264098
264187
|
async function readAttemptTrace(dir2) {
|
|
264099
|
-
const text31 = (await
|
|
264188
|
+
const text31 = (await readFile49(join68(dir2, "trace.jsonl"), "utf8")).trim();
|
|
264100
264189
|
return text31 ? text31.split("\n").map((line2) => JSON.parse(line2)) : [];
|
|
264101
264190
|
}
|
|
264102
264191
|
|
|
@@ -264219,7 +264308,7 @@ async function listTraces(source, { limit: limit2, since, name: name5 }, env2, f
|
|
|
264219
264308
|
}
|
|
264220
264309
|
|
|
264221
264310
|
// packages/cli/src/trace-files.ts
|
|
264222
|
-
import { readFile as
|
|
264311
|
+
import { readFile as readFile50, stat as stat16 } from "node:fs/promises";
|
|
264223
264312
|
import { basename as basename14, relative as relative23, resolve as resolve49 } from "node:path";
|
|
264224
264313
|
init_src();
|
|
264225
264314
|
var MB3 = 1024 * 1024;
|
|
@@ -264248,7 +264337,7 @@ async function findTraceFiles(cwd, args) {
|
|
|
264248
264337
|
return [...found].sort();
|
|
264249
264338
|
}
|
|
264250
264339
|
async function readTraceTexts(cwd, paths3) {
|
|
264251
|
-
return Promise.all(paths3.map(async (path9) => ({ file: relative23(cwd, path9) || basename14(path9), name: basename14(path9), text: await
|
|
264340
|
+
return Promise.all(paths3.map(async (path9) => ({ file: relative23(cwd, path9) || basename14(path9), name: basename14(path9), text: await readFile50(path9, "utf8").catch(() => void 0) })));
|
|
264252
264341
|
}
|
|
264253
264342
|
function readTraceUnits(texts4, { fileToIr: fileToIr2, sourceOf: sourceOf2 }) {
|
|
264254
264343
|
const drafts = /* @__PURE__ */ new Map(), skipped = [], read7 = [];
|
|
@@ -264710,7 +264799,7 @@ var importedCheckLines = (scene2, production3) => [
|
|
|
264710
264799
|
...importedChecks(scene2, production3).map((c) => ` ${c.id}: ${c.required ? "required" : "optional"}, ${c.production} in production`)
|
|
264711
264800
|
];
|
|
264712
264801
|
async function localChanges(dir2) {
|
|
264713
|
-
const text31 = await
|
|
264802
|
+
const text31 = await readFile51(join69(dir2, "scene.yaml"), "utf8").catch(() => void 0);
|
|
264714
264803
|
if (text31 === void 0) return void 0;
|
|
264715
264804
|
const local2 = (() => {
|
|
264716
264805
|
try {
|
|
@@ -264721,7 +264810,7 @@ async function localChanges(dir2) {
|
|
|
264721
264810
|
})(), mark = MARK.exec(text31)?.[1];
|
|
264722
264811
|
if (local2 === void 0 || mark === void 0) return { added: [], other: true };
|
|
264723
264812
|
if (digest4(local2) === mark) return { added: [], other: false };
|
|
264724
|
-
const production3 = await
|
|
264813
|
+
const production3 = await readFile51(join69(dir2, "production.json"), "utf8").then((t) => JSON.parse(t).checks, () => void 0);
|
|
264725
264814
|
const added = production3 ? checksOf2(local2).filter((c) => !Object.hasOwn(production3, c.id)) : [];
|
|
264726
264815
|
const addedIds = new Set(added.map((c) => c.id));
|
|
264727
264816
|
const required6 = (Array.isArray(local2.pass) ? local2.pass : checksOf2(local2).map((c) => c.id)).filter((id15) => addedIds.has(id15));
|
|
@@ -264760,22 +264849,22 @@ function sceneToWrite(next2, changes) {
|
|
|
264760
264849
|
}
|
|
264761
264850
|
async function writeWorld(ctx, world5, dest, changes) {
|
|
264762
264851
|
const dir2 = resolve50(ctx.io.cwd, dest, world5.name);
|
|
264763
|
-
await
|
|
264852
|
+
await mkdir32(dir2, { recursive: true });
|
|
264764
264853
|
const { scene: content2, kept } = sceneToWrite(world5.scene, changes);
|
|
264765
264854
|
const scene2 = join69(dir2, "scene.yaml");
|
|
264766
264855
|
const { sceneFiles: sceneFiles2 } = await Promise.resolve().then(() => (init_rebuild(), rebuild_exports));
|
|
264767
264856
|
const files2 = sceneFiles2(content2);
|
|
264768
|
-
await
|
|
264857
|
+
await writeFile34(scene2, `# Rebuilt by Ancha from a production trace (world ${world5.id}). Where each part came from: provenance.json.
|
|
264769
264858
|
# ancha pull: ${world5.id} ${digest4(sceneFiles2(world5.scene).scene)}
|
|
264770
264859
|
${(0, import_yaml21.stringify)(files2.scene)}`);
|
|
264771
|
-
if (files2.observations !== void 0) await
|
|
264772
|
-
if (world5.record) await
|
|
264773
|
-
await
|
|
264774
|
-
if (world5.summary?.candidates) await
|
|
264775
|
-
await
|
|
264860
|
+
if (files2.observations !== void 0) await writeFile34(join69(dir2, "observations.jsonl"), files2.observations);
|
|
264861
|
+
if (world5.record) await writeFile34(join69(dir2, "production.jsonl"), productionLines(world5.record));
|
|
264862
|
+
await writeFile34(join69(dir2, "provenance.json"), JSON.stringify(world5.provenance, null, 2) + "\n");
|
|
264863
|
+
if (world5.summary?.candidates) await writeFile34(join69(dir2, "candidates.json"), JSON.stringify(world5.summary.candidates, null, 2) + "\n");
|
|
264864
|
+
await writeFile34(join69(dir2, "questions.json"), JSON.stringify(world5.questions ?? [], null, 2) + "\n");
|
|
264776
264865
|
if (world5.summary?.production !== void 0) {
|
|
264777
264866
|
const checks2 = { ...Object.fromEntries(checksOf2(world5.scene).map((c) => [c.id, "unknown"])), ...world5.summary.production };
|
|
264778
|
-
await
|
|
264867
|
+
await writeFile34(join69(dir2, "production.json"), JSON.stringify({ trace: world5.summary.trace, checks: checks2, signatures: Object.fromEntries(checksOf2(world5.scene).map((c) => [c.id, productionSignature(c)])) }, null, 2) + "\n");
|
|
264779
264868
|
}
|
|
264780
264869
|
await loadSceneFile(scene2);
|
|
264781
264870
|
return { dir: dir2, scene: scene2, kept };
|
|
@@ -264797,7 +264886,7 @@ async function report7(ctx, world5, written) {
|
|
|
264797
264886
|
...open17.length ? [` answer: ancha pull ${world5.id.slice(0, 8)} --answer <question>=<value>; ancha traces show ${world5.id.slice(0, 8)} says how for each`] : [],
|
|
264798
264887
|
...traceConnectionLines(connection4),
|
|
264799
264888
|
`next: ${connection4.commands.init ? `${connection4.commands.init}, then ` : ""}${connection4.commands.run}`,
|
|
264800
|
-
...seen ? [] : [`note: scenes: in ancha.yaml does not include ${where3}; add ${relative25(ctx.io.cwd,
|
|
264889
|
+
...seen ? [] : [`note: scenes: in ancha.yaml does not include ${where3}; add ${relative25(ctx.io.cwd, dirname26(written.dir)) || "."}/**/scene.yaml to run it with the rest`]
|
|
264801
264890
|
].join("\n")
|
|
264802
264891
|
);
|
|
264803
264892
|
}
|
|
@@ -265291,7 +265380,7 @@ function registerTraces(program2, ctx) {
|
|
|
265291
265380
|
});
|
|
265292
265381
|
}
|
|
265293
265382
|
async function traceSource(ctx, trace2, from) {
|
|
265294
|
-
if (!from) return { text: await
|
|
265383
|
+
if (!from) return { text: await readFile51(resolve50(ctx.io.cwd, trace2), "utf8").catch(() => {
|
|
265295
265384
|
throw new AnchaError("USAGE", `cannot read ${trace2}`, { hint: "pass the path of a trace file: ancha import --offline <trace.jsonl>" });
|
|
265296
265385
|
}), name: basename15(trace2), label: basename15(trace2) };
|
|
265297
265386
|
const doc = await fetchTrace(from, trace2, ctx.io.env);
|
|
@@ -265299,7 +265388,7 @@ async function traceSource(ctx, trace2, from) {
|
|
|
265299
265388
|
return { text: JSON.stringify(doc), name: `${from}-${id15}`.slice(0, 80), label: `${from === "langfuse" ? "Langfuse" : "LangSmith"} trace ${id15}` };
|
|
265300
265389
|
}
|
|
265301
265390
|
async function traceFileLines(ctx, file3) {
|
|
265302
|
-
const text31 = await
|
|
265391
|
+
const text31 = await readFile51(resolve50(ctx.io.cwd, file3), "utf8").catch(() => {
|
|
265303
265392
|
throw new AnchaError("USAGE", `cannot read ${file3}`, { hint: "pass the path of a trace file: ancha traces diff <trace.jsonl> latest" });
|
|
265304
265393
|
});
|
|
265305
265394
|
return { text: text31, lines: await traceTextLines(text31, basename15(file3)) };
|
|
@@ -265372,9 +265461,9 @@ async function writeRecords(ctx, conversations, dest) {
|
|
|
265372
265461
|
const seen = conversations.flatMap((c) => recordsOf2(toolCallsOf(c.lines), { conversation: c.id }));
|
|
265373
265462
|
if (!seen.length) return void 0;
|
|
265374
265463
|
const path9 = resolve50(ctx.io.cwd, dest, "records.jsonl");
|
|
265375
|
-
const merged = mergeRecords2(readRecordLines2(await
|
|
265376
|
-
await
|
|
265377
|
-
await
|
|
265464
|
+
const merged = mergeRecords2(readRecordLines2(await readFile51(path9, "utf8").catch(() => "")), seen);
|
|
265465
|
+
await mkdir32(dirname26(path9), { recursive: true });
|
|
265466
|
+
await writeFile34(path9, recordLines2(merged));
|
|
265378
265467
|
const types = merged.reduce((all9, r2) => all9.set(r2.type, (all9.get(r2.type) ?? 0) + 1), /* @__PURE__ */ new Map());
|
|
265379
265468
|
return { path: relative25(ctx.io.cwd, path9), count: merged.length, types: Object.fromEntries(types) };
|
|
265380
265469
|
}
|
|
@@ -265386,7 +265475,7 @@ async function importLocally(ctx, source, options5) {
|
|
|
265386
265475
|
const { text: text31 } = source, all9 = await traceConversations(text31, source.name);
|
|
265387
265476
|
const { sceneFiles: sceneFiles2 } = await Promise.resolve().then(() => (init_trace_import(), trace_import_exports));
|
|
265388
265477
|
const rebuild3 = rebuildTraceImport;
|
|
265389
|
-
const checks2 = options5.checks ? readImportChecks(await
|
|
265478
|
+
const checks2 = options5.checks ? readImportChecks(await readFile51(resolve50(ctx.io.cwd, options5.checks), "utf8").catch(() => {
|
|
265390
265479
|
throw new AnchaError("USAGE", `cannot read checks file ${options5.checks}`);
|
|
265391
265480
|
})) : void 0;
|
|
265392
265481
|
const picked = options5.conversation === void 0 ? all9 : all9.filter((c) => c.id === options5.conversation || c.traces.includes(options5.conversation));
|
|
@@ -265405,7 +265494,7 @@ async function importLocally(ctx, source, options5) {
|
|
|
265405
265494
|
const made = [], skipped = [];
|
|
265406
265495
|
for (const [i, conversation3] of picked.entries()) {
|
|
265407
265496
|
const examples2 = [...all9.filter((c) => c !== conversation3).map((c) => c.lines), ...files2], customer3 = customers3.people[i];
|
|
265408
|
-
const earlier2 = options5.resetAnswers ? {} : await
|
|
265497
|
+
const earlier2 = options5.resetAnswers ? {} : await readFile51(resolve50(ctx.io.cwd, options5.dest, named5.get(conversation3), "answers.json"), "utf8").then((text32) => JSON.parse(text32), () => ({}));
|
|
265409
265498
|
try {
|
|
265410
265499
|
const preview = rebuild3(conversation3.lines, { id: named5.get(conversation3), withRecords: true, examples: examples2, useReportedResults: options5.useReportedResults });
|
|
265411
265500
|
const answers = { ...answersFor(preview.questions, earlier2, options5.answer), ...options5.expect && { "checks.expect": options5.expect } };
|
|
@@ -265418,22 +265507,22 @@ async function importLocally(ctx, source, options5) {
|
|
|
265418
265507
|
}
|
|
265419
265508
|
const paths3 = made.map((m) => join69(resolve50(ctx.io.cwd, options5.dest, m.id), "scene.yaml"));
|
|
265420
265509
|
if (!options5.force) {
|
|
265421
|
-
for (const path9 of paths3) if (await
|
|
265510
|
+
for (const path9 of paths3) if (await readFile51(path9, "utf8").then(() => true, () => false)) throw new AnchaError("USAGE", `${relative25(ctx.io.cwd, path9)} exists; --force replaces it`);
|
|
265422
265511
|
}
|
|
265423
265512
|
for (const [i, m] of made.entries()) {
|
|
265424
|
-
const path9 = paths3[i], dir2 =
|
|
265425
|
-
await
|
|
265513
|
+
const path9 = paths3[i], dir2 = dirname26(path9);
|
|
265514
|
+
await mkdir32(dir2, { recursive: true });
|
|
265426
265515
|
const files3 = sceneFiles2(m.made.scene);
|
|
265427
|
-
await
|
|
265428
|
-
await
|
|
265429
|
-
await
|
|
265430
|
-
if (files3.observations !== void 0) await
|
|
265431
|
-
if (m.made.record) await
|
|
265432
|
-
if (m.made.production !== void 0) await
|
|
265516
|
+
await writeFile34(path9, (0, import_yaml21.stringify)(files3.scene, { lineWidth: 0 }));
|
|
265517
|
+
await writeFile34(join69(dir2, "candidates.json"), JSON.stringify(m.made.candidates, null, 2) + "\n");
|
|
265518
|
+
await writeFile34(join69(dir2, "answers.json"), JSON.stringify(m.answers, null, 2) + "\n");
|
|
265519
|
+
if (files3.observations !== void 0) await writeFile34(join69(dir2, "observations.jsonl"), files3.observations);
|
|
265520
|
+
if (m.made.record) await writeFile34(join69(dir2, "production.jsonl"), productionLines(m.made.record));
|
|
265521
|
+
if (m.made.production !== void 0) await writeFile34(join69(dir2, "production.json"), `${JSON.stringify({ trace: m.made.summary.trace, checks: { ...Object.fromEntries(checksOf2(m.made.scene).map((c) => [c.id, "unknown"])), ...m.made.production }, signatures: Object.fromEntries(checksOf2(m.made.scene).map((c) => [c.id, productionSignature(c)])) }, null, 2)}
|
|
265433
265522
|
`);
|
|
265434
|
-
await
|
|
265523
|
+
await writeFile34(join69(dir2, "provenance.json"), `${JSON.stringify({ summary: m.made.summary, evidence: m.made.evidence, candidates: m.made.candidates, provenance: m.made.provenance, questions: m.made.questions, ...all9.length > 1 && { conversation: { id: m.conversation.id, traces: m.conversation.traces } } }, null, 2)}
|
|
265435
265524
|
`);
|
|
265436
|
-
await
|
|
265525
|
+
await writeFile34(join69(dir2, "questions.json"), `${JSON.stringify(m.made.questions, null, 2)}
|
|
265437
265526
|
`);
|
|
265438
265527
|
await loadSceneFile(path9);
|
|
265439
265528
|
}
|
|
@@ -265508,8 +265597,8 @@ function evidenceLines2(made) {
|
|
|
265508
265597
|
|
|
265509
265598
|
// packages/cli/src/commands/test-import.ts
|
|
265510
265599
|
import { existsSync as existsSync4 } from "node:fs";
|
|
265511
|
-
import { access as access14, mkdir as
|
|
265512
|
-
import { basename as basename16, dirname as
|
|
265600
|
+
import { access as access14, mkdir as mkdir33, readFile as readFile52, writeFile as writeFile35 } from "node:fs/promises";
|
|
265601
|
+
import { basename as basename16, dirname as dirname27, extname as extname2, isAbsolute as isAbsolute13, relative as relative26, resolve as resolve51 } from "node:path";
|
|
265513
265602
|
init_src();
|
|
265514
265603
|
init_detect();
|
|
265515
265604
|
init_function_tools();
|
|
@@ -265542,7 +265631,7 @@ async function testImport(ctx, file3, options5) {
|
|
|
265542
265631
|
}
|
|
265543
265632
|
let text31, encoding;
|
|
265544
265633
|
try {
|
|
265545
|
-
({ text: text31, encoding } = decodeEvalText(await
|
|
265634
|
+
({ text: text31, encoding } = decodeEvalText(await readFile52(path9)));
|
|
265546
265635
|
} catch (error65) {
|
|
265547
265636
|
throw new AnchaError("USAGE", `cannot read ${file3}: ${error65.code === "ENOENT" ? "no such file" : error65 instanceof Error ? error65.message : String(error65)}`, { hint: "ancha test import <evals file> --world <id>" });
|
|
265548
265637
|
}
|
|
@@ -265576,11 +265665,11 @@ ${skipped.slice(0, 10).map((s3) => `item ${s3.item}: ${s3.reason}`).join("\n")}`
|
|
|
265576
265665
|
const tests = [];
|
|
265577
265666
|
for (const test3 of imported2.tests) {
|
|
265578
265667
|
const target6 = resolve51(ctx.io.cwd, test3.path);
|
|
265579
|
-
const before = existsSync4(target6) ? await
|
|
265668
|
+
const before = existsSync4(target6) ? await readFile52(target6, "utf8") : void 0;
|
|
265580
265669
|
const status6 = before === void 0 ? "written" : before === test3.yaml ? "unchanged" : !editedSinceImport(before) ? "updated" : options5.force ? "written" : "kept";
|
|
265581
265670
|
if (status6 === "written" || status6 === "updated") {
|
|
265582
|
-
await
|
|
265583
|
-
await
|
|
265671
|
+
await mkdir33(dirname27(target6), { recursive: true });
|
|
265672
|
+
await writeFile35(target6, test3.yaml);
|
|
265584
265673
|
}
|
|
265585
265674
|
tests.push({ id: String(test3.scene.id), file: relative26(ctx.io.cwd, target6), checks: test3.scene.checks.map(kind), status: status6 });
|
|
265586
265675
|
}
|
|
@@ -265628,7 +265717,7 @@ function registerTestImport(tests, ctx) {
|
|
|
265628
265717
|
}
|
|
265629
265718
|
|
|
265630
265719
|
// packages/cli/src/commands/test-files.ts
|
|
265631
|
-
import { readFile as
|
|
265720
|
+
import { readFile as readFile53, stat as stat18 } from "node:fs/promises";
|
|
265632
265721
|
import { basename as basename17, relative as relative27, resolve as resolve52 } from "node:path";
|
|
265633
265722
|
init_src();
|
|
265634
265723
|
init_scenes();
|
|
@@ -265650,7 +265739,7 @@ async function showTestFile(ctx, ref23) {
|
|
|
265650
265739
|
const matches11 = [];
|
|
265651
265740
|
for (const file3 of await projectTestFiles(ctx)) {
|
|
265652
265741
|
try {
|
|
265653
|
-
const doc2 = parseSceneYaml(await
|
|
265742
|
+
const doc2 = parseSceneYaml(await readFile53(resolve52(ctx.io.cwd, file3), "utf8"));
|
|
265654
265743
|
if (doc2 && typeof doc2 === "object" && "id" in doc2 && doc2.id === ref23) matches11.push(file3);
|
|
265655
265744
|
} catch {
|
|
265656
265745
|
}
|
|
@@ -265661,7 +265750,7 @@ async function showTestFile(ctx, ref23) {
|
|
|
265661
265750
|
path9 = matches11[0];
|
|
265662
265751
|
}
|
|
265663
265752
|
const [{ scene: scene2, world: worldPath }] = await loadScenes(ctx.io.cwd, [path9]);
|
|
265664
|
-
const doc = parseSceneYaml(await
|
|
265753
|
+
const doc = parseSceneYaml(await readFile53(resolve52(ctx.io.cwd, path9), "utf8"));
|
|
265665
265754
|
const world5 = {
|
|
265666
265755
|
...worldPath !== void 0 && { id: basename17(worldPath, ".yaml"), path: relative27(ctx.io.cwd, worldPath) },
|
|
265667
265756
|
tools: scene2.twins
|
|
@@ -265944,7 +266033,7 @@ Run again with ancha test run ${saved.id}`);
|
|
|
265944
266033
|
// packages/cli/src/commands/sandbox.ts
|
|
265945
266034
|
var import_yaml22 = __toESM(require_dist(), 1);
|
|
265946
266035
|
init_src();
|
|
265947
|
-
import { readFile as
|
|
266036
|
+
import { readFile as readFile54 } from "node:fs/promises";
|
|
265948
266037
|
import { resolve as resolve54 } from "node:path";
|
|
265949
266038
|
init_backend();
|
|
265950
266039
|
function tools(value6) {
|
|
@@ -265991,7 +266080,7 @@ Use --json to export this configuration.`);
|
|
|
265991
266080
|
if ([opts.tools, opts.preset, opts.definition].filter(Boolean).length > 1) throw new AnchaError("USAGE", "choose --tools, --preset or --definition");
|
|
265992
266081
|
let input5;
|
|
265993
266082
|
if (opts.definition) {
|
|
265994
|
-
const doc = (0, import_yaml22.parseDocument)(await
|
|
266083
|
+
const doc = (0, import_yaml22.parseDocument)(await readFile54(resolve54(ctx.io.cwd, opts.definition), "utf8"));
|
|
265995
266084
|
if (doc.errors.length) throw new AnchaError("CONFIG_INVALID", doc.errors.map((error65) => error65.message).join("; "));
|
|
265996
266085
|
input5 = doc.toJS({ maxAliasCount: 100 });
|
|
265997
266086
|
if (opts.name && input5 && typeof input5 === "object" && !Array.isArray(input5)) input5 = { ...input5, name: opts.name };
|
|
@@ -282594,7 +282683,7 @@ init_src();
|
|
|
282594
282683
|
init_backend();
|
|
282595
282684
|
import { fork as fork2 } from "node:child_process";
|
|
282596
282685
|
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
282597
|
-
import { mkdir as
|
|
282686
|
+
import { mkdir as mkdir34, open as open14, readFile as readFile55, rename as rename12, rm as rm22, stat as stat19, writeFile as writeFile36 } from "node:fs/promises";
|
|
282598
282687
|
import { createRequire as createRequire6 } from "node:module";
|
|
282599
282688
|
import { join as join70 } from "node:path";
|
|
282600
282689
|
var WORLD_SERVER_IDLE_MS = 10 * 6e4;
|
|
@@ -282604,13 +282693,13 @@ var LOCK_FILE = "world-server.lock";
|
|
|
282604
282693
|
var dir = (cwd) => join70(cwd, ".ancha");
|
|
282605
282694
|
async function writePrivate(path9, value6) {
|
|
282606
282695
|
const temporary = `${path9}.${process.pid}.tmp`;
|
|
282607
|
-
await
|
|
282696
|
+
await writeFile36(temporary, `${JSON.stringify(value6, null, 2)}
|
|
282608
282697
|
`, { mode: 384 });
|
|
282609
282698
|
await rename12(temporary, path9);
|
|
282610
282699
|
}
|
|
282611
282700
|
async function readJson2(path9) {
|
|
282612
282701
|
try {
|
|
282613
|
-
return JSON.parse(await
|
|
282702
|
+
return JSON.parse(await readFile55(path9, "utf8"));
|
|
282614
282703
|
} catch {
|
|
282615
282704
|
return void 0;
|
|
282616
282705
|
}
|
|
@@ -282638,7 +282727,7 @@ async function withLock(cwd, work) {
|
|
|
282638
282727
|
if (error65.code !== "EEXIST") throw error65;
|
|
282639
282728
|
const age2 = Date.now() - await stat19(path9).then((s3) => s3.mtimeMs, () => Date.now());
|
|
282640
282729
|
if (age2 > 3e4) {
|
|
282641
|
-
await
|
|
282730
|
+
await rm22(path9, { force: true });
|
|
282642
282731
|
continue;
|
|
282643
282732
|
}
|
|
282644
282733
|
if (attempt2 > 150) throw new AnchaError("SESSION_CONFLICT", "another ancha world up is starting the local world server", { hint: "retry in a few seconds" });
|
|
@@ -282648,11 +282737,11 @@ async function withLock(cwd, work) {
|
|
|
282648
282737
|
try {
|
|
282649
282738
|
return await work();
|
|
282650
282739
|
} finally {
|
|
282651
|
-
await
|
|
282740
|
+
await rm22(path9, { force: true });
|
|
282652
282741
|
}
|
|
282653
282742
|
}
|
|
282654
282743
|
async function localWorldServer(cwd) {
|
|
282655
|
-
await
|
|
282744
|
+
await mkdir34(dir(cwd), { recursive: true });
|
|
282656
282745
|
const path9 = join70(dir(cwd), SERVER_FILE);
|
|
282657
282746
|
const current = await readJson2(path9);
|
|
282658
282747
|
if (current?.version === CLI_VERSION && await alive3(current)) return current;
|
|
@@ -282710,7 +282799,7 @@ function startWorldServer(cwd, controlToken) {
|
|
|
282710
282799
|
});
|
|
282711
282800
|
}
|
|
282712
282801
|
async function recordWorld(cwd, envId, record32) {
|
|
282713
|
-
await
|
|
282802
|
+
await mkdir34(dir(cwd), { recursive: true });
|
|
282714
282803
|
const path9 = join70(dir(cwd), ENVS_FILE);
|
|
282715
282804
|
const all9 = await readJson2(path9) ?? {};
|
|
282716
282805
|
for (const [id15, entry3] of Object.entries(all9)) if (Date.now() - Date.parse(entry3.createdAt) > 864e5) delete all9[id15];
|
|
@@ -283057,7 +283146,7 @@ init_docker();
|
|
|
283057
283146
|
init_world_image();
|
|
283058
283147
|
import { execFile as execFile12, spawn as spawn7 } from "node:child_process";
|
|
283059
283148
|
import { promisify as promisify11 } from "node:util";
|
|
283060
|
-
import { access as access15, chmod as
|
|
283149
|
+
import { access as access15, chmod as chmod8, copyFile as copyFile5, mkdir as mkdir35, writeFile as writeFile37 } from "node:fs/promises";
|
|
283061
283150
|
import { join as join71 } from "node:path";
|
|
283062
283151
|
var exec7 = promisify11(execFile12);
|
|
283063
283152
|
var VERSION3 = "0.25.0";
|
|
@@ -283101,7 +283190,7 @@ async function preparePlaygroundRuntime(workspace4, progress2 = () => {
|
|
|
283101
283190
|
"image/Dockerfile"
|
|
283102
283191
|
].map((path9) => ({ relativePath: `.ancha/harbor-runtime/${path9}`, content: "" })));
|
|
283103
283192
|
const runtime2 = join71(workspace4, ".ancha/harbor-runtime");
|
|
283104
|
-
await
|
|
283193
|
+
await mkdir35(runtime2, { recursive: true, mode: 448 });
|
|
283105
283194
|
const python = join71(runtime2, ".venv/bin/python");
|
|
283106
283195
|
if (!await exists6(python)) {
|
|
283107
283196
|
progress2("Preparing the local execution runtime");
|
|
@@ -283137,22 +283226,22 @@ async function preparePlaygroundRuntime(workspace4, progress2 = () => {
|
|
|
283137
283226
|
if (!await exists6(plugin)) {
|
|
283138
283227
|
const qualified3 = join71(workspace4, ".ancha/harbor-spike/docker-config/cli-plugins/docker-compose");
|
|
283139
283228
|
if (!await exists6(qualified3)) throw new AnchaError("AGENT_UNREACHABLE", "Docker Compose is needed for local execution.", { hint: "Install the Docker Compose plugin, then run ancha execution prepare again." });
|
|
283140
|
-
await
|
|
283229
|
+
await mkdir35(join71(runtime2, "docker-config/cli-plugins"), { recursive: true, mode: 448 });
|
|
283141
283230
|
await copyFile5(qualified3, plugin);
|
|
283142
|
-
await
|
|
283231
|
+
await chmod8(plugin, 448);
|
|
283143
283232
|
}
|
|
283144
283233
|
}
|
|
283145
283234
|
progress2("Preparing the seeded tools");
|
|
283146
283235
|
const imageDir = join71(runtime2, "image");
|
|
283147
|
-
await
|
|
283236
|
+
await mkdir35(imageDir, { recursive: true, mode: 448 });
|
|
283148
283237
|
const companion = await packagedCompanion(), worker = await packagedSuiteqlWorker();
|
|
283149
283238
|
const image2 = worldImageTag(companion, worker);
|
|
283150
|
-
await
|
|
283151
|
-
await
|
|
283152
|
-
await
|
|
283153
|
-
await
|
|
283239
|
+
await writeFile37(join71(imageDir, "companion.mjs"), companion);
|
|
283240
|
+
await writeFile37(join71(imageDir, "suiteql-worker.mjs"), worker);
|
|
283241
|
+
await writeFile37(join71(imageDir, "package.json"), WORLD_PACKAGE_JSON);
|
|
283242
|
+
await writeFile37(join71(imageDir, "Dockerfile"), WORLD_DOCKERFILE);
|
|
283154
283243
|
await run6("docker", ["--context", docker3.context, "build", "--tag", image2, imageDir]);
|
|
283155
|
-
await
|
|
283244
|
+
await writeFile37(join71(runtime2, "setup.json"), JSON.stringify({ harbor: VERSION3, image: image2, preparedAt: (/* @__PURE__ */ new Date()).toISOString() }) + "\n", { mode: 384 });
|
|
283156
283245
|
return { available: true, message: "Local playgrounds are ready.", worldImage: image2 };
|
|
283157
283246
|
}
|
|
283158
283247
|
|
|
@@ -283190,8 +283279,8 @@ init_src();
|
|
|
283190
283279
|
// packages/cli/src/commands/world-company.ts
|
|
283191
283280
|
init_src();
|
|
283192
283281
|
import { constants as constants14 } from "node:fs";
|
|
283193
|
-
import { lstat as lstat13, mkdir as
|
|
283194
|
-
import { dirname as
|
|
283282
|
+
import { lstat as lstat13, mkdir as mkdir36, open as open15, readFile as readFile56, rm as rm23 } from "node:fs/promises";
|
|
283283
|
+
import { dirname as dirname28, join as join72, resolve as resolve56 } from "node:path";
|
|
283195
283284
|
|
|
283196
283285
|
// backend/src/company/fetch.ts
|
|
283197
283286
|
init_src();
|
|
@@ -283450,7 +283539,7 @@ async function writeCompanyFiles(cwd, files2, force) {
|
|
|
283450
283539
|
try {
|
|
283451
283540
|
const stat22 = await lstat13(target6);
|
|
283452
283541
|
if (stat22.isFile() && !force) throw new AnchaError("USAGE", `${file3.relativePath} already exists`, { hint: "pass --force to overwrite generated files" });
|
|
283453
|
-
previous.set(target6, await
|
|
283542
|
+
previous.set(target6, await readFile56(target6));
|
|
283454
283543
|
} catch (error65) {
|
|
283455
283544
|
if (error65.code !== "ENOENT") throw error65;
|
|
283456
283545
|
previous.set(target6, void 0);
|
|
@@ -283459,7 +283548,7 @@ async function writeCompanyFiles(cwd, files2, force) {
|
|
|
283459
283548
|
if (!force) {
|
|
283460
283549
|
const result = await applyScaffold(cwd, files2);
|
|
283461
283550
|
if (result.skipped.length) {
|
|
283462
|
-
await Promise.all(result.created.map((file3) =>
|
|
283551
|
+
await Promise.all(result.created.map((file3) => rm23(join72(cwd, file3), { force: true })));
|
|
283463
283552
|
throw new AnchaError("USAGE", "a generated target appeared while writing; retry with --force");
|
|
283464
283553
|
}
|
|
283465
283554
|
return;
|
|
@@ -283468,7 +283557,7 @@ async function writeCompanyFiles(cwd, files2, force) {
|
|
|
283468
283557
|
try {
|
|
283469
283558
|
for (const file3 of files2) {
|
|
283470
283559
|
const target6 = join72(cwd, file3.relativePath);
|
|
283471
|
-
await
|
|
283560
|
+
await mkdir36(dirname28(target6), { recursive: true });
|
|
283472
283561
|
await preflightFiles(cwd, [file3]);
|
|
283473
283562
|
const exists7 = previous.get(target6) !== void 0;
|
|
283474
283563
|
const handle31 = await open15(target6, constants14.O_WRONLY | constants14.O_NOFOLLOW | (exists7 ? 0 : constants14.O_CREAT | constants14.O_EXCL), 420);
|
|
@@ -283483,7 +283572,7 @@ async function writeCompanyFiles(cwd, files2, force) {
|
|
|
283483
283572
|
} catch (error65) {
|
|
283484
283573
|
for (const target6 of written.reverse()) {
|
|
283485
283574
|
const original2 = previous.get(target6);
|
|
283486
|
-
if (original2 === void 0) await
|
|
283575
|
+
if (original2 === void 0) await rm23(target6, { force: true });
|
|
283487
283576
|
else {
|
|
283488
283577
|
const handle31 = await open15(target6, constants14.O_WRONLY | constants14.O_NOFOLLOW);
|
|
283489
283578
|
try {
|
|
@@ -283506,7 +283595,7 @@ async function worldCompany(ctx, url4, options5, deps = {}) {
|
|
|
283506
283595
|
let source = null, fetched = [], modelCredit = null;
|
|
283507
283596
|
if (options5.profile) {
|
|
283508
283597
|
try {
|
|
283509
|
-
profile2 = parseCompanyProfile(JSON.parse(await
|
|
283598
|
+
profile2 = parseCompanyProfile(JSON.parse(await readFile56(resolve56(ctx.io.cwd, options5.profile), "utf8")));
|
|
283510
283599
|
} catch {
|
|
283511
283600
|
throw new AnchaError("CONFIG_INVALID", "company profile file must contain a valid version 1 profile", { hint: "see ancha docs company" });
|
|
283512
283601
|
}
|
|
@@ -283590,7 +283679,7 @@ function registerWorldFrom(command, ctx) {
|
|
|
283590
283679
|
// packages/cli/src/commands/world-import.ts
|
|
283591
283680
|
init_src();
|
|
283592
283681
|
import { existsSync as existsSync5 } from "node:fs";
|
|
283593
|
-
import { mkdir as
|
|
283682
|
+
import { mkdir as mkdir37, readdir as readdir17, readFile as readFile58, stat as stat20, writeFile as writeFile38 } from "node:fs/promises";
|
|
283594
283683
|
import { extname as extname3, join as join73, relative as relative29, resolve as resolve58 } from "node:path";
|
|
283595
283684
|
|
|
283596
283685
|
// backend/src/kit/netsuite-import.ts
|
|
@@ -284082,7 +284171,7 @@ function realmOf(href2) {
|
|
|
284082
284171
|
const m = href2 === void 0 ? null : /^https?:\/\/(\d{4,10})(?:[-_]sb(\d{1,2}))?\.suitetalk\.api\.netsuite\.com/i.exec(href2);
|
|
284083
284172
|
return m ? `${m[1]}${m[2] ? `_SB${m[2]}` : ""}` : void 0;
|
|
284084
284173
|
}
|
|
284085
|
-
function
|
|
284174
|
+
function readFile57(file3, type, notes7) {
|
|
284086
284175
|
const text31 = file3.text.replace(/^/, ""), start2 = text31.trimStart();
|
|
284087
284176
|
if (!/^[[{]/.test(start2)) return readCsv2(file3.path, text31, type, notes7);
|
|
284088
284177
|
let values3;
|
|
@@ -285308,7 +285397,7 @@ function importNetsuite(files2, options5) {
|
|
|
285308
285397
|
const notes7 = [], problems = [], read7 = [], type = options5.type === void 0 ? void 0 : canonical11(options5.type);
|
|
285309
285398
|
let raws = [];
|
|
285310
285399
|
for (const file3 of files2) {
|
|
285311
|
-
let rows35 =
|
|
285400
|
+
let rows35 = readFile57(file3, type, notes7).map((raw3) => ({ ...raw3, type: rowType(raw3) }));
|
|
285312
285401
|
const untyped = rows35.filter((raw3) => raw3.type === "record" || raw3.type === TRANSACTION || raw3.type === ENTITY2);
|
|
285313
285402
|
if (untyped.length) problems.push(`${file3.path}: ${untyped.length === 1 ? "a record" : `${untyped.length} records`} with no record type: name the file after its type (customers.csv, invoice.json) or pass --type`);
|
|
285314
285403
|
rows35 = rows35.filter((raw3) => !untyped.includes(raw3));
|
|
@@ -285479,7 +285568,7 @@ async function worldImportNetsuite(ctx, paths3, options5) {
|
|
|
285479
285568
|
if (existsSync5(worldPath) && !options5.force) throw new AnchaError("USAGE", `${rel(worldPath)} already exists`, { hint: "pass --force to overwrite it, or choose another --id" });
|
|
285480
285569
|
const names8 = [...new Set((await Promise.all(paths3.map((path9) => exportFiles(ctx.io.cwd, path9)))).flat())];
|
|
285481
285570
|
if (!names8.length) throw new AnchaError("USAGE", `no export files in ${paths3.join(", ")}`, { hint: "NetSuite exports are .json (REST records, SuiteQL results) and .csv (saved searches)" });
|
|
285482
|
-
const files2 = await Promise.all(names8.map(async (name5) => ({ path: rel(name5), text: decodeEvalText(await
|
|
285571
|
+
const files2 = await Promise.all(names8.map(async (name5) => ({ path: rel(name5), text: decodeEvalText(await readFile58(name5)).text })));
|
|
285483
285572
|
const imported2 = importNetsuite(files2, {
|
|
285484
285573
|
id: options5.id,
|
|
285485
285574
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -285487,8 +285576,8 @@ async function worldImportNetsuite(ctx, paths3, options5) {
|
|
|
285487
285576
|
...options5.type !== void 0 && { type: options5.type },
|
|
285488
285577
|
...options5.start !== void 0 && { start: options5.start }
|
|
285489
285578
|
});
|
|
285490
|
-
await
|
|
285491
|
-
await
|
|
285579
|
+
await mkdir37(outDir, { recursive: true });
|
|
285580
|
+
await writeFile38(worldPath, worldFileYaml(imported2.world));
|
|
285492
285581
|
const { coverage: coverage4, problems } = imported2, plain9 = imported2.plainable.filter((type) => !NETSUITE_IMPORT_MODELED.includes(type));
|
|
285493
285582
|
if (problems.length) ctx.exitCode = 1;
|
|
285494
285583
|
const again = [
|
|
@@ -285570,8 +285659,8 @@ init_privacy();
|
|
|
285570
285659
|
init_assets();
|
|
285571
285660
|
init_report2();
|
|
285572
285661
|
import { createHash as createHash87, randomBytes as randomBytes12 } from "node:crypto";
|
|
285573
|
-
import { lstat as lstat14, mkdir as
|
|
285574
|
-
import { dirname as
|
|
285662
|
+
import { lstat as lstat14, mkdir as mkdir38, mkdtemp as mkdtemp13, readFile as readFile59, rename as rename13, rm as rm24, writeFile as writeFile39 } from "node:fs/promises";
|
|
285663
|
+
import { dirname as dirname29, join as join74, resolve as resolve59 } from "node:path";
|
|
285575
285664
|
var object27 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
285576
285665
|
var instant = external_exports.string().max(80).refine((value6) => /^\d{4}-\d\d-\d\dT.+(?:Z|[+-]\d\d:\d\d)$/.test(value6) && Number.isFinite(Date.parse(value6)));
|
|
285577
285666
|
var code3 = external_exports.string().regex(/^[A-Za-z_][A-Za-z0-9_.:-]{0,127}$/);
|
|
@@ -285738,7 +285827,7 @@ async function recordPytestRun(cwd, input5, env2 = {}) {
|
|
|
285738
285827
|
const exists7 = async () => {
|
|
285739
285828
|
await preflightFiles(cwd, [{ relativePath: `${relative31}/record.json`, content: "" }]);
|
|
285740
285829
|
const completed = async () => {
|
|
285741
|
-
const text31 = await
|
|
285830
|
+
const text31 = await readFile59(join74(runDir, "record.json"), "utf8");
|
|
285742
285831
|
let previous;
|
|
285743
285832
|
try {
|
|
285744
285833
|
previous = JSON.parse(text31);
|
|
@@ -285770,13 +285859,13 @@ async function recordPytestRun(cwd, input5, env2 = {}) {
|
|
|
285770
285859
|
if (await exists7()) return result;
|
|
285771
285860
|
const files2 = artifacts(cleaned, runDir);
|
|
285772
285861
|
files2.set("record.json", json39({ version: 1, fingerprint }));
|
|
285773
|
-
await
|
|
285862
|
+
await mkdir38(outDir, { recursive: true, mode: 448 });
|
|
285774
285863
|
await preflightFiles(cwd, [{ relativePath: `${relative31}/summary.json`, content: "" }]);
|
|
285775
285864
|
const staging = await mkdtemp13(join74(outDir, ".pytest-"));
|
|
285776
285865
|
try {
|
|
285777
285866
|
for (const [path9, content2] of files2) {
|
|
285778
|
-
await
|
|
285779
|
-
await
|
|
285867
|
+
await mkdir38(dirname29(join74(staging, path9)), { recursive: true, mode: 448 });
|
|
285868
|
+
await writeFile39(join74(staging, path9), content2, { flag: "wx", mode: 384 });
|
|
285780
285869
|
}
|
|
285781
285870
|
await preflightFiles(cwd, [{ relativePath: `${relative31}/summary.json`, content: "" }]);
|
|
285782
285871
|
try {
|
|
@@ -285787,16 +285876,16 @@ async function recordPytestRun(cwd, input5, env2 = {}) {
|
|
|
285787
285876
|
}
|
|
285788
285877
|
const latest2 = join74(outDir, `.latest-pytest-${randomBytes12(8).toString("hex")}`);
|
|
285789
285878
|
try {
|
|
285790
|
-
await
|
|
285879
|
+
await writeFile39(latest2, `${record32.runId}
|
|
285791
285880
|
`, { flag: "wx", mode: 384 });
|
|
285792
285881
|
await preflightFiles(cwd, [{ relativePath: `${DEFAULT_RUNS_DIR}/latest`, content: "" }]);
|
|
285793
285882
|
await rename13(latest2, join74(outDir, "latest"));
|
|
285794
285883
|
} finally {
|
|
285795
|
-
await
|
|
285884
|
+
await rm24(latest2, { force: true });
|
|
285796
285885
|
}
|
|
285797
285886
|
return result;
|
|
285798
285887
|
} finally {
|
|
285799
|
-
await
|
|
285888
|
+
await rm24(staging, { recursive: true, force: true });
|
|
285800
285889
|
}
|
|
285801
285890
|
}
|
|
285802
285891
|
|
|
@@ -285874,7 +285963,7 @@ ${formatTable(value6.configuration.preset.datasets.map((data7) => [data7.tool, d
|
|
|
285874
285963
|
// packages/cli/src/commands/secrets.ts
|
|
285875
285964
|
var import_yaml23 = __toESM(require_dist(), 1);
|
|
285876
285965
|
init_src();
|
|
285877
|
-
import { readFile as
|
|
285966
|
+
import { readFile as readFile60, writeFile as writeFile40 } from "node:fs/promises";
|
|
285878
285967
|
import { resolve as resolve61 } from "node:path";
|
|
285879
285968
|
init_credentials();
|
|
285880
285969
|
var NAME_RE2 = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
@@ -285882,7 +285971,7 @@ var DEFERRED_SYNC = "Saved in the workspace; the workspace machine picks it up w
|
|
|
285882
285971
|
async function nameInConfig(ctx, names8) {
|
|
285883
285972
|
const label7 = ctx.globals().config ?? "ancha.yaml", file3 = resolve61(ctx.io.cwd, label7);
|
|
285884
285973
|
const them = names8.length === 1 ? "it" : "them", list19 = names8.join(", ");
|
|
285885
|
-
const text31 = await
|
|
285974
|
+
const text31 = await readFile60(file3, "utf8").catch(() => void 0);
|
|
285886
285975
|
if (text31 === void 0) return { passEnvHint: `no ${label7} here: list ${list19} under agent.pass_env in the agent's ${label7} so its cloud runs get ${them}` };
|
|
285887
285976
|
const doc = (0, import_yaml23.parseDocument)(text31);
|
|
285888
285977
|
const listed2 = (path9) => {
|
|
@@ -285898,7 +285987,7 @@ async function nameInConfig(ctx, names8) {
|
|
|
285898
285987
|
else for (const name5 of added) doc.addIn(["agent", "pass_env"], name5);
|
|
285899
285988
|
const out = doc.toString({ lineWidth: 0, flowCollectionPadding: /\[ [^\]\n]*\S \]/.test(text31) });
|
|
285900
285989
|
try {
|
|
285901
|
-
await
|
|
285990
|
+
await writeFile40(file3, out);
|
|
285902
285991
|
} catch {
|
|
285903
285992
|
return { passEnvHint: `${label7} could not be written: list ${added.join(", ")} under agent.pass_env so the agent's cloud runs get ${added.length === 1 ? "it" : "them"}` };
|
|
285904
285993
|
}
|
|
@@ -286306,7 +286395,7 @@ import { randomUUID as randomUUID23 } from "node:crypto";
|
|
|
286306
286395
|
init_run_metadata();
|
|
286307
286396
|
var import_yaml24 = __toESM(require_dist(), 1);
|
|
286308
286397
|
init_src();
|
|
286309
|
-
import { mkdir as
|
|
286398
|
+
import { mkdir as mkdir39, readFile as readFile61, stat as stat21, writeFile as writeFile41 } from "node:fs/promises";
|
|
286310
286399
|
import { basename as basename18, join as join75, relative as relative30, resolve as resolve62 } from "node:path";
|
|
286311
286400
|
init_report2();
|
|
286312
286401
|
init_run_store();
|
|
@@ -286337,7 +286426,7 @@ async function testTask(ctx, file3, worldOverride) {
|
|
|
286337
286426
|
const path9 = resolve62(ctx.io.cwd, file3);
|
|
286338
286427
|
let doc;
|
|
286339
286428
|
try {
|
|
286340
|
-
doc = (0, import_yaml24.parse)(await
|
|
286429
|
+
doc = (0, import_yaml24.parse)(await readFile61(path9, "utf8"));
|
|
286341
286430
|
} catch (error65) {
|
|
286342
286431
|
throw new AnchaError("CONFIG_INVALID", `cannot read ${file3}: ${error65 instanceof Error ? error65.message.split("\n")[0] : String(error65)}`, { hint: "pass a task file (version 2) or a test file (scene.yaml)" });
|
|
286343
286432
|
}
|
|
@@ -286441,7 +286530,7 @@ next page: ancha runs list --cursor ${page20.nextCursor}`}`);
|
|
|
286441
286530
|
const workspace4 = await uploadWorkspace(ctx);
|
|
286442
286531
|
const summary = await loadRunSummary(ctx.io.cwd, ref23, options5.out);
|
|
286443
286532
|
const runDir = join75(resolve62(ctx.io.cwd, options5.out ?? DEFAULT_RUNS_DIR), summary.runId);
|
|
286444
|
-
const inputs2 = JSON.parse(await
|
|
286533
|
+
const inputs2 = JSON.parse(await readFile61(join75(runDir, "inputs.json"), "utf8").catch(() => "{}"));
|
|
286445
286534
|
const passEnv = inputs2.agentEnvironment?.passEnv ?? (await ctx.loadConfig().catch(() => void 0))?.agent?.passEnv ?? [];
|
|
286446
286535
|
const inheritEnv = inputs2.agentEnvironment?.inheritEnv ?? summary.agentEnvironment?.inheritAll === true;
|
|
286447
286536
|
const upload6 = await uploadRun(ctx, workspace4, { runId: summary.runId, runDir, passEnv, inheritEnv });
|
|
@@ -286462,14 +286551,14 @@ next page: ancha runs list --cursor ${page20.nextCursor}`}`);
|
|
|
286462
286551
|
hint: `ancha report ${summary.runId}${options5.out === void 0 ? "" : ` --out ${shellWord(options5.out)}`} shows the saved result; export a run with captured world traces`
|
|
286463
286552
|
});
|
|
286464
286553
|
}
|
|
286465
|
-
await
|
|
286466
|
-
const inputs2 = await
|
|
286554
|
+
await mkdir39(dest, { recursive: true });
|
|
286555
|
+
const inputs2 = await readFile61(join75(resolve62(ctx.io.cwd, options5.out ?? DEFAULT_RUNS_DIR), summary.runId, "inputs.json"), "utf8").then((text31) => JSON.parse(text31), () => ({}));
|
|
286467
286556
|
const files2 = [], cases = withSeeds(inputs2.cases ?? []);
|
|
286468
286557
|
for (const scene2 of summary.scenes) for (const trial of scene2.trialsDetail) {
|
|
286469
286558
|
const dir2 = resolve62(ctx.io.cwd, trial.dir), name5 = basename18(dir2), file3 = join75(dest, `${name5}.ir.jsonl`);
|
|
286470
|
-
await
|
|
286559
|
+
await writeFile41(file3, attemptToIr(await readAttemptTrace(dir2), `${summary.runId}/${name5}`, summary.agent, {
|
|
286471
286560
|
scene: cases.find((c) => c.id === scene2.sceneId)?.scene,
|
|
286472
|
-
checks: await
|
|
286561
|
+
checks: await readFile61(join75(dir2, "checks.json"), "utf8").then((text31) => JSON.parse(text31), () => void 0),
|
|
286473
286562
|
outcome: trial.outcome ?? (trial.valid === false ? "invalid" : trial.passed ? "passed" : "failed"),
|
|
286474
286563
|
exit: trial.exit,
|
|
286475
286564
|
exitCode: trial.exitCode
|