(opts: RunInstallerOptions)
| 82 | } |
| 83 | |
| 84 | export async function runInstallerWithOptions(opts: RunInstallerOptions): Promise<void> { |
| 85 | const clack = await importESM('@clack/prompts'); |
| 86 | |
| 87 | clack.intro(`CodeGraph v${getVersion()}`); |
| 88 | |
| 89 | // --yes implies all defaults; explicit flags still win. |
| 90 | const useDefaults = opts.yes === true; |
| 91 | |
| 92 | // Step 1: which agent targets? Asked FIRST so the user knows what |
| 93 | // they're committing to before we touch npm or disk. Detection |
| 94 | // probes the user-provided location if known, else 'global' as the |
| 95 | // most common default — labels are a hint, not load-bearing. |
| 96 | const detectionLocation: Location = opts.location ?? 'global'; |
| 97 | const targets = await resolveTargets(clack, opts, detectionLocation, useDefaults); |
| 98 | if (targets.length === 0) { |
| 99 | clack.outro('No agent targets selected — nothing to do.'); |
| 100 | return; |
| 101 | } |
| 102 | |
| 103 | // Step 2: install the codegraph npm package on PATH (always offered; |
| 104 | // matches existing behavior). Skipped when --yes (assume present). |
| 105 | if (!useDefaults) { |
| 106 | const shouldInstallGlobally = await clack.confirm({ |
| 107 | message: 'Install the codegraph CLI on your PATH? (Required so agents can launch the MCP server)', |
| 108 | initialValue: true, |
| 109 | }); |
| 110 | if (clack.isCancel(shouldInstallGlobally)) { |
| 111 | clack.cancel('Installation cancelled.'); |
| 112 | process.exit(0); |
| 113 | } |
| 114 | if (shouldInstallGlobally) { |
| 115 | const s = clack.spinner(); |
| 116 | s.start('Installing codegraph CLI...'); |
| 117 | try { |
| 118 | execSync('npm install -g @colbymchenry/codegraph', { stdio: 'pipe', windowsHide: true }); |
| 119 | s.stop('Installed codegraph CLI on PATH'); |
| 120 | } catch { |
| 121 | s.stop('Could not install (permission denied)'); |
| 122 | clack.log.warn('Try: sudo npm install -g @colbymchenry/codegraph'); |
| 123 | } |
| 124 | } else { |
| 125 | clack.log.info('Skipped CLI install — agents will not be able to launch the MCP server without it'); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | // Step 3: where the per-agent config files should land. |
| 130 | let location: Location; |
| 131 | if (opts.location) { |
| 132 | location = opts.location; |
| 133 | } else if (useDefaults) { |
| 134 | location = 'global'; |
| 135 | } else { |
| 136 | // If every selected target is global-only (e.g. Codex), skip the |
| 137 | // prompt and force user-wide — project-local would just produce |
| 138 | // skip warnings. |
| 139 | const allGlobalOnly = targets.every((t) => !t.supportsLocation('local')); |
| 140 | if (allGlobalOnly) { |
| 141 | location = 'global'; |
no test coverage detected