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
- Variables
- func ClaimStands(commentAt time.Time, commentOK bool, statusChangedAt string) bool
- func FormatSeconds(secs float64) string
- func HasDoneWord(body string) bool
- func Max(vals []float64) (float64, bool)
- func P85(vals []float64) (float64, bool)
- func ParseSessionGap(s string) (time.Duration, error)
- func ParseSince(s string) (time.Duration, error)
- type Bucket
- type BucketJSON
- type BucketKeys
- type Doc
- type Options
- type Report
Constants ¶
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.
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.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Max is the largest value, for wip age max beside wip age p85 — the tail the percentile smooths over.
func P85 ¶
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 ¶
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.
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.
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 ¶
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
// (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 ¶
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.