Documentation
¶
Overview ¶
Package harness holds the harness registry (registry.go), recognizes the processes of the coding agents it lists, and connections that come from their process trees (guard.go).
Index ¶
- Variables
- func BatchArgs(id string, argv []string) bool
- func Command(argv []string) string
- func CopilotHome(home string, getenv func(string) string) string
- func IDs() []string
- func Interpreter(n string) bool
- func Known(id string) bool
- func Missing[V any](table map[string]V) []string
- func Name(n string) string
- func Of(name string, argv []string) string
- func PiAgentDir(home string, getenv func(string) string) string
- type Batch
- type Guard
- type Harness
- type Table
Constants ¶
This section is empty.
Variables ¶
var All = []Harness{ { ID: wire.HarnessClaude, Command: "claude", Packages: []string{"@anthropic-ai/claude-code"}, Batch: Batch{Flags: []string{"-p", "--print"}}, TranscriptRoot: func(home string, getenv func(string) string) string { dir := getenv("CLAUDE_CONFIG_DIR") if dir == "" { dir = filepath.Join(home, ".claude") } return filepath.Join(dir, "projects") }, HookHeldForPrompt: true, }, { ID: wire.HarnessCodex, Command: "codex", NativePrefixes: []string{"codex-x86_64-", "codex-aarch64-"}, Packages: []string{"@openai/codex"}, Batch: Batch{Subcommands: []string{"exec", "e"}}, TranscriptRoot: func(home string, getenv func(string) string) string { if dir := getenv("CODEX_HOME"); dir != "" { return dir } return filepath.Join(home, ".codex") }, }, { ID: wire.HarnessOmp, Command: "omp", Packages: []string{"@oh-my-pi/pi-coding-agent"}, Batch: Batch{Flags: []string{"-p", "--print"}, Mode: "--mode", ModeInteractive: "text"}, TranscriptRoot: func(home string, _ func(string) string) string { return filepath.Join(home, ".omp", "agent", "sessions") }, }, { ID: wire.HarnessPi, Command: "pi", Packages: []string{"@earendil-works/pi-coding-agent", "@mariozechner/pi-coding-agent"}, Batch: Batch{ Subcommands: []string{"install", "remove", "uninstall", "update", "list", "config", "auth", "mcp"}, Flags: []string{"-p", "--print", "--no-session"}, Mode: "--mode", ModeInteractive: "text", }, TranscriptRoot: func(home string, getenv func(string) string) string { return filepath.Join(PiAgentDir(home, getenv), "sessions") }, }, { ID: wire.HarnessCopilot, Command: "copilot", Packages: []string{"@github/copilot"}, Batch: Batch{ Subcommands: []string{"login", "help", "init", "config", "update", "version", "workflow", "sessions", "memories", "plugin", "mcp", "skill", "instruction", "lsp", "sandbox", "completion", "app"}, Flags: []string{"-p", "--prompt", "--acp"}, Prefixes: []string{"--prompt="}, }, TranscriptRoot: func(home string, getenv func(string) string) string { return filepath.Join(CopilotHome(home, getenv), "session-state") }, }, }
All is the registry.
Functions ¶
func BatchArgs ¶ added in v0.15.0
BatchArgs reports whether a command line of harness id (argv[0] first) asks for a non-interactive run, by the rule the shell wrapper applies. Every argument is looked at for flags and the mode: omp runs under its JavaScript runtime, its script first.
func Command ¶ added in v0.15.0
Command maps a command line to the harness its program is, wire.HarnessOther for other programs. For a task's prepared session it is the command `stagent task run` ends in (wire.AgentArgv).
func CopilotHome ¶ added in v0.16.0
CopilotHome is Copilot CLI's configuration directory (hooks, sessions): $COPILOT_HOME, else ~/.copilot.
func Interpreter ¶
Interpreter reports whether n (a ptable.BaseName) is a script interpreter an agent may run under.
func Missing ¶ added in v0.15.0
Missing lists, in the order of All, the ids of the harnesses a per-harness table keyed by harness id has no entry for. Each package's test that its table covers the registry checks it is empty.
func Name ¶
Name returns the harness a program called n (a ptable.BaseName) is, "" for other programs. It is the one judgement of which harness a program is: Of and Command build on it.
Types ¶
type Batch ¶ added in v0.15.0
type Batch struct {
// Subcommands: the first argument is one of them (codex exec).
Subcommands []string
// Flags: any argument is one of them (claude -p).
Flags []string
// Prefixes: any argument starts with one of them (copilot
// --prompt=…).
Prefixes []string
// Mode is an option whose value other than ModeInteractive asks for a
// non-interactive run, given as `Mode value` or `Mode=value` (omp
// --mode json).
Mode, ModeInteractive string
}
Batch describes the arguments that make a harness run without its terminal UI. The shell wrapper leaves those runs alone, and hooks from them are not counted as launches the app misses.
type Guard ¶
type Guard struct {
// PeerPID returns the pid of the process that connected c.
PeerPID func(c net.Conn) (int, error)
Table Table
// Sandboxed tells whether pid runs in a macOS sandbox (nil: not
// asked). Seatbelt has no PID namespace, so a sandboxed command that
// double forks leaves the agent's tree but stays sandboxed.
Sandboxed func(pid int) bool
}
Guard tells whether a connection comes from a coding agent's process tree, which stagent refuses (ADR 0004): with a sandboxed agent's commands approved without asking, the agent could otherwise type approvals into its own session or commands into another one outside its sandbox.
func NewGuard ¶
NewGuard returns the guard of the stagent location l: nil, which refuses nothing, when l is isolated (STAGENT_HOME: tests and development, which run under agents) and on Windows, which keeps the parent pid of a process whose parent exited, so parents cannot be told reliably. The receiving side decides with its own layout, so a client cannot opt out.
type Harness ¶ added in v0.15.0
type Harness struct {
// ID is the harness id on the wire (wire.Session.Harness) and the
// integration target id of `stagent integrate --harness / --remove`.
ID string
// Command is the program the user runs: what the shell wrapper wraps,
// what doctor looks for, and the process name the agent runs as.
Command string
// NativePrefixes are process names of native binaries the npm package
// runs under another name (codex-<target triple>).
NativePrefixes []string
// Packages are the npm packages (current name first), for launchers
// that run its script by path (Claude Code's cli.js).
Packages []string
// Batch is how a command line asks for a non-interactive run.
Batch Batch
// TranscriptRoot is the directory the harness keeps its conversations
// in, for a home directory and the environment the harness runs with.
TranscriptRoot func(home string, getenv func(string) string) string
// HookHeldForPrompt: the harness shows its permission prompt while its
// PermissionRequest hook runs, so the hook may wait until the prompt
// is answered (Codex shows its prompt only once the hook returned).
HookHeldForPrompt bool
}
Harness is one entry of the registry.
type Table ¶
type Table struct {
Process func(pid int) (ptable.Proc, bool)
Argv func(pid int) ([]string, error)
}
Table reads single processes; ptable.Process and ptable.Argv on a real host.
func (Table) Agent ¶
Agent returns the harness that pid is, or that is one of its ancestors ("" when there is none). It fails when that cannot be told: pid exited, its ancestry is deeper than maxAncestry, or kept changing.
An ancestor that cannot be read while its child is still there with the same parent ends the walk: it runs as another user, or is hidden like one (Linux's hidepid), and an agent runs as stagent's user — the only user ipc lets connect. When the child is gone or has a new parent instead, an ancestor exited meanwhile, and the walk starts again from pid along the new parents (up to a sandbox's subreaper).