md4ai 0.6.1 → 0.6.2

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.
@@ -1161,7 +1161,7 @@ function escapeHtml(text) {
1161
1161
 
1162
1162
  // dist/check-update.js
1163
1163
  import chalk8 from "chalk";
1164
- var CURRENT_VERSION = "0.6.1";
1164
+ var CURRENT_VERSION = "0.6.2";
1165
1165
  async function checkForUpdate() {
1166
1166
  try {
1167
1167
  const controller = new AbortController();
@@ -2002,6 +2002,7 @@ async function fetchGitHubVersions(repo, signal) {
2002
2002
 
2003
2003
  // dist/commands/mcp-watch.js
2004
2004
  import chalk18 from "chalk";
2005
+ import { execFileSync as execFileSync5 } from "node:child_process";
2005
2006
 
2006
2007
  // dist/mcp/read-configs.js
2007
2008
  import { readFile as readFile7 } from "node:fs/promises";
@@ -2217,6 +2218,17 @@ function getProcessTable() {
2217
2218
 
2218
2219
  // dist/commands/mcp-watch.js
2219
2220
  var POLL_INTERVAL_MS = 3e4;
2221
+ function detectTty() {
2222
+ try {
2223
+ const result = execFileSync5("ps", ["-o", "tty=", "-p", String(process.pid)], {
2224
+ encoding: "utf-8",
2225
+ timeout: 3e3
2226
+ }).trim();
2227
+ return result && result !== "?" ? result : null;
2228
+ } catch {
2229
+ return null;
2230
+ }
2231
+ }
2220
2232
  function checkEnvVars(config) {
2221
2233
  const required = config.env ? Object.keys(config.env) : [];
2222
2234
  const missing = required.filter((key) => !process.env[key]);
@@ -2362,7 +2374,19 @@ async function mcpWatchCommand() {
2362
2374
  const { supabase, userId } = await getAuthenticatedClient();
2363
2375
  const deviceId = await resolveDeviceId(supabase, userId);
2364
2376
  const deviceName = detectDeviceName();
2377
+ const myPid = process.pid;
2378
+ const myTty = detectTty();
2365
2379
  console.log(chalk18.blue(`Starting MCP monitor for ${deviceName}...`));
2380
+ await supabase.from("mcp_watchers").upsert({
2381
+ device_id: deviceId,
2382
+ pid: myPid,
2383
+ tty: myTty,
2384
+ cli_version: CURRENT_VERSION,
2385
+ started_at: (/* @__PURE__ */ new Date()).toISOString(),
2386
+ last_heartbeat: (/* @__PURE__ */ new Date()).toISOString()
2387
+ }, { onConflict: "device_id,pid" });
2388
+ const staleThreshold = new Date(Date.now() - 12e4).toISOString();
2389
+ await supabase.from("mcp_watchers").delete().eq("device_id", deviceId).lt("last_heartbeat", staleThreshold);
2366
2390
  async function cycle() {
2367
2391
  const configs = await readAllMcpConfigs();
2368
2392
  const rows = buildRows(configs);
@@ -2375,17 +2399,23 @@ async function mcpWatchCommand() {
2375
2399
  checked_at: now
2376
2400
  })));
2377
2401
  }
2402
+ await supabase.from("mcp_watchers").update({ last_heartbeat: now }).eq("device_id", deviceId).eq("pid", myPid);
2378
2403
  printTable(rows, deviceName);
2379
2404
  }
2380
2405
  await cycle();
2381
2406
  const interval = setInterval(cycle, POLL_INTERVAL_MS);
2382
- const shutdown = () => {
2407
+ const shutdown = async () => {
2383
2408
  clearInterval(interval);
2409
+ await supabase.from("mcp_watchers").delete().eq("device_id", deviceId).eq("pid", myPid);
2384
2410
  console.log(chalk18.dim("\nMCP monitor stopped."));
2385
2411
  process.exit(0);
2386
2412
  };
2387
- process.on("SIGINT", shutdown);
2388
- process.on("SIGTERM", shutdown);
2413
+ process.on("SIGINT", () => {
2414
+ void shutdown();
2415
+ });
2416
+ process.on("SIGTERM", () => {
2417
+ void shutdown();
2418
+ });
2389
2419
  }
2390
2420
 
2391
2421
  // dist/index.js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "md4ai",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "CLI for MD4AI — scan Claude projects and sync to your dashboard",
5
5
  "type": "module",
6
6
  "bin": {