agentactivity

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 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 agentactivity classifies live agent terminal observations without depending on tmux, Bubble Tea, or persistent conversation storage.

Where the rules live

Not here. Every provider is classified by Herdr's vendored detection manifest for it, executed by internal/agentactivity/manifest; anything Sidecar knows that upstream does not is a data overlay under manifests/sidecar/. This package owns what surrounds that: a stricter-than-Herdr process gate per provider, the identity resolver, the two evidence strings no manifest can produce, the low-evidence fallback policy, and Tracker, which turns a stream of verdicts into transitions. See docs/reference/herdr-detection-parity.md.

Spinner glyph sets are provider-owned, and are upstream's problem now

The rule tables that used to live here shared this failure mode, and it is worth remembering because it is what the cutover bought. A spinner set that is too narrow does not merely miss activity, it inverts the verdict: Claude shared one eleven-glyph braille pattern with Codex, so the frames outside that set left the title rule unmatched, evaluation fell through to the prompt-box idle rule while subagents were still running, and Tracker turned that working→idle transition into a completed turn. Sessions reported "done" with work in flight. Claude Code 2.1.228 then switched to half-circle frames (U+25D0–U+25D3), which Sidecar's hand-written pattern never learned and upstream's `osc_title_working` already covered.

If a spinner is missed today, the fix is a fixture and either an overlay rule or a pull request to Herdr — never a regex added back into this package.

Index

Constants

View Source
const AgentHintEnv = "SIDECAR_AGENT"

AgentHintEnv is the launch-time process-identity hint: a provider name a wrapper command may publish into its own environment so Sidecar can name an agent it cannot see.

Herdr's equivalent is `HERDR_AGENT` (src/platform/mod.rs:346 at d08e4468, `parse_agent_env_hint`). It exists for the pane Sidecar cannot resolve from the process table at all: a sandbox or container wrapper whose foreground process is the sandbox, with the agent running out of reach inside it.

It is a hint and never a claim. See ResolveForegroundAgent for the seam that keeps it away from lifecycle authority, and why that seam must not be collapsed.

Reading it means reading another process's environment, which both adapters can do and neither can do unconditionally: Linux denies another user's /proc/<pid>/environ, and macOS withholds the environment of a *restricted* binary from everyone, including the same user. The macOS half is the surprising one and is measured in platformProcessAgentHint (process_identity_darwin.go) — read it before concluding from a live proof that the hint does not work, because a proof whose stand-in wrapper is a system binary sees nothing for that reason alone.

View Source
const IdleDebounce = 400 * time.Millisecond
View Source
const SkipRetentionCap = 2 * time.Minute

SkipRetentionCap bounds how long an overlay rule may retain the prior state. Retention exists so a transcript or model picker does not erase a live turn, but an overlay left open — or a rule matching chrome that never clears — would otherwise hold a confident badge forever. Past the cap the tracker admits it no longer knows rather than continuing to assert stale evidence.

Variables

This section is empty.

Functions

func ExplainManifest added in v1.12.0

func ExplainManifest(ob Observation) *manifest.Explain

ExplainManifest is DetectManifest for a caller that only wants the record, such as `sidecar agent explain --file`.

func ExplainVendoredManifest added in v1.12.0

func ExplainVendoredManifest(agentID string, ob Observation) (*manifest.Explain, bool)

ExplainVendoredManifest evaluates a screen against the vendored manifest for a Herdr agent id, with no provider gate and no Result.

It exists for the agents Sidecar vendors a manifest for and does not claim as providers. Since Phase 4 registered the ten detection-only families that is `gemini` alone (Decision 4 of the plan), but the reason it was written has not gone away, and it is why the entry point stays: when it was added, `kiro` and `qodercli` were outside Supports and carried two of the four `\p{Alphabetic}` overlay rewrites between them, so those rewrites had no fixture, no census row and no differential-harness row, and a dead rule in either file would have gone on being dead until someone read the TOML. Both are providers now and reach the live path, but the next agent synced in and not yet registered will be in exactly the position they were, and `sidecar agent explain --file` is what covers it. It is a debugging surface for a manifest rather than a verdict for a pane, so refusing an id the binary carries the bytes for was an arbitrary limit.

It is deliberately not a second Detect: there is no Sidecar provider here, so there is no process gate to apply, no evidence string to mint and no fallback policy to choose. A caller that wants a verdict wants Detect and a supported agent. The bool reports whether a manifest for the id exists at all.

func ForegroundShellReady added in v1.11.0

func ForegroundShellReady(panePID int, currentCommand string) bool

ForegroundShellReady is the strict launch gate for a managed tmux pane. It accepts only the pane shell's own process group with exactly one member, and that member must resolve to a known interactive shell. Unknown helpers are busy, not ignorable.

It reads argv[0] and nothing else on purpose. Process-tree scoring exists to look *past* a runtime to the program behind it, which is the opposite of what this question wants: a pane running `node` is occupied whether or not the node turns out to be an agent, and a hint is irrelevant because nobody launches into a hint.

func HasProcessIdentity added in v1.11.0

func HasProcessIdentity() bool

HasProcessIdentity reports whether this platform can disambiguate a pane's foreground job by argv[0].

It exists so the answer is read from the build rather than restated as a GOOS list somewhere else — the host protocol's hello carries this bit, and a second copy of "which platforms are implemented" would be wrong the moment a third one is added.

func HasVendoredManifest added in v1.12.0

func HasVendoredManifest(agentID string) bool

HasVendoredManifest reports whether a Herdr agent id has a vendored manifest that compiles, whether or not Sidecar claims it as a provider.

func HerdrAgentLabel added in v1.12.0

func HerdrAgentLabel(agent string) string

HerdrAgentLabel maps a Sidecar provider family to Herdr's *label* for it — the string `agent_label` returns (src/detect/mod.rs:121 at e2b85c7), which is what `herdr agent explain --agent` takes, what keys its alias table, and what names Herdr's own local override file.

It does not name Sidecar's: a local override under ~/.config/sidecar/agent-detection is named after the vendored manifest file it replaces (manifests.OverridePath), so `agy` is Herdr's override name and `antigravity.toml` is Sidecar's. This label is for talking to Herdr.

It is a second, different mapping from ManifestAgentID, and the difference is not tidy: Herdr's Antigravity manifest lives in antigravity.toml but its label is "agy", and its Copilot manifest lives in github-copilot.toml but its label is "copilot". Conflating the two silently reads the wrong file for one of the two providers, so both mappings are spelled out rather than derived.

func Identify added in v0.94.0

func Identify(ob Observation) string

Identify returns the live program owning an agent pane when the existing tmux metadata or current UI makes that identity unambiguous. It deliberately returns an empty string for shared runtimes such as node and bun unless the current screen distinguishes the provider. Callers can retain their prior identity in that case without paying for a process-tree scan.

func ManifestAgentID added in v1.12.0

func ManifestAgentID(agent string) string

ManifestAgentID maps a Sidecar provider family to the Herdr agent id whose manifest classifies it.

One mapping is not the identity: Sidecar's family is `copilot` and Herdr's manifest is `github-copilot.toml`. Everything else Sidecar claims shares Herdr's spelling, including `antigravity` (whose *manifest id* is "agy" while its file is antigravity.toml — the file name is what the loader keys on). Keeping the whole mapping in one function is what stops a second, subtly different copy appearing next to a new call site.

func NeedsProcessIdentity added in v1.9.0

func NeedsProcessIdentity(command string) bool

NeedsProcessIdentity reports whether tmux's command name is shared by multiple agent CLIs and therefore benefits from a foreground process scan.

This is a cost gate, not a correctness one. Its callers poll every workspace row, and answering true means paying for a process-table walk (a full kern.proc.all on macOS) behind a two-second cache. So it names the runtimes that hide an agent and nothing else.

It is no longer a gate any caller of ResolveForegroundAgent applies: it is the top rung of that resolver's own cost ladder (agentIdentityEffort), because duplicating it at each call site is what kept AgentHintEnv permanently out of reach of the sandbox panes it exists for — a `docker` pane answers false here and so never reached the hint. It survives as an exported predicate for the other question it answers: whether a pane needs live UI chrome captured to name its provider (workspace's shellNeedsIdentityScreen).

It is therefore a strict subset of isGenericRuntimeOrShell, and the three exclusions are deliberate:

  • The interactive shells. `sh`, `bash`, `zsh` and `fish` are in the scoring predicate because a shell-wrapped agent (`/bin/sh /usr/local/bin/pi`) is a real install shape upstream tests. But an idle shell is the overwhelmingly common pane, so admitting them here would make every idle row in every workspace scan the process table forever to find nothing. Those panes are still resolved on the paths that scan unconditionally — agentcontrol's Inspect and observer, which is what `sidecar agent list` and `agent start` read.
  • `tmux`. wrappedAgentNameFromRuntimeArgv refuses it by construction, so a scan could not produce an answer even in principle.
  • `cmd`, `powershell`, `pwsh`. No Windows process-identity adapter exists, so the scan would return nothing on every platform that reaches this.

Python was added when process-tree scoring landed: upstream unwraps `python3.12 /nix/store/.../hermes --resume …`, and a python pane is rare enough that the scan is affordable where a shell pane is not.

func ResolveForegroundAgent added in v1.9.0

func ResolveForegroundAgent(panePID int, currentCommand string) string

ResolveForegroundAgent names the agent running in a pane, for detection and display. It is the hint-aware resolver. currentCommand is tmux's pane_current_command, which decides how much the answer is allowed to cost.

Why this is a different function from ResolveForegroundProcess

This one may consider AgentHintEnv. That one may not, and the split is the whole point rather than an accident of history.

ResolveForegroundProcess feeds lifecycleenv.OccupantKind, which feeds VerifyReportedKind, which *refuses* a hook report whose claimed kind disagrees with the pane's occupant. AgentHintEnv is an environment variable: anything running in the session can set it. If a hint could reach OccupantKind, then exporting `SIDECAR_AGENT=codex` in a Claude pane would make Sidecar reject Claude's own reports — a writable variable would have acquired the power to switch off a lifecycle lane. So the hint stops here, on the display side, where being wrong costs a wrong badge and nothing else.

Do not "simplify" these two back into one function. If a caller needs both answers it should ask for both.

Precedence, and a deliberate divergence from upstream

Upstream's `probe_foreground_process_from_jobs` (src/pane.rs:608 at d08e4468) reads the process group leader's hint *before* identifying the leader, so a hint outranks process evidence. This port inverts that: evidence first, hint only when evidence names nothing.

The difference is who can write the hint. Herdr's `HERDR_AGENT` is set by Herdr's own wrapper, so trusting it over evidence is trusting itself. Sidecar's `SIDECAR_AGENT` is a bare environment variable that Sidecar reads and never writes (see the Slice 3 result in docs/plans/implemented/herdr-parity-close-the-gap.md), so anything in the session can set it. Under upstream's order, `export SIDECAR_AGENT=codex` in a Claude pane would relabel that pane — the display-side echo of exactly the failure the resolver split exists to prevent, and the hint's only observable effect on a pane whose evidence already answers.

Inverting it also removes a cost: upstream's order forces a hint read on every trivially identified leader, once per pane per poll.

So the ladder is: identifyAgentInJob across the job (which already prefers the leader, then scores members), then the leader's hint, then any other member's hint. Hints keep upstream's leader-before-members order among themselves, because a member's hint may have been inherited from an unrelated ancestor.

func ResolveForegroundProcess added in v1.11.0

func ResolveForegroundProcess(panePID int) string

ResolveForegroundProcess identifies the known program in the pane's actual foreground process group, including "shell" when the group belongs to an interactive shell. Unlike pane_current_command, this is process ownership evidence and is therefore safe for agent-control's shell-ready gate and for lifecycleenv's occupant check.

Process evidence only. It never reads an environment; see ResolveForegroundAgent. It also takes no command, and therefore no cost ladder: its callers ask about one pane deliberately (agent start, the occupant check), not about every row on screen, so it always scans.

func Supports added in v0.94.0

func Supports(agent string) bool

Supports reports whether Sidecar has provider-owned activity evidence rules.

It answers true for twenty agents: the ten with a hand-written process gate, and the ten below that reach the engine through the alias table alone. Both groups have the same two things for detection purposes, a vendored Herdr manifest and a gate, which is the point. Supports is a statement about the screen lane, not about launch, resume, or a conversation adapter; agentcatalog.Families and agentcatalog.DetectionOnly are what answer those.

`omp` and `mastracode` are deliberately absent. They are launchable catalog families and identifyProcessName names them, but upstream ships them hooks-only with no screen manifest, so there is nothing for this lane to execute and claiming otherwise would put a provider chip on a row whose state could only ever be unknown.

Types

type Observation

type Observation struct {
	Agent          string
	Screen         string
	PaneTitle      string
	CurrentCommand string
	// ProcessIdentity is a provider name resolved from the pane's foreground
	// process group and argv[0]. It disambiguates shared runtimes such as Node
	// without promoting phrases from another agent's transcript.
	ProcessIdentity string
	// PaneHeight is the pane's own row count (tmux #{pane_height}). It is the
	// manifest engine's read window: Herdr reads the tail of the buffer N rows
	// deep where N is the pane's height, so a capture carrying scrollback has to
	// be bounded to the same N or a resolved historical prompt wins a rule it
	// should never have seen. Zero means the height was not available and the
	// engine falls back to 24, Herdr's own DEFAULT_DETECTION_ROWS. See
	// docs/reference/herdr-detection-parity.md ("Read window").
	PaneHeight int
	CapturedAt time.Time
}

type Result

type Result struct {
	State           State
	Evidence        string
	VisibleIdle     bool
	VisibleWorking  bool
	VisibleBlocker  bool
	SkipStateUpdate bool
	// FallbackIdle distinguishes provider-owned explicit idle evidence from the
	// conservative no-match policy for a positively identified live process.
	// Fallback idle may establish/display idle, but cannot announce completion.
	FallbackIdle bool
}

func Detect

func Detect(ob Observation) Result

Detect dispatches an observation to the vendored Herdr manifest for its provider. Keeping dispatch here lets the workspace poll remain product-neutral while each provider file owns only its process gate.

There is one lane. Every provider Sidecar claims was cut over in Phase 2 of docs/plans/active/herdr-detection-parity.md, so the Go rule tables, the selector that used to choose between the two lanes, and the shadow mode that compared them are all gone. What is left of each `<provider>.go` is the process gate, plus an identity pattern for cursor and grok; Claude's and Codex's identity patterns sit beside Identify above, because that is the only thing that reads them.

func DetectAmp

func DetectAmp(ob Observation) Result

DetectAmp classifies an Amp pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

func DetectAntigravity

func DetectAntigravity(ob Observation) Result

DetectAntigravity classifies an Antigravity pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's, plus the three overlay rules.

func DetectClaude

func DetectClaude(ob Observation) Result

DetectClaude classifies a Claude Code pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

func DetectCodex

func DetectCodex(ob Observation) Result

DetectCodex classifies a Codex pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's. tmux commonly reports "node" for the npm-installed Codex launcher, which is why the gate is a set rather than an equality.

func DetectCopilot

func DetectCopilot(ob Observation) Result

DetectCopilot classifies a Copilot pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

func DetectCursor

func DetectCursor(ob Observation) Result

DetectCursor classifies a Cursor pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's, plus the three overlay rules.

func DetectGrok

func DetectGrok(ob Observation) Result

DetectGrok classifies a Grok pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's, plus the four overlay rules.

func DetectManifest added in v1.12.0

func DetectManifest(ob Observation) (Result, *manifest.Explain)

DetectManifest is DetectManifestResult with the explain record beside the verdict, for a caller that wants to show its reasoning: `sidecar agent explain`, the census, the differential harness.

The Explain is nil when the process gate refused or the manifest could not be loaded: there is nothing to explain about rules that were never evaluated.

func DetectManifestResult added in v1.12.0

func DetectManifestResult(ob Observation) Result

DetectManifestResult classifies an observation through the vendored Herdr manifest for its agent and returns the verdict alone.

This is the live path, and it is separate from DetectManifest for one reason: building an explain record costs an EvaluatedRule struct and a 240-character region preview per rule — around eighteen of each for Codex — and the poller runs every 200ms per visible pane and throws all of it away. Evaluate does the same work and allocates none of it.

func DetectMuse added in v1.12.0

func DetectMuse(ob Observation) Result

DetectMuse classifies a Muse pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

func DetectOpenCode

func DetectOpenCode(ob Observation) Result

DetectOpenCode classifies an OpenCode pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

func DetectPi

func DetectPi(ob Observation) Result

DetectPi classifies a Pi pane. The process gate runs first and refuses before any manifest is evaluated; everything after it is upstream's.

type Snapshot added in v0.96.0

type Snapshot struct {
	State        string    `json:"state"`
	Evidence     string    `json:"evidence,omitempty"`
	ChangedAt    time.Time `json:"changedAt"`
	Seen         bool      `json:"seen"`
	IdleInferred bool      `json:"idleInferred,omitempty"`
}

Snapshot is the persistable projection of a tracker. It carries only the fields that survive a restart meaningfully: transition policy timers are in-process concerns and are deliberately dropped.

type State

type State string
const (
	StateUnknown State = "unknown"
	StateIdle    State = "idle"
	StateWorking State = "working"
	StateBlocked State = "blocked"
)

type Tracker

type Tracker struct {
	State          State
	Evidence       string
	ChangedAt      time.Time
	Seen           bool
	VisibleBlocker bool
	// IdleInferred records that the current idle state came from the absence
	// of activity rather than an explicit completion marker. Providers without
	// a completion signal can never assert "done", and views use this to say so
	// instead of letting their absence from the done lane read as a bug.
	IdleInferred bool
	// contains filtered or unexported fields
}

Tracker owns transition policy while classification remains state-free.

func Restore added in v0.96.0

func Restore(s Snapshot) Tracker

Restore rebuilds a tracker from persisted state. A restored idle keeps its original ChangedAt, so a turn that finished before the restart still reads as recently finished rather than as "just observed".

func (*Tracker) Acknowledge

func (t *Tracker) Acknowledge()

func (*Tracker) Apply

func (t *Tracker) Apply(result Result, now time.Time) bool

func (Tracker) DisplayState

func (t Tracker) DisplayState() string

func (*Tracker) ResetForProcessChange added in v0.94.0

func (t *Tracker) ResetForProcessChange(now time.Time)

ResetForProcessChange clears semantic state from the prior pane owner while allowing a confirmed new process's first explicit idle observation to land immediately. That first idle is initialization, not a completion event.

func (Tracker) Snapshot added in v0.96.0

func (t Tracker) Snapshot() Snapshot

Directories

Path Synopsis
Package manifest implements Herdr's agent-detection manifest grammar in Go.
Package manifest implements Herdr's agent-detection manifest grammar in Go.
Package manifests holds Sidecar's vendored copy of Herdr's agent-detection manifests, the lock that pins them, and the extracted alias and authority tables that go with them.
Package manifests holds Sidecar's vendored copy of Herdr's agent-detection manifests, the lock that pins them, and the extracted alias and authority tables that go with them.

Jump to

Keyboard shortcuts

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