Skip to content

Commit 7cf0a8b

Browse files
committed
feat: Add advanced search capabilities and improve search query guidance in documentation
1 parent a8798ac commit 7cf0a8b

File tree

6 files changed

+417
-3
lines changed

6 files changed

+417
-3
lines changed

AGENTS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Lightweight spec methodology for AI-powered development.
1010
2. **Search**`search` or `lean-spec search` before creating new specs
1111
3. **Never create files manually** → Always use `create` tool or `lean-spec create`
1212

13+
### 🔍 Search Query Best Practices
14+
15+
| ✅ Good Query | ❌ Poor Query |
16+
|---------------|---------------|
17+
| `"search ranking"` | `"AI agent integration coding agent orchestration"` |
18+
| `"token validation"` | `"how to validate tokens in specs"` |
19+
| `"api"` + tags filter `["integration"]` | `"api integration feature"` |
20+
21+
**Why?** All search terms must appear in the SAME field/line to match. Use 2-4 specific terms + filters instead of long queries.
22+
1323
## 🔧 Managing Specs
1424

1525
### MCP Tools (Preferred) with CLI Fallback

packages/cli/src/commands/create.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { normalizeDateFields } from '../frontmatter.js';
1212
import { autoCheckIfEnabled } from './check.js';
1313
import { sanitizeUserInput } from '../utils/ui.js';
1414
import { parseCustomFieldOptions } from '../utils/cli-helpers.js';
15+
import { linkSpec } from './link.js';
1516

1617
/**
1718
* Create command - create new spec
@@ -28,6 +29,8 @@ export function createCommand(): Command {
2829
.option('--template <template>', 'Use a specific template')
2930
.option('--field <name=value...>', 'Set custom field (can specify multiple)')
3031
.option('--no-prefix', 'Skip date prefix even if configured')
32+
.option('--depends-on <specs>', 'Add dependencies (comma-separated spec numbers or names)')
33+
.option('--related <specs>', 'Add related specs (comma-separated spec numbers or names)')
3134
.action(async (name: string, options: {
3235
title?: string;
3336
description?: string;
@@ -37,6 +40,8 @@ export function createCommand(): Command {
3740
template?: string;
3841
field?: string[];
3942
prefix?: boolean;
43+
dependsOn?: string;
44+
related?: string;
4045
}) => {
4146
const customFields = parseCustomFieldOptions(options.field);
4247
const createOptions: {
@@ -48,6 +53,8 @@ export function createCommand(): Command {
4853
template?: string;
4954
customFields?: Record<string, unknown>;
5055
noPrefix?: boolean;
56+
dependsOn?: string[];
57+
related?: string[];
5158
} = {
5259
title: options.title,
5360
description: options.description,
@@ -57,6 +64,8 @@ export function createCommand(): Command {
5764
template: options.template,
5865
customFields: Object.keys(customFields).length > 0 ? customFields : undefined,
5966
noPrefix: options.prefix === false,
67+
dependsOn: options.dependsOn ? options.dependsOn.split(',').map(s => s.trim()) : undefined,
68+
related: options.related ? options.related.split(',').map(s => s.trim()) : undefined,
6069
};
6170
await createSpec(name, createOptions);
6271
});
@@ -71,6 +80,8 @@ export async function createSpec(name: string, options: {
7180
template?: string;
7281
customFields?: Record<string, unknown>;
7382
noPrefix?: boolean;
83+
dependsOn?: string[];
84+
related?: string[];
7485
} = {}): Promise<void> {
7586
const config = await loadConfig();
7687
const cwd = process.cwd();
@@ -286,6 +297,21 @@ export async function createSpec(name: string, options: {
286297
console.log(chalk.gray(` Edit: ${sanitizeUserInput(specFile)}`));
287298
}
288299

300+
// Add dependencies and related specs if specified
301+
const hasRelationships = (options.dependsOn && options.dependsOn.length > 0) ||
302+
(options.related && options.related.length > 0);
303+
if (hasRelationships) {
304+
const newSpecName = path.basename(specDir);
305+
try {
306+
await linkSpec(newSpecName, {
307+
dependsOn: options.dependsOn?.join(','),
308+
related: options.related?.join(','),
309+
});
310+
} catch (error: any) {
311+
console.log(chalk.yellow(`⚠️ Warning: Failed to add relationships: ${error.message}`));
312+
}
313+
}
314+
289315
// Auto-check for conflicts after creation
290316
await autoCheckIfEnabled();
291317
}

packages/cli/src/mcp/tools/create.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function createTool(): ToolDefinition {
2525
priority: z.enum(['low', 'medium', 'high', 'critical']).optional().describe('Priority level for the spec. Defaults to "medium" if not specified.'),
2626
assignee: z.string().optional().describe('Person responsible for this spec.'),
2727
template: z.string().optional().describe('Template name to use (e.g., "minimal", "enterprise"). Uses default template if omitted.'),
28+
dependsOn: z.array(z.string()).optional().describe('Specs this depends on (e.g., ["045-api-design", "046-database"]). Creates upstream dependencies.'),
29+
related: z.array(z.string()).optional().describe('Related specs (e.g., ["047-frontend"]). Creates bidirectional relationships.'),
2830
},
2931
outputSchema: {
3032
success: z.boolean(),
@@ -49,6 +51,8 @@ export function createTool(): ToolDefinition {
4951
priority: input.priority as SpecPriority | undefined,
5052
assignee: input.assignee,
5153
template: input.template,
54+
dependsOn: input.dependsOn,
55+
related: input.related,
5256
});
5357

5458
const output = {

packages/cli/src/mcp/tools/search.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,24 @@ export function searchTool(): ToolDefinition {
124124
'search',
125125
{
126126
title: 'Search Specs',
127-
description: 'Intelligent relevance-ranked search across all specification content. Uses field-weighted scoring (title > tags > description > content) to return the most relevant specs. Returns matching specs with relevance scores, highlighted excerpts, and metadata.',
127+
description: `Intelligent relevance-ranked search across all specification content. Uses field-weighted scoring (title > tags > description > content) to return the most relevant specs.
128+
129+
**Query Formulation Tips:**
130+
- Use 2-4 specific terms for best results (e.g., "search ranking" not "AI agent integration coding agent orchestration")
131+
- All terms must appear in the SAME field/line to match - keep queries focused
132+
- Prefer nouns and technical terms over common words
133+
- Use filters (status, tags, priority) to narrow scope instead of adding more search terms
134+
135+
**Examples:**
136+
- Good: "search ranking" or "token validation"
137+
- Good: "api" with tags filter ["integration"]
138+
- Poor: "AI agent integration coding agent orchestration" (too many terms, unlikely all in one line)
139+
140+
Returns matching specs with relevance scores, highlighted excerpts, and metadata.`,
128141
inputSchema: {
129-
query: z.string().describe('Search term or phrase to find in spec content. Multiple terms are combined with AND logic. Searches across titles, tags, descriptions, and body text with intelligent relevance ranking.'),
142+
query: z.string().describe('Search term or phrase. Use 2-4 specific terms. All terms must appear in the same field/line to match. For broad concepts, use fewer terms + filters instead of long queries.'),
130143
status: z.enum(['planned', 'in-progress', 'complete', 'archived']).optional().describe('Limit search to specs with this status.'),
131-
tags: z.array(z.string()).optional().describe('Limit search to specs with these tags.'),
144+
tags: z.array(z.string()).optional().describe('Limit search to specs with these tags. Use this to narrow scope instead of adding more search terms.'),
132145
priority: z.enum(['low', 'medium', 'high', 'critical']).optional().describe('Limit search to specs with this priority.'),
133146
},
134147
outputSchema: {
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
---
2+
status: planned
3+
created: '2025-11-26'
4+
tags:
5+
- ai-agents
6+
- workflow
7+
- automation
8+
- cli
9+
- integration
10+
- parallel-development
11+
priority: high
12+
created_at: '2025-11-26T06:25:37.182Z'
13+
related:
14+
- 118-parallel-spec-implementation
15+
- 072-ai-agent-first-use-workflow
16+
- 110-project-aware-agents-generation
17+
---
18+
19+
# AI Coding Agent Integration for Automated Spec Orchestration
20+
21+
> **Status**: 📅 Planned · **Priority**: High · **Created**: 2025-11-26
22+
23+
**Project**: lean-spec
24+
**Team**: Core Development
25+
26+
## Overview
27+
28+
Integrate AI coding agents (GitHub Copilot CLI, Claude Code, Gemini CLI, OpenChat, GitHub Coding Agent, etc.) directly into LeanSpec to automate spec implementation orchestration. Currently users manually manage agent sessions, branch creation, and spec status updates. This spec extends the parallel spec implementation work (spec 118) to enable seamless agent-driven development without manual coordination.
29+
30+
**Problem**:
31+
- Users manually orchestrate AI agents to implement specs (copy context, manage branches, update status)
32+
- No unified interface across different agent types (CLI-based vs cloud-based)
33+
- Parallel spec implementation (spec 118) requires manual worktree management
34+
- Agent sessions are disconnected from spec lifecycle (status, dependencies, completion)
35+
36+
**Goals**:
37+
1. Unified interface to dispatch specs to various AI coding agents
38+
2. Automatic environment setup (branches, worktrees) based on spec requirements
39+
3. Bi-directional sync between agent progress and spec status
40+
4. Support both CLI agents (local) and cloud agents (GitHub Coding Agent)
41+
5. Enable parallel spec implementation with minimal manual coordination
42+
43+
## Design
44+
45+
### Supported Agent Types
46+
47+
**CLI-Based Agents (Local)**:
48+
- GitHub Copilot CLI (`gh copilot`)
49+
- Claude Code (Anthropic)
50+
- Gemini CLI (Google)
51+
- Aider
52+
- Continue.dev
53+
54+
**Cloud-Based Agents**:
55+
- GitHub Coding Agent (creates PRs automatically)
56+
- Future: Other cloud coding services
57+
58+
### Architecture
59+
60+
```
61+
┌─────────────────────────────────────────────────────────────┐
62+
│ LeanSpec CLI / MCP │
63+
├─────────────────────────────────────────────────────────────┤
64+
│ Agent Orchestrator │
65+
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
66+
│ │ CLI Adapter │ │Cloud Adapter │ │ Status Sync │ │
67+
│ │ (local exec) │ │ (API/GH) │ │ (webhooks) │ │
68+
│ └──────────────┘ └──────────────┘ └──────────────┘ │
69+
├─────────────────────────────────────────────────────────────┤
70+
│ Environment Manager │
71+
│ • Git worktree creation (parallel specs) │
72+
│ • Branch strategy enforcement │
73+
│ • Context injection (spec content → agent prompt) │
74+
└─────────────────────────────────────────────────────────────┘
75+
```
76+
77+
### Proposed Commands
78+
79+
```bash
80+
# Dispatch a spec to an AI agent
81+
lean-spec agent run <spec> [--agent <type>] [--parallel]
82+
83+
# Examples:
84+
lean-spec agent run 045 --agent claude # Use Claude Code locally
85+
lean-spec agent run 045 --agent gh-coding # Use GitHub Coding Agent (cloud)
86+
lean-spec agent run 045 --agent copilot # Use GitHub Copilot CLI
87+
lean-spec agent run 045 # Use default agent from config
88+
89+
# Run multiple specs in parallel (extends spec 118)
90+
lean-spec agent run 045 047 048 --parallel # Creates worktrees, dispatches agents
91+
92+
# Check agent status
93+
lean-spec agent status [<spec>]
94+
95+
# Configure default agent
96+
lean-spec config set default-agent claude
97+
```
98+
99+
### MCP Tool Extensions
100+
101+
```typescript
102+
// New MCP tools for agent orchestration
103+
mcp_lean-spec_agent_run // Dispatch spec to agent
104+
mcp_lean-spec_agent_status // Check agent progress
105+
mcp_lean-spec_agent_list // List available agents
106+
```
107+
108+
### Workflow Integration
109+
110+
**Single Spec → Agent**:
111+
```bash
112+
lean-spec agent run 045 --agent claude
113+
# 1. Updates spec status to in-progress
114+
# 2. Creates feature branch (feature/045-dashboard)
115+
# 3. Injects spec content as agent context
116+
# 4. Launches agent with appropriate prompt
117+
# 5. Monitors for completion (optional webhook/polling)
118+
# 6. Updates spec status on completion
119+
```
120+
121+
**Parallel Specs → Agents (extends spec 118)**:
122+
```bash
123+
lean-spec agent run 045 047 048 --parallel --agent claude
124+
# 1. Creates .worktrees/ for each spec
125+
# 2. Updates all specs to in-progress
126+
# 3. Dispatches agent to each worktree (separate sessions)
127+
# 4. Monitors all sessions
128+
# 5. Reports completion status
129+
```
130+
131+
**Cloud Agent (GitHub Coding Agent)**:
132+
```bash
133+
lean-spec agent run 045 --agent gh-coding
134+
# 1. Creates GitHub issue from spec (if not exists)
135+
# 2. Triggers GitHub Coding Agent via API
136+
# 3. Agent creates branch + PR automatically
137+
# 4. LeanSpec monitors PR status via webhooks
138+
# 5. Updates spec status when PR merged
139+
```
140+
141+
### Configuration
142+
143+
```yaml
144+
# .leanspec/config.yaml
145+
agents:
146+
default: claude
147+
148+
claude:
149+
type: cli
150+
command: claude
151+
context-template: |
152+
Implement the following spec:
153+
---
154+
{spec_content}
155+
---
156+
Create the implementation in this worktree.
157+
158+
gh-coding:
159+
type: cloud
160+
provider: github
161+
# Uses GitHub App or PAT for API access
162+
163+
copilot:
164+
type: cli
165+
command: gh copilot suggest
166+
```
167+
168+
## Plan
169+
170+
- [ ] Research agent APIs and CLI interfaces (Claude Code, Copilot CLI, Gemini CLI)
171+
- [ ] Design agent adapter interface (abstract common operations)
172+
- [ ] Implement CLI agent adapter (exec-based, stdin/stdout)
173+
- [ ] Implement GitHub Coding Agent adapter (API-based)
174+
- [ ] Create `lean-spec agent run` command
175+
- [ ] Integrate with worktree creation (spec 118)
176+
- [ ] Add spec status auto-update on agent events
177+
- [ ] Implement `lean-spec agent status` for monitoring
178+
- [ ] Add MCP tools for agent orchestration
179+
- [ ] Document agent setup for each supported provider
180+
- [ ] Create example workflows in docs
181+
182+
## Test
183+
184+
**Verification Criteria**:
185+
186+
- [ ] Can dispatch a spec to Claude Code and have it start implementation
187+
- [ ] Can dispatch a spec to GitHub Coding Agent and receive PR
188+
- [ ] Parallel dispatch creates proper worktrees and isolated sessions
189+
- [ ] Spec status updates automatically on agent completion
190+
- [ ] Agent configuration is flexible and extensible
191+
- [ ] MCP tools work for AI-to-AI orchestration
192+
193+
**Integration Tests**:
194+
195+
- [ ] End-to-end: spec → agent → implementation → PR → status update
196+
- [ ] Parallel: 3 specs → 3 agents → 3 worktrees → all complete
197+
- [ ] Failure handling: agent error → spec status reflects failure
198+
199+
## Notes
200+
201+
**Open Questions**:
202+
- How to handle agent authentication (API keys, OAuth)?
203+
- Should we support custom agent prompts per spec/project?
204+
- How to handle long-running agents (timeout, checkpoints)?
205+
- Priority: CLI agents first (simpler) or cloud agents first (more powerful)?
206+
207+
**Research Needed**:
208+
- Claude Code CLI interface and automation options
209+
- GitHub Coding Agent API (triggering, status checking)
210+
- Gemini CLI capabilities
211+
- Aider integration patterns
212+
213+
**Related Work**:
214+
- Spec 118: Git worktrees for parallel development (foundation)
215+
- Spec 072: AI agent first-use workflow (onboarding)
216+
- Spec 110: Project-aware AGENTS.md generation (context)
217+
218+
**Alternatives Considered**:
219+
- IDE-only integration (VS Code tasks) - too narrow
220+
- Shell scripts only - not portable, hard to maintain
221+
- Full orchestration platform - too complex for LeanSpec's lean philosophy

0 commit comments

Comments
 (0)