# The Context Bundle

One read that returns everything a ticket needs, the milestone tier included.

## The Context Bundle

One read of a ticket, the Context Bundle, returns everything needed to do and verify the work: `tkt ticket get PAY-001` (for a program `--json`) returns the ticket, its `effectiveRepoAnchor`, its groups' descriptors, its own and inherited `context_references`, and the context guard hints. `has_blockers` is the gate (`block_reason` says why): never start with `has_blockers: true`.

- `location: repo` refs carry no code (`resolution.originalRange`); the client checks them in the worktree (Stage 2; the CWD, or `--worktree-dir` / `AITODO_WORKTREE_DIR`). Elsewhere: `not_found`, a `REPO_REF_NOT_FOUND` warning; `cd` to the repo root, check `resolution.status`.

### Details

**Inheritance:** `ticket → epic → primary group → secondary groups`; `repoAnchor` field by field, the first value wins (`_source`). Put durable context on the group once, on the ticket only what is specific to it. On a server store too the client runs Stage 2; until it has, `pending_local_resolution: true`, and unresolved repo refs get `REPO_REF_PENDING`. Refs are inherited along the same chain (the epic's `contextRefs`, then each group's `requiredReading` and `contextRefs`), tagged `_source` (`ticket`, `mention`, `epic:<id>`, `group:<id>`), `_list`, `_tier`. The first `(ref, anchor)` wins; a ref the ticket cites stays the ticket's. Inherited refs do not count for `MISSING_CONTEXT_REFERENCE` or `NO_CODE_LOCATIONS`.

**cuts[]:** every cut, always present (`[]` when none), the ticket's exclusions too. A pointer by design (a repo ref, a mention without a section, a URL) is no cut.

**Templates:** without `--body`, `tkt ticket new` fills the type's template (`feature`, `bug`: `## Description` + `## Acceptance Criteria`; others: `## Description`), which `--details` and `--ac` fill in; it holds no empty `- [ ]` and no empty `## In Scope`; `.aitodo/templates/<type>.md` overrides it.

**Epic:** `ticket.parentEpicSummary` claims right after tier 1: `mode: "full"` is the whole body when it fits the per-ref cap and the budget; else `"sections"`: `## Description`, `## Current state`, `## Decisions`, `## Terms` in that order, each whole or not at all; else `"brief"` (its first paragraph, 600 chars, past the budget). A cut has `cutBy`, `reason`, `fetch` (`tkt ticket get`), the first `cuts[]` entry (`kind: "epic"`) and `OVERSIZED_BUNDLE` (`data.epic`).

**Group body:** `## Overview` (800 chars) is in every bundle (`groups[].descriptor.markdown`; empty: `MISSING_GROUP_DESCRIPTOR`); `## Conventions`, `## Gotchas`, `## Verification` follow in `groups[].descriptor.sections[]` (800 chars each; `mode: "pointer"` when the budget ran out). Each part has `cutBy` (`section_cap`, `budget` or null), `fullyDelivered` and `reason` (`section cap: <delivered> of <total> characters`); the overview's are on `descriptor`.

**ContextRef:** `kind` (`doc`, `gotcha`, `decision`, `code`), `location` (`server`: `doc://<id>`; `repo`: a worktree path; `external`: a URL), `ref`, optional `note`, `summary`, `anchor`, `lineRange` (`L10-L42`), `verifiedAt`, `sourceRev`, `staleAfterDays` (then `STALE_DOC`). `repoAnchor`: `repo` (required), `branch`, `baseRef` (missing: `INCOMPLETE_REPO_ANCHOR`), `verifiedAt` (missing: `UNVERIFIED_REPO_ANCHOR`), `sourceRev`.

**fetch:** how to get the full original; always present (`null` when there is nothing to get): `resolution.fetch` on every ref, `fetch` on every group part, on `descriptor`, on the `## Value` and on every `cuts[]` entry (the same object as the cut part). Kinds: `command` (a plain `get`: `tkt doc get plan --anchor '## Sync'`, `tkt gotcha get`, `tkt decision get D84`, `tkt group get`, `tkt ticket get`), `file` (a repo ref: `src/app.ts:L120-L168` from `originalRange`; the bare path when no range is known), `url` (the external ref). A target delivered whole or missing: `null`. `fetch_url` stays for HTTP clients.

**In `tkt ticket get <ID> --json`, resolution:** `status` (`resolved`, `pending_local`, `not_found`), `resolved_by`, `mode` (`excerpt`, `summary`, `brief`, `pointer`), `content_excerpt`, `excerpt_range`, `stale`, `loadBearing`, `srcMtime`, `srcChecksum`, `error`, `originalRange` (a repo ref's range); a server doc or gotcha adds `type`, `title`, `description`; every ref has `essential`, `own`. Top level also: `kind: "context_bundle"`, `api_version`, `ticket.acceptanceCriteria {items, total, done}`, `ticket.body.markdown`, `relationships`, `milestones[]`, `cuts[]`, `guard {version, hints[], completeness_score, completeness}`.

**A cuts[] entry:** `{kind, target, anchor, delivered, total, cutBy, essential, own, fetch}`, in characters; `kind`: `epic`, `group_overview`, `group_section`, `value` (the inherited `## Value`), `ref`. Order: the epic, group parts, `## Value`, refs, then the ticket's exclusions (`cutBy: "excluded"`, `note`, `floor`, `source`).

## Milestones in the bundle

The bundle's `milestones[]` is always present (`[]` when the ticket is in no planned or active milestone): `id`, `title`, `status`, `goal` (at most 300 chars, cut on a word), `targetDate`, `progress`. Done or canceled milestones are left out. Mentions in a milestone's `## Decisions` arrive as tier-4 background refs (`_source: "milestone:<id>"`, `_list: "decisions"`) that never displace tier 1 to 3 content.

## Related

- Hint · warning: [`REPO_REF_NOT_FOUND`](/en/docs/reference/hints.md#REPO_REF_NOT_FOUND): A repo ref's file is missing in your worktree (Stage 2, client side)
- Hint · info: [`REPO_REF_PENDING`](/en/docs/reference/hints.md#REPO_REF_PENDING): Repo refs wait for Stage 2: resolve them from your worktree
- Hint · warning: [`MISSING_GROUP_DESCRIPTOR`](/en/docs/reference/hints.md#MISSING_GROUP_DESCRIPTOR): A group has no ## Overview (info on a CLI read)
