// internal/skills/sessionlog/handlers.go package sessionlog import ( "context" "encoding/json" "fmt" "time" "github.com/mathiasbq/supervisor/internal/session" ) type logArgs struct { SessionID string `json:"session_id"` Skill string `json:"skill"` Phase string `json:"phase,omitempty"` ProjectRoot string `json:"project_root,omitempty"` FinalStatus string `json:"final_status,omitempty"` FilePath string `json:"file_path,omitempty"` ModelUsed string `json:"model_used,omitempty"` DurationMs int64 `json:"duration_ms,omitempty"` Message string `json:"message,omitempty"` } // Handle dispatches the session_log tool call. func (s *Skill) Handle(ctx context.Context, tool string, args json.RawMessage) (json.RawMessage, error) { if tool != "session_log" { return nil, fmt.Errorf("unknown sessionlog tool: %s", tool) } var a logArgs if err := json.Unmarshal(args, &a); err != nil { return nil, fmt.Errorf("parse args: %w", err) } if a.SessionID == "" { return nil, fmt.Errorf("session_id is required") } entry := session.Entry{ SessionID: a.SessionID, Timestamp: time.Now().UTC(), Skill: a.Skill, Phase: a.Phase, ProjectRoot: a.ProjectRoot, FinalStatus: a.FinalStatus, FilePath: a.FilePath, ModelUsed: a.ModelUsed, DurationMs: a.DurationMs, Message: a.Message, } if err := session.Append(s.cfg.SessionsDir, a.SessionID, entry); err != nil { return nil, fmt.Errorf("append session log: %w", err) } b, err := json.Marshal(map[string]string{"status": "ok", "session_id": a.SessionID}) if err != nil { return nil, fmt.Errorf("marshal response: %w", err) } return b, nil }