planmode

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: 15 Imported by: 0

Documentation

Overview

Package planmode owns the plan-mode state machine, the session-bound plan file, and the model-facing reminder text.

Index

Constants

View Source
const AgentModeReminder = "You are now in Agent mode. Continue with the task in the new mode."

AgentModeReminder is injected when the session returns to agent mode.

View Source
const ApprovalCommentsPrefix = "The user approved the plan with the following review comments:"

ApprovalCommentsPrefix introduces review comments attached to an approval.

View Source
const DeclineResult = "The user declined to enter plan mode. Continue in normal mode without it."

DeclineResult is returned when the user declines to enter plan mode.

View Source
const EnterDescription = "Use this tool when a task has ambiguity about the right approach " +
	"or when the user asks you to write a plan. This tool enables a read-only plan mode " +
	"where you explore the codebase and create an implementation plan for the user."

EnterDescription is the enter_plan_mode tool description.

View Source
const EnterResult = "You have entered plan mode. You should now focus on exploring the codebase " +
	"and creating an implementation plan."

EnterResult is returned after an approved enter_plan_mode call.

View Source
const EnterToolName = "enter_plan_mode"

EnterToolName is the model-facing entry gate.

View Source
const ExitApprovedEmptyResult = "Plan mode exit approved. No plan content was found - you can proceed."

ExitApprovedEmptyResult is returned when the user approves without a plan.

View Source
const ExitApprovedResult = "Your plan has been approved. You can now start coding."

ExitApprovedResult is returned when the user approves the plan.

View Source
const ExitDescription = "Exit plan mode and present your plan to the user.\n\n" +
	"Use this after you have finished writing your plan to the plan file in plan mode."

ExitDescription is the exit_plan_mode tool description.

View Source
const ExitQuitResult = "The user chose to abandon the plan entirely (via the Abandon option in " +
	"the plan approval dialog). Plan mode has been disabled. Do not call " + ExitToolName +
	" again unless the user explicitly asks to re-enter plan mode."

ExitQuitResult is returned when the user abandons the plan.

View Source
const ExitReviseResult = "The user does not want to exit plan mode. Continue planning and ask " +
	"the user what they would like to do."

ExitReviseResult is returned when the user requests changes instead of approving.

View Source
const ExitToolName = "exit_plan_mode"

ExitToolName is the model-facing exit gate.

View Source
const ExitedReminder = "You have exited plan mode. You can now make edits, run tools, and take actions."

ExitedReminder is injected on the first request after plan mode is turned off while a turn is still in flight.

View Source
const RevisionPrefix = "User revision notes:"

RevisionPrefix introduces freeform revision notes requested from the user.

View Source
const StillActiveReminder = "Plan mode is still active. Do not make any edits or writes to the " +
	"system except for the plan file."

StillActiveReminder is the short reminder for follow-up requests.

Variables

View Source
var (
	// ErrNotFound means the session has no plan file yet.
	ErrNotFound = errors.New("coding plan file: not found")
	// ErrUnsafe means a filesystem object violates the private-file contract.
	ErrUnsafe = errors.New("coding plan file: unsafe filesystem object")
	// ErrUnsupported means the platform cannot provide the required guarantees.
	ErrUnsupported = errors.New("coding plan file: unsupported platform")
)
View Source
var ErrInvalid = errors.New("coding plan mode: invalid value")

ErrInvalid reports a malformed state or transition.

Functions

func ApprovalResult

func ApprovalResult(comments []string) string

ApprovalResult renders the approval tool result, including pending review comments when present.

func EditRejection

func EditRejection(planPath string) string

EditRejection is the model-facing rejection for edits outside the plan file.

func IterationGuidance

func IterationGuidance(ask string) string

IterationGuidance renders the plan-iteration-versus-execution guidance injected on user turns while plan mode is still active.

func PlanReminder

func PlanReminder(planPath string, hasContent bool, names ReminderNames) string

PlanReminder renders the plan-mode reminder injected with each request while plan mode is active.

func ReturningReminder

func ReturningReminder(planPath string, names ReminderNames) string

ReturningReminder renders the reminder used when plan mode is entered again while a plan file from the previous planning session still exists.

func RevisionResult

func RevisionResult(notes string) string

RevisionResult renders the request-changes tool result with revision notes.

Types

type Document

type Document struct {
	Content string `json:"content,omitempty"`
	Size    int64  `json:"size"`
}

Document is one immutable plan snapshot.

type Limits

type Limits struct {
	MaxBytes int64
}

Limits bound private plan storage.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns production plan storage limits.

type ReminderNames

type ReminderNames struct {
	Edit string
	Ask  string
	Exit string
}

ReminderNames are the tool names interpolated into the plan-mode reminder.

type State

type State string

State is the plan-mode state machine value.

Inactive    -- normal operating mode; no gate
Pending     -- the user toggled plan mode on; no prompt has been sent yet
Active      -- the edit gate is armed and the plan reminder is injected
ExitPending -- the user toggled plan mode off while a turn is in flight;
               the gate holds until the turn completes
const (
	StateInactive    State = "inactive"
	StatePending     State = "pending"
	StateActive      State = "active"
	StateExitPending State = "exit_pending"
)

Plan-mode states.

func (State) Activate

func (s State) Activate() (State, error)

Activate promotes Pending to Active when the first prompt of the plan-mode interaction starts. Other states pass through unchanged.

func (State) Durable

func (s State) Durable() State

Durable returns the state persisted across restarts. Transient states (Pending, ExitPending) collapse to Inactive because they depend on in-flight interactions.

func (State) EnterApproved

func (s State) EnterApproved() (State, error)

EnterApproved applies an approved enter_plan_mode call, which skips Pending.

func (State) ExitApproved

func (s State) ExitApproved() (State, error)

ExitApproved applies an approved or abandoned exit_plan_mode call. Plan mode is disabled immediately, even mid-turn.

func (State) GateArmed

func (s State) GateArmed() bool

GateArmed reports whether file edits outside the plan file are rejected.

func (State) Plan

func (s State) Plan() bool

Plan reports whether the state is reported as the plan operating mode. Pending and ExitPending both keep the plan flag while they are observable.

func (State) ToggleOff

func (s State) ToggleOff(inFlight bool) (State, error)

ToggleOff is the user-initiated exit transition. inFlight marks that a turn is currently running, which defers the exit to the end of the turn.

func (State) ToggleOn

func (s State) ToggleOn() (State, error)

ToggleOn is the user-initiated entry transition (/plan, Shift+Tab, ACP set_mode plan). From ExitPending it re-arms the active state.

func (State) TurnComplete

func (s State) TurnComplete() (State, error)

TurnComplete settles ExitPending once its in-flight turn finishes.

func (State) Valid

func (s State) Valid() bool

Valid reports whether the value is a known state.

type Store

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

Store owns one session's private plan directory: the plan file the model edits plus the durable plan-mode state.

func NewStore

func NewStore(sessionsDir, sessionID string, limits Limits) (*Store, error)

NewStore opens (creating when needed) the private plan directory of one conversation session under the Harness sessions directory.

func (*Store) CopyTo

func (s *Store) CopyTo(ctx context.Context, target *Store) error

CopyTo copies the plan file and durable state into another session store. A source without a plan is a successful no-op.

func (*Store) Dir

func (s *Store) Dir() string

Dir returns the private plan directory.

func (*Store) LoadState

func (s *Store) LoadState(ctx context.Context) (State, error)

LoadState reads the durable plan-mode state. Missing state is Inactive and transient states collapse to Inactive because they depend on in-flight interactions that did not survive the restart.

func (*Store) Path

func (s *Store) Path() string

Path returns the absolute plan file path disclosed to the model and the frontend. It never creates or reads the file.

func (*Store) Read

func (s *Store) Read(ctx context.Context) (Document, error)

Read returns the current plan content.

func (*Store) Replace

func (s *Store) Replace(ctx context.Context, content string) (Document, error)

Replace atomically replaces the complete plan content.

func (*Store) SaveState

func (s *Store) SaveState(ctx context.Context, state State) error

SaveState persists the durable projection of the given state.

func (*Store) Seed

func (s *Store) Seed(ctx context.Context) (bool, error)

Seed creates an empty plan file when none exists. An existing file (empty or not) is left untouched so entry can never truncate a preserved plan.

func (*Store) SessionID

func (s *Store) SessionID() string

SessionID returns the owning session identity.

Jump to

Keyboard shortcuts

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