feat: extract repetitive bash patterns into gsd-tools commands (#472)

* feat(gsd-tools): add history-digest, atomic state operations, and summary variants

Adds new performance-focused commands to gsd-tools and introduces specialized
summary templates to reduce context tax:

- history-digest: Compiles phase summaries into structured JSON for JIT loading
- state get/patch: Enables atomic STATE.md operations instead of full rewrites
- template select: Automatically chooses optimal summary template based on plan complexity
- Adds minimal, standard, and complex summary templates

Part of the "Hydra" architecture for GSD context optimization.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* chore: add project config

* docs: define v1 requirements

* docs: create roadmap (6 phases)

* feat(history-digest): fix nested YAML parsing and add tests

- Fix extractFrontmatter() to handle nested YAML structures like
  dependency-graph.provides, tech-stack.added using stack-based parsing
- Add test infrastructure with Node test runner (npm test)
- Update gsd-planner to use digest fields directly instead of reading
  full SUMMARY.md files
- Add 6 schema validation tests covering nested fields, merging,
  malformed files, and backward compatibility

Closes: HIST-01, HIST-02, HIST-03, HIST-04

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* fix(planner): use digest for selection, full SUMMARY for understanding

The previous commit went too far by eliminating full SUMMARY reads.
The digest is an index for smart selection, not a replacement for
understanding what actually happened.

Two-step approach:
1. Digest to score/select relevant phases (2-4 typically)
2. Full SUMMARY read for selected phases (implementation details)
3. Digest-level context retained for unselected phases

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(gsd-tools): add phases, roadmap, and phase commands

TDD implementation of three new commands to replace repetitive bash:

phases list [--type plans|summaries] [--phase N]
- Lists phase directories sorted numerically (handles decimals)
- Filter by file type or specific phase
- Replaces: ls -d .planning/phases/*/ | sort -V (22 occurrences)

roadmap get-phase <N>
- Extracts phase section from ROADMAP.md
- Returns name, goal, full section content
- Replaces: grep -A20 "Phase X:" ROADMAP.md (19 occurrences)

phase next-decimal <N>
- Calculates next decimal phase (06 → 06.1, 06.2 → 06.3)
- Handles gaps, normalizes input
- Replaces: complex bash math in insert-phase (3 occurrences)

16 new tests, all passing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* refactor: migrate agents/workflows to use gsd-tools commands

Replace inline bash patterns with centralized gsd-tools commands:

phases list:
- audit-milestone.md: ls -d .planning/phases/*/ | sort -V
- plan-milestone-gaps.md: ls -d ... | sort -V | tail -1

roadmap get-phase:
- plan-phase.md: grep -A5 "Phase X:" ROADMAP.md (2 occurrences)
- research-phase.md: grep patterns (2 occurrences)
- verify-phase.md: grep -A5 pattern
- gsd-verifier.md: grep -A5 pattern
- gsd-plan-checker.md: grep -A10 pattern
- commands/gsd/research-phase.md: grep patterns (2 occurrences)

phase next-decimal:
- insert-phase.md: complex bash decimal calculation
- decimal-phase-calculation.md: reference doc rewritten

phase-argument-parsing.md: updated to reference gsd-tools

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
TÂCHES
2026-02-08 00:44:49 -06:00
committed by GitHub
parent 3f5ab10713
commit 1b317dec45
29 changed files with 2938 additions and 84 deletions

63
.planning/PROJECT.md Normal file
View File

@@ -0,0 +1,63 @@
# GSD Context Optimization
## What This Is
Optimizing GSD's context loading so agents start lean and stay in their peak quality zone. Reduces prompt bloat through lazy loading, tiered prompts, and compiled artifacts while preserving instructional density.
## Core Value
Agents execute at peak quality by starting at 8-12% context instead of 15-25%.
## Requirements
### Validated
(None yet — ship to validate)
### Active
- [ ] History loads as structured digest instead of full SUMMARY.md files
- [ ] Summary templates match plan complexity (minimal/standard/complex)
- [ ] State operations are atomic patches, not full file read/write cycles
- [ ] Executor loads references on-demand based on task type
- [ ] Planner loads extensions based on planning mode
- [ ] Plans can be pre-compiled before execution
### Out of Scope
- Enhanced semantic queries (Phase 4) — defer unless Phases 1-3 prove insufficient
- Compressing instructional content — core methodology must remain intact
- Complex cache invalidation — simple mtime checks are sufficient
## Context
**Problem:** Claude's quality degrades predictably with context load:
- 0-30% context: Peak quality
- 30-50%: Good, occasional shortcuts
- 50-70%: Degrading, efficiency mode
- 70%+: Poor, rushed, misses requirements
Complex phases currently start agents at 15-25% context from prompt loading alone—before any codebase reading.
**Prior work:** v1.12.x shipped compound init commands (4,245 net line reduction), proving the direction works.
**Target state:** Agents start at 8-12% context, preserving peak quality zone for execution.
## Constraints
- **Instructional density**: Teaching content cannot be compressed—it's GSD's value
- **Adaptive intelligence**: Agents must still handle mid-execution surprises
- **Maintainability**: Clear separation between core and extensions
- **Debuggability**: Easy to trace which modules loaded for any execution
- **TDD**: Use test-driven development for gsd-tools.js changes — write tests first, then implementation
## Key Decisions
| Decision | Rationale | Outcome |
|----------|-----------|---------|
| Lazy loading over railroad architecture | Preserves adaptive intelligence while reducing context | — Pending |
| Build on compound-init foundation | v1.12.x proved the pattern works | — Pending |
| Three-phase implementation | Incremental, reversible changes | — Pending |
---
*Last updated: 2025-02-07 after initialization*

114
.planning/REQUIREMENTS.md Normal file
View File

@@ -0,0 +1,114 @@
# Requirements: GSD Context Optimization
**Defined:** 2025-02-07
**Core Value:** Agents execute at peak quality by starting at 8-12% context instead of 15-25%
## v1 Requirements
### History Digest
- [ ] **HIST-01**: `gsd-tools history-digest` generates structured JSON from SUMMARY.md frontmatter
- [ ] **HIST-02**: Digest includes phases, provides, patterns, affects, decisions, and tech_stack
- [ ] **HIST-03**: Planner uses digest instead of reading full SUMMARY.md files
- [ ] **HIST-04**: Tests verify digest output matches expected schema
### Summary Variants
- [ ] **SUMM-01**: Three summary templates exist: minimal (~30 lines), standard (~60 lines), complex (~100 lines)
- [ ] **SUMM-02**: `gsd-tools select-template` returns appropriate template based on plan complexity
- [ ] **SUMM-03**: Selection logic considers task count, decision tasks, and file count
- [ ] **SUMM-04**: Executor uses selected template for summary creation
- [ ] **SUMM-05**: Tests verify template selection logic
### Atomic State Operations
- [ ] **STATE-01**: `gsd-tools state get <field>` returns specific STATE.md field value
- [ ] **STATE-02**: `gsd-tools state patch --field value` updates specific fields atomically
- [ ] **STATE-03**: Agents use atomic ops instead of full STATE.md read/write
- [ ] **STATE-04**: Tests verify get/patch operations
### Lazy-Load Executor
- [ ] **EXEC-01**: `gsd-executor-core.md` contains base executor (~150 lines)
- [ ] **EXEC-02**: `references/executor/` contains modular references (deviation-rules, tdd, checkpoint, continuation, summary-creation)
- [ ] **EXEC-03**: Executor loads TDD reference only when task.tdd="true"
- [ ] **EXEC-04**: Executor loads checkpoint reference only when task.type="checkpoint:*"
- [ ] **EXEC-05**: Executor loads continuation reference only when <completed_tasks> present
- [ ] **EXEC-06**: Executor loads summary-creation reference at plan completion
### Tiered Planner
- [ ] **PLAN-01**: `gsd-planner-core.md` contains base planner (~300 lines)
- [ ] **PLAN-02**: `gsd-planner-ext/` contains extensions (gap-closure, revision, tdd, checkpoints)
- [ ] **PLAN-03**: Orchestrator builds prompt dynamically based on flags and context
- [ ] **PLAN-04**: Gap-closure extension loads only with --gaps flag
- [ ] **PLAN-05**: Revision extension loads only when checker issues exist
- [ ] **PLAN-06**: TDD extension loads only when TDD candidates detected
### Compiled Plans
- [ ] **COMP-01**: `gsd-tools compile-plan` inlines all @ references
- [ ] **COMP-02**: Compilation strips irrelevant sections based on task types
- [ ] **COMP-03**: Compiled plans saved as .compiled.md
- [ ] **COMP-04**: Executor uses compiled version when available
- [ ] **COMP-05**: Staleness detection via mtime comparison
- [ ] **COMP-06**: Tests verify compilation output
## v2 Requirements
### Enhanced Semantic Queries
- **SEM-01**: gsd-memory MCP supports structured queries (what_uses, pattern_for, decisions_affecting)
## Out of Scope
| Feature | Reason |
|---------|--------|
| Compressing instructional content | Core methodology must remain intact |
| Complex cache invalidation | Simple mtime checks are sufficient |
| Railroad architecture | Loses adaptive intelligence |
## Traceability
| Requirement | Phase | Status |
|-------------|-------|--------|
| HIST-01 | Phase 1 | Pending |
| HIST-02 | Phase 1 | Pending |
| HIST-03 | Phase 1 | Pending |
| HIST-04 | Phase 1 | Pending |
| SUMM-01 | Phase 2 | Pending |
| SUMM-02 | Phase 2 | Pending |
| SUMM-03 | Phase 2 | Pending |
| SUMM-04 | Phase 2 | Pending |
| SUMM-05 | Phase 2 | Pending |
| STATE-01 | Phase 3 | Pending |
| STATE-02 | Phase 3 | Pending |
| STATE-03 | Phase 3 | Pending |
| STATE-04 | Phase 3 | Pending |
| EXEC-01 | Phase 4 | Pending |
| EXEC-02 | Phase 4 | Pending |
| EXEC-03 | Phase 4 | Pending |
| EXEC-04 | Phase 4 | Pending |
| EXEC-05 | Phase 4 | Pending |
| EXEC-06 | Phase 4 | Pending |
| PLAN-01 | Phase 5 | Pending |
| PLAN-02 | Phase 5 | Pending |
| PLAN-03 | Phase 5 | Pending |
| PLAN-04 | Phase 5 | Pending |
| PLAN-05 | Phase 5 | Pending |
| PLAN-06 | Phase 5 | Pending |
| COMP-01 | Phase 6 | Pending |
| COMP-02 | Phase 6 | Pending |
| COMP-03 | Phase 6 | Pending |
| COMP-04 | Phase 6 | Pending |
| COMP-05 | Phase 6 | Pending |
| COMP-06 | Phase 6 | Pending |
**Coverage:**
- v1 requirements: 28 total
- Mapped to phases: 28
- Unmapped: 0 ✓
---
*Requirements defined: 2025-02-07*
*Last updated: 2025-02-07 after initial definition*

183
.planning/ROADMAP.md Normal file
View File

@@ -0,0 +1,183 @@
# Roadmap: GSD Context Optimization
**Created:** 2025-02-07
**Phases:** 6
**Depth:** Standard
**Core Value:** Agents execute at peak quality by starting at 8-12% context instead of 15-25%
## Overview
| # | Phase | Goal | Requirements | Status |
|---|-------|------|--------------|--------|
| 1 | History Digest | Planner loads structured digest instead of full SUMMARY.md | HIST-01, HIST-02, HIST-03, HIST-04 | Pending |
| 2 | Summary Variants | Executor produces right-sized summaries | SUMM-01, SUMM-02, SUMM-03, SUMM-04, SUMM-05 | Pending |
| 3 | Atomic State | Agents update STATE.md fields atomically | STATE-01, STATE-02, STATE-03, STATE-04 | Pending |
| 4 | Lazy Executor | Executor loads references on-demand | EXEC-01, EXEC-02, EXEC-03, EXEC-04, EXEC-05, EXEC-06 | Pending |
| 5 | Tiered Planner | Planner prompt built dynamically | PLAN-01, PLAN-02, PLAN-03, PLAN-04, PLAN-05, PLAN-06 | Pending |
| 6 | Compiled Plans | Plans pre-compiled for minimal execution context | COMP-01, COMP-02, COMP-03, COMP-04, COMP-05, COMP-06 | Pending |
## Dependencies
```
Phase 1 ─┐
Phase 2 ─┼─► Phase 4 ─► Phase 5 ─► Phase 6
Phase 3 ─┘
```
- Phases 1, 2, 3 can run in parallel (no dependencies)
- Phase 4 depends on Phase 2 (summary templates) and Phase 3 (state ops)
- Phase 5 depends on Phase 4 (executor patterns inform planner structure)
- Phase 6 depends on Phase 4 and 5 (compilation targets both agents)
---
## Phase 1: History Digest
**Goal:** Planner loads structured digest instead of full SUMMARY.md files
**Requirements:** HIST-01, HIST-02, HIST-03, HIST-04
### Success Criteria
1. `gsd-tools history-digest` produces valid JSON with frontmatter fields
2. Digest includes: phases, provides, patterns, affects, decisions, tech_stack
3. Planner startup no longer reads full SUMMARY.md files
4. Tests pass for digest schema validation
### Approach
- Add `history-digest` command to gsd-tools.js
- Parse SUMMARY.md frontmatter (YAML between `---` markers)
- Extract key fields into structured JSON
- Update planner to consume digest instead of full files
- TDD: Write tests first for digest output schema
---
## Phase 2: Summary Variants
**Goal:** Executor produces right-sized summaries based on plan complexity
**Requirements:** SUMM-01, SUMM-02, SUMM-03, SUMM-04, SUMM-05
### Success Criteria
1. Three template files exist: summary-minimal.md (~30 lines), summary-standard.md (~60 lines), summary-complex.md (~100 lines)
2. `gsd-tools select-template` returns appropriate template path
3. Selection considers: task count, decision tasks, file count
4. Executor uses selected template for summary creation
### Approach
- Create three summary templates with increasing detail
- Add `select-template` command with selection logic
- Update executor workflow to call select-template
- TDD: Write tests first for template selection logic
---
## Phase 3: Atomic State Operations
**Goal:** Agents update STATE.md fields atomically without full file read/write
**Requirements:** STATE-01, STATE-02, STATE-03, STATE-04
### Success Criteria
1. `gsd-tools state get <field>` returns specific STATE.md field value
2. `gsd-tools state patch --field value` updates specific fields atomically
3. Agent workflows updated to use atomic ops
4. Tests verify get/patch operations preserve file integrity
### Approach
- Add `state get` subcommand to read specific fields
- Add `state patch` subcommand for atomic field updates
- Parse STATE.md as markdown, update in place
- Update executor/planner workflows to use atomic ops
- TDD: Write tests first for get/patch operations
---
## Phase 4: Lazy-Load Executor
**Goal:** Executor loads references on-demand based on task type
**Requirements:** EXEC-01, EXEC-02, EXEC-03, EXEC-04, EXEC-05, EXEC-06
### Success Criteria
1. `gsd-executor-core.md` contains base executor (~150 lines)
2. `references/executor/` contains: deviation-rules.md, tdd-execution.md, checkpoint-protocol.md, continuation.md, summary-creation.md
3. TDD reference loads only when task.tdd="true"
4. Checkpoint reference loads only for task.type="checkpoint:*"
5. Continuation reference loads only when <completed_tasks> present
### Approach
- Extract current executor into core + modular references
- Core contains: role, task execution loop, basic flow
- References contain: specialized protocols for specific situations
- Add conditional @ references based on task attributes
- Measure context reduction vs current executor
---
## Phase 5: Tiered Planner
**Goal:** Planner prompt built dynamically based on planning mode
**Requirements:** PLAN-01, PLAN-02, PLAN-03, PLAN-04, PLAN-05, PLAN-06
### Success Criteria
1. `gsd-planner-core.md` contains base planner (~300 lines)
2. `gsd-planner-ext/` contains: gap-closure.md, revision.md, tdd.md, checkpoints.md
3. Gap-closure loads only with --gaps flag
4. Revision loads only when checker issues exist
5. TDD loads only when TDD candidates detected
### Approach
- Extract current planner into core + extensions
- Core contains: role, philosophy, task breakdown, plan format
- Extensions contain: specialized planning modes
- Update orchestrator to build prompt dynamically
- Measure context reduction vs current planner
---
## Phase 6: Compiled Plans
**Goal:** Plans pre-compiled for minimal execution context
**Requirements:** COMP-01, COMP-02, COMP-03, COMP-04, COMP-05, COMP-06
### Success Criteria
1. `gsd-tools compile-plan` inlines all @ references
2. Compilation strips irrelevant sections based on task types in plan
3. Compiled plans saved as .compiled.md alongside original
4. Executor uses compiled version when fresh (mtime check)
5. Tests verify compilation output matches expected structure
### Approach
- Add `compile-plan` command to gsd-tools.js
- Resolve all @ references recursively
- Strip sections not relevant to this plan's tasks
- Save as PLAN.compiled.md
- Update executor to prefer compiled version
- TDD: Write tests first for compilation logic
---
## Coverage
**v1 Requirements:** 28 total
**Mapped to phases:** 28
**Unmapped:** 0 ✓
---
*Roadmap created: 2025-02-07*
*Last updated: 2025-02-07 after initial creation*

45
.planning/STATE.md Normal file
View File

@@ -0,0 +1,45 @@
# Project State: GSD Context Optimization
## Current Position
**Phase:** 1 - History Digest
**Status:** Not Started
**Plan:** None
## Project Reference
See: .planning/PROJECT.md (updated 2025-02-07)
**Core value:** Agents execute at peak quality by starting at 8-12% context instead of 15-25%
**Current focus:** Phase 1 - History Digest
## Phase Progress
| Phase | Status | Plans |
|-------|--------|-------|
| 1 - History Digest | ○ Pending | 0/0 |
| 2 - Summary Variants | ○ Pending | 0/0 |
| 3 - Atomic State | ○ Pending | 0/0 |
| 4 - Lazy Executor | ○ Pending | 0/0 |
| 5 - Tiered Planner | ○ Pending | 0/0 |
| 6 - Compiled Plans | ○ Pending | 0/0 |
## Recent Activity
- 2025-02-07: Project initialized
- 2025-02-07: Requirements defined (28 total)
- 2025-02-07: Roadmap created (6 phases)
## Blockers
None
## Key Decisions
| Decision | Phase | Rationale |
|----------|-------|-----------|
| TDD for gsd-tools changes | All | Write tests first to ensure behavior matches expectations |
| Lazy loading over railroad | All | Preserves adaptive intelligence while reducing context |
---
*Last updated: 2025-02-07 after initialization*

12
.planning/config.json Normal file
View File

@@ -0,0 +1,12 @@
{
"mode": "yolo",
"depth": "standard",
"parallelization": true,
"commit_docs": true,
"model_profile": "quality",
"workflow": {
"research": false,
"plan_check": true,
"verifier": true
}
}