model

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 8 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 model holds the domain types and the pure read-path logic: label normalization, ready-work detection, and dependency-cycle detection.

Index

Constants

View Source
const (
	SourceTitle   = "title"
	SourceBody    = "body"
	SourceComment = "comment"
)

Sources a SourcedFindings can name.

View Source
const DefaultPriority = P2

DefaultPriority is applied by the write path when none is given.

View Source
const EpicLabel = "epic"

EpicLabel marks an issue the tool created as an epic. Sub-issues are what make an epic in practice, but a freshly created one has none yet, and without a marker it would read as an untriaged plain issue and vanish from every list-shaped read. A label rather than the title prefix because it is permission-verified like the priority and type labels: GitHub drops labels from non-collaborators, whereas anyone can type "Epic: " into a title.

View Source
const IdeaType = "idea"

IdeaType is the discovery type. It comes after the implementation types so an existing issue that already used `idea` as a label beside one of them keeps its old reading (and the multiple-type warning), while an issue whose only type label is idea reads as an idea.

View Source
const InProgressLabel = "in-progress"

InProgressLabel marks claimed issues; the assignee is the claim, the label is the visibility.

Variables

View Source
var Types = []string{"bug", "enhancement", "task", IdeaType}

Types lists the type labels in normalization precedence order: when an issue carries more than one, the first of these wins.

Functions

func ByNumber

func ByNumber(issues []Issue) map[int]Issue

ByNumber indexes issues by number.

func Cycles

func Cycles(allOpen []Issue) [][]int

Cycles finds dependency cycles among open issues, following blocked-by edges. GitHub only rejects self-blocks and direct two-issue cycles, so longer cycles can exist (created via web UI or raw API) and must be detected client-side: every member of a cycle has an open blocker, so a cycle silently excludes all its members from ready forever.

allOpen must be every open issue in the repository. Edges to issues not in the set are dropped as non-blocking, so passing a filtered subset yields false negatives — a cycle whose members were filtered out goes undetected.

Each cycle is returned once as a slice of issue numbers in edge order (a blocked-by b blocked-by c ... blocked-by a), starting from its smallest member.

func IsConventionLabel added in v0.18.0

func IsConventionLabel(label string) bool

IsConventionLabel reports whether the label name is a priority, type, in-progress or epic label in any case — the names an area must not take.

func IsEpicLabel added in v0.18.0

func IsEpicLabel(label string) bool

IsEpicLabel reports whether the label name is the epic marker, case-insensitively.

func IsInProgressLabel added in v0.18.0

func IsInProgressLabel(label string) bool

IsInProgressLabel reports whether the label name is the in-progress label, case-insensitively.

func IsType

func IsType(label string) bool

IsType reports whether a flag value is exactly one of the type names. Label names go through LabelType, which ignores case.

func LabelType added in v0.18.0

func LabelType(label string) (string, bool)

LabelType recognizes a type label by name, case-insensitively, and returns its canonical spelling.

func LabelVocabulary

func LabelVocabulary() []string

LabelVocabulary returns every label name the tool assigns meaning to, in a stable order: priorities, then types, then the in-progress and epic labels. It is the single source of truth for label names — conventions attaches the cosmetics (color, description) keyed by these names.

func RelatedGroups added in v0.17.0

func RelatedGroups(issues []Issue) [][]Issue

RelatedGroups partitions issues into groups that are connected by a shared parent, a shared area label, or a dependency between two of them. A single group means the set plausibly belongs in one PR; several means some of it has nothing visible in common with the rest. Groups and their members keep the order the issues were given in.

func SortByPriority

func SortByPriority(issues []Issue)

SortByPriority orders issues P0→P4 then P?, oldest (lowest number) first within a priority. Stable and deterministic.

func SortForList

func SortForList(issues []Issue)

SortForList orders hew ready-first (each bucket P0→P4 then P?, oldest first), so one `hew list` answers both "what's actionable" and "what exists but is stuck".

Types

type Checker added in v0.19.0

type Checker struct {
	// contains filtered or unexported fields
}

Checker is a prepared cycle check over one open-issue graph. Build it once to check several prospective edges without rebuilding the graph for each, which is what a multi-blocker write does.

func NewChecker added in v0.19.0

func NewChecker(allOpen []Issue) *Checker

NewChecker prepares a check over allOpen. The set has the same requirement as CheckBlockedBy: it must be every open issue in the repository, or a cycle whose members were filtered out goes undetected.

func (*Checker) Check added in v0.19.0

func (c *Checker) Check(issue, blocker int) CycleCheck

Check answers one edge against the prepared graph, with CheckBlockedBy's semantics. A found cycle is definite even when part of the graph is truncated; a nil cycle on a truncated path is not proof the edge is safe.

type Comment

type Comment struct {
	Author    string
	CreatedAt time.Time
	Body      string
}

Comment is a recent issue comment (populated by show only).

type CycleCheck

type CycleCheck struct {
	// Cycle is the cycle the edge would close, in edge order starting at
	// issue, or nil if no cycle was found.
	Cycle []int
	// Verifiable is false when an issue reached during the search had more
	// blockers than were fetched: an unfetched blocker could complete a
	// cycle the search cannot see, so a nil Cycle must not be treated as
	// proof the edge is safe.
	Verifiable bool
}

CycleCheck is the verdict on a prospective "issue blocked by blocker" edge.

func CheckBlockedBy

func CheckBlockedBy(allOpen []Issue, issue, blocker int) CycleCheck

CheckBlockedBy reports whether adding "issue blocked by blocker" would create a cycle. The check is transitive over blocked-by edges: the edge closes a cycle iff blocker is already (transitively) blocked by issue.

allOpen must be every open issue in the repository (see Cycles). When any issue on the search path had a truncated blocker list the verdict is marked unverifiable, because the missing edges could hide a cycle.

type Issue

type Issue struct {
	ID          string // GraphQL node ID, needed for mutations
	Number      int
	Title       string
	Body        string
	State       string // "OPEN" or "CLOSED"
	StateReason string
	CreatedAt   time.Time
	Labels      []string
	Assignees   []string
	Parent      *Ref
	ParentTitle string
	SubIssues   []Ref
	// SubIssuesTotal is the server-side total; may exceed len(SubIssues)
	// when the nested connection was capped.
	SubIssuesTotal     int
	SubIssuesCompleted int
	BlockedBy          []Ref
	// BlockedByTotal is the server-side total; may exceed len(BlockedBy)
	// when the nested connection was capped.
	BlockedByTotal int
	Comments       []Comment
	// CommentsTotal is the server-side total; may exceed len(Comments) when
	// only the most recent were fetched.
	CommentsTotal int
}

Issue is the normalized domain shape of a GitHub issue. Raw labels are kept as-is; priority/type/areas are derived by the methods below.

func Children

func Children(issues []Issue, epic int) []Issue

Children returns the issues whose parent is the given epic, oldest first. It is derived from parent backlinks over the full fetched set, so it stays complete even when the epic's sub-issue connection was capped — unlike the epic's own SubIssues refs.

func EpicNext added in v0.12.0

func EpicNext(children []Issue) (r Issue, ok bool)

EpicNext returns the epic's next workable child: the first child, in Children's creation order, that is open, has no open blockers, is triaged, and is not an idea. For epics whose children are sequenced by blocked-by, that order is the sequence itself. A claimed child is still next — the claim is an annotation to resolve (resume yours, skip someone else's), and `start`'s exit codes say which. Untriaged children, nested epics and ideas are skipped exactly as ready skips them: next feeds the same automatic paths, an epic is never worked directly, and an idea child — which only arrives through a relationship made outside hew — is investigation work rather than the epic's implementation sequence.

func Epics

func Epics(issues []Issue) []Issue

Epics returns open issues that have sub-issues, sorted by priority.

func EpicsOf added in v0.19.0

func EpicsOf(issues []Issue) []Issue

EpicsOf is Epics over whatever states the caller fetched: a closed epic is listed when the issues include it.

func InProgressIssues

func InProgressIssues(issues []Issue) []Issue

InProgressIssues returns open, triaged issues carrying the in-progress label, sorted by priority. Untriaged non-epics are excluded because this list feeds the automatic primer path; epics remain exempt from triage and are surfaced here so the in-progress-epic contradiction stays visible.

func List added in v0.19.0

func List(issues []Issue, filter ListFilter) []Issue

List returns the issues that survive the filter, preserving their order. Untriaged issues are omitted in every state and under every filter: list is a list-shaped read, and triage is the deliberate path that returns the unvetted text. Callers that want list order sort first with SortForList.

func Ready

func Ready(issues []Issue) []Issue

Ready returns open, non-epic, unclaimed, triaged, non-idea issues with zero open blockers, sorted by priority.

Untriaged issues are excluded because ready feeds the automatic paths — `hew ready` and the primer — where issue text reaches an agent with no human in between. Anyone can open an issue on a public repo, but GitHub drops labels from non-collaborators, so a priority and type label is evidence that a maintainer saw the issue. That makes triage state a forgery-resistant gate, and it costs hew-created issues nothing: the write path labels them by construction. The work is not hidden — `hew triage` and `hew list` still show it, and the primer carries the count.

Ideas are excluded because ready is the implementation queue: an idea is a question a maintainer has not yet decided to investigate, and every ready consumer may act on what it is offered. Investigation is a deliberate claim (`hew start --for-discovery`), so an idea stays visible in `list`, `show` and its epic's detail without being offered as work.

func UntriagedIssues

func UntriagedIssues(issues []Issue) []Issue

UntriagedIssues returns open untriaged issues, oldest first.

func (Issue) Areas

func (i Issue) Areas() []string

Areas returns all labels that are not priority, type, or in-progress, in any case.

func (Issue) Claimed

func (i Issue) Claimed() bool

Claimed reports whether someone has taken the issue: the assignee is the claim, the in-progress label is the visibility. Either half counts.

func (Issue) HasChildren added in v0.20.0

func (i Issue) HasChildren() bool

HasChildren reports whether the issue has sub-issues. SubIssuesTotal is the backend's count, so a capped connection does not hide them.

func (Issue) HasEpicMarker added in v0.20.0

func (i Issue) HasEpicMarker() bool

HasEpicMarker reports whether the issue carries the epic label the tool puts on every epic it creates. A childless epic is an epic by the marker alone.

func (Issue) HasLabel added in v0.18.0

func (i Issue) HasLabel(name string) bool

HasLabel reports whether the issue carries the label. Label names are case-insensitive on GitHub, so the match is too.

func (Issue) IdeaEpicConflict added in v0.20.0

func (i Issue) IdeaEpicConflict() string

IdeaEpicConflict reports why the issue cannot be typed as an idea while keeping its current hierarchy, or "" when nothing holds it: an idea takes no epic position, so a parent, sub-issues or the epic label each conflict with it. It is the write-side counterpart of IsEpic's read precedence — an existing overlap stays visible on reads, and a type change must remove the relationship rather than coexist with it.

func (Issue) InProgress

func (i Issue) InProgress() bool

InProgress reports whether the issue carries the in-progress label.

func (Issue) IsEpic

func (i Issue) IsEpic() bool

IsEpic reports whether the issue has sub-issues or carries the epic label the tool puts on every epic it creates, so a new epic is an epic before its first child is attached. The "Epic: " title prefix is cosmetic.

The hierarchy outranks the type: an issue also typed idea reads and claims as an epic until a maintainer repairs the overlap.

func (Issue) IsIdea added in v0.20.0

func (i Issue) IsIdea() bool

IsIdea reports whether the issue's effective type is the discovery type. Type precedence decides, so a legacy issue carrying idea beside task is a task, not an idea.

func (Issue) IsOpen

func (i Issue) IsOpen() bool

IsOpen reports whether the issue is open.

func (Issue) OpenBlockers

func (i Issue) OpenBlockers() []int

OpenBlockers returns the numbers of open blocking issues; closed blockers are non-blocking.

func (Issue) Priority

func (i Issue) Priority() (p Priority, multi bool)

Priority returns the effective priority. When an issue carries multiple priority labels the highest urgency wins and multi is true (a contradiction the warnings pass reports).

func (Issue) Type

func (i Issue) Type() (typ string, multi bool)

Type returns the effective type ("" when untyped). When an issue carries multiple type labels the first of bug|enhancement|task|idea wins and multi is true.

func (Issue) Untriaged

func (i Issue) Untriaged() bool

Untriaged reports whether a non-epic issue is missing its priority or type label — a normal state for issues filed outside the tool, never a defect. Epics are containers and exempt.

type ListFilter added in v0.19.0

type ListFilter struct {
	// Label keeps issues carrying the label, compared case-insensitively.
	Label string
	// Epic keeps issues whose parent is this epic; zero applies no filter.
	Epic int
	// NoEpic keeps issues that belong to no epic: no parent, and not an epic
	// themselves.
	NoEpic bool
}

ListFilter narrows a list-shaped read. The zero value keeps every issue.

type Priority

type Priority int

Priority is the P0 (critical) to P4 (backlog) scale, plus Unknown for issues with no priority label. Lower values are more urgent.

const (
	P0 Priority = iota
	P1
	P2
	P3
	P4
	// PriorityUnknown sorts after P4; rendered as "P?".
	PriorityUnknown
)

func LabelPriority added in v0.18.0

func LabelPriority(label string) (Priority, bool)

LabelPriority recognizes a priority label by name. Label names are case-insensitive on GitHub, so "p0" is the P0 label; ParsePriority stays exact because flag values are not label names.

func ParsePriority

func ParsePriority(s string) (Priority, bool)

ParsePriority parses a flag value, "P0".."P4", exactly. It is not the label matcher: label names are case-insensitive, so labels go through LabelPriority.

func (Priority) String

func (p Priority) String() string

type Ref

type Ref struct {
	Number int
	State  string // "OPEN" or "CLOSED"
}

Ref is a lightweight reference to another issue, as returned inside nested connections (blockers, sub-issues).

func (Ref) IsOpen

func (r Ref) IsOpen() bool

IsOpen reports whether the referenced issue is open.

type SourcedFindings added in v0.13.0

type SourcedFindings struct {
	Source string
	// Comment indexes Issue.Comments — the comments actually fetched and
	// displayed, not the server-side thread — when Source is SourceComment.
	Comment int
	TextFindings
}

SourcedFindings attributes findings to the one field they were found in.

func ScanIssue added in v0.13.0

func ScanIssue(i Issue) []SourcedFindings

ScanIssue scans the title, the body and each fetched comment on its own, returning one entry per field with findings, in display order. It is the detail view's form of ScanText: the same checks, but attributed, so a reader knows which part of the issue to look at. A clean issue yields nil.

type TextFindings added in v0.12.0

type TextFindings struct {
	ZeroWidth   bool `json:"zeroWidth"`
	BidiControl bool `json:"bidiControl"`
	UnicodeTags bool `json:"unicodeTags"`
	Confusable  bool `json:"confusable"`
}

TextFindings flags characters that deserve a human look during triage or a show read. Findings are advisory: legitimate language and mathematical notation can contain them too. No text is normalized, hidden, or rejected.

func ScanText added in v0.12.0

func ScanText(title, body string) TextFindings

ScanText scans title and body independently and combines their findings. ASCII lookalikes use the pinned Unicode confusables subset in textscan_data.go; this is an advisory scan of prose, not a UTS #39 identifier validator. Recognized emoji clusters are exempt so their joiners, selectors and flag tags don't trigger warnings. Extra hidden characters outside those exact sequences still do. Canonical decomposition alone is not suspicious: decomposed accents are ordinary text, so we deliberately do not flag non-NFC.

type Warning

type Warning struct {
	Kind    WarningKind
	Issue   int
	Cycle   []int
	Total   int
	Fetched int
}

Warning is a structured contradiction or completeness notice. Issue names the subject (0 for a cycle, which spans several); Cycle carries the member path for WarnDependencyCycle; Total and Fetched carry the server-side and fetched counts for the truncation kinds. Message formatting lives in the render package, not here.

func Warnings

func Warnings(issues []Issue) []Warning

Warnings reports contradictions and data-completeness notices — the per-issue conditions prime and ready surface. Absences (untriaged issues) are not warnings. Order is deterministic given the input order: per-issue warnings first, then cycles, then truncation notices.

func WarningsOfKind

func WarningsOfKind(ws []Warning, kinds ...WarningKind) []Warning

WarningsOfKind returns the subset of ws matching any of kinds, preserving order — each command surfaces the kinds relevant to its output.

type WarningKind

type WarningKind string

WarningKind identifies a contradiction or data-completeness notice, so callers can filter by cause and renderers can format the message without parsing prose.

const (
	WarnMultiPriority   WarningKind = "multiple-priority-labels"
	WarnMultiType       WarningKind = "multiple-type-labels"
	WarnInProgressEpic  WarningKind = "in-progress-epic"
	WarnDependencyCycle WarningKind = "dependency-cycle"
	WarnSubIssuesCapped WarningKind = "sub-issues-truncated"
	WarnBlockersCapped  WarningKind = "blockers-truncated"
)

Jump to

Keyboard shortcuts

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