Repository navigation
Description
Problem (User Impact)
The /spec skill prompt is 9,240 tokens (SKILL.md + 3 reference files = 48,321 chars). When loaded, it consumes ~10% of a standard context window before any work begins. Real-world spec executions then generate 12,000–16,000 chars of output (3,500–4,500 tokens), much of which is boilerplate ceremony rather than substantive analysis.
Measured across 3 consumer projects (workout, matcha-maps, sequant-landing):
| Metric | Current | Problem |
|---|---|---|
| Prompt size | 9,240 tokens | Loaded every invocation regardless of issue complexity |
| Code blocks | 45 blocks, 43% of file | 7 npx tsx blocks (6%) reference libs that don't exist in consumer projects |
| Output size | 12K–16K chars/run | Simple 3-AC issues produce same-size output as 13-AC complex issues |
| Execution time | 5–6 minutes | Mandatory 3 explorer agents even for docs/config changes |
| Duplicated sections | 13 headers defined 2–5× each | "Recommended Workflow" defined 5×, output structure specified 3× |
| Dead code | 2,727 chars | npx tsx blocks importing ac-parser, ac-linter, state-manager — none exist in consumer installs |
Impact: Every sequant user pays the full prompt tax on every /spec invocation. Users on metered API plans (Cursor, Windsurf, Claude API) pay real money for tokens that teach the model to call code it can never call. Longer prompts also degrade instruction-following quality — research shows models produce worse output as context noise increases, even within their window limits.
Why Now
- Token costs are the feat: Complete remaining v1.0 features (AC-10, AC-13, AC-14) #1 user friction point for AI coding tools in 2026
- Industry has converged on tiered/lazy-loaded skill architecture — sequant's skills are still monolithic
- Consumer skill versions are already drifting (sequant: 1,139 lines, workout: 813, matcha-maps: 754) with no upgrade path
- This is prerequisite work for MCP server (arch: in-process MCP engine — eliminate subprocess indirection and enable real-time streaming #508) — MCP loads tool schemas eagerly, so skill prompts must be lean
- Martin Fowler's context engineering guide documents the progressive disclosure pattern that all major AI IDEs now implement
Research: Industry Best Practices
1. Tiered Context Architecture (source)
Measured 62% reduction in per-session context:
- Tier 1 (Always loaded): <800 tokens — purpose, critical rules, quick-start
- Tier 2 (On demand): 500–1,500 tokens — component-specific docs loaded when relevant
- Tier 3 (Never loaded): 0 tokens — detailed specs linked but not embedded
2. Progressive Disclosure for Skills (source)
With 42 production skills, lazy loading achieved 97% reduction in startup tokens:
- Level 1 (Metadata): ~10-20 tokens per skill — name + description only
- Level 2 (Documentation): ~200-2,000 tokens on-demand — usage instructions, parameters
- Level 3 (Execution): Tool registration happens only when agent commits to invocation
3. Context Window Pollution (source)
"Including irrelevant data actively worsens hallucinations"
An 800K-token unfocused context produces confused outputs, while a 150-token curated context solves the same task correctly. The spec skill's 45 code blocks (including examples the model never needs to reference) are textbook context pollution.
4. CLAUDE.md / Skill File Best Practices (source)
"Give it 5 rules & point it to the details when it needs them. Think 'email with links', not a '2000-page employee handbook'."
MCP tool schemas inject into context on both sides — keeping skill prompts lean is even more critical for MCP/plugin users.
5. Cursor/Windsurf Rule Architecture (source)
Both major AI IDEs use two-tier rules: global (reusable) + workspace-specific. Task-oriented shortcuts (/plan, /review) encapsulate domain-specific guidance rather than requiring the full rulebook on every invocation.
Acceptance Criteria
Prompt Compression (Target: ~3,700 tokens, 60% reduction)
- AC-1: Consolidate triple output specification into single authoritative template. The output structure is currently defined in prose (sections 1-8), verified in "Output Verification" checklist, and templated in "Output Template" — merge into one template section with inline guidance notes. Target: eliminate ~3,000 tokens of redundancy (13 headers currently defined 2-5× each)
- AC-2: Extract dead
npx tsxcode blocks (ac-parser, ac-linter, state-manager, state/update.ts) into a conditional section or separate reference file. These 7 blocks (2,727 chars) import from./src/lib/paths that only exist in the sequant repo — consumer installs have zeronpx tsxcalls across all logged sessions. Guard with: "If./src/lib/ac-parser.tsexists (sequant repo), run programmatic checks. Otherwise, perform analysis inline." - AC-3: Reduce example verbosity by 60%. Current: 9 example/template blocks consuming 8,274 chars (20% of file). Target: 1 concise example per concept (max 10 lines each), retaining decision framework tables (which are already dense/efficient). Remove the Improve multi-issue reliability: default to parallel worktrees and add spec retry logic #452 case study from SKILL.md (it's already in
references/verification-criteria.md) - AC-4: Convert Feature Quality Planning from 25+ checkbox ceremony to exception-based reporting. Current: model outputs
[x] N/Afor 80% of checkboxes. New pattern: "All standard checks pass. Notable items: [only list gaps/concerns]". Retain full checklist in reference file for complex issues that need it
Complexity-Gated Output (Target: 40-60% output reduction for simple issues)
- AC-5: Define concrete output tiers enforced by issue complexity:
- Simple (
simple-fix,typo,docs-only,bugwith ≤2 AC): AC list + plan + Design Review Q1/Q3 only. Target: <4,000 chars - Standard (3-8 AC, no complexity labels): Full output minus Polish section, minus trivially-passing quality checks. Target: <8,000 chars
- Complex (
complex,refactor,breaking, or 9+ AC): Everything. Target: <15,000 chars
- Simple (
- AC-6: Output tier is announced at the top of spec output:
**Complexity: Standard** (5 ACs, 3 directories)— makes the gating decision transparent and overridable
Conditional Context Gathering (Target: eliminate wasted agent spawns)
- AC-7: Make explorer agent count conditional on issue content instead of mandatory 3:
- Has database/SQL/migration keywords in AC or labels → 3 agents (similar features + codebase + database)
- UI/frontend only → 2 agents (similar features + codebase area, drop database)
- Docs/config/simple-fix → 1 agent (general context only)
- CLI/script changes → 2 agents (similar features + codebase, drop database)
- AC-8: Agent prompts are specific to the issue, not generic templates. Current: "Find similar features for [FEATURE]. Check components/admin/, lib/queries/, docs/patterns/." — the
components/admin/andlib/queries/paths are sequant-specific and don't exist in consumer projects. New: derive search paths frompackage.jsonstructure orlsof the actual project
Platform Portability
- AC-9: Add platform detection preamble that sets capabilities before skill execution:
gh --version→ setsGITHUB_AVAILABLE(gates: issue fetch, phase detection, label review, comment posting).sequant/settings.jsonexists → setsSETTINGS_AVAILABLE(gates: parallel mode, scope config)- If GitHub unavailable: skip phase detection, label review, auto-comment; prompt user for AC from description
- If settings unavailable: use defaults silently (no error)
- AC-10: Agent search paths derived from actual project structure, not hardcoded sequant paths. Replace
components/admin/,lib/queries/,docs/patterns/with dynamic discovery:ls src/ app/ lib/ components/ 2>/dev/nullto build search targets from what actually exists
Skill Versioning & Drift Prevention
- AC-11: Add
versionfield to skill YAML frontmatter thatsequant initstamps andsequant statuschecks. Current drift: sequant source (1,139 lines) vs workout (813 lines) vs matcha-maps (754 lines) — no mechanism to detect or reconcile. Format:version: "2.1"in frontmatter,sequant statusoutputsspec skill: v1.0 (update available: v2.1) - AC-12:
sequant init --upgrade-skillsupdates skill files in.claude/skills/from installed sequant version's templates, with diff preview before overwriting. Does NOT auto-run — user must opt in
Non-Goals
- Rewriting the spec skill from scratch — this is compression and restructuring, not a redesign
- Changing what the spec skill produces — the output sections remain the same, just leaner
- Automated prompt compression (LLMLingua-style) — we're doing manual structural optimization
- MCP-native skill loading — that's arch: in-process MCP engine — eliminate subprocess indirection and enable real-time streaming #508's scope; this makes skills lean enough for MCP
- Removing reference files entirely — they serve as Tier 3 documentation for edge cases
Scope & Gaps to Watch
- Gap: Consumer skill sync — AC-11/AC-12 add versioning but don't auto-upgrade. Users with heavily customized skills may not want upgrades. The diff-preview approach respects this but means some users will stay on old versions
- Gap: Agent count heuristics — AC-7 uses keyword matching which is imperfect. A database-related issue without explicit keywords would get only 2 agents. Acceptable: the model can spawn additional agents if the first round reveals database work
- Gap: Output size enforcement — AC-5 sets targets but LLMs don't strictly respect character limits. The tier announcement (AC-6) primes the model, but actual output may vary ±30%. This is a prompt engineering constraint, not a code bug
- Risk: Over-compression — Removing too many examples could degrade output quality for less capable models (Haiku). Test on Haiku as well as Sonnet/Opus before shipping
- Risk: Breaking existing fullsolve pipelines —
/fullsolveinvokes/specprogrammatically. Ensure compressed output retains all structured markers that downstream phases parse (phase markers, workflow recommendations, AC checksums)
Technical Notes
- Skill files live in 3 mirrored directories:
.claude/skills/,skills/,templates/skills/— all three must be updated - Consumer projects get skills via
sequant initwhich copies fromtemplates/skills/ - The
references/subdirectory within skills supports Tier 3 deferred loading — move verbose content there - Output template should use structured markers (
<!-- SEQUANT_SPEC_TIER: standard -->) for downstream parsing - Test with
wc -wbefore/after to verify token reduction targets
Dependencies
- Depends on: Nothing — fully independent
- Blocks: MCP server (arch: in-process MCP engine — eliminate subprocess indirection and enable real-time streaming #508) benefits from leaner skill prompts
- Related: Phase plugin registry (arch: phase plugin registry — user-extensible workflow phases #505) — user-extensible phases will need the same tiered pattern
Verification Plan
| AC | Method | How to Verify |
|---|---|---|
| AC-1 through AC-4 | Manual measurement | wc -w on SKILL.md before/after; target ≤3,700 tokens (from 9,240) |
| AC-5, AC-6 | Integration test | Run /spec on a simple-fix issue and a complex issue; measure output char counts |
| AC-7, AC-8 | Log analysis | Run /spec on 3 issue types; verify agent spawn count matches heuristic |
| AC-9, AC-10 | Manual test | Run /spec in a non-GitHub project; verify graceful fallback |
| AC-11, AC-12 | Unit test | sequant status shows version mismatch; sequant init --upgrade-skills shows diff |
Activity
admarble commentedon Apr 12, 2026
→ PROCEED — 12 ACs, spec compression + tiered context, no blockers
spec → exec → qa · 12 ACs · -q (complex, multi-concern: prompt + output + agents + platform + versioning)
⚠ Sequence after #502 (dead code cleanup simplifies SKILL.md files first)
admarble commentedon Apr 12, 2026
Note: AC-2's
scripts/state/update.tsremoval overlaps with #502 (which removes dead state references from all skill templates). #502 is sequenced first — after it lands, AC-2's remaining scope is the other deadnpx tsxblocks: ac-parser, ac-linter, state-manager.admarble commentedon Apr 12, 2026
Spec Plan — #515: Spec prompt compression and tiered context
Complexity: Complex (12 ACs, 5 concerns, ~30 files across 3 skill dirs)
Dependency: #502 merged ✅
Implementation Plan
Phase 1: Prompt Compression (AC-1 through AC-4)
npx tsxblocks (ac-parser, ac-linter, state-manager) with conditional: "If./src/lib/ac-parser.tsexists, run programmatic checks. Otherwise, perform analysis inline."Phase 2: Complexity-Gated Output (AC-5, AC-6)
5. AC-5: Add output tier definitions gated by issue complexity (simple/standard/complex). Simple: AC list + plan + Q1/Q3 only. Standard: full minus polish. Complex: everything.
6. AC-6: Add tier announcement at top of output:
**Complexity: Standard** (5 ACs, 3 directories).Phase 3: Conditional Context Gathering (AC-7, AC-8)
7. AC-7: Replace mandatory 3-agent spawn with keyword-conditional agent count. DB keywords → 3, UI → 2, docs/config → 1.
8. AC-8: Replace hardcoded
components/admin/,lib/queries/paths with dynamic discovery:ls src/ app/ lib/ components/ 2>/dev/null.Phase 4: Platform Portability (AC-9, AC-10)
9. AC-9: Add platform detection preamble checking
gh,.sequant/settings.json. Gates downstream features.10. AC-10: Dynamic search paths (same work as AC-8, combined).
Phase 5: Skill Versioning (AC-11, AC-12)
11. AC-11: Add
versionfield to skill YAML frontmatter. Add version check tosequant statusoutput.12. AC-12: Add
sequant init --upgrade-skillswith diff preview before overwriting.Design Review
.claude/skills/spec/SKILL.md(prompt layer). AC-11/12 touchsrc/commands/init.tsandsrc/commands/status.ts.package.jsonversion pattern.Verification
wc -won SKILL.md: target ≤3,700 tokens (from 5,496 words)/specon simple vs complex issue, compare output sizes/specon 3 issue types, verify agent count/specin non-GitHub project, verify fallbacksequant statusshows version infosequant init --upgrade-skillsshows diff previewRecommended Workflow
Phases: spec → exec → qa
Quality Loop: enabled (12 ACs, complex multi-concern)
Risk
feat(#515): compress spec skill prompt by 75% and add tiered context
fix(#515): reuse getTemplatesDir() in upgradeSkills instead of duplic…
admarble commentedon Apr 13, 2026
/fullsolve Complete
Issue: #515
Status: READY_FOR_MERGE
PR: #523
Summary
version: "2.1"in frontmatter,sequant statusshows updatessequant init --upgrade-skillswith diff previewAC Coverage: 12/12 MET
Quality Metrics
Iterations
Verdict: READY_FOR_MERGE
fix(#515): retain decision framework tables per AC-3
fix(#515): add concrete AC example per AC-3 target
fix(#515): move version field under metadata to pass skills-ref valid…
fix(#515): add testgen auto-detection section back to spec skill
feat(#515): compress spec skill prompt by 68% and add tiered context (#…
admarble commentedon Apr 15, 2026
Documentation Generated
File:
docs/features/spec-prompt-compression.mdSections Included:
sequant status+sequant init --upgrade-skills)Next Steps:
Documentation complete.
docs: add missing feature docs for #484 and #515; ignore nested .sequ…
feat(#533): default /assess spec phase ON, remove bug/docs auto-skip (#…
docs(#533): add central reference page for spec-by-default behavior
fix(#834): §7 gates must be reachable — lint /qa's own enforcement ch…
fix(#899): create the worktree in /fullsolve, verify it in /exec (#902)