Skip to content

Commit 38928fe

Browse files
committed
feat: Add precision-guided navigation for long slash commands
## Motivation Generated speckit commands can exceed 500-1000 lines (e.g., marketing-spec-kit has 4 commands >800 lines), consuming excessive tokens when AI reads them. ## Solution Add guidance in `implement.md.j2` for AI to generate navigation tables for long commands (>500 lines). ## Changes ### Added Section: "3. Optimize Long Slash Commands" **Location**: After pyproject.toml guidance (lines 433-508, 75 lines) **Content**: 1. **When**: Commands exceed 500 lines 2. **Why**: Save 70-90% token consumption 3. **How**: Add navigation guide at file start 4. **Template**: Complete navigation template with: - Section breakdown (4-6 sections, 100-300 lines each) - Line numbers and read_file usage - Token savings calculation - Typical usage patterns 5. **Guidelines**: - Threshold: 500 lines - Token estimate: ~3.5 tokens/line - Section design principles 6. **Example**: 847-line command breakdown ### Updated Navigation Table **File size**: 1084 → 1158 lines (+74 lines) **Main table**: - Section 7: 275-464 (189) → 275-525 (251 lines) +62 - Section 8-10: 465-556 → 526-617 +61 - Section 11-13: 557-681 → 618-742 +61 - Section 14-15: 682-808 → 743-869 +61 - Section 16: 809-1096 → 870-1158 +61 **Section 7 subsections**: - Python: 306-446 (141) → 306-508 (203 lines) * Now includes: command navigation guidance (74 lines) **Phase-specific**: - Added: Command Navigation (433-508, 75 lines) - Updated all phase line numbers **Token savings**: - Full file: ~3800 → ~4050 tokens - Command navigation: 75 lines (~260 tokens) → **94% savings** ## Benefits 1. ✅ **Token optimization**: 70-90% savings for long commands 2. ✅ **Consistency**: Matches MetaSpec's own command style 3. ✅ **Best practice**: Guides AI to follow precision navigation pattern 4. ✅ **Scalability**: Works for any domain (SDM, SDT, SDO, etc.) ## Example Use Cases - marketing-spec-kit: 4 commands >800 lines need navigation - Future speckits with complex workflows - Any SD-X system with detailed command guidance
1 parent 8b2baea commit 38928fe

File tree

1 file changed

+102
-22
lines changed

1 file changed

+102
-22
lines changed

src/metaspec/templates/meta/sdd/commands/implement.md.j2

Lines changed: 102 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,47 @@ You **MUST** consider the user input before proceeding (if not empty).
2828
|------|-------|------|----------|-----------------|
2929
| 1-5. Prerequisites & Setup | 86-232 | 146 lines | 🔴 MUST READ | `read_file(target_file, offset=86, limit=146)` |
3030
| 6. Execute Implementation | 233-274 | 41 lines | 🔴 MUST READ | `read_file(target_file, offset=233, limit=41)` |
31-
| **7. Task Execution Details** ⭐ | 275-464 | 189 lines | 🔴 **KEY** | See subsections below ⬇️ |
32-
| 8-10. Checkpoints & Reporting | 465-556 | 91 lines | 🟡 Important | `read_file(target_file, offset=465, limit=91)` |
33-
| 11-13. Validation & Saves | 557-681 | 124 lines | 🟡 Important | `read_file(target_file, offset=557, limit=124)` |
34-
| 14-15. Propagation & Validation | 682-808 | 126 lines | 🟡 Important | `read_file(target_file, offset=682, limit=126)` |
35-
| 16. Final Report | 809-1096 | 287 lines | 🟢 Reference | `read_file(target_file, offset=809, limit=287)` |
31+
| **7. Task Execution Details** ⭐ | 275-525 | 251 lines | 🔴 **KEY** | See subsections below ⬇️ |
32+
| 8-10. Checkpoints & Reporting | 526-617 | 91 lines | 🟡 Important | `read_file(target_file, offset=526, limit=91)` |
33+
| 11-13. Validation & Saves | 618-742 | 124 lines | 🟡 Important | `read_file(target_file, offset=618, limit=124)` |
34+
| 14-15. Propagation & Validation | 743-869 | 126 lines | 🟡 Important | `read_file(target_file, offset=743, limit=126)` |
35+
| 16. Final Report | 870-1158 | 288 lines | 🟢 Reference | `read_file(target_file, offset=870, limit=288)` |
3636

37-
**📋 Section 7: Task Execution Details by Language** (189 lines):
37+
**📋 Section 7: Task Execution Details by Language** (251 lines):
3838

3939
| Component | Lines | Size | Usage |
4040
|-----------|-------|------|-------|
41-
| **Python Implementation** ⭐ | 306-446 | 141 lines | `read_file(target_file, offset=306, limit=141)` |
41+
| **Python Implementation** ⭐ | 306-508 | 203 lines | `read_file(target_file, offset=306, limit=203)` |
4242
| **TypeScript Implementation** | 315-323 | 8 lines | `read_file(target_file, offset=315, limit=8)` |
4343
| **Go Implementation** | 324-332 | 8 lines | `read_file(target_file, offset=324, limit=8)` |
4444
| **Rust Implementation** | 333-341 | 8 lines | `read_file(target_file, offset=333, limit=8)` |
4545

46-
**Note**: Python section (141 lines) includes overview (8 lines) + detailed `pyproject.toml` structure (97 lines) with `[tool.metaspec]` metadata, CLI commands, slash commands, sd_type calculation, and 3 example scenarios.
46+
**Note**: Python section (203 lines) includes overview (8 lines) + `pyproject.toml` structure (97 lines) + **long command navigation guidance (74 lines)** with template and examples.
4747

4848
**🎯 Phase-Specific Reading** (By component type):
4949

5050
| Phase | Lines | Size | Usage |
5151
|-------|-------|------|-------|
52-
| Setup & pyproject.toml | 136-207, 306-446 | 211 lines | `read_file(target_file, offset=136, limit=71)` + `offset=306, limit=141` |
52+
| Setup & pyproject.toml | 136-207, 306-508 | 273 lines | `read_file(target_file, offset=136, limit=71)` + `offset=306, limit=203` |
5353
| Language-Specific Impl | 306-341 | 35 lines | `read_file(target_file, offset=306, limit=35)` |
54-
| Checkpoints & Validation | 465-556 | 91 lines | `read_file(target_file, offset=465, limit=91)` |
55-
| Progress & Error Handling | 489-556 | 67 lines | `read_file(target_file, offset=489, limit=67)` |
56-
| Completion & Reporting | 557-681 | 124 lines | `read_file(target_file, offset=557, limit=124)` |
54+
| Command Navigation | 433-508 | 75 lines | `read_file(target_file, offset=433, limit=75)` |
55+
| Checkpoints & Validation | 526-617 | 91 lines | `read_file(target_file, offset=526, limit=91)` |
56+
| Progress & Error Handling | 550-617 | 67 lines | `read_file(target_file, offset=550, limit=67)` |
57+
| Completion & Reporting | 618-742 | 124 lines | `read_file(target_file, offset=618, limit=124)` |
5758

5859
**💡 Typical Usage Patterns**:
5960
```python
6061
# Quick start: Read Prerequisites only (146 lines)
6162
read_file(target_file, offset=86, limit=146)
6263

63-
# Python implementation: Read Python guidance + pyproject.toml update (141 lines)
64-
read_file(target_file, offset=306, limit=141)
64+
# Python implementation: Read Python guidance + pyproject.toml + navigation (203 lines)
65+
read_file(target_file, offset=306, limit=203)
66+
67+
# Command navigation: Read long command optimization guidance (75 lines)
68+
read_file(target_file, offset=433, limit=75)
6569

6670
# Validation phase: Read validation guidance (124 lines)
67-
read_file(target_file, offset=557, limit=124)
71+
read_file(target_file, offset=618, limit=124)
6872

6973
# Specific language: Jump to language section
7074
read_file(target_file, offset=315, limit=8) # TypeScript
@@ -73,11 +77,12 @@ read_file(target_file, offset=333, limit=8) # Rust
7377
```
7478

7579
**Token Savings**:
76-
- Full file: 1097 lines (~3800 tokens)
77-
- Prerequisites only: 146 lines (~500 tokens) → **87% savings**
80+
- Full file: 1158 lines (~4050 tokens)
81+
- Prerequisites only: 146 lines (~500 tokens) → **88% savings**
7882
- Language-specific: 8 lines (~30 tokens) → **99% savings** 🏆
79-
- Python + pyproject.toml: 141 lines (~490 tokens) → **87% savings**
80-
- Phase-specific: 67-211 lines (~230-730 tokens) → **81-94% savings**
83+
- Python + metadata + navigation: 203 lines (~710 tokens) → **82% savings**
84+
- Command navigation only: 75 lines (~260 tokens) → **94% savings**
85+
- Phase-specific: 67-273 lines (~230-950 tokens) → **77-94% savings**
8186

8287
---
8388

@@ -430,7 +435,82 @@ grep -A 30 "^## Implementation" specs/toolkit/001-*/spec.md
430435
- Understand AI command system type (what workflow pattern?)
431436
- Search/filter speckits by capabilities
432437

433-
3. **Verify task**:
438+
3. **Optimize Long Slash Commands** ⭐ NEW
439+
440+
**When**: Slash command files in `.metaspec/commands/` or `templates/*/commands/` exceed 500 lines
441+
442+
**Why**: Save 70-90% token consumption when AI reads commands
443+
444+
**How**: Add precision-guided navigation at file start (after frontmatter)
445+
446+
**Navigation Template**:
447+
448+
```markdown
449+
---
450+
name: command-name
451+
description: Command description
452+
---
453+
454+
# /command-name
455+
456+
📖 **Navigation Guide** (Token Optimization)
457+
458+
**File Size**: {line_count} lines (~{token_estimate} tokens)
459+
**Recommended**: Read specific sections to save 70-90% tokens
460+
461+
| Section | Lines | Size | Usage |
462+
|---------|-------|------|-------|
463+
| 1. Purpose & Usage | 1-100 | 100 lines | `read_file(target, offset=1, limit=100)` |
464+
| 2. Input Analysis | 101-250 | 150 lines | `read_file(target, offset=101, limit=150)` |
465+
| 3. Processing Rules | 251-500 | 250 lines | `read_file(target, offset=251, limit=250)` |
466+
| 4. Output Format | 501-750 | 250 lines | `read_file(target, offset=501, limit=250)` |
467+
| 5. Examples | 751-{end} | {size} lines | `read_file(target, offset=751, limit={size})` |
468+
469+
**💡 Typical Usage**:
470+
```python
471+
# Quick reference: Read purpose only (100 lines)
472+
read_file(target, offset=1, limit=100)
473+
474+
# Specific section: Read processing rules (250 lines)
475+
read_file(target, offset=251, limit=250)
476+
477+
# Full understanding: Read all sections sequentially
478+
```
479+
480+
**Token Savings**:
481+
- Full file: {line_count} lines (~{token_estimate} tokens)
482+
- Single section: 100-250 lines (~350-850 tokens) → **70-90% savings** 🏆
483+
484+
---
485+
486+
[Actual command content starts here...]
487+
```
488+
489+
**Guidelines**:
490+
- **Threshold**: Add navigation for commands >500 lines
491+
- **Sections**: 4-6 logical sections, each 100-300 lines
492+
- **Line Numbers**: Calculate actual boundaries (use `wc -l`)
493+
- **Token Estimate**: ~3.5 tokens per line average
494+
- **Savings**: Emphasize 70-90% for section reads
495+
496+
**Section Design**:
497+
- Section 1: Purpose, usage, quick reference
498+
- Section 2-N: Major logical blocks (input, rules, output, etc.)
499+
- Last section: Examples and edge cases
500+
501+
**Example Calculation**:
502+
```bash
503+
# For 847-line command
504+
Section 1: Purpose & Usage (1-100, 100 lines)
505+
Section 2: Input Analysis (101-250, 150 lines)
506+
Section 3: Processing Rules (251-500, 250 lines)
507+
Section 4: Output Format (501-700, 200 lines)
508+
Section 5: Examples (701-847, 147 lines)
509+
510+
Token savings: 847 lines → 150 lines = 82% savings
511+
```
512+
513+
4. **Verify task**:
434514
- **SETUP**: Files created, configs valid, dependencies installable
435515
- **MODELS**: Models instantiable, match specification entities
436516
- **PARSER**: Can parse valid/invalid specs, error handling works
@@ -439,11 +519,11 @@ grep -A 30 "^## Implementation" specs/toolkit/001-*/spec.md
439519
- **TESTS**: Tests pass, coverage adequate
440520
- **DOCS**: Documentation complete, examples work
441521

442-
4. **Mark complete**:
522+
5. **Mark complete**:
443523
- Update tasks.md: `- [ ] T001` → `- [x] T001`
444524
- Report: "✅ T001 complete: Created directory structure"
445525

446-
5. **Handle errors**:
526+
6. **Handle errors**:
447527
- If task fails: Report error, suggest fix
448528
- If sequential task fails: Halt phase
449529
- If parallel task fails: Continue others, report at end

0 commit comments

Comments
 (0)