Documentation
¶
Overview ¶
Package prompt handles prompt file loading, saving, and queue management.
Index ¶
- Variables
- func AllPreviousCompleted(ctx context.Context, completedDir string, n int) bool
- func Content(ctx context.Context, path string, ...) (string, error)
- func HasExecuting(ctx context.Context, dir string, ...) bool
- func IncrementRetryCount(ctx context.Context, path string, ...) error
- func MoveToCompleted(ctx context.Context, path string, completedDir string, mover FileMover, ...) error
- func ResetExecuting(ctx context.Context, dir string, ...) error
- func ResetFailed(ctx context.Context, dir string, ...) error
- func SetBranch(ctx context.Context, path string, branch string, ...) error
- func SetContainer(ctx context.Context, path string, container string, ...) error
- func SetPRURL(ctx context.Context, path string, url string, ...) error
- func SetStatus(ctx context.Context, path string, status string, ...) error
- func SetVersion(ctx context.Context, path string, version string, ...) error
- func StripNumberPrefix(filename string) string
- func Title(ctx context.Context, path string, ...) (string, error)
- type Counter
- type FileMover
- type Frontmatter
- type Manager
- type Prompt
- type PromptFile
- func (pf *PromptFile) Branch() string
- func (pf *PromptFile) Content() (string, error)
- func (pf *PromptFile) Issue() string
- func (pf *PromptFile) MarkApproved()
- func (pf *PromptFile) MarkCompleted()
- func (pf *PromptFile) MarkFailed()
- func (pf *PromptFile) MarkPendingVerification()
- func (pf *PromptFile) PRURL() string
- func (pf *PromptFile) PrepareForExecution(container, version string)
- func (pf *PromptFile) RetryCount() int
- func (pf *PromptFile) Save(ctx context.Context) error
- func (pf *PromptFile) SetBranch(branch string)
- func (pf *PromptFile) SetBranchIfEmpty(branch string)
- func (pf *PromptFile) SetIssue(issue string)
- func (pf *PromptFile) SetIssueIfEmpty(issue string)
- func (pf *PromptFile) SetPRURL(url string)
- func (pf *PromptFile) SetSummary(summary string)
- func (pf *PromptFile) Specs() []string
- func (pf *PromptFile) Title() string
- func (pf *PromptFile) VerificationSection() string
- type PromptStatus
- type PromptStatuses
- type Rename
- type SpecList
Constants ¶
This section is empty.
Variables ¶
var AvailablePromptStatuses = PromptStatuses{ DraftPromptStatus, ApprovedPromptStatus, ExecutingPromptStatus, CompletedPromptStatus, FailedPromptStatus, InReviewPromptStatus, PendingVerificationPromptStatus, }
AvailablePromptStatuses is the collection of all valid PromptStatus values.
var ErrEmptyPrompt = stderrors.New("prompt file is empty")
ErrEmptyPrompt is returned when a prompt file is empty or contains only whitespace.
Functions ¶
func AllPreviousCompleted ¶ added in v0.4.0
AllPreviousCompleted checks if all prompts with numbers less than n are in completed directory.
func Content ¶
func Content( ctx context.Context, path string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) (string, error)
Content returns the prompt content (without frontmatter) for passing to Docker. Returns ErrEmptyPrompt if the file is empty or contains only whitespace.
func HasExecuting ¶ added in v0.2.24
func HasExecuting( ctx context.Context, dir string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) bool
HasExecuting returns true if any prompt in dir has status "executing".
func IncrementRetryCount ¶ added in v0.17.34
func IncrementRetryCount( ctx context.Context, path string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
IncrementRetryCount increments the retryCount field in a prompt file's frontmatter by 1. If the file has no frontmatter, adds frontmatter with retryCount set to 1.
func MoveToCompleted ¶
func MoveToCompleted( ctx context.Context, path string, completedDir string, mover FileMover, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
MoveToCompleted sets status to "completed" and moves a prompt file to the completed directory. This ensures files in completed/ always have the correct status.
func ResetExecuting ¶ added in v0.2.5
func ResetExecuting( ctx context.Context, dir string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
ResetExecuting resets any prompts with status "executing" back to "approved". This handles prompts that got stuck from a previous crash.
func ResetFailed ¶ added in v0.10.6
func ResetFailed( ctx context.Context, dir string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
ResetFailed resets any prompts with status "failed" back to "approved". This allows the factory to retry failed prompts after a restart.
func SetBranch ¶ added in v0.17.17
func SetBranch( ctx context.Context, path string, branch string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
SetBranch updates the branch field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the branch field.
func SetContainer ¶ added in v0.2.11
func SetContainer( ctx context.Context, path string, container string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
SetContainer updates the container field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the container field.
func SetPRURL ¶ added in v0.16.0
func SetPRURL( ctx context.Context, path string, url string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
SetPRURL updates the pr-url field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the pr-url field.
func SetStatus ¶
func SetStatus( ctx context.Context, path string, status string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
SetStatus updates the status field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the status field. Also sets appropriate timestamp fields based on status.
func SetVersion ¶ added in v0.6.0
func SetVersion( ctx context.Context, path string, version string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) error
SetVersion updates the dark-factory-version field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the version field.
func StripNumberPrefix ¶ added in v0.47.0
StripNumberPrefix removes any leading numeric prefix (e.g. "200-foo.md" → "foo.md", "1-bar.md" → "bar.md"). Returns the original filename if no numeric prefix is found.
Types ¶
type Counter ¶ added in v0.17.24
type Counter interface {
CountBySpec(ctx context.Context, specID string) (completed, total int, err error)
}
Counter counts prompts linked to specs.
func NewCounter ¶ added in v0.17.24
func NewCounter(currentDateTimeGetter libtime.CurrentDateTimeGetter, dirs ...string) Counter
NewCounter creates a Counter that scans the given directories.
type Frontmatter ¶
type Frontmatter struct {
Status string `yaml:"status"`
Specs SpecList `yaml:"spec,omitempty,flow"`
Summary string `yaml:"summary,omitempty"`
Container string `yaml:"container,omitempty"`
DarkFactoryVersion string `yaml:"dark-factory-version,omitempty"`
Created string `yaml:"created,omitempty"`
Queued string `yaml:"queued,omitempty"`
Started string `yaml:"started,omitempty"`
Completed string `yaml:"completed,omitempty"`
PRURL string `yaml:"pr-url,omitempty"`
Branch string `yaml:"branch,omitempty"`
Issue string `yaml:"issue,omitempty"`
RetryCount int `yaml:"retryCount,omitempty"`
}
Frontmatter represents the YAML frontmatter in a prompt file.
func ReadFrontmatter ¶ added in v0.2.0
func ReadFrontmatter( ctx context.Context, path string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) (*Frontmatter, error)
ReadFrontmatter reads frontmatter from a file.
func (Frontmatter) HasSpec ¶ added in v0.17.28
func (f Frontmatter) HasSpec(id string) bool
HasSpec returns true if the given spec ID is in the Specs list. Comparison is by parsed integer prefix: "019" matches "19", "0019", and "019-review-fix-loop". If either value has no numeric prefix, falls back to exact string match.
type Manager ¶ added in v0.2.26
type Manager interface {
ResetExecuting(ctx context.Context) error
ResetFailed(ctx context.Context) error
HasExecuting(ctx context.Context) bool
ListQueued(ctx context.Context) ([]Prompt, error)
Load(ctx context.Context, path string) (*PromptFile, error)
ReadFrontmatter(ctx context.Context, path string) (*Frontmatter, error)
SetStatus(ctx context.Context, path string, status string) error
SetContainer(ctx context.Context, path string, name string) error
SetVersion(ctx context.Context, path string, version string) error
SetPRURL(ctx context.Context, path string, url string) error
SetBranch(ctx context.Context, path string, branch string) error
IncrementRetryCount(ctx context.Context, path string) error
Content(ctx context.Context, path string) (string, error)
Title(ctx context.Context, path string) (string, error)
MoveToCompleted(ctx context.Context, path string) error
NormalizeFilenames(ctx context.Context, dir string) ([]Rename, error)
AllPreviousCompleted(ctx context.Context, n int) bool
// HasQueuedPromptsOnBranch returns true if any queued prompt (other than excludePath)
// has the given branch value in its frontmatter.
HasQueuedPromptsOnBranch(ctx context.Context, branch string, excludePath string) (bool, error)
}
Manager manages prompt file operations.
func NewManager ¶ added in v0.2.26
func NewManager( inboxDir string, inProgressDir string, completedDir string, mover FileMover, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) Manager
NewManager creates a new Manager.
type Prompt ¶
type Prompt struct {
Path string
Status PromptStatus
}
Prompt represents a prompt file with YAML frontmatter.
func ListQueued ¶
func ListQueued( ctx context.Context, dir string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) ([]Prompt, error)
ListQueued scans a directory for .md files that should be picked up. Files are picked up UNLESS they have an explicit skip status (executing, completed, failed). Sorted alphabetically by filename.
func (Prompt) Number ¶ added in v0.4.0
Number extracts the numeric prefix from the prompt filename. Returns -1 if the filename has no numeric prefix.
type PromptFile ¶ added in v0.11.6
type PromptFile struct {
Path string
Frontmatter Frontmatter
Body []byte // immutable after Load — never modified
// contains filtered or unexported fields
}
PromptFile represents a loaded prompt file with immutable body and mutable frontmatter.
func Load ¶ added in v0.11.6
func Load( ctx context.Context, path string, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) (*PromptFile, error)
Load reads a prompt file from disk, parsing frontmatter and body. Body is stored as-is and never modified by Save.
func NewPromptFile ¶ added in v0.36.3
func NewPromptFile( path string, fm Frontmatter, body []byte, currentDateTimeGetter libtime.CurrentDateTimeGetter, ) *PromptFile
NewPromptFile creates a PromptFile with the given fields and currentDateTimeGetter. This is intended for use in tests where a PromptFile must be constructed without reading from disk.
func (*PromptFile) Branch ¶ added in v0.17.17
func (pf *PromptFile) Branch() string
Branch returns the branch field from frontmatter.
func (*PromptFile) Content ¶ added in v0.11.6
func (pf *PromptFile) Content() (string, error)
Content returns the body as a string, stripped of leading empty frontmatter blocks. Returns ErrEmptyPrompt if body is empty or whitespace-only.
func (*PromptFile) Issue ¶ added in v0.43.0
func (pf *PromptFile) Issue() string
Issue returns the issue tracker reference from the prompt frontmatter (empty string if unset).
func (*PromptFile) MarkApproved ¶ added in v0.24.2
func (pf *PromptFile) MarkApproved()
MarkApproved sets status to approved and ensures created/queued timestamps exist.
func (*PromptFile) MarkCompleted ¶ added in v0.11.6
func (pf *PromptFile) MarkCompleted()
MarkCompleted sets status to completed with timestamp.
func (*PromptFile) MarkFailed ¶ added in v0.11.6
func (pf *PromptFile) MarkFailed()
MarkFailed sets status to failed with timestamp.
func (*PromptFile) MarkPendingVerification ¶ added in v0.28.0
func (pf *PromptFile) MarkPendingVerification()
MarkPendingVerification sets status to pending_verification.
func (*PromptFile) PRURL ¶ added in v0.17.17
func (pf *PromptFile) PRURL() string
PRURL returns the pr-url field from frontmatter.
func (*PromptFile) PrepareForExecution ¶ added in v0.11.6
func (pf *PromptFile) PrepareForExecution(container, version string)
PrepareForExecution sets all fields needed before container launch. This replaces separate SetContainer + SetVersion + SetStatus calls.
func (*PromptFile) RetryCount ¶ added in v0.17.34
func (pf *PromptFile) RetryCount() int
RetryCount returns the retryCount field from frontmatter.
func (*PromptFile) Save ¶ added in v0.11.6
func (pf *PromptFile) Save(ctx context.Context) error
Save writes the prompt file back to disk: frontmatter + body. Body is always preserved exactly as loaded.
func (*PromptFile) SetBranch ¶ added in v0.17.17
func (pf *PromptFile) SetBranch(branch string)
SetBranch sets the branch field in frontmatter.
func (*PromptFile) SetBranchIfEmpty ¶ added in v0.40.0
func (pf *PromptFile) SetBranchIfEmpty(branch string)
SetBranchIfEmpty sets the branch field only if it is currently empty.
func (*PromptFile) SetIssue ¶ added in v0.40.0
func (pf *PromptFile) SetIssue(issue string)
SetIssue sets the issue field in frontmatter.
func (*PromptFile) SetIssueIfEmpty ¶ added in v0.40.0
func (pf *PromptFile) SetIssueIfEmpty(issue string)
SetIssueIfEmpty sets the issue field only if it is currently empty.
func (*PromptFile) SetPRURL ¶ added in v0.16.0
func (pf *PromptFile) SetPRURL(url string)
SetPRURL sets the pr-url field in frontmatter.
func (*PromptFile) SetSummary ¶ added in v0.13.1
func (pf *PromptFile) SetSummary(summary string)
SetSummary sets the summary field in frontmatter.
func (*PromptFile) Specs ¶ added in v0.17.28
func (pf *PromptFile) Specs() []string
Specs returns the specs slice from frontmatter. Returns an empty slice if nil.
func (*PromptFile) Title ¶ added in v0.11.6
func (pf *PromptFile) Title() string
Title extracts the first # heading from the body.
func (*PromptFile) VerificationSection ¶ added in v0.28.0
func (pf *PromptFile) VerificationSection() string
VerificationSection extracts the content of the <verification> tag from the prompt body. Returns an empty string if no <verification> tag is found.
type PromptStatus ¶ added in v0.24.2
type PromptStatus string
PromptStatus represents the current state of a prompt.
const ( DraftPromptStatus PromptStatus = "draft" ApprovedPromptStatus PromptStatus = "approved" ExecutingPromptStatus PromptStatus = "executing" CompletedPromptStatus PromptStatus = "completed" FailedPromptStatus PromptStatus = "failed" InReviewPromptStatus PromptStatus = "in_review" PendingVerificationPromptStatus PromptStatus = "pending_verification" )
func (PromptStatus) String ¶ added in v0.24.2
func (s PromptStatus) String() string
String returns the string representation of the PromptStatus.
type PromptStatuses ¶ added in v0.24.2
type PromptStatuses []PromptStatus
PromptStatuses is a slice of PromptStatus values.
func (PromptStatuses) Contains ¶ added in v0.24.2
func (p PromptStatuses) Contains(status PromptStatus) bool
Contains returns true if the given status is in the collection.
type Rename ¶ added in v0.2.15
Rename represents a file rename operation.
func NormalizeFilenames ¶ added in v0.2.15
func NormalizeFilenames( ctx context.Context, dir string, completedDir string, mover FileMover, ) ([]Rename, error)
NormalizeFilenames scans a directory for .md files and ensures they follow the NNN-slug.md naming convention. Files are renamed if they: - Have no numeric prefix (gets next available number) - Have a duplicate number (later file gets next available number) - Have wrong format (e.g., 9-foo.md instead of 009-foo.md) Returns list of renames performed.