observe

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package observe turns what a hook sees - a Bash command and its output, a file written - into typed facts about a run: an issue or PR opened, a commit, a push, a step loaded, a plan or findings file saved.

It only recognises; it never acts. Observers do: the badge reads a few of these to settle what the model would otherwise have to report, and the ledger persists all of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Segments

func Segments(line string) [][]string

Segments splits a command line into its simple commands, each as words with quotes removed: split on `&&`, `||`, `;`, `|`, `&`, newlines and parentheses outside quotes. Redirections and their targets are dropped, here-document bodies and comments skipped, and `$(...)` kept inside its word. It reads, never evaluates: no expansion, no globbing.

func Stamp

func Stamp(o Observation, session, cwd string, at time.Time)

Stamp fills an observation's Meta.

Types

type Committed

type Committed struct {
	Meta

	Branch  string `json:"branch"`
	SHA     string `json:"sha"` // abbreviated, as git printed it
	Subject string `json:"subject"`
}

Committed is a `git commit` that made a commit, seen by its `[branch sha] subject` line.

func (*Committed) Kind

func (*Committed) Kind() string

type FindingsWritten

type FindingsWritten struct {
	Meta

	Path  string `json:"path"`
	Task  string `json:"task"`
	Round string `json:"round"`
}

FindingsWritten is a review's findings file saved under the storage root's reviews/<task>/.

func (*FindingsWritten) Kind

func (*FindingsWritten) Kind() string

type Finished

type Finished struct {
	Meta

	Args []string `json:"args"`
}

Finished is an `f10 finish` call, with its arguments.

func (*Finished) Kind

func (*Finished) Kind() string

type IssueCreated

type IssueCreated struct {
	Meta

	Host string `json:"host"` // gh or glab
	URL  string `json:"url"`
}

IssueCreated is a tracker issue opened with `gh issue create` or `glab issue create`, seen by the url it printed.

func (*IssueCreated) Kind

func (*IssueCreated) Kind() string

type Meta

type Meta struct {
	Session string    `json:"session"`
	Cwd     string    `json:"cwd,omitempty"`
	At      time.Time `json:"at"`
}

Meta is what every observation carries: the session it happened in, the directory it ran from, and when the hook saw it.

func MetaOf

func MetaOf(o Observation) Meta

MetaOf reads an observation's Meta.

type Observation

type Observation interface {
	Kind() string
	// contains filtered or unexported methods
}

An Observation is one fact. The set is closed: only this package's types satisfy it, so an observer's type switch can be exhaustive.

func FromBash

func FromBash(command, stdout, stderr string) []Observation

FromBash reads one Bash tool call: the command line as the model wrote it and what it printed. A creation, commit or push counts only with its evidence in the output - the url on stdout, the commit line, a moved ref - which covers failures and dry runs without an exit code the payload may not carry. Urls are read from stdout alone: `gh pr create` names an existing PR on stderr when it refuses. Meta is left for the caller to Stamp.

func FromMoves

func FromMoves(command, cwd, storageRoot string) []Observation

FromMoves reads the `mv` commands in a Bash call for plans moved into plans/archive/, counted only when the archived file exists afterwards. Relative paths resolve against cwd; storageRoot is matched as in FromWrite. Meta is left for the caller to Stamp.

func FromWrite

func FromWrite(path, storageRoot string) Observation

FromWrite reads one file written with Write or Edit. storageRoot is the checkout's resolved storage root, in-repo or out-of-tree; empty falls back to the `.f10/` the path itself holds. Plan archives are moves, not new plans, and are not matched. Meta is left for the caller to Stamp.

type Observer

type Observer interface {
	Observe(ctx context.Context, o Observation) error
}

An Observer receives observations, one at a time, in the order a hook saw them. An error is the observer's own; the hook carries on.

type PRCreated

type PRCreated struct {
	Meta

	Host string `json:"host"`
	URL  string `json:"url"`
}

PRCreated is a PR or MR opened with `gh pr create` or `glab mr create`.

func (*PRCreated) Kind

func (*PRCreated) Kind() string

type PlanArchived

type PlanArchived struct {
	Meta

	From string `json:"from"`
	To   string `json:"to"`
	Task string `json:"task"`
}

PlanArchived is a plan moved into the storage root's plans/archive/, the plan step's way of superseding it.

func (*PlanArchived) Kind

func (*PlanArchived) Kind() string

type PlanWritten

type PlanWritten struct {
	Meta

	Path string `json:"path"`
	Task string `json:"task"`
}

PlanWritten is a plan file saved under the storage root's plans/.

func (*PlanWritten) Kind

func (*PlanWritten) Kind() string

type Pushed

type Pushed struct {
	Meta

	Remote string   `json:"remote,omitempty"` // the `To <remote>` line
	Refs   []string `json:"refs"`             // each `src -> dst` as printed
}

Pushed is a `git push` that moved at least one ref.

func (*Pushed) Kind

func (*Pushed) Kind() string

type SessionStopped

type SessionStopped struct {
	Meta

	Task     string `json:"task,omitempty"`
	Phase    string `json:"phase"`
	Status   string `json:"status"`
	Leaf     string `json:"leaf,omitempty"`
	Backstop bool   `json:"backstop,omitempty"`
}

SessionStopped is a turn ending with a run in the session, at the phase, status and leaf its state held before the Stop backstop ran. Backstop says the backstop then promoted it to done.

func (*SessionStopped) Kind

func (*SessionStopped) Kind() string

type SkillStarted

type SkillStarted struct {
	Meta

	Skill string `json:"skill"`
	Args  string `json:"args,omitempty"`
}

SkillStarted is an f10 skill starting: typed, which Claude Code expands, or called by the model through the Skill tool.

func (*SkillStarted) Kind

func (*SkillStarted) Kind() string

type StepStarted

type StepStarted struct {
	Meta

	Steps []string `json:"steps"`
}

StepStarted is `f10-load-project.sh` loading steps: ship loads each pipeline step right before it runs, so one step named is that step starting. No steps is a load for a pipeline with no step to name.

func (*StepStarted) Kind

func (*StepStarted) Kind() string

type VerdictWritten

type VerdictWritten struct {
	Meta

	Path string `json:"path"`
	Key  string `json:"key"`
	N    string `json:"n"`
}

VerdictWritten is a judge's verdict file saved under the storage root's verdicts/<key>/, key the task id or, for an idea, a slug.

func (*VerdictWritten) Kind

func (*VerdictWritten) Kind() string

Jump to

Keyboard shortcuts

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