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 ¶
var AvailableStates = States{ StateApproved, StateExecuting, StateCommitting, StateCompleted, StateCancelled, StatePendingVerification, StateAborted, }
AvailableStates lists every canonical State value the system accepts. StateUnknown is the error-only sentinel and is deliberately NOT in AvailableStates.
Functions ¶
func IsPreExecutionStatus ¶
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 ¶
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 DockerState = "unavailable" )
type Location ¶
type Location string
Location is where the prompt file currently lives — the half-state discriminator.
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.