# 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.

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/present (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
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**

```go
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 s1
```

Output:

```text
Bash: make deploy - execute
[allow] Allow once
[s1] Always allow: Bash(make deploy)
[deny] Deny
allow_session s1
```


## Constants

```go
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.

```go
const TitleLen = 120
```

TitleLen is the most bytes of an argument Title shows.


## Answer

```go
func Answer(a event.Approval, id, message string) event.ApprovalAnswer
```

Answer 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

```go
func FullTitle(tool string, input json.RawMessage) string
```

FullTitle is Title with the argument whole, for a view that wraps it rather than cutting it, or copies it.


## Title

```go
func Title(tool string, input json.RawMessage) string
```

Title 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.


## Why

```go
func Why(a event.Approval) string
```

Why 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

```go
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

```go
func Choices(a event.Approval) []Choice
```

Choices 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

```go
type ChoiceKind string
```

ChoiceKind is what a choice does, in the Agent Client Protocol's terms.

```go
const (
	AllowOnce   ChoiceKind = "allow_once"
	AllowAlways ChoiceKind = "allow_always"
	RejectOnce  ChoiceKind = "reject_once"
)
```

The kinds of choice.


## Delivery

```go
type Delivery string
```

Delivery is whether a background job's ending is still to reach the session, as a completion notice the model asked for.

```go
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

```go
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.


### End

```go
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**

```go
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:

```text
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.
```


### Ending.Headline

```go
func (e Ending) Headline() string
```

Headline says how the run ended in a few words, without the cause.


### Ending.String

```go
func (e Ending) String() string
```

String 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.


## Job

```go
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.


## Kind

```go
type Kind string
```

Kind is what a tool call does, in the vocabulary of the Agent Client Protocol, for an icon or a grouping.

```go
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

```go
func KindOf(tool string) Kind
```

KindOf returns what a call of the named tool does: zelk's built-in tools have kinds, and any other tool is KindOther.


## Overview

```go
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**

```go
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/server
```

Output:

```text
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/server
```


### Overview.String

```go
func (o Overview) String() string
```

String renders the overview as lines of plain text, listing at most eight tasks and eight jobs.
