promptstate

package
v0.198.21 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: BSD-2-Clause Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package promptstate is the single owner of prompt-state interpretation. It declares the seven canonical in-memory State values (distinct from the on-disk pkg/prompt.PromptStatus), a transition table with IsValidTransition, and the pure function InterpretTuple that maps the four observable inputs (filesystem location, frontmatter status, container name, docker liveness) to an authoritative State. No existing consumer is wired to this package yet; that migration happens in later prompts.

Index

Constants

This section is empty.

Variables

AvailableStates lists every canonical State value the system accepts. StateUnknown is the error-only sentinel and is deliberately NOT in AvailableStates.

Functions

func IsPreExecutionStatus

func IsPreExecutionStatus(rawStatus string) bool

IsPreExecutionStatus reports whether the raw status is a pre-execution status (idea/draft/approved). It preserves the queuescanner pre-lock gate semantics, which are broader than the seven canonical InterpretTuple states.

func IsValidTransition

func IsValidTransition(from, to State) bool

IsValidTransition reports whether moving from -> to is an allowed state transition. Transitions not in the table (including any involving StateUnknown) return false.

func StatusFromRaw

func StatusFromRaw(rawStatus string) prompt.PromptStatus

StatusFromRaw converts a raw on-disk status string to a prompt.PromptStatus, keeping the conversion inside the allow-listed owner package.

Types

type DockerState

type DockerState string

DockerState is the liveness of the prompt's container as reported by Docker.

const (
	// DockerStateRunning means the container is alive and executing.
	DockerStateRunning DockerState = "running"
	// DockerStateStopped means the container has exited or does not exist.
	DockerStateStopped DockerState = "stopped"
	// DockerStateUnavailable means the Docker daemon is unreachable or the liveness probe errored.
	DockerStateUnavailable DockerState = "unavailable"
)

type Location

type Location string

Location is where the prompt file currently lives — the half-state discriminator.

const (
	// LocationInProgress means the file lives in prompts/in-progress/.
	LocationInProgress Location = "in_progress"
	// LocationCompleted means the file lives in prompts/completed/.
	LocationCompleted Location = "completed"
)

type State

type State string

State is the in-memory authoritative state of a prompt, derived by InterpretTuple from the four observable inputs. It is DISTINCT from pkg/prompt.PromptStatus, which is the on-disk storage type; the 1:1 mapping between them lives in this package.

const (
	// StateApproved — prompt is queued, not yet executing.
	StateApproved State = "approved"
	// StateExecuting — prompt is running in a container (or being resumed into one).
	StateExecuting State = "executing"
	// StateCommitting — container succeeded; git commit pending.
	StateCommitting State = "committing"
	// StateCompleted — prompt finished and (re)located in the completed dir.
	StateCompleted State = "completed"
	// StateCancelled — prompt was cancelled before or during execution.
	StateCancelled State = "cancelled"
	// StatePendingVerification — prompt awaits post-review verification.
	StatePendingVerification State = "pending_verification"
	// StateAborted is the INTERPRETED state for "frontmatter says executing but the
	// container is gone" — the case the daemon resolves by resetting to approved.
	// It has NO on-disk status string; it is a transient/interpreted state only.
	// (See OPEN QUESTION in prompt context: there is no "aborted" frontmatter value.)
	StateAborted State = "aborted"
	// StateUnknown is the error-only sentinel returned by InterpretTuple when the
	// frontmatter status string is not one InterpretTuple recognises
	// (spec Failure Mode row 2). Callers log ERROR unknown_prompt_status and surface
	// the prompt as "unknown"; the daemon does NOT silently coerce.
	StateUnknown State = "unknown"
)

func InterpretRawTuple

func InterpretRawTuple(
	location Location,
	rawStatus string,
	container string,
	dockerState DockerState,
) State

InterpretRawTuple is InterpretTuple with the raw on-disk status string as input. Consumers pass pf.Frontmatter.Status directly; the PromptStatus conversion lives here so consumer files contain no prompt.PromptStatus token (spec AC-3 gate).

func InterpretTuple

func InterpretTuple(
	location Location,
	status prompt.PromptStatus,
	container string,
	dockerState DockerState,
) State

InterpretTuple is the ONLY function in the codebase allowed to decide the authoritative current State from the four observable inputs. It is pure: same inputs always yield the same State; it has no shared mutable state and never blocks on docker. status is the raw on-disk frontmatter status string.

Rules (each locked by a regression test in interpret_test.go):

  • executing + container running -> StateExecuting (resume keeps it executing)
  • executing + container gone (stopped) -> StateAborted (reset-to-approved path)
  • executing + docker unavailable -> StateExecuting (refuse to coerce; file truth wins)
  • committing + file in completed dir -> StateCompleted (location wins; PR #30 half-state)
  • committing + file in in-progress dir -> StateCommitting
  • cancelled -> StateCancelled
  • pending_verification -> StatePendingVerification
  • approved -> StateApproved
  • completed -> StateCompleted
  • any unrecognised status string -> StateUnknown

Pre-execution states (idea, draft) and terminal-failure states (failed, in_review, rejected) are not in the seven canonical execution-lifecycle states and map to StateUnknown here — this is intentional, not a bug.

func (State) String

func (s State) String() string

String returns the string representation of the State.

func (State) Validate

func (s State) Validate(ctx context.Context) error

Validate returns an error if s is not a canonical State value. StateUnknown is invalid per Validate — it is a sentinel, not a canonical state.

type States

type States []State

States is a slice of State values.

func (States) Contains

func (ss States) Contains(s State) bool

Contains returns true if the given state is in the collection.

Jump to

Keyboard shortcuts

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