[Feature]: Context Auto-Discovery from team-ai-directives using grep-based search
Problem Statement
Currently, when running /spec.specify, the context.md file is populated with mostly placeholder values ([NEEDS INPUT]). Users must manually identify and add relevant directives from their team-ai-directives repository. This is:
- Time-consuming - Users must manually search through team-ai-directives to find relevant personas, rules, and skills
- Error-prone - Users may miss relevant directives that could improve specification quality
- Inconsistent - Different team members may select different directives for similar features
The team-ai-directives repository already contains well-organized knowledge (constitution, personas, rules, skills), but there's no automatic mechanism to match this knowledge to feature descriptions.
Proposed Solution
Implement grep-based context auto-discovery that automatically searches team-ai-directives for relevant content based on the user's feature description.
Two-Layer Architecture
Layer 1: Bash Script (create-new-feature.sh)
- Extract keywords from feature description
- Use
grep -rilto search team-ai-directives for matching files - Rank files by match count (files with more keyword matches rank higher)
- Output discovered directives as JSON for the slash command to consume
Layer 2: Slash Command (specify.md and plan.md)
- Parse the discovered directives from script output
- Validate and refine results (AI can run additional searches if needed)
- Populate
context.mdwith discovered directive paths
Discovery Logic
# Extract keywords from feature description
keywords=$(echo "$feature_description" | tr '[:upper:]' '[:lower:]' | ...)
# Search team-ai-directives
for keyword in $keywords; do
grep -ril "$keyword" "$team_directives_path" >> results
done
# Rank by match frequency, categorize by type
# Output: constitution, personas[], rules[], skills[], examples[]
Example
Input: /spec.specify Implement OAuth2 authentication for Python FastAPI
Grep finds:
- senior_python_developer.md (3 matches: oauth, python, fastapi)
- prevent_sql_injection.md (2 matches: oauth, authentication)
- python_testing.md (1 match: python)
Output in context.md:
- Constitution: context_modules/constitution.md
- Persona: context_modules/personas/senior_python_developer.md
- Rules: security/prevent_sql_injection.md, testing/python_testing.md
Alternatives Considered
- Hardcoded keyword-to-file mappings - Requires constant maintenance, breaks when team-ai-directives structure changes
- AI-only discovery - Slower, less deterministic, depends on AI tool access
- Pre-computed index during
specify init- Becomes stale when directives change
Grep-based search is self-updating, adapts to any team-ai-directives structure, and finds context-specific matches.
Component
- Scripts (Bash/PowerShell utilities)
- Spec templates (BDD, Testing Strategy, etc.)
- Agent integrations (command files, workflows)
AI Agent
All agents
Use Cases
- New feature specification - When running
/spec.specify, automatically discover relevant personas, rules, and skills from team-ai-directives - Planning phase -
/spec.plancan refresh/supplement context if feature scope changed during clarification - Team consistency - Ensure all team members get consistent directive recommendations for similar features
- Onboarding - New team members automatically benefit from team knowledge without manually searching
Acceptance Criteria
- [ ]
create-new-feature.shincludesdiscover_directives()function with grep-based search - [ ]
create-new-feature.ps1includes equivalent PowerShell implementation - [ ] Script JSON output includes
DISCOVERED_DIRECTIVESfield - [ ]
specify.mdincludes instructions for parsing and validating discovery results - [ ]
plan.mdincludes optional context refresh capability - [ ]
context-template.mdupdated with new structure for discovered directives - [ ] Constitution is always included when team-ai-directives exists
- [ ] Files with no keyword matches are excluded (threshold: ≥1 match)
- [ ] No limit on included directives (include all matches above threshold)
- [ ] Graceful fallback when team-ai-directives not configured
- [ ] Works in both
buildandspecmodes
Additional Context
Files to Modify
| File | Changes |
|---|---|
scripts/bash/create-new-feature.sh |
Add discover_directives() function |
scripts/powershell/create-new-feature.ps1 |
Add Discover-Directives function |
templates/commands/specify.md |
Add discovery validation instructions |
templates/commands/plan.md |
Add context refresh section |
templates/context-template.md |
Update structure for discovered directives |
Related
- Builds on existing Skills Auto-Discovery (
src/specify_cli/skills/discovery.py) - Complements team-ai-directives integration (
--team-ai-directivesflag)