nanocoder
nanocoder copied to clipboard
[Bug] Git tool availability is checked with blocking git/gh spawns while the tool registry is imported
Summary
source/tools/index.ts calls getGitTools() when the module is imported. That runs git --version, git rev-parse --is-inside-work-tree and gh --version with execSync, so three child processes block startup before the first frame in both the TUI and --plain.
Steps to reproduce
pnpm run build- From the repo root run:
node --input-type=module -e "
import cp from 'node:child_process';
import {syncBuiltinESMExports} from 'node:module';
const o = cp.execSync;
cp.execSync = (c, ...a) => { console.log('execSync:', c); return o(c, ...a); };
syncBuiltinESMExports();
await import('./dist/tools/index.js');"
Expected behaviour
Importing the tool registry spawns no processes. Git availability is checked lazily or asynchronously.
Actual behaviour
execSync: git --version
execSync: git rev-parse --is-inside-work-tree
execSync: gh --version
Measured with a timing wrapper: 42 ms + 48 ms + 105 ms, about 195 ms blocked at import. Outside a git repo it is 2 spawns, about 90 ms. The result is also fixed at import time from process.cwd(), so it is never re-evaluated.
Environment
- OS: Windows 11 (10.0.26300)
- Node: 22.22.3, pnpm 11.0.9
- Nanocoder: 1.31.0 (main at be428fc7)
Suggested fix
source/tools/index.ts:57(const conditionalTools = [...getGitTools()]): do not evaluate at import time.source/tools/git/utils.ts:63,75,87andsource/tools/git/index.ts:29,43: cache the result of one async check, run it in the background after the first frame, or decide availability when tools are first listed.- Keep the behaviour: git tools offered inside a repo, hidden outside. Tests:
source/tools/git/*.spec.ts,tool-manager.spec.ts.
hi @addyCooks should i take this one?