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) string
- 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`.
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.
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.
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.