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 any](e Event) (T, error)
- 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 Claim
- type ClaimPayload
- type ClaimV1
- type CommittedPayload
- type CommittedV1
- type Event
- type Filter
- type FindingVerdictPayload
- type FindingVerdictV1
- type JudgeVerdictPayload
- type JudgeVerdictV1
- 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 Observer
- type PROpenedPayload
- type PROpenedV1
- type Payload
- type Place
- type PlanSavedPayload
- type PlanSavedV1
- type PlanSupersededPayload
- type PlanSupersededV1
- type PushedPayload
- type PushedV1
- type RegressionClaimedPayload
- type RegressionClaimedV1
- type RegressionFoundPayload
- type RegressionFoundV1
- type ReviewRoundOpenedPayload
- type ReviewRoundOpenedV1
- type RunContext
- type RunStartedPayload
- type RunStartedV1
- type RunStartedV2
- type Scope
- type SessionStoppedPayload
- type SessionStoppedV1
- type SessionStoppedV2
- type SpikeSavedPayload
- type SpikeSavedV1
- type StepEnteredPayload
- type StepEnteredV1
- type TaskCapturedPayload
- type TaskCapturedV1
- type TaskFinishedPayload
- type TaskFinishedV1
- type TaskHaltedPayload
- type TaskHaltedV1
- type TaskRef
- type TaskSizedPayload
- type TaskSizedV1
- type Tokens
- type TurnUsedPayload
- type TurnUsedV1
- type Usage
- type WaitEndedPayload
- type WaitEndedV1
- type WaitStartedPayload
- type WaitStartedV1
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 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 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 struct could read of it.
Functions ¶
func Decode ¶ added in v0.61.0
Decode reads e's payload as T, its kind's current struct, 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 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 registered structs: docs/ledger.schema.json is its output.
Types ¶
type AgentProfile ¶ added in v0.61.0
type AgentProfile struct {
Kind string `json:"kind,omitempty"`
Model string `json:"model,omitempty"`
Effort string `json:"effort,omitempty"`
}
AgentProfile is the profile f10 started the agent with, as the branch records it; an empty segment was left to the agent's default.
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
type ClaimPayload = ClaimV1
func EncodeClaim ¶ added in v0.58.0
func EncodeClaim(r *state.Run, args []string) ClaimPayload
EncodeClaim is the payload of a claim row.
type ClaimV1 ¶ added in v0.61.0
type ClaimV1 struct {
Args []string `json:"args"`
Capture string `json:"capture"`
Plan string `json:"plan"`
Ship string `json:"ship"`
Leaf string `json:"leaf,omitempty"`
Final string `json:"final,omitempty"`
Note string `json:"note,omitempty"`
Next string `json:"next,omitempty"`
Ask string `json:"ask,omitempty"`
Wait string `json:"wait,omitempty"`
Done string `json:"done,omitempty"`
Pipeline []string `json:"pipeline,omitempty"`
Labels []string `json:"labels,omitempty"`
At int `json:"at,omitempty"`
}
ClaimV1 is a recorded `f10 state` call, every state_* kind: its arguments and the run it left. Session, task, checkout and time are the row's.
type CommittedPayload ¶ added in v0.61.0
type CommittedPayload = CommittedV1
type CommittedV1 ¶ added in v0.61.0
type CommittedV1 struct {
Branch string `json:"branch"`
SHA string `json:"sha"`
Subject string `json:"subject"`
}
CommittedV1 is a commit made.
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 struct; 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 = FindingVerdictV1
type FindingVerdictV1 ¶ added in v0.61.0
type FindingVerdictV1 struct {
Round string `json:"round"`
Finding string `json:"finding"`
Title string `json:"title"`
Verdict string `json:"verdict,omitempty"`
Category string `json:"category,omitempty"`
Reason string `json:"reason,omitempty"`
Status string `json:"status,omitempty"`
}
FindingVerdictV1 is a finding whose verdict or status changed.
type JudgeVerdictPayload ¶ added in v0.61.0
type JudgeVerdictPayload = JudgeVerdictV1
type JudgeVerdictV1 ¶ added in v0.61.0
type JudgeVerdictV1 struct {
Path string `json:"path"`
Key string `json:"key"`
N string `json:"n"`
Subject string `json:"subject,omitempty"`
Verdict string `json:"verdict,omitempty"`
Reason string `json:"reason,omitempty"`
Run string `json:"run,omitempty"`
Decision string `json:"decision,omitempty"`
Blind bool `json:"blind,omitempty"`
Idea bool `json:"idea,omitempty"`
ParseError string `json:"parse_error,omitempty"`
}
JudgeVerdictV1 is a verdict file's verdict and decision.
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 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
type PROpenedPayload = PROpenedV1
type PROpenedV1 ¶ added in v0.61.0
PROpenedV1 is a PR or MR opened.
type Payload ¶
type Payload struct {
// contains filtered or unexported fields
}
Payload is a row's kind-specific detail as stored: the JSON object of its kind's payload struct, 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 struct.
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 PlanSavedPayload ¶ added in v0.61.0
type PlanSavedPayload = PlanSavedV1
type PlanSavedV1 ¶ added in v0.61.0
PlanSavedV1 is a plan file written.
type PlanSupersededPayload ¶ added in v0.61.0
type PlanSupersededPayload = PlanSupersededV1
type PlanSupersededV1 ¶ added in v0.61.0
type PlanSupersededV1 struct {
From string `json:"from"`
To string `json:"to"`
Task string `json:"task"`
}
PlanSupersededV1 is a plan moved into the archive.
type PushedPayload ¶ added in v0.61.0
type PushedPayload = PushedV1
type RegressionClaimedPayload ¶ added in v0.61.0
type RegressionClaimedPayload = RegressionClaimedV1
type RegressionClaimedV1 ¶ added in v0.61.0
type RegressionClaimedV1 struct {
OriginTask string `json:"origin_task"`
Text string `json:"text,omitempty"`
}
RegressionClaimedV1 is a task whose own text names the task it is a regression of: the user's word, kept apart from what debug finds.
type RegressionFoundPayload ¶ added in v0.61.0
type RegressionFoundPayload = RegressionFoundV1
type RegressionFoundV1 ¶ added in v0.61.0
type RegressionFoundV1 struct {
OriginTask string `json:"origin_task"`
Origin string `json:"origin"`
Commit string `json:"commit,omitempty"`
Lines []string `json:"lines,omitempty"`
FoundBy string `json:"found_by"`
Confidence string `json:"confidence"`
Class string `json:"class,omitempty"`
Round string `json:"round,omitempty"`
Finding string `json:"finding,omitempty"`
Repro string `json:"repro"`
Note string `json:"note,omitempty"`
}
RegressionFoundV1 is a bug task's root cause traced to the commit and the task that introduced it, with how review let it through. Lines are `path:start-end`; Round and Finding name the skipped finding.
type ReviewRoundOpenedPayload ¶ added in v0.61.0
type ReviewRoundOpenedPayload = ReviewRoundOpenedV1
type ReviewRoundOpenedV1 ¶ added in v0.61.0
type ReviewRoundOpenedV1 struct {
Path string `json:"path"`
Round string `json:"round"`
Reviewed string `json:"reviewed,omitempty"`
Reviewer string `json:"reviewer,omitempty"`
Verdict string `json:"verdict,omitempty"`
Categories map[string]int `json:"categories,omitempty"`
ParseError string `json:"parse_error,omitempty"`
}
ReviewRoundOpenedV1 is a findings file's round, once per reviewed sha; ParseError alone with Path and Round when the file did not parse.
type RunContext ¶ added in v0.61.0
type RunContext struct {
F10Version string `json:"f10_version,omitempty"`
Model string `json:"model,omitempty"`
Agent string `json:"agent,omitempty"`
Profile AgentProfile `json:"profile,omitzero"`
}
RunContext is what a run ran on, each key absent when the hook could not tell. Its keys are part of every version that embeds it, so changing one is a new version of each.
type RunStartedPayload ¶ added in v0.61.0
type RunStartedPayload = RunStartedV2
type RunStartedV1 ¶ added in v0.61.0
RunStartedV1 is an f10 skill starting, with its arguments as typed.
type RunStartedV2 ¶ added in v0.61.0
type RunStartedV2 struct {
RunContext
Skill string `json:"skill"`
Args string `json:"args,omitempty"`
}
RunStartedV2 adds what ran the skill.
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 = SessionStoppedV2
type SessionStoppedV1 ¶ added in v0.61.0
type SessionStoppedV1 struct {
Task string `json:"task,omitempty"`
Phase string `json:"phase"`
Status string `json:"status"`
Leaf string `json:"leaf,omitempty"`
Backstop bool `json:"backstop,omitempty"`
}
SessionStoppedV1 is a turn ending, at the run's phase, status and leaf.
type SessionStoppedV2 ¶ added in v0.61.0
type SessionStoppedV2 struct {
RunContext
Task string `json:"task,omitempty"`
Phase string `json:"phase"`
Status string `json:"status"`
Leaf string `json:"leaf,omitempty"`
Backstop bool `json:"backstop,omitempty"`
}
SessionStoppedV2 adds the run context, set only when it changed since the session's last row that carried one.
type SpikeSavedPayload ¶ added in v0.61.0
type SpikeSavedPayload = SpikeSavedV1
type SpikeSavedV1 ¶ added in v0.61.0
SpikeSavedV1 is a spike report written.
type StepEnteredPayload ¶ added in v0.61.0
type StepEnteredPayload = StepEnteredV1
type StepEnteredV1 ¶ added in v0.61.0
type StepEnteredV1 struct {
Steps []string `json:"steps"`
}
StepEnteredV1 is a step load: the steps it named.
type TaskCapturedPayload ¶ added in v0.61.0
type TaskCapturedPayload = TaskCapturedV1
type TaskCapturedV1 ¶ added in v0.61.0
type TaskCapturedV1 struct {
Host string `json:"host"`
URL string `json:"url,omitempty"`
ID string `json:"id,omitempty"`
}
TaskCapturedV1 is a tracker issue created, by the url or id it printed.
type TaskFinishedPayload ¶ added in v0.61.0
type TaskFinishedPayload = TaskFinishedV1
type TaskFinishedV1 ¶ added in v0.61.0
TaskFinishedV1 is an `f10 finish` call: its arguments, and who ran it when it ran in-process ("drive", "watch").
type TaskHaltedPayload ¶ added in v0.61.0
type TaskHaltedPayload = TaskHaltedV1
type TaskHaltedV1 ¶ added in v0.61.0
type TaskHaltedV1 struct {
Skill string `json:"skill"`
Reason string `json:"reason"`
Attempts []string `json:"attempts,omitempty"`
}
TaskHaltedV1 is a task a drive stopped, with the attempts it counted.
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"`
}
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
type TaskSizedPayload = TaskSizedV1
type TaskSizedV1 ¶ added in v0.61.0
type TaskSizedV1 struct {
Lines int `json:"lines"`
MdLines int `json:"md_lines"`
Files int `json:"files"`
Base string `json:"base"`
}
TaskSizedV1 is a branch's diffstat against its base, before it lands.
type Tokens ¶ added in v0.61.0
type Tokens struct {
Input int `json:"input"`
Output int `json:"output"`
CacheWrite int `json:"cache_write"`
CacheRead int `json:"cache_read"`
}
Tokens is the four token counts of an API usage.
type TurnUsedPayload ¶ added in v0.61.0
type TurnUsedPayload = TurnUsedV1
type TurnUsedV1 ¶ added in v0.61.0
type TurnUsedV1 struct {
Usage Usage `json:"usage"`
}
TurnUsedV1 is the tokens a turn spent: the transcript's usage since the session's previous turn_used row, so a sum over rows is a cost.
type Usage ¶ added in v0.61.0
type Usage struct {
Tokens
ByModel map[string]Tokens `json:"by_model,omitempty"`
Subagents Tokens `json:"subagents,omitzero"`
Through string `json:"through,omitempty"`
}
Usage is one turn's tokens: the session's own messages, by model when the turn used more than one, its subagents' apart, and the last entry counted.
type WaitEndedPayload ¶ added in v0.61.0
type WaitEndedPayload = WaitEndedV1
type WaitEndedV1 ¶ added in v0.61.0
type WaitEndedV1 struct {
Reason string `json:"reason"`
Tool string `json:"tool,omitempty"`
By string `json:"by"`
}
WaitEndedV1 is that wait over, By the hook event that ended it.
type WaitStartedPayload ¶ added in v0.61.0
type WaitStartedPayload = WaitStartedV1
type WaitStartedV1 ¶ added in v0.61.0
WaitStartedV1 is a run starting to wait on the user.