1
0
Fork 0
mirror of https://github.com/imjasonh/cnotes synced 2026-07-10 09:54:26 +00:00

Complete git notes implementation with clean code

- Fixed git commit detection for compound commands (using contains instead of prefix)
- Fixed ToolResponse JSON parsing to extract stdout properly
- Removed debug logging and test files
- Git notes integration is now fully functional and ready for production use
This commit is contained in:
Jason Hall 2025-07-21 12:33:10 -04:00
parent 6bb1d700f2
commit ae18ff9ea3
Failed to extract signature
10 changed files with 34 additions and 10 deletions

View file

@ -2,6 +2,7 @@ package handlers
import (
"context"
"encoding/json"
"fmt"
"log/slog"
"strings"
@ -42,7 +43,19 @@ func AttachConversationToCommit(ctx context.Context, input hooks.HookInput) (hoo
// Extract commit hash from tool response/result
var gitOutput string
if len(input.ToolResponse) > 0 {
gitOutput = string(input.ToolResponse)
// Parse the JSON response to extract stdout
var toolResponse struct {
Stdout string `json:"stdout"`
Stderr string `json:"stderr"`
Interrupted bool `json:"interrupted"`
IsImage bool `json:"isImage"`
}
if err := json.Unmarshal(input.ToolResponse, &toolResponse); err == nil {
gitOutput = toolResponse.Stdout
} else {
// Fallback to raw string if JSON parsing fails
gitOutput = string(input.ToolResponse)
}
} else if len(input.ToolUseResult) > 0 {
gitOutput = string(input.ToolUseResult)
}

View file

@ -117,11 +117,11 @@ func ExtractCommitHashFromOutput(output string) string {
return ""
}
// IsGitCommitCommand checks if a bash command is a git commit
// IsGitCommitCommand checks if a bash command contains a git commit
func IsGitCommitCommand(command string) bool {
command = strings.TrimSpace(command)
// Handle various git commit patterns
// Handle various git commit patterns - check if command contains any of these
patterns := []string{
"git commit",
"git commit -m",
@ -130,7 +130,7 @@ func IsGitCommitCommand(command string) bool {
}
for _, pattern := range patterns {
if strings.HasPrefix(command, pattern) {
if strings.Contains(command, pattern) {
return true
}
}