# Issue tracker: GitHub

Issues and specs for this repo live as GitHub issues. Use the `gh` CLI for all operations.

## Conventions

- **Create an issue**: `gh issue create --title "..." --body "..."`. Use a heredoc for multi-line bodies.
- **Read an issue**: `gh issue view <number> --comments`, filtering comments by `jq` and also fetching labels.
- **List issues**: `gh issue list --state open --json number,title,body,labels,comments --jq '[.[] | {number, title, body, labels: [.labels[].name], comments: [.comments[].body]}]'` with appropriate `--label` and `--state` filters.
- **Comment on an issue**: `gh issue comment <number> --body "..."`
- **Apply / remove labels**: `gh issue edit <number> --add-label "..."` / `--remove-label "..."`
- **Close**: `gh issue close <number> --comment "..."`

Infer the repo from `git remote -v` — `gh` does this automatically when run inside a clone.

## Pull requests as a triage surface

**PRs as a request surface: no.** _(Set to `yes` if this repo treats external PRs as feature requests; `/triage` reads this flag.)_

When set to `yes`, PRs run through the same labels and states as issues, using the `gh pr` equivalents:

- **Read a PR**: `gh pr view <number> --comments` and `gh pr diff <number>` for the diff.
- **List external PRs for triage**: `gh pr list --state open --json number,title,body,labels,author,authorAssociation,comments` then keep only `authorAssociation` of `CONTRIBUTOR`, `FIRST_TIME_CONTRIBUTOR`, or `NONE` (drop `OWNER`/`MEMBER`/`COLLABORATOR`).
- **Comment / label / close**: `gh pr comment`, `gh pr edit --add-label`/`--remove-label`, `gh pr close`.

GitHub shares one number space across issues and PRs, so a bare `#42` may be either — resolve with `gh pr view 42` and fall back to `gh issue view 42`.

## When a skill says "publish to the issue tracker"

Create a GitHub issue.

## When a skill says "fetch the relevant ticket"

Run `gh issue view <number> --comments`.

## `/to-qa` support

Use GitHub's native sub-issue relationship for implementation children. Create the child issue, read its database ID, then attach it to the parent:

```bash
child_issue_id=$(gh api "repos/{owner}/{repo}/issues/<child-number>" --jq .id)
gh api --method POST "repos/{owner}/{repo}/issues/<parent-number>/sub_issues" \
  -F sub_issue_id="$child_issue_id"
```

Fetch the complete child set, across every response page, with:

```bash
gh api --paginate "repos/{owner}/{repo}/issues/<parent-number>/sub_issues?per_page=100" | jq -s 'add'
```

Include only children whose `state` is `closed` and whose `state_reason` is `completed`. Report open children and children closed as `not_planned` as warnings. Read each included child with `gh issue view <child-number> --comments --json number,title,body,state,closedAt,comments,url`. Do not mutate GitHub issues during `/to-qa`.

During setup, run the child-list query against the selected repository. If its GitHub host does not support native sub-issues or the current credential cannot read them, stop and ask the user for a concrete parent marker and a full-set query. Do not emit an incomplete `/to-qa` configuration.

## Wayfinding operations

Used by `/wayfinder`. The **map** is a single issue with child issues as tickets.

- **Map**: create one issue labelled `wayfinder:map`; its body holds Destination, Notes, Decisions so far, Not yet specified, and Out of scope.
- **Child ticket**: link an issue as a GitHub sub-issue. If sub-issues are unavailable, add it to a task list in the map and put `Part of #<map>` at the top of its body. Apply one `wayfinder:<type>` label plus the mapped mode label: `ready-for-agent` for AFK or `ready-for-human` for HITL.
- **Blocking**: use GitHub's native issue dependencies. Add an edge with `gh api --method POST repos/<owner>/<repo>/issues/<child>/dependencies/blocked_by -F issue_id=<blocker-db-id>`, where the database ID comes from `gh api repos/<owner>/<repo>/issues/<n> --jq .id`. If dependencies are unavailable, use `Blocked by: #<n>, #<n>` near the top of the child body.
- **AFK frontier**: list the map's open children, exclude assigned tickets and tickets with an open blocker, then keep the mapped `ready-for-agent` label. Only this frontier may be dispatched autonomously.
- **HITL frontier**: apply the same open, unblocked, and unassigned filters, then keep the mapped `ready-for-human` label and surface those tickets to the human. Preserve map order within each mode.
- **Claim**: `gh issue edit <n> --add-assignee @me` as the session's first write.
- **Resolve**: comment with the answer, close the child, then add a one-line gist and link to the map's Decisions so far.
