#!/usr/bin/env tsx /** * Rebrand script: keeps the CLI published as @boujot/happy-coder (binary `boujot`, config `~/.boujot`). * * Usage: yarn rebrand * * master is already rebranded, so on master this script changes nothing. The release script * (scripts/release-boujot-cli.sh) runs it as a check and stops if it would change any file. * It is still the tool to convert upstream happy-coder code (`happy`, `.happy`) when adopting it. * * ## Branches and releases * * ``` * master ← the one development line, already @boujot/happy-coder * ├── feat/*, fix/* ← short-lived work, merged into master * └── tag boujot-cli-v ← each published release: a version commit on master * ``` * * master only ever moves forward; a release never needs a forced push. * * ## Adopting Upstream Changes * * Don't merge - review upstream diffs and apply them to master manually or via LLM, then run * `yarn rebrand` and commit what it converts. * * ## Publishing the CLI to npm * * ```bash * git switch master && git pull --ff-only master * npm run release:boujot -- * git push master boujot-cli-v * ``` */ import { readFileSync, writeFileSync, renameSync, existsSync } from 'node:fs'; import { join } from 'node:path'; const CLI_DIR = join(import.meta.dirname, '..'); // Brand replacements const OLD_PACKAGE_NAME = 'happy-coder'; const NEW_PACKAGE_NAME = '@boujot/happy-coder'; const OLD_BINARY = 'happy'; const NEW_BINARY = 'boujot'; const OLD_CONFIG_DIR = '.happy'; const NEW_CONFIG_DIR = '.boujot'; /** * Replace all occurrences of a pattern in a file */ function replaceInFile(filePath: string, replacements: [string | RegExp, string][]): void { if (!existsSync(filePath)) { console.log(` ⚠️ File not found: ${filePath}`); return; } let content = readFileSync(filePath, 'utf-8'); let modified = false; for (const [pattern, replacement] of replacements) { const newContent = content.replace(pattern, replacement); if (newContent !== content) { content = newContent; modified = true; } } if (modified) { writeFileSync(filePath, content, 'utf-8'); console.log(` ✓ Updated: ${filePath}`); } } /** * Rename a file if source exists */ function renameFile(oldPath: string, newPath: string): void { if (existsSync(oldPath)) { renameSync(oldPath, newPath); console.log(` ✓ Renamed: ${oldPath} → ${newPath}`); } else if (existsSync(newPath)) { console.log(` ✓ Already renamed: ${newPath}`); } else { console.log(` ⚠️ Source not found: ${oldPath}`); } } function main() { console.log('\n🔄 Rebranding happy-coder → @boujot/happy-coder\n'); // 1. Update package.json console.log('📦 Updating package.json...'); const packageJsonPath = join(CLI_DIR, 'package.json'); const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')); packageJson.name = NEW_PACKAGE_NAME; packageJson.bin = { [NEW_BINARY]: `./bin/${NEW_BINARY}.mjs`, [`${NEW_BINARY}-mcp`]: `./bin/${NEW_BINARY}-mcp.mjs` }; writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n', 'utf-8'); console.log(` ✓ Updated: package.json`); // 2. Rename bin files console.log('\n📁 Renaming bin files...'); renameFile( join(CLI_DIR, 'bin', 'happy.mjs'), join(CLI_DIR, 'bin', `${NEW_BINARY}.mjs`) ); renameFile( join(CLI_DIR, 'bin', 'happy-mcp.mjs'), join(CLI_DIR, 'bin', `${NEW_BINARY}-mcp.mjs`) ); // 3. Update MCP bridge references in source code (matches bin rename above) console.log('\n🔗 Updating MCP bridge path references...'); const mcpBridgeFiles = [ 'src/codex/runCodex.ts', 'src/gemini/runGemini.ts', ]; for (const file of mcpBridgeFiles) { replaceInFile(join(CLI_DIR, file), [ [/happy-mcp\.mjs/g, `${NEW_BINARY}-mcp.mjs`], ]); } // 4. Update configuration.ts - change config directory console.log('\n⚙️ Updating configuration path...'); replaceInFile(join(CLI_DIR, 'src', 'configuration.ts'), [ [/join\(homedir\(\), '\.happy'\)/g, `join(homedir(), '${NEW_CONFIG_DIR}')`], [/'\.happy'/g, `'${NEW_CONFIG_DIR}'`], ]); // 5. Update help text in source files console.log('\n📝 Updating help text...'); // Files with help text to update const helpTextReplacements: [string | RegExp, string][] = [ // chalk.bold with quotes [/\$\{chalk\.bold\('happy'\)\}/g, `\${chalk.bold('${NEW_BINARY}')}`], [/\$\{chalk\.bold\('happy /g, `\${chalk.bold('${NEW_BINARY} `], [/\$\{chalk\.cyan\('happy /g, `\${chalk.cyan('${NEW_BINARY} `], // Multi-line help text - command listings (with proper spacing) [/ happy \[options\]/g, ` ${NEW_BINARY} [options]`], [/ happy auth /g, ` ${NEW_BINARY} auth `], [/ happy codex /g, ` ${NEW_BINARY} codex `], [/ happy gemini /g, ` ${NEW_BINARY} gemini `], [/ happy connect /g, ` ${NEW_BINARY} connect `], [/ happy notify /g, ` ${NEW_BINARY} notify `], [/ happy daemon /g, ` ${NEW_BINARY} daemon `], [/ happy doctor /g, ` ${NEW_BINARY} doctor `], // Single-quoted strings [/'happy auth/g, `'${NEW_BINARY} auth`], [/'happy connect/g, `'${NEW_BINARY} connect`], [/'happy daemon/g, `'${NEW_BINARY} daemon`], [/'happy doctor/g, `'${NEW_BINARY} doctor`], [/'happy notify/g, `'${NEW_BINARY} notify`], [/'happy logout/g, `'${NEW_BINARY} logout`], [/'happy gemini/g, `'${NEW_BINARY} gemini`], // Double-quoted strings [/"happy auth/g, `"${NEW_BINARY} auth`], [/"happy connect/g, `"${NEW_BINARY} connect`], [/"happy daemon/g, `"${NEW_BINARY} daemon`], [/"happy doctor/g, `"${NEW_BINARY} doctor`], [/"happy notify/g, `"${NEW_BINARY} notify`], [/"happy logout/g, `"${NEW_BINARY} logout`], [/"happy gemini/g, `"${NEW_BINARY} gemini`], // Examples section (with proper spacing preserved) [/ happy Start session/g, ` ${NEW_BINARY} Start session`], [/happy --yolo/g, `${NEW_BINARY} --yolo`], [/happy --chrome/g, `${NEW_BINARY} --chrome`], [/happy --no-chrome/g, `${NEW_BINARY} --no-chrome`], [/happy --js-runtime/g, `${NEW_BINARY} --js-runtime`], [/happy --claude-env/g, `${NEW_BINARY} --claude-env`], [/happy --resume/g, `${NEW_BINARY} --resume`], [/happy sugar for/g, `${NEW_BINARY} sugar for`], // CLI supports phrase [/Happy supports ALL/g, `Boujot supports ALL`], [/flag with happy as/g, `flag with ${NEW_BINARY} as`], // Version output [/console\.log\(`happy version:/g, `console.log(\`${NEW_BINARY} version:`], // Error messages with backticks [/run \`happy auth\`/g, `run \`${NEW_BINARY} auth\``], [/`happy auth`/g, `\`${NEW_BINARY} auth\``], [/`happy doctor clean`/g, `\`${NEW_BINARY} doctor clean\``], // Startup and log messages [/Starting happy CLI/g, `Starting ${NEW_BINARY} CLI`], [/happy directly/g, `${NEW_BINARY} directly`], [/const fullCommand = `happy /g, `const fullCommand = \`${NEW_BINARY} `], // Usage lines [/Usage: happy /g, `Usage: ${NEW_BINARY} `], ]; const sourceFiles = [ 'src/index.ts', 'src/commands/auth.ts', 'src/commands/connect.ts', 'src/api/api.ts', // serverConnectionErrors.ts uses configuration.cliName at runtime — no rebrand needed // serverConnectionErrors.test.ts hardcodes 'happy' to match the test-time cliName 'src/utils/spawnHappyCLI.ts', 'src/agent/factories/gemini.ts', 'src/gemini/runGemini.ts', 'src/daemon/controlClient.ts', 'src/daemon/run.ts', 'src/daemon/daemon.integration.test.ts', 'src/daemon/CLAUDE.md', 'src/claude/utils/startHookServer.ts', ]; for (const file of sourceFiles) { replaceInFile(join(CLI_DIR, file), helpTextReplacements); } // 6. Update spawnHappyCLI.ts specifically console.log('\n🔧 Updating spawn command...'); replaceInFile(join(CLI_DIR, 'src/utils/spawnHappyCLI.ts'), [ [/const fullCommand = `happy /g, `const fullCommand = \`${NEW_BINARY} `], ]); // 7. Update daemon/run.ts specifically replaceInFile(join(CLI_DIR, 'src/daemon/run.ts'), [ [`'happy directly`, `'${NEW_BINARY} directly`], ]); // 8. Update integration tests replaceInFile(join(CLI_DIR, 'src/daemon/daemon.integration.test.ts'), [ [`'happy directly`, `'${NEW_BINARY} directly`], ]); // 9. Update auth.ts QR code messages console.log('\n📱 Updating QR code messages...'); replaceInFile(join(CLI_DIR, 'src/ui/auth.ts'), [ [/Happy mobile app/g, 'Boujot mobile app'], ]); // 10. Update README.md for npm console.log('\n📄 Updating README.md...'); replaceInFile(join(CLI_DIR, 'README.md'), [ [/# Happy\n/g, `# Boujot\n`], [/npm install -g happy-coder/g, `npm install -g ${NEW_PACKAGE_NAME}`], [/^happy$/gm, NEW_BINARY], [/^happy /gm, `${NEW_BINARY} `], [/`happy`/g, `\`${NEW_BINARY}\``], [/`happy /g, `\`${NEW_BINARY} `], [/'happy'/g, `'${NEW_BINARY}'`], [/~\/\.happy\b/g, `~/${NEW_CONFIG_DIR}`], [/happy gemini\b/g, `${NEW_BINARY} gemini`], [/Free\. Open source\./g, 'Open source.'], ]); console.log('\n✅ Rebranding complete!\n'); console.log('Next steps:'); console.log(' 1. yarn build # Build the CLI'); console.log(` 2. node ./bin/${NEW_BINARY}.mjs --help # Test locally`); console.log(' 3. npm publish --access public # Publish to npm\n'); } main();