handlers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package handlers is the only place framework Go code is allowed to have side effects. Handlers are the write side of CQRS: they accept a domain command, do any validation against loaded state, perform IO (git, disk, pre-flight via a finder dependency), and return only errors. Results flow back through callbacks defined on the command struct.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Brancher

type Brancher interface {
	Checkout(branch string, create bool) error
	BranchMerged(branch string) bool
	DeleteBranch(branch string, force bool) error
}

Brancher performs git branch operations. Injected so tests can fake checkout/branch deletion without touching real git.

type Committer

type Committer interface {
	Commit(message string, paths ...string) error
}

Committer performs a git commit of the given paths with the given message. Injected so tests can record or no-op commits.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler holds injected dependencies shared across command methods. Each public method corresponds to one command and lives in its own file (handler_new_entry.go, etc.).

func New

func New(opts Options) *Handler

New constructs a Handler with the given options.

func (*Handler) FinishWIP

func (h *Handler) FinishWIP(ctx context.Context, cmd *command.FinishWIPCmd) error

FinishWIP removes the WIP marker identified by cmd.MarkerID, commits the removal, and (if the marker referenced a branch) deletes the branch when merged or when --force is set. Unmerged non-force branches are preserved and OnBranchPreserved fires so the CLI can print guidance.

func (*Handler) Init

func (h *Handler) Init(ctx context.Context, cmd *command.InitCmd) error

Init executes an InitCmd: creates .sdd/ directory structure at cmd.RepoRoot, writes config.yaml from the template, creates the graph directory, adds .sdd/tmp to .gitignore, and optionally migrates legacy .sdd-tmp/ contents.

This handler does NOT use h.graphDir — all paths are derived from cmd.RepoRoot and cmd.GraphDir.

func (*Handler) LintFix

func (h *Handler) LintFix(ctx context.Context, cmd *command.LintFixCmd) error

LintFix applies mechanical fixes to graph entries: loads the graph, identifies fixable issues, patches files in place, and commits.

func (*Handler) NewEntry

func (h *Handler) NewEntry(ctx context.Context, cmd *command.NewEntryCmd) (retErr error)

NewEntry executes a NewEntryCmd: validates, loads the graph, runs pre-flight, writes the entry + attachments, commits, and fires cmd.OnNewEntry with the new ID. Stdin attachments are persisted to .sdd-tmp/ on pre-flight rejection and on every --dry-run invocation so the user can iterate without re-piping heredocs.

Returns only errors. On dry-run success, returns nil without invoking the callback (no entry was created).

func (*Handler) StartWIP

func (h *Handler) StartWIP(ctx context.Context, cmd *command.StartWIPCmd) error

StartWIP creates a WIP marker for cmd.EntryID, commits it, and optionally creates + checks out a derived git branch. Validates that the entry exists in the graph and warns (via OnExclusiveCollision) when another exclusive marker already covers the entry.

func (*Handler) Summarize

func (h *Handler) Summarize(ctx context.Context, cmd *command.SummarizeCmd) error

Summarize executes a SummarizeCmd: loads the graph, determines which entries need summaries, generates them via the LLM, and writes updated frontmatter back to disk. Entries are processed in topological (DAG) order so that ref summaries are available before downstream entries.

type Options

type Options struct {
	GraphDir  string
	SDDDir    string // path to .sdd/ directory; required for commands that write tmp files
	Reader    Reader
	LLMRunner llm.Runner
	Committer Committer
	Brancher  Brancher
	Stderr    io.Writer
	Now       func() time.Time
}

Options configures a new Handler. Zero-valued fields get sensible defaults.

type Reader

type Reader interface {
	LoadGraph(dir string) (*model.Graph, error)
	LoadWIPMarkers(graphDir string) ([]*model.WIPMarker, error)
	Preflight(ctx context.Context, q query.PreflightQuery) (*query.PreflightResult, error)
}

Reader is the handler-side view of the finder. It bundles every read operation handlers need (graph loading, pre-flight, WIP markers). Defined here (rather than imported as the concrete *finders.Finder) so consumers can substitute fakes in tests — standard "accept interfaces, return structs" Go pattern. *finders.Finder satisfies this interface.

Jump to

Keyboard shortcuts

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