@introspection-ai/recipes 0.13.0 → 0.14.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 (222) hide show
  1. package/README.md +45 -58
  2. package/dist/{agent-tool.d.ts → agents.d.ts} +4 -1
  3. package/dist/agents.d.ts.map +1 -0
  4. package/dist/{agent-tool.js → agents.js} +1 -1
  5. package/dist/agents.js.map +1 -0
  6. package/dist/api/extensions.d.ts +3 -0
  7. package/dist/api/extensions.d.ts.map +1 -0
  8. package/dist/api/extensions.js +2 -0
  9. package/dist/api/extensions.js.map +1 -0
  10. package/dist/api/mcp.d.ts +4 -0
  11. package/dist/api/mcp.d.ts.map +1 -0
  12. package/dist/api/mcp.js +2 -0
  13. package/dist/api/mcp.js.map +1 -0
  14. package/dist/api/session.d.ts +3 -0
  15. package/dist/api/session.d.ts.map +1 -0
  16. package/dist/api/session.js +2 -0
  17. package/dist/api/session.js.map +1 -0
  18. package/dist/child-agent.d.ts +5 -4
  19. package/dist/child-agent.d.ts.map +1 -1
  20. package/dist/child-agent.js +26 -117
  21. package/dist/child-agent.js.map +1 -1
  22. package/dist/child-session.d.ts +23 -0
  23. package/dist/child-session.d.ts.map +1 -0
  24. package/dist/child-session.js +48 -0
  25. package/dist/child-session.js.map +1 -0
  26. package/dist/extensions.d.ts +29 -0
  27. package/dist/extensions.d.ts.map +1 -0
  28. package/dist/extensions.js +119 -0
  29. package/dist/extensions.js.map +1 -0
  30. package/dist/index.d.ts +4 -13
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +2 -13
  33. package/dist/index.js.map +1 -1
  34. package/dist/inspect.d.ts +38 -5
  35. package/dist/inspect.d.ts.map +1 -1
  36. package/dist/inspect.js +92 -41
  37. package/dist/inspect.js.map +1 -1
  38. package/dist/interactions.d.ts +18 -2
  39. package/dist/interactions.d.ts.map +1 -1
  40. package/dist/interactions.js +41 -10
  41. package/dist/interactions.js.map +1 -1
  42. package/dist/mcp-catalog.d.ts +1 -0
  43. package/dist/mcp-catalog.d.ts.map +1 -1
  44. package/dist/mcp-catalog.js +14 -6
  45. package/dist/mcp-catalog.js.map +1 -1
  46. package/dist/mcp-chunks/auth-command-ZLGYIEUY.js +273 -0
  47. package/dist/mcp-chunks/call-arguments-LU3W6D3K.js +13 -0
  48. package/dist/mcp-chunks/call-command-LKTKSYTH.js +612 -0
  49. package/dist/mcp-chunks/chunk-2U4BSDC4.js +3951 -0
  50. package/dist/mcp-chunks/chunk-2XL7MG7R.js +272 -0
  51. package/dist/mcp-chunks/chunk-3BJA27PY.js +2321 -0
  52. package/dist/mcp-chunks/chunk-4SQKWYFF.js +15 -0
  53. package/dist/mcp-chunks/chunk-5QOSCSQB.js +290 -0
  54. package/dist/mcp-chunks/chunk-6W5QFASN.js +77 -0
  55. package/dist/mcp-chunks/chunk-6XCZGU3G.js +1004 -0
  56. package/dist/mcp-chunks/chunk-7FHEBT5G.js +149 -0
  57. package/dist/mcp-chunks/chunk-7KA2VJVZ.js +114 -0
  58. package/dist/mcp-chunks/chunk-7UDVSOOF.js +138 -0
  59. package/dist/mcp-chunks/chunk-BNV3TPE4.js +66 -0
  60. package/dist/mcp-chunks/chunk-BTLAWHTA.js +129 -0
  61. package/dist/mcp-chunks/chunk-BV56DXPW.js +13 -0
  62. package/dist/mcp-chunks/chunk-BWHIA4PC.js +90 -0
  63. package/dist/mcp-chunks/chunk-BZIQOWE6.js +267 -0
  64. package/dist/mcp-chunks/chunk-D3MRAZ6H.js +16140 -0
  65. package/dist/mcp-chunks/chunk-DHBE7UBH.js +750 -0
  66. package/dist/mcp-chunks/chunk-E22DYOW5.js +251 -0
  67. package/dist/mcp-chunks/chunk-ECIVB7P4.js +139 -0
  68. package/dist/mcp-chunks/chunk-HKRJ6O36.js +1076 -0
  69. package/dist/mcp-chunks/chunk-IABRYROW.js +44 -0
  70. package/dist/mcp-chunks/chunk-J6LYIZXN.js +45 -0
  71. package/dist/mcp-chunks/chunk-L7NTQVYN.js +161 -0
  72. package/dist/mcp-chunks/chunk-LEZSACDE.js +141 -0
  73. package/dist/mcp-chunks/chunk-LKIBAYKU.js +208 -0
  74. package/dist/mcp-chunks/chunk-LNH5LAJD.js +152 -0
  75. package/dist/mcp-chunks/chunk-LQQEYD76.js +124 -0
  76. package/dist/mcp-chunks/chunk-LRKZP7DJ.js +47 -0
  77. package/dist/mcp-chunks/chunk-LS7PMWSR.js +109 -0
  78. package/dist/mcp-chunks/chunk-M3TPODXI.js +95 -0
  79. package/dist/mcp-chunks/chunk-MZ2NARG7.js +400 -0
  80. package/dist/mcp-chunks/chunk-N46NEFAF.js +45 -0
  81. package/dist/mcp-chunks/chunk-NNOEGEUZ.js +17273 -0
  82. package/dist/mcp-chunks/chunk-NRAJX5E4.js +69 -0
  83. package/dist/mcp-chunks/chunk-P3PSC54P.js +869 -0
  84. package/dist/mcp-chunks/chunk-PIIYJR44.js +6341 -0
  85. package/dist/mcp-chunks/chunk-PWYFKGKG.js +385 -0
  86. package/dist/mcp-chunks/chunk-SJCCBNZ4.js +45 -0
  87. package/dist/mcp-chunks/chunk-TATVT5IT.js +194 -0
  88. package/dist/mcp-chunks/chunk-TEUKFFQL.js +29 -0
  89. package/dist/mcp-chunks/chunk-UKYNQGNE.js +150 -0
  90. package/dist/mcp-chunks/chunk-UNKB4SBV.js +37 -0
  91. package/dist/mcp-chunks/chunk-WD6BOD24.js +138 -0
  92. package/dist/mcp-chunks/chunk-WQJZMCJN.js +73 -0
  93. package/dist/mcp-chunks/chunk-XANPGTLI.js +364 -0
  94. package/dist/mcp-chunks/chunk-XQK2JSW4.js +35 -0
  95. package/dist/mcp-chunks/chunk-YHQUTU6L.js +571 -0
  96. package/dist/mcp-chunks/chunk-YVZKMV5H.js +57 -0
  97. package/dist/mcp-chunks/cli-UV4QJZZM.js +929 -0
  98. package/dist/mcp-chunks/client-S7RQUG5U.js +13 -0
  99. package/dist/mcp-chunks/config-command-NLAGKID5.js +1101 -0
  100. package/dist/mcp-chunks/daemon-command-U242Z6VY.js +26 -0
  101. package/dist/mcp-chunks/dist-LK3SHAMX.js +6478 -0
  102. package/dist/mcp-chunks/emit-ts-command-VBXVXO6V.js +386 -0
  103. package/dist/mcp-chunks/generate-cli-runner-6CAZZA3P.js +1426 -0
  104. package/dist/mcp-chunks/inspect-cli-command-3ZORTOR7.js +111 -0
  105. package/dist/mcp-chunks/launch-YKRXHXJI.js +10 -0
  106. package/dist/mcp-chunks/lifecycle-XVKRHPH3.js +16 -0
  107. package/dist/mcp-chunks/list-command-2MEGGNFQ.js +4190 -0
  108. package/dist/mcp-chunks/output-utils-NKESLAJ6.js +12 -0
  109. package/dist/mcp-chunks/prompt-B1Yc1NPt-VGOTWJMN.js +918 -0
  110. package/dist/mcp-chunks/record-command-YXHTTTT5.js +17 -0
  111. package/dist/mcp-chunks/replay-command-25HJ6AQU.js +85 -0
  112. package/dist/mcp-chunks/resource-command-OO4NYF5C.js +97 -0
  113. package/dist/mcp-chunks/result-utils-MOHHLNM7.js +15 -0
  114. package/dist/mcp-chunks/runtime-5WJ3G25Y.js +33 -0
  115. package/dist/mcp-chunks/runtime-wrapper-RPWDIDBF.js +10 -0
  116. package/dist/mcp-chunks/serve-command-DHXJZMMN.js +3302 -0
  117. package/dist/mcp-chunks/timeouts-W2XWCCXR.js +18 -0
  118. package/dist/mcp-chunks/vault-command-PIYIUEZL.js +154 -0
  119. package/dist/mcp-daemon-client.d.ts +6 -1
  120. package/dist/mcp-daemon-client.d.ts.map +1 -1
  121. package/dist/mcp-daemon-client.js +119 -2
  122. package/dist/mcp-daemon-client.js.map +1 -1
  123. package/dist/mcp-daemon-protocol.d.ts +18 -1
  124. package/dist/mcp-daemon-protocol.d.ts.map +1 -1
  125. package/dist/mcp-daemon-protocol.js +31 -0
  126. package/dist/mcp-daemon-protocol.js.map +1 -1
  127. package/dist/mcp-daemon.js +169 -76602
  128. package/dist/mcp-daemon.js.map +1 -1
  129. package/dist/mcp-policy.d.ts +11 -0
  130. package/dist/mcp-policy.d.ts.map +1 -0
  131. package/dist/mcp-policy.js +27 -0
  132. package/dist/mcp-policy.js.map +1 -0
  133. package/dist/mcp-run-worker.js +38 -76540
  134. package/dist/mcp-tools.d.ts +39 -0
  135. package/dist/mcp-tools.d.ts.map +1 -0
  136. package/dist/mcp-tools.js +493 -0
  137. package/dist/mcp-tools.js.map +1 -0
  138. package/dist/mcp.d.ts +21 -9
  139. package/dist/mcp.d.ts.map +1 -1
  140. package/dist/mcp.js +101 -31
  141. package/dist/mcp.js.map +1 -1
  142. package/dist/model-binding.d.ts +39 -0
  143. package/dist/model-binding.d.ts.map +1 -0
  144. package/dist/model-binding.js +103 -0
  145. package/dist/model-binding.js.map +1 -0
  146. package/dist/pi-extension.d.ts +2 -22
  147. package/dist/pi-extension.d.ts.map +1 -1
  148. package/dist/pi-extension.js +296 -71
  149. package/dist/pi-extension.js.map +1 -1
  150. package/dist/recipe/resolve.d.ts +43 -20
  151. package/dist/recipe/resolve.d.ts.map +1 -1
  152. package/dist/recipe/resolve.js +215 -70
  153. package/dist/recipe/resolve.js.map +1 -1
  154. package/dist/recipe-agent.d.ts +24 -27
  155. package/dist/recipe-agent.d.ts.map +1 -1
  156. package/dist/recipe-agent.js +278 -230
  157. package/dist/recipe-agent.js.map +1 -1
  158. package/dist/recipe-check.d.ts +17 -0
  159. package/dist/recipe-check.d.ts.map +1 -0
  160. package/dist/recipe-check.js +258 -0
  161. package/dist/recipe-check.js.map +1 -0
  162. package/dist/recipe-extensions.d.ts.map +1 -1
  163. package/dist/recipe-extensions.js +0 -3
  164. package/dist/recipe-extensions.js.map +1 -1
  165. package/dist/recipe-model.d.ts +3 -1
  166. package/dist/recipe-model.d.ts.map +1 -1
  167. package/dist/recipe-model.js +15 -12
  168. package/dist/recipe-model.js.map +1 -1
  169. package/dist/recipe-package.d.ts +6 -28
  170. package/dist/recipe-package.d.ts.map +1 -1
  171. package/dist/recipe-package.js +248 -191
  172. package/dist/recipe-package.js.map +1 -1
  173. package/dist/recipe-skills.d.ts.map +1 -1
  174. package/dist/recipe-skills.js +42 -29
  175. package/dist/recipe-skills.js.map +1 -1
  176. package/dist/run-controller.d.ts +10 -9
  177. package/dist/run-controller.d.ts.map +1 -1
  178. package/dist/run-controller.js +28 -21
  179. package/dist/run-controller.js.map +1 -1
  180. package/dist/session.d.ts +40 -53
  181. package/dist/session.d.ts.map +1 -1
  182. package/dist/session.js +312 -173
  183. package/dist/session.js.map +1 -1
  184. package/dist/test-utils.d.ts +7 -7
  185. package/dist/test-utils.d.ts.map +1 -1
  186. package/dist/test-utils.js +32 -15
  187. package/dist/test-utils.js.map +1 -1
  188. package/docs/agent-composition.md +41 -35
  189. package/docs/host-api.md +201 -0
  190. package/docs/index.md +8 -14
  191. package/docs/interactions.md +12 -11
  192. package/docs/mcp-auth.md +6 -6
  193. package/docs/mcp-configuration.md +72 -24
  194. package/docs/pi-extension.md +39 -11
  195. package/docs/recipe-flow.md +9 -9
  196. package/docs/recipe-format.md +90 -41
  197. package/package.json +23 -17
  198. package/vendor/mcp-client/darwin-arm64/mcp-client +0 -0
  199. package/vendor/mcp-client/darwin-x64/mcp-client +0 -0
  200. package/vendor/mcp-client/linux-arm64/mcp-client +0 -0
  201. package/vendor/recipe-check/darwin-arm64/recipe-check +0 -0
  202. package/vendor/recipe-check/darwin-x64/recipe-check +0 -0
  203. package/vendor/recipe-check/linux-arm64/recipe-check +0 -0
  204. package/vendor/recipe-check/linux-x64/recipe-check +0 -0
  205. package/vendor/recipe-check/linux-x64-musl/recipe-check +0 -0
  206. package/vendor/recipe-check/win32-x64/recipe-check.exe +0 -0
  207. package/dist/agent-tool.d.ts.map +0 -1
  208. package/dist/agent-tool.js.map +0 -1
  209. package/dist/run.d.ts +0 -28
  210. package/dist/run.d.ts.map +0 -1
  211. package/dist/run.js +0 -84
  212. package/dist/run.js.map +0 -1
  213. package/dist/testing.d.ts +0 -25
  214. package/dist/testing.d.ts.map +0 -1
  215. package/dist/testing.js +0 -96
  216. package/dist/testing.js.map +0 -1
  217. package/docs/deployment-configuration.md +0 -65
  218. package/docs/migration.md +0 -70
  219. package/docs/python-bindings-release.md +0 -47
  220. package/docs/recipe-evals.md +0 -70
  221. package/docs/recipe-judges.md +0 -152
  222. package/docs/runtime-library.md +0 -171
@@ -0,0 +1,385 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ withFileLock
4
+ } from "./chunk-2XL7MG7R.js";
5
+ import {
6
+ listConfigLayerPaths
7
+ } from "./chunk-WQJZMCJN.js";
8
+ import {
9
+ expandHome,
10
+ mcporterDir
11
+ } from "./chunk-ECIVB7P4.js";
12
+
13
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/daemon/client.js
14
+ import crypto, { randomUUID } from "node:crypto";
15
+ import fs from "node:fs/promises";
16
+ import net from "node:net";
17
+ import path2 from "node:path";
18
+
19
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/daemon/paths.js
20
+ import path from "node:path";
21
+ function resolveBaseDir() {
22
+ const override = process.env.MCPORTER_DAEMON_DIR;
23
+ if (override && override.trim().length > 0) {
24
+ return path.resolve(expandHome(override.trim()));
25
+ }
26
+ return mcporterDir("state");
27
+ }
28
+ function ensureRunDir() {
29
+ return path.join(resolveBaseDir(), "daemon");
30
+ }
31
+ function getDaemonMetadataPath(configKey) {
32
+ return path.join(ensureRunDir(), `daemon-${configKey}.json`);
33
+ }
34
+ function getDaemonSocketPath(configKey) {
35
+ const runDir = ensureRunDir();
36
+ if (process.platform === "win32") {
37
+ return `\\\\.\\pipe\\mcporter-daemon-${configKey}`;
38
+ }
39
+ return path.join(runDir, `daemon-${configKey}.sock`);
40
+ }
41
+ function getDaemonLogPath(configKey) {
42
+ return path.join(ensureRunDir(), `daemon-${configKey}.log`);
43
+ }
44
+
45
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/daemon/client.js
46
+ var DEFAULT_DAEMON_TIMEOUT_MS = 3e4;
47
+ var MIN_DAEMON_STATUS_TIMEOUT_MS = 1e3;
48
+ function resolveDaemonPaths(configPath) {
49
+ const key = deriveConfigKey(configPath);
50
+ return {
51
+ key,
52
+ socketPath: getDaemonSocketPath(key),
53
+ metadataPath: getDaemonMetadataPath(key)
54
+ };
55
+ }
56
+ var DaemonClient = class {
57
+ options;
58
+ socketPath;
59
+ metadataPath;
60
+ startingPromise = null;
61
+ constructor(options) {
62
+ this.options = options;
63
+ const paths = resolveDaemonPaths(options.configPath);
64
+ this.socketPath = paths.socketPath;
65
+ this.metadataPath = paths.metadataPath;
66
+ }
67
+ async callTool(params) {
68
+ return this.invoke("callTool", params, params.timeoutMs);
69
+ }
70
+ async listTools(params) {
71
+ return this.invoke("listTools", params);
72
+ }
73
+ async listResources(params) {
74
+ return this.invoke("listResources", params);
75
+ }
76
+ async readResource(params) {
77
+ return this.invoke("readResource", params);
78
+ }
79
+ async closeServer(params) {
80
+ await this.invoke("closeServer", params);
81
+ }
82
+ async status() {
83
+ return await this.readVerifiedStatus();
84
+ }
85
+ async stop() {
86
+ try {
87
+ await this.sendRequest("stop", {});
88
+ } catch (error) {
89
+ if (isTransportError(error)) {
90
+ return;
91
+ }
92
+ throw error;
93
+ }
94
+ }
95
+ async invoke(method, params, timeoutMs) {
96
+ await this.ensureDaemon(timeoutMs);
97
+ try {
98
+ return await this.sendRequest(method, params, timeoutMs);
99
+ } catch (error) {
100
+ if (isTransportError(error)) {
101
+ await this.restartDaemon();
102
+ return await this.sendRequest(method, params, timeoutMs);
103
+ }
104
+ throw error;
105
+ }
106
+ }
107
+ async ensureDaemon(timeoutMs) {
108
+ const statusTimeoutMs = resolveDaemonStatusTimeout(timeoutMs);
109
+ const metadata = await readDaemonMetadata(this.metadataPath);
110
+ const configState = await this.checkConfigState(metadata);
111
+ if (configState === "stale") {
112
+ await this.restartDaemon({ reason: "stale-config", expectedPid: metadata?.pid });
113
+ return;
114
+ }
115
+ if (configState === "fresh") {
116
+ if (await this.isResponsive(statusTimeoutMs)) {
117
+ return;
118
+ }
119
+ }
120
+ await this.startDaemon({ preflightTimeoutMs: statusTimeoutMs });
121
+ }
122
+ async restartDaemon(options = {}) {
123
+ await this.startingWithLock(async () => {
124
+ const currentStatus = await this.readVerifiedStatus();
125
+ if (currentStatus && options.expectedPid !== void 0 && currentStatus.pid !== options.expectedPid && await this.checkConfigState() === "fresh") {
126
+ return;
127
+ }
128
+ if (options.reason === "stale-config" && currentStatus && await this.checkConfigState() === "fresh") {
129
+ return;
130
+ }
131
+ await this.stop().catch(() => {
132
+ });
133
+ await this.waitForStopped();
134
+ await this.launchDaemonAndWait();
135
+ });
136
+ }
137
+ async startDaemon(options = {}) {
138
+ await this.startingWithLock(async () => {
139
+ if (await this.isResponsive(options.preflightTimeoutMs)) {
140
+ return;
141
+ }
142
+ await this.launchDaemonAndWait();
143
+ });
144
+ }
145
+ async startingWithLock(task) {
146
+ if (this.startingPromise) {
147
+ await this.startingPromise;
148
+ return;
149
+ }
150
+ this.startingPromise = withFileLock(this.metadataPath, async () => {
151
+ await task();
152
+ }).finally(() => {
153
+ this.startingPromise = null;
154
+ });
155
+ await this.startingPromise;
156
+ }
157
+ async launchDaemonAndWait() {
158
+ const { launchDaemonDetached } = await import("./launch-YKRXHXJI.js");
159
+ launchDaemonDetached({
160
+ configPath: this.options.configPath,
161
+ configExplicit: this.options.configExplicit,
162
+ rootDir: this.options.rootDir,
163
+ metadataPath: this.metadataPath,
164
+ socketPath: this.socketPath
165
+ });
166
+ await this.waitForReady();
167
+ }
168
+ async waitForStopped() {
169
+ const deadline = Date.now() + 5e3;
170
+ while (Date.now() < deadline) {
171
+ if (!await this.isResponsive()) {
172
+ return;
173
+ }
174
+ await delay(100);
175
+ }
176
+ throw new Error("Daemon did not stop before restart could begin.");
177
+ }
178
+ async waitForReady() {
179
+ const deadline = Date.now() + 1e4;
180
+ while (Date.now() < deadline) {
181
+ if (await this.isResponsive()) {
182
+ return;
183
+ }
184
+ await delay(100);
185
+ }
186
+ throw new Error("Timeout while waiting for MCPorter daemon to start.");
187
+ }
188
+ async isResponsive(timeoutMs) {
189
+ return await this.readVerifiedStatus(timeoutMs) !== null;
190
+ }
191
+ async readVerifiedStatus(timeoutMs) {
192
+ const metadata = await readDaemonMetadata(this.metadataPath);
193
+ if (!metadata || metadata.socketPath !== this.socketPath || !isProcessRunning(metadata.pid)) {
194
+ return null;
195
+ }
196
+ try {
197
+ const status = await this.sendRequest("status", {}, timeoutMs);
198
+ if (status.pid !== metadata.pid || status.socketPath !== metadata.socketPath) {
199
+ return null;
200
+ }
201
+ return status;
202
+ } catch (error) {
203
+ if (isTransportError(error)) {
204
+ return null;
205
+ }
206
+ throw error;
207
+ }
208
+ }
209
+ async checkConfigState(metadata) {
210
+ metadata ??= await readDaemonMetadata(this.metadataPath);
211
+ if (!metadata) {
212
+ return "missing";
213
+ }
214
+ const currentLayers = normalizeLayers(await collectConfigLayers(this.options));
215
+ const metadataLayers = normalizeLayers(metadata.configLayers ?? [{ path: metadata.configPath, mtimeMs: metadata.configMtimeMs ?? null }]);
216
+ if (currentLayers.length !== metadataLayers.length) {
217
+ return "stale";
218
+ }
219
+ for (let i = 0; i < currentLayers.length; i += 1) {
220
+ const current = currentLayers[i];
221
+ const previous = metadataLayers[i];
222
+ if (!current || !previous || current.path !== previous.path || current.mtimeMs !== previous.mtimeMs) {
223
+ return "stale";
224
+ }
225
+ }
226
+ return "fresh";
227
+ }
228
+ async sendRequest(method, params, timeoutOverrideMs) {
229
+ const request = {
230
+ id: randomUUID(),
231
+ method,
232
+ params
233
+ };
234
+ const payload = JSON.stringify(request);
235
+ const timeoutMs = resolveDaemonTimeout(timeoutOverrideMs);
236
+ const response = await new Promise((resolve, reject) => {
237
+ const socket = net.createConnection(this.socketPath);
238
+ let settled = false;
239
+ const finishReject = (error) => {
240
+ if (settled) {
241
+ return;
242
+ }
243
+ settled = true;
244
+ reject(error);
245
+ };
246
+ const finishResolve = (value) => {
247
+ if (settled) {
248
+ return;
249
+ }
250
+ settled = true;
251
+ resolve(value);
252
+ };
253
+ socket.setTimeout(timeoutMs, () => {
254
+ socket.destroy(Object.assign(new Error("Daemon request timed out."), {
255
+ code: "ETIMEDOUT"
256
+ }));
257
+ });
258
+ let buffer = "";
259
+ socket.on("connect", () => {
260
+ socket.write(payload, (error) => {
261
+ if (error) {
262
+ finishReject(error);
263
+ }
264
+ });
265
+ });
266
+ socket.on("data", (chunk) => {
267
+ buffer += chunk.toString();
268
+ });
269
+ socket.on("end", () => finishResolve(buffer));
270
+ socket.on("error", (error) => {
271
+ finishReject(error);
272
+ });
273
+ });
274
+ const trimmed = response.trim();
275
+ if (!trimmed) {
276
+ const error = new Error("Empty daemon response.");
277
+ error.code = "ECONNRESET";
278
+ throw error;
279
+ }
280
+ let parsed;
281
+ try {
282
+ parsed = JSON.parse(trimmed);
283
+ } catch {
284
+ const parseError = new Error("Failed to parse daemon response.");
285
+ parseError.code = "ECONNRESET";
286
+ throw parseError;
287
+ }
288
+ if (!parsed.ok) {
289
+ const error = new Error(parsed.error?.message ?? "Daemon error");
290
+ error.code = parsed.error?.code;
291
+ throw error;
292
+ }
293
+ return parsed.result;
294
+ }
295
+ };
296
+ function deriveConfigKey(configPath) {
297
+ const absolute = path2.resolve(configPath);
298
+ return crypto.createHash("sha1").update(absolute).digest("hex").slice(0, 12);
299
+ }
300
+ function isTransportError(error) {
301
+ if (!error || typeof error !== "object") {
302
+ return false;
303
+ }
304
+ const code = error.code;
305
+ return code === "ECONNREFUSED" || code === "ENOENT" || code === "ETIMEDOUT" || code === "ECONNRESET";
306
+ }
307
+ function isProcessRunning(pid) {
308
+ if (!Number.isInteger(pid) || pid <= 0) {
309
+ return false;
310
+ }
311
+ try {
312
+ process.kill(pid, 0);
313
+ return true;
314
+ } catch (error) {
315
+ return error.code === "EPERM";
316
+ }
317
+ }
318
+ function resolveDaemonTimeout(override) {
319
+ if (typeof override === "number" && Number.isFinite(override) && override > 0) {
320
+ return override;
321
+ }
322
+ const raw = process.env.MCPORTER_DAEMON_TIMEOUT_MS;
323
+ if (!raw) {
324
+ return DEFAULT_DAEMON_TIMEOUT_MS;
325
+ }
326
+ const parsed = Number.parseInt(raw, 10);
327
+ if (!Number.isFinite(parsed) || parsed <= 0) {
328
+ return DEFAULT_DAEMON_TIMEOUT_MS;
329
+ }
330
+ return parsed;
331
+ }
332
+ function resolveDaemonStatusTimeout(override) {
333
+ if (typeof override !== "number" || !Number.isFinite(override) || override <= 0) {
334
+ return void 0;
335
+ }
336
+ return Math.max(override, MIN_DAEMON_STATUS_TIMEOUT_MS);
337
+ }
338
+ async function statConfigMtime(configPath) {
339
+ try {
340
+ const stats = await fs.stat(configPath);
341
+ return stats.mtimeMs;
342
+ } catch {
343
+ return null;
344
+ }
345
+ }
346
+ async function collectConfigLayers(options) {
347
+ const layerPaths = await listConfigLayerPaths(options.configExplicit ? { configPath: options.configPath } : {}, options.rootDir ?? process.cwd());
348
+ const layers = [];
349
+ for (const layerPath of layerPaths) {
350
+ layers.push({ path: layerPath, mtimeMs: await statConfigMtime(layerPath) });
351
+ }
352
+ if (layers.length === 0) {
353
+ layers.push({ path: path2.resolve(options.configPath), mtimeMs: await statConfigMtime(options.configPath) });
354
+ }
355
+ return layers;
356
+ }
357
+ async function readDaemonMetadata(metadataPath) {
358
+ try {
359
+ const raw = await fs.readFile(metadataPath, "utf8");
360
+ return JSON.parse(raw);
361
+ } catch {
362
+ return null;
363
+ }
364
+ }
365
+ function delay(ms) {
366
+ return new Promise((resolve) => {
367
+ setTimeout(resolve, ms);
368
+ });
369
+ }
370
+ function normalizeLayers(layers) {
371
+ const normalized = layers.map((entry) => ({
372
+ path: path2.isAbsolute(entry.path) ? entry.path : path2.resolve(entry.path),
373
+ mtimeMs: entry.mtimeMs ?? null
374
+ }));
375
+ if (normalized.length < 2) {
376
+ return normalized;
377
+ }
378
+ return normalized.toSorted((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
379
+ }
380
+
381
+ export {
382
+ getDaemonLogPath,
383
+ resolveDaemonPaths,
384
+ DaemonClient
385
+ };
@@ -0,0 +1,45 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+
3
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/json-output.js
4
+ function buildConnectionIssueEnvelope(params) {
5
+ return {
6
+ server: params.server,
7
+ tool: params.tool,
8
+ error: formatErrorMessage(params.error),
9
+ issue: serializeConnectionIssue(params.issue)
10
+ };
11
+ }
12
+ function serializeConnectionIssue(issue) {
13
+ if (!issue) {
14
+ return void 0;
15
+ }
16
+ return {
17
+ kind: issue.kind,
18
+ statusCode: issue.statusCode,
19
+ stdioExitCode: issue.stdioExitCode,
20
+ stdioSignal: issue.stdioSignal,
21
+ rawMessage: issue.rawMessage
22
+ };
23
+ }
24
+ function formatErrorMessage(error) {
25
+ if (error instanceof Error) {
26
+ return error.message ?? "Unknown error";
27
+ }
28
+ if (typeof error === "string") {
29
+ return error;
30
+ }
31
+ if (error === void 0 || error === null) {
32
+ return "Unknown error";
33
+ }
34
+ try {
35
+ return JSON.stringify(error);
36
+ } catch {
37
+ return "Unknown error";
38
+ }
39
+ }
40
+
41
+ export {
42
+ buildConnectionIssueEnvelope,
43
+ serializeConnectionIssue,
44
+ formatErrorMessage
45
+ };
@@ -0,0 +1,194 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ readJsonFile,
4
+ withFileLock,
5
+ writeJsonFile
6
+ } from "./chunk-2XL7MG7R.js";
7
+ import {
8
+ mcporterDir
9
+ } from "./chunk-ECIVB7P4.js";
10
+
11
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/oauth-vault.js
12
+ import crypto from "node:crypto";
13
+ import path from "node:path";
14
+ function getOAuthVaultPath() {
15
+ return path.join(mcporterDir("data"), "credentials.json");
16
+ }
17
+ async function readVaultState() {
18
+ try {
19
+ const existing = await readJsonFile(getOAuthVaultPath());
20
+ if (existing && existing.version === 1 && existing.entries && typeof existing.entries === "object") {
21
+ return { vault: existing, needsRepair: false };
22
+ }
23
+ if (existing !== void 0) {
24
+ return { vault: emptyVault(), needsRepair: true };
25
+ }
26
+ } catch (error) {
27
+ if (!(error instanceof SyntaxError)) {
28
+ throw error;
29
+ }
30
+ return { vault: emptyVault(), needsRepair: true };
31
+ }
32
+ return { vault: emptyVault(), needsRepair: false };
33
+ }
34
+ async function readVault() {
35
+ return (await readVaultState()).vault;
36
+ }
37
+ function emptyVault() {
38
+ return { version: 1, entries: {} };
39
+ }
40
+ async function writeVault(contents) {
41
+ await writeJsonFile(getOAuthVaultPath(), contents);
42
+ }
43
+ function vaultKeyForDefinition(definition) {
44
+ const descriptor = {
45
+ name: definition.name,
46
+ url: definition.command.kind === "http" ? definition.command.url.toString() : null,
47
+ command: definition.command.kind === "stdio" ? { command: definition.command.command, args: definition.command.args ?? [] } : null
48
+ };
49
+ const hash = crypto.createHash("sha256").update(JSON.stringify(descriptor)).digest("hex").slice(0, 16);
50
+ return `${definition.name}|${hash}`;
51
+ }
52
+ async function loadVaultEntry(definition) {
53
+ const vault = await readVault();
54
+ const key = vaultKeyForDefinition(definition);
55
+ const exact = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
56
+ const fallback = findSameUrlCredentials(vault, definition, key, exact);
57
+ if (!fallback.tokens && !fallback.clientInfo) {
58
+ return exact;
59
+ }
60
+ if (!exact) {
61
+ return {
62
+ serverName: definition.name,
63
+ serverUrl: definition.command.kind === "http" ? definition.command.url.toString() : void 0,
64
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
65
+ tokens: fallback.tokens,
66
+ clientInfo: fallback.clientInfo
67
+ };
68
+ }
69
+ return {
70
+ ...exact,
71
+ tokens: exact.tokens ?? fallback.tokens,
72
+ clientInfo: exact.clientInfo ?? (exact.tokens ? void 0 : fallback.clientInfo)
73
+ };
74
+ }
75
+ function findSameUrlCredentials(vault, definition, exactKey, exact) {
76
+ if (definition.command.kind !== "http") {
77
+ return { sourceKeys: [] };
78
+ }
79
+ const serverUrl = definition.command.url.toString();
80
+ const candidates = Object.entries(vault.entries).filter(([key, entry]) => key !== exactKey && isVaultEntry(entry) && entry.serverUrl === serverUrl && isLegacyOAuthRenameCandidate(definition, entry) && (entry.tokens || entry.clientInfo)).map(([key, entry]) => ({ key, entry })).toSorted((a, b) => Date.parse(b.entry.updatedAt) - Date.parse(a.entry.updatedAt));
81
+ const requiredClientId = definition.oauthClientId ?? clientIdFromEntry(exact);
82
+ if (requiredClientId) {
83
+ const tokenSource = candidates.find(({ entry }) => (entry.tokens || entry.clientInfo) && clientIdFromEntry(entry) === requiredClientId);
84
+ return {
85
+ tokens: tokenSource?.entry.tokens,
86
+ clientInfo: exact?.clientInfo ? void 0 : tokenSource?.entry.clientInfo,
87
+ sourceKeys: tokenSource ? [tokenSource.key] : []
88
+ };
89
+ }
90
+ const source = candidates.find(({ entry }) => entry.clientInfo && clientIdFromEntry(entry));
91
+ return {
92
+ tokens: source?.entry.tokens,
93
+ clientInfo: source?.entry.clientInfo,
94
+ sourceKeys: source ? [source.key] : []
95
+ };
96
+ }
97
+ function isLegacyOAuthRenameCandidate(definition, entry) {
98
+ return entry.serverName === `${definition.name}-oauth`;
99
+ }
100
+ function legacyOAuthRenameKeys(vault, definition, exactKey) {
101
+ if (definition.command.kind !== "http") {
102
+ return [];
103
+ }
104
+ const serverUrl = definition.command.url.toString();
105
+ return Object.entries(vault.entries).filter(([key, entry]) => key !== exactKey && isVaultEntry(entry) && entry.serverUrl === serverUrl && isLegacyOAuthRenameCandidate(definition, entry)).map(([key]) => key);
106
+ }
107
+ function isVaultEntry(entry) {
108
+ return Boolean(entry && typeof entry === "object" && typeof entry.serverName === "string" && typeof entry.updatedAt === "string");
109
+ }
110
+ function clientIdFromEntry(entry) {
111
+ const clientId = entry?.clientInfo?.client_id;
112
+ return typeof clientId === "string" && clientId.length > 0 ? clientId : void 0;
113
+ }
114
+ async function saveVaultEntry(definition, patch) {
115
+ await withFileLock(getOAuthVaultPath(), async () => {
116
+ const vault = await readVault();
117
+ const key = vaultKeyForDefinition(definition);
118
+ const existing = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
119
+ const fallback = findSameUrlCredentials(vault, definition, key, existing);
120
+ const current = existing ?? {
121
+ serverName: definition.name,
122
+ serverUrl: definition.command.kind === "http" ? definition.command.url.toString() : void 0,
123
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
124
+ };
125
+ vault.entries[key] = {
126
+ ...current,
127
+ ...patch,
128
+ clientInfo: patch.clientInfo ?? current.clientInfo ?? (patch.tokens && !current.tokens ? fallback.clientInfo : void 0),
129
+ updatedAt: (/* @__PURE__ */ new Date()).toISOString()
130
+ };
131
+ await writeVault(vault);
132
+ });
133
+ }
134
+ async function clearVaultEntry(definition, scope) {
135
+ const key = vaultKeyForDefinition(definition);
136
+ await withFileLock(getOAuthVaultPath(), async () => {
137
+ const { vault, needsRepair } = await readVaultState();
138
+ const existing = isVaultEntry(vault.entries[key]) ? vault.entries[key] : void 0;
139
+ const fallback = findSameUrlCredentials(vault, definition, key, existing);
140
+ const inheritedKeys = scope === "all" ? legacyOAuthRenameKeys(vault, definition, key) : fallback.sourceKeys;
141
+ if (!existing && inheritedKeys.length === 0) {
142
+ if (needsRepair) {
143
+ await writeVault(vault);
144
+ }
145
+ return;
146
+ }
147
+ if (scope === "all") {
148
+ delete vault.entries[key];
149
+ } else if (existing) {
150
+ const updated = { ...existing };
151
+ if (scope === "tokens") {
152
+ delete updated.tokens;
153
+ }
154
+ if (scope === "client") {
155
+ delete updated.clientInfo;
156
+ }
157
+ if (scope === "verifier") {
158
+ delete updated.codeVerifier;
159
+ }
160
+ if (scope === "state") {
161
+ delete updated.state;
162
+ }
163
+ updated.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
164
+ vault.entries[key] = updated;
165
+ }
166
+ for (const fallbackKey of inheritedKeys) {
167
+ const inherited = vault.entries[fallbackKey];
168
+ if (!inherited) {
169
+ continue;
170
+ }
171
+ if (scope === "all") {
172
+ delete vault.entries[fallbackKey];
173
+ continue;
174
+ }
175
+ const updated = { ...inherited };
176
+ if (scope === "tokens") {
177
+ delete updated.tokens;
178
+ }
179
+ if (scope === "client") {
180
+ delete updated.clientInfo;
181
+ }
182
+ updated.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
183
+ vault.entries[fallbackKey] = updated;
184
+ }
185
+ await writeVault(vault);
186
+ });
187
+ }
188
+
189
+ export {
190
+ getOAuthVaultPath,
191
+ loadVaultEntry,
192
+ saveVaultEntry,
193
+ clearVaultEntry
194
+ };
@@ -0,0 +1,29 @@
1
+ import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
+ import {
3
+ normalizeHttpUrl
4
+ } from "./chunk-M3TPODXI.js";
5
+
6
+ // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/cli/server-lookup.js
7
+ function findServerByHttpUrl(definitions, urlString) {
8
+ const normalizedTarget = normalizeHttpUrl(urlString);
9
+ if (!normalizedTarget) {
10
+ return void 0;
11
+ }
12
+ for (const definition of definitions) {
13
+ if (definition.command.kind !== "http") {
14
+ continue;
15
+ }
16
+ const normalizedDefinitionUrl = normalizeHttpUrl(definition.command.url);
17
+ if (!normalizedDefinitionUrl) {
18
+ continue;
19
+ }
20
+ if (normalizedDefinitionUrl === normalizedTarget) {
21
+ return definition.name;
22
+ }
23
+ }
24
+ return void 0;
25
+ }
26
+
27
+ export {
28
+ findServerByHttpUrl
29
+ };