handler

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

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

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

type Handler struct {
	ContextDir  string
	TokenBudget int
	Session     *session.State
}

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

func New(contextDir string, tokenBudget int) *Handler

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

func (h *Handler) Add(
	entryType, content string, opts EntryOpts,
) (string, error)

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

func (h *Handler) CheckTaskCompletion(recentAction string) (string, error)

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

func (h *Handler) Compact(archive bool) (string, error)

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

func (h *Handler) Complete(query string) (string, error)

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

func (h *Handler) Drift() (string, error)

Drift runs drift detection and returns the report.

Returns:

  • string: formatted drift report with violations, warnings, passed
  • error: context load error

func (*Handler) Next

func (h *Handler) Next() (string, error)

Next suggests the next pending task.

Returns:

  • string: next pending task or all-complete message
  • error: context load error

func (*Handler) Recall

func (h *Handler) Recall(limit int, since time.Time) (string, error)

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

func (h *Handler) Remind() (string, error)

Remind lists pending session-scoped reminders.

Returns:

  • string: formatted reminder list or no-reminders message
  • error: reminder read error

func (*Handler) SessionEvent

func (h *Handler) SessionEvent(
	eventType, caller string,
) (string, error)

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

func (h *Handler) Status() (string, error)

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

func (h *Handler) WatchUpdate(
	entryType, content string, opts EntryOpts,
) (string, error)

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

Directories

Path Synopsis
Package task iterates pending tasks from TASKS.md for MCP tool responses.
Package task iterates pending tasks from TASKS.md for MCP tool responses.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL