@introspection-ai/recipes 0.50.0 → 0.52.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 (249) hide show
  1. package/README.md +3 -3
  2. package/dist/api/api-bindings.d.ts +3 -0
  3. package/dist/api/api-bindings.d.ts.map +1 -0
  4. package/dist/api/api-bindings.js +2 -0
  5. package/dist/api/api-bindings.js.map +1 -0
  6. package/dist/api/session.d.ts +1 -0
  7. package/dist/api/session.d.ts.map +1 -1
  8. package/dist/api-bindings.d.ts +101 -0
  9. package/dist/api-bindings.d.ts.map +1 -0
  10. package/dist/api-bindings.js +406 -0
  11. package/dist/api-bindings.js.map +1 -0
  12. package/dist/channels/arguments.d.ts +116 -0
  13. package/dist/channels/arguments.d.ts.map +1 -0
  14. package/dist/channels/arguments.generated.d.ts +15 -0
  15. package/dist/channels/arguments.generated.d.ts.map +1 -0
  16. package/dist/channels/arguments.generated.js +181 -0
  17. package/dist/channels/arguments.generated.js.map +1 -0
  18. package/dist/channels/arguments.js +8 -0
  19. package/dist/channels/arguments.js.map +1 -0
  20. package/dist/channels/module.d.ts +5 -0
  21. package/dist/channels/module.d.ts.map +1 -1
  22. package/dist/channels/module.js +10 -5
  23. package/dist/channels/module.js.map +1 -1
  24. package/dist/channels/tools.d.ts.map +1 -1
  25. package/dist/channels/tools.js +22 -59
  26. package/dist/channels/tools.js.map +1 -1
  27. package/dist/channels/types.d.ts +5 -0
  28. package/dist/channels/types.d.ts.map +1 -1
  29. package/dist/child/session.d.ts +5 -0
  30. package/dist/child/session.d.ts.map +1 -1
  31. package/dist/child/session.js +2 -0
  32. package/dist/child/session.js.map +1 -1
  33. package/dist/clock.d.ts +80 -0
  34. package/dist/clock.d.ts.map +1 -0
  35. package/dist/clock.js +169 -0
  36. package/dist/clock.js.map +1 -0
  37. package/dist/command-parameters.d.ts +37 -5
  38. package/dist/command-parameters.d.ts.map +1 -1
  39. package/dist/command-parameters.js +73 -11
  40. package/dist/command-parameters.js.map +1 -1
  41. package/dist/connector-tools.d.ts +18 -0
  42. package/dist/connector-tools.d.ts.map +1 -1
  43. package/dist/connector-tools.js +49 -6
  44. package/dist/connector-tools.js.map +1 -1
  45. package/dist/documents/module.d.ts.map +1 -1
  46. package/dist/documents/module.js +1 -3
  47. package/dist/documents/module.js.map +1 -1
  48. package/dist/documents/tools.d.ts.map +1 -1
  49. package/dist/documents/tools.js +3 -3
  50. package/dist/documents/tools.js.map +1 -1
  51. package/dist/egress.d.ts +23 -0
  52. package/dist/egress.d.ts.map +1 -0
  53. package/dist/egress.js +36 -0
  54. package/dist/egress.js.map +1 -0
  55. package/dist/issues/index.d.ts +7 -0
  56. package/dist/issues/index.d.ts.map +1 -0
  57. package/dist/issues/index.js +4 -0
  58. package/dist/issues/index.js.map +1 -0
  59. package/dist/issues/module.d.ts +38 -0
  60. package/dist/issues/module.d.ts.map +1 -0
  61. package/dist/issues/module.js +114 -0
  62. package/dist/issues/module.js.map +1 -0
  63. package/dist/issues/tool.d.ts +95 -0
  64. package/dist/issues/tool.d.ts.map +1 -0
  65. package/dist/issues/tool.js +479 -0
  66. package/dist/issues/tool.js.map +1 -0
  67. package/dist/issues/types.d.ts +280 -0
  68. package/dist/issues/types.d.ts.map +1 -0
  69. package/dist/issues/types.js +79 -0
  70. package/dist/issues/types.js.map +1 -0
  71. package/dist/mcp/cli/command-context.d.ts +20 -1
  72. package/dist/mcp/cli/command-context.d.ts.map +1 -1
  73. package/dist/mcp/cli/command-context.js.map +1 -1
  74. package/dist/mcp/cli/core.d.ts +0 -2
  75. package/dist/mcp/cli/core.d.ts.map +1 -1
  76. package/dist/mcp/cli/core.js +9 -33
  77. package/dist/mcp/cli/core.js.map +1 -1
  78. package/dist/mcp/cli/handshake-retry.d.ts +5 -0
  79. package/dist/mcp/cli/handshake-retry.d.ts.map +1 -0
  80. package/dist/mcp/cli/handshake-retry.js +32 -0
  81. package/dist/mcp/cli/handshake-retry.js.map +1 -0
  82. package/dist/mcp/daemon/index.js +3 -4
  83. package/dist/mcp/daemon/index.js.map +1 -1
  84. package/dist/mcp/pi-client.d.ts +2 -0
  85. package/dist/mcp/pi-client.d.ts.map +1 -1
  86. package/dist/mcp/pi-client.js +5 -1
  87. package/dist/mcp/pi-client.js.map +1 -1
  88. package/dist/mcp/pi-mcp-runtime.d.ts +25 -0
  89. package/dist/mcp/pi-mcp-runtime.d.ts.map +1 -0
  90. package/dist/mcp/pi-mcp-runtime.js +215 -0
  91. package/dist/mcp/pi-mcp-runtime.js.map +1 -0
  92. package/dist/mcp/pi-runtime.d.ts +7 -0
  93. package/dist/mcp/pi-runtime.d.ts.map +1 -0
  94. package/dist/mcp/pi-runtime.js +26 -0
  95. package/dist/mcp/pi-runtime.js.map +1 -0
  96. package/dist/mcp-chunks/chunk-3UVHZECT.js +31 -0
  97. package/dist/mcp-chunks/{chunk-PO2SOBEN.js → chunk-CGJ2XOSF.js} +43 -35
  98. package/dist/mcp-chunks/{chunk-GTETFUPQ.js → chunk-IMG2JMBS.js} +8 -8
  99. package/dist/mcp-chunks/{chunk-UFV6SVQG.js → chunk-LQKMNWDE.js} +2 -2
  100. package/dist/mcp-chunks/{chunk-S2F7DDP5.js → chunk-QUDOU7MQ.js} +1 -1
  101. package/dist/mcp-chunks/{cli-IYD7Y7MO.js → cli-BM23ZXPJ.js} +54 -54
  102. package/dist/mcp-chunks/{client-5MNBV3Z7.js → client-RKTAKDAY.js} +7 -7
  103. package/dist/mcp-chunks/{daemon-command-V3B3EMXD.js → daemon-command-VU6WTFCJ.js} +8 -8
  104. package/dist/mcp-chunks/{generate-cli-runner-PW5WJ7KI.js → generate-cli-runner-JAAPSWGX.js} +12 -12
  105. package/dist/mcp-chunks/{generated-daemon-runtime-3C4NWGAU.js → generated-daemon-runtime-LX4L2X7Z.js} +8 -8
  106. package/dist/mcp-chunks/pi-mcp-runtime-GHDEPXUL.js +1231 -0
  107. package/dist/mcp-chunks/{runtime-RMI3XCYJ.js → runtime-T63YI7TC.js} +6 -6
  108. package/dist/mcp-chunks/{serve-command-UF5SVREV.js → serve-command-75P4VBJ6.js} +7 -7
  109. package/dist/mcp-daemon.js +21 -19
  110. package/dist/mcp-run-worker.js +11 -10
  111. package/dist/pi-extension.d.ts +3 -0
  112. package/dist/pi-extension.d.ts.map +1 -1
  113. package/dist/pi-extension.js +82 -18
  114. package/dist/pi-extension.js.map +1 -1
  115. package/dist/productivity/arguments.d.ts +298 -0
  116. package/dist/productivity/arguments.d.ts.map +1 -0
  117. package/dist/productivity/arguments.generated.d.ts +28 -0
  118. package/dist/productivity/arguments.generated.d.ts.map +1 -0
  119. package/dist/productivity/arguments.generated.js +489 -0
  120. package/dist/productivity/arguments.generated.js.map +1 -0
  121. package/dist/productivity/arguments.js +10 -0
  122. package/dist/productivity/arguments.js.map +1 -0
  123. package/dist/productivity/http.d.ts.map +1 -1
  124. package/dist/productivity/http.js +12 -22
  125. package/dist/productivity/http.js.map +1 -1
  126. package/dist/productivity/index.d.ts +1 -1
  127. package/dist/productivity/index.d.ts.map +1 -1
  128. package/dist/productivity/index.js +1 -1
  129. package/dist/productivity/index.js.map +1 -1
  130. package/dist/productivity/module.d.ts +15 -2
  131. package/dist/productivity/module.d.ts.map +1 -1
  132. package/dist/productivity/module.js +24 -21
  133. package/dist/productivity/module.js.map +1 -1
  134. package/dist/productivity/tools.d.ts +6 -0
  135. package/dist/productivity/tools.d.ts.map +1 -1
  136. package/dist/productivity/tools.js +64 -224
  137. package/dist/productivity/tools.js.map +1 -1
  138. package/dist/productivity/types.d.ts +2 -0
  139. package/dist/productivity/types.d.ts.map +1 -1
  140. package/dist/productivity/types.js.map +1 -1
  141. package/dist/recipe/agent.d.ts +40 -10
  142. package/dist/recipe/agent.d.ts.map +1 -1
  143. package/dist/recipe/agent.js +209 -30
  144. package/dist/recipe/agent.js.map +1 -1
  145. package/dist/recipe/companions.d.ts +2 -1
  146. package/dist/recipe/companions.d.ts.map +1 -1
  147. package/dist/recipe/companions.js +11 -9
  148. package/dist/recipe/companions.js.map +1 -1
  149. package/dist/recipe/manifest.generated.d.ts +4 -1
  150. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  151. package/dist/recipe/manifest.generated.js +5 -2
  152. package/dist/recipe/manifest.generated.js.map +1 -1
  153. package/dist/recipe/package.d.ts +28 -3
  154. package/dist/recipe/package.d.ts.map +1 -1
  155. package/dist/recipe/package.js +155 -1
  156. package/dist/recipe/package.js.map +1 -1
  157. package/dist/recipe/providers.d.ts +62 -0
  158. package/dist/recipe/providers.d.ts.map +1 -0
  159. package/dist/recipe/providers.js +95 -0
  160. package/dist/recipe/providers.js.map +1 -0
  161. package/dist/recipe/resolve.d.ts +7 -3
  162. package/dist/recipe/resolve.d.ts.map +1 -1
  163. package/dist/recipe/resolve.js +7 -2
  164. package/dist/recipe/resolve.js.map +1 -1
  165. package/dist/run-controller.d.ts +6 -0
  166. package/dist/run-controller.d.ts.map +1 -1
  167. package/dist/run-controller.js +2 -0
  168. package/dist/run-controller.js.map +1 -1
  169. package/dist/search/egress.d.ts +12 -0
  170. package/dist/search/egress.d.ts.map +1 -0
  171. package/dist/search/egress.js +24 -0
  172. package/dist/search/egress.js.map +1 -0
  173. package/dist/search/http.d.ts +16 -0
  174. package/dist/search/http.d.ts.map +1 -0
  175. package/dist/search/http.js +75 -0
  176. package/dist/search/http.js.map +1 -0
  177. package/dist/search/index.d.ts +10 -0
  178. package/dist/search/index.d.ts.map +1 -0
  179. package/dist/search/index.js +5 -0
  180. package/dist/search/index.js.map +1 -0
  181. package/dist/search/mcp.d.ts +58 -0
  182. package/dist/search/mcp.d.ts.map +1 -0
  183. package/dist/search/mcp.js +84 -0
  184. package/dist/search/mcp.js.map +1 -0
  185. package/dist/search/module.d.ts +28 -0
  186. package/dist/search/module.d.ts.map +1 -0
  187. package/dist/search/module.js +49 -0
  188. package/dist/search/module.js.map +1 -0
  189. package/dist/search/tool.d.ts +101 -0
  190. package/dist/search/tool.d.ts.map +1 -0
  191. package/dist/search/tool.js +518 -0
  192. package/dist/search/tool.js.map +1 -0
  193. package/dist/search/types.d.ts +257 -0
  194. package/dist/search/types.d.ts.map +1 -0
  195. package/dist/search/types.js +63 -0
  196. package/dist/search/types.js.map +1 -0
  197. package/dist/session.d.ts +21 -1
  198. package/dist/session.d.ts.map +1 -1
  199. package/dist/session.js +132 -43
  200. package/dist/session.js.map +1 -1
  201. package/dist/test-utils.d.ts +2 -0
  202. package/dist/test-utils.d.ts.map +1 -1
  203. package/dist/test-utils.js +3 -1
  204. package/dist/test-utils.js.map +1 -1
  205. package/dist/tool-search.d.ts +9 -0
  206. package/dist/tool-search.d.ts.map +1 -1
  207. package/dist/tool-search.js +23 -0
  208. package/dist/tool-search.js.map +1 -1
  209. package/dist/tools/bridge.d.ts +44 -0
  210. package/dist/tools/bridge.d.ts.map +1 -0
  211. package/dist/tools/bridge.js +106 -0
  212. package/dist/tools/bridge.js.map +1 -0
  213. package/dist/tools/cli.d.ts +20 -0
  214. package/dist/tools/cli.d.ts.map +1 -0
  215. package/dist/tools/cli.js +246 -0
  216. package/dist/tools/cli.js.map +1 -0
  217. package/dist/tools/entry.d.ts +2 -0
  218. package/dist/tools/entry.d.ts.map +1 -0
  219. package/dist/tools/entry.js +3 -0
  220. package/dist/tools/entry.js.map +1 -0
  221. package/dist/tools/shell.d.ts +12 -0
  222. package/dist/tools/shell.d.ts.map +1 -0
  223. package/dist/tools/shell.js +50 -0
  224. package/dist/tools/shell.js.map +1 -0
  225. package/dist/tuning/tpe.d.ts +112 -0
  226. package/dist/tuning/tpe.d.ts.map +1 -0
  227. package/dist/tuning/tpe.js +286 -0
  228. package/dist/tuning/tpe.js.map +1 -0
  229. package/docs/README.md +4 -1
  230. package/docs/channels/README.md +10 -0
  231. package/docs/documents/README.md +20 -19
  232. package/docs/host-api.md +10 -0
  233. package/docs/issues/README.md +183 -0
  234. package/docs/mcp-configuration.md +67 -2
  235. package/docs/pi-extension.md +5 -0
  236. package/docs/productivity/README.md +8 -3
  237. package/docs/providers.md +321 -0
  238. package/docs/recipe-format.md +103 -32
  239. package/docs/search/README.md +818 -0
  240. package/package.json +33 -10
  241. package/skills/documents/SKILL.md +2 -1
  242. package/skills/search/SKILL.md +72 -0
  243. package/dist/mcp-chunks/{auth-command-M7TQE3AL.js → auth-command-UYFOGGQR.js} +6 -6
  244. package/dist/mcp-chunks/{call-command-7LD7UEFK.js → call-command-6U5BNDR7.js} +17 -17
  245. package/dist/mcp-chunks/{chunk-PSE442BC.js → chunk-36D4FILJ.js} +26 -26
  246. package/dist/mcp-chunks/{config-command-6DXILFNO.js → config-command-ZSPJI34E.js} +10 -10
  247. package/dist/mcp-chunks/{emit-ts-command-NDCDFDRM.js → emit-ts-command-SY4LQE4S.js} +3 -3
  248. package/dist/mcp-chunks/{inspect-cli-command-4MGF5CPP.js → inspect-cli-command-JPX4ON6N.js} +4 -4
  249. package/dist/mcp-chunks/{resource-command-SRFQQROJ.js → resource-command-DUY4SVE5.js} +4 -4
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Tree-structured Parzen Estimator (TPE): a small Bayesian optimizer for
3
+ * black-box searches such as hyperparameters or a Recipe's settings, the
4
+ * algorithm Hyperopt and Optuna use by default (Bergstra et al., 2011).
5
+ *
6
+ * Each parameter is modelled on its own. After the random startup trials,
7
+ * the trials told so far are split into the best `gamma(n)` and the rest; a
8
+ * Parzen estimator is fitted to each group, `l(x)` to the good and `g(x)` to
9
+ * the bad, and the candidate drawn from `l` with the highest `l(x) / g(x)` is
10
+ * asked next. Numbers use a mixture of truncated Gaussians, on a log scale
11
+ * when `log` is set; choices use smoothed, weighted counts.
12
+ *
13
+ * ```ts
14
+ * const sampler = new TpeSampler({
15
+ * lr: float(1e-5, 1e-1, { log: true }),
16
+ * layers: int(1, 8),
17
+ * optimizer: choice(["adam", "sgd"]),
18
+ * });
19
+ * for (let i = 0; i < 50; i++) {
20
+ * const config = sampler.ask();
21
+ * sampler.tell(config, await evaluate(config));
22
+ * }
23
+ * sampler.best; // { config, value }
24
+ * ```
25
+ */
26
+ export interface FloatParam {
27
+ readonly type: "float";
28
+ readonly low: number;
29
+ readonly high: number;
30
+ readonly log: boolean;
31
+ }
32
+ export interface IntParam {
33
+ readonly type: "int";
34
+ readonly low: number;
35
+ readonly high: number;
36
+ readonly log: boolean;
37
+ }
38
+ export interface ChoiceParam<T> {
39
+ readonly type: "choice";
40
+ readonly choices: readonly T[];
41
+ }
42
+ export type Param = FloatParam | IntParam | ChoiceParam<unknown>;
43
+ export type SearchSpace = Readonly<Record<string, Param>>;
44
+ /** The value each parameter of a space takes in one configuration. */
45
+ export type Config<S extends SearchSpace> = {
46
+ -readonly [K in keyof S]: S[K] extends ChoiceParam<infer T> ? T : number;
47
+ };
48
+ export interface Trial<S extends SearchSpace> {
49
+ config: Config<S>;
50
+ value: number;
51
+ }
52
+ export interface TpeOptions {
53
+ /** Default `minimize`. */
54
+ direction?: "minimize" | "maximize";
55
+ /** Random trials before TPE takes over. Default 10. */
56
+ startupTrials?: number;
57
+ /** Candidates drawn from `l(x)` per parameter per ask. Default 24. */
58
+ candidates?: number;
59
+ /** How many of `n` trials count as good. Default `min(ceil(0.1 n), 25)`. */
60
+ gamma?: (n: number) => number;
61
+ /** Weight of the prior (the whole range) in each estimator. Default 1. */
62
+ priorWeight?: number;
63
+ /** Seed for the sampler's own random numbers. Default 0. */
64
+ seed?: number;
65
+ }
66
+ /** A number in `[low, high]`; `log` samples it on a log scale. */
67
+ export declare function float(low: number, high: number, options?: {
68
+ log?: boolean;
69
+ }): FloatParam;
70
+ /** An integer in `[low, high]`, both included. */
71
+ export declare function int(low: number, high: number, options?: {
72
+ log?: boolean;
73
+ }): IntParam;
74
+ /** One of `choices`, compared by identity. */
75
+ export declare function choice<const T>(choices: readonly T[]): ChoiceParam<T>;
76
+ export declare class TpeSampler<S extends SearchSpace> {
77
+ readonly trials: Array<Trial<S>>;
78
+ private readonly random;
79
+ private readonly sign;
80
+ private readonly startupTrials;
81
+ private readonly candidates;
82
+ private readonly gamma;
83
+ private readonly priorWeight;
84
+ readonly space: S;
85
+ constructor(space: S, options?: TpeOptions);
86
+ /** The next configuration to evaluate. */
87
+ ask(): Config<S>;
88
+ /** Records what `config` scored. `NaN` or `±Infinity` marks a failure. */
89
+ tell(config: Config<S>, value: number): void;
90
+ /** The best trial told so far, ignoring failures. */
91
+ get best(): Trial<S> | undefined;
92
+ private loss;
93
+ private sampleRandom;
94
+ private sampleNumber;
95
+ /**
96
+ * Hyperopt's adaptive Parzen estimator: one Gaussian per observation plus
97
+ * a prior over the whole range, each as wide as the larger gap to its
98
+ * neighbours, clipped to `[range / min(100, n + 1), range]`.
99
+ */
100
+ private parzen;
101
+ private sampleChoice;
102
+ /** Each choice's probability: its count plus a share of the prior. */
103
+ private choiceWeights;
104
+ }
105
+ /** Runs `trials` evaluations of `objective` one after another. */
106
+ export declare function optimize<S extends SearchSpace>(space: S, objective: (config: Config<S>) => number | Promise<number>, options: TpeOptions & {
107
+ trials: number;
108
+ }): Promise<{
109
+ best: Trial<S> | undefined;
110
+ trials: Array<Trial<S>>;
111
+ }>;
112
+ //# sourceMappingURL=tpe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tpe.d.ts","sourceRoot":"","sources":["../../src/tuning/tpe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IACrB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;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B,QAAQ,CAAC,CAAC,SAAS,WAAW,EAClD,KAAK,EAAE,CAAC,EACR,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,EAC1D,OAAO,EAAE,UAAU,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GACvC,OAAO,CAAC;IAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC,CAOlE"}
@@ -0,0 +1,286 @@
1
+ /**
2
+ * Tree-structured Parzen Estimator (TPE): a small Bayesian optimizer for
3
+ * black-box searches such as hyperparameters or a Recipe's settings, the
4
+ * algorithm Hyperopt and Optuna use by default (Bergstra et al., 2011).
5
+ *
6
+ * Each parameter is modelled on its own. After the random startup trials,
7
+ * the trials told so far are split into the best `gamma(n)` and the rest; a
8
+ * Parzen estimator is fitted to each group, `l(x)` to the good and `g(x)` to
9
+ * the bad, and the candidate drawn from `l` with the highest `l(x) / g(x)` is
10
+ * asked next. Numbers use a mixture of truncated Gaussians, on a log scale
11
+ * when `log` is set; choices use smoothed, weighted counts.
12
+ *
13
+ * ```ts
14
+ * const sampler = new TpeSampler({
15
+ * lr: float(1e-5, 1e-1, { log: true }),
16
+ * layers: int(1, 8),
17
+ * optimizer: choice(["adam", "sgd"]),
18
+ * });
19
+ * for (let i = 0; i < 50; i++) {
20
+ * const config = sampler.ask();
21
+ * sampler.tell(config, await evaluate(config));
22
+ * }
23
+ * sampler.best; // { config, value }
24
+ * ```
25
+ */
26
+ /** A number in `[low, high]`; `log` samples it on a log scale. */
27
+ export function float(low, high, options = {}) {
28
+ checkRange(low, high, options.log ?? false);
29
+ return { type: "float", low, high, log: options.log ?? false };
30
+ }
31
+ /** An integer in `[low, high]`, both included. */
32
+ export function int(low, high, options = {}) {
33
+ if (!Number.isInteger(low) || !Number.isInteger(high))
34
+ throw new RangeError(`int bounds must be integers: ${low}, ${high}`);
35
+ checkRange(low, high, options.log ?? false);
36
+ return { type: "int", low, high, log: options.log ?? false };
37
+ }
38
+ /** One of `choices`, compared by identity. */
39
+ export function choice(choices) {
40
+ if (choices.length === 0)
41
+ throw new RangeError("choice needs at least one option");
42
+ return { type: "choice", choices };
43
+ }
44
+ function checkRange(low, high, log) {
45
+ if (!(Number.isFinite(low) && Number.isFinite(high) && low <= high))
46
+ throw new RangeError(`invalid range: [${low}, ${high}]`);
47
+ if (log && low <= 0)
48
+ throw new RangeError(`a log range must be positive: [${low}, ${high}]`);
49
+ }
50
+ export class TpeSampler {
51
+ trials = [];
52
+ random;
53
+ sign;
54
+ startupTrials;
55
+ candidates;
56
+ gamma;
57
+ priorWeight;
58
+ space;
59
+ // A plain field, not a parameter property, so Node can strip the types and
60
+ // run this file as it is.
61
+ constructor(space, options = {}) {
62
+ this.space = space;
63
+ this.random = mulberry32(options.seed ?? 0);
64
+ this.sign = options.direction === "maximize" ? -1 : 1;
65
+ this.startupTrials = options.startupTrials ?? 10;
66
+ this.candidates = options.candidates ?? 24;
67
+ this.gamma = options.gamma ?? ((n) => Math.min(Math.ceil(0.1 * n), 25));
68
+ this.priorWeight = options.priorWeight ?? 1;
69
+ }
70
+ /** The next configuration to evaluate. */
71
+ ask() {
72
+ const config = {};
73
+ const told = this.trials.length;
74
+ if (told < this.startupTrials) {
75
+ for (const [name, param] of Object.entries(this.space))
76
+ config[name] = this.sampleRandom(param);
77
+ return config;
78
+ }
79
+ // Lower is better internally; a value that isn't finite (a failed trial)
80
+ // sorts last and is never in the good group.
81
+ const ranked = this.trials
82
+ .map((trial) => ({ config: trial.config, loss: this.loss(trial.value) }))
83
+ .sort((a, b) => a.loss - b.loss);
84
+ const finite = ranked.filter((t) => Number.isFinite(t.loss)).length;
85
+ if (finite === 0) {
86
+ for (const [name, param] of Object.entries(this.space))
87
+ config[name] = this.sampleRandom(param);
88
+ return config;
89
+ }
90
+ const nGood = Math.max(1, Math.min(finite, told - 1, this.gamma(told)));
91
+ const good = ranked.slice(0, nGood).map((t) => t.config);
92
+ const bad = ranked.slice(nGood).map((t) => t.config);
93
+ for (const [name, param] of Object.entries(this.space)) {
94
+ const below = good.map((c) => c[name]);
95
+ const above = bad.map((c) => c[name]);
96
+ config[name] =
97
+ param.type === "choice"
98
+ ? this.sampleChoice(param, below, above)
99
+ : this.sampleNumber(param, below, above);
100
+ }
101
+ return config;
102
+ }
103
+ /** Records what `config` scored. `NaN` or `±Infinity` marks a failure. */
104
+ tell(config, value) {
105
+ this.trials.push({ config, value });
106
+ }
107
+ /** The best trial told so far, ignoring failures. */
108
+ get best() {
109
+ let best;
110
+ for (const trial of this.trials) {
111
+ if (!Number.isFinite(trial.value))
112
+ continue;
113
+ if (!best || this.sign * trial.value < this.sign * best.value)
114
+ best = trial;
115
+ }
116
+ return best;
117
+ }
118
+ loss(value) {
119
+ return Number.isFinite(value) ? this.sign * value : Infinity;
120
+ }
121
+ sampleRandom(param) {
122
+ if (param.type === "choice")
123
+ return param.choices[Math.floor(this.random() * param.choices.length)];
124
+ const [low, high] = internalBounds(param);
125
+ return fromInternal(param, low + this.random() * (high - low));
126
+ }
127
+ sampleNumber(param, below, above) {
128
+ const [low, high] = internalBounds(param);
129
+ if (low === high)
130
+ return fromInternal(param, low);
131
+ const l = this.parzen(below.map((v) => toInternal(param, v)), low, high);
132
+ const g = this.parzen(above.map((v) => toInternal(param, v)), low, high);
133
+ let bestX = low;
134
+ let bestScore = -Infinity;
135
+ for (let i = 0; i < this.candidates; i++) {
136
+ const x = sampleMixture(l, low, high, this.random);
137
+ const score = mixtureLogPdf(l, x, low, high) - mixtureLogPdf(g, x, low, high);
138
+ if (score > bestScore)
139
+ [bestX, bestScore] = [x, score];
140
+ }
141
+ return fromInternal(param, bestX);
142
+ }
143
+ /**
144
+ * Hyperopt's adaptive Parzen estimator: one Gaussian per observation plus
145
+ * a prior over the whole range, each as wide as the larger gap to its
146
+ * neighbours, clipped to `[range / min(100, n + 1), range]`.
147
+ */
148
+ parzen(observed, low, high) {
149
+ const range = high - low;
150
+ const prior = {
151
+ mu: (low + high) / 2,
152
+ sigma: range,
153
+ weight: this.priorWeight,
154
+ };
155
+ const components = [
156
+ ...observed.map((mu) => ({ mu, sigma: 0, weight: 1 })),
157
+ prior,
158
+ ].sort((a, b) => a.mu - b.mu);
159
+ const minSigma = range / Math.min(100, components.length);
160
+ for (let i = 0; i < components.length; i++) {
161
+ const component = components[i];
162
+ if (component === prior)
163
+ continue;
164
+ const left = component.mu - (components[i - 1]?.mu ?? low);
165
+ const right = (components[i + 1]?.mu ?? high) - component.mu;
166
+ component.sigma = Math.min(range, Math.max(minSigma, left, right));
167
+ }
168
+ const total = components.reduce((sum, c) => sum + c.weight, 0);
169
+ for (const component of components)
170
+ component.weight /= total;
171
+ return components;
172
+ }
173
+ sampleChoice(param, below, above) {
174
+ const l = this.choiceWeights(param, below);
175
+ const g = this.choiceWeights(param, above);
176
+ let best = 0;
177
+ let bestScore = -Infinity;
178
+ for (let i = 0; i < this.candidates; i++) {
179
+ const index = pickWeighted(l, this.random);
180
+ const score = Math.log(l[index]) - Math.log(g[index]);
181
+ if (score > bestScore)
182
+ [best, bestScore] = [index, score];
183
+ }
184
+ return param.choices[best];
185
+ }
186
+ /** Each choice's probability: its count plus a share of the prior. */
187
+ choiceWeights(param, observed) {
188
+ const k = param.choices.length;
189
+ const counts = param.choices.map(() => this.priorWeight / k);
190
+ for (const value of observed) {
191
+ const index = param.choices.indexOf(value);
192
+ if (index >= 0)
193
+ counts[index] += 1;
194
+ }
195
+ const total = counts.reduce((sum, c) => sum + c, 0);
196
+ return counts.map((c) => c / total);
197
+ }
198
+ }
199
+ /** Runs `trials` evaluations of `objective` one after another. */
200
+ export async function optimize(space, objective, options) {
201
+ const sampler = new TpeSampler(space, options);
202
+ for (let i = 0; i < options.trials; i++) {
203
+ const config = sampler.ask();
204
+ sampler.tell(config, await objective(config));
205
+ }
206
+ return { best: sampler.best, trials: sampler.trials };
207
+ }
208
+ // Internal space: log-scaled when `log`; an int widened by half a step each
209
+ // side so both ends are as likely as the values between.
210
+ function internalBounds(param) {
211
+ const pad = param.type === "int" ? 0.5 : 0;
212
+ const low = param.low - pad;
213
+ const high = param.high + pad;
214
+ // A log int's lower bound stays positive: `int(1, 8, { log: true })` → [0.5, 8.5].
215
+ return param.log ? [Math.log(low), Math.log(high)] : [low, high];
216
+ }
217
+ function toInternal(param, value) {
218
+ return param.log ? Math.log(value) : value;
219
+ }
220
+ function fromInternal(param, x) {
221
+ const value = param.log ? Math.exp(x) : x;
222
+ const clamped = Math.min(param.high, Math.max(param.low, value));
223
+ return param.type === "int" ? Math.round(clamped) : clamped;
224
+ }
225
+ function mixtureLogPdf(mixture, x, low, high) {
226
+ let density = 0;
227
+ for (const { mu, sigma, weight } of mixture) {
228
+ const mass = normalCdf((high - mu) / sigma) - normalCdf((low - mu) / sigma);
229
+ const z = (x - mu) / sigma;
230
+ density +=
231
+ (weight * Math.exp(-0.5 * z * z)) /
232
+ (sigma * Math.sqrt(2 * Math.PI) * Math.max(mass, 1e-12));
233
+ }
234
+ return Math.log(Math.max(density, Number.MIN_VALUE));
235
+ }
236
+ /**
237
+ * A draw from the mixture truncated to `[low, high]`. Each component's mean
238
+ * is inside the range and its width at most the range, so rejection accepts
239
+ * at least a third of draws; the clamp is only a backstop.
240
+ */
241
+ function sampleMixture(mixture, low, high, random) {
242
+ const { mu, sigma } = mixture[pickWeighted(mixture.map((c) => c.weight), random)];
243
+ for (let attempt = 0; attempt < 100; attempt++) {
244
+ const x = mu + sigma * standardNormal(random);
245
+ if (x >= low && x <= high)
246
+ return x;
247
+ }
248
+ return Math.min(high, Math.max(low, mu));
249
+ }
250
+ function pickWeighted(weights, random) {
251
+ let r = random() * weights.reduce((sum, w) => sum + w, 0);
252
+ for (let i = 0; i < weights.length; i++) {
253
+ r -= weights[i];
254
+ if (r < 0)
255
+ return i;
256
+ }
257
+ return weights.length - 1;
258
+ }
259
+ function standardNormal(random) {
260
+ // Box–Muller; `1 - random()` keeps the log's argument above zero.
261
+ return (Math.sqrt(-2 * Math.log(1 - random())) * Math.cos(2 * Math.PI * random()));
262
+ }
263
+ /** Φ(z), via Abramowitz and Stegun 7.1.26 (absolute error below 1.5e-7). */
264
+ function normalCdf(z) {
265
+ const x = Math.abs(z) / Math.SQRT2;
266
+ const t = 1 / (1 + 0.3275911 * x);
267
+ const poly = t *
268
+ (0.254829592 +
269
+ t *
270
+ (-0.284496736 +
271
+ t * (1.421413741 + t * (-1.453152027 + t * 1.061405429))));
272
+ const erf = 1 - poly * Math.exp(-x * x);
273
+ return z >= 0 ? 0.5 * (1 + erf) : 0.5 * (1 - erf);
274
+ }
275
+ /** A small, fast, seedable PRNG; returns floats in `[0, 1)`. */
276
+ function mulberry32(seed) {
277
+ let state = seed >>> 0;
278
+ return () => {
279
+ state = (state + 0x6d2b79f5) >>> 0;
280
+ let t = state;
281
+ t = Math.imul(t ^ (t >>> 15), t | 1);
282
+ t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
283
+ return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
284
+ };
285
+ }
286
+ //# sourceMappingURL=tpe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tpe.js","sourceRoot":"","sources":["../../src/tuning/tpe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAiDH,kEAAkE;AAClE,MAAM,UAAU,KAAK,CACnB,GAAW,EACX,IAAY,EACZ,OAAO,GAAsB,EAAE;IAE/B,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC;IAC5C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,EAAE,CAAC;AACjE,CAAC;AAED,kDAAkD;AAClD,MAAM,U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,CAAC"}
package/docs/README.md CHANGED
@@ -24,8 +24,11 @@ at run time.
24
24
  | Declare capability policy and bindings | [MCP configuration](mcp-configuration.md) |
25
25
  | Answer a chat message from a Recipe | [Channel tools](channels/README.md) |
26
26
  | Add Slack tools to a Recipe | [Slack channel connector](channels/slack.md) |
27
- | Read and mark up Word and PDF files from a Recipe | [Document tools](documents/README.md) |
27
+ | Read and mark up Word, PDF and HTML files from a Recipe | [Document tools](documents/README.md) |
28
28
  | Work with a person's mail, calendar and files | [Productivity tools](productivity/README.md) |
29
+ | Search the web from a Recipe | [Web search](search/README.md) |
30
+ | Track work in Linear, Jira or Introspection | [Issues tool](issues/README.md) |
31
+ | Bring a provider for search, productivity or issues | [Provider modules](providers.md) |
29
32
  | Define portable evaluation judges | [Recipe judges](recipe-judges.md) |
30
33
 
31
34
  ## Boundary
@@ -270,6 +270,7 @@ const capabilities = {
270
270
  react: false, edit: true, retract: true, read: false,
271
271
  attach: false, fetchFile: false,
272
272
  documents: false, resolveAuthors: true, permalinks: false,
273
+ hosts: ["api.my-channel.example"],
273
274
  };
274
275
 
275
276
  class MyAdapter implements ChannelAdapter {
@@ -314,6 +315,15 @@ their own API fields and do not define provider-specific origin types.
314
315
  Registration checks that the adapter implements every method its capabilities
315
316
  claim, so a descriptor cannot promise a tool the adapter does not have.
316
317
 
318
+ `hosts` lists every host the adapter sends to; only a declared host can be
319
+ rebound by `.pi/api.local.json` (see
320
+ [Bind a provider's API host](../mcp-configuration.md#bind-a-providers-api-host)).
321
+ `createSession` also receives `isApiBound(url)`: a request to a bound host
322
+ goes to a fake or local server rather than through the egress, so the adapter
323
+ sends it without a credential instead of refusing for want of an egress.
324
+ Read `globalThis.fetch` per call rather than capturing it, so the binding
325
+ applies.
326
+
317
327
  The host turns the descriptor into an ordinary `RecipeConnectorModule` with
318
328
  `createChannelConnectorModule`, which a package may still call itself if it
319
329
  depends on Recipes. Manifest validation and agent
@@ -35,8 +35,8 @@ tools: [documents]
35
35
  ```
36
36
 
37
37
  Each declaration names a format, served by the package
38
- `@introspection-ai/recipe-documents-<format>`. Recipes installs the docx and
39
- pdf packages alongside itself (they are `optionalDependencies` of
38
+ `@introspection-ai/recipe-documents-<format>`. Recipes installs the docx,
39
+ pdf and html packages alongside itself (they are `optionalDependencies` of
40
40
  `@introspection-ai/recipes`), so a Recipe that does not list them uses the
41
41
  copy beside the running Recipes, Python environment and profiles included.
42
42
  Declare it in `peerDependencies` by default, which says so explicitly: the
@@ -200,13 +200,13 @@ doesn't ship fails when the Recipe loads, with the names it does ship.
200
200
 
201
201
  | Command (`documents` + `command`) | Arguments | Requires |
202
202
  | --- | --- | --- |
203
- | `read` | `path`, `offset?`, `budget?`, `pages?`, `tables?` | always |
204
- | `revise` | `path`, `output?`, `author`, `revisions[]` (`paragraph`, `text`, `rationale`) | `revise` |
205
- | `propose_edits` | `path`, `output?`, `author`, `edits[]` | `proposeEdits` |
206
- | `comment` | `path`, `output?`, `author`, `text`, and `quote` (`paragraph?`, `near?`, `occurrence?`) or `thread` | `comment` |
207
- | `respond` | `path`, `output?`, `author`, `responses[]` | `respond` |
208
- | `remove_section` | `path`, `output?`, `author`, `from`, `through`, `keep?`, `rationale` | `removeSection` |
209
- | `render` | `path`, `pages?` | `render` |
203
+ | `read` | `path`, `offset?`, `budget?`, `pages?`, `tables?` | always | The page as markdown (`.html`, `.htm`; an `.svg` file is one chart): headings, lists and GFM tables, scripts and styles dropped, each chart (an outermost `<figure>` or `<svg>`) a `[chart N: label]` line. Paged by character. |
204
+ | `revise` | `path`, `output?`, `author`, `revisions[]` (`paragraph`, `text`, `rationale`) | `revise` | not registered |
205
+ | `propose_edits` | `path`, `output?`, `author`, `edits[]` | `proposeEdits` | not registered |
206
+ | `comment` | `path`, `output?`, `author`, `text`, and `quote` (`paragraph?`, `near?`, `occurrence?`) or `thread` | `comment` | not registered |
207
+ | `respond` | `path`, `output?`, `author`, `responses[]` | `respond` | not registered |
208
+ | `remove_section` | `path`, `output?`, `author`, `from`, `through`, `keep?`, `rationale` | `removeSection` | not registered |
209
+ | `render` | `path`, `pages?` | `render` | With a browser, the full page light and dark and each chart as its own element screenshot, at 2x; without one, each inline `<svg>` chart through resvg, naming what it could not draw. `pages` picks charts. |
210
210
 
211
211
  An edit is `{ op: "replace" | "delete" | "insert_after", quote, paragraph?,
212
212
  near?, occurrence?, new?, rationale }`. A response is `{ action: "accept" |
@@ -219,15 +219,15 @@ candidate paragraphs. It never returns the whole document; `read` does that.
219
219
 
220
220
  ## What each format registers
221
221
 
222
- | Command | docx (`@introspection-ai/recipe-documents-docx`) | PDF (`@introspection-ai/recipe-documents-pdf`) |
223
- | --- | --- | --- |
224
- | `read` | Paragraphs with stable ids (`p-031`, `p-012.r2c3` in tables) and their current text, Word's list numbers, a `markup:` line with tracked changes and comments by author, then numbered changes and comment threads. Paged by paragraph. | The path used (text, tables or page images), then pypdfium2's text page by page in reading order, filled form fields and page comments. `tables: true` adds table cells with the `tables` extra. Pages with no text layer are named, to render. Paged by character. |
225
- | `revise` | Each paragraph's revised text: on a file with no pending changes, untracked edits on a working copy and paper-docx `compare(granularity="word")` build the redline; if compare refuses the batch, or the file already has changes, the same word-level changes go in as targeted tracked edits. The rationale is a comment on the changed text. | not registered |
226
- | `propose_edits` | Tracked changes signed by `author`, each with its rationale as a comment, saved with `patch_save` | not registered |
227
- | `comment` | New comment on a quote, or a reply under a thread's first comment | not registered |
228
- | `respond` | Accept or reject by change number (tracked moves resolve as a pair), reply, or counter | not registered |
229
- | `remove_section` | Strikes the paragraphs, leaves `Reserved.` after `keep`, keeps numbering | not registered |
230
- | `render` | not registered | PNG files of pages, at most 10 per call; returns their paths for Pi's `read` tool |
222
+ | Command | docx (`@introspection-ai/recipe-documents-docx`) | PDF (`@introspection-ai/recipe-documents-pdf`) | HTML (`@introspection-ai/recipe-documents-html`) |
223
+ | --- | --- | --- | --- |
224
+ | `read` | Paragraphs with stable ids (`p-031`, `p-012.r2c3` in tables) and their current text, Word's list numbers, a `markup:` line with tracked changes and comments by author, then numbered changes and comment threads. Paged by paragraph. | The path used (text, tables or page images), then pypdfium2's text page by page in reading order, filled form fields and page comments. `tables: true` adds table cells with the `tables` extra. Pages with no text layer are named, to render. Paged by character. | The page as markdown (`.html`, `.htm`; an `.svg` file is one chart): headings, lists and GFM tables, scripts and styles dropped, each chart (an outermost `<figure>` or `<svg>`) a `[chart N: label]` line. Paged by character. |
225
+ | `revise` | Each paragraph's revised text: on a file with no pending changes, untracked edits on a working copy and paper-docx `compare(granularity="word")` build the redline; if compare refuses the batch, or the file already has changes, the same word-level changes go in as targeted tracked edits. The rationale is a comment on the changed text. | not registered | not registered |
226
+ | `propose_edits` | Tracked changes signed by `author`, each with its rationale as a comment, saved with `patch_save` | not registered | not registered |
227
+ | `comment` | New comment on a quote, or a reply under a thread's first comment | not registered | not registered |
228
+ | `respond` | Accept or reject by change number (tracked moves resolve as a pair), reply, or counter | not registered | not registered |
229
+ | `remove_section` | Strikes the paragraphs, leaves `Reserved.` after `keep`, keeps numbering | not registered | not registered |
230
+ | `render` | not registered | PNG files of pages, at most 10 per call; returns their paths for Pi's `read` tool | With a browser, the full page light and dark and each chart as its own element screenshot, at 2x; without one, each inline `<svg>` chart through resvg, naming what it could not draw. `pages` picks charts. |
231
231
 
232
232
  ### docx: revise or propose_edits
233
233
 
@@ -338,7 +338,7 @@ recommend the extra; a Recipe that only reads briefs can leave it out.
338
338
 
339
339
  ## Python
340
340
 
341
- The Word and PDF helpers are small Python programs. Each format package
341
+ The Word and PDF helpers are small Python programs (HTML runs in Node and needs none). Each format package
342
342
  declares its own `pi.runtime.python` environment, locked by the package's
343
343
  `python/uv.lock`: paper-docx for Word, pypdfium2 and pillow for PDF. The host
344
344
  prepares that environment for the installed package, as it does every
@@ -424,3 +424,4 @@ dependency of the Recipe that uses it, installed when the runtime is baked.
424
424
 
425
425
  - Word: this page; `packages/documents/docx/README.md`.
426
426
  - PDF: this page; `packages/documents/pdf/README.md`.
427
+ - HTML: this page; `packages/documents/html/README.md`.
package/docs/host-api.md CHANGED
@@ -75,6 +75,7 @@ const handle = await createAgentSession({
75
75
  },
76
76
  memoryOverride,
77
77
  transformSystemPrompt,
78
+ clock: { timeZone: "America/Los_Angeles", locale: "en-US" },
78
79
  onDiagnostics,
79
80
  onEvent,
80
81
  onAgentRunEvent,
@@ -119,6 +120,15 @@ gateway-decorated model without reimplementing Recipe semantics. The Recipe
119
120
  continues to own model configuration and tool selection; host seams replace
120
121
  transport and materialized resources, not the portable definition.
121
122
 
123
+ ### The person's clock
124
+
125
+ `clock` sets the time zone (IANA) and locale (BCP 47) of the person the
126
+ session serves, and optionally `now`, which pins the clock in tests. Every
127
+ turn's prompt names the date in that zone, and the built-in `today` tool and
128
+ `calendar list`'s default range read the same clock, as do the default
129
+ in-process children. Omitted fields fall back to the host's time zone and
130
+ locale and the system clock; an unknown zone fails construction.
131
+
122
132
  ### Persistent memory context
123
133
 
124
134
  Hosts can provide one durable memory index through `memory`. Recipes loads the