.taskmaster/docs/tdd-workflow-phase-2-pr-resumability.md
Add PR creation with GitHub CLI integration, resumable checkpoints for interrupted runs, and enhanced guardrails with coverage enforcement.
gh CLI--resume flagPRAdapter (packages/tm-core/src/services/pr-adapter.ts):
class PRAdapter {
async isGHAvailable(): Promise<boolean>
async createPR(options: PROptions): Promise<PRResult>
async getPRTemplate(runReport: RunReport): Promise<string>
// Fallback for missing gh CLI
async getManualPRInstructions(options: PROptions): Promise<string>
}
interface PROptions {
branch: string
base: string
title: string
body: string
draft?: boolean
}
interface PRResult {
url: string
number: number
}
PR Title Format:
Task #<id> [<tag>]: <title>
Example: Task #42 [analytics]: User metrics tracking
PR Body Template:
Located at .taskmaster/templates/pr-body.md:
## Summary
Implements Task #42 from TaskMaster autonomous workflow.
**Branch:** {branch}
**Tag:** {tag}
**Subtasks completed:** {subtaskCount}
{taskDescription}
## Subtasks
{subtasksList}
## Test Coverage
| Metric | Coverage |
|--------|----------|
| Lines | {lines}% |
| Branches | {branches}% |
| Functions | {functions}% |
| Statements | {statements}% |
**All subtasks passed with {totalTests} tests.**
## Commits
{commitsList}
## Run Report
Full execution report: `.taskmaster/reports/runs/{runId}/`
---
š¤ Generated with [Task Master](https://github.com/cline/task-master) autonomous TDD workflow
Token replacement:
{branch} ā branch name{tag} ā active tag{subtaskCount} ā number of completed subtasks{taskDescription} ā task description from TaskMaster{subtasksList} ā markdown list of subtask titles{lines}, {branches}, {functions}, {statements} ā coverage percentages{totalTests} ā total test count{commitsList} ā markdown list of commit SHAs and messages{runId} ā run ID timestampDetection:
which gh
If not found, show fallback instructions:
ā Branch pushed: analytics/task-42-user-metrics
ā gh CLI not found - cannot create PR automatically
To create PR manually:
gh pr create \
--base main \
--head analytics/task-42-user-metrics \
--title "Task #42 [analytics]: User metrics tracking" \
--body-file .taskmaster/reports/runs/2025-01-15-142033/pr.md
Or visit:
https://github.com/org/repo/compare/main...analytics/task-42-user-metrics
Confirmation gate:
Ready to create PR:
Title: Task #42 [analytics]: User metrics tracking
Base: main
Head: analytics/task-42-user-metrics
Create PR? [Y/n]
Unless --no-confirm flag is set.
State Checkpoint (state.json):
{
"runId": "2025-01-15-142033",
"taskId": "42",
"phase": "subtask-loop",
"currentSubtask": "42.2",
"currentPhase": "green",
"attempts": 2,
"completedSubtasks": ["42.1"],
"commits": ["a1b2c3d"],
"branch": "analytics/task-42-user-metrics",
"tag": "analytics",
"canResume": true,
"pausedAt": "2025-01-15T14:25:35Z",
"pausedReason": "max_attempts_reached",
"nextAction": "manual_review_required"
}
Resume Command:
$ tm autopilot --resume
Resuming run: 2025-01-15-142033
Task: #42 [analytics] User metrics tracking
Branch: analytics/task-42-user-metrics
Last subtask: 42.2 (GREEN phase, attempt 2/3 failed)
Paused: 5 minutes ago
Reason: Could not achieve green state after 3 attempts
Last error: POST /api/metrics returns 500 instead of 201
Resume from subtask 42.2 GREEN phase? [Y/n]
Resume logic:
.taskmaster/reports/runs/<runId>/state.json--force)Multiple interrupted runs:
$ tm autopilot --resume
Found 2 resumable runs:
1. 2025-01-15-142033 - Task #42 (paused 5 min ago at subtask 42.2 GREEN)
2. 2025-01-14-103022 - Task #38 (paused 2 hours ago at subtask 38.3 RED)
Select run to resume [1-2]:
Coverage Check Phase (before finalization):
async function enforceCoverage(runId: string): Promise<void> {
const testResults = await testRunner.runAll()
const coverage = await testRunner.getCoverage()
const thresholds = config.test.coverageThresholds
const failures = []
if (coverage.lines < thresholds.lines) {
failures.push(`Lines: ${coverage.lines}% < ${thresholds.lines}%`)
}
// ... check branches, functions, statements
if (failures.length > 0) {
throw new CoverageError(
`Coverage thresholds not met:\n${failures.join('\n')}`
)
}
// Store coverage in run report
await storeRunArtifact(runId, 'coverage.json', coverage)
}
Handling coverage failures:
ā ļø Coverage check failed:
Lines: 78.5% < 80%
Branches: 75.0% < 80%
Options:
1. Add more tests and resume
2. Lower thresholds in .taskmaster/config.json
3. Skip coverage check: tm autopilot --resume --skip-coverage
Run paused. Fix coverage and resume with:
tm autopilot --resume
Configuration:
{
"autopilot": {
"finalization": {
"lint": {
"enabled": true,
"command": "npm run lint",
"fix": true,
"failOnError": false
},
"format": {
"enabled": true,
"command": "npm run format",
"commitChanges": true
}
}
}
}
Execution:
Finalization Steps:
ā All tests passing (12 tests, 0 failures)
ā Coverage thresholds met (85% lines, 82% branches)
LINT Running linter... ā³
LINT ā No lint errors
FORMAT Running formatter... ā³
FORMAT ā Formatted 3 files
FORMAT ā Committed formatting changes: "chore: auto-format code"
PUSH Pushing to origin... ā³
PUSH ā Pushed analytics/task-42-user-metrics
PR Creating pull request... ā³
PR ā Created PR #123
https://github.com/org/repo/pull/123
Pause Points:
failOnError: true)Each pause saves:
Automatic recovery attempts:
Updated workflow:
failOnError: true--no-confirm)Final output:
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā
Task #42 [analytics]: User metrics tracking - COMPLETE
Branch: analytics/task-42-user-metrics
Subtasks completed: 3/3
Commits: 3
Total tests: 12 (12 passed, 0 failed)
Coverage: 85% lines, 82% branches, 88% functions, 85% statements
PR #123: https://github.com/org/repo/pull/123
Run report: .taskmaster/reports/runs/2025-01-15-142033/
Next steps:
- Review PR and request changes if needed
- Merge when ready
- Task status updated to 'review'
Completed in 24 minutes
New flags:
--resume ā Resume from last checkpoint--skip-coverage ā Skip coverage checks--skip-lint ā Skip lint step--skip-format ā Skip format step--skip-pr ā Push branch but don't create PR--draft-pr ā Create draft PR instead of ready-for-reviewAdd to .taskmaster/config.json:
{
"autopilot": {
"finalization": {
"lint": {
"enabled": false,
"command": "npm run lint",
"fix": true,
"failOnError": false
},
"format": {
"enabled": false,
"command": "npm run format",
"commitChanges": true
},
"updateTaskStatus": "review"
}
},
"git": {
"pr": {
"enabled": true,
"base": "default",
"bodyTemplate": ".taskmaster/templates/pr-body.md",
"draft": false
},
"pushRetries": 3,
"pushRetryDelay": 5000
}
}
gh CLI for PR creation testsgh) installed (optional, fallback provided)1-2 weeks
Risk: GitHub CLI auth issues
Risk: PR body template doesn't match all project needs
Risk: Resume state gets corrupted
Risk: Coverage calculation differs between runs
Test with:
gh CLI (fallback to manual)