Documentation
¶
Overview ¶
Package conventions holds the tool's opinions: the label set, the issue body template, and the static primer text.
Index ¶
- Constants
- Variables
- func AppendOutcome(body, note string) (string, error)
- func DiscoveredFrom(n int) string
- func FirstSection(body string, names ...string) string
- func FixesLine(n int) string
- func FixesReferences(body string) []int
- func FormatUnmarkedCodeText(tokens []string) string
- func HasCommitPrefix(title string) bool
- func HasProvenanceMarker(body, kind, key, digest string) bool
- func IsConventionalBranch(branch string) bool
- func PRTitle(issueType, title string) string
- func PartOfLine(n int) string
- func ProvenanceMarker(kind, key, digest string) string
- func ReviewSection(body, name string) string
- func Section(body, name string) string
- func SectionList(values []string) string
- func StripEmptySections(body string) string
- func TemplateSections(issueType string) []string
- func TemplateSkeleton(issueType string) string
- func UnmarkedCodeText(body string) []string
- type Label
- type PRSections
- type PRTrailers
- type Sections
Constants ¶
const ( // ProvenanceApply marks issues created by `hew apply`. ProvenanceApply = "apply" // ProvenanceMigrate marks issues created by `hew migrate` (beads or local). ProvenanceMigrate = "migrate" )
Batch writers stamp a provenance marker into every issue body they create so a later run can tell an issue it made from one it merely has a number for. Checkpoint state files are ordinary repository content and therefore untrusted: without a marker, a hand-written state file could point a mapping at any issue and the tool would wire, comment on, or close it (#81).
The marker binds three things, and verification requires all three:
- the batch kind, so an apply mapping cannot be satisfied by a migrated issue or the reverse;
- the source key (plan entry id, bead id), so a mapping cannot be redirected onto a different issue the same run created;
- a digest of the source file, so an attacker who supplies their own plan or snapshot cannot claim issues created from the real one.
The digest is what makes the marker unforgeable in the case that matters. A marker is public, readable text, so anyone can copy one into an issue they control — but they cannot make an issue created from a different source file carry their digest.
const ClaudeSnippet = `## Issue tracking
Work is tracked in GitHub Issues via the ` + "`hew`" + ` CLI.
Run ` + "`hew prime`" + ` at session start — it prints the conventions,
the ready work, and current state. When in doubt: ` + "`hew ready`" + `.`
ClaudeSnippet is what `hew init` prints for the repo's CLAUDE.md: the point of prime is that the snippet stays this short.
const ClaudeSnippetLocal = `## Issue tracking
Work is tracked locally in ` + "`.hew`" + ` via the ` + "`hew`" + ` CLI; there is no GitHub tracker.
Run ` + "`hew prime`" + ` at session start — it prints the conventions,
the ready work, and current state. When in doubt: ` + "`hew ready`" + `.`
ClaudeSnippetLocal is the same for a repo that tracks issues locally: the issues live in `.hew`, not GitHub, and the primer is still the entry point.
const CodeSpanGuidance = "Write commands, flags, branch names, paths and error strings as code spans\n" +
"(`--title`, `feat/pr-head`, `internal/cli/pr.go`, `go test -race ./...`): issue\n" +
"and PR bodies are Markdown that outlives the branch (rendered in a browser on\n" +
"GitHub, and `hew migrate local` carries local ones there), and those are the\n" +
"characters that blur into prose. Wrap the whole command, not just the flag\n" +
"inside it. Composed bodies are checked and unmarked code text is warned about."
CodeSpanGuidance is the authoring rule the body templates prescribe. It is stated on the create/pr/apply help surfaces, but help text is read when someone goes looking for it and the composing agent generally does not — which is why the rule is also checked. UnmarkedCodeText is what makes it land; this text is what the warning points at.
const EpicTitlePrefix = "Epic: "
EpicTitlePrefix is the cosmetic title prefix the tool adds to parent issues. Epic-ness itself is defined by having sub-issues or the epic label.
const PRBodyGuidance = `Body: ### What / ### Why / ### Testing, plus ### Risk when a reviewer must weigh the merge. What and Why default to the issue's Fix/Approach and Problem/Goal. What, Why, Testing and Risk repeat: several values become a bullet list, one value stays a paragraph. Empty sections are omitted. Testing: ` + PRTestingGuidance + `. Risk: ` + PRRiskGuidance + `. Repeat the flag once per line. For a diff sketch, file tree or diagram, compose the body in a file and pass --body-file; the section flags are for short text.`
PRBodyGuidance is the body contract stated on the pr help surface. It sits next to Compose so the template and its explanation cannot drift, and it embeds the warning constants so the layout advice has one source; the primer carries only the short form.
const PRRiskGuidance = `` /* 144-byte string literal not displayed */
PRRiskGuidance is the short form carried by the missing-Risk warning.
const PRTestingGuidance = `` /* 184-byte string literal not displayed */
PRTestingGuidance is the short form carried by the missing-Testing warning. Help is read by someone who goes looking; the agent composing a body generally does not, so the rule is also stated at the moment it applies. It says how to lay the evidence out as well as what to prove, because a section written as one run-on paragraph renders as a dense block on GitHub.
const PrimerLocal = primerLocalWorkflow + "\n" + primerDedup + "\n\n" +
primerConventions + "\n" + primerTail
PrimerLocal is the primer for a repo that tracks issues in a local `.hew` directory. It drops the pull-request step and the GitHub-only sandbox note, and completes work with `hew close --completed`.
const PrimerStatic = primerGitHubWorkflow + "\n" + primerDedup + "\n\n" + primerSandbox + "\n\n" +
primerConventions + "\n" + primerPR + "\n" + primerTail
PrimerStatic is the conventions-and-cheatsheet half of `hew prime`, kept deliberately terse: the whole primer targets ~1200 tokens (measured, see DESIGN.md's token-efficiency section).
Variables ¶
var BranchPrefixes = []string{"feat/", "fix/", "chore/", "docs/"}
BranchPrefixes are the branch-name prefixes the workflow prescribes. A branch outside this set isn't refused — the work is already committed by the time a PR is opened — but it is warned about.
var CommitPrefixes = []string{"feat", "fix", "chore", "docs", "refactor", "test", "perf", "build", "ci", "style", "revert"}
CommitPrefixes are the conventional-commit prefixes a PR title may carry. The release changelog is grouped by them, so they are the reason the tool has an opinion about titles at all.
var Labels = buildLabels()
Labels is the convention label set `hew init` bootstraps: model's vocabulary (names) plus the cosmetics above. init creates the missing ones; color/description drift on labels that already exist is left alone — names are the contract, cosmetics are the repo owner's.
Functions ¶
func AppendOutcome ¶ added in v0.20.0
AppendOutcome adds a note to the first top-level ATX Outcome section, creating one if needed. It inserts text without reformatting the rest of the body. Notes must leave the surrounding Markdown blocks intact.
func DiscoveredFrom ¶
DiscoveredFrom is the body line linking discovered work to its origin.
func FirstSection ¶
FirstSection returns the first non-empty of the named sections, so a caller can ask for a wording pair (Fix or Approach) in one go.
func FixesLine ¶
FixesLine is the closing keyword GitHub links a merged PR to its issue by. Rendered in one place so the read-back check and the composed body can never drift apart.
func FixesReferences ¶
FixesReferences returns the issue numbers a body already closes, in order of appearance, so the write path can compare them with the declared set. It matches the closing keywords GitHub itself acts on (case-insensitively), not just the one this tool writes — a hand-written "Closes #7" links the PR just as hard as "Fixes #7", and silently adding a second link would close two issues on merge.
func FormatUnmarkedCodeText ¶ added in v0.8.0
FormatUnmarkedCodeText renders the warning body for a set of findings, capping the list so a long body cannot bury the rest of the output.
func HasCommitPrefix ¶
HasCommitPrefix reports whether a title already carries a prefix.
func HasProvenanceMarker ¶ added in v0.9.0
HasProvenanceMarker reports whether body carries the marker for exactly this kind, key, and source digest.
func IsConventionalBranch ¶
IsConventionalBranch reports whether a branch name carries one of the prescribed prefixes.
func PRTitle ¶
PRTitle derives a PR title from the issue's type and title. A squash merge makes the PR title the commit subject, and the changelog is grouped by conventional-commit prefix — so a PR titled with the issue's own words lands the work under "Other" (#44). Issue titles deliberately carry no prefix (the type label holds that), which makes the type exactly the information the prefix encodes. An untyped issue gets no prefix: there is nothing to derive one from, and inventing one is worse than none.
func PartOfLine ¶
PartOfLine names the epic a sub-issue's PR belongs to.
func ProvenanceMarker ¶ added in v0.9.0
ProvenanceMarker returns the marker for one created issue: an HTML comment, so it carries no weight in the rendered body a human reads.
func ReviewSection ¶ added in v0.16.0
ReviewSection extracts section content from a free-form body. A top-level heading of any level or a bold section label can open or end a section. Closing and epic trailers are skipped. Every occurrence counts, so an empty first heading does not hide a real later one.
func Section ¶
Section extracts the content under a top-level "### Name" heading, empty when absent. Headings inside Markdown blocks stay part of the content.
func SectionList ¶ added in v0.21.0
SectionList renders the values of a repeatable section flag. One value is returned verbatim, so a caller that passes a single string gets the same body it always did; several become a markdown bullet list, one item per value. Blank values are dropped; a leading "- " or "* " the author already wrote is stripped so it does not nest as "- - item"; and a continuation line is indented under its bullet so it stays part of that item.
func StripEmptySections ¶
StripEmptySections removes template sections whose body is blank, so a half-filled skeleton posts clean. Non-template content is preserved verbatim.
func TemplateSections ¶
TemplateSections returns the body-template section headers for a type, in order. Bugs describe a problem and a fix; enhancements and tasks a goal and an approach; an idea a problem and its open questions, with no approach or checklist to fill in.
func TemplateSkeleton ¶
TemplateSkeleton renders the empty template for --edit: headers with blank slots, "Done when" seeded with one checklist item.
func UnmarkedCodeText ¶ added in v0.8.0
UnmarkedCodeText returns the code-shaped tokens in a body that are not inside a code span or a fenced block, de-duplicated and in order of first appearance. It reports; it never rewrites.
Checking rather than transforming is the whole design. Marking text up automatically requires knowing what the text means — whether --body-file is a flag being named or part of "gh pr edit --body-file" — and that information is not in the token stream, so a transform splits compound commands and cannot be iterated out of it. The author knows. So the tool's job is to notice and say so, at the moment the body is composed, rather than to guess or to rely on help text having been read.
Reporting also inverts the cost of a false positive: a wrong rewrite ships permanently in a published body, while a wrong warning costs one line of stderr. That is what lets the checked set cover paths and identifiers, which no safe transform could ever touch.
Types ¶
type PRSections ¶
PRSections are the pull-request body fields, mirroring the issue body template: What replaces the issue's Fix/Approach, Why its Problem/Goal, Testing is the half an issue never carries, and Risk is the merge claim a reviewer weighs after reading the change.
func (PRSections) Compose ¶
func (s PRSections) Compose(t PRTrailers) string
Compose renders the PR body: the provided sections in template order, then the trailers. Empty sections are omitted rather than left as bare headers, matching the issue template's rule.
func (PRSections) IsZero ¶
func (s PRSections) IsZero() bool
IsZero reports whether no section was provided.
type PRTrailers ¶
PRTrailers are the tracker links that close the claim lifecycle: one Fixes line per issue the PR closes (normally exactly one; several only when the author declared the set), plus each epic those issues hang off.
func (PRTrailers) Render ¶
func (t PRTrailers) Render() string
Render returns the trailer block, empty when there is nothing to link. Both body paths go through it: the composed one renders the whole set, the --body-file one renders whatever the author didn't already write, so the escape hatch can't quietly lose a link the template would have made.
type Sections ¶
type Sections struct {
Where string
Problem string
Goal string
Fix string
Approach string
OpenQuestions []string
DoneWhen []string
}
Sections are the structured body fields carried by the create section flags and plan entries. Problem/Goal and Fix/Approach are wording pairs — at most one of each is set (the write path enforces it), and whichever is set picks the header, so word choice is never policed against the issue type. Open questions is optional and only rendered when supplied; it is a bullet list, not a checklist, so an idea can carry questions without a done-when.