/** * Manifest bootstrap — the "this repo has no profiles yet" path. * * `install` and `update` both require `.claude/profiles.json`. Rather than * giving each a manifest-free fallback (two behaviours to keep in step, and a * repo that never gets a committed manifest), a repo without one is offered * adoption: claudeup writes the manifest that describes the project as it * stands, then the original command proceeds against it normally. */ import { getManifestPath, readManifest, writeManifest, } from "../services/manifest.js"; import { type AdoptResult, adoptCurrentProject, } from "../services/profile-adopt.js"; import type { ProfileManifest } from "../types/index.js"; import { confirm } from "./prompt.js"; /** Print what adoption would capture, so the user can judge it before writing. */ function printAdoptionPlan(result: AdoptResult): void { console.log( "\nThis project has no .claude/profiles.json — claudeup can create one from its current setup.\n", ); console.log(` profile ${result.profileId} (${result.entry.name})`); console.log( ` plugins ${result.counts.plugins} enabled, adopted as "latest"`, ); if (result.source === "user") { // Never let this be invisible: the generated file is meant to be committed, // and these came from ~/.claude/settings.json — this machine's personal // global set, not anything this repo chose. console.log( " ⚠ read from ~/.claude/settings.json (user scope) — this project", ); console.log( " enables none of its own. Review before committing.", ); } if (result.counts.mcpServers > 0) { console.log(` mcp servers ${result.counts.mcpServers} from .mcp.json`); } if (result.counts.settingsKeys > 0) { console.log( ` settings ${result.counts.settingsKeys} keys carried over`, ); } for (const id of result.skipped) { console.log( ` ⚠ skipped ${id} — no marketplace in its id, not reproducible`, ); } for (const hit of result.machinePaths) { console.log(` ⚠ machine path ${hit}`); } if (result.machinePaths.length > 0) { console.log( " Those name a directory on THIS machine and will not resolve on another.", ); } console.log( "\nCommit the file to share this setup with the team; edit it to pin versions.", ); } export interface EnsureManifestOptions { /** Read-only mode: never write, just report that adoption is needed. */ check?: boolean; /** * Adopt without prompting. Set only by `claudeup profile init`, where * creating the manifest IS the command the user asked for. */ allowAdopt?: boolean; } /** * Return the project's manifest, creating one by adoption if it has none. * * Resolves to null when there is no manifest and none was created — the caller * should exit non-zero. Anything it prints has already explained why. */ export async function ensureManifest( projectPath: string, opts: EnsureManifestOptions = {}, ): Promise { const manifest = await readManifest(projectPath); if (Object.keys(manifest.profiles).length > 0) return manifest; const result = await adoptCurrentProject(projectPath); if (result.counts.plugins === 0) { console.error( `No .claude/profiles.json in ${projectPath}, and no enabled plugins to adopt one from.`, ); console.error( "Open claudeup and select the plugins this project needs, then re-run.", ); return null; } printAdoptionPlan(result); if (opts.check) { console.error( "\n--check is read-only and will not create the manifest. Run `claudeup install` once to adopt.", ); return null; } // `--yes` alone is NOT consent to author this file. It means "do not ask me // about the thing I invoked", and someone running `claudeup update --yes` in // CI invoked an update, not the creation of their team's committed contract — // which this would otherwise write unreviewed, possibly from the machine's // user-scope plugin set. Creating it needs either a human at the prompt or // the command whose whole purpose is to create it. if (opts.allowAdopt) { // fall through to the write } else if (!process.stdin.isTTY) { console.error( "\nRefusing to create .claude/profiles.json without a human: run `claudeup profile init` to create it deliberately.", ); return null; } else if (!(await confirm("\nCreate .claude/profiles.json?"))) { console.log("Aborted — nothing written."); return null; } await writeManifest(result.manifest, projectPath); console.log(`✓ Wrote ${getManifestPath(projectPath)}\n`); return result.manifest; }