grepmax 0.16.0 → 0.16.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.
@@ -0,0 +1,91 @@
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.languageOf = languageOf;
37
+ exports.groupByLanguage = groupByLanguage;
38
+ const path = __importStar(require("node:path"));
39
+ const EXTENSION_TO_LANGUAGE = {
40
+ ".ts": "ts",
41
+ ".tsx": "ts",
42
+ ".js": "js",
43
+ ".jsx": "js",
44
+ ".mjs": "js",
45
+ ".cjs": "js",
46
+ ".py": "py",
47
+ ".swift": "swift",
48
+ ".kt": "kotlin",
49
+ ".kts": "kotlin",
50
+ ".go": "go",
51
+ ".rs": "rust",
52
+ ".rb": "ruby",
53
+ ".java": "java",
54
+ ".c": "c",
55
+ ".h": "c",
56
+ ".cpp": "cpp",
57
+ ".cc": "cpp",
58
+ ".hpp": "cpp",
59
+ ".cs": "csharp",
60
+ ".php": "php",
61
+ ".lua": "lua",
62
+ ".sh": "bash",
63
+ ".bash": "bash",
64
+ ".zsh": "bash",
65
+ ".sql": "sql",
66
+ ".md": "md",
67
+ ".mdx": "md",
68
+ ".json": "json",
69
+ ".yaml": "yaml",
70
+ ".yml": "yaml",
71
+ ".toml": "toml",
72
+ };
73
+ function languageOf(filePath) {
74
+ const ext = path.extname(filePath).toLowerCase();
75
+ if (EXTENSION_TO_LANGUAGE[ext])
76
+ return EXTENSION_TO_LANGUAGE[ext];
77
+ const fallback = ext.replace(/^\./, "");
78
+ return fallback || "unknown";
79
+ }
80
+ function groupByLanguage(chunks) {
81
+ const out = new Map();
82
+ for (const c of chunks) {
83
+ const lang = languageOf(c.path);
84
+ const arr = out.get(lang);
85
+ if (arr)
86
+ arr.push(c);
87
+ else
88
+ out.set(lang, [c]);
89
+ }
90
+ return out;
91
+ }
@@ -48,6 +48,8 @@ exports.getProject = getProject;
48
48
  exports.removeProject = removeProject;
49
49
  exports.getParentProject = getParentProject;
50
50
  exports.getChildProjects = getChildProjects;
51
+ exports.resolveRootOrExit = resolveRootOrExit;
52
+ exports.resolveProjectRoot = resolveProjectRoot;
51
53
  const fs = __importStar(require("node:fs"));
52
54
  const path = __importStar(require("node:path"));
53
55
  const proper_lockfile_1 = __importDefault(require("proper-lockfile"));
@@ -126,3 +128,44 @@ function getChildProjects(root) {
126
128
  const prefix = root.endsWith("/") ? root : `${root}/`;
127
129
  return loadRegistry().filter((e) => e.root !== root && e.root.startsWith(prefix));
128
130
  }
131
+ /**
132
+ * Resolve a `--root` argument with cwd fallback, printing the helper's
133
+ * error message and setting process.exitCode = 1 on failure. Returns
134
+ * null when the caller should bail out. Used at command entry points.
135
+ */
136
+ function resolveRootOrExit(arg) {
137
+ if (!arg)
138
+ return process.cwd();
139
+ try {
140
+ return resolveProjectRoot(arg);
141
+ }
142
+ catch (err) {
143
+ console.error(err instanceof Error ? err.message : String(err));
144
+ process.exitCode = 1;
145
+ return null;
146
+ }
147
+ }
148
+ /**
149
+ * Resolve a `--root` argument that may be either a path or a registered
150
+ * project name. Throws on no-match or duplicate-name so callers can
151
+ * report a uniform error.
152
+ */
153
+ function resolveProjectRoot(arg) {
154
+ if (arg.includes("/") || arg.includes("\\"))
155
+ return path.resolve(arg);
156
+ const resolved = path.resolve(arg);
157
+ if (fs.existsSync(resolved))
158
+ return resolved;
159
+ const matches = loadRegistry().filter((p) => p.name === arg);
160
+ if (matches.length === 1)
161
+ return matches[0].root;
162
+ if (matches.length === 0) {
163
+ const all = loadRegistry();
164
+ const list = all.length > 0
165
+ ? all.map((p) => ` ${p.name.padEnd(24)} ${p.root}`).join("\n")
166
+ : " (none registered)";
167
+ throw new Error(`No registered project named "${arg}".\nAvailable:\n${list}`);
168
+ }
169
+ const paths = matches.map((p) => ` ${p.root}`).join("\n");
170
+ throw new Error(`Multiple registered projects named "${arg}":\n${paths}\nPass an absolute path to disambiguate.`);
171
+ }
@@ -0,0 +1,104 @@
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.resolveScope = resolveScope;
37
+ exports.buildScopeWhere = buildScopeWhere;
38
+ const path = __importStar(require("node:path"));
39
+ const filter_builder_1 = require("./filter-builder");
40
+ function toArray(value) {
41
+ if (value === undefined)
42
+ return [];
43
+ const arr = Array.isArray(value) ? value : [value];
44
+ // Support comma-separated values within each occurrence so agents can pass
45
+ // either `--in a --in b` or `--in a,b` interchangeably.
46
+ return arr
47
+ .flatMap((v) => v.split(","))
48
+ .map((v) => v.trim())
49
+ .filter(Boolean);
50
+ }
51
+ function joinSubpath(projectRoot, sub) {
52
+ const rootWithSlash = projectRoot.endsWith("/") ? projectRoot : `${projectRoot}/`;
53
+ if (path.isAbsolute(sub))
54
+ return sub.endsWith("/") ? sub : `${sub}/`;
55
+ if (sub.startsWith(rootWithSlash))
56
+ return sub.endsWith("/") ? sub : `${sub}/`;
57
+ const joined = path.join(rootWithSlash, sub);
58
+ return joined.endsWith("/") ? joined : `${joined}/`;
59
+ }
60
+ function resolveScope(opts) {
61
+ const { projectRoot } = opts;
62
+ const ins = toArray(opts.in);
63
+ const excludes = toArray(opts.exclude);
64
+ const projectPrefix = projectRoot.endsWith("/")
65
+ ? projectRoot
66
+ : `${projectRoot}/`;
67
+ const inPrefixesAll = ins.map((v) => joinSubpath(projectRoot, v));
68
+ const excludePrefixes = excludes.map((v) => joinSubpath(projectRoot, v));
69
+ // Collapse a single --in into pathPrefix to keep WHERE clauses simple.
70
+ if (inPrefixesAll.length === 1) {
71
+ return {
72
+ pathPrefix: inPrefixesAll[0],
73
+ inPrefixes: [],
74
+ excludePrefixes,
75
+ };
76
+ }
77
+ return {
78
+ pathPrefix: projectPrefix,
79
+ inPrefixes: inPrefixesAll,
80
+ excludePrefixes,
81
+ };
82
+ }
83
+ /**
84
+ * Compose a SQL WHERE clause that AND-applies the resolved scope to an
85
+ * existing condition. Used by symbol commands that build their own table
86
+ * queries (peek/extract/similar/related) instead of going through
87
+ * Searcher.buildWhereClause or GraphBuilder.scopeWhere.
88
+ */
89
+ function buildScopeWhere(scope, condition) {
90
+ const parts = [];
91
+ if (condition)
92
+ parts.push(condition);
93
+ parts.push(`path LIKE '${(0, filter_builder_1.escapeSqlString)(scope.pathPrefix)}%'`);
94
+ for (const ex of scope.excludePrefixes) {
95
+ parts.push(`path NOT LIKE '${(0, filter_builder_1.escapeSqlString)(ex)}%'`);
96
+ }
97
+ if (scope.inPrefixes.length > 0) {
98
+ const ors = scope.inPrefixes
99
+ .map((p) => `path LIKE '${(0, filter_builder_1.escapeSqlString)(p)}%'`)
100
+ .join(" OR ");
101
+ parts.push(`(${ors})`);
102
+ }
103
+ return parts.join(" AND ");
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grepmax",
3
- "version": "0.16.0",
3
+ "version": "0.16.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.16.0",
3
+ "version": "0.16.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",
@@ -176,7 +176,7 @@ async function main() {
176
176
  hookSpecificOutput: {
177
177
  hookEventName: "SessionStart",
178
178
  additionalContext:
179
- 'gmax ready. Use Bash(gmax "query" --agent) for search (one line per result, 89% fewer tokens). Bash(gmax extract <symbol>) for full function body. Bash(gmax peek <symbol>) for quick overview (sig+callers+callees). Bash(gmax trace <symbol>) for call graphs. Bash(gmax skeleton <path>) for structure. Bash(gmax diff [ref]) for git changes. Bash(gmax test <symbol>) for test coverage. Bash(gmax impact <symbol>) for blast radius. Bash(gmax similar <symbol>) for similar code. Bash(gmax context "topic" --budget 4000) for topic summary. Bash(gmax status) to check indexed projects. --agent flag works on search, trace, symbols, related, recent, status, project, extract, peek, diff, test, impact, similar. If search says "not added yet", run Bash(gmax add). If results look stale, run Bash(gmax index) to repair.',
179
+ 'gmax ready. Use Bash(gmax "query" --agent) for search (one line per result, 89% fewer tokens). Bash(gmax extract <symbol>) for full function body. Bash(gmax peek <symbol>) for quick overview (sig+callers+callees). Bash(gmax trace <symbol>) for call graphs. Bash(gmax skeleton <path>) for structure. Bash(gmax diff [ref]) for git changes. Bash(gmax test <symbol>) for test coverage. Bash(gmax impact <symbol>) for blast radius. Bash(gmax similar <symbol>) for similar code. Bash(gmax context "topic" --budget 4000) for topic summary. Bash(gmax status) to check indexed projects. Role tags in results: [DEFI]=definition, [ORCH]=orchestration, [IMPL]=implementation, [DOCS]=docs. --agent flag works on search, trace, symbols, related, recent, status, project, extract, peek, diff, test, impact, similar. If search says "not added yet", run Bash(gmax add). If results look stale, run Bash(gmax index) to repair.',
180
180
  },
181
181
  };
182
182
  process.stdout.write(JSON.stringify(response));