@phi-code-admin/phi-code 0.84.2 → 0.86.0
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.
- package/CHANGELOG.md +100 -0
- package/README.md +95 -126
- package/agents/code.md +1 -0
- package/agents/explore.md +11 -5
- package/agents/plan.md +18 -3
- package/agents/review.md +18 -7
- package/agents/test.md +1 -0
- package/config/routing.example.json +129 -0
- package/config/routing.schema.json +58 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +1 -1
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -1
- package/dist/config.js.map +1 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +3 -3
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +6 -6
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +1 -1
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +2 -2
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +32 -30
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +9 -8
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/utils/pi-user-agent.d.ts.map +1 -1
- package/dist/utils/pi-user-agent.js +4 -1
- package/dist/utils/pi-user-agent.js.map +1 -1
- package/dist/utils/version-check.d.ts +5 -5
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +13 -8
- package/dist/utils/version-check.js.map +1 -1
- package/docs/compaction.md +11 -11
- package/docs/custom-provider.md +4 -4
- package/docs/development.md +2 -2
- package/docs/extensions.md +47 -47
- package/docs/fork-policy.md +63 -0
- package/docs/index.md +7 -7
- package/docs/json.md +3 -3
- package/docs/keybindings.md +5 -5
- package/docs/models.md +6 -6
- package/docs/packages.md +37 -37
- package/docs/prompt-templates.md +4 -4
- package/docs/providers.md +9 -9
- package/docs/quickstart.md +25 -25
- package/docs/rpc.md +3 -3
- package/docs/sdk.md +34 -34
- package/docs/session-format.md +4 -4
- package/docs/sessions.md +11 -11
- package/docs/settings.md +11 -11
- package/docs/shell-aliases.md +2 -2
- package/docs/skills.md +9 -9
- package/docs/terminal-setup.md +7 -7
- package/docs/termux.md +6 -6
- package/docs/themes.md +9 -9
- package/docs/tmux.md +3 -3
- package/docs/tui.md +8 -8
- package/docs/usage.md +40 -40
- package/docs/windows.md +2 -2
- package/examples/sdk/12-full-control.ts +1 -1
- package/extensions/phi/agents.ts +5 -113
- package/extensions/phi/models.ts +170 -49
- package/extensions/phi/orchestrator.ts +44 -37
- package/extensions/phi/providers/agent-def.ts +128 -0
- package/extensions/phi/providers/live-models.ts +31 -1
- package/extensions/phi/providers/opencode-go.ts +7 -3
- package/extensions/phi/setup.ts +9 -0
- package/extensions/phi/skill-loader.ts +46 -25
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager-cli.d.ts","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AA2UtE,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB1E;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAiK3E","sourcesContent":["import chalk from \"chalk\";\nimport { spawn } from \"child_process\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport {\n\tAPP_NAME,\n\tgetAgentDir,\n\tgetSelfUpdateCommand,\n\tgetSelfUpdateUnavailableInstruction,\n\tPACKAGE_NAME,\n\ttype SelfUpdateCommand,\n\tVERSION,\n} from \"./config.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\nimport { isNewerPackageVersion } from \"./utils/version-check.js\";\n\nexport type PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\n\ntype UpdateTarget = { type: \"all\" } | { type: \"self\" } | { type: \"extensions\"; source?: string };\n\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tupdateTarget?: UpdateTarget;\n\tlocal: boolean;\n\tforce: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n\tinvalidArgument?: string;\n\tmissingOptionValue?: string;\n\tconflictingOptions?: string;\n}\n\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\n\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source|self|pi] [--self] [--extensions] [--extension <source>] [--force]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\n\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\n\nInstall a package and add it to settings.\n\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\n\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https://github.com/user/repo\n ${APP_NAME} install ssh://git@github.com/user/repo\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\n\nRemove a package and its source from settings.\nAlias: ${APP_NAME} uninstall <source> [-l]\n\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\n\nExamples:\n ${APP_NAME} remove npm:@foo/bar\n ${APP_NAME} uninstall npm:@foo/bar\n`);\n\t\t\treturn;\n\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\n\nUpdate pi and installed packages.\n\nOptions:\n --self Update pi only\n --extensions Update installed packages only\n --extension <source> Update one package only\n --force Reinstall pi even if the current version is latest\n\nShort forms:\n ${APP_NAME} update Update pi and all extensions\n ${APP_NAME} update <source> Update one package\n ${APP_NAME} update pi Update pi only (self works as alias to pi)\n`);\n\t\t\treturn;\n\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\n\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\n\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [rawCommand, ...rest] = args;\n\tlet command: PackageCommand | undefined;\n\tif (rawCommand === \"uninstall\") {\n\t\tcommand = \"remove\";\n\t} else if (rawCommand === \"install\" || rawCommand === \"remove\" || rawCommand === \"update\" || rawCommand === \"list\") {\n\t\tcommand = rawCommand;\n\t}\n\tif (!command) {\n\t\treturn undefined;\n\t}\n\n\tlet local = false;\n\tlet force = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet invalidArgument: string | undefined;\n\tlet missingOptionValue: string | undefined;\n\tlet conflictingOptions: string | undefined;\n\tlet source: string | undefined;\n\tlet selfFlag = false;\n\tlet extensionsFlag = false;\n\tlet extensionFlagSource: string | undefined;\n\n\tfor (let index = 0; index < rest.length; index++) {\n\t\tconst arg = rest[index];\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--self\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tselfFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extensions\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\textensionsFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--force\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tforce = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extension\") {\n\t\t\tif (command !== \"update\") {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst value = rest[index + 1];\n\t\t\tif (!value || value.startsWith(\"-\")) {\n\t\t\t\tmissingOptionValue = missingOptionValue ?? arg;\n\t\t\t} else if (extensionFlagSource) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension can only be provided once\";\n\t\t\t\tindex++;\n\t\t\t} else {\n\t\t\t\textensionFlagSource = value;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t} else {\n\t\t\tinvalidArgument = invalidArgument ?? arg;\n\t\t}\n\t}\n\n\tlet updateTarget: UpdateTarget | undefined;\n\tif (command === \"update\") {\n\t\tif (extensionFlagSource) {\n\t\t\tif (selfFlag || extensionsFlag) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with --self or --extensions\";\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with a positional source\";\n\t\t\t}\n\t\t\tupdateTarget = { type: \"extensions\", source: extensionFlagSource };\n\t\t} else if (source) {\n\t\t\tconst sourceIsSelf = source === \"self\" || source === \"pi\";\n\t\t\tif (sourceIsSelf) {\n\t\t\t\tupdateTarget = extensionsFlag ? { type: \"all\" } : { type: \"self\" };\n\t\t\t} else {\n\t\t\t\tif (extensionsFlag || selfFlag) {\n\t\t\t\t\tconflictingOptions =\n\t\t\t\t\t\tconflictingOptions ?? \"positional update targets cannot be combined with --self or --extensions\";\n\t\t\t\t}\n\t\t\t\tupdateTarget = { type: \"extensions\", source };\n\t\t\t}\n\t\t} else if (selfFlag && extensionsFlag) {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t} else if (selfFlag) {\n\t\t\tupdateTarget = { type: \"self\" };\n\t\t} else if (extensionsFlag) {\n\t\t\tupdateTarget = { type: \"extensions\" };\n\t\t} else {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t}\n\t}\n\n\treturn {\n\t\tcommand,\n\t\tsource,\n\t\tupdateTarget,\n\t\tlocal,\n\t\tforce,\n\t\thelp,\n\t\tinvalidOption,\n\t\tinvalidArgument,\n\t\tmissingOptionValue,\n\t\tconflictingOptions,\n\t};\n}\n\nfunction updateTargetIncludesSelf(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"self\";\n}\n\nfunction updateTargetIncludesExtensions(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"extensions\";\n}\n\nfunction printSelfUpdateUnavailable(npmCommand?: string[], updatePackageName = PACKAGE_NAME): void {\n\tconsole.error(`error: ${APP_NAME} cannot self-update this installation.`);\n\tconsole.error(getSelfUpdateUnavailableInstruction(PACKAGE_NAME, npmCommand, updatePackageName));\n\n\tconst entrypoint = process.argv[1];\n\tif (entrypoint) {\n\t\tconsole.error(\"\");\n\t\tconsole.error(`Location of pi executable: ${entrypoint}`);\n\t}\n}\n\nfunction printSelfUpdateFallback(command: SelfUpdateCommand): void {\n\tconsole.error(chalk.dim(`If this keeps failing, run this command yourself: ${command.display}`));\n}\n\ninterface SelfUpdatePlan {\n\tpackageName: string;\n\tshouldRun: boolean;\n}\n\nasync function getSelfUpdatePlan(force: boolean): Promise<SelfUpdatePlan> {\n\tif (force) {\n\t\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n\t}\n\ttry {\n\t\t// Check the npm registry for the latest @phi-code-admin/phi-code. (The old\n\t\t// flow queried pi.dev, the upstream Pi endpoint, which reported the upstream\n\t\t// package name and an unrelated version line.) Skipping the reinstall when\n\t\t// already current also avoids the Windows EBUSY where the running phi\n\t\t// process holds its own native .node modules locked during `npm install -g`.\n\t\tconst response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {\n\t\t\theaders: { accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(10000),\n\t\t});\n\t\tif (response.ok) {\n\t\t\tconst data = (await response.json()) as { version?: unknown };\n\t\t\tconst latest = typeof data.version === \"string\" ? data.version.trim() : \"\";\n\t\t\tif (latest && !isNewerPackageVersion(latest, VERSION)) {\n\t\t\t\tconsole.log(chalk.green(`${APP_NAME} is already up to date (v${VERSION})`));\n\t\t\t\treturn { packageName: PACKAGE_NAME, shouldRun: false };\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Registry/network error: fall through and attempt the update anyway.\n\t}\n\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n}\n\nasync function runSelfUpdate(command: SelfUpdateCommand): Promise<void> {\n\tconsole.log(chalk.dim(`Updating ${APP_NAME} with ${command.display}...`));\n\tfor (const step of command.steps ?? [command]) {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t// Windows package managers are commonly .cmd shims. Use the shell so Node can execute them.\n\t\t\tconst child = spawn(step.command, step.args, {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: shouldUseWindowsShell(step.command),\n\t\t\t});\n\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t\t\tchild.on(\"close\", (code, signal) => {\n\t\t\t\tif (code === 0) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else if (signal) {\n\t\t\t\t\treject(new Error(`${step.display} terminated by signal ${signal}`));\n\t\t\t\t} else {\n\t\t\t\t\treject(new Error(`${step.display} exited with code ${code ?? \"unknown\"}`));\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n\nexport async function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\n\tprocess.exit(0);\n}\n\nexport async function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.missingOptionValue) {\n\t\tconsole.error(chalk.red(`Missing value for ${options.missingOptionValue}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.invalidArgument) {\n\t\tconsole.error(chalk.red(`Unexpected argument ${options.invalidArgument}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.conflictingOptions) {\n\t\tconsole.error(chalk.red(options.conflictingOptions));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst selfUpdateNpmCommand = settingsManager.getGlobalSettings().npmCommand;\n\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.installAndPersist(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\n\t\t\tcase \"remove\": {\n\t\t\t\tconst removed = await packageManager.removeAndPersist(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"list\": {\n\t\t\t\tconst configuredPackages = packageManager.listConfiguredPackages();\n\t\t\t\tconst userPackages = configuredPackages.filter((pkg) => pkg.scope === \"user\");\n\t\t\t\tconst projectPackages = configuredPackages.filter((pkg) => pkg.scope === \"project\");\n\n\t\t\t\tif (configuredPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst formatPackage = (pkg: (typeof configuredPackages)[number]) => {\n\t\t\t\t\tconst display = pkg.filtered ? `${pkg.source} (filtered)` : pkg.source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tif (pkg.installedPath) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${pkg.installedPath}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif (userPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of userPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (userPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"update\": {\n\t\t\t\tconst target = options.updateTarget ?? { type: \"all\" };\n\t\t\t\tif (updateTargetIncludesExtensions(target)) {\n\t\t\t\t\tconst updateSource = target.type === \"extensions\" ? target.source : undefined;\n\t\t\t\t\tawait packageManager.update(updateSource);\n\t\t\t\t\tif (updateSource) {\n\t\t\t\t\t\tconsole.log(chalk.green(`Updated ${updateSource}`));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (updateTargetIncludesSelf(target)) {\n\t\t\t\t\tconst selfUpdatePlan = await getSelfUpdatePlan(options.force);\n\t\t\t\t\tif (!selfUpdatePlan.shouldRun) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconst selfUpdateCommand = getSelfUpdateCommand(\n\t\t\t\t\t\tPACKAGE_NAME,\n\t\t\t\t\t\tselfUpdateNpmCommand,\n\t\t\t\t\t\tselfUpdatePlan.packageName,\n\t\t\t\t\t);\n\t\t\t\t\tif (!selfUpdateCommand) {\n\t\t\t\t\t\tprintSelfUpdateUnavailable(selfUpdateNpmCommand, selfUpdatePlan.packageName);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runSelfUpdate(selfUpdateCommand);\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\t\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\t\t\tprintSelfUpdateFallback(selfUpdateCommand);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${APP_NAME}`));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"package-manager-cli.d.ts","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AAiBA,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AA4UtE,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAoB1E;AAED,wBAAsB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAiK3E","sourcesContent":["import chalk from \"chalk\";\nimport { spawn } from \"child_process\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport {\n\tAPP_NAME,\n\tgetAgentDir,\n\tgetSelfUpdateCommand,\n\tgetSelfUpdateUnavailableInstruction,\n\tPACKAGE_NAME,\n\ttype SelfUpdateCommand,\n\tVERSION,\n} from \"./config.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\nimport { isNewerPackageVersion } from \"./utils/version-check.js\";\n\nexport type PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\n\ntype UpdateTarget = { type: \"all\" } | { type: \"self\" } | { type: \"extensions\"; source?: string };\n\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tupdateTarget?: UpdateTarget;\n\tlocal: boolean;\n\tforce: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n\tinvalidArgument?: string;\n\tmissingOptionValue?: string;\n\tconflictingOptions?: string;\n}\n\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\n\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source|self] [--self] [--extensions] [--extension <source>] [--force]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\n\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\n\nInstall a package and add it to settings.\n\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\n\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https://github.com/user/repo\n ${APP_NAME} install ssh://git@github.com/user/repo\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\n\nRemove a package and its source from settings.\nAlias: ${APP_NAME} uninstall <source> [-l]\n\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\n\nExamples:\n ${APP_NAME} remove npm:@foo/bar\n ${APP_NAME} uninstall npm:@foo/bar\n`);\n\t\t\treturn;\n\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\n\nUpdate ${APP_NAME} and installed packages.\n\nOptions:\n --self Update ${APP_NAME} only\n --extensions Update installed packages only\n --extension <source> Update one package only\n --force Reinstall ${APP_NAME} even if the current version is latest\n\nShort forms:\n ${APP_NAME} update Update ${APP_NAME} and all extensions\n ${APP_NAME} update <source> Update one package\n ${APP_NAME} update self Update ${APP_NAME} only\n`);\n\t\t\treturn;\n\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\n\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\n\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [rawCommand, ...rest] = args;\n\tlet command: PackageCommand | undefined;\n\tif (rawCommand === \"uninstall\") {\n\t\tcommand = \"remove\";\n\t} else if (rawCommand === \"install\" || rawCommand === \"remove\" || rawCommand === \"update\" || rawCommand === \"list\") {\n\t\tcommand = rawCommand;\n\t}\n\tif (!command) {\n\t\treturn undefined;\n\t}\n\n\tlet local = false;\n\tlet force = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet invalidArgument: string | undefined;\n\tlet missingOptionValue: string | undefined;\n\tlet conflictingOptions: string | undefined;\n\tlet source: string | undefined;\n\tlet selfFlag = false;\n\tlet extensionsFlag = false;\n\tlet extensionFlagSource: string | undefined;\n\n\tfor (let index = 0; index < rest.length; index++) {\n\t\tconst arg = rest[index];\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--self\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tselfFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extensions\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\textensionsFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--force\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tforce = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extension\") {\n\t\t\tif (command !== \"update\") {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst value = rest[index + 1];\n\t\t\tif (!value || value.startsWith(\"-\")) {\n\t\t\t\tmissingOptionValue = missingOptionValue ?? arg;\n\t\t\t} else if (extensionFlagSource) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension can only be provided once\";\n\t\t\t\tindex++;\n\t\t\t} else {\n\t\t\t\textensionFlagSource = value;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t} else {\n\t\t\tinvalidArgument = invalidArgument ?? arg;\n\t\t}\n\t}\n\n\tlet updateTarget: UpdateTarget | undefined;\n\tif (command === \"update\") {\n\t\tif (extensionFlagSource) {\n\t\t\tif (selfFlag || extensionsFlag) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with --self or --extensions\";\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with a positional source\";\n\t\t\t}\n\t\t\tupdateTarget = { type: \"extensions\", source: extensionFlagSource };\n\t\t} else if (source) {\n\t\t\t// \"pi\" kept as a hidden legacy alias (upstream muscle memory).\n\t\t\tconst sourceIsSelf = source === \"self\" || source === \"pi\" || source === APP_NAME;\n\t\t\tif (sourceIsSelf) {\n\t\t\t\tupdateTarget = extensionsFlag ? { type: \"all\" } : { type: \"self\" };\n\t\t\t} else {\n\t\t\t\tif (extensionsFlag || selfFlag) {\n\t\t\t\t\tconflictingOptions =\n\t\t\t\t\t\tconflictingOptions ?? \"positional update targets cannot be combined with --self or --extensions\";\n\t\t\t\t}\n\t\t\t\tupdateTarget = { type: \"extensions\", source };\n\t\t\t}\n\t\t} else if (selfFlag && extensionsFlag) {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t} else if (selfFlag) {\n\t\t\tupdateTarget = { type: \"self\" };\n\t\t} else if (extensionsFlag) {\n\t\t\tupdateTarget = { type: \"extensions\" };\n\t\t} else {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t}\n\t}\n\n\treturn {\n\t\tcommand,\n\t\tsource,\n\t\tupdateTarget,\n\t\tlocal,\n\t\tforce,\n\t\thelp,\n\t\tinvalidOption,\n\t\tinvalidArgument,\n\t\tmissingOptionValue,\n\t\tconflictingOptions,\n\t};\n}\n\nfunction updateTargetIncludesSelf(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"self\";\n}\n\nfunction updateTargetIncludesExtensions(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"extensions\";\n}\n\nfunction printSelfUpdateUnavailable(npmCommand?: string[], updatePackageName = PACKAGE_NAME): void {\n\tconsole.error(`error: ${APP_NAME} cannot self-update this installation.`);\n\tconsole.error(getSelfUpdateUnavailableInstruction(PACKAGE_NAME, npmCommand, updatePackageName));\n\n\tconst entrypoint = process.argv[1];\n\tif (entrypoint) {\n\t\tconsole.error(\"\");\n\t\tconsole.error(`Location of ${APP_NAME} executable: ${entrypoint}`);\n\t}\n}\n\nfunction printSelfUpdateFallback(command: SelfUpdateCommand): void {\n\tconsole.error(chalk.dim(`If this keeps failing, run this command yourself: ${command.display}`));\n}\n\ninterface SelfUpdatePlan {\n\tpackageName: string;\n\tshouldRun: boolean;\n}\n\nasync function getSelfUpdatePlan(force: boolean): Promise<SelfUpdatePlan> {\n\tif (force) {\n\t\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n\t}\n\ttry {\n\t\t// Check the npm registry for the latest @phi-code-admin/phi-code. (The old\n\t\t// flow queried pi.dev, the upstream Pi endpoint, which reported the upstream\n\t\t// package name and an unrelated version line.) Skipping the reinstall when\n\t\t// already current also avoids the Windows EBUSY where the running phi\n\t\t// process holds its own native .node modules locked during `npm install -g`.\n\t\tconst response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {\n\t\t\theaders: { accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(10000),\n\t\t});\n\t\tif (response.ok) {\n\t\t\tconst data = (await response.json()) as { version?: unknown };\n\t\t\tconst latest = typeof data.version === \"string\" ? data.version.trim() : \"\";\n\t\t\tif (latest && !isNewerPackageVersion(latest, VERSION)) {\n\t\t\t\tconsole.log(chalk.green(`${APP_NAME} is already up to date (v${VERSION})`));\n\t\t\t\treturn { packageName: PACKAGE_NAME, shouldRun: false };\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Registry/network error: fall through and attempt the update anyway.\n\t}\n\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n}\n\nasync function runSelfUpdate(command: SelfUpdateCommand): Promise<void> {\n\tconsole.log(chalk.dim(`Updating ${APP_NAME} with ${command.display}...`));\n\tfor (const step of command.steps ?? [command]) {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t// Windows package managers are commonly .cmd shims. Use the shell so Node can execute them.\n\t\t\tconst child = spawn(step.command, step.args, {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: shouldUseWindowsShell(step.command),\n\t\t\t});\n\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t\t\tchild.on(\"close\", (code, signal) => {\n\t\t\t\tif (code === 0) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else if (signal) {\n\t\t\t\t\treject(new Error(`${step.display} terminated by signal ${signal}`));\n\t\t\t\t} else {\n\t\t\t\t\treject(new Error(`${step.display} exited with code ${code ?? \"unknown\"}`));\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n\nexport async function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\n\tprocess.exit(0);\n}\n\nexport async function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.missingOptionValue) {\n\t\tconsole.error(chalk.red(`Missing value for ${options.missingOptionValue}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.invalidArgument) {\n\t\tconsole.error(chalk.red(`Unexpected argument ${options.invalidArgument}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.conflictingOptions) {\n\t\tconsole.error(chalk.red(options.conflictingOptions));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst selfUpdateNpmCommand = settingsManager.getGlobalSettings().npmCommand;\n\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.installAndPersist(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\n\t\t\tcase \"remove\": {\n\t\t\t\tconst removed = await packageManager.removeAndPersist(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"list\": {\n\t\t\t\tconst configuredPackages = packageManager.listConfiguredPackages();\n\t\t\t\tconst userPackages = configuredPackages.filter((pkg) => pkg.scope === \"user\");\n\t\t\t\tconst projectPackages = configuredPackages.filter((pkg) => pkg.scope === \"project\");\n\n\t\t\t\tif (configuredPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst formatPackage = (pkg: (typeof configuredPackages)[number]) => {\n\t\t\t\t\tconst display = pkg.filtered ? `${pkg.source} (filtered)` : pkg.source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tif (pkg.installedPath) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${pkg.installedPath}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif (userPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of userPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (userPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"update\": {\n\t\t\t\tconst target = options.updateTarget ?? { type: \"all\" };\n\t\t\t\tif (updateTargetIncludesExtensions(target)) {\n\t\t\t\t\tconst updateSource = target.type === \"extensions\" ? target.source : undefined;\n\t\t\t\t\tawait packageManager.update(updateSource);\n\t\t\t\t\tif (updateSource) {\n\t\t\t\t\t\tconsole.log(chalk.green(`Updated ${updateSource}`));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (updateTargetIncludesSelf(target)) {\n\t\t\t\t\tconst selfUpdatePlan = await getSelfUpdatePlan(options.force);\n\t\t\t\t\tif (!selfUpdatePlan.shouldRun) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconst selfUpdateCommand = getSelfUpdateCommand(\n\t\t\t\t\t\tPACKAGE_NAME,\n\t\t\t\t\t\tselfUpdateNpmCommand,\n\t\t\t\t\t\tselfUpdatePlan.packageName,\n\t\t\t\t\t);\n\t\t\t\t\tif (!selfUpdateCommand) {\n\t\t\t\t\t\tprintSelfUpdateUnavailable(selfUpdateNpmCommand, selfUpdatePlan.packageName);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runSelfUpdate(selfUpdateCommand);\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\t\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\t\t\tprintSelfUpdateFallback(selfUpdateCommand);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${APP_NAME}`));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -22,7 +22,7 @@ function getPackageCommandUsage(command) {
|
|
|
22
22
|
case "remove":
|
|
23
23
|
return `${APP_NAME} remove <source> [-l]`;
|
|
24
24
|
case "update":
|
|
25
|
-
return `${APP_NAME} update [source|self
|
|
25
|
+
return `${APP_NAME} update [source|self] [--self] [--extensions] [--extension <source>] [--force]`;
|
|
26
26
|
case "list":
|
|
27
27
|
return `${APP_NAME} list`;
|
|
28
28
|
}
|
|
@@ -66,18 +66,18 @@ Examples:
|
|
|
66
66
|
console.log(`${chalk.bold("Usage:")}
|
|
67
67
|
${getPackageCommandUsage("update")}
|
|
68
68
|
|
|
69
|
-
Update
|
|
69
|
+
Update ${APP_NAME} and installed packages.
|
|
70
70
|
|
|
71
71
|
Options:
|
|
72
|
-
--self Update
|
|
72
|
+
--self Update ${APP_NAME} only
|
|
73
73
|
--extensions Update installed packages only
|
|
74
74
|
--extension <source> Update one package only
|
|
75
|
-
--force Reinstall
|
|
75
|
+
--force Reinstall ${APP_NAME} even if the current version is latest
|
|
76
76
|
|
|
77
77
|
Short forms:
|
|
78
|
-
${APP_NAME} update Update
|
|
78
|
+
${APP_NAME} update Update ${APP_NAME} and all extensions
|
|
79
79
|
${APP_NAME} update <source> Update one package
|
|
80
|
-
${APP_NAME} update
|
|
80
|
+
${APP_NAME} update self Update ${APP_NAME} only
|
|
81
81
|
`);
|
|
82
82
|
return;
|
|
83
83
|
case "list":
|
|
@@ -196,7 +196,8 @@ function parsePackageCommand(args) {
|
|
|
196
196
|
updateTarget = { type: "extensions", source: extensionFlagSource };
|
|
197
197
|
}
|
|
198
198
|
else if (source) {
|
|
199
|
-
|
|
199
|
+
// "pi" kept as a hidden legacy alias (upstream muscle memory).
|
|
200
|
+
const sourceIsSelf = source === "self" || source === "pi" || source === APP_NAME;
|
|
200
201
|
if (sourceIsSelf) {
|
|
201
202
|
updateTarget = extensionsFlag ? { type: "all" } : { type: "self" };
|
|
202
203
|
}
|
|
@@ -246,7 +247,7 @@ function printSelfUpdateUnavailable(npmCommand, updatePackageName = PACKAGE_NAME
|
|
|
246
247
|
const entrypoint = process.argv[1];
|
|
247
248
|
if (entrypoint) {
|
|
248
249
|
console.error("");
|
|
249
|
-
console.error(`Location of
|
|
250
|
+
console.error(`Location of ${APP_NAME} executable: ${entrypoint}`);
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
253
|
function printSelfUpdateFallback(command) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager-cli.js","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACN,QAAQ,EACR,WAAW,EACX,oBAAoB,EACpB,mCAAmC,EACnC,YAAY,EAEZ,OAAO,GACP,MAAM,aAAa,CAAC;A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GAAG,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;AAAA,CACD","sourcesContent":["import chalk from \"chalk\";\nimport { spawn } from \"child_process\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport {\n\tAPP_NAME,\n\tgetAgentDir,\n\tgetSelfUpdateCommand,\n\tgetSelfUpdateUnavailableInstruction,\n\tPACKAGE_NAME,\n\ttype SelfUpdateCommand,\n\tVERSION,\n} from \"./config.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\nimport { isNewerPackageVersion } from \"./utils/version-check.js\";\n\nexport type PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\n\ntype UpdateTarget = { type: \"all\" } | { type: \"self\" } | { type: \"extensions\"; source?: string };\n\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tupdateTarget?: UpdateTarget;\n\tlocal: boolean;\n\tforce: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n\tinvalidArgument?: string;\n\tmissingOptionValue?: string;\n\tconflictingOptions?: string;\n}\n\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\n\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source|self|pi] [--self] [--extensions] [--extension <source>] [--force]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\n\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\n\nInstall a package and add it to settings.\n\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\n\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https://github.com/user/repo\n ${APP_NAME} install ssh://git@github.com/user/repo\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\n\nRemove a package and its source from settings.\nAlias: ${APP_NAME} uninstall <source> [-l]\n\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\n\nExamples:\n ${APP_NAME} remove npm:@foo/bar\n ${APP_NAME} uninstall npm:@foo/bar\n`);\n\t\t\treturn;\n\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\n\nUpdate pi and installed packages.\n\nOptions:\n --self Update pi only\n --extensions Update installed packages only\n --extension <source> Update one package only\n --force Reinstall pi even if the current version is latest\n\nShort forms:\n ${APP_NAME} update Update pi and all extensions\n ${APP_NAME} update <source> Update one package\n ${APP_NAME} update pi Update pi only (self works as alias to pi)\n`);\n\t\t\treturn;\n\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\n\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\n\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [rawCommand, ...rest] = args;\n\tlet command: PackageCommand | undefined;\n\tif (rawCommand === \"uninstall\") {\n\t\tcommand = \"remove\";\n\t} else if (rawCommand === \"install\" || rawCommand === \"remove\" || rawCommand === \"update\" || rawCommand === \"list\") {\n\t\tcommand = rawCommand;\n\t}\n\tif (!command) {\n\t\treturn undefined;\n\t}\n\n\tlet local = false;\n\tlet force = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet invalidArgument: string | undefined;\n\tlet missingOptionValue: string | undefined;\n\tlet conflictingOptions: string | undefined;\n\tlet source: string | undefined;\n\tlet selfFlag = false;\n\tlet extensionsFlag = false;\n\tlet extensionFlagSource: string | undefined;\n\n\tfor (let index = 0; index < rest.length; index++) {\n\t\tconst arg = rest[index];\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--self\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tselfFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extensions\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\textensionsFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--force\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tforce = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extension\") {\n\t\t\tif (command !== \"update\") {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst value = rest[index + 1];\n\t\t\tif (!value || value.startsWith(\"-\")) {\n\t\t\t\tmissingOptionValue = missingOptionValue ?? arg;\n\t\t\t} else if (extensionFlagSource) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension can only be provided once\";\n\t\t\t\tindex++;\n\t\t\t} else {\n\t\t\t\textensionFlagSource = value;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t} else {\n\t\t\tinvalidArgument = invalidArgument ?? arg;\n\t\t}\n\t}\n\n\tlet updateTarget: UpdateTarget | undefined;\n\tif (command === \"update\") {\n\t\tif (extensionFlagSource) {\n\t\t\tif (selfFlag || extensionsFlag) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with --self or --extensions\";\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with a positional source\";\n\t\t\t}\n\t\t\tupdateTarget = { type: \"extensions\", source: extensionFlagSource };\n\t\t} else if (source) {\n\t\t\tconst sourceIsSelf = source === \"self\" || source === \"pi\";\n\t\t\tif (sourceIsSelf) {\n\t\t\t\tupdateTarget = extensionsFlag ? { type: \"all\" } : { type: \"self\" };\n\t\t\t} else {\n\t\t\t\tif (extensionsFlag || selfFlag) {\n\t\t\t\t\tconflictingOptions =\n\t\t\t\t\t\tconflictingOptions ?? \"positional update targets cannot be combined with --self or --extensions\";\n\t\t\t\t}\n\t\t\t\tupdateTarget = { type: \"extensions\", source };\n\t\t\t}\n\t\t} else if (selfFlag && extensionsFlag) {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t} else if (selfFlag) {\n\t\t\tupdateTarget = { type: \"self\" };\n\t\t} else if (extensionsFlag) {\n\t\t\tupdateTarget = { type: \"extensions\" };\n\t\t} else {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t}\n\t}\n\n\treturn {\n\t\tcommand,\n\t\tsource,\n\t\tupdateTarget,\n\t\tlocal,\n\t\tforce,\n\t\thelp,\n\t\tinvalidOption,\n\t\tinvalidArgument,\n\t\tmissingOptionValue,\n\t\tconflictingOptions,\n\t};\n}\n\nfunction updateTargetIncludesSelf(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"self\";\n}\n\nfunction updateTargetIncludesExtensions(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"extensions\";\n}\n\nfunction printSelfUpdateUnavailable(npmCommand?: string[], updatePackageName = PACKAGE_NAME): void {\n\tconsole.error(`error: ${APP_NAME} cannot self-update this installation.`);\n\tconsole.error(getSelfUpdateUnavailableInstruction(PACKAGE_NAME, npmCommand, updatePackageName));\n\n\tconst entrypoint = process.argv[1];\n\tif (entrypoint) {\n\t\tconsole.error(\"\");\n\t\tconsole.error(`Location of pi executable: ${entrypoint}`);\n\t}\n}\n\nfunction printSelfUpdateFallback(command: SelfUpdateCommand): void {\n\tconsole.error(chalk.dim(`If this keeps failing, run this command yourself: ${command.display}`));\n}\n\ninterface SelfUpdatePlan {\n\tpackageName: string;\n\tshouldRun: boolean;\n}\n\nasync function getSelfUpdatePlan(force: boolean): Promise<SelfUpdatePlan> {\n\tif (force) {\n\t\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n\t}\n\ttry {\n\t\t// Check the npm registry for the latest @phi-code-admin/phi-code. (The old\n\t\t// flow queried pi.dev, the upstream Pi endpoint, which reported the upstream\n\t\t// package name and an unrelated version line.) Skipping the reinstall when\n\t\t// already current also avoids the Windows EBUSY where the running phi\n\t\t// process holds its own native .node modules locked during `npm install -g`.\n\t\tconst response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {\n\t\t\theaders: { accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(10000),\n\t\t});\n\t\tif (response.ok) {\n\t\t\tconst data = (await response.json()) as { version?: unknown };\n\t\t\tconst latest = typeof data.version === \"string\" ? data.version.trim() : \"\";\n\t\t\tif (latest && !isNewerPackageVersion(latest, VERSION)) {\n\t\t\t\tconsole.log(chalk.green(`${APP_NAME} is already up to date (v${VERSION})`));\n\t\t\t\treturn { packageName: PACKAGE_NAME, shouldRun: false };\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Registry/network error: fall through and attempt the update anyway.\n\t}\n\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n}\n\nasync function runSelfUpdate(command: SelfUpdateCommand): Promise<void> {\n\tconsole.log(chalk.dim(`Updating ${APP_NAME} with ${command.display}...`));\n\tfor (const step of command.steps ?? [command]) {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t// Windows package managers are commonly .cmd shims. Use the shell so Node can execute them.\n\t\t\tconst child = spawn(step.command, step.args, {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: shouldUseWindowsShell(step.command),\n\t\t\t});\n\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t\t\tchild.on(\"close\", (code, signal) => {\n\t\t\t\tif (code === 0) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else if (signal) {\n\t\t\t\t\treject(new Error(`${step.display} terminated by signal ${signal}`));\n\t\t\t\t} else {\n\t\t\t\t\treject(new Error(`${step.display} exited with code ${code ?? \"unknown\"}`));\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n\nexport async function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\n\tprocess.exit(0);\n}\n\nexport async function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.missingOptionValue) {\n\t\tconsole.error(chalk.red(`Missing value for ${options.missingOptionValue}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.invalidArgument) {\n\t\tconsole.error(chalk.red(`Unexpected argument ${options.invalidArgument}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.conflictingOptions) {\n\t\tconsole.error(chalk.red(options.conflictingOptions));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst selfUpdateNpmCommand = settingsManager.getGlobalSettings().npmCommand;\n\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.installAndPersist(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\n\t\t\tcase \"remove\": {\n\t\t\t\tconst removed = await packageManager.removeAndPersist(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"list\": {\n\t\t\t\tconst configuredPackages = packageManager.listConfiguredPackages();\n\t\t\t\tconst userPackages = configuredPackages.filter((pkg) => pkg.scope === \"user\");\n\t\t\t\tconst projectPackages = configuredPackages.filter((pkg) => pkg.scope === \"project\");\n\n\t\t\t\tif (configuredPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst formatPackage = (pkg: (typeof configuredPackages)[number]) => {\n\t\t\t\t\tconst display = pkg.filtered ? `${pkg.source} (filtered)` : pkg.source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tif (pkg.installedPath) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${pkg.installedPath}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif (userPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of userPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (userPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"update\": {\n\t\t\t\tconst target = options.updateTarget ?? { type: \"all\" };\n\t\t\t\tif (updateTargetIncludesExtensions(target)) {\n\t\t\t\t\tconst updateSource = target.type === \"extensions\" ? target.source : undefined;\n\t\t\t\t\tawait packageManager.update(updateSource);\n\t\t\t\t\tif (updateSource) {\n\t\t\t\t\t\tconsole.log(chalk.green(`Updated ${updateSource}`));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (updateTargetIncludesSelf(target)) {\n\t\t\t\t\tconst selfUpdatePlan = await getSelfUpdatePlan(options.force);\n\t\t\t\t\tif (!selfUpdatePlan.shouldRun) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconst selfUpdateCommand = getSelfUpdateCommand(\n\t\t\t\t\t\tPACKAGE_NAME,\n\t\t\t\t\t\tselfUpdateNpmCommand,\n\t\t\t\t\t\tselfUpdatePlan.packageName,\n\t\t\t\t\t);\n\t\t\t\t\tif (!selfUpdateCommand) {\n\t\t\t\t\t\tprintSelfUpdateUnavailable(selfUpdateNpmCommand, selfUpdatePlan.packageName);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runSelfUpdate(selfUpdateCommand);\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\t\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\t\t\tprintSelfUpdateFallback(selfUpdateCommand);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${APP_NAME}`));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"package-manager-cli.js","sourceRoot":"","sources":["../src/package-manager-cli.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EACN,QAAQ,EACR,WAAW,EACX,oBAAoB,EACpB,mCAAmC,EACnC,YAAY,EAEZ,OAAO,GACP,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAmBjE,SAAS,oBAAoB,CAAC,eAAgC,EAAE,OAAe,EAAQ;IACtF,MAAM,MAAM,GAAG,eAAe,CAAC,WAAW,EAAE,CAAC;IAC7C,KAAK,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,MAAM,EAAE,CAAC;QACvC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,YAAY,OAAO,KAAK,KAAK,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACzF,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;QACvC,CAAC;IACF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AAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC;wBACzF,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,CAAC;wBAC9C,uBAAuB,CAAC,iBAAiB,CAAC,CAAC;wBAC3C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;wBACrB,OAAO,IAAI,CAAC;oBACb,CAAC;oBACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,QAAQ,EAAE,CAAC,CAAC,CAAC;gBACjD,CAAC;gBACD,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACzB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,+BAA+B,CAAC;QACzF,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,CAAC;QAC9C,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACrB,OAAO,IAAI,CAAC;IACb,CAAC;AAAA,CACD","sourcesContent":["import chalk from \"chalk\";\nimport { spawn } from \"child_process\";\nimport { selectConfig } from \"./cli/config-selector.js\";\nimport {\n\tAPP_NAME,\n\tgetAgentDir,\n\tgetSelfUpdateCommand,\n\tgetSelfUpdateUnavailableInstruction,\n\tPACKAGE_NAME,\n\ttype SelfUpdateCommand,\n\tVERSION,\n} from \"./config.js\";\nimport { DefaultPackageManager } from \"./core/package-manager.js\";\nimport { SettingsManager } from \"./core/settings-manager.js\";\nimport { shouldUseWindowsShell } from \"./utils/child-process.js\";\nimport { isNewerPackageVersion } from \"./utils/version-check.js\";\n\nexport type PackageCommand = \"install\" | \"remove\" | \"update\" | \"list\";\n\ntype UpdateTarget = { type: \"all\" } | { type: \"self\" } | { type: \"extensions\"; source?: string };\n\ninterface PackageCommandOptions {\n\tcommand: PackageCommand;\n\tsource?: string;\n\tupdateTarget?: UpdateTarget;\n\tlocal: boolean;\n\tforce: boolean;\n\thelp: boolean;\n\tinvalidOption?: string;\n\tinvalidArgument?: string;\n\tmissingOptionValue?: string;\n\tconflictingOptions?: string;\n}\n\nfunction reportSettingsErrors(settingsManager: SettingsManager, context: string): void {\n\tconst errors = settingsManager.drainErrors();\n\tfor (const { scope, error } of errors) {\n\t\tconsole.error(chalk.yellow(`Warning (${context}, ${scope} settings): ${error.message}`));\n\t\tif (error.stack) {\n\t\t\tconsole.error(chalk.dim(error.stack));\n\t\t}\n\t}\n}\n\nfunction getPackageCommandUsage(command: PackageCommand): string {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\treturn `${APP_NAME} install <source> [-l]`;\n\t\tcase \"remove\":\n\t\t\treturn `${APP_NAME} remove <source> [-l]`;\n\t\tcase \"update\":\n\t\t\treturn `${APP_NAME} update [source|self] [--self] [--extensions] [--extension <source>] [--force]`;\n\t\tcase \"list\":\n\t\t\treturn `${APP_NAME} list`;\n\t}\n}\n\nfunction printPackageCommandHelp(command: PackageCommand): void {\n\tswitch (command) {\n\t\tcase \"install\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"install\")}\n\nInstall a package and add it to settings.\n\nOptions:\n -l, --local Install project-locally (.pi/settings.json)\n\nExamples:\n ${APP_NAME} install npm:@foo/bar\n ${APP_NAME} install git:github.com/user/repo\n ${APP_NAME} install git:git@github.com:user/repo\n ${APP_NAME} install https://github.com/user/repo\n ${APP_NAME} install ssh://git@github.com/user/repo\n ${APP_NAME} install ./local/path\n`);\n\t\t\treturn;\n\n\t\tcase \"remove\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"remove\")}\n\nRemove a package and its source from settings.\nAlias: ${APP_NAME} uninstall <source> [-l]\n\nOptions:\n -l, --local Remove from project settings (.pi/settings.json)\n\nExamples:\n ${APP_NAME} remove npm:@foo/bar\n ${APP_NAME} uninstall npm:@foo/bar\n`);\n\t\t\treturn;\n\n\t\tcase \"update\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"update\")}\n\nUpdate ${APP_NAME} and installed packages.\n\nOptions:\n --self Update ${APP_NAME} only\n --extensions Update installed packages only\n --extension <source> Update one package only\n --force Reinstall ${APP_NAME} even if the current version is latest\n\nShort forms:\n ${APP_NAME} update Update ${APP_NAME} and all extensions\n ${APP_NAME} update <source> Update one package\n ${APP_NAME} update self Update ${APP_NAME} only\n`);\n\t\t\treturn;\n\n\t\tcase \"list\":\n\t\t\tconsole.log(`${chalk.bold(\"Usage:\")}\n ${getPackageCommandUsage(\"list\")}\n\nList installed packages from user and project settings.\n`);\n\t\t\treturn;\n\t}\n}\n\nfunction parsePackageCommand(args: string[]): PackageCommandOptions | undefined {\n\tconst [rawCommand, ...rest] = args;\n\tlet command: PackageCommand | undefined;\n\tif (rawCommand === \"uninstall\") {\n\t\tcommand = \"remove\";\n\t} else if (rawCommand === \"install\" || rawCommand === \"remove\" || rawCommand === \"update\" || rawCommand === \"list\") {\n\t\tcommand = rawCommand;\n\t}\n\tif (!command) {\n\t\treturn undefined;\n\t}\n\n\tlet local = false;\n\tlet force = false;\n\tlet help = false;\n\tlet invalidOption: string | undefined;\n\tlet invalidArgument: string | undefined;\n\tlet missingOptionValue: string | undefined;\n\tlet conflictingOptions: string | undefined;\n\tlet source: string | undefined;\n\tlet selfFlag = false;\n\tlet extensionsFlag = false;\n\tlet extensionFlagSource: string | undefined;\n\n\tfor (let index = 0; index < rest.length; index++) {\n\t\tconst arg = rest[index];\n\t\tif (arg === \"-h\" || arg === \"--help\") {\n\t\t\thelp = true;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"-l\" || arg === \"--local\") {\n\t\t\tif (command === \"install\" || command === \"remove\") {\n\t\t\t\tlocal = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--self\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tselfFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extensions\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\textensionsFlag = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--force\") {\n\t\t\tif (command === \"update\") {\n\t\t\t\tforce = true;\n\t\t\t} else {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg === \"--extension\") {\n\t\t\tif (command !== \"update\") {\n\t\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst value = rest[index + 1];\n\t\t\tif (!value || value.startsWith(\"-\")) {\n\t\t\t\tmissingOptionValue = missingOptionValue ?? arg;\n\t\t\t} else if (extensionFlagSource) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension can only be provided once\";\n\t\t\t\tindex++;\n\t\t\t} else {\n\t\t\t\textensionFlagSource = value;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (arg.startsWith(\"-\")) {\n\t\t\tinvalidOption = invalidOption ?? arg;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (!source) {\n\t\t\tsource = arg;\n\t\t} else {\n\t\t\tinvalidArgument = invalidArgument ?? arg;\n\t\t}\n\t}\n\n\tlet updateTarget: UpdateTarget | undefined;\n\tif (command === \"update\") {\n\t\tif (extensionFlagSource) {\n\t\t\tif (selfFlag || extensionsFlag) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with --self or --extensions\";\n\t\t\t}\n\t\t\tif (source) {\n\t\t\t\tconflictingOptions = conflictingOptions ?? \"--extension cannot be combined with a positional source\";\n\t\t\t}\n\t\t\tupdateTarget = { type: \"extensions\", source: extensionFlagSource };\n\t\t} else if (source) {\n\t\t\t// \"pi\" kept as a hidden legacy alias (upstream muscle memory).\n\t\t\tconst sourceIsSelf = source === \"self\" || source === \"pi\" || source === APP_NAME;\n\t\t\tif (sourceIsSelf) {\n\t\t\t\tupdateTarget = extensionsFlag ? { type: \"all\" } : { type: \"self\" };\n\t\t\t} else {\n\t\t\t\tif (extensionsFlag || selfFlag) {\n\t\t\t\t\tconflictingOptions =\n\t\t\t\t\t\tconflictingOptions ?? \"positional update targets cannot be combined with --self or --extensions\";\n\t\t\t\t}\n\t\t\t\tupdateTarget = { type: \"extensions\", source };\n\t\t\t}\n\t\t} else if (selfFlag && extensionsFlag) {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t} else if (selfFlag) {\n\t\t\tupdateTarget = { type: \"self\" };\n\t\t} else if (extensionsFlag) {\n\t\t\tupdateTarget = { type: \"extensions\" };\n\t\t} else {\n\t\t\tupdateTarget = { type: \"all\" };\n\t\t}\n\t}\n\n\treturn {\n\t\tcommand,\n\t\tsource,\n\t\tupdateTarget,\n\t\tlocal,\n\t\tforce,\n\t\thelp,\n\t\tinvalidOption,\n\t\tinvalidArgument,\n\t\tmissingOptionValue,\n\t\tconflictingOptions,\n\t};\n}\n\nfunction updateTargetIncludesSelf(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"self\";\n}\n\nfunction updateTargetIncludesExtensions(target: UpdateTarget): boolean {\n\treturn target.type === \"all\" || target.type === \"extensions\";\n}\n\nfunction printSelfUpdateUnavailable(npmCommand?: string[], updatePackageName = PACKAGE_NAME): void {\n\tconsole.error(`error: ${APP_NAME} cannot self-update this installation.`);\n\tconsole.error(getSelfUpdateUnavailableInstruction(PACKAGE_NAME, npmCommand, updatePackageName));\n\n\tconst entrypoint = process.argv[1];\n\tif (entrypoint) {\n\t\tconsole.error(\"\");\n\t\tconsole.error(`Location of ${APP_NAME} executable: ${entrypoint}`);\n\t}\n}\n\nfunction printSelfUpdateFallback(command: SelfUpdateCommand): void {\n\tconsole.error(chalk.dim(`If this keeps failing, run this command yourself: ${command.display}`));\n}\n\ninterface SelfUpdatePlan {\n\tpackageName: string;\n\tshouldRun: boolean;\n}\n\nasync function getSelfUpdatePlan(force: boolean): Promise<SelfUpdatePlan> {\n\tif (force) {\n\t\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n\t}\n\ttry {\n\t\t// Check the npm registry for the latest @phi-code-admin/phi-code. (The old\n\t\t// flow queried pi.dev, the upstream Pi endpoint, which reported the upstream\n\t\t// package name and an unrelated version line.) Skipping the reinstall when\n\t\t// already current also avoids the Windows EBUSY where the running phi\n\t\t// process holds its own native .node modules locked during `npm install -g`.\n\t\tconst response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {\n\t\t\theaders: { accept: \"application/json\" },\n\t\t\tsignal: AbortSignal.timeout(10000),\n\t\t});\n\t\tif (response.ok) {\n\t\t\tconst data = (await response.json()) as { version?: unknown };\n\t\t\tconst latest = typeof data.version === \"string\" ? data.version.trim() : \"\";\n\t\t\tif (latest && !isNewerPackageVersion(latest, VERSION)) {\n\t\t\t\tconsole.log(chalk.green(`${APP_NAME} is already up to date (v${VERSION})`));\n\t\t\t\treturn { packageName: PACKAGE_NAME, shouldRun: false };\n\t\t\t}\n\t\t}\n\t} catch {\n\t\t// Registry/network error: fall through and attempt the update anyway.\n\t}\n\treturn { packageName: PACKAGE_NAME, shouldRun: true };\n}\n\nasync function runSelfUpdate(command: SelfUpdateCommand): Promise<void> {\n\tconsole.log(chalk.dim(`Updating ${APP_NAME} with ${command.display}...`));\n\tfor (const step of command.steps ?? [command]) {\n\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t// Windows package managers are commonly .cmd shims. Use the shell so Node can execute them.\n\t\t\tconst child = spawn(step.command, step.args, {\n\t\t\t\tstdio: \"inherit\",\n\t\t\t\tshell: shouldUseWindowsShell(step.command),\n\t\t\t});\n\t\t\tchild.on(\"error\", (error) => {\n\t\t\t\treject(error);\n\t\t\t});\n\t\t\tchild.on(\"close\", (code, signal) => {\n\t\t\t\tif (code === 0) {\n\t\t\t\t\tresolve();\n\t\t\t\t} else if (signal) {\n\t\t\t\t\treject(new Error(`${step.display} terminated by signal ${signal}`));\n\t\t\t\t} else {\n\t\t\t\t\treject(new Error(`${step.display} exited with code ${code ?? \"unknown\"}`));\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\t}\n}\n\nexport async function handleConfigCommand(args: string[]): Promise<boolean> {\n\tif (args[0] !== \"config\") {\n\t\treturn false;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"config command\");\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\tconst resolvedPaths = await packageManager.resolve();\n\n\tawait selectConfig({\n\t\tresolvedPaths,\n\t\tsettingsManager,\n\t\tcwd,\n\t\tagentDir,\n\t});\n\n\tprocess.exit(0);\n}\n\nexport async function handlePackageCommand(args: string[]): Promise<boolean> {\n\tconst options = parsePackageCommand(args);\n\tif (!options) {\n\t\treturn false;\n\t}\n\n\tif (options.help) {\n\t\tprintPackageCommandHelp(options.command);\n\t\treturn true;\n\t}\n\n\tif (options.invalidOption) {\n\t\tconsole.error(chalk.red(`Unknown option ${options.invalidOption} for \"${options.command}\".`));\n\t\tconsole.error(chalk.dim(`Use \"${APP_NAME} --help\" or \"${getPackageCommandUsage(options.command)}\".`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.missingOptionValue) {\n\t\tconsole.error(chalk.red(`Missing value for ${options.missingOptionValue}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.invalidArgument) {\n\t\tconsole.error(chalk.red(`Unexpected argument ${options.invalidArgument}.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tif (options.conflictingOptions) {\n\t\tconsole.error(chalk.red(options.conflictingOptions));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst source = options.source;\n\tif ((options.command === \"install\" || options.command === \"remove\") && !source) {\n\t\tconsole.error(chalk.red(`Missing ${options.command} source.`));\n\t\tconsole.error(chalk.dim(`Usage: ${getPackageCommandUsage(options.command)}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n\n\tconst cwd = process.cwd();\n\tconst agentDir = getAgentDir();\n\tconst settingsManager = SettingsManager.create(cwd, agentDir);\n\treportSettingsErrors(settingsManager, \"package command\");\n\tconst selfUpdateNpmCommand = settingsManager.getGlobalSettings().npmCommand;\n\n\tconst packageManager = new DefaultPackageManager({ cwd, agentDir, settingsManager });\n\n\tpackageManager.setProgressCallback((event) => {\n\t\tif (event.type === \"start\") {\n\t\t\tprocess.stdout.write(chalk.dim(`${event.message}\\n`));\n\t\t}\n\t});\n\n\ttry {\n\t\tswitch (options.command) {\n\t\t\tcase \"install\":\n\t\t\t\tawait packageManager.installAndPersist(source!, { local: options.local });\n\t\t\t\tconsole.log(chalk.green(`Installed ${source}`));\n\t\t\t\treturn true;\n\n\t\t\tcase \"remove\": {\n\t\t\t\tconst removed = await packageManager.removeAndPersist(source!, { local: options.local });\n\t\t\t\tif (!removed) {\n\t\t\t\t\tconsole.error(chalk.red(`No matching package found for ${source}`));\n\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tconsole.log(chalk.green(`Removed ${source}`));\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"list\": {\n\t\t\t\tconst configuredPackages = packageManager.listConfiguredPackages();\n\t\t\t\tconst userPackages = configuredPackages.filter((pkg) => pkg.scope === \"user\");\n\t\t\t\tconst projectPackages = configuredPackages.filter((pkg) => pkg.scope === \"project\");\n\n\t\t\t\tif (configuredPackages.length === 0) {\n\t\t\t\t\tconsole.log(chalk.dim(\"No packages installed.\"));\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\n\t\t\t\tconst formatPackage = (pkg: (typeof configuredPackages)[number]) => {\n\t\t\t\t\tconst display = pkg.filtered ? `${pkg.source} (filtered)` : pkg.source;\n\t\t\t\t\tconsole.log(` ${display}`);\n\t\t\t\t\tif (pkg.installedPath) {\n\t\t\t\t\t\tconsole.log(chalk.dim(` ${pkg.installedPath}`));\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tif (userPackages.length > 0) {\n\t\t\t\t\tconsole.log(chalk.bold(\"User packages:\"));\n\t\t\t\t\tfor (const pkg of userPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (projectPackages.length > 0) {\n\t\t\t\t\tif (userPackages.length > 0) console.log();\n\t\t\t\t\tconsole.log(chalk.bold(\"Project packages:\"));\n\t\t\t\t\tfor (const pkg of projectPackages) {\n\t\t\t\t\t\tformatPackage(pkg);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\tcase \"update\": {\n\t\t\t\tconst target = options.updateTarget ?? { type: \"all\" };\n\t\t\t\tif (updateTargetIncludesExtensions(target)) {\n\t\t\t\t\tconst updateSource = target.type === \"extensions\" ? target.source : undefined;\n\t\t\t\t\tawait packageManager.update(updateSource);\n\t\t\t\t\tif (updateSource) {\n\t\t\t\t\t\tconsole.log(chalk.green(`Updated ${updateSource}`));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.log(chalk.green(\"Updated packages\"));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif (updateTargetIncludesSelf(target)) {\n\t\t\t\t\tconst selfUpdatePlan = await getSelfUpdatePlan(options.force);\n\t\t\t\t\tif (!selfUpdatePlan.shouldRun) {\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconst selfUpdateCommand = getSelfUpdateCommand(\n\t\t\t\t\t\tPACKAGE_NAME,\n\t\t\t\t\t\tselfUpdateNpmCommand,\n\t\t\t\t\t\tselfUpdatePlan.packageName,\n\t\t\t\t\t);\n\t\t\t\t\tif (!selfUpdateCommand) {\n\t\t\t\t\t\tprintSelfUpdateUnavailable(selfUpdateNpmCommand, selfUpdatePlan.packageName);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait runSelfUpdate(selfUpdateCommand);\n\t\t\t\t\t} catch (error: unknown) {\n\t\t\t\t\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\t\t\t\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\t\t\t\t\tprintSelfUpdateFallback(selfUpdateCommand);\n\t\t\t\t\t\tprocess.exitCode = 1;\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t}\n\t\t\t\t\tconsole.log(chalk.green(`Updated ${APP_NAME}`));\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\t} catch (error: unknown) {\n\t\tconst message = error instanceof Error ? error.message : \"Unknown package command error\";\n\t\tconsole.error(chalk.red(`Error: ${message}`));\n\t\tprocess.exitCode = 1;\n\t\treturn true;\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-user-agent.d.ts","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pi-user-agent.d.ts","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAIA,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGtD","sourcesContent":["import { APP_NAME } from \"../config.js\";\n\n// Function name kept as-is (upstream-merge friendly); the emitted UA string\n// follows the configured app name (\"phi/<version> (...)\" for phi-code).\nexport function getPiUserAgent(version: string): string {\n\tconst runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;\n\treturn `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;\n}\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { APP_NAME } from "../config.js";
|
|
2
|
+
// Function name kept as-is (upstream-merge friendly); the emitted UA string
|
|
3
|
+
// follows the configured app name ("phi/<version> (...)" for phi-code).
|
|
1
4
|
export function getPiUserAgent(version) {
|
|
2
5
|
const runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;
|
|
3
|
-
return
|
|
6
|
+
return `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;
|
|
4
7
|
}
|
|
5
8
|
//# sourceMappingURL=pi-user-agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pi-user-agent.js","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAC,OAAe,EAAU;IACvD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,OAAO,EAAE,CAAC;IACjG,OAAO,
|
|
1
|
+
{"version":3,"file":"pi-user-agent.js","sourceRoot":"","sources":["../../src/utils/pi-user-agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,4EAA4E;AAC5E,wEAAwE;AACxE,MAAM,UAAU,cAAc,CAAC,OAAe,EAAU;IACvD,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,OAAO,CAAC,OAAO,EAAE,CAAC;IACjG,OAAO,GAAG,QAAQ,IAAI,OAAO,KAAK,OAAO,CAAC,QAAQ,KAAK,OAAO,KAAK,OAAO,CAAC,IAAI,GAAG,CAAC;AAAA,CACnF","sourcesContent":["import { APP_NAME } from \"../config.js\";\n\n// Function name kept as-is (upstream-merge friendly); the emitted UA string\n// follows the configured app name (\"phi/<version> (...)\" for phi-code).\nexport function getPiUserAgent(version: string): string {\n\tconst runtime = process.versions.bun ? `bun/${process.versions.bun}` : `node/${process.version}`;\n\treturn `${APP_NAME}/${version} (${process.platform}; ${runtime}; ${process.arch})`;\n}\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export interface
|
|
1
|
+
export interface LatestRelease {
|
|
2
2
|
version: string;
|
|
3
3
|
packageName?: string;
|
|
4
4
|
}
|
|
5
5
|
export declare function comparePackageVersions(leftVersion: string, rightVersion: string): number | undefined;
|
|
6
6
|
export declare function isNewerPackageVersion(candidateVersion: string, currentVersion: string): boolean;
|
|
7
|
-
export declare function
|
|
7
|
+
export declare function getLatestRelease(currentVersion: string, options?: {
|
|
8
8
|
timeoutMs?: number;
|
|
9
|
-
}): Promise<
|
|
10
|
-
export declare function
|
|
9
|
+
}): Promise<LatestRelease | undefined>;
|
|
10
|
+
export declare function getLatestVersion(currentVersion: string, options?: {
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
}): Promise<string | undefined>;
|
|
13
|
-
export declare function
|
|
13
|
+
export declare function checkForNewVersion(currentVersion: string): Promise<string | undefined>;
|
|
14
14
|
//# sourceMappingURL=version-check.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-check.d.ts","sourceRoot":"","sources":["../../src/utils/version-check.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"version-check.d.ts","sourceRoot":"","sources":["../../src/utils/version-check.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,aAAa;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAsBD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAcpG;AAED,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAM/F;AAED,wBAAsB,gBAAgB,CACrC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAClC,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAkBpC;AAED,wBAAsB,gBAAgB,CACrC,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,MAAM,CAAA;CAAO,GAClC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAE7B;AAED,wBAAsB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAU5F","sourcesContent":["import { PACKAGE_NAME } from \"../config.js\";\nimport { getPiUserAgent } from \"./pi-user-agent.js\";\n\n// Version checks query the npm registry for the published phi-code package.\n// (The inherited flow queried pi.dev, the upstream Pi endpoint, which reported\n// upstream Pi releases and made \"Update Available\" fire for versions of the\n// wrong product.)\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org\";\nconst DEFAULT_VERSION_CHECK_TIMEOUT_MS = 10000;\n\nexport interface LatestRelease {\n\tversion: string;\n\tpackageName?: string;\n}\n\ninterface ParsedVersion {\n\tmajor: number;\n\tminor: number;\n\tpatch: number;\n\tprerelease?: string;\n}\n\nfunction parsePackageVersion(version: string): ParsedVersion | undefined {\n\tconst match = version.trim().match(/^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?(?:\\+.*)?$/);\n\tif (!match) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tmajor: Number.parseInt(match[1], 10),\n\t\tminor: Number.parseInt(match[2], 10),\n\t\tpatch: Number.parseInt(match[3], 10),\n\t\tprerelease: match[4],\n\t};\n}\n\nexport function comparePackageVersions(leftVersion: string, rightVersion: string): number | undefined {\n\tconst left = parsePackageVersion(leftVersion);\n\tconst right = parsePackageVersion(rightVersion);\n\tif (!left || !right) {\n\t\treturn undefined;\n\t}\n\n\tif (left.major !== right.major) return left.major - right.major;\n\tif (left.minor !== right.minor) return left.minor - right.minor;\n\tif (left.patch !== right.patch) return left.patch - right.patch;\n\tif (left.prerelease === right.prerelease) return 0;\n\tif (!left.prerelease) return 1;\n\tif (!right.prerelease) return -1;\n\treturn left.prerelease.localeCompare(right.prerelease);\n}\n\nexport function isNewerPackageVersion(candidateVersion: string, currentVersion: string): boolean {\n\tconst comparison = comparePackageVersions(candidateVersion, currentVersion);\n\tif (comparison !== undefined) {\n\t\treturn comparison > 0;\n\t}\n\treturn candidateVersion.trim() !== currentVersion.trim();\n}\n\nexport async function getLatestRelease(\n\tcurrentVersion: string,\n\toptions: { timeoutMs?: number } = {},\n): Promise<LatestRelease | undefined> {\n\tif (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE) return undefined;\n\n\tconst response = await fetch(`${NPM_REGISTRY_URL}/${PACKAGE_NAME}/latest`, {\n\t\theaders: {\n\t\t\t\"User-Agent\": getPiUserAgent(currentVersion),\n\t\t\taccept: \"application/json\",\n\t\t},\n\t\tsignal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_VERSION_CHECK_TIMEOUT_MS),\n\t});\n\tif (!response.ok) return undefined;\n\n\tconst data = (await response.json()) as { name?: unknown; version?: unknown };\n\tif (typeof data.version !== \"string\" || !data.version.trim()) {\n\t\treturn undefined;\n\t}\n\tconst packageName = typeof data.name === \"string\" && data.name.trim() ? data.name.trim() : undefined;\n\treturn { version: data.version.trim(), packageName };\n}\n\nexport async function getLatestVersion(\n\tcurrentVersion: string,\n\toptions: { timeoutMs?: number } = {},\n): Promise<string | undefined> {\n\treturn (await getLatestRelease(currentVersion, options))?.version;\n}\n\nexport async function checkForNewVersion(currentVersion: string): Promise<string | undefined> {\n\ttry {\n\t\tconst latestVersion = await getLatestVersion(currentVersion);\n\t\tif (latestVersion && isNewerPackageVersion(latestVersion, currentVersion)) {\n\t\t\treturn latestVersion;\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { PACKAGE_NAME } from "../config.js";
|
|
1
2
|
import { getPiUserAgent } from "./pi-user-agent.js";
|
|
2
|
-
|
|
3
|
+
// Version checks query the npm registry for the published phi-code package.
|
|
4
|
+
// (The inherited flow queried pi.dev, the upstream Pi endpoint, which reported
|
|
5
|
+
// upstream Pi releases and made "Update Available" fire for versions of the
|
|
6
|
+
// wrong product.)
|
|
7
|
+
const NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
3
8
|
const DEFAULT_VERSION_CHECK_TIMEOUT_MS = 10000;
|
|
4
9
|
function parsePackageVersion(version) {
|
|
5
10
|
const match = version.trim().match(/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/);
|
|
@@ -40,10 +45,10 @@ export function isNewerPackageVersion(candidateVersion, currentVersion) {
|
|
|
40
45
|
}
|
|
41
46
|
return candidateVersion.trim() !== currentVersion.trim();
|
|
42
47
|
}
|
|
43
|
-
export async function
|
|
48
|
+
export async function getLatestRelease(currentVersion, options = {}) {
|
|
44
49
|
if (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE)
|
|
45
50
|
return undefined;
|
|
46
|
-
const response = await fetch(
|
|
51
|
+
const response = await fetch(`${NPM_REGISTRY_URL}/${PACKAGE_NAME}/latest`, {
|
|
47
52
|
headers: {
|
|
48
53
|
"User-Agent": getPiUserAgent(currentVersion),
|
|
49
54
|
accept: "application/json",
|
|
@@ -56,15 +61,15 @@ export async function getLatestPiRelease(currentVersion, options = {}) {
|
|
|
56
61
|
if (typeof data.version !== "string" || !data.version.trim()) {
|
|
57
62
|
return undefined;
|
|
58
63
|
}
|
|
59
|
-
const packageName = typeof data.
|
|
64
|
+
const packageName = typeof data.name === "string" && data.name.trim() ? data.name.trim() : undefined;
|
|
60
65
|
return { version: data.version.trim(), packageName };
|
|
61
66
|
}
|
|
62
|
-
export async function
|
|
63
|
-
return (await
|
|
67
|
+
export async function getLatestVersion(currentVersion, options = {}) {
|
|
68
|
+
return (await getLatestRelease(currentVersion, options))?.version;
|
|
64
69
|
}
|
|
65
|
-
export async function
|
|
70
|
+
export async function checkForNewVersion(currentVersion) {
|
|
66
71
|
try {
|
|
67
|
-
const latestVersion = await
|
|
72
|
+
const latestVersion = await getLatestVersion(currentVersion);
|
|
68
73
|
if (latestVersion && isNewerPackageVersion(latestVersion, currentVersion)) {
|
|
69
74
|
return latestVersion;
|
|
70
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-check.js","sourceRoot":"","sources":["../../src/utils/version-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,
|
|
1
|
+
{"version":3,"file":"version-check.js","sourceRoot":"","sources":["../../src/utils/version-check.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,4EAA4E;AAC5E,+EAA+E;AAC/E,4EAA4E;AAC5E,kBAAkB;AAClB,MAAM,gBAAgB,GAAG,4BAA4B,CAAC;AACtD,MAAM,gCAAgC,GAAG,KAAK,CAAC;AAc/C,SAAS,mBAAmB,CAAC,OAAe,EAA6B;IACxE,MAAM,KAAK,GAAG,OAAO,C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,QAAQ,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACrG,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,WAAW,EAAE,CAAC;AAAA,CACrD;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACrC,cAAsB,EACtB,OAAO,GAA2B,EAAE,EACN;IAC9B,OAAO,CAAC,MAAM,gBAAgB,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC;AAAA,CAClE;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,cAAsB,EAA+B;IAC7F,IAAI,CAAC;QACJ,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,cAAc,CAAC,CAAC;QAC7D,IAAI,aAAa,IAAI,qBAAqB,CAAC,aAAa,EAAE,cAAc,CAAC,EAAE,CAAC;YAC3E,OAAO,aAAa,CAAC;QACtB,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;AAAA,CACD","sourcesContent":["import { PACKAGE_NAME } from \"../config.js\";\nimport { getPiUserAgent } from \"./pi-user-agent.js\";\n\n// Version checks query the npm registry for the published phi-code package.\n// (The inherited flow queried pi.dev, the upstream Pi endpoint, which reported\n// upstream Pi releases and made \"Update Available\" fire for versions of the\n// wrong product.)\nconst NPM_REGISTRY_URL = \"https://registry.npmjs.org\";\nconst DEFAULT_VERSION_CHECK_TIMEOUT_MS = 10000;\n\nexport interface LatestRelease {\n\tversion: string;\n\tpackageName?: string;\n}\n\ninterface ParsedVersion {\n\tmajor: number;\n\tminor: number;\n\tpatch: number;\n\tprerelease?: string;\n}\n\nfunction parsePackageVersion(version: string): ParsedVersion | undefined {\n\tconst match = version.trim().match(/^v?(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?(?:\\+.*)?$/);\n\tif (!match) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tmajor: Number.parseInt(match[1], 10),\n\t\tminor: Number.parseInt(match[2], 10),\n\t\tpatch: Number.parseInt(match[3], 10),\n\t\tprerelease: match[4],\n\t};\n}\n\nexport function comparePackageVersions(leftVersion: string, rightVersion: string): number | undefined {\n\tconst left = parsePackageVersion(leftVersion);\n\tconst right = parsePackageVersion(rightVersion);\n\tif (!left || !right) {\n\t\treturn undefined;\n\t}\n\n\tif (left.major !== right.major) return left.major - right.major;\n\tif (left.minor !== right.minor) return left.minor - right.minor;\n\tif (left.patch !== right.patch) return left.patch - right.patch;\n\tif (left.prerelease === right.prerelease) return 0;\n\tif (!left.prerelease) return 1;\n\tif (!right.prerelease) return -1;\n\treturn left.prerelease.localeCompare(right.prerelease);\n}\n\nexport function isNewerPackageVersion(candidateVersion: string, currentVersion: string): boolean {\n\tconst comparison = comparePackageVersions(candidateVersion, currentVersion);\n\tif (comparison !== undefined) {\n\t\treturn comparison > 0;\n\t}\n\treturn candidateVersion.trim() !== currentVersion.trim();\n}\n\nexport async function getLatestRelease(\n\tcurrentVersion: string,\n\toptions: { timeoutMs?: number } = {},\n): Promise<LatestRelease | undefined> {\n\tif (process.env.PI_SKIP_VERSION_CHECK || process.env.PI_OFFLINE) return undefined;\n\n\tconst response = await fetch(`${NPM_REGISTRY_URL}/${PACKAGE_NAME}/latest`, {\n\t\theaders: {\n\t\t\t\"User-Agent\": getPiUserAgent(currentVersion),\n\t\t\taccept: \"application/json\",\n\t\t},\n\t\tsignal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_VERSION_CHECK_TIMEOUT_MS),\n\t});\n\tif (!response.ok) return undefined;\n\n\tconst data = (await response.json()) as { name?: unknown; version?: unknown };\n\tif (typeof data.version !== \"string\" || !data.version.trim()) {\n\t\treturn undefined;\n\t}\n\tconst packageName = typeof data.name === \"string\" && data.name.trim() ? data.name.trim() : undefined;\n\treturn { version: data.version.trim(), packageName };\n}\n\nexport async function getLatestVersion(\n\tcurrentVersion: string,\n\toptions: { timeoutMs?: number } = {},\n): Promise<string | undefined> {\n\treturn (await getLatestRelease(currentVersion, options))?.version;\n}\n\nexport async function checkForNewVersion(currentVersion: string): Promise<string | undefined> {\n\ttry {\n\t\tconst latestVersion = await getLatestVersion(currentVersion);\n\t\tif (latestVersion && isNewerPackageVersion(latestVersion, currentVersion)) {\n\t\t\treturn latestVersion;\n\t\t}\n\t\treturn undefined;\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n"]}
|
package/docs/compaction.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Compaction & Branch Summarization
|
|
2
2
|
|
|
3
|
-
LLMs have limited context windows. When conversations grow too long,
|
|
3
|
+
LLMs have limited context windows. When conversations grow too long, phi uses compaction to summarize older content while preserving recent work. This page covers both auto-compaction and branch summarization.
|
|
4
4
|
|
|
5
5
|
**Source files** ([pi-mono](https://github.com/earendil-works/pi-mono)):
|
|
6
6
|
- [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Auto-compaction logic
|
|
@@ -9,11 +9,11 @@ LLMs have limited context windows. When conversations grow too long, pi uses com
|
|
|
9
9
|
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
|
|
10
10
|
- [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/earendil-works/pi-mono/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
|
|
11
11
|
|
|
12
|
-
For TypeScript definitions in your project, inspect `node_modules/@
|
|
12
|
+
For TypeScript definitions in your project, inspect `node_modules/@phi-code-admin/phi-code/dist/`.
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
phi has two summarization mechanisms:
|
|
17
17
|
|
|
18
18
|
| Mechanism | Trigger | Purpose |
|
|
19
19
|
|-----------|---------|---------|
|
|
@@ -32,13 +32,13 @@ Auto-compaction triggers when:
|
|
|
32
32
|
contextTokens > contextWindow - reserveTokens
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
By default, `reserveTokens` is 16384 tokens (configurable in `~/.
|
|
35
|
+
By default, `reserveTokens` is 16384 tokens (configurable in `~/.phi/agent/settings.json` or `<project-dir>/.pi/settings.json`). This leaves room for the LLM's response.
|
|
36
36
|
|
|
37
37
|
You can also trigger manually with `/compact [instructions]`, where optional instructions focus the summary.
|
|
38
38
|
|
|
39
39
|
### How It Works
|
|
40
40
|
|
|
41
|
-
1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.
|
|
41
|
+
1. **Find cut point**: Walk backwards from newest message, accumulating token estimates until `keepRecentTokens` (default 20k, configurable in `~/.phi/agent/settings.json` or `<project-dir>/.pi/settings.json`) is reached
|
|
42
42
|
2. **Extract messages**: Collect messages from the previous kept boundary (or session start) up to the cut point
|
|
43
43
|
3. **Generate summary**: Call LLM to summarize with structured format, passing the previous summary as iterative context when present
|
|
44
44
|
4. **Append entry**: Save `CompactionEntry` with summary and `firstKeptEntryId`
|
|
@@ -76,7 +76,7 @@ What the LLM sees:
|
|
|
76
76
|
prompt from cmp messages from firstKeptEntryId
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well.
|
|
79
|
+
On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. phi also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
|
|
80
80
|
|
|
81
81
|
### Split Turns
|
|
82
82
|
|
|
@@ -102,7 +102,7 @@ Split turn (one huge turn exceeds budget):
|
|
|
102
102
|
turnPrefixMessages = [usr, ass, tool, ass, tool, tool]
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
For split turns,
|
|
105
|
+
For split turns, phi generates two summaries and merges them:
|
|
106
106
|
1. **History summary**: Previous context (if any)
|
|
107
107
|
2. **Turn prefix summary**: The early part of the split turn
|
|
108
108
|
|
|
@@ -148,7 +148,7 @@ See [`prepareCompaction()`](https://github.com/earendil-works/pi-mono/blob/main/
|
|
|
148
148
|
|
|
149
149
|
### When It Triggers
|
|
150
150
|
|
|
151
|
-
When you use `/tree` to navigate to a different branch,
|
|
151
|
+
When you use `/tree` to navigate to a different branch, phi offers to summarize the work you're leaving. This injects context from the left branch into the new branch.
|
|
152
152
|
|
|
153
153
|
### How It Works
|
|
154
154
|
|
|
@@ -177,7 +177,7 @@ After navigation with summary:
|
|
|
177
177
|
|
|
178
178
|
### Cumulative File Tracking
|
|
179
179
|
|
|
180
|
-
Both compaction and branch summarization track files cumulatively. When generating a summary,
|
|
180
|
+
Both compaction and branch summarization track files cumulatively. When generating a summary, phi extracts file operations from:
|
|
181
181
|
- Tool calls in the messages being summarized
|
|
182
182
|
- Previous compaction or branch summary `details` (if any)
|
|
183
183
|
|
|
@@ -309,7 +309,7 @@ pi.on("session_before_compact", async (event, ctx) => {
|
|
|
309
309
|
To generate a summary with your own model, convert messages to text using `serializeConversation`:
|
|
310
310
|
|
|
311
311
|
```typescript
|
|
312
|
-
import { convertToLlm, serializeConversation } from "@
|
|
312
|
+
import { convertToLlm, serializeConversation } from "@phi-code-admin/phi-code";
|
|
313
313
|
|
|
314
314
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
315
315
|
const { preparation } = event;
|
|
@@ -373,7 +373,7 @@ See `SessionBeforeTreeEvent` and `TreePreparation` in the types file.
|
|
|
373
373
|
|
|
374
374
|
## Settings
|
|
375
375
|
|
|
376
|
-
Configure compaction in `~/.
|
|
376
|
+
Configure compaction in `~/.phi/agent/settings.json` or `<project-dir>/.pi/settings.json`:
|
|
377
377
|
|
|
378
378
|
```json
|
|
379
379
|
{
|
package/docs/custom-provider.md
CHANGED
|
@@ -30,7 +30,7 @@ See these complete provider examples:
|
|
|
30
30
|
## Quick Reference
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
|
-
import type { ExtensionAPI } from "@
|
|
33
|
+
import type { ExtensionAPI } from "@phi-code-admin/phi-code";
|
|
34
34
|
|
|
35
35
|
export default function (pi: ExtensionAPI) {
|
|
36
36
|
// Override baseUrl for existing provider
|
|
@@ -59,7 +59,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
The extension factory can also be `async`. For dynamic model discovery, fetch and register models in the factory instead of `session_start`.
|
|
62
|
+
The extension factory can also be `async`. For dynamic model discovery, fetch and register models in the factory instead of `session_start`. phi waits for the factory before startup continues, so the provider is available during interactive startup and to `phi --list-models`.
|
|
63
63
|
|
|
64
64
|
## Override Existing Provider
|
|
65
65
|
|
|
@@ -96,7 +96,7 @@ To add a completely new provider, specify `models` along with the required confi
|
|
|
96
96
|
If the model list comes from a remote endpoint, use an async extension factory:
|
|
97
97
|
|
|
98
98
|
```typescript
|
|
99
|
-
import type { ExtensionAPI } from "@
|
|
99
|
+
import type { ExtensionAPI } from "@phi-code-admin/phi-code";
|
|
100
100
|
|
|
101
101
|
export default async function (pi: ExtensionAPI) {
|
|
102
102
|
const response = await fetch("http://localhost:1234/v1/models");
|
|
@@ -330,7 +330,7 @@ interface OAuthLoginCallbacks {
|
|
|
330
330
|
|
|
331
331
|
### OAuthCredentials
|
|
332
332
|
|
|
333
|
-
Credentials are persisted in `~/.
|
|
333
|
+
Credentials are persisted in `~/.phi/agent/auth.json`:
|
|
334
334
|
|
|
335
335
|
```typescript
|
|
336
336
|
interface OAuthCredentials {
|
package/docs/development.md
CHANGED
|
@@ -17,7 +17,7 @@ Run from source:
|
|
|
17
17
|
/path/to/pi-mono/pi-test.sh
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
The script can be run from any directory.
|
|
20
|
+
The script can be run from any directory. phi keeps the caller's current working directory.
|
|
21
21
|
|
|
22
22
|
## Forking / Rebranding
|
|
23
23
|
|
|
@@ -48,7 +48,7 @@ Never use `__dirname` directly for package assets.
|
|
|
48
48
|
|
|
49
49
|
## Debug Command
|
|
50
50
|
|
|
51
|
-
`/debug` (hidden) writes to `~/.
|
|
51
|
+
`/debug` (hidden) writes to `~/.phi/agent/pi-debug.log`:
|
|
52
52
|
- Rendered TUI lines with ANSI codes
|
|
53
53
|
- Last messages sent to the LLM
|
|
54
54
|
|