planreview

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package planreview coordinates the explicit plan-mode decisions surfaced to the user: the enter approval and the exit review.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid means a request or resolution violates the plan review protocol.
	ErrInvalid = errors.New("coding plan review: invalid value")
	// ErrNoPending means no plan decision is waiting for a resolution.
	ErrNoPending = errors.New("coding plan review: no pending request")
	// ErrMismatch means a resolution does not identify the pending request exactly.
	ErrMismatch = errors.New("coding plan review: request mismatch")
)

Functions

func ValidDecision

func ValidDecision(kind Kind, decision Decision) bool

ValidDecision reports whether one decision is well-formed for a request kind. It validates the shape only; comments and notes are bounded by ValidateResolutionShape.

func ValidateRequest

func ValidateRequest(request Request) error

ValidateRequest verifies a request's deterministic identity and bounds.

func ValidateResolution

func ValidateResolution(request Request, resolution Resolution) error

ValidateResolution verifies one decision against the exact pending request.

func ValidateResolutionShape

func ValidateResolutionShape(kind Kind, resolution Resolution, requestID string) error

ValidateResolutionShape verifies bounded fields for one request kind.

Types

type Controller

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

Controller owns the enter/exit plan-mode pause protocol.

func NewController

func NewController(
	store *planmode.Store,
	service Service,
	resolver Resolver,
) (*Controller, error)

NewController constructs one plan-mode decision coordinator.

func (*Controller) BeforeTool

BeforeTool turns enter/exit calls into pauses and rejects malformed calls.

func (*Controller) Catalog

func (c *Controller) Catalog() (*catalog.Catalog, error)

Catalog returns both local plan-mode tool registrations.

func (*Controller) Pending

func (c *Controller) Pending() *Request

Pending reports the currently displayed request, when any.

func (*Controller) Reconcile

func (c *Controller) Reconcile(ctx context.Context, pending []ai.ToolCallPart) (*Request, error)

Reconcile reconstructs a pending plan-mode decision from the first durable pending call. The exit request reads the plan file from disk; content is never taken from tool arguments.

func (*Controller) Resolve

func (c *Controller) Resolve(resolution Resolution) (Outcome, error)

Resolve persists the exact decision and reports the outcome to the runtime.

type Decision

type Decision string

Decision is the user's explicit disposition of a plan-mode request.

const (
	// DecisionApprove accepts the exit revision (or approves entering plan mode).
	DecisionApprove Decision = "approve"
	// DecisionDecline refuses to enter plan mode.
	DecisionDecline Decision = "decline"
	// DecisionRevise sends the plan back for another revision.
	DecisionRevise Decision = "revise"
	// DecisionQuit abandons the plan and turns plan mode off.
	DecisionQuit Decision = "quit"
)

Plan-mode decisions.

type Kind

type Kind string

Kind distinguishes the two plan-mode decisions.

const (
	// KindEnter asks the user to approve entering plan mode.
	KindEnter Kind = "enter"
	// KindExit presents the plan for approval, revision, or abandonment.
	KindExit Kind = "exit"
)

Plan-mode decision kinds.

func (Kind) Valid

func (k Kind) Valid() bool

Valid reports whether the kind is known.

type Outcome

type Outcome struct {
	Kind     Kind
	Decision Decision
}

Outcome reports what the runtime must apply after a resolution.

type Request

type Request struct {
	Kind       Kind   `json:"kind"`
	ID         string `json:"id"`
	ToolCallID string `json:"tool_call_id"`
	Content    string `json:"content,omitempty"`
	HasContent bool   `json:"has_content"`
	Size       int64  `json:"size"`
}

Request is one content-bound plan-mode decision identity. The plan content is read from disk when the request is created; it is never passed as a tool argument.

func CloneRequest

func CloneRequest(request Request) Request

CloneRequest returns an independent request value.

func NewRequest

func NewRequest(kind Kind, toolCallID, content string) (Request, error)

NewRequest binds one tool call to the plan content read from disk.

type Resolution

type Resolution struct {
	RequestID string   `json:"request_id"`
	Decision  Decision `json:"decision"`
	Comments  []string `json:"comments,omitempty"`
	Notes     string   `json:"notes,omitempty"`
}

Resolution is one exact user decision for a pending request.

func CloneResolution

func CloneResolution(resolution Resolution) Resolution

CloneResolution returns an independent resolution value.

type Resolver

type Resolver interface {
	ResolveToolCalls(...agent.ToolResolution) error
}

Resolver durably records one result for a paused Tool call.

type Service

type Service interface {
	// PlanState reports the current plan-mode state.
	PlanState() planmode.State
	// EnterPlanMode executes an enter_plan_mode call that needs no approval.
	EnterPlanMode(context.Context) (string, error)
	// ExitPlanMode executes an exit_plan_mode call in a state without a gate.
	ExitPlanMode(context.Context) (string, error)
}

Service exposes the runtime-owned plan-mode state and direct tool execution to the controller.

Jump to

Keyboard shortcuts

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