@boyingliu01/xp-gate 0.14.11 → 0.14.13

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 (44) hide show
  1. package/bin/xp-gate.js +13 -2
  2. package/build-integrity/__tests__/gate-10.test.ts +41 -18
  3. package/build-integrity/__tests__/orchestrator.test.ts +16 -2
  4. package/build-integrity/gate-10.ts +46 -10
  5. package/gate-8.sh +1 -1
  6. package/hooks/pre-commit +56 -1
  7. package/lib/__tests__/doctor.test.js +99 -7
  8. package/lib/__tests__/install-skill.test.js +3 -2
  9. package/lib/__tests__/sprint-discovery.test.ts +1 -1
  10. package/lib/__tests__/ui-detector.test.ts +1 -0
  11. package/lib/__tests__/ui-review.test.ts +19 -6
  12. package/lib/__tests__/update-hooks.test.js +6 -1
  13. package/lib/check.js +59 -18
  14. package/lib/doctor.js +281 -54
  15. package/lib/gate-runner.js +73 -7
  16. package/lib/install-skill.js +2 -0
  17. package/lib/ui-review.ts +32 -8
  18. package/lib/upgrade.js +4 -1
  19. package/mock-policy/AGENTS.md +3 -3
  20. package/mutation/AGENTS.md +3 -3
  21. package/mutation/__tests__/pitest-runner.test.ts +1 -1
  22. package/mutation/__tests__/stryker-runner.test.ts +1 -1
  23. package/mutation/runners/go-mutant-runner.ts +1 -1
  24. package/mutation/runners/mutmut-runner.ts +1 -1
  25. package/mutation/runners/pitest-runner.ts +2 -2
  26. package/mutation/runners/stryker-runner.ts +2 -2
  27. package/package.json +2 -2
  28. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  29. package/plugins/claude-code/skills/delphi-review/AGENTS.md +3 -3
  30. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +3 -3
  31. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +3 -3
  32. package/plugins/opencode/package.json +1 -1
  33. package/plugins/opencode/skills/delphi-review/AGENTS.md +3 -3
  34. package/plugins/opencode/skills/sprint-flow/AGENTS.md +3 -3
  35. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +3 -3
  36. package/plugins/qoder/plugin.json +1 -1
  37. package/plugins/qoder/skills/delphi-review/AGENTS.md +3 -3
  38. package/plugins/qoder/skills/sprint-flow/AGENTS.md +3 -3
  39. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +3 -3
  40. package/principles/AGENTS.md +3 -3
  41. package/principles/__tests__/boy-scout.test.ts +1 -0
  42. package/skills/delphi-review/AGENTS.md +3 -3
  43. package/skills/sprint-flow/AGENTS.md +3 -3
  44. package/skills/test-specification-alignment/AGENTS.md +3 -3
package/lib/check.js CHANGED
@@ -2,7 +2,15 @@
2
2
 
3
3
  const { principles } = require('./principles.js');
4
4
  const { arch } = require('./arch.js');
5
- const { getGateInfo, runGate } = require('./gate-runner.js');
5
+ const { getGateInfo, runGate, resolveAlias, getAliases } = require('./gate-runner.js');
6
+
7
+ /**
8
+ * Resolve a token (gate ID or alias) to a canonical gate ID.
9
+ * Returns null if unresolved.
10
+ */
11
+ function resolveGateToken(token) {
12
+ return resolveAlias(token);
13
+ }
6
14
 
7
15
  function parseCheckArgs(args) {
8
16
  const flags = { all: false, list: false, gateIds: null };
@@ -23,12 +31,13 @@ function parseCheckArgs(args) {
23
31
  else { posArgs.push(arg); i++; }
24
32
  }
25
33
  const rawTarget = posArgs[0] || null;
26
- const isGateNumber = rawTarget && /^\d+$/.test(rawTarget);
34
+ // Try to resolve positional as a gate alias/number
35
+ const resolvedGate = rawTarget ? resolveGateToken(rawTarget) : null;
27
36
  return {
28
37
  ...flags,
29
38
  positionals: posArgs,
30
- pathArg: isGateNumber ? posArgs[1] || null : rawTarget,
31
- gateNumber: isGateNumber ? rawTarget : null,
39
+ pathArg: resolvedGate ? posArgs[1] || null : rawTarget,
40
+ gateNumber: resolvedGate,
32
41
  };
33
42
  }
34
43
 
@@ -41,19 +50,25 @@ async function check(args) {
41
50
  if (opts.gateIds && opts.gateIds.length > 0) return runGatesByIds(opts.gateIds, opts.pathArg);
42
51
 
43
52
  if (!opts.pathArg) {
44
- console.error('Usage: xp-gate check <file_or_directory|gate_number> [options]');
53
+ console.error('Usage: xp-gate check <file_or_directory|gate-or-alias> [options]');
45
54
  console.error('');
46
55
  console.error('Options:');
47
- console.error(' --gates <ids> Run specific gates (comma-separated, e.g. "3,4,6")');
56
+ console.error(' --gates <ids> Run specific gates (comma-separated IDs or aliases, e.g. "version,4,secrets")');
48
57
  console.error(' --all Run all invokable gates');
49
58
  console.error(' --list List all available gates');
50
59
  console.error('');
60
+ console.error('Available Gates:');
61
+ console.error(' 0/version 1/lint 2/duplicates 3/complexity');
62
+ console.error(' 4/principles 5/tests 6/architecture 7/iac');
63
+ console.error(' 8/secrets 9/sast 10/build 11/sprint');
64
+ console.error('');
51
65
  console.error('Examples:');
52
- console.error(' xp-gate check src/ # Run principles + architecture check');
53
- console.error(' xp-gate check 3 # Run Gate 3 (Complexity)');
54
- console.error(' xp-gate check --gates 3,4,6 # Run gates 3, 4, and 6');
55
- console.error(' xp-gate check --all # Run all invokable gates');
56
- console.error(' xp-gate check --list # List available gates');
66
+ console.error(' xp-gate check src/ # Default: principles + architecture');
67
+ console.error(' xp-gate check 3 # Run Gate 3 (Complexity)');
68
+ console.error(' xp-gate check secrets # Run Gate 8 via alias');
69
+ console.error(' xp-gate check . --gates version,4,secrets # Run gates 0, 4, and 8');
70
+ console.error(' xp-gate check . --all # Run all invokable gates');
71
+ console.error(' xp-gate check --list # List available gates');
57
72
  return 1;
58
73
  }
59
74
 
@@ -99,9 +114,28 @@ async function checkAllGates(target) {
99
114
  async function runGatesByIds(gateIds, target) {
100
115
  let failures = 0;
101
116
  let ran = 0;
117
+ const resolvedGates = [];
118
+ const unknown = [];
102
119
 
103
120
  for (const gateId of gateIds) {
104
- const code = await runGate(gateId, target);
121
+ const resolved = resolveGateToken(gateId);
122
+ if (resolved) {
123
+ resolvedGates.push(resolved);
124
+ } else {
125
+ unknown.push(gateId);
126
+ }
127
+ }
128
+
129
+ if (unknown.length > 0) {
130
+ const { getAllGates } = require('./gate-runner.js');
131
+ const allAliases = getAllGates().flatMap(g => g.aliases);
132
+ console.error(`[xp-gate check] Unknown gate(s) in --gates list: ${unknown.join(', ')}`);
133
+ console.error(` Known aliases/IDs: ${allAliases.join(', ')}`);
134
+ return 1;
135
+ }
136
+
137
+ for (const resolvedId of resolvedGates) {
138
+ const code = await runGate(resolvedId, target);
105
139
  if (code !== 0) failures += 1;
106
140
  ran += 1;
107
141
  console.log('');
@@ -123,22 +157,29 @@ function listGates() {
123
157
 
124
158
  console.log('');
125
159
  console.log('XP-Gate Quality Gates:');
126
- console.log('┌──────┬──────────────────────────────┬──────────┬──────────────────────────────────────────┐');
127
- console.log('│ Gate │ Name │ CLI │ Description │');
128
- console.log('├──────┼──────────────────────────────┼──────────┼──────────────────────────────────────────┤');
160
+ console.log('┌──────┬──────────────────────────────┬──────────────────────────────┬──────────┬──────────────────────────────────────────┐');
161
+ console.log('│ Gate │ Name │ Aliases │ CLI │ Description │');
162
+ console.log('├──────┼──────────────────────────────┼──────────────────────────────┼──────────┼──────────────────────────────────────────┤');
129
163
  for (const gate of allGates) {
130
164
  const id = gate.id.padEnd(4);
131
165
  const name = gate.name.slice(0, 28).padEnd(28);
166
+ const aliases = (gate.aliases || []).join(', ').slice(0, 28).padEnd(28);
132
167
  const cli = gate.preCommitOnly ? 'commit' : 'check';
133
168
  const desc = gate.description.slice(0, 40).padEnd(40);
134
- console.log(`│ ${id} │ ${name} │ ${cli.padEnd(8)} │ ${desc} │`);
169
+ console.log(`│ ${id} │ ${name} │ ${aliases} │ ${cli.padEnd(8)} │ ${desc} │`);
135
170
  }
136
- console.log('└──────┴──────────────────────────────┴──────────┴──────────────────────────────────────────┘');
171
+ console.log('└──────┴──────────────────────────────┴──────────────────────────────┴──────────┴──────────────────────────────────────────┘');
137
172
  console.log('');
138
173
  console.log('Legend:');
139
- console.log(' check — invokable via xp-gate check <gate-id>');
174
+ console.log(' check — invokable via xp-gate check <gate-id-or-alias>');
140
175
  console.log(' commit — only runs during git commit (pre-commit hook)');
141
176
  console.log('');
177
+ console.log('Examples:');
178
+ console.log(' xp-gate check . --gates version,principles,secrets');
179
+ console.log(' xp-gate check . --gates 0,4,8');
180
+ console.log(' xp-gate check secrets');
181
+ console.log(' xp-gate check . --all');
182
+ console.log('');
142
183
  return 0;
143
184
  }
144
185
 
package/lib/doctor.js CHANGED
@@ -1,6 +1,9 @@
1
1
  const fs = require('fs');
2
2
  const path = require('path');
3
3
  const { execSync } = require('child_process');
4
+ const { exec } = require('child_process');
5
+ const util = require('util');
6
+ const execAsync = util.promisify(exec);
4
7
  const {
5
8
  HOME_DIR,
6
9
  CONFIG_DIR,
@@ -38,6 +41,29 @@ const SIGNATURES = {
38
41
  'adapter-common.sh': 'detect_project_lang()'
39
42
  };
40
43
 
44
+ /**
45
+ * Hard timeout for all execSync calls in doctor diagnostics.
46
+ * Prevents hanging subprocesses (e.g., missing CLI tools on Windows)
47
+ * from blocking the entire doctor run.
48
+ */
49
+ const EXEC_TIMEOUT_MS = 3000;
50
+
51
+ /**
52
+ * Execute a command with a hard timeout using async exec.
53
+ * Returns { stdout, stderr } on success, null on failure/timeout.
54
+ */
55
+ async function execWithTimeout(cmd, opts = {}) {
56
+ try {
57
+ const { stdout, stderr } = await execAsync(cmd, {
58
+ ...opts,
59
+ timeout: opts.timeout || EXEC_TIMEOUT_MS,
60
+ });
61
+ return { stdout: stdout.trim(), stderr: stderr.trim() };
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
41
67
  function isXpGateFile(filePath, signature) {
42
68
  if (!fs.existsSync(filePath)) return false;
43
69
  try {
@@ -61,45 +87,83 @@ function saveConfig(config) {
61
87
  fs.writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
62
88
  }
63
89
 
64
- function getGitDir() {
90
+ async function getGitDir() {
65
91
  try {
66
- return execSync('git rev-parse --git-dir', { encoding: 'utf8' }).trim();
92
+ const result = await execWithTimeout('git rev-parse --git-dir');
93
+ return result ? result.stdout : null;
67
94
  } catch {
68
95
  return null;
69
96
  }
70
97
  }
71
98
 
72
- function getCurrentHooksPath() {
99
+ /**
100
+ * Synchronous version for --fix code path (runs before async diagnosis).
101
+ * Always includes a 3-second timeout.
102
+ */
103
+ function getGitDirSync() {
73
104
  try {
74
- const result = execSync('git config --global core.hooksPath', {
105
+ return execSync('git rev-parse --git-dir', {
75
106
  encoding: 'utf8',
76
- stdio: ['pipe', 'pipe', 'pipe']
77
- });
78
- return result.trim();
107
+ timeout: EXEC_TIMEOUT_MS,
108
+ stdio: ['pipe', 'pipe', 'pipe'],
109
+ }).trim();
110
+ } catch {
111
+ return null;
112
+ }
113
+ }
114
+
115
+ async function getCurrentHooksPath() {
116
+ const result = await execWithTimeout('git config --global core.hooksPath', {
117
+ stdio: ['pipe', 'pipe', 'pipe']
118
+ });
119
+ return result ? result.stdout : null;
120
+ }
121
+
122
+ /**
123
+ * Synchronous version for --fix code path (runs before async diagnosis).
124
+ * Always includes a 3-second timeout.
125
+ */
126
+ function getCurrentHooksPathSync() {
127
+ try {
128
+ return execSync('git config --global core.hooksPath', {
129
+ encoding: 'utf8',
130
+ timeout: EXEC_TIMEOUT_MS,
131
+ stdio: ['pipe', 'pipe', 'pipe'],
132
+ }).trim();
79
133
  } catch {
80
134
  return null;
81
135
  }
82
136
  }
83
137
 
84
- function checkEnv(checks) {
138
+ /**
139
+ * Check environment dependencies — runs all checks IN PARALLEL.
140
+ * @param {Array} checks — mutated with results
141
+ * @returns {Promise<boolean>} all ok
142
+ */
143
+ async function checkEnv(checks) {
85
144
  const envChecks = [
86
- { name: 'Node.js', cmd: 'node --version', label: null },
87
- { name: 'Git', cmd: 'git --version', label: null },
88
- { name: 'Bash', cmd: 'bash --version', label: null }
145
+ { name: 'Node.js', cmd: 'node --version' },
146
+ { name: 'Git', cmd: 'git --version' },
147
+ { name: 'Bash', cmd: 'bash --version' }
89
148
  ];
90
149
 
150
+ const results = await Promise.allSettled(
151
+ envChecks.map(async (env) => {
152
+ const result = await execWithTimeout(env.cmd, { stdio: ['ignore', 'pipe', 'pipe'] });
153
+ return { name: env.name, result };
154
+ })
155
+ );
156
+
91
157
  let allOk = true;
92
- for (const env of envChecks) {
93
- try {
94
- const output = execSync(env.cmd, {
95
- encoding: 'utf8',
96
- stdio: ['ignore', 'pipe', 'pipe']
97
- });
98
- const version = output.trim().split('\n')[0];
99
- env.label = version;
100
- checks.push({ name: `Environment: ${env.name}`, status: 'PASS', detail: version });
101
- } catch {
102
- checks.push({ name: `Environment: ${env.name}`, status: 'FAIL', detail: 'Not found' });
158
+ for (const entry of envChecks) {
159
+ const settled = results.find(r => r.value && r.value.name === entry.name);
160
+ const version = settled && settled.value && settled.value.result
161
+ ? settled.value.result.stdout.split('\n')[0]
162
+ : null;
163
+ if (version) {
164
+ checks.push({ name: `Environment: ${entry.name}`, status: 'PASS', detail: version });
165
+ } else {
166
+ checks.push({ name: `Environment: ${entry.name}`, status: 'FAIL', detail: 'Not found' });
103
167
  allOk = false;
104
168
  }
105
169
  }
@@ -132,9 +196,9 @@ function checkConfig() {
132
196
  ], issues: 0 };
133
197
  }
134
198
 
135
- function checkLocalHooks(checks) {
199
+ async function checkLocalHooks(checks) {
136
200
  let issues = 0;
137
- const gitDir = getGitDir();
201
+ const gitDir = await getGitDir();
138
202
  if (!gitDir) {
139
203
  checks.push({ name: 'Git repository', status: 'FAIL', detail: 'Not in a git repo' });
140
204
  return 1;
@@ -145,12 +209,12 @@ function checkLocalHooks(checks) {
145
209
  return issues;
146
210
  }
147
211
 
148
- function checkGlobalHooks(checks) {
212
+ async function checkGlobalHooks(checks) {
149
213
  let issues = 0;
150
214
  issues += checkSingleHook(GLOBAL_HOOKS_DIR, 'pre-commit', SIGNATURES['pre-commit'], 'Global hooks', checks);
151
215
  issues += checkSingleHook(GLOBAL_HOOKS_DIR, 'pre-push', SIGNATURES['pre-push'], 'Global hooks', checks);
152
216
 
153
- const hooksPath = getCurrentHooksPath();
217
+ const hooksPath = await getCurrentHooksPath();
154
218
  if (hooksPath === null || hooksPath === '') {
155
219
  checks.push({ name: 'Git core.hooksPath', status: 'FAIL', detail: 'Not set' });
156
220
  issues++;
@@ -188,7 +252,8 @@ const EXPECTED_GATE_SCRIPTS = [
188
252
  'gate-9.sh',
189
253
  ];
190
254
 
191
- function checkAdapters(checks, mode, gitDir) {
255
+ async function checkAdapters(checks, mode, gitDirPromise) {
256
+ const gitDir = typeof gitDirPromise === 'string' ? gitDirPromise : await gitDirPromise;
192
257
  let issues = 0;
193
258
  const adaptersDir = mode === 'local'
194
259
  ? path.join(path.dirname(gitDir || ''), 'githooks', 'adapters')
@@ -224,12 +289,20 @@ function checkAdapters(checks, mode, gitDir) {
224
289
  /**
225
290
  * Build check report for the doctor.
226
291
  * Returns { checks: Array<{name, status, detail}>, issues: number }
292
+ *
293
+ * Uses Promise.allSettled to run independent checks in parallel.
294
+ * Check groups:
295
+ * A) Config-dependent (config, version, templateDir) — sequential (data deps)
296
+ * B) Hooks — depends on config.mode + gitDir
297
+ * C) Adapters — depends on config.mode
298
+ * D) Env + CLI tools — fully independent, run IN PARALLEL
299
+ * E) TUI + Skills — independent, run IN PARALLEL
227
300
  */
228
- function diagnose() {
301
+ async function diagnoseAsync() {
229
302
  const checks = [];
230
303
  let issues = 0;
231
304
 
232
- // --- Check 1: Config file ---
305
+ // --- Phase 1: Config-dependent checks (sequential, data dependencies) ---
233
306
  const configResult = checkConfig();
234
307
  if (configResult.config === null) {
235
308
  return { checks: configResult.checks, issues: configResult.issues };
@@ -238,35 +311,188 @@ function diagnose() {
238
311
  checks.push(...configResult.checks);
239
312
  issues += configResult.issues;
240
313
 
241
- // --- Check 2: Version mismatch ---
314
+ // Version check (sync, no I/O)
242
315
  issues += diagnoseVersion(config, getPackageVersion(), checks);
243
-
244
- // --- Check 3: templateDir validation ---
316
+ // TemplateDir check (sync, no I/O)
245
317
  issues += diagnoseTemplateDir(config, checks);
246
318
 
247
- // --- Check 4: Hooks files ---
248
- if (config.mode === 'local') {
249
- issues += checkLocalHooks(checks);
250
- } else {
251
- issues += checkGlobalHooks(checks);
319
+ // --- Phase 2: Fetch gitDir early (needed by hooks and adapters) ---
320
+ const gitDirPromise = getGitDir();
321
+
322
+ // --- Phase 3: Run independent groups in parallel ---
323
+ // Group A: Hooks (needs config.mode + gitDir)
324
+ const hooksPromise = (async () => {
325
+ if (config.mode === 'local') {
326
+ return checkLocalHooks(checks);
327
+ }
328
+ return checkGlobalHooks(checks);
329
+ })();
330
+
331
+ // Group B: Adapters (needs config.mode + gitDir)
332
+ const adaptersPromise = checkAdapters(checks, config.mode, gitDirPromise);
333
+
334
+ // Group C: Environment checks + CLI tools — fully parallel
335
+ const envPromise = checkEnv(checks);
336
+ const cliToolsPromise = diagnoseCliToolsAsync(checks);
337
+
338
+ // Group D: TUI + Skills (independent)
339
+ const tuiPromise = diagnoseTuiRegistration(checks);
340
+ const skillsPromise = diagnoseInstalledSkills(config, checks);
341
+
342
+ // Wait for ALL parallel groups
343
+ const results = await Promise.allSettled([
344
+ hooksPromise,
345
+ adaptersPromise,
346
+ envPromise,
347
+ cliToolsPromise,
348
+ tuiPromise,
349
+ skillsPromise,
350
+ ]);
351
+
352
+ // Collect issue counts from settled promises
353
+ for (const result of results) {
354
+ if (result.status === 'fulfilled' && typeof result.value === 'number') {
355
+ issues += result.value;
356
+ }
252
357
  }
253
358
 
254
- // --- Check 5: Adapters directory ---
255
- issues += checkAdapters(checks, config.mode, getGitDir());
359
+ return { checks, issues };
360
+ }
256
361
 
257
- // --- Check 6: Environment dependencies ---
258
- checkEnv(checks);
362
+ /**
363
+ * Async CLI tools check — runs each tool detection with a 3-second timeout
364
+ * using async exec. Tools are checked IN PARALLEL via Promise.allSettled.
365
+ * This mirrors checkCliTool logic but uses async exec for parallelization.
366
+ *
367
+ * @param {Array} checks
368
+ * @returns {Promise<number>} issue count
369
+ */
370
+ async function diagnoseCliToolsAsync(checks) {
371
+ let issues = 0;
372
+ const platform = process.platform;
373
+ const isWindows = platform === 'win32';
374
+
375
+ // Build parallel checks for each tool
376
+ const toolChecks = GATE_CLI_TOOLS.map(async (entry) => {
377
+ const toolName = entry.tool;
378
+ const result = await detectCliToolAsync(toolName, isWindows);
379
+ return { entry, toolName, result };
380
+ });
381
+
382
+ // Run ALL tool checks in parallel
383
+ const results = await Promise.allSettled(toolChecks);
384
+
385
+ // Collect results (maintain original order)
386
+ for (const settled of results) {
387
+ if (settled.status === 'rejected') continue;
388
+ const { entry, result } = settled.value;
389
+ const gateLabels = entry.gates.join(', ');
259
390
 
260
- // --- Check 7: CLI tools for quality gates (Issue #261) ---
261
- issues += diagnoseCliTools(checks);
391
+ if (result.available) {
392
+ checks.push({
393
+ name: `CLI tool: ${entry.tool} (${gateLabels})`,
394
+ status: 'PASS',
395
+ detail: result.version || 'available',
396
+ });
397
+ } else {
398
+ const installCmd = getToolInstallCmd(entry, platform);
399
+ checks.push({
400
+ name: `CLI tool: ${entry.tool} (${gateLabels})`,
401
+ status: 'WARN',
402
+ detail: `Not found — install with: ${installCmd}`,
403
+ });
404
+ issues++;
405
+ }
406
+ }
262
407
 
263
- // --- Check 8: TUI auto-registration ---
264
- issues += diagnoseTuiRegistration(checks);
408
+ return issues;
409
+ }
265
410
 
266
- // --- Check 9: Installed skills version consistency (#332) ---
267
- issues += diagnoseInstalledSkills(config, checks);
411
+ /**
412
+ * Async CLI tool detection — mirrors checkCliTool but uses async exec
413
+ * with a hard 3-second timeout per subprocess call.
414
+ *
415
+ * @param {string} toolName
416
+ * @param {boolean} isWindows
417
+ * @returns {Promise<{available: boolean, version?: string, path?: string}>}
418
+ */
419
+ async function detectCliToolAsync(toolName, isWindows) {
420
+ const shell = isWindows ? 'cmd.exe' : '/bin/sh';
421
+ const execOpts = { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], shell, timeout: EXEC_TIMEOUT_MS };
422
+
423
+ // Step 1: Locate tool via which/where (async, 3s timeout)
424
+ const locator = isWindows ? 'where' : 'which';
425
+ const locatorResult = await execWithTimeout(`${locator} ${toolName}`, execOpts);
426
+ if (locatorResult && locatorResult.stdout) {
427
+ const resolvedPath = locatorResult.stdout.split('\n')[0].trim();
428
+ if (resolvedPath) {
429
+ const version = await getVersionAsync(resolvedPath, isWindows);
430
+ return { available: true, path: resolvedPath, version };
431
+ }
432
+ }
268
433
 
269
- return { checks, issues };
434
+ // Step 2: Direct exec fallback (async, 3s timeout)
435
+ const fallbackCmd = isWindows
436
+ ? `${toolName} --version`
437
+ : `${toolName} --version 2>/dev/null || ${toolName} -v 2>/dev/null`;
438
+ const fallbackResult = await execWithTimeout(fallbackCmd, execOpts);
439
+ if (fallbackResult && fallbackResult.stdout) {
440
+ return { available: true, path: toolName, version: fallbackResult.stdout.split('\n')[0] };
441
+ }
442
+
443
+ // Step 3: Check local fallback paths (sync fs, no exec)
444
+ const localPaths = getLocalFallbackPathsSync(toolName, isWindows);
445
+ for (const localPath of localPaths) {
446
+ if (!fs.existsSync(localPath)) continue;
447
+ const version = await getVersionAsync(localPath, isWindows);
448
+ if (version) {
449
+ return { available: true, path: localPath, version };
450
+ }
451
+ }
452
+
453
+ return { available: false };
454
+ }
455
+
456
+ /**
457
+ * Get version string from a tool path using async exec with 3s timeout.
458
+ */
459
+ async function getVersionAsync(execPath, isWindows) {
460
+ const fallbackCmd = isWindows
461
+ ? `"${execPath}" --version`
462
+ : `"${execPath}" --version 2>/dev/null || "${execPath}" -v 2>/dev/null`;
463
+ const result = await execWithTimeout(fallbackCmd);
464
+ return result && result.stdout ? result.stdout.split('\n')[0] : undefined;
465
+ }
466
+
467
+ /**
468
+ * Get local fallback paths for CLI tool (sync, no exec).
469
+ * Mirrors getLocalFallbackPaths from detect-deps.js.
470
+ */
471
+ function getLocalFallbackPathsSync(toolName, isWindows) {
472
+ const os = require('os');
473
+ const home = os.homedir();
474
+ const paths = [path.join(home, '.local', 'bin', toolName)];
475
+
476
+ if (isWindows) {
477
+ const appData = process.env.APPDATA || path.join(home, 'AppData', 'Roaming');
478
+ const localAppData = process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local');
479
+ paths.push(
480
+ path.join(appData, 'npm', `${toolName}.cmd`),
481
+ path.join(home, '.local', 'bin', `${toolName}.exe`),
482
+ );
483
+ const pythonBase = path.join(localAppData, 'Programs', 'Python');
484
+ if (fs.existsSync(pythonBase)) {
485
+ try {
486
+ for (const entry of fs.readdirSync(pythonBase)) {
487
+ if (entry.startsWith('Python')) {
488
+ paths.push(path.join(pythonBase, entry, 'Scripts', `${toolName}.exe`));
489
+ }
490
+ }
491
+ } catch { /* skip */ }
492
+ }
493
+ }
494
+
495
+ return paths;
270
496
  }
271
497
 
272
498
  /**
@@ -426,7 +652,8 @@ function fixMissingHooks(mode, srcDir, hooksDir) {
426
652
  function fixCoreHooksPath(globalHooksDir) {
427
653
  try {
428
654
  execSync(`git config --global core.hooksPath "${globalHooksDir}"`, {
429
- stdio: ['pipe', 'pipe', 'pipe']
655
+ stdio: ['pipe', 'pipe', 'pipe'],
656
+ timeout: EXEC_TIMEOUT_MS,
430
657
  });
431
658
  console.log(` ✓ Set core.hooksPath to ${globalHooksDir}`);
432
659
  return true;
@@ -500,7 +727,7 @@ function fixConfigMismatches(config) {
500
727
  function fixHooksByMode(config, srcDir) {
501
728
  let fixed = false;
502
729
  if (config.mode === 'local') {
503
- const gitDir = getGitDir();
730
+ const gitDir = getGitDirSync();
504
731
  if (gitDir) {
505
732
  const hooksDir = path.join(gitDir, 'hooks');
506
733
  fixed = fixMissingHooks('local', srcDir, hooksDir) || fixed;
@@ -513,7 +740,7 @@ function fixHooksByMode(config, srcDir) {
513
740
 
514
741
  function fixGlobalHooksPath(config) {
515
742
  if (config.mode !== 'global') return false;
516
- const hooksPath = getCurrentHooksPath();
743
+ const hooksPath = getCurrentHooksPathSync();
517
744
  if (hooksPath !== GLOBAL_HOOKS_DIR) {
518
745
  return fixCoreHooksPath(GLOBAL_HOOKS_DIR);
519
746
  }
@@ -522,7 +749,7 @@ function fixGlobalHooksPath(config) {
522
749
 
523
750
  function getAdaptersDirByMode(config) {
524
751
  return config.mode === 'local'
525
- ? path.join(path.dirname(getGitDir() || ''), 'githooks', 'adapters')
752
+ ? path.join(path.dirname(getGitDirSync() || ''), 'githooks', 'adapters')
526
753
  : GLOBAL_ADAPTERS_DIR;
527
754
  }
528
755
 
@@ -842,7 +1069,7 @@ async function doctor(args) {
842
1069
  fixIssues(null, config);
843
1070
  }
844
1071
 
845
- const { checks, issues: diagnosedIssues } = diagnose();
1072
+ const { checks, issues: diagnosedIssues } = await diagnoseAsync();
846
1073
  let issues = diagnosedIssues;
847
1074
 
848
1075
  printReport(checks);
@@ -860,7 +1087,7 @@ async function doctor(args) {
860
1087
  // Re-run diagnosis after fix to report updated status
861
1088
  if (fixMode && isActiveMode(config)) {
862
1089
  console.log('\nRe-running diagnosis after fix...');
863
- const { checks: postChecks } = diagnose();
1090
+ const { checks: postChecks } = await diagnoseAsync();
864
1091
  printReport(postChecks);
865
1092
  }
866
1093