grepmax 0.15.0 → 0.15.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.
@@ -361,12 +361,13 @@ exports.doctor = new commander_1.Command("doctor")
361
361
  }
362
362
  yield db.close();
363
363
  }
364
- catch (_g) {
364
+ catch (err) {
365
+ const msg = err instanceof Error ? err.message : String(err);
365
366
  if (opts.agent) {
366
- console.log("index_health\terror=could_not_check");
367
+ console.log(`index_health\terror=${msg.replace(/\t/g, " ")}`);
367
368
  }
368
369
  else {
369
- console.log("\nWARN Could not check index health");
370
+ console.log(`\nWARN Could not check index health: ${msg}`);
370
371
  }
371
372
  }
372
373
  if (!opts.agent) {
@@ -43,6 +43,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.watch = void 0;
46
+ const fs = __importStar(require("node:fs"));
46
47
  const node_child_process_1 = require("node:child_process");
47
48
  const path = __importStar(require("node:path"));
48
49
  const commander_1 = require("commander");
@@ -77,11 +78,20 @@ exports.watch = new commander_1.Command("watch")
77
78
  return;
78
79
  }
79
80
  if (options.background) {
80
- // Skip spawn if daemon already running prevents process accumulation
81
- // when SessionStart hook fires on every session/clear/resume
82
- const { isDaemonRunning } = yield Promise.resolve().then(() => __importStar(require("../lib/utils/daemon-client")));
81
+ // Skip spawn if daemon already running at the same version.
82
+ // If version mismatches (e.g. after npm install -g), shut down the old
83
+ // daemon so we can start a fresh one with the new code.
84
+ const { isDaemonRunning, sendDaemonCommand } = yield Promise.resolve().then(() => __importStar(require("../lib/utils/daemon-client")));
83
85
  if (yield isDaemonRunning()) {
84
- process.exit(0);
86
+ const cliVersion = JSON.parse(fs.readFileSync(path.join(__dirname, "../../package.json"), "utf-8")).version;
87
+ const resp = yield sendDaemonCommand({ cmd: "ping" });
88
+ if (resp.version && resp.version === cliVersion) {
89
+ process.exit(0);
90
+ }
91
+ console.log(`Daemon version mismatch (${resp.version} → ${cliVersion}), restarting...`);
92
+ yield sendDaemonCommand({ cmd: "shutdown" });
93
+ // Brief wait for old daemon to release socket/lock
94
+ yield new Promise((r) => setTimeout(r, 2000));
85
95
  }
86
96
  const logFile = path.join(config_1.PATHS.logsDir, "daemon.log");
87
97
  const out = (0, log_rotate_1.openRotatedLog)(logFile);
@@ -1,4 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
36
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
37
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -12,7 +45,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
45
  exports.writeProgress = writeProgress;
13
46
  exports.writeDone = writeDone;
14
47
  exports.handleCommand = handleCommand;
48
+ const fs = __importStar(require("node:fs"));
49
+ const path = __importStar(require("node:path"));
15
50
  const logger_1 = require("../utils/logger");
51
+ const DAEMON_VERSION = (() => {
52
+ try {
53
+ return JSON.parse(fs.readFileSync(path.join(__dirname, "../../../package.json"), "utf-8")).version;
54
+ }
55
+ catch (_a) {
56
+ return "unknown";
57
+ }
58
+ })();
16
59
  /**
17
60
  * Write a streaming progress line to the IPC connection.
18
61
  */
@@ -42,7 +85,7 @@ function handleCommand(daemon, cmd, conn) {
42
85
  (0, logger_1.debug)("daemon", `ipc cmd=${cmd.cmd}${cmd.root ? ` root=${cmd.root}` : ""}`);
43
86
  switch (cmd.cmd) {
44
87
  case "ping":
45
- return { ok: true, pid: process.pid, uptime: daemon.uptime() };
88
+ return { ok: true, pid: process.pid, uptime: daemon.uptime(), version: DAEMON_VERSION };
46
89
  case "watch": {
47
90
  const root = String(cmd.root || "");
48
91
  if (!root)
@@ -86,7 +86,9 @@ class LlmServer {
86
86
  if (runningModel) {
87
87
  const configBasename = path.basename(this.config.model);
88
88
  if (runningModel !== configBasename && !configBasename.includes(runningModel) && !runningModel.includes(configBasename)) {
89
- console.log(`[llm] Model mismatch: running "${runningModel}" but config expects "${configBasename}"`);
89
+ console.log(`[llm] Model mismatch: running "${runningModel}" but config expects "${configBasename}" — will restart`);
90
+ resolve(false);
91
+ return;
90
92
  }
91
93
  }
92
94
  }
@@ -120,6 +122,12 @@ class LlmServer {
120
122
  this.startIdleWatchdog();
121
123
  return;
122
124
  }
125
+ // Kill stale/mismatched server before spawning a new one
126
+ const existingPid = this.readPid();
127
+ if (existingPid && this.isAlive(existingPid)) {
128
+ console.log(`[llm] Stopping existing server (PID: ${existingPid}) before restart`);
129
+ yield this.stop();
130
+ }
123
131
  // Validate binary
124
132
  const binary = this.config.binary;
125
133
  try {
@@ -38,6 +38,9 @@ var __importStar = (this && this.__importStar) || (function () {
38
38
  return result;
39
39
  };
40
40
  })();
41
+ var __importDefault = (this && this.__importDefault) || function (mod) {
42
+ return (mod && mod.__esModule) ? mod : { "default": mod };
43
+ };
41
44
  Object.defineProperty(exports, "__esModule", { value: true });
42
45
  exports.registerProject = registerProject;
43
46
  exports.listProjects = listProjects;
@@ -47,6 +50,7 @@ exports.getParentProject = getParentProject;
47
50
  exports.getChildProjects = getChildProjects;
48
51
  const fs = __importStar(require("node:fs"));
49
52
  const path = __importStar(require("node:path"));
53
+ const proper_lockfile_1 = __importDefault(require("proper-lockfile"));
50
54
  const config_1 = require("../../config");
51
55
  const REGISTRY_PATH = path.join(config_1.PATHS.globalRoot, "projects.json");
52
56
  function loadRegistry() {
@@ -64,16 +68,37 @@ function saveRegistry(entries) {
64
68
  fs.writeFileSync(tmp, `${JSON.stringify(entries, null, 2)}\n`);
65
69
  fs.renameSync(tmp, REGISTRY_PATH);
66
70
  }
67
- function registerProject(entry) {
68
- const entries = loadRegistry();
69
- const idx = entries.findIndex((e) => e.root === entry.root);
70
- if (idx >= 0) {
71
- entries[idx] = entry;
71
+ function withRegistryLock(fn) {
72
+ // Ensure the directory exists for the lock target
73
+ fs.mkdirSync(path.dirname(REGISTRY_PATH), { recursive: true });
74
+ // Ensure the file exists (lockSync needs it)
75
+ if (!fs.existsSync(REGISTRY_PATH)) {
76
+ fs.writeFileSync(REGISTRY_PATH, "[]\n");
77
+ }
78
+ let release;
79
+ try {
80
+ release = proper_lockfile_1.default.lockSync(REGISTRY_PATH, { stale: 10000, retries: { retries: 3, minTimeout: 100 } });
81
+ return fn();
72
82
  }
73
- else {
74
- entries.push(entry);
83
+ finally {
84
+ try {
85
+ release === null || release === void 0 ? void 0 : release();
86
+ }
87
+ catch (_a) { }
75
88
  }
76
- saveRegistry(entries);
89
+ }
90
+ function registerProject(entry) {
91
+ withRegistryLock(() => {
92
+ const entries = loadRegistry();
93
+ const idx = entries.findIndex((e) => e.root === entry.root);
94
+ if (idx >= 0) {
95
+ entries[idx] = entry;
96
+ }
97
+ else {
98
+ entries.push(entry);
99
+ }
100
+ saveRegistry(entries);
101
+ });
77
102
  }
78
103
  function listProjects() {
79
104
  return loadRegistry();
@@ -82,8 +107,10 @@ function getProject(root) {
82
107
  return loadRegistry().find((e) => e.root === root);
83
108
  }
84
109
  function removeProject(root) {
85
- const entries = loadRegistry().filter((e) => e.root !== root);
86
- saveRegistry(entries);
110
+ withRegistryLock(() => {
111
+ const entries = loadRegistry().filter((e) => e.root !== root);
112
+ saveRegistry(entries);
113
+ });
87
114
  }
88
115
  /**
89
116
  * Find a registered parent that covers this path, if any.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "author": "Robert Owens <78518764+reowens@users.noreply.github.com>",
5
5
  "homepage": "https://github.com/reowens/grepmax",
6
6
  "bugs": {
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.15.0",
3
+ "version": "0.15.2",
4
4
  "description": "Semantic code search for Claude Code. Automatically indexes your project and provides intelligent search capabilities.",
5
5
  "author": {
6
6
  "name": "Robert Owens",