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 ¶
- type Brancher
- type Committer
- type Handler
- func (h *Handler) FinishWIP(ctx context.Context, cmd *command.FinishWIPCmd) error
- func (h *Handler) Init(ctx context.Context, cmd *command.InitCmd) error
- func (h *Handler) LintFix(ctx context.Context, cmd *command.LintFixCmd) error
- func (h *Handler) NewEntry(ctx context.Context, cmd *command.NewEntryCmd) (retErr error)
- func (h *Handler) StartWIP(ctx context.Context, cmd *command.StartWIPCmd) error
- func (h *Handler) Summarize(ctx context.Context, cmd *command.SummarizeCmd) error
- type Options
- type Reader
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 ¶
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 (*Handler) FinishWIP ¶
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 ¶
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 ¶
LintFix applies mechanical fixes to graph entries: loads the graph, identifies fixable issues, patches files in place, and commits.
func (*Handler) NewEntry ¶
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 ¶
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 ¶
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.