harness

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 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 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

Constants

This section is empty.

Variables

View Source
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, _ := ClaudeConfigDir(home, getenv)
			return filepath.Join(dir, "projects")
		},
		HookHeldForPrompt: true,
		QuestionTool:      "AskUserQuestion",
		Resume:            func(id string) []string { return []string{"--resume", id} },
	},
	{
		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")
		},
		QuestionTool: "request_user_input",
		Resume:       func(id string) []string { return []string{"resume", id} },
	},
	{
		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")
		},
		QuestionTool: "ask",
		Resume:       func(id string) []string { return []string{"--resume", id} },
	},
	{
		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")
		},
		Resume: func(id string) []string { return []string{"--session", id} },
	},
	{
		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")
		},
		Resume: func(id string) []string { return []string{"--resume=" + id} },
	},
	{
		ID:      wire.HarnessQwen,
		Command: "qwen",

		Packages: []string{"@qwen-code/qwen-code"},

		Batch: Batch{
			Subcommands: []string{"agents", "attach", "autofix-pr", "auth", "batch", "board", "channel", "extensions", "hooks", "mcp", "memory", "review", "sandbox", "serve", "daemon", "sessions", "update"},
			Flags:       []string{"-p", "--prompt", "--acp", "-o", "--output-format"},
			Prefixes:    []string{"--prompt=", "--output-format="},
			Prompt:      true,

			Values: []string{
				"-m", "--model", "--advisor", "--workflow-mode", "--fallback-model",
				"--system-prompt", "--append-system-prompt", "--output-style",
				"-s", "--sandbox", "--sandbox-image", "--approval-mode", "--channel",
				"--allowed-mcp-server-names", "--disable-mcp-server", "--mcp-config",
				"--allowed-tools", "-e", "--extensions", "--include-directories", "--add-dir",
				"--openai-logging-dir", "--openai-api-key", "--openai-base-url", "--input-format",
				"--json-fd", "--json-file", "--json-schema", "--input-file",
				"-r", "--resume", "--session-id", "--worktree",
				"--max-session-turns", "--max-wall-time", "--max-tool-calls", "--max-subagent-depth",
				"--core-tools", "--exclude-tools", "--disabled-slash-commands", "--auth-type",
				"--proxy", "--telemetry-target", "--telemetry-otlp-endpoint",
				"--telemetry-otlp-protocol", "--telemetry-outfile",
			},
			Interactive: []string{"-i", "--prompt-interactive"},
		},
		TranscriptRoot: func(home string, getenv func(string) string) string {
			return filepath.Join(QwenRuntimeDir(home, getenv), "projects")
		},
		QuestionTool: "ask_user_question",
		Resume:       func(id string) []string { return []string{"--resume", id} },
	},
	{
		ID:      wire.HarnessOpenCode,
		Command: "opencode",

		Packages: []string{"@opencode/cli"},

		Batch: Batch{
			Subcommands: []string{"run", "serve", "service", "session", "api", "debug", "auth", "mcp", "plugin", "models", "stats", "upgrade", "update", "uninstall", "acp", "reload", "pair", "mini"},
			Flags:       []string{"-h", "--help", "-v", "--version", "--completions"},
			Prefixes:    []string{"--completions="},
		},

		TranscriptRoot: func(home string, getenv func(string) string) string {
			if dir := getenv("STAGENT_HOME"); dir != "" {
				home = dir
			}
			return filepath.Join(home, ".ssh-term", "agent", "state", "opencode")
		},
		QuestionTool: "question",

		Resume: func(id string) []string { return []string{"--standalone", "--session", id} },
	},
	{
		ID:      wire.HarnessGrok,
		Command: "grok",

		NativePrefixes: []string{"grok-macos-", "grok-linux-", "grok-windows-"},

		Batch: Batch{
			Subcommands: []string{
				"agent", "clone", "completions", "doctor", "du", "disk-usage", "export", "help",
				"inspect", "leader", "login", "logout", "mcp", "memory", "models", "plugin",
				"sessions", "setup", "trace", "update", "usage", "version", "v", "worker",
				"worktree", "wrap",
			},
			Flags:    []string{"-p", "--single", "--prompt-file", "--prompt-json", "-h", "--help", "-v", "--version"},
			Prefixes: []string{"--single=", "--prompt-file=", "--prompt-json="},
		},

		TranscriptRoot: func(home string, getenv func(string) string) string {
			return filepath.Join(GrokHome(home, getenv), "sessions")
		},
		QuestionTool: "ask_user_question",
		Resume:       func(id string) []string { return []string{"--resume", id} },
	},
}

All is the registry.

Functions

func BatchArgs added in v0.15.0

func BatchArgs(id string, argv []string) bool

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. A harness run by its JavaScript runtime (claude or qwen under node, omp under bun) is judged by the arguments after its script — the first argument that is not an option, as Of finds it: the runtime's own options before it are not the harness's.

func ClaudeConfigDir added in v0.19.0

func ClaudeConfigDir(home string, getenv func(string) string) (dir, env string)

ClaudeConfigDir is the directory Claude Code keeps its files in, the account its limit windows are kept under: $CLAUDE_CONFIG_DIR as a clean path, else ~/.claude. env is the variable as set ("" when unset), which names Claude Code's Keychain item (usage.KeychainService).

func Command added in v0.15.0

func Command(argv []string) string

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

func CopilotHome(home string, getenv func(string) string) string

CopilotHome is Copilot CLI's configuration directory (hooks, sessions): $COPILOT_HOME, else ~/.copilot.

func GrokHome added in v0.22.0

func GrokHome(home string, getenv func(string) string) string

GrokHome is Grok Build's directory (hooks, sessions): $GROK_HOME, else ~/.grok.

func IDs added in v0.15.0

func IDs() []string

IDs lists the ids of All, in its order.

func Interpreter

func Interpreter(n string) bool

Interpreter reports whether n (a ptable.BaseName) is a script interpreter an agent may run under.

func Known added in v0.15.0

func Known(id string) bool

Known reports whether id is a harness of the registry.

func Missing added in v0.15.0

func Missing[V any](table map[string]V) []string

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

func Name(n string) string

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.

func Of

func Of(name string, argv []string) string

Of recognizes an agent by its process name, its argv[0] (native binaries, and scripts that set their process title) or the script an interpreter runs; "" for other processes.

func PiAgentDir added in v0.16.0

func PiAgentDir(home string, getenv func(string) string) string

PiAgentDir is Pi's agent directory (extensions, sessions): $PI_CODING_AGENT_DIR, with a leading ~ expanded as Pi does, else ~/.pi/agent.

func QuestionToolOf added in v0.20.0

func QuestionToolOf(id string) string

QuestionToolOf is the question tool of harness id ("" when it has none).

func QwenHome added in v0.22.0

func QwenHome(home string, getenv func(string) string) string

QwenHome is Qwen Code's directory (settings, extensions): $QWEN_HOME, with a leading ~ expanded as Qwen Code does, else ~/.qwen.

func QwenRuntimeDir added in v0.22.0

func QwenRuntimeDir(home string, getenv func(string) string) string

QwenRuntimeDir is where Qwen Code records its conversations (projects/<cwd>/chats/<session id>.jsonl): $QWEN_RUNTIME_DIR, with ~ expanded, else QwenHome. Its setting advanced.runtimeOutputDir moves it too; that is not read here (the hooks name the conversation's file).

func ResumeArgv added in v0.21.0

func ResumeArgv(id, conv string) ([]string, bool)

ResumeArgv is the command line that continues conversation conv of harness id (its Command first); false for an unknown harness.

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
	// Prompt: a positional argument — neither an option nor the value of
	// one of Values or Interactive — is a prompt the harness runs once
	// without its terminal UI (qwen "fix it"), unless one of Interactive
	// is given too. After `--` every argument is positional.
	Prompt bool
	// Values are the options that take the next argument as their value.
	Values []string
	// Interactive are the options that take a prompt (the next argument,
	// or after `=`) and run it in the terminal UI (qwen -i "fix it").
	Interactive []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

func NewGuard(l *paths.Layout) *Guard

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.

func (*Guard) Check

func (g *Guard) Check(c net.Conn) *wire.Error

Check returns nil when c may be served, else the agent_refused error to answer its requests with. A connection whose process cannot be read any more is refused too: a process could otherwise hand its socket to a child and exit before it is checked.

func (*Guard) CheckPID

func (g *Guard) CheckPID(pid int) *wire.Error

CheckPID is Check for the process pid: the bridge asks it of itself before it starts a holder that would refuse its connection.

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>), or the program is
	// a link to (grok-<os>-<arch>).
	NativePrefixes []string
	// Packages are the npm packages (current name first), for launchers
	// that run its script by path (Claude Code's cli.js); none for a
	// harness that ships a native binary only.
	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
	// QuestionTool is the tool through which the harness asks the user a
	// choice question ("" when it has none): its hooks and transcript rows
	// naming it are a question (PROTOCOL.md "Questions").
	QuestionTool string
	// Resume is the arguments after Command that continue conversation id
	// in the terminal UI: what the app's resumeCommand runs and what
	// stopped.resume starts (ResumeArgv).
	Resume func(id string) []string
}

Harness is one entry of the registry.

func Lookup added in v0.15.0

func Lookup(id string) (Harness, bool)

Lookup returns the entry of id.

func QuestionToolHarness added in v0.20.0

func QuestionToolHarness(tool, id string) (Harness, bool)

QuestionToolHarness returns the harness whose question tool is tool: harness id when tool is its question tool (Qwen Code and Grok Build both call theirs ask_user_question), else the first of All whose it is.

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

func (t Table) Agent(pid int) (string, error)

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).

Jump to

Keyboard shortcuts

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