@odla-ai/harness 0.11.13 → 0.11.15
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/dist/{chunk-OXWLPB7P.js → chunk-6T26HEWI.js} +3 -2
- package/dist/chunk-6T26HEWI.js.map +1 -0
- package/dist/{chunk-B2PQAORN.js → chunk-ZYZN43G4.js} +46 -30
- package/dist/chunk-ZYZN43G4.js.map +1 -0
- package/dist/code-runtime-cli.cjs +58 -41
- package/dist/code-runtime-cli.cjs.map +1 -1
- package/dist/code-runtime-cli.js +2 -2
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/node.cjs +58 -41
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-B2PQAORN.js.map +0 -1
- package/dist/chunk-OXWLPB7P.js.map +0 -1
|
@@ -82,7 +82,8 @@ function codeToolRequestPresentation(request) {
|
|
|
82
82
|
}
|
|
83
83
|
function codeToolResultPresentation(request, response) {
|
|
84
84
|
const started = codeToolRequestPresentation(request);
|
|
85
|
-
if (!started
|
|
85
|
+
if (!started) return void 0;
|
|
86
|
+
if (!response.ok && started.kind !== "recipe") return started;
|
|
86
87
|
const details = record(response.details);
|
|
87
88
|
if (started.kind === "read") {
|
|
88
89
|
return {
|
|
@@ -175,4 +176,4 @@ export {
|
|
|
175
176
|
toolFailureReason,
|
|
176
177
|
observedBroker
|
|
177
178
|
};
|
|
178
|
-
//# sourceMappingURL=chunk-
|
|
179
|
+
//# sourceMappingURL=chunk-6T26HEWI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/code-tool-presentation.ts","../src/code-runtime-observer.ts"],"sourcesContent":["import type {\n CodeToolLocationPreview, CodeToolPresentation, HarnessToolRequest, HarnessToolResponse,\n} from \"./types\";\n\nconst text = (value: unknown, maximum: number): string | undefined => {\n if (typeof value !== \"string\") return undefined;\n const bounded = value.replace(/[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f]/g, \" \").trim();\n return bounded ? bounded.slice(0, maximum) : undefined;\n};\nconst integer = (value: unknown): number | undefined =>\n Number.isSafeInteger(value) && Number(value) >= 0 ? Number(value) : undefined;\nconst record = (value: unknown): Record<string, unknown> | undefined =>\n value && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown> : undefined;\nconst excerpt = (value: unknown, tail = false): string | undefined => {\n if (typeof value !== \"string\") return undefined;\n const safe = value.replace(/[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f]/g, \" \");\n const source = (tail ? safe.slice(-10_000) : safe.slice(0, 10_000)).trim();\n if (!source) return undefined;\n const lines = source.split(\"\\n\").filter((line) => line.trim()).map((line) => line.slice(0, 240));\n const selected = tail ? lines.slice(-10) : lines.slice(0, 10);\n return text(selected.join(\"\\n\"), 2_400);\n};\nconst paths = (value: unknown): string[] | undefined => {\n if (!Array.isArray(value)) return undefined;\n const items = value.flatMap((item) => {\n const path = text(item, 1_024);\n return path ? [path] : [];\n }).slice(0, 12);\n return items.length ? items : undefined;\n};\n\nfunction patchStats(value: unknown): { additions?: number; deletions?: number } {\n if (typeof value !== \"string\") return {};\n let additions = 0;\n let deletions = 0;\n for (const line of value.slice(0, 262_144).split(\"\\n\")) {\n if (line.startsWith(\"+++\") || line.startsWith(\"---\")) continue;\n if (line.startsWith(\"+\")) additions += 1;\n else if (line.startsWith(\"-\")) deletions += 1;\n }\n return { ...(additions ? { additions } : {}), ...(deletions ? { deletions } : {}) };\n}\n\nfunction searchResults(value: unknown): CodeToolLocationPreview[] | undefined {\n if (typeof value !== \"string\") return undefined;\n const results = value.split(\"\\n\").flatMap((line) => {\n const match = /^([^:\\n]{1,1024}):(\\d+):\\s?(.*)$/.exec(line);\n if (!match) return [];\n const lineNumber = Number(match[2]);\n const itemText = text(match[3], 240);\n if (!Number.isSafeInteger(lineNumber) || lineNumber < 1) return [];\n return [{ path: match[1]!, line: lineNumber, ...(itemText ? { text: itemText } : {}) }];\n }).slice(0, 5);\n return results.length ? results : undefined;\n}\n\n/** Produce the bounded presentation available as soon as a broker call starts. */\nexport function codeToolRequestPresentation(request: HarnessToolRequest): CodeToolPresentation | undefined {\n const input = request.input;\n if (request.tool === \"sandbox.read\") {\n const path = text(input.path, 1_024);\n if (!path) return undefined;\n const startLine = integer(input.startLine);\n const endLine = integer(input.endLine);\n return { kind: \"read\", path, ...(startLine ? { startLine } : {}), ...(endLine ? { endLine } : {}) };\n }\n if (request.tool === \"sandbox.list\") {\n const scope = text(input.prefix, 1_024);\n return { kind: \"list\", ...(scope ? { scope } : {}) };\n }\n if (request.tool === \"sandbox.search\" || request.tool === \"sandbox.overview\"\n || request.tool === \"sandbox.where_is\" || request.tool === \"sandbox.who_imports\"\n || request.tool === \"sandbox.who_touches\") {\n const query = text(input.query, 512);\n const scope = request.tool === \"sandbox.search\" ? text(input.prefix, 1_024) : undefined;\n if (request.tool === \"sandbox.search\" && !query) return undefined;\n return { kind: \"query\", ...(query ? { query } : {}), ...(scope ? { scope } : {}) };\n }\n if (request.tool === \"sandbox.apply_patch\") {\n return { kind: \"patch\", ...patchStats(input.patch) };\n }\n if (request.tool === \"sandbox.edit\") {\n const lines = (value: unknown) => (typeof value === \"string\" ? value.slice(0, 262_144).split(\"\\n\").length : 0);\n return { kind: \"patch\", additions: lines(input.newText), deletions: lines(input.oldText) };\n }\n if (request.tool === \"sandbox.write\") {\n const path = text(input.path, 1_024);\n const additions = typeof input.content === \"string\" ? input.content.slice(0, 262_144).split(\"\\n\").length : 0;\n return { kind: \"patch\", additions, ...(path ? { paths: [path] } : {}) };\n }\n const recipeId = text(input.recipeId, 120);\n return recipeId ? { kind: \"recipe\", recipeId } : undefined;\n}\n\n/** Enrich a started presentation with only the broker's bounded result shape. */\nexport function codeToolResultPresentation(\n request: HarnessToolRequest,\n response: HarnessToolResponse,\n): CodeToolPresentation | undefined {\n const started = codeToolRequestPresentation(request);\n if (!started) return undefined;\n // A failed read or search has nothing to show but its reason; a failed\n // recipe is the one result whose output matters most, and a bounded reason\n // showed nothing of a red test run (bug eff741ee).\n if (!response.ok && started.kind !== \"recipe\") return started;\n const details = record(response.details);\n if (started.kind === \"read\") {\n return {\n ...started,\n ...(integer(details?.startLine) ? { startLine: integer(details?.startLine) } : {}),\n ...(integer(details?.endLine) ? { endLine: integer(details?.endLine) } : {}),\n ...(excerpt(response.content) ? { excerpt: excerpt(response.content) } : {}),\n };\n }\n if (started.kind === \"list\") {\n const listed = response.content.split(\"\\n\")\n .filter((line) => line && !line.startsWith(\"…\") && !line.startsWith(\"Workspace \"))\n .map((line) => text(line, 1_024)).filter((line): line is string => Boolean(line)).slice(0, 8);\n return {\n ...started,\n ...(integer(details?.count) !== undefined ? { count: integer(details?.count) } : {}),\n ...(listed.length ? { paths: listed } : {}),\n };\n }\n if (started.kind === \"query\") {\n const results = request.tool === \"sandbox.search\" ? searchResults(response.content) : undefined;\n const resultExcerpt = request.tool === \"sandbox.search\" ? undefined : excerpt(response.content);\n return {\n ...started,\n ...(integer(details?.count) !== undefined ? { count: integer(details?.count) } : {}),\n ...(results ? { results } : {}),\n ...(resultExcerpt ? { excerpt: resultExcerpt } : {}),\n };\n }\n if (started.kind === \"patch\") {\n return { ...started, ...(paths(details?.paths) ? { paths: paths(details?.paths) } : {}) };\n }\n const output = response.content.replace(/^Recipe [^\\n]*\\.?\\s*/u, \"\");\n return {\n ...started,\n ...(integer(details?.exitCode) !== undefined ? { exitCode: integer(details?.exitCode) } : {}),\n ...(typeof details?.timedOut === \"boolean\" ? { timedOut: details.timedOut } : {}),\n ...(typeof details?.outputLimitExceeded === \"boolean\"\n ? { outputLimitExceeded: details.outputLimitExceeded } : {}),\n ...(excerpt(output, true) ? { excerpt: excerpt(output, true) } : {}),\n };\n}\n","// Reporting a brokered tool effect onto the session event stream.\n//\n// Split out of code-runtime-engine.ts, which was one line under the 250 LOC cap\n// and so could not absorb the failure reason below (PM bug c775485c: the same\n// two lines left PR #684 red and unlandable). The seam is real rather than\n// convenient — this is the only code in the engine that translates a broker\n// call into what a watcher sees, and it is the only code that needs to know how\n// a failure is described.\n\nimport { codeToolRequestPresentation, codeToolResultPresentation } from \"./code-tool-presentation\";\nimport type { CodeSessionEventData, HarnessToolBroker, HarnessToolResponse } from \"./types\";\n\n/** Longest failure reason forwarded onto a session event. A reason is a short\n * diagnostic for a human or an agent reading the stream, never a transcript. */\nexport const MAX_FAILURE_REASON = 240;\n\n/** The bounded reason a failed tool response carries, if it carries one.\n *\n * Only `response.ok` used to reach the stream, so a watcher saw that a call\n * failed and could never see why — which is what made an 84% apply_patch\n * failure rate undiagnosable (PM bugs 515655ec and 38d92f1d). */\nexport function toolFailureReason(response: HarnessToolResponse): string | undefined {\n if (response.ok) return undefined;\n // Guaranteed here rather than only where the response is built, because this\n // is the boundary that emits the event: a failure reaching the stream without\n // a reason is the defect, whoever constructed the response.\n const supplied = response.details?.failureReason;\n const reason = (typeof supplied === \"string\" && supplied)\n || DEFAULT_FAILURE_REASON[response.content]\n || response.content\n || \"tool request failed; inspect the tool input and workspace state\";\n if (reason.length <= MAX_FAILURE_REASON) return reason;\n // A test runner states its verdict last, so a reason that must be cut keeps\n // its first line and its tail rather than a head that ends mid-preamble.\n const head = reason.slice(0, 60); const gap = \" … \";\n return `${head}${gap}${reason.slice(-(MAX_FAILURE_REASON - head.length - gap.length))}`;\n}\n\n/** Reasons for the two refusals the broker states as bare content. */\nconst DEFAULT_FAILURE_REASON: Record<string, string> = {\n \"tool denied by CaMeL policy\": \"tool denied by CaMeL policy\",\n \"review sessions are read-only\": \"review session is read-only; workspace changes are not permitted\",\n};\n\n/** Wrap `broker` so every effect reports its start and its finish.\n *\n * `emit` is the engine's own event sink; it already swallows its own errors, so\n * reporting can never fail the effect it is reporting on.\n */\nexport function observedBroker(input: {\n broker: HarnessToolBroker;\n operationIdFor: (requestId: string) => string;\n emit: (event: CodeSessionEventData) => Promise<void>;\n now?: () => number;\n}): HarnessToolBroker {\n const now = input.now ?? Date.now;\n return {\n execute: async (context, request) => {\n const startedAt = now();\n // Stable and opaque: an older container may choose any bounded request\n // id, while the owner stream admits only a closed printable id shape.\n const operationId = input.operationIdFor(request.requestId);\n const startedPresentation = codeToolRequestPresentation(request);\n await input.emit({\n type: \"tool\", phase: \"started\", tool: request.tool, operationId,\n ...(startedPresentation ? { presentation: startedPresentation } : {}),\n });\n const response = await input.broker.execute(context, request);\n const completedPresentation = codeToolResultPresentation(request, response);\n const failureReason = toolFailureReason(response);\n await input.emit({\n type: \"tool\", phase: \"completed\", tool: request.tool,\n ok: response.ok, durationMs: now() - startedAt, operationId,\n ...(failureReason ? { failureReason } : {}),\n ...(completedPresentation ? { presentation: completedPresentation } : {}),\n });\n return response;\n },\n };\n}\n"],"mappings":";AAIA,IAAM,OAAO,CAAC,OAAgB,YAAwC;AACpE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,UAAU,MAAM,QAAQ,mDAAmD,GAAG,EAAE,KAAK;AAC3F,SAAO,UAAU,QAAQ,MAAM,GAAG,OAAO,IAAI;AAC/C;AACA,IAAM,UAAU,CAAC,UACf,OAAO,cAAc,KAAK,KAAK,OAAO,KAAK,KAAK,IAAI,OAAO,KAAK,IAAI;AACtE,IAAM,SAAS,CAAC,UACd,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK,IACtD,QAAmC;AACzC,IAAM,UAAU,CAAC,OAAgB,OAAO,UAA8B;AACpE,MAAI,OAAO,UAAU,SAAU,QAAO;AACtC,QAAM,OAAO,MAAM,QAAQ,mDAAmD,GAAG;AACjF,QAAM,UAAU,OAAO,KAAK,MAAM,IAAO,IAAI,KAAK,MAAM,GAAG,GAAM,GAAG,KAAK;AACzE,MAAI,CAAC,OAAQ,QAAO;AACpB,QAAM,QAAQ,OAAO,MAAM,IAAI,EAAE,OAAO,CAAC,SAAS,KAAK,KAAK,CAAC,EAAE,IAAI,CAAC,SAAS,KAAK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AgB,kBAAkB,QAAQ;AAChD,YAAM,MAAM,KAAK;AAAA,QACf,MAAM;AAAA,QAAQ,OAAO;AAAA,QAAa,MAAM,QAAQ;AAAA,QAChD,IAAI,SAAS;AAAA,QAAI,YAAY,IAAI,IAAI;AAAA,QAAW;AAAA,QAChD,GAAI,gBAAgB,EAAE,cAAc,IAAI,CAAC;AAAA,QACzC,GAAI,wBAAwB,EAAE,cAAc,sBAAsB,IAAI,CAAC;AAAA,MACzE,CAAC;AACD,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observedBroker
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-6T26HEWI.js";
|
|
4
4
|
import {
|
|
5
5
|
SECRET_WORKSPACE_FILE,
|
|
6
6
|
SKIP_WORKSPACE_DIRS,
|
|
@@ -3227,6 +3227,19 @@ async function graphQuery(context, request, options, policy, registry) {
|
|
|
3227
3227
|
return response(request, true, renderWhoTouches(graphs, query));
|
|
3228
3228
|
}
|
|
3229
3229
|
|
|
3230
|
+
// src/code-tool-recipe-output.ts
|
|
3231
|
+
var RECIPE_OUTPUT_HEAD = 4e3;
|
|
3232
|
+
var RECIPE_OUTPUT_TAIL = 24e3;
|
|
3233
|
+
var ANSI = /\u001b\[[0-9;?]*[A-Za-z]/g;
|
|
3234
|
+
function boundedRecipeOutput(output) {
|
|
3235
|
+
const plain = output.replace(ANSI, "");
|
|
3236
|
+
if (plain.length <= RECIPE_OUTPUT_HEAD + RECIPE_OUTPUT_TAIL) return plain;
|
|
3237
|
+
const omitted = plain.length - RECIPE_OUTPUT_HEAD - RECIPE_OUTPUT_TAIL;
|
|
3238
|
+
return `${plain.slice(0, RECIPE_OUTPUT_HEAD)}
|
|
3239
|
+
\u2026 [${omitted} characters omitted; the last ${RECIPE_OUTPUT_TAIL} follow] \u2026
|
|
3240
|
+
${plain.slice(-RECIPE_OUTPUT_TAIL)}`;
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3230
3243
|
// src/code-tool-broker.ts
|
|
3231
3244
|
function createCodeToolBroker(options) {
|
|
3232
3245
|
validateOptions(options);
|
|
@@ -3326,8 +3339,9 @@ async function recipe(context, request, options, recipes, policy) {
|
|
|
3326
3339
|
const output = [result.stdout, result.stderr].filter(Boolean).join("\n");
|
|
3327
3340
|
const ok = result.exitCode === 0 && !result.outputLimitExceeded && !result.timedOut;
|
|
3328
3341
|
const status = result.timedOut ? "timed out" : result.outputLimitExceeded ? "exceeded output limit" : ok ? "passed" : `failed with exit ${result.exitCode}`;
|
|
3329
|
-
|
|
3330
|
-
${
|
|
3342
|
+
const shown = boundedRecipeOutput(output);
|
|
3343
|
+
return response(request, ok, `Recipe ${recipeId} ${status}.${shown ? `
|
|
3344
|
+
${shown}` : ""}`, {
|
|
3331
3345
|
recipeId,
|
|
3332
3346
|
exitCode: result.exitCode,
|
|
3333
3347
|
durationMs: result.durationMs,
|
|
@@ -3629,7 +3643,7 @@ function describeProofRecipes(proven, proof, envelope) {
|
|
|
3629
3643
|
function createCodeRuntimeToolBroker(input, lease, role) {
|
|
3630
3644
|
const broker = createCodeToolBroker({
|
|
3631
3645
|
recipes: input.recipes,
|
|
3632
|
-
recipeExecutor: createContainerRecipeExecutor(input.engine),
|
|
3646
|
+
recipeExecutor: input.recipeExecutor ?? createContainerRecipeExecutor(input.engine),
|
|
3633
3647
|
recipeAuthorization: input.recipeAuthorization ?? "registered_recipe",
|
|
3634
3648
|
readerId: `code-session:${lease.task.taskId}`,
|
|
3635
3649
|
readOnlyPrefixes: [".odla-references"]
|
|
@@ -3647,6 +3661,19 @@ function createCodeRuntimeToolBroker(input, lease, role) {
|
|
|
3647
3661
|
return role === "coding" ? broker : { execute: (context, request) => reviewTools.has(request.tool) ? broker.execute(context, request) : Promise.resolve({ requestId: request.requestId, ok: false, content: "review sessions are read-only" }) };
|
|
3648
3662
|
}
|
|
3649
3663
|
|
|
3664
|
+
// src/code-runtime-engine-report.ts
|
|
3665
|
+
async function recordSessionFailure(options, command, active, value) {
|
|
3666
|
+
active.failure = value.slice(0, 2e3);
|
|
3667
|
+
if (active.acknowledged) {
|
|
3668
|
+
await options.control.reportSessionFailure(command.sessionId, active.failure).catch(() => void 0);
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
async function recordDiagnostic(options, command, active, value) {
|
|
3672
|
+
const detail = value.trim().slice(0, 2e3) || "Theseus runtime failed";
|
|
3673
|
+
options.onDiagnostic?.(detail);
|
|
3674
|
+
await appendCodeRuntimeEvent(options.control, command, { type: "diagnostic", level: "error", message: detail }, active.conversationRefs).catch(() => void 0);
|
|
3675
|
+
}
|
|
3676
|
+
|
|
3650
3677
|
// src/code-runtime-goal.ts
|
|
3651
3678
|
var POSITIVE = (value) => Number.isFinite(value) && Number(value) > 0 ? Number(value) : void 0;
|
|
3652
3679
|
function codeGoalSpec(payload) {
|
|
@@ -3882,10 +3909,11 @@ var TheseusRuntimeEngine = class {
|
|
|
3882
3909
|
this.options = options;
|
|
3883
3910
|
this.#attempt = options.runAgentAttempt ?? runCodeAgentAttempt;
|
|
3884
3911
|
this.#buildPolicyDigest = digestRuntimeValue(JSON.stringify(options.recipes));
|
|
3912
|
+
this.#recipeExecutor = options.recipeExecutor ?? createContainerRecipeExecutor(options.engine, { dependencies: options.recipeDependencies ?? null });
|
|
3885
3913
|
this.#checkpoints = new CodeRuntimeCheckpointManager({
|
|
3886
3914
|
control: options.control,
|
|
3887
3915
|
recipes: options.recipes,
|
|
3888
|
-
recipeExecutor:
|
|
3916
|
+
recipeExecutor: this.#recipeExecutor,
|
|
3889
3917
|
fallbackPolicyDigest: this.#buildPolicyDigest,
|
|
3890
3918
|
event: (command, event, refs) => this.#event(command, event, refs)
|
|
3891
3919
|
});
|
|
@@ -3895,6 +3923,8 @@ var TheseusRuntimeEngine = class {
|
|
|
3895
3923
|
#attempt;
|
|
3896
3924
|
#buildPolicyDigest;
|
|
3897
3925
|
#checkpoints;
|
|
3926
|
+
/** One executor for the session broker, the verifier and goal pursuit, built with the host's dependency tree. */
|
|
3927
|
+
#recipeExecutor;
|
|
3898
3928
|
execute(command) {
|
|
3899
3929
|
if (command.kind === "checkpoint_stop") return this.#checkpoint(command);
|
|
3900
3930
|
if (command.kind === "pursue") return this.#pursue(command);
|
|
@@ -3967,9 +3997,9 @@ var TheseusRuntimeEngine = class {
|
|
|
3967
3997
|
active.done = startGate.ready.then((run) => run ? this.#runAttempt(command, metadata, active) : null).catch(async (cause) => {
|
|
3968
3998
|
const detail = runtimeErrorMessage(cause);
|
|
3969
3999
|
await this.#event(command, { type: "message", actor: "system", body: detail }, conversationRefs).catch(() => void 0);
|
|
3970
|
-
await this
|
|
4000
|
+
await recordDiagnostic(this.options, command, active, detail);
|
|
3971
4001
|
await this.#event(command, { type: "status", status: "failed" }, conversationRefs).catch(() => void 0);
|
|
3972
|
-
await this
|
|
4002
|
+
await recordSessionFailure(this.options, command, active, detail);
|
|
3973
4003
|
return null;
|
|
3974
4004
|
});
|
|
3975
4005
|
return {
|
|
@@ -3993,7 +4023,7 @@ var TheseusRuntimeEngine = class {
|
|
|
3993
4023
|
active.done = startGoalPursuit({
|
|
3994
4024
|
spec,
|
|
3995
4025
|
recipes: active.recipes,
|
|
3996
|
-
recipeExecutor: this
|
|
4026
|
+
recipeExecutor: this.#recipeExecutor,
|
|
3997
4027
|
workspace: active.workspace,
|
|
3998
4028
|
baseCommitSha: active.baseCommitSha,
|
|
3999
4029
|
trustedBaseDigest: active.trustedBaseDigest,
|
|
@@ -4015,8 +4045,8 @@ var TheseusRuntimeEngine = class {
|
|
|
4015
4045
|
}, active)
|
|
4016
4046
|
}).catch(async (cause) => {
|
|
4017
4047
|
const detail = runtimeErrorMessage(cause);
|
|
4018
|
-
await this
|
|
4019
|
-
await this
|
|
4048
|
+
await recordDiagnostic(this.options, command, active, detail);
|
|
4049
|
+
await recordSessionFailure(this.options, command, active, detail);
|
|
4020
4050
|
return { status: "failed", finalText: "", error: detail };
|
|
4021
4051
|
});
|
|
4022
4052
|
return { status: "running", message: `Pursuing the goal, up to ${spec.budget.maxAttempts} attempt(s)` };
|
|
@@ -4063,9 +4093,9 @@ var TheseusRuntimeEngine = class {
|
|
|
4063
4093
|
{ type: "message", actor: "system", body: detail },
|
|
4064
4094
|
active.conversationRefs
|
|
4065
4095
|
).catch(() => void 0);
|
|
4066
|
-
await this
|
|
4096
|
+
await recordDiagnostic(this.options, command, active, detail);
|
|
4067
4097
|
await this.#event(command, { type: "status", status: "failed" }, active.conversationRefs).catch(() => void 0);
|
|
4068
|
-
await this
|
|
4098
|
+
await recordSessionFailure(this.options, command, active, detail);
|
|
4069
4099
|
return null;
|
|
4070
4100
|
});
|
|
4071
4101
|
return { status: "running", message: "Theseus accepted the owner prompt" };
|
|
@@ -4075,6 +4105,7 @@ var TheseusRuntimeEngine = class {
|
|
|
4075
4105
|
const broker = this.#observed(command, active, createCodeRuntimeToolBroker({
|
|
4076
4106
|
recipes: active.recipes,
|
|
4077
4107
|
engine: this.options.engine,
|
|
4108
|
+
recipeExecutor: this.#recipeExecutor,
|
|
4078
4109
|
recipeAuthorization: this.options.recipeAuthorization
|
|
4079
4110
|
}, lease, metadata.role));
|
|
4080
4111
|
const startedAt = Date.now();
|
|
@@ -4117,8 +4148,8 @@ var TheseusRuntimeEngine = class {
|
|
|
4117
4148
|
durationMs: Date.now() - startedAt
|
|
4118
4149
|
}, active.conversationRefs).catch(() => void 0);
|
|
4119
4150
|
if (!completed) {
|
|
4120
|
-
await this
|
|
4121
|
-
await this
|
|
4151
|
+
await recordDiagnostic(this.options, command, active, detail);
|
|
4152
|
+
await recordSessionFailure(this.options, command, active, detail);
|
|
4122
4153
|
}
|
|
4123
4154
|
return {
|
|
4124
4155
|
...result,
|
|
@@ -4143,21 +4174,6 @@ var TheseusRuntimeEngine = class {
|
|
|
4143
4174
|
this.#active.delete(command.sessionId);
|
|
4144
4175
|
return result;
|
|
4145
4176
|
}
|
|
4146
|
-
async #failure(command, active, value) {
|
|
4147
|
-
active.failure = value.slice(0, 2e3);
|
|
4148
|
-
if (active.acknowledged) {
|
|
4149
|
-
await this.options.control.reportSessionFailure(command.sessionId, active.failure).catch(() => void 0);
|
|
4150
|
-
}
|
|
4151
|
-
}
|
|
4152
|
-
async #diagnostic(command, active, value) {
|
|
4153
|
-
const detail = value.trim().slice(0, 2e3) || "Theseus runtime failed";
|
|
4154
|
-
this.options.onDiagnostic?.(detail);
|
|
4155
|
-
await this.#event(
|
|
4156
|
-
command,
|
|
4157
|
-
{ type: "diagnostic", level: "error", message: detail },
|
|
4158
|
-
active.conversationRefs
|
|
4159
|
-
).catch(() => void 0);
|
|
4160
|
-
}
|
|
4161
4177
|
async #event(command, event, refs) {
|
|
4162
4178
|
await appendCodeRuntimeEvent(this.options.control, command, event, refs);
|
|
4163
4179
|
}
|
|
@@ -4232,4 +4248,4 @@ export {
|
|
|
4232
4248
|
withProofRecipes,
|
|
4233
4249
|
TheseusRuntimeEngine
|
|
4234
4250
|
};
|
|
4235
|
-
//# sourceMappingURL=chunk-
|
|
4251
|
+
//# sourceMappingURL=chunk-ZYZN43G4.js.map
|