grepmax 0.23.0 → 0.25.0

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 (85) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/README.md +25 -6
  3. package/dist/commands/add.js +38 -31
  4. package/dist/commands/config.js +16 -15
  5. package/dist/commands/context.js +38 -13
  6. package/dist/commands/doctor.js +76 -83
  7. package/dist/commands/extract.js +12 -1
  8. package/dist/commands/impact.js +33 -1
  9. package/dist/commands/index.js +23 -24
  10. package/dist/commands/list.js +23 -14
  11. package/dist/commands/mcp.js +494 -162
  12. package/dist/commands/peek.js +16 -5
  13. package/dist/commands/repair.js +54 -120
  14. package/dist/commands/search-output.js +30 -9
  15. package/dist/commands/search-run.js +75 -47
  16. package/dist/commands/search-skeletons.js +28 -18
  17. package/dist/commands/search.js +45 -49
  18. package/dist/commands/serve.js +415 -373
  19. package/dist/commands/setup.js +2 -2
  20. package/dist/commands/similar.js +5 -5
  21. package/dist/commands/skeleton.js +67 -41
  22. package/dist/commands/status.js +5 -2
  23. package/dist/commands/summarize.js +6 -0
  24. package/dist/commands/surprises.js +150 -0
  25. package/dist/commands/watch.js +102 -38
  26. package/dist/config.js +3 -0
  27. package/dist/eval-surprising-connections.js +191 -0
  28. package/dist/index.js +2 -0
  29. package/dist/lib/analysis/surprising-connections.js +600 -0
  30. package/dist/lib/daemon/daemon.js +1101 -379
  31. package/dist/lib/daemon/ipc-handler.js +122 -13
  32. package/dist/lib/daemon/mlx-server-manager.js +268 -125
  33. package/dist/lib/daemon/process-manager.js +7 -4
  34. package/dist/lib/daemon/search-handler.js +23 -9
  35. package/dist/lib/daemon/watcher-manager.js +353 -110
  36. package/dist/lib/graph/impact-rollup.js +202 -0
  37. package/dist/lib/graph/impact.js +15 -1
  38. package/dist/lib/help/agent-cheatsheet.js +1 -0
  39. package/dist/lib/index/batch-processor.js +231 -67
  40. package/dist/lib/index/embedding-generation.js +109 -0
  41. package/dist/lib/index/embedding-status.js +23 -0
  42. package/dist/lib/index/file-policy.js +273 -0
  43. package/dist/lib/index/ignore-patterns.js +4 -0
  44. package/dist/lib/index/index-config.js +18 -4
  45. package/dist/lib/index/syncer.js +256 -79
  46. package/dist/lib/index/walker.js +66 -86
  47. package/dist/lib/index/watcher-batch.js +9 -0
  48. package/dist/lib/index/watcher.js +129 -3
  49. package/dist/lib/llm/server.js +6 -0
  50. package/dist/lib/search/searcher.js +30 -19
  51. package/dist/lib/skeleton/skeletonizer.js +118 -0
  52. package/dist/lib/skeleton/summary-formatter.js +8 -1
  53. package/dist/lib/store/store-lease.js +473 -0
  54. package/dist/lib/store/vector-db.js +302 -57
  55. package/dist/lib/utils/blocked-roots.js +63 -0
  56. package/dist/lib/utils/cross-project.js +7 -3
  57. package/dist/lib/utils/daemon-client.js +24 -1
  58. package/dist/lib/utils/daemon-launcher.js +38 -13
  59. package/dist/lib/utils/doctor-status.js +76 -0
  60. package/dist/lib/utils/file-utils.js +74 -4
  61. package/dist/lib/utils/keyed-mutex.js +101 -0
  62. package/dist/lib/utils/logger.js +57 -1
  63. package/dist/lib/utils/mlx-hf-cache.js +114 -0
  64. package/dist/lib/utils/operation-coordinator.js +146 -0
  65. package/dist/lib/utils/path-containment.js +106 -0
  66. package/dist/lib/utils/process.js +44 -0
  67. package/dist/lib/utils/project-registry.js +351 -3
  68. package/dist/lib/utils/scope-filter.js +3 -9
  69. package/dist/lib/utils/stale-hint.js +12 -19
  70. package/dist/lib/utils/watcher-launcher.js +5 -1
  71. package/dist/lib/utils/watcher-store.js +2 -2
  72. package/dist/lib/workers/colbert-math.js +15 -12
  73. package/dist/lib/workers/embeddings/colbert.js +3 -2
  74. package/dist/lib/workers/embeddings/granite.js +4 -3
  75. package/dist/lib/workers/embeddings/mlx-client.js +59 -16
  76. package/dist/lib/workers/orchestrator.js +39 -8
  77. package/dist/lib/workers/pool.js +150 -83
  78. package/dist/lib/workers/process-child.js +11 -2
  79. package/dist/lib/workers/serialized-handler.js +10 -0
  80. package/dist/lib/workers/worker.js +13 -4
  81. package/mlx-embed-server/server.py +21 -3
  82. package/mlx-embed-server/summarizer.py +8 -0
  83. package/package.json +6 -3
  84. package/plugins/grepmax/.claude-plugin/plugin.json +1 -1
  85. package/plugins/grepmax/hooks/start.js +3 -170
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OperationCoordinator = exports.OperationClosedError = exports.OperationBusyError = void 0;
13
+ class OperationBusyError extends Error {
14
+ constructor(operation) {
15
+ super(`daemon busy: exclusive operation ${operation} is pending`);
16
+ this.code = "DAEMON_BUSY";
17
+ this.name = "OperationBusyError";
18
+ }
19
+ }
20
+ exports.OperationBusyError = OperationBusyError;
21
+ class OperationClosedError extends Error {
22
+ constructor(message = "daemon is closing") {
23
+ super(message);
24
+ this.code = "DAEMON_CLOSING";
25
+ this.name = "OperationClosedError";
26
+ }
27
+ }
28
+ exports.OperationClosedError = OperationClosedError;
29
+ function abortError(reason) {
30
+ if (reason instanceof Error)
31
+ return reason;
32
+ const error = new Error("Aborted");
33
+ error.name = "AbortError";
34
+ return error;
35
+ }
36
+ class OperationCoordinator {
37
+ constructor() {
38
+ this.state = { kind: "open" };
39
+ this.controllers = new Set();
40
+ this.activeTasks = new Set();
41
+ this.sharedTasks = new Set();
42
+ this.closePromise = null;
43
+ }
44
+ get status() {
45
+ return this.state.kind;
46
+ }
47
+ get activeCount() {
48
+ return this.activeTasks.size;
49
+ }
50
+ runShared(_name, signal, fn) {
51
+ try {
52
+ this.assertSharedAdmission();
53
+ }
54
+ catch (error) {
55
+ return Promise.reject(error);
56
+ }
57
+ const controller = new AbortController();
58
+ const unlink = this.linkSignal(signal, controller);
59
+ this.controllers.add(controller);
60
+ const task = (() => __awaiter(this, void 0, void 0, function* () {
61
+ if (controller.signal.aborted) {
62
+ throw abortError(controller.signal.reason);
63
+ }
64
+ return fn(controller.signal);
65
+ }))();
66
+ this.activeTasks.add(task);
67
+ this.sharedTasks.add(task);
68
+ const cleanup = () => {
69
+ unlink();
70
+ this.controllers.delete(controller);
71
+ this.activeTasks.delete(task);
72
+ this.sharedTasks.delete(task);
73
+ };
74
+ void task.then(cleanup, cleanup);
75
+ return task;
76
+ }
77
+ runExclusive(name, quiesce, fn) {
78
+ if (this.state.kind === "closing" || this.state.kind === "closed") {
79
+ return Promise.reject(new OperationClosedError());
80
+ }
81
+ if (this.state.kind !== "open") {
82
+ const current = "name" in this.state ? this.state.name : "unknown operation";
83
+ return Promise.reject(new OperationBusyError(current));
84
+ }
85
+ this.state = { kind: "exclusive-pending", name };
86
+ const controller = new AbortController();
87
+ this.controllers.add(controller);
88
+ const task = (() => __awaiter(this, void 0, void 0, function* () {
89
+ try {
90
+ yield quiesce();
91
+ yield Promise.allSettled([...this.sharedTasks]);
92
+ if (controller.signal.aborted) {
93
+ throw abortError(controller.signal.reason);
94
+ }
95
+ if (this.state.kind === "closing" || this.state.kind === "closed") {
96
+ throw new OperationClosedError();
97
+ }
98
+ this.state = { kind: "exclusive", name };
99
+ return yield fn(controller.signal);
100
+ }
101
+ finally {
102
+ this.controllers.delete(controller);
103
+ if (this.state.kind === "exclusive" ||
104
+ this.state.kind === "exclusive-pending") {
105
+ this.state = { kind: "open" };
106
+ }
107
+ }
108
+ }))();
109
+ this.activeTasks.add(task);
110
+ const cleanup = () => this.activeTasks.delete(task);
111
+ void task.then(cleanup, cleanup);
112
+ return task;
113
+ }
114
+ close(reason = new OperationClosedError()) {
115
+ if (this.closePromise)
116
+ return this.closePromise;
117
+ this.state = { kind: "closing" };
118
+ for (const controller of this.controllers)
119
+ controller.abort(reason);
120
+ const tasks = [...this.activeTasks];
121
+ this.closePromise = Promise.allSettled(tasks).then(() => {
122
+ this.state = { kind: "closed" };
123
+ });
124
+ return this.closePromise;
125
+ }
126
+ assertSharedAdmission() {
127
+ if (this.state.kind === "closing" || this.state.kind === "closed") {
128
+ throw new OperationClosedError();
129
+ }
130
+ if (this.state.kind === "exclusive" ||
131
+ this.state.kind === "exclusive-pending") {
132
+ throw new OperationBusyError(this.state.name);
133
+ }
134
+ }
135
+ linkSignal(source, target) {
136
+ if (!source)
137
+ return () => { };
138
+ const abort = () => target.abort(source.reason);
139
+ if (source.aborted)
140
+ abort();
141
+ else
142
+ source.addEventListener("abort", abort, { once: true });
143
+ return () => source.removeEventListener("abort", abort);
144
+ }
145
+ }
146
+ exports.OperationCoordinator = OperationCoordinator;
@@ -0,0 +1,106 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PathContainmentError = void 0;
37
+ exports.isPathWithin = isPathWithin;
38
+ exports.resolveContainedPath = resolveContainedPath;
39
+ exports.resolveContainedFile = resolveContainedFile;
40
+ const fs = __importStar(require("node:fs"));
41
+ const path = __importStar(require("node:path"));
42
+ class PathContainmentError extends Error {
43
+ constructor(root, candidate) {
44
+ super(`Path is outside project root: ${candidate}`);
45
+ this.root = root;
46
+ this.candidate = candidate;
47
+ this.code = "PATH_OUTSIDE_PROJECT";
48
+ this.name = "PathContainmentError";
49
+ }
50
+ }
51
+ exports.PathContainmentError = PathContainmentError;
52
+ function isWithinResolved(root, candidate) {
53
+ const relative = path.relative(root, candidate);
54
+ return (relative === "" ||
55
+ (relative !== ".." &&
56
+ !relative.startsWith(`..${path.sep}`) &&
57
+ !path.isAbsolute(relative)));
58
+ }
59
+ function isPathWithin(root, candidate) {
60
+ return isWithinResolved(path.resolve(root), path.resolve(candidate));
61
+ }
62
+ function canonicalizeExistingPath(candidate) {
63
+ let existing = candidate;
64
+ while (!fs.existsSync(existing)) {
65
+ const parent = path.dirname(existing);
66
+ if (parent === existing)
67
+ return candidate;
68
+ existing = parent;
69
+ }
70
+ const canonicalExisting = fs.realpathSync(existing);
71
+ const remainder = path.relative(existing, candidate);
72
+ return path.resolve(canonicalExisting, remainder);
73
+ }
74
+ function resolveContainedPath(root, input, options = {}) {
75
+ if (input.includes("\0")) {
76
+ throw new PathContainmentError(path.resolve(root), input);
77
+ }
78
+ const resolvedRoot = path.resolve(root);
79
+ const candidate = path.isAbsolute(input)
80
+ ? path.resolve(input)
81
+ : path.resolve(resolvedRoot, input);
82
+ if (!isWithinResolved(resolvedRoot, candidate) ||
83
+ (options.allowRoot === false && candidate === resolvedRoot)) {
84
+ throw new PathContainmentError(resolvedRoot, candidate);
85
+ }
86
+ if (options.verifyExistingTarget) {
87
+ const canonicalRoot = fs.realpathSync(resolvedRoot);
88
+ const canonicalCandidate = canonicalizeExistingPath(candidate);
89
+ if (!isWithinResolved(canonicalRoot, canonicalCandidate)) {
90
+ throw new PathContainmentError(resolvedRoot, candidate);
91
+ }
92
+ }
93
+ return candidate;
94
+ }
95
+ /** Resolve an existing regular file and return its canonical, contained path. */
96
+ function resolveContainedFile(root, input) {
97
+ const candidate = resolveContainedPath(root, input);
98
+ const resolvedRoot = path.resolve(root);
99
+ const canonicalRoot = fs.realpathSync(resolvedRoot);
100
+ const canonicalCandidate = fs.realpathSync(candidate);
101
+ if (!isWithinResolved(canonicalRoot, canonicalCandidate) ||
102
+ !fs.statSync(canonicalCandidate).isFile()) {
103
+ throw new PathContainmentError(resolvedRoot, candidate);
104
+ }
105
+ return canonicalCandidate;
106
+ }
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.killProcess = killProcess;
13
+ exports.terminateProcessGroup = terminateProcessGroup;
13
14
  const watcher_store_1 = require("./watcher-store");
14
15
  /**
15
16
  * Send SIGTERM, wait up to 3s, then SIGKILL if still alive.
@@ -43,3 +44,46 @@ function killProcess(pid) {
43
44
  return !(0, watcher_store_1.isProcessRunning)(pid);
44
45
  });
45
46
  }
47
+ function isProcessGroupRunning(pgid) {
48
+ try {
49
+ process.kill(-pgid, 0);
50
+ return true;
51
+ }
52
+ catch (error) {
53
+ return error.code === "EPERM";
54
+ }
55
+ }
56
+ function terminateProcessGroup(pgid_1) {
57
+ return __awaiter(this, arguments, void 0, function* (pgid, options = {}) {
58
+ var _a, _b;
59
+ const termTimeoutMs = (_a = options.termTimeoutMs) !== null && _a !== void 0 ? _a : 3000;
60
+ const killTimeoutMs = (_b = options.killTimeoutMs) !== null && _b !== void 0 ? _b : 1000;
61
+ try {
62
+ process.kill(-pgid, "SIGTERM");
63
+ }
64
+ catch (error) {
65
+ if (error.code === "ESRCH")
66
+ return true;
67
+ return false;
68
+ }
69
+ const waitForExit = (timeoutMs) => __awaiter(this, void 0, void 0, function* () {
70
+ const attempts = Math.max(1, Math.ceil(timeoutMs / 100));
71
+ for (let i = 0; i < attempts; i++) {
72
+ if (!isProcessGroupRunning(pgid))
73
+ return true;
74
+ yield new Promise((resolve) => setTimeout(resolve, 100));
75
+ }
76
+ return !isProcessGroupRunning(pgid);
77
+ });
78
+ if (yield waitForExit(termTimeoutMs))
79
+ return true;
80
+ try {
81
+ process.kill(-pgid, "SIGKILL");
82
+ }
83
+ catch (error) {
84
+ if (error.code === "ESRCH")
85
+ return true;
86
+ }
87
+ return waitForExit(killTimeoutMs);
88
+ });
89
+ }