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
- Variables
- func Finish(draft, record string) (string, error)
- func ForkArgs(session string) []string
- func KeyOf(draft string) (string, error)
- func Prompt(q Question) string
- func Read(ctx context.Context, in io.Reader, w io.Writer, draft string, asker Asker, ...) error
- func Record(title string, shown []Shown, total int) string
- func Wait(ctx context.Context, draft string, ...) (string, error)
- type Asker
- type Draft
- type Fork
- type QA
- type Question
- type Reply
- type Shown
Constants ¶
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.
const DraftSuffix = ".draft.md"
DraftSuffix ends every draft's name: `<key>.draft.md` beside `<key>.md`.
const PaneMisses = 5
PaneMisses is how many pane checks in a row may fail before Wait gives up, because one slow Herdr answer must not end a read still going.
Variables ¶
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.
var ErrReaderGone = errors.New("the reader closed without writing a record")
ErrReaderGone is a reader whose pane closed with the draft still on disk: it died before Finish, so no record was written.
Functions ¶
func Finish ¶
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 ¶
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 Prompt ¶
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 ¶
Record is the record's text: the title, the beats shown, and each question with its answer after the beat it followed. A read that stopped short of total beats ends with a line saying how far it got, because the draft that held the rest is deleted.
func Wait ¶ added in v0.74.0
func Wait( ctx context.Context, draft string, paneOpen func(context.Context) (bool, error), every time.Duration, ) (string, error)
Wait blocks until the read of draft ends and returns the record's path. The draft's removal is the end, because Finish writes the record first. paneOpen is asked only while the draft remains, so a reader that ended in the same moment its pane closed still counts as finished.
Types ¶
type Draft ¶
A Draft is the whole explanation. It opens with a `# ` title and the subject block, then holds the beats, each under a `## <n>` heading.
type Fork ¶
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.
type Question ¶
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 ¶
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.