# Template Context Injection

**Completed**: 2026-01-15
**Branch**: `027-template-context-injection`
**Epic**: #254
**Feature**: #255

> **Historical note (0.2.0)**: As of doit 0.2.0, Claude Code templates
> also ship as Agent Skills at `.claude/skills/doit.<name>/SKILL.md`
> alongside the legacy `.claude/commands/doit.<name>.md` files referenced
> throughout this spec. See [agent-skills.md](../templates/agent-skills.md).

## Overview

Integrates the `doit context show` command into all 11 doit command templates, enabling AI agents (Claude Code, GitHub Copilot) to automatically load project context before executing workflow commands. This completes the context injection workflow by bridging the CLI infrastructure (from feature 026-ai-context-injection) with the actual command templates that AI agents execute.

## Requirements Implemented

| ID | Description | Status |
|----|-------------|--------|
| FR-001 | All templates include context loading step | Done |
| FR-002 | Context loading positioned before main logic | Done |
| FR-003 | Templates handle context loading failures gracefully | Done |
| FR-004 | Specit references constitution principles | Done |
| FR-005 | Planit considers tech stack context | Done |
| FR-006 | Taskit uses context for task breakdown | Done |
| FR-007 | Fallback behavior when doit unavailable | Done |
| FR-008 | No manual context loading required | Done |
| FR-009 | Clear bash command instruction | Done |
| FR-010 | Existing functionality preserved | Done |
| FR-011 | Sync-prompts propagates to all targets | Done |

## Technical Details

### Context Loading Section

The following section was added to all 11 templates after the "## User Input" section:

```markdown
## Load Project Context

Before proceeding, load the project context to inform your responses:

```bash
doit context show
```

**If the command fails or doit is not installed**: Continue without context, but note that alignment with project principles cannot be verified.

**Use loaded context to**:
- Reference constitution principles when making decisions
- Consider roadmap priorities
- Identify connections to related specifications
```

### Template-Specific Guidance

- **doit.specit.md**: Reference constitution principles when defining requirements, align with roadmap priorities, check for overlap with existing specifications
- **doit.planit.md**: Use tech stack from constitution as baseline for architecture, flag technology deviations, reference related specifications for integration points

## Files Changed

### Templates Modified (11 files)
- `templates/commands/doit.specit.md`
- `templates/commands/doit.planit.md`
- `templates/commands/doit.taskit.md`
- `templates/commands/doit.implementit.md`
- `templates/commands/doit.testit.md`
- `templates/commands/doit.reviewit.md`
- `templates/commands/doit.checkin.md`
- `templates/commands/doit.constitution.md`
- `templates/commands/doit.roadmapit.md`
- `templates/commands/doit.scaffoldit.md`
- `templates/commands/doit.documentit.md`

### Synced Targets (22 files)
- `.claude/commands/` - 11 files synced via `doit sync-prompts`
- `.github/prompts/` - 11 files synced via `doit sync-prompts`

## Testing

- **Automated tests**: N/A (manual verification only for template modifications)
- **Manual tests**: 8/8 passed
  - MT-001: Template instructs AI to load context
  - MT-002: Context loading section positioning
  - MT-003: Graceful fallback behavior
  - MT-004: Specit has constitution principle guidance
  - MT-005: Planit has tech stack guidance
  - MT-006: All 11 templates have context section
  - MT-007: Claude commands synced
  - MT-008: Copilot prompts synced

## Related Issues

- **Epic**: #254 - Template Context Injection
- **Feature**: #255 - Automatic Context Loading in Commands

## User Stories Implemented

1. **US1 - Automatic Context Loading** (P1): All doit commands now instruct AI agents to load project context via `doit context show`
2. **US2 - Context-Aware Spec Creation** (P1): specit template includes guidance to reference constitution principles
3. **US3 - Context-Aware Planning** (P2): planit template includes guidance to use constitution tech stack
4. **US4 - Selective Context Loading** (P3): Documented for future implementation in quickstart.md

---

*Generated by `/doit.checkin`*
