@ancha-labs/cli 0.4.29 → 0.4.30
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 +78 -65
- package/lib/worker.mjs +4 -2
- package/package.json +1 -1
package/lib/ancha.mjs
CHANGED
|
@@ -220888,6 +220888,69 @@ var init_agent_fix = __esm({
|
|
|
220888
220888
|
}
|
|
220889
220889
|
});
|
|
220890
220890
|
|
|
220891
|
+
// backend/src/attempt-tool-diagnostics.ts
|
|
220892
|
+
function business(entry3) {
|
|
220893
|
+
if (entry3.source !== "agent" || isAgentAnswer(entry3)) return false;
|
|
220894
|
+
if (/(?:^|\/)(?:health|healthz|ready|readiness|oauth2?|authorize|token|metadata-catalog)(?:\/|$)/i.test(entry3.path)) return false;
|
|
220895
|
+
if (entry3.service === "slack" && /\/(?:auth|api)\.test$/.test(entry3.path)) return false;
|
|
220896
|
+
if (entry3.path.includes("/mcp")) return object21(entry3.request).method === "tools/call";
|
|
220897
|
+
return true;
|
|
220898
|
+
}
|
|
220899
|
+
function successful(entry3) {
|
|
220900
|
+
const response5 = object21(entry3.response);
|
|
220901
|
+
return !entry3.gap && !entry3.issue && entry3.status !== void 0 && entry3.status >= 200 && entry3.status < 300 && response5.ok !== false && !response5.error && !object21(response5.result).isError && !["unknown", "pending", "failed"].includes(String(response5.execution_status));
|
|
220902
|
+
}
|
|
220903
|
+
function attemptToolDiagnostics(scene2, trial) {
|
|
220904
|
+
const entries4 = projectToolCalls(trial.trace).filter(business);
|
|
220905
|
+
const tools2 = [.../* @__PURE__ */ new Set([...scene2.twins ?? [], ...entries4.map((e) => e.service).filter((s3) => typeof s3 === "string" && s3 !== "" && s3 !== "agent" && s3 !== "world")])];
|
|
220906
|
+
const toolCalls = tools2.map((tool) => {
|
|
220907
|
+
const calls2 = entries4.filter((e) => e.service === tool);
|
|
220908
|
+
const writes3 = tool === "netsuite" ? calls2.filter((e) => successful(e) && (/\/services\/rest\/record\/v1\//.test(e.path) && ["POST", "PATCH", "PUT", "DELETE"].includes(e.method) || e.path.includes("/mcp") && NETSUITE_WRITES.has(String(object21(object21(e.request).params).name)))).length : void 0;
|
|
220909
|
+
return { tool, calls: calls2.length, successful: calls2.filter(successful).length, ...writes3 !== void 0 && { writes: writes3 } };
|
|
220910
|
+
});
|
|
220911
|
+
const failed = trial.checks.filter((c) => c.required && !c.passed && c.status !== "skipped" && !c.error);
|
|
220912
|
+
const endedNormally = trial.exit === "done" || trial.exit === "idle" || trial.exit === "exited" && trial.exitCode === 0;
|
|
220913
|
+
const diagnoses = !trial.valid || trial.passed || !endedNormally || ["skipped", "xfailed"].includes(trial.outcome ?? "") || !failed.length ? [] : toolCalls.filter((t) => (scene2.twins ?? []).some((tool) => tool === t.tool) && t.successful === 0).map((t) => ({ code: "tool_not_reached", tool: t.tool, fix: toolAccessFix(t.tool) }));
|
|
220914
|
+
const missing9 = new Set(diagnoses.map((d) => d.tool));
|
|
220915
|
+
const unreachedChecks = failed.filter((result) => {
|
|
220916
|
+
const check4 = (scene2.checks ?? []).find((c) => c.id === result.id);
|
|
220917
|
+
if (!check4) return false;
|
|
220918
|
+
if ("state" in check4) return Object.keys(check4.state).some((key4) => missing9.has(key4.split(".")[0]));
|
|
220919
|
+
if ("message" in check4 || "never" in check4) return missing9.has("slack");
|
|
220920
|
+
if ("trace" in check4 || "tool_call" in check4) return false;
|
|
220921
|
+
return missing9.size > 0;
|
|
220922
|
+
}).map((c) => c.id);
|
|
220923
|
+
return AttemptToolDiagnosticsSchema.parse({ toolCalls, ...diagnoses.length && { diagnosis: diagnoses[0], diagnoses, unreachedChecks } });
|
|
220924
|
+
}
|
|
220925
|
+
function toolDiagnosticLines(attempt) {
|
|
220926
|
+
const diagnoses = attempt.diagnoses ?? (attempt.diagnosis ? [attempt.diagnosis] : []);
|
|
220927
|
+
return [
|
|
220928
|
+
...diagnoses.flatMap((d) => [`never reached ${toolTitle(d.tool)}: no successful ${toolTitle(d.tool)} call`, `fix: ${d.fix}`]),
|
|
220929
|
+
...(attempt.toolCalls ?? []).map((t) => `${toolTitle(t.tool)}: ${t.calls} ${t.calls === 1 ? "call" : "calls"}${t.writes ? `, ${t.writes} ${t.writes === 1 ? "write" : "writes"}` : ""}`),
|
|
220930
|
+
...(attempt.unreachedChecks?.length ?? 0) > 0 ? [`business checks not reached: ${attempt.unreachedChecks.join(", ")}`] : []
|
|
220931
|
+
];
|
|
220932
|
+
}
|
|
220933
|
+
var count5, ToolDiagnosisSchema, AttemptToolDiagnosticsSchema, toolTitle, toolAccessFix, NETSUITE_WRITES, object21;
|
|
220934
|
+
var init_attempt_tool_diagnostics = __esm({
|
|
220935
|
+
"backend/src/attempt-tool-diagnostics.ts"() {
|
|
220936
|
+
"use strict";
|
|
220937
|
+
init_src();
|
|
220938
|
+
init_zod();
|
|
220939
|
+
count5 = external_exports.number().int().nonnegative();
|
|
220940
|
+
ToolDiagnosisSchema = external_exports.strictObject({ code: external_exports.literal("tool_not_reached"), tool: external_exports.string().min(1), fix: external_exports.string().min(1) });
|
|
220941
|
+
AttemptToolDiagnosticsSchema = external_exports.strictObject({
|
|
220942
|
+
toolCalls: external_exports.array(external_exports.strictObject({ tool: external_exports.string().min(1), calls: count5, successful: count5, writes: count5.optional() })),
|
|
220943
|
+
diagnosis: ToolDiagnosisSchema.optional(),
|
|
220944
|
+
diagnoses: external_exports.array(ToolDiagnosisSchema).optional(),
|
|
220945
|
+
unreachedChecks: external_exports.array(external_exports.string()).optional()
|
|
220946
|
+
});
|
|
220947
|
+
toolTitle = (tool) => TOOL_DESCRIPTORS.find((t) => t.name === tool)?.title ?? tool;
|
|
220948
|
+
toolAccessFix = (tool) => `if the agent should call ${toolTitle(tool)} in this test, set up its client with ancha connect ${tool}`;
|
|
220949
|
+
NETSUITE_WRITES = /* @__PURE__ */ new Set(["ns_createRecord", "ns_transformRecord", "ns_updateRecord", "ns_executeRecordAction", "ns_attachFile", "ns_detachFile"]);
|
|
220950
|
+
object21 = (value5) => value5 !== null && typeof value5 === "object" ? value5 : {};
|
|
220951
|
+
}
|
|
220952
|
+
});
|
|
220953
|
+
|
|
220891
220954
|
// backend/src/agent-outcome.ts
|
|
220892
220955
|
function plainTextTaskParseError(lines2) {
|
|
220893
220956
|
const text31 = lines2.join("\n");
|
|
@@ -220986,6 +221049,13 @@ function attemptOutcome(view3, ctx) {
|
|
|
220986
221049
|
const key4 = ctx.taskFix === void 0 ? missingKey(tail) : void 0;
|
|
220987
221050
|
return out({ code: key4 !== void 0 && fix?.includes(key4) ? "missing_secret" : "crashed", level: "fail", message: endedSentence(view3), ...fix !== void 0 && { fix } });
|
|
220988
221051
|
}
|
|
221052
|
+
const denied = calls2.find((entry3) => refused2(entry3) && typeof entry3.service === "string");
|
|
221053
|
+
if (crashed) return out({
|
|
221054
|
+
code: "crashed",
|
|
221055
|
+
level: "warning",
|
|
221056
|
+
message: `${calls2.length > 0 ? `It took the task and made ${calls2.length === 1 ? "a call" : `${calls2.length} calls`}` : "It read the task"}, then exited with an error; its log ends below.`,
|
|
221057
|
+
fix: denied ? `${toolTitle(denied.service)} answered ${denied.status}: set up its client with ancha connect ${denied.service}, which uses the credentials Ancha gives.` : "The check gives it a short task and starter data. If the error is about the task or data it expected, that is expected here: your tests give it their own tasks and worlds."
|
|
221058
|
+
});
|
|
220989
221059
|
if (view3.exit === "timeout" && view3.log.trim() === "" && calls2.length === 0 && !view3.modelReplies?.length && answer === void 0) {
|
|
220990
221060
|
const fix = ctx.stdin ? `it reads its task from stdin (${ctx.stdin.source}:${ctx.stdin.line}): in ancha.yaml under agent:, set input: stdin` : "if it waits for input, hand it the task: it is in ANCHA_TASK and ANCHA_TASK_FILE, or on its stdin with agent.input: stdin in ancha.yaml";
|
|
220991
221061
|
return out({ code: "idle", level: "fail", message: `It ran ${Math.round(view3.realMs / 1e3)} s without output, a model call, a tool call or an answer.`, fix });
|
|
@@ -221010,6 +221080,7 @@ var init_agent_outcome = __esm({
|
|
|
221010
221080
|
"use strict";
|
|
221011
221081
|
init_src();
|
|
221012
221082
|
init_agent_fix();
|
|
221083
|
+
init_attempt_tool_diagnostics();
|
|
221013
221084
|
init_gateway();
|
|
221014
221085
|
oneLine4 = (text31) => text31.replace(/\s+/g, " ").trim();
|
|
221015
221086
|
quoted3 = (text31) => {
|
|
@@ -221256,68 +221327,6 @@ var init_trial = __esm({
|
|
|
221256
221327
|
}
|
|
221257
221328
|
});
|
|
221258
221329
|
|
|
221259
|
-
// backend/src/attempt-tool-diagnostics.ts
|
|
221260
|
-
function business(entry3) {
|
|
221261
|
-
if (entry3.source !== "agent" || isAgentAnswer(entry3)) return false;
|
|
221262
|
-
if (/(?:^|\/)(?:health|healthz|ready|readiness|oauth2?|authorize|token|metadata-catalog)(?:\/|$)/i.test(entry3.path)) return false;
|
|
221263
|
-
if (entry3.service === "slack" && /\/(?:auth|api)\.test$/.test(entry3.path)) return false;
|
|
221264
|
-
if (entry3.path.includes("/mcp")) return object21(entry3.request).method === "tools/call";
|
|
221265
|
-
return true;
|
|
221266
|
-
}
|
|
221267
|
-
function successful(entry3) {
|
|
221268
|
-
const response5 = object21(entry3.response);
|
|
221269
|
-
return !entry3.gap && !entry3.issue && entry3.status !== void 0 && entry3.status >= 200 && entry3.status < 300 && response5.ok !== false && !response5.error && !object21(response5.result).isError && !["unknown", "pending", "failed"].includes(String(response5.execution_status));
|
|
221270
|
-
}
|
|
221271
|
-
function attemptToolDiagnostics(scene2, trial) {
|
|
221272
|
-
const entries4 = projectToolCalls(trial.trace).filter(business);
|
|
221273
|
-
const tools2 = [.../* @__PURE__ */ new Set([...scene2.twins ?? [], ...entries4.map((e) => e.service).filter((s3) => typeof s3 === "string" && s3 !== "" && s3 !== "agent" && s3 !== "world")])];
|
|
221274
|
-
const toolCalls = tools2.map((tool) => {
|
|
221275
|
-
const calls2 = entries4.filter((e) => e.service === tool);
|
|
221276
|
-
const writes3 = tool === "netsuite" ? calls2.filter((e) => successful(e) && (/\/services\/rest\/record\/v1\//.test(e.path) && ["POST", "PATCH", "PUT", "DELETE"].includes(e.method) || e.path.includes("/mcp") && NETSUITE_WRITES.has(String(object21(object21(e.request).params).name)))).length : void 0;
|
|
221277
|
-
return { tool, calls: calls2.length, successful: calls2.filter(successful).length, ...writes3 !== void 0 && { writes: writes3 } };
|
|
221278
|
-
});
|
|
221279
|
-
const failed = trial.checks.filter((c) => c.required && !c.passed && c.status !== "skipped" && !c.error);
|
|
221280
|
-
const endedNormally = trial.exit === "done" || trial.exit === "idle" || trial.exit === "exited" && trial.exitCode === 0;
|
|
221281
|
-
const diagnoses = !trial.valid || trial.passed || !endedNormally || ["skipped", "xfailed"].includes(trial.outcome ?? "") || !failed.length ? [] : toolCalls.filter((t) => (scene2.twins ?? []).some((tool) => tool === t.tool) && t.successful === 0).map((t) => ({ code: "tool_not_reached", tool: t.tool, fix: toolAccessFix(t.tool) }));
|
|
221282
|
-
const missing9 = new Set(diagnoses.map((d) => d.tool));
|
|
221283
|
-
const unreachedChecks = failed.filter((result) => {
|
|
221284
|
-
const check4 = (scene2.checks ?? []).find((c) => c.id === result.id);
|
|
221285
|
-
if (!check4) return false;
|
|
221286
|
-
if ("state" in check4) return Object.keys(check4.state).some((key4) => missing9.has(key4.split(".")[0]));
|
|
221287
|
-
if ("message" in check4 || "never" in check4) return missing9.has("slack");
|
|
221288
|
-
return missing9.size > 0;
|
|
221289
|
-
}).map((c) => c.id);
|
|
221290
|
-
return AttemptToolDiagnosticsSchema.parse({ toolCalls, ...diagnoses.length && { diagnosis: diagnoses[0], diagnoses, unreachedChecks } });
|
|
221291
|
-
}
|
|
221292
|
-
function toolDiagnosticLines(attempt) {
|
|
221293
|
-
const diagnoses = attempt.diagnoses ?? (attempt.diagnosis ? [attempt.diagnosis] : []);
|
|
221294
|
-
return [
|
|
221295
|
-
...diagnoses.flatMap((d) => [`never reached ${toolTitle(d.tool)}: no successful ${toolTitle(d.tool)} call`, `fix: ${d.fix}`]),
|
|
221296
|
-
...(attempt.toolCalls ?? []).map((t) => `${toolTitle(t.tool)}: ${t.calls} ${t.calls === 1 ? "call" : "calls"}${t.writes ? `, ${t.writes} ${t.writes === 1 ? "write" : "writes"}` : ""}`),
|
|
221297
|
-
...(attempt.unreachedChecks?.length ?? 0) > 0 ? [`business checks not reached: ${attempt.unreachedChecks.join(", ")}`] : []
|
|
221298
|
-
];
|
|
221299
|
-
}
|
|
221300
|
-
var count5, ToolDiagnosisSchema, AttemptToolDiagnosticsSchema, toolAccessFix, toolTitle, NETSUITE_WRITES, object21;
|
|
221301
|
-
var init_attempt_tool_diagnostics = __esm({
|
|
221302
|
-
"backend/src/attempt-tool-diagnostics.ts"() {
|
|
221303
|
-
"use strict";
|
|
221304
|
-
init_src();
|
|
221305
|
-
init_zod();
|
|
221306
|
-
count5 = external_exports.number().int().nonnegative();
|
|
221307
|
-
ToolDiagnosisSchema = external_exports.strictObject({ code: external_exports.literal("tool_not_reached"), tool: external_exports.string().min(1), fix: external_exports.string().min(1) });
|
|
221308
|
-
AttemptToolDiagnosticsSchema = external_exports.strictObject({
|
|
221309
|
-
toolCalls: external_exports.array(external_exports.strictObject({ tool: external_exports.string().min(1), calls: count5, successful: count5, writes: count5.optional() })),
|
|
221310
|
-
diagnosis: ToolDiagnosisSchema.optional(),
|
|
221311
|
-
diagnoses: external_exports.array(ToolDiagnosisSchema).optional(),
|
|
221312
|
-
unreachedChecks: external_exports.array(external_exports.string()).optional()
|
|
221313
|
-
});
|
|
221314
|
-
toolAccessFix = (tool) => `configure the native SDK using ancha connect ${tool}; health and process exit do not prove agent access`;
|
|
221315
|
-
toolTitle = (tool) => TOOL_DESCRIPTORS.find((t) => t.name === tool)?.title ?? tool;
|
|
221316
|
-
NETSUITE_WRITES = /* @__PURE__ */ new Set(["ns_createRecord", "ns_transformRecord", "ns_updateRecord", "ns_executeRecordAction", "ns_attachFile", "ns_detachFile"]);
|
|
221317
|
-
object21 = (value5) => value5 !== null && typeof value5 === "object" ? value5 : {};
|
|
221318
|
-
}
|
|
221319
|
-
});
|
|
221320
|
-
|
|
221321
221330
|
// backend/src/harness-issues.ts
|
|
221322
221331
|
var init_harness_issues2 = __esm({
|
|
221323
221332
|
"backend/src/harness-issues.ts"() {
|
|
@@ -248639,7 +248648,11 @@ async function uploadReport(ctx, done, from, dest) {
|
|
|
248639
248648
|
return [
|
|
248640
248649
|
`Uploaded ${plural6(done.sent, "trace")} from ${from}: ${made}${done.skipped.length ? `; ${done.skipped.length} skipped` : ""}`,
|
|
248641
248650
|
...rows34.length ? formatTable(rows34).split("\n").map((line2) => ` ${line2}`) : [],
|
|
248642
|
-
|
|
248651
|
+
// Each test's evidence under its name when there are several.
|
|
248652
|
+
...tests.flatMap((m) => {
|
|
248653
|
+
const lines2 = m.world.summary?.evidence ? evidenceLines2({ evidence: m.world.summary.evidence, candidates: m.world.summary.candidates ?? [] }) : [];
|
|
248654
|
+
return tests.length > 1 && lines2.length ? [` ${m.world.name}:`, ...lines2.map((line2) => ` ${line2}`)] : lines2;
|
|
248655
|
+
}),
|
|
248643
248656
|
// One test: its checks as well, as `ancha pull` lists them.
|
|
248644
248657
|
...tests.length === 1 ? importedCheckLines(tests[0].world.scene, tests[0].world.summary?.production ?? {}) : [],
|
|
248645
248658
|
...done.skipped.map((s3) => ` skipped ${s3.trace ? `trace ${s3.trace.slice(0, 8)}${files2 && s3.file ? ` (${s3.file})` : ""}` : s3.file}: ${s3.reason}`),
|
|
@@ -249123,12 +249136,12 @@ async function importLocally(ctx, source, options4) {
|
|
|
249123
249136
|
}
|
|
249124
249137
|
function evidenceLines2(made) {
|
|
249125
249138
|
return [
|
|
249126
|
-
...made.evidence.tools.flatMap((t) => [` ${t.name}: ${t.executed} executed, ${t.requested} requested, ${t.reported} reported (${t.calls
|
|
249139
|
+
...made.evidence.tools.flatMap((t) => [` ${t.name}: ${t.executed} executed, ${t.requested} requested, ${t.reported} reported (${plural6(t.calls, "call")})`, ...t.evidence.map((e) => {
|
|
249127
249140
|
const capture4 = e.capture;
|
|
249128
249141
|
return ` ${e.origin}: span ${e.id ?? "no id"}, call ${e.call_id ?? "no id"}; args ${capture4.args}, result ${capture4.result}`;
|
|
249129
249142
|
})]),
|
|
249130
249143
|
...made.evidence.diagnostics.map((d) => ` evidence: ${d.kind} (${d.tool ?? "unnamed tool"}, trace ${d.trace_id}, call ${d.call_id ?? "no id"})`),
|
|
249131
|
-
` candidates: ${made.candidates.length} in candidates.json; select checks with --checks <file>`
|
|
249144
|
+
...made.candidates.length ? [` candidates: ${made.candidates.length} in candidates.json; select checks with --checks <file>`] : []
|
|
249132
249145
|
];
|
|
249133
249146
|
}
|
|
249134
249147
|
|
package/lib/worker.mjs
CHANGED
|
@@ -42547,6 +42547,7 @@ function attemptToolDiagnostics(scene2, trial) {
|
|
|
42547
42547
|
if (!check3) return false;
|
|
42548
42548
|
if ("state" in check3) return Object.keys(check3.state).some((key4) => missing7.has(key4.split(".")[0]));
|
|
42549
42549
|
if ("message" in check3 || "never" in check3) return missing7.has("slack");
|
|
42550
|
+
if ("trace" in check3 || "tool_call" in check3) return false;
|
|
42550
42551
|
return missing7.size > 0;
|
|
42551
42552
|
}).map((c) => c.id);
|
|
42552
42553
|
return AttemptToolDiagnosticsSchema.parse({ toolCalls, ...diagnoses.length && { diagnosis: diagnoses[0], diagnoses, unreachedChecks } });
|
|
@@ -42559,7 +42560,7 @@ function toolDiagnosticLines(attempt) {
|
|
|
42559
42560
|
...(attempt.unreachedChecks?.length ?? 0) > 0 ? [`business checks not reached: ${attempt.unreachedChecks.join(", ")}`] : []
|
|
42560
42561
|
];
|
|
42561
42562
|
}
|
|
42562
|
-
var count2, ToolDiagnosisSchema, AttemptToolDiagnosticsSchema,
|
|
42563
|
+
var count2, ToolDiagnosisSchema, AttemptToolDiagnosticsSchema, toolTitle, toolAccessFix, NETSUITE_WRITES, object4;
|
|
42563
42564
|
var init_attempt_tool_diagnostics = __esm({
|
|
42564
42565
|
"backend/src/attempt-tool-diagnostics.ts"() {
|
|
42565
42566
|
"use strict";
|
|
@@ -42573,8 +42574,8 @@ var init_attempt_tool_diagnostics = __esm({
|
|
|
42573
42574
|
diagnoses: external_exports.array(ToolDiagnosisSchema).optional(),
|
|
42574
42575
|
unreachedChecks: external_exports.array(external_exports.string()).optional()
|
|
42575
42576
|
});
|
|
42576
|
-
toolAccessFix = (tool) => `configure the native SDK using ancha connect ${tool}; health and process exit do not prove agent access`;
|
|
42577
42577
|
toolTitle = (tool) => TOOL_DESCRIPTORS.find((t) => t.name === tool)?.title ?? tool;
|
|
42578
|
+
toolAccessFix = (tool) => `if the agent should call ${toolTitle(tool)} in this test, set up its client with ancha connect ${tool}`;
|
|
42578
42579
|
NETSUITE_WRITES = /* @__PURE__ */ new Set(["ns_createRecord", "ns_transformRecord", "ns_updateRecord", "ns_executeRecordAction", "ns_attachFile", "ns_detachFile"]);
|
|
42579
42580
|
object4 = (value4) => value4 !== null && typeof value4 === "object" ? value4 : {};
|
|
42580
42581
|
}
|
|
@@ -211344,6 +211345,7 @@ var init_agent_outcome = __esm({
|
|
|
211344
211345
|
"use strict";
|
|
211345
211346
|
init_src();
|
|
211346
211347
|
init_agent_fix();
|
|
211348
|
+
init_attempt_tool_diagnostics();
|
|
211347
211349
|
init_gateway();
|
|
211348
211350
|
PROVIDER_KEYS = {
|
|
211349
211351
|
"api.anthropic.com": [/ANTHROPIC|CLAUDE/, "ANTHROPIC_API_KEY"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ancha-labs/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.30",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Simulation playgrounds for agents: run your agent against stateful replicas of Slack, GitHub, Datadog and more, each attempt on a fresh cloud machine in your app.ancha.io workspace, or on your computer.",
|
|
6
6
|
"bugs": {
|