Help us shape the future of Go! Take the 2026 Go Developer Survey

plan

package
v0.7.225 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package plan is the planning screen: a chat with Claude beside the plan factory is writing, rendered as markdown. The developer can comment on any part of the plan; comments are queued locally and saved to factory when the developer sends. When the developer approves the plan, chunk builds it through factory.

The screen is a component: its host passes it messages and draws what Content returns, and it reports that it is done with a ClosedMsg. Screen hosts it as a program of its own.

Index

Constants

View Source
const ReadyState = "Planning - Human"

ReadyState is the state a plan waits in for the developer once its review has passed; it can be approved only from there.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent added in v0.7.225

type Agent interface {
	// Send delivers message to the agent, starting it on the first.
	Send(ctx context.Context, message string) error
	// Events is everything the agent reports, in order.
	Events() <-chan Event
}

Agent is the planning agent: one long-lived factory session the screen sends the developer's messages to and reads what it does from. It plans through factory's tasks as well as the developer's messages, so it can be working with nothing sent, and a message can reach it mid-turn.

type Approver added in v0.7.225

type Approver func(step func(string)) (string, error)

Approver approves the plan in factory and starts its build, returning the build's ID. It reads the plan itself rather than taking the screen's copy, which may be behind factory's by a poll. It calls step with each step as it starts, as a line for the screen to show while it works.

type ClosedMsg

type ClosedMsg struct {
	BuildID string
}

ClosedMsg is the screen asking its host to close it: the plan was approved and is being built as BuildID, or, when BuildID is "", the developer left.

type Comment added in v0.7.225

type Comment struct {
	ID       string
	Quote    string
	Body     string
	Resolved bool
}

Comment is a comment on the plan as factory keeps it.

type Event added in v0.7.225

type Event struct {
	// Activity is a tool call the agent made, or a piece of text it wrote, as
	// a line for the chat.
	Activity string
	// Reply is the agent's reply ending a turn.
	Reply *Reply
	// Problem is something wrong with the session.
	Problem error
}

Event is one thing the agent reports. Exactly one field is set.

type Flow added in v0.7.225

type Flow struct {
	// Events are the events factory applies to the flow now, by name; one
	// sent at any other time is ignored.
	Events []string
	// Task is the category of the task factory has handed out for the plan
	// and not yet had back, such as "early-plan"; "" when none is out.
	Task string
}

Flow is what the screen reads of the plan's flow in factory.

type Model

type Model struct {

	// BuildID is the build of the plan, once it has been approved.
	BuildID string
	// contains filtered or unexported fields
}

Model is the planning screen.

func New

func New(ctx context.Context, agent Agent, approve Approver, store Store, first string) Model

New returns the planning screen. A non-empty first message is sent as soon as the screen opens.

func (Model) Content

func (m Model) Content() string

Content is the screen as its host draws it: the panes and the footer, filling the size it was last sent.

func (Model) Init

func (m Model) Init() tea.Cmd

func (Model) Next added in v0.7.225

func (m Model) Next() tea.Cmd

Next waits for the agent's next event, as the screen itself does from Init on. A host can use it to deliver one deterministically.

func (Model) Poll added in v0.7.225

func (m Model) Poll() tea.Cmd

Poll reads the plan's state, text and comments from the store, as the screen's own timer does every few seconds. A host can use it to refresh the screen deterministically, without waiting for that timer.

func (Model) Unsent added in v0.7.225

func (m Model) Unsent() string

Unsent reports local input that quitting the host would discard.

func (Model) Update

func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)

func (Model) WithBack

func (m Model) WithBack() Model

WithBack returns a copy of m for a host that keeps the screen when it is closed and can open it again as it was: esc, when there is nothing for it to stop or cancel, and ctrl+c close it without asking or stopping Claude.

func (Model) WithBranch

func (m Model) WithBranch(branch string) Model

WithBranch returns a copy of m that names the branch the plan is for in its header.

func (Model) WithInbox added in v0.7.225

func (m Model) WithInbox(title, project string) Model

WithInbox names the plan and local project and returns to the host's inbox. No agent starts until a message is sent. Chat history belongs to this visit.

func (Model) WithTerminal

func (m Model) WithTerminal(dark, disambiguates bool) Model

WithTerminal returns a copy of m for a terminal with a dark background or not, that tells shift+enter from enter or not. The screen learns of a change to either from the messages its host passes on.

type Reply added in v0.7.225

type Reply struct {
	Text string
	// ByTask is true when the agent started the turn on its own, on a factory
	// task, rather than on a message from the developer.
	ByTask bool
}

Reply is one reply of the agent's.

type Screen

type Screen struct {
	Model Model
}

Screen runs the planning screen as a program's whole screen, which ends when the screen closes.

func (Screen) Init

func (s Screen) Init() tea.Cmd

func (Screen) Update

func (s Screen) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (Screen) View

func (s Screen) View() tea.View

type Stage added in v0.7.225

type Stage int

Stage is what ctrl+s approves for a plan in ReadyState.

const (
	// StageDesign is a plan whose design waits for approval, so factory
	// writes its units.
	StageDesign Stage = iota
	// StagePlan is a plan that waits for approval, so factory builds it.
	StagePlan
	// StageQuestions is a plan factory offers no approval for: it waits for
	// a human to answer 3. Open Questions in comments.
	StageQuestions
)

func StageOf added in v0.7.225

func StageOf(events []string, units int) Stage

StageOf is what ctrl+s approves, given the events the plan's flow applies and how many units the plan has. When events lists exactly one approval, that one wins. When it lists both, as a flow factory stored before it told the two apart does, or is nil, because it has not loaded or there is no flow, the plan's units decide: none is StageDesign, any is StagePlan. When it is loaded and lists neither, even empty, it is StageQuestions.

type Store added in v0.7.225

type Store interface {
	ID() string
	// Create makes the plan in factory for message, the developer's first
	// message, naming it for what the message asks for.
	Create(ctx context.Context, message string) error
	State(ctx context.Context) (string, error)
	// Flow is the plan's flow as factory has it now; empty before the plan
	// is created or has a flow.
	Flow(ctx context.Context) (Flow, error)
	// AddressComments has factory take up the plan's comments, moving it
	// from a Human state to its phase's Agent state. Factory moves it at
	// its next poll, not before AddressComments returns.
	AddressComments(ctx context.Context) error
	// ResolveConflicts has factory rebase the plan's conflicting PR, moving
	// it from Integrating - Human to Integrating - Agent. Factory moves it at
	// its next poll, not before ResolveConflicts returns.
	ResolveConflicts(ctx context.Context) error
	// ApproveDesign approves the plan's design, moving it from Planning -
	// Human for factory to write its units. Factory moves it at its next
	// poll, not before ApproveDesign returns.
	ApproveDesign(ctx context.Context) error
	Text(ctx context.Context) (string, error)
	// SetText replaces the plan's text with text, which the developer
	// has edited. It is a whole-text write: the caller checks the plan is
	// as it last read it first.
	SetText(ctx context.Context, text string) error
	Comments(ctx context.Context) ([]Comment, error)
	AddComment(ctx context.Context, quote, body string) (Comment, error)
	EditComment(ctx context.Context, id, body string) error
	ResolveComment(ctx context.Context, id string) error
	DeleteComment(ctx context.Context, id string) error
}

Store is where the plan and its comments are kept. Before Create, ID and reads are empty and writes fail. An existing plan starts with its ID set.

Jump to

Keyboard shortcuts

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