diff --git a/bin/install.js b/bin/install.js index b348677d9..05f686221 100755 --- a/bin/install.js +++ b/bin/install.js @@ -23,6 +23,7 @@ const hasLocal = args.includes('--local') || args.includes('-l'); const hasOpencode = args.includes('--opencode'); const hasClaude = args.includes('--claude'); const hasGemini = args.includes('--gemini'); +const hasCodex = args.includes('--codex'); const hasBoth = args.includes('--both'); // Legacy flag, keeps working const hasAll = args.includes('--all'); const hasUninstall = args.includes('--uninstall') || args.includes('-u'); @@ -30,26 +31,28 @@ const hasUninstall = args.includes('--uninstall') || args.includes('-u'); // Runtime selection - can be set by flags or interactive prompt let selectedRuntimes = []; if (hasAll) { - selectedRuntimes = ['claude', 'opencode', 'gemini']; + selectedRuntimes = ['claude', 'opencode', 'gemini', 'codex']; } else if (hasBoth) { selectedRuntimes = ['claude', 'opencode']; } else { if (hasOpencode) selectedRuntimes.push('opencode'); if (hasClaude) selectedRuntimes.push('claude'); if (hasGemini) selectedRuntimes.push('gemini'); + if (hasCodex) selectedRuntimes.push('codex'); } // Helper to get directory name for a runtime (used for local/project installs) function getDirName(runtime) { if (runtime === 'opencode') return '.opencode'; if (runtime === 'gemini') return '.gemini'; + if (runtime === 'codex') return '.codex'; return '.claude'; } /** * Get the config directory path relative to home directory for a runtime * Used for templating hooks that use path.join(homeDir, '', ...) - * @param {string} runtime - 'claude', 'opencode', or 'gemini' + * @param {string} runtime - 'claude', 'opencode', 'gemini', or 'codex' * @param {boolean} isGlobal - Whether this is a global install */ function getConfigDirFromHome(runtime, isGlobal) { @@ -64,6 +67,7 @@ function getConfigDirFromHome(runtime, isGlobal) { return "'.config', 'opencode'"; } if (runtime === 'gemini') return "'.gemini'"; + if (runtime === 'codex') return "'.codex'"; return "'.claude'"; } @@ -94,7 +98,7 @@ function getOpencodeGlobalDir() { /** * Get the global config directory for a runtime - * @param {string} runtime - 'claude', 'opencode', or 'gemini' + * @param {string} runtime - 'claude', 'opencode', 'gemini', or 'codex' * @param {string|null} explicitDir - Explicit directory from --config-dir flag */ function getGlobalDir(runtime, explicitDir = null) { @@ -116,6 +120,17 @@ function getGlobalDir(runtime, explicitDir = null) { } return path.join(os.homedir(), '.gemini'); } + + if (runtime === 'codex') { + // Codex: --config-dir > CODEX_HOME > ~/.codex + if (explicitDir) { + return expandTilde(explicitDir); + } + if (process.env.CODEX_HOME) { + return expandTilde(process.env.CODEX_HOME); + } + return path.join(os.homedir(), '.codex'); + } // Claude Code: --config-dir > CLAUDE_CONFIG_DIR > ~/.claude if (explicitDir) { @@ -137,7 +152,7 @@ const banner = '\n' + '\n' + ' Get Shit Done ' + dim + 'v' + pkg.version + reset + '\n' + ' A meta-prompting, context engineering and spec-driven\n' + - ' development system for Claude Code, OpenCode, and Gemini by TÂCHES.\n'; + ' development system for Claude Code, OpenCode, Gemini, and Codex by TÂCHES.\n'; // Parse --config-dir argument function parseConfigDirArg() { @@ -171,7 +186,7 @@ console.log(banner); // Show help if requested if (hasHelp) { - console.log(` ${yellow}Usage:${reset} npx get-shit-done-cc [options]\n\n ${yellow}Options:${reset}\n ${cyan}-g, --global${reset} Install globally (to config directory)\n ${cyan}-l, --local${reset} Install locally (to current directory)\n ${cyan}--claude${reset} Install for Claude Code only\n ${cyan}--opencode${reset} Install for OpenCode only\n ${cyan}--gemini${reset} Install for Gemini only\n ${cyan}--all${reset} Install for all runtimes\n ${cyan}-u, --uninstall${reset} Uninstall GSD (remove all GSD files)\n ${cyan}-c, --config-dir ${reset} Specify custom config directory\n ${cyan}-h, --help${reset} Show this help message\n ${cyan}--force-statusline${reset} Replace existing statusline config\n\n ${yellow}Examples:${reset}\n ${dim}# Interactive install (prompts for runtime and location)${reset}\n npx get-shit-done-cc\n\n ${dim}# Install for Claude Code globally${reset}\n npx get-shit-done-cc --claude --global\n\n ${dim}# Install for Gemini globally${reset}\n npx get-shit-done-cc --gemini --global\n\n ${dim}# Install for all runtimes globally${reset}\n npx get-shit-done-cc --all --global\n\n ${dim}# Install to custom config directory${reset}\n npx get-shit-done-cc --claude --global --config-dir ~/.claude-bc\n\n ${dim}# Install to current project only${reset}\n npx get-shit-done-cc --claude --local\n\n ${dim}# Uninstall GSD from Claude Code globally${reset}\n npx get-shit-done-cc --claude --global --uninstall\n\n ${yellow}Notes:${reset}\n The --config-dir option is useful when you have multiple configurations.\n It takes priority over CLAUDE_CONFIG_DIR / GEMINI_CONFIG_DIR environment variables.\n`); + console.log(` ${yellow}Usage:${reset} npx get-shit-done-cc [options]\n\n ${yellow}Options:${reset}\n ${cyan}-g, --global${reset} Install globally (to config directory)\n ${cyan}-l, --local${reset} Install locally (to current directory)\n ${cyan}--claude${reset} Install for Claude Code only\n ${cyan}--opencode${reset} Install for OpenCode only\n ${cyan}--gemini${reset} Install for Gemini only\n ${cyan}--codex${reset} Install for Codex only\n ${cyan}--all${reset} Install for all runtimes\n ${cyan}-u, --uninstall${reset} Uninstall GSD (remove all GSD files)\n ${cyan}-c, --config-dir ${reset} Specify custom config directory\n ${cyan}-h, --help${reset} Show this help message\n ${cyan}--force-statusline${reset} Replace existing statusline config\n\n ${yellow}Examples:${reset}\n ${dim}# Interactive install (prompts for runtime and location)${reset}\n npx get-shit-done-cc\n\n ${dim}# Install for Claude Code globally${reset}\n npx get-shit-done-cc --claude --global\n\n ${dim}# Install for Gemini globally${reset}\n npx get-shit-done-cc --gemini --global\n\n ${dim}# Install for Codex globally${reset}\n npx get-shit-done-cc --codex --global\n\n ${dim}# Install for all runtimes globally${reset}\n npx get-shit-done-cc --all --global\n\n ${dim}# Install to custom config directory${reset}\n npx get-shit-done-cc --codex --global --config-dir ~/.codex-work\n\n ${dim}# Install to current project only${reset}\n npx get-shit-done-cc --claude --local\n\n ${dim}# Uninstall GSD from Codex globally${reset}\n npx get-shit-done-cc --codex --global --uninstall\n\n ${yellow}Notes:${reset}\n The --config-dir option is useful when you have multiple configurations.\n It takes priority over CLAUDE_CONFIG_DIR / GEMINI_CONFIG_DIR / CODEX_HOME environment variables.\n`); process.exit(0); } @@ -221,7 +236,7 @@ const attributionCache = new Map(); /** * Get commit attribution setting for a runtime - * @param {string} runtime - 'claude', 'opencode', or 'gemini' + * @param {string} runtime - 'claude', 'opencode', 'gemini', or 'codex' * @returns {null|undefined|string} null = remove, undefined = keep default, string = custom */ function getCommitAttribution(runtime) { @@ -245,7 +260,7 @@ function getCommitAttribution(runtime) { } else { result = settings.attribution.commit; } - } else { + } else if (runtime === 'claude') { // Claude Code const settings = readSettings(path.join(getGlobalDir('claude', explicitConfigDir), 'settings.json')); if (!settings.attribution || settings.attribution.commit === undefined) { @@ -255,6 +270,9 @@ function getCommitAttribution(runtime) { } else { result = settings.attribution.commit; } + } else { + // Codex currently has no attribution setting equivalent + result = undefined; } // Cache and return @@ -371,6 +389,83 @@ function convertGeminiToolName(claudeTool) { return claudeTool.toLowerCase(); } +function toSingleLine(value) { + return value.replace(/\s+/g, ' ').trim(); +} + +function yamlQuote(value) { + return JSON.stringify(value); +} + +function extractFrontmatterAndBody(content) { + if (!content.startsWith('---')) { + return { frontmatter: null, body: content }; + } + + const endIndex = content.indexOf('---', 3); + if (endIndex === -1) { + return { frontmatter: null, body: content }; + } + + return { + frontmatter: content.substring(3, endIndex).trim(), + body: content.substring(endIndex + 3), + }; +} + +function extractFrontmatterField(frontmatter, fieldName) { + const regex = new RegExp(`^${fieldName}:\\s*(.+)$`, 'm'); + const match = frontmatter.match(regex); + if (!match) return null; + return match[1].trim().replace(/^['"]|['"]$/g, ''); +} + +function convertSlashCommandsToCodexSkillMentions(content) { + let converted = content.replace(/\/gsd:([a-z0-9-]+)/gi, (_, commandName) => { + return `$gsd-${String(commandName).toLowerCase()}`; + }); + converted = converted.replace(/\/gsd-help\b/g, '$gsd-help'); + return converted; +} + +function convertClaudeToCodexMarkdown(content) { + let converted = convertSlashCommandsToCodexSkillMentions(content); + converted = converted.replace(/\$ARGUMENTS\b/g, '{{GSD_ARGS}}'); + return converted; +} + +function getCodexSkillAdapterHeader(skillName) { + const invocation = `$${skillName}`; + return ` +Codex skills-first mode: +- This skill is invoked by mentioning \`${invocation}\`. +- Treat all user text after \`${invocation}\` as \`{{GSD_ARGS}}\`. +- If no arguments are present, treat \`{{GSD_ARGS}}\` as empty. + +Legacy orchestration compatibility: +- Any \`Task(...)\` pattern in referenced workflow docs is legacy syntax. +- Implement equivalent behavior with Codex collaboration tools: \`spawn_agent\`, \`wait\`, \`send_input\`, and \`close_agent\`. +- Treat legacy \`subagent_type\` names as role hints in the spawned message. +`; +} + +function convertClaudeCommandToCodexSkill(content, skillName) { + const converted = convertClaudeToCodexMarkdown(content); + const { frontmatter, body } = extractFrontmatterAndBody(converted); + let description = `Run GSD workflow ${skillName}.`; + if (frontmatter) { + const maybeDescription = extractFrontmatterField(frontmatter, 'description'); + if (maybeDescription) { + description = maybeDescription; + } + } + description = toSingleLine(description); + const shortDescription = description.length > 180 ? `${description.slice(0, 177)}...` : description; + const adapter = getCodexSkillAdapterHeader(skillName); + + return `---\nname: ${yamlQuote(skillName)}\ndescription: ${yamlQuote(description)}\nmetadata:\n short-description: ${yamlQuote(shortDescription)}\n---\n\n${adapter}\n\n${body.trimStart()}`; +} + /** * Strip HTML tags for Gemini CLI output * Terminals don't support subscript — Gemini renders these as raw HTML. @@ -672,16 +767,78 @@ function copyFlattenedCommands(srcDir, destDir, prefix, pathPrefix, runtime) { } } +function listCodexSkillNames(skillsDir, prefix = 'gsd-') { + if (!fs.existsSync(skillsDir)) return []; + const entries = fs.readdirSync(skillsDir, { withFileTypes: true }); + return entries + .filter(entry => entry.isDirectory() && entry.name.startsWith(prefix)) + .filter(entry => fs.existsSync(path.join(skillsDir, entry.name, 'SKILL.md'))) + .map(entry => entry.name) + .sort(); +} + +function copyCommandsAsCodexSkills(srcDir, skillsDir, prefix, pathPrefix, runtime) { + if (!fs.existsSync(srcDir)) { + return; + } + + fs.mkdirSync(skillsDir, { recursive: true }); + + // Remove previous GSD Codex skills to avoid stale command skills. + const existing = fs.readdirSync(skillsDir, { withFileTypes: true }); + for (const entry of existing) { + if (entry.isDirectory() && entry.name.startsWith(`${prefix}-`)) { + fs.rmSync(path.join(skillsDir, entry.name), { recursive: true }); + } + } + + function recurse(currentSrcDir, currentPrefix) { + const entries = fs.readdirSync(currentSrcDir, { withFileTypes: true }); + + for (const entry of entries) { + const srcPath = path.join(currentSrcDir, entry.name); + if (entry.isDirectory()) { + recurse(srcPath, `${currentPrefix}-${entry.name}`); + continue; + } + + if (!entry.name.endsWith('.md')) { + continue; + } + + const baseName = entry.name.replace('.md', ''); + const skillName = `${currentPrefix}-${baseName}`; + const skillDir = path.join(skillsDir, skillName); + fs.mkdirSync(skillDir, { recursive: true }); + + let content = fs.readFileSync(srcPath, 'utf8'); + const globalClaudeRegex = /~\/\.claude\//g; + const localClaudeRegex = /\.\/\.claude\//g; + const codexDirRegex = /~\/\.codex\//g; + content = content.replace(globalClaudeRegex, pathPrefix); + content = content.replace(localClaudeRegex, `./${getDirName(runtime)}/`); + content = content.replace(codexDirRegex, pathPrefix); + content = processAttribution(content, getCommitAttribution(runtime)); + content = convertClaudeCommandToCodexSkill(content, skillName); + + fs.writeFileSync(path.join(skillDir, 'SKILL.md'), content); + } + } + + recurse(srcDir, prefix); +} + /** * Recursively copy directory, replacing paths in .md files * Deletes existing destDir first to remove orphaned files from previous versions * @param {string} srcDir - Source directory * @param {string} destDir - Destination directory * @param {string} pathPrefix - Path prefix for file references - * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini') + * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini', 'codex') */ function copyWithPathReplacement(srcDir, destDir, pathPrefix, runtime) { const isOpencode = runtime === 'opencode'; + const isCodex = runtime === 'codex'; const dirName = getDirName(runtime); // Clean install: remove existing destination to prevent orphaned files @@ -718,6 +875,9 @@ function copyWithPathReplacement(srcDir, destDir, pathPrefix, runtime) { // Replace extension with .toml const tomlPath = destPath.replace(/\.md$/, '.toml'); fs.writeFileSync(tomlPath, tomlContent); + } else if (isCodex) { + content = convertClaudeToCodexMarkdown(content); + fs.writeFileSync(destPath, content); } else { fs.writeFileSync(destPath, content); } @@ -806,10 +966,11 @@ function cleanupOrphanedHooks(settings) { * Uninstall GSD from the specified directory for a specific runtime * Removes only GSD-specific files/directories, preserves user content * @param {boolean} isGlobal - Whether to uninstall from global or local - * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini') + * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini', 'codex') */ function uninstall(isGlobal, runtime = 'claude') { const isOpencode = runtime === 'opencode'; + const isCodex = runtime === 'codex'; const dirName = getDirName(runtime); // Get the target directory based on runtime and install type @@ -824,6 +985,7 @@ function uninstall(isGlobal, runtime = 'claude') { let runtimeLabel = 'Claude Code'; if (runtime === 'opencode') runtimeLabel = 'OpenCode'; if (runtime === 'gemini') runtimeLabel = 'Gemini'; + if (runtime === 'codex') runtimeLabel = 'Codex'; console.log(` Uninstalling GSD from ${cyan}${runtimeLabel}${reset} at ${cyan}${locationLabel}${reset}\n`); @@ -836,7 +998,7 @@ function uninstall(isGlobal, runtime = 'claude') { let removedCount = 0; - // 1. Remove GSD commands directory + // 1. Remove GSD commands/skills if (isOpencode) { // OpenCode: remove command/gsd-*.md files const commandDir = path.join(targetDir, 'command'); @@ -850,6 +1012,23 @@ function uninstall(isGlobal, runtime = 'claude') { } console.log(` ${green}✓${reset} Removed GSD commands from command/`); } + } else if (isCodex) { + // Codex: remove skills/gsd-*/SKILL.md skill directories + const skillsDir = path.join(targetDir, 'skills'); + if (fs.existsSync(skillsDir)) { + let skillCount = 0; + const entries = fs.readdirSync(skillsDir, { withFileTypes: true }); + for (const entry of entries) { + if (entry.isDirectory() && entry.name.startsWith('gsd-')) { + fs.rmSync(path.join(skillsDir, entry.name), { recursive: true }); + skillCount++; + } + } + if (skillCount > 0) { + removedCount++; + console.log(` ${green}✓${reset} Removed ${skillCount} Codex skills`); + } + } } else { // Claude Code & Gemini: remove commands/gsd/ directory const gsdCommandsDir = path.join(targetDir, 'commands', 'gsd'); @@ -1190,7 +1369,7 @@ function verifyFileInstalled(filePath, description) { /** * Install to the specified directory for a specific runtime * @param {boolean} isGlobal - Whether to install globally or locally - * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini') + * @param {string} runtime - Target runtime ('claude', 'opencode', 'gemini', 'codex') */ // ────────────────────────────────────────────────────── @@ -1231,9 +1410,13 @@ function generateManifest(dir, baseDir) { /** * Write file manifest after installation for future modification detection */ -function writeManifest(configDir) { +function writeManifest(configDir, runtime = 'claude') { + const isOpencode = runtime === 'opencode'; + const isCodex = runtime === 'codex'; const gsdDir = path.join(configDir, 'get-shit-done'); const commandsDir = path.join(configDir, 'commands', 'gsd'); + const opencodeCommandDir = path.join(configDir, 'command'); + const codexSkillsDir = path.join(configDir, 'skills'); const agentsDir = path.join(configDir, 'agents'); const manifest = { version: pkg.version, timestamp: new Date().toISOString(), files: {} }; @@ -1241,12 +1424,28 @@ function writeManifest(configDir) { for (const [rel, hash] of Object.entries(gsdHashes)) { manifest.files['get-shit-done/' + rel] = hash; } - if (fs.existsSync(commandsDir)) { + if (!isOpencode && !isCodex && fs.existsSync(commandsDir)) { const cmdHashes = generateManifest(commandsDir); for (const [rel, hash] of Object.entries(cmdHashes)) { manifest.files['commands/gsd/' + rel] = hash; } } + if (isOpencode && fs.existsSync(opencodeCommandDir)) { + for (const file of fs.readdirSync(opencodeCommandDir)) { + if (file.startsWith('gsd-') && file.endsWith('.md')) { + manifest.files['command/' + file] = fileHash(path.join(opencodeCommandDir, file)); + } + } + } + if (isCodex && fs.existsSync(codexSkillsDir)) { + for (const skillName of listCodexSkillNames(codexSkillsDir)) { + const skillRoot = path.join(codexSkillsDir, skillName); + const skillHashes = generateManifest(skillRoot); + for (const [rel, hash] of Object.entries(skillHashes)) { + manifest.files[`skills/${skillName}/${rel}`] = hash; + } + } + } if (fs.existsSync(agentsDir)) { for (const file of fs.readdirSync(agentsDir)) { if (file.startsWith('gsd-') && file.endsWith('.md')) { @@ -1303,7 +1502,7 @@ function saveLocalPatches(configDir) { /** * After install, report backed-up patches for user to reapply. */ -function reportLocalPatches(configDir) { +function reportLocalPatches(configDir, runtime = 'claude') { const patchesDir = path.join(configDir, PATCHES_DIR_NAME); const metaPath = path.join(patchesDir, 'backup-meta.json'); if (!fs.existsSync(metaPath)) return []; @@ -1312,6 +1511,11 @@ function reportLocalPatches(configDir) { try { meta = JSON.parse(fs.readFileSync(metaPath, 'utf8')); } catch { return []; } if (meta.files && meta.files.length > 0) { + const reapplyCommand = runtime === 'opencode' + ? '/gsd-reapply-patches' + : runtime === 'codex' + ? '$gsd-reapply-patches' + : '/gsd:reapply-patches'; console.log(''); console.log(' ' + yellow + 'Local patches detected' + reset + ' (from v' + meta.from_version + '):'); for (const f of meta.files) { @@ -1319,7 +1523,7 @@ function reportLocalPatches(configDir) { } console.log(''); console.log(' Your modifications are saved in ' + cyan + PATCHES_DIR_NAME + '/' + reset); - console.log(' Run ' + cyan + '/gsd:reapply-patches' + reset + ' to merge them into the new version.'); + console.log(' Run ' + cyan + reapplyCommand + reset + ' to merge them into the new version.'); console.log(' Or manually compare and merge the files.'); console.log(''); } @@ -1329,6 +1533,7 @@ function reportLocalPatches(configDir) { function install(isGlobal, runtime = 'claude') { const isOpencode = runtime === 'opencode'; const isGemini = runtime === 'gemini'; + const isCodex = runtime === 'codex'; const dirName = getDirName(runtime); const src = path.join(__dirname, '..'); @@ -1351,6 +1556,7 @@ function install(isGlobal, runtime = 'claude') { let runtimeLabel = 'Claude Code'; if (isOpencode) runtimeLabel = 'OpenCode'; if (isGemini) runtimeLabel = 'Gemini'; + if (isCodex) runtimeLabel = 'Codex'; console.log(` Installing for ${cyan}${runtimeLabel}${reset} to ${cyan}${locationLabel}${reset}\n`); @@ -1363,8 +1569,7 @@ function install(isGlobal, runtime = 'claude') { // Clean up orphaned files from previous versions cleanupOrphanedFiles(targetDir); - // OpenCode uses 'command/' (singular) with flat structure - // Claude Code & Gemini use 'commands/' (plural) with nested structure + // OpenCode uses command/ (flat), Codex uses skills/, Claude/Gemini use commands/gsd/ if (isOpencode) { // OpenCode: flat structure in command/ directory const commandDir = path.join(targetDir, 'command'); @@ -1379,6 +1584,16 @@ function install(isGlobal, runtime = 'claude') { } else { failures.push('command/gsd-*'); } + } else if (isCodex) { + const skillsDir = path.join(targetDir, 'skills'); + const gsdSrc = path.join(src, 'commands', 'gsd'); + copyCommandsAsCodexSkills(gsdSrc, skillsDir, 'gsd', pathPrefix, runtime); + const installedSkillNames = listCodexSkillNames(skillsDir); + if (installedSkillNames.length > 0) { + console.log(` ${green}✓${reset} Installed ${installedSkillNames.length} skills to skills/`); + } else { + failures.push('skills/gsd-*'); + } } else { // Claude Code & Gemini: nested structure in commands/ directory const commandsDir = path.join(targetDir, 'commands'); @@ -1433,6 +1648,8 @@ function install(isGlobal, runtime = 'claude') { content = convertClaudeToOpencodeFrontmatter(content); } else if (isGemini) { content = convertClaudeToGeminiAgent(content); + } else if (isCodex) { + content = convertClaudeToCodexMarkdown(content); } fs.writeFileSync(path.join(agentsDest, entry.name), content); } @@ -1465,39 +1682,41 @@ function install(isGlobal, runtime = 'claude') { failures.push('VERSION'); } - // Write package.json to force CommonJS mode for GSD scripts - // Prevents "require is not defined" errors when project has "type": "module" - // Node.js walks up looking for package.json - this stops inheritance from project - const pkgJsonDest = path.join(targetDir, 'package.json'); - fs.writeFileSync(pkgJsonDest, '{"type":"commonjs"}\n'); - console.log(` ${green}✓${reset} Wrote package.json (CommonJS mode)`); + if (!isCodex) { + // Write package.json to force CommonJS mode for GSD scripts + // Prevents "require is not defined" errors when project has "type": "module" + // Node.js walks up looking for package.json - this stops inheritance from project + const pkgJsonDest = path.join(targetDir, 'package.json'); + fs.writeFileSync(pkgJsonDest, '{"type":"commonjs"}\n'); + console.log(` ${green}✓${reset} Wrote package.json (CommonJS mode)`); - // Copy hooks from dist/ (bundled with dependencies) - // Template paths for the target runtime (replaces '.claude' with correct config dir) - const hooksSrc = path.join(src, 'hooks', 'dist'); - if (fs.existsSync(hooksSrc)) { - const hooksDest = path.join(targetDir, 'hooks'); - fs.mkdirSync(hooksDest, { recursive: true }); - const hookEntries = fs.readdirSync(hooksSrc); - const configDirReplacement = getConfigDirFromHome(runtime, isGlobal); - for (const entry of hookEntries) { - const srcFile = path.join(hooksSrc, entry); - if (fs.statSync(srcFile).isFile()) { - const destFile = path.join(hooksDest, entry); - // Template .js files to replace '.claude' with runtime-specific config dir - if (entry.endsWith('.js')) { - let content = fs.readFileSync(srcFile, 'utf8'); - content = content.replace(/'\.claude'/g, configDirReplacement); - fs.writeFileSync(destFile, content); - } else { - fs.copyFileSync(srcFile, destFile); + // Copy hooks from dist/ (bundled with dependencies) + // Template paths for the target runtime (replaces '.claude' with correct config dir) + const hooksSrc = path.join(src, 'hooks', 'dist'); + if (fs.existsSync(hooksSrc)) { + const hooksDest = path.join(targetDir, 'hooks'); + fs.mkdirSync(hooksDest, { recursive: true }); + const hookEntries = fs.readdirSync(hooksSrc); + const configDirReplacement = getConfigDirFromHome(runtime, isGlobal); + for (const entry of hookEntries) { + const srcFile = path.join(hooksSrc, entry); + if (fs.statSync(srcFile).isFile()) { + const destFile = path.join(hooksDest, entry); + // Template .js files to replace '.claude' with runtime-specific config dir + if (entry.endsWith('.js')) { + let content = fs.readFileSync(srcFile, 'utf8'); + content = content.replace(/'\.claude'/g, configDirReplacement); + fs.writeFileSync(destFile, content); + } else { + fs.copyFileSync(srcFile, destFile); + } } } - } - if (verifyInstalled(hooksDest, 'hooks')) { - console.log(` ${green}✓${reset} Installed hooks (bundled)`); - } else { - failures.push('hooks'); + if (verifyInstalled(hooksDest, 'hooks')) { + console.log(` ${green}✓${reset} Installed hooks (bundled)`); + } else { + failures.push('hooks'); + } } } @@ -1506,6 +1725,17 @@ function install(isGlobal, runtime = 'claude') { process.exit(1); } + // Write file manifest for future modification detection + writeManifest(targetDir, runtime); + console.log(` ${green}✓${reset} Wrote file manifest (${MANIFEST_NAME})`); + + // Report any backed-up local patches + reportLocalPatches(targetDir, runtime); + + if (isCodex) { + return { settingsPath: null, settings: null, statuslineCommand: null, runtime }; + } + // Configure statusline and hooks in settings.json // Gemini shares same hook system as Claude Code for now const settingsPath = path.join(targetDir, 'settings.json'); @@ -1554,13 +1784,6 @@ function install(isGlobal, runtime = 'claude') { } } - // Write file manifest for future modification detection - writeManifest(targetDir); - console.log(` ${green}✓${reset} Wrote file manifest (${MANIFEST_NAME})`); - - // Report any backed-up local patches - reportLocalPatches(targetDir); - return { settingsPath, settings, statuslineCommand, runtime }; } @@ -1569,8 +1792,9 @@ function install(isGlobal, runtime = 'claude') { */ function finishInstall(settingsPath, settings, statuslineCommand, shouldInstallStatusline, runtime = 'claude', isGlobal = true) { const isOpencode = runtime === 'opencode'; + const isCodex = runtime === 'codex'; - if (shouldInstallStatusline && !isOpencode) { + if (shouldInstallStatusline && !isOpencode && !isCodex) { settings.statusLine = { type: 'command', command: statuslineCommand @@ -1578,8 +1802,10 @@ function finishInstall(settingsPath, settings, statuslineCommand, shouldInstallS console.log(` ${green}✓${reset} Configured statusline`); } - // Always write settings - writeSettings(settingsPath, settings); + // Write settings when runtime supports settings.json + if (!isCodex) { + writeSettings(settingsPath, settings); + } // Configure OpenCode permissions if (isOpencode) { @@ -1589,8 +1815,11 @@ function finishInstall(settingsPath, settings, statuslineCommand, shouldInstallS let program = 'Claude Code'; if (runtime === 'opencode') program = 'OpenCode'; if (runtime === 'gemini') program = 'Gemini'; + if (runtime === 'codex') program = 'Codex'; - const command = isOpencode ? '/gsd-help' : '/gsd:help'; + let command = '/gsd:help'; + if (runtime === 'opencode') command = '/gsd-help'; + if (runtime === 'codex') command = '$gsd-help'; console.log(` ${green}Done!${reset} Launch ${program} and run ${cyan}${command}${reset}. @@ -1671,15 +1900,18 @@ function promptRuntime(callback) { console.log(` ${yellow}Which runtime(s) would you like to install for?${reset}\n\n ${cyan}1${reset}) Claude Code ${dim}(~/.claude)${reset} ${cyan}2${reset}) OpenCode ${dim}(~/.config/opencode)${reset} - open source, free models ${cyan}3${reset}) Gemini ${dim}(~/.gemini)${reset} - ${cyan}4${reset}) All + ${cyan}4${reset}) Codex ${dim}(~/.codex)${reset} + ${cyan}5${reset}) All `); rl.question(` Choice ${dim}[1]${reset}: `, (answer) => { answered = true; rl.close(); const choice = answer.trim() || '1'; - if (choice === '4') { - callback(['claude', 'opencode', 'gemini']); + if (choice === '5') { + callback(['claude', 'opencode', 'gemini', 'codex']); + } else if (choice === '4') { + callback(['codex']); } else if (choice === '3') { callback(['gemini']); } else if (choice === '2') { @@ -1746,34 +1978,27 @@ function installAllRuntimes(runtimes, isGlobal, isInteractive) { results.push(result); } - // Handle statusline for Claude & Gemini (OpenCode uses themes) - const claudeResult = results.find(r => r.runtime === 'claude'); - const geminiResult = results.find(r => r.runtime === 'gemini'); + const statuslineRuntimes = ['claude', 'gemini']; + const primaryStatuslineResult = results.find(r => statuslineRuntimes.includes(r.runtime)); - // Logic: if both are present, ask once if interactive? Or ask for each? - // Simpler: Ask once and apply to both if applicable. - - if (claudeResult || geminiResult) { - // Use whichever settings exist to check for existing statusline - const primaryResult = claudeResult || geminiResult; - - handleStatusline(primaryResult.settings, isInteractive, (shouldInstallStatusline) => { - if (claudeResult) { - finishInstall(claudeResult.settingsPath, claudeResult.settings, claudeResult.statuslineCommand, shouldInstallStatusline, 'claude', isGlobal); - } - if (geminiResult) { - finishInstall(geminiResult.settingsPath, geminiResult.settings, geminiResult.statuslineCommand, shouldInstallStatusline, 'gemini', isGlobal); - } + const finalize = (shouldInstallStatusline) => { + for (const result of results) { + const useStatusline = statuslineRuntimes.includes(result.runtime) && shouldInstallStatusline; + finishInstall( + result.settingsPath, + result.settings, + result.statuslineCommand, + useStatusline, + result.runtime, + isGlobal + ); + } + }; - const opencodeResult = results.find(r => r.runtime === 'opencode'); - if (opencodeResult) { - finishInstall(opencodeResult.settingsPath, opencodeResult.settings, opencodeResult.statuslineCommand, false, 'opencode', isGlobal); - } - }); + if (primaryStatuslineResult) { + handleStatusline(primaryStatuslineResult.settings, isInteractive, finalize); } else { - // Only OpenCode - const opencodeResult = results[0]; - finishInstall(opencodeResult.settingsPath, opencodeResult.settings, opencodeResult.statuslineCommand, false, 'opencode', isGlobal); + finalize(false); } }