draft

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 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 draft is learning's third stage (design 08 section 2): one prompt-only session per run turns a batch of signals into proposed map entries, with the learning skill, under an appetite whose circuit breaker stops the session and keeps nothing.

Index

Constants

View Source
const DefaultAppetite = 60000

DefaultAppetite is how many tokens one draft session may use when the run names no appetite. It is a first guess, to be tuned from real runs (design 08 section 7, and the decision measure-before-budget).

Variables

This section is empty.

Functions

func Fence

func Fence(w io.Writer, text string)

Fence writes text in a fence longer than any run of backticks in it, so that nothing inside can close it.

func NewSessionID

func NewSessionID() string

NewSessionID returns a fresh version 4 UUID, 8-4-4-4-12 in lower-case hex, for a draft session to run under.

func OneLine

func OneLine(s string) string

OneLine returns s with every run of white space as one space, so a value keeps to its own line of a fenced block.

func Parse

func Parse(text string) ([]Proposal, []Malformed, error)

Parse reads the session's answer: the last fenced json block in text, holding one object with a proposals list. The error, worded to follow "the session's output: ", is for an answer with no such block or one that does not decode. Each item is decoded on its own, refusing unknown keys, so one that is not a proposal becomes a Malformed and the others are kept, in order.

func Prompt

func Prompt(m *mapfile.Map, b Batch) (string, error)

Prompt returns everything the session reads for one batch: the learning skill, then the index, the slices for the batch's capabilities with their decisions and questions, and the signals, each under its own heading. All that others wrote (change messages, capability names from trailers, evidence) sits in fenced blocks nothing inside can close. The same map and batch always give the same text.

Types

type Batch

type Batch struct {
	// Person is the name of the person running Physa (internal/person), or
	// empty when unknown.
	Person string
	// Changes are the changes with signals, newest first, as triage found
	// them.
	Changes []learn.ChangeSignals
	// Capabilities are the capabilities the map holds that the batch's
	// changes serve or its signals are about, each once, sorted.
	Capabilities []string
}

Batch is what one session drafts from: the changes of a run that carry signals, and the capabilities those signals bear on.

func NewBatch

func NewBatch(m *mapfile.Map, r learn.Result) Batch

NewBatch returns the batch of r: its changes with signals, and the capabilities they bear on, which are each change's Capability trailers and each signal's capability. Names m does not hold as a capability are left out.

func (Batch) CapabilityCount

func (b Batch) CapabilityCount() int

CapabilityCount is how many capabilities the batch bears on.

func (Batch) ChangeCount

func (b Batch) ChangeCount() int

ChangeCount is how many changes carry the batch's signals.

func (Batch) Cuts

func (b Batch) Cuts() string

Cuts says in one clause what Prompt cut or left out of what it quotes of the batch, or returns "" when it cut nothing.

func (Batch) Empty

func (b Batch) Empty() bool

Empty reports whether the batch holds no signal, so that no session is worth starting.

func (Batch) SignalCount

func (b Batch) SignalCount() int

SignalCount is how many signals the batch holds.

type Malformed

type Malformed struct {
	// Raw is the item as the session wrote it.
	Raw string
	// Reason says what is wrong with it.
	Reason string
}

Malformed is one item of the session's output that is not a proposal, kept so that it is reported and never dropped silently.

type Outcome

type Outcome struct {
	// Text is the agent's answer; empty when the circuit breaker stopped the
	// session, whatever had arrived.
	Text string
	// Model is the name the agent reported for what it ran on.
	Model string
	// Tokens is what the session used: its result's count, or the last the
	// agent reported when it ended without one.
	Tokens adapter.Tokens
	// Stopped says the circuit breaker stopped the session at the appetite.
	Stopped bool
	// SessionID is the id the session ran under, as the agent reported it;
	// empty when the agent did not say.
	SessionID string
}

Outcome is how one draft session ended.

func Run

func Run(ctx context.Context, a adapter.Adapter, prompt string, appetite int64, sessionID string) (Outcome, error)

Run starts one prompt-only session of a with prompt, in a fresh empty directory that is removed afterwards, and waits for it. The appetite counts every token in and out, cached input included: when a report of the session's tokens reaches it, the circuit breaker stops the session and the Outcome is Stopped, with no text and a nil error. Any other failure is the adapter's own error (adapter.ErrNotInstalled, adapter.ErrFailed), with the tokens the session reported when it reported any. sessionID is the id the session is asked to run under (see NewSessionID); the Outcome's SessionID is the one the agent reported, which is empty for an agent that cannot take one.

type Proposal

type Proposal struct {
	// Kind is rule, decision, question or promise.
	Kind string `json:"kind"`
	// Capability is the capability whose file the entry goes in.
	Capability string `json:"capability"`
	// Section is Rules, Decisions, Questions or promise.
	Section string `json:"section"`
	// Signal names the signal of the batch the proposal comes from.
	Signal SignalRef `json:"signal"`
	// Changes are the short ids of the changes the entry is anchored to.
	Changes []string `json:"changes"`
	// Entry is the entry in the map's form, or the new promise.
	Entry string `json:"entry"`
}

Proposal is one map entry the session proposes, as the learning skill's output contract writes it. Parse checks only its shape; whether it holds against the batch and the map is the next stage's to say.

type SignalRef

type SignalRef struct {
	Kind    string   `json:"kind"`
	Changes []string `json:"changes"`
}

SignalRef names a signal of the batch by its kind and the changes it is about.

Jump to

Keyboard shortcuts

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