Documentation
¶
Overview ¶
Package handler contains domain logic for MCP tool operations.
Functions accept typed Go parameters and return (string, error) pairs. The server package handles JSON-RPC protocol translation, argument extraction from MCP maps, and response wrapping. This separation keeps domain logic testable without protocol coupling.
Index ¶
- type EntryOpts
- type Handler
- func (h *Handler) Add(entryType, content string, opts EntryOpts) (string, error)
- func (h *Handler) CheckTaskCompletion(recentAction string) (string, error)
- func (h *Handler) Compact(archive bool) (string, error)
- func (h *Handler) Complete(query string) (string, error)
- func (h *Handler) Drift() (string, error)
- func (h *Handler) Next() (string, error)
- func (h *Handler) Recall(limit int, since time.Time) (string, error)
- func (h *Handler) Remind() (string, error)
- func (h *Handler) SessionEvent(eventType, caller string) (string, error)
- func (h *Handler) Status() (string, error)
- func (h *Handler) WatchUpdate(entryType, content string, opts EntryOpts) (string, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EntryOpts ¶
type EntryOpts struct {
Priority string
Context string
Rationale string
Consequence string
Lesson string
Application string
}
EntryOpts holds optional fields for entry creation.
type Handler ¶
Handler contains domain logic for MCP operations.
It holds the context directory, token budget, and session state needed by tool handlers. The Server package delegates to Handler for all domain work and handles only protocol translation.
func New ¶
New creates a Handler for the given context directory.
Parameters:
- contextDir: path to the .context/ directory
- tokenBudget: maximum token budget for context assembly
Returns:
- *Handler: initialized handler with fresh session state
func (*Handler) Add ¶
Add adds an entry to a context file.
Parameters:
- entryType: the type of entry (task, decision, learning, convention)
- content: the entry content
- opts: optional fields for the entry
Returns:
- string: confirmation message with entry type and target file
- error: boundary, validation, or write error
func (*Handler) CheckTaskCompletion ¶
CheckTaskCompletion checks if a recent action completed any pending tasks.
Parameters:
- recentAction: description of the action to match against tasks
Returns:
- string: matching task prompt with the completion hint, or empty
- error: context load error
func (*Handler) Compact ¶
Compact moves completed tasks to the archive section.
Parameters:
- archive: whether to write archivable blocks to the archive file
Returns:
- string: summary of moved tasks and cleaned sections
- error: boundary, context load, or write error
func (*Handler) Complete ¶
Complete marks a task as done by number or text match.
Parameters:
- query: task number or text fragment to match
Returns:
- string: confirmation message with completed task text
- error: boundary or completion error
func (*Handler) Drift ¶
Drift runs drift detection and returns the report.
Returns:
- string: formatted drift report with violations, warnings, passed
- error: context load error
func (*Handler) Next ¶
Next suggests the next pending task.
Returns:
- string: next pending task or all-complete message
- error: context load error
func (*Handler) Recall ¶
Recall queries recent session history.
Parameters:
- limit: max sessions to return
- since: only return sessions after this time (zero value = no filter)
Returns:
- string: formatted session list with dates, projects, durations
- error: session discovery error
func (*Handler) Remind ¶
Remind lists pending session-scoped reminders.
Returns:
- string: formatted reminder list or no-reminders message
- error: reminder read error
func (*Handler) SessionEvent ¶
SessionEvent handles session lifecycle events (start/end).
Parameters:
- eventType: the event type (start or end)
- caller: optional caller identifier for start events
Returns:
- string: session confirmation or end-of-session summary
- error: unknown event type error
func (*Handler) Status ¶
Status loads context and returns a status summary.
Returns:
- string: formatted status text with file list and token counts
- error: context load error
func (*Handler) WatchUpdate ¶
WatchUpdate applies a structured context-update to .context/ files.
Parameters:
- entryType: the type of entry
- content: the entry content
- opts: optional fields for the entry
Returns:
- string: confirmation with file name and review status
- error: boundary, validation, or write error