Documentation
¶
Overview ¶
Package executor runs a provider CLI as a child process and turns its stream into canonical events (ADR-0006). An Adapter knows only how to launch one CLI and how to translate its stream; this common Executor owns the child lifecycle (start, timeout, SIGINT forwarding), assigns ts, and observes exit code and wall-clock duration. Nothing here touches the DB, connections, or seq numbering — those live behind the Sink (SCHEMA.md).
Index ¶
Constants ¶
const ( EventProviderSelected = "provider.selected" EventProviderOutput = "provider.output" EventProviderFinished = "provider.finished" EventProviderError = "provider.error" )
Canonical event types an Adapter may emit (SCHEMA.md R4). The vocabulary lives here, not in the adapters, so the Executor can recognise the two events it treats specially: provider.finished, whose exit_code only the Executor observes (see Run), and provider.error, whose presence the Executor reports back so a caller doesn't record the same failure twice.
const PayloadDetail = "detail"
PayloadDetail is a view-only payload key (ADR-0024 Decision 6): a short, human-readable summary of a tool_use — the file it touched, the command it ran — that an Adapter may attach so a turn view can show "what, where", not just the tool name. It never reaches the ledger: the recorded event keeps the tool name only (SCHEMA.md R3), because a summary in the digest would pressure maxEventChars/maxSessionChars and force an extractor_ver bump.
const PayloadToolResult = "tool_result"
PayloadToolResult is a view-only payload key (ADR-0030): a tool's own output — a Bash colour demo, a diff, a test result — that a turn view shows so the human can judge an answer that IS terminal output, not just its assistant text. Like PayloadDetail it never reaches the ledger: SCHEMA.md R3 keeps the tool name only, and recording tool output would spend the perception digest budget (maxEventChars/maxSessionChars) on what R3 deliberately drops. It carries the provider's raw ANSI; the view sanitises it (mdlite.ToolOutput).
Variables ¶
This section is empty.
Functions ¶
func StripViewOnly ¶
StripViewOnly returns payload without its view-only keys (PayloadDetail), the form a Sink records. It never mutates the input and returns a copy only when there is something to strip: a chat's sink shows the event first and records it after, so the shown map must keep its detail regardless of call order, and events without a detail (the common case) allocate nothing.
func TruncateDetail ¶
TruncateDetail trims a candidate view-only summary and caps it at 60 runes (not bytes, so a Japanese path is measured by characters), ending the cut side with an ellipsis. A path keeps its tail — the filename answers "where", and a deep absolute path cut from the right shows only the prefix every path shares (measured on a real turn: the view showed ~/.claude-personal/projects/… with the filename gone). Everything else keeps its head. A blank value returns "" so an adapter can fall through to its next candidate. The ruler lives here beside PayloadDetail: two adapters measuring the same channel differently would be a drift bug waiting.
Types ¶
type Adapter ¶
type Adapter interface {
// Name is the canonical provider name recorded as the connection target
// (SCHEMA.md R3), e.g. "claude-code".
Name() string
// Command returns the executable, args, and any extra environment
// entries ("KEY=value", appended to the parent's environment) to launch
// for req. The launch environment is part of knowing the CLI: a provider
// that selects a profile via an env var (e.g. CLAUDE_CONFIG_DIR) owns
// that here, not in shell aliases around tomobit.
Command(req Request) (name string, args []string, extraEnv []string)
// Translate maps one stream line to zero or more canonical events. Pure:
// no I/O and no state, so recorded fixtures can pin the mapping.
Translate(line []byte) ([]Event, error)
}
Adapter is a provider's entire surface (ADR-0006 Decision 2): it knows the CLI and its stream format, and nothing about the DB, connections, questions, or seq/ts.
type Event ¶
Event is one canonical event: an R4 type plus its payload. Adapters produce these as pure data from a single stream line; the Executor assigns ts and the Sink assigns seq (store side).
type Executor ¶
type Executor struct {
Adapter Adapter
Stderr io.Writer // child stderr passthrough; nil discards
// Warn receives translate errors — stream lines the adapter could not
// parse at all. Distinct from Debug: a malformed line is a real defect,
// not the forward-compatible "unknown type, ignore" path, so callers
// that want failures visible by default wire this to os.Stderr
// unconditionally instead of gating it behind a debug flag. Nil discards.
Warn io.Writer
// Debug receives lower-signal diagnostics: lines the adapter recognised
// and intentionally dropped (0 events, no error). Nil is silent.
Debug io.Writer
}
Executor runs an Adapter's CLI and drives its events into a Sink.
func (*Executor) Run ¶
Run launches the adapter's command, streams stdout line by line through Translate, and emits each event via sink. It manages the child lifecycle and returns the observed exit code and duration.
A non-zero exit is NOT an error — it is reported in Result.ExitCode so the caller can decide what to record. Run errors only on operational failures: the command not starting, the timeout firing, a failed emit, or an unexpected wait error. Cancelling ctx (SIGINT) forwards SIGINT to the child and returns without error; the caller detects the cancellation via its own context.
type Request ¶
type Request struct {
Prompt string
// ResumeID continues a provider thread instead of starting one
// (ADR-0022 Decision 2): the provider_session_id an earlier run of the
// same session reported. Empty starts a fresh thread. How to continue —
// or that the CLI cannot — is the Adapter's to know.
ResumeID string
PermissionMode string
Timeout time.Duration // 0 = no limit
// WorkDir is where Tomo works — the child's cwd (ADR-0047 Decision 2).
// Empty inherits tomobit's own, which is what a terminal `cd` already
// expressed. The Executor applies it and no Adapter translates it: cwd is
// an OS concept, not a CLI's vocabulary.
WorkDir string
// AddDirs are the places outside WorkDir that Tomo may also work with
// (ADR-0047 Decision 3). Unlike WorkDir this one IS translated: each
// Adapter maps it onto its own CLI's flag, and an Adapter whose CLI has
// no such flag ignores it rather than inventing one.
AddDirs []string
}
Request describes a single execution. The Adapter turns it into a launch command; the Executor enforces the timeout.
type Result ¶
type Result struct {
// Started reports whether the child process actually launched. When
// false, ExitCode and Duration are meaningless — the caller should treat
// this as "nothing ran", not as a failed run (e.g. skip any adoption
// question, since there is nothing to judge).
Started bool
// ErrorReported reports whether the adapter's own stream already
// produced a provider.error event (delivered to the Sink during Run).
// A caller that also wants to record ExitCode/runErr as provider.error
// should skip it when this is true, to avoid recording the same failure
// twice.
ErrorReported bool
ExitCode int
Duration time.Duration
}
Result is what the Executor observes about a run, independent of what the stream said (ADR-0006 Decision 2).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package claudecode adapts the Claude Code CLI (`claude -p ...
|
Package claudecode adapts the Claude Code CLI (`claude -p ... |
|
Package codex adapts the Codex CLI (`codex exec --json`) to the executor's canonical events (ADR-0010 Decision 3).
|
Package codex adapts the Codex CLI (`codex exec --json`) to the executor's canonical events (ADR-0010 Decision 3). |