diff --git a/.claude/settings.json b/.claude/settings.json index a824844..907ab88 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -1,16 +1,5 @@ { "hooks": { - "Notification": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } - ], "PostToolUse": [ { "matcher": ".*", @@ -21,61 +10,6 @@ } ] } - ], - "PreCompact": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } - ], - "PreToolUse": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } - ], - "Stop": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } - ], - "SubagentStop": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } - ], - "UserPromptSubmit": [ - { - "matcher": ".*", - "hooks": [ - { - "type": "command", - "command": "/Users/jason/go/bin/cnotes" - } - ] - } ] } } \ No newline at end of file diff --git a/cmd/install.go b/cmd/install.go index c47a627..f44c918 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -26,7 +26,7 @@ Use --local for local directory settings (./.claude/settings.json). This command will: 1. Find or create the appropriate settings.json file -2. Add cnotes to handle PostToolUse events for Bash commands +2. Add cnotes to handle PostToolUse events for Bash commands containing git commits 3. Configure git to preserve notes during rebases Use --uninstall to remove cnotes from Claude settings.`, @@ -70,28 +70,28 @@ func runInstall(cmd *cobra.Command, args []string) error { // Prevent installation from temporary directories (unless uninstalling) if !uninstall { tempDir := os.TempDir() - + // Resolve any symlinks in the executable path for comparison realExecutable, err := filepath.EvalSymlinks(executable) if err != nil { realExecutable = executable // Fall back to original if can't resolve } - + // Also resolve tempDir in case it's a symlink (like /tmp on macOS) realTempDir, err := filepath.EvalSymlinks(tempDir) if err != nil { realTempDir = tempDir } - + // Check if executable is in temp directory or is from go run - if strings.HasPrefix(realExecutable, tempDir) || - strings.HasPrefix(executable, tempDir) || - strings.HasPrefix(realExecutable, realTempDir) || - strings.HasPrefix(executable, realTempDir) || - strings.Contains(executable, "/go-build/") || - strings.Contains(realExecutable, "/go-build/") || - strings.Contains(executable, "/Caches/go-build/") || - strings.Contains(realExecutable, "/Caches/go-build/") { + if strings.HasPrefix(realExecutable, tempDir) || + strings.HasPrefix(executable, tempDir) || + strings.HasPrefix(realExecutable, realTempDir) || + strings.HasPrefix(executable, realTempDir) || + strings.Contains(executable, "/go-build/") || + strings.Contains(realExecutable, "/go-build/") || + strings.Contains(executable, "/Caches/go-build/") || + strings.Contains(realExecutable, "/Caches/go-build/") { return fmt.Errorf("cannot install from temporary directory: %s\nPlease build and install cnotes properly:\n go install && cnotes install", executable) } } diff --git a/internal/config/settings.go b/internal/config/settings.go index b6c2762..b9bd4a5 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -106,40 +106,30 @@ func InstallHooksToPath(binaryPath, settingsPath string) error { Hooks: []HookAction{hookAction}, } - // Map our event names to Claude's event names - eventMap := map[string]string{ - "pre_tool_use": "PreToolUse", - "post_tool_use": "PostToolUse", - "user_prompt_submit": "UserPromptSubmit", - "stop": "Stop", - "subagent_stop": "SubagentStop", - "notification": "Notification", - "pre_compact": "PreCompact", - } + // Only register for PostToolUse events since that's all we handle + claudeEvent := "PostToolUse" - for _, claudeEvent := range eventMap { - // Check if our hook is already installed - found := false - for i, def := range settings.Hooks[claudeEvent] { - for j, action := range def.Hooks { - if action.Command == binaryPath { - // Update existing hook - settings.Hooks[claudeEvent][i].Hooks[j] = hookAction - found = true - break - } - } - if found { + // Check if our hook is already installed + found := false + for i, def := range settings.Hooks[claudeEvent] { + for j, action := range def.Hooks { + if action.Command == binaryPath { + // Update existing hook + settings.Hooks[claudeEvent][i].Hooks[j] = hookAction + found = true break } } - - if !found { - // Add new hook - settings.Hooks[claudeEvent] = append(settings.Hooks[claudeEvent], hookDef) + if found { + break } } + if !found { + // Add new hook + settings.Hooks[claudeEvent] = append(settings.Hooks[claudeEvent], hookDef) + } + return SaveSettings(settingsPath, settings) }