@introspection-ai/recipes 0.63.1 → 0.65.0

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 (147) hide show
  1. package/dist/agent-tool/arguments.d.ts +39 -0
  2. package/dist/agent-tool/arguments.d.ts.map +1 -0
  3. package/dist/agent-tool/arguments.generated.d.ts +4 -0
  4. package/dist/agent-tool/arguments.generated.d.ts.map +1 -0
  5. package/dist/agent-tool/arguments.generated.js +60 -0
  6. package/dist/agent-tool/arguments.generated.js.map +1 -0
  7. package/dist/agent-tool/arguments.js +8 -0
  8. package/dist/agent-tool/arguments.js.map +1 -0
  9. package/dist/agents.d.ts +28 -6
  10. package/dist/agents.d.ts.map +1 -1
  11. package/dist/agents.js +280 -47
  12. package/dist/agents.js.map +1 -1
  13. package/dist/api-bindings.d.ts.map +1 -1
  14. package/dist/api-bindings.js +2 -2
  15. package/dist/api-bindings.js.map +1 -1
  16. package/dist/artifact-review-tui.js +1 -1
  17. package/dist/artifact-review-tui.js.map +1 -1
  18. package/dist/artifact-viewer-tui.js +1 -1
  19. package/dist/artifact-viewer-tui.js.map +1 -1
  20. package/dist/artifact-viewer.d.ts.map +1 -1
  21. package/dist/artifact-viewer.js +3 -3
  22. package/dist/artifact-viewer.js.map +1 -1
  23. package/dist/batch/agent-batches.d.ts +53 -0
  24. package/dist/batch/agent-batches.d.ts.map +1 -0
  25. package/dist/batch/agent-batches.js +168 -0
  26. package/dist/batch/agent-batches.js.map +1 -0
  27. package/dist/batch/index.d.ts +2 -0
  28. package/dist/batch/index.d.ts.map +1 -1
  29. package/dist/batch/index.js +2 -1
  30. package/dist/batch/index.js.map +1 -1
  31. package/dist/batch/lines.d.ts.map +1 -1
  32. package/dist/batch/lines.js +4 -2
  33. package/dist/batch/lines.js.map +1 -1
  34. package/dist/child/agent-completions.d.ts +16 -1
  35. package/dist/child/agent-completions.d.ts.map +1 -1
  36. package/dist/child/agent-completions.js +31 -5
  37. package/dist/child/agent-completions.js.map +1 -1
  38. package/dist/child/agent-store.d.ts +2 -0
  39. package/dist/child/agent-store.d.ts.map +1 -1
  40. package/dist/child/agent-store.js.map +1 -1
  41. package/dist/child/agent.d.ts +9 -0
  42. package/dist/child/agent.d.ts.map +1 -1
  43. package/dist/child/agent.js +7 -0
  44. package/dist/child/agent.js.map +1 -1
  45. package/dist/child/arguments.d.ts +32 -0
  46. package/dist/child/arguments.d.ts.map +1 -0
  47. package/dist/child/arguments.generated.d.ts +4 -0
  48. package/dist/child/arguments.generated.d.ts.map +1 -0
  49. package/dist/child/arguments.generated.js +29 -0
  50. package/dist/child/arguments.generated.js.map +1 -0
  51. package/dist/child/arguments.js +8 -0
  52. package/dist/child/arguments.js.map +1 -0
  53. package/dist/child/inboxes.d.ts +21 -0
  54. package/dist/child/inboxes.d.ts.map +1 -0
  55. package/dist/child/inboxes.js +35 -0
  56. package/dist/child/inboxes.js.map +1 -0
  57. package/dist/child/messages.d.ts +202 -0
  58. package/dist/child/messages.d.ts.map +1 -0
  59. package/dist/child/messages.js +490 -0
  60. package/dist/child/messages.js.map +1 -0
  61. package/dist/child/run-processes.d.ts +14 -0
  62. package/dist/child/run-processes.d.ts.map +1 -0
  63. package/dist/child/run-processes.js +101 -0
  64. package/dist/child/run-processes.js.map +1 -0
  65. package/dist/child/session.d.ts +10 -0
  66. package/dist/child/session.d.ts.map +1 -1
  67. package/dist/child/session.js +34 -3
  68. package/dist/child/session.js.map +1 -1
  69. package/dist/child/streaming-usage.d.ts +40 -0
  70. package/dist/child/streaming-usage.d.ts.map +1 -0
  71. package/dist/child/streaming-usage.js +101 -0
  72. package/dist/child/streaming-usage.js.map +1 -0
  73. package/dist/documents/python.d.ts.map +1 -1
  74. package/dist/documents/python.js +2 -2
  75. package/dist/documents/python.js.map +1 -1
  76. package/dist/judges/cli-main.d.ts.map +1 -1
  77. package/dist/judges/cli-main.js +1 -1
  78. package/dist/judges/cli-main.js.map +1 -1
  79. package/dist/judges/run.d.ts.map +1 -1
  80. package/dist/judges/run.js +6 -2
  81. package/dist/judges/run.js.map +1 -1
  82. package/dist/judges/verdict.d.ts.map +1 -1
  83. package/dist/judges/verdict.js +1 -1
  84. package/dist/judges/verdict.js.map +1 -1
  85. package/dist/mcp/contract.d.ts.map +1 -1
  86. package/dist/mcp/contract.js +1 -3
  87. package/dist/mcp/contract.js.map +1 -1
  88. package/dist/mcp/daemon/client.d.ts.map +1 -1
  89. package/dist/mcp/daemon/client.js +1 -2
  90. package/dist/mcp/daemon/client.js.map +1 -1
  91. package/dist/mcp/pi-mcp-runtime.js +2 -2
  92. package/dist/mcp/pi-mcp-runtime.js.map +1 -1
  93. package/dist/mcp/pi-runtime.d.ts +3 -3
  94. package/dist/mcp/pi-runtime.d.ts.map +1 -1
  95. package/dist/mcp/pi-runtime.js +11 -20
  96. package/dist/mcp/pi-runtime.js.map +1 -1
  97. package/dist/mcp/tools.d.ts.map +1 -1
  98. package/dist/mcp/tools.js +1 -1
  99. package/dist/mcp/tools.js.map +1 -1
  100. package/dist/mcp-chunks/{chunk-OHAXEQ22.js → chunk-N6QLCGHR.js} +2 -2
  101. package/dist/mcp-chunks/{chunk-3UONQ24E.js → chunk-WVHEDCS6.js} +6 -4
  102. package/dist/mcp-chunks/chunk-ZH6FNTNJ.js +34 -0
  103. package/dist/mcp-chunks/{pi-mcp-runtime-V2OMZAIR.js → pi-mcp-runtime-W5OLELOO.js} +34 -27
  104. package/dist/mcp-chunks/{server-6DQUPUFW.js → server-UZ5OMTWP.js} +3 -3
  105. package/dist/mcp-daemon.js +3 -3
  106. package/dist/mcp-run-worker.js +2 -2
  107. package/dist/pi-extension.d.ts +2 -0
  108. package/dist/pi-extension.d.ts.map +1 -1
  109. package/dist/pi-extension.js +241 -43
  110. package/dist/pi-extension.js.map +1 -1
  111. package/dist/recipe/manifest.generated.d.ts +1 -1
  112. package/dist/recipe/manifest.generated.js +1 -1
  113. package/dist/recipe/package.d.ts +2 -0
  114. package/dist/recipe/package.d.ts.map +1 -1
  115. package/dist/recipe/package.js +15 -21
  116. package/dist/recipe/package.js.map +1 -1
  117. package/dist/recipe/python.d.ts.map +1 -1
  118. package/dist/recipe/python.js +8 -5
  119. package/dist/recipe/python.js.map +1 -1
  120. package/dist/run-controller.d.ts +5 -0
  121. package/dist/run-controller.d.ts.map +1 -1
  122. package/dist/run-controller.js +89 -12
  123. package/dist/run-controller.js.map +1 -1
  124. package/dist/session.d.ts +14 -0
  125. package/dist/session.d.ts.map +1 -1
  126. package/dist/session.js +21 -3
  127. package/dist/session.js.map +1 -1
  128. package/dist/shell-quote.d.ts +3 -0
  129. package/dist/shell-quote.d.ts.map +1 -0
  130. package/dist/shell-quote.js +5 -0
  131. package/dist/shell-quote.js.map +1 -0
  132. package/dist/skill-progress.d.ts +12 -1
  133. package/dist/skill-progress.d.ts.map +1 -1
  134. package/dist/skill-progress.js +11 -4
  135. package/dist/skill-progress.js.map +1 -1
  136. package/docs/agent-batch.md +87 -0
  137. package/docs/agent-composition.md +49 -19
  138. package/docs/batch.md +7 -0
  139. package/docs/documents/README.md +1 -1
  140. package/docs/mcp-auth.md +2 -1
  141. package/docs/mcp-configuration.md +2 -3
  142. package/docs/productivity/google.md +27 -15
  143. package/docs/recipe-format.md +4 -4
  144. package/package.json +15 -14
  145. package/python/shared/pyproject.toml +2 -2
  146. package/python/shared/uv.lock +30 -30
  147. package/dist/mcp-chunks/chunk-V65N6VX7.js +0 -33
@@ -0,0 +1,490 @@
1
+ /**
2
+ * Messages between the agents of one Pi session: the root agent and the runs
3
+ * it started, at every depth. A run sends one with `send_message`, naming its
4
+ * recipient as `root` or another run's name (its label) or id, as Claude
5
+ * Code's teammates use `SendMessage`.
6
+ *
7
+ * A message reaches an agent that is waiting on its runs at once, whichever
8
+ * run it waits on: Pi delivers a steer only after the current tool call ends,
9
+ * and an `agent` wait blocks until its run settles, so a steer to a waiting
10
+ * agent would never arrive. Otherwise it is steered into the agent's turn, or
11
+ * starts one.
12
+ */
13
+ import { defineTool, } from "@earendil-works/pi-coding-agent";
14
+ import { SEND_MESSAGE_ARGUMENTS } from "./arguments.generated.js";
15
+ /** Pi custom message type of a message delivered to the root agent. */
16
+ export const AGENT_RUN_MESSAGE_TYPE = "agent_run_message";
17
+ /** The name the root agent is addressed by. */
18
+ export const ROOT_AGENT = "root";
19
+ /** The model-facing text of a delivered message. */
20
+ export function renderAgentMessage(message) {
21
+ return [
22
+ `<agent_message from="${message.from}" id="${message.fromId}"${message.id === undefined ? "" : ` n="${message.id}"`}>`,
23
+ message.text,
24
+ "</agent_message>",
25
+ ].join("\n");
26
+ }
27
+ /** Several messages, in the order they were sent. */
28
+ export function renderAgentMessages(messages) {
29
+ return messages.map(renderAgentMessage).join("\n\n");
30
+ }
31
+ /** One kind for messages handed together, so Pi keeps them in order: a steer among them makes all steers. */
32
+ function kindOf(messages) {
33
+ return messages.some((message) => message.deliver === "steer")
34
+ ? "steer"
35
+ : "followUp";
36
+ }
37
+ /**
38
+ * One agent's incoming messages: the only way a message reaches its session.
39
+ * Every operation is a command applied in arrival order, so messages reach the
40
+ * agent in the order they were sent. Modelled in specs/agents/Inbox.tla.
41
+ *
42
+ * - starting: held, and given with the first prompt.
43
+ * - waiting: held, and the wait ends with them.
44
+ * - busy: a steer goes to the session now, behind what is held; a follow-up is held.
45
+ * - idle: held for the turn its owner starts (`onHeld` says one is due).
46
+ * - closed: refused.
47
+ */
48
+ export class AgentInbox {
49
+ phase;
50
+ beforeWait = "busy";
51
+ held = [];
52
+ // Handed to the session and perhaps not read yet, to match what `takeBack` returns.
53
+ handed = [];
54
+ // Closed by `finish`, which a resumed run reopens; `close` is for good.
55
+ finished = false;
56
+ queue = Promise.resolve();
57
+ accepted = 0;
58
+ // The waits in progress, oldest first: several when the agent's tools run in parallel.
59
+ waits = [];
60
+ // Waits started since the agent last had none open: Pi returns their results in this order.
61
+ calls = 0;
62
+ // A wait in this batch put what it took back among what is held.
63
+ requeued = false;
64
+ session;
65
+ send;
66
+ onHeld;
67
+ canStartTurn;
68
+ /**
69
+ * `onHeld`: an idle agent holds a message; its owner should start a turn.
70
+ * `canStartTurn`: whether the session is idle, for an agent whose turns the inbox
71
+ * follows from its session rather than being told (root), and may start itself.
72
+ */
73
+ constructor(send, options = {}) {
74
+ this.send = send;
75
+ this.phase = options.phase ?? "busy";
76
+ this.onHeld = options.onHeld;
77
+ this.canStartTurn = options.canStartTurn;
78
+ }
79
+ /** Where the agent is. */
80
+ get state() {
81
+ return this.phase;
82
+ }
83
+ /** The session read a message it was handed (root: Pi's `message_end` for it). */
84
+ read(message) {
85
+ const index = this.handed.findIndex((handed) => handed.id === message.id);
86
+ if (index >= 0)
87
+ this.handed.splice(index, 1);
88
+ }
89
+ // Without a view of the session's queue, what was handed and not yet reported read.
90
+ unread() {
91
+ return this.session ? this.session.unread() : this.handed.length > 0;
92
+ }
93
+ /** Let the inbox see the session's queue once the session exists. */
94
+ attach(session) {
95
+ this.session = session;
96
+ }
97
+ // Root's turns are Pi's own: idle when Pi is, which also covers a turn started unseen.
98
+ followSession() {
99
+ if (!this.canStartTurn)
100
+ return;
101
+ if (this.phase === "idle" || this.phase === "busy")
102
+ this.phase = this.canStartTurn() ? "idle" : "busy";
103
+ }
104
+ command(apply) {
105
+ const applied = this.queue.then(apply);
106
+ this.queue = applied.catch(() => { });
107
+ return applied;
108
+ }
109
+ take() {
110
+ return this.held.splice(0);
111
+ }
112
+ // Back among what is held, every message in the order the inbox accepted it.
113
+ hold(messages) {
114
+ this.held.push(...messages);
115
+ this.held.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
116
+ }
117
+ async hand(messages, deliver) {
118
+ if (messages.length === 0)
119
+ return;
120
+ this.handed.push(...messages);
121
+ await this.send(messages.map((message) => ({ ...message, deliver })), deliver);
122
+ }
123
+ /** Accept a message; refused once the agent is closed. */
124
+ deliver(sent) {
125
+ const message = { ...sent, id: ++this.accepted };
126
+ return this.command(async () => {
127
+ this.followSession();
128
+ switch (this.phase) {
129
+ case "closed":
130
+ throw new Error(`${message.from}'s message was not delivered: the run has closed.`);
131
+ case "busy":
132
+ if (message.deliver === "steer") {
133
+ await this.hand([...this.take(), message], "steer");
134
+ return;
135
+ }
136
+ this.held.push(message);
137
+ return;
138
+ case "waiting": {
139
+ this.held.push(message);
140
+ // The oldest wait not yet woken ends with it, and with what was held before it.
141
+ const wait = this.waits.find((open) => !open.woken);
142
+ if (wait) {
143
+ wait.got = this.take();
144
+ wait.woken = true;
145
+ wait.resolve();
146
+ }
147
+ return;
148
+ }
149
+ case "idle":
150
+ this.held.push(message);
151
+ if (this.canStartTurn) {
152
+ this.phase = "busy";
153
+ const held = this.take();
154
+ await this.hand(held, kindOf(held));
155
+ return;
156
+ }
157
+ this.onHeld?.();
158
+ return;
159
+ case "starting":
160
+ this.held.push(message);
161
+ }
162
+ });
163
+ }
164
+ /** The session is up and its first turn starts: what is held, for its prompt. */
165
+ started() {
166
+ return this.command(() => {
167
+ if (this.phase === "starting")
168
+ this.phase = "busy";
169
+ return this.take();
170
+ });
171
+ }
172
+ /**
173
+ * A turn starts: what is held opens it, behind what the session was handed
174
+ * and has not read, which it takes back so the prompt keeps send order.
175
+ */
176
+ turnStarted() {
177
+ return this.command(() => {
178
+ if (this.phase === "closed" && !this.finished)
179
+ return [];
180
+ this.phase = "busy";
181
+ this.finished = false;
182
+ return [...this.takeBackUnread(), ...this.take()];
183
+ });
184
+ }
185
+ // What the session holds unread, taken out of its queue, in the order it was handed.
186
+ takeBackUnread() {
187
+ const back = this.session?.takeBack?.();
188
+ if (!back)
189
+ return [];
190
+ const unread = this.handed.filter((message) => back.includes(renderAgentMessage(message)));
191
+ this.handed = [];
192
+ return unread;
193
+ }
194
+ /**
195
+ * The turn is over. What the session was handed and did not read is taken back
196
+ * among what is held, in send order; returns what is held, for the turn the owner starts next.
197
+ * `unsent` is what the turn opened with but never prompted, as when it stopped first.
198
+ */
199
+ turnEnded(unsent = []) {
200
+ return this.command(() => {
201
+ if (this.phase === "closed")
202
+ return [];
203
+ this.phase = "idle";
204
+ // A steer handed after the turn opened is newer than what it opened with.
205
+ this.hold([
206
+ ...this.takeBackUnread().map((message) => ({
207
+ ...message,
208
+ deliver: "followUp",
209
+ })),
210
+ ...unsent,
211
+ ]);
212
+ this.handed = [];
213
+ const held = [...this.held];
214
+ if (held.length > 0)
215
+ this.onHeld?.();
216
+ return held;
217
+ });
218
+ }
219
+ /** Root's idle delivery: once its session is idle, start a turn for what is held. */
220
+ flush() {
221
+ return this.command(async () => {
222
+ this.followSession();
223
+ if (this.phase !== "idle")
224
+ return;
225
+ const held = this.take();
226
+ if (held.length === 0)
227
+ return;
228
+ this.phase = "busy";
229
+ await this.hand(held, kindOf(held));
230
+ });
231
+ }
232
+ /**
233
+ * A wait starts. `arrived` resolves when a message comes for it, or once
234
+ * `signal` aborts; the wait ends only through its own `end`.
235
+ */
236
+ waitStarted(signal) {
237
+ const wait = {
238
+ got: [],
239
+ woken: false,
240
+ resolve: () => { },
241
+ call: 0,
242
+ };
243
+ const arrived = new Promise((resolve) => {
244
+ wait.resolve = resolve;
245
+ if (signal?.aborted)
246
+ return resolve();
247
+ signal?.addEventListener("abort", () => resolve(), { once: true });
248
+ });
249
+ // Registered even when `signal` has aborted, so the wait still ends with what is held.
250
+ void this.command(() => {
251
+ if (this.phase === "closed")
252
+ return wait.resolve();
253
+ if (this.waits.length === 0) {
254
+ this.beforeWait = this.phase;
255
+ this.calls = 0;
256
+ }
257
+ this.phase = "waiting";
258
+ wait.call = ++this.calls;
259
+ this.waits.push(wait);
260
+ // Between turns, what is held is what the agent waits for; in a turn, held follow-ups wait for its end.
261
+ if (this.beforeWait === "idle" && this.held.length > 0) {
262
+ wait.got = this.take();
263
+ wait.woken = true;
264
+ wait.resolve();
265
+ }
266
+ });
267
+ return { arrived, end: (options) => this.waitEnded(wait, options?.keep) };
268
+ }
269
+ /**
270
+ * A wait is over, however it ended: its result is what came for it. Pi reads
271
+ * a batch's results in call order, so what is held when the last wait ends
272
+ * joins the newest wait's result, or else follows the batch. When the session
273
+ * still has an older message to read, a result goes to it as steers behind
274
+ * that one instead, and comes back empty.
275
+ */
276
+ waitEnded(wait, keep = false) {
277
+ return this.command(async () => {
278
+ const index = this.waits.indexOf(wait);
279
+ if (index < 0)
280
+ return wait.got.splice(0);
281
+ this.waits.splice(index, 1);
282
+ const result = wait.got.splice(0);
283
+ if (keep) {
284
+ this.hold(result);
285
+ if (this.waits.length === 0)
286
+ this.phase = this.beforeWait;
287
+ return [];
288
+ }
289
+ const last = this.waits.length === 0;
290
+ if (last)
291
+ this.phase = this.beforeWait;
292
+ // Held messages join the newest wait's result in the order they were accepted.
293
+ if (last && wait.call === this.calls) {
294
+ result.push(...this.take());
295
+ result.sort((a, b) => (a.id ?? 0) - (b.id ?? 0));
296
+ }
297
+ const inTurn = this.beforeWait === "busy";
298
+ // Behind an older message the session has not read, a wait reports nothing:
299
+ // what it took goes back among what is held, in the order it was accepted.
300
+ if (inTurn && result.length > 0 && this.unread()) {
301
+ this.hold(result);
302
+ this.requeued = true;
303
+ result.length = 0;
304
+ }
305
+ // After the batch, held steers and requeued results go to the session together, in
306
+ // send order; held follow-ups alone wait for the turn's end.
307
+ if (last &&
308
+ inTurn &&
309
+ (this.requeued || this.held.some((m) => m.deliver === "steer"))) {
310
+ this.requeued = false;
311
+ await this.hand(this.take(), "steer");
312
+ }
313
+ return result;
314
+ });
315
+ }
316
+ /**
317
+ * The agent's loop would finish: what is held, to carry on with, or none, and
318
+ * the inbox closes, so nothing is accepted that would never be read.
319
+ */
320
+ finish() {
321
+ return this.command(() => {
322
+ const held = this.take();
323
+ if (held.length === 0) {
324
+ this.phase = "closed";
325
+ this.finished = true;
326
+ }
327
+ return held;
328
+ });
329
+ }
330
+ /** A finished run is resumed: it holds what arrives until its next turn opens. */
331
+ resume() {
332
+ return this.command(() => {
333
+ if (this.phase !== "closed" || !this.finished)
334
+ return;
335
+ this.phase = "idle";
336
+ this.finished = false;
337
+ });
338
+ }
339
+ /** The run closed: nothing more is accepted. Returns what it held, never read. */
340
+ close() {
341
+ return this.command(() => {
342
+ this.phase = "closed";
343
+ this.finished = false;
344
+ const dropped = this.waits.flatMap((wait) => wait.got.splice(0));
345
+ for (const wait of this.waits.splice(0))
346
+ wait.resolve();
347
+ this.handed = [];
348
+ return [...dropped, ...this.take()];
349
+ });
350
+ }
351
+ /** How many messages it holds, its waits' included, none of them handed over yet. */
352
+ holding() {
353
+ return (this.held.length +
354
+ this.waits.reduce((count, wait) => count + wait.got.length, 0));
355
+ }
356
+ /** Whether messages are held. */
357
+ needsTurn() {
358
+ return this.held.length > 0;
359
+ }
360
+ }
361
+ // The form of a run id, which a label may not take.
362
+ const RUN_ID = /^agent-run-\d+$/;
363
+ /** Every agent of a session that can be messaged, by id and by name. */
364
+ export class AgentMessageBus {
365
+ byId = new Map();
366
+ byName = new Map();
367
+ /** Whether a live agent already goes by `name`. */
368
+ hasName(name) {
369
+ return this.byName.has(name);
370
+ }
371
+ /** Add an agent; a name already in use is refused. Returns its removal. */
372
+ register(recipient) {
373
+ if (recipient.name !== undefined && this.byName.has(recipient.name)) {
374
+ throw new Error(`An agent named "${recipient.name}" is already running in this session; pick another label.`);
375
+ }
376
+ // A name resolves before an id, so neither may stand for the other's run.
377
+ if (recipient.name !== undefined &&
378
+ recipient.name !== recipient.id &&
379
+ (RUN_ID.test(recipient.name) || this.byId.has(recipient.name))) {
380
+ throw new Error(`"${recipient.name}" reads as a run id; pick a label that does not.`);
381
+ }
382
+ if (this.byName.has(recipient.id)) {
383
+ throw new Error(`A run is labelled "${recipient.id}", which is this run's id; pick another label for it.`);
384
+ }
385
+ this.byId.set(recipient.id, recipient);
386
+ if (recipient.name !== undefined)
387
+ this.byName.set(recipient.name, recipient.id);
388
+ return () => {
389
+ if (this.byId.get(recipient.id) !== recipient)
390
+ return;
391
+ this.byId.delete(recipient.id);
392
+ if (recipient.name !== undefined &&
393
+ this.byName.get(recipient.name) === recipient.id)
394
+ this.byName.delete(recipient.name);
395
+ };
396
+ }
397
+ /** The line a run's system prompt carries so it knows how it is addressed. */
398
+ introduce(id) {
399
+ const name = this.byId.get(id)?.name;
400
+ return `Your name is ${name ?? id}${name ? ` (run ${id})` : ""}. Sign messages with your name; send_message's \`to\` is ${ROOT_AGENT} or another run's name.`;
401
+ }
402
+ /** The name a sender signs a message with: its name, else its id. */
403
+ nameOf(id) {
404
+ return this.byId.get(id)?.name ?? id;
405
+ }
406
+ /** Set the agent `id`'s own status note; it reaches no other agent. */
407
+ setStatus(id, note) {
408
+ this.byId.get(id)?.setStatus?.(note);
409
+ }
410
+ /** Send `text` from the agent `fromId` to `to`, a name or a run id. */
411
+ async send(fromId, to, text, deliver = "steer") {
412
+ const recipientId = this.byName.get(to) ?? to;
413
+ const recipient = this.byId.get(recipientId);
414
+ if (!recipient || recipientId === fromId) {
415
+ const others = [...this.byId.values()]
416
+ .filter((agent) => agent.id !== fromId && agent.accepting())
417
+ .map((agent) => agent.name ?? agent.id);
418
+ const reason = recipient
419
+ ? "You cannot message yourself"
420
+ : `No agent "${to}"`;
421
+ throw new Error(`${reason}. You can message: ${others.length ? others.join(", ") : "nobody"}.`);
422
+ }
423
+ if (!recipient.accepting()) {
424
+ throw new Error(`"${to}" has finished and takes no messages; it was started by its parent, which can resume it.`);
425
+ }
426
+ await recipient.inbox.deliver({
427
+ from: this.nameOf(fromId),
428
+ fromId,
429
+ text,
430
+ deliver,
431
+ });
432
+ return recipient.name ?? recipient.id;
433
+ }
434
+ }
435
+ /** The `send_message` tool of the agent `senderId`. */
436
+ export function createSendMessageTool(bus, senderId) {
437
+ return defineTool({
438
+ name: "send_message",
439
+ label: "Send message",
440
+ description: [
441
+ `Send a message to another agent of this session while you keep working: "${ROOT_AGENT}" is the agent that started this work.`,
442
+ "It arrives at once, even while they wait on you, so use it for what they need to know before you finish: a result that changes their plan, a failure, a question.",
443
+ "Your final answer still reaches them when you finish; don't repeat it here.",
444
+ ].join(" "),
445
+ parameters: SEND_MESSAGE_ARGUMENTS,
446
+ async execute(_callId, rawParams) {
447
+ const params = rawParams;
448
+ try {
449
+ if (params.deliver === "status") {
450
+ bus.setStatus(senderId, {
451
+ text: params.message,
452
+ ...(params.usage
453
+ ? {
454
+ usage: {
455
+ input_tokens: params.usage.input,
456
+ output_tokens: params.usage.output,
457
+ cost_usd: params.usage.cost,
458
+ },
459
+ }
460
+ : {}),
461
+ });
462
+ return {
463
+ content: [{ type: "text", text: "Status set." }],
464
+ details: { to: params.to },
465
+ };
466
+ }
467
+ if (params.usage)
468
+ throw new Error('usage goes with deliver "status" only: it reports work you ran elsewhere, on your own line.');
469
+ const to = await bus.send(senderId, params.to, params.message, params.deliver);
470
+ return {
471
+ content: [{ type: "text", text: `Sent to ${to}.` }],
472
+ details: { to },
473
+ };
474
+ }
475
+ catch (error) {
476
+ return {
477
+ content: [
478
+ {
479
+ type: "text",
480
+ text: error instanceof Error ? error.message : String(error),
481
+ },
482
+ ],
483
+ details: { to: params.to },
484
+ isError: true,
485
+ };
486
+ }
487
+ },
488
+ });
489
+ }
490
+ //# sourceMappingURL=messages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messages.js","sourceRoot":"","sources":["../../src/child/messages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,UAAU,GAEX,MAAM,iCAAiC,CAAC;AAGzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAElE,uEAAuE;AACvE,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,+CAA+C;AAC/C,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC;AAuCjC,oDAAoD;AACpD,MAAM,UAAU,kBAAkB,CAAC,OAAwB;IACzD,OAAO;QACL,wBAAwB,OAAO,CAAC,IAAI,SAAS,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,EAAE,GAAG,GAAG;QACtH,O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AC,KAAK,CAAC,KAAK;oCAChC,aAAa,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM;oCAClC,QAAQ,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI;iCAC5B;6BACF;4BACH,CAAC,CAAC,EAAE,CAAC;qBACR,CAAC,CAAC;oBACH,OAAO;wBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;wBACzD,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;qBAC3B,CAAC;gBACJ,CAAC;gBACD,IAAI,MAAM,CAAC,KAAK;oBACd,MAAM,IAAI,KAAK,CACb,6FAA6F,CAC9F,CAAC;gBACJ,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,IAAI,CACvB,QAAQ,EACR,MAAM,CAAC,EAAE,EACT,MAAM,CAAC,OAAO,EACd,MAAM,CAAC,OAAO,CACf,CAAC;gBACF,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC;oBAC5D,OAAO,EAAE,EAAE,EAAE,EAAE;iBAChB,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAC7D;qBACF;oBACD,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE;oBAC1B,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ /** A run's bash process groups, and a way to end them. */
2
+ export interface RunProcesses {
3
+ /** The command, recording its shell's process group first. */
4
+ track(command: string): string;
5
+ /** End every group the run's commands started: SIGTERM, then SIGKILL after `graceMs`. */
6
+ end(graceMs?: number): Promise<void>;
7
+ }
8
+ /**
9
+ * Pi spawns each bash command detached, so its shell leads a process group
10
+ * that a command's `&` children stay in after the shell exits. Recording each
11
+ * shell's `$$` (its group id) in `dir` lets the run end those children.
12
+ */
13
+ export declare function createRunProcesses(dir: string): RunProcesses;
14
+ //# sourceMappingURL=run-processes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-processes.d.ts","sourceRoot":"","sources":["../../src/child/run-processes.ts"],"names":[],"mappings":"AAOA,0DAA0D;AAC1D,MAAM,WAAW,YAAY;IAC3B,8DAA8D;IAC9D,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,yFAAyF;IACzF,GAAG,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtC;AAQD;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CA0B5D"}
@@ -0,0 +1,101 @@
1
+ // The process groups a subagent run's bash commands start, so closing or
2
+ // interrupting the run ends what it left running in the background.
3
+ import { execFileSync } from "node:child_process";
4
+ import { readFileSync, rmSync } from "node:fs";
5
+ import { join } from "node:path";
6
+ import { shellQuote } from "../shell-quote.js";
7
+ const DEFAULT_GRACE_MS = 5000;
8
+ const POLL_MS = 100;
9
+ /** The shell's own start time: /proc's starttime on Linux, ps's on macOS, matching `startedAt`. */
10
+ const STARTED = "if [ -r /proc/$$/stat ]; then sed 's/.*) //' /proc/$$/stat | cut -d' ' -f20; else ps -o lstart= -p $$ | tr -s ' ' | sed 's/^ //;s/ $//'; fi";
11
+ /**
12
+ * Pi spawns each bash command detached, so its shell leads a process group
13
+ * that a command's `&` children stay in after the shell exits. Recording each
14
+ * shell's `$$` (its group id) in `dir` lets the run end those children.
15
+ */
16
+ export function createRunProcesses(dir) {
17
+ const file = join(dir, "process-groups");
18
+ if (process.platform === "win32") {
19
+ // Pi doesn't detach on Windows, so there is no group to record.
20
+ return { track: (command) => command, end: async () => { } };
21
+ }
22
+ return {
23
+ track: (command) => `printf '%s %s\\n' "$$" "$(${STARTED})" >> ${shellQuote(file)}; ${command}`,
24
+ async end(graceMs = DEFAULT_GRACE_MS) {
25
+ const groups = recordedGroups(file);
26
+ rmSync(file, { force: true });
27
+ // A group id is reused only by a new process with that pid, so a leader started at another time is not ours.
28
+ const ours = groups.filter(({ group, started }) => {
29
+ const now = startedAt(group);
30
+ return now === undefined || started === "" || now === started;
31
+ });
32
+ const live = ours
33
+ .map(({ group }) => group)
34
+ .filter((group) => signal(group, "SIGTERM"));
35
+ const deadline = Date.now() + graceMs;
36
+ while (Date.now() < deadline && live.some((group) => signal(group, 0)))
37
+ await new Promise((resolve) => setTimeout(resolve, POLL_MS));
38
+ for (const group of live)
39
+ signal(group, "SIGKILL");
40
+ },
41
+ };
42
+ }
43
+ function recordedGroups(file) {
44
+ let text;
45
+ try {
46
+ text = readFileSync(file, "utf8");
47
+ }
48
+ catch (error) {
49
+ if (error.code === "ENOENT")
50
+ return [];
51
+ throw error;
52
+ }
53
+ const groups = new Map();
54
+ for (const line of text.split("\n")) {
55
+ const [id, ...rest] = line.trim().split(/\s+/);
56
+ const group = Number(id);
57
+ if (Number.isInteger(group) && group > 1 && !groups.has(group))
58
+ groups.set(group, rest.join(" "));
59
+ }
60
+ return [...groups].map(([group, started]) => ({ group, started }));
61
+ }
62
+ /** When `pid` started, as the shell records it; undefined when no such process runs. */
63
+ function startedAt(pid) {
64
+ try {
65
+ const stat = readFileSync(`/proc/${pid}/stat`, "utf8");
66
+ return stat.slice(stat.lastIndexOf(") ") + 2).split(" ")[19];
67
+ }
68
+ catch (error) {
69
+ if (error.code !== "ENOENT")
70
+ throw error;
71
+ }
72
+ if (process.platform === "linux")
73
+ return undefined;
74
+ try {
75
+ const out = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
76
+ encoding: "utf8",
77
+ });
78
+ return out.trim().split(/\s+/).join(" ") || undefined;
79
+ }
80
+ catch (error) {
81
+ // ps exits 1 when no process has that pid.
82
+ if (error.status === 1)
83
+ return undefined;
84
+ throw error;
85
+ }
86
+ }
87
+ /** Signal a whole group; false when it no longer exists. */
88
+ function signal(group, sig) {
89
+ try {
90
+ process.kill(-group, sig);
91
+ return true;
92
+ }
93
+ catch (error) {
94
+ // macOS answers EPERM for a group left with only zombies; neither it nor a reused id is ours to signal.
95
+ const code = error.code;
96
+ if (code === "ESRCH" || code === "EPERM")
97
+ return false;
98
+ throw error;
99
+ }
100
+ }
101
+ //# sourceMappingURL=run-processes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run-processes.js","sourceRoot":"","sources":["../../src/child/run-processes.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,oEAAoE;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU/C,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAC9B,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,mGAAmG;AACnG,MAAM,OAAO,GACX,6IAA6I,CAAC;AAEhJ;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;IACzC,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QACjC,gEAAgE;QAChE,OAAO,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC,EAAE,CAAC;IAC9D,CAAC;IACD,OAAO;QACL,KAAK,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,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAC;IACtE,CAAC;IACD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,SAAS,CAAC;IACnD,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE;YACnE,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,SAAS,CAAC;IACxD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,2CAA2C;QAC3C,IAAK,KAA6B,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QAClE,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,4DAA4D;AAC5D,SAAS,MAAM,CAAC,KAAa,EAAE,GAAuB;IACpD,IAAI,CAAC;QACH,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,wGAAwG;QACxG,MAAM,IAAI,GAAI,KAA+B,CAAC,IAAI,CAAC;QACnD,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,OAAO;YAAE,OAAO,KAAK,CAAC;QACvD,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { Api, CredentialStore, Model } from "@earendil-works/pi-ai";
2
2
  import type { AgentSessionEvent, ModelRegistry, SettingsManager } from "@earendil-works/pi-coding-agent";
3
3
  import { type AgentRunEventObserver } from "../agents.js";
4
+ import { type AgentInbox, type AgentMessageBus } from "./messages.js";
4
5
  import type { ResolvedRecipe } from "../recipe/resolve.js";
5
6
  import type { ApiLocalConfig } from "../api-bindings.js";
6
7
  import type { RecipeClockOptions } from "../clock.js";
@@ -32,6 +33,15 @@ export interface CreateIsolatedChildSessionOptions {
32
33
  depth?: number;
33
34
  /** Observe events from runs this child starts in turn. */
34
35
  onAgentRunEvent?: AgentRunEventObserver;
36
+ /**
37
+ * The session's agents, this child's run id and its inbox: the child gets
38
+ * `send_message`, and runs it starts join the same bus.
39
+ */
40
+ messages?: {
41
+ bus: AgentMessageBus;
42
+ id: string;
43
+ inbox: AgentInbox;
44
+ };
35
45
  /**
36
46
  * Pi's model registry, when the child was bound through it: the runs this
37
47
  * child starts are bound the same way, each for its own model and provider,