retro

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 13 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 retro computes the weekly retrospective docs/project/THEORY.md calls its instrument: one table, read from the mirror plus local.db, definitions printed under the numbers every time. Nine rows: sessions, resume (median), wip age p85, wip age max, in progress, closed, cycle p50, cycle p85, mismatch. Columns are ISO weeks (Monday 00:00 local, oldest left, the current partial week last) and a change column against the previous week. Everything is a read: the mirror, the status_catalog lookup, and local.visits; nothing here writes or touches a network. Statuses are keyed by id through status_catalog and by status_category — never by the display name beside them.

Degradation is a dash, never an error: an empty status_catalog blanks the weeks only the changelog can answer, an unparseable timestamp drops one row, and a workspace with no self identity resolves resume against any author on the issues the session visited (the footer says so).

Every count carries the issue keys behind it (Bucket.ClosedKeys and friends), so a number is never a dead end: the CLI opens a cell's keys in the running app and the server serves the same document. Key slices are collected in lockstep with each count increment — a count is the length of its slice by construction, mismatch included, where two matching comments on one issue leave the key twice.

Index

Constants

View Source
const (
	MinSessionGap = 5 * time.Minute
	MaxSessionGap = 24 * time.Hour
)

MinSessionGap and MaxSessionGap bound the --session-gap parameter. Below five minutes a session is every coffee refill; above a day the split has stopped meaning anything weekly. Both bounds are named in ParseSessionGap's error so a rejected value says which wall it hit.

View Source
const MaxJSONKeys = 500

MaxJSONKeys caps each key array of the JSON document. It matches internal/jql MaxKeys, the ceiling a keys view may open, so a cell that fits the document also fits the app.

View Source
const SessionGap = 30 * time.Minute

SessionGap splits person reads into sessions: a counted visit more than this after the previous one starts a new session. Exactly the gap is still the same session — strictly greater, so a test can sit on the line. Exported because the server's session strip (internal/server/read.go) walks the same boundary — one owner for the rule. It is also the default of the --session-gap parameter and of Options.SessionGap; Compute is free to be told a different one.

Variables

View Source
var DoneWords = []string{
	"done", "fixed", "merged", "resolved", "shipped",
	"완료", "해결", "머지", "반영", "배포",
	"完了", "修正済み", "対応済み",
	"已完成", "已解决", "已修复",
}

DoneWords is the mismatch heuristic: a comment containing one of these on an issue that is not done now. A heuristic, not a parser — the row says so in its definition, and the words cover the languages this workspace writes (English, Korean, Japanese, Chinese).

Matching is HasDoneWord's job, not a plain Contains: an English word must stand on its own (2026-09-06 — "abandoned" contains "done", "unresolved" contains "resolved"), and a CJK word must not be carrying a negation prefix ("미완료" contains "완료", "未完了" contains "完了"). Both classes pointed the signal backwards, at exactly the comments saying the work is NOT finished.

Functions

func ClaimStands

func ClaimStands(commentAt time.Time, commentOK bool, statusChangedAt string) bool

ClaimStands reports whether a done-word comment is a live claim: it is newer than the issue's last status change. A comment that predates the change was answered by it — the structure moved after the prose — and is not a mismatch now. No recorded status change means nothing answered the claim, so it stands; a comment with no usable stamp cannot be shown to be newer, so it does not.

The web mirror of this signal (web/src/lib/done-words.ts) implements the same truth table; keep the two in lockstep.

func FormatSeconds

func FormatSeconds(secs float64) string

FormatSeconds is the resume cell: 4m 10s / 1h 02m / 45s. Exported for the surfaces that render the same document (the CLI test checks its table against JSON with it).

func HasDoneWord

func HasDoneWord(body string) bool

HasDoneWord reports whether a comment claims the work is finished.

It is a guarded match, not a substring test. Plain containment read every negation as its opposite — measured on the shipped rule, "미완료", "완료되지 않음", "未完了", "not fixed", "unresolved", "unmerged", "abandoned" and "is this done?" all came back true, and each of those is a comment saying the work is NOT done. The guards, in the order they run:

  • a question is not a claim: a body whose last sentence ends in "?" or "?" is rejected outright;
  • quoted lines (Markdown "> ") and fenced code blocks are stripped — quoting someone else's "done" is not saying it;
  • an English word must stand alone (word boundaries), so "abandoned" and "unresolved" no longer carry "done" and "resolved";
  • a CJK word must not carry a negation prefix (미 未 불 非 无 無) or be followed by a negation ("되지 않", "ではない").

The result is a candidate, never a fact (THEORY.md T5). It is precise enough for an affordance that costs one dismissal when wrong; a count shown to a steward needs more than this.

func Max

func Max(vals []float64) (float64, bool)

Max is the largest value, for wip age max beside wip age p85 — the tail the percentile smooths over.

func P85

func P85(vals []float64) (float64, bool)

P85 is the nearest-rank 85th percentile. Integer rank arithmetic ((85n+99)/100) on purpose: 85*20/100 in floats lands on 17.000000000000004 and a ceil rounds a hair high.

func ParseSessionGap

func ParseSessionGap(s string) (time.Duration, error)

ParseSessionGap accepts a Go duration (30m, 1h30m, 90m) between MinSessionGap and MaxSessionGap, naming both bounds in every rejection — the same posture as ParseSince: a usage error the caller wraps, never a silent default.

func ParseSince

func ParseSince(s string) (time.Duration, error)

ParseSince accepts <N>d or <N>w, 1..365 days equivalent. Anything else is a usage error (the caller wraps it), never a silent default.

Types

type Bucket

type Bucket struct {
	From    time.Time
	To      time.Time
	Partial bool

	Sessions int
	Resume   *float64 // median seconds to the first own write
	ResumeK  int      // sessions in this bucket that had a write
	ResumeN  int      // sessions in this bucket
	WipP85   *float64 // days, nearest-rank 85th percentile
	WipMax   *float64 // days, the oldest in-progress issue at week end
	InProg   *int
	Closed   *int
	CycleP50 *float64 // days, median cycle of the week's closures
	CycleP85 *float64 // days, nearest-rank 85th percentile of the same
	Mismatch int

	// The issue keys behind the counts, sorted by key, one entry per
	// counted item (mismatch: per counted comment), so each count is the
	// length of its slice. CycleKeys has no count field of its own: its
	// length is the week's sample size, and CycleP50/CycleP85 exist exactly
	// when it is non-empty.
	ClosedKeys     []string
	InProgressKeys []string
	MismatchKeys   []string
	CycleKeys      []string
}

Bucket is one ISO week column: From is Monday 00:00 local; the last bucket runs to now and is partial. The metric fields are per bucket: pointers are nil where the answer does not exist (no data for it), which the table prints as a dash and JSON emits as null.

func Buckets

func Buckets(now time.Time, since time.Duration) []Bucket

Buckets lays the weeks from the Monday of the first week since reaches up to now. At least one bucket comes back: an empty span (now exactly on a Monday midnight) still gets the single partial week.

func (Bucket) Label

func (b Bucket) Label() string

Label is the bucket's column title and the name --open reports: 08-24..08-31, or 08-31..now for the current partial week.

type BucketJSON

type BucketJSON struct {
	From       string     `json:"from"`
	To         string     `json:"to"`
	Partial    bool       `json:"partial"`
	Sessions   int        `json:"sessions"`
	Resume     *float64   `json:"resume (median)"`
	WipP85     *float64   `json:"wip age p85"`
	WipMax     *float64   `json:"wip age max"`
	InProgress *int       `json:"in progress"`
	Closed     *int       `json:"closed"`
	CycleP50   *float64   `json:"cycle p50"`
	CycleP85   *float64   `json:"cycle p85"`
	Mismatch   int        `json:"mismatch"`
	Keys       BucketKeys `json:"keys"`
}

BucketJSON is one element of buckets. The keys are the table row names verbatim, so a consumer reads the same words the footer defines.

type BucketKeys

type BucketKeys struct {
	Closed        []string `json:"closed"`
	InProgress    []string `json:"in progress"`
	Mismatch      []string `json:"mismatch"`
	Cycle         []string `json:"cycle"`
	KeysTruncated bool     `json:"keys_truncated,omitempty"`
}

BucketKeys is the keys object of one JSON bucket: the issue keys behind each count, capped at MaxJSONKeys per array with KeysTruncated set when any array was cut.

type Doc

type Doc struct {
	Buckets     []BucketJSON      `json:"buckets"`
	Definitions map[string]string `json:"definitions"`
}

Doc is the JSON document: buckets plus the same definitions strings the footer prints.

type Options

type Options struct {
	SessionGap time.Duration
}

Options is the tunable half of Compute; the zero value is every default. SessionGap zero or negative means the SessionGap constant (30m).

type Report

type Report struct {
	Buckets      []Bucket
	CLIFallback  bool // no ui/unknown visits; sessions came from cli rows
	SelfResolved bool // a FeedIdentity was available for resume
	CatalogEmpty bool // status_catalog has no rows

	// SessionGap is the effective split gap Compute ran with. Definitions
	// prints it; zero or negative (a hand-built Report) renders the default.
	SessionGap time.Duration
	// CycleUnavailable marks a mirror whose schema predates cycle_hours
	// (user_version < 43): every cycle cell is a dash and the footer says
	// how to fix it, in the same shape as CatalogEmpty.
	CycleUnavailable bool
}

Report is everything the table and the JSON document render.

func Compute

func Compute(ctx context.Context, db *sql.DB, me store.FeedIdentity, since time.Duration, now time.Time, opts Options) (Report, error)

Compute reads the mirror plus local.visits and fills the buckets. db is a handle on the mirror with local.db attached (store.OpenReadOnly gives the CLI one; the server opens its own the same way). opts carries the tunables; the zero Options is the shipped default (SessionGap constant). Each table walks in its own loader below the function — one defer rows.Close() and one rows.Err() per walk, not three close sites on every error branch (GDK-1575).

func (Report) Definitions

func (r Report) Definitions() [][2]string

Definitions is the footer under every table (and the definitions object of JSON): a metric name and the sentence that fixes what it counts. Branch lines (which visits fed sessions, whether self resolved, the empty-catalog note) are rows with their own names so both surfaces print the same strings.

func (Report) JSON

func (r Report) JSON() Doc

func (Report) Table

func (r Report) Table() string

Table renders the text output: header row, the metric rows, then the definitions footer — every time, in every invocation.

Jump to

Keyboard shortcuts

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