@odla-ai/harness 0.11.18 → 0.11.19

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.
Files changed (39) hide show
  1. package/dist/{chunk-T2IW7MYQ.js → chunk-4TG55ATB.js} +2 -2
  2. package/dist/{chunk-O47JCUGI.js → chunk-7NP3YOMY.js} +33 -5
  3. package/dist/chunk-7NP3YOMY.js.map +1 -0
  4. package/dist/{chunk-3ON6UAOV.js → chunk-A5B3CEK2.js} +3 -3
  5. package/dist/{chunk-EXSEQEZ6.js → chunk-M6BNH25Z.js} +4 -4
  6. package/dist/{chunk-ONYW2VSB.js → chunk-O4QLHUGO.js} +1 -1
  7. package/dist/chunk-O4QLHUGO.js.map +1 -0
  8. package/dist/{chunk-6T26HEWI.js → chunk-SMN2FWQE.js} +17 -3
  9. package/dist/{chunk-6T26HEWI.js.map → chunk-SMN2FWQE.js.map} +1 -1
  10. package/dist/cli.cjs.map +1 -1
  11. package/dist/cli.js +4 -4
  12. package/dist/code-runtime-cli.cjs +42 -3
  13. package/dist/code-runtime-cli.cjs.map +1 -1
  14. package/dist/code-runtime-cli.js +5 -5
  15. package/dist/code-session-event-data-C6mQB76s.d.cts +134 -0
  16. package/dist/code-session-event-data-wCQc2py3.d.ts +134 -0
  17. package/dist/index.cjs +19 -2
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +15 -4
  20. package/dist/index.d.ts +15 -4
  21. package/dist/index.js +9 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/node.cjs +42 -3
  24. package/dist/node.cjs.map +1 -1
  25. package/dist/node.d.cts +8 -1
  26. package/dist/node.d.ts +8 -1
  27. package/dist/node.js +6 -6
  28. package/dist/testing.cjs.map +1 -1
  29. package/dist/testing.d.cts +1 -1
  30. package/dist/testing.d.ts +1 -1
  31. package/dist/testing.js +1 -1
  32. package/dist/{types-D-Kv1svf.d.ts → types-DM-UgoBN.d.cts} +2 -118
  33. package/dist/{types-D-Kv1svf.d.cts → types-DM-UgoBN.d.ts} +2 -118
  34. package/package.json +1 -1
  35. package/dist/chunk-O47JCUGI.js.map +0 -1
  36. package/dist/chunk-ONYW2VSB.js.map +0 -1
  37. /package/dist/{chunk-T2IW7MYQ.js.map → chunk-4TG55ATB.js.map} +0 -0
  38. /package/dist/{chunk-3ON6UAOV.js.map → chunk-A5B3CEK2.js.map} +0 -0
  39. /package/dist/{chunk-EXSEQEZ6.js.map → chunk-M6BNH25Z.js.map} +0 -0
@@ -7,14 +7,14 @@ import {
7
7
  createCodeRuntimeControlClient,
8
8
  createCodeRuntimeSessionSkillLoader,
9
9
  runCodeRuntimeHeartbeatLoop
10
- } from "./chunk-O47JCUGI.js";
11
- import "./chunk-6T26HEWI.js";
10
+ } from "./chunk-7NP3YOMY.js";
11
+ import "./chunk-SMN2FWQE.js";
12
12
  import {
13
13
  assertPinnedImage,
14
14
  selectContainerEngine
15
- } from "./chunk-3ON6UAOV.js";
16
- import "./chunk-T2IW7MYQ.js";
17
- import "./chunk-ONYW2VSB.js";
15
+ } from "./chunk-A5B3CEK2.js";
16
+ import "./chunk-4TG55ATB.js";
17
+ import "./chunk-O4QLHUGO.js";
18
18
 
19
19
  // src/code-runtime-cli.ts
20
20
  import { cpus, totalmem } from "os";
@@ -0,0 +1,134 @@
1
+ import { f as HarnessToolName } from './types-DM-UgoBN.cjs';
2
+
3
+ /** One bounded result location that an owner may inspect without loading the
4
+ * complete broker result into the activity stream. */
5
+ interface CodeToolLocationPreview {
6
+ path: string;
7
+ line?: number;
8
+ text?: string;
9
+ }
10
+ /** Deliberately small, tool-specific owner presentation. These projections are
11
+ * built after the trusted broker has bounded the corresponding request/result;
12
+ * they are not arbitrary model narration or complete tool output. */
13
+ type CodeToolPresentation = {
14
+ kind: "query";
15
+ query?: string;
16
+ scope?: string;
17
+ count?: number;
18
+ results?: CodeToolLocationPreview[];
19
+ excerpt?: string;
20
+ } | {
21
+ kind: "read";
22
+ path: string;
23
+ startLine?: number;
24
+ endLine?: number;
25
+ excerpt?: string;
26
+ } | {
27
+ kind: "list";
28
+ scope?: string;
29
+ count?: number;
30
+ paths?: string[];
31
+ } | {
32
+ kind: "patch";
33
+ paths?: string[];
34
+ additions?: number;
35
+ deletions?: number;
36
+ } | {
37
+ kind: "recipe";
38
+ recipeId: string;
39
+ exitCode?: number;
40
+ timedOut?: boolean;
41
+ outputLimitExceeded?: boolean;
42
+ excerpt?: string;
43
+ };
44
+
45
+ /** Bounded, content-minimized session activity emitted by a Code runtime.
46
+ * Message bodies are projected separately into the app's owner-private
47
+ * odla-db chat. `interactionId` is optional so stored v1 events remain valid. */
48
+ type CodeSessionEventData = ({
49
+ type: "message";
50
+ actor: "agent" | "system";
51
+ body: string;
52
+ } | {
53
+ type: "diagnostic";
54
+ level: "error";
55
+ message: string;
56
+ } | {
57
+ type: "thinking";
58
+ available: true;
59
+ durationMs: number;
60
+ /** The reasoning itself, bounded. Present only for a session created
61
+ * with `eventDetail: "verbose"`; the standard stream carries duration. */
62
+ text?: string;
63
+ }
64
+ /** Interim assistant prose between tool calls, verbose sessions only. The
65
+ * closing answer is still the `message` event. */
66
+ | {
67
+ type: "text";
68
+ text: string;
69
+ } | {
70
+ type: "tool";
71
+ phase: "started";
72
+ tool: HarnessToolName;
73
+ operationId?: string;
74
+ presentation?: CodeToolPresentation;
75
+ /** The request as the agent made it, bounded; verbose sessions only. */
76
+ input?: Record<string, unknown>;
77
+ } | {
78
+ type: "tool";
79
+ phase: "completed";
80
+ tool: HarnessToolName;
81
+ ok: boolean;
82
+ durationMs: number;
83
+ operationId?: string;
84
+ /** Why the call failed, bounded. Absent when `ok`. Without this a watcher
85
+ * saw that a tool failed and never why, which is what made an 84%
86
+ * apply_patch failure rate impossible to diagnose (PM bug 515655ec). */
87
+ failureReason?: string;
88
+ presentation?: CodeToolPresentation;
89
+ /** The result as the agent received it, bounded; verbose sessions only. */
90
+ output?: string;
91
+ } | {
92
+ type: "collaboration";
93
+ phase: "started";
94
+ skill: string;
95
+ tool: string;
96
+ operationId: string;
97
+ } | {
98
+ type: "collaboration";
99
+ phase: "completed";
100
+ skill: string;
101
+ tool: string;
102
+ ok: boolean;
103
+ durationMs: number;
104
+ operationId: string;
105
+ } | {
106
+ type: "usage";
107
+ provider: string;
108
+ model: string;
109
+ inputTokens: number;
110
+ outputTokens: number;
111
+ durationMs: number;
112
+ interactionTokens?: number;
113
+ interactionMaxTokens?: number;
114
+ /** USD for this call; absent when the model is unpriced, never zero. */
115
+ costUsd?: number;
116
+ /** Cumulative USD for this owner interaction, when every call in it was
117
+ * priced. Absent the moment one was not, so a partial total can never be
118
+ * mistaken for the whole. */
119
+ interactionCostUsd?: number;
120
+ } | {
121
+ type: "status";
122
+ status: "running" | "idle" | "failed" | "checkpointed";
123
+ durationMs?: number;
124
+ }) & {
125
+ interactionId?: string;
126
+ };
127
+ /** Registry-assigned cursor and timestamp for an owner-visible Code event. */
128
+ type CodeSessionEvent = CodeSessionEventData & {
129
+ eventId: string;
130
+ sequence: number;
131
+ createdAt: number;
132
+ };
133
+
134
+ export type { CodeSessionEventData as C, CodeSessionEvent as a, CodeToolLocationPreview as b, CodeToolPresentation as c };
@@ -0,0 +1,134 @@
1
+ import { f as HarnessToolName } from './types-DM-UgoBN.js';
2
+
3
+ /** One bounded result location that an owner may inspect without loading the
4
+ * complete broker result into the activity stream. */
5
+ interface CodeToolLocationPreview {
6
+ path: string;
7
+ line?: number;
8
+ text?: string;
9
+ }
10
+ /** Deliberately small, tool-specific owner presentation. These projections are
11
+ * built after the trusted broker has bounded the corresponding request/result;
12
+ * they are not arbitrary model narration or complete tool output. */
13
+ type CodeToolPresentation = {
14
+ kind: "query";
15
+ query?: string;
16
+ scope?: string;
17
+ count?: number;
18
+ results?: CodeToolLocationPreview[];
19
+ excerpt?: string;
20
+ } | {
21
+ kind: "read";
22
+ path: string;
23
+ startLine?: number;
24
+ endLine?: number;
25
+ excerpt?: string;
26
+ } | {
27
+ kind: "list";
28
+ scope?: string;
29
+ count?: number;
30
+ paths?: string[];
31
+ } | {
32
+ kind: "patch";
33
+ paths?: string[];
34
+ additions?: number;
35
+ deletions?: number;
36
+ } | {
37
+ kind: "recipe";
38
+ recipeId: string;
39
+ exitCode?: number;
40
+ timedOut?: boolean;
41
+ outputLimitExceeded?: boolean;
42
+ excerpt?: string;
43
+ };
44
+
45
+ /** Bounded, content-minimized session activity emitted by a Code runtime.
46
+ * Message bodies are projected separately into the app's owner-private
47
+ * odla-db chat. `interactionId` is optional so stored v1 events remain valid. */
48
+ type CodeSessionEventData = ({
49
+ type: "message";
50
+ actor: "agent" | "system";
51
+ body: string;
52
+ } | {
53
+ type: "diagnostic";
54
+ level: "error";
55
+ message: string;
56
+ } | {
57
+ type: "thinking";
58
+ available: true;
59
+ durationMs: number;
60
+ /** The reasoning itself, bounded. Present only for a session created
61
+ * with `eventDetail: "verbose"`; the standard stream carries duration. */
62
+ text?: string;
63
+ }
64
+ /** Interim assistant prose between tool calls, verbose sessions only. The
65
+ * closing answer is still the `message` event. */
66
+ | {
67
+ type: "text";
68
+ text: string;
69
+ } | {
70
+ type: "tool";
71
+ phase: "started";
72
+ tool: HarnessToolName;
73
+ operationId?: string;
74
+ presentation?: CodeToolPresentation;
75
+ /** The request as the agent made it, bounded; verbose sessions only. */
76
+ input?: Record<string, unknown>;
77
+ } | {
78
+ type: "tool";
79
+ phase: "completed";
80
+ tool: HarnessToolName;
81
+ ok: boolean;
82
+ durationMs: number;
83
+ operationId?: string;
84
+ /** Why the call failed, bounded. Absent when `ok`. Without this a watcher
85
+ * saw that a tool failed and never why, which is what made an 84%
86
+ * apply_patch failure rate impossible to diagnose (PM bug 515655ec). */
87
+ failureReason?: string;
88
+ presentation?: CodeToolPresentation;
89
+ /** The result as the agent received it, bounded; verbose sessions only. */
90
+ output?: string;
91
+ } | {
92
+ type: "collaboration";
93
+ phase: "started";
94
+ skill: string;
95
+ tool: string;
96
+ operationId: string;
97
+ } | {
98
+ type: "collaboration";
99
+ phase: "completed";
100
+ skill: string;
101
+ tool: string;
102
+ ok: boolean;
103
+ durationMs: number;
104
+ operationId: string;
105
+ } | {
106
+ type: "usage";
107
+ provider: string;
108
+ model: string;
109
+ inputTokens: number;
110
+ outputTokens: number;
111
+ durationMs: number;
112
+ interactionTokens?: number;
113
+ interactionMaxTokens?: number;
114
+ /** USD for this call; absent when the model is unpriced, never zero. */
115
+ costUsd?: number;
116
+ /** Cumulative USD for this owner interaction, when every call in it was
117
+ * priced. Absent the moment one was not, so a partial total can never be
118
+ * mistaken for the whole. */
119
+ interactionCostUsd?: number;
120
+ } | {
121
+ type: "status";
122
+ status: "running" | "idle" | "failed" | "checkpointed";
123
+ durationMs?: number;
124
+ }) & {
125
+ interactionId?: string;
126
+ };
127
+ /** Registry-assigned cursor and timestamp for an owner-visible Code event. */
128
+ type CodeSessionEvent = CodeSessionEventData & {
129
+ eventId: string;
130
+ sequence: number;
131
+ createdAt: number;
132
+ };
133
+
134
+ export type { CodeSessionEventData as C, CodeSessionEvent as a, CodeToolLocationPreview as b, CodeToolPresentation as c };
package/dist/index.cjs CHANGED
@@ -25,6 +25,9 @@ __export(src_exports, {
25
25
  HarnessControlError: () => HarnessControlError,
26
26
  HarnessProtocolError: () => HarnessProtocolError,
27
27
  MAX_FAILURE_REASON: () => MAX_FAILURE_REASON,
28
+ MAX_VERBOSE_TOOL_BYTES: () => MAX_VERBOSE_TOOL_BYTES,
29
+ boundedToolInput: () => boundedToolInput,
30
+ boundedToolOutput: () => boundedToolOutput,
28
31
  createHarnessControlClient: () => createHarnessControlClient,
29
32
  createOdlaAiConnection: () => createOdlaAiConnection,
30
33
  encodeAgentInput: () => encodeAgentInput,
@@ -180,8 +183,17 @@ var DEFAULT_FAILURE_REASON = {
180
183
  "tool denied by CaMeL policy": "tool denied by CaMeL policy",
181
184
  "review sessions are read-only": "review session is read-only; workspace changes are not permitted"
182
185
  };
186
+ var MAX_VERBOSE_TOOL_BYTES = 4096;
187
+ function boundedToolInput(value) {
188
+ const serialized = JSON.stringify(value);
189
+ return serialized.length <= MAX_VERBOSE_TOOL_BYTES ? value : { truncated: true, bytes: serialized.length, keys: Object.keys(value).slice(0, 20) };
190
+ }
191
+ function boundedToolOutput(content) {
192
+ return content.length <= MAX_VERBOSE_TOOL_BYTES ? content : `${content.slice(0, MAX_VERBOSE_TOOL_BYTES - 1)}\u2026`;
193
+ }
183
194
  function observedBroker(input) {
184
195
  const now = input.now ?? Date.now;
196
+ const verbose = input.detail === "verbose";
185
197
  return {
186
198
  execute: async (context, request) => {
187
199
  const startedAt = now();
@@ -192,7 +204,8 @@ function observedBroker(input) {
192
204
  phase: "started",
193
205
  tool: request.tool,
194
206
  operationId,
195
- ...startedPresentation ? { presentation: startedPresentation } : {}
207
+ ...startedPresentation ? { presentation: startedPresentation } : {},
208
+ ...verbose ? { input: boundedToolInput(request.input) } : {}
196
209
  });
197
210
  const response = await input.broker.execute(context, request);
198
211
  const completedPresentation = codeToolResultPresentation(request, response);
@@ -205,7 +218,8 @@ function observedBroker(input) {
205
218
  durationMs: now() - startedAt,
206
219
  operationId,
207
220
  ...failureReason ? { failureReason } : {},
208
- ...completedPresentation ? { presentation: completedPresentation } : {}
221
+ ...completedPresentation ? { presentation: completedPresentation } : {},
222
+ ...verbose ? { output: boundedToolOutput(response.content) } : {}
209
223
  });
210
224
  return response;
211
225
  }
@@ -396,6 +410,9 @@ function createOdlaAiConnection(ai, options = {}) {
396
410
  HarnessControlError,
397
411
  HarnessProtocolError,
398
412
  MAX_FAILURE_REASON,
413
+ MAX_VERBOSE_TOOL_BYTES,
414
+ boundedToolInput,
415
+ boundedToolOutput,
399
416
  createHarnessControlClient,
400
417
  createOdlaAiConnection,
401
418
  encodeAgentInput,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/code-tool-presentation.ts","../src/code-runtime-observer.ts","../src/protocol.ts","../src/client.ts","../src/ai.ts"],"sourcesContent":["export * from \"./types\";\n// Runtime-neutral: pure translation of a broker call into a session event, so a\n// Worker can hold the emitter and the validator against each other.\nexport * from \"./code-runtime-observer\";\nexport * from \"./protocol\";\nexport * from \"./client\";\nexport * from \"./ai\";\n","import type { ChatInput, OracleResponse } from \"@odla-ai/ai\";\nimport type { CodeToolPresentation } from \"./code-session-event-types\";\nexport type { CodeToolLocationPreview, CodeToolPresentation } from \"./code-session-event-types\";\n\n/** Current JSONL protocol version exchanged between a runner and an agent container. */\nexport const HARNESS_PROTOCOL_VERSION = 1 as const;\n\n/** Default control-plane route used for model inference requested by coding agents. */\nexport const DEFAULT_AI_ROUTE = \"coding\" as const;\n\n/** Lifecycle state reported for a harness task and its active attempt. */\nexport type HarnessTaskStatus =\n | \"queued\"\n | \"running\"\n | \"cancel_requested\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\n/** Lifecycle state of one execution attempt for a task. */\nexport type HarnessAttemptStatus = HarnessTaskStatus;\n\n/** Trusted or untrusted participant that emitted a harness event. */\nexport type HarnessActor = \"operator\" | \"runner\" | \"agent\" | \"model\" | \"system\";\n\n/** Resource and isolation limits enforced while an untrusted task executes. */\nexport interface HarnessPolicy {\n network: \"none\";\n timeoutMs: number;\n maxOutputBytes: number;\n maxPatchBytes: number;\n}\n\n/** Immutable task instructions and execution policy delivered with a lease. */\nexport interface HarnessTaskSpec {\n taskId: string;\n attemptId: string;\n title: string;\n prompt: string;\n workspace: string;\n aiRoute: string;\n policy: HarnessPolicy;\n parentAttemptId?: string | null;\n checkpointSeq?: number | null;\n}\n\n/** Time-bound assignment authorizing a runner to execute one task attempt. */\nexport interface HarnessLease {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n leaseId: string;\n generation: number;\n expiresAt: number;\n task: HarnessTaskSpec;\n}\n\n/** Runner-supplied event before the control plane assigns sequence and task metadata. */\nexport interface HarnessEventInput {\n eventId: string;\n kind: string;\n actor: HarnessActor;\n payload: unknown;\n createdAt: number;\n}\n\n/** Persisted, ordered event associated with a specific task attempt. */\nexport interface HarnessEvent extends HarnessEventInput {\n seq: number;\n taskId: string;\n attemptId: string;\n}\n\n/** List-view metadata for a task and its current attempt. */\nexport interface HarnessTaskSummary {\n taskId: string;\n attemptId: string;\n appId: string;\n env: string;\n title: string;\n prompt: string;\n workspace: string;\n aiRoute: string;\n status: HarnessTaskStatus;\n parentAttemptId: string | null;\n checkpointSeq: number | null;\n runnerId: string | null;\n generation: number;\n createdAt: number;\n updatedAt: number;\n}\n\n/** List-view metadata for one attempt, including retry ancestry and runner ownership. */\nexport interface HarnessAttemptSummary {\n attemptId: string;\n taskId: string;\n parentAttemptId: string | null;\n checkpointSeq: number | null;\n status: HarnessAttemptStatus;\n runnerId: string | null;\n generation: number;\n createdAt: number;\n updatedAt: number;\n}\n\n/** Complete task view including attempts, events, result, and generated patch. */\nexport interface HarnessTaskDetail extends HarnessTaskSummary {\n attempts: HarnessAttemptSummary[];\n events: HarnessEvent[];\n patch: string | null;\n result: unknown;\n}\n\n/** Public control-plane view of a registered harness runner. */\nexport interface HarnessRunnerView {\n runnerId: string;\n appId: string;\n env: string;\n name: string;\n createdAt: number;\n lastSeenAt: number | null;\n revokedAt: number | null;\n}\n\n/** Credential-free normalized model request sent from an agent through the runner. */\nexport interface HarnessInferenceRequest {\n requestId: string;\n /** Exact initial, follow-up, or resume command whose budget this call consumes. */\n interactionId?: string;\n call: ChatInput;\n}\n\n/** Normalized model response plus auditable provider, policy, and token metadata. */\nexport interface HarnessInferenceResponse {\n requestId: string;\n response: OracleResponse;\n receipt: {\n provider: string;\n model: string;\n policyVersion: number;\n inputTokens: number;\n outputTokens: number;\n /**\n * USD charged for this call, priced against the model the control plane\n * actually resolved.\n *\n * ABSENT when the live catalog has no price for that model — never zero.\n * An unpriced call is unknown spend, and reporting it as free is what let\n * a goal's `maxUsd` look enforced while nothing enforced it. The runtime\n * cannot compute this itself: it asks for `brokered` and only the control\n * plane knows which model answered.\n */\n costUsd?: number;\n };\n}\n\n/** Bounded, content-minimized session activity emitted by a Code runtime.\n * Message bodies are projected separately into the app's owner-private\n * odla-db chat. `interactionId` is optional so stored v1 events remain valid. */\nexport type CodeSessionEventData = (\n | { type: \"message\"; actor: \"agent\" | \"system\"; body: string }\n | { type: \"diagnostic\"; level: \"error\"; message: string }\n | { type: \"thinking\"; available: true; durationMs: number }\n | {\n type: \"tool\";\n phase: \"started\";\n tool: HarnessToolName;\n operationId?: string;\n presentation?: CodeToolPresentation;\n }\n | {\n type: \"tool\";\n phase: \"completed\";\n tool: HarnessToolName;\n ok: boolean;\n durationMs: number;\n operationId?: string;\n /** Why the call failed, bounded. Absent when `ok`. Without this a watcher\n * saw that a tool failed and never why, which is what made an 84%\n * apply_patch failure rate impossible to diagnose (PM bug 515655ec). */\n failureReason?: string;\n presentation?: CodeToolPresentation;\n }\n | {\n type: \"collaboration\";\n phase: \"started\";\n skill: string;\n tool: string;\n operationId: string;\n }\n | {\n type: \"collaboration\";\n phase: \"completed\";\n skill: string;\n tool: string;\n ok: boolean;\n durationMs: number;\n operationId: string;\n }\n | {\n type: \"usage\"; provider: string; model: string;\n inputTokens: number; outputTokens: number; durationMs: number;\n interactionTokens?: number; interactionMaxTokens?: number;\n /** USD for this call; absent when the model is unpriced, never zero. */\n costUsd?: number;\n /** Cumulative USD for this owner interaction, when every call in it was\n * priced. Absent the moment one was not, so a partial total can never be\n * mistaken for the whole. */\n interactionCostUsd?: number;\n }\n | {\n type: \"status\"; status: \"running\" | \"idle\" | \"failed\" | \"checkpointed\";\n durationMs?: number;\n }\n) & { interactionId?: string };\n\n/** Registry-assigned cursor and timestamp for an owner-visible Code event. */\nexport type CodeSessionEvent = CodeSessionEventData & {\n eventId: string; sequence: number; createdAt: number;\n};\n\n/** Closed set of effects an agent container may request from its trusted broker. */\nexport type HarnessToolName =\n | \"sandbox.read\"\n | \"sandbox.list\"\n | \"sandbox.search\"\n | \"sandbox.overview\"\n | \"sandbox.where_is\"\n | \"sandbox.who_imports\"\n | \"sandbox.who_touches\"\n | \"sandbox.apply_patch\"\n | \"sandbox.edit\"\n | \"sandbox.write\"\n | \"sandbox.run_recipe\";\n/** Correlated, structured tool request emitted by an untrusted agent container. */\nexport interface HarnessToolRequest {\n requestId: string;\n tool: HarnessToolName;\n input: Record<string, unknown>;\n}\n/** Bounded tool result returned to an agent after trusted policy evaluation. */\nexport interface HarnessToolResponse {\n requestId: string;\n ok: boolean;\n content: string;\n details?: Record<string, unknown>;\n}\n\n/** Validated JSONL message emitted by an untrusted agent container. */\nexport type HarnessAgentOutput =\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"event\";\n kind: string;\n payload?: unknown;\n }\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"inference.request\";\n requestId: string;\n call: ChatInput;\n }\n | ({ protocolVersion: typeof HARNESS_PROTOCOL_VERSION; type: \"tool.request\" } & HarnessToolRequest)\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"attempt.complete\";\n status: \"completed\" | \"failed\" | \"cancelled\";\n result?: unknown;\n };\n\n/** JSONL command or inference result written by the trusted runner to an agent. */\nexport type HarnessAgentInput =\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"task.start\";\n task: HarnessTaskSpec;\n }\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"inference.response\";\n requestId: string;\n response: OracleResponse;\n }\n | ({ protocolVersion: typeof HARNESS_PROTOCOL_VERSION; type: \"tool.response\" } & HarnessToolResponse)\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"attempt.cancel\";\n reason: string;\n };\n\n/** Terminal attempt report submitted by a runner to the control plane. */\nexport interface HarnessCompletion {\n status: \"completed\" | \"failed\" | \"cancelled\";\n result?: unknown;\n patch?: string;\n error?: string;\n}\n\n/** Operations a credentialed runner may perform against the harness control plane. */\nexport interface HarnessControlPlane {\n lease(workspaces: string[]): Promise<HarnessLease | null>;\n heartbeat(attemptId: string, leaseId: string): Promise<{ cancelRequested: boolean; expiresAt: number }>;\n appendEvents(attemptId: string, leaseId: string, events: HarnessEventInput[]): Promise<void>;\n infer(attemptId: string, leaseId: string, request: HarnessInferenceRequest): Promise<HarnessInferenceResponse>;\n complete(attemptId: string, leaseId: string, completion: HarnessCompletion): Promise<void>;\n}\n\n/** Trusted inference bridge used to keep model credentials outside agent containers. */\nexport interface HarnessAiConnection {\n infer(request: HarnessInferenceRequest): Promise<HarnessInferenceResponse>;\n}\n\n/** Trusted tool boundary. Implementations must evaluate CaMeL policy before effects. */\nexport interface HarnessToolBroker {\n execute(\n context: { lease: HarnessLease; workspaceDir: string; signal?: AbortSignal },\n request: HarnessToolRequest,\n ): Promise<HarnessToolResponse>;\n}\n","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","import type { ChatInput } from \"@odla-ai/ai\";\nimport {\n HARNESS_PROTOCOL_VERSION,\n type HarnessAgentInput,\n type HarnessAgentOutput,\n type HarnessEventInput,\n} from \"./types\";\n\nconst CONTROL = /[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f]/;\n\n/** Error raised when an agent emits malformed, oversized, or unsupported protocol data. */\nexport class HarnessProtocolError extends Error {\n override readonly name = \"HarnessProtocolError\";\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null;\n}\n\nfunction boundedText(value: unknown, label: string, max: number): string {\n if (typeof value !== \"string\" || !value || value.length > max || CONTROL.test(value)) {\n throw new HarnessProtocolError(`${label} must be a non-empty string of at most ${max} characters`);\n }\n return value;\n}\n\n/** Parse and validate one newline-delimited message emitted by an agent container. */\nexport function parseAgentOutput(line: string): HarnessAgentOutput {\n if (Buffer.byteLength(line, \"utf8\") > 1_000_000) throw new HarnessProtocolError(\"agent message exceeds 1 MB\");\n let value: unknown;\n try { value = JSON.parse(line); } catch { throw new HarnessProtocolError(\"agent emitted invalid JSON\"); }\n const message = record(value);\n if (!message || message.protocolVersion !== HARNESS_PROTOCOL_VERSION) {\n throw new HarnessProtocolError(`agent protocolVersion must be ${HARNESS_PROTOCOL_VERSION}`);\n }\n if (message.type === \"event\") {\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"event\",\n kind: boundedText(message.kind, \"event.kind\", 120),\n ...(message.payload === undefined ? {} : { payload: message.payload }),\n };\n }\n if (message.type === \"inference.request\") {\n const call = record(message.call);\n if (!call || !Array.isArray(call.messages) || !Number.isSafeInteger(call.maxTokens)) {\n throw new HarnessProtocolError(\"inference.request.call requires messages and maxTokens\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"inference.request\",\n requestId: boundedText(message.requestId, \"requestId\", 180),\n call: call as unknown as ChatInput,\n };\n }\n if (message.type === \"tool.request\") {\n const input = record(message.input);\n const tool = String(message.tool);\n if (!input || ![\"sandbox.read\", \"sandbox.apply_patch\", \"sandbox.edit\", \"sandbox.run_recipe\"].includes(tool)) {\n throw new HarnessProtocolError(\"tool.request requires a registered tool and object input\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"tool.request\",\n requestId: boundedText(message.requestId, \"requestId\", 180),\n tool: tool as \"sandbox.read\" | \"sandbox.apply_patch\" | \"sandbox.edit\" | \"sandbox.run_recipe\",\n input,\n };\n }\n if (message.type === \"attempt.complete\") {\n if (!new Set([\"completed\", \"failed\", \"cancelled\"]).has(String(message.status))) {\n throw new HarnessProtocolError(\"attempt.complete.status is invalid\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"attempt.complete\",\n status: message.status as \"completed\" | \"failed\" | \"cancelled\",\n ...(message.result === undefined ? {} : { result: message.result }),\n };\n }\n throw new HarnessProtocolError(\"agent message type is unsupported\");\n}\n\n/** Serialize one trusted runner message as a newline-terminated JSONL record. */\nexport function encodeAgentInput(message: HarnessAgentInput): string {\n return `${JSON.stringify(message)}\\n`;\n}\n\n/** Create a timestamped, uniquely identified event for control-plane submission. */\nexport function makeHarnessEvent(\n kind: string,\n actor: HarnessEventInput[\"actor\"],\n payload: unknown,\n now = Date.now(),\n id = crypto.randomUUID(),\n): HarnessEventInput {\n boundedText(kind, \"event.kind\", 120);\n return { eventId: id, kind, actor, payload, createdAt: now };\n}\n","import type {\n HarnessCompletion,\n HarnessControlPlane,\n HarnessEventInput,\n HarnessInferenceRequest,\n HarnessInferenceResponse,\n HarnessLease,\n} from \"./types\";\n\n/** HTTP error returned by the harness control plane, including its stable error code. */\nexport class HarnessControlError extends Error {\n override readonly name = \"HarnessControlError\";\n constructor(message: string, readonly status: number, readonly code = \"control_error\") { super(message); }\n}\n\n/** Connection, credential, cancellation, and timeout settings for a runner client. */\nexport interface HarnessControlClientOptions {\n endpoint: string;\n token: string;\n fetch?: typeof fetch;\n requestTimeoutMs?: number;\n signal?: AbortSignal;\n}\n\n/** Create a validated HTTPS client implementing the runner control-plane operations. */\nexport function createHarnessControlClient(options: HarnessControlClientOptions): HarnessControlPlane {\n const endpoint = options.endpoint.replace(/\\/+$/, \"\");\n let endpointUrl: URL;\n try { endpointUrl = new URL(endpoint); } catch { throw new TypeError(\"endpoint must be an HTTPS URL\"); }\n const loopback = endpointUrl.hostname === \"localhost\" || endpointUrl.hostname === \"127.0.0.1\" || endpointUrl.hostname === \"[::1]\";\n if (endpointUrl.username || endpointUrl.password || (endpointUrl.protocol !== \"https:\" && !(loopback && endpointUrl.protocol === \"http:\"))) {\n throw new TypeError(\"endpoint must use HTTPS (HTTP is allowed only for loopback testing)\");\n }\n if (!/^odla_hrn_[0-9a-f]{64}$/.test(options.token)) throw new TypeError(\"invalid harness runner credential\");\n const requestTimeoutMs = options.requestTimeoutMs ?? 30_000;\n if (!Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 1_000 || requestTimeoutMs > 120_000) {\n throw new TypeError(\"requestTimeoutMs must be an integer from 1000 to 120000\");\n }\n const request = options.fetch ?? fetch;\n const call = async <T>(path: string, body: unknown, allowEmpty = false): Promise<T | null> => {\n const timeout = AbortSignal.timeout(requestTimeoutMs);\n const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;\n const response = await request(`${endpoint}${path}`, {\n method: \"POST\",\n headers: { authorization: `Bearer ${options.token}`, \"content-type\": \"application/json\" },\n body: JSON.stringify(body),\n redirect: \"error\",\n signal,\n });\n if (allowEmpty && response.status === 204) return null;\n const value = await response.json().catch(() => null) as { error?: { code?: string; message?: string } } | null;\n if (!response.ok) throw new HarnessControlError(\n value?.error?.message ?? `harness control request failed (${response.status})`,\n response.status,\n value?.error?.code,\n );\n return value as T;\n };\n return {\n lease: async (workspaces) => {\n const body = await call<{ lease: HarnessLease }>(\"/registry/harness/lease\", { workspaces }, true);\n return body?.lease ?? null;\n },\n heartbeat: async (attemptId, leaseId) => {\n const body = await call<{ cancelRequested: boolean; expiresAt: number }>(\n `/registry/harness/attempts/${encodeURIComponent(attemptId)}/heartbeat`, { leaseId },\n );\n return body!;\n },\n appendEvents: async (attemptId, leaseId, events: HarnessEventInput[]) => {\n await call(`/registry/harness/attempts/${encodeURIComponent(attemptId)}/events`, { leaseId, events });\n },\n infer: async (attemptId, leaseId, inference: HarnessInferenceRequest) => {\n const body = await call<HarnessInferenceResponse>(\n `/registry/harness/attempts/${encodeURIComponent(attemptId)}/inference`, { leaseId, ...inference },\n );\n return body!;\n },\n complete: async (attemptId, leaseId, completion: HarnessCompletion) => {\n await call(`/registry/harness/attempts/${encodeURIComponent(attemptId)}/complete`, { leaseId, ...completion });\n },\n };\n}\n","import type { Ai } from \"@odla-ai/ai\";\nimport type { HarnessAiConnection, HarnessInferenceRequest, HarnessInferenceResponse } from \"./types\";\n\n/**\n * Adapt the normalized odla AI chat surface to a harness connection.\n * Provider credentials remain in the process that owns `ai`; only normalized\n * requests and responses cross the container protocol.\n */\nexport function createOdlaAiConnection(\n ai: Pick<Ai, \"chat\">,\n options: { model?: string; policyVersion?: number } = {},\n): HarnessAiConnection {\n return {\n async infer(request: HarnessInferenceRequest): Promise<HarnessInferenceResponse> {\n const response = await ai.chat({ ...request.call, ...(options.model ? { model: options.model } : {}) });\n return {\n requestId: request.requestId,\n response,\n receipt: {\n provider: response.provider,\n model: response.model,\n policyVersion: options.policyVersion ?? 1,\n inputTokens: response.usage.inputTokens ?? 0,\n outputTokens: response.usage.outputTokens ?? 0,\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,2BAA2B;AAGjC,IAAM,mBAAmB;;;ACJhC,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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mBAAmB,SAAS,CAAC;AAAA,QAAc,EAAE,QAAQ;AAAA,MACrF;AACA,aAAO;AAAA,IACT;AAAA,IACA,cAAc,OAAO,WAAW,SAAS,WAAgC;AACvE,YAAM,KAAK,8BAA8B,mBAAmB,SAAS,CAAC,WAAW,EAAE,SAAS,OAAO,CAAC;AAAA,IACtG;AAAA,IACA,OAAO,OAAO,WAAW,SAAS,cAAuC;AACvE,YAAM,OAAO,MAAM;AAAA,QACjB,8BAA8B,mBAAmB,SAAS,CAAC;AAAA,QAAc,EAAE,SAAS,GAAG,UAAU;AAAA,MACnG;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,OAAO,WAAW,SAAS,eAAkC;AACrE,YAAM,KAAK,8BAA8B,mBAAmB,SAAS,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC;AAAA,IAC/G;AAAA,EACF;AACF;;;AC1EO,SAAS,uBACd,IACA,UAAsD,CAAC,GAClC;AACrB,SAAO;AAAA,IACL,MAAM,MAAM,SAAqE;AAC/E,YAAM,WAAW,MAAM,GAAG,KAAK,EAAE,GAAG,QAAQ,MAAM,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC,EAAG,CAAC;AACtG,aAAO;AAAA,QACL,WAAW,QAAQ;AAAA,QACnB;AAAA,QACA,SAAS;AAAA,UACP,UAAU,SAAS;AAAA,UACnB,OAAO,SAAS;AAAA,UAChB,eAAe,QAAQ,iBAAiB;AAAA,UACxC,aAAa,SAAS,MAAM,eAAe;AAAA,UAC3C,cAAc,SAAS,MAAM,gBAAgB;AAAA,QAC/C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["record"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/types.ts","../src/code-tool-presentation.ts","../src/code-runtime-observer.ts","../src/protocol.ts","../src/client.ts","../src/ai.ts"],"sourcesContent":["export * from \"./types\";\n// Runtime-neutral: pure translation of a broker call into a session event, so a\n// Worker can hold the emitter and the validator against each other.\nexport * from \"./code-runtime-observer\";\nexport * from \"./protocol\";\nexport * from \"./client\";\nexport * from \"./ai\";\n","import type { ChatInput, OracleResponse } from \"@odla-ai/ai\";\nimport type { CodeToolPresentation } from \"./code-session-event-types\";\nexport type { CodeToolLocationPreview, CodeToolPresentation } from \"./code-session-event-types\";\n\n/** Current JSONL protocol version exchanged between a runner and an agent container. */\nexport const HARNESS_PROTOCOL_VERSION = 1 as const;\n\n/** Default control-plane route used for model inference requested by coding agents. */\nexport const DEFAULT_AI_ROUTE = \"coding\" as const;\n\n/** Lifecycle state reported for a harness task and its active attempt. */\nexport type HarnessTaskStatus =\n | \"queued\"\n | \"running\"\n | \"cancel_requested\"\n | \"completed\"\n | \"failed\"\n | \"cancelled\";\n\n/** Lifecycle state of one execution attempt for a task. */\nexport type HarnessAttemptStatus = HarnessTaskStatus;\n\n/** Trusted or untrusted participant that emitted a harness event. */\nexport type HarnessActor = \"operator\" | \"runner\" | \"agent\" | \"model\" | \"system\";\n\n/** Resource and isolation limits enforced while an untrusted task executes. */\nexport interface HarnessPolicy {\n network: \"none\";\n timeoutMs: number;\n maxOutputBytes: number;\n maxPatchBytes: number;\n}\n\n/** Immutable task instructions and execution policy delivered with a lease. */\nexport interface HarnessTaskSpec {\n taskId: string;\n attemptId: string;\n title: string;\n prompt: string;\n workspace: string;\n aiRoute: string;\n policy: HarnessPolicy;\n parentAttemptId?: string | null;\n checkpointSeq?: number | null;\n}\n\n/** Time-bound assignment authorizing a runner to execute one task attempt. */\nexport interface HarnessLease {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n leaseId: string;\n generation: number;\n expiresAt: number;\n task: HarnessTaskSpec;\n}\n\n/** Runner-supplied event before the control plane assigns sequence and task metadata. */\nexport interface HarnessEventInput {\n eventId: string;\n kind: string;\n actor: HarnessActor;\n payload: unknown;\n createdAt: number;\n}\n\n/** Persisted, ordered event associated with a specific task attempt. */\nexport interface HarnessEvent extends HarnessEventInput {\n seq: number;\n taskId: string;\n attemptId: string;\n}\n\n/** List-view metadata for a task and its current attempt. */\nexport interface HarnessTaskSummary {\n taskId: string;\n attemptId: string;\n appId: string;\n env: string;\n title: string;\n prompt: string;\n workspace: string;\n aiRoute: string;\n status: HarnessTaskStatus;\n parentAttemptId: string | null;\n checkpointSeq: number | null;\n runnerId: string | null;\n generation: number;\n createdAt: number;\n updatedAt: number;\n}\n\n/** List-view metadata for one attempt, including retry ancestry and runner ownership. */\nexport interface HarnessAttemptSummary {\n attemptId: string;\n taskId: string;\n parentAttemptId: string | null;\n checkpointSeq: number | null;\n status: HarnessAttemptStatus;\n runnerId: string | null;\n generation: number;\n createdAt: number;\n updatedAt: number;\n}\n\n/** Complete task view including attempts, events, result, and generated patch. */\nexport interface HarnessTaskDetail extends HarnessTaskSummary {\n attempts: HarnessAttemptSummary[];\n events: HarnessEvent[];\n patch: string | null;\n result: unknown;\n}\n\n/** Public control-plane view of a registered harness runner. */\nexport interface HarnessRunnerView {\n runnerId: string;\n appId: string;\n env: string;\n name: string;\n createdAt: number;\n lastSeenAt: number | null;\n revokedAt: number | null;\n}\n\n/** Credential-free normalized model request sent from an agent through the runner. */\nexport interface HarnessInferenceRequest {\n requestId: string;\n /** Exact initial, follow-up, or resume command whose budget this call consumes. */\n interactionId?: string;\n call: ChatInput;\n}\n\n/** Normalized model response plus auditable provider, policy, and token metadata. */\nexport interface HarnessInferenceResponse {\n requestId: string;\n response: OracleResponse;\n receipt: {\n provider: string;\n model: string;\n policyVersion: number;\n inputTokens: number;\n outputTokens: number;\n /**\n * USD charged for this call, priced against the model the control plane\n * actually resolved.\n *\n * ABSENT when the live catalog has no price for that model — never zero.\n * An unpriced call is unknown spend, and reporting it as free is what let\n * a goal's `maxUsd` look enforced while nothing enforced it. The runtime\n * cannot compute this itself: it asks for `brokered` and only the control\n * plane knows which model answered.\n */\n costUsd?: number;\n };\n}\n\nexport type { CodeSessionEvent, CodeSessionEventData } from \"./code-session-event-data\";\n\n/** Closed set of effects an agent container may request from its trusted broker. */\nexport type HarnessToolName =\n | \"sandbox.read\"\n | \"sandbox.list\"\n | \"sandbox.search\"\n | \"sandbox.overview\"\n | \"sandbox.where_is\"\n | \"sandbox.who_imports\"\n | \"sandbox.who_touches\"\n | \"sandbox.apply_patch\"\n | \"sandbox.edit\"\n | \"sandbox.write\"\n | \"sandbox.run_recipe\";\n/** Correlated, structured tool request emitted by an untrusted agent container. */\nexport interface HarnessToolRequest {\n requestId: string;\n tool: HarnessToolName;\n input: Record<string, unknown>;\n}\n/** Bounded tool result returned to an agent after trusted policy evaluation. */\nexport interface HarnessToolResponse {\n requestId: string;\n ok: boolean;\n content: string;\n details?: Record<string, unknown>;\n}\n\n/** Validated JSONL message emitted by an untrusted agent container. */\nexport type HarnessAgentOutput =\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"event\";\n kind: string;\n payload?: unknown;\n }\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"inference.request\";\n requestId: string;\n call: ChatInput;\n }\n | ({ protocolVersion: typeof HARNESS_PROTOCOL_VERSION; type: \"tool.request\" } & HarnessToolRequest)\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"attempt.complete\";\n status: \"completed\" | \"failed\" | \"cancelled\";\n result?: unknown;\n };\n\n/** JSONL command or inference result written by the trusted runner to an agent. */\nexport type HarnessAgentInput =\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"task.start\";\n task: HarnessTaskSpec;\n }\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"inference.response\";\n requestId: string;\n response: OracleResponse;\n }\n | ({ protocolVersion: typeof HARNESS_PROTOCOL_VERSION; type: \"tool.response\" } & HarnessToolResponse)\n | {\n protocolVersion: typeof HARNESS_PROTOCOL_VERSION;\n type: \"attempt.cancel\";\n reason: string;\n };\n\n/** Terminal attempt report submitted by a runner to the control plane. */\nexport interface HarnessCompletion {\n status: \"completed\" | \"failed\" | \"cancelled\";\n result?: unknown;\n patch?: string;\n error?: string;\n}\n\n/** Operations a credentialed runner may perform against the harness control plane. */\nexport interface HarnessControlPlane {\n lease(workspaces: string[]): Promise<HarnessLease | null>;\n heartbeat(attemptId: string, leaseId: string): Promise<{ cancelRequested: boolean; expiresAt: number }>;\n appendEvents(attemptId: string, leaseId: string, events: HarnessEventInput[]): Promise<void>;\n infer(attemptId: string, leaseId: string, request: HarnessInferenceRequest): Promise<HarnessInferenceResponse>;\n complete(attemptId: string, leaseId: string, completion: HarnessCompletion): Promise<void>;\n}\n\n/** Trusted inference bridge used to keep model credentials outside agent containers. */\nexport interface HarnessAiConnection {\n infer(request: HarnessInferenceRequest): Promise<HarnessInferenceResponse>;\n}\n\n/** Trusted tool boundary. Implementations must evaluate CaMeL policy before effects. */\nexport interface HarnessToolBroker {\n execute(\n context: { lease: HarnessLease; workspaceDir: string; signal?: AbortSignal },\n request: HarnessToolRequest,\n ): Promise<HarnessToolResponse>;\n}\n","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/** Longest serialized tool input, and longest tool output, a verbose stream carries. */\nexport const MAX_VERBOSE_TOOL_BYTES = 4_096;\n\n/** A tool input as a verbose watcher sees it: the object when it fits, else a\n * marker saying how large it was. A stream must never carry a whole file. */\nexport function boundedToolInput(value: Record<string, unknown>): Record<string, unknown> {\n const serialized = JSON.stringify(value);\n return serialized.length <= MAX_VERBOSE_TOOL_BYTES\n ? value : { truncated: true, bytes: serialized.length, keys: Object.keys(value).slice(0, 20) };\n}\n\n/** A tool output as a verbose watcher sees it, bounded. */\nexport function boundedToolOutput(content: string): string {\n return content.length <= MAX_VERBOSE_TOOL_BYTES\n ? content : `${content.slice(0, MAX_VERBOSE_TOOL_BYTES - 1)}…`;\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. With `detail:\n * \"verbose\"` each event also carries the bounded input and output.\n */\nexport function observedBroker(input: {\n broker: HarnessToolBroker;\n operationIdFor: (requestId: string) => string;\n emit: (event: CodeSessionEventData) => Promise<void>;\n now?: () => number;\n detail?: \"standard\" | \"verbose\";\n}): HarnessToolBroker {\n const now = input.now ?? Date.now;\n const verbose = input.detail === \"verbose\";\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 ...(verbose ? { input: boundedToolInput(request.input) } : {}),\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 ...(verbose ? { output: boundedToolOutput(response.content) } : {}),\n });\n return response;\n },\n };\n}\n","import type { ChatInput } from \"@odla-ai/ai\";\nimport {\n HARNESS_PROTOCOL_VERSION,\n type HarnessAgentInput,\n type HarnessAgentOutput,\n type HarnessEventInput,\n} from \"./types\";\n\nconst CONTROL = /[\\u0000-\\u0008\\u000b\\u000c\\u000e-\\u001f\\u007f]/;\n\n/** Error raised when an agent emits malformed, oversized, or unsupported protocol data. */\nexport class HarnessProtocolError extends Error {\n override readonly name = \"HarnessProtocolError\";\n}\n\nfunction record(value: unknown): Record<string, unknown> | null {\n return value !== null && typeof value === \"object\" && !Array.isArray(value)\n ? value as Record<string, unknown>\n : null;\n}\n\nfunction boundedText(value: unknown, label: string, max: number): string {\n if (typeof value !== \"string\" || !value || value.length > max || CONTROL.test(value)) {\n throw new HarnessProtocolError(`${label} must be a non-empty string of at most ${max} characters`);\n }\n return value;\n}\n\n/** Parse and validate one newline-delimited message emitted by an agent container. */\nexport function parseAgentOutput(line: string): HarnessAgentOutput {\n if (Buffer.byteLength(line, \"utf8\") > 1_000_000) throw new HarnessProtocolError(\"agent message exceeds 1 MB\");\n let value: unknown;\n try { value = JSON.parse(line); } catch { throw new HarnessProtocolError(\"agent emitted invalid JSON\"); }\n const message = record(value);\n if (!message || message.protocolVersion !== HARNESS_PROTOCOL_VERSION) {\n throw new HarnessProtocolError(`agent protocolVersion must be ${HARNESS_PROTOCOL_VERSION}`);\n }\n if (message.type === \"event\") {\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"event\",\n kind: boundedText(message.kind, \"event.kind\", 120),\n ...(message.payload === undefined ? {} : { payload: message.payload }),\n };\n }\n if (message.type === \"inference.request\") {\n const call = record(message.call);\n if (!call || !Array.isArray(call.messages) || !Number.isSafeInteger(call.maxTokens)) {\n throw new HarnessProtocolError(\"inference.request.call requires messages and maxTokens\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"inference.request\",\n requestId: boundedText(message.requestId, \"requestId\", 180),\n call: call as unknown as ChatInput,\n };\n }\n if (message.type === \"tool.request\") {\n const input = record(message.input);\n const tool = String(message.tool);\n if (!input || ![\"sandbox.read\", \"sandbox.apply_patch\", \"sandbox.edit\", \"sandbox.run_recipe\"].includes(tool)) {\n throw new HarnessProtocolError(\"tool.request requires a registered tool and object input\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"tool.request\",\n requestId: boundedText(message.requestId, \"requestId\", 180),\n tool: tool as \"sandbox.read\" | \"sandbox.apply_patch\" | \"sandbox.edit\" | \"sandbox.run_recipe\",\n input,\n };\n }\n if (message.type === \"attempt.complete\") {\n if (!new Set([\"completed\", \"failed\", \"cancelled\"]).has(String(message.status))) {\n throw new HarnessProtocolError(\"attempt.complete.status is invalid\");\n }\n return {\n protocolVersion: HARNESS_PROTOCOL_VERSION,\n type: \"attempt.complete\",\n status: message.status as \"completed\" | \"failed\" | \"cancelled\",\n ...(message.result === undefined ? {} : { result: message.result }),\n };\n }\n throw new HarnessProtocolError(\"agent message type is unsupported\");\n}\n\n/** Serialize one trusted runner message as a newline-terminated JSONL record. */\nexport function encodeAgentInput(message: HarnessAgentInput): string {\n return `${JSON.stringify(message)}\\n`;\n}\n\n/** Create a timestamped, uniquely identified event for control-plane submission. */\nexport function makeHarnessEvent(\n kind: string,\n actor: HarnessEventInput[\"actor\"],\n payload: unknown,\n now = Date.now(),\n id = crypto.randomUUID(),\n): HarnessEventInput {\n boundedText(kind, \"event.kind\", 120);\n return { eventId: id, kind, actor, payload, createdAt: now };\n}\n","import type {\n HarnessCompletion,\n HarnessControlPlane,\n HarnessEventInput,\n HarnessInferenceRequest,\n HarnessInferenceResponse,\n HarnessLease,\n} from \"./types\";\n\n/** HTTP error returned by the harness control plane, including its stable error code. */\nexport class HarnessControlError extends Error {\n override readonly name = \"HarnessControlError\";\n constructor(message: string, readonly status: number, readonly code = \"control_error\") { super(message); }\n}\n\n/** Connection, credential, cancellation, and timeout settings for a runner client. */\nexport interface HarnessControlClientOptions {\n endpoint: string;\n token: string;\n fetch?: typeof fetch;\n requestTimeoutMs?: number;\n signal?: AbortSignal;\n}\n\n/** Create a validated HTTPS client implementing the runner control-plane operations. */\nexport function createHarnessControlClient(options: HarnessControlClientOptions): HarnessControlPlane {\n const endpoint = options.endpoint.replace(/\\/+$/, \"\");\n let endpointUrl: URL;\n try { endpointUrl = new URL(endpoint); } catch { throw new TypeError(\"endpoint must be an HTTPS URL\"); }\n const loopback = endpointUrl.hostname === \"localhost\" || endpointUrl.hostname === \"127.0.0.1\" || endpointUrl.hostname === \"[::1]\";\n if (endpointUrl.username || endpointUrl.password || (endpointUrl.protocol !== \"https:\" && !(loopback && endpointUrl.protocol === \"http:\"))) {\n throw new TypeError(\"endpoint must use HTTPS (HTTP is allowed only for loopback testing)\");\n }\n if (!/^odla_hrn_[0-9a-f]{64}$/.test(options.token)) throw new TypeError(\"invalid harness runner credential\");\n const requestTimeoutMs = options.requestTimeoutMs ?? 30_000;\n if (!Number.isSafeInteger(requestTimeoutMs) || requestTimeoutMs < 1_000 || requestTimeoutMs > 120_000) {\n throw new TypeError(\"requestTimeoutMs must be an integer from 1000 to 120000\");\n }\n const request = options.fetch ?? fetch;\n const call = async <T>(path: string, body: unknown, allowEmpty = false): Promise<T | null> => {\n const timeout = AbortSignal.timeout(requestTimeoutMs);\n const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;\n const response = await request(`${endpoint}${path}`, {\n method: \"POST\",\n headers: { authorization: `Bearer ${options.token}`, \"content-type\": \"application/json\" },\n body: JSON.stringify(body),\n redirect: \"error\",\n signal,\n });\n if (allowEmpty && response.status === 204) return null;\n const value = await response.json().catch(() => null) as { error?: { code?: string; message?: string } } | null;\n if (!response.ok) throw new HarnessControlError(\n value?.error?.message ?? `harness control request failed (${response.status})`,\n response.status,\n value?.error?.code,\n );\n return value as T;\n };\n return {\n lease: async (workspaces) => {\n const body = await call<{ lease: HarnessLease }>(\"/registry/harness/lease\", { workspaces }, true);\n return body?.lease ?? null;\n },\n heartbeat: async (attemptId, leaseId) => {\n const body = await call<{ cancelRequested: boolean; expiresAt: number }>(\n `/registry/harness/attempts/${encodeURIComponent(attemptId)}/heartbeat`, { leaseId },\n );\n return body!;\n },\n appendEvents: async (attemptId, leaseId, events: HarnessEventInput[]) => {\n await call(`/registry/harness/attempts/${encodeURIComponent(attemptId)}/events`, { leaseId, events });\n },\n infer: async (attemptId, leaseId, inference: HarnessInferenceRequest) => {\n const body = await call<HarnessInferenceResponse>(\n `/registry/harness/attempts/${encodeURIComponent(attemptId)}/inference`, { leaseId, ...inference },\n );\n return body!;\n },\n complete: async (attemptId, leaseId, completion: HarnessCompletion) => {\n await call(`/registry/harness/attempts/${encodeURIComponent(attemptId)}/complete`, { leaseId, ...completion });\n },\n };\n}\n","import type { Ai } from \"@odla-ai/ai\";\nimport type { HarnessAiConnection, HarnessInferenceRequest, HarnessInferenceResponse } from \"./types\";\n\n/**\n * Adapt the normalized odla AI chat surface to a harness connection.\n * Provider credentials remain in the process that owns `ai`; only normalized\n * requests and responses cross the container protocol.\n */\nexport function createOdlaAiConnection(\n ai: Pick<Ai, \"chat\">,\n options: { model?: string; policyVersion?: number } = {},\n): HarnessAiConnection {\n return {\n async infer(request: HarnessInferenceRequest): Promise<HarnessInferenceResponse> {\n const response = await ai.chat({ ...request.call, ...(options.model ? { model: options.model } : {}) });\n return {\n requestId: request.requestId,\n response,\n receipt: {\n provider: response.provider,\n model: response.model,\n policyVersion: options.policyVersion ?? 1,\n inputTokens: response.usage.inputTokens ?? 0,\n outputTokens: response.usage.outputTokens ?? 0,\n },\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACKO,IAAM,2BAA2B;AAGjC,IAAM,mBAAmB;;;ACJhC,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,IAA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S;AAAA,IACxB;AAAA,IACA,WAAW,OAAO,WAAW,YAAY;AACvC,YAAM,OAAO,MAAM;AAAA,QACjB,8BAA8B,mBAAmB,SAAS,CAAC;AAAA,QAAc,EAAE,QAAQ;AAAA,MACrF;AACA,aAAO;AAAA,IACT;AAAA,IACA,cAAc,OAAO,WAAW,SAAS,WAAgC;AACvE,YAAM,KAAK,8BAA8B,mBAAmB,SAAS,CAAC,WAAW,EAAE,SAAS,OAAO,CAAC;AAAA,IACtG;AAAA,IACA,OAAO,OAAO,WAAW,SAAS,cAAuC;AACvE,YAAM,OAAO,MAAM;AAAA,QACjB,8BAA8B,mBAAmB,SAAS,CAAC;AAAA,QAAc,EAAE,SAAS,GAAG,UAAU;AAAA,MACnG;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,OAAO,WAAW,SAAS,eAAkC;AACrE,YAAM,KAAK,8BAA8B,mBAAmB,SAAS,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC;AAAA,IAC/G;AAAA,EACF;AACF;;;AC1EO,SAAS,uBACd,IACA,UAAsD,CAAC,GAClC;AACrB,SAAO;AAAA,IACL,MAAM,MAAM,SAAqE;AAC/E,YAAM,WAAW,MAAM,GAAG,KAAK,EAAE,GAAG,QAAQ,MAAM,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC,EAAG,CAAC;AACtG,aAAO;AAAA,QACL,WAAW,QAAQ;AAAA,QACnB;AAAA,QACA,SAAS;AAAA,UACP,UAAU,SAAS;AAAA,UACnB,OAAO,SAAS;AAAA,UAChB,eAAe,QAAQ,iBAAiB;AAAA,UACxC,aAAa,SAAS,MAAM,eAAe;AAAA,UAC3C,cAAc,SAAS,MAAM,gBAAgB;AAAA,QAC/C;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["record"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,7 @@
1
- import { f as HarnessToolBroker, C as CodeSessionEventData, g as HarnessToolResponse, h as HarnessAgentInput, b as HarnessEventInput, i as HarnessAgentOutput, H as HarnessControlPlane, j as HarnessAiConnection } from './types-D-Kv1svf.cjs';
2
- export { k as CodeSessionEvent, l as CodeToolLocationPreview, m as CodeToolPresentation, D as DEFAULT_AI_ROUTE, n as HARNESS_PROTOCOL_VERSION, o as HarnessActor, p as HarnessAttemptStatus, q as HarnessAttemptSummary, c as HarnessCompletion, r as HarnessEvent, d as HarnessInferenceRequest, e as HarnessInferenceResponse, a as HarnessLease, s as HarnessPolicy, t as HarnessRunnerView, u as HarnessTaskDetail, v as HarnessTaskSpec, w as HarnessTaskStatus, x as HarnessTaskSummary, y as HarnessToolName, z as HarnessToolRequest } from './types-D-Kv1svf.cjs';
1
+ import { g as HarnessToolBroker, h as HarnessToolResponse, i as HarnessAgentInput, b as HarnessEventInput, j as HarnessAgentOutput, H as HarnessControlPlane, k as HarnessAiConnection } from './types-DM-UgoBN.cjs';
2
+ export { D as DEFAULT_AI_ROUTE, l as HARNESS_PROTOCOL_VERSION, m as HarnessActor, n as HarnessAttemptStatus, o as HarnessAttemptSummary, c as HarnessCompletion, p as HarnessEvent, d as HarnessInferenceRequest, e as HarnessInferenceResponse, a as HarnessLease, q as HarnessPolicy, r as HarnessRunnerView, s as HarnessTaskDetail, t as HarnessTaskSpec, u as HarnessTaskStatus, v as HarnessTaskSummary, f as HarnessToolName, w as HarnessToolRequest } from './types-DM-UgoBN.cjs';
3
+ import { C as CodeSessionEventData } from './code-session-event-data-C6mQB76s.cjs';
4
+ export { a as CodeSessionEvent, b as CodeToolLocationPreview, c as CodeToolPresentation } from './code-session-event-data-C6mQB76s.cjs';
3
5
  import { Ai } from '@odla-ai/ai';
4
6
 
5
7
  /** Longest failure reason forwarded onto a session event. A reason is a short
@@ -11,16 +13,25 @@ declare const MAX_FAILURE_REASON = 240;
11
13
  * failed and could never see why — which is what made an 84% apply_patch
12
14
  * failure rate undiagnosable (PM bugs 515655ec and 38d92f1d). */
13
15
  declare function toolFailureReason(response: HarnessToolResponse): string | undefined;
16
+ /** Longest serialized tool input, and longest tool output, a verbose stream carries. */
17
+ declare const MAX_VERBOSE_TOOL_BYTES = 4096;
18
+ /** A tool input as a verbose watcher sees it: the object when it fits, else a
19
+ * marker saying how large it was. A stream must never carry a whole file. */
20
+ declare function boundedToolInput(value: Record<string, unknown>): Record<string, unknown>;
21
+ /** A tool output as a verbose watcher sees it, bounded. */
22
+ declare function boundedToolOutput(content: string): string;
14
23
  /** Wrap `broker` so every effect reports its start and its finish.
15
24
  *
16
25
  * `emit` is the engine's own event sink; it already swallows its own errors, so
17
- * reporting can never fail the effect it is reporting on.
26
+ * reporting can never fail the effect it is reporting on. With `detail:
27
+ * "verbose"` each event also carries the bounded input and output.
18
28
  */
19
29
  declare function observedBroker(input: {
20
30
  broker: HarnessToolBroker;
21
31
  operationIdFor: (requestId: string) => string;
22
32
  emit: (event: CodeSessionEventData) => Promise<void>;
23
33
  now?: () => number;
34
+ detail?: "standard" | "verbose";
24
35
  }): HarnessToolBroker;
25
36
 
26
37
  /** Error raised when an agent emits malformed, oversized, or unsupported protocol data. */
@@ -62,4 +73,4 @@ declare function createOdlaAiConnection(ai: Pick<Ai, "chat">, options?: {
62
73
  policyVersion?: number;
63
74
  }): HarnessAiConnection;
64
75
 
65
- export { CodeSessionEventData, HarnessAgentInput, HarnessAgentOutput, HarnessAiConnection, type HarnessControlClientOptions, HarnessControlError, HarnessControlPlane, HarnessEventInput, HarnessProtocolError, HarnessToolBroker, HarnessToolResponse, MAX_FAILURE_REASON, createHarnessControlClient, createOdlaAiConnection, encodeAgentInput, makeHarnessEvent, observedBroker, parseAgentOutput, toolFailureReason };
76
+ export { CodeSessionEventData, HarnessAgentInput, HarnessAgentOutput, HarnessAiConnection, type HarnessControlClientOptions, HarnessControlError, HarnessControlPlane, HarnessEventInput, HarnessProtocolError, HarnessToolBroker, HarnessToolResponse, MAX_FAILURE_REASON, MAX_VERBOSE_TOOL_BYTES, boundedToolInput, boundedToolOutput, createHarnessControlClient, createOdlaAiConnection, encodeAgentInput, makeHarnessEvent, observedBroker, parseAgentOutput, toolFailureReason };