present
import "github.com/barevoidco/zelk/core/present"Package present describes what an agent does for a person: a tool call’s title and kind, the choices an approval offers with the answer each one gives, how a run that didn’t succeed ended, and where a session stands. Hosts that show calls, ask for approvals, report endings or show a session’s status, such as the CLI, a TUI or an ACP client, share it so they present the same things the same way. Overviews include per-server MCP connection status, with bounded reasons. Plan controls share the switch-mode kind; entering includes its reason.
Example
a := event.Approval{Tool: "Bash", Input: json.RawMessage(`{"command":"make deploy"}`), Digest: "sha256:aa", Reason: "no rule allows it", Suggestions: []event.Suggestion{{ID: "s1", Rule: "Bash(make deploy)"}}}fmt.Println(present.Title(a.Tool, a.Input), "-", present.KindOf(a.Tool))for _, c := range present.Choices(a) { fmt.Printf("[%s] %s\n", c.ID, c.Label)}ans := present.Answer(a, "s1", "")fmt.Println(ans.Decision, ans.Suggestion)// Output:// Bash: make deploy - execute// [allow] Allow once// [s1] Always allow: Bash(make deploy)// [deny] Deny// allow_session s1Output:
Bash: make deploy - execute[allow] Allow once[s1] Always allow: Bash(make deploy)[deny] Denyallow_session s1Constants
Section titled “Constants”const ( ChoiceAllow = "allow" ChoiceAlways = "always" ChoiceDeny = "deny")The IDs of the choices an approval offers. ChoiceAlways grants all its suggestions; when it has one, the choice that does has that one’s ID.
const TitleLen = 120TitleLen is the most bytes of an argument Title shows.
Answer
Section titled “Answer”func Answer(a event.Approval, id, message string) event.ApprovalAnswerAnswer returns the answer the choice with ID id gives to approval a, as the event the session records; message, if not empty, tells the model why. An ID Choices didn’t offer denies the action, as no answer would.
FullTitle
Section titled “FullTitle”func FullTitle(tool string, input json.RawMessage) stringFullTitle is Title with the argument whole, for a view that wraps it rather than cutting it, or copies it.
func Title(tool string, input json.RawMessage) stringTitle names a call for a person: the tool and its main argument, such as a command, path, pattern or URL, cut to TitleLen bytes. It is the tool’s name alone if the input has none.
func Why(a event.Approval) stringWhy is why approval a asks, for a person deciding it, or empty when the reason is only that no rule allows the action: that is what an approval ordinarily means, and saying it on each one hides the reasons that matter, such as a classifier’s doubt or a protected path.
Choice
Section titled “Choice”type Choice struct { // ID identifies the choice for Answer. ID string Label string Kind ChoiceKind}Choice is one answer to an approval a person can pick.
Choices
Section titled “Choices”func Choices(a event.Approval) []ChoiceChoices returns what a person may answer an approval, in order: allow once, allow the suggested rules for the rest of the session (none for an action only a person may allow), and deny. The rules are one choice: a command of several parts suggests a rule for each, and only all of them cover it.
ChoiceKind
Section titled “ChoiceKind”type ChoiceKind stringChoiceKind is what a choice does, in the Agent Client Protocol’s terms.
const ( AllowOnce ChoiceKind = "allow_once" AllowAlways ChoiceKind = "allow_always" RejectOnce ChoiceKind = "reject_once")The kinds of choice.
Delivery
Section titled “Delivery”type Delivery stringDelivery is whether a background job’s ending is still to reach the session, as a completion notice the model asked for.
const ( // DeliveryOnCompletion is a job that reports back when it ends. DeliveryOnCompletion Delivery = "on_completion" // DeliveryPending is a job that ended and whose notice the session // hasn't yet taken. DeliveryPending Delivery = "pending")Ending
Section titled “Ending”type Ending struct { Outcome event.RunOutcome // Cause is why the run ended, as its log records it; empty when the // log records no reason. Cause string // ErrorKind is the class of the failed model call that ended an error // run, which names it in the headline; empty for other endings. ErrorKind event.ModelErrorKind // Open is what is left: the model's open items, checks without fresh // passing evidence, claims no evidence supports and the problems with // rejected structured output. Open []string // Next says what the person can do now. Next string // Caution marks an ending that tells of checks that don't pass rather // than of a run that went wrong: a success whose report left failing // checks as they were, or a run that ended on the model's reply, whose // only open items are checks without a pass and whose reply says why. // Hosts show it as a caution, not as an error. Caution bool}Ending is how a run that didn’t succeed ended, told for a person: what happened, why, what is left and what they can do about it. Hosts show the same Ending for the same run, so a CLI, a TUI and an ACP client agree on it.
func End(fin event.RunFinished, r *event.Report) (Ending, bool)End explains how a run ended from its ending and its report, which may be nil. It reports false for an ending that needs no explaining: a success that left no failing checks, a session waiting for answers, or a run someone interrupted.
Example
fin := event.RunFinished{Outcome: event.RunIncomplete, Error: "completion check: go test: not run"}report := &event.Report{Unverified: []string{"go test: not run"}}if e, ok := present.End(fin, report); ok { fmt.Println(e)}// Output:// The run ended incomplete: completion check: go test: not run// - check go test: not run// Send a message to continue; the session keeps the work done so far.Output:
The run ended incomplete: completion check: go test: not run- check go test: not runSend a message to continue; the session keeps the work done so far.Ending.Headline
Section titled “Ending.Headline”func (e Ending) Headline() stringHeadline says how the run ended in a few words, without the cause.
Ending.String
Section titled “Ending.String”func (e Ending) String() stringString renders the ending as lines of plain text: the headline with its cause, up to eight open items, and what to do next. A failed run’s cause is an error’s own text, a chain of causes rather than words for a person, so it has a line of its own under the headline.
type Job struct { // ID is the job's handle: a child session or a process handle. ID string // Kind is "subagent" or "process". Kind string // State is how it stands: running, waiting, completed, failed, // cancelled, stopped, killed, lost or ended, or unfinished when the log shows // it mid-run and no one here drives it. State string // About says what it is, such as a process's command. About string // Delivery says whether its ending is still to reach the session. Delivery Delivery}Job is a subagent or background process a session started.
type Kind stringKind is what a tool call does, in the vocabulary of the Agent Client Protocol, for an icon or a grouping.
const ( KindRead Kind = "read" KindEdit Kind = "edit" KindSearch Kind = "search" KindExecute Kind = "execute" KindFetch Kind = "fetch" KindSwitchMode Kind = "switch_mode" KindThink Kind = "think" KindOther Kind = "other")The kinds of call.
KindOf
Section titled “KindOf”func KindOf(tool string) KindKindOf returns what a call of the named tool does: zelk’s built-in tools have kinds, and any other tool is KindOther.
Overview
Section titled “Overview”type Overview struct { // MCP reports per-server connection status; absent State means connected. MCP []event.MCPServer Session string Title string // Model, Effort and Mode are what the session calls and how: the model, // its reasoning effort (empty when the provider decides) and the // permission mode. Model string Effort event.Effort Mode event.PermissionMode // ModeName is the host's own name for Mode, such as the TUI's ASK // for default, shown with it; empty shows the mode alone. ModeName string // Running says a run is under way, and Waiting how many requests for // input it waits for. Running bool Waiting int // Ended explains how the last run ended, when it didn't succeed and no // run is under way since. Ended *Ending // Todos is the task list. Todos []event.Todo // Jobs are the subagents and background processes the session started. Jobs []Job // Tokens is what the session's model calls measurably spent. Tokens event.Tokens // Context is the last model call's input, Uncached the session's input // that no cache served, and Cleared how many times old tool results // were cleared to keep the context lean. String leaves Uncached out // when it is all the input: the provider then reported no cache use, // which doesn't show that none happened. Context int64 Uncached int64 Cleared int // Log and Memory say where the session's log and the agent's notes are // kept; empty when the host doesn't say. Log string Memory string}Overview is where a session stands, told for a person: what calls it, whether work is under way, what the work has left and what runs in the background. Hosts show the same Overview, so a CLI, a TUI and an ACP client agree on a session’s state; it holds nothing a host must keep for itself.
Example
o := present.Overview{Session: "s1", Model: "gpt-6-luna", Effort: event.EffortHigh, Mode: event.ModeDefault, Todos: []event.Todo{{Content: "write the parser", Status: event.TodoCompleted}, {Content: "test it", Status: event.TodoInProgress}}, Jobs: []present.Job{{ID: "server", Kind: "process", State: "running", About: "go run ./cmd/server"}}}fmt.Println(o)// Output:// Session s1// Model gpt-6-luna · effort high · default mode// Idle// Tasks: 1 of 2 done// ✓ write the parser// ▸ test it// Background:// process server running: go run ./cmd/serverOutput:
Session s1Model gpt-6-luna · effort high · default modeIdleTasks: 1 of 2 done ✓ write the parser ▸ test itBackground: process server running: go run ./cmd/serverOverview.String
Section titled “Overview.String”func (o Overview) String() stringString renders the overview as lines of plain text, listing at most eight tasks and eight jobs.