diff --git a/cli/src/api/encryption.ts b/cli/src/api/encryption.ts deleted file mode 100644 index 600f122d..00000000 --- a/cli/src/api/encryption.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function encodeBase64(buffer: Uint8Array): string { - return Buffer.from(buffer).toString('base64') -} diff --git a/cli/src/commands/daemon.ts b/cli/src/commands/daemon.ts index 033d4cbf..22fae15e 100644 --- a/cli/src/commands/daemon.ts +++ b/cli/src/commands/daemon.ts @@ -9,8 +9,6 @@ import { import { getLatestDaemonLog } from '@/ui/logger' import { spawnHappyCLI } from '@/utils/spawnHappyCLI' import { runDoctorCommand } from '@/ui/doctor' -import { install } from '@/daemon/install' -import { uninstall } from '@/daemon/uninstall' import { initializeToken } from '@/ui/tokenInit' import type { CommandDefinition } from './types' @@ -104,26 +102,6 @@ export const daemonCommand: CommandDefinition = { process.exit(0) } - if (daemonSubcommand === 'install') { - try { - await install() - } catch (error) { - console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error') - process.exit(1) - } - return - } - - if (daemonSubcommand === 'uninstall') { - try { - await uninstall() - } catch (error) { - console.error(chalk.red('Error:'), error instanceof Error ? error.message : 'Unknown error') - process.exit(1) - } - return - } - console.log(` ${chalk.bold('hapi daemon')} - Daemon management diff --git a/cli/src/daemon/install.ts b/cli/src/daemon/install.ts deleted file mode 100644 index b15092fd..00000000 --- a/cli/src/daemon/install.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { logger } from '@/ui/logger'; -import { install as installMac } from './mac/install'; - -export async function install(): Promise { - if (process.platform === 'win32') { - throw new Error('Daemon installation as Windows service not yet supported. Use "hapi daemon start".'); - } - - if (process.platform !== 'darwin') { - throw new Error('Daemon installation is currently only supported on macOS'); - } - - if (process.getuid && process.getuid() !== 0) { - throw new Error('Daemon installation requires sudo privileges. Please run with sudo.'); - } - - logger.info('Installing HAPI CLI daemon for macOS...'); - await installMac(); -} diff --git a/cli/src/daemon/mac/install.ts b/cli/src/daemon/mac/install.ts deleted file mode 100644 index 3722d860..00000000 --- a/cli/src/daemon/mac/install.ts +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Installation script for HAPI daemon using macOS LaunchDaemons - * - * NOTE: This installation method is currently NOT USED in favor of auto-starting - * the daemon when the user runs the hapi command. - * - * Why we're not using this approach: - * 1. Installing a LaunchDaemon requires sudo permissions, which users might not be comfortable with - * 2. We assume users will run hapi frequently (every time they open their laptop) - * 3. The auto-start approach provides the same functionality without requiring elevated permissions - * - * This code is kept for potential future use if we decide to offer system-level installation as an option. - */ - -import { writeFileSync, chmodSync, existsSync } from 'fs'; -import { execSync } from 'child_process'; -import { logger } from '@/ui/logger'; -import { trimIdent } from '@/utils/trimIdent'; -import os from 'os'; - -const PLIST_LABEL = 'com.hapi-cli.daemon'; -const PLIST_FILE = `/Library/LaunchDaemons/${PLIST_LABEL}.plist`; - -// NOTE: Local installation like --local does not make too much sense I feel like - -export async function install(): Promise { - try { - // Check if already installed - if (existsSync(PLIST_FILE)) { - logger.info('Daemon plist already exists. Uninstalling first...'); - execSync(`launchctl unload ${PLIST_FILE}`, { stdio: 'inherit' }); - } - - // Get the path to the hapi CLI executable - const happyPath = process.argv[0]; // Node.js executable - const scriptPath = process.argv[1]; // Script path - - // Create plist content - const plistContent = trimIdent(` - - - - - Label - ${PLIST_LABEL} - - ProgramArguments - - ${happyPath} - ${scriptPath} - hapi-daemon - - - EnvironmentVariables - - HAPI_DAEMON_MODE - true - - - RunAtLoad - - - KeepAlive - - - StandardErrorPath - ${os.homedir()}/.hapi/daemon.err - - StandardOutPath - ${os.homedir()}/.hapi/daemon.log - - WorkingDirectory - /tmp - - - `); - - // Write plist file - writeFileSync(PLIST_FILE, plistContent); - chmodSync(PLIST_FILE, 0o644); - - logger.info(`Created daemon plist at ${PLIST_FILE}`); - - // Load the daemon - execSync(`launchctl load ${PLIST_FILE}`, { stdio: 'inherit' }); - - logger.info('Daemon installed and started successfully'); - logger.info('Check logs at ~/.hapi/daemon.log'); - - } catch (error) { - logger.debug('Failed to install daemon:', error); - throw error; - } -} diff --git a/cli/src/daemon/mac/uninstall.ts b/cli/src/daemon/mac/uninstall.ts deleted file mode 100644 index ce2aebdb..00000000 --- a/cli/src/daemon/mac/uninstall.ts +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Uninstallation script for HAPI daemon LaunchDaemon - * - * NOTE: This uninstallation method is currently NOT USED since we moved away from - * system-level daemon installation. See install.ts for the full explanation. - * - * This code is kept for potential future use if we decide to offer system-level - * installation/uninstallation as an option. - */ - -import { existsSync, unlinkSync } from 'fs'; -import { execSync } from 'child_process'; -import { logger } from '@/ui/logger'; - -const PLIST_LABEL = 'com.hapi-cli.daemon'; -const PLIST_FILE = `/Library/LaunchDaemons/${PLIST_LABEL}.plist`; - -export async function uninstall(): Promise { - try { - // Check if plist exists - if (!existsSync(PLIST_FILE)) { - logger.info('Daemon plist not found. Nothing to uninstall.'); - return; - } - - // Unload the daemon - try { - execSync(`launchctl unload ${PLIST_FILE}`, { stdio: 'inherit' }); - logger.info('Daemon stopped successfully'); - } catch (error) { - // Daemon might not be loaded, continue with removal - logger.info('Failed to unload daemon (it might not be running)'); - } - - // Remove the plist file - unlinkSync(PLIST_FILE); - logger.info(`Removed daemon plist from ${PLIST_FILE}`); - - logger.info('Daemon uninstalled successfully'); - - } catch (error) { - logger.debug('Failed to uninstall daemon:', error); - throw error; - } -} diff --git a/cli/src/daemon/uninstall.ts b/cli/src/daemon/uninstall.ts deleted file mode 100644 index e21ef05e..00000000 --- a/cli/src/daemon/uninstall.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { logger } from '@/ui/logger'; -import { uninstall as uninstallMac } from './mac/uninstall'; - -export async function uninstall(): Promise { - if (process.platform === 'win32') { - throw new Error('Daemon uninstallation as Windows service not yet supported. Use "hapi daemon start".'); - } - - if (process.platform !== 'darwin') { - throw new Error('Daemon uninstallation is currently only supported on macOS'); - } - - if (process.getuid && process.getuid() !== 0) { - throw new Error('Daemon uninstallation requires sudo privileges. Please run with sudo.'); - } - - logger.info('Uninstalling HAPI CLI daemon for macOS...'); - await uninstallMac(); -} diff --git a/cli/src/modules/common/gitHandlers.ts b/cli/src/modules/common/gitHandlers.ts deleted file mode 100644 index 7ef5ce6d..00000000 --- a/cli/src/modules/common/gitHandlers.ts +++ /dev/null @@ -1 +0,0 @@ -export { registerGitHandlers } from './handlers/git' diff --git a/cli/src/modules/common/registerCommonHandlers.ts b/cli/src/modules/common/registerCommonHandlers.ts index 91fd5303..33062e5f 100644 --- a/cli/src/modules/common/registerCommonHandlers.ts +++ b/cli/src/modules/common/registerCommonHandlers.ts @@ -3,7 +3,7 @@ import { registerBashHandlers } from './handlers/bash' import { registerDirectoryHandlers } from './handlers/directories' import { registerDifftasticHandlers } from './handlers/difftastic' import { registerFileHandlers } from './handlers/files' -import { registerGitHandlers } from './gitHandlers' +import { registerGitHandlers } from './handlers/git' import { registerRipgrepHandlers } from './handlers/ripgrep' import { registerSlashCommandHandlers } from './handlers/slashCommands' diff --git a/cli/src/persistence.ts b/cli/src/persistence.ts index 67413819..9be53326 100644 --- a/cli/src/persistence.ts +++ b/cli/src/persistence.ts @@ -8,7 +8,6 @@ import { FileHandle } from 'node:fs/promises' import { readFile, writeFile, mkdir, open, unlink, rename, stat } from 'node:fs/promises' import { existsSync, writeFileSync, readFileSync, unlinkSync } from 'node:fs' import { configuration } from '@/configuration' -import { encodeBase64 } from '@/api/encryption'; import { isProcessAlive } from '@/utils/process'; interface Settings { @@ -136,7 +135,7 @@ export async function writeCredentialsDataKey(credentials: { publicKey: Uint8Arr await mkdir(configuration.happyHomeDir, { recursive: true }) } await writeFile(configuration.privateKeyFile, JSON.stringify({ - encryption: { publicKey: encodeBase64(credentials.publicKey), machineKey: encodeBase64(credentials.machineKey) }, + encryption: { publicKey: Buffer.from(credentials.publicKey).toString('base64'), machineKey: Buffer.from(credentials.machineKey).toString('base64') }, token: credentials.token }, null, 2)); }