harness

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 16 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 layer between the daemon and each coding agent's own files (ADR-0019). A Provider in internal/harness/<name> holds what is specific to one agent. Required: Info, Discover and Read. Optional, each a small interface of its own: Stater, Hooker, Forker, plus Stamper, Checker, BackgroundChecker, Factser and Historian. The daemon knows only this package and asks the Registry.

Index

Constants

View Source
const (
	TestsPassed = "passed"
	TestsFailed = "failed"
	TestsNone   = "none" // no test command finished after that edit
)

Facts.Tests values. They speak only of the time after the last edit of a non-doc file.

View Source
const (
	LevelFull   = "full"
	LevelHerdr  = "herdr"
	LevelListed = "listed"
)

Support levels of a session (ADR-0019). A session at the herdr or listed level has no provider behind it: only a scan of herdr or of the process table found it.

View Source
const (
	RoleHuman = "you"
	RoleAgent = "claude"
)

Roles of a Turn, as session.tail sends them. The answer role keeps its wire value for every agent.

View Source
const (
	// TailBytes is how much of a transcript's end a provider reads.
	TailBytes = 2 << 20
	// MaxTurnRunes caps the text of one turn.
	MaxTurnRunes = 6000
	// MaxTargetRunes caps a step's target.
	MaxTargetRunes = 300
)
View Source
const ClaudeName = "claude"

ClaudeName is Claude Code's harness name: the default harness.

View Source
const MaxSteps = 12

MaxSteps caps Activity.Steps.

Variables

This section is empty.

Functions

func ArgWords

func ArgWords(argv []string) []string

ArgWords are argv's words that are no flag, after the program and any wrapper's script. A flag's value counts as a word.

func BuiltinCommand added in v0.2.0

func BuiltinCommand(name string) string

BuiltinCommand is the program that starts a built-in agent ("" = none).

func BuiltinNames added in v0.2.0

func BuiltinNames() []string

BuiltinNames are the agents of the built-in table, sorted, Claude Code left out.

func CanTellState

func CanTellState(p Provider) bool

CanTellState reports whether the provider has a state source: its own or the hooks. Without one a session's state is unknown, never idle.

func ClipTarget

func ClipTarget(s string) string

ClipTarget makes text fit a step's target: its first line, cut.

func HerdrIntegrationsCurrent

func HerdrIntegrationsCurrent(status string) map[string]bool

HerdrIntegrationsCurrent reads the output of `herdr integration status` and names the agents whose integration is current. Each line reads "<agent>: <state> (<path>)", with the state `not installed`, `current (v9)`, `outdated (legacy < v9)` or `needs repair (...)` (herdr 0.9.5, docs/compat.md).

Only current counts. A file with no herdr code at the right path reads outdated, so outdated does not prove a working integration, and any other line is an answer smif cannot read: the agent stays out of the result.

func HerdrNeedsIntegration

func HerdrNeedsIntegration(agent string) bool

HerdrNeedsIntegration reports whether herdr's idle for this agent counts only with herdr's integration for it.

func HerdrTellsIdle

func HerdrTellsIdle(agent string) bool

HerdrTellsIdle reports whether herdr can tell idle from a dialog for this agent. Where it cannot, herdr's idle and done are unknown, never idle.

func IsBuiltinProvider added in v0.2.0

func IsBuiltinProvider(name string) bool

IsBuiltinProvider reports a name that a provider of this repo owns.

func IsCommit added in v0.2.0

func IsCommit(command string) bool

IsCommit reports a shell command that runs git commit.

func IsDocFile added in v0.2.0

func IsDocFile(path string) bool

IsDocFile reports a file whose edit needs no new test run: .md, .txt, or anything under a docs folder.

func IsTestCommand added in v0.2.0

func IsTestCommand(command string, extra []*regexp.Regexp) bool

IsTestCommand reports a shell command that runs tests: a built-in pattern outside quotes, or one of extra (daemon.test_commands) anywhere in the command.

func LastAnswer

func LastAnswer(turns []Turn) (string, time.Time)

LastAnswer is the final message of the newest answer and when it came ("" when the newest answer has no text yet).

func ListedProcess

func ListedProcess(argv []string) string

ListedProcess names the agent a process runs ("" = none), from its argv. argv[0] counts first (it is what the agent calls itself); under a node, bun, python or sh wrapper the script counts.

func ListedProcessWith added in v0.2.0

func ListedProcessWith(argv []string, extra map[string]string) string

ListedProcessWith is ListedProcess plus the configured process names (process name → agent, [harnesses.<name>] in the config, ADR-0021).

func ParseLstart

func ParseLstart(words []string) time.Time

ParseLstart reads the five words of `ps -o lstart=` in the C locale. A zero time means it cannot be read.

func ProcCwd

func ProcCwd(ctx context.Context, pid int) string

ProcCwd is a process's working folder ("" when it cannot be read).

func ProcLister

func ProcLister(keep func(Proc) bool) func() []Proc

ProcLister gives a function that lists the processes keep accepts, each with its folder. It remembers the folders, because lsof is slow.

func ProcStart

func ProcStart(pid int) time.Time

ProcStart is when a process started, to the second. A zero time means it cannot be read.

func ProcessAlive

func ProcessAlive(pid int) bool

ProcessAlive reports whether a process with this pid exists.

func ProcessOwner added in v0.2.0

func ProcessOwner(process string) string

ProcessOwner names the built-in agent that owns a process name ("" = none). claude counts here: a process table entry never makes a Claude Code row, because a `claude -p` run is no session.

func ReadOnly

func ReadOnly(name string, p Provider) string

ReadOnly says why smif must neither type into nor fork a session of this provider ("" = it may). p is nil when no provider has the session's harness name.

func SameDir

func SameDir(a, b string) bool

SameDir compares folders after symlinks: lsof reports /private/tmp where an agent may have written /tmp.

func ScanTail

func ScanTail(path string, fn func(line []byte)) error

ScanTail calls fn for each JSON line in the last TailBytes of a file. A line that starts before the cut is left out. The line slice is valid only during the call.

func StepText

func StepText(tool, target string) string

StepText is a step in words: "Bash: git push origin main", a question as itself.

func Target

func Target(args map[string]any, keys ...string) string

Target is what a tool call works on: the first of keys that holds text, on one line.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a session id: providers build paths from it.

Types

type Activity

type Activity struct {
	Prompt   string
	PromptAt time.Time
	Tools    int
	Steps    []Step
	Pending  *Step
}

Activity is what the newest exchange is doing: the human's prompt it answers and the tool calls since, oldest first (the last MaxSteps). Pending is the oldest call without a result: the tool that runs now, or the permission or question a waiting session shows in its tab.

type BackgroundChecker added in v0.2.0

type BackgroundChecker interface {
	CheckBackground() (state, detail string)
}

BackgroundChecker is a provider with a list of background sessions. The list is not a documented interface, so its state is news, never a failure (smif doctor). State is ok, none or changed.

type Candidate

type Candidate struct {
	ID      string
	Cwd     string
	Path    string // the transcript, for an agent that keeps files
	Name    string
	Created time.Time
	Wrote   time.Time
}

Candidate is a session that a process can own, for an agent that keeps no file to link a pid to a session.

type Checker

type Checker interface {
	Check() (state, detail string)
}

Checker is a provider that checks that the agent's files still have the shape it reads (smif doctor). State is ok, none or changed.

type Facts added in v0.2.0

type Facts struct {
	Files         int    // distinct files that edit tools changed
	Commits       int    // Bash calls with git commit that succeeded
	Tests         string // TestsPassed, TestsFailed, TestsNone, or "" with no edit of a non-doc file
	ContextTokens int64  // input + cache read + cache creation of the newest assistant record
}

Facts is what a transcript shows from the newest human prompt on (ADR-0021). The UI states these facts and does not judge the answer.

type Factser added in v0.2.0

type Factser interface {
	Facts(sessionID string, isTest func(command string) bool) (f Facts, ok bool)
}

Factser is a provider that reads Facts from a session's transcript. It reads only what the transcript added since the last call, so a call on an unchanged transcript parses nothing. isTest says whether a shell command is a test command; nil means the built-in list. ok is false with no transcript.

type FileCache

type FileCache[T any] struct {
	Find  func(sessionID string) string // the transcript, "" for none
	Parse func(path string) T
	// contains filtered or unexported fields
}

FileCache remembers where each session's transcript is and what one parse of it gave, so session.list parses a transcript only when it changed. A missing transcript is looked for at most every 30 s.

func (*FileCache[T]) Get

func (c *FileCache[T]) Get(sessionID string) (value T, wrote time.Time, ok bool)

Get gives the parse of a session's transcript and when the file changed. ok is false with no transcript.

func (*FileCache[T]) Remember

func (c *FileCache[T]) Remember(sessionID, path string)

Remember sets a session's transcript, when discovery already found it.

func (*FileCache[T]) Stamp

func (c *FileCache[T]) Stamp(sessionID string) string

Stamp is the transcript's path, size and time, "" with no transcript.

type Forker

type Forker interface {
	// ForkDir is the folder the copy must start in, for a session in cwd
	// under repo.
	ForkDir(cwd, repo string) string
}

Forker is a provider with a route that asks a copy of a session and leaves the source unchanged (ADR-0013). A provider without one has no side questions.

type Historian added in v0.2.0

type Historian interface {
	// History returns the past sessions, newest first.
	History() []HistoryRow
	// Search looks through the text of user and assistant records, newest
	// file first. It stops at limit hits and when ctx ends.
	Search(ctx context.Context, query string, limit int) []SearchHit
}

Historian is a provider that can list and search its past sessions.

type HistoryRow added in v0.2.0

type HistoryRow struct {
	SessionID string
	Dir       string    // the folder the session started in
	Name      string    // its title, else its first prompt, on one line
	At        time.Time // its last user or assistant record
}

HistoryRow is one past session of a provider (ADR-0021).

type Hooker

type Hooker interface {
	HookEvents() []string
}

Hooker is a provider whose agent reports turns through `smif hook`.

type Info

type Info struct {
	Name string // the session's harness: "claude"
	// Process is the agent's process name. The foreground check before
	// typing (ADR-0012) wants a process whose name contains it.
	Process string
	// Verified is true when a real session checked the provider and
	// docs/compat.md has a row with that version. The zero value is the
	// safe one: an unverified provider only shows sessions (ADR-0019).
	Verified bool
}

Info is what the daemon must know about a provider.

type Owned

type Owned struct {
	Proc    Proc
	Session Candidate
}

Owned is a process and the session it owns.

func MatchProcs

func MatchProcs(procs []Proc, found []Candidate, named func(Proc) string) []Owned

MatchProcs ties processes to sessions. A process that names a session in argv (named, may be nil) owns it. Each other process owns the session in its folder that was written since it started, newest process to newest session, which can swap two processes in one folder when the newer one resumed an older session. A process with no session gets no match.

type Proc

type Proc struct {
	PID   int
	TTY   string
	Argv  []string
	Start time.Time
	Cwd   string
}

Proc is a process that may be an agent's session.

func ParsePS

func ParsePS(out string) []Proc

ParsePS reads `ps -ax -o pid=,tty=,lstart=,args=` in the C locale.

func ProcLook

func ProcLook(pid int) (p Proc, ok bool)

ProcLook reads one process with ps: its terminal, start and argv. ok is false when it cannot be read. Cwd stays empty.

type Provider

type Provider interface {
	Info() Info
	// Discover returns the live sessions: the interactive ones whose
	// process lives, and a provider's background sessions. The daemon calls
	// it under the status line, so it must not wait for a slow command.
	Discover() []Session
	// Read reads the last limit turns of a session. An unknown session
	// gives a Reading with OK false.
	Read(sessionID string, limit int) Reading
}

Provider is one agent. Read is on demand, so it may be slow; session.list runs on every UI refresh, so give a slow provider a Stamper.

type Reading

type Reading struct {
	Turns    []Turn   // the last turns, oldest first
	Activity Activity // what the newest exchange does now
	WroteAt  time.Time
	OK       bool // the session's source was there and was read
}

Reading is what a provider read of one session.

type Registry

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

Registry holds the providers. Register them before the daemon serves.

func NewRegistry

func NewRegistry(ps ...Provider) *Registry

NewRegistry returns a registry with these providers, in this order.

func (*Registry) All

func (r *Registry) All() []Provider

All returns the providers in order.

func (*Registry) Discover

func (r *Registry) Discover() []Session

Discover returns every provider's live sessions, each with its harness.

func (*Registry) Get

func (r *Registry) Get(name string) Provider

Get returns the provider with that name, or nil.

func (*Registry) Read

func (r *Registry) Read(sessionID string, limit int) Reading

Read asks the providers in order for a session: a session id alone does not say which agent wrote it, and an ended session has no live row.

func (*Registry) Register

func (r *Registry) Register(p Provider)

Register adds a provider, or replaces the one with its name.

type SearchHit added in v0.2.0

type SearchHit struct {
	HistoryRow
	Role string // RoleHuman or RoleAgent
	Text string // the words with some text around them, on one line

}

SearchHit is one record whose text holds the words searched for.

type Session

type Session struct {
	Harness   string // the provider's name (Registry.Discover sets it)
	PID       int
	SessionID string
	Cwd       string
	Name      string
	StartedAt int64     // process start, ms: with PID it names one process
	Status    string    // the agent's own word for its state, for Stater
	StatusAt  time.Time // when the agent wrote Status
	// AttachID marks a background session (ADR-0021): the id `claude attach`
	// takes. A background session has no tab, so Smif never types into it.
	AttachID string
	// EndedAt is set when a background session finished: its last answer,
	// else its start. LastAnswerAt is zero when it never answered.
	EndedAt, LastAnswerAt time.Time
}

Session is one live session a provider found.

type Stamper

type Stamper interface {
	Stamp(sessionID string) string
}

Stamper is a provider with a cheap check for change: the stamp differs when Read would give something new, and "" means no source yet. Without one the daemon reads on every session.list.

type Stater

type Stater interface {
	// State maps a discovered session to a turn: idle, busy, waiting, or
	// "" when its source says nothing. Return "" when the source cannot
	// tell a pending approval from idle: smif does not type then.
	State(s Session) (turn string, at time.Time)
}

Stater is a provider that can say what a session does.

type Step

type Step struct {
	ID     string    `json:"-"`
	Tool   string    `json:"tool"`
	Target string    `json:"target,omitempty"`
	At     time.Time `json:"at"`
	Done   bool      `json:"done"`
}

Step is one tool call of the newest answer: the tool, what it works on (a command, a file, a question) and whether its result came back.

type Turn

type Turn struct {
	Role  string    `json:"role"`
	Text  string    `json:"text"`
	At    time.Time `json:"at"`
	Tools int       `json:"tools,omitempty"`
}

Turn is one step of a session's conversation: the human's prompt (RoleHuman) or the agent's answer (RoleAgent). An answer holds only its final message ("" while it still works) and counts its tool calls.

type TurnLog

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

TurnLog builds turns and the activity while a provider walks a transcript, oldest record first. An answer holds only its final message: a tool call drops the text before it.

func (*TurnLog) Answer

func (l *TurnLog) Answer(text string, at time.Time)

Answer sets the newest answer's message. A newer message replaces it: agents write the same text in more than one record.

func (*TurnLog) Call

func (l *TurnLog) Call(s Step)

Call adds a tool call to the newest answer. s.ID ties it to its result.

func (*TurnLog) Done

func (l *TurnLog) Done(id string)

Done marks a tool call's result.

func (*TurnLog) Exchange

func (l *TurnLog) Exchange()

Exchange starts a new exchange: the steps so far belong to the old one.

func (*TurnLog) Human

func (l *TurnLog) Human(text string, at time.Time)

Human adds the human's prompt. The same text right after the same prompt is one prompt: some agents record it twice.

func (*TurnLog) Result

func (l *TurnLog) Result(limit int) ([]Turn, Activity)

Result gives the last limit turns and the newest exchange's activity.

Directories

Path Synopsis
Package claude is the Claude Code provider (ADR-0019): session files, transcripts, the file status, the fork route, the process name and the history of past sessions (history.go, ADR-0021).
Package claude is the Claude Code provider (ADR-0019): session files, transcripts, the file status, the fork route, the process name and the history of past sessions (history.go, ADR-0021).
Package codex is the Codex CLI provider (ADR-0019).
Package codex is the Codex CLI provider (ADR-0019).
Package copilot is the GitHub Copilot CLI provider (ADR-0019).
Package copilot is the GitHub Copilot CLI provider (ADR-0019).
Package droid is the Factory Droid provider (ADR-0019).
Package droid is the Factory Droid provider (ADR-0019).
Package opencode is the OpenCode V2 provider (ADR-0019).
Package opencode is the OpenCode V2 provider (ADR-0019).
Package qwen is the Qwen Code provider (ADR-0019).
Package qwen is the Qwen Code provider (ADR-0019).

Jump to

Keyboard shortcuts

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