@mindexec/cli 0.2.406 → 0.2.407

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 (2) hide show
  1. package/package.json +1 -1
  2. package/port-guard.cjs +54 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindexec/cli",
3
- "version": "0.2.406",
3
+ "version": "0.2.407",
4
4
  "description": "MindExec local runtime and bridge CLI",
5
5
  "main": "server.js",
6
6
  "type": "module",
package/port-guard.cjs CHANGED
@@ -1,9 +1,11 @@
1
1
  const { execFile } = require('child_process');
2
+ const http = require('http');
2
3
  const path = require('path');
3
4
  const { promisify } = require('util');
4
5
 
5
6
  const execFileAsync = promisify(execFile);
6
7
  const DEFAULT_WAIT_MS = 3500;
8
+ const STATUS_PROBE_TIMEOUT_MS = 650;
7
9
 
8
10
  function normalizePort(value, fallback = 5147) {
9
11
  const parsed = Number.parseInt(String(value || '').trim(), 10);
@@ -141,6 +143,55 @@ function looksLikeMindExecBridge(details, bridgeRoot) {
141
143
  || /\bmindexec(\.cmd|\.ps1|\.exe)?\b/i.test(text);
142
144
  }
143
145
 
146
+ async function probeMindExecStatus(port) {
147
+ return await new Promise(resolve => {
148
+ const request = http.request({
149
+ hostname: '127.0.0.1',
150
+ port,
151
+ path: '/api/status',
152
+ method: 'GET',
153
+ timeout: STATUS_PROBE_TIMEOUT_MS,
154
+ headers: {
155
+ Accept: 'application/json'
156
+ }
157
+ }, response => {
158
+ let body = '';
159
+ response.setEncoding('utf8');
160
+ response.on('data', chunk => {
161
+ body += chunk;
162
+ if (body.length > 64 * 1024) {
163
+ request.destroy();
164
+ resolve(false);
165
+ }
166
+ });
167
+ response.on('end', () => {
168
+ if (response.statusCode !== 200) {
169
+ resolve(false);
170
+ return;
171
+ }
172
+
173
+ try {
174
+ const payload = JSON.parse(body || '{}');
175
+ resolve(
176
+ payload?.app === 'MindExec' &&
177
+ payload?.packageName === '@mindexec/cli' &&
178
+ payload?.status === 'ok'
179
+ );
180
+ } catch {
181
+ resolve(false);
182
+ }
183
+ });
184
+ });
185
+
186
+ request.on('timeout', () => {
187
+ request.destroy();
188
+ resolve(false);
189
+ });
190
+ request.on('error', () => resolve(false));
191
+ request.end();
192
+ });
193
+ }
194
+
144
195
  async function waitForPortRelease(port, timeoutMs = DEFAULT_WAIT_MS) {
145
196
  const started = Date.now();
146
197
  while (Date.now() - started < timeoutMs) {
@@ -182,7 +233,9 @@ async function releaseBridgePort(options = {}) {
182
233
 
183
234
  for (const pid of pids) {
184
235
  const details = await getProcessDetails(pid);
185
- const canKill = force || looksLikeMindExecBridge(details, bridgeRoot);
236
+ const canKill = force ||
237
+ looksLikeMindExecBridge(details, bridgeRoot) ||
238
+ await probeMindExecStatus(port);
186
239
  if (!canKill) {
187
240
  skipped.push(details);
188
241
  continue;