Implements MCP server for semantic search across GSD projects: MCP Tools: - gsd_memory_search: Search across all registered projects - gsd_memory_decisions: Find decisions from SUMMARY/PROJECT.md - gsd_memory_patterns: Find patterns from SUMMARY.md - gsd_memory_pitfalls: Find pitfalls from RESEARCH.md - gsd_memory_stack: Find tech stack entries - gsd_memory_register: Register project with memory - gsd_memory_index: Trigger indexing/update - gsd_memory_status: Show system status Architecture: - QMD wrapper with grep fallback when QMD unavailable - YAML frontmatter extractors for GSD document types - Project registry at ~/.gsd/projects.json - Auto-install via bin/install.js for Claude Code Workflow integrations: - new-project: Registers project with memory - plan-phase: Indexes after planning - execute-phase: Indexes after execution - complete-milestone: Indexes milestone completion - Researcher agents query memory before Context7 Tests: 117 passing (66 unit + 51 integration) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import { getAllProjects } from '../registry.js';
|
|
import { extractResearch, type Pitfall } from '../extractors/research.js';
|
|
import { readFileSync, existsSync, readdirSync, statSync } from 'fs';
|
|
import { join } from 'path';
|
|
|
|
export interface PitfallResult extends Pitfall {
|
|
project: string;
|
|
phase?: string;
|
|
domain: string;
|
|
source: string;
|
|
}
|
|
|
|
export interface PitfallOptions {
|
|
query?: string;
|
|
project?: string;
|
|
domain?: string;
|
|
limit?: number;
|
|
}
|
|
|
|
/**
|
|
* Search for pitfalls documented across all registered GSD projects
|
|
*/
|
|
export async function findPitfalls(options: PitfallOptions): Promise<PitfallResult[]> {
|
|
const projects = options.project
|
|
? getAllProjects().filter(p => p.name === options.project)
|
|
: getAllProjects();
|
|
|
|
const allPitfalls: PitfallResult[] = [];
|
|
|
|
for (const project of projects) {
|
|
const planningPath = join(project.path, '.planning');
|
|
if (!existsSync(planningPath)) continue;
|
|
|
|
// Find all RESEARCH.md files
|
|
const researchFiles = findResearchFiles(planningPath);
|
|
|
|
for (const file of researchFiles) {
|
|
try {
|
|
const content = readFileSync(file, 'utf-8');
|
|
const researchData = extractResearch(content);
|
|
|
|
// Extract phase from path if present
|
|
const phaseMatch = file.match(/phases\/(\d+-[^/]+)/);
|
|
const phase = phaseMatch ? phaseMatch[1] : undefined;
|
|
|
|
for (const pitfall of researchData.pitfalls) {
|
|
allPitfalls.push({
|
|
...pitfall,
|
|
project: project.name,
|
|
phase,
|
|
domain: researchData.domain,
|
|
source: file
|
|
});
|
|
}
|
|
} catch {
|
|
// Skip files that can't be parsed
|
|
}
|
|
}
|
|
}
|
|
|
|
// Filter by query if provided
|
|
let filtered = allPitfalls;
|
|
if (options.query) {
|
|
const query = options.query.toLowerCase();
|
|
filtered = allPitfalls.filter(p =>
|
|
p.name.toLowerCase().includes(query) ||
|
|
p.description.toLowerCase().includes(query) ||
|
|
p.prevention.toLowerCase().includes(query)
|
|
);
|
|
}
|
|
|
|
// Filter by domain if provided
|
|
if (options.domain) {
|
|
const domain = options.domain.toLowerCase();
|
|
filtered = filtered.filter(p =>
|
|
p.domain.toLowerCase().includes(domain)
|
|
);
|
|
}
|
|
|
|
// Apply limit
|
|
const limit = options.limit || 50;
|
|
return filtered.slice(0, limit);
|
|
}
|
|
|
|
/**
|
|
* Recursively find all RESEARCH.md files
|
|
*/
|
|
function findResearchFiles(dir: string, files: string[] = []): string[] {
|
|
try {
|
|
const entries = readdirSync(dir);
|
|
|
|
for (const entry of entries) {
|
|
const fullPath = join(dir, entry);
|
|
try {
|
|
const stat = statSync(fullPath);
|
|
|
|
if (stat.isDirectory() && !entry.startsWith('.')) {
|
|
findResearchFiles(fullPath, files);
|
|
} else if (entry.toUpperCase().includes('RESEARCH') && entry.endsWith('.md')) {
|
|
files.push(fullPath);
|
|
}
|
|
} catch {
|
|
// Skip entries that can't be accessed
|
|
}
|
|
}
|
|
} catch {
|
|
// Return empty if directory can't be read
|
|
}
|
|
|
|
return files;
|
|
}
|