MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / runInstallerWithOptions

Function runInstallerWithOptions

src/installer/index.ts:85–301  ·  view source on GitHub ↗
(opts: RunInstallerOptions)

Source from the content-addressed store, hash-verified

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

Callers 2

runInstallerFunction · 0.85
mainFunction · 0.85

Calls 15

getTelemetryFunction · 0.90
maybeOfferBetaSignupFunction · 0.90
getVersionFunction · 0.85
resolveTargetsFunction · 0.85
tildifyFunction · 0.85
warnMethod · 0.80
getStatusMethod · 0.80
hasStoredChoiceMethod · 0.80
setEnabledMethod · 0.80
recordLifecycleMethod · 0.80
flushNowMethod · 0.80
startMethod · 0.65

Tested by

no test coverage detected