@odla-ai/harness 0.11.12 → 0.11.14

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.
@@ -1252,6 +1252,10 @@ function parseMemory(value) {
1252
1252
  function execute(engine, args, name, recipe2, signal) {
1253
1253
  return runContainerCommand(engine, args, name, { timeoutMs: recipe2.timeoutMs, maxOutputBytes: recipe2.maxOutputBytes }, signal);
1254
1254
  }
1255
+ var CONTAINER_PROGRESS = /^\[\d+\/\d+\] .*$/gm;
1256
+ function recipeOutput(engine, stderr) {
1257
+ return engine === "container" ? stderr.replace(CONTAINER_PROGRESS, "").replace(/^\n+/, "") : stderr;
1258
+ }
1255
1259
  function runContainerCommand(engine, args, name, recipe2, signal) {
1256
1260
  return new Promise((accept, reject) => {
1257
1261
  const started = Date.now();
@@ -1294,7 +1298,7 @@ function runContainerCommand(engine, args, name, recipe2, signal) {
1294
1298
  accept({
1295
1299
  exitCode: code ?? 1,
1296
1300
  stdout: Buffer.concat(stdout).toString("utf8"),
1297
- stderr: Buffer.concat(stderr).toString("utf8"),
1301
+ stderr: recipeOutput(engine, Buffer.concat(stderr).toString("utf8")),
1298
1302
  durationMs: Date.now() - started,
1299
1303
  outputLimitExceeded,
1300
1304
  timedOut
@@ -2799,7 +2803,8 @@ function codeToolRequestPresentation(request) {
2799
2803
  }
2800
2804
  function codeToolResultPresentation(request, response2) {
2801
2805
  const started = codeToolRequestPresentation(request);
2802
- if (!started || !response2.ok) return started;
2806
+ if (!started) return void 0;
2807
+ if (!response2.ok && started.kind !== "recipe") return started;
2803
2808
  const details = record3(response2.details);
2804
2809
  if (started.kind === "read") {
2805
2810
  return {
@@ -2846,7 +2851,10 @@ function toolFailureReason(response2) {
2846
2851
  if (response2.ok) return void 0;
2847
2852
  const supplied = response2.details?.failureReason;
2848
2853
  const reason = typeof supplied === "string" && supplied || DEFAULT_FAILURE_REASON[response2.content] || response2.content || "tool request failed; inspect the tool input and workspace state";
2849
- return reason.slice(0, MAX_FAILURE_REASON);
2854
+ if (reason.length <= MAX_FAILURE_REASON) return reason;
2855
+ const head = reason.slice(0, 60);
2856
+ const gap = " \u2026 ";
2857
+ return `${head}${gap}${reason.slice(-(MAX_FAILURE_REASON - head.length - gap.length))}`;
2850
2858
  }
2851
2859
  var DEFAULT_FAILURE_REASON = {
2852
2860
  "tool denied by CaMeL policy": "tool denied by CaMeL policy",
@@ -3741,7 +3749,7 @@ function validateOptions(options) {
3741
3749
  function createCodeRuntimeToolBroker(input, lease, role) {
3742
3750
  const broker = createCodeToolBroker({
3743
3751
  recipes: input.recipes,
3744
- recipeExecutor: createContainerRecipeExecutor(input.engine),
3752
+ recipeExecutor: input.recipeExecutor ?? createContainerRecipeExecutor(input.engine),
3745
3753
  recipeAuthorization: input.recipeAuthorization ?? "registered_recipe",
3746
3754
  readerId: `code-session:${lease.task.taskId}`,
3747
3755
  readOnlyPrefixes: [".odla-references"]
@@ -3759,6 +3767,31 @@ function createCodeRuntimeToolBroker(input, lease, role) {
3759
3767
  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" }) };
3760
3768
  }
3761
3769
 
3770
+ // src/code-runtime-events.ts
3771
+ var import_node_crypto4 = require("crypto");
3772
+ async function appendCodeRuntimeEvent(control, command, event, refs) {
3773
+ const eventId = `${command.commandId.slice(0, 45)}:${refs.length + 1}`;
3774
+ refs.push(eventId);
3775
+ const attributed = { ...event, interactionId: command.commandId };
3776
+ const bounded = attributed.type === "message" ? { ...attributed, body: attributed.body.trim().slice(0, 2e4) || `${attributed.actor} event` } : attributed;
3777
+ await control.appendSessionEvent(command.sessionId, eventId, bounded);
3778
+ }
3779
+ var digestRuntimeValue = (value) => `sha256:${(0, import_node_crypto4.createHash)("sha256").update(value).digest("hex")}`;
3780
+ var runtimeErrorMessage = (value) => value instanceof Error ? value.message : String(value);
3781
+
3782
+ // src/code-runtime-engine-report.ts
3783
+ async function recordSessionFailure(options, command, active, value) {
3784
+ active.failure = value.slice(0, 2e3);
3785
+ if (active.acknowledged) {
3786
+ await options.control.reportSessionFailure(command.sessionId, active.failure).catch(() => void 0);
3787
+ }
3788
+ }
3789
+ async function recordDiagnostic(options, command, active, value) {
3790
+ const detail = value.trim().slice(0, 2e3) || "Theseus runtime failed";
3791
+ options.onDiagnostic?.(detail);
3792
+ await appendCodeRuntimeEvent(options.control, command, { type: "diagnostic", level: "error", message: detail }, active.conversationRefs).catch(() => void 0);
3793
+ }
3794
+
3762
3795
  // src/code-memory.ts
3763
3796
  var import_graph2 = require("@odla-ai/graph");
3764
3797
  var MAX_MEMORY_BODY = 4e3;
@@ -4047,18 +4080,6 @@ async function startGoalPursuit(input) {
4047
4080
  return { status: run.met ? "completed" : "failed", finalText: "" };
4048
4081
  }
4049
4082
 
4050
- // src/code-runtime-events.ts
4051
- var import_node_crypto4 = require("crypto");
4052
- async function appendCodeRuntimeEvent(control, command, event, refs) {
4053
- const eventId = `${command.commandId.slice(0, 45)}:${refs.length + 1}`;
4054
- refs.push(eventId);
4055
- const attributed = { ...event, interactionId: command.commandId };
4056
- const bounded = attributed.type === "message" ? { ...attributed, body: attributed.body.trim().slice(0, 2e4) || `${attributed.actor} event` } : attributed;
4057
- await control.appendSessionEvent(command.sessionId, eventId, bounded);
4058
- }
4059
- var digestRuntimeValue = (value) => `sha256:${(0, import_node_crypto4.createHash)("sha256").update(value).digest("hex")}`;
4060
- var runtimeErrorMessage = (value) => value instanceof Error ? value.message : String(value);
4061
-
4062
4083
  // src/code-runtime-acknowledgement-gate.ts
4063
4084
  function codeRuntimeAcknowledgementGate(signal) {
4064
4085
  let settle;
@@ -4246,10 +4267,11 @@ var TheseusRuntimeEngine = class {
4246
4267
  this.options = options;
4247
4268
  this.#attempt = options.runAgentAttempt ?? runCodeAgentAttempt;
4248
4269
  this.#buildPolicyDigest = digestRuntimeValue(JSON.stringify(options.recipes));
4270
+ this.#recipeExecutor = options.recipeExecutor ?? createContainerRecipeExecutor(options.engine, { dependencies: options.recipeDependencies ?? null });
4249
4271
  this.#checkpoints = new CodeRuntimeCheckpointManager({
4250
4272
  control: options.control,
4251
4273
  recipes: options.recipes,
4252
- recipeExecutor: options.recipeExecutor ?? createContainerRecipeExecutor(options.engine, { dependencies: options.recipeDependencies ?? null }),
4274
+ recipeExecutor: this.#recipeExecutor,
4253
4275
  fallbackPolicyDigest: this.#buildPolicyDigest,
4254
4276
  event: (command, event, refs) => this.#event(command, event, refs)
4255
4277
  });
@@ -4259,6 +4281,8 @@ var TheseusRuntimeEngine = class {
4259
4281
  #attempt;
4260
4282
  #buildPolicyDigest;
4261
4283
  #checkpoints;
4284
+ /** One executor for the session broker, the verifier and goal pursuit, built with the host's dependency tree. */
4285
+ #recipeExecutor;
4262
4286
  execute(command) {
4263
4287
  if (command.kind === "checkpoint_stop") return this.#checkpoint(command);
4264
4288
  if (command.kind === "pursue") return this.#pursue(command);
@@ -4331,9 +4355,9 @@ var TheseusRuntimeEngine = class {
4331
4355
  active.done = startGate.ready.then((run) => run ? this.#runAttempt(command, metadata, active) : null).catch(async (cause) => {
4332
4356
  const detail = runtimeErrorMessage(cause);
4333
4357
  await this.#event(command, { type: "message", actor: "system", body: detail }, conversationRefs).catch(() => void 0);
4334
- await this.#diagnostic(command, active, detail);
4358
+ await recordDiagnostic(this.options, command, active, detail);
4335
4359
  await this.#event(command, { type: "status", status: "failed" }, conversationRefs).catch(() => void 0);
4336
- await this.#failure(command, active, detail);
4360
+ await recordSessionFailure(this.options, command, active, detail);
4337
4361
  return null;
4338
4362
  });
4339
4363
  return {
@@ -4357,7 +4381,7 @@ var TheseusRuntimeEngine = class {
4357
4381
  active.done = startGoalPursuit({
4358
4382
  spec,
4359
4383
  recipes: active.recipes,
4360
- recipeExecutor: this.options.recipeExecutor ?? createContainerRecipeExecutor(this.options.engine, { dependencies: this.options.recipeDependencies ?? null }),
4384
+ recipeExecutor: this.#recipeExecutor,
4361
4385
  workspace: active.workspace,
4362
4386
  baseCommitSha: active.baseCommitSha,
4363
4387
  trustedBaseDigest: active.trustedBaseDigest,
@@ -4379,8 +4403,8 @@ var TheseusRuntimeEngine = class {
4379
4403
  }, active)
4380
4404
  }).catch(async (cause) => {
4381
4405
  const detail = runtimeErrorMessage(cause);
4382
- await this.#diagnostic(command, active, detail);
4383
- await this.#failure(command, active, detail);
4406
+ await recordDiagnostic(this.options, command, active, detail);
4407
+ await recordSessionFailure(this.options, command, active, detail);
4384
4408
  return { status: "failed", finalText: "", error: detail };
4385
4409
  });
4386
4410
  return { status: "running", message: `Pursuing the goal, up to ${spec.budget.maxAttempts} attempt(s)` };
@@ -4427,9 +4451,9 @@ var TheseusRuntimeEngine = class {
4427
4451
  { type: "message", actor: "system", body: detail },
4428
4452
  active.conversationRefs
4429
4453
  ).catch(() => void 0);
4430
- await this.#diagnostic(command, active, detail);
4454
+ await recordDiagnostic(this.options, command, active, detail);
4431
4455
  await this.#event(command, { type: "status", status: "failed" }, active.conversationRefs).catch(() => void 0);
4432
- await this.#failure(command, active, detail);
4456
+ await recordSessionFailure(this.options, command, active, detail);
4433
4457
  return null;
4434
4458
  });
4435
4459
  return { status: "running", message: "Theseus accepted the owner prompt" };
@@ -4439,6 +4463,7 @@ var TheseusRuntimeEngine = class {
4439
4463
  const broker = this.#observed(command, active, createCodeRuntimeToolBroker({
4440
4464
  recipes: active.recipes,
4441
4465
  engine: this.options.engine,
4466
+ recipeExecutor: this.#recipeExecutor,
4442
4467
  recipeAuthorization: this.options.recipeAuthorization
4443
4468
  }, lease, metadata.role));
4444
4469
  const startedAt = Date.now();
@@ -4481,8 +4506,8 @@ var TheseusRuntimeEngine = class {
4481
4506
  durationMs: Date.now() - startedAt
4482
4507
  }, active.conversationRefs).catch(() => void 0);
4483
4508
  if (!completed) {
4484
- await this.#diagnostic(command, active, detail);
4485
- await this.#failure(command, active, detail);
4509
+ await recordDiagnostic(this.options, command, active, detail);
4510
+ await recordSessionFailure(this.options, command, active, detail);
4486
4511
  }
4487
4512
  return {
4488
4513
  ...result,
@@ -4507,21 +4532,6 @@ var TheseusRuntimeEngine = class {
4507
4532
  this.#active.delete(command.sessionId);
4508
4533
  return result;
4509
4534
  }
4510
- async #failure(command, active, value) {
4511
- active.failure = value.slice(0, 2e3);
4512
- if (active.acknowledged) {
4513
- await this.options.control.reportSessionFailure(command.sessionId, active.failure).catch(() => void 0);
4514
- }
4515
- }
4516
- async #diagnostic(command, active, value) {
4517
- const detail = value.trim().slice(0, 2e3) || "Theseus runtime failed";
4518
- this.options.onDiagnostic?.(detail);
4519
- await this.#event(
4520
- command,
4521
- { type: "diagnostic", level: "error", message: detail },
4522
- active.conversationRefs
4523
- ).catch(() => void 0);
4524
- }
4525
4535
  async #event(command, event, refs) {
4526
4536
  await appendCodeRuntimeEvent(this.options.control, command, event, refs);
4527
4537
  }