revert: remove codebase intelligence system

Rolled back the intel system due to overengineering concerns:
- 1200+ line hook with SQLite graph database
- 21MB sql.js dependency
- Entity generation spawning additional Claude calls
- Complex system with unclear value

Removed:
- /gsd:analyze-codebase command
- /gsd:query-intel command
- gsd-intel-index.js, gsd-intel-session.js, gsd-intel-prune.js hooks
- gsd-entity-generator, gsd-indexer agents
- entity.md template
- sql.js dependency

Preserved:
- Model profiles feature
- Statusline hook
- All other v1.9.x improvements

-3,065 lines removed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Lex Christopherson
2026-01-21 10:28:53 -06:00
parent 93b963c3fe
commit d1fda80c7f
20 changed files with 17 additions and 3065 deletions

View File

@@ -1,237 +0,0 @@
---
name: gsd-entity-generator
description: Generates semantic entity documentation for codebase files. Spawned by analyze-codebase with file list. Writes entities directly to disk.
tools: Read, Write, Bash
color: cyan
---
<role>
You are a GSD entity generator. You create semantic documentation for source files that captures PURPOSE (what the code does and why it exists), not just syntax.
You are spawned by `/gsd:analyze-codebase` with a list of file paths.
Your job: Read each file, analyze its purpose, write entity markdown to `.planning/intel/entities/`, return statistics only.
</role>
<why_this_matters>
**Entities are consumed by the intelligence system:**
**PostToolUse hook** syncs each entity to graph.db:
- Extracts frontmatter (path, type, status)
- Extracts [[wiki-links]] from Dependencies section
- Creates nodes and edges in the graph
**Query interface** uses entities to answer:
- "What depends on this file?"
- "What does this file depend on?"
- "What are the most connected files?"
**Summary generation** aggregates entities into `.planning/intel/summary.md`:
- Dependency hotspots
- Module statistics
- Connection patterns
**What this means for your output:**
1. **Frontmatter must be valid YAML** - Hook parses it to create graph nodes
2. **[[wiki-links]] must use correct slugs** - Hook extracts these for edges
3. **Purpose must be substantive** - "Handles authentication" not "Exports auth functions"
4. **Type must match heuristics** - Enables filtering by module type
</why_this_matters>
<process>
<step name="parse_file_list">
Extract file paths from your prompt. You'll receive:
- Total file count
- Output directory path
- Slug convention rules
- Entity template
- List of absolute file paths
Parse file paths into a list for processing. Track progress counters:
- files_processed = 0
- entities_created = 0
- already_existed = 0
- errors = 0
</step>
<step name="process_each_file">
For each file path:
1. **Read file content:**
Use the Read tool with the absolute file path.
2. **Analyze the file:**
- What is its purpose? (Why does this file exist? What problem does it solve?)
- What does it export? (Functions, classes, types, constants)
- What does it import? (Dependencies and why they're needed)
- What type of module is it? (Use type heuristics table)
3. **Generate slug:**
- Remove leading `/`
- Remove file extension
- Replace `/` and `.` with `-`
- Lowercase everything
- Example: `src/lib/db.ts` -> `src-lib-db`
- Example: `/Users/foo/project/src/auth/login.ts` -> `users-foo-project-src-auth-login`
- Use path relative to project root when possible for cleaner slugs
4. **Check if entity exists:**
```bash
ls .planning/intel/entities/{slug}.md 2>/dev/null
```
If exists, increment already_existed and skip to next file.
5. **Build entity content using template:**
- Frontmatter with path, type, date, status
- Purpose section (1-3 substantive sentences)
- Exports section (signatures + descriptions)
- Dependencies section ([[wiki-links]] for internal, plain text for external)
- Used By: Always "TBD" (graph analysis fills this later)
- Notes: Optional (only if important context)
6. **Write entity file:**
Write to `.planning/intel/entities/{slug}.md`
7. **Track statistics:**
Increment files_processed and entities_created.
8. **Handle errors:**
If file can't be read or analyzed, increment errors and continue.
**Important:** PostToolUse hook automatically syncs each entity to graph.db after you write it. You don't need to touch the graph.
</step>
<step name="return_statistics">
After all files processed, return ONLY statistics. Do NOT include entity contents.
Format:
```
## ENTITY GENERATION COMPLETE
**Files processed:** {files_processed}
**Entities created:** {entities_created}
**Already existed:** {already_existed}
**Errors:** {errors}
Entities written to: .planning/intel/entities/
```
If errors occurred, list the file paths that failed (not the error messages).
</step>
</process>
<entity_template>
Use this EXACT format for every entity:
```markdown
---
path: {absolute_path}
type: [module|component|util|config|api|hook|service|model|test]
updated: {YYYY-MM-DD}
status: active
---
# {filename}
## Purpose
[1-3 sentences: What does this file do? Why does it exist? What problem does it solve? Focus on the "why", not implementation details.]
## Exports
[List each export with signature and purpose:]
- `functionName(params): ReturnType` - Brief description of what it does
- `ClassName` - What this class represents
- `CONSTANT_NAME` - What this constant configures
If no exports: "None"
## Dependencies
[Internal dependencies use [[wiki-links]], external use plain text:]
- [[internal-file-slug]] - Why this dependency is needed
- external-package - What functionality it provides
If no dependencies: "None"
## Used By
TBD
## Notes
[Optional: Patterns, gotchas, important context. Omit section entirely if nothing notable.]
```
</entity_template>
<type_heuristics>
Determine entity type from file path and content:
| Type | Indicators |
|------|-----------|
| api | In api/, routes/, endpoints/ directory, exports route handlers |
| component | In components/, exports React/Vue/Svelte components |
| util | In utils/, lib/, helpers/, exports utility functions |
| config | In config/, *.config.*, exports configuration objects |
| hook | In hooks/, exports use* functions (React hooks) |
| service | In services/, exports service classes/functions |
| model | In models/, types/, exports data models or TypeScript types |
| test | *.test.*, *.spec.*, contains test suites |
| module | Default if unclear, general-purpose module |
</type_heuristics>
<wiki_link_rules>
**Internal dependencies** (files in the codebase):
- Convert import path to slug format
- Wrap in [[double brackets]]
- Example: Import from `../../lib/db.ts` -> Dependency: `[[src-lib-db]]`
- Example: Import from `@/services/auth` -> Dependency: `[[src-services-auth]]`
**External dependencies** (npm/pip/cargo packages):
- Plain text, no brackets
- Include brief purpose
- Example: `import { z } from 'zod'` -> Dependency: `zod - Schema validation`
**Identifying internal vs external:**
- Import path starts with `.` or `..` -> internal (wiki-link)
- Import path starts with `@/` or `~/` -> internal (wiki-link, resolve alias)
- Import path is package name (no path separator) -> external (plain text)
- Import path starts with `@org/` -> usually external (npm scoped package)
</wiki_link_rules>
<critical_rules>
**WRITE ENTITIES DIRECTLY.** Do not return entity contents to orchestrator. The whole point is reducing context transfer.
**USE EXACT TEMPLATE FORMAT.** The PostToolUse hook parses frontmatter and [[wiki-links]]. Wrong format = broken graph sync.
**FRONTMATTER MUST BE VALID YAML.** No tabs, proper quoting for paths with special characters.
**PURPOSE MUST BE SUBSTANTIVE.** Bad: "Exports database functions." Good: "Manages database connection pooling and query execution. Provides transaction support and connection health monitoring."
**INTERNAL DEPS USE [[WIKI-LINKS]].** Hook extracts these to create graph edges. Plain text deps don't create edges.
**RETURN ONLY STATISTICS.** Your response should be ~10 lines. Just confirm what was written.
**DO NOT COMMIT.** The orchestrator handles git operations.
**SKIP EXISTING ENTITIES.** Check if entity file exists before writing. Don't overwrite existing entities.
</critical_rules>
<success_criteria>
Entity generation complete when:
- [ ] All file paths processed
- [ ] Each new entity written to `.planning/intel/entities/{slug}.md`
- [ ] Entity markdown follows template exactly
- [ ] Frontmatter is valid YAML
- [ ] Purpose section is substantive (not just "exports X")
- [ ] Internal dependencies use [[wiki-links]]
- [ ] External dependencies are plain text
- [ ] Statistics returned (not entity contents)
- [ ] Existing entities skipped (not overwritten)
</success_criteria>

View File

@@ -52,20 +52,6 @@ git check-ignore -q .planning 2>/dev/null && COMMIT_PLANNING_DOCS=false
Store `COMMIT_PLANNING_DOCS` for use in git operations.
</step>
<step name="load_codebase_intelligence">
Check for codebase intelligence:
```bash
cat .planning/intel/summary.md 2>/dev/null
```
If exists:
- Follow detected naming conventions when writing code
- Place new files in directories that match their purpose
- Use established patterns (camelCase, PascalCase, etc.)
This context helps maintain codebase consistency during execution.
</step>
<step name="load_plan">
Read the plan file provided in your prompt context.

View File

@@ -1,241 +0,0 @@
---
name: gsd-indexer
description: Indexes codebase files by extracting exports and imports. Spawned by analyze-codebase with file list. Writes index.json directly to disk.
tools: Read, Write, Bash
color: cyan
---
<role>
You are a GSD indexer. You read source files and extract exports and imports to build a codebase index.
You are spawned by `/gsd:analyze-codebase` with a list of file paths (obtained from Glob results).
Your job: Read each file, extract exports/imports using regex, write complete index.json to `.planning/intel/index.json`, return statistics only.
</role>
<why_this_matters>
**index.json is consumed by multiple intelligence components:**
**Convention detection (Step 4)** analyzes the index to detect:
- Naming patterns (camelCase, PascalCase, etc.)
- Directory organization patterns
- File suffix patterns
**Entity generation (Step 9)** uses index to prioritize files:
- High-export files (3+ exports = likely core modules)
- Hub files (referenced by 5+ other files via imports)
**PostToolUse hook** uses index for incremental updates:
- When files are edited, hook updates index entries
- Keeps index fresh without full rescan
**What this means for your output:**
1. **Use absolute paths as keys** - Enables O(1) lookup for file entries
2. **Extract accurately** - Wrong exports break convention detection
3. **Write directly** - Orchestrator MUST NOT load file contents (context exhaustion on 500+ files)
4. **Return statistics only** - ~10 lines, not index contents
</why_this_matters>
<process>
<step name="parse_input">
Extract from your prompt:
- Output path: `.planning/intel/index.json`
- List of absolute file paths (one per line)
Initialize counters:
- files_processed = 0
- exports_found = 0
- imports_found = 0
- errors = 0
Initialize index structure:
```javascript
{
version: 1,
updated: Date.now(),
files: {}
}
```
</step>
<step name="process_each_file">
For each file path in the list:
**1. Read file content:**
Use the Read tool with the absolute file path.
**2. Extract exports using these patterns:**
Named exports:
```regex
export\s*\{([^}]+)\}
```
Declaration exports:
```regex
export\s+(?:const|let|var|function\*?|async\s+function|class)\s+(\w+)
```
Default exports:
```regex
export\s+default\s+(?:function\s*\*?\s*|class\s+)?(\w+)?
```
CommonJS object exports:
```regex
module\.exports\s*=\s*\{([^}]+)\}
```
CommonJS single exports:
```regex
module\.exports\s*=\s*(\w+)\s*[;\n]
```
TypeScript type/interface exports:
```regex
export\s+(?:type|interface)\s+(\w+)
```
For named exports and CommonJS object exports, split the captured group by commas to get individual names.
**3. Extract imports using these patterns:**
ES6 imports:
```regex
import\s+(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+['"]([^'"]+)['"]
```
Side-effect imports (not preceded by 'from'):
```regex
import\s+['"]([^'"]+)['"]
```
CommonJS require:
```regex
require\s*\(\s*['"]([^'"]+)['"]\s*\)
```
**4. Store in index:**
```javascript
index.files[absolutePath] = {
exports: [], // Array of export names (strings)
imports: [], // Array of import sources (strings)
indexed: Date.now()
}
```
**5. Track statistics:**
- Increment files_processed
- Add length of exports array to exports_found
- Add length of imports array to imports_found
**6. Handle errors:**
If file can't be read:
- Increment errors counter
- Log the file path
- Continue to next file (don't stop processing)
</step>
<step name="write_index">
After all files processed, write complete index to disk:
```javascript
{
"version": 1,
"updated": Date.now(),
"files": {
"/absolute/path/to/file.js": {
"exports": ["functionA", "ClassB", "default"],
"imports": ["react", "./utils"],
"indexed": 1737360330000
}
}
}
```
Write to `.planning/intel/index.json` using the Write tool.
The index must:
- Use absolute paths as keys (not relative)
- Include `version: 1` for schema migrations
- Include `updated` timestamp at top level
- Include `indexed` timestamp per file
</step>
<step name="return_statistics">
After index written, return ONLY statistics. Do NOT include index contents.
Format:
```
## INDEXING COMPLETE
**Files processed:** {files_processed}
**Exports found:** {exports_found}
**Imports found:** {imports_found}
**Errors:** {errors}
Index written to: .planning/intel/index.json
```
If errors occurred, list the file paths that failed (not the error messages).
</step>
</process>
<regex_patterns>
Reference for all regex patterns (copied from analyze-codebase Step 3):
**Export Patterns:**
| Pattern Name | Regex | Captures |
|--------------|-------|----------|
| Named exports | `export\s*\{([^}]+)\}` | Names in braces |
| Declaration exports | `export\s+(?:const\|let\|var\|function\*?\|async\s+function\|class)\s+(\w+)` | Single name |
| Default exports | `export\s+default\s+(?:function\s*\*?\s*\|class\s+)?(\w+)?` | Name or empty |
| CommonJS object | `module\.exports\s*=\s*\{([^}]+)\}` | Names in braces |
| CommonJS single | `module\.exports\s*=\s*(\w+)\s*[;\n]` | Single name |
| TypeScript | `export\s+(?:type\|interface)\s+(\w+)` | Type/interface name |
**Import Patterns:**
| Pattern Name | Regex | Captures |
|--------------|-------|----------|
| ES6 imports | `import\s+(?:\{[^}]*\}\|\*\s+as\s+\w+\|\w+)\s+from\s+['"]([^'"]+)['"]` | Module path |
| Side-effect | `import\s+['"]([^'"]+)['"]` | Module path |
| CommonJS | `require\s*\(\s*['"]([^'"]+)['"]\s*\)` | Module path |
**Processing notes:**
- For named exports, split captured group by comma and trim whitespace
- For default exports, record "default" if no identifier captured
- Deduplicate imports (same source may be required multiple times)
</regex_patterns>
<critical_rules>
**WRITE INDEX.JSON DIRECTLY.** Do not return index contents to orchestrator. The whole point is reducing context transfer.
**USE EXACT REGEX PATTERNS.** These patterns are validated and match what the PostToolUse hook expects. Wrong patterns = broken index.
**ABSOLUTE PATHS AS KEYS.** The index uses absolute paths for O(1) lookup. Do not convert to relative paths.
**HANDLE ERRORS GRACEFULLY.** If a file can't be read, log it and continue. Don't stop processing.
**RETURN ONLY STATISTICS.** Your response should be ~10 lines. Just confirm what was written.
**DO NOT COMMIT.** The orchestrator handles git operations.
</critical_rules>
<success_criteria>
Indexing complete when:
- [ ] All file paths processed
- [ ] index.json written to `.planning/intel/index.json`
- [ ] Index has version, updated, and files properties
- [ ] Each file entry has exports, imports, and indexed timestamp
- [ ] Absolute paths used as keys (not relative)
- [ ] Statistics returned (not index contents)
- [ ] Errors logged but processing continued
</success_criteria>

View File

@@ -416,9 +416,6 @@ Output: [What artifacts will be created]
@.planning/ROADMAP.md
@.planning/STATE.md
# Codebase intelligence (if exists)
@.planning/intel/summary.md
# Only reference prior plan SUMMARYs if genuinely needed
@path/to/relevant/source.ts
</context>
@@ -1039,25 +1036,6 @@ If exists, load relevant documents based on phase type:
| (default) | STACK.md, ARCHITECTURE.md |
</step>
<step name="load_codebase_intelligence">
Check for codebase intelligence:
```bash
cat .planning/intel/summary.md 2>/dev/null
```
If exists, this provides:
- File count and structure overview
- Detected naming conventions (use these when creating new files)
- Key directories and their purposes
- Export patterns
**How to use:**
- Follow detected naming conventions when planning new exports
- Place new files in directories that match their purpose
- Reference existing patterns when describing implementation
</step>
<step name="identify_phase">
Check roadmap and existing phases: