MCPcopy Create free account
hub / github.com/cortexkit/magic-context / runSetup

Function runSetup

packages/cli/src/commands/setup-pi.ts:226–390  ·  view source on GitHub ↗
(options: RunSetupOptions = {})

Source from the content-addressed store, hash-verified

224}
225
226export async function runSetup(options: RunSetupOptions = {}): Promise<number> {
227 const prompts = options.prompts ?? (await getDefaultPrompts());
228 const env = options.env ?? DEFAULT_ENV;
229 const dryRun = options.dryRun === true;
230
231 prompts.intro("Magic Context for Pi — Setup");
232 if (dryRun) {
233 prompts.log.warn("Dry run — no files will be written and no package will be registered.");
234 prompts.log.message(
235 "[dry-run] would migrate legacy Magic Context config before setup reads or writes the shared CortexKit config.",
236 );
237 } else {
238 const migrationWarnings = migrateConfigLocationsForCli(process.cwd(), prompts.log);
239 if (hasUserConfigLocationMigrationRefusal(migrationWarnings)) {
240 prompts.outro(
241 "Setup stopped — resolve the legacy Magic Context user config migration conflict, then rerun setup.",
242 );
243 return 1;
244 }
245 }
246
247 const spinner = prompts.spinner();
248 spinner.start("Checking Pi installation");
249 const pi = env.detectPiBinary();
250 if (!pi) {
251 spinner.stop("Pi not found");
252 prompts.log.warn("Could not find `pi` on PATH or at ~/.pi/bin/pi.");
253 prompts.log.message(
254 "Install Pi first, then rerun setup. If Pi is installed in a custom location, add it to PATH.",
255 );
256 prompts.outro("Setup skipped");
257 return 0;
258 }
259
260 const version = env.getPiVersion(pi.path);
261 spinner.stop(version ? `Pi ${version} detected at ${pi.path}` : `Pi detected at ${pi.path}`);
262
263 // Pi 0.74.0 moved to the `@earendil-works/pi-coding-agent` package scope.
264 // Magic Context's peerDependency targets that scope, so older Pi versions
265 // (on `@mariozechner/pi-coding-agent`) cannot load this extension.
266 const MIN_PI_VERSION = "0.74.0";
267 if (version && comparePiVersion(version, MIN_PI_VERSION) < 0) {
268 prompts.log.warn(
269 `Pi ${version} is older than the required ${MIN_PI_VERSION}.\n` +
270 `Pi 0.74.0 renamed the npm package from \`@mariozechner/pi-coding-agent\` ` +
271 `to \`@earendil-works/pi-coding-agent\`. Magic Context's peer dependency ` +
272 `targets the new scope, so older Pi installs cannot load this extension.\n` +
273 `Run \`pi update --self\` (or \`npm install -g @earendil-works/pi-coding-agent@latest\`) before continuing.`,
274 );
275 const proceed = await prompts.confirm(
276 "Continue with setup anyway? (subagents will fail at runtime)",
277 false,
278 );
279 if (!proceed) {
280 prompts.outro("Setup cancelled — upgrade Pi and try again.");
281 return 0;
282 }
283 }

Callers 1

setup-pi.test.tsFile · 0.90

Calls 15

pickModelFunction · 0.90
runDreamerSetupFunction · 0.90
getDefaultPromptsFunction · 0.85
comparePiVersionFunction · 0.85
writePiSettingsPackageFunction · 0.85
chooseEmbeddingFunction · 0.85
writeMagicContextConfigFunction · 0.70
introMethod · 0.65
warnMethod · 0.65
messageMethod · 0.65

Tested by

no test coverage detected