explain

package
v0.73.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 18 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 explain reads and writes the files of a paced explain (modes/paced.md): the draft the beats are read from, and the record of what the reader saw. Read is the popup that shows them.

Index

Constants

View Source
const AskTimeout = 5 * time.Minute

AskTimeout bounds one question, because a fork re-reads the explain session's whole context and a stalled one would hold the reader forever.

View Source
const DraftSuffix = ".draft.md"

DraftSuffix ends every draft's name: `<key>.draft.md` beside `<key>.md`.

Variables

View Source
var ErrNoSession = errors.New("questions need the explain session, and this viewer was opened without one")

ErrNoSession is the reply to a question when the viewer has no explain session to fork, so it can show beats but answer nothing.

Functions

func Finish

func Finish(draft, record string) (string, error)

Finish writes the record beside the draft and deletes the draft. A record already there is archived first, so a second run on a subject keeps the first one's.

func ForkArgs

func ForkArgs(session string) []string

ForkArgs is the fork's command line. --tools removes every other tool, since --allowedTools alone only pre-approves these three and a permissive default mode would still let the fork edit. The prompt goes on stdin, because both flags are variadic and would read it as one more tool name.

func KeyOf

func KeyOf(draft string) (string, error)

KeyOf is the key a draft path names, an error for a path that is no draft.

func Prompt

func Prompt(q Question) string

Prompt is the fork's turn: the question, the beats as the reader has them, and paced mode's rule for what a question does to the unread rest.

func Read

func Read(
	ctx context.Context, in io.Reader, w io.Writer, draft string, asker Asker, interrupts <-chan os.Signal,
) error

Read shows the draft one beat at a time. Enter or `.` shows the next one with no model call, and `q` ends. Any other line is a question for asker, whose reply rewrites the unread beats on disk. An interrupt cancels a waiting question only, and at the prompt it ends the read. Every ending writes the record and deletes the draft, ctx's included.

func Record

func Record(title string, shown []Shown) string

Record is the record's text: the title, the beats shown, and each question with its answer after the beat it followed.

Types

type Asker

type Asker interface {
	Ask(ctx context.Context, q Question) (Reply, error)
}

An Asker answers a question about the explanation.

type Draft

type Draft struct {
	Title  string
	Header string
	Beats  []string
}

A Draft is the whole explanation. It opens with a `# ` title and the subject block, then holds the beats, each under a `## <n>` heading.

func Parse

func Parse(text string) Draft

Parse reads a draft. A `## <n>` inside a code fence is the beat's text, not a new beat, so fences are tracked line by line.

func (Draft) Render

func (d Draft) Render() string

Render writes the draft back, the beats numbered from 1 in their order.

type Fork

type Fork struct {
	Session string
	Dir     string
}

Fork answers through a fork of the explain session, so the answer has the codebase context that session gathered and the session itself is left as it was. Its tools are read-only (ForkArgs), because the viewer alone writes the draft.

func (Fork) Ask

func (f Fork) Ask(ctx context.Context, q Question) (Reply, error)

Ask runs one headless turn on the fork.

type QA

type QA struct {
	Question string
	Answer   string
}

A QA is one question the reader asked and the answer it got.

type Question

type Question struct {
	Text   string
	Title  string
	Shown  []Shown
	Unread []string
}

A Question is what the reader asked, with what the answer must see. That is the beats already read, the unread ones and the earlier questions.

type Reply

type Reply struct {
	Answer string   `json:"answer"`
	Beats  []string `json:"beats"`
	Keep   bool     `json:"-"`
}

A Reply is the answer and the unread beats rewritten for it. Keep means the reply carried no beats the viewer could read, so the unread ones stay.

func ParseResult

func ParseResult(stdout string) (Reply, error)

ParseResult reads `claude -p --output-format json`. The schema's reply is in structured_output. An older CLI leaves it as JSON in result. A reply that is not JSON at all is kept as the answer alone.

type Shown

type Shown struct {
	Beat string
	QAs  []QA
}

A Shown beat is one the reader saw, with the questions asked after it.

Jump to

Keyboard shortcuts

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