local-mcp 3.0.432 → 3.0.434

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/index.js CHANGED
@@ -496,7 +496,11 @@ async function main() {
496
496
  // El server arrancó y sigue vivo pasada la ventana: este proceso queda toda la sesión y el
497
497
  // evento sale desde acá.
498
498
  let arranque = null
499
+ let nacio = 0
500
+ let alSalirHijo = (salir) => salir()
499
501
  child.on('spawn', () => {
502
+ nacio = Date.now()
503
+ if (ES_LANZAMIENTO) alSalirHijo = evento.rastroAlCerrarPorSenal(nacio)
500
504
  arranque = setTimeout(() => { arranque = null; reportarLanzamiento('spawned', { enProceso: true }) }, VENTANA_ARRANQUE_MS)
501
505
  arranque.unref() // el evento nunca retiene al proceso ni demora una salida
502
506
  })
@@ -517,7 +521,8 @@ async function main() {
517
521
  reportarLanzamiento(s.outcome, { reason: s.reason, signal: s.signal })
518
522
  } else reportarLanzamiento('spawn-failed', { reason: 'early-exit' })
519
523
  }
520
- process.exit(code ?? 0)
524
+ if (ES_LANZAMIENTO) evento.reportarSalidaHijo(Date.now() - nacio, code, signal)
525
+ alSalirHijo(() => process.exit(code ?? 0))
521
526
  })
522
527
  }
523
528
 
package/launch-event.js CHANGED
@@ -119,16 +119,80 @@ function cuerpo (outcome, clase, deps = {}) {
119
119
  return c
120
120
  }
121
121
 
122
+ // Contrato de la fuga, sección C (lmcp-api#817): cuánto vivió el server y cómo terminó. Cada envío es un
123
+ // proceso suelto y la cohorte que se quiere medir lanza miles por día, así que sale 1 de cada 10.
124
+ // Sin id de máquina: el id de Windows pide un probe de PowerShell. Un SIGKILL, o cualquier kill en Windows, no deja
125
+ // evento: que falte no significa que el proceso se filtró.
126
+ const BALDES_VIDA = ['lt_10s', 'lt_1m', 'lt_5m', 'lt_30m', 'gte_30m']
127
+ const TOPES_VIDA_MS = [10000, 60000, 300000, 1800000]
128
+ const CLASES_SALIDA = ['clean', 'error', 'client_closed', 'crashed', 'other']
129
+ const MUESTRA_SALIDA = 0.1
130
+ function baldeDeVida (ms) {
131
+ const i = TOPES_VIDA_MS.findIndex(tope => ms < tope)
132
+ return BALDES_VIDA[i === -1 ? BALDES_VIDA.length - 1 : i]
133
+ }
134
+ function claseDeSalidaHijo (code, signal) {
135
+ if (signal) return DEL_CLIENTE.includes(signal) ? 'client_closed' : 'crashed'
136
+ if (code === 0) return 'clean'
137
+ return Number.isInteger(code) ? 'error' : 'other'
138
+ }
139
+ function cuerpoSalidaHijo (balde, clase, deps = {}) {
140
+ const version = deps.version || require('./package.json').version
141
+ const plataforma = deps.platform || process.platform
142
+ if (!BALDES_VIDA.includes(balde) || !CLASES_SALIDA.includes(clase) || !RE_VERSION.test(version)) return null
143
+ return { type: 'npm_child_exit', source: CAMINO, data: { lifetime_bucket: balde, exit_class: clase,
144
+ platform: PLATAFORMAS.includes(plataforma) ? plataforma : 'other', package_version: version } }
145
+ }
146
+ function reportarSalidaHijo (ms, code, signal, deps = {}) {
147
+ try {
148
+ const { azar = Math.random, lanzar = lanzarSalidaSuelta, stdinTTY = !!(process.stdin && process.stdin.isTTY) } = deps
149
+ if (azar() >= MUESTRA_SALIDA || apagado() || stdinTTY) return
150
+ lanzar(baldeDeVida(ms), claseDeSalidaHijo(code, signal))
151
+ } catch {}
152
+ }
153
+ // Un cliente que cierra con una señal mata al wrapper antes de `child.on('exit')` y no quedaba rastro. Este manejador
154
+ // sólo reporta y después suelta las señales y vuelve a lanzar la misma, así el cliente ve la muerte de siempre. Suelta
155
+ // después porque npm reenvía la suya: con dos SIGTERM juntos, soltar antes cortaba el reporte. No se reenvía
156
+ // al server: hoy no la recibe por el wrapper, y sale al cerrarse stdin. Windows queda afuera: un kill ahí no pasa por
157
+ // un manejador, y relanzar SIGINT cambiaría el código de salida.
158
+ const SENALES_DE_CIERRE = ['SIGTERM', 'SIGINT', 'SIGHUP']
159
+ function rastroAlCerrarPorSenal (nacio, deps = {}) {
160
+ const { proceso = process, plataforma = process.platform, reportar = reportarSalidaHijo, diferir = setImmediate } = deps
161
+ if (plataforma === 'win32') return (salir) => salir()
162
+ let reportado = false
163
+ const soltar = () => { for (const s of SENALES_DE_CIERRE) proceso.removeListener(s, alRecibir) }
164
+ function alRecibir (senal) {
165
+ if (!reportado) try { reportar(Date.now() - nacio, null, senal) } catch {}
166
+ soltar()
167
+ proceso.kill(proceso.pid, senal)
168
+ }
169
+ for (const s of SENALES_DE_CIERRE) proceso.on(s, alRecibir)
170
+ // Sin manejador, una señal mataba al wrapper aunque el hijo ya hubiera salido. Con él, ese exit y la señal pueden
171
+ // llegar en el mismo giro y el exit iba primero: el cliente veía un código en vez de la señal. El exit del hijo ya
172
+ // reportó, así que espera a que pase lo que ya llegó, y suelta para que una señal tardía mate como siempre.
173
+ return (salir) => {
174
+ reportado = true
175
+ diferir(() => { soltar(); salir() })
176
+ }
177
+ }
178
+ function lanzarSalidaSuelta (balde, clase) {
179
+ const hijo = cp.spawn(process.execPath, [__filename, 'npm_child_exit', balde, clase],
180
+ { detached: true, stdio: 'ignore', windowsHide: true })
181
+ hijo.on('error', () => {})
182
+ hijo.unref()
183
+ }
184
+
122
185
  // Un POST, sin reintento, respuesta ignorada. `soltar` es para el pedido que sale desde el
123
186
  // wrapper vivo: el socket no retiene al proceso.
124
- function enviar (c, { soltar = false } = {}) {
187
+ function enviar (c, { soltar = false, ruta = DESTINO.path, timeout = TIMEOUT_MS } = {}) {
125
188
  try {
126
189
  const datos = JSON.stringify(c)
127
190
  const req = https.request({
128
191
  ...DESTINO,
192
+ path: ruta,
129
193
  method: 'POST',
130
194
  headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(datos) },
131
- timeout: TIMEOUT_MS
195
+ timeout
132
196
  }, (res) => res.resume())
133
197
  req.on('error', () => {})
134
198
  req.on('timeout', () => { try { req.destroy() } catch {} })
@@ -272,11 +336,17 @@ function soltarPendiente () {
272
336
  // Como programa es el proceso suelto: `node launch-event.js <outcome> <clase> [reason] [binary_source]`.
273
337
  if (require.main === module) {
274
338
  setTimeout(() => process.exit(0), TOPE_MS).unref()
275
- const a = desdeArgv(process.argv.slice(2))
276
- const c = apagado() ? null : cuerpo(a.outcome, a.clase, a)
277
- if (c) enviar(c)
339
+ const argv = process.argv.slice(2)
340
+ if (argv[0] === 'npm_child_exit') {
341
+ const c = apagado() ? null : cuerpoSalidaHijo(argv[1], argv[2])
342
+ if (c) enviar(c, { ruta: '/events', timeout: 2000 })
343
+ } else {
344
+ const a = desdeArgv(argv)
345
+ const c = apagado() ? null : cuerpo(a.outcome, a.clase, a)
346
+ if (c) enviar(c)
347
+ }
278
348
  }
279
349
 
280
- module.exports = { PLATAFORMAS, CLASES, OUTCOMES, RAZONES, CAMINO, FUENTES, SENALES, RE_CLASE_ERROR, fuente, razonDeError,
350
+ module.exports = { BALDES_VIDA, CLASES_SALIDA, baldeDeVida, claseDeSalidaHijo, cuerpoSalidaHijo, reportarSalidaHijo, rastroAlCerrarPorSenal, PLATAFORMAS, CLASES, OUTCOMES, RAZONES, CAMINO, FUENTES, SENALES, RE_CLASE_ERROR, fuente, razonDeError,
281
351
  salidaPorSenal, claseDeError, argumentosSueltos, desdeArgv, RE_VERSION, RE_MAQUINA, TOPE_ID_MS, claseDeArgumento, apagado, cuerpo, reportar, silenciar, soltarPendiente,
282
352
  _idDeHardwareWindows: idDeHardwareWindows } // costura de test
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-mcp",
3
- "version": "3.0.432",
3
+ "version": "3.0.434",
4
4
  "description": "Let ChatGPT, Claude, Cursor & any MCP client actually use your Mac or Windows PC — read & reply to email, manage your calendar, text over iMessage, find files, work with Teams, Slack, Notion & Office. Runs locally, no API keys.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -26,10 +26,10 @@
26
26
  "node": ">=20"
27
27
  },
28
28
  "optionalDependencies": {
29
- "local-mcp-darwin-arm64": "3.0.432",
30
- "local-mcp-darwin-x64": "3.0.432",
31
- "local-mcp-windows-x64": "3.0.432",
32
- "local-mcp-windows-arm64": "3.0.432"
29
+ "local-mcp-darwin-arm64": "3.0.434",
30
+ "local-mcp-darwin-x64": "3.0.434",
31
+ "local-mcp-windows-x64": "3.0.434",
32
+ "local-mcp-windows-arm64": "3.0.434"
33
33
  },
34
34
  "os": [
35
35
  "darwin",
package/setup.js CHANGED
@@ -332,6 +332,7 @@ async function runSetup(opts = {}) {
332
332
  process.exitCode = sinLinux.exitCode
333
333
  return
334
334
  }
335
+ _trackNpxSetup('started')
335
336
  // Cross-platform: macOS configures the Swift tray + embedded server; Windows installs the
336
337
  // go-server from the npm platform package (bundled.js) and writes the MCP client config.
337
338
  const forceAll = opts.all || process.argv.includes('--all')
@@ -749,7 +750,33 @@ function _migrateCurlLaunchAgent() {
749
750
  // Fire-and-forget. Sends one event per step to /setup-step so we can see exactly
750
751
  // where each machine's install funnel breaks without waiting for a heartbeat.
751
752
 
753
+ // Contrato de la fuga, sección C (lmcp-api#817): un intento, 2 s, sin token ni ids. Nunca cambia el setup.
754
+ const NPX_SETUP = ['started', 'linked', 'link_shown', 'token_registered', 'failed']
755
+ const NPX_SETUP_DE_PASO = {
756
+ 'relay_register:ok': 'token_registered', 'relay_register:reused': 'token_registered', 'relay_register:failed': 'failed',
757
+ 'account_link:shown': 'link_shown', 'account_link:linked': 'linked', 'account_link:failed': 'failed',
758
+ 'setup_complete:failed': 'failed',
759
+ }
760
+ function _trackNpxSetup(status) {
761
+ try {
762
+ if (!NPX_SETUP.includes(status) || require('./launch-event').apagado()) return
763
+ const { https } = require('./user-agent')
764
+ const data = JSON.stringify({ step: 'npx_setup', status, platform: process.platform })
765
+ const req = https.request({
766
+ hostname: BACKEND_HOST,
767
+ path: '/install/step',
768
+ method: 'POST',
769
+ headers: { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(data) },
770
+ timeout: 2000,
771
+ }, (res) => res.resume())
772
+ req.on('error', () => {})
773
+ req.on('timeout', () => { try { req.destroy() } catch {} })
774
+ req.end(data)
775
+ } catch { /* non-fatal */ }
776
+ }
777
+
752
778
  function _trackSetupStep(step, status, client, detail) {
779
+ _trackNpxSetup(NPX_SETUP_DE_PASO[`${step}:${status}`])
753
780
  try {
754
781
  const { https } = require('./user-agent')
755
782
  const payload = {
@@ -953,5 +980,5 @@ module.exports = {
953
980
  _launcherSpawnSpec, _writeLaunchScript, _writeLaunchSpec,
954
981
  _getMachineId, _healthCheckSpec, _localMcpConfigDir, _installRefDir,
955
982
  _cloudTokenPath, _readCachedCloudToken, _pingInstall,
956
- _fetchClientsCatalog, _trackSetupStep,
983
+ _fetchClientsCatalog, _trackSetupStep, _trackNpxSetup, NPX_SETUP,
957
984
  }