cli

package
v0.1.78 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Overview

Package cli defines agentctl commands, global flags (design doc section 11.1), and exit-code mapping (section 11.2). Output formatting lives in render.

The init command scaffolds a minimal project from embedded templates (section 10.2).

The new command (issue #113) scaffolds individual Tool, Policy, Workflow, or Agent resources under conventional paths and appends them to project.yaml imports with atomic rollback-safe writes.

The validate command (section 10.2) loads the project, applies defaults and optional environment overlays, then runs spec.ValidateProjectGraph.

The fmt command (section 10.2) rewrites YAML files in the project import closure via project.ListProjectYAMLFiles and project.NormalizeYAML, with optional --check for CI.

The inspect command (section 10.2) uses the same preparation pipeline and prints one effective normalized resource envelope (Kind/name) as JSON, YAML, or indented JSON for table output. With --web it serves a read-only local inspector via inspect over SQLite state (issue #109).

The state command (section 10.2, §14.1) lists or shows rows from the SQLite deployment store (applied_resources, applied_projects) read-only via state.DeploymentStore.

The test command (section 10.2, §17.4) runs YAML workflow fixtures from <project>/tests/ via testkit.

The plan command compares that prepared graph to the SQLite deployment store (default .agentic/state.db, or project.spec.state.dsn / --state) and prints a diff plus risk delta via plan.ComputePlan and plan.FormatPlan.

The diff command uses the same comparison but prints a detailed per-resource view (field-level updates, full JSON for creates/deletes) and supports an optional Kind/name argument (§10.2).

The apply command runs the same preparation and planning, then prompts on a TTY (unless --auto-approve or AGENTCTL_AUTO_APPROVE) and persists via apply.Applier.ApplyPlan.

The run command executes a workflow by name (workflow/<name>), validates input, writes trace rows to the same SQLite file as plan/apply, and maps policy denials to exit code 5.

The logs command reads runs and trace_events from that SQLite file (ordered by seq per run) and supports listing recent runs, filtering by --run, or by --workflow.

The audit command (issue #116) verifies tamper-evident hash chains over trace_events via audit.VerifyRunChain; see docs/AUDIT_CHAIN.md.

Index

Constants

View Source
const (
	ExitSuccess           = 0
	ExitGenericFailure    = 1
	ExitValidationError   = 2
	ExitPlanApplyConflict = 3
	ExitExecutionError    = 4
	ExitPolicyDenied      = 5
)

Exit codes (design doc section 11.2).

View Source
const EnvActorID = "AGENTCTL_ACTOR_ID"

EnvActorID overrides --actor-id when the flag is omitted.

View Source
const EnvAutoApprove = "AGENTCTL_AUTO_APPROVE"

EnvAutoApprove is read when true-like to skip the apply confirmation prompt (non-TTY / CI).

View Source
const EnvHitlActor = "AGENTCTL_HITL_ACTOR"

EnvHitlActor overrides the actor recorded on approval trace events.

View Source
const EnvRequireAttribution = "AGENTCTL_REQUIRE_ATTRIBUTION"

EnvRequireAttribution, when set to a truthy value, requires explicit tenant/thread/actor ids on run.

View Source
const EnvTenantID = "AGENTCTL_TENANT_ID"

EnvTenantID overrides --tenant-id when the flag is omitted.

View Source
const EnvThreadID = "AGENTCTL_THREAD_ID"

EnvThreadID overrides --thread-id when the flag is omitted.

Variables

View Source
var Version = "0.0.0-dev"

Version is set at link time; default for dev builds.

Functions

func BindPersistentFlags

func BindPersistentFlags(cmd *cobra.Command)

BindPersistentFlags registers -e/--env, -o/--output, --project, --state, --no-color on cmd.

func Execute

func Execute() error

Execute runs the root command.

func ExitCodeOf

func ExitCodeOf(err error) int

ExitCodeOf maps errors to process exit codes. Unknown errors use ExitGenericFailure.

func Main

func Main() int

Main is an optional entrypoint that maps errors to exit codes and writes diagnostics to stderr.

func NewExitError

func NewExitError(code int, err error) error

NewExitError wraps err with a specific exit code.

func NewExitErrorf

func NewExitErrorf(code int, format string, a ...any) error

NewExitErrorf is like fmt.Errorf with an exit code.

func NewRootCmd

func NewRootCmd() *cobra.Command

NewRootCmd builds the agentctl command tree (exposed for tests).

func ParseResourceRef added in v0.1.4

func ParseResourceRef(s string) (spec.ResourceID, error)

ParseResourceRef parses a CLI resource argument as Kind/name (e.g. Policy/default, workflow/hello). Kind is matched case-insensitively and normalized to spec kind constants.

func ResetGlobalsForTest

func ResetGlobalsForTest()

ResetGlobalsForTest resets global flags (for tests only).

func ValidateGlobals

func ValidateGlobals() error

ValidateGlobals checks flag values after parsing.

Types

type ExitError

type ExitError struct {
	Code int
	Err  error
}

ExitError carries a non-zero exit status for ExitCodeOf.

func (*ExitError) Error

func (e *ExitError) Error() string

func (*ExitError) Unwrap

func (e *ExitError) Unwrap() error

Unwrap returns the underlying error.

type Global

type Global struct {
	Env         string
	Output      string
	ProjectRoot string
	StatePath   string
	NoColor     bool
}

Global holds root persistent flags shared by all subcommands (design doc section 11.1).

func Globals

func Globals() *Global

Globals returns the process-wide CLI global options after flags are parsed.

Jump to

Keyboard shortcuts

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