feat: add Table of Contents to generated markdown documents (#1970)#2080
feat: add Table of Contents to generated markdown documents (#1970)#2080Quratulain-bilal wants to merge 14 commits intogithub:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Table of Contents (TOC) guidance to the Speckit command templates so generated spec.md, plan.md, and tasks.md include a concise TOC linking to ##-level sections.
Changes:
- Instruct
/speckit.specifyto include a TOC after the document header and before the first content section. - Instruct
/speckit.planto include a TOC after the document header and before the Summary section. - Instruct
/speckit.tasksto include a TOC after the document header and before the first phase.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| templates/commands/specify.md | Adds instruction to generate a ##-heading TOC with GitHub-style anchors. |
| templates/commands/plan.md | Adds instruction to generate a ##-heading TOC before Summary. |
| templates/commands/tasks.md | Adds instruction to generate a ##-heading TOC before phases. |
Comments suppressed due to low confidence (1)
templates/commands/specify.md:123
- PR description mentions adding exemplar TOC sections to
templates/spec-template.md,templates/plan-template.md, andtemplates/tasks-template.md, but those files currently contain no “Table of Contents” section (verified via search). Either update the structure templates as described, or adjust the PR description/scope so it matches what’s actually changed.
5. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings. Include a **Table of Contents** section immediately after the header metadata block and before the first content section. The TOC must list all `##`-level headings as markdown anchor links (lowercase, spaces to hyphens, strip special characters). Example: `- [User Scenarios & Testing](#user-scenarios--testing)`. Only include sections that actually appear in the final document.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mnriem
left a comment
There was a problem hiding this comment.
Please address Copilot feedback. If not applicable, please explain why
|
Addressed all 3 Copilot comments replaced ambiguous 'header metadata block' wording with |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please address Copilot feedback. If not applicable, please explain why |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please address Copilot feedback. If not applicable please explain why! |
|
Addressed Copilot feedback — fixed TOC anchors in spec-template.md to include the -mandatory suffix matching the actual heading IDs. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please address Copilot feedback. Hopefully that will be the last round |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Address the last nit from Copilot and I think we are ready :) |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Looks like there is more critical Copilot feedback |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please address Copilot feedback. Keep in mind that these are indeed templates so we probably have instructions in the corresponding command to actually add those slugs with an example there and have none here? This should apply to all templates I would guess. |
|
Good point removed all hardcoded anchor links from the structure templates. Templates now contain |
|
The comment should not be in the template as the command that uses the template is responsible for filling it in and knows how to do that |
|
Removed the HTML comments from all three templates — the command templates already have the |
There was a problem hiding this comment.
Pull request overview
Adds Table of Contents (TOC) guidance and exemplar sections to the markdown templates used by speckit so generated spec.md, plan.md, and tasks.md are easier to navigate.
Changes:
- Added
## Table of Contentssections to spec/plan/tasks structure templates. - Updated command templates (
specify,plan,tasks) to instruct agents to generate TOCs from##headings using GitHub-style anchors. - Standardized TOC scope to
##-level headings to keep TOCs concise.
Show a summary per file
| File | Description |
|---|---|
| templates/tasks-template.md | Adds an exemplar TOC section to the tasks template. |
| templates/spec-template.md | Adds an exemplar TOC section to the spec template. |
| templates/plan-template.md | Adds an exemplar TOC section to the plan template. |
| templates/commands/tasks.md | Instructs tasks generation to include a TOC with anchor links. |
| templates/commands/specify.md | Instructs spec generation to include a TOC with anchor links (with example). |
| templates/commands/plan.md | Instructs plan generation to include a TOC with anchor links. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 2
|
OK since this seems to have higher impact than I initially realized I suggest we pivot and I am going to ask you to deliver this as a preset (see https://github.com/github/spec-kit/tree/main/presets) so you can try out these changes and make sure they work well and we can refer people to the preset. Below I have included an impact assessment that explains why I am asking for this pivot. PR #2080 Impact Assessment: TOC Generation for Spec-Driven Documents1. Template TOC Entries Are NOT Anchor Links (Inconsistency with Commands)The command files (
The But the template exemplars use plain text instead: - Summary
- Technical ContextThe templates serve as the structural reference that commands instruct AI to follow. An AI seeing the template's plain-text format may replicate it verbatim instead of generating proper anchor links as the command instructions demand — creating a direct conflict between the two sources of truth. 2. Missing Headings in tasks-template TOCThe
The TOC entry 3. spec-template TOC Omits Heading DecoratorsThe actual headings in ## User Scenarios & Testing *(mandatory)*
## Requirements *(mandatory)*
## Success Criteria *(mandatory)*The TOC lists them without the annotation: - User Scenarios & Testing
- Requirements
- Success CriteriaThis is arguably fine since the command instruction says "strip special characters" — but the 4. plan-template TOC Placement Creates Awkward StructureThe TOC is inserted between the metadata block and the **Input**: Feature specification from `/specs/[###-feature-name]/spec.md`
## Table of Contents ← TOC inserted here
- Summary
...
**Note**: This template is filled in by... ← Meta-content now sits between TOC and first real section
## SummaryThe 5. Downstream Consumer:
|
| # | Angle | Severity | Type |
|---|---|---|---|
| 1 | Template exemplars use plain text, not anchor links | High | Conflict between templates and command instructions |
| 2 | tasks-template TOC has fabricated/missing headings | High | Factual incorrectness |
| 3 | spec-template TOC ignores *(mandatory)* in headings |
Medium | Ambiguous anchor generation |
| 4 | plan-template TOC placement buries **Note** paragraph |
Low | Structural awkwardness |
| 5 | analyze.md not updated for new TOC section | Low | Potential false positive in analysis |
| 6 | clarify.md may leave TOC stale after spec edits | Medium | TOC drift after clarification |
| 7 | implement.md could misparse TOC as a task phase | Low | Edge case for weaker models |
| 8 | Internal format inconsistency (plain text vs. anchor links) | Medium | Self-contradictory PR |
Items 1, 2, and 3 are the most actionable and should be addressed before merge.
Pivots from core template changes to a preset approach per reviewer request. Adds presets/toc-navigation/ with 3 template overrides and 3 command overrides that add Table of Contents sections to generated spec.md, plan.md, and tasks.md documents. Addresses all 8 impact concerns from review: - Templates use anchor links (not plain text) matching command instructions - All 12 tasks-template headings accounted for (dynamic phases as plain text) - spec-template anchors include -mandatory suffix - TOC placed after Note paragraph in plan-template - Self-reference exclusion explicit in all commands - Clarify stale TOC instruction in specify command - Implement misparse warning in tasks command Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
--- Pivoted to a preset approach as requested. The TOC is now delivered as presets/toc-navigation/ instead What changed:
All 8 impact concerns addressed:
|
Summary
tasks-template.md)
##-level headings included to keep TOC conciseCloses #1970
Changes
templates/spec-template.mdtemplates/plan-template.mdtemplates/tasks-template.mdtemplates/commands/specify.mdtemplates/commands/plan.mdtemplates/commands/tasks.mdDesign decisions