Refactor: Remove hook-templates and related functionality
- Updated the published package contents to exclude `hook-templates`. - Removed references to the hooks directory and related scripts in the installation and uninstallation processes. - Simplified the status command by eliminating checks for runtime hook scripts. - Adjusted the path discovery service to remove methods related to hook templates. - Updated the installation logic to directly configure hooks using CLI commands. - Cleaned up the uninstall process to remove claude-mem hooks from settings.
This commit is contained in:
Vendored
+65
-65
File diff suppressed because one or more lines are too long
+1
-1
@@ -125,4 +125,4 @@ claude-mem/
|
|||||||
- The build process embeds the version from `package.json` at build time
|
- The build process embeds the version from `package.json` at build time
|
||||||
- `prepublishOnly` script ensures build runs before npm publish
|
- `prepublishOnly` script ensures build runs before npm publish
|
||||||
- Dependencies are bundled except for external packages
|
- Dependencies are bundled except for external packages
|
||||||
- The published package includes: `dist/`, `hook-templates/`, `commands/`, `src/`, `docs/`
|
- The published package includes: `dist/`, `commands/`, `src/`, `docs/`
|
||||||
|
|||||||
@@ -54,7 +54,6 @@
|
|||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"dist",
|
"dist",
|
||||||
"hook-templates",
|
|
||||||
"commands",
|
"commands",
|
||||||
"src",
|
"src",
|
||||||
"docs",
|
"docs",
|
||||||
|
|||||||
+11
-14
@@ -86,7 +86,16 @@ function detectClaudePath(): string {
|
|||||||
|
|
||||||
function hasExistingInstallation(): boolean {
|
function hasExistingInstallation(): boolean {
|
||||||
const pathDiscovery = PathDiscovery.getInstance();
|
const pathDiscovery = PathDiscovery.getInstance();
|
||||||
return existsSync(pathDiscovery.getHooksDirectory());
|
const settingsPath = pathDiscovery.getClaudeSettingsPath();
|
||||||
|
|
||||||
|
if (!existsSync(settingsPath)) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
|
||||||
|
return !!(settings.hooks?.SessionStart || settings.hooks?.Stop || settings.hooks?.PostToolUse);
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runInstallationWizard(existingInstall: boolean): Promise<InstallConfig | null> {
|
async function runInstallationWizard(existingInstall: boolean): Promise<InstallConfig | null> {
|
||||||
@@ -232,17 +241,6 @@ function copyFileRecursively(src: string, dest: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No longer needed - hooks are now CLI commands
|
|
||||||
// Kept for backwards compatibility only
|
|
||||||
function ensureHooksDirectory(): void {
|
|
||||||
const pathDiscovery = PathDiscovery.getInstance();
|
|
||||||
const runtimeHooksDir = pathDiscovery.getHooksDirectory();
|
|
||||||
|
|
||||||
// Just ensure the directory exists for any legacy references
|
|
||||||
if (!existsSync(runtimeHooksDir)) {
|
|
||||||
mkdirSync(runtimeHooksDir, { recursive: true });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function ensureClaudeMdInstructions(): void {
|
function ensureClaudeMdInstructions(): void {
|
||||||
@@ -366,7 +364,7 @@ function configureHooks(settingsPath: string): void {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Configure hooks to use CLI commands directly (new architecture)
|
// Configure hooks to use CLI commands directly
|
||||||
const cliPath = detectClaudePath() || PACKAGE_NAME;
|
const cliPath = detectClaudePath() || PACKAGE_NAME;
|
||||||
|
|
||||||
settings.hooks.SessionStart = [createHookConfig(`${cliPath} context`, 180)];
|
settings.hooks.SessionStart = [createHookConfig(`${cliPath} context`, 180)];
|
||||||
@@ -494,7 +492,6 @@ export async function install(options: OptionValues = {}): Promise<void> {
|
|||||||
{ name: 'Installing Chroma MCP server', fn: () => installChromaMcp(config.forceReinstall) },
|
{ name: 'Installing Chroma MCP server', fn: () => installChromaMcp(config.forceReinstall) },
|
||||||
{ name: 'Adding CLAUDE.md instructions', fn: () => ensureClaudeMdInstructions() },
|
{ name: 'Adding CLAUDE.md instructions', fn: () => ensureClaudeMdInstructions() },
|
||||||
{ name: 'Installing Claude commands', fn: () => installClaudeCommands() },
|
{ name: 'Installing Claude commands', fn: () => installClaudeCommands() },
|
||||||
{ name: 'Configuring CLI hook integration', fn: () => ensureHooksDirectory() },
|
|
||||||
{ name: 'Configuring Claude settings', fn: () => configureHooks(getSettingsPath(config)) },
|
{ name: 'Configuring Claude settings', fn: () => configureHooks(getSettingsPath(config)) },
|
||||||
{ name: 'Configuring user settings', fn: () => configureUserSettings(config) }
|
{ name: 'Configuring user settings', fn: () => configureUserSettings(config) }
|
||||||
];
|
];
|
||||||
|
|||||||
+8
-37
@@ -13,28 +13,7 @@ export async function status(): Promise<void> {
|
|||||||
console.log('🔍 Claude Memory System Status Check');
|
console.log('🔍 Claude Memory System Status Check');
|
||||||
console.log('=====================================\n');
|
console.log('=====================================\n');
|
||||||
|
|
||||||
console.log('📂 Runtime Hook Scripts (installed from hook-templates/):');
|
|
||||||
const pathDiscovery = PathDiscovery.getInstance();
|
const pathDiscovery = PathDiscovery.getInstance();
|
||||||
const runtimeHooksDir = pathDiscovery.getHooksDirectory();
|
|
||||||
const sessionStartScript = join(runtimeHooksDir, 'session-start.js');
|
|
||||||
const stopScript = join(runtimeHooksDir, 'stop.js');
|
|
||||||
const userPromptScript = join(runtimeHooksDir, 'user-prompt-submit.js');
|
|
||||||
const postToolScript = join(runtimeHooksDir, 'post-tool-use.js');
|
|
||||||
|
|
||||||
const checkScript = (path: string, name: string) => {
|
|
||||||
if (existsSync(path)) {
|
|
||||||
console.log(` ✅ ${name}: Found at ${path}`);
|
|
||||||
} else {
|
|
||||||
console.log(` ❌ ${name}: Not found at ${path}`);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
checkScript(sessionStartScript, 'session-start.js');
|
|
||||||
checkScript(stopScript, 'stop.js');
|
|
||||||
checkScript(userPromptScript, 'user-prompt-submit.js');
|
|
||||||
checkScript(postToolScript, 'post-tool-use.js');
|
|
||||||
|
|
||||||
console.log('');
|
|
||||||
|
|
||||||
console.log('⚙️ Settings Configuration:');
|
console.log('⚙️ Settings Configuration:');
|
||||||
|
|
||||||
@@ -50,33 +29,25 @@ export async function status(): Promise<void> {
|
|||||||
const settings = JSON.parse(readFileSync(path, 'utf8'));
|
const settings = JSON.parse(readFileSync(path, 'utf8'));
|
||||||
|
|
||||||
const hasSessionStart = settings.hooks?.SessionStart?.some((matcher: any) =>
|
const hasSessionStart = settings.hooks?.SessionStart?.some((matcher: any) =>
|
||||||
matcher.hooks?.some((hook: any) =>
|
matcher.hooks?.some((hook: any) => hook.command?.includes('claude-mem'))
|
||||||
hook.command?.includes('session-start.js') || hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasStop = settings.hooks?.Stop?.some((matcher: any) =>
|
const hasStop = settings.hooks?.Stop?.some((matcher: any) =>
|
||||||
matcher.hooks?.some((hook: any) =>
|
matcher.hooks?.some((hook: any) => hook.command?.includes('claude-mem'))
|
||||||
hook.command?.includes('stop.js') || hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasUserPrompt = settings.hooks?.UserPromptSubmit?.some((matcher: any) =>
|
const hasUserPrompt = settings.hooks?.UserPromptSubmit?.some((matcher: any) =>
|
||||||
matcher.hooks?.some((hook: any) =>
|
matcher.hooks?.some((hook: any) => hook.command?.includes('claude-mem'))
|
||||||
hook.command?.includes('user-prompt-submit.js') || hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const hasPostTool = settings.hooks?.PostToolUse?.some((matcher: any) =>
|
const hasPostTool = settings.hooks?.PostToolUse?.some((matcher: any) =>
|
||||||
matcher.hooks?.some((hook: any) =>
|
matcher.hooks?.some((hook: any) => hook.command?.includes('claude-mem'))
|
||||||
hook.command?.includes('post-tool-use.js') || hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(` SessionStart: ${hasSessionStart ? '✅' : '❌'}`);
|
console.log(` SessionStart (claude-mem context): ${hasSessionStart ? '✅' : '❌'}`);
|
||||||
console.log(` Stop: ${hasStop ? '✅' : '❌'}`);
|
console.log(` Stop (claude-mem summary): ${hasStop ? '✅' : '❌'}`);
|
||||||
console.log(` UserPromptSubmit: ${hasUserPrompt ? '✅' : '❌'}`);
|
console.log(` UserPromptSubmit (claude-mem new): ${hasUserPrompt ? '✅' : '❌'}`);
|
||||||
console.log(` PostToolUse: ${hasPostTool ? '✅' : '❌'}`);
|
console.log(` PostToolUse (claude-mem save): ${hasPostTool ? '✅' : '❌'}`);
|
||||||
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.log(` ⚠️ Could not parse settings`);
|
console.log(` ⚠️ Could not parse settings`);
|
||||||
|
|||||||
+15
-51
@@ -86,12 +86,6 @@ export async function uninstall(options: OptionValues = {}): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const pathDiscovery = PathDiscovery.getInstance();
|
|
||||||
const runtimeHooksDir = pathDiscovery.getHooksDirectory();
|
|
||||||
const preCompactScript = join(runtimeHooksDir, 'pre-compact.js');
|
|
||||||
const sessionStartScript = join(runtimeHooksDir, 'session-start.js');
|
|
||||||
const sessionEndScript = join(runtimeHooksDir, 'session-end.js');
|
|
||||||
|
|
||||||
let removedCount = 0;
|
let removedCount = 0;
|
||||||
|
|
||||||
for (const location of locations) {
|
for (const location of locations) {
|
||||||
@@ -110,57 +104,27 @@ export async function uninstall(options: OptionValues = {}): Promise<void> {
|
|||||||
|
|
||||||
let modified = false;
|
let modified = false;
|
||||||
|
|
||||||
if (settings.hooks.PreCompact) {
|
// Remove claude-mem hooks (CLI commands)
|
||||||
const filteredPreCompact = settings.hooks.PreCompact.filter((matcher: any) =>
|
const hookTypes = ['SessionStart', 'Stop', 'UserPromptSubmit', 'PostToolUse'];
|
||||||
!matcher.hooks?.some((hook: any) =>
|
|
||||||
hook.command === preCompactScript ||
|
for (const hookType of hookTypes) {
|
||||||
hook.command?.includes('pre-compact.js') ||
|
if (settings.hooks[hookType]) {
|
||||||
hook.command?.includes('claude-mem')
|
const filteredHooks = settings.hooks[hookType].filter((matcher: any) =>
|
||||||
)
|
!matcher.hooks?.some((hook: any) => hook.command?.includes('claude-mem'))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (filteredPreCompact.length !== settings.hooks.PreCompact.length) {
|
if (filteredHooks.length !== settings.hooks[hookType].length) {
|
||||||
settings.hooks.PreCompact = filteredPreCompact.length ? filteredPreCompact : undefined;
|
settings.hooks[hookType] = filteredHooks.length ? filteredHooks : undefined;
|
||||||
modified = true;
|
modified = true;
|
||||||
console.log(`✅ Removed PreCompact hook from ${location.name} settings`);
|
console.log(`✅ Removed ${hookType} hook from ${location.name} settings`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.hooks.SessionStart) {
|
// Clean up undefined hooks
|
||||||
const filteredSessionStart = settings.hooks.SessionStart.filter((matcher: any) =>
|
hookTypes.forEach(hookType => {
|
||||||
!matcher.hooks?.some((hook: any) =>
|
if (settings.hooks[hookType] === undefined) delete settings.hooks[hookType];
|
||||||
hook.command === sessionStartScript ||
|
});
|
||||||
hook.command?.includes('session-start.js') ||
|
|
||||||
hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (filteredSessionStart.length !== settings.hooks.SessionStart.length) {
|
|
||||||
settings.hooks.SessionStart = filteredSessionStart.length ? filteredSessionStart : undefined;
|
|
||||||
modified = true;
|
|
||||||
console.log(`✅ Removed SessionStart hook from ${location.name} settings`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hooks.SessionEnd) {
|
|
||||||
const filteredSessionEnd = settings.hooks.SessionEnd.filter((matcher: any) =>
|
|
||||||
!matcher.hooks?.some((hook: any) =>
|
|
||||||
hook.command === sessionEndScript ||
|
|
||||||
hook.command?.includes('session-end.js') ||
|
|
||||||
hook.command?.includes('claude-mem')
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (filteredSessionEnd.length !== settings.hooks.SessionEnd.length) {
|
|
||||||
settings.hooks.SessionEnd = filteredSessionEnd.length ? filteredSessionEnd : undefined;
|
|
||||||
modified = true;
|
|
||||||
console.log(`✅ Removed SessionEnd hook from ${location.name} settings`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (settings.hooks.PreCompact === undefined) delete settings.hooks.PreCompact;
|
|
||||||
if (settings.hooks.SessionStart === undefined) delete settings.hooks.SessionStart;
|
|
||||||
if (settings.hooks.SessionEnd === undefined) delete settings.hooks.SessionEnd;
|
|
||||||
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
if (!Object.keys(settings.hooks).length) delete settings.hooks;
|
||||||
|
|
||||||
if (modified) {
|
if (modified) {
|
||||||
|
|||||||
@@ -53,12 +53,6 @@ export class PathDiscovery {
|
|||||||
return join(this.getDataDirectory(), 'archives');
|
return join(this.getDataDirectory(), 'archives');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hooks directory where claude-mem hooks are installed
|
|
||||||
*/
|
|
||||||
getHooksDirectory(): string {
|
|
||||||
return join(this.getDataDirectory(), 'hooks');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs directory for claude-mem operation logs
|
* Logs directory for claude-mem operation logs
|
||||||
@@ -222,31 +216,6 @@ export class PathDiscovery {
|
|||||||
throw new Error('Cannot locate claude-mem package root. Ensure claude-mem is properly installed.');
|
throw new Error('Cannot locate claude-mem package root. Ensure claude-mem is properly installed.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Find hook templates directory in the installed package
|
|
||||||
*
|
|
||||||
* This returns the SOURCE templates directory that gets copied during installation
|
|
||||||
* to the runtime hooks directory (~/.claude-mem/hooks/)
|
|
||||||
*/
|
|
||||||
findPackageHookTemplatesDirectory(): string {
|
|
||||||
const packageRoot = this.getPackageRoot();
|
|
||||||
const hookTemplatesDir = join(packageRoot, 'hook-templates');
|
|
||||||
|
|
||||||
// Verify it contains expected hook template files
|
|
||||||
const requiredHookTemplates = [
|
|
||||||
'session-start.js',
|
|
||||||
'stop.js',
|
|
||||||
'user-prompt-submit.js',
|
|
||||||
'post-tool-use.js'
|
|
||||||
];
|
|
||||||
for (const hookTemplateFile of requiredHookTemplates) {
|
|
||||||
if (!existsSync(join(hookTemplatesDir, hookTemplateFile))) {
|
|
||||||
throw new Error(`Package hook-templates directory missing required template file: ${hookTemplateFile}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return hookTemplatesDir;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find commands directory in the installed package
|
* Find commands directory in the installed package
|
||||||
@@ -293,7 +262,6 @@ export class PathDiscovery {
|
|||||||
this.ensureDirectories([
|
this.ensureDirectories([
|
||||||
this.getDataDirectory(),
|
this.getDataDirectory(),
|
||||||
this.getArchivesDirectory(),
|
this.getArchivesDirectory(),
|
||||||
this.getHooksDirectory(),
|
|
||||||
this.getLogsDirectory(),
|
this.getLogsDirectory(),
|
||||||
this.getTrashDirectory(),
|
this.getTrashDirectory(),
|
||||||
this.getBackupsDirectory(),
|
this.getBackupsDirectory(),
|
||||||
|
|||||||
Reference in New Issue
Block a user