harness

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: MIT Imports: 13 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 is the execution layer: one adapter interface over the harnesses devsys can drive (方案 §9.1/§9.2) plus the shell adapter that runs an arbitrary command with line-level streaming.

The package is pure execution: it knows nothing about .devsys state, runs or events. The application service wires a session's output to the run event stream (方案 §14.2) and to whatever is watching (CLI, dispatch).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Names

func Names() []string

Names lists the harnesses devsys can drive.

Types

type Adapter

type Adapter interface {
	Name() string
	Probe(ctx context.Context) (Availability, error)
	Capabilities() Capabilities
	Prepare(ctx context.Context, ws Workspace) error
	Command(req Request) (Command, error)
	Start(ctx context.Context, cmd Command) (Session, error)
}

Adapter is the unified execution interface of §9.2. The mapping to the spec's method list is:

get_name            -> Name
check_available     -> Probe
get_capabilities    -> Capabilities
prepare_workspace   -> Prepare
build_command       -> Command
start               -> Start (returns a Session)
stream_output       -> Session.Lines
stop                -> Session.Stop
collect_result      -> Session.Wait

func ByName

func ByName(name string) (Adapter, bool)

ByName resolves a harness name to its adapter. The name set is fixed: an unknown name is a caller error, not something to guess at.

func ClaudeCode

func ClaudeCode() Adapter

ClaudeCode drives `claude -p`. The prompt goes to stdin, like codex.

func Codex

func Codex() Adapter

Codex drives codex-cli's non-interactive mode. The prompt goes to stdin (`-`): a full round's brief is far larger than a command line should carry.

func OpenCode

func OpenCode() Adapter

OpenCode drives `opencode run`. It has no stdin entry, so the prompt is the positional argument — a documented length caveat.

type Availability

type Availability struct {
	Installed bool   `json:"installed"`
	Version   string `json:"version,omitempty"`
	Detail    string `json:"detail,omitempty"`
}

Availability is what check_available found on this machine.

type Capabilities

type Capabilities struct {
	NonInteractive bool `json:"supports_non_interactive"`
	JSONOutput     bool `json:"supports_json_output"`
	SessionResume  bool `json:"supports_session_resume"`
	MCP            bool `json:"supports_mcp"`
	Worktree       bool `json:"supports_worktree"`
	Streaming      bool `json:"supports_streaming"`
	ModelSelection bool `json:"supports_model_selection"`
	Approval       bool `json:"supports_approval"`
}

Capabilities is the §9.2 capability probe. A false flag means the caller must not rely on the behaviour; it is not a rejection.

type Command

type Command struct {
	Argv    []string
	Dir     string
	Env     []string
	Timeout time.Duration
	Stdin   []byte
}

Command is the concrete invocation build_command produced: argv plus the directory and environment it must run in.

type Line

type Line struct {
	Stream string // "stdout" or "stderr"
	Text   string
	Time   time.Time
}

Line is one streamed output line (stream_output, §9.2). Text carries no line terminator. Lines longer than the reader's buffer are emitted as several consecutive chunks so no output is dropped.

type Request

type Request struct {
	Command []string
	Dir     string
	Env     []string
	Timeout time.Duration
	// Stdin is fed to the process and then closed. Harness CLIs that read the
	// prompt from stdin use it (方案 §9.3): a prompt is too large to trust to a
	// command line's length limit.
	Stdin     []byte
	Prompt    string
	Model     string
	SessionID string
}

Request is what the caller asks the adapter to execute. Prompt, Model and SessionID are the harness-level knobs of §9.2; the shell adapter ignores them and the real adapters (M6.7) render them into their own command line.

type Result

type Result struct {
	ExitCode  int
	TimedOut  bool
	Canceled  bool
	StartedAt time.Time
	EndedAt   time.Time
	Err       string
}

Result is collect_result (§9.2): how the attempt ended. Err is a spawn or wait failure; a non-zero ExitCode is a normal result, not an error.

func (Result) Duration

func (r Result) Duration() time.Duration

Duration is how long the attempt ran.

type Session

type Session interface {
	// Lines returns the output stream. The channel is closed once the
	// process has exited and every line has been emitted.
	Lines() <-chan Line
	// Wait blocks until the attempt ended and reports its result.
	Wait(ctx context.Context) (Result, error)
	// Stop terminates the attempt and its process tree.
	Stop(ctx context.Context) error
}

Session is one started attempt. Streamed output, stopping and collecting the result live on the session handle rather than on the adapter, so an adapter never holds mutable per-attempt state (the Go shape of §9.2's stream_output / stop / collect_result).

type Shell

type Shell struct{}

Shell runs an arbitrary command as argv, without shell interpretation: to get shell features the caller passes them explicitly ("sh -c …", "cmd /c …"). It is the minimal adapter of §9.3 and the baseline the real harness adapters are measured against.

func NewShell

func NewShell() *Shell

NewShell returns the shell adapter.

func (*Shell) Capabilities

func (s *Shell) Capabilities() Capabilities

Capabilities implements Adapter: the shell runs non-interactively, streams its output and works inside any workspace directory.

func (*Shell) Command

func (s *Shell) Command(req Request) (Command, error)

Command implements Adapter: validate the request and freeze the invocation.

func (*Shell) Name

func (s *Shell) Name() string

Name implements Adapter.

func (*Shell) Prepare

func (s *Shell) Prepare(ctx context.Context, ws Workspace) error

Prepare implements Adapter: the execution directory must exist and be a directory. The workspace invariants of §4.8 (root containment, worktree creation, hooks) arrive with M6.2.

func (*Shell) Probe

func (s *Shell) Probe(ctx context.Context) (Availability, error)

Probe implements Adapter. The shell adapter can always spawn argv, so it is available wherever devsys runs; the report names the host shell it would use for callers that want shell features.

func (*Shell) Start

func (s *Shell) Start(ctx context.Context, cmd Command) (Session, error)

Start implements Adapter: spawn the command, stream both output streams line by line, and terminate the whole process tree on timeout or stop.

type Workspace

type Workspace struct {
	Path     string `json:"path"`
	Branch   string `json:"branch,omitempty"`
	Worktree string `json:"worktree,omitempty"`
}

Workspace is the execution directory a run is bound to (方案 §4.8). M6.1 only checks it exists; M6.2 adds the worktree invariants.

Jump to

Keyboard shortcuts

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