-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(hooks): prefer PATH gitnexus in stale hint #1958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -207,6 +207,48 @@ function resolveCliPath() { | |
| return cliPath; | ||
| } | ||
|
|
||
| function commandExistsOnPath(command) { | ||
| const pathValue = process.env.PATH || process.env.Path || process.env.path || ''; | ||
| if (!pathValue) return false; | ||
|
|
||
| const extensions = | ||
| process.platform === 'win32' | ||
| ? Array.from( | ||
| new Set([ | ||
| '', | ||
| '.cmd', | ||
| '.bat', | ||
| '.exe', | ||
| '.ps1', | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2 [code-read] — Fix: On win32, accept |
||
| ...(process.env.PATHEXT || '') | ||
| .split(';') | ||
| .map((ext) => ext.trim().toLowerCase()) | ||
| .filter(Boolean) | ||
| .map((ext) => (ext.startsWith('.') ? ext : `.${ext}`)), | ||
| ]), | ||
| ) | ||
| : ['']; | ||
|
|
||
| for (const dir of pathValue.split(path.delimiter).filter(Boolean)) { | ||
| for (const ext of extensions) { | ||
| try { | ||
| const candidate = path.join(dir, `${command}${ext}`); | ||
| if (!fs.statSync(candidate).isFile()) continue; | ||
| if (process.platform !== 'win32') fs.accessSync(candidate, fs.constants.X_OK); | ||
| return true; | ||
| } catch { | ||
| /* try next candidate */ | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| function buildAnalyzeCommand(hadEmbeddings) { | ||
| const analyzeBin = commandExistsOnPath('gitnexus') ? 'gitnexus' : 'npx gitnexus'; | ||
| return `${analyzeBin} analyze${hadEmbeddings ? ' --embeddings' : ''}`; | ||
| } | ||
|
|
||
| /** | ||
| * Spawn a gitnexus CLI command synchronously. | ||
| * Returns the stderr output (KuzuDB captures stdout at OS level). | ||
|
|
@@ -340,7 +382,7 @@ function handlePostToolUse(input) { | |
| // If HEAD matches last indexed commit, no reindex needed | ||
| if (currentHead && currentHead === lastCommit) return; | ||
|
|
||
| const analyzeCmd = `npx gitnexus analyze${hadEmbeddings ? ' --embeddings' : ''}`; | ||
| const analyzeCmd = buildAnalyzeCommand(hadEmbeddings); | ||
| sendHookResponse( | ||
| 'PostToolUse', | ||
| `GitNexus index is stale (last indexed: ${lastCommit ? lastCommit.slice(0, 7) : 'never'}). ` + | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 [code-read] — This file now has two PATH strategies:
buildAnalyzeCommanduses the new fs PATH walk (L188–227), whilerunGitNexusClistill useswhere/which+ hardcodedgitnexus.cmd(L250–271). They can disagree on edge cases (PATHEXT, non-spawnable shims).Fix: Share one launcher-resolution helper for both the stale hint and CLI spawn paths.