observe

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 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. It only recognises; observers act on them: the badge settles what the model would otherwise report.

Index

Constants

View Source
const (
	WaitTurn       = "turn"
	WaitQuestion   = "question"
	WaitPermission = "permission"
)

Wait reasons: a turn ended and the user has not answered, an AskUserQuestion open, a permission dialog open.

Variables

This section is empty.

Functions

func Segments

func Segments(line string) [][]string

Segments splits a command line into its simple commands as unquoted words. Redirections with their targets, heredoc bodies and comments are dropped, `$(...)` stays inside its word. It reads, never evaluates: no expansion.

func Stamp

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

Stamp fills an observation's Meta, which the From* readers leave empty.

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. A creation, commit or push counts only with its evidence in the output, so failures and dry runs need no exit code; urls come from stdout alone: a refused `gh pr create` names a PR on stderr.

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.

func FromWrite

func FromWrite(path, storageRoot string) Observation

FromWrite reads one file written with Write or Edit. storageRoot is the resolved storage root; empty falls back to the `.f10/` the path holds. Plan archives are moves, not new plans, and are not matched.

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

type WaitEnded added in v0.45.0

type WaitEnded struct {
	Meta

	Reason string `json:"reason"`
	Tool   string `json:"tool,omitempty"`
	By     string `json:"by"`
}

WaitEnded is that wait over, By the hook event that ended it.

func (*WaitEnded) Kind added in v0.45.0

func (*WaitEnded) Kind() string

type WaitStarted added in v0.45.0

type WaitStarted struct {
	Meta

	Reason string `json:"reason"`
	Tool   string `json:"tool,omitempty"`
}

WaitStarted is a run starting to wait on the user. Tool names the tool a question or permission dialog belongs to.

func (*WaitStarted) Kind added in v0.45.0

func (*WaitStarted) Kind() string

Jump to

Keyboard shortcuts

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