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
- func ArgWords(argv []string) []string
- func BuiltinCommand(name string) string
- func BuiltinNames() []string
- func CanTellState(p Provider) bool
- func ClipTarget(s string) string
- func HerdrIntegrationsCurrent(status string) map[string]bool
- func HerdrNeedsIntegration(agent string) bool
- func HerdrTellsIdle(agent string) bool
- func IsBuiltinProvider(name string) bool
- func IsCommit(command string) bool
- func IsDocFile(path string) bool
- func IsTestCommand(command string, extra []*regexp.Regexp) bool
- func LastAnswer(turns []Turn) (string, time.Time)
- func ListedProcess(argv []string) string
- func ListedProcessWith(argv []string, extra map[string]string) string
- func ParseLstart(words []string) time.Time
- func ProcCwd(ctx context.Context, pid int) string
- func ProcLister(keep func(Proc) bool) func() []Proc
- func ProcStart(pid int) time.Time
- func ProcessAlive(pid int) bool
- func ProcessOwner(process string) string
- func ReadOnly(name string, p Provider) string
- func SameDir(a, b string) bool
- func ScanTail(path string, fn func(line []byte)) error
- func StepText(tool, target string) string
- func Target(args map[string]any, keys ...string) string
- func ValidID(id string) bool
- type Activity
- type BackgroundChecker
- type Candidate
- type Checker
- type Facts
- type Factser
- type FileCache
- type Forker
- type Historian
- type HistoryRow
- type Hooker
- type Info
- type Owned
- type Proc
- type Provider
- type Reading
- type Registry
- type SearchHit
- type Session
- type Stamper
- type Stater
- type Step
- type Turn
- type TurnLog
Constants ¶
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.
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.
const ( RoleHuman = "you" RoleAgent = "claude" )
Roles of a Turn, as session.tail sends them. The answer role keeps its wire value for every agent.
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 )
const ClaudeName = "claude"
ClaudeName is Claude Code's harness name: the default harness.
const MaxSteps = 12
MaxSteps caps Activity.Steps.
Variables ¶
This section is empty.
Functions ¶
func ArgWords ¶
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
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 ¶
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 ¶
ClipTarget makes text fit a step's target: its first line, cut.
func HerdrIntegrationsCurrent ¶
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 ¶
HerdrNeedsIntegration reports whether herdr's idle for this agent counts only with herdr's integration for it.
func HerdrTellsIdle ¶
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
IsBuiltinProvider reports a name that a provider of this repo owns.
func IsDocFile ¶ added in v0.2.0
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
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 ¶
LastAnswer is the final message of the newest answer and when it came ("" when the newest answer has no text yet).
func ListedProcess ¶
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
ListedProcessWith is ListedProcess plus the configured process names (process name → agent, [harnesses.<name>] in the config, ADR-0021).
func ParseLstart ¶
ParseLstart reads the five words of `ps -o lstart=` in the C locale. A zero time means it cannot be read.
func ProcLister ¶
ProcLister gives a function that lists the processes keep accepts, each with its folder. It remembers the folders, because lsof is slow.
func ProcStart ¶
ProcStart is when a process started, to the second. A zero time means it cannot be read.
func ProcessAlive ¶
ProcessAlive reports whether a process with this pid exists.
func ProcessOwner ¶ added in v0.2.0
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 ¶
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 ¶
SameDir compares folders after symlinks: lsof reports /private/tmp where an agent may have written /tmp.
func ScanTail ¶
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.
Types ¶
type Activity ¶
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 ¶
Get gives the parse of a session's transcript and when the file changed. ok is false 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 ¶
Owned is a process and the session it owns.
func MatchProcs ¶
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 ¶
Proc is a process that may be an agent's session.
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 ¶
NewRegistry returns a registry with these providers, in this order.
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 ¶
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 ¶
Answer sets the newest answer's message. A newer message replaces it: agents write the same text in more than one record.
func (*TurnLog) Exchange ¶
func (l *TurnLog) Exchange()
Exchange starts a new exchange: the steps so far belong to the old one.
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 hermes is the Hermes Agent provider.
|
Package hermes is the Hermes Agent provider. |
|
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). |