Documentation
¶
Overview ¶
Package automate provides shared workflow discovery and validation for the automate/ feature used by both the CLI (cmd/automate.go) and the agent tool layer (pkg/agent/tool_handlers_automate.go).
Index ¶
- func Dir() string
- func ExtractDescription(path string) (string, error)
- func GetAutomateSessionDir(baseDir string) (string, error)
- func IsNotExists(err error) bool
- func IsProcessAlive(pid int) bool
- func IsValidFilename(name string) bool
- func RemoveSessionFile(sproutDir string, sessionID string) error
- func ResolvePath(dir string, name string) (string, error)
- func StopProcess(pid int) (bool, error)
- func SweepStaleSessions(sproutDir string) (int, error)
- func WriteSessionFile(sproutDir string, sessionID string, info *AutomateSessionInfo) error
- type AutomateSessionInfo
- type BudgetSummary
- type Entry
- type InitialSummary
- type StepSummary
- type SubagentOverrideSummary
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractDescription ¶
ExtractDescription reads a workflow JSON file and returns its description field.
func GetAutomateSessionDir ¶ added in v0.16.4
GetAutomateSessionDir returns the .sprout/automate/ directory path. It resolves the sprout directory relative to the given base (typically project root). Creates the directory if it doesn't exist.
func IsNotExists ¶
IsNotExists returns true if the error indicates a missing file or directory.
func IsProcessAlive ¶ added in v0.16.4
func IsValidFilename ¶
IsValidFilename checks if a filename is safe for use as a workflow filename. Only allows alphanumeric characters, dots, underscores, and hyphens, followed by .json. Prevents shell injection via filenames.
func RemoveSessionFile ¶ added in v0.16.4
RemoveSessionFile removes the PID file for a session.
func ResolvePath ¶
ResolvePath finds a workflow file by name, with or without .json extension, and verifies the resolved path stays under the given directory to prevent path traversal attacks.
func StopProcess ¶ added in v0.16.4
StopProcess escalates signals to gracefully (then forcefully) stop a process. It sends SIGINT, waits 10s, then SIGTERM, waits 5s, then SIGKILL, waits 2s. Returns true if the process is confirmed dead after escalation.
func SweepStaleSessions ¶ added in v0.16.4
SweepStaleSessions removes session files whose tracked process is no longer alive. It returns the number of removed entries. Errors from listing or reading the session directory are returned; errors from individual file removals are silently ignored to avoid failing the sweep for one bad entry.
func WriteSessionFile ¶ added in v0.16.4
func WriteSessionFile(sproutDir string, sessionID string, info *AutomateSessionInfo) error
WriteSessionFile writes a session info JSON to .sprout/automate/<sessionID>.json. Creates the directory if needed.
Types ¶
type AutomateSessionInfo ¶ added in v0.16.4
type AutomateSessionInfo struct {
Workflow string `json:"workflow"`
PID int `json:"pid"`
StartedAt time.Time `json:"started_at"`
OutputFilePath string `json:"output_file_path,omitempty"`
BudgetUSD *float64 `json:"budget_usd,omitempty"`
Kind string `json:"kind"` // always "automate"
}
AutomateSessionInfo is the schema for .sprout/automate/<session_id>.json PID files.
func ListSessionFiles ¶ added in v0.16.4
func ListSessionFiles(sproutDir string) ([]AutomateSessionInfo, error)
ListSessionFiles reads all session files in .sprout/automate/ and returns them.
func ReadSessionFile ¶ added in v0.16.4
func ReadSessionFile(sproutDir string, sessionID string) (*AutomateSessionInfo, error)
ReadSessionFile reads and parses a single session file.
type BudgetSummary ¶ added in v0.16.4
BudgetSummary mirrors the cmd-level budget config in a package that has no cmd dependency, so the overview renderer can display it.
type Entry ¶
type Entry struct {
Filename string `json:"name"`
FilePath string
Description string `json:"description,omitempty"`
}
Entry represents a discovered workflow file with its metadata.
type InitialSummary ¶ added in v0.16.4
type InitialSummary struct {
Persona string
Provider string
Model string
MaxIterations int
RiskProfile string
HasPrompt bool
SubagentOverrides []SubagentOverrideSummary
}
InitialSummary describes the initial run.
type StepSummary ¶ added in v0.16.4
type StepSummary struct {
Name string
Kind string
Persona string
Provider string
Model string
When string
CommandPreview string
}
StepSummary describes a single workflow step.
Kind is one of "agent" (LLM inference) or "shell" (raw command). For shell steps, CommandPreview holds a single-line excerpt of the command for display.
type SubagentOverrideSummary ¶ added in v0.16.4
SubagentOverrideSummary describes one entry of subagent_overrides for display.
type Summary ¶ added in v0.16.4
type Summary struct {
Description string
ContinueOnError bool
NoWebUI bool
Initial *InitialSummary
Steps []StepSummary
Budget *BudgetSummary
// RequiresApproval reports whether the run_automate tool path should
// prompt the user before launching this workflow. nil means the field
// was unset in JSON (defaults to true). Explicit false marks the
// workflow as agent-runnable without user confirmation.
RequiresApproval *bool
}
Summary describes the structure of a workflow file at a glance. It is produced by Summarize and used by the CLI to render a human-readable overview before kicking off the workflow.
func Summarize ¶ added in v0.16.4
Summarize parses a workflow file and returns its high-level structure. Fields the JSON does not specify are left at their zero value.
func (*Summary) IsApprovalRequired ¶ added in v0.16.4
IsApprovalRequired returns true unless the workflow JSON explicitly declared requires_approval: false. Used by the agent tool path to decide whether to surface the intent-confirmation prompt.