@tempoxyz/mercator 0.0.836 → 0.0.840
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.
- package/dist/command.js +76 -36
- package/dist/setup.js +10 -1
- package/package.json +1 -1
package/dist/command.js
CHANGED
|
@@ -86,6 +86,27 @@ export function resolveCommand(command, env = process.env) {
|
|
|
86
86
|
code: 'ENOENT',
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
+
function terminateCommandTree(child, taskkill) {
|
|
90
|
+
if (!child.pid)
|
|
91
|
+
return;
|
|
92
|
+
if (taskkill) {
|
|
93
|
+
spawnSync(taskkill, ['/pid', String(child.pid), '/T', '/F'], {
|
|
94
|
+
stdio: 'ignore',
|
|
95
|
+
timeout: 5_000,
|
|
96
|
+
windowsHide: true,
|
|
97
|
+
});
|
|
98
|
+
child.kill('SIGKILL');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
try {
|
|
102
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error.code !== 'ESRCH')
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
89
110
|
/** Runs a command while inheriting the current terminal. */
|
|
90
111
|
export async function runInteractiveCommand(command, args, options = {}) {
|
|
91
112
|
options.signal?.throwIfAborted();
|
|
@@ -102,27 +123,7 @@ export async function runInteractiveCommand(command, args, options = {}) {
|
|
|
102
123
|
// Isolate the whole shim/native process tree so timeout cleanup reaches descendants.
|
|
103
124
|
detached: bounded && process.platform !== 'win32',
|
|
104
125
|
});
|
|
105
|
-
const terminate = () =>
|
|
106
|
-
if (!child.pid)
|
|
107
|
-
return;
|
|
108
|
-
if (taskkill) {
|
|
109
|
-
spawnSync(taskkill, ['/pid', String(child.pid), '/T', '/F'], {
|
|
110
|
-
stdio: 'ignore',
|
|
111
|
-
timeout: 5_000,
|
|
112
|
-
windowsHide: true,
|
|
113
|
-
});
|
|
114
|
-
child.kill('SIGKILL');
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
try {
|
|
118
|
-
process.kill(-child.pid, 'SIGKILL');
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
if (error.code !== 'ESRCH')
|
|
122
|
-
throw error;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
+
const terminate = () => terminateCommandTree(child, taskkill);
|
|
126
127
|
const cleanup = () => {
|
|
127
128
|
clearTimeout(timer);
|
|
128
129
|
options.signal?.removeEventListener('abort', onAbort);
|
|
@@ -189,32 +190,71 @@ export async function runCapturedCommand(command, args, options = {}) {
|
|
|
189
190
|
if (!executable)
|
|
190
191
|
return { code: 1, errorCode: 'ENOENT', output: '' };
|
|
191
192
|
return new Promise((resolve) => {
|
|
193
|
+
const bounded = options.timeoutMs !== undefined || options.maxOutputBytes !== undefined;
|
|
194
|
+
const taskkill = bounded && process.platform === 'win32' ? resolveCommand('taskkill.exe') : undefined;
|
|
192
195
|
const child = spawn(executable, args, {
|
|
193
196
|
stdio: ['ignore', 'pipe', 'pipe'],
|
|
194
|
-
|
|
195
|
-
? {}
|
|
196
|
-
: { timeout: options.timeoutMs, killSignal: 'SIGKILL' }),
|
|
197
|
+
detached: bounded && process.platform !== 'win32',
|
|
197
198
|
});
|
|
198
|
-
let output =
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
|
|
199
|
+
let output = Buffer.alloc(0);
|
|
200
|
+
let settled = false;
|
|
201
|
+
const finish = (code, errorCode) => {
|
|
202
|
+
if (settled)
|
|
203
|
+
return;
|
|
204
|
+
settled = true;
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
process.removeListener('SIGINT', onInterrupt);
|
|
207
|
+
process.removeListener('SIGTERM', onTerminate);
|
|
208
|
+
resolve({ code, ...(errorCode ? { errorCode } : {}), output: output.toString() });
|
|
209
|
+
};
|
|
210
|
+
const terminate = (errorCode) => {
|
|
211
|
+
if (settled)
|
|
212
|
+
return;
|
|
213
|
+
try {
|
|
214
|
+
terminateCommandTree(child, taskkill);
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
finish(1, error.code ?? 'PROCESS_TERMINATED');
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
// A descendant may retain inherited pipes even after the shim exits.
|
|
221
|
+
// The deadline must settle without waiting for the close event.
|
|
222
|
+
child.stdout?.destroy();
|
|
223
|
+
child.stderr?.destroy();
|
|
224
|
+
finish(1, errorCode);
|
|
204
225
|
}
|
|
205
226
|
};
|
|
227
|
+
const onSignal = (signal) => {
|
|
228
|
+
terminate('PROCESS_TERMINATED');
|
|
229
|
+
process.kill(process.pid, signal);
|
|
230
|
+
};
|
|
231
|
+
const onInterrupt = () => onSignal('SIGINT');
|
|
232
|
+
const onTerminate = () => onSignal('SIGTERM');
|
|
233
|
+
const timer = options.timeoutMs === undefined
|
|
234
|
+
? undefined
|
|
235
|
+
: setTimeout(() => terminate('ETIMEDOUT'), options.timeoutMs);
|
|
236
|
+
if (bounded) {
|
|
237
|
+
process.once('SIGINT', onInterrupt);
|
|
238
|
+
process.once('SIGTERM', onTerminate);
|
|
239
|
+
}
|
|
240
|
+
const append = (chunk) => {
|
|
241
|
+
if (settled)
|
|
242
|
+
return;
|
|
243
|
+
const remaining = options.maxOutputBytes === undefined
|
|
244
|
+
? chunk.length
|
|
245
|
+
: Math.max(0, options.maxOutputBytes - output.length);
|
|
246
|
+
output = Buffer.concat([output, chunk.subarray(0, remaining)]);
|
|
247
|
+
if (chunk.length > remaining)
|
|
248
|
+
terminate('ENOBUFS');
|
|
249
|
+
};
|
|
206
250
|
child.stdout?.on('data', append);
|
|
207
251
|
if (options.includeStderr)
|
|
208
252
|
child.stderr?.on('data', append);
|
|
209
253
|
else
|
|
210
254
|
child.stderr?.resume();
|
|
211
|
-
child.once('error', (error) =>
|
|
255
|
+
child.once('error', (error) => finish(1, error.code));
|
|
212
256
|
// Process exit can precede pipe delivery, especially for short-lived client shims.
|
|
213
|
-
child.once('close', (code, signal) =>
|
|
214
|
-
code: code ?? 1,
|
|
215
|
-
...(signal ? { errorCode: 'PROCESS_TERMINATED' } : {}),
|
|
216
|
-
output,
|
|
217
|
-
}));
|
|
257
|
+
child.once('close', (code, signal) => finish(code ?? 1, signal ? 'PROCESS_TERMINATED' : undefined));
|
|
218
258
|
}).catch((error) => ({
|
|
219
259
|
code: 1,
|
|
220
260
|
...(error.code ? { errorCode: error.code } : {}),
|
package/dist/setup.js
CHANGED
|
@@ -122,7 +122,11 @@ export async function setup(options, dependencies, progress, telemetry, diagnost
|
|
|
122
122
|
const inspectionErrors = new Map();
|
|
123
123
|
const uncheckedClients = clients.filter((client) => !detectedStates.has(client));
|
|
124
124
|
if (uncheckedClients.length > 0) {
|
|
125
|
-
|
|
125
|
+
const pending = new Set(uncheckedClients);
|
|
126
|
+
const reportPending = () => progress?.report(pending.size > 0
|
|
127
|
+
? `Checking MCP registrations: ${[...pending].map(clientLabel).join(', ')}...`
|
|
128
|
+
: 'MCP registration checks complete.');
|
|
129
|
+
reportPending();
|
|
126
130
|
await Promise.all(uncheckedClients.map(async (client) => {
|
|
127
131
|
try {
|
|
128
132
|
const plan = setupPlan(client, clientEndpoint(client, options.url));
|
|
@@ -134,6 +138,10 @@ export async function setup(options, dependencies, progress, telemetry, diagnost
|
|
|
134
138
|
detectedStates.set(client, 'unknown');
|
|
135
139
|
inspectionErrors.set(client, errorMessage(error));
|
|
136
140
|
}
|
|
141
|
+
finally {
|
|
142
|
+
pending.delete(client);
|
|
143
|
+
reportPending();
|
|
144
|
+
}
|
|
137
145
|
}));
|
|
138
146
|
}
|
|
139
147
|
if (!options.dryRun) {
|
|
@@ -167,6 +175,7 @@ export async function setup(options, dependencies, progress, telemetry, diagnost
|
|
|
167
175
|
continue;
|
|
168
176
|
if (client === Client.Claude && detectedStates.get(client) === 'unavailable')
|
|
169
177
|
continue;
|
|
178
|
+
progress?.report(`Checking ${clientLabel(client)} plugin registrations...`);
|
|
170
179
|
let registration;
|
|
171
180
|
try {
|
|
172
181
|
registration =
|