@introspection-ai/recipes 0.18.0 → 0.19.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 (146) hide show
  1. package/dist/inspect.d.ts +1 -0
  2. package/dist/inspect.d.ts.map +1 -1
  3. package/dist/inspect.js +3 -0
  4. package/dist/inspect.js.map +1 -1
  5. package/dist/mcp-chunks/{auth-command-ZLGYIEUY.js → auth-command-3K7V3VCW.js} +31 -35
  6. package/dist/mcp-chunks/call-arguments-TX3F2TEE.js +15 -0
  7. package/dist/mcp-chunks/{call-command-LKTKSYTH.js → call-command-OFPHPFM5.js} +36 -34
  8. package/dist/mcp-chunks/chunk-2FSDGCHW.js +3299 -0
  9. package/dist/mcp-chunks/{chunk-BV56DXPW.js → chunk-2JHHONW4.js} +1 -1
  10. package/dist/mcp-chunks/chunk-2MEHGB7D.js +63 -0
  11. package/dist/mcp-chunks/chunk-3IZQW4H4.js +929 -0
  12. package/dist/mcp-chunks/{chunk-MZ2NARG7.js → chunk-54EWGONA.js} +5 -5
  13. package/dist/mcp-chunks/{chunk-LQQEYD76.js → chunk-55JIHDU3.js} +1 -1
  14. package/dist/mcp-chunks/chunk-64EP2BVO.js +39 -0
  15. package/dist/mcp-chunks/{chunk-LS7PMWSR.js → chunk-6D6KPSXN.js} +1 -1
  16. package/dist/mcp-chunks/{chunk-2XL7MG7R.js → chunk-7A63PAGP.js} +15 -9
  17. package/dist/mcp-chunks/chunk-7DH57OKF.js +28 -0
  18. package/dist/mcp-chunks/{chunk-BTLAWHTA.js → chunk-7RDLPFIO.js} +2 -2
  19. package/dist/mcp-chunks/chunk-C2PQFLWS.js +422 -0
  20. package/dist/mcp-chunks/chunk-CA5WFJZA.js +197 -0
  21. package/dist/mcp-chunks/{chunk-LNH5LAJD.js → chunk-CNDY7WB4.js} +2 -2
  22. package/dist/mcp-chunks/{chunk-UKYNQGNE.js → chunk-DEUU7WSN.js} +34 -8
  23. package/dist/mcp-chunks/{chunk-LKIBAYKU.js → chunk-DXPHJFSA.js} +25 -35
  24. package/dist/mcp-chunks/{chunk-J6LYIZXN.js → chunk-E6RVTWJY.js} +1 -1
  25. package/dist/mcp-chunks/{chunk-7FHEBT5G.js → chunk-E6T37ED6.js} +18 -13
  26. package/dist/mcp-chunks/chunk-ETWN4IIA.js +57 -0
  27. package/dist/mcp-chunks/{chunk-YVZKMV5H.js → chunk-F3LL4EBL.js} +1 -1
  28. package/dist/mcp-chunks/chunk-FWP4RACK.js +42 -0
  29. package/dist/mcp-chunks/{chunk-6W5QFASN.js → chunk-GFYTST6N.js} +1 -1
  30. package/dist/mcp-chunks/{chunk-TEUKFFQL.js → chunk-GIF7LOYU.js} +2 -2
  31. package/dist/mcp-chunks/{chunk-QXJUA3ND.js → chunk-GSZOK5TS.js} +828 -7
  32. package/dist/mcp-chunks/chunk-H7F5RZXS.js +26 -0
  33. package/dist/mcp-chunks/{chunk-ECIVB7P4.js → chunk-HAO6PL7Z.js} +2 -37
  34. package/dist/mcp-chunks/{chunk-WQJZMCJN.js → chunk-HTZ2URXW.js} +5 -3
  35. package/dist/mcp-chunks/{chunk-BWHIA4PC.js → chunk-JAKI24KR.js} +1 -1
  36. package/dist/mcp-chunks/{chunk-PWYFKGKG.js → chunk-KSGYBW3F.js} +180 -89
  37. package/dist/mcp-chunks/{chunk-SJCCBNZ4.js → chunk-KSMY7PXI.js} +1 -1
  38. package/dist/mcp-chunks/{chunk-2U4BSDC4.js → chunk-L4VKBFYI.js} +48 -29
  39. package/dist/mcp-chunks/{chunk-LEZSACDE.js → chunk-LICH4Q7A.js} +4 -4
  40. package/dist/mcp-chunks/{chunk-PIIYJR44.js → chunk-LNSUME65.js} +29 -33
  41. package/dist/mcp-chunks/{chunk-D3MRAZ6H.js → chunk-LWVFSQYX.js} +13974 -15562
  42. package/dist/mcp-chunks/{chunk-7KA2VJVZ.js → chunk-NCXEJ35U.js} +10 -5
  43. package/dist/mcp-chunks/{chunk-5QOSCSQB.js → chunk-NZOIX6XW.js} +2 -2
  44. package/dist/mcp-chunks/{chunk-XANPGTLI.js → chunk-P3RN22HQ.js} +11 -4
  45. package/dist/mcp-chunks/{chunk-IABRYROW.js → chunk-PKOJCYNA.js} +3 -3
  46. package/dist/mcp-chunks/{chunk-BNV3TPE4.js → chunk-QJACOI2W.js} +5 -13
  47. package/dist/mcp-chunks/{chunk-UNKB4SBV.js → chunk-RBVYCKCD.js} +2 -2
  48. package/dist/mcp-chunks/{chunk-DHBE7UBH.js → chunk-SB2UUURE.js} +12 -42
  49. package/dist/mcp-chunks/{chunk-4SQKWYFF.js → chunk-SFREPU3D.js} +1 -1
  50. package/dist/mcp-chunks/{chunk-BZIQOWE6.js → chunk-SRZZQ6TL.js} +35 -36
  51. package/dist/mcp-chunks/{chunk-M3TPODXI.js → chunk-UENXT3NE.js} +1 -1
  52. package/dist/mcp-chunks/chunk-UHOKCTZT.js +37 -0
  53. package/dist/mcp-chunks/{chunk-E22DYOW5.js → chunk-WWO5WGH5.js} +5 -5
  54. package/dist/mcp-chunks/{chunk-6XCZGU3G.js → chunk-WXBPMFSN.js} +149 -192
  55. package/dist/mcp-chunks/{chunk-XQK2JSW4.js → chunk-XRGLP3Z2.js} +14 -2
  56. package/dist/mcp-chunks/{chunk-L7NTQVYN.js → chunk-XTL4MHFH.js} +28 -10
  57. package/dist/mcp-chunks/{chunk-N46NEFAF.js → chunk-XUF6KARU.js} +1 -1
  58. package/dist/mcp-chunks/{chunk-WD6BOD24.js → chunk-YCYSQA5V.js} +23 -4
  59. package/dist/mcp-chunks/chunk-YPJ5EHXR.js +17394 -0
  60. package/dist/mcp-chunks/{chunk-NRAJX5E4.js → chunk-YSPT6F7K.js} +3 -3
  61. package/dist/mcp-chunks/{chunk-7UDVSOOF.js → chunk-YTKRAHO6.js} +54 -46
  62. package/dist/mcp-chunks/chunk-ZBFZ5UFE.js +67 -0
  63. package/dist/mcp-chunks/{cli-UV4QJZZM.js → cli-E4P6SZLQ.js} +89 -76
  64. package/dist/mcp-chunks/client-2EJC4PLL.js +18 -0
  65. package/dist/mcp-chunks/{config-command-NLAGKID5.js → config-command-MWF3RHPQ.js} +38 -59
  66. package/dist/mcp-chunks/daemon-command-6CJ26MKI.js +33 -0
  67. package/dist/mcp-chunks/{dist-LK3SHAMX.js → dist-ZIPUENTM.js} +527 -469
  68. package/dist/mcp-chunks/{emit-ts-command-VBXVXO6V.js → emit-ts-command-GOVJJ64A.js} +16 -13
  69. package/dist/mcp-chunks/{generate-cli-runner-6CAZZA3P.js → generate-cli-runner-L5OQIMEY.js} +242 -247
  70. package/dist/mcp-chunks/{inspect-cli-command-3ZORTOR7.js → inspect-cli-command-7OMMREPE.js} +10 -9
  71. package/dist/mcp-chunks/{launch-YKRXHXJI.js → launch-BWXPLPB7.js} +1 -1
  72. package/dist/mcp-chunks/{lifecycle-XVKRHPH3.js → lifecycle-B5UC65PT.js} +1 -1
  73. package/dist/mcp-chunks/{list-command-2MEGGNFQ.js → list-command-ZO4HVFQK.js} +74 -43
  74. package/dist/mcp-chunks/{output-utils-NKESLAJ6.js → output-utils-M3TJ2N4M.js} +3 -3
  75. package/dist/mcp-chunks/{prompt-B1Yc1NPt-VGOTWJMN.js → prompt-CH6TK0bC-C7OTKGRD.js} +1 -3
  76. package/dist/mcp-chunks/{record-command-YXHTTTT5.js → record-command-VD3HUQIC.js} +5 -4
  77. package/dist/mcp-chunks/replay-command-AX6IN7YD.js +42 -0
  78. package/dist/mcp-chunks/{resource-command-OO4NYF5C.js → resource-command-JEZ2DW2G.js} +10 -10
  79. package/dist/mcp-chunks/{result-utils-MOHHLNM7.js → result-utils-3YHYGS45.js} +4 -4
  80. package/dist/mcp-chunks/runtime-HSYVOME7.js +37 -0
  81. package/dist/mcp-chunks/{runtime-wrapper-RPWDIDBF.js → runtime-wrapper-UREU7GC3.js} +7 -3
  82. package/dist/mcp-chunks/serve-command-M47YZ6JN.js +16018 -0
  83. package/dist/mcp-chunks/{timeouts-W2XWCCXR.js → timeouts-THZRYP4B.js} +3 -1
  84. package/dist/mcp-chunks/{vault-command-PIYIUEZL.js → vault-command-53P7MLCB.js} +7 -6
  85. package/dist/mcp-chunks/webapi-PHEQZQKH.js +3316 -0
  86. package/dist/mcp-client.js +11 -1
  87. package/dist/mcp-client.js.map +1 -1
  88. package/dist/mcp-daemon-client.d.ts.map +1 -1
  89. package/dist/mcp-daemon-client.js +3 -0
  90. package/dist/mcp-daemon-client.js.map +1 -1
  91. package/dist/mcp-daemon-protocol.d.ts +6 -0
  92. package/dist/mcp-daemon-protocol.d.ts.map +1 -1
  93. package/dist/mcp-daemon-protocol.js.map +1 -1
  94. package/dist/mcp-daemon.js +43 -22
  95. package/dist/mcp-daemon.js.map +1 -1
  96. package/dist/mcp-run-worker.js +29 -22
  97. package/dist/mcp-trace-context.d.ts +6 -0
  98. package/dist/mcp-trace-context.d.ts.map +1 -0
  99. package/dist/mcp-trace-context.js +31 -0
  100. package/dist/mcp-trace-context.js.map +1 -0
  101. package/dist/model-binding.d.ts.map +1 -1
  102. package/dist/model-binding.js +8 -4
  103. package/dist/model-binding.js.map +1 -1
  104. package/dist/pi-extension.d.ts.map +1 -1
  105. package/dist/pi-extension.js +12 -0
  106. package/dist/pi-extension.js.map +1 -1
  107. package/dist/recipe/resolve.d.ts +2 -0
  108. package/dist/recipe/resolve.d.ts.map +1 -1
  109. package/dist/recipe/resolve.js +2 -1
  110. package/dist/recipe/resolve.js.map +1 -1
  111. package/dist/recipe-agent.d.ts +5 -2
  112. package/dist/recipe-agent.d.ts.map +1 -1
  113. package/dist/recipe-agent.js +20 -4
  114. package/dist/recipe-agent.js.map +1 -1
  115. package/dist/recipe-model.d.ts +7 -1
  116. package/dist/recipe-model.d.ts.map +1 -1
  117. package/dist/recipe-model.js +89 -20
  118. package/dist/recipe-model.js.map +1 -1
  119. package/dist/recipe-session.d.ts +14 -0
  120. package/dist/recipe-session.d.ts.map +1 -0
  121. package/dist/recipe-session.js +181 -0
  122. package/dist/recipe-session.js.map +1 -0
  123. package/dist/session.d.ts.map +1 -1
  124. package/dist/session.js +23 -1
  125. package/dist/session.js.map +1 -1
  126. package/docs/agent-composition.md +46 -22
  127. package/docs/pi-extension.md +9 -3
  128. package/docs/recipe-format.md +41 -5
  129. package/package.json +7 -7
  130. package/vendor/introspection-recipe-check/darwin-arm64/introspection-recipe-check +0 -0
  131. package/vendor/introspection-recipe-check/darwin-x64/introspection-recipe-check +0 -0
  132. package/vendor/introspection-recipe-check/linux-arm64/introspection-recipe-check +0 -0
  133. package/vendor/introspection-recipe-check/linux-x64/introspection-recipe-check +0 -0
  134. package/vendor/introspection-recipe-check/linux-x64-musl/introspection-recipe-check +0 -0
  135. package/vendor/introspection-recipe-check/win32-x64/introspection-recipe-check.exe +0 -0
  136. package/dist/mcp-chunks/call-arguments-LU3W6D3K.js +0 -13
  137. package/dist/mcp-chunks/chunk-HKRJ6O36.js +0 -1076
  138. package/dist/mcp-chunks/chunk-NNOEGEUZ.js +0 -17273
  139. package/dist/mcp-chunks/chunk-P3PSC54P.js +0 -869
  140. package/dist/mcp-chunks/chunk-TATVT5IT.js +0 -194
  141. package/dist/mcp-chunks/chunk-YHQUTU6L.js +0 -571
  142. package/dist/mcp-chunks/client-S7RQUG5U.js +0 -13
  143. package/dist/mcp-chunks/daemon-command-U242Z6VY.js +0 -26
  144. package/dist/mcp-chunks/replay-command-25HJ6AQU.js +0 -85
  145. package/dist/mcp-chunks/runtime-5WJ3G25Y.js +0 -33
  146. package/dist/mcp-chunks/serve-command-DHXJZMMN.js +0 -3302
@@ -1,1076 +0,0 @@
1
- import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
2
- import {
3
- JSONRPCMessageSchema
4
- } from "./chunk-D3MRAZ6H.js";
5
- import {
6
- __commonJS,
7
- __require,
8
- __toESM
9
- } from "./chunk-LRKZP7DJ.js";
10
-
11
- // node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js
12
- var require_windows = __commonJS({
13
- "node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module) {
14
- module.exports = isexe;
15
- isexe.sync = sync;
16
- var fs = __require("fs");
17
- function checkPathExt(path, options) {
18
- var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
19
- if (!pathext) {
20
- return true;
21
- }
22
- pathext = pathext.split(";");
23
- if (pathext.indexOf("") !== -1) {
24
- return true;
25
- }
26
- for (var i = 0; i < pathext.length; i++) {
27
- var p = pathext[i].toLowerCase();
28
- if (p && path.substr(-p.length).toLowerCase() === p) {
29
- return true;
30
- }
31
- }
32
- return false;
33
- }
34
- function checkStat(stat, path, options) {
35
- if (!stat.isSymbolicLink() && !stat.isFile()) {
36
- return false;
37
- }
38
- return checkPathExt(path, options);
39
- }
40
- function isexe(path, options, cb) {
41
- fs.stat(path, function(er, stat) {
42
- cb(er, er ? false : checkStat(stat, path, options));
43
- });
44
- }
45
- function sync(path, options) {
46
- return checkStat(fs.statSync(path), path, options);
47
- }
48
- }
49
- });
50
-
51
- // node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js
52
- var require_mode = __commonJS({
53
- "node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module) {
54
- module.exports = isexe;
55
- isexe.sync = sync;
56
- var fs = __require("fs");
57
- function isexe(path, options, cb) {
58
- fs.stat(path, function(er, stat) {
59
- cb(er, er ? false : checkStat(stat, options));
60
- });
61
- }
62
- function sync(path, options) {
63
- return checkStat(fs.statSync(path), options);
64
- }
65
- function checkStat(stat, options) {
66
- return stat.isFile() && checkMode(stat, options);
67
- }
68
- function checkMode(stat, options) {
69
- var mod = stat.mode;
70
- var uid = stat.uid;
71
- var gid = stat.gid;
72
- var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
73
- var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
74
- var u = parseInt("100", 8);
75
- var g = parseInt("010", 8);
76
- var o = parseInt("001", 8);
77
- var ug = u | g;
78
- var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
79
- return ret;
80
- }
81
- }
82
- });
83
-
84
- // node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js
85
- var require_isexe = __commonJS({
86
- "node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module) {
87
- var fs = __require("fs");
88
- var core;
89
- if (process.platform === "win32" || global.TESTING_WINDOWS) {
90
- core = require_windows();
91
- } else {
92
- core = require_mode();
93
- }
94
- module.exports = isexe;
95
- isexe.sync = sync;
96
- function isexe(path, options, cb) {
97
- if (typeof options === "function") {
98
- cb = options;
99
- options = {};
100
- }
101
- if (!cb) {
102
- if (typeof Promise !== "function") {
103
- throw new TypeError("callback not provided");
104
- }
105
- return new Promise(function(resolve, reject) {
106
- isexe(path, options || {}, function(er, is) {
107
- if (er) {
108
- reject(er);
109
- } else {
110
- resolve(is);
111
- }
112
- });
113
- });
114
- }
115
- core(path, options || {}, function(er, is) {
116
- if (er) {
117
- if (er.code === "EACCES" || options && options.ignoreErrors) {
118
- er = null;
119
- is = false;
120
- }
121
- }
122
- cb(er, is);
123
- });
124
- }
125
- function sync(path, options) {
126
- try {
127
- return core.sync(path, options || {});
128
- } catch (er) {
129
- if (options && options.ignoreErrors || er.code === "EACCES") {
130
- return false;
131
- } else {
132
- throw er;
133
- }
134
- }
135
- }
136
- }
137
- });
138
-
139
- // node_modules/.pnpm/which@2.0.2/node_modules/which/which.js
140
- var require_which = __commonJS({
141
- "node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module) {
142
- var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
143
- var path = __require("path");
144
- var COLON = isWindows ? ";" : ":";
145
- var isexe = require_isexe();
146
- var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
147
- var getPathInfo = (cmd, opt) => {
148
- const colon = opt.colon || COLON;
149
- const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
150
- // windows always checks the cwd first
151
- ...isWindows ? [process.cwd()] : [],
152
- ...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
153
- "").split(colon)
154
- ];
155
- const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
156
- const pathExt = isWindows ? pathExtExe.split(colon) : [""];
157
- if (isWindows) {
158
- if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
159
- pathExt.unshift("");
160
- }
161
- return {
162
- pathEnv,
163
- pathExt,
164
- pathExtExe
165
- };
166
- };
167
- var which = (cmd, opt, cb) => {
168
- if (typeof opt === "function") {
169
- cb = opt;
170
- opt = {};
171
- }
172
- if (!opt)
173
- opt = {};
174
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
175
- const found = [];
176
- const step = (i) => new Promise((resolve, reject) => {
177
- if (i === pathEnv.length)
178
- return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
179
- const ppRaw = pathEnv[i];
180
- const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
181
- const pCmd = path.join(pathPart, cmd);
182
- const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
183
- resolve(subStep(p, i, 0));
184
- });
185
- const subStep = (p, i, ii) => new Promise((resolve, reject) => {
186
- if (ii === pathExt.length)
187
- return resolve(step(i + 1));
188
- const ext = pathExt[ii];
189
- isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
190
- if (!er && is) {
191
- if (opt.all)
192
- found.push(p + ext);
193
- else
194
- return resolve(p + ext);
195
- }
196
- return resolve(subStep(p, i, ii + 1));
197
- });
198
- });
199
- return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
200
- };
201
- var whichSync = (cmd, opt) => {
202
- opt = opt || {};
203
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
204
- const found = [];
205
- for (let i = 0; i < pathEnv.length; i++) {
206
- const ppRaw = pathEnv[i];
207
- const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
208
- const pCmd = path.join(pathPart, cmd);
209
- const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
210
- for (let j = 0; j < pathExt.length; j++) {
211
- const cur = p + pathExt[j];
212
- try {
213
- const is = isexe.sync(cur, { pathExt: pathExtExe });
214
- if (is) {
215
- if (opt.all)
216
- found.push(cur);
217
- else
218
- return cur;
219
- }
220
- } catch (ex) {
221
- }
222
- }
223
- }
224
- if (opt.all && found.length)
225
- return found;
226
- if (opt.nothrow)
227
- return null;
228
- throw getNotFoundError(cmd);
229
- };
230
- module.exports = which;
231
- which.sync = whichSync;
232
- }
233
- });
234
-
235
- // node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js
236
- var require_path_key = __commonJS({
237
- "node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports, module) {
238
- "use strict";
239
- var pathKey = (options = {}) => {
240
- const environment = options.env || process.env;
241
- const platform = options.platform || process.platform;
242
- if (platform !== "win32") {
243
- return "PATH";
244
- }
245
- return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
246
- };
247
- module.exports = pathKey;
248
- module.exports.default = pathKey;
249
- }
250
- });
251
-
252
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js
253
- var require_resolveCommand = __commonJS({
254
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module) {
255
- "use strict";
256
- var path = __require("path");
257
- var which = require_which();
258
- var getPathKey = require_path_key();
259
- function resolveCommandAttempt(parsed, withoutPathExt) {
260
- const env = parsed.options.env || process.env;
261
- const cwd = process.cwd();
262
- const hasCustomCwd = parsed.options.cwd != null;
263
- const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
264
- if (shouldSwitchCwd) {
265
- try {
266
- process.chdir(parsed.options.cwd);
267
- } catch (err) {
268
- }
269
- }
270
- let resolved;
271
- try {
272
- resolved = which.sync(parsed.command, {
273
- path: env[getPathKey({ env })],
274
- pathExt: withoutPathExt ? path.delimiter : void 0
275
- });
276
- } catch (e) {
277
- } finally {
278
- if (shouldSwitchCwd) {
279
- process.chdir(cwd);
280
- }
281
- }
282
- if (resolved) {
283
- resolved = path.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
284
- }
285
- return resolved;
286
- }
287
- function resolveCommand(parsed) {
288
- return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
289
- }
290
- module.exports = resolveCommand;
291
- }
292
- });
293
-
294
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js
295
- var require_escape = __commonJS({
296
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module) {
297
- "use strict";
298
- var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
299
- function escapeCommand(arg) {
300
- arg = arg.replace(metaCharsRegExp, "^$1");
301
- return arg;
302
- }
303
- function escapeArgument(arg, doubleEscapeMetaChars) {
304
- arg = `${arg}`;
305
- arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
306
- arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
307
- arg = `"${arg}"`;
308
- arg = arg.replace(metaCharsRegExp, "^$1");
309
- if (doubleEscapeMetaChars) {
310
- arg = arg.replace(metaCharsRegExp, "^$1");
311
- }
312
- return arg;
313
- }
314
- module.exports.command = escapeCommand;
315
- module.exports.argument = escapeArgument;
316
- }
317
- });
318
-
319
- // node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js
320
- var require_shebang_regex = __commonJS({
321
- "node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports, module) {
322
- "use strict";
323
- module.exports = /^#!(.*)/;
324
- }
325
- });
326
-
327
- // node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js
328
- var require_shebang_command = __commonJS({
329
- "node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports, module) {
330
- "use strict";
331
- var shebangRegex = require_shebang_regex();
332
- module.exports = (string = "") => {
333
- const match = string.match(shebangRegex);
334
- if (!match) {
335
- return null;
336
- }
337
- const [path, argument] = match[0].replace(/#! ?/, "").split(" ");
338
- const binary = path.split("/").pop();
339
- if (binary === "env") {
340
- return argument;
341
- }
342
- return argument ? `${binary} ${argument}` : binary;
343
- };
344
- }
345
- });
346
-
347
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js
348
- var require_readShebang = __commonJS({
349
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module) {
350
- "use strict";
351
- var fs = __require("fs");
352
- var shebangCommand = require_shebang_command();
353
- function readShebang(command) {
354
- const size = 150;
355
- const buffer = Buffer.alloc(size);
356
- let fd;
357
- try {
358
- fd = fs.openSync(command, "r");
359
- fs.readSync(fd, buffer, 0, size, 0);
360
- fs.closeSync(fd);
361
- } catch (e) {
362
- }
363
- return shebangCommand(buffer.toString());
364
- }
365
- module.exports = readShebang;
366
- }
367
- });
368
-
369
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js
370
- var require_parse = __commonJS({
371
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module) {
372
- "use strict";
373
- var path = __require("path");
374
- var resolveCommand = require_resolveCommand();
375
- var escape = require_escape();
376
- var readShebang = require_readShebang();
377
- var isWin = process.platform === "win32";
378
- var isExecutableRegExp = /\.(?:com|exe)$/i;
379
- var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
380
- function detectShebang(parsed) {
381
- parsed.file = resolveCommand(parsed);
382
- const shebang = parsed.file && readShebang(parsed.file);
383
- if (shebang) {
384
- parsed.args.unshift(parsed.file);
385
- parsed.command = shebang;
386
- return resolveCommand(parsed);
387
- }
388
- return parsed.file;
389
- }
390
- function parseNonShell(parsed) {
391
- if (!isWin) {
392
- return parsed;
393
- }
394
- const commandFile = detectShebang(parsed);
395
- const needsShell = !isExecutableRegExp.test(commandFile);
396
- if (parsed.options.forceShell || needsShell) {
397
- const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
398
- parsed.command = path.normalize(parsed.command);
399
- parsed.command = escape.command(parsed.command);
400
- parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
401
- const shellCommand = [parsed.command].concat(parsed.args).join(" ");
402
- parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
403
- parsed.command = process.env.comspec || "cmd.exe";
404
- parsed.options.windowsVerbatimArguments = true;
405
- }
406
- return parsed;
407
- }
408
- function parse(command, args, options) {
409
- if (args && !Array.isArray(args)) {
410
- options = args;
411
- args = null;
412
- }
413
- args = args ? args.slice(0) : [];
414
- options = Object.assign({}, options);
415
- const parsed = {
416
- command,
417
- args,
418
- options,
419
- file: void 0,
420
- original: {
421
- command,
422
- args
423
- }
424
- };
425
- return options.shell ? parsed : parseNonShell(parsed);
426
- }
427
- module.exports = parse;
428
- }
429
- });
430
-
431
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js
432
- var require_enoent = __commonJS({
433
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module) {
434
- "use strict";
435
- var isWin = process.platform === "win32";
436
- function notFoundError(original, syscall) {
437
- return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
438
- code: "ENOENT",
439
- errno: "ENOENT",
440
- syscall: `${syscall} ${original.command}`,
441
- path: original.command,
442
- spawnargs: original.args
443
- });
444
- }
445
- function hookChildProcess(cp, parsed) {
446
- if (!isWin) {
447
- return;
448
- }
449
- const originalEmit = cp.emit;
450
- cp.emit = function(name, arg1) {
451
- if (name === "exit") {
452
- const err = verifyENOENT(arg1, parsed);
453
- if (err) {
454
- return originalEmit.call(cp, "error", err);
455
- }
456
- }
457
- return originalEmit.apply(cp, arguments);
458
- };
459
- }
460
- function verifyENOENT(status, parsed) {
461
- if (isWin && status === 1 && !parsed.file) {
462
- return notFoundError(parsed.original, "spawn");
463
- }
464
- return null;
465
- }
466
- function verifyENOENTSync(status, parsed) {
467
- if (isWin && status === 1 && !parsed.file) {
468
- return notFoundError(parsed.original, "spawnSync");
469
- }
470
- return null;
471
- }
472
- module.exports = {
473
- hookChildProcess,
474
- verifyENOENT,
475
- verifyENOENTSync,
476
- notFoundError
477
- };
478
- }
479
- });
480
-
481
- // node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js
482
- var require_cross_spawn = __commonJS({
483
- "node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module) {
484
- "use strict";
485
- var cp = __require("child_process");
486
- var parse = require_parse();
487
- var enoent = require_enoent();
488
- function spawn2(command, args, options) {
489
- const parsed = parse(command, args, options);
490
- const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
491
- enoent.hookChildProcess(spawned, parsed);
492
- return spawned;
493
- }
494
- function spawnSync(command, args, options) {
495
- const parsed = parse(command, args, options);
496
- const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
497
- result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
498
- return result;
499
- }
500
- module.exports = spawn2;
501
- module.exports.spawn = spawn2;
502
- module.exports.sync = spawnSync;
503
- module.exports._parse = parse;
504
- module.exports._enoent = enoent;
505
- }
506
- });
507
-
508
- // node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
509
- var import_cross_spawn = __toESM(require_cross_spawn(), 1);
510
- import process2 from "node:process";
511
- import { PassThrough } from "node:stream";
512
-
513
- // node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
514
- var ReadBuffer = class {
515
- append(chunk) {
516
- this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
517
- }
518
- readMessage() {
519
- if (!this._buffer) {
520
- return null;
521
- }
522
- const index = this._buffer.indexOf("\n");
523
- if (index === -1) {
524
- return null;
525
- }
526
- const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
527
- this._buffer = this._buffer.subarray(index + 1);
528
- return deserializeMessage(line);
529
- }
530
- clear() {
531
- this._buffer = void 0;
532
- }
533
- };
534
- function deserializeMessage(line) {
535
- return JSONRPCMessageSchema.parse(JSON.parse(line));
536
- }
537
- function serializeMessage(message) {
538
- return JSON.stringify(message) + "\n";
539
- }
540
-
541
- // node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js
542
- var DEFAULT_INHERITED_ENV_VARS = process2.platform === "win32" ? [
543
- "APPDATA",
544
- "HOMEDRIVE",
545
- "HOMEPATH",
546
- "LOCALAPPDATA",
547
- "PATH",
548
- "PROCESSOR_ARCHITECTURE",
549
- "SYSTEMDRIVE",
550
- "SYSTEMROOT",
551
- "TEMP",
552
- "USERNAME",
553
- "USERPROFILE",
554
- "PROGRAMFILES"
555
- ] : (
556
- /* list inspired by the default env inheritance of sudo */
557
- ["HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER"]
558
- );
559
- function getDefaultEnvironment() {
560
- const env = {};
561
- for (const key of DEFAULT_INHERITED_ENV_VARS) {
562
- const value = process2.env[key];
563
- if (value === void 0) {
564
- continue;
565
- }
566
- if (value.startsWith("()")) {
567
- continue;
568
- }
569
- env[key] = value;
570
- }
571
- return env;
572
- }
573
- var StdioClientTransport = class {
574
- constructor(server) {
575
- this._readBuffer = new ReadBuffer();
576
- this._stderrStream = null;
577
- this._serverParams = server;
578
- if (server.stderr === "pipe" || server.stderr === "overlapped") {
579
- this._stderrStream = new PassThrough();
580
- }
581
- }
582
- /**
583
- * Starts the server process and prepares to communicate with it.
584
- */
585
- async start() {
586
- if (this._process) {
587
- throw new Error("StdioClientTransport already started! If using Client class, note that connect() calls start() automatically.");
588
- }
589
- return new Promise((resolve, reject) => {
590
- this._process = (0, import_cross_spawn.default)(this._serverParams.command, this._serverParams.args ?? [], {
591
- // merge default env with server env because mcp server needs some env vars
592
- env: {
593
- ...getDefaultEnvironment(),
594
- ...this._serverParams.env
595
- },
596
- stdio: ["pipe", "pipe", this._serverParams.stderr ?? "inherit"],
597
- shell: false,
598
- windowsHide: process2.platform === "win32",
599
- cwd: this._serverParams.cwd
600
- });
601
- this._process.on("error", (error) => {
602
- reject(error);
603
- this.onerror?.(error);
604
- });
605
- this._process.on("spawn", () => {
606
- resolve();
607
- });
608
- this._process.on("close", (_code) => {
609
- this._process = void 0;
610
- this.onclose?.();
611
- });
612
- this._process.stdin?.on("error", (error) => {
613
- this.onerror?.(error);
614
- });
615
- this._process.stdout?.on("data", (chunk) => {
616
- this._readBuffer.append(chunk);
617
- this.processReadBuffer();
618
- });
619
- this._process.stdout?.on("error", (error) => {
620
- this.onerror?.(error);
621
- });
622
- if (this._stderrStream && this._process.stderr) {
623
- this._process.stderr.pipe(this._stderrStream);
624
- }
625
- });
626
- }
627
- /**
628
- * The stderr stream of the child process, if `StdioServerParameters.stderr` was set to "pipe" or "overlapped".
629
- *
630
- * If stderr piping was requested, a PassThrough stream is returned _immediately_, allowing callers to
631
- * attach listeners before the start method is invoked. This prevents loss of any early
632
- * error output emitted by the child process.
633
- */
634
- get stderr() {
635
- if (this._stderrStream) {
636
- return this._stderrStream;
637
- }
638
- return this._process?.stderr ?? null;
639
- }
640
- /**
641
- * The child process pid spawned by this transport.
642
- *
643
- * This is only available after the transport has been started.
644
- */
645
- get pid() {
646
- return this._process?.pid ?? null;
647
- }
648
- processReadBuffer() {
649
- while (true) {
650
- try {
651
- const message = this._readBuffer.readMessage();
652
- if (message === null) {
653
- break;
654
- }
655
- this.onmessage?.(message);
656
- } catch (error) {
657
- this.onerror?.(error);
658
- }
659
- }
660
- }
661
- async close() {
662
- if (this._process) {
663
- const processToClose = this._process;
664
- this._process = void 0;
665
- const closePromise = new Promise((resolve) => {
666
- processToClose.once("close", () => {
667
- resolve();
668
- });
669
- });
670
- try {
671
- processToClose.stdin?.end();
672
- } catch {
673
- }
674
- await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
675
- if (processToClose.exitCode === null) {
676
- try {
677
- processToClose.kill("SIGTERM");
678
- } catch {
679
- }
680
- await Promise.race([closePromise, new Promise((resolve) => setTimeout(resolve, 2e3).unref())]);
681
- }
682
- if (processToClose.exitCode === null) {
683
- try {
684
- processToClose.kill("SIGKILL");
685
- } catch {
686
- }
687
- }
688
- }
689
- this._readBuffer.clear();
690
- }
691
- send(message) {
692
- return new Promise((resolve) => {
693
- if (!this._process?.stdin) {
694
- throw new Error("Not connected");
695
- }
696
- const json = serializeMessage(message);
697
- if (this._process.stdin.write(json)) {
698
- resolve();
699
- } else {
700
- this._process.stdin.once("drain", resolve);
701
- }
702
- });
703
- }
704
- };
705
-
706
- // node_modules/.pnpm/mcporter@0.12.3/node_modules/mcporter/dist/sdk-patches.js
707
- var PROCESS_BUFFERS = /* @__PURE__ */ new WeakMap();
708
- var TRANSPORT_BUFFERS = /* @__PURE__ */ new WeakMap();
709
- var STDIO_LOGS_FORCED = process.env.MCPORTER_STDIO_LOGS === "1";
710
- var STDIO_TRACE_ENABLED = process.env.MCPORTER_STDIO_TRACE === "1";
711
- var stdioLogMode = STDIO_LOGS_FORCED ? "always" : "auto";
712
- function setStdioLogMode(mode) {
713
- const previous = stdioLogMode;
714
- if (!STDIO_LOGS_FORCED) {
715
- stdioLogMode = mode;
716
- }
717
- return previous;
718
- }
719
- function evaluateStdioLogPolicy(mode, hasStderr, exitCode) {
720
- if (!hasStderr) {
721
- return false;
722
- }
723
- if (mode === "silent") {
724
- return false;
725
- }
726
- if (mode === "always") {
727
- return true;
728
- }
729
- return typeof exitCode === "number" && exitCode !== 0;
730
- }
731
- function shouldPrintStdioLogs(meta) {
732
- return evaluateStdioLogPolicy(stdioLogMode, meta.stderrChunks.length > 0, meta.code);
733
- }
734
- if (STDIO_TRACE_ENABLED) {
735
- console.log("[mcporter] STDIO trace logging enabled (set MCPORTER_STDIO_TRACE=0 to disable).");
736
- }
737
- function ignoreEmitterError() {
738
- }
739
- function destroyStream(stream) {
740
- if (!stream || typeof stream !== "object") {
741
- return;
742
- }
743
- const emitter = stream;
744
- try {
745
- emitter.on?.("error", ignoreEmitterError);
746
- } catch {
747
- }
748
- try {
749
- emitter.destroy?.();
750
- } catch {
751
- }
752
- try {
753
- emitter.end?.();
754
- } catch {
755
- }
756
- try {
757
- emitter.unref?.();
758
- } catch {
759
- }
760
- try {
761
- emitter.off?.("error", ignoreEmitterError);
762
- } catch {
763
- }
764
- try {
765
- emitter.removeListener?.("error", ignoreEmitterError);
766
- } catch {
767
- }
768
- }
769
- function waitForChildClose(child, timeoutMs) {
770
- if (!child) {
771
- return Promise.resolve();
772
- }
773
- if (child.exitCode !== null && child.exitCode !== void 0) {
774
- return Promise.resolve();
775
- }
776
- return new Promise((resolve, reject) => {
777
- let settled = false;
778
- try {
779
- child.on?.("error", ignoreEmitterError);
780
- } catch {
781
- }
782
- const finish = () => {
783
- if (settled) {
784
- return;
785
- }
786
- settled = true;
787
- cleanup();
788
- resolve();
789
- };
790
- const timeout = () => {
791
- if (settled) {
792
- return;
793
- }
794
- settled = true;
795
- cleanup();
796
- reject(new Error(`Timed out waiting ${timeoutMs}ms for child process to close.`));
797
- };
798
- const cleanup = () => {
799
- child.removeListener("exit", finish);
800
- child.removeListener("close", finish);
801
- child.removeListener("error", finish);
802
- try {
803
- child.removeListener?.("error", ignoreEmitterError);
804
- } catch {
805
- }
806
- if (timer) {
807
- clearTimeout(timer);
808
- }
809
- };
810
- child.once("exit", finish);
811
- child.once("close", finish);
812
- child.once("error", finish);
813
- let timer;
814
- if (Number.isFinite(timeoutMs) && timeoutMs > 0) {
815
- timer = setTimeout(timeout, timeoutMs);
816
- timer.unref?.();
817
- }
818
- });
819
- }
820
- function flushProcessLogs(_child, meta) {
821
- if (meta.flushed) {
822
- return;
823
- }
824
- meta.flushed = true;
825
- if (STDIO_TRACE_ENABLED) {
826
- const stderrChunks = meta.stderrChunks.length;
827
- const stdoutChunks = meta.stdoutChunks?.length ?? 0;
828
- const stdinChunks = meta.stdinChunks?.length ?? 0;
829
- const label = meta.command ?? "stdio server";
830
- console.log(`[mcporter] STDIO trace summary for ${label}: stdin=${stdinChunks} message(s), stdout=${stdoutChunks} chunk(s), stderr=${stderrChunks} chunk(s).`);
831
- }
832
- for (const { stream, event, handler } of meta.listeners) {
833
- try {
834
- stream.removeListener?.(event, handler);
835
- } catch {
836
- }
837
- }
838
- meta.listeners.length = 0;
839
- if (shouldPrintStdioLogs(meta)) {
840
- const heading = meta.command ? `[mcporter] stderr from ${meta.command}` : "[mcporter] stderr from stdio server";
841
- console.log(heading);
842
- process.stdout.write(meta.stderrChunks.join(""));
843
- if (!meta.stderrChunks[meta.stderrChunks.length - 1]?.endsWith("\n")) {
844
- console.log("");
845
- }
846
- }
847
- if (STDIO_TRACE_ENABLED && meta.stdoutChunks && meta.stdoutChunks.length > 0) {
848
- const heading = meta.command ? `[mcporter] stdout from ${meta.command}` : "[mcporter] stdout from stdio server";
849
- console.log(heading);
850
- process.stdout.write(meta.stdoutChunks.join(""));
851
- if (!meta.stdoutChunks[meta.stdoutChunks.length - 1]?.endsWith("\n")) {
852
- console.log("");
853
- }
854
- }
855
- if (STDIO_TRACE_ENABLED && meta.stdinChunks && meta.stdinChunks.length > 0) {
856
- const heading = meta.command ? `[mcporter] stdin to ${meta.command}` : "[mcporter] stdin to stdio server";
857
- console.log(heading);
858
- for (const entry of meta.stdinChunks) {
859
- console.log(entry);
860
- }
861
- }
862
- if (meta.child) {
863
- PROCESS_BUFFERS.delete(meta.child);
864
- }
865
- if (meta.transport) {
866
- TRANSPORT_BUFFERS.delete(meta.transport);
867
- }
868
- }
869
- function patchStdioClose() {
870
- const marker = /* @__PURE__ */ Symbol.for("mcporter.stdio.patched");
871
- const proto = StdioClientTransport.prototype;
872
- if (proto[marker]) {
873
- return;
874
- }
875
- patchStdioStart();
876
- StdioClientTransport.prototype.close = async function patchedClose() {
877
- const transport = this;
878
- const child = transport._process ?? null;
879
- const stderrStream = transport._stderrStream ?? null;
880
- const meta = (child ? PROCESS_BUFFERS.get(child) : void 0) ?? TRANSPORT_BUFFERS.get(transport);
881
- if (stderrStream) {
882
- destroyStream(stderrStream);
883
- transport._stderrStream = null;
884
- }
885
- transport._abortController?.abort();
886
- transport._abortController = null;
887
- transport._readBuffer?.clear?.();
888
- transport._readBuffer = null;
889
- if (!child) {
890
- transport.onclose?.();
891
- return;
892
- }
893
- destroyStream(child.stdin);
894
- destroyStream(child.stdout);
895
- destroyStream(child.stderr);
896
- const stdio = Array.isArray(child.stdio) ? child.stdio : [];
897
- for (const stream of stdio) {
898
- destroyStream(stream);
899
- }
900
- let exited = await waitForChildClose(child, 700).then(() => true, () => false);
901
- if (!exited) {
902
- try {
903
- child.kill("SIGTERM");
904
- } catch {
905
- }
906
- exited = await waitForChildClose(child, 700).then(() => true, () => false);
907
- }
908
- if (!exited) {
909
- try {
910
- child.kill("SIGKILL");
911
- } catch {
912
- }
913
- await waitForChildClose(child, 500).catch(() => {
914
- });
915
- }
916
- destroyStream(child.stdin);
917
- destroyStream(child.stdout);
918
- destroyStream(child.stderr);
919
- const stdioAfter = Array.isArray(child.stdio) ? child.stdio : [];
920
- for (const stream of stdioAfter) {
921
- destroyStream(stream);
922
- }
923
- child.unref?.();
924
- if (meta) {
925
- flushProcessLogs(meta.child ?? child, meta);
926
- } else if (STDIO_TRACE_ENABLED) {
927
- console.log("[mcporter] STDIO trace: attempted to close transport without recorded metadata.");
928
- }
929
- transport._process = null;
930
- transport.onclose?.();
931
- };
932
- proto[marker] = true;
933
- }
934
- function patchStdioStart() {
935
- const marker = /* @__PURE__ */ Symbol.for("mcporter.stdio.startPatched");
936
- const proto = StdioClientTransport.prototype;
937
- if (proto[marker]) {
938
- return;
939
- }
940
- const originalStart = StdioClientTransport.prototype.start;
941
- StdioClientTransport.prototype.start = async function patchedStart() {
942
- const transport = this;
943
- if (STDIO_TRACE_ENABLED) {
944
- console.log("[mcporter] STDIO trace: start() invoked for stdio transport.");
945
- }
946
- if (transport._serverParams && transport._serverParams.stderr !== "pipe") {
947
- transport._serverParams = {
948
- ...transport._serverParams,
949
- stderr: "pipe"
950
- };
951
- }
952
- const startPromise = originalStart.apply(this);
953
- const child = transport._process ?? null;
954
- const meta = {
955
- stderrChunks: [],
956
- stdoutChunks: STDIO_TRACE_ENABLED ? [] : void 0,
957
- stdinChunks: STDIO_TRACE_ENABLED ? [] : void 0,
958
- command: transport._serverParams?.command,
959
- code: null,
960
- listeners: [],
961
- child,
962
- transport
963
- };
964
- TRANSPORT_BUFFERS.set(transport, meta);
965
- if (child) {
966
- PROCESS_BUFFERS.set(child, meta);
967
- if (STDIO_TRACE_ENABLED) {
968
- const pid = typeof child.pid === "number" ? child.pid : "unknown";
969
- console.log(`[mcporter] STDIO trace: spawned ${meta.command ?? "stdio server"} (pid=${pid}).`);
970
- }
971
- } else if (STDIO_TRACE_ENABLED) {
972
- console.log(`[mcporter] STDIO trace: transport for ${meta.command ?? "stdio server"} exited before spawn listeners attached.`);
973
- }
974
- const targetStream = transport._stderrStream ?? child?.stderr ?? null;
975
- if (targetStream) {
976
- if (typeof targetStream.setEncoding === "function") {
977
- targetStream.setEncoding?.("utf8");
978
- }
979
- const handleChunk = (chunk) => {
980
- if (typeof chunk === "string") {
981
- meta.stderrChunks.push(chunk);
982
- } else if (Buffer.isBuffer(chunk)) {
983
- meta.stderrChunks.push(chunk.toString("utf8"));
984
- }
985
- };
986
- targetStream.on("data", handleChunk);
987
- targetStream.on("error", ignoreEmitterError);
988
- meta.listeners.push({
989
- stream: targetStream,
990
- event: "data",
991
- handler: handleChunk
992
- });
993
- meta.listeners.push({
994
- stream: targetStream,
995
- event: "error",
996
- handler: ignoreEmitterError
997
- });
998
- }
999
- if (STDIO_TRACE_ENABLED && child?.stdout) {
1000
- const stdoutStream = child.stdout;
1001
- const handleStdout = (chunk) => {
1002
- if (!meta.stdoutChunks) {
1003
- meta.stdoutChunks = [];
1004
- }
1005
- if (typeof chunk === "string") {
1006
- meta.stdoutChunks.push(chunk);
1007
- } else if (Buffer.isBuffer(chunk)) {
1008
- meta.stdoutChunks.push(chunk.toString("utf8"));
1009
- }
1010
- };
1011
- stdoutStream.on("data", handleStdout);
1012
- stdoutStream.on("error", ignoreEmitterError);
1013
- meta.listeners.push({
1014
- stream: stdoutStream,
1015
- event: "data",
1016
- handler: handleStdout
1017
- });
1018
- meta.listeners.push({
1019
- stream: stdoutStream,
1020
- event: "error",
1021
- handler: ignoreEmitterError
1022
- });
1023
- }
1024
- if (child) {
1025
- child.once("exit", (code) => {
1026
- const entry = PROCESS_BUFFERS.get(child);
1027
- if (entry) {
1028
- entry.code = code;
1029
- flushProcessLogs(child, entry);
1030
- }
1031
- });
1032
- }
1033
- await startPromise;
1034
- };
1035
- proto[marker] = true;
1036
- }
1037
- patchStdioClose();
1038
- patchStdioSend();
1039
- function patchStdioSend() {
1040
- if (!STDIO_TRACE_ENABLED) {
1041
- return;
1042
- }
1043
- const marker = /* @__PURE__ */ Symbol.for("mcporter.stdio.sendPatched");
1044
- const proto = StdioClientTransport.prototype;
1045
- if (proto[marker]) {
1046
- return;
1047
- }
1048
- const originalSend = StdioClientTransport.prototype.send;
1049
- StdioClientTransport.prototype.send = function patchedSend(message) {
1050
- if (STDIO_TRACE_ENABLED) {
1051
- try {
1052
- const transport = this;
1053
- const child = transport._process ?? null;
1054
- if (child) {
1055
- const meta = PROCESS_BUFFERS.get(child);
1056
- if (meta) {
1057
- if (!meta.stdinChunks) {
1058
- meta.stdinChunks = [];
1059
- }
1060
- meta.stdinChunks.push(JSON.stringify(message));
1061
- }
1062
- }
1063
- } catch {
1064
- }
1065
- }
1066
- return originalSend.call(this, message);
1067
- };
1068
- proto[marker] = true;
1069
- }
1070
-
1071
- export {
1072
- ReadBuffer,
1073
- serializeMessage,
1074
- StdioClientTransport,
1075
- setStdioLogMode
1076
- };