refactor: streamline claude-mem integration and remove unused code

- Updated CODEMAP to reflect changes in fallback methods for package root discovery.
- Removed the `detectClaudePath` function and replaced its usage with direct references to `PACKAGE_NAME`.
- Eliminated the `claudePath` property from Settings interface and user settings configuration.
- Cleaned up path discovery logic by removing the npm list command method.
- Removed the `findExecutable` method from the Platform utility as it was no longer needed.
This commit is contained in:
Alex Newman
2025-10-16 14:24:32 -04:00
parent 6e9be84a01
commit eddb321489
6 changed files with 90 additions and 131 deletions
+6 -13
View File
@@ -58,9 +58,6 @@ function installUv(): void {
process.env.PATH = `${homedir()}/.cargo/bin:${process.env.PATH}`;
}
function detectClaudePath(): string {
return Platform.findExecutable('claude');
}
function hasExistingInstallation(): boolean {
const pathDiscovery = PathDiscovery.getInstance();
@@ -343,12 +340,11 @@ function configureHooks(settingsPath: string): void {
});
// Configure hooks to use CLI commands directly
const cliPath = detectClaudePath() || PACKAGE_NAME;
settings.hooks.SessionStart = [createHookConfig(`${cliPath} context`, 180)];
settings.hooks.Stop = [createHookConfig(`${cliPath} summary`, 60)];
settings.hooks.UserPromptSubmit = [createHookConfig(`${cliPath} new`, 60)];
settings.hooks.PostToolUse = [createHookConfig(`${cliPath} save`, 180, "*")];
// claude-mem should be in PATH after npm installation
settings.hooks.SessionStart = [createHookConfig(`${PACKAGE_NAME} context`, 180)];
settings.hooks.Stop = [createHookConfig(`${PACKAGE_NAME} summary`, 60)];
settings.hooks.UserPromptSubmit = [createHookConfig(`${PACKAGE_NAME} new`, 60)];
settings.hooks.PostToolUse = [createHookConfig(`${PACKAGE_NAME} save`, 180, "*")];
writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
}
@@ -375,7 +371,6 @@ function configureUserSettings(config: InstallConfig): void {
userSettings.installed = true;
userSettings.embedded = true;
userSettings.saveMemoriesOnClear = config.saveMemoriesOnClear || false;
userSettings.claudePath = detectClaudePath();
writeFileSync(userSettingsPath, JSON.stringify(userSettings, null, 2));
}
@@ -383,9 +378,7 @@ function configureUserSettings(config: InstallConfig): void {
function configureSmartTrashAlias(): void {
const shellConfigs = Platform.getShellConfigPaths();
const aliasDefinition = Platform.getAliasDefinition('rm', 'claude-mem trash');
const commentLine = Platform.isWindows()
? '# claude-mem smart trash alias'
: '# claude-mem smart trash alias';
const commentLine = '# claude-mem smart trash alias';
for (const configPath of shellConfigs) {
if (!existsSync(configPath)) {
+1 -16
View File
@@ -182,7 +182,7 @@ export class PathDiscovery {
// Method 2: Walk up from current module location
const currentFile = fileURLToPath(import.meta.url);
let currentDir = dirname(currentFile);
for (let i = 0; i < 10; i++) {
const packageJsonPath = join(currentDir, 'package.json');
if (existsSync(packageJsonPath)) {
@@ -198,21 +198,6 @@ export class PathDiscovery {
currentDir = parentDir;
}
// Method 3: Try npm list command
try {
const npmOutput = execSync('npm list -g claude-mem --json 2>/dev/null || npm list claude-mem --json 2>/dev/null', {
encoding: 'utf8'
});
const npmData = JSON.parse(npmOutput);
if (npmData.dependencies?.['claude-mem']?.resolved) {
this._packageRoot = dirname(npmData.dependencies['claude-mem'].resolved);
return this._packageRoot;
}
} catch {
// Continue to error
}
throw new Error('Cannot locate claude-mem package root. Ensure claude-mem is properly installed.');
}
-1
View File
@@ -19,7 +19,6 @@ export interface Settings {
backend?: string;
embedded?: boolean;
saveMemoriesOnClear?: boolean;
claudePath?: string;
rollingCaptureEnabled?: boolean;
rollingSummaryEnabled?: boolean;
rollingSessionStartEnabled?: boolean;
-13
View File
@@ -9,19 +9,6 @@ const isWindows = platform() === 'win32';
* Handles differences between Windows and Unix-like systems
*/
export const Platform = {
/**
* Finds the path to an executable command
* @param name - Name of the executable to find
* @returns Full path to the executable
*/
findExecutable: (name: string): string => {
const cmd = isWindows ? `where ${name}` : `which ${name}`;
return execSync(cmd, {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore']
}).trim();
},
/**
* Installs uv package manager using platform-specific method
*/