general improvements (#17)

* refactor(hooks): simplify hook execution with shared context

- [x] Extract BaseInput struct to eliminate duplicate fields across hooks
- [x] Create RunHook handler pattern for session-start and user-prompt
- [x] Create RunStatuslineHook for fast statusline rendering without worker startup
- [x] Add HookContext struct to pass port, project, CWD, SessionID to handlers
- [x] Add db/interface.go with ObservationReader/Writer interfaces
- [x] Add comprehensive conflict management tests in sqlite/conflict_test.go
- [x] Add vector client tests for Count, ModelVersion, NeedsRebuild, GetStaleVectors
- [x] Add FilterByThreshold helper tests for query result filtering
- [x] Make handlers_test more robust for network-dependent update checks
- [x] Update package versions in UI

* Move to GORM + general cleanup

* feat(mcp): add observation relations discovery and scoring integration

- [x] Add find_related_observations MCP tool for discovering related observations by confidence
- [x] Integrate scoring calculator and recalculator into MCP server initialization
- [x] Add pattern, relation, and session stores to MCP server dependencies
- [x] Register MCP server in Claude Code settings during plugin installation
- [x] Update install scripts (bash, PowerShell) to configure MCP server settings
- [x] Switch plugin manifest files to template-based versioning (plugin.json.tpl, marketplace.json.tpl)
- [x] Update all MCP server tests to pass new dependency parameters
This commit is contained in:
2026-01-07 00:26:20 +00:00
committed by GitHub
parent 92a99c7615
commit 7a061c85eb
85 changed files with 8445 additions and 8202 deletions
+11 -53
View File
@@ -2,9 +2,7 @@
package main
import (
"encoding/json"
"fmt"
"io"
"net/url"
"os"
"strings"
@@ -14,11 +12,8 @@ import (
// Input is the hook input from Claude Code.
type Input struct {
SessionID string `json:"session_id"`
CWD string `json:"cwd"`
PermissionMode string `json:"permission_mode"`
HookEventName string `json:"hook_event_name"`
Source string `json:"source"` // "startup", "resume", "clear", "compact"
hooks.BaseInput
Source string `json:"source"` // "startup", "resume", "clear", "compact"
}
// Observation represents an observation from the API.
@@ -32,53 +27,26 @@ type Observation struct {
}
func main() {
// Skip if this is an internal call (from SDK processor)
if os.Getenv("CLAUDE_MNEMONIC_INTERNAL") == "1" {
hooks.WriteResponse("SessionStart", true)
return
}
// Read input from stdin
inputData, err := io.ReadAll(os.Stdin)
if err != nil {
hooks.WriteError("SessionStart", err)
os.Exit(1)
}
var input Input
if err := json.Unmarshal(inputData, &input); err != nil {
hooks.WriteError("SessionStart", err)
os.Exit(1)
}
// Ensure worker is running
port, err := hooks.EnsureWorkerRunning()
if err != nil {
hooks.WriteError("SessionStart", err)
os.Exit(1)
}
// Generate unique project ID from CWD (dirname_hash format)
project := hooks.ProjectIDWithName(input.CWD)
hooks.RunHook("SessionStart", handleSessionStart)
}
func handleSessionStart(ctx *hooks.HookContext, input *Input) (string, error) {
// Fetch observations for context injection
endpoint := fmt.Sprintf("/api/context/inject?project=%s&cwd=%s",
url.QueryEscape(project),
url.QueryEscape(input.CWD))
url.QueryEscape(ctx.Project),
url.QueryEscape(ctx.CWD))
result, err := hooks.GET(port, endpoint)
result, err := hooks.GET(ctx.Port, endpoint)
if err != nil {
fmt.Fprintf(os.Stderr, "[claude-mnemonic] Warning: context fetch failed: %v\n", err)
hooks.WriteResponse("SessionStart", true)
return
return "", nil
}
// Parse observations from response
obsData, ok := result["observations"].([]interface{})
if !ok || len(obsData) == 0 {
// No observations - just continue normally
hooks.WriteResponse("SessionStart", true)
return
return "", nil
}
// Get full_count from response (how many observations get full detail)
@@ -136,17 +104,7 @@ func main() {
}
contextBuilder += "</claude-mnemonic-context>\n"
// Output context as JSON with additionalContext field
response := map[string]interface{}{
"continue": true,
"hookSpecificOutput": map[string]interface{}{
"hookEventName": "SessionStart",
"additionalContext": contextBuilder,
},
}
_ = json.NewEncoder(os.Stdout).Encode(response)
os.Exit(0)
return contextBuilder, nil
}
func getString(m map[string]interface{}, key string) string {