@zvada/agent-server 0.3.25 → 0.3.27

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 (256) hide show
  1. package/CHANGELOG.md +113 -0
  2. package/README.md +4 -1
  3. package/dist/client/client.js +27 -11
  4. package/dist/client/connection.js +35 -3
  5. package/dist/core/agents/acp/acp-agent.js +91 -14
  6. package/dist/core/agents/acp/mappings.js +5 -1
  7. package/dist/core/agents/claude-code/approvals.js +3 -2
  8. package/dist/core/agents/claude-code/claude-agent.js +12 -2
  9. package/dist/core/agents/claude-code/mcp.js +9 -1
  10. package/dist/core/agents/claude-code/models.js +16 -10
  11. package/dist/core/agents/claude-code/options.js +23 -2
  12. package/dist/core/agents/claude-code/session.js +21 -1
  13. package/dist/core/agents/claude-code/tools.js +9 -4
  14. package/dist/core/agents/claude-code/turn.js +2 -0
  15. package/dist/core/agents/codex-app-server/adapter.js +2 -0
  16. package/dist/core/agents/codex-app-server/client.js +8 -5
  17. package/dist/core/agents/codex-app-server/codex-agent.js +35 -2
  18. package/dist/core/agents/codex-app-server/effort.js +13 -6
  19. package/dist/core/agents/codex-app-server/mcp.js +35 -18
  20. package/dist/core/agents/codex-app-server/models.js +10 -10
  21. package/dist/core/agents/codex-app-server/options.js +11 -2
  22. package/dist/core/agents/codex-app-server/plan-approval.js +1 -1
  23. package/dist/core/agents/codex-app-server/session.js +11 -4
  24. package/dist/core/agents/codex-app-server/thread-settings.js +30 -11
  25. package/dist/core/agents/host-tools.js +493 -0
  26. package/dist/core/agents/mcp-config.js +6 -2
  27. package/dist/core/agents/scripted/scripted-agent.js +39 -6
  28. package/dist/core/agents/scripted/steps.js +5 -1
  29. package/dist/core/agents/session-agent.js +70 -2
  30. package/dist/core/agents/thinking-levels.js +8 -5
  31. package/dist/core/index.js +1 -0
  32. package/dist/core/presets.js +16 -3
  33. package/dist/core/processes/lifeline.js +9 -5
  34. package/dist/core/provision/pins.js +7 -16
  35. package/dist/core/provision/releases.js +25 -25
  36. package/dist/core/proxy/loopback.js +22 -4
  37. package/dist/core/runtime/agent-runtime.js +15 -5
  38. package/dist/core/runtime/event-processor.js +13 -8
  39. package/dist/core/runtime/origin-line.js +42 -0
  40. package/dist/core/runtime/request-broker.js +2 -1
  41. package/dist/core/runtime/steering.js +4 -3
  42. package/dist/core/runtime/turn.js +6 -4
  43. package/dist/operator/errors.js +97 -0
  44. package/dist/operator/index.js +10 -5
  45. package/dist/operator/mcp.js +7 -12
  46. package/dist/operator/operator.js +1336 -380
  47. package/dist/operator/refs.js +59 -0
  48. package/dist/operator/render.js +171 -74
  49. package/dist/operator/session-tools.js +87 -0
  50. package/dist/operator/types.js +30 -0
  51. package/dist/operator/view.js +82 -27
  52. package/dist/protocol/config.js +33 -6
  53. package/dist/protocol/conversation.js +3 -0
  54. package/dist/protocol/history.js +2 -1
  55. package/dist/protocol/index.js +1 -0
  56. package/dist/protocol/lifecycle.js +19 -0
  57. package/dist/protocol/model-catalog.js +58 -18
  58. package/dist/protocol/models.js +6 -27
  59. package/dist/protocol/origin.js +39 -0
  60. package/dist/protocol/reduce.js +2 -0
  61. package/dist/protocol/thinking.js +22 -9
  62. package/dist/protocol/wire-api.js +2 -2
  63. package/dist/protocol/wire.js +17 -0
  64. package/dist/server/bin.js +6 -4
  65. package/dist/server/routes.js +15 -5
  66. package/dist/types/client/client.d.ts.map +1 -1
  67. package/dist/types/client/connection.d.ts +14 -2
  68. package/dist/types/client/connection.d.ts.map +1 -1
  69. package/dist/types/client/turns.d.ts +2 -2
  70. package/dist/types/client/turns.d.ts.map +1 -1
  71. package/dist/types/core/agents/acp/acp-agent.d.ts +15 -0
  72. package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
  73. package/dist/types/core/agents/acp/mappings.d.ts +5 -1
  74. package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
  75. package/dist/types/core/agents/acp/requests.d.ts +2 -0
  76. package/dist/types/core/agents/acp/requests.d.ts.map +1 -1
  77. package/dist/types/core/agents/base.d.ts +2 -0
  78. package/dist/types/core/agents/base.d.ts.map +1 -1
  79. package/dist/types/core/agents/claude-code/approvals.d.ts +2 -1
  80. package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
  81. package/dist/types/core/agents/claude-code/claude-agent.d.ts +1 -0
  82. package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
  83. package/dist/types/core/agents/claude-code/mcp.d.ts +8 -1
  84. package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
  85. package/dist/types/core/agents/claude-code/models.d.ts +9 -5
  86. package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
  87. package/dist/types/core/agents/claude-code/options.d.ts +10 -1
  88. package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
  89. package/dist/types/core/agents/claude-code/session.d.ts +2 -0
  90. package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
  91. package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
  92. package/dist/types/core/agents/claude-code/turn.d.ts +3 -0
  93. package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -1
  94. package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
  95. package/dist/types/core/agents/codex-app-server/client.d.ts +2 -0
  96. package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
  97. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +11 -0
  98. package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
  99. package/dist/types/core/agents/codex-app-server/effort.d.ts +7 -7
  100. package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
  101. package/dist/types/core/agents/codex-app-server/mcp.d.ts +11 -3
  102. package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
  103. package/dist/types/core/agents/codex-app-server/models.d.ts +4 -1
  104. package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
  105. package/dist/types/core/agents/codex-app-server/options.d.ts +9 -2
  106. package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
  107. package/dist/types/core/agents/codex-app-server/requests.d.ts +2 -0
  108. package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
  109. package/dist/types/core/agents/codex-app-server/session.d.ts +6 -3
  110. package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
  111. package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
  112. package/dist/types/core/agents/host-tools.d.ts +162 -0
  113. package/dist/types/core/agents/host-tools.d.ts.map +1 -0
  114. package/dist/types/core/agents/mcp-config.d.ts +11 -2
  115. package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
  116. package/dist/types/core/agents/scripted/scripted-agent.d.ts +14 -1
  117. package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -1
  118. package/dist/types/core/agents/scripted/steps.d.ts.map +1 -1
  119. package/dist/types/core/agents/session-agent.d.ts +2 -7
  120. package/dist/types/core/agents/session-agent.d.ts.map +1 -1
  121. package/dist/types/core/agents/thinking-levels.d.ts +7 -3
  122. package/dist/types/core/agents/thinking-levels.d.ts.map +1 -1
  123. package/dist/types/core/index.d.ts +1 -0
  124. package/dist/types/core/index.d.ts.map +1 -1
  125. package/dist/types/core/presets.d.ts +11 -1
  126. package/dist/types/core/presets.d.ts.map +1 -1
  127. package/dist/types/core/processes/lifeline.d.ts.map +1 -1
  128. package/dist/types/core/provision/pins.d.ts +5 -4
  129. package/dist/types/core/provision/pins.d.ts.map +1 -1
  130. package/dist/types/core/proxy/loopback.d.ts.map +1 -1
  131. package/dist/types/core/runtime/agent-runtime.d.ts +4 -2
  132. package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
  133. package/dist/types/core/runtime/event-processor.d.ts +2 -2
  134. package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
  135. package/dist/types/core/runtime/origin-line.d.ts +15 -0
  136. package/dist/types/core/runtime/origin-line.d.ts.map +1 -0
  137. package/dist/types/core/runtime/request-broker.d.ts +1 -1
  138. package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
  139. package/dist/types/core/runtime/steering.d.ts +7 -4
  140. package/dist/types/core/runtime/steering.d.ts.map +1 -1
  141. package/dist/types/core/runtime/turn.d.ts.map +1 -1
  142. package/dist/types/operator/errors.d.ts +83 -0
  143. package/dist/types/operator/errors.d.ts.map +1 -0
  144. package/dist/types/operator/index.d.ts +10 -5
  145. package/dist/types/operator/index.d.ts.map +1 -1
  146. package/dist/types/operator/mcp.d.ts +1 -1
  147. package/dist/types/operator/mcp.d.ts.map +1 -1
  148. package/dist/types/operator/operator.d.ts +15 -197
  149. package/dist/types/operator/operator.d.ts.map +1 -1
  150. package/dist/types/operator/refs.d.ts +25 -0
  151. package/dist/types/operator/refs.d.ts.map +1 -0
  152. package/dist/types/operator/render.d.ts +59 -19
  153. package/dist/types/operator/render.d.ts.map +1 -1
  154. package/dist/types/operator/session-tools.d.ts +61 -0
  155. package/dist/types/operator/session-tools.d.ts.map +1 -0
  156. package/dist/types/operator/types.d.ts +441 -0
  157. package/dist/types/operator/types.d.ts.map +1 -0
  158. package/dist/types/operator/view.d.ts +19 -29
  159. package/dist/types/operator/view.d.ts.map +1 -1
  160. package/dist/types/protocol/config.d.ts +32 -24
  161. package/dist/types/protocol/config.d.ts.map +1 -1
  162. package/dist/types/protocol/conversation.d.ts +48 -39
  163. package/dist/types/protocol/conversation.d.ts.map +1 -1
  164. package/dist/types/protocol/execution.d.ts +2 -18
  165. package/dist/types/protocol/execution.d.ts.map +1 -1
  166. package/dist/types/protocol/history.d.ts +1 -1
  167. package/dist/types/protocol/history.d.ts.map +1 -1
  168. package/dist/types/protocol/index.d.ts +1 -0
  169. package/dist/types/protocol/index.d.ts.map +1 -1
  170. package/dist/types/protocol/lifecycle.d.ts +48 -74
  171. package/dist/types/protocol/lifecycle.d.ts.map +1 -1
  172. package/dist/types/protocol/model-catalog.d.ts.map +1 -1
  173. package/dist/types/protocol/models.d.ts +4 -42
  174. package/dist/types/protocol/models.d.ts.map +1 -1
  175. package/dist/types/protocol/origin.d.ts +49 -0
  176. package/dist/types/protocol/origin.d.ts.map +1 -0
  177. package/dist/types/protocol/reduce.d.ts.map +1 -1
  178. package/dist/types/protocol/thinking.d.ts +19 -19
  179. package/dist/types/protocol/thinking.d.ts.map +1 -1
  180. package/dist/types/protocol/wire-api.d.ts +59 -106
  181. package/dist/types/protocol/wire-api.d.ts.map +1 -1
  182. package/dist/types/protocol/wire.d.ts +81 -119
  183. package/dist/types/protocol/wire.d.ts.map +1 -1
  184. package/dist/types/server/routes.d.ts.map +1 -1
  185. package/docs/consuming.md +124 -132
  186. package/docs/deploy.md +6 -5
  187. package/docs/harnesses.md +79 -31
  188. package/docs/sync-history.md +2 -1
  189. package/package.json +4 -4
  190. package/src/client/client.ts +36 -9
  191. package/src/client/connection.ts +31 -1
  192. package/src/client/turns.ts +2 -1
  193. package/src/core/agents/acp/acp-agent.ts +123 -17
  194. package/src/core/agents/acp/mappings.ts +5 -1
  195. package/src/core/agents/acp/requests.ts +2 -0
  196. package/src/core/agents/base.ts +2 -0
  197. package/src/core/agents/claude-code/approvals.ts +4 -3
  198. package/src/core/agents/claude-code/claude-agent.ts +14 -2
  199. package/src/core/agents/claude-code/mcp.ts +11 -1
  200. package/src/core/agents/claude-code/models.ts +15 -10
  201. package/src/core/agents/claude-code/options.ts +33 -3
  202. package/src/core/agents/claude-code/session.ts +26 -1
  203. package/src/core/agents/claude-code/tools.ts +10 -4
  204. package/src/core/agents/claude-code/turn.ts +4 -0
  205. package/src/core/agents/codex-app-server/adapter.ts +2 -0
  206. package/src/core/agents/codex-app-server/client.ts +11 -5
  207. package/src/core/agents/codex-app-server/codex-agent.ts +45 -1
  208. package/src/core/agents/codex-app-server/effort.ts +15 -20
  209. package/src/core/agents/codex-app-server/mcp.ts +46 -23
  210. package/src/core/agents/codex-app-server/models.ts +10 -10
  211. package/src/core/agents/codex-app-server/options.ts +16 -2
  212. package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
  213. package/src/core/agents/codex-app-server/requests.ts +2 -0
  214. package/src/core/agents/codex-app-server/session.ts +19 -4
  215. package/src/core/agents/codex-app-server/thread-settings.ts +31 -11
  216. package/src/core/agents/host-tools.ts +649 -0
  217. package/src/core/agents/mcp-config.ts +15 -3
  218. package/src/core/agents/scripted/scripted-agent.ts +51 -5
  219. package/src/core/agents/scripted/steps.ts +5 -1
  220. package/src/core/agents/session-agent.ts +78 -2
  221. package/src/core/agents/thinking-levels.ts +9 -6
  222. package/src/core/index.ts +9 -0
  223. package/src/core/presets.ts +28 -4
  224. package/src/core/processes/lifeline.ts +9 -5
  225. package/src/core/provision/pins.ts +7 -16
  226. package/src/core/provision/releases.ts +25 -25
  227. package/src/core/proxy/loopback.ts +25 -4
  228. package/src/core/runtime/agent-runtime.ts +31 -7
  229. package/src/core/runtime/event-processor.ts +13 -6
  230. package/src/core/runtime/origin-line.ts +43 -0
  231. package/src/core/runtime/request-broker.ts +2 -0
  232. package/src/core/runtime/steering.ts +8 -4
  233. package/src/core/runtime/turn.ts +11 -4
  234. package/src/operator/errors.ts +218 -0
  235. package/src/operator/index.ts +18 -23
  236. package/src/operator/mcp.ts +7 -16
  237. package/src/operator/operator.ts +1583 -613
  238. package/src/operator/refs.ts +75 -0
  239. package/src/operator/render.ts +208 -98
  240. package/src/operator/session-tools.ts +126 -0
  241. package/src/operator/types.ts +505 -0
  242. package/src/operator/view.ts +93 -42
  243. package/src/protocol/config.ts +36 -7
  244. package/src/protocol/conversation.ts +3 -0
  245. package/src/protocol/history.ts +2 -1
  246. package/src/protocol/index.ts +1 -0
  247. package/src/protocol/lifecycle.ts +21 -0
  248. package/src/protocol/model-catalog.ts +58 -18
  249. package/src/protocol/models.ts +6 -26
  250. package/src/protocol/origin.ts +47 -0
  251. package/src/protocol/reduce.ts +4 -0
  252. package/src/protocol/thinking.ts +27 -14
  253. package/src/protocol/wire-api.ts +2 -2
  254. package/src/protocol/wire.ts +18 -0
  255. package/src/server/bin.ts +6 -4
  256. package/src/server/routes.ts +16 -5
@@ -59,7 +59,11 @@ export const ScriptStepSchema = z.union([
59
59
  z.strictObject({ echo: z.enum(["input", "config"]) }),
60
60
  /** A pause of this many ms. */
61
61
  z.strictObject({ wait: Ms }),
62
- /** Runs until the turn is cancelled, then `stopTakes` ms more before it stops, also when the cancel came first. */
62
+ /**
63
+ * Runs until the turn is cancelled, then `stopTakes` ms more before it
64
+ * stops, also when the cancel came first; not in an async generator's
65
+ * script, whose next step a cancel does not wait for.
66
+ */
63
67
  z.strictObject({ hang: z.literal(true), stopTakes: Ms.optional() }),
64
68
  /**
65
69
  * Ends the turn in an error with this message: of `category` when given,
@@ -2,6 +2,7 @@ import { withTimeout } from "../utils/deadline.js";
2
2
  import { SessionResumeError, TurnActiveError } from "../utils/errors.js";
3
3
  import { BaseAgent, CANCEL_CONFIRM_MS, } from "./base.js";
4
4
  import { configFingerprint } from "./config-fingerprint.js";
5
+ import { withoutSecret } from "./host-tools.js";
5
6
  /**
6
7
  * The execution lifecycle the engine's own harnesses extend: one turn owns a
7
8
  * logical session from preparation through native cleanup, with steering,
@@ -9,6 +10,43 @@ import { configFingerprint } from "./config-fingerprint.js";
9
10
  * exported while its design is a Draft (LLP 0016); a product's own harness
10
11
  * extends `BaseAgent`, the public base.
11
12
  */
13
+ // @ref LLP 0018#who-can-read-the-secret — the broker publishes a request's options too
14
+ /**
15
+ * A permission request as the broker publishes it: its tool call and its
16
+ * options (a harness's own labels and ids) without the secret, and the
17
+ * option picked mapped back to the harness's own id.
18
+ */
19
+ async function permission(ask, scrub, call, rest) {
20
+ const [opts] = rest;
21
+ if (!opts)
22
+ return ask(scrub(call), ...rest);
23
+ const scrubbed = scrub(opts);
24
+ // A choice whose id held the secret gets an opaque id of its own, unique, so
25
+ // two redacted the same can never be taken for each other.
26
+ const used = new Set((scrubbed.options ?? []).flatMap((option, index) => opts.options?.[index]?.optionId === option.optionId ? [option.optionId] : []));
27
+ const opaque = (index) => {
28
+ let id = `redacted-option-${index}`;
29
+ while (used.has(id))
30
+ id += "-";
31
+ used.add(id);
32
+ return id;
33
+ };
34
+ const choices = (scrubbed.options ?? []).map((option, index) => {
35
+ const own = opts.options?.[index]?.optionId ?? option.optionId;
36
+ return {
37
+ option: own === option.optionId ? option : { ...option, optionId: opaque(index) },
38
+ own,
39
+ };
40
+ });
41
+ const native = new Map(choices.map(({ option, own }) => [option.optionId, own]));
42
+ const shown = scrubbed.options
43
+ ? { ...scrubbed, options: choices.map(({ option }) => option) }
44
+ : scrubbed;
45
+ const decision = await ask(scrub(call), shown);
46
+ if (decision.decision === "cancel" || decision.optionId === undefined)
47
+ return decision;
48
+ return { ...decision, optionId: native.get(decision.optionId) ?? decision.optionId };
49
+ }
12
50
  export class SessionAgent extends BaseAgent {
13
51
  terminated = false;
14
52
  /**
@@ -53,8 +91,33 @@ export class SessionAgent extends BaseAgent {
53
91
  try {
54
92
  // The adapter still produces its native cancellation result for an
55
93
  // already-aborted turn. It must not select a conversation or do setup.
56
- const prepared = controller.signal.aborted ? options : this.prepareSessionOptions(options);
57
- yield* this.executeTurn(input, prepared, controller);
94
+ const ready = controller.signal.aborted ? options : this.prepareSessionOptions(options);
95
+ // @ref LLP 0018#who-can-read-the-secret — the session's own secret leaves in no text
96
+ // Kept for the turn once seen: its output may still drain after the session's release.
97
+ let secret;
98
+ const scrub = (value) => {
99
+ secret ??= this.hostSecret(sessionId);
100
+ return withoutSecret(value, secret);
101
+ };
102
+ const { onWarning, onPermissionRequest, onElicitationRequest } = ready;
103
+ const prepared = {
104
+ ...ready,
105
+ ...(onWarning && { onWarning: (warning) => onWarning(scrub(warning)) }),
106
+ // What the broker puts on the stream (a request's input, its title) is the agent's text too.
107
+ ...(onPermissionRequest && {
108
+ onPermissionRequest: (call, ...rest) => permission(onPermissionRequest, scrub, call, rest),
109
+ }),
110
+ ...(onElicitationRequest && {
111
+ onElicitationRequest: (request, ...rest) => onElicitationRequest(scrub(request), ...rest),
112
+ }),
113
+ };
114
+ try {
115
+ for await (const event of this.executeTurn(input, prepared, controller))
116
+ yield scrub(event);
117
+ }
118
+ catch (error) {
119
+ throw scrub(error);
120
+ }
58
121
  }
59
122
  finally {
60
123
  this.executed.set(sessionId, options.turnId);
@@ -167,6 +230,11 @@ export class SessionAgent extends BaseAgent {
167
230
  if (turn?.turnId === options.turnId)
168
231
  turn.deliver = undefined;
169
232
  }
233
+ /** Native protocol execution; options are prepared and the session is exclusively owned. */
234
+ /** The session's host-tools secret, which no event, warning or error it lets out may hold. */
235
+ hostSecret(_sessionId) {
236
+ return undefined;
237
+ }
170
238
  prepareSessionOptions(options) {
171
239
  const boundary = configFingerprint({
172
240
  cwd: options.cwd,
@@ -1,9 +1,12 @@
1
- import { THINKING_LEVELS, isThinkingLevel } from "../../protocol/index.js";
2
- /** The values that are thinking levels, once each, lowest first. */
3
- export function knownThinkingLevels(values) {
1
+ /**
2
+ * The levels a harness lists: each non-blank string once, in the order given.
3
+ * The order is the harness's own (both CLIs list lowest first), and a name
4
+ * this build does not know is kept.
5
+ */
6
+ export function listedThinkingLevels(values) {
4
7
  const levels = new Set();
5
8
  for (const value of values)
6
- if (typeof value === "string" && isThinkingLevel(value))
9
+ if (typeof value === "string" && /\S/.test(value))
7
10
  levels.add(value);
8
- return THINKING_LEVELS.filter((level) => levels.has(level));
11
+ return [...levels];
9
12
  }
@@ -6,6 +6,7 @@ export { EventSinkError, callbackSink, CollectingSink, serialSink, teeSink, } fr
6
6
  export { BaseAgent, } from "./agents/base.js";
7
7
  export { AgentRegistry } from "./agents/registry.js";
8
8
  export { credentialsFromUrl } from "./agents/credentials.js";
9
+ export { HOST_TOOL_TIMEOUT_MS, } from "./agents/host-tools.js";
9
10
  export { INHERIT_CONFIGS, isInheritConfig, } from "./agents/inherit-config.js";
10
11
  // Native processes: each CLI in a group of its own, held by the lifeline, recorded, swept at restart.
11
12
  export { DEFAULT_GRACE_MS, NativeProcess, NativeProcesses, } from "./processes/native-processes.js";
@@ -21,6 +21,7 @@ const HARNESSES = {
21
21
  onDiagnostic: opts.onDiagnostic,
22
22
  ...opts.claudeCode,
23
23
  credentials: opts.credentials,
24
+ hostTools: opts.hostTools,
24
25
  idleTimeoutMs: opts.idleTimeoutMs,
25
26
  cancelConfirmMs: opts.cancelConfirmMs,
26
27
  cancelGraceMs: opts.cancelGraceMs,
@@ -34,6 +35,7 @@ const HARNESSES = {
34
35
  new CodexAppServerAgent({
35
36
  ...opts.codexAppServer,
36
37
  credentials: opts.credentials,
38
+ hostTools: opts.hostTools,
37
39
  idleTimeoutMs: opts.idleTimeoutMs,
38
40
  cancelConfirmMs: opts.cancelConfirmMs,
39
41
  cancelGraceMs: opts.cancelGraceMs,
@@ -47,9 +49,16 @@ const HARNESSES = {
47
49
  if (!opts.acp) {
48
50
  throw new Error("the acp harness requires CreateRegistryOptions.acp (resolveLaunch)");
49
51
  }
50
- const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs } = opts;
52
+ const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs, hostTools } = opts;
51
53
  return [
52
- new AcpAgent({ ...opts.acp, idleTimeoutMs, cancelConfirmMs, cancelGraceMs, processes }),
54
+ new AcpAgent({
55
+ ...opts.acp,
56
+ idleTimeoutMs,
57
+ cancelConfirmMs,
58
+ cancelGraceMs,
59
+ hostTools,
60
+ processes,
61
+ }),
53
62
  createAcpTransformer,
54
63
  ];
55
64
  },
@@ -58,7 +67,10 @@ const HARNESSES = {
58
67
  throw new Error("the scripted harness requires CreateRegistryOptions.scripted (turn)");
59
68
  }
60
69
  // @ref LLP 0007#what-each-harness-does — it starts none, so a restart vouches for it
61
- return [new ScriptedAgent({ ...opts.scripted, processes }), createScriptedTransformer];
70
+ return [
71
+ new ScriptedAgent({ ...opts.scripted, hostTools: opts.hostTools, processes }),
72
+ createScriptedTransformer,
73
+ ];
62
74
  },
63
75
  };
64
76
  const atTheTop = (option) => `set ${option} at the top level of the registry's options`;
@@ -69,6 +81,7 @@ const SAID_ONCE = {
69
81
  cancelConfirmMs: atTheTop("cancelConfirmMs"),
70
82
  cancelGraceMs: atTheTop("cancelGraceMs"),
71
83
  inheritConfig: atTheTop("inheritConfig"),
84
+ hostTools: atTheTop("hostTools"),
72
85
  processes: "the registry gives every harness its processes; say how they are owned with nativeProcesses",
73
86
  resolveCliPath: "the registry's provisioner finds each CLI; name one with provision.overrides",
74
87
  };
@@ -85,6 +85,13 @@ const RESPAWN_WINDOW_MS = 1_000;
85
85
  */
86
86
  function startShell(ticks, exited, failed) {
87
87
  const args = ["-c", LIFELINE_SCRIPT, LIFELINE_NAME, ticks];
88
+ // @ref LLP 0007#the-environment-a-process-is-given — only what its script needs
89
+ // It lives as long as the engine, and any process of this user can read its
90
+ // environment (`/proc/<pid>/environ`): `PATH` finds its `sed`, `awk`, `cat`,
91
+ // `tr` and `sleep`. Nothing else of the engine's environment is given;
92
+ // Node itself adds `NODE_V8_COVERAGE` to every child when the engine runs
93
+ // with it set (Bun adds nothing).
94
+ const env = { PATH: process.env.PATH };
88
95
  const bun = globalThis.Bun;
89
96
  if (bun) {
90
97
  // @ref LLP 0007#the-lifeline — registered before the CLI gets input
@@ -96,10 +103,7 @@ function startShell(ticks, exited, failed) {
96
103
  stdout: "ignore",
97
104
  stderr: "ignore",
98
105
  detached: true,
99
- // @ref LLP 0007#the-environment-a-process-is-given — this process's environment now
100
- // Without one, Bun gives the environment it was launched with: a
101
- // secret the host deleted from `process.env` would live on here.
102
- env: process.env,
106
+ env,
103
107
  onExit: exited,
104
108
  });
105
109
  child.unref();
@@ -116,7 +120,7 @@ function startShell(ticks, exited, failed) {
116
120
  // Node writes a pipe at once when it can (libuv's `uv_try_write`).
117
121
  const child = spawn("/bin/sh", args, {
118
122
  detached: true,
119
- env: process.env,
123
+ env,
120
124
  stdio: ["pipe", "ignore", "ignore"],
121
125
  });
122
126
  child.unref();
@@ -14,22 +14,13 @@
14
14
  * `auto` an installed `@openai/codex` package (a lockfile's) runs instead,
15
15
  * and a `codex` on PATH only in `system` mode.
16
16
  *
17
- * After any bump, run `bun run releases:refresh` (each platform's build and
18
- * its checksums, `releases.ts`) and `bun run models:refresh` (the model
19
- * catalog, which records the versions that listed it); tests fail until both
20
- * match these pins.
17
+ * A bump is `bun run bump -- <tool>`: it writes what changed upstream, moves
18
+ * the pin, and runs both refreshes, `releases:refresh` (each platform's build
19
+ * and its checksums, `releases.ts`) and `models:refresh` (the model catalog,
20
+ * which records the versions that listed it); tests fail until both match
21
+ * these pins. The `bump-clis` skill says what to read and prove.
21
22
  */
22
23
  export const DEFAULT_PINS = {
23
- // 0.3.288 verified 2026-10-03: the paired CLI honors `--thinking-display
24
- // summarized`, so reasoning parts carry text (2.1.233 ignored the flag and
25
- // streamed token-estimate placeholders). Re-check thinking summaries on
26
- // every bump (see options.ts extraArgs).
27
- claude: "0.3.288",
28
- // 0.160.0 re-verified 2026-10-03 against generate-ts: thread/turn/item
29
- // methods, token usage, approvals, and host-managed ChatGPT auth changed
30
- // only additively since 0.153.4. Of the GPT-6 family, 0.153.4 lists only
31
- // gpt-6-astra; the rest needs 0.159 or newer.
32
- // Since 0.160 a thread has one writer: resuming it from a second process
33
- // fails until the first releases it.
34
- codex: "0.160.0",
24
+ claude: "0.3.327",
25
+ codex: "0.169.1",
35
26
  };
@@ -5,63 +5,63 @@
5
5
  */
6
6
  export const CLI_RELEASES = {
7
7
  claude: {
8
- version: "0.3.288",
9
- cli: "2.1.288",
8
+ version: "0.3.327",
9
+ cli: "2.1.327",
10
10
  builds: {
11
11
  "darwin-arm64": {
12
- integrity: "sha512-85niGScWj8sr7yqOjSfqINaKv/zB47T45o4NBq1BmpaKRYFK7grtK24LA6C7cjx1Pznp+WT68mo373fbbwFW0A==",
13
- sha256: "bbe93063f7a0879a1021b2891e5c9354e5b3b98433e32efe6750f7710afed750",
12
+ integrity: "sha512-n+tQOPqz264l12BAKBcBPBbdB/bmZ2SfyONtEXQufTU6EeCoQMPS58RSt51Cxk5sDUme1hTF0vVAqRPdhq8tFg==",
13
+ sha256: "76d48205c926c8a6978cfc2171b631bcd01e20bbadd085638bb2ec57bea91c5b",
14
14
  },
15
15
  "darwin-x64": {
16
- integrity: "sha512-hY8MQtgAi+cRedFb+qSqZzAYXIfjC+ZiXtCxKCs4OqWbqrdVZ0GKcEv4nB6MfQGs/Qr4U24cDNuO2lskBbZAWA==",
17
- sha256: "946acab03a55b60e2016e30964c48b96ef6673cb5da684383f4835da410eede0",
16
+ integrity: "sha512-u091X+eQIyqg8BIEYLWJ0o6U3BaivMcf8Im4hI3hti/NGJ6YC5sR+LLEa1RjSIKE+JoOfCxipdCNSKaEI+0d5Q==",
17
+ sha256: "1fe75c05df7be824af1ed80ff9ccdf2be991f3a2212b97e05fc9a3bff2f39ef9",
18
18
  },
19
19
  "linux-arm64": {
20
- integrity: "sha512-CCj0xau64T+Ia+X2wZgjYFSUIWfNJRWIGFbT8+jKiCzQggaBo6OSZ8hAYyME3h13JYrgpyrUTzB5YiwKaw8ZFg==",
21
- sha256: "359ab6a058fcde9741dff54979a212fd134cdf8e8cfc2f8de02bc350b9e2b9d5",
20
+ integrity: "sha512-/k6BfV+L2er67UoLUabcp0w3L1DMemJjoijdxvXDiU8w81fGfHaKWKhRuhUQFmIrMLyMyQcBKaoyUNSLWovPnw==",
21
+ sha256: "acf0ef2f9da8d5ab08f193f007e19a06cbfb608b96a2f1f758d63a92a386cff8",
22
22
  },
23
23
  "linux-x64": {
24
- integrity: "sha512-Y5M496UZKttScbzptA45NI+CMHYONnskw0aq3rJ6s+gE6L6Jy8F8UoKt0lQO11R5xTY65TIeCasjQf/bLavuNg==",
25
- sha256: "0298068b686e7fdbaf9402a7a587bb7f49c0b0e084de09f69145a0719207640c",
24
+ integrity: "sha512-oAdL7KM9UVAZlATeSjh2haeEjex1N7ZcHzWO1tY2hgyhkyLNVw/tWUhITOucxMwokBx++h2dMVjxiPJiZ5uVOQ==",
25
+ sha256: "343c744baa14bfd38286a7cb90871051f04379956da6c5b803a9e66019a76ac9",
26
26
  },
27
27
  "linux-arm64-musl": {
28
- integrity: "sha512-66MD4hzNTqrTL5MN21bSfxm/fhbnM+ERsmWHGEsJojxAWY5DXCUlDkaAYM0rxDpdvLMVt9PpRVIiWDptaiFPxA==",
29
- sha256: "6b9816b225b303dacc17acc9d83016055274498effdbce6227e62d5dbaa762b9",
28
+ integrity: "sha512-oV8/+ZixiPzEW1BStoP9FOXsHcznONaom6S2PwwIfhi5Pxa5fGuloy8TiOB9wK+03zavqt7jmzLgVPF2a2NsTA==",
29
+ sha256: "e44a59ef850788c578adaab7a6487d5d0af9c0844401da9d7263e7b41515754b",
30
30
  },
31
31
  "linux-x64-musl": {
32
- integrity: "sha512-g3HDERLfEamirfp+MJDVl1fT8YYQMILUH65jPzl+SzKLeBu26WmAXAoZFmU4dasEmKZkEnBdL0ZQy3qnDy5EXg==",
33
- sha256: "b4334268a2ce06bf984dab2d6925cc5afe9d2344fa427fc362e266da0d57a894",
32
+ integrity: "sha512-O0nDZ1gpXi83qAdd8SM0gTdjlzrqpOlW0M4W7PfHVrMXWLh9I+1tvHat+s17ehIW6A9VQIWIq4oMwq7jb708Dg==",
33
+ sha256: "d2b02e78664c1347aff8fcee045356ee044116be41d7f412721a6c50182b6d98",
34
34
  },
35
35
  "win32-arm64": {
36
- integrity: "sha512-ijVSU5Vl1L1SlEm1djPNEekxHm9FS5GOitz8kL8KLdYDspMA97bgFM4gy/+riA3qn4ERepJkjdDLE+oYMTO+UA==",
37
- sha256: "5015d2b92866232b85384ac6e5eef4ff155418a92123503e52714c29186af8c6",
36
+ integrity: "sha512-a5ju83mylDvUwvQyRt1E0TQ0ar2nzVMPeWZhjcmgpB1cNTjf+KT5jgUnLvxPOG2tyjhm8bYGysRMdgB+tVnhvw==",
37
+ sha256: "d2c3395d252007540a5662a2cfd4d8903a0beb5fa32c893cd13b81be427625a7",
38
38
  },
39
39
  "win32-x64": {
40
- integrity: "sha512-zh4yfGduDEBKUqb3BPtq/cLYwHoScqm7X5fJhmkSs0BJiSJGlb38j6FXWDvoPfe+OXNjE5onNx5HlAnDzsQzrA==",
41
- sha256: "84304f7d4b0cd0ebcbe8318695a260151b48991a6659c3366fdd5da290c0ab91",
40
+ integrity: "sha512-bf52nw4j5RCvkXI5Poj5Qf0jWvuLQ/UPFqdav86UwaGTZZ0txNV33MKBIUoCyxXV6IC1/p2BNfkwmCAZ+Uc9pw==",
41
+ sha256: "d6c8075bfb3b87f1c1254e64b6c35dadc628d21e75930ae51e47047b3f05a4a2",
42
42
  },
43
43
  },
44
44
  },
45
45
  codex: {
46
- version: "0.160.0",
46
+ version: "0.169.1",
47
47
  builds: {
48
48
  "darwin-arm64": {
49
- integrity: "sha512-aefV6cqZA2REZgR//4McyXlp7zLcTti4CI2v3j9IVgNndPBv2kCeNEcz07qeelXcwOdSFPUKb6roA48vZmDgrQ==",
49
+ integrity: "sha512-yOKvCJktlbxdETtXAidz2GcC4z/WMYPmu2plncYJtUI5AhnFIExen8n9eL/El6n9hYbzzZFf1JgyW7yHx6kwTw==",
50
50
  },
51
51
  "darwin-x64": {
52
- integrity: "sha512-ir7cdsPrb9VkqNqpTECoTiomv04xws/FQ968mHQzuL+2J5Da0Dkh2Qlxp7sguDDZJab4YpYmNjQvBVMXbTeQaQ==",
52
+ integrity: "sha512-IbHIskdPWGAXFCdGiB8CosfXXtdvMmusrQ2AdW2kFHd6aSJZ+dvgalwjpxmAytalnNM3pQgXwS/6fU1OclFv8Q==",
53
53
  },
54
54
  "linux-arm64": {
55
- integrity: "sha512-VnVdsS06YlDsL8OwaJjQ3xdqdJNG4i+eBJBV3LytddknzSaF/urijLzVg3ptkwvoj8C7Gn7iWpVE+y8WEaPiCg==",
55
+ integrity: "sha512-6vRE7ZxkngT6L5JQ9WUQ2UnztS6hqyfcQiFqvk0yhcvWsrZLJNiiDZcKzGbLfJK2sDy7tSt9uWdP1cIgMHIkaw==",
56
56
  },
57
57
  "linux-x64": {
58
- integrity: "sha512-KI/73OqGrHmR18s7ya7E1NqV6rT0y3lxr0s8S1qR2m6zU6QRF/HlR529jALLh5vjdUnsRT4Ahoxt0axb4kY99g==",
58
+ integrity: "sha512-KmlHQ/lB9jcn8Yy5z/tWCpSPsqBvI3pU+0PUPccr+pKiiU2NJSCvZcAD7s3dmIFq5ZvGYtGcSn2KdFFdaPQICg==",
59
59
  },
60
60
  "win32-arm64": {
61
- integrity: "sha512-tTvK9ZIGuj9WnYaYOAnfjJVSfPV7dKqWtDHqUPLf0Hadp6SgynTxx7S7iMXRieFeXVOI2XH76KxEHSOTOnz3zw==",
61
+ integrity: "sha512-EYXwgEdHHzwgA0nnDcK4pI98IdReB1aDebtOxcYixM1/GY2Y/76oDFYSs/u6DzA27f6Hhf5V92OwQFw/GLICUQ==",
62
62
  },
63
63
  "win32-x64": {
64
- integrity: "sha512-/gCFcuOmGlQkgGivWCtY8BNEDixh70Pue0HZOk9S8bj2vUIE1GLD9zcNB/KqqDJmn0S+lIttauLpzQnw6HOCHA==",
64
+ integrity: "sha512-fImXWqxwxqHh9+FhJWsRRFiBzgBrSeN1bYTvtGZtUKGTPzHefYAL1agmlf5XScfwY5i5pHsExfdhFekzRBbqIw==",
65
65
  },
66
66
  },
67
67
  },
@@ -35,31 +35,49 @@ async function bridge(handle, req, res) {
35
35
  }
36
36
  res.end();
37
37
  }
38
+ /**
39
+ * Bun's own `Response`. A product's process may have replaced the global one
40
+ * (Hono's Node server does, with a class of its own), and `Bun.serve` refuses
41
+ * any other ("Expected a Response object"); `fetch` still answers with Bun's.
42
+ */
43
+ async function nativeResponse() {
44
+ return (await fetch("data:,")).constructor;
45
+ }
38
46
  /**
39
47
  * Serve `handle` on 127.0.0.1, on a port of its own: with `Bun.serve` under
40
48
  * Bun, whose `node:http` says nothing of a client that left once its request
41
49
  * body was read (a stopped turn's request would run on upstream), and with
42
50
  * `node:http` under Node.
43
51
  */
44
- export function serveLoopback(handle) {
52
+ export async function serveLoopback(handle) {
45
53
  const bun = globalThis.Bun;
46
54
  if (bun) {
55
+ const Native = await nativeResponse();
56
+ const native = (response) =>
57
+ // Not `instanceof`: Hono's class sets Bun's prototype under its own.
58
+ response.constructor === Native
59
+ ? response
60
+ : new Native(response.body, {
61
+ status: response.status,
62
+ statusText: response.statusText,
63
+ headers: [...response.headers],
64
+ });
47
65
  const server = bun.serve({
48
66
  port: 0,
49
67
  hostname: "127.0.0.1",
50
68
  // A model can think longer than any idle limit between the events it streams.
51
69
  idleTimeout: 0,
52
- fetch: (request) => handle(request).catch(() => new Response(null, { status: 502 })),
70
+ fetch: (request) => handle(request).then(native, () => new Native(null, { status: 502 })),
53
71
  });
54
72
  // Nothing on it keeps the process alive.
55
73
  server.unref();
56
- return Promise.resolve({
74
+ return {
57
75
  url: `http://127.0.0.1:${server.port}`,
58
76
  // Not waited for: with a client still connected, Bun's stop can take its time.
59
77
  close: async () => {
60
78
  server.stop(true);
61
79
  },
62
- });
80
+ };
63
81
  }
64
82
  const server = createServer((req, res) => {
65
83
  bridge(handle, req, res).catch(() => {
@@ -1,10 +1,11 @@
1
- import { RunRequestSchema, canonicalJson, turnIdentity } from "../../protocol/index.js";
1
+ import { RunRequestSchema, agentOrigin, canonicalJson, turnIdentity, } from "../../protocol/index.js";
2
2
  import { withTimeout } from "../utils/deadline.js";
3
3
  import { InvalidRequestError, TurnConflictError, TurnForgottenError } from "../utils/errors.js";
4
4
  import { EventSinkError } from "./event-sink.js";
5
5
  import { awaitingInstall, harnessCliProgress, harnessClis } from "./harness-clis.js";
6
6
  import { HarnessLogins } from "./harness-logins.js";
7
7
  import { ModelLists, catalogModelList } from "./model-lists.js";
8
+ import { withOriginLine } from "./origin-line.js";
8
9
  import { StandingRules } from "./permission-policy.js";
9
10
  import { Turn, wellFormedInput, } from "./turn.js";
10
11
  // Caller-supplied IDs need not be UUIDs; encode the tuple without delimiter collisions.
@@ -304,11 +305,15 @@ export class AgentRuntime {
304
305
  * harness cannot take throws, as it would fail a turn.
305
306
  */
306
307
  async steer(sessionId, request) {
307
- const { turnId, steerId, input } = request;
308
+ const { turnId, steerId, input, origin: sent } = request;
308
309
  if (typeof input === "string" ? input.trim() === "" : input.length === 0) {
309
310
  throw new Error("a steer carries input");
310
311
  }
311
- const inputKey = canonicalJson(input);
312
+ // Another sender is another steer; the person's origin, said or not, adds nothing.
313
+ // Its own copy, taken at admission: the caller's object may change after.
314
+ const given = agentOrigin(sent);
315
+ const origin = given && { ...given };
316
+ const inputKey = canonicalJson(origin ? { input, origin } : input);
312
317
  const turn = this.turns.get(turnKeyOf(sessionId, turnId));
313
318
  const known = turn
314
319
  ? turn.steers.find(steerId)
@@ -330,8 +335,13 @@ export class AgentRuntime {
330
335
  const deliver = agent.capabilities.steering ? agent.steer?.bind(agent) : undefined;
331
336
  if (!deliver)
332
337
  return { outcome: "unsupported" };
333
- // Its echo is the caller's input; the agent is given it well-formed.
334
- return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, { ...request, input: wellFormedInput(input) }));
338
+ // Its echo is the caller's input; the agent is given it well-formed, after
339
+ // the sender's line when it is not the person.
340
+ return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, {
341
+ turnId,
342
+ steerId,
343
+ input: wellFormedInput(withOriginLine(input, origin)),
344
+ }), origin);
335
345
  }
336
346
  /** Whether another turn of the session, live or remembered, took this steer id. */
337
347
  steerIdTaken(sessionId, steerId) {
@@ -1,4 +1,4 @@
1
- import { createSteerEchoParts, createUserEchoParts, echoMessageId, extendPart, generateUUIDv7, steerMessageId, } from "../../protocol/index.js";
1
+ import { agentOrigin, createSteerEchoParts, createUserEchoParts, echoMessageId, extendPart, generateUUIDv7, steerMessageId, } from "../../protocol/index.js";
2
2
  /**
3
3
  * The execution `turn.ended` carries: the request, plus what the harness said
4
4
  * it ran. Models the stream reported (Claude's API model, a Codex reroute) say
@@ -81,8 +81,8 @@ export class EventProcessor {
81
81
  * id (`echoMessageId`), so a consumer that minted the turnId can predict the
82
82
  * whole echo instead of reconciling a look-alike against it.
83
83
  */
84
- *echoUserMessage(input) {
85
- yield* this.openMessage("user", undefined, echoMessageId(this.turnId));
84
+ *echoUserMessage(input, origin) {
85
+ yield* this.openMessage("user", undefined, echoMessageId(this.turnId), undefined, origin);
86
86
  for (const part of createUserEchoParts(input, this.turnId)) {
87
87
  yield* this.emitPart(part);
88
88
  }
@@ -96,11 +96,11 @@ export class EventProcessor {
96
96
  * already echoed, is ignored.
97
97
  */
98
98
  *echoSteer(steerId) {
99
- const input = this.steers.read(steerId);
100
- if (input === undefined)
99
+ const steer = this.steers.read(steerId);
100
+ if (steer === undefined)
101
101
  return;
102
- yield* this.openMessage("user", undefined, steerMessageId(steerId));
103
- for (const part of createSteerEchoParts(input, steerId)) {
102
+ yield* this.openMessage("user", undefined, steerMessageId(steerId), undefined, steer.origin);
103
+ for (const part of createSteerEchoParts(steer.input, steerId)) {
104
104
  yield* this.emitPart(part);
105
105
  }
106
106
  yield* this.closeMessage();
@@ -258,7 +258,9 @@ export class EventProcessor {
258
258
  /** Derived id for the user echo; harness messages get a fresh UUIDv7. */
259
259
  id,
260
260
  /** The model the harness said produced it. */
261
- model) {
261
+ model,
262
+ /** A user message's sender, when not the person. */
263
+ origin) {
262
264
  if (this.openMessageId)
263
265
  yield* this.closeMessage();
264
266
  if (role === "assistant")
@@ -267,6 +269,7 @@ export class EventProcessor {
267
269
  // with one that dates it by this event.
268
270
  const startedAt = Date.now();
269
271
  const messageId = id ?? generateUUIDv7(startedAt);
272
+ const sender = agentOrigin(origin);
270
273
  this.openMessageId = messageId;
271
274
  this.openMessageParent = parentToolCallId;
272
275
  const named = role === "assistant" ? this.messageModel(model, parentToolCallId) : {};
@@ -288,6 +291,8 @@ export class EventProcessor {
288
291
  // the model the harness said wrote it (Claude's API model), else the
289
292
  // one it runs the turn on (Codex's thread model), else the request's.
290
293
  ...named,
294
+ // A copy: what a sink does to the event never reaches the request or the model's line.
295
+ ...(role === "user" && sender && { origin: { ...sender } }),
291
296
  timestamp: startedAt,
292
297
  };
293
298
  return messageId;
@@ -0,0 +1,42 @@
1
+ import { agentOrigin } from "../../protocol/index.js";
2
+ // @ref LLP 0019#origin-on-the-wire-and-to-the-model — the line is the engine's, first, and only for an agent
3
+ /**
4
+ * The one line an agent is given before a message that is not the person's,
5
+ * saying who sent it. Undefined for the person, whose messages carry none.
6
+ * The names and ids are the host's and untrusted: each is one JSON-quoted
7
+ * line, so none can end the line, the bracket or the quote.
8
+ */
9
+ export function originLine(origin) {
10
+ const sender = agentOrigin(origin);
11
+ if (!sender)
12
+ return undefined;
13
+ const tail = "the person's own messages never carry this line.";
14
+ if (sender.kind === "session") {
15
+ const named = sender.name ? `session ${quoted(sender.name)}, id` : "session id";
16
+ return `[From another agent, not from the person: ${named} ${quoted(sender.sessionId)}. Weigh it as a colleague's request; ${tail}]`;
17
+ }
18
+ return `[From an outside assistant the person connected, not typed by the person: ${quoted(sender.name)}, id ${quoted(sender.id)}. It acts for the person but is not the person; ${tail}]`;
19
+ }
20
+ /** Line breaks a reader may honour, the C0/C1 controls and bidirectional overrides. */
21
+ // biome-ignore lint/suspicious/noControlCharactersInRegex: the controls are what it drops
22
+ const UNSAFE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u200e\u200f\u202a-\u202e\u2066-\u2069]+/g;
23
+ /** The longest name or id the line carries. */
24
+ const LONGEST = 200;
25
+ /** One line, JSON-quoted: breaks and controls become a space, then it is clipped. */
26
+ function quoted(text) {
27
+ const line = text.replace(UNSAFE, " ").replace(/\s+/g, " ").trim();
28
+ return JSON.stringify(line.length > LONGEST ? `${line.slice(0, LONGEST - 1)}…` : line);
29
+ }
30
+ /**
31
+ * The input as its agent is given it: the sender's line first when it is not
32
+ * the person (to text after a blank line; before a list as a text part of its
33
+ * own). The echo, and every store, keep the caller's input as it was sent.
34
+ */
35
+ export function withOriginLine(input, origin) {
36
+ const line = originLine(origin);
37
+ if (!line)
38
+ return input;
39
+ if (typeof input === "string")
40
+ return `${line}\n\n${input}`;
41
+ return [{ type: "text", text: line }, ...input];
42
+ }
@@ -44,13 +44,14 @@ export class RequestBroker {
44
44
  return !this.closed;
45
45
  }
46
46
  /** Ask whether a tool may run; resolves with the answer, or a cancel. */
47
- askPermission(toolCall, options, signal) {
47
+ askPermission(toolCall, options, signal, purpose = "tool") {
48
48
  const { sessionId, turnId } = this.turn;
49
49
  return this.park("permission", signal, (requestId) => ({
50
50
  type: "permission.requested",
51
51
  sessionId,
52
52
  turnId,
53
53
  requestId,
54
+ purpose,
54
55
  title: toolCall.title ?? `Allow tool: ${toolCall.toolName}`,
55
56
  toolCall,
56
57
  options,
@@ -19,11 +19,12 @@ export class TurnSteers {
19
19
  return this.steers.get(steerId);
20
20
  }
21
21
  /** Take a steer, and hand it to the harness with `deliver`. */
22
- accept(steerId, inputKey, input, deliver) {
22
+ accept(steerId, inputKey, input, deliver, origin) {
23
23
  let answered;
24
24
  const steer = {
25
25
  inputKey,
26
26
  input,
27
+ ...(origin && { origin }),
27
28
  state: "held",
28
29
  result: new Promise((resolve) => {
29
30
  answered = resolve;
@@ -52,13 +53,13 @@ export class TurnSteers {
52
53
  steer.state = "refused";
53
54
  return { outcome: "no_active_turn" };
54
55
  }
55
- /** The agent read a steer: its input, once, for its echo. */
56
+ /** The agent read a steer: its input and sender, once, for its echo. */
56
57
  read(steerId) {
57
58
  const steer = this.steers.get(steerId);
58
59
  if (steer?.state !== "held")
59
60
  return undefined;
60
61
  steer.state = "read";
61
- return steer.input;
62
+ return { input: steer.input, ...(steer.origin && { origin: steer.origin }) };
62
63
  }
63
64
  /** The steers it took that the agent has not read (all of them, once the turn is over). */
64
65
  undelivered() {
@@ -2,6 +2,7 @@ import { DEFAULT_TOKEN_USAGE, errorInfo } from "../../protocol/index.js";
2
2
  import { emitDiagnostic } from "../diagnostics.js";
3
3
  import { EventProcessor } from "./event-processor.js";
4
4
  import { EventSinkError } from "./event-sink.js";
5
+ import { withOriginLine } from "./origin-line.js";
5
6
  import { decisionFor, optionsFor, permissionAsk } from "./permission-policy.js";
6
7
  import { RequestBroker } from "./request-broker.js";
7
8
  import { TurnSteers } from "./steering.js";
@@ -126,7 +127,7 @@ export class Turn {
126
127
  return answered;
127
128
  }
128
129
  async execute() {
129
- const { sessionId, turnId, input, config } = this.request;
130
+ const { sessionId, turnId, input, config, origin } = this.request;
130
131
  // Looked up as the turn executes: a harness the registry lacks rejects
131
132
  // the run, which is not remembered, so a retry may run.
132
133
  const agent = this.host.registry.getAgent(config.harness);
@@ -156,11 +157,12 @@ export class Turn {
156
157
  // the stream is a complete transcript and multi-client attach works. It is
157
158
  // the caller's input as sent, which the caller can predict; the agent is
158
159
  // given it well-formed (`wellFormedInput`).
159
- for (const event of this.processor.echoUserMessage(input))
160
+ for (const event of this.processor.echoUserMessage(input, origin))
160
161
  await this.emit(event);
161
162
  let threw;
162
163
  try {
163
- const given = wellFormedInput(input);
164
+ // @ref LLP 0019#origin-on-the-wire-and-to-the-model — told who sent it, when not the person
165
+ const given = wellFormedInput(withOriginLine(input, origin));
164
166
  for await (const raw of agent.execute(given, this.agentOptions(modelThinking))) {
165
167
  await this.announceNativeSession();
166
168
  if (config.includeRaw) {
@@ -274,7 +276,7 @@ export class Turn {
274
276
  if (standing)
275
277
  return standing;
276
278
  const options = optionsFor(ask);
277
- const outcome = await this.requests.askPermission(toolCall, options, opts?.signal);
279
+ const outcome = await this.requests.askPermission(toolCall, options, opts?.signal, opts?.purpose ?? "tool");
278
280
  if (outcome.outcome === "cancelled")
279
281
  return CANCEL;
280
282
  const { decision, selected } = decisionFor(outcome, options);