Skip to content

Commit a8798ac

Browse files
committed
feat: Enhance MCP-first agent experience and improve dependency validation in AGENTS.md
1 parent 1424310 commit a8798ac

File tree

2 files changed

+120
-219
lines changed

2 files changed

+120
-219
lines changed

AGENTS.md

Lines changed: 82 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -4,260 +4,123 @@
44

55
Lightweight spec methodology for AI-powered development.
66

7-
## First Principles (Decision Framework)
7+
## 🚨 CRITICAL: Before ANY Task
88

9-
When making spec decisions, apply these principles in priority order:
9+
1. **Discover**`board` or `lean-spec board` to see project state
10+
2. **Search**`search` or `lean-spec search` before creating new specs
11+
3. **Never create files manually** → Always use `create` tool or `lean-spec create`
1012

11-
### 1. Context Economy - Fit in working memory
12-
**Specs must fit in working memory—both human and AI.**
13+
## 🔧 Managing Specs
1314

14-
- **Target**: <2,000 tokens per spec file
15-
- **Warning**: 2,000-3,500 tokens (acceptable but watch complexity)
16-
- **Problem**: >3,500 tokens (consider splitting)
17-
- **Question**: "Can this be read in 5-10 minutes? Can you hold the entire structure in your head?"
18-
- **Why**: Attention and cognitive capacity are scarce resources. AI performance degrades with longer context (quality drops beyond 50K tokens despite 200K limits). Humans can't hold >7 concepts in working memory. **Use `lean-spec tokens <spec>` to check.**
15+
### MCP Tools (Preferred) with CLI Fallback
1916

20-
### 2. Signal-to-Noise Maximization - Every word informs decisions
21-
**Every word must inform decisions or be cut.**
17+
| Action | MCP Tool | CLI Fallback |
18+
|--------|----------|--------------|
19+
| Project status | `board` | `lean-spec board` |
20+
| List specs | `list` | `lean-spec list` |
21+
| Search specs | `search` | `lean-spec search "query"` |
22+
| View spec | `view` | `lean-spec view <spec>` |
23+
| Create spec | `create` | `lean-spec create <name>` |
24+
| Update spec | `update` | `lean-spec update <spec> --status <status>` |
25+
| Dependencies | `deps` | `lean-spec deps <spec>` |
26+
| Token count | `tokens` | `lean-spec tokens <spec>` |
2227

23-
- **Test**: "What decision does this sentence inform?"
24-
- **Cut**: Obvious, inferable, or "maybe future" content
25-
- **Keep**: Decision rationale, constraints, success criteria
26-
- **Action**: Remove anything that doesn't answer the test question
27-
- **Why**: While Context Economy asks "Can you hold it all?", Signal-to-Noise asks "Is each piece worth holding?" Cognitive load, token costs, and maintenance burden all penalize low-value content.
28+
**Local Development:** Use `node bin/lean-spec.js <command>` instead of `npx lean-spec`. Build first with `pnpm build`.
2829

29-
### 3. Intent Over Implementation - Capture why, not just how
30-
**Capture "why" and "what," let "how" emerge.**
30+
## ⚠️ Core Rules
3131

32-
- **Must have**: Problem, intent, success criteria
33-
- **Should have**: Design rationale, trade-offs
34-
- **Could have**: Implementation details, examples
35-
- **Question**: "Is the rationale clear?"
36-
- **Action**: Explain trade-offs, constraints, success criteria
37-
- **Why**: Intent is stable, implementation changes, AI needs why
32+
| Rule | Details |
33+
|------|---------|
34+
| **NEVER edit frontmatter manually** | Use `update`, `link`, `unlink` for: `status`, `priority`, `tags`, `assignee`, `transitions`, timestamps, `depends_on`, `related` |
35+
| **ALWAYS link spec references** | Content mentions another spec → `lean-spec link <spec> --related <other>` or `--depends-on <other>` |
36+
| **Track status transitions** | `planned``in-progress` (before coding) → `complete` (after done) |
37+
| **No nested code blocks** | Use indentation instead |
3838

39-
### 4. Bridge the Gap - Both human and AI must understand
40-
**Specs exist to align human intent with machine execution.**
39+
### 🚫 Common Mistakes
4140

42-
- **For humans**: Overview, context, rationale
43-
- **For AI**: Unambiguous requirements, clear structure, examples
44-
- **Both must understand**: Use clear structure + natural language
45-
- **Question**: "Can both parse and reason about this?"
46-
- **Action**: Clear structure + natural language explanation
47-
- **Why**: Gap between human goals and machine execution must be bridged
41+
| ❌ Don't | ✅ Do Instead |
42+
|----------|---------------|
43+
| Create spec files manually | Use `create` tool |
44+
| Skip discovery | Run `board` and `search` first |
45+
| Leave status as "planned" | Update to `in-progress` before coding |
46+
| Edit frontmatter manually | Use `update` tool |
4847

49-
### 5. Progressive Disclosure - Add complexity when pain is felt
50-
**Start simple, add structure only when pain is felt.**
48+
## 📋 SDD Workflow
5149

52-
- **Solo dev**: Just status + created
53-
- **Feel pain?**: Add tags, priority, custom fields
54-
- **Never add**: "Just in case" features
55-
- **Question**: "Do we need this now?"
56-
- **Action**: Start minimal, add fields when required
57-
- **Why**: Teams evolve, requirements emerge, premature abstraction is waste
58-
59-
### Conflict Resolution Examples
60-
61-
When practices conflict, apply principles in priority order:
62-
63-
**"Should I split this 4,000-token spec?"**
64-
**Yes** (Context Economy: >3,500 tokens needs splitting)
65-
66-
**"Should I document every edge case?"**
67-
**Only if it informs current decisions** (Signal-to-Noise test)
68-
69-
**"Should I add custom fields upfront?"**
70-
**Only if you feel pain without them** (Progressive Disclosure)
71-
72-
**"This spec is complex but only 2,500 tokens, split it?"**
73-
**No** (Under Context Economy warning threshold)
74-
75-
## Core Rules
76-
77-
1. **Read README.md first** - Understand project context
78-
2. **Check specs/** - Review existing specs before starting
79-
3. **Use `lean-spec --help`** - When unsure about commands, check the built-in help
80-
4. **Follow LeanSpec principles** - Clarity over documentation
81-
5. **Keep it minimal** - If it doesn't add clarity, cut it
82-
6. **NEVER manually edit system-managed frontmatter** - Fields like `status`, `priority`, `tags`, `assignee`, `transitions`, `created_at`, `updated_at`, `completed_at`, `depends_on`, `related` are system-managed. Always use `lean-spec update`, `lean-spec link`, `lean-spec unlink`, or `lean-spec create` commands. Manual edits will cause metadata corruption and tracking issues.
83-
7. **Never use nested code blocks** - Markdown doesn't support code blocks within code blocks. If you need to show code examples in documentation, use indentation or describe the structure instead of nesting backticks.
84-
8. **ALWAYS link spec dependencies** - When a spec mentions or references another spec in its content, you MUST add it to frontmatter using `lean-spec link <spec> --related <other>` or `lean-spec link <spec> --depends-on <other>`. Content and frontmatter must stay aligned.
85-
86-
## When to Use Specs
87-
88-
Write a spec for:
89-
- Features affecting multiple parts of the system
90-
- Breaking changes or significant refactors
91-
- Design decisions needing team alignment
92-
93-
Skip specs for:
94-
- Bug fixes
95-
- Trivial changes
96-
- Self-explanatory refactors
97-
98-
## Essential Commands
99-
100-
**Quick Reference** (for full details, see [docs/agents/COMMANDS.md](docs/agents/COMMANDS.md)):
101-
102-
**Discovery:**
103-
- `lean-spec list` - See all specs
104-
- `lean-spec search "<query>"` - Find relevant specs
105-
106-
**Working with specs:**
107-
- `lean-spec create <name>` - Create new spec
108-
- `lean-spec update <spec> --status <status>` - Update status (REQUIRED - never edit frontmatter manually)
109-
- `lean-spec update <spec> --priority <priority>` - Update priority
110-
- `lean-spec deps <spec>` - Show dependency graph
111-
- `lean-spec tokens <spec>` - Count tokens for context management
112-
113-
**Project overview:**
114-
- `lean-spec board` - Kanban view with project health
115-
- `lean-spec stats` - Quick project metrics
50+
```
51+
BEFORE: board → search → check existing specs
52+
DURING: update status to in-progress → code → document decisions → link related specs
53+
AFTER: update status to complete → document learnings
54+
```
11655

117-
**When in doubt:** Run `lean-spec --help` or `lean-spec <command> --help` to discover commands.
56+
**Status tracks implementation, NOT spec writing.**
11857

11958
## Spec Relationships
12059

121-
LeanSpec has two types of relationships (for detailed examples, see [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md)):
122-
123-
### `related` - Bidirectional Soft Reference
124-
Informational relationship between specs. Automatically shown from both sides.
125-
126-
**Use when:** Specs cover related topics, work is coordinated but not blocking.
60+
| Type | Direction | Use When |
61+
|------|-----------|----------|
62+
| `related` | Bidirectional | Related topics, coordinated work |
63+
| `depends_on` | Directional | True blocker, work order matters |
12764

128-
### `depends_on` - Directional Blocking Dependency
129-
Hard dependency - spec cannot start until dependencies complete.
65+
**Default to `related`**. Reserve `depends_on` for true blockers.
13066

131-
**Use when:** Spec truly cannot start until another completes, work order matters.
132-
133-
**Best Practice:** Use `related` by default. Reserve `depends_on` for true blocking dependencies.
134-
135-
### ⚠️ CRITICAL: Link Dependencies When Creating/Editing Specs
136-
137-
**After creating or editing any spec, you MUST:**
138-
139-
1. **Scan the content** for references to other specs (e.g., "spec 045", "related to 072", "depends on", "see also", "builds on", "requires")
140-
2. **Link each reference** using the CLI:
141-
```bash
142-
# For informational references
143-
lean-spec link <spec> --related <other-spec>
144-
145-
# For blocking dependencies
146-
lean-spec link <spec> --depends-on <other-spec>
147-
```
148-
3. **Verify with:** `lean-spec deps <spec>`
149-
150-
**Examples of content that MUST be linked:**
151-
- "This builds on spec 045" → `lean-spec link <this-spec> --depends-on 045`
152-
- "Related to spec 072" → `lean-spec link <this-spec> --related 072`
153-
- "See spec 110 for details" → `lean-spec link <this-spec> --related 110`
154-
- "Blocked by spec 086" → `lean-spec link <this-spec> --depends-on 086`
155-
- "## Related Specs" section listing specs → Link each one
156-
157-
## SDD Workflow
158-
159-
**Full workflow details:** See [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md)
67+
## When to Use Specs
16068

161-
1. **Discover** - Check existing specs with `lean-spec list`
162-
2. **Plan** - Create spec with `lean-spec create <name>` (status: `planned`)
163-
3. **Start Work** - Run `lean-spec update <spec> --status in-progress` before implementing
164-
4. **Implement** - Write code/docs, keep spec in sync as you learn
165-
5. **Complete** - Run `lean-spec update <spec> --status complete` after implementation done
166-
6. **Document** - Report progress and document changes into the spec
69+
| ✅ Write spec | ❌ Skip spec |
70+
|---------------|--------------|
71+
| Multi-part features | Bug fixes |
72+
| Breaking changes | Trivial changes |
73+
| Design decisions | Self-explanatory refactors |
16774

168-
**CRITICAL - What "Work" Means:**
169-
-**NOT**: Creating/writing the spec document itself
170-
-**YES**: Implementing what the spec describes (code, docs, features, etc.)
75+
## Token Thresholds
17176

172-
**Frontmatter Editing Rules:**
173-
- **NEVER manually edit**: `status`, `priority`, `tags`, `assignee`, `transitions`, timestamps, `depends_on`, `related`
174-
- **Use CLI commands**: `lean-spec update`, `lean-spec link`, `lean-spec unlink`
77+
| Tokens | Status |
78+
|--------|--------|
79+
| <2,000 | ✅ Optimal |
80+
| 2,000-3,500 | ✅ Good |
81+
| 3,500-5,000 | ⚠️ Consider splitting |
82+
| >5,000 | 🔴 Must split |
17583

176-
**Note on Archiving**: Archive specs when they're no longer actively referenced (weeks/months after completion), not immediately. Use `lean-spec archive <spec>` to move old/stale specs to `archived/` directory.
84+
## First Principles (Priority Order)
17785

178-
## Quality Standards
86+
1. **Context Economy** - <2,000 tokens optimal, >3,500 needs splitting
87+
2. **Signal-to-Noise** - Every word must inform a decision
88+
3. **Intent Over Implementation** - Capture why, let how emerge
89+
4. **Bridge the Gap** - Both human and AI must understand
90+
5. **Progressive Disclosure** - Add complexity only when pain is felt
17991

180-
- Code is clear and maintainable
181-
- Tests cover critical paths
182-
- Specs stay in sync with implementation
183-
- **Status tracking is mandatory:**
184-
- Specs start as `planned` after creation
185-
- Mark `in-progress` BEFORE starting implementation work
186-
- Mark `complete` AFTER implementation is finished
187-
- **Remember**: Status tracks implementation, not spec document completion
188-
- Never leave specs with stale status
189-
- **Always validate before completing work:**
190-
- Run `node bin/lean-spec.js validate` to check spec structure and frontmatter (use local build, not `npx`)
191-
- Run `node bin/lean-spec.js validate --check-deps` to verify content/frontmatter dependency alignment
192-
- Run `cd docs-site && npm run build` to ensure documentation site builds successfully
193-
- Update spec status to `complete` with `lean-spec update <spec> --status complete`
194-
- Fix any validation errors or build failures before marking work complete
92+
## Quality Validation
19593

196-
**Note on Local Development:**
197-
When working on the LeanSpec codebase itself, always use the local build (`node bin/lean-spec.js <command>`) instead of `npx lean-spec`, which runs the published npm package. Build changes with `pnpm build` before testing.
94+
Before completing work:
95+
```bash
96+
node bin/lean-spec.js validate # Check structure
97+
node bin/lean-spec.js validate --check-deps # Verify dependencies
98+
cd docs-site && npm run build # Test docs build
99+
```
198100

199101
## Publishing Releases
200102

201-
⚠️ **CRITICAL**: When publishing a release, you MUST create a GitHub release. This is not optional.
202-
203-
See [docs/agents/PUBLISHING.md](docs/agents/PUBLISHING.md) for the complete release process.
103+
See [docs/agents/PUBLISHING.md](docs/agents/PUBLISHING.md).
204104

205-
**Quick reminder of mandatory steps:**
105+
**Mandatory steps:**
206106
1. Update versions & CHANGELOG
207-
2. Run pre-release checks (`pnpm pre-release`)
208-
3. Commit, tag, and push
209-
4. Prepare packages (`pnpm prepare-publish`)
107+
2. `pnpm pre-release`
108+
3. Commit, tag, push
109+
4. `pnpm prepare-publish`
210110
5. Publish to npm (all packages)
211-
6. Restore packages (`pnpm restore-packages`)
212-
7. **CREATE GITHUB RELEASE** (`gh release create vX.Y.Z --title "..." --notes-file ...`) ← DO NOT SKIP THIS
213-
8. Verify everything is published correctly
111+
6. `pnpm restore-packages`
112+
7. **CREATE GITHUB RELEASE** ← DO NOT SKIP
113+
8. Verify
214114

215-
## Spec Complexity Guidelines
216-
217-
**Token Thresholds:**
218-
- **<2,000 tokens**: ✅ Optimal
219-
- **2,000-3,500 tokens**: ✅ Good
220-
- **3,500-5,000 tokens**: ⚠️ Warning - Consider splitting
221-
- **>5,000 tokens**: 🔴 Should split
222-
223-
**Check with:** `lean-spec tokens <spec>`
224-
225-
**When to split:** >3,500 tokens, multiple concerns, takes >10 min to read
226-
227-
**How to split:** Use `lean-spec analyze <spec>`, `lean-spec split`, and `lean-spec compact` commands. See [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md) for detailed examples.
228-
229-
## Parallel Development
230-
231-
Need to work on multiple specs at once? Use Git worktrees for complete code isolation:
115+
## Advanced: Parallel Development
232116

117+
Use Git worktrees for multiple specs:
233118
```bash
234-
# Create worktree for spec 045
235-
lean-spec update 045 --status in-progress
236-
git worktree add .worktrees/spec-045-dashboard -b feature/045-dashboard
237-
cd .worktrees/spec-045-dashboard
238-
# Implement spec 045...
239-
240-
# Meanwhile, start spec 047 in a separate worktree
241-
cd ~/project # Back to main
242-
lean-spec update 047 --status in-progress
243-
git worktree add .worktrees/spec-047-timestamps -b feature/047-timestamps
119+
git worktree add .worktrees/spec-045-feature -b feature/045-feature
244120
```
245121

246-
**Best Practices:**
247-
- **Naming**: Use `spec-<number>-<short-name>` for worktrees
248-
- **Branches**: Feature branch per spec (`feature/045-dashboard`)
249-
- **Cleanup**: `git worktree remove <path>` after merge
250-
- **Status**: Update spec status from main worktree
251-
- **Ignore**: Add `.worktrees/` to `.gitignore`
252-
253-
**Full guide:** See [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md) for complete patterns.
254-
255-
## FAQ
256-
257-
**Q: How do I work on multiple specs at once?**
258-
259-
Use Git worktrees. Each worktree gives you an isolated working directory with its own branch while sharing the same Git history. See [Parallel Development](#parallel-development) above and [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md) for detailed patterns.
122+
See [docs/agents/WORKFLOWS.md](docs/agents/WORKFLOWS.md) for patterns.
260123

261124
---
262125

263-
**Remember**: LeanSpec is a mindset, not a rulebook. When in doubt, apply the first principles in order: Context Economy → Signal-to-Noise → Intent Over Implementation → Bridge the Gap → Progressive Disclosure. Use `lean-spec --help` to discover features as needed.
126+
**Remember**: Context Economy → Signal-to-Noise → Intent → Bridge Gap → Progressive Disclosure

CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
- **MCP-first agent experience** (spec 121) - Enhanced AI agent workflow with better SDD compliance
12+
- Multi-tool symlink support: `lean-spec init` now creates tool-specific symlinks (CLAUDE.md, GEMINI.md → AGENTS.md)
13+
- New `--agent-tools` flag for non-interactive mode (`--agent-tools all`, `--agent-tools claude,gemini`, `--agent-tools none`)
14+
- MCP-first AGENTS.md rewrite emphasizing MCP tools as primary method over CLI
15+
- New MCP prompt: `checkpoint` - Periodic SDD compliance reminder for long sessions
16+
- New MCP prompt: `create-spec` - Guided spec creation workflow with dependency linking
17+
- Stale spec warnings in board output
18+
- SDD Workflow Checkpoints section in AGENTS.md
19+
- **Dependency alignment validation** (spec 122) - Automated detection of content/frontmatter misalignment
20+
- New `--check-deps` flag for `lean-spec validate` command
21+
- `DependencyAlignmentValidator` scans spec content for references to other specs
22+
- Detects patterns like "spec 045", "depends on", "related to", "builds on", etc.
23+
- Outputs actionable fix commands (e.g., `lean-spec link <spec> --related 045`)
24+
- MCP `validate` tool now supports `checkDeps` option
25+
- Added Core Rule #8 in AGENTS.md: "ALWAYS link spec dependencies"
26+
- **Native diagram rendering in Web UI** (spec 119) - Mermaid diagram support in spec detail view
27+
- Client-side Mermaid rendering for flowcharts, sequence diagrams, class diagrams, etc.
28+
- Dark mode theme support with automatic theme switching
29+
- Error handling with fallback to code block display
30+
- Lazy loading for optimal bundle size (only loads when diagrams present)
31+
- **Parallel spec implementation workflow** (spec 118) - Documentation for concurrent spec development
32+
- Git worktrees pattern for working on multiple specs simultaneously
33+
- Patterns for solo developers, teams, and experimental work
34+
- Best practices for worktree naming, branch strategy, and cleanup
35+
- Added to AGENTS.md FAQ section
36+
37+
### Changed
38+
- **AGENTS.md restructured for MCP-first approach**
39+
- MCP tools listed before CLI commands
40+
- Added "How to Manage Specs" section with MCP vs CLI comparison table
41+
- Added "SDD Workflow Checkpoints" with before/during/after task reminders
42+
- Added "Common Mistakes to Avoid" section with clear ❌/✅ examples
43+
- **Quality Standards updated** - Added `--check-deps` validation to required checks before completing work
44+
45+
### Fixed
46+
- All existing specs now have aligned dependencies (19+ specs fixed after running `validate --check-deps`)
47+
1048
## [0.2.6] - 2025-11-25
1149

1250
### Added

0 commit comments

Comments
 (0)