@ancha-labs/cli 0.4.54 → 0.4.55
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 +299 -223
- package/lib/assets/harbor/companion.mjs +30 -11
- package/lib/worker.mjs +68 -17
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -231343,7 +231343,7 @@ var init_jobs_contract = __esm({
|
|
|
231343
231343
|
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"];
|
|
231344
231344
|
DEFAULT_MODEL_HOSTS = ["openrouter.ai", "api.openai.com", "api.anthropic.com"];
|
|
231345
231345
|
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"];
|
|
231346
|
-
PROBE_OUTCOMES = ["answered", "answer_refused", "refused", "outside_host", "unserved", "crashed", "idle", "no_answer", "wrong_answer", "model_key", "missing_secret", "route_key"];
|
|
231346
|
+
PROBE_OUTCOMES = ["answered", "answer_refused", "refused", "outside_host", "unserved", "crashed", "idle", "no_answer", "wrong_answer", "model_key", "missing_secret", "route_key", "model_unreachable"];
|
|
231347
231347
|
ANSWER_SOURCES = ["done", "reply", "stdout"];
|
|
231348
231348
|
HEARTBEAT_MS = 1e4;
|
|
231349
231349
|
AGENT_UID = 10001;
|
|
@@ -231420,9 +231420,25 @@ function requireWorld(name5, route15) {
|
|
|
231420
231420
|
if (!(route15.toolkits ?? { quickbooks: "composio" })[toolkit]) throw new RouteRefusal("NOT_ROUTED", toolkit);
|
|
231421
231421
|
if (!activeComposioToolkits(route15)[toolkit]) throw new RouteRefusal("NO_WORLD", toolkit);
|
|
231422
231422
|
}
|
|
231423
|
-
function
|
|
231424
|
-
const
|
|
231425
|
-
|
|
231423
|
+
function schemaDetail(issues, at6) {
|
|
231424
|
+
const issue9 = issues[0];
|
|
231425
|
+
if (!issue9) return void 0;
|
|
231426
|
+
const path9 = [...at6 ? [at6] : [], ...issue9.path].reduce((text31, key5) => typeof key5 === "number" ? `${text31}[${key5}]` : text31 ? `${text31}.${String(key5)}` : String(key5), "");
|
|
231427
|
+
const said = issue9.code === "invalid_type" ? `expected ${issue9.expected}, received ${issue9.input === null ? "null" : Array.isArray(issue9.input) ? "array" : typeof issue9.input}` : issue9.code === "unrecognized_keys" ? `unknown field${issue9.keys.length === 1 ? "" : "s"} ${issue9.keys.slice(0, 3).join(", ")}` : issue9.code === "too_small" ? `expected at least ${String(issue9.minimum)}${issue9.origin === "array" ? ` item${issue9.minimum === 1 ? "" : "s"}` : ""}` : issue9.code === "invalid_value" ? "not an accepted value" : issue9.code.replace(/_/g, " ");
|
|
231428
|
+
return `${path9 ? `${path9}: ` : ""}${said}`.slice(0, 160);
|
|
231429
|
+
}
|
|
231430
|
+
function jsonText(value6) {
|
|
231431
|
+
if (typeof value6 !== "string") return value6;
|
|
231432
|
+
try {
|
|
231433
|
+
return JSON.parse(value6);
|
|
231434
|
+
} catch {
|
|
231435
|
+
return value6;
|
|
231436
|
+
}
|
|
231437
|
+
}
|
|
231438
|
+
function parsed3(schema4, value6, at6) {
|
|
231439
|
+
const result = schema4.safeParse(value6, { reportInput: true });
|
|
231440
|
+
if (result.success) return result.data;
|
|
231441
|
+
throw new RouteRefusal("SCHEMA", void 0, schemaDetail(result.error.issues, at6));
|
|
231426
231442
|
}
|
|
231427
231443
|
function jsonBody3(body8, contentType) {
|
|
231428
231444
|
if (typeof contentType !== "string" || !/^application\/json(?:\s*;|$)/i.test(contentType)) refuse("CONTENT_TYPE");
|
|
@@ -231439,7 +231455,7 @@ function toolArguments(route15, name5, value6 = {}, metaOnly = false) {
|
|
|
231439
231455
|
if (!meta5.has(name5) && (metaOnly || !quickbooks.test(name5))) refuse(name5.startsWith("COMPOSIO_") || metaOnly ? "META_TOOL" : "TOOL");
|
|
231440
231456
|
const { account: _account, ...args } = value6;
|
|
231441
231457
|
if (name5 === multi) {
|
|
231442
|
-
const items2 = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: record26.optional() }).passthrough()).min(1), args.tools);
|
|
231458
|
+
const items2 = parsed3(external_exports.array(external_exports.object({ tool_slug: external_exports.string(), arguments: external_exports.preprocess(jsonText, record26).optional() }).passthrough()).min(1), jsonText(args.tools), "tools");
|
|
231443
231459
|
for (const item2 of items2) requireWorld(item2.tool_slug, route15);
|
|
231444
231460
|
args.tools = items2.map(({ account: _account2, connected_account_id: _id, user_id: _user, ...item2 }) => {
|
|
231445
231461
|
if (item2.tool_slug.startsWith("NETSUITE_")) refuse("NETSUITE_TOOL");
|
|
@@ -231513,7 +231529,7 @@ function validateComposio(method2, target6, apiKey, body8, contentType, route15,
|
|
|
231513
231529
|
if (Array.isArray(json40)) refuse("MCP_BATCH");
|
|
231514
231530
|
const value6 = parsed3(external_exports.strictObject({ jsonrpc: external_exports.literal("2.0"), id: external_exports.union([external_exports.string(), external_exports.number(), external_exports.null()]).optional(), method: external_exports.string(), params: record26.optional() }), json40);
|
|
231515
231531
|
if (value6.method === "tools/call") {
|
|
231516
|
-
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record26.optional(), account: external_exports.unknown().optional(), _meta: record26.optional() }), value6.params);
|
|
231532
|
+
const params10 = parsed3(external_exports.strictObject({ name: external_exports.string(), arguments: record26.optional(), account: external_exports.unknown().optional(), _meta: record26.optional() }), value6.params, "params");
|
|
231517
231533
|
const call4 = toolArguments(route15, params10.name, params10.arguments);
|
|
231518
231534
|
if (!qb) refuse("SESSION_ENDPOINT");
|
|
231519
231535
|
const { account: _account, ...kept } = params10;
|
|
@@ -231672,9 +231688,9 @@ async function readComposioBody(req) {
|
|
|
231672
231688
|
}
|
|
231673
231689
|
return Buffer.concat(chunks);
|
|
231674
231690
|
}
|
|
231675
|
-
function refuseComposio(res, reason2, toolkit) {
|
|
231691
|
+
function refuseComposio(res, reason2, toolkit, detail3) {
|
|
231676
231692
|
res.writeHead(403, { "content-type": "application/json", connection: "close" });
|
|
231677
|
-
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit).message } }));
|
|
231693
|
+
res.end(JSON.stringify({ error: { code: "COMPOSIO_ROUTE_REFUSED", reason: reason2, message: new RouteRefusal(reason2, toolkit, detail3).message } }));
|
|
231678
231694
|
}
|
|
231679
231695
|
function nextRouteId(route15, kind2) {
|
|
231680
231696
|
let ids3 = routeIds.get(route15);
|
|
@@ -231773,10 +231789,13 @@ var init_composio = __esm({
|
|
|
231773
231789
|
RouteRefusal = class extends Error {
|
|
231774
231790
|
reason;
|
|
231775
231791
|
toolkit;
|
|
231776
|
-
|
|
231777
|
-
|
|
231792
|
+
/** For SCHEMA: the field and what it held, as types (SPEC-104 F1). */
|
|
231793
|
+
detail;
|
|
231794
|
+
constructor(reason2, toolkit, detail3) {
|
|
231795
|
+
super(reason2 === "SCHEMA" && detail3 ? `The request does not match this endpoint's input schema: ${detail3}.` : reason2 === "NO_WORLD" && toolkit ? noWorldMessage(toolkit) : reason2 === "NOT_ROUTED" && toolkit ? notRoutedMessage(toolkit) : reason2 === "NETSUITE_TOOL" ? NETSUITE_FIX : "Configure this call to use the declared QuickBooks or NetSuite route.");
|
|
231778
231796
|
this.reason = reason2;
|
|
231779
231797
|
this.toolkit = toolkit;
|
|
231798
|
+
if (detail3) this.detail = detail3;
|
|
231780
231799
|
}
|
|
231781
231800
|
};
|
|
231782
231801
|
activeComposioToolkits = (route15) => route15.activeToolkits ?? route15.toolkits ?? { quickbooks: "composio" };
|
|
@@ -231978,8 +231997,8 @@ async function startIsolationGateway(options5) {
|
|
|
231978
231997
|
const reason2 = error65 instanceof RouteRefusal ? error65.reason : "JSON";
|
|
231979
231998
|
const toolkit = (error65 instanceof RouteRefusal ? error65.toolkit : void 0) ?? (reason2 === "NETSUITE_TOOL" || /NETSUITE_/.test(toolBody?.toString("utf8") ?? "") || /NETSUITE_/.test(req.url ?? "") || route15?.toolkits && !route15.toolkits.quickbooks ? "netsuite" : "quickbooks");
|
|
231980
231999
|
const via = composioVia((req.url ?? "").slice("/_tool/composio".length));
|
|
231981
|
-
route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2 });
|
|
231982
|
-
refuseComposio(res, reason2, toolkit);
|
|
232000
|
+
route15?.record({ leg: "platform", op: "refused", toolkit, via, method: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"].includes(req.method ?? "") ? req.method : "OTHER", ...req.method === "POST" && via === "mcp" && refusedRpc(toolBody), status: 403, ms: Math.round(performance.now() - toolStarted), reason: reason2, ...error65 instanceof RouteRefusal && error65.detail && { detail: error65.detail } });
|
|
232001
|
+
refuseComposio(res, reason2, toolkit, error65 instanceof RouteRefusal ? error65.detail : void 0);
|
|
231983
232002
|
return;
|
|
231984
232003
|
}
|
|
231985
232004
|
}
|
|
@@ -232801,7 +232820,7 @@ function connectionRouteEvidence(routes2, summary, trace2, log3) {
|
|
|
232801
232820
|
for (const entry3 of refused2.slice(0, 5)) {
|
|
232802
232821
|
const event3 = entry3.routeEvent;
|
|
232803
232822
|
if (event3.leg !== "platform") continue;
|
|
232804
|
-
details.push(`refused: ${event3.method} ${[event3.rpc, event3.slug].filter(Boolean).join(" ") || "Composio call"}${event3.via ? ` via ${event3.via}` : ""} (${event3.reason ?? "REFUSED"})`);
|
|
232823
|
+
details.push(`refused: ${event3.method} ${[event3.rpc, event3.slug].filter(Boolean).join(" ") || "Composio call"}${event3.via ? ` via ${event3.via}` : ""} (${event3.reason ?? "REFUSED"}${event3.detail ? `: ${event3.detail}` : ""})`);
|
|
232805
232824
|
}
|
|
232806
232825
|
const first2 = refused2[0];
|
|
232807
232826
|
if (first2 || counts2.some(({ route: route15 }) => (route15?.refused ?? 0) > 0)) return { details, reason: {
|
|
@@ -232874,7 +232893,8 @@ async function bounded(response6, cap) {
|
|
|
232874
232893
|
}
|
|
232875
232894
|
return Buffer.concat(chunks);
|
|
232876
232895
|
}
|
|
232877
|
-
function refusedDetail(reason2 = "REFUSED", toolkit) {
|
|
232896
|
+
function refusedDetail(reason2 = "REFUSED", toolkit, detail3) {
|
|
232897
|
+
if (reason2 === "SCHEMA" && detail3) return `a Composio call was refused (SCHEMA: ${detail3}): send the fields its input schema names; the route supplies the world connection.`;
|
|
232878
232898
|
const fix = REFUSAL_FIX[reason2] ?? "use the declared QuickBooks route";
|
|
232879
232899
|
return `a Composio call was refused (${reason2}): ${typeof fix === "function" ? fix(toolkit) : `${fix}.`}`;
|
|
232880
232900
|
}
|
|
@@ -233072,7 +233092,7 @@ async function startIngressClient(options5) {
|
|
|
233072
233092
|
if (reached) counts2[toolkit].reached++;
|
|
233073
233093
|
}
|
|
233074
233094
|
if (event3.op === "refused") counts2[toolkit].refused++;
|
|
233075
|
-
record33({ ...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);
|
|
233095
|
+
record33({ ...event3, toolkit, relayHash: hash6(id15) }, event3.status, event3.op === "refused" ? issue9("ROUTE_REFUSED", refusedDetail(event3.reason, toolkit, event3.detail), 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);
|
|
233076
233096
|
},
|
|
233077
233097
|
summary: () => {
|
|
233078
233098
|
const result = {};
|
|
@@ -235690,6 +235710,27 @@ var init_per_event = __esm({
|
|
|
235690
235710
|
});
|
|
235691
235711
|
|
|
235692
235712
|
// backend/src/agent-fix.ts
|
|
235713
|
+
function modelBaseUrlFix(host) {
|
|
235714
|
+
const variable = host === "openrouter.ai" ? "OPENROUTER_BASE_URL" : host === "api.openai.com" ? "OPENAI_BASE_URL" : host === "api.anthropic.com" ? "ANTHROPIC_BASE_URL" : void 0;
|
|
235715
|
+
const prefix2 = "in Ancha a model provider is reached through its base URL variable: ";
|
|
235716
|
+
if (!variable && host) return `${prefix2}build the client from its ${host} entry in ANCHA_MODEL_URLS`;
|
|
235717
|
+
if (!variable) return `${prefix2}build the client from OPENROUTER_BASE_URL, OPENAI_BASE_URL or ANTHROPIC_BASE_URL for that provider, or its entry in ANCHA_MODEL_URLS`;
|
|
235718
|
+
return `${prefix2}build the client from ${variable} (${host === "api.anthropic.com" ? "Anthropic SDK" : "OpenAI SDK"}: baseURL: process.env.${variable}${host === "openrouter.ai" ? "; @openrouter/ai-sdk-provider: createOpenRouter({ baseURL: process.env.OPENROUTER_BASE_URL })" : ""})`;
|
|
235719
|
+
}
|
|
235720
|
+
function modelUnreachable(log3, requests2) {
|
|
235721
|
+
if (requests2 === void 0 || Object.values(requests2).some((count14) => count14.requests > 0)) return void 0;
|
|
235722
|
+
const sdk = SDK_CONNECTION.test(log3);
|
|
235723
|
+
if (!sdk && !NET_CONNECTION.test(log3)) return void 0;
|
|
235724
|
+
const named5 = (host2) => ({ host: host2, message: `It could not reach ${host2}: its model client calls https://${host2} directly.`, fix: modelBaseUrlFix(host2) });
|
|
235725
|
+
const failed2 = [...log3.matchAll(/getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)\s+([a-z0-9.-]+)|request to https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => (match3[1] ?? match3[2]).toLowerCase());
|
|
235726
|
+
if (failed2.length > 0) {
|
|
235727
|
+
const host2 = failed2.find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
|
|
235728
|
+
return host2 ? named5(host2) : void 0;
|
|
235729
|
+
}
|
|
235730
|
+
if (!sdk) return void 0;
|
|
235731
|
+
const host = [...log3.matchAll(/https?:\/\/([a-z0-9.-]+)/gi)].map((match3) => match3[1].toLowerCase()).find((name5) => CLOUD_MODEL_HOSTS.includes(name5));
|
|
235732
|
+
return host ? named5(host) : { message: "Its model client could not connect, and it made no model request through Ancha.", fix: modelBaseUrlFix() };
|
|
235733
|
+
}
|
|
235693
235734
|
function givenByTwins(name5) {
|
|
235694
235735
|
twinVariables ??= new Set(Object.keys(toolConnectionEnvironment(Object.fromEntries(SUPPORTED_TWINS.map((twin) => [twin, ANY_SERVICE])))));
|
|
235695
235736
|
return twinVariables.has(name5);
|
|
@@ -235757,6 +235798,8 @@ function missingFix(text31, context3) {
|
|
|
235757
235798
|
return void 0;
|
|
235758
235799
|
}
|
|
235759
235800
|
function likelyFix(logTail3, context3 = {}) {
|
|
235801
|
+
const unreachable = modelUnreachable(logTail3.join("\n"), context3.modelRequests);
|
|
235802
|
+
if (unreachable) return unreachable.fix;
|
|
235760
235803
|
const task2 = taskFix(logTail3.join("\n"), context3.command);
|
|
235761
235804
|
if (task2 !== void 0 || context3.withheld !== void 0) return task2 ?? context3.withheld;
|
|
235762
235805
|
if (logTail3.some((line2) => /^Not logged in · Please run \/login\b/.test(line2.trim()))) {
|
|
@@ -235771,12 +235814,15 @@ function likelyFix(logTail3, context3 = {}) {
|
|
|
235771
235814
|
}
|
|
235772
235815
|
return void 0;
|
|
235773
235816
|
}
|
|
235774
|
-
var TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape16, MODEL_ID_REFUSED;
|
|
235817
|
+
var SDK_CONNECTION, NET_CONNECTION, TASK_WORD, TASK_NAME, TASK_FLAG, CREDENTIAL, MISSING, twinVariables, escape16, MODEL_ID_REFUSED;
|
|
235775
235818
|
var init_agent_fix = __esm({
|
|
235776
235819
|
"backend/src/agent-fix.ts"() {
|
|
235777
235820
|
"use strict";
|
|
235778
235821
|
init_src();
|
|
235779
235822
|
init_agent_env();
|
|
235823
|
+
init_jobs_contract();
|
|
235824
|
+
SDK_CONNECTION = /APIConnectionError|Connection error\.|AI_RetryError|AI_APICallError|Cannot connect to API/;
|
|
235825
|
+
NET_CONNECTION = /getaddrinfo\s+(?:ENOTFOUND|EAI_AGAIN)|request to https?:\/\/\S+\s+failed|Temporary failure in name resolution|httpx\.ConnectError|fetch failed/i;
|
|
235780
235826
|
TASK_WORD = "(?:TASKS?|PROMPTS?|QUERY|QUERIES|INSTRUCTIONS?|MESSAGES?|REQUESTS?|INPUTS?)";
|
|
235781
235827
|
TASK_NAME = new RegExp(`(?<![A-Za-z0-9_])((?:[A-Z][A-Z0-9]*_)*${TASK_WORD}(?:_[A-Z0-9]+)*)(?![A-Za-z0-9_])`, "g");
|
|
235782
235828
|
TASK_FLAG = /(?<![\w-])(--(?:task|prompt|message|input|query|instructions?|request)(?:-file)?)(?![\w-])/g;
|
|
@@ -235929,6 +235975,10 @@ function attemptOutcome(view3, ctx) {
|
|
|
235929
235975
|
const gaps3 = [...new Set(calls2.filter((entry3) => entry3.gap === true || unserved.includes(entry3)).map((entry3) => `${entry3.method} ${entry3.path}`))];
|
|
235930
235976
|
const summary = { total: calls2.length, byStatus, gaps: gaps3.slice(0, 5), hosts: hosts.slice(0, 5) };
|
|
235931
235977
|
const out = (reason2) => ({ reason: reason2, calls: summary, ...answer !== void 0 && { answer: { source: answer.source, text: answer.text.slice(0, 200) } } });
|
|
235978
|
+
const crashed = view3.exit === "spawn_failed" || view3.exit === "exited" && view3.exitCode !== 0;
|
|
235979
|
+
const modelConnection = crashed && !view3.modelReplies?.length ? modelUnreachable(`${view3.log}
|
|
235980
|
+
${view3.logTail?.join("\n") ?? ""}`, view3.modelRequests) : void 0;
|
|
235981
|
+
if (modelConnection) return out({ code: "model_unreachable", kind: "fix", level: "fail", message: modelConnection.message, fix: modelConnection.fix });
|
|
235932
235982
|
if (answer !== void 0 && (ctx.check === "start" || ctx.check === "netsuite" && namesStarterCustomer(answer.text))) {
|
|
235933
235983
|
if (unserved.length > 0) return out({ code: "unserved", level: "warning", ...unservedReason(unserved) });
|
|
235934
235984
|
return out({ code: "answered", level: "pass", message: ctx.check === "netsuite" ? answeredNetsuite(netsuite, answer.text) : `It took the task and answered ${quoted3(answer.text)}.` });
|
|
@@ -235960,7 +236010,6 @@ function attemptOutcome(view3, ctx) {
|
|
|
235960
236010
|
const unreachable = outside.find((tool) => tool.hosts.length > 0 && !tool.served);
|
|
235961
236011
|
if (unreachable) return out({ code: "outside_host", level: "fail", message: `It tried to reach ${list18(unreachable.hosts.slice(0, 3))}.`, fix: unreachable.fix });
|
|
235962
236012
|
if (unserved.length > 0 && data7.length === 0) return out({ code: "unserved", level: "fail", ...unservedReason(unserved) });
|
|
235963
|
-
const crashed = view3.exit === "spawn_failed" || view3.exit === "exited" && view3.exitCode !== 0;
|
|
235964
236013
|
const did = calls2.length > 0 || ctx.taskMark !== void 0 && view3.log.includes(ctx.taskMark);
|
|
235965
236014
|
if (crashed && (ctx.check !== "start" || !did)) {
|
|
235966
236015
|
const tail = view3.logTail?.length ? view3.logTail : view3.log.trimEnd().split("\n").slice(-10);
|
|
@@ -236041,7 +236090,7 @@ var init_agent_outcome = __esm({
|
|
|
236041
236090
|
// backend/src/runner/trial.ts
|
|
236042
236091
|
import { setTimeout as sleep9 } from "node:timers/promises";
|
|
236043
236092
|
import { closeSync as closeSync6, openSync as openSync6, writeSync as writeSync6 } from "node:fs";
|
|
236044
|
-
import { mkdir as mkdir10 } from "node:fs/promises";
|
|
236093
|
+
import { mkdir as mkdir10, readFile as readFile4 } from "node:fs/promises";
|
|
236045
236094
|
import { join as join16 } from "node:path";
|
|
236046
236095
|
function answersFrom(agent, source) {
|
|
236047
236096
|
const mode = agent.answer ?? "auto";
|
|
@@ -236208,6 +236257,10 @@ async function runTrialInner(spec) {
|
|
|
236208
236257
|
const capture4 = await captureTrialAfterFailure(failure6, backend, env2.id, session2.id, dir2, scene2, { ...spec.judge, ...signal !== void 0 && { signal } }, void 0, spec.onCaptured);
|
|
236209
236258
|
const { checks: checks2, trace: trace2, simMs } = capture4, harnessIssues = [...capture4.harnessIssues, ...playOutIssues];
|
|
236210
236259
|
if (output2?.modelRefusal !== void 0) harnessIssues.push(modelKeyIssue(output2.modelRefusal, Object.keys(agent.env ?? {})));
|
|
236260
|
+
if ((exit === "spawn_failed" || exit === "exited" && exitCode !== 0) && output2?.model && !output2.modelReplies?.length) {
|
|
236261
|
+
const unreachable = modelUnreachable(await readFile4(join16(dir2, "agent.log"), "utf8").catch(() => ""), output2.model.requests);
|
|
236262
|
+
if (unreachable) harnessIssues.push({ kind: "model", owner: "harness", service: unreachable.host ?? "model", code: "MODEL_UNREACHABLE", message: `${unreachable.message} ${unreachable.fix.charAt(0).toUpperCase()}${unreachable.fix.slice(1)}.` });
|
|
236263
|
+
}
|
|
236211
236264
|
if (failure6 !== void 0) throw failure6.error;
|
|
236212
236265
|
signal?.throwIfAborted();
|
|
236213
236266
|
return {
|
|
@@ -236254,6 +236307,7 @@ var init_trial = __esm({
|
|
|
236254
236307
|
init_budget();
|
|
236255
236308
|
init_agent_output();
|
|
236256
236309
|
init_agent_outcome();
|
|
236310
|
+
init_agent_fix();
|
|
236257
236311
|
init_agent_env();
|
|
236258
236312
|
EXIT_COMMAND_NOT_FOUND2 = 127;
|
|
236259
236313
|
unknownRoute18 = (error65) => error65 instanceof AnchaError && error65.code === "USAGE" && error65.message.startsWith("no such route");
|
|
@@ -236314,13 +236368,13 @@ var init_harness_issues2 = __esm({
|
|
|
236314
236368
|
});
|
|
236315
236369
|
|
|
236316
236370
|
// backend/src/scenes.ts
|
|
236317
|
-
import { access as access4, readdir as readdir3, readFile as
|
|
236371
|
+
import { access as access4, readdir as readdir3, readFile as readFile5 } from "node:fs/promises";
|
|
236318
236372
|
import { basename as basename4, dirname as dirname6, join as join17, relative as relative5, resolve as resolve13 } from "node:path";
|
|
236319
236373
|
import { createHash as createHash62 } from "node:crypto";
|
|
236320
236374
|
async function checkWorldFile(cwd, path9) {
|
|
236321
236375
|
let text31;
|
|
236322
236376
|
try {
|
|
236323
|
-
text31 = await
|
|
236377
|
+
text31 = await readFile5(resolve13(cwd, path9), "utf8");
|
|
236324
236378
|
} catch (e) {
|
|
236325
236379
|
return { path: path9, bytes: 0, counts: {}, warnings: [], problems: [e.code === "ENOENT" ? "no such file" : e.message] };
|
|
236326
236380
|
}
|
|
@@ -236328,7 +236382,7 @@ async function checkWorldFile(cwd, path9) {
|
|
|
236328
236382
|
}
|
|
236329
236383
|
async function isWorldFile(cwd, path9) {
|
|
236330
236384
|
try {
|
|
236331
|
-
const doc = parseSceneYaml(await
|
|
236385
|
+
const doc = parseSceneYaml(await readFile5(resolve13(cwd, path9), "utf8"));
|
|
236332
236386
|
return typeof doc === "object" && doc !== null && doc.version === 2 && !isTestFile(doc);
|
|
236333
236387
|
} catch {
|
|
236334
236388
|
return false;
|
|
@@ -236349,7 +236403,7 @@ async function loadWorldFile(cwd, ref23) {
|
|
|
236349
236403
|
}
|
|
236350
236404
|
async function readWorldFile(cwd, path9) {
|
|
236351
236405
|
try {
|
|
236352
|
-
const text31 = await
|
|
236406
|
+
const text31 = await readFile5(path9, "utf8"), kept = parsedWorlds.get(path9);
|
|
236353
236407
|
if (kept?.text === text31) return structuredClone(kept.world);
|
|
236354
236408
|
const world5 = parseWorldFile(parseSceneYaml(text31));
|
|
236355
236409
|
parsedWorlds.delete(path9);
|
|
@@ -236371,13 +236425,13 @@ async function withAppDatabase(cwd, scene2) {
|
|
|
236371
236425
|
let migrations = [];
|
|
236372
236426
|
try {
|
|
236373
236427
|
const names8 = (await readdir3(folder2)).filter((name5) => name5.endsWith(".sql")).sort();
|
|
236374
|
-
migrations = await Promise.all(names8.map(async (name5) => ({ name: name5, sql: await
|
|
236428
|
+
migrations = await Promise.all(names8.map(async (name5) => ({ name: name5, sql: await readFile5(join17(folder2, name5), "utf8") })));
|
|
236375
236429
|
} catch (e) {
|
|
236376
236430
|
if (!missing10(e)) throw e;
|
|
236377
236431
|
}
|
|
236378
236432
|
let seedSql;
|
|
236379
236433
|
try {
|
|
236380
|
-
seedSql = await
|
|
236434
|
+
seedSql = await readFile5(join17(cwd, "supabase", "seed.sql"), "utf8");
|
|
236381
236435
|
} catch (e) {
|
|
236382
236436
|
if (!missing10(e)) throw e;
|
|
236383
236437
|
}
|
|
@@ -236392,7 +236446,7 @@ async function loadSceneOrTestFile(cwd, path9) {
|
|
|
236392
236446
|
const file3 = resolve13(cwd, path9);
|
|
236393
236447
|
let doc;
|
|
236394
236448
|
try {
|
|
236395
|
-
doc = parseSceneYaml(await
|
|
236449
|
+
doc = parseSceneYaml(await readFile5(file3, "utf8"));
|
|
236396
236450
|
} catch {
|
|
236397
236451
|
return { scene: await loadSceneFile(file3) };
|
|
236398
236452
|
}
|
|
@@ -236447,7 +236501,7 @@ var init_scenes = __esm({
|
|
|
236447
236501
|
});
|
|
236448
236502
|
|
|
236449
236503
|
// backend/src/actions.ts
|
|
236450
|
-
import { readFile as
|
|
236504
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
236451
236505
|
import { join as join18 } from "node:path";
|
|
236452
236506
|
function actionsOf(scene2, trace2) {
|
|
236453
236507
|
const writes3 = writeTools(scene2);
|
|
@@ -236509,7 +236563,7 @@ function actionLabel(action) {
|
|
|
236509
236563
|
return `${action.tool} ${args.length > 120 ? `${args.slice(0, 117)}...` : args}`;
|
|
236510
236564
|
}
|
|
236511
236565
|
async function savedFunctionTools(dir2, trace2, names8 = []) {
|
|
236512
|
-
const state3 = await
|
|
236566
|
+
const state3 = await readFile6(join18(dir2, "state.json"), "utf8").then((text31) => JSON.parse(text31)).catch(() => void 0);
|
|
236513
236567
|
return projectFunctionTools(trace2, state3, names8);
|
|
236514
236568
|
}
|
|
236515
236569
|
var writeTools, keyOf2;
|
|
@@ -236620,7 +236674,7 @@ var init_reproduction_text = __esm({
|
|
|
236620
236674
|
});
|
|
236621
236675
|
|
|
236622
236676
|
// backend/src/report.ts
|
|
236623
|
-
import { readFile as
|
|
236677
|
+
import { readFile as readFile7, writeFile as writeFile8 } from "node:fs/promises";
|
|
236624
236678
|
import { basename as basename5, dirname as dirname7, join as join19, relative as relative6, resolve as resolve14 } from "node:path";
|
|
236625
236679
|
function okFalseError(response6) {
|
|
236626
236680
|
if (typeof response6 !== "object" || response6 === null || response6.ok !== false) return void 0;
|
|
@@ -237134,7 +237188,7 @@ function normalizeSummary(s3) {
|
|
|
237134
237188
|
})) };
|
|
237135
237189
|
}
|
|
237136
237190
|
async function withAttemptToolDiagnostics(summary, runDir) {
|
|
237137
|
-
const inputs2 = await
|
|
237191
|
+
const inputs2 = await readFile7(join19(runDir, "inputs.json"), "utf8").then((text31) => JSON.parse(text31)).catch(() => void 0);
|
|
237138
237192
|
if (!inputs2?.cases) return summary;
|
|
237139
237193
|
return { ...summary, scenes: await Promise.all(summary.scenes.map(async (scene2) => {
|
|
237140
237194
|
const definition3 = inputs2.cases.find((c) => c.id === scene2.sceneId)?.scene;
|
|
@@ -237143,7 +237197,7 @@ async function withAttemptToolDiagnostics(summary, runDir) {
|
|
|
237143
237197
|
if (trial.toolCalls !== void 0) return trial;
|
|
237144
237198
|
const folder2 = join19(runDir, `trial-${scene2.sceneId}-${trial.trial}`);
|
|
237145
237199
|
try {
|
|
237146
|
-
const [traceText, checkText2] = await Promise.all([
|
|
237200
|
+
const [traceText, checkText2] = await Promise.all([readFile7(join19(folder2, "trace.jsonl"), "utf8"), readFile7(join19(folder2, "checks.json"), "utf8")]);
|
|
237147
237201
|
const trace2 = traceText.split("\n").filter(Boolean).map((line2) => JSON.parse(line2)), checks2 = JSON.parse(checkText2);
|
|
237148
237202
|
return { ...trial, ...attemptToolDiagnostics(definition3, { ...trial, trace: trace2, checks: checks2 }) };
|
|
237149
237203
|
} catch {
|
|
@@ -237205,7 +237259,7 @@ function sinceStart2(ms2) {
|
|
|
237205
237259
|
async function withWorldEvidence(s3, runDir, failures) {
|
|
237206
237260
|
const starts = /* @__PURE__ */ new Map();
|
|
237207
237261
|
try {
|
|
237208
|
-
const inputs2 = JSON.parse(await
|
|
237262
|
+
const inputs2 = JSON.parse(await readFile7(join19(runDir, "inputs.json"), "utf8"));
|
|
237209
237263
|
for (const item2 of inputs2.cases ?? []) {
|
|
237210
237264
|
const start2 = Date.parse(item2.scene?.start_time ?? "");
|
|
237211
237265
|
if (Number.isFinite(start2)) starts.set(item2.id, start2);
|
|
@@ -237218,7 +237272,7 @@ async function withWorldEvidence(s3, runDir, failures) {
|
|
|
237218
237272
|
let file3 = files2.get(key5);
|
|
237219
237273
|
if (file3 === void 0) {
|
|
237220
237274
|
const dir2 = s3.scenes.find((scene2) => scene2.sceneId === f2.sceneId)?.trialsDetail.find((t) => t.trial === f2.trial)?.dir;
|
|
237221
|
-
file3 = dir2 === void 0 ? Promise.resolve([]) :
|
|
237275
|
+
file3 = dir2 === void 0 ? Promise.resolve([]) : readFile7(join19(runDir, basename5(dir2), "explain.json"), "utf8").then((text31) => {
|
|
237222
237276
|
const value6 = JSON.parse(text31);
|
|
237223
237277
|
return Array.isArray(value6) ? value6 : [];
|
|
237224
237278
|
}).catch(() => []);
|
|
@@ -237400,7 +237454,7 @@ var init_report2 = __esm({
|
|
|
237400
237454
|
});
|
|
237401
237455
|
|
|
237402
237456
|
// backend/src/run-store.ts
|
|
237403
|
-
import { readFile as
|
|
237457
|
+
import { readFile as readFile8, stat as stat3 } from "node:fs/promises";
|
|
237404
237458
|
import { join as join20, resolve as resolve15 } from "node:path";
|
|
237405
237459
|
async function latestRunId(cwd, out) {
|
|
237406
237460
|
if (out !== void 0) return resolveRunId(cwd, "latest", out);
|
|
@@ -237408,11 +237462,11 @@ async function latestRunId(cwd, out) {
|
|
|
237408
237462
|
let local2;
|
|
237409
237463
|
try {
|
|
237410
237464
|
const path9 = join20(dir2, "latest");
|
|
237411
|
-
local2 = { runId: (await
|
|
237465
|
+
local2 = { runId: (await readFile8(path9, "utf8")).trim(), time: (await stat3(path9)).mtimeMs };
|
|
237412
237466
|
} catch (error65) {
|
|
237413
237467
|
if (!isEnoent(error65)) throw error65;
|
|
237414
237468
|
}
|
|
237415
|
-
const text31 = await
|
|
237469
|
+
const text31 = await readFile8(join20(dir2, "latest-cloud"), "utf8").catch((error65) => {
|
|
237416
237470
|
if (!isEnoent(error65)) throw error65;
|
|
237417
237471
|
return void 0;
|
|
237418
237472
|
});
|
|
@@ -237431,7 +237485,7 @@ async function resolveRunId(cwd, ref23, out) {
|
|
|
237431
237485
|
let runId2 = ref23;
|
|
237432
237486
|
if (ref23 === "latest") {
|
|
237433
237487
|
try {
|
|
237434
|
-
runId2 = (await
|
|
237488
|
+
runId2 = (await readFile8(join20(dir2, "latest"), "utf8")).trim();
|
|
237435
237489
|
} catch (e) {
|
|
237436
237490
|
if (isEnoent(e)) throw new AnchaError("USAGE", `no runs found in ${dir2}`, { hint: "run `ancha run` first", cause: e });
|
|
237437
237491
|
throw e;
|
|
@@ -237446,7 +237500,7 @@ async function loadRunSummary(cwd, ref23, out) {
|
|
|
237446
237500
|
if (!RUN_ID.test(runId2)) throw new AnchaError("USAGE", `unknown run ${JSON.stringify(runId2)}`, { hint });
|
|
237447
237501
|
let text31;
|
|
237448
237502
|
try {
|
|
237449
|
-
text31 = await
|
|
237503
|
+
text31 = await readFile8(join20(dir2, runId2, "summary.json"), "utf8");
|
|
237450
237504
|
} catch (e) {
|
|
237451
237505
|
if (!isEnoent(e)) throw e;
|
|
237452
237506
|
if (await stat3(join20(dir2, runId2)).then((s4) => s4.isDirectory(), () => false)) {
|
|
@@ -237483,7 +237537,7 @@ var init_run_store = __esm({
|
|
|
237483
237537
|
|
|
237484
237538
|
// backend/src/runner/run-state.ts
|
|
237485
237539
|
import { randomBytes as randomBytes7 } from "node:crypto";
|
|
237486
|
-
import { mkdir as mkdir11, readFile as
|
|
237540
|
+
import { mkdir as mkdir11, readFile as readFile9, rename as rename2, stat as stat4, writeFile as writeFile9 } from "node:fs/promises";
|
|
237487
237541
|
import { join as join21 } from "node:path";
|
|
237488
237542
|
function validateRunId(runId2) {
|
|
237489
237543
|
if (runId2.length > 128 || !/^run_[A-Za-z0-9_-]+$/.test(runId2)) throw new AnchaError("USAGE", "invalid run id", { hint: "use the run id returned by run" });
|
|
@@ -237515,7 +237569,7 @@ async function readRunState(outDir, runId2) {
|
|
|
237515
237569
|
validateRunId(runId2);
|
|
237516
237570
|
let value6;
|
|
237517
237571
|
try {
|
|
237518
|
-
value6 = JSON.parse(await
|
|
237572
|
+
value6 = JSON.parse(await readFile9(pathOf5(outDir, runId2), "utf8"));
|
|
237519
237573
|
} catch (error65) {
|
|
237520
237574
|
if (error65.code === "ENOENT") {
|
|
237521
237575
|
const summary = await loadRunSummary(outDir, runId2, ".");
|
|
@@ -237599,7 +237653,7 @@ var init_run_state = __esm({
|
|
|
237599
237653
|
|
|
237600
237654
|
// backend/src/runner/run.ts
|
|
237601
237655
|
import { createHash as createHash63, randomInt } from "node:crypto";
|
|
237602
|
-
import { access as access5, mkdir as mkdir12, readFile as
|
|
237656
|
+
import { access as access5, mkdir as mkdir12, readFile as readFile10, writeFile as writeFile10 } from "node:fs/promises";
|
|
237603
237657
|
import { dirname as dirname8, join as join22, relative as relative7, resolve as resolve16 } from "node:path";
|
|
237604
237658
|
function interrupted(dir2) {
|
|
237605
237659
|
return new AnchaError("USAGE", "run interrupted", dir2 === void 0 ? {} : { hint: `partial results in ${dir2}` });
|
|
@@ -237621,7 +237675,7 @@ async function recordsFor(scenePath, root3 = process.cwd()) {
|
|
|
237621
237675
|
}
|
|
237622
237676
|
async function recordsDigest(scenePath, root3) {
|
|
237623
237677
|
const file3 = await recordsFor(scenePath, root3);
|
|
237624
|
-
return file3 === void 0 ? void 0 : createHash63("sha256").update(await
|
|
237678
|
+
return file3 === void 0 ? void 0 : createHash63("sha256").update(await readFile10(file3)).digest("hex");
|
|
237625
237679
|
}
|
|
237626
237680
|
async function createEnvFor(backend, scene2, seed44, path9, people4) {
|
|
237627
237681
|
try {
|
|
@@ -237780,7 +237834,7 @@ async function executeRun(opts) {
|
|
|
237780
237834
|
for (const [index, item2] of cases.entries()) {
|
|
237781
237835
|
const source = await recordsFor(pathOf6(item2), opts.root);
|
|
237782
237836
|
if (source === void 0) continue;
|
|
237783
|
-
const text31 = await
|
|
237837
|
+
const text31 = await readFile10(source), copy = join22(dir2, "records", `${index}.jsonl`);
|
|
237784
237838
|
await mkdir12(dirname8(copy), { recursive: true });
|
|
237785
237839
|
await writeFile10(copy, text31, { flag: "wx", mode: 384 });
|
|
237786
237840
|
kept.set(item2.id, copy);
|
|
@@ -239222,13 +239276,13 @@ var init_agent_tools3 = __esm({
|
|
|
239222
239276
|
});
|
|
239223
239277
|
|
|
239224
239278
|
// backend/src/kit/connection-tools.ts
|
|
239225
|
-
import { readFile as
|
|
239279
|
+
import { readFile as readFile12 } from "node:fs/promises";
|
|
239226
239280
|
import { join as join25 } from "node:path";
|
|
239227
239281
|
async function probeTwins(dir2, agent, tests = []) {
|
|
239228
239282
|
return [.../* @__PURE__ */ new Set([...(await agentTools2(dir2, agent)).tools, ...tests])].slice(0, 6);
|
|
239229
239283
|
}
|
|
239230
239284
|
async function connectionTools(root3) {
|
|
239231
|
-
const text31 = await
|
|
239285
|
+
const text31 = await readFile12(join25(root3, CONNECTION_TOOLS_PATH), "utf8").catch((error65) => {
|
|
239232
239286
|
if (error65.code === "ENOENT") return void 0;
|
|
239233
239287
|
throw error65;
|
|
239234
239288
|
});
|
|
@@ -239259,7 +239313,7 @@ var init_connection_tools = __esm({
|
|
|
239259
239313
|
|
|
239260
239314
|
// backend/src/run-bundle.ts
|
|
239261
239315
|
import { createHash as createHash65 } from "node:crypto";
|
|
239262
|
-
import { readdir as readdir5, readFile as
|
|
239316
|
+
import { readdir as readdir5, readFile as readFile13 } from "node:fs/promises";
|
|
239263
239317
|
import { join as join27 } from "node:path";
|
|
239264
239318
|
import { gunzipSync as gunzipSync3, gzipSync } from "node:zlib";
|
|
239265
239319
|
function bundleSource(env2) {
|
|
@@ -239269,7 +239323,7 @@ async function bundleSecrets(options5) {
|
|
|
239269
239323
|
const base6 = new Set(BASE_ENV);
|
|
239270
239324
|
const names8 = options5.inheritEnv ? Object.keys(options5.env).filter((name5) => !base6.has(name5) && !name5.startsWith("LC_")) : [...options5.passEnv ?? []];
|
|
239271
239325
|
const values3 = names8.map((name5) => options5.env[name5]);
|
|
239272
|
-
const file3 = await
|
|
239326
|
+
const file3 = await readFile13(join27(options5.cwd, ".ancha/openrouter.env"), "utf8").catch(() => "");
|
|
239273
239327
|
for (const line2 of file3.split(/\r?\n/)) {
|
|
239274
239328
|
const match3 = /^\s*(?:export\s+)?[A-Za-z_][A-Za-z0-9_]*\s*=\s*(.*?)\s*$/.exec(line2);
|
|
239275
239329
|
if (match3) values3.push(match3[1].replace(/^(['"])(.*)\1$/, "$2"));
|
|
@@ -239323,7 +239377,7 @@ async function packRun(options5) {
|
|
|
239323
239377
|
if (paths3.length + 1 > most) throw tooBig2(`run ${options5.runId} has ${paths3.length} files to upload; a run bundle holds at most ${most - 1} besides its manifest`);
|
|
239324
239378
|
const entries4 = [], omitted = [];
|
|
239325
239379
|
for (const path9 of paths3) {
|
|
239326
|
-
let data7 = redact(await
|
|
239380
|
+
let data7 = redact(await readFile13(join27(options5.runDir, path9)), options5.secrets);
|
|
239327
239381
|
const cap = capFor(path9, options5.inputsBytes);
|
|
239328
239382
|
if (data7.length > cap) {
|
|
239329
239383
|
if (path9.endsWith("/agent.log")) data7 = logTail2(data7, cap);
|
|
@@ -239452,7 +239506,7 @@ var init_run_bundle = __esm({
|
|
|
239452
239506
|
|
|
239453
239507
|
// backend/src/kit/assets.ts
|
|
239454
239508
|
import { constants as constants10 } from "node:fs";
|
|
239455
|
-
import { lstat as lstat5, mkdir as mkdir14, open as open9, readFile as
|
|
239509
|
+
import { lstat as lstat5, mkdir as mkdir14, open as open9, readFile as readFile16, realpath as realpath6, rm as rm4 } from "node:fs/promises";
|
|
239456
239510
|
import { dirname as dirname12, isAbsolute as isAbsolute9, join as join31, relative as relative12, resolve as resolve23, sep as sep7 } from "node:path";
|
|
239457
239511
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
239458
239512
|
function assetRoot() {
|
|
@@ -239519,7 +239573,7 @@ async function templateFiles(template3, suppliedRoot) {
|
|
|
239519
239573
|
let manifest2;
|
|
239520
239574
|
try {
|
|
239521
239575
|
await preflightFiles(fileURLToPath2(root3), [{ relativePath: "manifest.json", content: "" }]);
|
|
239522
|
-
manifest2 = JSON.parse(await
|
|
239576
|
+
manifest2 = JSON.parse(await readFile16(new URL("manifest.json", root3), "utf8"));
|
|
239523
239577
|
} catch (cause) {
|
|
239524
239578
|
throw new AnchaError("CONFIG_INVALID", `the ${template3} template pack is unavailable or incomplete`, { hint: "install a distribution containing the pack, or use --template starter", docs: "ancha docs scenes", cause });
|
|
239525
239579
|
}
|
|
@@ -239529,7 +239583,7 @@ async function templateFiles(template3, suppliedRoot) {
|
|
|
239529
239583
|
safePath3(name5);
|
|
239530
239584
|
await preflightFiles(fileURLToPath2(root3), [{ relativePath: name5, content: "" }]);
|
|
239531
239585
|
try {
|
|
239532
|
-
files2.push({ relativePath: name5, content: await
|
|
239586
|
+
files2.push({ relativePath: name5, content: await readFile16(join31(fileURLToPath2(root3), name5), "utf8") });
|
|
239533
239587
|
} catch (cause) {
|
|
239534
239588
|
throw new AnchaError("CONFIG_INVALID", `template file is missing: ${name5}`, { hint: "install a complete template pack", cause });
|
|
239535
239589
|
}
|
|
@@ -239573,7 +239627,7 @@ var init_workspace = __esm({
|
|
|
239573
239627
|
|
|
239574
239628
|
// backend/src/execution/world-image.ts
|
|
239575
239629
|
import { createHash as createHash69 } from "node:crypto";
|
|
239576
|
-
import { readFile as
|
|
239630
|
+
import { readFile as readFile20 } from "node:fs/promises";
|
|
239577
239631
|
function worldImageTag(companion, worker = new Uint8Array()) {
|
|
239578
239632
|
const hash10 = createHash69("sha256");
|
|
239579
239633
|
for (const part of [WORLD_DOCKERFILE, WORLD_PACKAGE_JSON, companion, worker]) hash10.update(part).update("\0");
|
|
@@ -239581,14 +239635,14 @@ function worldImageTag(companion, worker = new Uint8Array()) {
|
|
|
239581
239635
|
}
|
|
239582
239636
|
async function packagedCompanion() {
|
|
239583
239637
|
try {
|
|
239584
|
-
return await
|
|
239638
|
+
return await readFile20(new URL("harbor/companion.mjs", assetRoot()));
|
|
239585
239639
|
} catch (cause) {
|
|
239586
239640
|
throw new AnchaError("CONFIG_INVALID", "The packaged world runtime is missing. Rebuild or reinstall Ancha.", { cause });
|
|
239587
239641
|
}
|
|
239588
239642
|
}
|
|
239589
239643
|
async function packagedSuiteqlWorker() {
|
|
239590
239644
|
try {
|
|
239591
|
-
return await
|
|
239645
|
+
return await readFile20(new URL("harbor/suiteql-worker.mjs", assetRoot()));
|
|
239592
239646
|
} catch (cause) {
|
|
239593
239647
|
throw new AnchaError("CONFIG_INVALID", "The packaged query runtime is missing. Rebuild or reinstall Ancha.", { cause });
|
|
239594
239648
|
}
|
|
@@ -239829,7 +239883,7 @@ __export(harbor_exports, {
|
|
|
239829
239883
|
validateHarborBatchSetup: () => validateHarborBatchSetup
|
|
239830
239884
|
});
|
|
239831
239885
|
import { execFile as execFile7, spawn as spawn4 } from "node:child_process";
|
|
239832
|
-
import { access as access9, chmod as chmod6, mkdir as mkdir17, mkdtemp as mkdtemp5, readFile as
|
|
239886
|
+
import { access as access9, chmod as chmod6, mkdir as mkdir17, mkdtemp as mkdtemp5, readFile as readFile21, rm as rm7, writeFile as writeFile15, lstat as lstat8, realpath as realpath10 } from "node:fs/promises";
|
|
239833
239887
|
import { tmpdir as tmpdir4, homedir } from "node:os";
|
|
239834
239888
|
import { dirname as dirname14, join as join36, basename as basename10 } from "node:path";
|
|
239835
239889
|
import { fileURLToPath as fileURLToPath4 } from "node:url";
|
|
@@ -239896,7 +239950,7 @@ async function cleanupHarborBatch(workspaceDir, batchId) {
|
|
|
239896
239950
|
const controller = join36(workspaceDir, ".ancha/harbor-runtime/controllers", batchId + ".json");
|
|
239897
239951
|
let marker;
|
|
239898
239952
|
try {
|
|
239899
|
-
marker = JSON.parse(await
|
|
239953
|
+
marker = JSON.parse(await readFile21(controller, "utf8"));
|
|
239900
239954
|
} catch (error65) {
|
|
239901
239955
|
if (error65.code !== "ENOENT") throw new AnchaError("INTERNAL", "The previous execution controller record could not be read.");
|
|
239902
239956
|
}
|
|
@@ -243277,19 +243331,19 @@ var init_production_trace = __esm({
|
|
|
243277
243331
|
|
|
243278
243332
|
// backend/src/production.ts
|
|
243279
243333
|
import { createHash as createHash71 } from "node:crypto";
|
|
243280
|
-
import { readFile as
|
|
243334
|
+
import { readFile as readFile23, writeFile as writeFile16 } from "node:fs/promises";
|
|
243281
243335
|
import { dirname as dirname15, join as join39 } from "node:path";
|
|
243282
243336
|
async function productionRecord(dir2) {
|
|
243283
|
-
const text31 = await
|
|
243337
|
+
const text31 = await readFile23(join39(dir2, "production.jsonl"), "utf8").catch(() => void 0);
|
|
243284
243338
|
return text31 === void 0 ? void 0 : productionTrace(text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2)));
|
|
243285
243339
|
}
|
|
243286
243340
|
async function completeProduction(scenePath, scene2, judge, into) {
|
|
243287
243341
|
const dir2 = dirname15(scenePath);
|
|
243288
|
-
const text31 = await
|
|
243342
|
+
const text31 = await readFile23(join39(dir2, "production.jsonl"), "utf8").catch(() => void 0);
|
|
243289
243343
|
if (text31 === void 0) return [];
|
|
243290
243344
|
const lines2 = text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
243291
243345
|
const file3 = into ?? join39(dir2, "production.json");
|
|
243292
|
-
const known2 = await
|
|
243346
|
+
const known2 = await readFile23(file3, "utf8").then((t) => JSON.parse(t), () => ({}));
|
|
243293
243347
|
const checks2 = { ...known2.checks }, signatures = { ...known2.signatures };
|
|
243294
243348
|
const sign4 = productionSignature;
|
|
243295
243349
|
const missing10 = scene2.checks.filter((check4) => checks2[check4.id] === void 0 || checks2[check4.id] === "unknown" || signatures[check4.id] !== void 0 && signatures[check4.id] !== sign4(check4));
|
|
@@ -243347,7 +243401,7 @@ var init_production = __esm({
|
|
|
243347
243401
|
});
|
|
243348
243402
|
|
|
243349
243403
|
// backend/src/production-comparison.ts
|
|
243350
|
-
import { readFile as
|
|
243404
|
+
import { readFile as readFile24 } from "node:fs/promises";
|
|
243351
243405
|
import { dirname as dirname16, join as join40, resolve as resolve28 } from "node:path";
|
|
243352
243406
|
async function reproductionOf(summary, scenePaths, cwd, runDir, scenes = [], productionFiles = {}) {
|
|
243353
243407
|
const out = [];
|
|
@@ -243355,7 +243409,7 @@ async function reproductionOf(summary, scenePaths, cwd, runDir, scenes = [], pro
|
|
|
243355
243409
|
const path9 = scenePaths[scene2.sceneId];
|
|
243356
243410
|
if (path9 === void 0) continue;
|
|
243357
243411
|
const file3 = Object.hasOwn(productionFiles, scene2.sceneId) ? productionFiles[scene2.sceneId] : join40(dirname16(resolve28(cwd, path9)), "production.json");
|
|
243358
|
-
const production3 = await
|
|
243412
|
+
const production3 = await readFile24(file3, "utf8").then((text31) => JSON.parse(text31), () => void 0);
|
|
243359
243413
|
if (production3?.checks === void 0) continue;
|
|
243360
243414
|
const checks2 = Object.entries(production3.checks).flatMap(([check4, result]) => {
|
|
243361
243415
|
const here = scene2.checks[check4];
|
|
@@ -243409,7 +243463,7 @@ async function reproductionOf(summary, scenePaths, cwd, runDir, scenes = [], pro
|
|
|
243409
243463
|
async function answerSources(runDir, scene2) {
|
|
243410
243464
|
const counts2 = {};
|
|
243411
243465
|
for (const { trial } of scene2.trialsDetail) {
|
|
243412
|
-
const text31 = await
|
|
243466
|
+
const text31 = await readFile24(join40(runDir, `trial-${scene2.sceneId}-${trial}`, "trace.jsonl"), "utf8").catch(() => "");
|
|
243413
243467
|
for (const entry3 of text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2))) {
|
|
243414
243468
|
const source = entry3.service === "tools" && entry3.path?.startsWith("/tools/") ? entry3.response?.source : void 0;
|
|
243415
243469
|
if (source) counts2[source] = (counts2[source] ?? 0) + 1;
|
|
@@ -243424,7 +243478,7 @@ async function writesOf(scene2, dir2, runDir, ran) {
|
|
|
243424
243478
|
for (const action of actionsOf(scene2, record33)) made.set(action.tool, (made.get(action.tool) ?? 0) + 1);
|
|
243425
243479
|
const trials = (ran.trialsDetail ?? []).filter((t) => t.valid !== false);
|
|
243426
243480
|
for (const { trial } of trials) {
|
|
243427
|
-
const text31 = await
|
|
243481
|
+
const text31 = await readFile24(join40(runDir, `trial-${ran.sceneId}-${trial}`, "trace.jsonl"), "utf8").catch(() => "");
|
|
243428
243482
|
const trace2 = text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
243429
243483
|
for (const tool of new Set(actionsOf(scene2, trace2).map((action) => action.tool))) here.set(tool, (here.get(tool) ?? 0) + 1);
|
|
243430
243484
|
}
|
|
@@ -243442,7 +243496,7 @@ var init_production_comparison = __esm({
|
|
|
243442
243496
|
|
|
243443
243497
|
// backend/src/baselines.ts
|
|
243444
243498
|
import { randomUUID as randomUUID14 } from "node:crypto";
|
|
243445
|
-
import { link as link6, mkdir as mkdir18, readFile as
|
|
243499
|
+
import { link as link6, mkdir as mkdir18, readFile as readFile25, rename as rename6, unlink, writeFile as writeFile17 } from "node:fs/promises";
|
|
243446
243500
|
import { dirname as dirname17, join as join41, resolve as resolve30 } from "node:path";
|
|
243447
243501
|
function validateTrialCounts(scene2) {
|
|
243448
243502
|
if (!Number.isSafeInteger(scene2.passed) || !Number.isSafeInteger(scene2.trials) || scene2.trials <= 0 || scene2.passed < 0 || scene2.passed > scene2.trials) {
|
|
@@ -243559,7 +243613,7 @@ async function loadComparisonSummary(cwd, ref23, out) {
|
|
|
243559
243613
|
const path9 = join41(baselineDir(cwd, out), `${ref23}.json`);
|
|
243560
243614
|
let text31;
|
|
243561
243615
|
try {
|
|
243562
|
-
text31 = await
|
|
243616
|
+
text31 = await readFile25(path9, "utf8");
|
|
243563
243617
|
} catch (error65) {
|
|
243564
243618
|
if (error65.code !== "ENOENT") throw error65;
|
|
243565
243619
|
}
|
|
@@ -243678,7 +243732,7 @@ __export(vm_connection_exports, {
|
|
|
243678
243732
|
taskFixFromLog: () => taskFixFromLog
|
|
243679
243733
|
});
|
|
243680
243734
|
import { closeSync as closeSync7, openSync as openSync7, writeSync as writeSync7 } from "node:fs";
|
|
243681
|
-
import { mkdir as mkdir20, readFile as
|
|
243735
|
+
import { mkdir as mkdir20, readFile as readFile26 } from "node:fs/promises";
|
|
243682
243736
|
import { createServer as createServer5 } from "node:net";
|
|
243683
243737
|
import { join as join44 } from "node:path";
|
|
243684
243738
|
import { setTimeout as sleep11 } from "node:timers/promises";
|
|
@@ -243863,7 +243917,7 @@ async function probeVmConnection(descriptor3, deps = {}) {
|
|
|
243863
243917
|
await child3?.stop();
|
|
243864
243918
|
if (child3?.output?.().model) probe.model = child3.output().model;
|
|
243865
243919
|
child3 = void 0;
|
|
243866
|
-
const text31 = await
|
|
243920
|
+
const text31 = await readFile26(join44(descriptor3.outDir, "agent.log"), "utf8").catch(() => "");
|
|
243867
243921
|
const tail = text31.trimEnd().split("\n").filter(Boolean).slice(-10);
|
|
243868
243922
|
if (tail.length) probe.logTail = tail;
|
|
243869
243923
|
if (error65 instanceof AnchaError || !(error65 instanceof Error) || !["AbortError", "TimeoutError"].includes(error65.name)) throw connectionFailure(error65, descriptor3);
|
|
@@ -243931,7 +243985,7 @@ async function runWithTask(descriptor3, agent, run7) {
|
|
|
243931
243985
|
await backend?.close().catch(() => {
|
|
243932
243986
|
});
|
|
243933
243987
|
}
|
|
243934
|
-
const log3 = trial === void 0 ? void 0 : await
|
|
243988
|
+
const log3 = trial === void 0 ? void 0 : await readFile26(join44(trial.dir, "agent.log")).catch(() => void 0);
|
|
243935
243989
|
if (log3 !== void 0) writeSync7(run7.fd, log3);
|
|
243936
243990
|
probe.durationMs = trial?.realMs ?? 0;
|
|
243937
243991
|
probe.exitCode = trial?.exitCode ?? null;
|
|
@@ -243946,7 +244000,7 @@ async function runWithTask(descriptor3, agent, run7) {
|
|
|
243946
244000
|
Object.assign(probe, { reason: route15.reason, logTail: tail.length > 0 ? tail : text31.trimEnd().split("\n").filter(Boolean).slice(-10) });
|
|
243947
244001
|
return { state: "failed", probe, message: route15.reason.message };
|
|
243948
244002
|
}
|
|
243949
|
-
const diagnosed = (code5) => ["MODEL_KEY_REFUSED", "MODEL_RATE_LIMITED", "MODEL_CREDITS_EXHAUSTED"].includes(code5 ?? "") || routed && (code5 === "ROUTE_REFUSED" || code5 === "ROUTE_NOT_REACHED" || code5 === "ROUTE_KEY_REJECTED");
|
|
244003
|
+
const diagnosed = (code5) => ["MODEL_KEY_REFUSED", "MODEL_RATE_LIMITED", "MODEL_CREDITS_EXHAUSTED", "MODEL_UNREACHABLE"].includes(code5 ?? "") || routed && (code5 === "ROUTE_REFUSED" || code5 === "ROUTE_NOT_REACHED" || code5 === "ROUTE_KEY_REJECTED");
|
|
243950
244004
|
const harnessIssue = trial.harnessIssues.some((issue9) => issue9.owner === "harness" && !diagnosed(issue9.code));
|
|
243951
244005
|
if (harnessIssue || !trial.valid && !trial.harnessIssues.some((issue9) => diagnosed(issue9.code))) throw connectionFailure(new AnchaError("INTERNAL", unfinished(trial)), descriptor3);
|
|
243952
244006
|
if (trial.exit === "spawn_failed" && agent.taskInput?.kind === "http") {
|
|
@@ -243957,7 +244011,7 @@ async function runWithTask(descriptor3, agent, run7) {
|
|
|
243957
244011
|
const own2 = netsuiteMappings(scan2?.variables ?? []).filter((mapping) => !Object.hasOwn(agent.env, mapping.name));
|
|
243958
244012
|
const suggestedJson = plainTextTaskParseError(tail) ? jsonTaskWiring(scan2, command) : void 0;
|
|
243959
244013
|
const jsonMapping = suggestedJson && suggestedJson.length <= 430 ? suggestedJson : void 0;
|
|
243960
|
-
const outcome4 = attemptOutcome({ exit: trial.exit, exitCode: trial.exitCode, realMs: trial.realMs, trace: trial.trace, log: text31, logTail: tail, modelReplies: trial.modelReplies, sessionRefusals: trial.sessionRefusals }, {
|
|
244014
|
+
const outcome4 = attemptOutcome({ exit: trial.exit, exitCode: trial.exitCode, realMs: trial.realMs, trace: trial.trace, log: text31, logTail: tail, modelReplies: trial.modelReplies, modelRequests: trial.model?.requests, sessionRefusals: trial.sessionRefusals }, {
|
|
243961
244015
|
check: netsuite ? "netsuite" : "start",
|
|
243962
244016
|
answerChecked: false,
|
|
243963
244017
|
stdin: agent.taskInput?.kind === "stdin" ? null : scan2?.stdin,
|
|
@@ -244026,7 +244080,7 @@ async function probeSlackApp(descriptor3, agent, probe, deps) {
|
|
|
244026
244080
|
await child3?.stop();
|
|
244027
244081
|
if (child3?.output?.().model) probe.model = child3.output().model;
|
|
244028
244082
|
child3 = void 0;
|
|
244029
|
-
const log3 = await
|
|
244083
|
+
const log3 = await readFile26(join44(descriptor3.outDir, "agent.log"), "utf8").catch(() => "");
|
|
244030
244084
|
probe.logTail = log3.trimEnd().split("\n").filter(Boolean).slice(-10);
|
|
244031
244085
|
if (ingress && routeKeyRejected(ingress.entries())) {
|
|
244032
244086
|
probe.reason = { ...ROUTE_KEY_REASON };
|
|
@@ -244087,7 +244141,7 @@ __export(assemble_exports, {
|
|
|
244087
244141
|
finalizeInput: () => finalizeInput
|
|
244088
244142
|
});
|
|
244089
244143
|
import { createHash as createHash73 } from "node:crypto";
|
|
244090
|
-
import { copyFile as copyFile4, lstat as lstat9, mkdir as mkdir21, mkdtemp as mkdtemp7, readdir as readdir8, readFile as
|
|
244144
|
+
import { copyFile as copyFile4, lstat as lstat9, mkdir as mkdir21, mkdtemp as mkdtemp7, readdir as readdir8, readFile as readFile27, rm as rm9, writeFile as writeFile19 } from "node:fs/promises";
|
|
244091
244145
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
244092
244146
|
import { dirname as dirname18, join as join45, resolve as resolve34, sep as sep9 } from "node:path";
|
|
244093
244147
|
function finalizeInput(value6) {
|
|
@@ -244190,7 +244244,7 @@ function inside2(root3, path9, what) {
|
|
|
244190
244244
|
async function bundleManifest(bundleDir) {
|
|
244191
244245
|
let manifest2;
|
|
244192
244246
|
try {
|
|
244193
|
-
manifest2 = JSON.parse(await
|
|
244247
|
+
manifest2 = JSON.parse(await readFile27(join45(bundleDir, "manifest.json"), "utf8"));
|
|
244194
244248
|
} catch {
|
|
244195
244249
|
throw new AnchaError("INTERNAL", "the bundle has no readable manifest.json");
|
|
244196
244250
|
}
|
|
@@ -244215,7 +244269,7 @@ async function evidenceOf(folder2, input5, attempt2) {
|
|
|
244215
244269
|
};
|
|
244216
244270
|
let manifest2;
|
|
244217
244271
|
try {
|
|
244218
|
-
manifest2 = JSON.parse(await
|
|
244272
|
+
manifest2 = JSON.parse(await readFile27(join45(folder2, "artifact.json"), "utf8"));
|
|
244219
244273
|
} catch {
|
|
244220
244274
|
broken("has no readable artifact.json");
|
|
244221
244275
|
}
|
|
@@ -244229,7 +244283,7 @@ async function evidenceOf(folder2, input5, attempt2) {
|
|
|
244229
244283
|
if (files2.has(name5)) broken(`lists ${file3.path} twice`);
|
|
244230
244284
|
const path9 = join45(folder2, file3.path);
|
|
244231
244285
|
if (!await lstat9(path9).then((info2) => info2.isFile(), () => false)) broken(`has no ${file3.path}`);
|
|
244232
|
-
const data7 = await
|
|
244286
|
+
const data7 = await readFile27(path9);
|
|
244233
244287
|
if (data7.length !== file3.bytes || sha2565(data7) !== file3.sha256) broken(`has a ${file3.path} that differs from its artifact.json`);
|
|
244234
244288
|
files2.set(name5, path9);
|
|
244235
244289
|
}
|
|
@@ -244240,7 +244294,7 @@ async function rebuilt(files2, attempt2, scene2, dir2) {
|
|
|
244240
244294
|
if (resultFile === void 0) return { problem: "the attempt left no result.json" };
|
|
244241
244295
|
let raw3;
|
|
244242
244296
|
try {
|
|
244243
|
-
raw3 = JSON.parse(await
|
|
244297
|
+
raw3 = JSON.parse(await readFile27(resultFile, "utf8"));
|
|
244244
244298
|
} catch {
|
|
244245
244299
|
return { problem: "the attempt's result.json is not JSON" };
|
|
244246
244300
|
}
|
|
@@ -244261,7 +244315,7 @@ async function rebuilt(files2, attempt2, scene2, dir2) {
|
|
|
244261
244315
|
const traceFile = files2.get("trace.jsonl");
|
|
244262
244316
|
if (traceFile !== void 0) {
|
|
244263
244317
|
try {
|
|
244264
|
-
trace2 = (await
|
|
244318
|
+
trace2 = (await readFile27(traceFile, "utf8")).split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
244265
244319
|
} catch {
|
|
244266
244320
|
return { problem: "the attempt's trace.jsonl is not JSON lines" };
|
|
244267
244321
|
}
|
|
@@ -244300,7 +244354,7 @@ async function trialOf(attempt2, item2, input5, artifactsDir, runDir) {
|
|
|
244300
244354
|
return result;
|
|
244301
244355
|
}
|
|
244302
244356
|
async function pinnedBaseline2(projectDir, pin2) {
|
|
244303
|
-
const data7 = await
|
|
244357
|
+
const data7 = await readFile27(inside2(projectDir, pin2.path, "the baseline"));
|
|
244304
244358
|
if (sha2565(data7) !== pin2.sha256) throw new AnchaError("INTERNAL", `the baseline ${pin2.path} is not the one the run was submitted with`);
|
|
244305
244359
|
const parsed5 = JSON.parse(data7.toString("utf8"));
|
|
244306
244360
|
if (!isRecord5(parsed5) || parsed5.runId !== pin2.runId || !Array.isArray(parsed5.scenes)) throw new AnchaError("INTERNAL", `the baseline ${pin2.path} is not run ${pin2.runId}`);
|
|
@@ -244333,7 +244387,7 @@ async function productionComparison(summary, cases, projectDir, runDir, judge) {
|
|
|
244333
244387
|
}
|
|
244334
244388
|
}
|
|
244335
244389
|
async function assembleCloudRun(options5) {
|
|
244336
|
-
const input5 = finalizeInput(typeof options5.input === "string" ? JSON.parse(await
|
|
244390
|
+
const input5 = finalizeInput(typeof options5.input === "string" ? JSON.parse(await readFile27(options5.input, "utf8")) : options5.input);
|
|
244337
244391
|
const { jobId: runId2, options: resolved } = input5, projectDir = join45(options5.bundleDir, "project");
|
|
244338
244392
|
checkMatrix(input5);
|
|
244339
244393
|
await checkFolders(options5.artifactsDir, input5);
|
|
@@ -244490,10 +244544,10 @@ __export(view_exports, {
|
|
|
244490
244544
|
renderCloudView: () => renderCloudView
|
|
244491
244545
|
});
|
|
244492
244546
|
import { randomBytes as randomBytes8 } from "node:crypto";
|
|
244493
|
-
import { readFile as
|
|
244547
|
+
import { readFile as readFile28 } from "node:fs/promises";
|
|
244494
244548
|
import { dirname as dirname19 } from "node:path";
|
|
244495
244549
|
async function renderCloudView(path9) {
|
|
244496
|
-
const input5 = JSON.parse(await
|
|
244550
|
+
const input5 = JSON.parse(await readFile28(path9, "utf8"));
|
|
244497
244551
|
if (!input5 || typeof input5 !== "object" || Array.isArray(input5) || Object.keys(input5).some((k) => !["scene", "configuration", "path", "seed"].includes(k)) || ["scene", "configuration", "path"].filter((k) => k in input5).length !== 1 || input5.seed !== null && (typeof input5.seed !== "string" || !input5.seed)) throw new AnchaError("CONFIG_INVALID", "Choose one world definition and its seed.");
|
|
244498
244552
|
if ("path" in input5 && (typeof input5.path !== "string" || !input5.path.split("/").every((p2) => p2 && p2 !== "." && p2 !== "..") || /[\\:\x00-\x1f]/.test(input5.path))) throw new AnchaError("CONFIG_INVALID", "Choose a test path inside the view bundle.");
|
|
244499
244553
|
const scene2 = "scene" in input5 ? parseScene(input5.scene) : "path" in input5 ? (await loadSceneOrTest(dirname19(path9), input5.path)).scene : null;
|
|
@@ -250389,7 +250443,7 @@ function serverError(status6, body8, fallback) {
|
|
|
250389
250443
|
init_src();
|
|
250390
250444
|
init_credentials();
|
|
250391
250445
|
import { execFile as execFile4 } from "node:child_process";
|
|
250392
|
-
import { mkdtemp as mkdtemp4, readFile as
|
|
250446
|
+
import { mkdtemp as mkdtemp4, readFile as readFile14, rm as rm3, stat as stat7, writeFile as writeFile12 } from "node:fs/promises";
|
|
250393
250447
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
250394
250448
|
import { basename as basename8, join as join29, resolve as resolve22 } from "node:path";
|
|
250395
250449
|
import { promisify as promisify4 } from "node:util";
|
|
@@ -250397,7 +250451,7 @@ import { promisify as promisify4 } from "node:util";
|
|
|
250397
250451
|
// backend/src/cloud/dependencies.ts
|
|
250398
250452
|
import { execFile as execFile3 } from "node:child_process";
|
|
250399
250453
|
import { constants as constants7 } from "node:fs";
|
|
250400
|
-
import { access as access6, lstat as lstat2, open as open5, readFile as
|
|
250454
|
+
import { access as access6, lstat as lstat2, open as open5, readFile as readFile11, realpath as realpath4, stat as stat5 } from "node:fs/promises";
|
|
250401
250455
|
import { basename as basename6, dirname as dirname9, isAbsolute as isAbsolute5, join as join23, posix as posix3, relative as relative8, resolve as resolve17, sep as sep3 } from "node:path";
|
|
250402
250456
|
import { promisify as promisify3 } from "node:util";
|
|
250403
250457
|
|
|
@@ -251303,7 +251357,7 @@ async function readYarnConfig(root3, path9) {
|
|
|
251303
251357
|
}
|
|
251304
251358
|
}
|
|
251305
251359
|
async function anchaIgnore(root3) {
|
|
251306
|
-
return (await
|
|
251360
|
+
return (await readFile11(join23(root3, ".anchaignore"), "utf8").catch(() => "")).split("\n").map((line2) => line2.trim()).filter((line2) => line2 && !line2.startsWith("#")).flatMap((pattern) => {
|
|
251307
251361
|
const bare = pattern.replace(/^\//, "").replace(/\/$/, "");
|
|
251308
251362
|
return pattern.startsWith("/") ? [bare, `${bare}/**`] : [bare, `${bare}/**`, `**/${bare}`, `**/${bare}/**`];
|
|
251309
251363
|
});
|
|
@@ -251361,7 +251415,7 @@ async function agentStartDefinitionError(input5, definition3) {
|
|
|
251361
251415
|
}
|
|
251362
251416
|
var readJson = async (path9) => {
|
|
251363
251417
|
try {
|
|
251364
|
-
const value6 = JSON.parse(await
|
|
251418
|
+
const value6 = JSON.parse(await readFile11(path9, "utf8"));
|
|
251365
251419
|
return value6 !== null && typeof value6 === "object" && !Array.isArray(value6) ? value6 : void 0;
|
|
251366
251420
|
} catch {
|
|
251367
251421
|
return void 0;
|
|
@@ -251398,7 +251452,7 @@ async function loadTests(root3, paths3) {
|
|
|
251398
251452
|
for (const path9 of tests) {
|
|
251399
251453
|
let doc;
|
|
251400
251454
|
try {
|
|
251401
|
-
doc = parseSceneYaml(await
|
|
251455
|
+
doc = parseSceneYaml(await readFile11(join23(root3, path9), "utf8"));
|
|
251402
251456
|
} catch {
|
|
251403
251457
|
continue;
|
|
251404
251458
|
}
|
|
@@ -251425,7 +251479,7 @@ async function caseProvenance(root3, test3) {
|
|
|
251425
251479
|
if (record27(provenance?.conversation) && Array.isArray(provenance.conversation.traces)) {
|
|
251426
251480
|
for (const trace2 of provenance.conversation.traces) if (typeof trace2 === "string" && trace2) external2.add(trace2);
|
|
251427
251481
|
}
|
|
251428
|
-
const pulled = /^# ancha pull: (\S+) /m.exec(await
|
|
251482
|
+
const pulled = /^# ancha pull: (\S+) /m.exec(await readFile11(join23(root3, test3.path), "utf8").catch(() => ""));
|
|
251429
251483
|
return { caseId: test3.scene.id, traceIds: [], externalTraceIds: [...external2].sort(), ...pulled !== null && { testId: pulled[1] } };
|
|
251430
251484
|
}
|
|
251431
251485
|
async function bundleInventory(input5) {
|
|
@@ -251447,7 +251501,7 @@ async function bundleInventory(input5) {
|
|
|
251447
251501
|
add(test3.path, "test");
|
|
251448
251502
|
let doc;
|
|
251449
251503
|
try {
|
|
251450
|
-
doc = parseSceneYaml(await
|
|
251504
|
+
doc = parseSceneYaml(await readFile11(join23(root3, test3.path), "utf8"));
|
|
251451
251505
|
} catch {
|
|
251452
251506
|
doc = void 0;
|
|
251453
251507
|
}
|
|
@@ -251462,7 +251516,7 @@ async function bundleInventory(input5) {
|
|
|
251462
251516
|
link8(test3.path, "world", world5, "world", "world");
|
|
251463
251517
|
let worldDoc;
|
|
251464
251518
|
try {
|
|
251465
|
-
worldDoc = parseSceneYaml(await
|
|
251519
|
+
worldDoc = parseSceneYaml(await readFile11(join23(root3, world5), "utf8"));
|
|
251466
251520
|
} catch {
|
|
251467
251521
|
worldDoc = void 0;
|
|
251468
251522
|
}
|
|
@@ -252338,7 +252392,7 @@ async function forward(ctx, serverUrl3, words9, raw3) {
|
|
|
252338
252392
|
continue;
|
|
252339
252393
|
}
|
|
252340
252394
|
const path9 = resolve22(ctx.io.cwd, value6), name5 = basename8(path9).replace(/[^A-Za-z0-9._-]/g, "-").replace(/^[^A-Za-z0-9]+/, "").slice(0, 100) || "file";
|
|
252341
|
-
const content2 = await
|
|
252395
|
+
const content2 = await readFile14(path9).catch(() => void 0);
|
|
252342
252396
|
if (content2 === void 0) {
|
|
252343
252397
|
if (flag5 === "--test") {
|
|
252344
252398
|
argv.push(flag5, value6);
|
|
@@ -252480,7 +252534,7 @@ async function packProject(dir2) {
|
|
|
252480
252534
|
try {
|
|
252481
252535
|
await writeFile12(join29(temporary, "files"), files2.join("\0"));
|
|
252482
252536
|
await run4("tar", ["-czf", join29(temporary, "project.tar.gz"), "-C", root3, "--null", "-T", join29(temporary, "files")], { maxBuffer: 16 * 1024 * 1024 });
|
|
252483
|
-
return { archive: await
|
|
252537
|
+
return { archive: await readFile14(join29(temporary, "project.tar.gz")), files: files2.length, bytes: bytes4 };
|
|
252484
252538
|
} finally {
|
|
252485
252539
|
await rm3(temporary, { recursive: true, force: true });
|
|
252486
252540
|
}
|
|
@@ -252583,7 +252637,7 @@ function registerEnv(program2, ctx) {
|
|
|
252583
252637
|
// packages/cli/src/commands/explain.ts
|
|
252584
252638
|
init_src();
|
|
252585
252639
|
init_src();
|
|
252586
|
-
import { readFile as
|
|
252640
|
+
import { readFile as readFile36, writeFile as writeFile24 } from "node:fs/promises";
|
|
252587
252641
|
import { join as join50, relative as relative19, resolve as resolve39 } from "node:path";
|
|
252588
252642
|
|
|
252589
252643
|
// packages/cli/src/numbers.ts
|
|
@@ -252609,7 +252663,7 @@ import { createHash as createHash66 } from "node:crypto";
|
|
|
252609
252663
|
init_src();
|
|
252610
252664
|
init_report2();
|
|
252611
252665
|
init_run_inputs();
|
|
252612
|
-
import { readFile as
|
|
252666
|
+
import { readFile as readFile15 } from "node:fs/promises";
|
|
252613
252667
|
import { join as join30 } from "node:path";
|
|
252614
252668
|
var CALLS_SHOWN = 200;
|
|
252615
252669
|
var LOG_LINES = 40;
|
|
@@ -252624,12 +252678,12 @@ var trialFolder = (sceneId, trial) => `trial-${sceneId}-${trial}`;
|
|
|
252624
252678
|
async function readRunRecords(runDir, summary, options5) {
|
|
252625
252679
|
const json40 = async (path9) => {
|
|
252626
252680
|
try {
|
|
252627
|
-
return JSON.parse(await
|
|
252681
|
+
return JSON.parse(await readFile15(path9, "utf8"));
|
|
252628
252682
|
} catch {
|
|
252629
252683
|
return null;
|
|
252630
252684
|
}
|
|
252631
252685
|
};
|
|
252632
|
-
const text31 = async (path9) =>
|
|
252686
|
+
const text31 = async (path9) => readFile15(path9, "utf8").catch(() => null);
|
|
252633
252687
|
const events3 = await text31(join30(runDir, "events.ndjson"));
|
|
252634
252688
|
let atOnce2 = null;
|
|
252635
252689
|
try {
|
|
@@ -253353,7 +253407,7 @@ async function consoleApi(base6) {
|
|
|
253353
253407
|
// packages/cli/src/commands/playground.ts
|
|
253354
253408
|
var import_yaml8 = __toESM(require_dist(), 1);
|
|
253355
253409
|
init_src();
|
|
253356
|
-
import { readFile as
|
|
253410
|
+
import { readFile as readFile31, stat as stat11 } from "node:fs/promises";
|
|
253357
253411
|
import { resolve as resolve37 } from "node:path";
|
|
253358
253412
|
|
|
253359
253413
|
// backend/src/playgrounds/service.ts
|
|
@@ -253673,13 +253727,13 @@ init_src();
|
|
|
253673
253727
|
import { createHash as createHash67, randomUUID as randomUUID9 } from "node:crypto";
|
|
253674
253728
|
import { execFile as execFile6 } from "node:child_process";
|
|
253675
253729
|
import { promisify as promisify6 } from "node:util";
|
|
253676
|
-
import { readFile as
|
|
253730
|
+
import { readFile as readFile19, readdir as readdir6, realpath as realpath9, rename as rename4, rm as rm5, stat as stat9, lstat as lstat7, writeFile as writeFile13 } from "node:fs/promises";
|
|
253677
253731
|
import { join as join34, resolve as resolve26 } from "node:path";
|
|
253678
253732
|
init_config();
|
|
253679
253733
|
init_assets();
|
|
253680
253734
|
|
|
253681
253735
|
// backend/src/console/catalog.ts
|
|
253682
|
-
import { readFile as
|
|
253736
|
+
import { readFile as readFile17, realpath as realpath7, stat as stat8 } from "node:fs/promises";
|
|
253683
253737
|
import { basename as basename9, join as join33, resolve as resolve24 } from "node:path";
|
|
253684
253738
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
253685
253739
|
var import_yaml6 = __toESM(require_dist(), 1);
|
|
@@ -253691,7 +253745,7 @@ async function safeRead(root3, path9, max = 2e6) {
|
|
|
253691
253745
|
await preflightFiles(root3, [{ relativePath: path9, content: "" }]);
|
|
253692
253746
|
const file3 = join33(root3, path9);
|
|
253693
253747
|
if ((await stat8(file3)).size > max) throw new AnchaError("USAGE", "file exceeds the console display limit");
|
|
253694
|
-
return
|
|
253748
|
+
return readFile17(file3, "utf8");
|
|
253695
253749
|
}
|
|
253696
253750
|
function parseDefinition(yaml) {
|
|
253697
253751
|
const doc = (0, import_yaml6.parseDocument)(yaml);
|
|
@@ -253815,7 +253869,7 @@ init_policy();
|
|
|
253815
253869
|
|
|
253816
253870
|
// backend/src/execution/provider.ts
|
|
253817
253871
|
init_src();
|
|
253818
|
-
import { lstat as lstat6, readFile as
|
|
253872
|
+
import { lstat as lstat6, readFile as readFile18, realpath as realpath8 } from "node:fs/promises";
|
|
253819
253873
|
import { isAbsolute as isAbsolute10, relative as relative13, resolve as resolve25 } from "node:path";
|
|
253820
253874
|
var providerDetails = {
|
|
253821
253875
|
openrouter: { key: "OPENROUTER_API_KEY", modelVariable: "OPENROUTER_MODEL", host: "openrouter.ai", baseVariable: "OPENROUTER_BASE_URL", baseUrl: "https://openrouter.ai/api/v1" },
|
|
@@ -253862,7 +253916,7 @@ async function readApprovedOpenRouterKey(workspace4) {
|
|
|
253862
253916
|
const actual = await realpath8(path9);
|
|
253863
253917
|
if (actual !== path9 || actual !== resolve25(root3, ".ancha/openrouter.env")) return void 0;
|
|
253864
253918
|
if (fileStat.size > 16384) return void 0;
|
|
253865
|
-
const contents2 = await
|
|
253919
|
+
const contents2 = await readFile18(path9, "utf8");
|
|
253866
253920
|
const keys7 = contents2.split(/\r?\n/).flatMap((line2) => {
|
|
253867
253921
|
const match3 = /^\s*OPENROUTER_API_KEY\s*=\s*(.*?)\s*$/.exec(line2);
|
|
253868
253922
|
if (!match3) return [];
|
|
@@ -253961,7 +254015,7 @@ async function identifyCode(cwd) {
|
|
|
253961
254015
|
for (const file3 of files2) {
|
|
253962
254016
|
const path9 = join34(cwd, file3), info2 = await lstat7(path9);
|
|
253963
254017
|
if (!info2.isFile() || (bytes4 += info2.size) > 2e7) throw new Error("source scope incomplete");
|
|
253964
|
-
content2.update(file3).update("\0").update(await
|
|
254018
|
+
content2.update(file3).update("\0").update(await readFile19(path9)).update("\0");
|
|
253965
254019
|
}
|
|
253966
254020
|
const sourceHash = content2.digest("hex");
|
|
253967
254021
|
return { ...git, sourceFiles: files2.length, codeCoverage: git ? "tracked-and-source" : "source-files", mutable: true, fingerprint: hash7({ git, sourceHash }) };
|
|
@@ -255402,7 +255456,7 @@ var PlaygroundService = class {
|
|
|
255402
255456
|
init_routed_trial();
|
|
255403
255457
|
import { createHash as createHash74 } from "node:crypto";
|
|
255404
255458
|
import { appendFileSync } from "node:fs";
|
|
255405
|
-
import { access as access11, mkdir as mkdir22, readFile as
|
|
255459
|
+
import { access as access11, mkdir as mkdir22, readFile as readFile30, writeFile as writeFile21 } from "node:fs/promises";
|
|
255406
255460
|
import { dirname as dirname20, join as join47, relative as relative15, resolve as resolve36 } from "node:path";
|
|
255407
255461
|
init_src();
|
|
255408
255462
|
init_run_state();
|
|
@@ -255487,7 +255541,7 @@ init_backend();
|
|
|
255487
255541
|
init_run_metadata();
|
|
255488
255542
|
init_src();
|
|
255489
255543
|
init_credentials();
|
|
255490
|
-
import { readFile as
|
|
255544
|
+
import { readFile as readFile22 } from "node:fs/promises";
|
|
255491
255545
|
import { basename as basename11, join as join38 } from "node:path";
|
|
255492
255546
|
|
|
255493
255547
|
// packages/cli/src/git-state.ts
|
|
@@ -255520,7 +255574,7 @@ async function uploadWorkspace(ctx, missing10 = { message: "--upload needs a wor
|
|
|
255520
255574
|
}
|
|
255521
255575
|
}
|
|
255522
255576
|
async function uploadRun(ctx, workspace4, run7) {
|
|
255523
|
-
const summary = JSON.parse(await
|
|
255577
|
+
const summary = JSON.parse(await readFile22(join38(run7.runDir, "summary.json"), "utf8").catch(() => "{}"));
|
|
255524
255578
|
if (summary.source === "pytest") throw new AnchaError("USAGE", "pytest run upload is not supported; records remain local");
|
|
255525
255579
|
const key5 = await apiKeyFor(workspace4, ctx.io.env);
|
|
255526
255580
|
if (key5 === void 0 && !isLoopbackUrl(workspace4)) throw authError(workspace4, { keySent: false });
|
|
@@ -256128,7 +256182,7 @@ async function connectOnCloud(ctx, ws, check4, signal) {
|
|
|
256128
256182
|
}
|
|
256129
256183
|
|
|
256130
256184
|
// packages/cli/src/commands/internal-cloud.ts
|
|
256131
|
-
import { readFile as
|
|
256185
|
+
import { readFile as readFile29, stat as stat10, writeFile as writeFile20 } from "node:fs/promises";
|
|
256132
256186
|
import { basename as basename13, join as join46, resolve as resolve35 } from "node:path";
|
|
256133
256187
|
init_src();
|
|
256134
256188
|
init_config();
|
|
@@ -256260,7 +256314,7 @@ function registerInternalCloud(program2, ctx) {
|
|
|
256260
256314
|
program2.command("_cloud-assemble", { hidden: true }).description("assemble a cloud run from its attempts' artifacts in the finalize machine").requiredOption("--input <file>", "the finalize input (FinalizeInput JSON)").requiredOption("--bundle <dir>", "the unpacked input bundle").requiredOption("--artifacts <dir>", "one folder per source attempt id with its unpacked artifact").requiredOption("--out <dir>", "where the run and its archive go").option("--relay <file>", "the workspace relay for model-graded checks ({ baseUrl, token, bootId }, written root-only by the runner)").action(async (opts) => {
|
|
256261
256315
|
let input5;
|
|
256262
256316
|
try {
|
|
256263
|
-
input5 = JSON.parse(await
|
|
256317
|
+
input5 = JSON.parse(await readFile29(resolve35(ctx.io.cwd, opts.input), "utf8"));
|
|
256264
256318
|
} catch (error65) {
|
|
256265
256319
|
throw new AnchaError("USAGE", `cannot read the finalize input ${opts.input}`, { hint: "pass the FinalizeInput JSON the runner wrote", cause: error65 });
|
|
256266
256320
|
}
|
|
@@ -256268,7 +256322,7 @@ function registerInternalCloud(program2, ctx) {
|
|
|
256268
256322
|
if (opts.relay !== void 0) {
|
|
256269
256323
|
let relay;
|
|
256270
256324
|
try {
|
|
256271
|
-
relay = JSON.parse(await
|
|
256325
|
+
relay = JSON.parse(await readFile29(resolve35(ctx.io.cwd, opts.relay), "utf8"));
|
|
256272
256326
|
} catch (error65) {
|
|
256273
256327
|
throw new AnchaError("USAGE", `cannot read the relay file ${opts.relay}`, { hint: "pass the relay JSON the runner wrote", cause: error65 });
|
|
256274
256328
|
}
|
|
@@ -256580,7 +256634,7 @@ async function claimIdempotencyKey(outDir, key5, definition3) {
|
|
|
256580
256634
|
} catch (error65) {
|
|
256581
256635
|
if (error65.code !== "EEXIST") throw error65;
|
|
256582
256636
|
}
|
|
256583
|
-
const previous = JSON.parse(await
|
|
256637
|
+
const previous = JSON.parse(await readFile30(path9, "utf8"));
|
|
256584
256638
|
if (previous.definition !== definition3) throw new AnchaError("USAGE", "this --idempotency-key was used for a different run", { hint: "use a new key for a new run; reuse a key only to retry the same command" });
|
|
256585
256639
|
if (previous.runId === void 0) throw new AnchaError("SESSION_CONFLICT", "a run with this --idempotency-key is still starting", { hint: "retry in a moment, or use a new key" });
|
|
256586
256640
|
return previous.runId;
|
|
@@ -256716,7 +256770,7 @@ async function definition2(ctx, path9) {
|
|
|
256716
256770
|
const info2 = await stat11(absolute2);
|
|
256717
256771
|
if (!info2.isFile()) throw new AnchaError("USAGE", "definition must be a file");
|
|
256718
256772
|
if (info2.size > 2e6) throw new AnchaError("USAGE", "definition file exceeds 2 MB");
|
|
256719
|
-
body8 = await
|
|
256773
|
+
body8 = await readFile31(absolute2, "utf8");
|
|
256720
256774
|
} catch (error65) {
|
|
256721
256775
|
if (["ENOENT", "EACCES"].includes(error65.code ?? "")) throw new AnchaError("USAGE", "definition file does not exist or cannot be read");
|
|
256722
256776
|
throw error65;
|
|
@@ -256917,7 +256971,7 @@ function modelEvidenceLine(probe, failed2 = false) {
|
|
|
256917
256971
|
}
|
|
256918
256972
|
|
|
256919
256973
|
// packages/cli/src/kit/doctor.ts
|
|
256920
|
-
import { mkdtemp as mkdtemp9, readFile as
|
|
256974
|
+
import { mkdtemp as mkdtemp9, readFile as readFile33, rm as rm11 } from "node:fs/promises";
|
|
256921
256975
|
import { tmpdir as tmpdir8 } from "node:os";
|
|
256922
256976
|
import { join as join49, relative as relative17, resolve as resolve38 } from "node:path";
|
|
256923
256977
|
var import_yaml9 = __toESM(require_dist(), 1);
|
|
@@ -256932,7 +256986,7 @@ init_scenes();
|
|
|
256932
256986
|
init_detect();
|
|
256933
256987
|
init_run();
|
|
256934
256988
|
import { randomUUID as randomUUID16 } from "node:crypto";
|
|
256935
|
-
import { access as access12, mkdtemp as mkdtemp8, readFile as
|
|
256989
|
+
import { access as access12, mkdtemp as mkdtemp8, readFile as readFile32, rm as rm10, writeFile as writeFile22 } from "node:fs/promises";
|
|
256936
256990
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
256937
256991
|
import { join as join48, relative as relative16 } from "node:path";
|
|
256938
256992
|
var messages3 = {
|
|
@@ -256994,7 +257048,7 @@ async function doctorRecords(opts) {
|
|
|
256994
257048
|
if (!groups.has(key5)) groups.set(key5, { ...item2, ...records6 !== void 0 && { records: records6 } });
|
|
256995
257049
|
}
|
|
256996
257050
|
for (const item2 of groups.values()) {
|
|
256997
|
-
const inputRecords = item2.records ? (await
|
|
257051
|
+
const inputRecords = item2.records ? (await readFile32(item2.records, "utf8")).split(/\r?\n/).filter((line2) => line2.trim()).length : 0;
|
|
256998
257052
|
if (!item2.records) await writeFile22(join48(directory, "records.jsonl"), "");
|
|
256999
257053
|
const scene2 = {
|
|
257000
257054
|
id: item2.scene.id,
|
|
@@ -257048,6 +257102,7 @@ async function doctorRecords(opts) {
|
|
|
257048
257102
|
|
|
257049
257103
|
// packages/cli/src/kit/doctor.ts
|
|
257050
257104
|
init_task_input();
|
|
257105
|
+
init_agent_fix();
|
|
257051
257106
|
function functionToolsDoctor(scene2, state3, trace2) {
|
|
257052
257107
|
const projection2 = functionToolObservationSchema.safeParse(state3?.tools?.observation);
|
|
257053
257108
|
const required6 = projection2.success ? projection2.data.required : [.../* @__PURE__ */ new Set([...requiredFunctionTools(scene2), ...Object.entries(scene2.tools ?? {}).filter(([, t]) => !t.mcp && (!t.pure || t.twin !== void 0) && !t.allow_unwrapped).map(([name5]) => name5)])];
|
|
@@ -257109,9 +257164,23 @@ async function taskCheck(ctx, agent) {
|
|
|
257109
257164
|
hint: "or run ancha init, which adds it"
|
|
257110
257165
|
};
|
|
257111
257166
|
}
|
|
257112
|
-
|
|
257167
|
+
var ENV_FILES = [".env", ".env.local", ".env.example", ".env.sample", ".env.template"];
|
|
257168
|
+
async function envFileKeys(dirs) {
|
|
257169
|
+
const found = [];
|
|
257170
|
+
for (const dir2 of [...new Set(dirs)]) for (const file3 of ENV_FILES) {
|
|
257171
|
+
const text31 = await readFile33(join49(dir2, file3), "utf8").catch(() => "");
|
|
257172
|
+
const names8 = [...new Set([...text31.matchAll(/^[ \t]*(?:export[ \t]+)?([A-Z][A-Z0-9_]*)[ \t]*=/gm)].map((match3) => match3[1]))].filter((name5) => /(?:_KEY|_TOKEN|_SECRET|_PASSWORD)$/.test(name5) && !name5.startsWith("ANCHA_") && !givenByTwins(name5));
|
|
257173
|
+
if (names8.length && !found.some((entry3) => entry3.file === file3)) found.push({ file: file3, names: names8 });
|
|
257174
|
+
}
|
|
257175
|
+
return found;
|
|
257176
|
+
}
|
|
257177
|
+
async function uploadSecrets(ws, names8, fromEnv = []) {
|
|
257113
257178
|
const wanted = [...new Set(names8)];
|
|
257114
|
-
|
|
257179
|
+
const files2 = fromEnv.filter((entry3) => entry3.names.some((name5) => !wanted.includes(name5)));
|
|
257180
|
+
const unpassed = [...new Set(files2.flatMap((entry3) => entry3.names))].filter((name5) => !wanted.includes(name5));
|
|
257181
|
+
const envLine = unpassed.length ? `${files2.map((entry3) => entry3.file).join(" and ")} ${files2.length === 1 ? "names" : "name"} ${unpassed.join(", ")}, which the agent does not get in the cloud` : void 0;
|
|
257182
|
+
const envFix = unpassed.length ? `ancha secrets set ${unpassed.join(" ")}` : void 0;
|
|
257183
|
+
if (!wanted.length) return envLine ? { name: "secrets", status: "warning", message: envLine, fix: envFix } : { name: "secrets", status: "pass", message: "the agent passes no workspace secrets" };
|
|
257115
257184
|
const saved = await getSecrets(ws), missing10 = wanted.filter((name5) => !saved.names.includes(name5));
|
|
257116
257185
|
if (missing10.length) throw new AnchaError("CONFIG_INVALID", `Workspace secrets are missing: ${missing10.join(", ")}. The project has not been bundled.`, { hint: missing10.map((name5) => `ancha secrets set ${name5}`).join("\n") });
|
|
257117
257186
|
let warning = false;
|
|
@@ -257122,7 +257191,12 @@ async function uploadSecrets(ws, names8) {
|
|
|
257122
257191
|
if (notes7.length) warning = true;
|
|
257123
257192
|
return [`${name5}${secret?.preview ? ` \xB7 ${secret.preview}` : ""} \xB7 ${status6}`, ...notes7.map((issue9) => ` ${issue9.message}${issue9.fix ? ` ${issue9.fix}` : ""}`)];
|
|
257124
257193
|
});
|
|
257125
|
-
return {
|
|
257194
|
+
return {
|
|
257195
|
+
name: "secrets",
|
|
257196
|
+
status: warning || envLine ? "warning" : "pass",
|
|
257197
|
+
message: `${wanted.length} workspace secret${wanted.length === 1 ? "" : "s"} saved`,
|
|
257198
|
+
details: envLine ? [...details, `${envLine}: ${envFix}`] : details
|
|
257199
|
+
};
|
|
257126
257200
|
}
|
|
257127
257201
|
async function uploadAgent(ctx, opts, command = "ancha agent upload") {
|
|
257128
257202
|
if (opts.agent === false) throw new AnchaError("USAGE", `${command} checks the agent in a cloud machine`, { hint: "leave out --no-agent" });
|
|
@@ -257130,7 +257204,8 @@ async function uploadAgent(ctx, opts, command = "ancha agent upload") {
|
|
|
257130
257204
|
const refusal4 = cloudAgentRefusal(config12, typeof opts.agent === "string" ? opts.agent : void 0);
|
|
257131
257205
|
if (refusal4) throw refusal4;
|
|
257132
257206
|
const ws = await cloudWorkspace(ctx, { code: "USAGE", message: `${command === "ancha agent upload" ? "agent upload" : "--on cloud"} needs a workspace`, hint: "run ancha login, or set ANCHA_SERVER_URL and ANCHA_API_KEY" });
|
|
257133
|
-
const
|
|
257207
|
+
const cwd = ctx.io?.cwd, fromEnv = cwd === void 0 ? [] : await envFileKeys([cwd, resolve38(cwd, config12.agent?.cwd ?? ".")]);
|
|
257208
|
+
const secrets2 = await uploadSecrets(ws, [...config12.agent?.passEnv ?? [], ...config12.agent?.execution?.mode === "container" ? config12.agent.execution.env : []], fromEnv);
|
|
257134
257209
|
const configured = config12.agent?.mode === "endpoint" ? void 0 : config12.agent;
|
|
257135
257210
|
const task2 = await taskCheck(ctx, typeof opts.agent === "string" ? { command: opts.agent, ...configured?.env && { env: configured.env } } : configured);
|
|
257136
257211
|
if (task2?.status === "warning") ctx.out.info(`${task2.message}: ${task2.fix} (${task2.hint})`);
|
|
@@ -257195,13 +257270,14 @@ function connectionReport(detail3, logTail3, readsAnswer = false) {
|
|
|
257195
257270
|
const said = (evidence3.message ?? "The agent could not be started.").replace(/\.$/, "");
|
|
257196
257271
|
const how = parsedTextTask ? ran.reason.message.replace(/^The agent /, "it ") : /(?:ModuleNotFoundError|ImportError):/.test(said) ? said : ran.exitCode !== null && ran.exitCode !== 0 ? `it exited with code ${ran.exitCode} after ${elapsed(ran.durationMs)} ${before(ran.calls?.total)}` : said.startsWith("The agent stopped on a signal") ? `it stopped on a signal after ${elapsed(ran.durationMs)} ${before(ran.calls?.total)}` : said.replace(/^The agent /, "it ").replace(/^The /, "the ");
|
|
257197
257272
|
const tail = ran.logTail?.length ? ran.logTail : logTail3;
|
|
257273
|
+
const fallback = ran.calls?.total ? `${tail.length > 0 ? "the end of its log is above; " : ""}it stopped after its tool calls answered, in its own code` : `${tail.length > 0 ? "the end of its log is above: " : ""}fix what it names, then run ancha agent upload again`;
|
|
257198
257274
|
checks2.push({
|
|
257199
257275
|
name: "agent",
|
|
257200
257276
|
status: "fail",
|
|
257201
257277
|
message: how,
|
|
257202
257278
|
...tail.length > 0 && { logTail: tail },
|
|
257203
257279
|
...fix !== void 0 && { fix },
|
|
257204
|
-
...fix === void 0 && { hint: `${tail.length > 0 ? "the end of its log is above; " : ""}${ran.reason
|
|
257280
|
+
...fix === void 0 && { hint: ran.reason?.fix ? `${tail.length > 0 ? "the end of its log is above; " : ""}${ran.reason.fix}` : fallback }
|
|
257205
257281
|
});
|
|
257206
257282
|
} else {
|
|
257207
257283
|
const attempt2 = detail3.attempts.find((item2) => item2.error !== null);
|
|
@@ -257246,7 +257322,7 @@ async function testsReadAnswer(cwd, scenes) {
|
|
|
257246
257322
|
for (const path9 of paths3.slice(0, 1e3)) {
|
|
257247
257323
|
let doc;
|
|
257248
257324
|
try {
|
|
257249
|
-
doc = (0, import_yaml9.parse)(await
|
|
257325
|
+
doc = (0, import_yaml9.parse)(await readFile33(path9, "utf8"));
|
|
257250
257326
|
} catch {
|
|
257251
257327
|
continue;
|
|
257252
257328
|
}
|
|
@@ -257379,7 +257455,7 @@ async function doctor(ctx, opts) {
|
|
|
257379
257455
|
const reached = accesses.some((entry3) => !entry3.gap && entry3.status !== void 0 && entry3.status >= 200 && entry3.status < 400 && !(typeof entry3.response === "object" && entry3.response !== null && "ok" in entry3.response && entry3.response.ok === false));
|
|
257380
257456
|
add({ name: `native:${twin}`, status: reached ? "pass" : "warning", message: reached ? `Observed a successful native ${twin} API request from the configured agent` : `Successful native ${twin} API access was not observed`, ...!reached && { hint: `configure the native SDK using ancha connect ${twin}; health and process exit do not prove agent access` } });
|
|
257381
257457
|
}
|
|
257382
|
-
const toolState = await
|
|
257458
|
+
const toolState = await readFile33(join49(trial.dir, "state.json"), "utf8").then((text31) => JSON.parse(text31), () => void 0);
|
|
257383
257459
|
const toolCheck = functionToolsDoctor(scene2, toolState, trial.trace);
|
|
257384
257460
|
if (toolCheck) {
|
|
257385
257461
|
add(toolCheck);
|
|
@@ -257537,7 +257613,7 @@ init_run_bundle();
|
|
|
257537
257613
|
// packages/cli/src/commands/login.ts
|
|
257538
257614
|
init_src();
|
|
257539
257615
|
import { spawn as spawn5 } from "node:child_process";
|
|
257540
|
-
import { chmod as chmod7, mkdir as mkdir23, readFile as
|
|
257616
|
+
import { chmod as chmod7, mkdir as mkdir23, readFile as readFile34, rm as rm12, writeFile as writeFile23 } from "node:fs/promises";
|
|
257541
257617
|
import { hostname as hostname5 } from "node:os";
|
|
257542
257618
|
import { dirname as dirname21 } from "node:path";
|
|
257543
257619
|
init_credentials();
|
|
@@ -257638,7 +257714,7 @@ async function readPending(env2, server) {
|
|
|
257638
257714
|
const path9 = pendingPath(env2);
|
|
257639
257715
|
if (!path9) return null;
|
|
257640
257716
|
try {
|
|
257641
|
-
const p2 = JSON.parse(await
|
|
257717
|
+
const p2 = JSON.parse(await readFile34(path9, "utf8"));
|
|
257642
257718
|
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;
|
|
257643
257719
|
return p2;
|
|
257644
257720
|
} catch {
|
|
@@ -257662,7 +257738,7 @@ async function dropPending(env2, deviceCode) {
|
|
|
257662
257738
|
const path9 = pendingPath(env2);
|
|
257663
257739
|
if (!path9) return;
|
|
257664
257740
|
try {
|
|
257665
|
-
if (JSON.parse(await
|
|
257741
|
+
if (JSON.parse(await readFile34(path9, "utf8")).deviceCode === deviceCode) await rm12(path9, { force: true });
|
|
257666
257742
|
} catch {
|
|
257667
257743
|
}
|
|
257668
257744
|
}
|
|
@@ -257823,11 +257899,11 @@ ${worlds2 === "local" ? loginRunLine(ctx) : "This server override keeps the agen
|
|
|
257823
257899
|
// packages/cli/src/kit/trace-connection.ts
|
|
257824
257900
|
var import_yaml10 = __toESM(require_dist(), 1);
|
|
257825
257901
|
init_src();
|
|
257826
|
-
import { readFile as
|
|
257902
|
+
import { readFile as readFile35 } from "node:fs/promises";
|
|
257827
257903
|
import { relative as relative18 } from "node:path";
|
|
257828
257904
|
init_detect();
|
|
257829
257905
|
async function traceConnection(cwd, paths3, configured, target6, recordsAdapter, cloud = false) {
|
|
257830
|
-
const scenes = await Promise.all(paths3.map(async (path9) => ({ path: relative18(cwd, path9), scene: (0, import_yaml10.parse)(await
|
|
257906
|
+
const scenes = await Promise.all(paths3.map(async (path9) => ({ path: relative18(cwd, path9), scene: (0, import_yaml10.parse)(await readFile35(path9, "utf8")) })));
|
|
257831
257907
|
const tools2 = [...new Set(scenes.flatMap(({ scene: scene2 }) => (scene2.twins ?? []).filter((name5) => !(name5 === "slack" && scene2.agent_input === "per_event" && scene2.people?.length))))].map((name5) => ({
|
|
257832
257908
|
name: name5,
|
|
257833
257909
|
env: connectionGuide(name5, "ts").env,
|
|
@@ -257900,8 +257976,8 @@ async function toolAnswers(runDir, summary, filter4) {
|
|
|
257900
257976
|
const out = [];
|
|
257901
257977
|
for (const scene2 of summary.scenes) for (const { trial } of scene2.trialsDetail) {
|
|
257902
257978
|
if (filter4.scene !== void 0 && filter4.scene !== scene2.sceneId || filter4.trial !== void 0 && filter4.trial !== trial) continue;
|
|
257903
|
-
const text31 = await
|
|
257904
|
-
const state3 = await
|
|
257979
|
+
const text31 = await readFile36(join50(runDir, `trial-${scene2.sceneId}-${trial}`, "trace.jsonl"), "utf8").catch(() => "");
|
|
257980
|
+
const state3 = await readFile36(join50(runDir, `trial-${scene2.sceneId}-${trial}`, "state.json"), "utf8").then(JSON.parse).catch(() => void 0);
|
|
257905
257981
|
const trace2 = text31.split("\n").filter(Boolean).map((line2) => JSON.parse(line2));
|
|
257906
257982
|
const functionTools = projectFunctionTools(trace2, state3);
|
|
257907
257983
|
const logical = new Map(functionTools.calls.map((c) => [c.seq, c]));
|
|
@@ -257939,7 +258015,7 @@ function invalidSetupNext(summary, out, readDirectory) {
|
|
|
257939
258015
|
})];
|
|
257940
258016
|
}
|
|
257941
258017
|
async function trialOutcomes(runDir, summary, filter4) {
|
|
257942
|
-
const inputs2 = await
|
|
258018
|
+
const inputs2 = await readFile36(join50(runDir, "inputs.json"), "utf8").then((text31) => JSON.parse(text31), () => ({ cases: [] }));
|
|
257943
258019
|
const out = [];
|
|
257944
258020
|
for (const scene2 of summary.scenes) {
|
|
257945
258021
|
if (filter4.scene !== void 0 && filter4.scene !== scene2.sceneId) continue;
|
|
@@ -257948,15 +258024,15 @@ async function trialOutcomes(runDir, summary, filter4) {
|
|
|
257948
258024
|
for (const detail3 of scene2.trialsDetail) {
|
|
257949
258025
|
if (detail3.passed || detail3.outcome === "skipped" || detail3.outcome === "xfailed" || filter4.trial !== void 0 && filter4.trial !== detail3.trial) continue;
|
|
257950
258026
|
const dir2 = join50(runDir, `trial-${scene2.sceneId}-${detail3.trial}`);
|
|
257951
|
-
const trace2 = (await
|
|
258027
|
+
const trace2 = (await readFile36(join50(dir2, "trace.jsonl"), "utf8").catch(() => "")).split("\n").filter(Boolean).flatMap((line2) => {
|
|
257952
258028
|
try {
|
|
257953
258029
|
return [JSON.parse(line2)];
|
|
257954
258030
|
} catch {
|
|
257955
258031
|
return [];
|
|
257956
258032
|
}
|
|
257957
258033
|
});
|
|
257958
|
-
const result = await
|
|
257959
|
-
const log3 = (await
|
|
258034
|
+
const result = await readFile36(join50(dir2, "result.json"), "utf8").then((text31) => JSON.parse(text31), () => ({}));
|
|
258035
|
+
const log3 = (await readFile36(join50(dir2, "agent.log"), "utf8").catch(() => "")).slice(-1e6);
|
|
257960
258036
|
const { reason: reason2, calls: calls2 } = attemptOutcome(
|
|
257961
258037
|
{ exit: detail3.exit, exitCode: detail3.exitCode, realMs: detail3.realMs, trace: trace2, log: log3, ...result.logTail && { logTail: result.logTail }, modelReplies: result.modelReplies, sessionRefusals: result.sessionRefusals },
|
|
257962
258038
|
{ check: "test", answerChecked, target: "local" }
|
|
@@ -258167,7 +258243,7 @@ function registerExplain(program2, ctx) {
|
|
|
258167
258243
|
const outcomes = await trialOutcomes(join50(resolve39(ctx.io.cwd, opts.out ?? DEFAULT_RUNS_DIR), summary.runId), summary, filter4);
|
|
258168
258244
|
const out = opts.out === void 0 ? "" : ` --out ${shellArgument(opts.out)}`;
|
|
258169
258245
|
const baselinePath = join50(resolve39(ctx.io.cwd, opts.out ?? DEFAULT_RUNS_DIR), "..", "baselines", "before.json");
|
|
258170
|
-
const baselineText = await
|
|
258246
|
+
const baselineText = await readFile36(baselinePath, "utf8").catch(() => void 0);
|
|
258171
258247
|
const baseline = baselineText === void 0 ? void 0 : (() => {
|
|
258172
258248
|
try {
|
|
258173
258249
|
return normalizeSummary(JSON.parse(baselineText));
|
|
@@ -258242,7 +258318,7 @@ init_src();
|
|
|
258242
258318
|
init_report2();
|
|
258243
258319
|
init_run();
|
|
258244
258320
|
init_run_inputs();
|
|
258245
|
-
import { readdir as readdir9, readFile as
|
|
258321
|
+
import { readdir as readdir9, readFile as readFile37 } from "node:fs/promises";
|
|
258246
258322
|
import { join as join51, resolve as resolve40 } from "node:path";
|
|
258247
258323
|
var RUN_ID2 = /^[A-Za-z0-9_][\w.-]*$/;
|
|
258248
258324
|
var TRIAL_DIR = /^trial-[a-z0-9][a-z0-9_-]*-[1-9]\d*$/;
|
|
@@ -258268,7 +258344,7 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
258268
258344
|
const trialDir = ref23.slice(slash + 1);
|
|
258269
258345
|
if (runId2 === "latest") {
|
|
258270
258346
|
try {
|
|
258271
|
-
runId2 = (await
|
|
258347
|
+
runId2 = (await readFile37(join51(runs, "latest"), "utf8")).trim();
|
|
258272
258348
|
} catch (error65) {
|
|
258273
258349
|
if (missing9(error65)) throw new AnchaError("USAGE", `no runs found in ${out ?? DEFAULT_RUNS_DIR}`, { hint: "run `ancha run` first", cause: error65 });
|
|
258274
258350
|
throw error65;
|
|
@@ -258278,10 +258354,10 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
258278
258354
|
const runDir = join51(runs, runId2);
|
|
258279
258355
|
let inputs2;
|
|
258280
258356
|
try {
|
|
258281
|
-
inputs2 = JSON.parse(await
|
|
258357
|
+
inputs2 = JSON.parse(await readFile37(join51(runDir, "inputs.json"), "utf8"));
|
|
258282
258358
|
} catch (error65) {
|
|
258283
258359
|
if (!missing9(error65)) throw error65;
|
|
258284
|
-
const left = await
|
|
258360
|
+
const left = await readFile37(join51(runDir, "bundle.json"), "utf8").then((text31) => JSON.parse(text31).omitted?.find((item2) => item2.path === "inputs.json")).catch(() => void 0);
|
|
258285
258361
|
const mb = (bytes4) => `${(bytes4 / (1024 * 1024)).toFixed(1)} MB`;
|
|
258286
258362
|
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 });
|
|
258287
258363
|
throw new AnchaError("USAGE", `unknown run ${JSON.stringify(runId2)}`, { hint: `see ${out ?? DEFAULT_RUNS_DIR}/`, cause: error65 });
|
|
@@ -258295,7 +258371,7 @@ async function loadReplayAttempt(cwd, ref23, out) {
|
|
|
258295
258371
|
const dir2 = join51(runDir, trialDir);
|
|
258296
258372
|
const read7 = async (name5, optional2 = false) => {
|
|
258297
258373
|
try {
|
|
258298
|
-
return await
|
|
258374
|
+
return await readFile37(join51(dir2, name5), "utf8");
|
|
258299
258375
|
} catch (error65) {
|
|
258300
258376
|
if (missing9(error65) && optional2) return "";
|
|
258301
258377
|
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 });
|
|
@@ -258332,7 +258408,7 @@ async function replayAttempt(attempt2, opts) {
|
|
|
258332
258408
|
...opts.onEvent !== void 0 && { onEvent: opts.onEvent }
|
|
258333
258409
|
});
|
|
258334
258410
|
const trial = run7.results.get(attempt2.caseId).trials[0];
|
|
258335
|
-
const people4 = JSON.parse(await
|
|
258411
|
+
const people4 = JSON.parse(await readFile37(join51(trial.dir, "people-replay.json"), "utf8").catch(() => "null")) ?? { replayed: 0, live: 0, divergence: null };
|
|
258336
258412
|
const recorded2 = new Map(attempt2.checks.map((check4) => [check4.id, check4.passed]));
|
|
258337
258413
|
return {
|
|
258338
258414
|
replayOf: attempt2.id,
|
|
@@ -258479,7 +258555,7 @@ init_src();
|
|
|
258479
258555
|
init_report2();
|
|
258480
258556
|
init_run_store();
|
|
258481
258557
|
init_run_state();
|
|
258482
|
-
import { readFile as
|
|
258558
|
+
import { readFile as readFile38 } from "node:fs/promises";
|
|
258483
258559
|
import { join as join53, resolve as resolve42 } from "node:path";
|
|
258484
258560
|
import { setTimeout as sleep13 } from "node:timers/promises";
|
|
258485
258561
|
function registerStatus(program2, ctx) {
|
|
@@ -258560,7 +258636,7 @@ hint: ${state3.upload.error.hint}` : ""}`);
|
|
|
258560
258636
|
let printed = 0;
|
|
258561
258637
|
for (; ; ) {
|
|
258562
258638
|
const state3 = await readRunState(outDir, id15);
|
|
258563
|
-
const lines2 = (await
|
|
258639
|
+
const lines2 = (await readFile38(log3, "utf8").catch(() => "")).split("\n");
|
|
258564
258640
|
if (!terminal(state3)) lines2.pop();
|
|
258565
258641
|
const complete = lines2.filter(Boolean);
|
|
258566
258642
|
for (const line2 of complete.slice(printed)) ctx.out.event(JSON.parse(line2));
|
|
@@ -258586,7 +258662,7 @@ init_src();
|
|
|
258586
258662
|
// packages/cli/src/commands/simulate.ts
|
|
258587
258663
|
init_src();
|
|
258588
258664
|
init_backend();
|
|
258589
|
-
import { readFile as
|
|
258665
|
+
import { readFile as readFile39 } from "node:fs/promises";
|
|
258590
258666
|
import { dirname as dirname22, join as join55, resolve as resolve43 } from "node:path";
|
|
258591
258667
|
init_config();
|
|
258592
258668
|
init_report2();
|
|
@@ -258707,7 +258783,7 @@ function registerSimulate(sceneCommand, ctx) {
|
|
|
258707
258783
|
timeline: trial.trace,
|
|
258708
258784
|
checks: trial.checks,
|
|
258709
258785
|
harnessIssues: trial.harnessIssues,
|
|
258710
|
-
state: JSON.parse(await
|
|
258786
|
+
state: JSON.parse(await readFile39(join55(trial.dir, "state.json"), "utf8")),
|
|
258711
258787
|
runId: run7.runId,
|
|
258712
258788
|
dir: trial.dir
|
|
258713
258789
|
};
|
|
@@ -258726,7 +258802,7 @@ init_scenes();
|
|
|
258726
258802
|
|
|
258727
258803
|
// packages/cli/src/kit/init.ts
|
|
258728
258804
|
import { constants as constants12 } from "node:fs";
|
|
258729
|
-
import { lstat as lstat10, mkdir as mkdir26, open as fsOpen, readFile as
|
|
258805
|
+
import { lstat as lstat10, mkdir as mkdir26, open as fsOpen, readFile as readFile44, rm as rm13, writeFile as fsWriteFile } from "node:fs/promises";
|
|
258730
258806
|
import { join as join58 } from "node:path";
|
|
258731
258807
|
import { Writable } from "node:stream";
|
|
258732
258808
|
var import_yaml18 = __toESM(require_dist(), 1);
|
|
@@ -260019,10 +260095,10 @@ function netsuiteData(size2, options5 = {}) {
|
|
|
260019
260095
|
// backend/src/kit/quickbooks-examples.ts
|
|
260020
260096
|
var import_yaml14 = __toESM(require_dist(), 1);
|
|
260021
260097
|
init_assets();
|
|
260022
|
-
import { readFile as
|
|
260098
|
+
import { readFile as readFile40 } from "node:fs/promises";
|
|
260023
260099
|
var QUICKBOOKS_EXAMPLES = { world: "pellmont-building-services", tests: ["pellmont-duplicates", "pellmont-approved-merge"] };
|
|
260024
260100
|
async function quickbooksExamples() {
|
|
260025
|
-
const read7 = (name5) =>
|
|
260101
|
+
const read7 = (name5) => readFile40(new URL(`data/pellmont/${name5}.yaml`, assetRoot()), "utf8");
|
|
260026
260102
|
const world5 = `ancha/worlds/${QUICKBOOKS_EXAMPLES.world}.yaml`;
|
|
260027
260103
|
const tests = await Promise.all(QUICKBOOKS_EXAMPLES.tests.map(async (id15) => {
|
|
260028
260104
|
const content2 = await read7(id15);
|
|
@@ -260049,7 +260125,7 @@ var import_yaml15 = __toESM(require_dist(), 1);
|
|
|
260049
260125
|
init_src();
|
|
260050
260126
|
import { createHash as createHash76 } from "node:crypto";
|
|
260051
260127
|
import { existsSync as existsSync2 } from "node:fs";
|
|
260052
|
-
import { mkdir as mkdir24, readFile as
|
|
260128
|
+
import { mkdir as mkdir24, readFile as readFile41, writeFile as writeFile25 } from "node:fs/promises";
|
|
260053
260129
|
import { dirname as dirname23, join as join56, relative as relative20, resolve as resolve45 } from "node:path";
|
|
260054
260130
|
async function model(ctx) {
|
|
260055
260131
|
const env2 = ctx.io.env;
|
|
@@ -260119,11 +260195,11 @@ async function worldGen(ctx, description2, options5) {
|
|
|
260119
260195
|
const request2 = { description: description2, id: options5.id ?? null, tools: tools2 ?? null, size: size2, variants, from: options5.from ?? null };
|
|
260120
260196
|
const keyFile = options5.idempotencyKey === void 0 ? void 0 : join56(ctx.io.cwd, ".ancha", "world-gen", `${createHash76("sha256").update(options5.idempotencyKey).digest("hex").slice(0, 32)}.json`);
|
|
260121
260197
|
if (keyFile && existsSync2(keyFile)) {
|
|
260122
|
-
const saved = JSON.parse(await
|
|
260198
|
+
const saved = JSON.parse(await readFile41(keyFile, "utf8"));
|
|
260123
260199
|
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" });
|
|
260124
260200
|
if (saved.result.files.every((file3) => existsSync2(resolve45(ctx.io.cwd, file3)))) return report5(ctx, { ...saved.result, reused: true });
|
|
260125
260201
|
}
|
|
260126
|
-
const from = options5.from === void 0 ? void 0 : parseWorldFile((0, import_yaml15.parse)(await
|
|
260202
|
+
const from = options5.from === void 0 ? void 0 : parseWorldFile((0, import_yaml15.parse)(await readFile41(resolve45(ctx.io.cwd, options5.from), "utf8")));
|
|
260127
260203
|
if (options5.id && !options5.force && existsSync2(join56(outDir, `${options5.id}.yaml`))) throw exists4(join56(outDir, `${options5.id}.yaml`), ctx);
|
|
260128
260204
|
const { client: client2, credit } = await model(ctx);
|
|
260129
260205
|
ctx.out.info(`generating a world from the description (size ${size2}${variants ? `, ${variants} variant${variants === 1 ? "" : "s"}` : ""})`);
|
|
@@ -260183,7 +260259,7 @@ function report5(ctx, result) {
|
|
|
260183
260259
|
var import_yaml17 = __toESM(require_dist(), 1);
|
|
260184
260260
|
import { createHash as createHash78 } from "node:crypto";
|
|
260185
260261
|
import { existsSync as existsSync3 } from "node:fs";
|
|
260186
|
-
import { mkdir as mkdir25, readFile as
|
|
260262
|
+
import { mkdir as mkdir25, readFile as readFile42, readdir as readdir10, writeFile as writeFile26 } from "node:fs/promises";
|
|
260187
260263
|
import { join as join57, relative as relative21, resolve as resolve46 } from "node:path";
|
|
260188
260264
|
init_src();
|
|
260189
260265
|
|
|
@@ -260593,7 +260669,7 @@ async function chooseWorld(ctx, id15, command = 'ancha test new "<sentence>"') {
|
|
|
260593
260669
|
const path9 = join57(dir2, `${chosen}.yaml`);
|
|
260594
260670
|
if (!existsSync3(path9)) throw new AnchaError("USAGE", `no world ${chosen} in ancha/worlds`, { hint: ids3.length ? `worlds: ${ids3.join(", ")}` : noWorldHint });
|
|
260595
260671
|
try {
|
|
260596
|
-
return parseWorldFile((0, import_yaml17.parse)(await
|
|
260672
|
+
return parseWorldFile((0, import_yaml17.parse)(await readFile42(path9, "utf8")));
|
|
260597
260673
|
} catch (error65) {
|
|
260598
260674
|
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" });
|
|
260599
260675
|
}
|
|
@@ -260628,7 +260704,7 @@ async function testNew(ctx, intent, options5) {
|
|
|
260628
260704
|
const request2 = { intent, world: world5.id, id: options5.id ?? null, out: relative21(ctx.io.cwd, outDir) };
|
|
260629
260705
|
const keyFile = options5.idempotencyKey === void 0 ? void 0 : join57(ctx.io.cwd, ".ancha", "test-new", `${createHash78("sha256").update(options5.idempotencyKey).digest("hex").slice(0, 32)}.json`);
|
|
260630
260706
|
if (keyFile && existsSync3(keyFile)) {
|
|
260631
|
-
const saved = JSON.parse(await
|
|
260707
|
+
const saved = JSON.parse(await readFile42(keyFile, "utf8"));
|
|
260632
260708
|
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" });
|
|
260633
260709
|
if ([saved.result.file, saved.result.record].every((file4) => existsSync3(resolve46(ctx.io.cwd, file4)))) return report6(ctx, { ...saved.result, reused: true });
|
|
260634
260710
|
}
|
|
@@ -260638,7 +260714,7 @@ async function testNew(ctx, intent, options5) {
|
|
|
260638
260714
|
const draft2 = await draftTest({ intent, world: world5, model: client2, ...options5.id && { id: options5.id }, onProgress: (line2) => ctx.out.info(` ${line2}`) });
|
|
260639
260715
|
const path9 = join57(outDir, `${draft2.test.id}.yaml`), recordPath = join57(outDir, `${draft2.test.id}.gen.json`);
|
|
260640
260716
|
if (existsSync3(path9) && !options5.force) throw exists5(ctx, path9);
|
|
260641
|
-
const before2 = existsSync3(path9) ? await
|
|
260717
|
+
const before2 = existsSync3(path9) ? await readFile42(path9, "utf8") : "";
|
|
260642
260718
|
const at6 = (/* @__PURE__ */ new Date()).toISOString();
|
|
260643
260719
|
const yaml = testYaml2({ ...draft2.test, generated: { by: "ancha test new", at: at6, from: intent, record: `${draft2.test.id}.gen.json` } }, intent);
|
|
260644
260720
|
const cost = Math.round(draft2.calls.reduce((sum6, call4) => sum6 + call4.costUsd, 0) * 1e6) / 1e6;
|
|
@@ -260711,11 +260787,11 @@ init_scenes();
|
|
|
260711
260787
|
// packages/cli/src/kit/docs.ts
|
|
260712
260788
|
init_src();
|
|
260713
260789
|
init_assets();
|
|
260714
|
-
import { readFile as
|
|
260790
|
+
import { readFile as readFile43 } from "node:fs/promises";
|
|
260715
260791
|
var DOC_TOPICS = ["setup", "apps", "run", "traces", "explain", "compare", "tests", "scenes", "integrations", "cloud", "playgrounds", "cli-quickstart", "tools", "datasets", "company"];
|
|
260716
260792
|
async function loadDoc(topic = "setup") {
|
|
260717
260793
|
if (!DOC_TOPICS.includes(topic)) throw new AnchaError("USAGE", `unknown docs topic: ${topic}`, { hint: `available topics: ${DOC_TOPICS.join(", ")}` });
|
|
260718
|
-
return { topics: [...DOC_TOPICS], topic, markdown: await
|
|
260794
|
+
return { topics: [...DOC_TOPICS], topic, markdown: await readFile43(new URL(`docs/${topic === "tests" ? "scenes" : topic}.md`, assetRoot()), "utf8") };
|
|
260719
260795
|
}
|
|
260720
260796
|
function registerDocs(program2, ctx) {
|
|
260721
260797
|
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) => {
|
|
@@ -260760,7 +260836,7 @@ function step2(ctx) {
|
|
|
260760
260836
|
}
|
|
260761
260837
|
var BEGIN = "<!-- ancha:begin -->";
|
|
260762
260838
|
var END = "<!-- ancha:end -->";
|
|
260763
|
-
var managedSection = () =>
|
|
260839
|
+
var managedSection = () => readFile44(new URL("agents-section.md", assetRoot()), "utf8");
|
|
260764
260840
|
async function installAgents(cwd, tools2) {
|
|
260765
260841
|
const target6 = join58(cwd, "AGENTS.md");
|
|
260766
260842
|
const base6 = await managedSection();
|
|
@@ -260773,7 +260849,7 @@ Read \`ancha docs tools\` for function checks and registration.
|
|
|
260773
260849
|
const managed = base6.replace(END, wiring + END);
|
|
260774
260850
|
let original2;
|
|
260775
260851
|
try {
|
|
260776
|
-
original2 = await
|
|
260852
|
+
original2 = await readFile44(target6, "utf8");
|
|
260777
260853
|
} catch (error65) {
|
|
260778
260854
|
if (error65.code !== "ENOENT") throw error65;
|
|
260779
260855
|
const result = await applyScaffold2(cwd, [{ relativePath: "AGENTS.md", content: managed }]);
|
|
@@ -260802,7 +260878,7 @@ async function ignoreAnchaDirectory(cwd) {
|
|
|
260802
260878
|
const target6 = join58(cwd, ".gitignore");
|
|
260803
260879
|
let original2;
|
|
260804
260880
|
try {
|
|
260805
|
-
original2 = await
|
|
260881
|
+
original2 = await readFile44(target6, "utf8");
|
|
260806
260882
|
} catch (error65) {
|
|
260807
260883
|
if (error65.code !== "ENOENT") throw error65;
|
|
260808
260884
|
const result = await applyScaffold2(cwd, [{ relativePath: ".gitignore", content: ".ancha/\n" }]);
|
|
@@ -260886,7 +260962,7 @@ ${twins.map((twin) => (routed.includes(twin) ? ROUTED_TASKS[twin] : void 0) ?? t
|
|
|
260886
260962
|
}
|
|
260887
260963
|
var STARTER_FILES = ["scene.yaml", "oracle.mjs", "null.mjs"];
|
|
260888
260964
|
async function ownStarter(cwd) {
|
|
260889
|
-
const read7 = (name5) =>
|
|
260965
|
+
const read7 = (name5) => readFile44(join58(cwd, "scenes/starter", name5), "utf8").catch(() => void 0);
|
|
260890
260966
|
const scene2 = await read7("scene.yaml");
|
|
260891
260967
|
if (scene2 === void 0) return void 0;
|
|
260892
260968
|
let twins;
|
|
@@ -260917,7 +260993,7 @@ async function wireComposio(cwd, candidates2) {
|
|
|
260917
260993
|
const added = [], pending = [];
|
|
260918
260994
|
const result = { added, pending, passEnvAdded: false };
|
|
260919
260995
|
if (!candidates2.length) return result;
|
|
260920
|
-
const text31 = await
|
|
260996
|
+
const text31 = await readFile44(join58(cwd, "ancha.yaml"), "utf8");
|
|
260921
260997
|
let config12;
|
|
260922
260998
|
try {
|
|
260923
260999
|
config12 = parseConfigText(text31);
|
|
@@ -260967,7 +261043,7 @@ async function rewrite(cwd, relativePath, content2) {
|
|
|
260967
261043
|
}
|
|
260968
261044
|
}
|
|
260969
261045
|
async function listTests(cwd, tests) {
|
|
260970
|
-
const text31 = await
|
|
261046
|
+
const text31 = await readFile44(join58(cwd, "ancha.yaml"), "utf8");
|
|
260971
261047
|
let scenes;
|
|
260972
261048
|
try {
|
|
260973
261049
|
scenes = parseConfigText(text31).scenes;
|
|
@@ -260994,7 +261070,7 @@ async function listTests(cwd, tests) {
|
|
|
260994
261070
|
return true;
|
|
260995
261071
|
}
|
|
260996
261072
|
async function addExampleSeeds(file3, twins) {
|
|
260997
|
-
const doc = (0, import_yaml18.parseDocument)(await
|
|
261073
|
+
const doc = (0, import_yaml18.parseDocument)(await readFile44(file3, "utf8"));
|
|
260998
261074
|
const added = [], skipped = [];
|
|
260999
261075
|
for (const twin of twins) {
|
|
261000
261076
|
if (doc.hasIn(["seed", twin])) continue;
|
|
@@ -261069,7 +261145,7 @@ async function wireExistingConfig(cwd, fillMissing) {
|
|
|
261069
261145
|
const target6 = join58(cwd, "ancha.yaml");
|
|
261070
261146
|
let text31;
|
|
261071
261147
|
try {
|
|
261072
|
-
text31 = await
|
|
261148
|
+
text31 = await readFile44(target6, "utf8");
|
|
261073
261149
|
} catch {
|
|
261074
261150
|
return void 0;
|
|
261075
261151
|
}
|
|
@@ -261112,7 +261188,7 @@ function registerKit(program2, ctx) {
|
|
|
261112
261188
|
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" });
|
|
261113
261189
|
}
|
|
261114
261190
|
const detection = await detectProject(ctx.io.cwd, opts.agent);
|
|
261115
|
-
const configText = await
|
|
261191
|
+
const configText = await readFile44(join58(ctx.io.cwd, "ancha.yaml"), "utf8").catch(() => void 0);
|
|
261116
261192
|
const configured = configText !== void 0;
|
|
261117
261193
|
let task2 = configured || detection.slackApp !== void 0 || detection.agent === null ? void 0 : await taskSetup(ctx.io.cwd, detection.agent, { command: detection.agent });
|
|
261118
261194
|
const existingConfig = (() => {
|
|
@@ -261158,15 +261234,15 @@ min_pass_rate: 1
|
|
|
261158
261234
|
` },
|
|
261159
261235
|
...templates.map((file3) => ({ ...file3, relativePath: `scenes/${opts.template}/${file3.relativePath}` })),
|
|
261160
261236
|
...starterWorld ? [starterWorld] : [],
|
|
261161
|
-
{ relativePath: ".claude/skills/ancha/SKILL.md", content: await
|
|
261237
|
+
{ relativePath: ".claude/skills/ancha/SKILL.md", content: await readFile44(new URL("SKILL.md", assetRoot()), "utf8") },
|
|
261162
261238
|
...pe?.files ?? [],
|
|
261163
261239
|
...examples2?.files ?? []
|
|
261164
261240
|
];
|
|
261165
261241
|
await preflightFiles(ctx.io.cwd, [...files2, { relativePath: "AGENTS.md", content: "" }, { relativePath: ".gitignore", content: "" }]);
|
|
261166
261242
|
const updated = [];
|
|
261167
|
-
const rewritten = own2 === void 0 ? [] : await Promise.all(files2.filter((file3) => file3.relativePath.startsWith("scenes/starter/")).map(async (file3) => await
|
|
261243
|
+
const rewritten = own2 === void 0 ? [] : await Promise.all(files2.filter((file3) => file3.relativePath.startsWith("scenes/starter/")).map(async (file3) => await readFile44(join58(ctx.io.cwd, file3.relativePath), "utf8").catch(() => void 0) === file3.content ? void 0 : file3)).then((list19) => list19.filter((file3) => file3 !== void 0));
|
|
261168
261244
|
if (starterWorld && own2 !== void 0) {
|
|
261169
|
-
const before2 = await
|
|
261245
|
+
const before2 = await readFile44(join58(ctx.io.cwd, starterWorld.relativePath), "utf8").catch(() => void 0);
|
|
261170
261246
|
const previous = await loadSceneFile(join58(ctx.io.cwd, "scenes/starter/scene.yaml"));
|
|
261171
261247
|
if (before2 === worldFileYaml(sceneWorld(previous)) && before2 !== starterWorld.content) rewritten.push(starterWorld);
|
|
261172
261248
|
}
|
|
@@ -261212,7 +261288,7 @@ min_pass_rate: 1
|
|
|
261212
261288
|
}
|
|
261213
261289
|
const routeWiring = await wireComposio(ctx.io.cwd, routeTools);
|
|
261214
261290
|
if (routeWiring.added.length && !result.created.includes("ancha.yaml") && !updated.includes("ancha.yaml")) updated.push("ancha.yaml");
|
|
261215
|
-
const savedConfig = await
|
|
261291
|
+
const savedConfig = await readFile44(join58(ctx.io.cwd, "ancha.yaml"), "utf8").then((text31) => {
|
|
261216
261292
|
try {
|
|
261217
261293
|
return parseConfigText(text31);
|
|
261218
261294
|
} catch {
|
|
@@ -261509,7 +261585,7 @@ init_assets();
|
|
|
261509
261585
|
init_src();
|
|
261510
261586
|
import { execFile as execFile9 } from "node:child_process";
|
|
261511
261587
|
import { createHash as createHash80, randomUUID as randomUUID18 } from "node:crypto";
|
|
261512
|
-
import { mkdir as mkdir28, mkdtemp as mkdtemp10, readFile as
|
|
261588
|
+
import { mkdir as mkdir28, mkdtemp as mkdtemp10, readFile as readFile46, readdir as readdir12, rename as rename8, rm as rm15, writeFile as writeFile29 } from "node:fs/promises";
|
|
261513
261589
|
import { tmpdir as tmpdir9 } from "node:os";
|
|
261514
261590
|
import { join as join60 } from "node:path";
|
|
261515
261591
|
init_detect();
|
|
@@ -261520,7 +261596,7 @@ init_policy();
|
|
|
261520
261596
|
|
|
261521
261597
|
// backend/src/execution/runtime-cache.ts
|
|
261522
261598
|
import { createHash as createHash79, randomUUID as randomUUID17 } from "node:crypto";
|
|
261523
|
-
import { mkdir as mkdir27, readFile as
|
|
261599
|
+
import { mkdir as mkdir27, readFile as readFile45, readdir as readdir11, realpath as realpath13, rename as rename7, rm as rm14, writeFile as writeFile28 } from "node:fs/promises";
|
|
261524
261600
|
import { join as join59 } from "node:path";
|
|
261525
261601
|
init_assets();
|
|
261526
261602
|
async function runtimeCacheKey(source, project14, command, context3) {
|
|
@@ -261529,7 +261605,7 @@ async function runtimeCacheKey(source, project14, command, context3) {
|
|
|
261529
261605
|
for (const entry3 of (await readdir11(path9, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261530
261606
|
const relative31 = prefix2 + entry3.name;
|
|
261531
261607
|
if (entry3.isDirectory()) await visit4(join59(path9, entry3.name), relative31 + "/");
|
|
261532
|
-
else hash10.update(relative31).update("\0").update(await
|
|
261608
|
+
else hash10.update(relative31).update("\0").update(await readFile45(join59(path9, entry3.name))).update("\0");
|
|
261533
261609
|
}
|
|
261534
261610
|
}
|
|
261535
261611
|
await visit4(source);
|
|
@@ -261561,7 +261637,7 @@ async function rememberRuntime(workspace4, key5, image2) {
|
|
|
261561
261637
|
}
|
|
261562
261638
|
|
|
261563
261639
|
// backend/src/execution/prepare-agent.ts
|
|
261564
|
-
var read6 = (directory, file3) =>
|
|
261640
|
+
var read6 = (directory, file3) => readFile46(join60(directory, file3), "utf8").catch((error65) => {
|
|
261565
261641
|
if (error65.code === "ENOENT") return void 0;
|
|
261566
261642
|
throw error65;
|
|
261567
261643
|
});
|
|
@@ -261697,13 +261773,13 @@ async function prepareAgent(workspace4, agentId2, options5 = {}) {
|
|
|
261697
261773
|
for (const entry3 of (await readdir12(path9, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {
|
|
261698
261774
|
const relative31 = prefix2 + entry3.name;
|
|
261699
261775
|
if (entry3.isDirectory()) await hashTree(join60(path9, entry3.name), relative31 + "/");
|
|
261700
|
-
else digest5.update(relative31).update("\0").update(await
|
|
261776
|
+
else digest5.update(relative31).update("\0").update(await readFile46(join60(path9, entry3.name))).update("\0");
|
|
261701
261777
|
}
|
|
261702
261778
|
}
|
|
261703
261779
|
await hashTree(source);
|
|
261704
261780
|
const fingerprint = digest5.digest("hex"), cacheRelative = `.ancha/agent-images/${fingerprint}.json`;
|
|
261705
261781
|
await preflightFiles(workspace4, [{ relativePath: cacheRelative, content: "" }]);
|
|
261706
|
-
const cached3 = await
|
|
261782
|
+
const cached3 = await readFile46(join60(workspace4, cacheRelative), "utf8").then((text31) => JSON.parse(text31)).catch(() => void 0);
|
|
261707
261783
|
let cachedImage;
|
|
261708
261784
|
if (cached3?.image && /^sha256:[a-f0-9]{64}$/.test(cached3.image)) {
|
|
261709
261785
|
try {
|
|
@@ -262172,7 +262248,7 @@ init_backend();
|
|
|
262172
262248
|
init_assets();
|
|
262173
262249
|
import { createServer as createServer6 } from "node:http";
|
|
262174
262250
|
import { randomBytes as randomBytes10 } from "node:crypto";
|
|
262175
|
-
import { readFile as
|
|
262251
|
+
import { readFile as readFile47, realpath as realpath14, stat as stat15 } from "node:fs/promises";
|
|
262176
262252
|
import { isAbsolute as isAbsolute12 } from "node:path";
|
|
262177
262253
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
262178
262254
|
|
|
@@ -263541,12 +263617,12 @@ async function startConsole(opts) {
|
|
|
263541
263617
|
const files2 = /* @__PURE__ */ new Map();
|
|
263542
263618
|
if (opts.assets !== false) {
|
|
263543
263619
|
const assets = opts.assets ?? fileURLToPath7(new URL("ui/", assetRoot()));
|
|
263544
|
-
const html4 = await
|
|
263620
|
+
const html4 = await readFile47(`${assets}/index.html`).catch(() => {
|
|
263545
263621
|
throw new AnchaError("USAGE", "console assets are missing; reinstall Ancha with `npm install -g @ancha-labs/cli`");
|
|
263546
263622
|
});
|
|
263547
263623
|
files2.set("/", { body: html4, mime: "text/html; charset=utf-8" });
|
|
263548
|
-
files2.set("/app.js", { body: await
|
|
263549
|
-
files2.set("/style.css", { body: await
|
|
263624
|
+
files2.set("/app.js", { body: await readFile47(`${assets}/app.js`), mime: "text/javascript; charset=utf-8" });
|
|
263625
|
+
files2.set("/style.css", { body: await readFile47(`${assets}/style.css`), mime: "text/css; charset=utf-8" });
|
|
263550
263626
|
}
|
|
263551
263627
|
const backend = opts.backend ?? await openBackend();
|
|
263552
263628
|
const catalog3 = new ScenarioCatalog(workspace4, opts.configPath);
|
|
@@ -264101,7 +264177,7 @@ function registerConnection(program2, ctx) {
|
|
|
264101
264177
|
// packages/cli/src/commands/test-pull.ts
|
|
264102
264178
|
init_src();
|
|
264103
264179
|
import { createHash as createHash84, randomUUID as randomUUID22 } from "node:crypto";
|
|
264104
|
-
import { lstat as lstat11, mkdir as mkdir30, readFile as
|
|
264180
|
+
import { lstat as lstat11, mkdir as mkdir30, readFile as readFile48, realpath as realpath15, rename as rename10, rm as rm20, writeFile as writeFile32 } from "node:fs/promises";
|
|
264105
264181
|
import { dirname as dirname24, join as join66 } from "node:path";
|
|
264106
264182
|
var hash8 = (text31) => createHash84("sha256").update(text31).digest("hex");
|
|
264107
264183
|
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("."));
|
|
@@ -264126,7 +264202,7 @@ async function writePulledTest(cwd, input5, force = false) {
|
|
|
264126
264202
|
});
|
|
264127
264203
|
if (!info2) return null;
|
|
264128
264204
|
if (!info2.isFile() || info2.isSymbolicLink()) throw new AnchaError("USAGE", "The test path must be a regular file.");
|
|
264129
|
-
return
|
|
264205
|
+
return readFile48(target6, "utf8");
|
|
264130
264206
|
};
|
|
264131
264207
|
const before2 = await current();
|
|
264132
264208
|
if (!force && before2 !== null && before2 !== input5.yaml && hash8(before2) !== input5.baseSha256 && hash8(before2) !== input5.previousSha256)
|
|
@@ -264159,7 +264235,7 @@ init_src();
|
|
|
264159
264235
|
init_scenes();
|
|
264160
264236
|
import { createHash as createHash85 } from "node:crypto";
|
|
264161
264237
|
import { constants as constants13 } from "node:fs";
|
|
264162
|
-
import { link as link7, lstat as lstat12, mkdir as mkdir31, mkdtemp as mkdtemp12, open as open13, readFile as
|
|
264238
|
+
import { link as link7, lstat as lstat12, mkdir as mkdir31, mkdtemp as mkdtemp12, open as open13, readFile as readFile49, readdir as readdir16, rename as rename11, rm as rm21, rmdir, unlink as unlink2, writeFile as writeFile33 } from "node:fs/promises";
|
|
264163
264239
|
import { dirname as dirname25, join as join67, relative as relative22, resolve as resolve48 } from "node:path";
|
|
264164
264240
|
var sha2567 = (bytes4) => createHash85("sha256").update(bytes4).digest("hex");
|
|
264165
264241
|
var KEY_ORDER = ["version", "id", "title", "variant", "start", "attempts", "deadline", "timeout", "until", "checks", "pass", "world"];
|
|
@@ -264322,7 +264398,7 @@ async function varyTestFiles(cwd, path9, options5 = {}, dependencies = {}) {
|
|
|
264322
264398
|
const source = resolve48(cwd, path9);
|
|
264323
264399
|
let test3;
|
|
264324
264400
|
try {
|
|
264325
|
-
test3 = parseSceneYaml(await
|
|
264401
|
+
test3 = parseSceneYaml(await readFile49(source, "utf8"));
|
|
264326
264402
|
} catch {
|
|
264327
264403
|
await loadSceneOrTest(cwd, source);
|
|
264328
264404
|
throw invalid40(`${path9}: cannot parse the parent test`);
|
|
@@ -264333,7 +264409,7 @@ async function varyTestFiles(cwd, path9, options5 = {}, dependencies = {}) {
|
|
|
264333
264409
|
path: relative22(cwd, source),
|
|
264334
264410
|
test: test3,
|
|
264335
264411
|
fingerprint: sceneFingerprint(loaded.scene),
|
|
264336
|
-
...loaded.world ? { world: parseSceneYaml(await
|
|
264412
|
+
...loaded.world ? { world: parseSceneYaml(await readFile49(loaded.world, "utf8")) } : {}
|
|
264337
264413
|
};
|
|
264338
264414
|
const out = options5.out === void 0 ? dirname25(source) : resolve48(cwd, options5.out);
|
|
264339
264415
|
const keyPath = options5.idempotencyKey === void 0 ? void 0 : join67(resolve48(cwd), ".ancha", "test-variation", `${sha2567(options5.idempotencyKey)}.json`);
|
|
@@ -264432,7 +264508,7 @@ init_trace_import();
|
|
|
264432
264508
|
// packages/cli/src/commands/traces.ts
|
|
264433
264509
|
init_trace_import();
|
|
264434
264510
|
import { createHash as createHash86 } from "node:crypto";
|
|
264435
|
-
import { access as access13, readFile as
|
|
264511
|
+
import { access as access13, readFile as readFile52, mkdir as mkdir32, stat as stat17, writeFile as writeFile34 } from "node:fs/promises";
|
|
264436
264512
|
import { basename as basename15, dirname as dirname26, join as join69, relative as relative25, resolve as resolve50 } from "node:path";
|
|
264437
264513
|
import { isDeepStrictEqual as isDeepStrictEqual7 } from "node:util";
|
|
264438
264514
|
var import_yaml21 = __toESM(require_dist(), 1);
|
|
@@ -264442,7 +264518,7 @@ init_run_store();
|
|
|
264442
264518
|
|
|
264443
264519
|
// backend/src/trace-ir.ts
|
|
264444
264520
|
init_src();
|
|
264445
|
-
import { readFile as
|
|
264521
|
+
import { readFile as readFile50 } from "node:fs/promises";
|
|
264446
264522
|
import { join as join68 } from "node:path";
|
|
264447
264523
|
var VENDOR_API_BASES2 = {
|
|
264448
264524
|
slack: "https://slack.com",
|
|
@@ -264515,7 +264591,7 @@ function attemptToIr(entries4, traceId, agent, saved) {
|
|
|
264515
264591
|
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];
|
|
264516
264592
|
}
|
|
264517
264593
|
async function readAttemptTrace(dir2) {
|
|
264518
|
-
const text31 = (await
|
|
264594
|
+
const text31 = (await readFile50(join68(dir2, "trace.jsonl"), "utf8")).trim();
|
|
264519
264595
|
return text31 ? text31.split("\n").map((line2) => JSON.parse(line2)) : [];
|
|
264520
264596
|
}
|
|
264521
264597
|
|
|
@@ -264645,7 +264721,7 @@ async function listTraces(source, { limit: limit2, since, name: name5 }, env2, f
|
|
|
264645
264721
|
}
|
|
264646
264722
|
|
|
264647
264723
|
// packages/cli/src/trace-files.ts
|
|
264648
|
-
import { readFile as
|
|
264724
|
+
import { readFile as readFile51, stat as stat16 } from "node:fs/promises";
|
|
264649
264725
|
import { basename as basename14, relative as relative23, resolve as resolve49 } from "node:path";
|
|
264650
264726
|
init_src();
|
|
264651
264727
|
var MB3 = 1024 * 1024;
|
|
@@ -264674,7 +264750,7 @@ async function findTraceFiles(cwd, args) {
|
|
|
264674
264750
|
return [...found].sort();
|
|
264675
264751
|
}
|
|
264676
264752
|
async function readTraceTexts(cwd, paths3) {
|
|
264677
|
-
return Promise.all(paths3.map(async (path9) => ({ file: relative23(cwd, path9) || basename14(path9), name: basename14(path9), text: await
|
|
264753
|
+
return Promise.all(paths3.map(async (path9) => ({ file: relative23(cwd, path9) || basename14(path9), name: basename14(path9), text: await readFile51(path9, "utf8").catch(() => void 0) })));
|
|
264678
264754
|
}
|
|
264679
264755
|
function readTraceUnits(texts4, { fileToIr: fileToIr2, sourceOf: sourceOf2 }) {
|
|
264680
264756
|
const drafts = /* @__PURE__ */ new Map(), skipped = [], read7 = [];
|
|
@@ -265166,7 +265242,7 @@ var importedCheckLines = (scene2, production3) => [
|
|
|
265166
265242
|
...importedChecks(scene2, production3).map((c) => ` ${c.id}: ${c.required ? "required" : "optional"}, ${c.production} in production`)
|
|
265167
265243
|
];
|
|
265168
265244
|
async function localChanges(dir2) {
|
|
265169
|
-
const text31 = await
|
|
265245
|
+
const text31 = await readFile52(join69(dir2, "scene.yaml"), "utf8").catch(() => void 0);
|
|
265170
265246
|
if (text31 === void 0) return void 0;
|
|
265171
265247
|
const local2 = (() => {
|
|
265172
265248
|
try {
|
|
@@ -265177,7 +265253,7 @@ async function localChanges(dir2) {
|
|
|
265177
265253
|
})(), mark = MARK.exec(text31)?.[1];
|
|
265178
265254
|
if (local2 === void 0 || mark === void 0) return { added: [], other: true };
|
|
265179
265255
|
if (digest4(local2) === mark) return { added: [], other: false };
|
|
265180
|
-
const production3 = await
|
|
265256
|
+
const production3 = await readFile52(join69(dir2, "production.json"), "utf8").then((t) => JSON.parse(t).checks, () => void 0);
|
|
265181
265257
|
const added = production3 ? checksOf2(local2).filter((c) => !Object.hasOwn(production3, c.id)) : [];
|
|
265182
265258
|
const addedIds = new Set(added.map((c) => c.id));
|
|
265183
265259
|
const required6 = (Array.isArray(local2.pass) ? local2.pass : checksOf2(local2).map((c) => c.id)).filter((id15) => addedIds.has(id15));
|
|
@@ -265758,7 +265834,7 @@ function registerTraces(program2, ctx) {
|
|
|
265758
265834
|
});
|
|
265759
265835
|
}
|
|
265760
265836
|
async function traceSource(ctx, trace2, from) {
|
|
265761
|
-
if (!from) return { text: await
|
|
265837
|
+
if (!from) return { text: await readFile52(resolve50(ctx.io.cwd, trace2), "utf8").catch(() => {
|
|
265762
265838
|
throw new AnchaError("USAGE", `cannot read ${trace2}`, { hint: "pass the path of a trace file: ancha import --offline <trace.jsonl>" });
|
|
265763
265839
|
}), name: basename15(trace2), label: basename15(trace2) };
|
|
265764
265840
|
const doc = await fetchTrace(from, trace2, ctx.io.env);
|
|
@@ -265766,7 +265842,7 @@ async function traceSource(ctx, trace2, from) {
|
|
|
265766
265842
|
return { text: JSON.stringify(doc), name: `${from}-${id15}`.slice(0, 80), label: `${from === "langfuse" ? "Langfuse" : "LangSmith"} trace ${id15}` };
|
|
265767
265843
|
}
|
|
265768
265844
|
async function traceFileLines(ctx, file3) {
|
|
265769
|
-
const text31 = await
|
|
265845
|
+
const text31 = await readFile52(resolve50(ctx.io.cwd, file3), "utf8").catch(() => {
|
|
265770
265846
|
throw new AnchaError("USAGE", `cannot read ${file3}`, { hint: "pass the path of a trace file: ancha traces diff <trace.jsonl> latest" });
|
|
265771
265847
|
});
|
|
265772
265848
|
return { text: text31, lines: await traceTextLines(text31, basename15(file3)) };
|
|
@@ -265839,7 +265915,7 @@ async function writeRecords(ctx, conversations, dest) {
|
|
|
265839
265915
|
const seen = conversations.flatMap((c) => recordsOf2(toolCallsOf(c.lines), { conversation: c.id }));
|
|
265840
265916
|
if (!seen.length) return void 0;
|
|
265841
265917
|
const path9 = resolve50(ctx.io.cwd, dest, "records.jsonl");
|
|
265842
|
-
const merged = mergeRecords2(readRecordLines2(await
|
|
265918
|
+
const merged = mergeRecords2(readRecordLines2(await readFile52(path9, "utf8").catch(() => "")), seen);
|
|
265843
265919
|
await mkdir32(dirname26(path9), { recursive: true });
|
|
265844
265920
|
await writeFile34(path9, recordLines2(merged));
|
|
265845
265921
|
const types = merged.reduce((all9, r2) => all9.set(r2.type, (all9.get(r2.type) ?? 0) + 1), /* @__PURE__ */ new Map());
|
|
@@ -265853,7 +265929,7 @@ async function importLocally(ctx, source, options5) {
|
|
|
265853
265929
|
const { text: text31 } = source, all9 = await traceConversations(text31, source.name);
|
|
265854
265930
|
const { sceneFiles: sceneFiles2 } = await Promise.resolve().then(() => (init_trace_import(), trace_import_exports));
|
|
265855
265931
|
const rebuild3 = rebuildTraceImport;
|
|
265856
|
-
const checks2 = options5.checks ? readImportChecks(await
|
|
265932
|
+
const checks2 = options5.checks ? readImportChecks(await readFile52(resolve50(ctx.io.cwd, options5.checks), "utf8").catch(() => {
|
|
265857
265933
|
throw new AnchaError("USAGE", `cannot read checks file ${options5.checks}`);
|
|
265858
265934
|
})) : void 0;
|
|
265859
265935
|
const picked = options5.conversation === void 0 ? all9 : all9.filter((c) => c.id === options5.conversation || c.traces.includes(options5.conversation));
|
|
@@ -265872,7 +265948,7 @@ async function importLocally(ctx, source, options5) {
|
|
|
265872
265948
|
const made = [], skipped = [];
|
|
265873
265949
|
for (const [i, conversation3] of picked.entries()) {
|
|
265874
265950
|
const examples2 = [...all9.filter((c) => c !== conversation3).map((c) => c.lines), ...files2], customer3 = customers3.people[i];
|
|
265875
|
-
const earlier2 = options5.resetAnswers ? {} : await
|
|
265951
|
+
const earlier2 = options5.resetAnswers ? {} : await readFile52(resolve50(ctx.io.cwd, options5.dest, named5.get(conversation3), "answers.json"), "utf8").then((text32) => JSON.parse(text32), () => ({}));
|
|
265876
265952
|
try {
|
|
265877
265953
|
const preview = rebuild3(conversation3.lines, { id: named5.get(conversation3), withRecords: true, examples: examples2, useReportedResults: options5.useReportedResults });
|
|
265878
265954
|
const answers = { ...answersFor(preview.questions, earlier2, options5.answer), ...options5.expect && { "checks.expect": options5.expect } };
|
|
@@ -265885,7 +265961,7 @@ async function importLocally(ctx, source, options5) {
|
|
|
265885
265961
|
}
|
|
265886
265962
|
const paths3 = made.map((m) => join69(resolve50(ctx.io.cwd, options5.dest, m.id), "scene.yaml"));
|
|
265887
265963
|
if (!options5.force) {
|
|
265888
|
-
for (const path9 of paths3) if (await
|
|
265964
|
+
for (const path9 of paths3) if (await readFile52(path9, "utf8").then(() => true, () => false)) throw new AnchaError("USAGE", `${relative25(ctx.io.cwd, path9)} exists; --force replaces it`);
|
|
265889
265965
|
}
|
|
265890
265966
|
for (const [i, m] of made.entries()) {
|
|
265891
265967
|
const path9 = paths3[i], dir2 = dirname26(path9);
|
|
@@ -265975,7 +266051,7 @@ function evidenceLines2(made) {
|
|
|
265975
266051
|
|
|
265976
266052
|
// packages/cli/src/commands/test-import.ts
|
|
265977
266053
|
import { existsSync as existsSync4 } from "node:fs";
|
|
265978
|
-
import { access as access14, mkdir as mkdir33, readFile as
|
|
266054
|
+
import { access as access14, mkdir as mkdir33, readFile as readFile53, writeFile as writeFile35 } from "node:fs/promises";
|
|
265979
266055
|
import { basename as basename16, dirname as dirname27, extname as extname2, isAbsolute as isAbsolute13, relative as relative26, resolve as resolve51 } from "node:path";
|
|
265980
266056
|
init_src();
|
|
265981
266057
|
init_detect();
|
|
@@ -266009,7 +266085,7 @@ async function testImport(ctx, file3, options5) {
|
|
|
266009
266085
|
}
|
|
266010
266086
|
let text31, encoding;
|
|
266011
266087
|
try {
|
|
266012
|
-
({ text: text31, encoding } = decodeEvalText(await
|
|
266088
|
+
({ text: text31, encoding } = decodeEvalText(await readFile53(path9)));
|
|
266013
266089
|
} catch (error65) {
|
|
266014
266090
|
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>" });
|
|
266015
266091
|
}
|
|
@@ -266043,7 +266119,7 @@ ${skipped.slice(0, 10).map((s3) => `item ${s3.item}: ${s3.reason}`).join("\n")}`
|
|
|
266043
266119
|
const tests = [];
|
|
266044
266120
|
for (const test3 of imported2.tests) {
|
|
266045
266121
|
const target6 = resolve51(ctx.io.cwd, test3.path);
|
|
266046
|
-
const before2 = existsSync4(target6) ? await
|
|
266122
|
+
const before2 = existsSync4(target6) ? await readFile53(target6, "utf8") : void 0;
|
|
266047
266123
|
const status6 = before2 === void 0 ? "written" : before2 === test3.yaml ? "unchanged" : !editedSinceImport(before2) ? "updated" : options5.force ? "written" : "kept";
|
|
266048
266124
|
if (status6 === "written" || status6 === "updated") {
|
|
266049
266125
|
await mkdir33(dirname27(target6), { recursive: true });
|
|
@@ -266095,7 +266171,7 @@ function registerTestImport(tests, ctx) {
|
|
|
266095
266171
|
}
|
|
266096
266172
|
|
|
266097
266173
|
// packages/cli/src/commands/test-files.ts
|
|
266098
|
-
import { readFile as
|
|
266174
|
+
import { readFile as readFile54, stat as stat18 } from "node:fs/promises";
|
|
266099
266175
|
import { basename as basename17, relative as relative27, resolve as resolve52 } from "node:path";
|
|
266100
266176
|
init_src();
|
|
266101
266177
|
init_scenes();
|
|
@@ -266117,7 +266193,7 @@ async function showTestFile(ctx, ref23) {
|
|
|
266117
266193
|
const matches11 = [];
|
|
266118
266194
|
for (const file3 of await projectTestFiles(ctx)) {
|
|
266119
266195
|
try {
|
|
266120
|
-
const doc2 = parseSceneYaml(await
|
|
266196
|
+
const doc2 = parseSceneYaml(await readFile54(resolve52(ctx.io.cwd, file3), "utf8"));
|
|
266121
266197
|
if (doc2 && typeof doc2 === "object" && "id" in doc2 && doc2.id === ref23) matches11.push(file3);
|
|
266122
266198
|
} catch {
|
|
266123
266199
|
}
|
|
@@ -266128,7 +266204,7 @@ async function showTestFile(ctx, ref23) {
|
|
|
266128
266204
|
path9 = matches11[0];
|
|
266129
266205
|
}
|
|
266130
266206
|
const [{ scene: scene2, world: worldPath }] = await loadScenes(ctx.io.cwd, [path9]);
|
|
266131
|
-
const doc = parseSceneYaml(await
|
|
266207
|
+
const doc = parseSceneYaml(await readFile54(resolve52(ctx.io.cwd, path9), "utf8"));
|
|
266132
266208
|
const world5 = {
|
|
266133
266209
|
...worldPath !== void 0 && { id: basename17(worldPath, ".yaml"), path: relative27(ctx.io.cwd, worldPath) },
|
|
266134
266210
|
tools: scene2.twins
|
|
@@ -266411,7 +266487,7 @@ Run again with ancha test run ${saved.id}`);
|
|
|
266411
266487
|
// packages/cli/src/commands/sandbox.ts
|
|
266412
266488
|
var import_yaml22 = __toESM(require_dist(), 1);
|
|
266413
266489
|
init_src();
|
|
266414
|
-
import { readFile as
|
|
266490
|
+
import { readFile as readFile55 } from "node:fs/promises";
|
|
266415
266491
|
import { resolve as resolve54 } from "node:path";
|
|
266416
266492
|
init_backend();
|
|
266417
266493
|
function tools(value6) {
|
|
@@ -266458,7 +266534,7 @@ Use --json to export this configuration.`);
|
|
|
266458
266534
|
if ([opts.tools, opts.preset, opts.definition].filter(Boolean).length > 1) throw new AnchaError("USAGE", "choose --tools, --preset or --definition");
|
|
266459
266535
|
let input5;
|
|
266460
266536
|
if (opts.definition) {
|
|
266461
|
-
const doc = (0, import_yaml22.parseDocument)(await
|
|
266537
|
+
const doc = (0, import_yaml22.parseDocument)(await readFile55(resolve54(ctx.io.cwd, opts.definition), "utf8"));
|
|
266462
266538
|
if (doc.errors.length) throw new AnchaError("CONFIG_INVALID", doc.errors.map((error65) => error65.message).join("; "));
|
|
266463
266539
|
input5 = doc.toJS({ maxAliasCount: 100 });
|
|
266464
266540
|
if (opts.name && input5 && typeof input5 === "object" && !Array.isArray(input5)) input5 = { ...input5, name: opts.name };
|
|
@@ -283061,7 +283137,7 @@ init_src();
|
|
|
283061
283137
|
init_backend();
|
|
283062
283138
|
import { fork as fork2 } from "node:child_process";
|
|
283063
283139
|
import { randomBytes as randomBytes11 } from "node:crypto";
|
|
283064
|
-
import { mkdir as mkdir34, open as open14, readFile as
|
|
283140
|
+
import { mkdir as mkdir34, open as open14, readFile as readFile56, rename as rename12, rm as rm22, stat as stat19, writeFile as writeFile36 } from "node:fs/promises";
|
|
283065
283141
|
import { createRequire as createRequire6 } from "node:module";
|
|
283066
283142
|
import { join as join70 } from "node:path";
|
|
283067
283143
|
var WORLD_SERVER_IDLE_MS = 10 * 6e4;
|
|
@@ -283077,7 +283153,7 @@ async function writePrivate(path9, value6) {
|
|
|
283077
283153
|
}
|
|
283078
283154
|
async function readJson2(path9) {
|
|
283079
283155
|
try {
|
|
283080
|
-
return JSON.parse(await
|
|
283156
|
+
return JSON.parse(await readFile56(path9, "utf8"));
|
|
283081
283157
|
} catch {
|
|
283082
283158
|
return void 0;
|
|
283083
283159
|
}
|
|
@@ -283657,7 +283733,7 @@ init_src();
|
|
|
283657
283733
|
// packages/cli/src/commands/world-company.ts
|
|
283658
283734
|
init_src();
|
|
283659
283735
|
import { constants as constants14 } from "node:fs";
|
|
283660
|
-
import { lstat as lstat13, mkdir as mkdir36, open as open15, readFile as
|
|
283736
|
+
import { lstat as lstat13, mkdir as mkdir36, open as open15, readFile as readFile57, rm as rm23 } from "node:fs/promises";
|
|
283661
283737
|
import { dirname as dirname28, join as join72, resolve as resolve56 } from "node:path";
|
|
283662
283738
|
|
|
283663
283739
|
// backend/src/company/fetch.ts
|
|
@@ -283917,7 +283993,7 @@ async function writeCompanyFiles(cwd, files2, force) {
|
|
|
283917
283993
|
try {
|
|
283918
283994
|
const stat22 = await lstat13(target6);
|
|
283919
283995
|
if (stat22.isFile() && !force) throw new AnchaError("USAGE", `${file3.relativePath} already exists`, { hint: "pass --force to overwrite generated files" });
|
|
283920
|
-
previous.set(target6, await
|
|
283996
|
+
previous.set(target6, await readFile57(target6));
|
|
283921
283997
|
} catch (error65) {
|
|
283922
283998
|
if (error65.code !== "ENOENT") throw error65;
|
|
283923
283999
|
previous.set(target6, void 0);
|
|
@@ -283973,7 +284049,7 @@ async function worldCompany(ctx, url4, options5, deps = {}) {
|
|
|
283973
284049
|
let source = null, fetched = [], modelCredit = null;
|
|
283974
284050
|
if (options5.profile) {
|
|
283975
284051
|
try {
|
|
283976
|
-
profile2 = parseCompanyProfile(JSON.parse(await
|
|
284052
|
+
profile2 = parseCompanyProfile(JSON.parse(await readFile57(resolve56(ctx.io.cwd, options5.profile), "utf8")));
|
|
283977
284053
|
} catch {
|
|
283978
284054
|
throw new AnchaError("CONFIG_INVALID", "company profile file must contain a valid version 1 profile", { hint: "see ancha docs company" });
|
|
283979
284055
|
}
|
|
@@ -284057,7 +284133,7 @@ function registerWorldFrom(command, ctx) {
|
|
|
284057
284133
|
// packages/cli/src/commands/world-import.ts
|
|
284058
284134
|
init_src();
|
|
284059
284135
|
import { existsSync as existsSync5 } from "node:fs";
|
|
284060
|
-
import { mkdir as mkdir37, readdir as readdir17, readFile as
|
|
284136
|
+
import { mkdir as mkdir37, readdir as readdir17, readFile as readFile59, stat as stat20, writeFile as writeFile38 } from "node:fs/promises";
|
|
284061
284137
|
import { extname as extname3, join as join73, relative as relative29, resolve as resolve58 } from "node:path";
|
|
284062
284138
|
|
|
284063
284139
|
// backend/src/kit/netsuite-import.ts
|
|
@@ -284549,7 +284625,7 @@ function realmOf(href2) {
|
|
|
284549
284625
|
const m = href2 === void 0 ? null : /^https?:\/\/(\d{4,10})(?:[-_]sb(\d{1,2}))?\.suitetalk\.api\.netsuite\.com/i.exec(href2);
|
|
284550
284626
|
return m ? `${m[1]}${m[2] ? `_SB${m[2]}` : ""}` : void 0;
|
|
284551
284627
|
}
|
|
284552
|
-
function
|
|
284628
|
+
function readFile58(file3, type, notes7) {
|
|
284553
284629
|
const text31 = file3.text.replace(/^/, ""), start2 = text31.trimStart();
|
|
284554
284630
|
if (!/^[[{]/.test(start2)) return readCsv2(file3.path, text31, type, notes7);
|
|
284555
284631
|
let values3;
|
|
@@ -285775,7 +285851,7 @@ function importNetsuite(files2, options5) {
|
|
|
285775
285851
|
const notes7 = [], problems = [], read7 = [], type = options5.type === void 0 ? void 0 : canonical11(options5.type);
|
|
285776
285852
|
let raws = [];
|
|
285777
285853
|
for (const file3 of files2) {
|
|
285778
|
-
let rows35 =
|
|
285854
|
+
let rows35 = readFile58(file3, type, notes7).map((raw3) => ({ ...raw3, type: rowType(raw3) }));
|
|
285779
285855
|
const untyped = rows35.filter((raw3) => raw3.type === "record" || raw3.type === TRANSACTION || raw3.type === ENTITY2);
|
|
285780
285856
|
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`);
|
|
285781
285857
|
rows35 = rows35.filter((raw3) => !untyped.includes(raw3));
|
|
@@ -285946,7 +286022,7 @@ async function worldImportNetsuite(ctx, paths3, options5) {
|
|
|
285946
286022
|
if (existsSync5(worldPath) && !options5.force) throw new AnchaError("USAGE", `${rel(worldPath)} already exists`, { hint: "pass --force to overwrite it, or choose another --id" });
|
|
285947
286023
|
const names8 = [...new Set((await Promise.all(paths3.map((path9) => exportFiles(ctx.io.cwd, path9)))).flat())];
|
|
285948
286024
|
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)" });
|
|
285949
|
-
const files2 = await Promise.all(names8.map(async (name5) => ({ path: rel(name5), text: decodeEvalText(await
|
|
286025
|
+
const files2 = await Promise.all(names8.map(async (name5) => ({ path: rel(name5), text: decodeEvalText(await readFile59(name5)).text })));
|
|
285950
286026
|
const imported2 = importNetsuite(files2, {
|
|
285951
286027
|
id: options5.id,
|
|
285952
286028
|
now: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -286037,7 +286113,7 @@ init_privacy();
|
|
|
286037
286113
|
init_assets();
|
|
286038
286114
|
init_report2();
|
|
286039
286115
|
import { createHash as createHash88, randomBytes as randomBytes12 } from "node:crypto";
|
|
286040
|
-
import { lstat as lstat14, mkdir as mkdir38, mkdtemp as mkdtemp13, readFile as
|
|
286116
|
+
import { lstat as lstat14, mkdir as mkdir38, mkdtemp as mkdtemp13, readFile as readFile60, rename as rename13, rm as rm24, writeFile as writeFile39 } from "node:fs/promises";
|
|
286041
286117
|
import { dirname as dirname29, join as join74, resolve as resolve59 } from "node:path";
|
|
286042
286118
|
var object27 = external_exports.record(external_exports.string(), external_exports.unknown());
|
|
286043
286119
|
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)));
|
|
@@ -286205,7 +286281,7 @@ async function recordPytestRun(cwd, input5, env2 = {}) {
|
|
|
286205
286281
|
const exists7 = async () => {
|
|
286206
286282
|
await preflightFiles(cwd, [{ relativePath: `${relative31}/record.json`, content: "" }]);
|
|
286207
286283
|
const completed = async () => {
|
|
286208
|
-
const text31 = await
|
|
286284
|
+
const text31 = await readFile60(join74(runDir, "record.json"), "utf8");
|
|
286209
286285
|
let previous;
|
|
286210
286286
|
try {
|
|
286211
286287
|
previous = JSON.parse(text31);
|
|
@@ -286341,7 +286417,7 @@ ${formatTable(value6.configuration.preset.datasets.map((data7) => [data7.tool, d
|
|
|
286341
286417
|
// packages/cli/src/commands/secrets.ts
|
|
286342
286418
|
var import_yaml23 = __toESM(require_dist(), 1);
|
|
286343
286419
|
init_src();
|
|
286344
|
-
import { readFile as
|
|
286420
|
+
import { readFile as readFile61, writeFile as writeFile40 } from "node:fs/promises";
|
|
286345
286421
|
import { resolve as resolve61 } from "node:path";
|
|
286346
286422
|
init_credentials();
|
|
286347
286423
|
var NAME_RE2 = /^[A-Z][A-Z0-9_]{0,63}$/;
|
|
@@ -286371,7 +286447,7 @@ function parseDotenv(text31) {
|
|
|
286371
286447
|
async function nameInConfig(ctx, names8) {
|
|
286372
286448
|
const label7 = ctx.globals().config ?? "ancha.yaml", file3 = resolve61(ctx.io.cwd, label7);
|
|
286373
286449
|
const them = names8.length === 1 ? "it" : "them", list19 = names8.join(", ");
|
|
286374
|
-
const text31 = await
|
|
286450
|
+
const text31 = await readFile61(file3, "utf8").catch(() => void 0);
|
|
286375
286451
|
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}` };
|
|
286376
286452
|
const doc = (0, import_yaml23.parseDocument)(text31);
|
|
286377
286453
|
const listed2 = (path9) => {
|
|
@@ -286394,7 +286470,7 @@ async function nameInConfig(ctx, names8) {
|
|
|
286394
286470
|
return { passEnv: { file: label7, added } };
|
|
286395
286471
|
}
|
|
286396
286472
|
async function configuredNames(ctx) {
|
|
286397
|
-
const text31 = await
|
|
286473
|
+
const text31 = await readFile61(resolve61(ctx.io.cwd, ctx.globals().config ?? "ancha.yaml"), "utf8").catch(() => void 0);
|
|
286398
286474
|
if (text31 === void 0) return [];
|
|
286399
286475
|
const doc = (0, import_yaml23.parseDocument)(text31), listed2 = (path9) => {
|
|
286400
286476
|
const node5 = doc.getIn(path9);
|
|
@@ -286462,7 +286538,7 @@ ${DEFERRED_SYNC}` : result.restarting ? " The workspace machine restarts its pro
|
|
|
286462
286538
|
});
|
|
286463
286539
|
command.command("import").argument("[file]", "dotenv file to read the values from", ".env").argument("[names...]", "variables to import (default: the ones ancha.yaml lists under agent.pass_env and agent.execution.env)").description("copy variables from a dotenv file into the workspace, checked as ancha secrets set checks them; never prints a value").option("--no-check", "save without asking Composio, OpenRouter, OpenAI or Anthropic whether they accept the key").action(async (file3, given2, opts) => {
|
|
286464
286540
|
const path9 = resolve61(ctx.io.cwd, file3);
|
|
286465
|
-
const text31 = await
|
|
286541
|
+
const text31 = await readFile61(path9, "utf8").catch(() => {
|
|
286466
286542
|
throw new AnchaError("USAGE", `cannot read ${file3}`, { hint: "pass the dotenv file that holds the values, e.g. ancha secrets import .env" });
|
|
286467
286543
|
});
|
|
286468
286544
|
const names8 = given2.length ? given2.map(validName) : await configuredNames(ctx);
|
|
@@ -286841,7 +286917,7 @@ import { randomUUID as randomUUID23 } from "node:crypto";
|
|
|
286841
286917
|
init_run_metadata();
|
|
286842
286918
|
var import_yaml24 = __toESM(require_dist(), 1);
|
|
286843
286919
|
init_src();
|
|
286844
|
-
import { mkdir as mkdir39, readFile as
|
|
286920
|
+
import { mkdir as mkdir39, readFile as readFile62, stat as stat21, writeFile as writeFile41 } from "node:fs/promises";
|
|
286845
286921
|
import { basename as basename18, join as join75, relative as relative30, resolve as resolve62 } from "node:path";
|
|
286846
286922
|
init_report2();
|
|
286847
286923
|
init_run_store();
|
|
@@ -286872,7 +286948,7 @@ async function testTask(ctx, file3, worldOverride) {
|
|
|
286872
286948
|
const path9 = resolve62(ctx.io.cwd, file3);
|
|
286873
286949
|
let doc;
|
|
286874
286950
|
try {
|
|
286875
|
-
doc = (0, import_yaml24.parse)(await
|
|
286951
|
+
doc = (0, import_yaml24.parse)(await readFile62(path9, "utf8"));
|
|
286876
286952
|
} catch (error65) {
|
|
286877
286953
|
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)" });
|
|
286878
286954
|
}
|
|
@@ -286976,7 +287052,7 @@ next page: ancha runs list --cursor ${page20.nextCursor}`}`);
|
|
|
286976
287052
|
const workspace4 = await uploadWorkspace(ctx);
|
|
286977
287053
|
const summary = await loadRunSummary(ctx.io.cwd, ref23, options5.out);
|
|
286978
287054
|
const runDir = join75(resolve62(ctx.io.cwd, options5.out ?? DEFAULT_RUNS_DIR), summary.runId);
|
|
286979
|
-
const inputs2 = JSON.parse(await
|
|
287055
|
+
const inputs2 = JSON.parse(await readFile62(join75(runDir, "inputs.json"), "utf8").catch(() => "{}"));
|
|
286980
287056
|
const passEnv = inputs2.agentEnvironment?.passEnv ?? (await ctx.loadConfig().catch(() => void 0))?.agent?.passEnv ?? [];
|
|
286981
287057
|
const inheritEnv = inputs2.agentEnvironment?.inheritEnv ?? summary.agentEnvironment?.inheritAll === true;
|
|
286982
287058
|
const upload6 = await uploadRun(ctx, workspace4, { runId: summary.runId, runDir, passEnv, inheritEnv });
|
|
@@ -286998,13 +287074,13 @@ next page: ancha runs list --cursor ${page20.nextCursor}`}`);
|
|
|
286998
287074
|
});
|
|
286999
287075
|
}
|
|
287000
287076
|
await mkdir39(dest, { recursive: true });
|
|
287001
|
-
const inputs2 = await
|
|
287077
|
+
const inputs2 = await readFile62(join75(resolve62(ctx.io.cwd, options5.out ?? DEFAULT_RUNS_DIR), summary.runId, "inputs.json"), "utf8").then((text31) => JSON.parse(text31), () => ({}));
|
|
287002
287078
|
const files2 = [], cases = withSeeds(inputs2.cases ?? []);
|
|
287003
287079
|
for (const scene2 of summary.scenes) for (const trial of scene2.trialsDetail) {
|
|
287004
287080
|
const dir2 = resolve62(ctx.io.cwd, trial.dir), name5 = basename18(dir2), file3 = join75(dest, `${name5}.ir.jsonl`);
|
|
287005
287081
|
await writeFile41(file3, attemptToIr(await readAttemptTrace(dir2), `${summary.runId}/${name5}`, summary.agent, {
|
|
287006
287082
|
scene: cases.find((c) => c.id === scene2.sceneId)?.scene,
|
|
287007
|
-
checks: await
|
|
287083
|
+
checks: await readFile62(join75(dir2, "checks.json"), "utf8").then((text31) => JSON.parse(text31), () => void 0),
|
|
287008
287084
|
outcome: trial.outcome ?? (trial.valid === false ? "invalid" : trial.passed ? "passed" : "failed"),
|
|
287009
287085
|
exit: trial.exit,
|
|
287010
287086
|
exitCode: trial.exitCode
|