engine

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package engine holds what one komando call is: who makes it and the state of its approvals. Today the CLI makes one call per process; the Mac and iPhone apps will run many calls in one process, for a person and for an agent at the same time, so nothing here reads the environment or a global by itself: the caller hands it in.

Index

Constants

View Source
const GateEnv = "KOMANDO_SSH_GATE"

GateEnv names the ssh-gate key a command came through.

Variables

View Source
var GateLabel = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$`)

GateLabel is what an ssh-gate key's name may look like.

Functions

func AgentName

func AgentName(lookup func(string) (string, bool)) string

AgentName is the AI agent the environment lookup describes, or "" for a person or a script. A variable that is there counts whatever its value, also 0, false and empty: an agent told to run `CLAUDECODE=0 komando ...` must not turn its own safety stops off.

func AgentVars

func AgentVars() []string

AgentVars are the variables that make a process an agent's, for the guard hook that refuses shell lines changing them.

Types

type Call added in v0.14.0

type Call struct {
	// Program is the first word of the command line ("komando"), as the
	// audit log and the approval window show it.
	Program string
	// LookupEnv and Environ are the call's environment. The CLI passes
	// os.LookupEnv and os.Environ; nil is an empty environment, also for
	// the programs the call starts (a dump tool gets no PATH or HOME).
	// Some programs still get the process's environment, whatever the
	// call's: a kubeconfig's exec credential plugin (internal/kube), the
	// openconnect a VPN runs (internal/cli/vpn_session.go), and the ones
	// komando starts for itself (the approval window, the browser, a
	// credential helper, background komando processes).
	LookupEnv func(string) (string, bool)
	Environ   func() []string
	// Stdin, Stdout and Stderr are the call's input and output. Stdout
	// gets the JSON envelope (or the text); Stderr gets notes, warnings
	// and, in text mode, errors.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
	// Terminal: a person can answer questions at the process's terminal
	// (stdin and stderr are one). An app's calls have no terminal. When
	// Terminal is true, Stderr must be safe for writes from several
	// goroutines at once: another call's goroutine may write a notice to
	// it (netx.LockBusy: a VPN is being connected elsewhere).
	Terminal bool
	// Ask opens the approval window for an agent's --yes,
	// --allow-dangerous or --reveal; nil opens komando's own window on
	// the screen.
	Ask func(text string) (allowed, shown bool)
}

Call is what one komando call runs with: the environment it sees and where it reads and writes. The CLI makes one from its process (os.LookupEnv, os.Stdin, os.Stdout ...). An app that runs a person's call and an agent's call at the same time makes one for each, so what one call reads, prints or is allowed never reaches the other.

func (Call) Caller added in v0.14.0

func (c Call) Caller() Caller

Caller is who makes the call, read from its environment.

func (Call) Env added in v0.14.0

func (c Call) Env() []string

Env is the call's whole environment as KEY=value lines, for a program the call starts.

func (Call) Getenv added in v0.14.0

func (c Call) Getenv(key string) string

Getenv is the value of key in the call's environment, or "".

func (Call) Lookup added in v0.14.0

func (c Call) Lookup(key string) (string, bool)

Lookup is LookupEnv, or nothing found when the call has no environment.

type Caller

type Caller struct {
	Kind  Kind
	Agent string // the agent's name, for the approval window and the audit log
	Actor string // who the audit log names (KOMANDO_ACTOR, else the account)
}

Caller is who makes a call.

func CallerFrom

func CallerFrom(lookup func(string) (string, bool), terminal bool) Caller

CallerFrom is the caller an environment lookup describes. terminal says whether a person could answer at a terminal (stdin and stderr are one).

func (Caller) IsAgent

func (c Caller) IsAgent() bool

IsAgent reports an AI agent (or an ssh-gate key) as the caller.

type Kind

type Kind int

Kind is who makes a call.

const (
	// Person: someone at a terminal or in an app.
	Person Kind = iota
	// Script: no person and no AI agent (a cron job, a pipeline).
	Script
	// Agent: an AI agent, or a key through ssh-gate.
	Agent
)

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is the state of one call's approvals: what a person allowed in a window, what they confirmed at a terminal. One answer covers the call, so a call that passes two checks asks once; the next call asks again.

func NewSession

func NewSession() *Session

NewSession is a fresh call's state.

func (*Session) Allowed

func (s *Session) Allowed() bool

Allowed reports a yes in the window, locking by itself.

func (*Session) ApproveSafety

func (s *Session) ApproveSafety(what string)

func (*Session) ConfirmDanger

func (s *Session) ConfirmDanger(key string)

func (*Session) DangerConfirmed

func (s *Session) DangerConfirmed(key string) bool

DangerConfirmed and its setter: a destructive action a person confirmed by typing its name.

func (*Session) GaveUp

func (s *Session) GaveUp() bool

func (*Session) Lock

func (s *Session) Lock()

Lock and Unlock guard a check that reads and then sets the window state.

func (*Session) MarkShown

func (s *Session) MarkShown(what string)

MarkShown records that a window named what.

func (*Session) PersonSaidNo

func (s *Session) PersonSaidNo() bool

PersonSaidNo and its setter: a person answered no at a terminal, so the stop that follows is their decision, not something to retry.

func (*Session) Reset added in v0.14.0

func (s *Session) Reset()

Reset forgets every answer, as NewSession starts: the next command of the call asks again. It locks by itself, so it is safe while other goroutines read the session.

func (*Session) SafetyApproved

func (s *Session) SafetyApproved(what string) bool

SafetyApproved and its setter: a safety change a person allowed.

func (*Session) SaidNo

func (s *Session) SaidNo(no bool)

func (*Session) SetAllowed

func (s *Session) SetAllowed(allowed bool)

func (*Session) SetAsked

func (s *Session) SetAsked(allowed bool)

func (*Session) SetGaveUp

func (s *Session) SetGaveUp(g bool)

func (*Session) SetUnshown

func (s *Session) SetUnshown(why string)

func (*Session) SetWhy

func (s *Session) SetWhy(why string)

func (*Session) Shown

func (s *Session) Shown(what string) bool

Shown reports whether a window already named what.

func (*Session) Unlock

func (s *Session) Unlock()

func (*Session) Window

func (s *Session) Window() Window

type Window

type Window struct {
	Asked, Allowed bool
	Why, Unshown   string
	GaveUp         bool
}

Window is a snapshot of the approval window's state.

Jump to

Keyboard shortcuts

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