diff --git a/src/tui/apply/index.ts b/src/tui/apply/index.ts index e1ae4f4..2a778b4 100644 --- a/src/tui/apply/index.ts +++ b/src/tui/apply/index.ts @@ -586,7 +586,7 @@ export async function runApplyTUI( case 'personality': if (key.name === 'return' && activeSelect) { - const idx = activeSelect.selectedIndex; + const idx = activeSelect.getSelectedIndex(); const speciesDefault = DEFAULT_PERSONALITIES[desired.species] ?? null; const values = speciesDefault ? ['keep', 'default', 'custom'] : ['keep', 'custom']; const choice = values[idx]; diff --git a/src/tui/commands/apply.ts b/src/tui/commands/apply.ts index 6d4c814..db70983 100644 --- a/src/tui/commands/apply.ts +++ b/src/tui/commands/apply.ts @@ -8,9 +8,30 @@ import { getMinSaltCount, } from '@/patcher/salt-ops.js'; import { patchBinary } from '@/patcher/patch.js'; -import { loadPetConfig } from '@/config/index.js'; +import { + loadPetConfig, + loadPetConfigV2, + renameCompanion, + setCompanionPersonality, +} from '@/config/index.js'; import { warnCodesign } from '../display.ts'; +function restoreProfileIdentity(salt: string): void { + const configV2 = loadPetConfigV2(); + const profile = configV2?.profiles[salt]; + if (!profile) return; + try { + if (profile.name) renameCompanion(profile.name); + } catch { + /* companion may not be hatched yet */ + } + try { + if (profile.personality) setCompanionPersonality(profile.personality); + } catch { + /* companion may not be hatched yet */ + } +} + export async function runApply({ silent = false } = {}): Promise { const config = loadPetConfig(); if (!config?.salt) { @@ -29,6 +50,7 @@ export async function runApply({ silent = false } = {}): Promise { const check = verifySalt(binaryPath, config.salt); if (check.found >= getMinSaltCount(binaryPath)) { if (!silent) console.log(chalk.green(' Pet already applied.')); + restoreProfileIdentity(config.salt); return; } @@ -44,6 +66,7 @@ export async function runApply({ silent = false } = {}): Promise { console.log(chalk.green(` Re-patched (${result.replacements} replacements).`)); } warnCodesign(result, binaryPath); + restoreProfileIdentity(config.salt); return; } } @@ -54,6 +77,7 @@ export async function runApply({ silent = false } = {}): Promise { console.log(chalk.green(` Patched after update (${result.replacements} replacements).`)); } warnCodesign(result, binaryPath); + restoreProfileIdentity(config.salt); return; } if (!silent) @@ -71,4 +95,5 @@ export async function runApply({ silent = false } = {}): Promise { console.log(chalk.yellow(' Restart Claude Code for the change to take effect.')); } } + restoreProfileIdentity(config.salt); }