@introspection-ai/recipes 0.51.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 (226) 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 +48 -2
  44. package/dist/connector-tools.js.map +1 -1
  45. package/dist/documents/tools.d.ts.map +1 -1
  46. package/dist/documents/tools.js +3 -3
  47. package/dist/documents/tools.js.map +1 -1
  48. package/dist/issues/index.d.ts +7 -0
  49. package/dist/issues/index.d.ts.map +1 -0
  50. package/dist/issues/index.js +4 -0
  51. package/dist/issues/index.js.map +1 -0
  52. package/dist/issues/module.d.ts +38 -0
  53. package/dist/issues/module.d.ts.map +1 -0
  54. package/dist/issues/module.js +114 -0
  55. package/dist/issues/module.js.map +1 -0
  56. package/dist/issues/tool.d.ts +95 -0
  57. package/dist/issues/tool.d.ts.map +1 -0
  58. package/dist/issues/tool.js +479 -0
  59. package/dist/issues/tool.js.map +1 -0
  60. package/dist/issues/types.d.ts +280 -0
  61. package/dist/issues/types.d.ts.map +1 -0
  62. package/dist/issues/types.js +79 -0
  63. package/dist/issues/types.js.map +1 -0
  64. package/dist/mcp/cli/command-context.d.ts +20 -1
  65. package/dist/mcp/cli/command-context.d.ts.map +1 -1
  66. package/dist/mcp/cli/command-context.js.map +1 -1
  67. package/dist/mcp/cli/core.d.ts +0 -2
  68. package/dist/mcp/cli/core.d.ts.map +1 -1
  69. package/dist/mcp/cli/core.js +9 -33
  70. package/dist/mcp/cli/core.js.map +1 -1
  71. package/dist/mcp/cli/handshake-retry.d.ts +5 -0
  72. package/dist/mcp/cli/handshake-retry.d.ts.map +1 -0
  73. package/dist/mcp/cli/handshake-retry.js +32 -0
  74. package/dist/mcp/cli/handshake-retry.js.map +1 -0
  75. package/dist/mcp/daemon/index.js +3 -4
  76. package/dist/mcp/daemon/index.js.map +1 -1
  77. package/dist/mcp/pi-client.d.ts +2 -0
  78. package/dist/mcp/pi-client.d.ts.map +1 -1
  79. package/dist/mcp/pi-client.js +5 -1
  80. package/dist/mcp/pi-client.js.map +1 -1
  81. package/dist/mcp/pi-mcp-runtime.d.ts +25 -0
  82. package/dist/mcp/pi-mcp-runtime.d.ts.map +1 -0
  83. package/dist/mcp/pi-mcp-runtime.js +215 -0
  84. package/dist/mcp/pi-mcp-runtime.js.map +1 -0
  85. package/dist/mcp/pi-runtime.d.ts +7 -0
  86. package/dist/mcp/pi-runtime.d.ts.map +1 -0
  87. package/dist/mcp/pi-runtime.js +26 -0
  88. package/dist/mcp/pi-runtime.js.map +1 -0
  89. package/dist/mcp-chunks/chunk-3UVHZECT.js +31 -0
  90. package/dist/mcp-chunks/{chunk-PO2SOBEN.js → chunk-CGJ2XOSF.js} +43 -35
  91. package/dist/mcp-chunks/{chunk-GTETFUPQ.js → chunk-IMG2JMBS.js} +8 -8
  92. package/dist/mcp-chunks/{chunk-UFV6SVQG.js → chunk-LQKMNWDE.js} +2 -2
  93. package/dist/mcp-chunks/{chunk-S2F7DDP5.js → chunk-QUDOU7MQ.js} +1 -1
  94. package/dist/mcp-chunks/{cli-IYD7Y7MO.js → cli-BM23ZXPJ.js} +54 -54
  95. package/dist/mcp-chunks/{client-5MNBV3Z7.js → client-RKTAKDAY.js} +7 -7
  96. package/dist/mcp-chunks/{daemon-command-V3B3EMXD.js → daemon-command-VU6WTFCJ.js} +8 -8
  97. package/dist/mcp-chunks/{generate-cli-runner-PW5WJ7KI.js → generate-cli-runner-JAAPSWGX.js} +12 -12
  98. package/dist/mcp-chunks/{generated-daemon-runtime-3C4NWGAU.js → generated-daemon-runtime-LX4L2X7Z.js} +8 -8
  99. package/dist/mcp-chunks/pi-mcp-runtime-GHDEPXUL.js +1231 -0
  100. package/dist/mcp-chunks/{runtime-RMI3XCYJ.js → runtime-T63YI7TC.js} +6 -6
  101. package/dist/mcp-chunks/{serve-command-UF5SVREV.js → serve-command-75P4VBJ6.js} +7 -7
  102. package/dist/mcp-daemon.js +21 -19
  103. package/dist/mcp-run-worker.js +11 -10
  104. package/dist/pi-extension.d.ts +3 -0
  105. package/dist/pi-extension.d.ts.map +1 -1
  106. package/dist/pi-extension.js +82 -18
  107. package/dist/pi-extension.js.map +1 -1
  108. package/dist/productivity/arguments.d.ts +298 -0
  109. package/dist/productivity/arguments.d.ts.map +1 -0
  110. package/dist/productivity/arguments.generated.d.ts +28 -0
  111. package/dist/productivity/arguments.generated.d.ts.map +1 -0
  112. package/dist/productivity/arguments.generated.js +489 -0
  113. package/dist/productivity/arguments.generated.js.map +1 -0
  114. package/dist/productivity/arguments.js +10 -0
  115. package/dist/productivity/arguments.js.map +1 -0
  116. package/dist/productivity/http.d.ts.map +1 -1
  117. package/dist/productivity/http.js +4 -1
  118. package/dist/productivity/http.js.map +1 -1
  119. package/dist/productivity/index.d.ts +1 -1
  120. package/dist/productivity/index.d.ts.map +1 -1
  121. package/dist/productivity/index.js +1 -1
  122. package/dist/productivity/index.js.map +1 -1
  123. package/dist/productivity/module.d.ts +15 -2
  124. package/dist/productivity/module.d.ts.map +1 -1
  125. package/dist/productivity/module.js +24 -19
  126. package/dist/productivity/module.js.map +1 -1
  127. package/dist/productivity/tools.d.ts +6 -0
  128. package/dist/productivity/tools.d.ts.map +1 -1
  129. package/dist/productivity/tools.js +64 -224
  130. package/dist/productivity/tools.js.map +1 -1
  131. package/dist/productivity/types.d.ts +2 -0
  132. package/dist/productivity/types.d.ts.map +1 -1
  133. package/dist/productivity/types.js.map +1 -1
  134. package/dist/recipe/agent.d.ts +40 -10
  135. package/dist/recipe/agent.d.ts.map +1 -1
  136. package/dist/recipe/agent.js +209 -30
  137. package/dist/recipe/agent.js.map +1 -1
  138. package/dist/recipe/companions.js +1 -1
  139. package/dist/recipe/manifest.generated.d.ts +3 -1
  140. package/dist/recipe/manifest.generated.d.ts.map +1 -1
  141. package/dist/recipe/manifest.generated.js +3 -1
  142. package/dist/recipe/manifest.generated.js.map +1 -1
  143. package/dist/recipe/package.d.ts +28 -3
  144. package/dist/recipe/package.d.ts.map +1 -1
  145. package/dist/recipe/package.js +155 -1
  146. package/dist/recipe/package.js.map +1 -1
  147. package/dist/recipe/providers.d.ts +62 -0
  148. package/dist/recipe/providers.d.ts.map +1 -0
  149. package/dist/recipe/providers.js +95 -0
  150. package/dist/recipe/providers.js.map +1 -0
  151. package/dist/recipe/resolve.d.ts +7 -3
  152. package/dist/recipe/resolve.d.ts.map +1 -1
  153. package/dist/recipe/resolve.js +7 -2
  154. package/dist/recipe/resolve.js.map +1 -1
  155. package/dist/run-controller.d.ts +6 -0
  156. package/dist/run-controller.d.ts.map +1 -1
  157. package/dist/run-controller.js +2 -0
  158. package/dist/run-controller.js.map +1 -1
  159. package/dist/search/index.d.ts +2 -1
  160. package/dist/search/index.d.ts.map +1 -1
  161. package/dist/search/index.js +1 -1
  162. package/dist/search/index.js.map +1 -1
  163. package/dist/search/module.d.ts +19 -7
  164. package/dist/search/module.d.ts.map +1 -1
  165. package/dist/search/module.js +38 -16
  166. package/dist/search/module.js.map +1 -1
  167. package/dist/search/tool.d.ts +6 -1
  168. package/dist/search/tool.d.ts.map +1 -1
  169. package/dist/search/tool.js +22 -9
  170. package/dist/search/tool.js.map +1 -1
  171. package/dist/search/types.d.ts +13 -3
  172. package/dist/search/types.d.ts.map +1 -1
  173. package/dist/search/types.js +4 -1
  174. package/dist/search/types.js.map +1 -1
  175. package/dist/session.d.ts +21 -1
  176. package/dist/session.d.ts.map +1 -1
  177. package/dist/session.js +132 -43
  178. package/dist/session.js.map +1 -1
  179. package/dist/test-utils.d.ts +2 -0
  180. package/dist/test-utils.d.ts.map +1 -1
  181. package/dist/test-utils.js +3 -1
  182. package/dist/test-utils.js.map +1 -1
  183. package/dist/tool-search.d.ts +9 -0
  184. package/dist/tool-search.d.ts.map +1 -1
  185. package/dist/tool-search.js +23 -0
  186. package/dist/tool-search.js.map +1 -1
  187. package/dist/tools/bridge.d.ts +44 -0
  188. package/dist/tools/bridge.d.ts.map +1 -0
  189. package/dist/tools/bridge.js +106 -0
  190. package/dist/tools/bridge.js.map +1 -0
  191. package/dist/tools/cli.d.ts +20 -0
  192. package/dist/tools/cli.d.ts.map +1 -0
  193. package/dist/tools/cli.js +246 -0
  194. package/dist/tools/cli.js.map +1 -0
  195. package/dist/tools/entry.d.ts +2 -0
  196. package/dist/tools/entry.d.ts.map +1 -0
  197. package/dist/tools/entry.js +3 -0
  198. package/dist/tools/entry.js.map +1 -0
  199. package/dist/tools/shell.d.ts +12 -0
  200. package/dist/tools/shell.d.ts.map +1 -0
  201. package/dist/tools/shell.js +50 -0
  202. package/dist/tools/shell.js.map +1 -0
  203. package/dist/tuning/tpe.d.ts +112 -0
  204. package/dist/tuning/tpe.d.ts.map +1 -0
  205. package/dist/tuning/tpe.js +286 -0
  206. package/dist/tuning/tpe.js.map +1 -0
  207. package/docs/README.md +3 -1
  208. package/docs/channels/README.md +10 -0
  209. package/docs/documents/README.md +20 -19
  210. package/docs/host-api.md +10 -0
  211. package/docs/issues/README.md +183 -0
  212. package/docs/mcp-configuration.md +65 -1
  213. package/docs/pi-extension.md +5 -0
  214. package/docs/productivity/README.md +8 -3
  215. package/docs/providers.md +321 -0
  216. package/docs/recipe-format.md +103 -32
  217. package/docs/search/README.md +37 -20
  218. package/package.json +28 -10
  219. package/skills/documents/SKILL.md +2 -1
  220. package/dist/mcp-chunks/{auth-command-M7TQE3AL.js → auth-command-UYFOGGQR.js} +6 -6
  221. package/dist/mcp-chunks/{call-command-7LD7UEFK.js → call-command-6U5BNDR7.js} +17 -17
  222. package/dist/mcp-chunks/{chunk-PSE442BC.js → chunk-36D4FILJ.js} +26 -26
  223. package/dist/mcp-chunks/{config-command-6DXILFNO.js → config-command-ZSPJI34E.js} +10 -10
  224. package/dist/mcp-chunks/{emit-ts-command-NDCDFDRM.js → emit-ts-command-SY4LQE4S.js} +3 -3
  225. package/dist/mcp-chunks/{inspect-cli-command-4MGF5CPP.js → inspect-cli-command-JPX4ON6N.js} +4 -4
  226. package/dist/mcp-chunks/{resource-command-SRFQQROJ.js → resource-command-DUY4SVE5.js} +4 -4
@@ -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,UAAU,GAAG,CACjB,GAAW,EACX,IAAY,EACZ,OAAO,GAAsB,EAAE;IAE/B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;QACnD,MAAM,IAAI,UAAU,CAAC,gCAAgC,GAAG,KAAK,IAAI,EAAE,CAAC,CAAC;IACvE,UAAU,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,KAAK,CAAC,CAAC;IAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,IA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AC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;AACpD,CAAC;AAED,gEAAgE;AAChE,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,KAAK,GAAG,IAAI,KAAK,CAAC,CAAC;IACvB,OAAO,GAAG,EAAE;QACV,KAAK,GAAG,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,CAAC,GAAG,KAAK,CAAC;QACd,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;QAC1C,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,UAAU,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC"}
package/docs/README.md CHANGED
@@ -24,9 +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
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) |
30
32
  | Define portable evaluation judges | [Recipe judges](recipe-judges.md) |
31
33
 
32
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
@@ -0,0 +1,183 @@
1
+ # Issues tool
2
+
3
+ **Status: built** (`@introspection-ai/recipes/issues` and
4
+ `@introspection-ai/recipe-issues`). The Linear and Jira adapters are written
5
+ against tool names and arguments from vendor documentation, not yet against a
6
+ captured tool list; see [Tool maps](#tool-maps).
7
+
8
+ One `issues` tool tracks work in whichever tracker a Recipe's members use:
9
+ Linear, Jira, or Introspection's own issues when neither is connected. It is
10
+ the `issues` family of [provider modules](../providers.md).
11
+
12
+ ## Declare it
13
+
14
+ ```json
15
+ {
16
+ "pi": {
17
+ "issues": [
18
+ { "provider": "linear", "options": { "team": "ENG" } },
19
+ {
20
+ "provider": "jira",
21
+ "options": { "project": "OPS", "issueType": "Task" }
22
+ }
23
+ ]
24
+ }
25
+ }
26
+ ```
27
+
28
+ and select the tool in the agent file:
29
+
30
+ ```yaml
31
+ tools: [issues]
32
+ mcp:
33
+ servers:
34
+ linear:
35
+ include: ["*"]
36
+ behind: [issues]
37
+ atlassian:
38
+ include: ["*"]
39
+ behind: [issues]
40
+ ```
41
+
42
+ Nothing about issues loads, and no `issues` tool is offered, unless a Recipe
43
+ declares `pi.issues` and its agent selects `issues`.
44
+
45
+ A declaration takes only these fields:
46
+
47
+ | Field | Applies to | Meaning |
48
+ | ---------- | --------------- | ----------------------------------------------------------------------------------------- |
49
+ | `provider` | all | `linear`, `jira`, `introspection`, or a Recipe's own id |
50
+ | `package` | a Recipe's own | the installed package that serves it ([providers](../providers.md#2-declaring-providers)) |
51
+ | `options` | all | the provider's own settings, below |
52
+ | `enabled` | `introspection` | `false` leaves out the fallback |
53
+
54
+ | Option | Provider | Meaning |
55
+ | ---------------------- | ---------------- | ------------------------------------------------------------------ |
56
+ | `team` | `linear` | the team `create` files into |
57
+ | `project`, `issueType` | `jira` | the project and issue type `create` files into |
58
+ | `server` | `linear`, `jira` | the Recipe's MCP server id, when it is not `linear` or `atlassian` |
59
+
60
+ Validation (`pi.issues_invalid`) reports any other field, an option a
61
+ first-party provider does not take or of the wrong type, an unknown
62
+ first-party id, a duplicate, and a bad source. A Recipe's own provider
63
+ declares its options in `capabilities.options` (`{ queue: "string" }`), and
64
+ loading it fails on an option it does not declare.
65
+
66
+ ## Providers
67
+
68
+ | Provider | Transport | Server | Credential |
69
+ | --------------- | --------- | -------------------------------------------------- | ---------------------------------- |
70
+ | `linear` | MCP | `https://mcp.linear.app/mcp` | the member's MCP connector binding |
71
+ | `jira` | MCP | `https://mcp.atlassian.com/v2/mcp`, its Jira tools | the member's MCP connector binding |
72
+ | `introspection` | REST | the data plane's `/v1/issues` | the task's own session |
73
+
74
+ **`introspection` is the fallback.** It is included whenever `pi.issues` is
75
+ declared, unless declared with `"enabled": false`, and is offered only while
76
+ no other declared provider has a working credential path. Once a member
77
+ connects Linear or Jira, `search` and `create` go there; an issue already
78
+ filed on Introspection stays readable by its handle.
79
+
80
+ **Choosing a provider.** A provider is on offer when it has a working
81
+ credential path: an MCP provider when its bound server offers one of its
82
+ adapter's tools, `introspection` when the runtime holds a data plane URL and
83
+ the task's token. `search` and `create` name a provider when several are on
84
+ offer; every other command takes a handle, which names its provider. The
85
+ tool's `provider` parameter lists the declared providers, since an MCP
86
+ server's tools are known only once it has connected; a call naming one that
87
+ is not on offer fails with `not_connected`.
88
+
89
+ **Connecting Linear or Jira.** Both are OAuth MCP servers, connected per
90
+ member through an MCP connector binding. When none is connected the tool
91
+ answers `not_connected`, and the agent asks the member to connect one with
92
+ `introspection_open`.
93
+
94
+ **Introspection's session.** The provider uses the JavaScript SDK
95
+ (`@introspection-sdk/introspection-node`): a `DataPlaneClient` on
96
+ `INTROSPECTION_DP_URL` (else `INTROSPECTION_BASE_API_URL`) with
97
+ `INTROSPECTION_TOKEN`, all of which the runtime injects into the task's
98
+ sandbox. `create` files the issue on the calling task
99
+ (`INTROSPECTION_TASK_ID`), in the Recipe's project.
100
+
101
+ ## Commands
102
+
103
+ | Command | Takes | Does |
104
+ | ------------ | ----------------------------------------------------------------------------------- | --------------------------- |
105
+ | `search` | `query`, `status`, `assignee`, `container`, `label`, `limit` | find issues |
106
+ | `get` | `handle` | one issue with its comments |
107
+ | `create` | `title`, `description`, `priority`, `labels`, `assignee`, `container`, `issue_type` | a new issue |
108
+ | `update` | `handle`, `title`, `description`, `priority`, `labels`, `assignee` | change fields |
109
+ | `comment` | `handle`, `body` | add a comment |
110
+ | `transition` | `handle`, `status` (a name or a category) | move to another status |
111
+
112
+ ## The shape
113
+
114
+ Every issue comes back in one shape, with a handle every later command takes:
115
+
116
+ | Field | Linear | Jira | Introspection |
117
+ | ------------------------ | ------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
118
+ | `handle` | `linear:ENG-123` | `jira:PROJ-45` | `introspection:<display index>` |
119
+ | `title` | title | summary | title |
120
+ | `description` (markdown) | description | description, from Atlassian Document Format (best-effort) | description |
121
+ | `status.name` | workflow state | status | status |
122
+ | `status.category` | backlog, unstarted, triage → open; started → in_progress; completed → done; canceled → cancelled | To Do → open, In Progress → in_progress, Done → done; a done status named like cancelled, won't do or rejected → cancelled | open → open, waiting → in_progress, closed → done, cancelled → cancelled |
123
+ | `priority` | 0 none, 1 urgent, 2 high, 3 medium, 4 low | Highest → urgent, High → high, Medium → medium, Low and Lowest → low | low to urgent, no `none` |
124
+ | `assignee` | assignee | assignee | none |
125
+ | `labels` | labels | labels | tags |
126
+ | `container` | team | project, with the issue type | the project |
127
+ | `url` | ✓ | the site's `/browse/<key>` | not yet |
128
+ | `comments` (on `get`) | ✓ | ✓ | from the issue's events |
129
+
130
+ ## What each provider supports
131
+
132
+ | | `linear` | `jira` | `introspection` |
133
+ | ------------ | -------------------------------------------------------------- | ------------------------------------------------------- | -------------------------------------------------------------- |
134
+ | `search` | ✓ | ✓ (JQL) | ✓; text matches the 200 most recent issues; no assignee filter |
135
+ | `get` | ✓ | ✓ | ✓ |
136
+ | `create` | ✓, needs a team | ✓, needs a project and issue type | ✓, on the calling task |
137
+ | `update` | ✓ | ✓ | ✓, no assignee |
138
+ | `comment` | ✓ | ✓ | not yet |
139
+ | `transition` | sets the state; a category picks the team's state of that type | applies the workflow transition that reaches the status | sets `status` |
140
+
141
+ An Introspection comment is an event attached to the issue. The provider reads
142
+ comments from `GET /v1/events?event_name=introspection.issue&issue_id=…`
143
+ (`payload.comment`), and reads none from a data plane that does not record
144
+ that family yet. It does not offer `comment` until the platform accepts one
145
+ on `PATCH /v1/issues/{id}`.
146
+
147
+ ## Tool maps
148
+
149
+ Each MCP adapter calls its server through one tool map
150
+ (`LINEAR_MCP_TOOLS`, `JIRA_MCP_TOOLS`), every entry with `verified: false`
151
+ until it is checked against the server's live tool list
152
+ (`introspection bindings mcp capture`). The adapters' tests run against
153
+ captured-tool-list fixtures in `test/fixtures/issues/`, authored from vendor
154
+ documentation; replace them with captured lists, fix the maps, and set
155
+ `verified: true`.
156
+
157
+ | Provider | Use | Tool | Arguments sent |
158
+ | -------- | -------------------------- | ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
159
+ | `linear` | search | `list_issues` | `query`, `state`, `assignee`, `team`, `label`, `limit` |
160
+ | `linear` | get | `get_issue`, `list_comments` | `id`; `issueId` |
161
+ | `linear` | create, update, transition | `save_issue` (else `create_issue`, `update_issue`) | `id`, `team`, `title`, `description`, `priority` (0–4), `labels`, `assignee`, `state` |
162
+ | `linear` | comment | `create_comment` | `issueId`, `body` |
163
+ | `linear` | transition by category | `list_issue_statuses` | `team` |
164
+ | `jira` | every call | `getAccessibleAtlassianResources` | none; the first site with Jira scopes gives `cloudId` |
165
+ | `jira` | assignee by name | `lookupJiraAccountId` | `cloudId`, `searchString` |
166
+ | `jira` | search | `searchJiraIssuesUsingJql` | `cloudId`, `jql`, `maxResults`, `fields` |
167
+ | `jira` | get | `getJiraIssue`, `listJiraIssueComments` | `cloudId`, `issueIdOrKey`, `fields` |
168
+ | `jira` | create | `createJiraIssue` | `cloudId`, `projectKey`, `issueTypeName`, `summary`, `description`, `assignee_account_id`, `additional_fields` |
169
+ | `jira` | update | `editJiraIssue` | `cloudId`, `issueIdOrKey`, `fields` |
170
+ | `jira` | comment | `addOrEditJiraIssueComment` (else `addCommentToJiraIssue`) | `cloudId`, `issueIdOrKey`, `commentBody` |
171
+ | `jira` | transition | `listJiraIssueTransitions` (else `getTransitionsForJiraIssue`), `transitionJiraIssue` | `cloudId`, `issueIdOrKey`, `transition: { id }` |
172
+
173
+ ## A provider of your own
174
+
175
+ A provider module is `{ kind: "issues", apiVersion: 1, id, capabilities,
176
+ mcp?, available?, createSession }` (`RecipeIssuesProviderModule`), importing
177
+ only types from `@introspection-ai/recipes/issues`. `capabilities` lists the
178
+ commands it serves, the fields it fills, every host it calls, and the options
179
+ it takes. Its session receives the declaration's options as `config.options`.
180
+ `createSession` returns one method per command; each receives the provider's
181
+ own reference (the handle without its prefix) and, for an MCP provider, a
182
+ caller bound to its server. A failure the model should read throws an
183
+ `Error` carrying `issues: { code, message }`.