@odla-ai/harness 0.11.13 → 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.
@@ -82,7 +82,8 @@ function codeToolRequestPresentation(request) {
82
82
  }
83
83
  function codeToolResultPresentation(request, response) {
84
84
  const started = codeToolRequestPresentation(request);
85
- if (!started || !response.ok) return 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-OXWLPB7P.js.map
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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AAM;AAC9C,SAAO,GAAG,IAAI,GAAG,GAAG,GAAG,OAAO,MAAM,EAAE,qBAAqB,KAAK,SAAS,IAAI,OAAO,CAAC;AACvF;AAGA,IAAM,yBAAiD;AAAA,EACrD,+BAA+B;AAAA,EAC/B,iCAAiC;AACnC;AAOO,SAAS,eAAe,OAKT;AACpB,QAAM,MAAM,MAAM,OAAO,KAAK;AAC9B,SAAO;AAAA,IACL,SAAS,OAAO,SAAS,YAAY;AACnC,YAAM,YAAY,IAAI;AAGtB,YAAM,cAAc,MAAM,eAAe,QAAQ,SAAS;AAC1D,YAAM,sBAAsB,4BAA4B,OAAO;AAC/D,YAAM,MAAM,KAAK;AAAA,QACf,MAAM;AAAA,QAAQ,OAAO;AAAA,QAAW,MAAM,QAAQ;AAAA,QAAM;AAAA,QACpD,GAAI,sBAAsB,EAAE,cAAc,oBAAoB,IAAI,CAAC;AAAA,MACrE,CAAC;AACD,YAAM,WAAW,MAAM,MAAM,OAAO,QAAQ,SAAS,OAAO;AAC5D,YAAM,wBAAwB,2BAA2B,SAAS,QAAQ;AAC1E,YAAM,gBAAgB,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-OXWLPB7P.js";
3
+ } from "./chunk-6T26HEWI.js";
4
4
  import {
5
5
  SECRET_WORKSPACE_FILE,
6
6
  SKIP_WORKSPACE_DIRS,
@@ -3629,7 +3629,7 @@ function describeProofRecipes(proven, proof, envelope) {
3629
3629
  function createCodeRuntimeToolBroker(input, lease, role) {
3630
3630
  const broker = createCodeToolBroker({
3631
3631
  recipes: input.recipes,
3632
- recipeExecutor: createContainerRecipeExecutor(input.engine),
3632
+ recipeExecutor: input.recipeExecutor ?? createContainerRecipeExecutor(input.engine),
3633
3633
  recipeAuthorization: input.recipeAuthorization ?? "registered_recipe",
3634
3634
  readerId: `code-session:${lease.task.taskId}`,
3635
3635
  readOnlyPrefixes: [".odla-references"]
@@ -3647,6 +3647,19 @@ function createCodeRuntimeToolBroker(input, lease, role) {
3647
3647
  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
3648
  }
3649
3649
 
3650
+ // src/code-runtime-engine-report.ts
3651
+ async function recordSessionFailure(options, command, active, value) {
3652
+ active.failure = value.slice(0, 2e3);
3653
+ if (active.acknowledged) {
3654
+ await options.control.reportSessionFailure(command.sessionId, active.failure).catch(() => void 0);
3655
+ }
3656
+ }
3657
+ async function recordDiagnostic(options, command, active, value) {
3658
+ const detail = value.trim().slice(0, 2e3) || "Theseus runtime failed";
3659
+ options.onDiagnostic?.(detail);
3660
+ await appendCodeRuntimeEvent(options.control, command, { type: "diagnostic", level: "error", message: detail }, active.conversationRefs).catch(() => void 0);
3661
+ }
3662
+
3650
3663
  // src/code-runtime-goal.ts
3651
3664
  var POSITIVE = (value) => Number.isFinite(value) && Number(value) > 0 ? Number(value) : void 0;
3652
3665
  function codeGoalSpec(payload) {
@@ -3882,10 +3895,11 @@ var TheseusRuntimeEngine = class {
3882
3895
  this.options = options;
3883
3896
  this.#attempt = options.runAgentAttempt ?? runCodeAgentAttempt;
3884
3897
  this.#buildPolicyDigest = digestRuntimeValue(JSON.stringify(options.recipes));
3898
+ this.#recipeExecutor = options.recipeExecutor ?? createContainerRecipeExecutor(options.engine, { dependencies: options.recipeDependencies ?? null });
3885
3899
  this.#checkpoints = new CodeRuntimeCheckpointManager({
3886
3900
  control: options.control,
3887
3901
  recipes: options.recipes,
3888
- recipeExecutor: options.recipeExecutor ?? createContainerRecipeExecutor(options.engine, { dependencies: options.recipeDependencies ?? null }),
3902
+ recipeExecutor: this.#recipeExecutor,
3889
3903
  fallbackPolicyDigest: this.#buildPolicyDigest,
3890
3904
  event: (command, event, refs) => this.#event(command, event, refs)
3891
3905
  });
@@ -3895,6 +3909,8 @@ var TheseusRuntimeEngine = class {
3895
3909
  #attempt;
3896
3910
  #buildPolicyDigest;
3897
3911
  #checkpoints;
3912
+ /** One executor for the session broker, the verifier and goal pursuit, built with the host's dependency tree. */
3913
+ #recipeExecutor;
3898
3914
  execute(command) {
3899
3915
  if (command.kind === "checkpoint_stop") return this.#checkpoint(command);
3900
3916
  if (command.kind === "pursue") return this.#pursue(command);
@@ -3967,9 +3983,9 @@ var TheseusRuntimeEngine = class {
3967
3983
  active.done = startGate.ready.then((run) => run ? this.#runAttempt(command, metadata, active) : null).catch(async (cause) => {
3968
3984
  const detail = runtimeErrorMessage(cause);
3969
3985
  await this.#event(command, { type: "message", actor: "system", body: detail }, conversationRefs).catch(() => void 0);
3970
- await this.#diagnostic(command, active, detail);
3986
+ await recordDiagnostic(this.options, command, active, detail);
3971
3987
  await this.#event(command, { type: "status", status: "failed" }, conversationRefs).catch(() => void 0);
3972
- await this.#failure(command, active, detail);
3988
+ await recordSessionFailure(this.options, command, active, detail);
3973
3989
  return null;
3974
3990
  });
3975
3991
  return {
@@ -3993,7 +4009,7 @@ var TheseusRuntimeEngine = class {
3993
4009
  active.done = startGoalPursuit({
3994
4010
  spec,
3995
4011
  recipes: active.recipes,
3996
- recipeExecutor: this.options.recipeExecutor ?? createContainerRecipeExecutor(this.options.engine, { dependencies: this.options.recipeDependencies ?? null }),
4012
+ recipeExecutor: this.#recipeExecutor,
3997
4013
  workspace: active.workspace,
3998
4014
  baseCommitSha: active.baseCommitSha,
3999
4015
  trustedBaseDigest: active.trustedBaseDigest,
@@ -4015,8 +4031,8 @@ var TheseusRuntimeEngine = class {
4015
4031
  }, active)
4016
4032
  }).catch(async (cause) => {
4017
4033
  const detail = runtimeErrorMessage(cause);
4018
- await this.#diagnostic(command, active, detail);
4019
- await this.#failure(command, active, detail);
4034
+ await recordDiagnostic(this.options, command, active, detail);
4035
+ await recordSessionFailure(this.options, command, active, detail);
4020
4036
  return { status: "failed", finalText: "", error: detail };
4021
4037
  });
4022
4038
  return { status: "running", message: `Pursuing the goal, up to ${spec.budget.maxAttempts} attempt(s)` };
@@ -4063,9 +4079,9 @@ var TheseusRuntimeEngine = class {
4063
4079
  { type: "message", actor: "system", body: detail },
4064
4080
  active.conversationRefs
4065
4081
  ).catch(() => void 0);
4066
- await this.#diagnostic(command, active, detail);
4082
+ await recordDiagnostic(this.options, command, active, detail);
4067
4083
  await this.#event(command, { type: "status", status: "failed" }, active.conversationRefs).catch(() => void 0);
4068
- await this.#failure(command, active, detail);
4084
+ await recordSessionFailure(this.options, command, active, detail);
4069
4085
  return null;
4070
4086
  });
4071
4087
  return { status: "running", message: "Theseus accepted the owner prompt" };
@@ -4075,6 +4091,7 @@ var TheseusRuntimeEngine = class {
4075
4091
  const broker = this.#observed(command, active, createCodeRuntimeToolBroker({
4076
4092
  recipes: active.recipes,
4077
4093
  engine: this.options.engine,
4094
+ recipeExecutor: this.#recipeExecutor,
4078
4095
  recipeAuthorization: this.options.recipeAuthorization
4079
4096
  }, lease, metadata.role));
4080
4097
  const startedAt = Date.now();
@@ -4117,8 +4134,8 @@ var TheseusRuntimeEngine = class {
4117
4134
  durationMs: Date.now() - startedAt
4118
4135
  }, active.conversationRefs).catch(() => void 0);
4119
4136
  if (!completed) {
4120
- await this.#diagnostic(command, active, detail);
4121
- await this.#failure(command, active, detail);
4137
+ await recordDiagnostic(this.options, command, active, detail);
4138
+ await recordSessionFailure(this.options, command, active, detail);
4122
4139
  }
4123
4140
  return {
4124
4141
  ...result,
@@ -4143,21 +4160,6 @@ var TheseusRuntimeEngine = class {
4143
4160
  this.#active.delete(command.sessionId);
4144
4161
  return result;
4145
4162
  }
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
4163
  async #event(command, event, refs) {
4162
4164
  await appendCodeRuntimeEvent(this.options.control, command, event, refs);
4163
4165
  }
@@ -4232,4 +4234,4 @@ export {
4232
4234
  withProofRecipes,
4233
4235
  TheseusRuntimeEngine
4234
4236
  };
4235
- //# sourceMappingURL=chunk-B2PQAORN.js.map
4237
+ //# sourceMappingURL=chunk-ZXUN2STV.js.map