Documentation
¶
Overview ¶
Package hostcompat reports golder's state to a terminal multiplexer that tracks coding agents — tuios and herdr — so golder shows up beside claude, codex and the rest without either project shipping an integration for it.
Both hosts accept a report from the agent itself, through a small contract neither project has to change:
- tuios takes `tuios set-agent-state`, an ordinary control-protocol verb. A pane finds the daemon through TUIOS_SOCKET and names itself through TUIOS_PANE_ID; the state names one of tuios's seven (none, working, needs_input, idle, done, errored, unknown). Being *recognised* as an agent at all is the one thing a report cannot do on its own: that needs a harness manifest, a file, which this package ships and installs (see install.go).
- herdr takes `$HERDR_BIN_PATH pane report-agent`. No file: the report names the agent, so it is identified by reporting. State is one of four (working, blocked, idle, unknown) and a resume command rides the report.
The two vocabularies and the two command lines differ, so this package speaks one neutral vocabulary (State) and translates per host. It is a leaf package: standard library only, no golder imports, so a driver can hold a *Reporter without dragging anything into the call graph.
Everything is optional and silent. Outside a host pane Open returns nil, a nil *Reporter answers every call as a no-op, and a report that fails (the host is gone, the binary is missing) is dropped: the person's agent must never wait on, or break over, bookkeeping for the terminal around it.
Index ¶
- Constants
- func ContextMeta(tokens, window int) map[string]string
- func Detect(getenv func(string) string) string
- func ManifestPath(getenv func(string) string) string
- func ManifestSource() string
- func ResumeArgv(id string) []string
- func Uninstall(getenv func(string) string) (path string, removed bool, err error)
- func ValidSessionID(id string) bool
- type Host
- type InstallResult
- type Kind
- type ManifestState
- type Options
- type Report
- type Reporter
- func (r *Reporter) Blocked(kind Kind, message string)
- func (r *Reporter) Close()
- func (r *Reporter) Done(message string)
- func (r *Reporter) HostName() string
- func (r *Reporter) Meta(kv map[string]string)
- func (r *Reporter) Release()
- func (r *Reporter) Session(id string, argv []string)
- func (r *Reporter) State(s State, kind Kind, message string)
- func (r *Reporter) Working(message string)
- type Session
- func (s *Session) Block(kind Kind, message string) func()
- func (s *Session) Close()
- func (s *Session) Conversation(id string, resumeArgv []string)
- func (s *Session) HostName() string
- func (s *Session) Meta(kv map[string]string)
- func (s *Session) Reporter() *Reporter
- func (s *Session) Start(id string, resumeArgv []string)
- func (s *Session) TurnEnd(failed bool)
- func (s *Session) TurnStart()
- type SessionRef
- type State
Constants ¶
const DefaultTimeout = 1500 * time.Millisecond
DefaultTimeout bounds one report. A host call is bookkeeping on the side of the person's real work, so it is given long enough to reach a local socket and no longer.
const EnvHostReport = "GOLDER_HOST_REPORT"
EnvHostReport is the escape hatch: "off" disables reporting everywhere, "tuios" or "herdr" forces one host (which is how a person works around a pane that looks like both, or tests a host from inside another).
const Harness = "golder"
Harness is the id golder reports itself under, everywhere: it is the harness manifest's id for tuios, and the agent label herdr shows beside the pane.
const ManifestVersion = 4
ManifestVersion goes up whenever the shipped manifest changes in a way an installed copy has to be replaced to get — a new rule, a reworded one. A status check compares it with the marker in the installed file.
1: the first manifest: golder's detection, its tool approval dialog, the launch-time trust picker, the idle and working rules, and the resume command. 2: the two prompts that were still answerable only at the pane — the read-outside-the-workspace question and the mid-run trust question. 3: the trust picker's rows were rekeyed onto the ladder every other dialog uses (y once, p this session, s saved). The picker used to give p the REMEMBERED meaning while the tool dialog used it for this session, so the same key wrote a permission to disk in one dialog and only tried it out in another. Its screen rule changed with the words. 4: a write outside the workspace became a question. apply_patch used to be refused outright with no consent path, so only the read question had a rule; now the same three answers exist for a write, and the dialog says "write" where it used to say "read".
const MetaContext = "context"
MetaContext is the metadata key holding how full the context window is, as a percentage.
const MetaModel = "model"
MetaModel is the metadata key holding the model's name.
Variables ¶
This section is empty.
Functions ¶
func ContextMeta ¶
ContextMeta renders a context reading for Session.Meta: the percentage both hosts show, and nothing when the window is unknown.
func Detect ¶
Detect names the host multiplexer this process runs inside, or "" when it runs in a plain terminal. It reads the environment only, so it is safe to call from anywhere.
A pane inside both is a tuios pane whose parent mentioned herdr (tuios does not pass herdr's variables on, so this should not happen); tuios wins, and GOLDER_HOST_REPORT can settle it by hand.
func ManifestPath ¶
ManifestPath is where tuios reads a user manifest from, as this machine has it configured: $TUIOS_HARNESS_DIR when set, else $XDG_CONFIG_HOME or $HOME. It mirrors internal/harness's UserDir in tuios, which is the only authority on the answer.
func ManifestSource ¶
func ManifestSource() string
ManifestSource returns the manifest as golder ships it.
func ResumeArgv ¶
ResumeArgv is the command that reopens a golder session. It is what herdr types into a restored pane; tuios builds the same command from the harness manifest's [resume] block, so the two stay in step through this function and that file.
The id is checked here rather than trusted: it arrives from the session store, and the command is typed at a shell.
func Uninstall ¶
Uninstall removes golder's manifest, and only golder's: the marker has to be in the file. It reports whether anything was removed.
func ValidSessionID ¶
ValidSessionID reports whether a session id may be reported: the hosts put it on a command line (tuios types a resume command from it, herdr holds it to its own rules), so it is restricted to what every shell and both hosts read as one plain token.
Types ¶
type Host ¶
type Host interface {
// Name is the host's id, "tuios" or "herdr".
Name() string
// Apply sends one state report, with the pane's conversation attached when
// one is known.
Apply(ctx context.Context, r Report, sess SessionRef) error
// ApplyMeta sends display metadata (model, context use, task summary).
// A host that cannot show metadata reports no error and does nothing.
ApplyMeta(ctx context.Context, kv map[string]string) error
// Release clears the pane's agent, for a golder that is going away.
Release(ctx context.Context) error
}
Host is one multiplexer's own dialect. Implementations are stateless apart from caching the binary they exec.
type InstallResult ¶
type InstallResult struct {
// Path is the manifest's location.
Path string
// Changed is false when the file was already current, which is the common
// case: installing twice is not an error and does not rewrite the file.
Changed bool
// State is what was there before the call.
State ManifestState
}
InstallResult says what an install did.
func Install ¶
func Install(getenv func(string) string) (InstallResult, error)
Install writes golder's manifest into tuios's user directory, and does nothing when the file is already current.
A file at the path that golder did not write is refused, never overwritten: it is the person's, and tuios documents editing these by hand. A symlink is followed the way tuios follows one when it reads the directory, so a dotfile-managed config installs into the file the link points at.
type Kind ¶
type Kind string
Kind says what a blocked state waits for. tuios records it (and its risk rules read the message that goes with it); herdr has no field for it, so the message alone carries the reason there.
type ManifestState ¶
type ManifestState int
ManifestState is what an installed manifest is worth.
const ( // ManifestAbsent: nothing at the path. ManifestAbsent ManifestState = iota // ManifestCurrent: golder's manifest, at this build's version. ManifestCurrent // ManifestOutdated: golder's manifest, from an older golder. ManifestOutdated // ManifestForeign: a file at the path that golder did not write. It is // never overwritten or removed: a person editing their own manifest there // is exactly the workflow tuios documents. ManifestForeign )
func ManifestStatus ¶
func ManifestStatus(getenv func(string) string) (state ManifestState, path string, err error)
ManifestStatus reads the manifest tuios would load and says what it is. A path that cannot be read is reported as absent with the error, so a caller can print why rather than guess.
func (ManifestState) String ¶
func (s ManifestState) String() string
String is the state in one word, as the diagnostic prints it.
type Options ¶
type Options struct {
// Getenv reads the environment (TUIOS_ENV, HERDR_ENV, ...).
Getenv func(string) string
// LookPath finds the tuios binary. herdr names its own through
// HERDR_BIN_PATH, so only the tuios host needs this.
LookPath func(string) (string, error)
// Run execs one argv. It exists so the command line each host sends is
// testable without either host installed.
Run func(ctx context.Context, argv []string) error
// Now is the clock behind herdr's monotonic sequence numbers.
Now func() time.Time
// Timeout bounds one report. Zero means DefaultTimeout.
Timeout time.Duration
// ErrLog receives one line per failed report. Nil discards them: a
// multiplexer hiccup is not worth interrupting an agent's transcript.
ErrLog io.Writer
}
Options are the seams a test (or a driver that knows better) can replace. Every field is optional; the zero Options reads the real environment and execs the real binaries.
type Report ¶
Report is one state report. Message is one plain line: for a blocked state it should say what golder waits for ("approve Bash: go test ./...").
An empty State means "no state change": the report carries the conversation alone (see Reporter.Session).
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter is a driver's handle on the host: nil outside a host pane, and safe to call in every case. Reports are coalesced and sent on a goroutine of their own, so an agent never waits on the terminal around it and a burst of state changes costs one command, not one per change.
func Open ¶
Open returns a reporter for the host this process runs in, or nil when it runs in neither. name is Detect's answer, resolved through the environment and GOLDER_HOST_REPORT.
func (*Reporter) Close ¶
func (r *Reporter) Close()
Close flushes what is queued and stops the reporter. It is safe to call more than once and safe on a nil reporter.
Close waits, bounded by Timeout, because it is normally called on the way out of the process: a release that is merely queued when the process exits is a pane the host believes still holds a running agent.
func (*Reporter) HostName ¶
HostName is the host this reporter talks to, "" for a nil reporter (or a reporter whose host went away).
func (*Reporter) Meta ¶
Meta reports display metadata: model, context use, a one-line summary of the task. A host without a field for it ignores the call.
func (*Reporter) Release ¶
func (r *Reporter) Release()
Release clears the pane's agent: golder is going away. It replaces anything still queued (a release after a state report is the same news, later) and is flushed by Close.
func (*Reporter) Session ¶
Session records the conversation a pane holds, so a host can offer to reopen it (and so a person reading the rail sees which conversation is running). argv is the resume command, used by the hosts that take one.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is one golder session's view of the multiplexer around it: the lifecycle half of this package, where Reporter is the transport half.
A driver calls it at the four moments it knows about — a session starts, a turn starts, a turn ends, golder is going away — and at the one moment only it can recognise: a prompt is now waiting for the person. The bookkeeping that matters is what happens when those overlap, and it lives here so every driver gets it:
- Prompts can overlap. Parallel tool calls can each need an answer, and the driver may open the second dialog before the first is answered, so the open-prompt count is a counter, not a flag. The pane is blocked while it is above zero and returns to work when it drops to zero.
- A turn that ends while a prompt is open must not report "done" over the top of "waiting for you": the person is still being waited for, and a host that saw "done" would stop showing the pane as needing attention.
- A prompt answered after the turn it belonged to has been cancelled reports rest, not work: there is nothing left running.
A nil *Session is a valid no-op, so a driver can hold one unconditionally and never test for a multiplexer again.
func OpenSession ¶
OpenSession returns the session for the multiplexer this process runs in, or nil when it runs in a plain terminal. It is Open plus the lifecycle bookkeeping, which is what a driver wants.
func (*Session) Block ¶
Block reports that golder is waiting for the person, and returns the call that says the wait is over. A driver defers it right where it opens the prompt:
unblock := s.host.Block(hostcompat.KindApproval, "approve Bash: go test ./...") defer unblock()
The returned function is safe to call more than once and on a nil Session, so the defer cannot go wrong on an early return.
func (*Session) Close ¶
func (s *Session) Close()
Close releases the pane and stops reporting. It is what golder runs on the way out: the pane's agent is cleared so the host stops drawing a golder that has quit, and the release is flushed before the process exits.
func (*Session) Conversation ¶
Conversation tells the host which conversation the pane holds, and how to reopen it. It is what makes a restored pane come back on the same conversation rather than on an empty prompt, so it is reported at session start, when the pane's shell is planted, and again whenever the session changes under it (/resume, /clone, /fork).
It does not move the pane's state: a report that names a conversation is not a report about what the agent is doing.
func (*Session) Meta ¶
Meta reports display metadata: the model, how full the context is, and what the agent is doing. It is display only — no host reads it as state.
func (*Session) Reporter ¶
Reporter returns the underlying reporter, for a caller that wants to send something this type does not model.
func (*Session) Start ¶
Start reports that a session is up and at rest: the pane holds a conversation and golder waits at its prompt.
type SessionRef ¶
SessionRef is the conversation a pane holds, as reported once per session. ResumeArgv is the command that reopens it, used by the hosts that take one (herdr); ID is used by both.
type State ¶
type State string
State is the neutral state vocabulary the drivers report in. Each host translates it; a host that cannot express a state ignores it rather than guessing (herdr has no "done", tuios has no "unknown").
const ( // StateNone clears the pane's agent: nothing runs there any more. It is a // real report, distinct from the zero State, which means "no state change" // and is only used by the reporter's own plumbing. StateNone State = "none" // StateIdle is at rest and ready for a prompt. StateIdle State = "idle" // StateWorking is mid-turn. StateWorking State = "working" // StateBlocked is waiting on the person (an approval or a question). StateBlocked State = "blocked" // StateDone finished its turn. Only a harness can claim this, which is // exactly the case here: golder says so itself. StateDone State = "done" // StateErrored stopped on an error. StateErrored State = "errored" )