app

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExitOK    = 0
	ExitFail  = 1
	ExitUsage = 2
)

Exit codes.

View Source
const (
	ANSIReset  = "\x1b[0m"
	ANSIBold   = "\x1b[1m"
	ANSIDim    = "\x1b[2m"
	ANSICyan   = "\x1b[1;36m"
	ANSIGreen  = "\x1b[32m"
	ANSIRed    = "\x1b[31m"
	ANSIYellow = "\x1b[33m"
)
View Source
const DiffContext = 3
View Source
const MaxTestInput = 8 << 20

maxTestInput bounds what `redact test` reads.

Variables

View Source
var ANSISGR = regexp.MustCompile(`\x1b\[[0-9;]*m`)
View Source
var RunIDPattern = regexp.MustCompile(`^[A-Za-z0-9_-]+$`)

Functions

func CodeErr

func CodeErr(code int) error

codeErr turns a handler's exit code into an error; zero is success.

func Commit

func Commit(tmp, path string) error

func Failf

func Failf(format string, args ...any) error

failf is a runtime failure (exit 1); usagef is a usage error (exit 2).

func FormatInt

func FormatInt(n int64) string

func OrUnknown

func OrUnknown(s string) string

func ParseFlags

func ParseFlags(fs *flag.FlagSet, args []string) (pos []string, code int, done bool)

parseFlags parses flags interleaved with positional arguments. done is true when the caller should return code immediately (help or a flag error).

func ProcessAlive

func ProcessAlive(pid int) bool

func ReadInputSource

func ReadInputSource(a *App, path string) (string, error)

readInputSource reads path (or stdin, for "-"), bounded by maxTestInput.

func RedactRawJSON

func RedactRawJSON(r *redact.Redactor, raw json.RawMessage) (json.RawMessage, error)

func RedactText

func RedactText(r *redact.Redactor, s string) (string, error)

redactText redacts a State or Instructions value: literal JSON text (the same shapes wireText treats as literal) is redacted recursively while preserving its JSON shape; anything else is redacted as a plain string, matching how the value will actually reach the wire.

func SplitLines

func SplitLines(s string) []string

func Stage

func Stage(path string, data []byte, perm os.FileMode) (string, error)

stage writes data to a fresh temp file beside path and returns its name.

func TextWidth

func TextWidth(s string) int

textWidth ignores SGR color codes so styled cells stay aligned.

func Truthy

func Truthy(value string) bool

func UnifiedDiff

func UnifiedDiff(fromName, toName, from, to string) string

unifiedDiff renders a unified diff of two texts with the same number of lines (redaction never adds or removes a line). It returns "" when the texts are equal.

func UnwrapReason

func UnwrapReason(err error) error

unwrapReason prefers the wrapped config error, which names file and key.

func UsageCount

func UsageCount(known int64, unknown int) string

func Usagef

func Usagef(format string, args ...any) error

func ValidModelName

func ValidModelName(model string) bool

func WithUsageOrigin

func WithUsageOrigin(ctx context.Context, origin, agent string) context.Context

func WithUsageRun

func WithUsageRun(ctx context.Context, runID string) context.Context

func WriteAtomic

func WriteAtomic(path string, data []byte, perm os.FileMode) error

writeAtomic writes data to path through a same-directory temp file and a rename, so a reader never sees a partial file.

func WriteTable

func WriteTable(w io.Writer, headers []string, rows [][]string)

writeTable renders a small table; callers decide whether cells have color.

func WriteTableAligned

func WriteTableAligned(w io.Writer, headers []string, rows [][]string, right []bool)

WriteTableAligned is WriteTable with the columns marked in right right-aligned, so counts line up by place value.

Types

type App

type App struct {
	Stdin          io.Reader
	Stdout, Stderr io.Writer
	// Environ is the process environment (KEY=value).
	Environ []string
	// WorkDir holds the project layer at .jevkit/redact.yaml.
	WorkDir string
	// ConfigDir holds the user layer at redact.yaml.
	ConfigDir string
	// StateDir holds the audit log and the review store.
	StateDir string
	// SecurityPolicy selects a named local security policy for this invocation.
	SecurityPolicy string
	// Yolo lifts the workspace guard; killswitch and Jev scoring still apply.
	Yolo bool
	// Now is the clock; nil means time.Now.
	Now     func() time.Time
	Version string

	// Keystore resolves and stores the API key; nil builds one from
	// ConfigDir, WorkDir and Environ.
	Keystore *keystore.Store
	// Keyring is the OS keychain backend; nil means the real one.
	Keyring keystore.Keyring
	// NewJev builds the client `key test` uses; nil builds the real one.
	NewJev func(cfg jev.Config, key func() (string, error)) Asker
	// Breaker is the persisted circuit breaker; nil uses StateDir.
	Breaker *breaker.Breaker
	// Dial probes endpoint reachability for doctor; nil skips the probe.
	Dial func(ctx context.Context, network, addr string) (net.Conn, error)
	// LookPath finds agent binaries for doctor/install; nil means not detected
	// (tests) or exec.LookPath at the call site when doctor needs real PATH.
	LookPath func(name string) (string, error)
	// HomeDir is the user home for agent user-scope installs; empty uses
	// os.UserHomeDir.
	HomeDir string
	// Binary is the jevkit path written into agent hooks; empty resolves to
	// the running executable or "jevkit".
	Binary string
	// ReadSecret reads a key with echo off. ok is false when stdin is not a
	// terminal; nil means the real terminal check on os.Stdin.
	ReadSecret func() (secret []byte, ok bool, err error)
	// NewRunID generates an sdlc run id; nil means a random one.
	NewRunID func() string
	// SdlcReach supplies fake runtime adapters in tests; nil probes CLI binaries.
	SdlcReach func() enrollment.Reach
	// SdlcExecutor replaces CLI invocation in tests and host integrations.
	SdlcExecutor worker.Executor
	// WorktreeCreator creates isolated Git worktrees for fan-out subtasks.
	// Nil uses worker.GitWorktreeCreator.
	WorktreeCreator worker.WorktreeCreator
	// SdlcSpecialistNeed replaces the specialist-need router in tests or hosts.
	// Nil uses Jev's registered specialist question set.
	SdlcSpecialistNeed func(context.Context, string, string, string) (bool, error)
	// Confirm prompts prompt and reports whether the user agreed; nil means
	// non-interactive (no TTY to confirm on), so a caller offering a
	// "gather"-confidence pick for confirmation must instead refuse.
	Confirm func(prompt string) (bool, error)
	// SuppressOutput silences Outf while a dashboard owns the terminal.
	SuppressOutput bool
}

App is the CLI with every external dependency injected, so commands run in-process under test.

func (*App) AuditPath

func (a *App) AuditPath() string

auditPath and reviewPath resolve through stateHome()+"jevkit" (the same resolver breaker.New, usage.Path, and registry.DecisionsPath use) rather than a.StateDir directly, so a JEVKIT_STATE_DIR override that doesn't itself end in "jevkit" still lands these files next to every other jevkit-owned state file instead of one directory up.

func (*App) Clock

func (a *App) Clock() time.Time

func (*App) ColorEnabled

func (a *App) ColorEnabled(w io.Writer) bool

func (*App) CompactionClient

func (a *App) CompactionClient(ctx context.Context) (compact.Asker, *compact.Policy)

func (*App) CompactionPolicyPath

func (a *App) CompactionPolicyPath(path string, project bool) string

func (*App) Errf

func (a *App) Errf(format string, args ...any)

func (*App) Getenv

func (a *App) Getenv(key string) string

getenv reads the injected environment (KEY=value pairs).

func (*App) Group

func (a *App) Group(use, short string, subs ...*cobra.Command) *cobra.Command

group makes a command that only holds subcommands.

func (*App) Heading

func (a *App) Heading(title string)

func (*App) HelpText

func (a *App) HelpText(w io.Writer, body string) string

helpText preserves Cobra's layout while making section labels and command names easier to scan on an interactive terminal.

func (*App) JevClient

func (a *App) JevClient(cfg jev.Config, key func() (string, error)) Asker

func (*App) JevConfig

func (a *App) JevConfig() (jev.Config, error)

func (*App) LayerName

func (a *App) LayerName(file string) string

layerName labels a config file as the user or project layer.

func (*App) LoadConfig

func (a *App) LoadConfig(cmd string) (*config.Config, bool)

load resolves the layered config, reporting a failure to stderr.

func (*App) LoadOptions

func (a *App) LoadOptions() config.LoadOptions

func (*App) LookPathFunc

func (a *App) LookPathFunc() func(string) (string, error)

func (*App) ModelPath

func (a *App) ModelPath() string

func (*App) ModelSelection

func (a *App) ModelSelection() (model, source string, err error)

modelSelection chooses the process override, user setting, then built-in default.

func (*App) NewFlagSet

func (a *App) NewFlagSet(name string) *flag.FlagSet

newFlagSet makes a FlagSet that reports to stderr and never exits.

func (*App) Outf

func (a *App) Outf(format string, args ...any)

func (*App) ProjectPath

func (a *App) ProjectPath() string

func (*App) RecordJev

func (a *App) RecordJev(client Asker, cfg jev.Config) Asker

func (*App) ResolveBinary

func (a *App) ResolveBinary(flag string) string

func (*App) ReviewPath

func (a *App) ReviewPath() string

func (*App) RootCmd

func (a *App) RootCmd(commands ...*cobra.Command) *cobra.Command

func (*App) Run

func (a *App) Run(args []string, commands ...*cobra.Command) int

Run dispatches args (without the program name) and returns the exit code. Cobra's own errors (unknown command, bad flag, bad arguments) are usage errors.

func (*App) RunContext

func (a *App) RunContext(ctx context.Context, args []string, commands ...*cobra.Command) int

RunContext dispatches a command with a caller-owned cancellation context. commands are the top-level subcommands; the root owns global flags and help.

func (*App) SDLCRunsDir

func (a *App) SDLCRunsDir() string

sdlcRunsDir is where run ledgers live under StateDir.

func (*App) SecurityAsker

func (a *App) SecurityAsker(ctx context.Context) Asker

func (*App) SecurityLoadOptions

func (a *App) SecurityLoadOptions() securityconfig.LoadOptions

func (*App) StateHome

func (a *App) StateHome() string

stateHome is the single resolver for the Jevkit state root, independent of how a.StateDir was set: the default (main.go's defaultStateDir, itself XDG/Windows/JEVKIT_STATE_DIR-aware) already ends in "jevkit", while an explicit JEVKIT_STATE_DIR override may or may not. Every caller below joins "jevkit" back on (or delegates to a package like breaker.New, usage.Path, or registry.DecisionsPath that does), so stateHome() always returns the same directory a "jevkit" segment is about to be appended to. Ownership under <stateHome()>/jevkit/:

  • sdlc/runs/<runID>/run.json, nodes/, artifacts/, events.jsonl, decisions.jsonl, logs/ — internal/sdlc/ledger, one directory per run (see sdlcRunsDir).
  • usage.jsonl — internal/usage, one shared append-only log for every run and every Jev call (see usage.Path).
  • decisions.jsonl (top-level, not per-run) — internal/registry, routing decisions outside any run (see registry.DecisionsPath).
  • breaker.json — internal/breaker, one shared circuit-breaker state.
  • redaction-audit.jsonl, redaction-review.json — internal/redact/audit, shared audit/review records (see auditPath, reviewPath).
  • jev-ask-audit.jsonl — internal/mcp, shared MCP audit trail.

External runtime sessions (Claude/Codex/Cursor/OpenCode/Antigravity session IDs used to resume a conversation) are not files under this root at all: they live in the owning CLI's own native session store and are only referenced by ID in ledger.Run.Sessions.

func (*App) Store

func (a *App) Store() *keystore.Store

store is the injected keystore, or one built from the app's directories.

func (*App) Styled

func (a *App) Styled(w io.Writer, code, value string) string

func (*App) Table

func (a *App) Table(headers []string, rows [][]string)

func (*App) Target

func (a *App) Target(project bool) (string, error)

target returns the layer file a write command edits.

func (*App) UserHome

func (a *App) UserHome() string

func (*App) UserPath

func (a *App) UserPath() string

type Asker

type Asker interface {
	Ask(ctx context.Context, req jev.Request) (*jev.Response, error)
}

Asker is the slice of the jev client `key test` uses.

func UsageOrigin

func UsageOrigin(client Asker, origin, agent string) Asker

type ExitError

type ExitError struct {
	Code int
	// contains filtered or unexported fields
}

exitError carries a process exit code out of a cobra RunE. An empty msg means the command already reported the failure itself.

func (*ExitError) Error

func (e *ExitError) Error() string

Jump to

Keyboard shortcuts

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