prompt

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func AllPreviousCompleted(ctx context.Context, completedDir string, n int) bool

AllPreviousCompleted checks if all prompts with numbers less than n are in completed directory.

func Content

func Content(ctx context.Context, path string) (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) bool

HasExecuting returns true if any prompt in dir has status "executing".

func MoveToCompleted

func MoveToCompleted(ctx context.Context, path string, completedDir string, mover FileMover) 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) error

ResetExecuting resets any prompts with status "executing" back to "queued". This handles prompts that got stuck from a previous crash.

func SetContainer added in v0.2.11

func SetContainer(ctx context.Context, path string, container string) 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 SetStatus

func SetStatus(ctx context.Context, path string, status string) error

SetStatus updates the status field in a prompt file's frontmatter. If the file has no frontmatter, adds frontmatter with the status field.

func SetVersion added in v0.6.0

func SetVersion(ctx context.Context, path string, version string) 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 Title

func Title(ctx context.Context, path string) (string, error)

Title extracts the first # heading from a prompt file. Handles files with or without frontmatter. If no heading is found, returns the filename without extension.

Types

type FileMover added in v0.2.36

type FileMover interface {
	MoveFile(ctx context.Context, oldPath string, newPath string) error
}

FileMover handles file move operations with git awareness.

type Frontmatter

type Frontmatter struct {
	Status             string `yaml:"status"`
	Container          string `yaml:"container,omitempty"`
	DarkFactoryVersion string `yaml:"dark-factory-version,omitempty"`
}

Frontmatter represents the YAML frontmatter in a prompt file.

func ReadFrontmatter added in v0.2.0

func ReadFrontmatter(ctx context.Context, path string) (*Frontmatter, error)

ReadFrontmatter reads frontmatter from a file.

type Manager added in v0.2.26

type Manager interface {
	ResetExecuting(ctx context.Context) error
	HasExecuting(ctx context.Context) bool
	ListQueued(ctx context.Context) ([]Prompt, 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
	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
}

Manager manages prompt file operations.

func NewManager added in v0.2.26

func NewManager(queueDir string, completedDir string, mover FileMover) Manager

NewManager creates a new Manager.

type Prompt

type Prompt struct {
	Path   string
	Status Status
}

Prompt represents a prompt file with YAML frontmatter.

func ListQueued

func ListQueued(ctx context.Context, dir string) ([]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

func (p Prompt) Number() int

Number extracts the numeric prefix from the prompt filename. Returns -1 if the filename has no numeric prefix.

func (Prompt) Validate added in v0.4.0

func (p Prompt) Validate(ctx context.Context) error

Validate validates the Prompt struct.

func (Prompt) ValidateForExecution added in v0.4.0

func (p Prompt) ValidateForExecution(ctx context.Context) error

ValidateForExecution validates that a prompt is ready to execute.

type Rename added in v0.2.15

type Rename struct {
	OldPath string
	NewPath string
}

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.

type Status added in v0.4.0

type Status string

Status represents the current state of a prompt.

const (
	StatusQueued    Status = "queued"
	StatusExecuting Status = "executing"
	StatusCompleted Status = "completed"
	StatusFailed    Status = "failed"
)

func (Status) Validate added in v0.4.0

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

Validate validates the Status value.

Jump to

Keyboard shortcuts

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