---
name: ignite:memory-search
description: Search your project memory with natural language queries
allowed-tools:
  - Bash
---

<objective>
Search through your project's accumulated memory - past decisions, observations, patterns, and work. Find relevant context from any previous session.

This command queries the persistent memory system to find:
- Similar past work
- Previous decisions and their outcomes
- Observed patterns and anti-patterns
- Past bugs and their solutions
- Architecture choices and rationale

**Usage Examples:**
- `ignite:memory-search "authentication implementation"`
- `ignite:memory-search "past database decisions"`
- `ignite:memory-search "errors with API integration"`
</objective>

<process>

## Step 1: Parse Query

Extract the user's search query from the command. If no query provided, ask for one.

## Step 2: Execute Memory Search

Use the memory bridge to search across all stored observations, summaries, and decisions:

```javascript
const { getMemoryBridge } = require('../../ignite/memory/lib/memory-bridge.js');
const memory = getMemoryBridge();

// Initialize if needed
await memory.initialize();

// Search with the query
const results = await memory.search(query, {
  limit: 20,
  project: currentProject // if in a project context
});
```

## Step 3: Search Similar Work

Also find similar phases or work patterns:

```javascript
const similar = await memory.findSimilar(query, {
  limit: 10
});
```

## Step 4: Format Results

Present the results in a clear, organized format:

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Ignite ► MEMORY SEARCH
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Query: "[user's query]"

## Relevant Observations ([count])

[For each observation:]
📝 **[Type]: [Title]**
   Project: [project] | Phase: [phase] | [time ago]
   [Summary/content excerpt]
   Files: [files if any]

## Similar Past Work ([count])

[For each similar item:]
🔄 **[Title]**
   Similarity: [score]%
   [Description]
   Outcome: [what happened]

## Past Decisions ([count])

[For each relevant decision:]
⚖️ **[Decision title]**
   Choice: [what was decided]
   Rationale: [why]
   Outcome: [result if known]

## Patterns Detected

✅ **Successful Patterns:**
- [Pattern 1]
- [Pattern 2]

⚠️ **Anti-patterns to Avoid:**
- [Anti-pattern 1]
- [Anti-pattern 2]
```

## Step 5: Provide Context Actions

Based on the search results, suggest relevant next actions:

```
───────────────────────────────────────────────────────

## Suggested Actions

Based on your search, you might want to:

1. **Review similar implementation**:
   `/ignite:show-observation [id]`

2. **Apply learned pattern**:
   `/ignite:apply-pattern [pattern-name]`

3. **Continue from checkpoint**:
   `/ignite:resume-work [checkpoint-id]`

───────────────────────────────────────────────────────
```

</process>

<implementation>

```javascript
// Implementation in JavaScript for the command
async function memorySearch(query) {
  const { getMemoryBridge } = require('../../ignite/memory/lib/memory-bridge.js');
  const memory = getMemoryBridge();

  // Initialize memory system
  await memory.initialize();

  // Perform searches in parallel
  const [searchResults, similarWork] = await Promise.all([
    memory.search(query, { limit: 20 }),
    memory.findSimilar(query, { limit: 10 })
  ]);

  // Extract decisions from search results
  const decisions = searchResults.results.filter(r => r.type === 'decision');
  const observations = searchResults.results.filter(r => r.type !== 'decision');

  // Format and display results
  formatResults({
    query,
    observations,
    similar: similarWork.results,
    decisions
  });

  // Store this search as an observation itself
  await memory.storeObservation({
    type: 'discovery',
    title: `Memory search: ${query}`,
    content: `Found ${searchResults.results.length} relevant items`,
    metadata: {
      resultCount: searchResults.results.length,
      query
    }
  });
}
```

</implementation>

<success_criteria>
- [ ] Memory system initialized
- [ ] Search executed successfully
- [ ] Results formatted and displayed clearly
- [ ] Similar work identified
- [ ] Relevant patterns highlighted
- [ ] Next actions suggested based on results
- [ ] Search itself logged as observation
</success_criteria>