Skip to content

Commit c244a47

Browse files
author
Marvin Zhang
committed
feat(mcp-tools): add link and unlink commands to MCP tools and update AGENTS.md
1 parent 35bb615 commit c244a47

File tree

6 files changed

+236
-4
lines changed

6 files changed

+236
-4
lines changed

AGENTS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ Lightweight spec methodology for AI-powered development.
3232
| View spec | `view` | `lean-spec view <spec>` |
3333
| Create spec | `create` | `lean-spec create <name>` |
3434
| Update spec | `update` | `lean-spec update <spec> --status <status>` |
35+
| Link specs | `create --related` | `lean-spec link <spec> --related <other>` |
36+
| Unlink specs | ❌ CLI only | `lean-spec unlink <spec> --related <other>` |
3537
| Dependencies | `deps` | `lean-spec deps <spec>` |
3638
| Token count | `tokens` | `lean-spec tokens <spec>` |
3739

40+
**⚠️ Link/Unlink**: Use `--related` or `--depends-on` params in `create` tool. For existing specs, use CLI fallback. (See spec 129 for MCP tool tracking)
41+
3842
**Local Development:** Use `node bin/lean-spec.js <command>` instead of `npx lean-spec`. Build first with `pnpm build`.
3943

4044
## ⚠️ Core Rules

specs/047-git-backfill-timestamps/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ related:
1212
- 046-stats-dashboard-refactor
1313
- 014-complete-custom-frontmatter
1414
- 118-parallel-spec-implementation
15+
- 128-constant-time-migration
1516
created_at: '2025-11-04T22:58:23+08:00'
16-
updated_at: '2025-11-26T06:04:17.915Z'
17+
updated_at: '2025-11-28T01:24:56.696Z'
1718
assignee: Marvin Zhang
18-
updated: '2025-11-26'
19+
updated: '2025-11-28'
1920
completed_at: '2025-11-04T15:08:31.110Z'
2021
completed: '2025-11-04'
2122
transitions:

specs/085-cli-relationship-commands/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ priority: medium
1010
created_at: '2025-11-16T13:33:40.858Z'
1111
depends_on:
1212
- 035-live-specs-showcase
13-
updated_at: '2025-11-26T06:03:58.540Z'
13+
updated_at: '2025-11-28T01:27:53.930Z'
1414
related:
1515
- 076-programmatic-spec-relationships
1616
- 081-web-app-ux-redesign
@@ -19,6 +19,7 @@ related:
1919
- 080-mcp-server-modular-architecture
2020
- 059-programmatic-spec-management
2121
- 086-template-component-deduplication
22+
- 129-mcp-link-tool
2223
completed_at: '2025-11-16T14:08:51.283Z'
2324
completed: '2025-11-16'
2425
transitions:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
status: planned
3+
created: '2025-11-28'
4+
tags:
5+
- cli
6+
- migration
7+
- dx
8+
- performance
9+
priority: high
10+
created_at: '2025-11-28T01:21:44.679Z'
11+
updated_at: '2025-11-28T01:24:56.701Z'
12+
related:
13+
- 047-git-backfill-timestamps
14+
---
15+
16+
# Constant-Time Migration (O(1) UX)
17+
18+
> **Status**: 🗓️ Planned · **Priority**: High · **Created**: 2025-11-28 · **Tags**: cli, migration, dx, performance
19+
20+
**Project**: lean-spec
21+
**Team**: Core Development
22+
23+
## Overview
24+
25+
Migration time should NOT scale with the number of existing specs. Whether you have 10 or 1000 specs, the migration experience should feel instant.
26+
27+
**Problem**: Current migration process is O(n) where n = number of specs. The time estimates table shows linear scaling (100 specs = 3x time of 20 specs). This is unacceptable for larger projects.
28+
29+
**Goal**: Achieve O(1) *perceived* migration time regardless of spec count.
30+
31+
## Problem Analysis
32+
33+
### Current Pain Points
34+
35+
1. **Manual folder restructuring** - Each spec requires individual attention
36+
2. **Sequential renaming** - `spec.md → README.md` one by one
37+
3. **Backfill is already fast** - This scales well via git operations
38+
4. **Validation per-spec** - Must check each spec individually
39+
40+
### Why O(n) Is Bad for AI Era
41+
42+
- AI agents work in parallel, shouldn't wait for migrations
43+
- Large projects shouldn't be punished
44+
- Migration should be "invisible" - just works
45+
46+
## Design
47+
48+
### Strategy: Batch Everything, Parallelize, Cache
49+
50+
**Phase 1: One-Shot Folder Transform**
51+
```bash
52+
lean-spec migrate ./source --auto
53+
```
54+
55+
This single command should:
56+
1. Auto-detect source format (spec-kit, OpenSpec, generic markdown)
57+
2. Bulk rename/restructure in one pass (using filesystem batch ops)
58+
3. Run backfill in parallel across all specs
59+
4. Validate all at once (not per-spec)
60+
61+
**Phase 2: AI-Assisted Instant Migration**
62+
63+
For any source format, generate a single AI prompt that handles ALL specs at once:
64+
```bash
65+
lean-spec migrate ./source --ai
66+
```
67+
68+
Outputs a comprehensive migration script that the AI executes in one shot.
69+
70+
**Phase 3: Zero-Touch Migration**
71+
72+
Ideal future state:
73+
```bash
74+
lean-spec init # Detects existing specs anywhere, migrates automatically
75+
```
76+
77+
### Key Insight
78+
79+
**Don't process specs one-by-one. Process the entire specs directory as a single unit.**
80+
81+
- Batch `mv` operations via shell
82+
- Parallel `git log` queries (already supported)
83+
- Single-pass validation with aggregated results
84+
85+
## Plan
86+
87+
- [ ] Audit current migration bottlenecks (profile with 100+ specs)
88+
- [ ] Implement batch folder restructure (`migrate --auto`)
89+
- [ ] Add auto-detection for source formats
90+
- [ ] Parallelize backfill across specs
91+
- [ ] Update `validate` to batch mode
92+
- [ ] Update docs to show single-command migration
93+
- [ ] Remove per-spec time estimates (irrelevant if instant)
94+
95+
## Test
96+
97+
- [ ] Migration of 100 specs completes in < 30 seconds
98+
- [ ] Migration of 500 specs completes in < 60 seconds
99+
- [ ] Time increase from 100 → 500 specs is < 2x (not 5x)
100+
- [ ] Single command handles entire migration
101+
102+
## Success Metrics
103+
104+
| Spec Count | Current Time | Target Time |
105+
|------------|--------------|-------------|
106+
| 20 | 5-30 min | < 30 sec |
107+
| 100 | 15-60 min | < 30 sec |
108+
| 500 | hours | < 60 sec |
109+
110+
## Notes
111+
112+
Related: [063-migration-from-existing-tools](../063-migration-from-existing-tools) - original migration design
113+
Related: [047-git-backfill-timestamps](../047-git-backfill-timestamps) - backfill command (already performant)

specs/129-mcp-link-tool/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
---
2+
status: planned
3+
created: '2025-11-28'
4+
tags:
5+
- mcp
6+
- tooling
7+
- dx
8+
- ai-agents
9+
priority: high
10+
created_at: '2025-11-28T01:27:53.890Z'
11+
related:
12+
- 085-cli-relationship-commands
13+
updated_at: '2025-11-28T01:27:53.931Z'
14+
---
15+
16+
# Add `link` and `unlink` MCP Tools
17+
18+
> **Status**: 🗓️ Planned · **Priority**: High · **Created**: 2025-11-28 · **Tags**: mcp, tooling, dx, ai-agents
19+
20+
**Project**: lean-spec
21+
**Team**: Core Development
22+
23+
## Overview
24+
25+
The `link` and `unlink` commands exist in CLI but are not exposed as MCP tools. This creates a gap where AGENTS.md tells AI agents to use tools that don't exist in MCP context.
26+
27+
### Problem
28+
29+
1. **AGENTS.md says**: "ALWAYS link spec references → use `link` tool"
30+
2. **MCP Tools table** lists `link` as available
31+
3. **Reality**: No `link.ts` in `packages/cli/src/mcp/tools/`
32+
33+
This causes AI agents to:
34+
- Try to use a non-existent MCP tool
35+
- Fall back to CLI (extra step, breaks flow)
36+
- Sometimes forget to link at all (spec 128 incident)
37+
38+
### Workarounds (Current)
39+
40+
1. Use `--related` / `--depends-on` at `create` time (works but easy to forget)
41+
2. Fall back to CLI: `lean-spec link <spec> --related <other>`
42+
43+
## Design
44+
45+
### Tooling Fix: Add MCP Tools
46+
47+
Create two new MCP tools following existing patterns:
48+
49+
**`packages/cli/src/mcp/tools/link.ts`**
50+
```typescript
51+
// Expose linkSpec() from commands/link.js
52+
inputSchema: {
53+
specPath: z.string().describe('Spec to add relationships to'),
54+
dependsOn: z.string().optional().describe('Comma-separated specs this depends on'),
55+
related: z.string().optional().describe('Comma-separated related specs'),
56+
}
57+
```
58+
59+
**`packages/cli/src/mcp/tools/unlink.ts`**
60+
```typescript
61+
// Expose unlinkSpec() from commands/unlink.js
62+
inputSchema: {
63+
specPath: z.string().describe('Spec to remove relationships from'),
64+
dependsOn: z.string().optional().describe('Comma-separated dependencies to remove'),
65+
related: z.string().optional().describe('Comma-separated related specs to remove'),
66+
}
67+
```
68+
69+
### Process Fix: Update AGENTS.md
70+
71+
Until tools are added, clarify the workaround:
72+
73+
```markdown
74+
| Action | MCP Tool | CLI Fallback |
75+
|--------|----------|--------------|
76+
| Link specs | `create --related` | `lean-spec link <spec> --related <other>` |
77+
| Unlink specs | ❌ CLI only | `lean-spec unlink <spec> --related <other>` |
78+
```
79+
80+
### Best Practice: Include relationships at creation
81+
82+
When creating a spec that references others, always include `related` or `dependsOn`:
83+
84+
```
85+
mcp_lean-spec_create(
86+
name: "my-feature",
87+
related: ["063", "047"] // ← Don't forget!
88+
)
89+
```
90+
91+
## Plan
92+
93+
- [ ] Create `packages/cli/src/mcp/tools/link.ts`
94+
- [ ] Create `packages/cli/src/mcp/tools/unlink.ts`
95+
- [ ] Register tools in `packages/cli/src/mcp/tools/registry.ts`
96+
- [ ] Add tests for new MCP tools
97+
- [ ] Update AGENTS.md MCP Tools table (remove "CLI only" note after impl)
98+
- [ ] Rebuild and test with MCP client
99+
100+
## Test
101+
102+
- [ ] `mcp_lean-spec_link` successfully adds relationships
103+
- [ ] `mcp_lean-spec_unlink` successfully removes relationships
104+
- [ ] Bidirectional links work correctly via MCP
105+
- [ ] Error handling for invalid spec paths
106+
107+
## Notes
108+
109+
Related: [085-cli-relationship-commands](../085-cli-relationship-commands) - original `link`/`unlink` CLI implementation
110+
111+
### Interim AGENTS.md Update
112+
113+
Until this is implemented, update AGENTS.md to note `link` requires CLI fallback.

0 commit comments

Comments
 (0)