@introspection-ai/recipes 0.13.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 (161) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +184 -0
  3. package/dist/agent-tool.d.ts +42 -0
  4. package/dist/agent-tool.d.ts.map +1 -0
  5. package/dist/agent-tool.js +159 -0
  6. package/dist/agent-tool.js.map +1 -0
  7. package/dist/child-agent-completions.d.ts +61 -0
  8. package/dist/child-agent-completions.d.ts.map +1 -0
  9. package/dist/child-agent-completions.js +135 -0
  10. package/dist/child-agent-completions.js.map +1 -0
  11. package/dist/child-agent-store.d.ts +48 -0
  12. package/dist/child-agent-store.d.ts.map +1 -0
  13. package/dist/child-agent-store.js +98 -0
  14. package/dist/child-agent-store.js.map +1 -0
  15. package/dist/child-agent.d.ts +43 -0
  16. package/dist/child-agent.d.ts.map +1 -0
  17. package/dist/child-agent.js +268 -0
  18. package/dist/child-agent.js.map +1 -0
  19. package/dist/direct-cli.d.ts +9 -0
  20. package/dist/direct-cli.d.ts.map +1 -0
  21. package/dist/direct-cli.js +22 -0
  22. package/dist/direct-cli.js.map +1 -0
  23. package/dist/index.d.ts +14 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +14 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/inspect.d.ts +26 -0
  28. package/dist/inspect.d.ts.map +1 -0
  29. package/dist/inspect.js +70 -0
  30. package/dist/inspect.js.map +1 -0
  31. package/dist/interactions.d.ts +204 -0
  32. package/dist/interactions.d.ts.map +1 -0
  33. package/dist/interactions.js +358 -0
  34. package/dist/interactions.js.map +1 -0
  35. package/dist/mcp-catalog.d.ts +8 -0
  36. package/dist/mcp-catalog.d.ts.map +1 -0
  37. package/dist/mcp-catalog.js +60 -0
  38. package/dist/mcp-catalog.js.map +1 -0
  39. package/dist/mcp-cli-core.d.ts +79 -0
  40. package/dist/mcp-cli-core.d.ts.map +1 -0
  41. package/dist/mcp-cli-core.js +1717 -0
  42. package/dist/mcp-cli-core.js.map +1 -0
  43. package/dist/mcp-cli-help.d.ts +2 -0
  44. package/dist/mcp-cli-help.d.ts.map +1 -0
  45. package/dist/mcp-cli-help.js +36 -0
  46. package/dist/mcp-cli-help.js.map +1 -0
  47. package/dist/mcp-cli-policy.d.ts +17 -0
  48. package/dist/mcp-cli-policy.d.ts.map +1 -0
  49. package/dist/mcp-cli-policy.js +230 -0
  50. package/dist/mcp-cli-policy.js.map +1 -0
  51. package/dist/mcp-cli.d.ts +3 -0
  52. package/dist/mcp-cli.d.ts.map +1 -0
  53. package/dist/mcp-cli.js +33 -0
  54. package/dist/mcp-cli.js.map +1 -0
  55. package/dist/mcp-client.d.ts +3 -0
  56. package/dist/mcp-client.d.ts.map +1 -0
  57. package/dist/mcp-client.js +86 -0
  58. package/dist/mcp-client.js.map +1 -0
  59. package/dist/mcp-command-context.d.ts +13 -0
  60. package/dist/mcp-command-context.d.ts.map +1 -0
  61. package/dist/mcp-command-context.js +29 -0
  62. package/dist/mcp-command-context.js.map +1 -0
  63. package/dist/mcp-contract.d.ts +16 -0
  64. package/dist/mcp-contract.d.ts.map +1 -0
  65. package/dist/mcp-contract.js +306 -0
  66. package/dist/mcp-contract.js.map +1 -0
  67. package/dist/mcp-daemon-client.d.ts +10 -0
  68. package/dist/mcp-daemon-client.d.ts.map +1 -0
  69. package/dist/mcp-daemon-client.js +119 -0
  70. package/dist/mcp-daemon-client.js.map +1 -0
  71. package/dist/mcp-daemon-protocol.d.ts +64 -0
  72. package/dist/mcp-daemon-protocol.d.ts.map +1 -0
  73. package/dist/mcp-daemon-protocol.js +6 -0
  74. package/dist/mcp-daemon-protocol.js.map +1 -0
  75. package/dist/mcp-daemon.d.ts +3 -0
  76. package/dist/mcp-daemon.d.ts.map +1 -0
  77. package/dist/mcp-daemon.js +76880 -0
  78. package/dist/mcp-daemon.js.map +1 -0
  79. package/dist/mcp-run-worker.d.ts +2 -0
  80. package/dist/mcp-run-worker.d.ts.map +1 -0
  81. package/dist/mcp-run-worker.js +76579 -0
  82. package/dist/mcp-run-worker.js.map +1 -0
  83. package/dist/mcp.d.ts +168 -0
  84. package/dist/mcp.d.ts.map +1 -0
  85. package/dist/mcp.js +558 -0
  86. package/dist/mcp.js.map +1 -0
  87. package/dist/pi-extension.d.ts +30 -0
  88. package/dist/pi-extension.d.ts.map +1 -0
  89. package/dist/pi-extension.js +880 -0
  90. package/dist/pi-extension.js.map +1 -0
  91. package/dist/provider-env.d.ts +2 -0
  92. package/dist/provider-env.d.ts.map +1 -0
  93. package/dist/provider-env.js +21 -0
  94. package/dist/provider-env.js.map +1 -0
  95. package/dist/recipe/resolve.d.ts +30 -0
  96. package/dist/recipe/resolve.d.ts.map +1 -0
  97. package/dist/recipe/resolve.js +131 -0
  98. package/dist/recipe/resolve.js.map +1 -0
  99. package/dist/recipe-agent.d.ts +71 -0
  100. package/dist/recipe-agent.d.ts.map +1 -0
  101. package/dist/recipe-agent.js +555 -0
  102. package/dist/recipe-agent.js.map +1 -0
  103. package/dist/recipe-extensions.d.ts +9 -0
  104. package/dist/recipe-extensions.d.ts.map +1 -0
  105. package/dist/recipe-extensions.js +81 -0
  106. package/dist/recipe-extensions.js.map +1 -0
  107. package/dist/recipe-mcp-config.d.ts +15 -0
  108. package/dist/recipe-mcp-config.d.ts.map +1 -0
  109. package/dist/recipe-mcp-config.js +82 -0
  110. package/dist/recipe-mcp-config.js.map +1 -0
  111. package/dist/recipe-model.d.ts +49 -0
  112. package/dist/recipe-model.d.ts.map +1 -0
  113. package/dist/recipe-model.js +299 -0
  114. package/dist/recipe-model.js.map +1 -0
  115. package/dist/recipe-package.d.ts +79 -0
  116. package/dist/recipe-package.d.ts.map +1 -0
  117. package/dist/recipe-package.js +479 -0
  118. package/dist/recipe-package.js.map +1 -0
  119. package/dist/recipe-skills.d.ts +7 -0
  120. package/dist/recipe-skills.d.ts.map +1 -0
  121. package/dist/recipe-skills.js +46 -0
  122. package/dist/recipe-skills.js.map +1 -0
  123. package/dist/run-controller.d.ts +32 -0
  124. package/dist/run-controller.d.ts.map +1 -0
  125. package/dist/run-controller.js +259 -0
  126. package/dist/run-controller.js.map +1 -0
  127. package/dist/run.d.ts +28 -0
  128. package/dist/run.d.ts.map +1 -0
  129. package/dist/run.js +84 -0
  130. package/dist/run.js.map +1 -0
  131. package/dist/session.d.ts +140 -0
  132. package/dist/session.d.ts.map +1 -0
  133. package/dist/session.js +363 -0
  134. package/dist/session.js.map +1 -0
  135. package/dist/test-utils.d.ts +32 -0
  136. package/dist/test-utils.d.ts.map +1 -0
  137. package/dist/test-utils.js +259 -0
  138. package/dist/test-utils.js.map +1 -0
  139. package/dist/testing.d.ts +25 -0
  140. package/dist/testing.d.ts.map +1 -0
  141. package/dist/testing.js +96 -0
  142. package/dist/testing.js.map +1 -0
  143. package/docs/agent-composition.md +196 -0
  144. package/docs/deployment-configuration.md +65 -0
  145. package/docs/index.md +49 -0
  146. package/docs/interactions.md +210 -0
  147. package/docs/mcp-auth.md +80 -0
  148. package/docs/mcp-configuration.md +126 -0
  149. package/docs/migration.md +70 -0
  150. package/docs/pi-extension.md +97 -0
  151. package/docs/python-bindings-release.md +47 -0
  152. package/docs/recipe-evals.md +70 -0
  153. package/docs/recipe-flow.md +41 -0
  154. package/docs/recipe-format.md +186 -0
  155. package/docs/recipe-judges.md +152 -0
  156. package/docs/runtime-library.md +171 -0
  157. package/package.json +106 -0
  158. package/vendor/mcp-client/darwin-arm64/mcp-client +0 -0
  159. package/vendor/mcp-client/darwin-x64/mcp-client +0 -0
  160. package/vendor/mcp-client/linux-arm64/mcp-client +0 -0
  161. package/vendor/mcp-client/linux-x64/mcp-client +0 -0
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Child agent-run completion queue.
3
+ *
4
+ * When a background child run settles as `completed`/`failed`, the extension
5
+ * enqueues an envelope here. The registered deliverer — wired up in
6
+ * `pi-extension.ts` — drains the queue into a parent-waking custom message
7
+ * (`pi.sendMessage(..., { triggerTurn: true })`) once the parent session is
8
+ * idle; while the parent is mid-turn the deliverer holds the queue and
9
+ * retries shortly after the `agent_end` boundary poke (a message queued
10
+ * during the turn teardown itself would be stranded on current pi releases).
11
+ *
12
+ * Successes batch briefly so N parallel children produce one notice;
13
+ * failures flush immediately. Runs whose terminal output the model already
14
+ * saw synchronously (`action:"wait"` or a terminal `status` read) are
15
+ * acknowledged out of the queue so nothing is delivered
16
+ * twice.
17
+ */
18
+ /** Batching window for successful completions. Failures skip it. */
19
+ export const COMPLETION_BATCH_WINDOW_MS = 2_000;
20
+ /** Cap on inline output previews; full output stays in status.json. */
21
+ export const OUTPUT_PREVIEW_CHARS = 4_000;
22
+ export function envelopeFromRun(run) {
23
+ if (run.status !== "completed" && run.status !== "failed")
24
+ return null;
25
+ const started = Date.parse(run.startedAt);
26
+ const completed = run.completedAt ? Date.parse(run.completedAt) : NaN;
27
+ const duration = Number.isFinite(started) && Number.isFinite(completed) && completed >= started
28
+ ? completed - started
29
+ : undefined;
30
+ return {
31
+ id: run.id,
32
+ agent: run.agent,
33
+ label: run.label,
34
+ status: run.status,
35
+ output_preview: run.output?.slice(0, OUTPUT_PREVIEW_CHARS),
36
+ error: run.error,
37
+ duration_ms: duration,
38
+ };
39
+ }
40
+ /**
41
+ * Model-facing notice. The `<agent_run_completions>` wrapper marks it as a
42
+ * runtime notification rather than user input.
43
+ */
44
+ export function renderCompletionNotice(batch) {
45
+ const blocks = batch.map((envelope) => {
46
+ const label = envelope.label ? ` — ${envelope.label}` : "";
47
+ const header = `[${envelope.agent}] (${envelope.id})${label} [${envelope.status}]`;
48
+ const body = envelope.status === "failed"
49
+ ? `Agent failed: ${envelope.error ?? "unknown error"}`
50
+ : envelope.output_preview?.trim() || "(no output)";
51
+ return `${header}\n${body}`;
52
+ });
53
+ return [
54
+ "<agent_run_completions>",
55
+ 'The following background agent run(s) finished. This is a runtime notification, not a user message. Review the results, continue the task, and reply to the user with anything they need to know. Use the agent tool with action "status" and the run id for full output.',
56
+ "",
57
+ blocks.join("\n\n"),
58
+ "</agent_run_completions>",
59
+ ].join("\n");
60
+ }
61
+ export class ChildCompletionQueue {
62
+ pending = [];
63
+ deliverer = null;
64
+ flushTimer = null;
65
+ deliveryScheduled = false;
66
+ setDeliverer(deliverer) {
67
+ this.deliverer = deliverer;
68
+ if (deliverer && this.pending.length > 0)
69
+ this.flushNow();
70
+ }
71
+ enqueue(envelope) {
72
+ this.pending.push(envelope);
73
+ if (envelope.status === "failed") {
74
+ this.flushNow();
75
+ return;
76
+ }
77
+ if (!this.flushTimer) {
78
+ this.flushTimer = setTimeout(() => this.flushNow(), COMPLETION_BATCH_WINDOW_MS);
79
+ this.flushTimer.unref?.();
80
+ }
81
+ }
82
+ /**
83
+ * Re-attempt delivery of anything still queued (no-op when empty). Called
84
+ * at the `agent_end` settle boundary: a batch held mid-turn delivers here,
85
+ * bypassing any open batch window.
86
+ */
87
+ poke() {
88
+ if (this.pending.length === 0)
89
+ return;
90
+ if (this.flushTimer) {
91
+ clearTimeout(this.flushTimer);
92
+ this.flushTimer = null;
93
+ }
94
+ this.deliverer?.();
95
+ }
96
+ /**
97
+ * Drop queued envelopes whose terminal output the model just saw
98
+ * synchronously (wait or terminal status read).
99
+ */
100
+ acknowledge(ids) {
101
+ if (ids.length === 0 || this.pending.length === 0)
102
+ return;
103
+ const acknowledged = new Set(ids);
104
+ this.pending = this.pending.filter((envelope) => !acknowledged.has(envelope.id));
105
+ }
106
+ hasPending() {
107
+ return this.pending.length > 0;
108
+ }
109
+ consumeBatch() {
110
+ if (this.pending.length === 0)
111
+ return [];
112
+ return this.pending.splice(0);
113
+ }
114
+ clear() {
115
+ this.pending = [];
116
+ if (this.flushTimer) {
117
+ clearTimeout(this.flushTimer);
118
+ this.flushTimer = null;
119
+ }
120
+ }
121
+ flushNow() {
122
+ if (this.flushTimer) {
123
+ clearTimeout(this.flushTimer);
124
+ this.flushTimer = null;
125
+ }
126
+ if (this.deliveryScheduled)
127
+ return;
128
+ this.deliveryScheduled = true;
129
+ queueMicrotask(() => {
130
+ this.deliveryScheduled = false;
131
+ this.deliverer?.();
132
+ });
133
+ }
134
+ }
135
+ //# sourceMappingURL=child-agent-completions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-agent-completions.js","sourceRoot":"","sources":["../src/child-agent-completions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,oEAAoE;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,CAAC;AAEhD,uEAAuE;AACvE,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,CAAC;AAY1C,MAAM,UAAU,eAAe,CAC7B,GAAqB;IAErB,IAAI,GAAG,CAAC,MAAM,KAAK,WAAW,IAAI,GAAG,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACvE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC1C,MAAM,SAAS,GAAG,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IACtE,MAAM,QAAQ,GACZ,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,OAAO;QAC5E,CAAC,CAAC,SAAS,GAAG,OAAO;QACrB,CAAC,CAAC,SAAS,CAAC;IAChB,OAAO;QACL,EAAE,EAAE,GAAG,CAAC,EAAE;QACV,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC;QAC1D,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,WAAW,EAAE,QAAQ;KACtB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OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;QAClB,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;IAEO,QAAQ;QACd,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACpB,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;YAC9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,CAAC,iBAAiB;YAAE,OAAO;QACnC,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAC9B,cAAc,CAAC,GAAG,EAAE;YAClB,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC;YAC/B,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;QACrB,CAAC,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Filesystem persistence for background agent runs.
3
+ *
4
+ * Each run owns `<workspace>/.pi/agents/<runId>/status.json` — a rolling
5
+ * snapshot of the run state. Snapshots let a later Pi process in the same
6
+ * workspace rehydrate
7
+ * run ids referenced by a resumed conversation: rehydrated runs are readable
8
+ * (status/wait) but not controllable, and a run persisted as `running` died
9
+ * with the previous process, so it is flipped to `interrupted` on rehydrate
10
+ * rather than silently "resumed".
11
+ */
12
+ export type ChildRunStatus = "running" | "completed" | "failed" | "interrupted";
13
+ export type ChildToolStatus = "running" | "completed" | "failed";
14
+ export interface ChildToolActivity {
15
+ id: string;
16
+ name: string;
17
+ args: unknown;
18
+ status: ChildToolStatus;
19
+ startedAt: string;
20
+ completedAt?: string;
21
+ output?: string;
22
+ error?: string;
23
+ }
24
+ export interface ChildRunSnapshot {
25
+ id: string;
26
+ agent: string;
27
+ label?: string;
28
+ prompt: string;
29
+ status: ChildRunStatus;
30
+ startedAt: string;
31
+ completedAt?: string;
32
+ output?: string;
33
+ error?: string;
34
+ toolCalls: ChildToolActivity[];
35
+ }
36
+ export declare class ChildAgentRunStore {
37
+ private readonly root;
38
+ private readonly pendingWrites;
39
+ constructor(workspaceDir: string);
40
+ writeStatus(snapshot: ChildRunSnapshot): Promise<void>;
41
+ /**
42
+ * Status snapshots persisted by any prior process for this workspace, one
43
+ * per `.pi/agents/<runId>/status.json`. Unreadable or malformed entries are
44
+ * skipped — rehydration is best-effort.
45
+ */
46
+ readPersistedSnapshots(): Promise<ChildRunSnapshot[]>;
47
+ }
48
+ //# sourceMappingURL=child-agent-store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-agent-store.d.ts","sourceRoot":"","sources":["../src/child-agent-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,aAAa,CAAC;AAChF,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,CAAC;AAEjE,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,iBAAiB,EAAE,CAAC;CAChC;AAoCD,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAG9B,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoC;gBAEtD,YAAY,EAAE,MAAM;IAI1B,WAAW,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB5D;;;;OAIG;IACG,sBAAsB,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;CAwB5D"}
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Filesystem persistence for background agent runs.
3
+ *
4
+ * Each run owns `<workspace>/.pi/agents/<runId>/status.json` — a rolling
5
+ * snapshot of the run state. Snapshots let a later Pi process in the same
6
+ * workspace rehydrate
7
+ * run ids referenced by a resumed conversation: rehydrated runs are readable
8
+ * (status/wait) but not controllable, and a run persisted as `running` died
9
+ * with the previous process, so it is flipped to `interrupted` on rehydrate
10
+ * rather than silently "resumed".
11
+ */
12
+ import { mkdir, readdir, readFile, writeFile } from "node:fs/promises";
13
+ import { join } from "node:path";
14
+ const RUN_STATUSES = [
15
+ "running",
16
+ "completed",
17
+ "failed",
18
+ "interrupted",
19
+ ];
20
+ function normalizeChildRunSnapshot(value) {
21
+ if (!value || typeof value !== "object" || Array.isArray(value))
22
+ return null;
23
+ const original = value;
24
+ const prompt = typeof original.prompt === "string"
25
+ ? original.prompt
26
+ : typeof original.task === "string"
27
+ ? original.task
28
+ : undefined;
29
+ const record = { ...original, prompt };
30
+ delete record.task;
31
+ if (!(typeof record.id === "string" &&
32
+ typeof record.agent === "string" &&
33
+ typeof record.prompt === "string" &&
34
+ typeof record.status === "string" &&
35
+ RUN_STATUSES.includes(record.status) &&
36
+ typeof record.startedAt === "string" &&
37
+ Array.isArray(record.toolCalls))) {
38
+ return null;
39
+ }
40
+ return record;
41
+ }
42
+ export class ChildAgentRunStore {
43
+ root;
44
+ // Concurrent writes to one status.json interleave (each truncates on open),
45
+ // so snapshot writes for a run are chained behind the previous one.
46
+ pendingWrites = new Map();
47
+ constructor(workspaceDir) {
48
+ this.root = join(workspaceDir, ".pi", "agents");
49
+ }
50
+ async writeStatus(snapshot) {
51
+ const previous = this.pendingWrites.get(snapshot.id) ?? Promise.resolve();
52
+ const write = previous
53
+ .catch(() => { })
54
+ .then(async () => {
55
+ const runDir = join(this.root, snapshot.id);
56
+ await mkdir(runDir, { recursive: true });
57
+ await writeFile(join(runDir, "status.json"), `${JSON.stringify(snapshot, null, 2)}\n`, "utf8");
58
+ });
59
+ this.pendingWrites.set(snapshot.id, write);
60
+ try {
61
+ await write;
62
+ }
63
+ finally {
64
+ if (this.pendingWrites.get(snapshot.id) === write) {
65
+ this.pendingWrites.delete(snapshot.id);
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Status snapshots persisted by any prior process for this workspace, one
71
+ * per `.pi/agents/<runId>/status.json`. Unreadable or malformed entries are
72
+ * skipped — rehydration is best-effort.
73
+ */
74
+ async readPersistedSnapshots() {
75
+ let runIds;
76
+ try {
77
+ runIds = await readdir(this.root);
78
+ }
79
+ catch {
80
+ return [];
81
+ }
82
+ const snapshots = [];
83
+ for (const runId of runIds) {
84
+ try {
85
+ const raw = await readFile(join(this.root, runId, "status.json"), "utf8");
86
+ const parsed = normalizeChildRunSnapshot(JSON.parse(raw));
87
+ if (parsed?.id === runId) {
88
+ snapshots.push(parsed);
89
+ }
90
+ }
91
+ catch {
92
+ // skip unreadable runs
93
+ }
94
+ }
95
+ return snapshots;
96
+ }
97
+ }
98
+ //# sourceMappingURL=child-agent-store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-agent-store.js","sourceRoot":"","sources":["../src/child-agent-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,QAA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AC,IAAI,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,MAAM,SAAS,GAAuB,EAAE,CAAC;QACzC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CACxB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,aAAa,CAAC,EACrC,MAAM,CACP,CAAC;gBACF,MAAM,MAAM,GAAG,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;gBAC1D,IAAI,MAAM,EAAE,EAAE,KAAK,KAAK,EAAE,CAAC;oBACzB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,uBAAuB;YACzB,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,43 @@
1
+ import { type CredentialStore } from "@earendil-works/pi-ai";
2
+ import { type ModelRegistry, ModelRuntime } from "@earendil-works/pi-coding-agent";
3
+ export interface CreateRecipeChildAgentRunnerOptions {
4
+ recipeDir: string;
5
+ workspaceDir: string;
6
+ agentName: string;
7
+ env?: NodeJS.ProcessEnv;
8
+ credentials?: CredentialStore;
9
+ modelRuntime?: ModelRuntime;
10
+ modelRegistry?: ModelRegistry;
11
+ onAssistantMessage?: (text: string, stream: "delta" | "final") => void;
12
+ onToolEvent?: (event: RecipeChildToolEvent) => void;
13
+ }
14
+ export interface RecipeChildAgentRunner {
15
+ start(): Promise<void>;
16
+ prompt(prompt: string): Promise<string>;
17
+ steer(message: string): Promise<void>;
18
+ cancel(): Promise<void>;
19
+ shutdown(): Promise<void>;
20
+ }
21
+ export type CreateRecipeChildAgentRunner = (opts: CreateRecipeChildAgentRunnerOptions) => RecipeChildAgentRunner;
22
+ export type RecipeChildToolEvent = {
23
+ type: "start";
24
+ id: string;
25
+ name: string;
26
+ args: unknown;
27
+ } | {
28
+ type: "update";
29
+ id: string;
30
+ name: string;
31
+ args: unknown;
32
+ partialResult: unknown;
33
+ } | {
34
+ type: "end";
35
+ id: string;
36
+ name: string;
37
+ args: unknown;
38
+ result: unknown;
39
+ isError: boolean;
40
+ };
41
+ export declare function promptResultText(result: unknown): string;
42
+ export declare function createRecipeChildAgentRunner(opts: CreateRecipeChildAgentRunnerOptions): RecipeChildAgentRunner;
43
+ //# sourceMappingURL=child-agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-agent.d.ts","sourceRoot":"","sources":["../src/child-agent.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAEtF,OAAO,EAGL,KAAK,aAAa,EAClB,YAAY,EAKb,MAAM,iCAAiC,CAAC;AAsBzC,MAAM,WAAW,mCAAmC;IAClD,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;IACxB,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,KAAK,IAAI,CAAC;IACvE,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,4BAA4B,GAAG,CACzC,IAAI,EAAE,mCAAmC,KACtC,sBAAsB,CAAC;AAE5B,MAAM,MAAM,oBAAoB,GAC5B;IACE,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf,GACD;IACE,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;CACxB,GACD;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAgGN,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAcxD;AAmMD,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,mCAAmC,GACxC,sBAAsB,CAExB"}
@@ -0,0 +1,268 @@
1
+ import { getEnvApiKey, getModel } from "@earendil-works/pi-ai/compat";
2
+ import { InMemoryCredentialStore } from "@earendil-works/pi-ai";
3
+ import { createAgentSessionFromServices, createAgentSessionServices, ModelRuntime, SessionManager, SettingsManager, } from "@earendil-works/pi-coding-agent";
4
+ import { autoResolveInteractions } from "./interactions.js";
5
+ import { loadRecipeSystemPrompt, REQUIRED_RECIPE_AGENT_FIELDS, resolveRecipeAgentDefinition, validateResolvedRecipeAgentDefinition, } from "./recipe-agent.js";
6
+ import { packageResourcePaths, readPiPackageManifest, } from "./recipe-package.js";
7
+ import { resolveAgentSkillPaths } from "./recipe-skills.js";
8
+ import { applyRecipeAgentModelConfigToModel, applyRecipeAgentModelConfigToSession, } from "./recipe-model.js";
9
+ import { executableRecipeToolNames, } from "./mcp.js";
10
+ function parseModelSpec(spec) {
11
+ const slash = spec.indexOf("/");
12
+ if (slash < 0) {
13
+ throw new Error(`Invalid recipe model "${spec}" - expected "<provider>/<model_id>"`);
14
+ }
15
+ const provider = spec.slice(0, slash);
16
+ const modelId = spec.slice(slash + 1);
17
+ const lookupProvider = provider === "gemini" ? "google" : provider;
18
+ return { provider, modelId, lookupProvider };
19
+ }
20
+ function modelFromSpec(spec, modelRegistry) {
21
+ const { modelId, lookupProvider } = parseModelSpec(spec);
22
+ return (modelRegistry?.find(lookupProvider, modelId) ??
23
+ getModel(lookupProvider, modelId));
24
+ }
25
+ async function modelRuntimeForChildAgent(model, opts) {
26
+ if (opts.modelRuntime)
27
+ return opts.modelRuntime;
28
+ const credentials = opts.credentials ?? new InMemoryCredentialStore();
29
+ if (!opts.credentials) {
30
+ // Resolve the child's API key up front: prefer the host registry (so a
31
+ // key configured inside Pi flows to children), then provider env keys.
32
+ let apiKey;
33
+ let credentialEnv;
34
+ if (opts.modelRegistry) {
35
+ const auth = await opts.modelRegistry.getApiKeyAndHeaders(model);
36
+ if (auth.ok) {
37
+ apiKey = auth.apiKey;
38
+ credentialEnv = auth.env;
39
+ if (auth.headers) {
40
+ model.headers = { ...(model.headers ?? {}), ...auth.headers };
41
+ }
42
+ }
43
+ }
44
+ const env = opts.env ?? process.env;
45
+ apiKey ??=
46
+ getEnvApiKey(model.provider) ??
47
+ env[`${model.provider.toUpperCase()}_API_KEY`];
48
+ if (!apiKey && Object.keys(model.headers ?? {}).length === 0) {
49
+ throw new Error(`${model.provider.toUpperCase()}_API_KEY is required when the background agent is not running inside Pi`);
50
+ }
51
+ await credentials.modify(model.provider, async () => ({
52
+ type: "api_key",
53
+ ...(apiKey ? { key: apiKey } : {}),
54
+ ...(credentialEnv ? { env: credentialEnv } : {}),
55
+ }));
56
+ }
57
+ return ModelRuntime.create({ credentials, modelsPath: null });
58
+ }
59
+ function applySystemInstructions(base, instructions) {
60
+ if (!instructions)
61
+ return base;
62
+ if (instructions.mode === "replace")
63
+ return instructions.content;
64
+ return [base, instructions.content].filter(Boolean).join("\n\n");
65
+ }
66
+ function asRecord(value) {
67
+ return value && typeof value === "object" && !Array.isArray(value)
68
+ ? value
69
+ : null;
70
+ }
71
+ function contentText(content) {
72
+ if (typeof content === "string")
73
+ return content;
74
+ if (!Array.isArray(content))
75
+ return "";
76
+ return content
77
+ .map((part) => {
78
+ const record = asRecord(part);
79
+ return record?.type === "text" && typeof record.text === "string"
80
+ ? record.text
81
+ : "";
82
+ })
83
+ .filter(Boolean)
84
+ .join("\n");
85
+ }
86
+ export function promptResultText(result) {
87
+ if (typeof result === "string")
88
+ return result;
89
+ if (!result || typeof result !== "object")
90
+ return "";
91
+ const record = result;
92
+ if (typeof record.output === "string")
93
+ return record.output;
94
+ const messages = Array.isArray(record.messages) ? record.messages : [];
95
+ for (let index = messages.length - 1; index >= 0; index -= 1) {
96
+ const message = asRecord(messages[index]);
97
+ if (!message)
98
+ continue;
99
+ if (message.role && message.role !== "assistant")
100
+ continue;
101
+ const text = contentText(message.content).trim();
102
+ if (text)
103
+ return text;
104
+ }
105
+ return "";
106
+ }
107
+ function messageFromEvent(event) {
108
+ const record = asRecord(event);
109
+ const direct = asRecord(record?.message);
110
+ if (direct)
111
+ return direct;
112
+ const assistantEvent = asRecord(record?.assistantMessageEvent);
113
+ return asRecord(assistantEvent?.partial);
114
+ }
115
+ class RecipeChildAgentSessionRunner {
116
+ opts;
117
+ session = null;
118
+ unsubscribe = null;
119
+ assistantStreamedText = false;
120
+ constructor(opts) {
121
+ this.opts = opts;
122
+ }
123
+ emitAssistantText(text, stream) {
124
+ const trimmed = text.trim();
125
+ if (!trimmed)
126
+ return;
127
+ this.opts.onAssistantMessage?.(trimmed, stream);
128
+ if (stream === "delta")
129
+ this.assistantStreamedText = true;
130
+ }
131
+ handleSessionEvent(event) {
132
+ const record = asRecord(event);
133
+ const message = messageFromEvent(event);
134
+ const role = typeof message?.role === "string" ? message.role : undefined;
135
+ if (record?.type === "tool_execution_start") {
136
+ this.opts.onToolEvent?.({
137
+ type: "start",
138
+ id: String(record.toolCallId ?? ""),
139
+ name: String(record.toolName ?? ""),
140
+ args: record.args,
141
+ });
142
+ return;
143
+ }
144
+ if (record?.type === "tool_execution_update") {
145
+ this.opts.onToolEvent?.({
146
+ type: "update",
147
+ id: String(record.toolCallId ?? ""),
148
+ name: String(record.toolName ?? ""),
149
+ args: record.args,
150
+ partialResult: record.partialResult,
151
+ });
152
+ return;
153
+ }
154
+ if (record?.type === "tool_execution_end") {
155
+ this.opts.onToolEvent?.({
156
+ type: "end",
157
+ id: String(record.toolCallId ?? ""),
158
+ name: String(record.toolName ?? ""),
159
+ args: record.args,
160
+ result: record.result,
161
+ isError: record.isError === true,
162
+ });
163
+ return;
164
+ }
165
+ if (record?.type === "message_start" && role === "assistant") {
166
+ this.assistantStreamedText = false;
167
+ }
168
+ const assistantEvent = asRecord(record?.assistantMessageEvent);
169
+ if (role === "assistant" &&
170
+ record?.type === "message_update" &&
171
+ assistantEvent?.type === "text_delta" &&
172
+ typeof assistantEvent.delta === "string") {
173
+ this.emitAssistantText(assistantEvent.delta, "delta");
174
+ return;
175
+ }
176
+ if (role === "assistant" &&
177
+ record?.type === "message_end" &&
178
+ !this.assistantStreamedText) {
179
+ this.emitAssistantText(contentText(message?.content), "final");
180
+ }
181
+ }
182
+ async start() {
183
+ if (this.session)
184
+ return;
185
+ const { agentName, agent } = resolveRecipeAgentDefinition({
186
+ recipeDir: this.opts.recipeDir,
187
+ agentName: this.opts.agentName,
188
+ });
189
+ if (!agent) {
190
+ throw new Error(`Agent not found: ${agentName}`);
191
+ }
192
+ const validationFindings = validateResolvedRecipeAgentDefinition({
193
+ recipeDir: this.opts.recipeDir,
194
+ agentName,
195
+ requireExplicitName: true,
196
+ requiredFields: REQUIRED_RECIPE_AGENT_FIELDS,
197
+ });
198
+ const validationErrors = validationFindings.filter((finding) => finding.severity !== "warning");
199
+ if (validationErrors.length > 0) {
200
+ throw new Error(validationErrors.map((finding) => finding.message).join("\n"));
201
+ }
202
+ const modelSpec = agent.model?.name;
203
+ if (!modelSpec) {
204
+ throw new Error(`Agent "${agentName}" must declare model.name`);
205
+ }
206
+ const model = applyRecipeAgentModelConfigToModel(modelFromSpec(modelSpec, this.opts.modelRegistry), agent.modelConfig);
207
+ const modelRuntime = await modelRuntimeForChildAgent(model, this.opts);
208
+ const services = await createAgentSessionServices({
209
+ cwd: this.opts.workspaceDir,
210
+ agentDir: this.opts.recipeDir,
211
+ modelRuntime,
212
+ settingsManager: SettingsManager.create(this.opts.workspaceDir, this.opts.recipeDir),
213
+ resourceLoaderOptions: {
214
+ noSkills: true,
215
+ additionalSkillPaths: resolveAgentSkillPaths(this.opts.recipeDir, packageResourcePaths(readPiPackageManifest(this.opts.recipeDir), "skills"), agent.skills),
216
+ systemPromptOverride: (base) => applySystemInstructions(loadRecipeSystemPrompt(this.opts.recipeDir) ?? base, agent.systemInstructions),
217
+ },
218
+ });
219
+ // Delegated recipe agents are intentionally one level deep. An agent
220
+ // selected as the root session gets the dynamic `agent` tool from the
221
+ // extension, while the same definition running as a child never does.
222
+ const executableTools = executableRecipeToolNames(agent.tools).filter((tool) => tool !== "agent");
223
+ const created = await createAgentSessionFromServices({
224
+ services,
225
+ sessionManager: SessionManager.inMemory(this.opts.workspaceDir),
226
+ model,
227
+ ...(agent.model?.thinkingLevel
228
+ ? { thinkingLevel: agent.model.thinkingLevel }
229
+ : {}),
230
+ tools: executableTools,
231
+ });
232
+ this.session = created.session;
233
+ applyRecipeAgentModelConfigToSession(this.session, agent.modelConfig);
234
+ await this.session.bindExtensions({});
235
+ this.unsubscribe = this.session.subscribe((event) => {
236
+ this.handleSessionEvent(event);
237
+ });
238
+ }
239
+ async prompt(prompt) {
240
+ await this.start();
241
+ if (!this.session)
242
+ throw new Error("Background agent did not start");
243
+ // Child sessions do not own the root session's interaction lifecycle.
244
+ // Resolve their approval tools internally so they cannot open UI or emit
245
+ // an interrupt that would strand the child waiting for the root user.
246
+ await autoResolveInteractions(() => this.session.prompt(prompt));
247
+ return promptResultText({ messages: [...this.session.messages] });
248
+ }
249
+ async steer(message) {
250
+ await this.start();
251
+ if (!this.session)
252
+ throw new Error("Background agent did not start");
253
+ await this.session.steer(message);
254
+ }
255
+ async cancel() {
256
+ await this.session?.abort();
257
+ }
258
+ async shutdown() {
259
+ this.unsubscribe?.();
260
+ this.unsubscribe = null;
261
+ this.session?.dispose();
262
+ this.session = null;
263
+ }
264
+ }
265
+ export function createRecipeChildAgentRunner(opts) {
266
+ return new RecipeChildAgentSessionRunner(opts);
267
+ }
268
+ //# sourceMappingURL=child-agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-agent.js","sourceRoot":"","sources":["../src/child-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAc,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,uBAAuB,EAAwB,MAAM,uBAAuB,CAAC;AAEtF,OAAO,EACL,8BAA8B,EAC9B,0BAA0B,EAE1B,YAAY,EACZ,cAAc,EACd,eAAe,GAGhB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EACL,sBAAsB,EACtB,4BAA4B,EAC5B,4BAA4B,EAC5B,qCAAqC,GAEtC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACL,kCAAkC,EAClC,oCAAoC,GACrC,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,yBAAyB,GAC1B,MAAM,UAAU,CAAC;AAi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,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;CACF;AAED,MAAM,UAAU,4BAA4B,CAC1C,IAAyC;IAEzC,OAAO,IAAI,6BAA6B,CAAC,IAAI,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * True when the current process was launched with the given module as its
3
+ * entry script. Compares realpaths: package-manager bin shims and
4
+ * node_modules symlinks (pnpm) hand us a symlinked argv[1] while
5
+ * import.meta.url is the real path, so naive equality would silently skip
6
+ * the CLI main. Callers pass their own `import.meta.url`.
7
+ */
8
+ export declare function isDirectEntry(moduleUrl: string, entry?: string): boolean;
9
+ //# sourceMappingURL=direct-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-cli.d.ts","sourceRoot":"","sources":["../src/direct-cli.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,KAAK,SAAkB,GACtB,OAAO,CAST"}