cli

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 22 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 cli implements the commands against the gh.Client interface, so cmd/hew is pure wiring and everything with behavior is testable against a fake.

Index

Constants

View Source
const (
	ExitGeneric = 1
	ExitUsage   = 2
	// ExitClaimed is start's "already claimed" refusal: pick the next
	// ready item instead of doubling up.
	ExitClaimed = 3
	ExitAuth    = 4
	// ExitClaimedByYou splits the claim refusal: the claimant is the
	// authenticated user, so the work is already yours and the response is
	// to resume it, not to pick a different item. The guard is unchanged —
	// this only says whose claim blocked it.
	ExitClaimedByYou = 5
)

Exit codes, kept meaningful so agent loops can branch on them.

View Source
const DefaultReadyLimit = 30

DefaultReadyLimit caps `ready` output unless the caller says otherwise. It sits above primeReadyCap on purpose: the primer truncates its own ready section and points at `hew ready` for the rest, so a cap at or below that one would leave the pointer pointing at nothing new.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps an error to the process exit code agent loops branch on: an ExitError's own code, ExitAuth for an auth failure (so "run gh auth login" is distinguishable), else ExitGeneric. nil maps to 0. The mapping lives here, not in main, so it is covered by tests.

func FindProjectRoot

func FindProjectRoot(start string) (string, error)

FindProjectRoot walks up from start until it finds the directory containing .git (a directory in a normal checkout, a file in a worktree). Project-level Claude Code settings live at its .claude/.

func ParseIssueNumber

func ParseIssueNumber(arg, usage string) (int, error)

ParseIssueNumber parses a required positional issue number, tolerating a leading '#'. It returns an ExitUsage error (with the given usage string) when the argument is missing or not a positive integer.

func ParseRepoSpec

func ParseRepoSpec(spec string) (gh.Repo, error)

ParseRepoSpec parses an "owner/name" repository spec, returning an ExitUsage error when it is malformed.

Types

type App

type App struct {
	Client gh.Client
	Repo   gh.Repo
	Out    io.Writer
	ErrOut io.Writer
	JSON   bool
	// Color is the precomputed TTY decision (render.ColorEnabled on the
	// real stdout in main): text renderers wrap their semantic spans in
	// ANSI only when it is set. JSON and piped output are never affected.
	Color bool
	// Edit opens an editor seeded with initial text and returns the result;
	// wired to $EDITOR by main, injected by tests.
	Edit func(initial string) (string, error)
	// Git reads the local branch state `pr` opens from; wired to the git
	// binary by main, injected by tests.
	Git func() (git.State, error)
}

App holds the dependencies every command needs.

func (*App) Apply

func (a *App) Apply(ctx context.Context, opts ApplyOpts) error

Apply batch-creates issues from a plan file: create in file order, checkpointing after every write, then wire parents and blockers — the migrate machinery generalized to arbitrary plans, with local ids playing the role of bead IDs.

func (*App) Block

func (a *App) Block(ctx context.Context, number, blocker int, allowClosed bool) error

Block adds a native dependency after a transitive client-side cycle check — GitHub itself only rejects self-blocks and direct two-issue cycles. It refuses a closed target unless allowClosed is set; a closed blocker is refused outright, since closed blockers don't block.

func (*App) Close

func (a *App) Close(ctx context.Context, number int, reason string, completed bool, duplicateOf int) error

Close comments the reason and closes: not-planned unless --completed or --duplicate-of. Closing via PR is the norm; this is for wontfix/duplicate.

func (*App) Create

func (a *App) Create(ctx context.Context, opts CreateOpts) error

Create files a new issue conforming to the conventions: exactly one priority and one type label, template-scaffolded body, native dependencies and parent links.

func (*App) EpicCreate

func (a *App) EpicCreate(ctx context.Context, opts EpicCreateOpts) error

EpicCreate files a parent issue and attaches existing children. Epics get the cosmetic title prefix and a priority label but no type — they are containers, not work.

func (*App) EpicStatus

func (a *App) EpicStatus(ctx context.Context, number int) error

EpicStatus with number <= 0 lists all open epics with progress rollups; with a number it shows that epic's children and the next workable one.

func (*App) HooksInstall

func (a *App) HooksInstall(projectRoot string, agent HookAgent) error

HooksInstall adds a session-start hook running `hew prime` to the selected agent's project configuration — a JSON settings entry for claude, codex, and cursor, an auto-discovered plugin file for opencode — creating the file if needed and leaving everything else in it untouched. Idempotent.

func (*App) HooksRemove

func (a *App) HooksRemove(projectRoot string, agent HookAgent) error

HooksRemove strips the selected agent's `hew prime` hook again, pruning any structures it leaves empty.

func (*App) Init

func (a *App) Init(ctx context.Context) error

Init bootstraps the convention labels in the repo and prints the CLAUDE.md snippet.

func (*App) List

func (a *App) List(ctx context.Context, opts ListOpts) error

List shows issues, open by default, filtered by state, label, or epic membership. Untriaged issues are omitted: their titles and bodies are unvetted input, and list is a read an agent can reach without a human in between — `hew triage` is the only command that emits them.

func (*App) MigrateBeads

func (a *App) MigrateBeads(ctx context.Context, opts MigrateOpts) error

MigrateBeads imports a beads snapshot as GitHub issues: create in history order, wire parents and blockers, then close what was closed.

func (*App) PR

func (a *App) PR(ctx context.Context, opts PROpts) error

PR opens the pull request that closes the claim lifecycle. It is deliberately thin: infer which issue this branch is for, compose a body from what the issue already says, and refuse the states that leave an issue claimed-but-orphaned after a merge. Reviews, merges and checks stay with `gh`.

func (*App) Prime

func (a *App) Prime(ctx context.Context, opts PrimeOpts) error

Prime emits the session-start context: static conventions, live state, contradictions. prime never reads stdin — Cursor writes its sessionStart payload there, and ignoring it is what keeps that JSON out of the primer.

func (*App) Ready

func (a *App) Ready(ctx context.Context, opts ReadyOpts) error

Ready lists open, non-epic, unclaimed issues with zero open blockers. No results is exit 0: an empty queue is an answer, not an error.

func (*App) Reopen added in v0.10.0

func (a *App) Reopen(ctx context.Context, number int, reason string) error

Reopen is close's inverse: comment the reason, reopen the issue. Closing comments routinely encode the condition to reopen on ("reopen only if #24 stalls"), and acting on one should keep close's comment-plus-state-change shape rather than degrade to a bare state flip. No retriage — the issue rejoins list/triage/ready with the priority, type, and area labels it already had.

A claim is the one thing reopen does clear. Neither close nor a PR merge removes the in-progress label or the assignee, so most issues closed in the normal workflow still carry the claim that produced the fix. Left in place on a reopened issue it makes the claim guard lie: exit 5 tells the old owner to resume merged work, exit 3 tells everyone else the issue is taken, and ready hides it. Whoever wants it back runs start.

func (*App) Search

func (a *App) Search(ctx context.Context, terms string) error

Search runs a repo-scoped text search over open and closed issues — the dedupe step before filing discovered work, where "already fixed" answers the question as well as "already filed". Output keeps the API's best-match order rather than the list sort: relevance is the point. Untriaged matches are omitted (their text is unvetted input); the other half of dedup, over the untriaged queue, is `hew triage --search`.

func (*App) Set

func (a *App) Set(ctx context.Context, number int, opts SetOpts) error

Set retriages or edits within the conventions, swapping the old priority/type label rather than stacking a second one. It refuses a closed target unless AllowClosed is set.

func (*App) Show

func (a *App) Show(ctx context.Context, number int) error

Show prints one issue in full: body, deps, parent, children, comments. An epic's detail view also names its next workable child, which needs each child's blockers — a second two-state fetch, but only when the subject is an epic.

func (*App) Start

func (a *App) Start(ctx context.Context, number int, priorityFlag string, force bool) error

Start claims an issue: assign @me plus the in-progress label. The guard refuses issues that are already assigned or in-progress — exit 3 for someone else's claim so an agent loop moves on to the next ready item, exit 5 when the claim is already yours; --force steals. Claiming an untriaged issue requires --priority — claiming forces triage.

func (*App) Triage

func (a *App) Triage(ctx context.Context, opts TriageOpts) error

Triage lists issues missing their priority or type label, oldest first — work through them with `hew set`. With Search it is the dedup path over untriaged content, the one list-shaped read that emits it: an agent harness deny list keys on this command, so nothing else may.

func (*App) Unblock

func (a *App) Unblock(ctx context.Context, number, blocker int, allowClosed bool) error

Unblock removes a dependency. It refuses a closed target unless allowClosed is set.

type ApplyOpts

type ApplyOpts struct {
	// File is the JSONL plan.
	File string
	// StatePath is where the entry-key→issue-number mapping and the edges
	// already wired are persisted after every write, making a failed run
	// resumable and an unchanged finished one a quiet no-op. Bound to the
	// repository and a digest of the plan, so an edited plan or a state file
	// from elsewhere is refused rather than trusted (#81). Empty means
	// File + ".state.json".
	StatePath string
	// DryRun prints the plan without touching GitHub.
	DryRun bool
	// Throttle is slept between writes to stay under GitHub's secondary
	// rate limits for content creation.
	Throttle time.Duration
}

ApplyOpts configure a batch apply.

type CreateOpts

type CreateOpts struct {
	Title          string
	Type           string
	Priority       string // empty means DefaultPriority
	Areas          []string
	BlockedBy      []int
	Parent         int
	DiscoveredFrom int
	Sections       conventions.Sections
	BodyFile       string
	Edit           bool
}

CreateOpts are the create command's inputs.

type EpicCreateOpts

type EpicCreateOpts struct {
	Title    string
	Children []int
	Sections conventions.Sections
	BodyFile string
	Edit     bool
}

EpicCreateOpts are the epic create inputs. The body paths match create: section flags, --body-file, or --edit.

type ExitError

type ExitError struct {
	Code    int
	Message string
}

ExitError carries a specific exit code to main.

func UsageError added in v0.9.0

func UsageError(format string, args ...any) *ExitError

UsageError lets command wiring report a usage failure with the same exit contract as command-layer validation.

func (*ExitError) Error

func (e *ExitError) Error() string

type HookAgent added in v0.9.0

type HookAgent string

HookAgent is an agent whose project-level session-start configuration hew manages.

const (
	HookAgentClaude   HookAgent = "claude"
	HookAgentCodex    HookAgent = "codex"
	HookAgentCursor   HookAgent = "cursor"
	HookAgentOpencode HookAgent = "opencode"
)

func ParseHookAgent added in v0.9.0

func ParseHookAgent(value string) (HookAgent, error)

ParseHookAgent accepts the agents whose hook file formats hew supports.

type ListOpts

type ListOpts struct {
	Label string
	Epic  int
	// State is "open", "closed", or "all"; empty means the default, which is
	// open — except under Epic, where progress means seeing what is done as
	// well as what is left.
	State string
	// Closed is the older spelling of State "closed". Kept working for
	// existing callers; passing both is a usage error rather than a silent
	// precedence rule.
	Closed bool
	// Bodies carries each issue's body on the NDJSON lines — triaged-tracker
	// dedup in one call (untriaged issues stay behind `hew triage`). JSON-only:
	// text output has no place for bodies.
	Bodies bool
}

ListOpts filters list output.

type MigrateOpts

type MigrateOpts struct {
	// File is the beads issues.jsonl snapshot.
	File string
	// StatePath is where the beadID→issue-number mapping is persisted
	// after every create, making a failed run resumable. Bound to the repository
	// and a digest of the snapshot (#81).
	StatePath string
	// DryRun prints the plan without touching GitHub.
	DryRun bool
	// IncludeClosed migrates closed beads too (created, commented with the
	// close reason, then closed). Real databases are >95% closed, so this
	// is opt-in.
	IncludeClosed bool
	// Throttle is slept between writes to stay under GitHub's secondary
	// rate limits for content creation.
	Throttle time.Duration
}

MigrateOpts configure the beads migration.

type PROpts

type PROpts struct {
	// For overrides issue inference; 0 means infer.
	For      int
	Title    string
	Sections conventions.PRSections
	BodyFile string
	// Ready opens the PR for review instead of as a draft.
	Ready bool
	// Base overrides the target branch; empty means the repo default.
	Base string
}

PROpts are the pr command's inputs. Every section is optional: the point of the command is that tracker state fills the gaps.

type PrimeOpts added in v0.11.0

type PrimeOpts struct {
	// HookFormat is the session-start hook format to emit. Empty is the
	// plain text primer; "cursor" JSON-encodes the primer into the
	// additional_context field Cursor's sessionStart hook reads.
	HookFormat string
}

PrimeOpts re-targets the primer's output at a caller with its own format, such as an agent hook whose stdout contract is not text.

type ReadyOpts added in v0.9.0

type ReadyOpts struct {
	// Limit caps how many issues are printed; 0 means unlimited. Capping is
	// safe because model.Ready is priority-sorted — the top N is the top N by
	// priority — but it is never silent: ready is the queue agents branch on,
	// and a truncated list read as complete reads as an empty backlog.
	Limit int
}

ReadyOpts filters ready output.

type SetOpts

type SetOpts struct {
	Priority    string
	Type        string
	AddAreas    []string
	RemoveAreas []string
	Parent      int
	NoParent    bool
	Title       string
	BodyFile    string
	AllowClosed bool
}

SetOpts are the retriage/edit inputs; zero values mean "leave alone".

type TriageOpts added in v0.11.0

type TriageOpts struct {
	// Search restricts triage to search matches instead of the open queue:
	// the dedup half over untriaged titles and bodies, spanning both states
	// so "already fixed" answers as well as "already filed". Empty is the
	// queue view: open untriaged issues, oldest first.
	Search string
}

TriageOpts retargets triage at the dedup case.

Jump to

Keyboard shortcuts

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