Documentation
¶
Overview ¶
Package ledger is f10's local record of what runs did: an append-only events table in ~/.f10/f10.db, outside every repo so stealth is unaffected, and task_refs, overwritten in place. A write never fails its caller: rows go to a spool beside the database, replayed in by the next opener.
Index ¶
- Constants
- Variables
- func Decode[T proto.Message](e Event) (T, error)
- func DecodeMessage(e Event) (proto.Message, error)
- func Known(kind string) bool
- func LookupRefs(ctx context.Context, project string, ids []string) map[string]TaskRef
- func MachineID(dir string) string
- func NormalizeRemote(url string) string
- func Path() string
- func Record(events ...Event)
- func RememberRefs(ctx context.Context, project string, refs ...TaskRef)
- func Schema() ([]byte, error)
- func Sync(ctx context.Context) error
- func SyncAt(ctx context.Context, path string) error
- type AgentProfile
- type Ask
- type AskAnsweredPayload
- type AskQuestion
- type AskRaisedPayload
- type Claim
- type ClaimPayload
- type CommittedPayload
- type Event
- type Filter
- type FindingVerdictPayload
- type JudgeVerdictPayload
- type Ledger
- func (l *Ledger) Append(ctx context.Context, events ...Event)
- func (l *Ledger) Close() error
- func (l *Ledger) Count(ctx context.Context, f Filter) (int64, error)
- func (l *Ledger) Last(ctx context.Context, f Filter) (Event, bool, error)
- func (l *Ledger) List(ctx context.Context, f Filter) ([]Event, error)
- func (l *Ledger) Refs(ctx context.Context, project string, ids []string) (map[string]TaskRef, error)
- func (l *Ledger) Remember(ctx context.Context, project string, refs ...TaskRef) error
- func (l *Ledger) ScopeEvents(ctx context.Context, s Scope) ([]Event, error)
- func (l *Ledger) Sessions(ctx context.Context, s Scope) ([]string, error)
- type Narrow
- type Observer
- type PROpenedPayload
- type Page
- type Payload
- type Place
- type Placed
- type PlanSavedPayload
- type PlanSupersededPayload
- type PushedPayload
- type RegressionClaimedPayload
- type RegressionFoundPayload
- type ReviewRoundOpenedPayload
- type RunStartedPayload
- type Scope
- type SessionStoppedPayload
- type SpikeSavedPayload
- type StepEnteredPayload
- type Tail
- type TaskCapturedPayload
- type TaskFinishedPayload
- type TaskHaltedPayload
- type TaskRef
- type TaskSizedPayload
- type Tokens
- type TurnUsedPayload
- type Usage
- type WaitEndedPayload
- type WaitStartedPayload
- type WatchReportedPayload
Constants ¶
const ( BusyAsync = 3 * time.Second BusySync = 200 * time.Millisecond )
Busy timeouts: under the 5s hook timeout for async writers, so a contended write spools instead of the hook being killed; short for a synchronous hook, so a busy ledger never delays a skill's start.
const ( Observed = "observed" Artifact = "artifact" Claimed = "claimed" )
Sources: what the hook saw, what an artifact holds, what the model said.
const ( RunStarted = "run_started" TaskCaptured = "task_captured" StepEntered = "step_entered" Committed = "committed" Pushed = "pushed" PROpened = "pr_opened" TaskFinished = "task_finished" TaskHalted = "task_halted" // drive's, not a hook's: a task it stopped SessionStopped = "session_stopped" TurnUsed = "turn_used" // the tokens a turn spent WaitStarted = "wait_started" WaitEnded = "wait_ended" TaskSized = "task_sized" // finish's: the branch's diffstat before it lands RegressionFound = "regression_found" // a bug task's cause traced to the task that shipped it RegressionClaimed = "regression_claimed" // a task whose text names the task it regressed AskRaised = "ask_raised" // an agent stopped on a question, from the inbox AskAnswered = "ask_answered" // the first answer closed it WatchReported = "watch_reported" // a fact the watcher told, once PlanSaved = "plan_saved" PlanSuperseded = "plan_superseded" SpikeSaved = "spike_saved" ReviewRoundOpened = "review_round_opened" FindingVerdict = "finding_verdict" JudgeVerdict = "judge_verdict" StateSet = "state_set" StateTask = "state_task" StateNote = "state_note" StateAsk = "state_ask" StateWait = "state_wait" StateStop = "state_stop" StatePipeline = "state_pipeline" StateDone = "state_done" // a phaseless step's report is out: the drive's end signal StateFinal = "state_final" )
Kinds, by source.
const AfterPage = 500
AfterPage bounds one After, so a stream far behind reads a long ledger a page at a time instead of whole.
const PathEnv = "F10_LEDGER"
PathEnv overrides the database's path; the spool and machine id live beside it, so a test pointing it at a temp dir touches nothing else.
Variables ¶
var ErrNewerVersion = errors.New("ledger: payload from a newer version")
ErrNewerVersion marks a row a newer f10 wrote: Decode returns what the current message could read of it.
Functions ¶
func Decode ¶ added in v0.61.0
Decode reads e's payload as T, its kind's current message, upcasting an older row. A row from a newer version decodes as far as T can read it and returns ErrNewerVersion with the value.
func DecodeMessage ¶ added in v0.62.0
DecodeMessage is Decode for a reader that takes any kind, such as the API.
func LookupRefs ¶ added in v0.44.0
LookupRefs reads project's rows for ids without writing anything: refs are written directly, never spooled, so no replay is needed. A missing database, or one no run has migrated to hold refs yet, knows none.
func MachineID ¶
MachineID is this machine's id, generated once into <dir>/machine-id. Created exclusively, so two first runs read back the same id. Empty when the directory cannot be written.
func NormalizeRemote ¶
NormalizeRemote turns a remote url into a project id, so one repo cloned over ssh and over https is one project: scheme, user, port and `.git` dropped, scp-style `host:path` read as `host/path`, the host lowercased.
func Path ¶
func Path() string
Path is the database file: F10_LEDGER, else f10.db in the user's f10 dir (~/.f10, or F10_USER_DIR).
func Record ¶
func Record(events ...Event)
Record spools events for the next replay point: a write never opens the database, so no caller waits on a migration or a busy lock.
func RememberRefs ¶ added in v0.44.0
RememberRefs opens the ledger at Path, writes refs and closes it. Like Record it never fails its caller, but a ref that cannot be written is dropped rather than spooled: the next read of the task rebuilds it.
func Schema ¶ added in v0.61.0
Schema is the JSON Schema of every kind's payload, every version, generated from the payload messages' descriptors: docs/ledger.schema.json is its output.
Types ¶
type AgentProfile ¶ added in v0.61.0
type AgentProfile = f10v1.AgentProfile
AgentProfile and the four below are the messages payloads nest.
type Ask ¶ added in v0.62.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type AskAnsweredPayload ¶ added in v0.62.0
type AskAnsweredPayload = agentsv1.AskAnswered
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type AskQuestion ¶ added in v0.62.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type AskRaisedPayload ¶ added in v0.62.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Claim ¶ added in v0.58.0
Claim is a recorded `f10 state` call: its arguments as the model typed them, and the run it left.
func DecodeClaim ¶ added in v0.58.0
DecodeClaim reads a claim row back; the row itself gives the session, task, checkout and time.
type ClaimPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
func EncodeClaim ¶ added in v0.58.0
func EncodeClaim(r *state.Run, args []string) *ClaimPayload
EncodeClaim is the payload of a claim row.
type CommittedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Event ¶
type Event struct {
ID string `db:"id,pk" json:"id"`
Machine string `db:"machine,immutable" json:"machine"`
At time.Time `db:"at,immutable" json:"at"`
Project string `db:"project,immutable" json:"project"`
ProjectLocal bool `db:"project_local,immutable" json:"project_local"`
Checkout string `db:"checkout,immutable" json:"checkout"`
Branch string `db:"branch,immutable" json:"branch"`
Session string `db:"session,immutable" json:"session"`
Task string `db:"task,immutable" json:"task"`
Kind string `db:"kind,immutable" json:"kind"`
Source string `db:"source,immutable" json:"source"`
Payload payloadCol `db:"payload,immutable" json:"payload"`
// generated from the payload (hotkeys.go): filtered on, never written
PPath *string `db:"p_path,readonly" json:"-"`
PRound *string `db:"p_round,readonly" json:"-"`
PFinding *string `db:"p_finding,readonly" json:"-"`
}
Event is one row. Every column but the id is immutable, so r3 has no update path for it and an upsert of a known id does nothing: the table only grows.
func NewEvent ¶ added in v0.61.0
NewEvent is a row of kind carrying payload, which must be the kind's current message; the caller fills the other columns.
func ReadEvents ¶ added in v0.58.0
ReadEvents is the events f matches in the database at path, oldest first, what writers spooled included. A missing database has no events.
func ReadScope ¶ added in v0.61.0
ReadScope is ScopeEvents in the database at path, what writers spooled included. A missing database has no events.
func (Event) Backstop ¶ added in v0.58.0
Backstop reports a session_stopped row the backstop wrote, not a Stop hook.
func (Event) Bundle ¶ added in v0.58.0
Bundle is the bundle the event's branch ships when the event's task leads it, else nil.
func (Event) FinishedTask ¶ added in v0.58.0
FinishedTask is the task a task_finished row names, as typed: finish's first non-flag argument, else the row's task, which the observer takes from the session's run and so names another task when finish ran from elsewhere.
func (Event) OnTask ¶ added in v0.58.0
OnTask reports whether the event is the task's: its own, or its bundle's.
func (Event) Reason ¶ added in v0.58.0
Reason is why a wait started or ended, or why drive halted a task.
type Filter ¶
type Filter struct {
Project string
Task string
Session string
Kind string
Path string // the payload's path: a plan, findings or verdict file
Round string // the payload's round: a review round
Checkout string
Since time.Time
IDs []string
Tasks []string
Sessions []string
Kinds []string
}
Filter narrows List; an empty field matches every row. Sessions is the exception: a non-nil empty slice, a lookup that found no session, matches none, so a bounded read never widens to the whole table.
type FindingVerdictPayload ¶ added in v0.61.0
type FindingVerdictPayload = f10v1.FindingVerdict
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type JudgeVerdictPayload ¶ added in v0.61.0
type JudgeVerdictPayload = f10v1.JudgeVerdict
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Ledger ¶
type Ledger struct {
// contains filtered or unexported fields
}
A Ledger is an open database.
func Open ¶
Open opens the database at path for writing: it creates the file and runs the migrations. With replay it also replays the spool, which a synchronous hook leaves to the next async writer: a backlog has no bound.
func OpenRead ¶
OpenRead opens an existing database read-only: no migration, no replay, so reading never writes. A missing file is fs.ErrNotExist.
func (*Ledger) Append ¶
Append writes events, ids and machine filled in where empty. An event the database refuses goes to the spool with the ones after it.
func (*Ledger) Last ¶ added in v0.61.0
Last returns the newest event f matches, and false when none does.
func (*Ledger) Refs ¶ added in v0.44.0
func (l *Ledger) Refs(ctx context.Context, project string, ids []string) (map[string]TaskRef, error)
Refs is the rows project holds for ids, by id; an id never read is absent.
func (*Ledger) Remember ¶ added in v0.44.0
Remember writes refs for project, each replacing the row for its id. A ref with no title is skipped: it would only hide a later lookup's miss. One with no url keeps the stored one, since some reads give a title alone.
func (*Ledger) ScopeEvents ¶ added in v0.61.0
ScopeEvents is every event of the sessions s covers, oldest first, and the rows of its tasks written outside any session: finish run by the daemon records a task's size with no session.
type Narrow ¶ added in v0.62.0
Narrow picks the rows a tail sends; an empty field matches every row. With a project set, a row with no project (an ask's) goes to Orphan, and is dropped when Orphan is nil.
type Observer ¶
type Observer struct {
StateDir string
Busy time.Duration
NoReplay bool // a synchronous hook holds the prompt: the spool waits for a later writer
// TaskID is the tracker task id a created issue's url names.
TaskID func(ctx context.Context, cwd, url string) string
// contains filtered or unexported fields
}
Observer records a hook's observations to the spool; only one that compares against prior rows (a stop, a findings or a verdict file) opens the ledger, so most hooks never touch SQLite.
type PROpenedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Page ¶ added in v0.62.0
A Page is one After read: the rows that matched, the cursor of the last row read whether it matched or not, and whether more rows may wait.
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
Payload is a row's kind-specific detail as stored: the protojson object of its kind's payload message, plus v. Only this package sees the keys; every other reader goes through Decode, so a key has one definition. It keeps the bytes as stored, so a read decodes them once, into the message.
func (Payload) MarshalJSON ¶ added in v0.61.0
func (*Payload) UnmarshalJSON ¶ added in v0.61.0
type Place ¶
type Place struct {
Project string
ProjectLocal bool // no remote: the main checkout's path stands in
Checkout string
Branch string
}
Place is where an event happened: the project, the checkout and its branch.
type Placed ¶ added in v0.62.0
A Placed event is a row with its cursor: its place in insertion order, which ids do not follow, since a spooled row is inserted after its id is minted and other machines mint ids on their own clocks.
type PlanSavedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type PlanSupersededPayload ¶ added in v0.61.0
type PlanSupersededPayload = f10v1.PlanSuperseded
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type PushedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type RegressionClaimedPayload ¶ added in v0.61.0
type RegressionClaimedPayload = f10v1.RegressionClaimed
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type RegressionFoundPayload ¶ added in v0.61.0
type RegressionFoundPayload = f10v1.RegressionFound
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type ReviewRoundOpenedPayload ¶ added in v0.61.0
type ReviewRoundOpenedPayload = f10v1.ReviewRoundOpened
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type RunStartedPayload ¶ added in v0.61.0
type RunStartedPayload = f10v1.RunStarted
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Scope ¶ added in v0.61.0
type Scope struct {
Project string
Tasks []string // the sessions that recorded any of these tasks
Since time.Time // the sessions active since, plus every session of their tasks
}
A Scope is the sessions a read covers. Step timing pairs each session's steps with its waits, and a wait may carry no task or another one, so a reader needs whole sessions and nothing outside them.
func SinceScope ¶ added in v0.61.0
SinceScope is every session of the project active at or after cutoff, and every session of the tasks those sessions carry: a task active lately is measured over its whole history.
type SessionStoppedPayload ¶ added in v0.61.0
type SessionStoppedPayload = f10v1.SessionStopped
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type SpikeSavedPayload ¶ added in v0.61.0
type SpikeSavedPayload = f10v1.SpikeSaved
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type StepEnteredPayload ¶ added in v0.61.0
type StepEnteredPayload = f10v1.StepEntered
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Tail ¶ added in v0.62.0
type Tail struct {
// contains filtered or unexported fields
}
A Tail reads one database's rows in insertion order for a stream, keeping its read handle between reads, so a stream polling often opens it once.
func OpenTail ¶ added in v0.62.0
OpenTail is a tail of the database at path; nothing opens until a read, and a database that does not exist yet reads as empty.
type TaskCapturedPayload ¶ added in v0.61.0
type TaskCapturedPayload = f10v1.TaskCaptured
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type TaskFinishedPayload ¶ added in v0.61.0
type TaskFinishedPayload = f10v1.TaskFinished
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type TaskHaltedPayload ¶ added in v0.61.0
type TaskHaltedPayload = f10v1.TaskHalted
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type TaskRef ¶ added in v0.44.0
type TaskRef struct {
Key string `db:"id,pk" json:"-"`
Project string `db:"project,immutable" json:"project"`
ID string `db:"task,immutable" json:"id"`
Title string `db:"title" json:"title"`
URL string `db:"url" json:"url"`
SeenAt time.Time `db:"seen_at" json:"seen_at"`
// Closed is read fresh on every lookup, never stored: a cached state
// would keep a reopened task closed until the next tracker read.
Closed bool `db:"-" json:"closed,omitempty"`
}
A TaskRef is a task's title and url as f10 last read them from the tracker. Unlike an event it is overwritten by the next read: a renamed task stays stale until f10 reads it again.
type TaskSizedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Tokens ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type TurnUsedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type Usage ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type WaitEndedPayload ¶ added in v0.61.0
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type WaitStartedPayload ¶ added in v0.61.0
type WaitStartedPayload = f10v1.WaitStarted
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.
type WatchReportedPayload ¶ added in v0.62.0
type WatchReportedPayload = f10v1.WatchReported
Each kind's payload is its f10.v1 message (proto/f10/v1/events.proto), stored as protojson. Within a version a field is only added, which buf breaking enforces; a real break is a new message with an upcaster. The aliases name each kind's current message for readers.