chore: install openagent opencode
Signed-off-by: Dmytro Stanchiev <git@dmytros.dev>
This commit is contained in:
921
.opencode/command/add-context.md
Normal file
921
.opencode/command/add-context.md
Normal file
@@ -0,0 +1,921 @@
|
||||
---
|
||||
description: Interactive wizard to add project patterns using Project Intelligence standard
|
||||
tags: [context, onboarding, project-intelligence, wizard]
|
||||
dependencies:
|
||||
- subagent:context-organizer
|
||||
- context:core/context-system/standards/mvi.md
|
||||
- context:core/context-system/standards/frontmatter.md
|
||||
- context:core/standards/project-intelligence.md
|
||||
---
|
||||
|
||||
<context>
|
||||
<system>Project Intelligence onboarding wizard for teaching agents YOUR coding patterns</system>
|
||||
<domain>Project-specific context creation w/ MVI compliance</domain>
|
||||
<task>Interactive 6-question wizard → structured context files w/ 100% pattern preservation</task>
|
||||
</context>
|
||||
|
||||
<role>Context Creation Wizard applying Project Intelligence + MVI + frontmatter standards</role>
|
||||
|
||||
<task>6-question wizard → technical-domain.md w/ tech stack, API/component patterns, naming, standards, security</task>
|
||||
|
||||
<critical_rules priority="absolute" enforcement="strict">
|
||||
<rule id="project_intelligence">
|
||||
MUST create technical-domain.md in project-intelligence/ dir (NOT single project-context.md)
|
||||
</rule>
|
||||
<rule id="frontmatter_required">
|
||||
ALL files MUST start w/ HTML frontmatter: <!-- Context: {category}/{function} | Priority: {level} | Version: X.Y | Updated: YYYY-MM-DD -->
|
||||
</rule>
|
||||
<rule id="mvi_compliance">
|
||||
Files MUST be <200 lines, scannable <30s. MVI formula: 1-3 sentence concept, 3-5 key points, 5-10 line example, ref link
|
||||
</rule>
|
||||
<rule id="codebase_refs">
|
||||
ALL files MUST include "📂 Codebase References" section linking context→actual code implementation
|
||||
</rule>
|
||||
<rule id="navigation_update">
|
||||
MUST update navigation.md when creating/modifying files (add to Quick Routes or Deep Dives table)
|
||||
</rule>
|
||||
<rule id="priority_assignment">
|
||||
MUST assign priority based on usage: critical (80%) | high (15%) | medium (4%) | low (1%)
|
||||
</rule>
|
||||
<rule id="version_tracking">
|
||||
MUST track versions: New file→1.0 | Content update→MINOR (1.1, 1.2) | Structure change→MAJOR (2.0, 3.0)
|
||||
</rule>
|
||||
</critical_rules>
|
||||
|
||||
<execution_priority>
|
||||
<tier level="1" desc="Project Intelligence + MVI + Standards">
|
||||
- @project_intelligence (technical-domain.md in project-intelligence/ dir)
|
||||
- @mvi_compliance (<200 lines, <30s scannable)
|
||||
- @frontmatter_required (HTML frontmatter w/ metadata)
|
||||
- @codebase_refs (link context→code)
|
||||
- @navigation_update (update navigation.md)
|
||||
- @priority_assignment (critical for tech stack/core patterns)
|
||||
- @version_tracking (1.0 for new, incremented for updates)
|
||||
</tier>
|
||||
<tier level="2" desc="Wizard Workflow">
|
||||
- Detect existing context→Review/Add/Replace
|
||||
- 6-question interactive wizard
|
||||
- Generate/update technical-domain.md
|
||||
- Validation w/ MVI checklist
|
||||
</tier>
|
||||
<tier level="3" desc="User Experience">
|
||||
- Clear formatting w/ ━ dividers
|
||||
- Helpful examples
|
||||
- Next steps guidance
|
||||
</tier>
|
||||
<conflict_resolution>Tier 1 always overrides Tier 2/3 - standards are non-negotiable</conflict_resolution>
|
||||
</execution_priority>
|
||||
|
||||
---
|
||||
|
||||
## Purpose
|
||||
|
||||
Help users add project patterns using Project Intelligence standard. **Easiest way** to teach agents YOUR coding patterns.
|
||||
|
||||
**Value**: Answer 6 questions (~5 min) → properly structured context files → agents generate code matching YOUR project.
|
||||
|
||||
**Standards**: @project_intelligence + @mvi_compliance + @frontmatter_required + @codebase_refs
|
||||
|
||||
**Note**: External context files are stored in `.tmp/` directory (e.g., `.tmp/external-context.md`) for temporary or external knowledge that will be organized into the permanent context system.
|
||||
|
||||
**External Context Integration**: The wizard automatically detects external context files in `.tmp/` and offers to extract and use them as source material for your project patterns.
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
/add-context # Interactive wizard (recommended, saves to project)
|
||||
/add-context --update # Update existing context
|
||||
/add-context --tech-stack # Add/update tech stack only
|
||||
/add-context --patterns # Add/update code patterns only
|
||||
/add-context --global # Save to global config (~/.config/opencode/) instead of project
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Quick Start
|
||||
|
||||
**Run**: `/add-context`
|
||||
|
||||
**What happens**:
|
||||
1. Saves to `.opencode/context/project-intelligence/` in your project (always local)
|
||||
2. Checks for external context files in `.tmp/` (if found, offers to extract)
|
||||
3. Checks for existing project intelligence
|
||||
4. Asks 6 questions (~5 min) OR reviews existing patterns
|
||||
5. Shows full preview of files to be created before writing
|
||||
6. Generates/updates technical-domain.md + navigation.md
|
||||
7. Agents now use YOUR patterns
|
||||
|
||||
**6 Questions** (~5 min):
|
||||
1. Tech stack?
|
||||
2. API endpoint example?
|
||||
3. Component example?
|
||||
4. Naming conventions?
|
||||
5. Code standards?
|
||||
6. Security requirements?
|
||||
|
||||
**Done!** Agents now use YOUR patterns.
|
||||
|
||||
**Management Options**:
|
||||
- Update patterns: `/add-context --update`
|
||||
- Manage external files: `/context harvest` (extract, organize, clean)
|
||||
- Harvest to permanent: `/context harvest`
|
||||
- Clean context: `/context harvest` (cleans up .tmp/ files)
|
||||
|
||||
---
|
||||
|
||||
## Workflow
|
||||
|
||||
### Stage 0.5: Resolve Context Location
|
||||
|
||||
Determine where project intelligence files should be saved. This runs BEFORE anything else.
|
||||
|
||||
**Default behavior**: Always use local `.opencode/context/project-intelligence/`.
|
||||
**Override**: `--global` flag saves to `~/.config/opencode/context/project-intelligence/` instead.
|
||||
|
||||
**Resolution:**
|
||||
1. If `--global` flag → `$CONTEXT_DIR = ~/.config/opencode/context/project-intelligence/`
|
||||
2. Otherwise → `$CONTEXT_DIR = .opencode/context/project-intelligence/` (always local)
|
||||
|
||||
**If `.opencode/context/` doesn't exist yet**, create it silently — no prompt needed. The directory structure is part of the output shown in Stage 4.
|
||||
|
||||
**Variable**: `$CONTEXT_DIR` is set here and used in all subsequent stages.
|
||||
|
||||
---
|
||||
|
||||
### Stage 0: Check for External Context Files
|
||||
|
||||
Check: `.tmp/` directory for external context files (e.g., `.tmp/external-context.md`, `.tmp/context-*.md`)
|
||||
|
||||
**If external files found**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Found external context files in .tmp/
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Files found:
|
||||
📄 .tmp/external-context.md (2.4 KB)
|
||||
📄 .tmp/api-patterns.md (1.8 KB)
|
||||
📄 .tmp/component-guide.md (3.1 KB)
|
||||
|
||||
These files can be extracted and organized into permanent context.
|
||||
|
||||
Options:
|
||||
1. Continue with /add-context (ignore external files for now)
|
||||
2. Manage external files first (via /context harvest)
|
||||
|
||||
Choose [1/2]: _
|
||||
```
|
||||
|
||||
**If option 1 (Continue)**:
|
||||
- Proceed to Stage 1 (detect existing project intelligence)
|
||||
- External files remain in .tmp/ for later processing
|
||||
|
||||
**If option 2 (Manage external files)**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Manage External Context Files
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
To manage external context files, use the /context command:
|
||||
|
||||
/context harvest
|
||||
|
||||
This will:
|
||||
✓ Extract knowledge from .tmp/ files
|
||||
✓ Organize into project-intelligence/
|
||||
✓ Clean up temporary files
|
||||
✓ Update navigation.md
|
||||
|
||||
After harvesting, run /add-context again to create project intelligence.
|
||||
|
||||
Ready to harvest? [y/n]: _
|
||||
```
|
||||
|
||||
**If yes**: Exit and run `/context harvest`
|
||||
**If no**: Continue with `/add-context` (Stage 1)
|
||||
|
||||
---
|
||||
|
||||
### Stage 1: Detect Existing Context
|
||||
|
||||
Check: `$CONTEXT_DIR` (set in Stage 0.5 — either `.opencode/context/project-intelligence/` or `~/.config/opencode/context/project-intelligence/`)
|
||||
|
||||
**If exists**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Found existing project intelligence!
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Files found:
|
||||
✓ technical-domain.md (Version: 1.2, Updated: 2026-01-15)
|
||||
✓ business-domain.md (Version: 1.0, Updated: 2026-01-10)
|
||||
✓ navigation.md
|
||||
|
||||
Current patterns:
|
||||
📦 Tech Stack: Next.js 14 + TypeScript + PostgreSQL + Tailwind
|
||||
🔧 API: Zod validation, error handling
|
||||
🎨 Component: Functional components, TypeScript props
|
||||
📝 Naming: kebab-case files, PascalCase components
|
||||
✅ Standards: TypeScript strict, Drizzle ORM
|
||||
🔒 Security: Input validation, parameterized queries
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Options:
|
||||
1. Review and update patterns (show each one)
|
||||
2. Add new patterns (keep all existing)
|
||||
3. Replace all patterns (start fresh)
|
||||
4. Cancel
|
||||
|
||||
Choose [1/2/3/4]: _
|
||||
```
|
||||
|
||||
**If user chooses 3 (Replace all):**
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Replace All: Preview
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Will BACKUP existing files to:
|
||||
.tmp/backup/project-intelligence-{timestamp}/
|
||||
← technical-domain.md (Version: 1.2)
|
||||
← business-domain.md (Version: 1.0)
|
||||
← navigation.md
|
||||
|
||||
Will DELETE and RECREATE:
|
||||
$CONTEXT_DIR/technical-domain.md (new Version: 1.0)
|
||||
$CONTEXT_DIR/navigation.md (new Version: 1.0)
|
||||
|
||||
Existing files backed up → you can restore from .tmp/backup/ if needed.
|
||||
|
||||
Proceed? [y/n]: _
|
||||
```
|
||||
|
||||
**If not exists**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
No project intelligence found. Let's create it!
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Saving to: $CONTEXT_DIR
|
||||
|
||||
Will create:
|
||||
- project-intelligence/technical-domain.md (tech stack & patterns)
|
||||
- project-intelligence/navigation.md (quick overview)
|
||||
|
||||
Takes ~5 min. Follows @mvi_compliance (<200 lines).
|
||||
|
||||
Ready? [y/n]: _
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Stage 1.5: Review Existing Patterns (if updating)
|
||||
|
||||
**Only runs if user chose "Review and update" in Stage 1.**
|
||||
|
||||
For each pattern, show current→ask Keep/Update/Remove:
|
||||
|
||||
#### Pattern 1: Tech Stack
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Pattern 1/6: Tech Stack
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Current:
|
||||
Framework: Next.js 14
|
||||
Language: TypeScript
|
||||
Database: PostgreSQL
|
||||
Styling: Tailwind
|
||||
|
||||
Options: 1. Keep | 2. Update | 3. Remove
|
||||
Choose [1/2/3]: _
|
||||
|
||||
If '2': New tech stack: _
|
||||
```
|
||||
|
||||
#### Pattern 2: API Pattern
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Pattern 2/6: API Pattern
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Current API pattern:
|
||||
```typescript
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json()
|
||||
const validated = schema.parse(body)
|
||||
return Response.json({ success: true })
|
||||
} catch (error) {
|
||||
return Response.json({ error: error.message }, { status: 400 })
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Options: 1. Keep | 2. Update | 3. Remove
|
||||
Choose [1/2/3]: _
|
||||
|
||||
If '2': Paste new API pattern: _
|
||||
```
|
||||
|
||||
#### Pattern 3-6: Component, Naming, Standards, Security
|
||||
*(Same format: show current→Keep/Update/Remove)*
|
||||
|
||||
**After reviewing all**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Review Summary
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Changes:
|
||||
✓ Tech Stack: Updated (Next.js 14 → Next.js 15)
|
||||
✓ API: Kept
|
||||
✓ Component: Updated (new pattern)
|
||||
✓ Naming: Kept
|
||||
✓ Standards: Updated (+2 new)
|
||||
✓ Security: Kept
|
||||
|
||||
Version: 1.2 → 1.3 (content update per @version_tracking)
|
||||
Updated: 2026-01-29
|
||||
|
||||
Proceed? [y/n]: _
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Stage 2: Interactive Wizard (for new patterns)
|
||||
|
||||
#### Q1: Tech Stack
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 1/6: What's your tech stack?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Examples:
|
||||
1. Next.js + TypeScript + PostgreSQL + Tailwind
|
||||
2. React + Python + MongoDB + Material-UI
|
||||
3. Vue + Go + MySQL + Bootstrap
|
||||
4. Other (describe)
|
||||
|
||||
Your tech stack: _
|
||||
```
|
||||
|
||||
**Capture**: Framework, Language, Database, Styling
|
||||
|
||||
#### Q2: API Pattern
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 2/6: API endpoint example?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Paste API endpoint from YOUR project (matches your API style).
|
||||
|
||||
Example (Next.js):
|
||||
```typescript
|
||||
export async function POST(request: Request) {
|
||||
const body = await request.json()
|
||||
const validated = schema.parse(body)
|
||||
return Response.json({ success: true })
|
||||
}
|
||||
```
|
||||
|
||||
Your API pattern (paste or 'skip'): _
|
||||
```
|
||||
|
||||
**Capture**: API endpoint, error handling, validation, response format
|
||||
|
||||
#### Q3: Component Pattern
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 3/6: Component example?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Paste component from YOUR project.
|
||||
|
||||
Example (React):
|
||||
```typescript
|
||||
interface UserCardProps { name: string; email: string }
|
||||
export function UserCard({ name, email }: UserCardProps) {
|
||||
return <div className="rounded-lg border p-4">
|
||||
<h3>{name}</h3><p>{email}</p>
|
||||
</div>
|
||||
}
|
||||
```
|
||||
|
||||
Your component (paste or 'skip'): _
|
||||
```
|
||||
|
||||
**Capture**: Component structure, props pattern, styling, TypeScript
|
||||
|
||||
#### Q4: Naming Conventions
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 4/6: Naming conventions?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Examples:
|
||||
Files: kebab-case (user-profile.tsx)
|
||||
Components: PascalCase (UserProfile)
|
||||
Functions: camelCase (getUserProfile)
|
||||
Database: snake_case (user_profiles)
|
||||
|
||||
Your conventions:
|
||||
Files: _
|
||||
Components: _
|
||||
Functions: _
|
||||
Database: _
|
||||
```
|
||||
|
||||
#### Q5: Code Standards
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 5/6: Code standards?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Examples:
|
||||
- TypeScript strict mode
|
||||
- Validate w/ Zod
|
||||
- Use Drizzle for DB queries
|
||||
- Prefer server components
|
||||
|
||||
Your standards (one/line, 'done' when finished):
|
||||
1. _
|
||||
```
|
||||
|
||||
#### Q6: Security Requirements
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Q 6/6: Security requirements?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Examples:
|
||||
- Validate all user input
|
||||
- Use parameterized queries
|
||||
- Sanitize before rendering
|
||||
- HTTPS only
|
||||
|
||||
Your requirements (one/line, 'done' when finished):
|
||||
1. _
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Stage 3: Generate/Update Context
|
||||
|
||||
**Preview**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Preview: technical-domain.md
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
<!-- Context: project-intelligence/technical | Priority: critical | Version: 1.0 | Updated: 2026-01-29 -->
|
||||
|
||||
# Technical Domain
|
||||
|
||||
**Purpose**: Tech stack, architecture, development patterns for this project.
|
||||
**Last Updated**: 2026-01-29
|
||||
|
||||
## Quick Reference
|
||||
**Update Triggers**: Tech stack changes | New patterns | Architecture decisions
|
||||
**Audience**: Developers, AI agents
|
||||
|
||||
## Primary Stack
|
||||
| Layer | Technology | Version | Rationale |
|
||||
|-------|-----------|---------|-----------|
|
||||
| Framework | {framework} | {version} | {why} |
|
||||
| Language | {language} | {version} | {why} |
|
||||
| Database | {database} | {version} | {why} |
|
||||
| Styling | {styling} | {version} | {why} |
|
||||
|
||||
## Code Patterns
|
||||
### API Endpoint
|
||||
```{language}
|
||||
{user_api_pattern}
|
||||
```
|
||||
|
||||
### Component
|
||||
```{language}
|
||||
{user_component_pattern}
|
||||
```
|
||||
|
||||
## Naming Conventions
|
||||
| Type | Convention | Example |
|
||||
|------|-----------|---------|
|
||||
| Files | {file_naming} | {example} |
|
||||
| Components | {component_naming} | {example} |
|
||||
| Functions | {function_naming} | {example} |
|
||||
| Database | {db_naming} | {example} |
|
||||
|
||||
## Code Standards
|
||||
{user_code_standards}
|
||||
|
||||
## Security Requirements
|
||||
{user_security_requirements}
|
||||
|
||||
## 📂 Codebase References
|
||||
**Implementation**: `{detected_files}` - {desc}
|
||||
**Config**: package.json, tsconfig.json
|
||||
|
||||
## Related Files
|
||||
- Business Domain (example: business-domain.md)
|
||||
- Decisions Log (example: decisions-log.md)
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Size: {line_count} lines (limit: 200 per @mvi_compliance)
|
||||
Status: ✅ MVI compliant
|
||||
|
||||
Save to: $CONTEXT_DIR/technical-domain.md
|
||||
|
||||
Looks good? [y/n/edit]: _
|
||||
```
|
||||
|
||||
**Actions**:
|
||||
- Confirm: Write file per @project_intelligence
|
||||
- Edit: Open in editor→validate after
|
||||
- Update: Show diff→highlight new→confirm
|
||||
|
||||
---
|
||||
|
||||
### Stage 4: Validation & Creation
|
||||
|
||||
**Validation**:
|
||||
```
|
||||
Running validation...
|
||||
|
||||
✅ <200 lines (@mvi_compliance)
|
||||
✅ Has HTML frontmatter (@frontmatter_required)
|
||||
✅ Has metadata (Purpose, Last Updated)
|
||||
✅ Has codebase refs (@codebase_refs)
|
||||
✅ Priority assigned: critical (@priority_assignment)
|
||||
✅ Version set: 1.0 (@version_tracking)
|
||||
✅ MVI compliant (<30s scannable)
|
||||
✅ No duplication
|
||||
```
|
||||
|
||||
**navigation.md preview** (also created/updated):
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Preview: navigation.md
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
# Project Intelligence
|
||||
|
||||
| File | Description | Priority |
|
||||
|------|-------------|----------|
|
||||
| technical-domain.md | Tech stack & patterns | critical |
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
```
|
||||
|
||||
**Full creation plan**:
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
Files to write:
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
CREATE $CONTEXT_DIR/technical-domain.md ({line_count} lines)
|
||||
CREATE $CONTEXT_DIR/navigation.md ({nav_line_count} lines)
|
||||
|
||||
Total: 2 files
|
||||
|
||||
Proceed? [y/n]: _
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
### Stage 5: Confirmation & Next Steps
|
||||
|
||||
```
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
✅ Project Intelligence created successfully!
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Files created:
|
||||
$CONTEXT_DIR/technical-domain.md
|
||||
$CONTEXT_DIR/navigation.md
|
||||
|
||||
Location: $CONTEXT_DIR
|
||||
Agents now use YOUR patterns automatically!
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
What's next?
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
1. Test it:
|
||||
opencode --agent OpenCoder
|
||||
> "Create API endpoint"
|
||||
(Uses YOUR pattern!)
|
||||
|
||||
2. Review: cat $CONTEXT_DIR/technical-domain.md
|
||||
|
||||
3. Add business context: /add-context --business
|
||||
|
||||
4. Build: opencode --agent OpenCoder > "Create user auth system"
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
💡 Tip: Update context as project evolves
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
When you:
|
||||
Add library → /add-context --update
|
||||
Change patterns → /add-context --update
|
||||
Migrate tech → /add-context --update
|
||||
|
||||
Agents stay synced!
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
💡 Tip: Global patterns
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
Want the same patterns across ALL your projects?
|
||||
/add-context --global
|
||||
→ Saves to ~/.config/opencode/context/project-intelligence/
|
||||
→ Acts as fallback for projects without local context
|
||||
|
||||
Already have global patterns? Bring them into this project:
|
||||
/context migrate
|
||||
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
📚 Learn More
|
||||
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||
|
||||
- Project Intelligence: .opencode/context/core/standards/project-intelligence.md
|
||||
- MVI Principles: .opencode/context/core/context-system/standards/mvi.md
|
||||
- Context System: CONTEXT_SYSTEM_GUIDE.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### External Context Detection (Stage 0)
|
||||
|
||||
**Process**:
|
||||
1. Check: `ls .tmp/external-context.md .tmp/context-*.md .tmp/*-context.md 2>/dev/null`
|
||||
2. If files found:
|
||||
- Display list of external context files
|
||||
- Offer options: Continue | Manage (via /context harvest)
|
||||
3. If option 1 (Continue):
|
||||
- Proceed to Stage 1 (detect existing project intelligence)
|
||||
- External files remain in .tmp/ for later processing via `/context harvest`
|
||||
4. If option 2 (Manage):
|
||||
- Guide user to `/context harvest` command
|
||||
- Explain what harvest does (extract, organize, clean)
|
||||
- Exit add-context
|
||||
- User runs `/context harvest` to process external files
|
||||
- User runs `/add-context` again after harvest completes
|
||||
|
||||
### Pattern Detection (Stage 1)
|
||||
|
||||
**Process**:
|
||||
1. Check: `ls $CONTEXT_DIR/` (path determined in Stage 0.5)
|
||||
2. Read: `cat technical-domain.md` (if exists)
|
||||
3. Parse existing patterns:
|
||||
- Frontmatter: version, updated date
|
||||
- Tech stack: "Primary Stack" table
|
||||
- API/Component: "Code Patterns" section
|
||||
- Naming: "Naming Conventions" table
|
||||
- Standards: "Code Standards" section
|
||||
- Security: "Security Requirements" section
|
||||
4. Display summary
|
||||
5. Offer options: Review/Add/Replace/Cancel
|
||||
|
||||
### Pattern Review (Stage 1.5)
|
||||
|
||||
**Per pattern**:
|
||||
1. Show current value (parsed from file)
|
||||
2. Ask: Keep | Update | Remove
|
||||
3. If Update: Prompt for new value
|
||||
4. Track changes in `changes_to_make[]`
|
||||
|
||||
**After all reviewed**:
|
||||
1. Show summary
|
||||
2. Calculate version per @version_tracking (content→MINOR, structure→MAJOR)
|
||||
3. Confirm
|
||||
4. Proceed to Stage 3
|
||||
|
||||
### Delegation to ContextOrganizer
|
||||
|
||||
```yaml
|
||||
operation: create | update
|
||||
template: technical-domain # Project Intelligence template
|
||||
target_directory: project-intelligence
|
||||
|
||||
# For create/update operations
|
||||
user_responses:
|
||||
tech_stack: {framework, language, database, styling}
|
||||
api_pattern: string | null
|
||||
component_pattern: string | null
|
||||
naming_conventions: {files, components, functions, database}
|
||||
code_standards: string[]
|
||||
security_requirements: string[]
|
||||
|
||||
frontmatter:
|
||||
context: project-intelligence/technical
|
||||
priority: critical # @priority_assignment (80% use cases)
|
||||
version: {calculated} # @version_tracking
|
||||
updated: {current_date}
|
||||
|
||||
validation:
|
||||
max_lines: 200 # @mvi_compliance
|
||||
has_frontmatter: true # @frontmatter_required
|
||||
has_codebase_references: true # @codebase_refs
|
||||
navigation_updated: true # @navigation_update
|
||||
```
|
||||
|
||||
**Note**: External context file management (harvest, extract, organize) is handled by `/context harvest` command, not `/add-context`.
|
||||
|
||||
### File Structure Inference
|
||||
|
||||
**Based on tech stack, infer common structure**:
|
||||
|
||||
Next.js: `src/app/ components/ lib/ db/`
|
||||
React: `src/components/ hooks/ utils/ api/`
|
||||
Express: `src/routes/ controllers/ models/ middleware/`
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
**User Experience**:
|
||||
- [ ] Wizard complete <5 min
|
||||
- [ ] Next steps clear
|
||||
- [ ] Update process understood
|
||||
|
||||
**File Quality**:
|
||||
- [ ] @mvi_compliance (<200 lines, <30s scannable)
|
||||
- [ ] @frontmatter_required (HTML frontmatter)
|
||||
- [ ] @codebase_refs (codebase references section)
|
||||
- [ ] @priority_assignment (critical for tech stack)
|
||||
- [ ] @version_tracking (1.0 new, incremented updates)
|
||||
|
||||
**System Integration**:
|
||||
- [ ] @project_intelligence (technical-domain.md in project-intelligence/)
|
||||
- [ ] @navigation_update (navigation.md updated)
|
||||
- [ ] Agents load & use patterns
|
||||
- [ ] No duplication
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: First Time (No Context)
|
||||
```bash
|
||||
/add-context
|
||||
|
||||
# Q1: Next.js + TypeScript + PostgreSQL + Tailwind
|
||||
# Q2: [pastes Next.js API route]
|
||||
# Q3: [pastes React component]
|
||||
# Q4-6: [answers]
|
||||
|
||||
✅ Created: technical-domain.md, navigation.md
|
||||
```
|
||||
|
||||
### Example 2: Review & Update
|
||||
```bash
|
||||
/add-context
|
||||
|
||||
# Found existing → Choose "1. Review and update"
|
||||
# Pattern 1: Tech Stack → Update (Next.js 14 → 15)
|
||||
# Pattern 2-6: Keep
|
||||
|
||||
✅ Updated: Version 1.2 → 1.3
|
||||
```
|
||||
|
||||
### Example 3: Quick Update
|
||||
```bash
|
||||
/add-context --tech-stack
|
||||
|
||||
# Current: Next.js 15 + TypeScript + PostgreSQL + Tailwind
|
||||
# New: Next.js 15 + TypeScript + PostgreSQL + Drizzle + Tailwind
|
||||
|
||||
✅ Version 1.4 → 1.5
|
||||
```
|
||||
|
||||
### Example 4: External Context Files Present
|
||||
```bash
|
||||
/add-context
|
||||
|
||||
# Found external context files in .tmp/
|
||||
# 📄 .tmp/external-context.md (2.4 KB)
|
||||
# 📄 .tmp/api-patterns.md (1.8 KB)
|
||||
#
|
||||
# Options:
|
||||
# 1. Continue with /add-context (ignore external files for now)
|
||||
# 2. Manage external files first (via /context harvest)
|
||||
#
|
||||
# Choose [1/2]: 2
|
||||
#
|
||||
# To manage external context files, use:
|
||||
# /context harvest
|
||||
#
|
||||
# This will:
|
||||
# ✓ Extract knowledge from .tmp/ files
|
||||
# ✓ Organize into project-intelligence/
|
||||
# ✓ Clean up temporary files
|
||||
# ✓ Update navigation.md
|
||||
#
|
||||
# After harvesting, run /add-context again.
|
||||
```
|
||||
|
||||
### Example 5: After Harvesting External Context
|
||||
```bash
|
||||
# After running: /context harvest
|
||||
|
||||
/add-context
|
||||
|
||||
# No external context files found in .tmp/
|
||||
# Proceeding to detect existing project intelligence...
|
||||
#
|
||||
# ✅ Created: technical-domain.md (merged with harvested patterns)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Error Handling
|
||||
|
||||
**Invalid Input**:
|
||||
```
|
||||
⚠️ Invalid input
|
||||
Expected: Tech stack description
|
||||
Got: [empty]
|
||||
|
||||
Example: Next.js + TypeScript + PostgreSQL + Tailwind
|
||||
```
|
||||
|
||||
**File Too Large**:
|
||||
```
|
||||
⚠️ Exceeds 200 lines (@mvi_compliance)
|
||||
Current: 245 | Limit: 200
|
||||
|
||||
Simplify patterns or split into multiple files.
|
||||
```
|
||||
|
||||
**Invalid Syntax**:
|
||||
```
|
||||
⚠️ Invalid code syntax in API pattern
|
||||
Error: Unexpected token line 3
|
||||
|
||||
Check code & retry.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Tips
|
||||
|
||||
**Keep Simple**: Focus on most common patterns, add more later
|
||||
**Use Real Examples**: Paste actual code from YOUR project
|
||||
**Update Regularly**: Run `/add-context --update` when patterns change
|
||||
**Test After**: Build something simple to verify agents use patterns correctly
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Q: Agents not using patterns?**
|
||||
A: Check file exists, <200 lines. Run `/context validate`
|
||||
|
||||
**Q: See what's in context?**
|
||||
A: `cat .opencode/context/project-intelligence/technical-domain.md` (local) or `cat ~/.config/opencode/context/project-intelligence/technical-domain.md` (global)
|
||||
|
||||
**Q: Multiple context files?**
|
||||
A: Yes! Create in your project-intelligence directory. Agents load all.
|
||||
|
||||
**Q: Remove pattern?**
|
||||
A: Edit directly: `nano .opencode/context/project-intelligence/technical-domain.md`
|
||||
|
||||
**Q: Share w/ team?**
|
||||
A: Yes! Use local install (`.opencode/context/project-intelligence/`) and commit to repo. Team members get your patterns automatically.
|
||||
|
||||
**Q: Local vs global?**
|
||||
A: Local (`.opencode/`) = project-specific, committed to git, team-shared. Global (`~/.config/opencode/`) = personal defaults across all projects. Local overrides global.
|
||||
|
||||
**Q: Installed globally but want project patterns?**
|
||||
A: Run `/add-context` (defaults to local). Creates `.opencode/context/project-intelligence/` in your project even if OAC was installed globally.
|
||||
|
||||
**Q: Have external context files in .tmp/?**
|
||||
A: Run `/context harvest` to extract and organize them into permanent context
|
||||
|
||||
**Q: Want to clean up .tmp/ files?**
|
||||
A: Run `/context harvest` to extract knowledge and clean up temporary files
|
||||
|
||||
**Q: Move .tmp/ files to permanent context?**
|
||||
A: Run `/context harvest` to extract and organize them
|
||||
|
||||
**Q: Update external context files?**
|
||||
A: Edit directly: `nano .tmp/external-context.md` then run `/context harvest`
|
||||
|
||||
**Q: Remove specific external file?**
|
||||
A: Delete directly: `rm .tmp/external-context.md` then run `/context harvest`
|
||||
|
||||
---
|
||||
|
||||
## Related Commands
|
||||
|
||||
- `/context` - Manage context files (harvest, organize, validate)
|
||||
- `/context validate` - Check integrity
|
||||
- `/context map` - View structure
|
||||
221
.opencode/command/analyze-patterns.md
Normal file
221
.opencode/command/analyze-patterns.md
Normal file
@@ -0,0 +1,221 @@
|
||||
---
|
||||
id: analyze-patterns
|
||||
name: analyze-patterns
|
||||
description: "Analyze codebase for patterns and similar implementations"
|
||||
type: command
|
||||
category: analysis
|
||||
version: 1.0.0
|
||||
---
|
||||
|
||||
# Command: analyze-patterns
|
||||
|
||||
## Description
|
||||
|
||||
Analyze codebase for recurring patterns, similar implementations, and refactoring opportunities. Replaces codebase-pattern-analyst subagent functionality with a command-based interface.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
/analyze-patterns [--pattern=<pattern>] [--language=<lang>] [--depth=<level>] [--output=<format>]
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|------|----------|-------------|
|
||||
| `--pattern` | string | No | Pattern name or regex to search for (e.g., "singleton", "factory", "error-handling") |
|
||||
| `--language` | string | No | Filter by language: js, ts, py, go, rust, java, etc. |
|
||||
| `--depth` | string | No | Search depth: shallow (current dir) \| medium (src/) \| deep (entire repo) |
|
||||
| `--output` | string | No | Output format: text (default) \| json \| markdown |
|
||||
|
||||
## Behavior
|
||||
|
||||
### Pattern Search
|
||||
- Searches codebase for pattern matches using regex + semantic analysis
|
||||
- Identifies similar implementations across files
|
||||
- Groups results by pattern type + similarity score
|
||||
- Suggests refactoring opportunities
|
||||
|
||||
### Analysis Output
|
||||
- Pattern occurrences with file locations + line numbers
|
||||
- Similarity metrics (how similar are implementations?)
|
||||
- Refactoring suggestions (consolidate, extract, standardize)
|
||||
- Code quality insights (duplication, inconsistency)
|
||||
|
||||
### Result Format
|
||||
```
|
||||
Pattern Analysis Report
|
||||
=======================
|
||||
|
||||
Pattern: [pattern_name]
|
||||
Occurrences: [count]
|
||||
Files: [file_list]
|
||||
|
||||
Implementations:
|
||||
1. [file:line] - [description] (similarity: X%)
|
||||
2. [file:line] - [description] (similarity: Y%)
|
||||
...
|
||||
|
||||
Refactoring Suggestions:
|
||||
- [suggestion 1]
|
||||
- [suggestion 2]
|
||||
...
|
||||
|
||||
Quality Insights:
|
||||
- [insight 1]
|
||||
- [insight 2]
|
||||
...
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Find all error handling patterns
|
||||
```bash
|
||||
/analyze-patterns --pattern="error-handling" --language=ts
|
||||
```
|
||||
|
||||
### Analyze factory patterns across codebase
|
||||
```bash
|
||||
/analyze-patterns --pattern="factory" --depth=deep --output=json
|
||||
```
|
||||
|
||||
### Find similar API endpoint implementations
|
||||
```bash
|
||||
/analyze-patterns --pattern="api-endpoint" --language=js --output=markdown
|
||||
```
|
||||
|
||||
### Search for singleton patterns
|
||||
```bash
|
||||
/analyze-patterns --pattern="singleton" --depth=medium
|
||||
```
|
||||
|
||||
## Implementation
|
||||
|
||||
### Delegation
|
||||
- Delegates to: **opencoder** (primary)
|
||||
- Uses context search capabilities for pattern matching
|
||||
- Returns structured pattern analysis results
|
||||
|
||||
### Context Requirements
|
||||
- Codebase structure + file organization
|
||||
- Language-specific patterns + conventions
|
||||
- Project-specific naming conventions
|
||||
- Existing refactoring guidelines
|
||||
|
||||
### Processing Steps
|
||||
1. Parse command parameters
|
||||
2. Validate pattern syntax (regex or predefined)
|
||||
3. Search codebase using glob + grep tools
|
||||
4. Analyze semantic similarity of matches
|
||||
5. Group results by pattern + similarity
|
||||
6. Generate refactoring suggestions
|
||||
7. Format output per requested format
|
||||
8. Return analysis report
|
||||
|
||||
## Predefined Patterns
|
||||
|
||||
### JavaScript/TypeScript
|
||||
- `singleton` - Singleton pattern implementations
|
||||
- `factory` - Factory pattern implementations
|
||||
- `observer` - Observer/event pattern implementations
|
||||
- `error-handling` - Error handling patterns
|
||||
- `async-patterns` - Promise/async-await patterns
|
||||
- `api-endpoint` - API endpoint definitions
|
||||
- `middleware` - Middleware implementations
|
||||
|
||||
### Python
|
||||
- `decorator` - Decorator pattern implementations
|
||||
- `context-manager` - Context manager patterns
|
||||
- `error-handling` - Exception handling patterns
|
||||
- `async-patterns` - Async/await patterns
|
||||
- `class-patterns` - Class design patterns
|
||||
|
||||
### Go
|
||||
- `interface-patterns` - Interface implementations
|
||||
- `error-handling` - Error handling patterns
|
||||
- `goroutine-patterns` - Goroutine patterns
|
||||
- `middleware` - Middleware implementations
|
||||
|
||||
### Custom Patterns
|
||||
Users can provide custom regex patterns for domain-specific analysis.
|
||||
|
||||
## Output Formats
|
||||
|
||||
### Text (Default)
|
||||
Human-readable report with clear sections and formatting
|
||||
|
||||
### JSON
|
||||
Structured data for programmatic processing:
|
||||
```json
|
||||
{
|
||||
"pattern": "error-handling",
|
||||
"occurrences": 12,
|
||||
"files": ["file1.ts", "file2.ts"],
|
||||
"implementations": [
|
||||
{
|
||||
"file": "file1.ts",
|
||||
"line": 42,
|
||||
"description": "try-catch block",
|
||||
"similarity": 0.95
|
||||
}
|
||||
],
|
||||
"suggestions": ["Consolidate error handling", "Extract to utility"]
|
||||
}
|
||||
```
|
||||
|
||||
### Markdown
|
||||
Formatted for documentation + sharing:
|
||||
```markdown
|
||||
# Pattern Analysis: error-handling
|
||||
|
||||
**Occurrences**: 12
|
||||
**Files**: 3
|
||||
**Similarity Range**: 85-98%
|
||||
|
||||
## Implementations
|
||||
...
|
||||
```
|
||||
|
||||
## Integration
|
||||
|
||||
### Registry Entry
|
||||
```json
|
||||
{
|
||||
"id": "analyze-patterns",
|
||||
"name": "analyze-patterns",
|
||||
"type": "command",
|
||||
"category": "analysis",
|
||||
"description": "Analyze codebase for patterns and similar implementations",
|
||||
"delegates_to": ["opencoder"],
|
||||
"parameters": ["pattern", "language", "depth", "output"]
|
||||
}
|
||||
```
|
||||
|
||||
### Profile Assignment
|
||||
- **Developer Profile**: ✅ Included
|
||||
- **Full Profile**: ✅ Included
|
||||
- **Advanced Profile**: ✅ Included
|
||||
- **Business Profile**: ❌ Not included
|
||||
|
||||
## Notes
|
||||
|
||||
- Replaces `codebase-pattern-analyst` subagent functionality
|
||||
- Command-based interface is more flexible + discoverable
|
||||
- Supports both predefined + custom patterns
|
||||
- Results can be exported for documentation
|
||||
- Integrates with refactoring workflows
|
||||
|
||||
---
|
||||
|
||||
## Validation Checklist
|
||||
|
||||
✅ Command structure defined
|
||||
✅ Parameters documented
|
||||
✅ Behavior specified
|
||||
✅ Examples provided
|
||||
✅ Implementation details included
|
||||
✅ Output formats defined
|
||||
✅ Integration ready
|
||||
✅ Ready for registry integration
|
||||
|
||||
**Status**: Ready for deployment
|
||||
76
.opencode/command/clean.md
Normal file
76
.opencode/command/clean.md
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
description: Clean the codebase or current working task in focus via Prettier, Import Sorter, ESLint, and TypeScript Compiler
|
||||
---
|
||||
|
||||
# Code Quality Cleanup
|
||||
|
||||
You are a code quality specialist. When provided with $ARGUMENTS (file paths or directories), systematically clean and optimize the code for production readiness. If no arguments provided, focus on currently open or recently modified files.
|
||||
|
||||
## Your Cleanup Process:
|
||||
|
||||
**Step 1: Analyze Target Scope**
|
||||
- If $ARGUMENTS provided: Focus on specified files/directories
|
||||
- If no arguments: Check git status for modified files and currently open files
|
||||
- Identify file types and applicable cleanup tools
|
||||
|
||||
**Step 2: Execute Cleanup Pipeline**
|
||||
Perform these actions in order:
|
||||
|
||||
1. **Remove Debug Code**
|
||||
- Strip console.log, debugger statements, and temporary debugging code
|
||||
- Remove commented-out code blocks
|
||||
- Clean up development-only imports
|
||||
|
||||
2. **Format Code Structure**
|
||||
- Run Prettier (if available) or apply consistent formatting
|
||||
- Ensure proper indentation and spacing
|
||||
- Standardize quote usage and trailing commas
|
||||
|
||||
3. **Optimize Imports**
|
||||
- Sort imports alphabetically
|
||||
- Remove unused imports
|
||||
- Group imports by type (libraries, local files)
|
||||
- Use absolute imports where configured
|
||||
|
||||
4. **Fix Linting Issues**
|
||||
- Resolve ESLint/TSLint errors and warnings
|
||||
- Apply auto-fixable rules
|
||||
- Report manual fixes needed
|
||||
|
||||
5. **Type Safety Validation**
|
||||
- Run TypeScript compiler checks
|
||||
- Fix obvious type issues
|
||||
- Add missing type annotations where beneficial
|
||||
|
||||
6. **Comment Optimization**
|
||||
- Remove redundant or obvious comments
|
||||
- Improve unclear comments
|
||||
- Ensure JSDoc/docstring completeness for public APIs
|
||||
|
||||
**Step 3: Present Cleanup Report**
|
||||
|
||||
## 📋 Cleanup Results
|
||||
|
||||
### 🎯 Files Processed
|
||||
- [List of files that were cleaned]
|
||||
|
||||
### 🔧 Actions Taken
|
||||
- **Debug Code Removed**: [Number of console.logs, debuggers removed]
|
||||
- **Formatting Applied**: [Files formatted]
|
||||
- **Imports Optimized**: [Unused imports removed, sorting applied]
|
||||
- **Linting Issues Fixed**: [Auto-fixed issues count]
|
||||
- **Type Issues Resolved**: [TypeScript errors fixed]
|
||||
- **Comments Improved**: [Redundant comments removed, unclear ones improved]
|
||||
|
||||
### 🚨 Manual Actions Needed
|
||||
- [List any issues that require manual intervention]
|
||||
|
||||
### ✅ Quality Improvements
|
||||
- [Summary of overall code quality improvements made]
|
||||
|
||||
## Quality Standards Applied:
|
||||
- **Production Ready**: Remove all debugging and development artifacts
|
||||
- **Consistent Style**: Apply project formatting standards
|
||||
- **Type Safety**: Ensure strong typing where applicable
|
||||
- **Clean Imports**: Optimize dependency management
|
||||
- **Clear Documentation**: Improve code readability through better comments
|
||||
160
.opencode/command/commit.md
Normal file
160
.opencode/command/commit.md
Normal file
@@ -0,0 +1,160 @@
|
||||
---
|
||||
description: Create well-formatted commits with conventional commit messages and emoji
|
||||
---
|
||||
|
||||
# Commit Command
|
||||
|
||||
You are an AI agent that helps create well-formatted git commits with conventional commit messages and emoji icons, follow these instructions exactly. Always run and push the commit, you don't need to ask for confirmation unless there is a big issue or error.
|
||||
|
||||
## Instructions for Agent
|
||||
|
||||
When the user runs this command, execute the following workflow:
|
||||
|
||||
1. **Check command mode**:
|
||||
- If user provides $ARGUMENTS (a simple message), skip to step 3
|
||||
|
||||
2. **Run pre-commit validation**:
|
||||
- Execute `pnpm lint` and report any issues
|
||||
- Execute `pnpm build` and ensure it succeeds
|
||||
- If either fails, ask user if they want to proceed anyway or fix issues first
|
||||
|
||||
3. **Analyze git status**:
|
||||
- Run `git status --porcelain` to check for changes
|
||||
- If no files are staged, run `git add .` to stage all modified files
|
||||
- If files are already staged, proceed with only those files
|
||||
|
||||
4. **Analyze the changes**:
|
||||
- Run `git diff --cached` to see what will be committed
|
||||
- Analyze the diff to determine the primary change type (feat, fix, docs, etc.)
|
||||
- Identify the main scope and purpose of the changes
|
||||
|
||||
5. **Generate commit message**:
|
||||
- Choose appropriate emoji and type from the reference below
|
||||
- Create message following format: `<emoji> <type>: <description>`
|
||||
- Keep description concise, clear, and in imperative mood
|
||||
- Show the proposed message to user for confirmation
|
||||
|
||||
6. **Execute the commit**:
|
||||
- Run `git commit -m "<generated message>"`
|
||||
- Display the commit hash and confirm success
|
||||
- Provide brief summary of what was committed
|
||||
|
||||
## Commit Message Guidelines
|
||||
|
||||
When generating commit messages, follow these rules:
|
||||
|
||||
- **Atomic commits**: Each commit should contain related changes that serve a single purpose
|
||||
- **Imperative mood**: Write as commands (e.g., "add feature" not "added feature")
|
||||
- **Concise first line**: Keep under 72 characters
|
||||
- **Conventional format**: Use `<emoji> <type>: <description>` where type is one of:
|
||||
- `feat`: A new feature
|
||||
- `fix`: A bug fix
|
||||
- `docs`: Documentation changes
|
||||
- `style`: Code style changes (formatting, etc.)
|
||||
- `refactor`: Code changes that neither fix bugs nor add features
|
||||
- `perf`: Performance improvements
|
||||
- `test`: Adding or fixing tests
|
||||
- `chore`: Changes to the build process, tools, etc.
|
||||
- **Present tense, imperative mood**: Write commit messages as commands (e.g., "add feature" not "added feature")
|
||||
- **Concise first line**: Keep the first line under 72 characters
|
||||
- **Emoji**: Each commit type is paired with an appropriate emoji:
|
||||
- ✨ `feat`: New feature
|
||||
- 🐛 `fix`: Bug fix
|
||||
- 📝 `docs`: Documentation
|
||||
- 💄 `style`: Formatting/style
|
||||
- ♻️ `refactor`: Code refactoring
|
||||
- ⚡️ `perf`: Performance improvements
|
||||
- ✅ `test`: Tests
|
||||
- 🔧 `chore`: Tooling, configuration
|
||||
- 🚀 `ci`: CI/CD improvements
|
||||
- 🗑️ `revert`: Reverting changes
|
||||
- 🧪 `test`: Add a failing test
|
||||
- 🚨 `fix`: Fix compiler/linter warnings
|
||||
- 🔒️ `fix`: Fix security issues
|
||||
- 👥 `chore`: Add or update contributors
|
||||
- 🚚 `refactor`: Move or rename resources
|
||||
- 🏗️ `refactor`: Make architectural changes
|
||||
- 🔀 `chore`: Merge branches
|
||||
- 📦️ `chore`: Add or update compiled files or packages
|
||||
- ➕ `chore`: Add a dependency
|
||||
- ➖ `chore`: Remove a dependency
|
||||
- 🌱 `chore`: Add or update seed files
|
||||
- 🧑💻 `chore`: Improve developer experience
|
||||
- 🧵 `feat`: Add or update code related to multithreading or concurrency
|
||||
- 🔍️ `feat`: Improve SEO
|
||||
- 🏷️ `feat`: Add or update types
|
||||
- 💬 `feat`: Add or update text and literals
|
||||
- 🌐 `feat`: Internationalization and localization
|
||||
- 👔 `feat`: Add or update business logic
|
||||
- 📱 `feat`: Work on responsive design
|
||||
- 🚸 `feat`: Improve user experience / usability
|
||||
- 🩹 `fix`: Simple fix for a non-critical issue
|
||||
- 🥅 `fix`: Catch errors
|
||||
- 👽️ `fix`: Update code due to external API changes
|
||||
- 🔥 `fix`: Remove code or files
|
||||
- 🎨 `style`: Improve structure/format of the code
|
||||
- 🚑️ `fix`: Critical hotfix
|
||||
- 🎉 `chore`: Begin a project
|
||||
- 🔖 `chore`: Release/Version tags
|
||||
- 🚧 `wip`: Work in progress
|
||||
- 💚 `fix`: Fix CI build
|
||||
- 📌 `chore`: Pin dependencies to specific versions
|
||||
- 👷 `ci`: Add or update CI build system
|
||||
- 📈 `feat`: Add or update analytics or tracking code
|
||||
- ✏️ `fix`: Fix typos
|
||||
- ⏪️ `revert`: Revert changes
|
||||
- 📄 `chore`: Add or update license
|
||||
- 💥 `feat`: Introduce breaking changes
|
||||
- 🍱 `assets`: Add or update assets
|
||||
- ♿️ `feat`: Improve accessibility
|
||||
- 💡 `docs`: Add or update comments in source code
|
||||
- 🗃️ `db`: Perform database related changes
|
||||
- 🔊 `feat`: Add or update logs
|
||||
- 🔇 `fix`: Remove logs
|
||||
- 🤡 `test`: Mock things
|
||||
- 🥚 `feat`: Add or update an easter egg
|
||||
- 🙈 `chore`: Add or update .gitignore file
|
||||
- 📸 `test`: Add or update snapshots
|
||||
- ⚗️ `experiment`: Perform experiments
|
||||
- 🚩 `feat`: Add, update, or remove feature flags
|
||||
- 💫 `ui`: Add or update animations and transitions
|
||||
- ⚰️ `refactor`: Remove dead code
|
||||
- 🦺 `feat`: Add or update code related to validation
|
||||
- ✈️ `feat`: Improve offline support
|
||||
|
||||
## Reference: Good Commit Examples
|
||||
|
||||
Use these as examples when generating commit messages:
|
||||
- ✨ feat: add user authentication system
|
||||
- 🐛 fix: resolve memory leak in rendering process
|
||||
- 📝 docs: update API documentation with new endpoints
|
||||
- ♻️ refactor: simplify error handling logic in parser
|
||||
- 🚨 fix: resolve linter warnings in component files
|
||||
- 🧑💻 chore: improve developer tooling setup process
|
||||
- 👔 feat: implement business logic for transaction validation
|
||||
- 🩹 fix: address minor styling inconsistency in header
|
||||
- 🚑️ fix: patch critical security vulnerability in auth flow
|
||||
- 🎨 style: reorganize component structure for better readability
|
||||
- 🔥 fix: remove deprecated legacy code
|
||||
- 🦺 feat: add input validation for user registration form
|
||||
- 💚 fix: resolve failing CI pipeline tests
|
||||
- 📈 feat: implement analytics tracking for user engagement
|
||||
- 🔒️ fix: strengthen authentication password requirements
|
||||
- ♿️ feat: improve form accessibility for screen readers
|
||||
|
||||
Example commit sequence:
|
||||
- ✨ feat: add user authentication system
|
||||
- 🐛 fix: resolve memory leak in rendering process
|
||||
- 📝 docs: update API documentation with new endpoints
|
||||
- ♻️ refactor: simplify error handling logic in parser
|
||||
- 🚨 fix: resolve linter warnings in component files
|
||||
- ✅ test: add unit tests for authentication flow
|
||||
|
||||
## Agent Behavior Notes
|
||||
|
||||
- **Error handling**: If validation fails, give user option to proceed or fix issues first
|
||||
- **Auto-staging**: If no files are staged, automatically stage all changes with `git add .`
|
||||
- **File priority**: If files are already staged, only commit those specific files
|
||||
- **Always run and push the commit**: You don't need to ask for confirmation unless there is a big issue or error `git push`.
|
||||
- **Message quality**: Ensure commit messages are clear, concise, and follow conventional format
|
||||
- **Success feedback**: After successful commit, show commit hash and brief summary
|
||||
309
.opencode/command/context.md
Normal file
309
.opencode/command/context.md
Normal file
@@ -0,0 +1,309 @@
|
||||
---
|
||||
description: Context system manager - harvest summaries, extract knowledge, organize context
|
||||
tags:
|
||||
- context
|
||||
- knowledge-management
|
||||
- harvest
|
||||
dependencies:
|
||||
- subagent:context-organizer
|
||||
- subagent:contextscout
|
||||
---
|
||||
|
||||
# Context Manager
|
||||
|
||||
<critical_rules priority="absolute" enforcement="strict">
|
||||
<rule id="mvi_strict">
|
||||
Files MUST be <200 lines. Extract core concepts only (1-3 sentences), 3-5 key points, minimal example, reference link.
|
||||
</rule>
|
||||
|
||||
<rule id="approval_gate">
|
||||
ALWAYS present approval UI before deleting/archiving files. Letter-based selection (A B C or 'all'). NEVER auto-delete.
|
||||
</rule>
|
||||
|
||||
<rule id="function_structure">
|
||||
ALWAYS organize by function: concepts/, examples/, guides/, lookup/, errors/ (not flat files).
|
||||
</rule>
|
||||
|
||||
<rule id="lazy_load">
|
||||
ALWAYS read required context files from .opencode/context/core/context-system/ BEFORE executing operations.
|
||||
</rule>
|
||||
</critical_rules>
|
||||
|
||||
<execution_priority>
|
||||
<tier level="1" desc="Safety & MVI">
|
||||
- Files <200 lines (@critical_rules.mvi_strict)
|
||||
- Show approval before cleanup (@critical_rules.approval_gate)
|
||||
- Function-based structure (@critical_rules.function_structure)
|
||||
- Load context before operations (@critical_rules.lazy_load)
|
||||
</tier>
|
||||
<tier level="2" desc="Core Operations">
|
||||
- Harvest (default), Extract, Organize, Update workflows
|
||||
</tier>
|
||||
<tier level="3" desc="Enhancements">
|
||||
- Cross-references, validation, navigation
|
||||
</tier>
|
||||
<conflict_resolution>
|
||||
Tier 1 always overrides Tier 2/3.
|
||||
</conflict_resolution>
|
||||
</execution_priority>
|
||||
|
||||
**Arguments**: `$ARGUMENTS`
|
||||
|
||||
---
|
||||
|
||||
## Default Behavior (No Arguments)
|
||||
|
||||
When invoked without arguments: `/context`
|
||||
|
||||
<workflow id="default_scan_harvest">
|
||||
<stage id="1" name="QuickScan">
|
||||
Scan workspace for summary files:
|
||||
- *OVERVIEW.md, *SUMMARY.md, SESSION-*.md, CONTEXT-*.md
|
||||
- Files in .tmp/ directory
|
||||
- Files >2KB in root directory
|
||||
</stage>
|
||||
|
||||
<stage id="2" name="Report">
|
||||
Show what was found:
|
||||
```
|
||||
Quick scan results:
|
||||
|
||||
Found 3 summary files:
|
||||
📄 CONTEXT-SYSTEM-OVERVIEW.md (4.2 KB)
|
||||
📄 SESSION-auth-work.md (1.8 KB)
|
||||
📄 .tmp/NOTES.md (800 bytes)
|
||||
|
||||
Recommended action:
|
||||
/context harvest - Clean up summaries → permanent context
|
||||
|
||||
Other options:
|
||||
/context extract {source} - Extract from docs/code
|
||||
/context organize {category} - Restructure existing files
|
||||
/context help - Show all operations
|
||||
```
|
||||
</stage>
|
||||
</workflow>
|
||||
|
||||
**Purpose**: Quick tidy-up. Default assumes you want to harvest summaries and compact workspace.
|
||||
|
||||
---
|
||||
|
||||
## Operations
|
||||
|
||||
### Primary: Harvest & Compact (Default Focus)
|
||||
|
||||
**`/context harvest [path]`** ⭐ Most Common
|
||||
- Extract knowledge from AI summaries → permanent context
|
||||
- Clean workspace (archive/delete summaries)
|
||||
- **Reads**: `operations/harvest.md` + `standards/mvi.md`
|
||||
|
||||
**`/context compact {file}`**
|
||||
- Minimize verbose file to MVI format
|
||||
- **Reads**: `guides/compact.md` + `standards/mvi.md`
|
||||
|
||||
---
|
||||
|
||||
### Secondary: Custom Context Creation
|
||||
|
||||
**`/context extract from {source}`**
|
||||
- Extract context from docs/code/URLs
|
||||
- **Reads**: `operations/extract.md` + `standards/mvi.md` + `guides/compact.md`
|
||||
|
||||
**`/context organize {category}`**
|
||||
- Restructure flat files → function-based folders
|
||||
- **Reads**: `operations/organize.md` + `standards/structure.md`
|
||||
|
||||
**`/context update for {topic}`**
|
||||
- Update context when APIs/frameworks change
|
||||
- **Reads**: `operations/update.md` + `guides/workflows.md`
|
||||
|
||||
**`/context error for {error}`**
|
||||
- Add recurring error to knowledge base
|
||||
- **Reads**: `operations/error.md` + `standards/templates.md`
|
||||
|
||||
**`/context create {category}`**
|
||||
- Create new context category with structure
|
||||
- **Reads**: `guides/creation.md` + `standards/structure.md` + `standards/templates.md`
|
||||
|
||||
---
|
||||
|
||||
### Migration
|
||||
|
||||
**`/context migrate`**
|
||||
- Copy project-intelligence from global (`~/.config/opencode/context/`) to local (`.opencode/context/`)
|
||||
- For users who installed globally but want project-specific, git-committed context
|
||||
- Shows diff if local files already exist, asks before overwriting
|
||||
- Optionally cleans up global project-intelligence after migration
|
||||
- **Reads**: `standards/mvi.md`
|
||||
|
||||
---
|
||||
|
||||
### Utility Operations
|
||||
|
||||
**`/context map [category]`**
|
||||
- View current context structure, file counts
|
||||
|
||||
**`/context validate`**
|
||||
- Check integrity, references, file sizes
|
||||
|
||||
**`/context help`**
|
||||
- Show all operations with examples
|
||||
|
||||
---
|
||||
|
||||
## Lazy Loading Strategy
|
||||
|
||||
<lazy_load_map>
|
||||
<operation name="default">
|
||||
Read: operations/harvest.md, standards/mvi.md
|
||||
</operation>
|
||||
|
||||
<operation name="harvest">
|
||||
Read: operations/harvest.md, standards/mvi.md, guides/workflows.md
|
||||
</operation>
|
||||
|
||||
<operation name="compact">
|
||||
Read: guides/compact.md, standards/mvi.md
|
||||
</operation>
|
||||
|
||||
<operation name="extract">
|
||||
Read: operations/extract.md, standards/mvi.md, guides/compact.md, guides/workflows.md
|
||||
</operation>
|
||||
|
||||
<operation name="organize">
|
||||
Read: operations/organize.md, standards/structure.md, guides/workflows.md
|
||||
</operation>
|
||||
|
||||
<operation name="update">
|
||||
Read: operations/update.md, guides/workflows.md, standards/mvi.md
|
||||
</operation>
|
||||
|
||||
<operation name="error">
|
||||
Read: operations/error.md, standards/templates.md, guides/workflows.md
|
||||
</operation>
|
||||
|
||||
<operation name="create">
|
||||
Read: guides/creation.md, standards/structure.md, standards/templates.md
|
||||
</operation>
|
||||
|
||||
<operation name="migrate">
|
||||
Read: standards/mvi.md
|
||||
</operation>
|
||||
</lazy_load_map>
|
||||
|
||||
**All files located in**: `.opencode/context/core/context-system/`
|
||||
|
||||
---
|
||||
|
||||
## Subagent Routing
|
||||
|
||||
<subagent_routing>
|
||||
<!-- Delegate operations to specialized subagents -->
|
||||
<route operations="harvest|extract|organize|update|error|create|migrate" to="ContextOrganizer">
|
||||
Pass: operation name, arguments, lazy load map
|
||||
Subagent loads: Required context files from .opencode/context/core/context-system/
|
||||
Subagent executes: Multi-stage workflow per operation
|
||||
</route>
|
||||
|
||||
<route operations="map|validate" to="ContextScout">
|
||||
Pass: operation name, arguments
|
||||
Subagent executes: Read-only analysis and reporting
|
||||
</route>
|
||||
</subagent_routing>
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference
|
||||
|
||||
### Structure
|
||||
```
|
||||
.opencode/context/core/context-system/
|
||||
├── operations/ # How to do things (harvest, extract, organize, update)
|
||||
├── standards/ # What to follow (mvi, structure, templates)
|
||||
└── guides/ # Step-by-step (workflows, compact, creation)
|
||||
```
|
||||
|
||||
### MVI Principle (Quick)
|
||||
- Core concept: 1-3 sentences
|
||||
- Key points: 3-5 bullets
|
||||
- Minimal example: <10 lines
|
||||
- Reference link: to full docs
|
||||
- File size: <200 lines
|
||||
|
||||
### Function-Based Structure (Quick)
|
||||
```
|
||||
{category}/
|
||||
├── navigation.md # Navigation
|
||||
├── concepts/ # What it is
|
||||
├── examples/ # Working code
|
||||
├── guides/ # How to
|
||||
├── lookup/ # Quick reference
|
||||
└── errors/ # Common issues
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### Default (Quick Scan)
|
||||
```bash
|
||||
/context
|
||||
# Scans workspace, suggests harvest if summaries found
|
||||
```
|
||||
|
||||
### Harvest Summaries
|
||||
```bash
|
||||
/context harvest
|
||||
/context harvest .tmp/
|
||||
/context harvest OVERVIEW.md
|
||||
```
|
||||
|
||||
### Extract from Docs
|
||||
```bash
|
||||
/context extract from docs/api.md
|
||||
/context extract from https://react.dev/hooks
|
||||
```
|
||||
|
||||
### Organize Existing
|
||||
```bash
|
||||
/context organize development/
|
||||
/context organize development/ --dry-run
|
||||
```
|
||||
|
||||
### Update for Changes
|
||||
```bash
|
||||
/context update for Next.js 15
|
||||
/context update for React 19 breaking changes
|
||||
```
|
||||
|
||||
### Migrate Global to Local
|
||||
```bash
|
||||
/context migrate
|
||||
# Copies project-intelligence from ~/.config/opencode/context/ to .opencode/context/
|
||||
# Shows what will be copied, asks for approval before proceeding
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
After any operation:
|
||||
- [ ] All files <200 lines? (@critical_rules.mvi_strict)
|
||||
- [ ] Function-based structure used? (@critical_rules.function_structure)
|
||||
- [ ] Approval UI shown for destructive ops? (@critical_rules.approval_gate)
|
||||
- [ ] Required context loaded? (@critical_rules.lazy_load)
|
||||
- [ ] navigation.md updated?
|
||||
- [ ] Files scannable in <30 seconds?
|
||||
|
||||
---
|
||||
|
||||
## Full Documentation
|
||||
|
||||
**Context System Location**: `.opencode/context/core/context-system/`
|
||||
|
||||
**Structure**:
|
||||
- `operations/` - Detailed operation workflows
|
||||
- `standards/` - MVI, structure, templates
|
||||
- `guides/` - Interactive examples, creation standards
|
||||
|
||||
**Read before using**: `standards/mvi.md` (understand Minimal Viable Information principle)
|
||||
433
.opencode/command/openagents/check-context-deps.md
Normal file
433
.opencode/command/openagents/check-context-deps.md
Normal file
@@ -0,0 +1,433 @@
|
||||
---
|
||||
description: Validate context file dependencies across agents and registry
|
||||
tags:
|
||||
- registry
|
||||
- validation
|
||||
- context
|
||||
- dependencies
|
||||
- openagents
|
||||
dependencies:
|
||||
- command:analyze-patterns
|
||||
---
|
||||
|
||||
# Check Context Dependencies
|
||||
|
||||
**Purpose**: Ensure agents properly declare their context file dependencies in frontmatter and registry.
|
||||
|
||||
**Arguments**: `$ARGUMENTS`
|
||||
|
||||
---
|
||||
|
||||
## What It Does
|
||||
|
||||
Validates consistency between:
|
||||
1. **Actual usage** - Context files referenced in agent prompts
|
||||
2. **Declared dependencies** - Dependencies in agent frontmatter
|
||||
3. **Registry entries** - Dependencies in registry.json
|
||||
|
||||
**Identifies**:
|
||||
- ✅ Missing dependency declarations (agents use context but don't declare it)
|
||||
- ✅ Unused context files (exist but no agent references them)
|
||||
- ✅ Broken references (referenced but don't exist)
|
||||
- ✅ Format inconsistencies (wrong dependency format)
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# Analyze all agents
|
||||
/check-context-deps
|
||||
|
||||
# Analyze specific agent
|
||||
/check-context-deps contextscout
|
||||
|
||||
# Auto-fix missing dependencies
|
||||
/check-context-deps --fix
|
||||
|
||||
# Verbose output (show all reference locations)
|
||||
/check-context-deps --verbose
|
||||
|
||||
# Combine flags
|
||||
/check-context-deps contextscout --verbose
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Workflow
|
||||
|
||||
<workflow id="analyze_context_dependencies">
|
||||
<stage id="1" name="ScanAgents" required="true">
|
||||
Scan agent files for context references:
|
||||
|
||||
**Search patterns**:
|
||||
- `.opencode/context/` (direct path references)
|
||||
- `@.opencode/context/` (@ symbol references)
|
||||
- `context:` (dependency declarations in frontmatter)
|
||||
|
||||
**Locations**:
|
||||
- `.opencode/agent/**/*.md` (all agents and subagents)
|
||||
- `.opencode/command/**/*.md` (commands that use context)
|
||||
|
||||
**Extract**:
|
||||
- Agent/command ID
|
||||
- Context file path
|
||||
- Line number
|
||||
- Reference type (path, @-reference, dependency)
|
||||
</stage>
|
||||
|
||||
<stage id="2" name="CheckRegistry" required="true">
|
||||
For each agent found, check registry.json:
|
||||
|
||||
```bash
|
||||
jq '.components.agents[] | select(.id == "AGENT_ID") | .dependencies' registry.json
|
||||
jq '.components.subagents[] | select(.id == "AGENT_ID") | .dependencies' registry.json
|
||||
```
|
||||
|
||||
**Verify**:
|
||||
- Does the agent have a dependencies array?
|
||||
- Are context file references declared as `context:core/standards/code`?
|
||||
- Are the dependency formats correct (`context:path/to/file`)?
|
||||
</stage>
|
||||
|
||||
<stage id="3" name="ValidateContextFiles" required="true">
|
||||
For each context file referenced:
|
||||
|
||||
**Check existence**:
|
||||
```bash
|
||||
test -f .opencode/context/core/standards/code-quality.md
|
||||
```
|
||||
|
||||
**Check registry**:
|
||||
```bash
|
||||
jq '.components.contexts[] | select(.id == "core/standards/code")' registry.json
|
||||
```
|
||||
|
||||
**Identify issues**:
|
||||
- Context file referenced but doesn't exist
|
||||
- Context file exists but not in registry
|
||||
- Context file in registry but never used
|
||||
</stage>
|
||||
|
||||
<stage id="4" name="Report" required="true">
|
||||
Generate comprehensive report:
|
||||
|
||||
```markdown
|
||||
# Context Dependency Analysis Report
|
||||
|
||||
## Summary
|
||||
- Agents scanned: 25
|
||||
- Context files referenced: 12
|
||||
- Missing dependencies: 8
|
||||
- Unused context files: 2
|
||||
- Missing context files: 0
|
||||
|
||||
## Missing Dependencies (agents using context but not declaring)
|
||||
|
||||
### opencoder
|
||||
**Uses but not declared**:
|
||||
- context:core/standards/code (referenced 3 times)
|
||||
- Line 64: "Code tasks → .opencode/context/core/standards/code-quality.md (MANDATORY)"
|
||||
- Line 170: "Read .opencode/context/core/standards/code-quality.md NOW"
|
||||
- Line 229: "NEVER execute write/edit without loading required context first"
|
||||
|
||||
**Current dependencies**: subagent:task-manager, subagent:coder-agent
|
||||
**Recommended fix**: Add to frontmatter:
|
||||
```yaml
|
||||
dependencies:
|
||||
- subagent:task-manager
|
||||
- subagent:coder-agent
|
||||
- context:core/standards/code # ADD THIS
|
||||
```
|
||||
|
||||
### openagent
|
||||
**Uses but not declared**:
|
||||
- context:core/standards/code (referenced 5 times)
|
||||
- context:core/standards/docs (referenced 3 times)
|
||||
- context:core/standards/tests (referenced 3 times)
|
||||
- context:core/workflows/review (referenced 2 times)
|
||||
- context:core/workflows/delegation (referenced 4 times)
|
||||
|
||||
**Recommended fix**: Add to frontmatter:
|
||||
```yaml
|
||||
dependencies:
|
||||
- subagent:task-manager
|
||||
- subagent:documentation
|
||||
- context:core/standards/code
|
||||
- context:core/standards/docs
|
||||
- context:core/standards/tests
|
||||
- context:core/workflows/review
|
||||
- context:core/workflows/delegation
|
||||
```
|
||||
|
||||
## Unused Context Files (exist but no agent references them)
|
||||
|
||||
- context:core/standards/analysis (0 references)
|
||||
- context:core/workflows/sessions (0 references)
|
||||
|
||||
**Recommendation**: Consider removing or documenting intended use
|
||||
|
||||
## Missing Context Files (referenced but don't exist)
|
||||
|
||||
None found ✅
|
||||
|
||||
## Context File Usage Map
|
||||
|
||||
| Context File | Used By | Reference Count |
|
||||
|--------------|---------|-----------------|
|
||||
| core/standards/code | opencoder, openagent, frontend-specialist, reviewer | 15 |
|
||||
| core/standards/docs | openagent, documentation, technical-writer | 8 |
|
||||
| core/standards/tests | openagent, tester | 6 |
|
||||
| core/workflows/delegation | openagent, task-manager | 5 |
|
||||
| core/workflows/review | openagent, reviewer | 4 |
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Review missing dependencies above
|
||||
2. Run `/check-context-deps --fix` to auto-update frontmatter
|
||||
3. Run `./scripts/registry/auto-detect-components.sh` to update registry
|
||||
4. Verify with `./scripts/registry/validate-registry.sh`
|
||||
```
|
||||
</stage>
|
||||
|
||||
<stage id="5" name="Fix" when="--fix flag provided">
|
||||
For each agent with missing context dependencies:
|
||||
|
||||
1. Read the agent file
|
||||
2. Parse frontmatter YAML
|
||||
3. Add missing context dependencies to dependencies array
|
||||
4. Preserve existing dependencies
|
||||
5. Write updated file
|
||||
6. Report what was changed
|
||||
|
||||
**Example**:
|
||||
```diff
|
||||
---
|
||||
id: opencoder
|
||||
dependencies:
|
||||
- subagent:task-manager
|
||||
- subagent:coder-agent
|
||||
+ - context:core/standards/code
|
||||
---
|
||||
```
|
||||
|
||||
**Safety**:
|
||||
- Only add dependencies that are actually referenced in the file
|
||||
- Don't remove existing dependencies
|
||||
- Preserve frontmatter formatting
|
||||
- Show diff before applying (if interactive)
|
||||
</stage>
|
||||
</workflow>
|
||||
|
||||
---
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### Search Patterns
|
||||
|
||||
**Find direct path references**:
|
||||
```bash
|
||||
grep -rn "\.opencode/context/" .opencode/agent/ .opencode/command/
|
||||
```
|
||||
|
||||
**Find @ references**:
|
||||
```bash
|
||||
grep -rn "@\.opencode/context/" .opencode/agent/ .opencode/command/
|
||||
```
|
||||
|
||||
**Find dependency declarations**:
|
||||
```bash
|
||||
grep -rn "^\s*-\s*context:" .opencode/agent/ .opencode/command/
|
||||
```
|
||||
|
||||
### Path Normalization
|
||||
|
||||
**Convert to dependency format**:
|
||||
- `.opencode/context/core/standards/code-quality.md` → `context:core/standards/code`
|
||||
- `@.opencode/context/openagents-repo/quick-start.md` → `context:openagents-repo/quick-start`
|
||||
- `context/core/standards/code` → `context:core/standards/code`
|
||||
|
||||
**Rules**:
|
||||
1. Strip `.opencode/` prefix
|
||||
2. Strip `.md` extension
|
||||
3. Add `context:` prefix for dependencies
|
||||
|
||||
### Registry Lookup
|
||||
|
||||
**Check if context file is in registry**:
|
||||
```bash
|
||||
jq '.components.contexts[] | select(.id == "core/standards/code")' registry.json
|
||||
```
|
||||
|
||||
**Get agent dependencies**:
|
||||
```bash
|
||||
jq '.components.agents[] | select(.id == "opencoder") | .dependencies[]?' registry.json
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Delegation
|
||||
|
||||
This command delegates to an analysis agent to perform the work:
|
||||
|
||||
```javascript
|
||||
task(
|
||||
subagent_type="PatternAnalyst",
|
||||
description="Analyze context dependencies",
|
||||
prompt=`
|
||||
Analyze context file usage across all agents in this repository.
|
||||
|
||||
TASK:
|
||||
1. Use grep to find all references to context files in:
|
||||
- .opencode/agent/**/*.md
|
||||
- .opencode/command/**/*.md
|
||||
|
||||
2. Search for these patterns:
|
||||
- ".opencode/context/core/" (direct paths)
|
||||
- "@.opencode/context/" (@ references)
|
||||
- "context:" in frontmatter (dependency declarations)
|
||||
|
||||
3. For each agent file found:
|
||||
- Extract agent ID from frontmatter
|
||||
- List all context files it references
|
||||
- Check registry.json for declared dependencies
|
||||
- Identify missing dependency declarations
|
||||
|
||||
4. For each context file in .opencode/context/core/:
|
||||
- Count how many agents reference it
|
||||
- Check if it exists in registry.json
|
||||
- Identify unused context files
|
||||
|
||||
5. Generate a comprehensive report showing:
|
||||
- Agents with missing context dependencies
|
||||
- Unused context files
|
||||
- Missing context files (referenced but don't exist)
|
||||
- Context file usage map (which agents use which files)
|
||||
|
||||
${ARGUMENTS.includes('--fix') ? `
|
||||
6. AUTO-FIX MODE:
|
||||
- Update agent frontmatter to add missing context dependencies
|
||||
- Use format: context:core/standards/code
|
||||
- Preserve existing dependencies
|
||||
- Show what was changed
|
||||
` : ''}
|
||||
|
||||
${ARGUMENTS.includes('--verbose') ? `
|
||||
VERBOSE MODE: Include all reference locations (file:line) in report
|
||||
` : ''}
|
||||
|
||||
${ARGUMENTS.length > 0 && !ARGUMENTS.includes('--') ? `
|
||||
FILTER: Only analyze agent: ${ARGUMENTS[0]}
|
||||
` : ''}
|
||||
|
||||
REPORT FORMAT:
|
||||
- Summary statistics
|
||||
- Missing dependencies by agent (with recommended fixes)
|
||||
- Unused context files
|
||||
- Context file usage map
|
||||
- Next steps
|
||||
|
||||
DO NOT make changes without --fix flag.
|
||||
ALWAYS show what would be changed before applying fixes.
|
||||
`
|
||||
)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
### Example 1: Basic Analysis
|
||||
|
||||
```bash
|
||||
/check-context-deps
|
||||
```
|
||||
|
||||
**Output**:
|
||||
```
|
||||
Analyzing context file usage across 25 agents...
|
||||
|
||||
Found 8 agents with missing context dependencies:
|
||||
- opencoder: missing context:core/standards/code
|
||||
- openagent: missing 5 context dependencies
|
||||
- frontend-specialist: missing context:core/standards/code
|
||||
...
|
||||
|
||||
Run /check-context-deps --fix to auto-update frontmatter
|
||||
```
|
||||
|
||||
### Example 2: Analyze Specific Agent
|
||||
|
||||
```bash
|
||||
/check-context-deps contextscout
|
||||
```
|
||||
|
||||
**Output**:
|
||||
```
|
||||
Analyzing agent: contextscout
|
||||
|
||||
Context files referenced:
|
||||
✓ .opencode/context/core/context-system.md (1 reference)
|
||||
- Line 15: "Load: context:core/context-system"
|
||||
✓ .opencode/context/core/context-system/standards/mvi.md (2 references)
|
||||
- Line 16: "Load: context:core/context-system/standards/mvi"
|
||||
- Line 89: "MVI-aware prioritization"
|
||||
|
||||
Registry dependencies:
|
||||
✓ context:core/context-system DECLARED
|
||||
✓ context:core/context-system/standards/mvi DECLARED
|
||||
|
||||
All dependencies properly declared ✅
|
||||
```
|
||||
|
||||
### Example 3: Auto-Fix
|
||||
|
||||
```bash
|
||||
/check-context-deps --fix
|
||||
```
|
||||
|
||||
**Output**:
|
||||
```
|
||||
Analyzing and fixing context dependencies...
|
||||
|
||||
Updated opencoder:
|
||||
+ Added: context:core/standards/code
|
||||
|
||||
Updated openagent:
|
||||
+ Added: context:core/standards/code
|
||||
+ Added: context:core/standards/docs
|
||||
+ Added: context:core/standards/tests
|
||||
+ Added: context:core/workflows/review
|
||||
+ Added: context:core/workflows/delegation
|
||||
|
||||
Total: 2 agents updated, 6 dependencies added
|
||||
|
||||
Next: Run ./scripts/registry/auto-detect-components.sh to update registry
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Success Criteria
|
||||
|
||||
✅ All agents that reference context files have them declared in dependencies
|
||||
✅ All context files in registry are actually used by at least one agent
|
||||
✅ No broken references (context files referenced but don't exist)
|
||||
✅ Dependency format is consistent (`context:path/to/file`)
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- **Read-only by default** - Only reports findings, doesn't modify files
|
||||
- **Use `--fix` to update** - Auto-adds missing dependencies to frontmatter
|
||||
- **After fixing** - Run `./scripts/registry/auto-detect-components.sh --auto-add` to sync registry
|
||||
- **Dependency format** - `context:path/to/file` (no `.opencode/` prefix, no `.md` extension)
|
||||
- **Scans both** - Direct path references and @ references
|
||||
|
||||
## Related
|
||||
|
||||
- **Registry validation**: `./scripts/registry/validate-registry.sh`
|
||||
- **Auto-detect components**: `./scripts/registry/auto-detect-components.sh`
|
||||
- **Context guide**: `.opencode/context/openagents-repo/quality/registry-dependencies.md`
|
||||
190
.opencode/command/optimize.md
Normal file
190
.opencode/command/optimize.md
Normal file
@@ -0,0 +1,190 @@
|
||||
---
|
||||
description: Analyze and optimize code for performance, security, and potential issues
|
||||
---
|
||||
|
||||
# Code Optimization Analysis
|
||||
|
||||
You are a code optimization specialist focused on performance, security, and identifying potential issues before they become problems. When provided with $ARGUMENTS (file paths or directories), analyze and optimize the specified code. If no arguments provided, analyze the current context (open files, recent changes, or project focus).
|
||||
|
||||
## Your Optimization Process:
|
||||
|
||||
**Step 1: Determine Analysis Scope**
|
||||
- If $ARGUMENTS provided: Focus on specified files/directories
|
||||
- If no arguments: Analyze current context by checking:
|
||||
- Currently open files in the IDE
|
||||
- Recently modified files via `git status` and `git diff --name-only HEAD~5`
|
||||
- Files with recent git blame activity
|
||||
- Identify file types and applicable optimization strategies
|
||||
|
||||
**Step 2: Performance Analysis**
|
||||
Execute comprehensive performance review:
|
||||
|
||||
1. **Algorithmic Efficiency**
|
||||
- Identify O(n²) or worse time complexity patterns
|
||||
- Look for unnecessary nested loops
|
||||
- Find redundant calculations or database queries
|
||||
- Spot inefficient data structure usage
|
||||
|
||||
2. **Memory Management**
|
||||
- Detect memory leaks and excessive allocations
|
||||
- Find large objects that could be optimized
|
||||
- Identify unnecessary data retention
|
||||
- Check for proper cleanup in event handlers
|
||||
|
||||
3. **I/O Optimization**
|
||||
- Analyze file read/write patterns
|
||||
- Check for unnecessary API calls
|
||||
- Look for missing caching opportunities
|
||||
- Identify blocking operations that could be async
|
||||
|
||||
4. **Framework-Specific Issues**
|
||||
- React: unnecessary re-renders, missing memoization
|
||||
- Node.js: synchronous operations, missing streaming
|
||||
- Database: N+1 queries, missing indexes
|
||||
- Frontend: bundle size, asset optimization
|
||||
|
||||
**Step 3: Security Analysis**
|
||||
Scan for security vulnerabilities:
|
||||
|
||||
1. **Input Validation**
|
||||
- Missing sanitization of user inputs
|
||||
- SQL injection vulnerabilities
|
||||
- XSS attack vectors
|
||||
- Path traversal risks
|
||||
|
||||
2. **Authentication & Authorization**
|
||||
- Weak password policies
|
||||
- Missing authentication checks
|
||||
- Inadequate session management
|
||||
- Privilege escalation risks
|
||||
|
||||
3. **Data Protection**
|
||||
- Sensitive data in logs or errors
|
||||
- Unencrypted sensitive data storage
|
||||
- Missing rate limiting
|
||||
- Insecure API endpoints
|
||||
|
||||
4. **Dependency Security**
|
||||
- Outdated packages with known vulnerabilities
|
||||
- Unused dependencies increasing attack surface
|
||||
- Missing security headers
|
||||
|
||||
**Step 4: Potential Issue Detection**
|
||||
Identify hidden problems:
|
||||
|
||||
1. **Error Handling**
|
||||
- Missing try-catch blocks
|
||||
- Silent failures
|
||||
- Inadequate error logging
|
||||
- Poor user error feedback
|
||||
|
||||
2. **Edge Cases**
|
||||
- Null/undefined handling
|
||||
- Empty array/object scenarios
|
||||
- Network failure handling
|
||||
- Race condition possibilities
|
||||
|
||||
3. **Scalability Concerns**
|
||||
- Hard-coded limits
|
||||
- Single points of failure
|
||||
- Resource exhaustion scenarios
|
||||
- Concurrent access issues
|
||||
|
||||
4. **Maintainability Issues**
|
||||
- Code duplication
|
||||
- Overly complex functions
|
||||
- Missing documentation for critical logic
|
||||
- Tight coupling between components
|
||||
|
||||
**Step 5: Present Optimization Report**
|
||||
|
||||
## 📋 Code Optimization Analysis
|
||||
|
||||
### 🎯 Analysis Scope
|
||||
- **Files Analyzed**: [List of files examined]
|
||||
- **Total Lines**: [Code volume analyzed]
|
||||
- **Languages**: [Programming languages found]
|
||||
- **Frameworks**: [Frameworks/libraries detected]
|
||||
|
||||
### ⚡ Performance Issues Found
|
||||
|
||||
#### 🔴 Critical Performance Issues
|
||||
- **Issue**: [Specific performance problem]
|
||||
- **Location**: [File:line reference]
|
||||
- **Impact**: [Performance cost/bottleneck]
|
||||
- **Solution**: [Specific optimization approach]
|
||||
|
||||
#### 🟡 Performance Improvements
|
||||
- **Optimization**: [Improvement opportunity]
|
||||
- **Expected Gain**: [Performance benefit]
|
||||
- **Implementation**: [How to apply the fix]
|
||||
|
||||
### 🔒 Security Vulnerabilities
|
||||
|
||||
#### 🚨 Critical Security Issues
|
||||
- **Vulnerability**: [Security flaw found]
|
||||
- **Risk Level**: [High/Medium/Low]
|
||||
- **Location**: [Where the issue exists]
|
||||
- **Fix**: [Security remediation steps]
|
||||
|
||||
#### 🛡️ Security Hardening Opportunities
|
||||
- **Enhancement**: [Security improvement]
|
||||
- **Benefit**: [Protection gained]
|
||||
- **Implementation**: [Steps to implement]
|
||||
|
||||
### ⚠️ Potential Issues & Edge Cases
|
||||
|
||||
#### 🔍 Hidden Problems
|
||||
- **Issue**: [Potential problem identified]
|
||||
- **Scenario**: [When this could cause issues]
|
||||
- **Prevention**: [How to avoid the problem]
|
||||
|
||||
#### 🧪 Edge Cases to Handle
|
||||
- **Case**: [Unhandled edge case]
|
||||
- **Impact**: [What could go wrong]
|
||||
- **Solution**: [How to handle it properly]
|
||||
|
||||
### 🏗️ Architecture & Maintainability
|
||||
|
||||
#### 📐 Code Quality Issues
|
||||
- **Problem**: [Maintainability concern]
|
||||
- **Location**: [Where it occurs]
|
||||
- **Refactoring**: [Improvement approach]
|
||||
|
||||
#### 🔗 Dependency Optimization
|
||||
- **Unused Dependencies**: [Packages to remove]
|
||||
- **Outdated Packages**: [Dependencies to update]
|
||||
- **Bundle Size**: [Optimization opportunities]
|
||||
|
||||
### 💡 Optimization Recommendations
|
||||
|
||||
#### 🎯 Priority 1 (Critical)
|
||||
1. [Most important optimization with immediate impact]
|
||||
2. [Critical security fix needed]
|
||||
3. [Performance bottleneck to address]
|
||||
|
||||
#### 🎯 Priority 2 (Important)
|
||||
1. [Significant improvements to implement]
|
||||
2. [Important edge cases to handle]
|
||||
|
||||
#### 🎯 Priority 3 (Nice to Have)
|
||||
1. [Code quality improvements]
|
||||
2. [Minor optimizations]
|
||||
|
||||
### 🔧 Implementation Guide
|
||||
```
|
||||
[Specific code examples showing how to implement key optimizations]
|
||||
```
|
||||
|
||||
### 📊 Expected Impact
|
||||
- **Performance**: [Expected speed/efficiency gains]
|
||||
- **Security**: [Risk reduction achieved]
|
||||
- **Maintainability**: [Code quality improvements]
|
||||
- **User Experience**: [End-user benefits]
|
||||
|
||||
## Optimization Focus Areas:
|
||||
- **Performance First**: Identify and fix actual bottlenecks, not premature optimizations
|
||||
- **Security by Design**: Build secure patterns from the start
|
||||
- **Proactive Issue Prevention**: Catch problems before they reach production
|
||||
- **Maintainable Solutions**: Ensure optimizations don't sacrifice code clarity
|
||||
- **Measurable Improvements**: Focus on changes that provide tangible benefits
|
||||
26
.opencode/command/test.md
Normal file
26
.opencode/command/test.md
Normal file
@@ -0,0 +1,26 @@
|
||||
---
|
||||
description: Run the complete testing pipeline
|
||||
---
|
||||
|
||||
# Testing Pipeline
|
||||
|
||||
This command runs the complete testing pipeline for the project.
|
||||
|
||||
## Usage
|
||||
|
||||
To run the complete testing pipeline, just type:
|
||||
|
||||
1. Run pnpm type:check
|
||||
2. Run pnpm lint
|
||||
3. Run pnpm test
|
||||
4. Report any failures
|
||||
5. Fix any failures
|
||||
6. Repeat until all tests pass
|
||||
7. Report success
|
||||
|
||||
## What This Command Does
|
||||
|
||||
1. Runs `pnpm type:check` to check for type errors
|
||||
2. Runs `pnpm lint` to check for linting errors
|
||||
3. Runs `pnpm test` to run the tests
|
||||
4. Reports any failures
|
||||
347
.opencode/command/validate-repo.md
Normal file
347
.opencode/command/validate-repo.md
Normal file
@@ -0,0 +1,347 @@
|
||||
# Validate Repository
|
||||
|
||||
Comprehensive validation command that checks the entire OpenAgents Control repository for consistency between CLI, documentation, registry, and components.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
/validate-repo
|
||||
```
|
||||
|
||||
## What It Checks
|
||||
|
||||
This command performs a comprehensive validation of:
|
||||
|
||||
1. **Registry Integrity**
|
||||
- JSON syntax validation
|
||||
- Component definitions completeness
|
||||
- File path references
|
||||
- Dependency declarations
|
||||
|
||||
2. **Component Existence**
|
||||
- All agents exist at specified paths
|
||||
- All subagents exist at specified paths
|
||||
- All commands exist at specified paths
|
||||
- All tools exist at specified paths
|
||||
- All plugins exist at specified paths
|
||||
- All context files exist at specified paths
|
||||
- All config files exist at specified paths
|
||||
|
||||
3. **Profile Consistency**
|
||||
- Component counts match documentation
|
||||
- Profile descriptions are accurate
|
||||
- Dependencies are satisfied
|
||||
- No duplicate components
|
||||
|
||||
4. **Documentation Accuracy**
|
||||
- README component counts match registry
|
||||
- OpenAgent documentation references are valid
|
||||
- Context file references are correct
|
||||
- Installation guide is up to date
|
||||
|
||||
5. **Context File Structure**
|
||||
- All referenced context files exist
|
||||
- Context file organization is correct
|
||||
- No orphaned context files
|
||||
|
||||
6. **Cross-References**
|
||||
- Agent dependencies exist
|
||||
- Subagent references are valid
|
||||
- Command references are valid
|
||||
- Tool dependencies are satisfied
|
||||
|
||||
## Output
|
||||
|
||||
The command generates a detailed report showing:
|
||||
- ✅ What's correct and validated
|
||||
- ⚠️ Warnings for potential issues
|
||||
- ❌ Errors that need fixing
|
||||
- 📊 Summary statistics
|
||||
|
||||
## Instructions
|
||||
|
||||
You are a validation specialist. Your task is to comprehensively validate the OpenAgents Control repository for consistency and correctness.
|
||||
|
||||
### Step 1: Validate Registry JSON
|
||||
|
||||
1. Read and parse `registry.json`
|
||||
2. Validate JSON syntax
|
||||
3. Check schema structure:
|
||||
- `version` field exists
|
||||
- `repository` field exists
|
||||
- `categories` object exists
|
||||
- `components` object exists with all types
|
||||
- `profiles` object exists
|
||||
- `metadata` object exists
|
||||
|
||||
### Step 2: Validate Component Definitions
|
||||
|
||||
For each component type (agents, subagents, commands, tools, plugins, contexts, config):
|
||||
|
||||
1. Check required fields:
|
||||
- `id` (unique)
|
||||
- `name`
|
||||
- `type`
|
||||
- `path`
|
||||
- `description`
|
||||
- `tags` (array)
|
||||
- `dependencies` (array)
|
||||
- `category`
|
||||
|
||||
2. Verify file exists at `path`
|
||||
3. Check for duplicate IDs
|
||||
4. Validate category is in defined categories
|
||||
|
||||
### Step 3: Validate Profiles
|
||||
|
||||
For each profile (essential, developer, business, full, advanced):
|
||||
|
||||
1. Count components in profile
|
||||
2. Verify all component references exist in components section
|
||||
3. Check dependencies are satisfied
|
||||
4. Validate no duplicate components
|
||||
|
||||
### Step 4: Cross-Reference with Documentation
|
||||
|
||||
1. **navigation.md**:
|
||||
- Extract component counts from profile descriptions
|
||||
- Compare with actual registry counts
|
||||
- Check profile descriptions match registry descriptions
|
||||
|
||||
2. **docs/agents/openagent.md**:
|
||||
- Verify delegation criteria mentioned
|
||||
- Check context file references
|
||||
- Validate workflow descriptions
|
||||
|
||||
3. **docs/getting-started/installation.md**:
|
||||
- Check profile descriptions
|
||||
- Verify installation commands
|
||||
|
||||
### Step 5: Validate Context File Structure
|
||||
|
||||
1. List all files in `.opencode/context/`
|
||||
2. Check against registry context entries
|
||||
3. Identify orphaned files (exist but not in registry)
|
||||
4. Identify missing files (in registry but don't exist)
|
||||
5. Validate structure:
|
||||
- `core/standards/` files
|
||||
- `core/workflows/` files
|
||||
- `core/system/` files
|
||||
- `project/` files
|
||||
|
||||
### Step 6: Validate Dependencies
|
||||
|
||||
For each component with dependencies:
|
||||
|
||||
1. Parse dependency string (format: `type:id`)
|
||||
2. Verify referenced component exists
|
||||
3. Check for circular dependencies
|
||||
4. Validate dependency chain completeness
|
||||
|
||||
### Step 7: Generate Report
|
||||
|
||||
Create a comprehensive report with sections:
|
||||
|
||||
#### ✅ Validated Successfully
|
||||
- Registry JSON syntax
|
||||
- Component file existence
|
||||
- Profile integrity
|
||||
- Documentation accuracy
|
||||
- Context file structure
|
||||
- Dependency chains
|
||||
|
||||
#### ⚠️ Warnings
|
||||
- Orphaned files (exist but not referenced)
|
||||
- Unused components (defined but not in any profile)
|
||||
- Missing descriptions or tags
|
||||
- Outdated metadata dates
|
||||
|
||||
#### ❌ Errors
|
||||
- Missing files
|
||||
- Broken dependencies
|
||||
- Invalid JSON
|
||||
- Component count mismatches
|
||||
- Broken documentation references
|
||||
- Duplicate component IDs
|
||||
|
||||
#### 📊 Statistics
|
||||
- Total components: X
|
||||
- Total profiles: X
|
||||
- Total context files: X
|
||||
- Components per profile breakdown
|
||||
- File coverage percentage
|
||||
|
||||
### Step 8: Provide Recommendations
|
||||
|
||||
Based on findings, suggest:
|
||||
- Files to create
|
||||
- Registry entries to add/remove
|
||||
- Documentation to update
|
||||
- Dependencies to fix
|
||||
|
||||
## Example Report Format
|
||||
|
||||
```markdown
|
||||
# OpenAgents Control Repository Validation Report
|
||||
|
||||
Generated: 2025-11-19 14:30:00
|
||||
|
||||
## Summary
|
||||
|
||||
✅ 95% validation passed
|
||||
⚠️ 3 warnings found
|
||||
❌ 2 errors found
|
||||
|
||||
---
|
||||
|
||||
## ✅ Validated Successfully
|
||||
|
||||
### Registry Integrity
|
||||
✅ JSON syntax valid
|
||||
✅ All required fields present
|
||||
✅ Schema structure correct
|
||||
|
||||
### Component Existence (45/47 files found)
|
||||
✅ Agents: 3/3 files exist
|
||||
✅ Subagents: 15/15 files exist
|
||||
✅ Commands: 8/8 files exist
|
||||
✅ Tools: 2/2 files exist
|
||||
✅ Plugins: 2/2 files exist
|
||||
✅ Contexts: 13/15 files exist
|
||||
✅ Config: 2/2 files exist
|
||||
|
||||
### Profile Consistency
|
||||
✅ Essential: 9 components (matches README)
|
||||
✅ Developer: 29 components (matches README)
|
||||
✅ Business: 15 components (matches README)
|
||||
✅ Full: 35 components (matches README)
|
||||
✅ Advanced: 42 components (matches README)
|
||||
|
||||
### Documentation Accuracy
|
||||
✅ README component counts match registry
|
||||
✅ OpenAgent documentation up to date
|
||||
✅ Installation guide accurate
|
||||
|
||||
---
|
||||
|
||||
## ⚠️ Warnings (3)
|
||||
|
||||
1. **Orphaned Context File**
|
||||
- File: `.opencode/context/legacy/old-patterns.md`
|
||||
- Issue: Exists but not referenced in registry
|
||||
- Recommendation: Add to registry or remove file
|
||||
|
||||
2. **Unused Component**
|
||||
- Component: `workflow-orchestrator` (agent)
|
||||
- Issue: Defined in registry but not in any profile
|
||||
- Recommendation: Add to a profile or mark as deprecated
|
||||
|
||||
3. **Outdated Metadata**
|
||||
- Field: `metadata.lastUpdated`
|
||||
- Current: 2025-11-15
|
||||
- Recommendation: Update to current date
|
||||
|
||||
---
|
||||
|
||||
## ❌ Errors (2)
|
||||
|
||||
1. **Missing Context File**
|
||||
- Component: `context:advanced-patterns`
|
||||
- Expected path: `.opencode/context/core/advanced-patterns.md`
|
||||
- Referenced in: developer, full, advanced profiles
|
||||
- Action: Create file or remove from registry
|
||||
|
||||
2. **Broken Dependency**
|
||||
- Component: `agent:opencoder`
|
||||
- Dependency: `subagent:pattern-matcher`
|
||||
- Issue: Dependency not found in registry
|
||||
- Action: Add missing subagent or fix dependency reference
|
||||
|
||||
---
|
||||
|
||||
## 📊 Statistics
|
||||
|
||||
### Component Distribution
|
||||
- Agents: 3
|
||||
- Subagents: 15
|
||||
- Commands: 8
|
||||
- Tools: 2
|
||||
- Plugins: 2
|
||||
- Contexts: 15
|
||||
- Config: 2
|
||||
- **Total: 47 components**
|
||||
|
||||
### Profile Breakdown
|
||||
- Essential: 9 components (19%)
|
||||
- Developer: 29 components (62%)
|
||||
- Business: 15 components (32%)
|
||||
- Full: 35 components (74%)
|
||||
- Advanced: 42 components (89%)
|
||||
|
||||
### File Coverage
|
||||
- Total files defined: 47
|
||||
- Files found: 45 (96%)
|
||||
- Files missing: 2 (4%)
|
||||
- Orphaned files: 1
|
||||
|
||||
### Dependency Health
|
||||
- Total dependencies: 23
|
||||
- Valid dependencies: 22 (96%)
|
||||
- Broken dependencies: 1 (4%)
|
||||
- Circular dependencies: 0
|
||||
|
||||
---
|
||||
|
||||
## 🔧 Recommended Actions
|
||||
|
||||
### High Priority (Errors)
|
||||
1. Create missing file: `.opencode/context/core/advanced-patterns.md`
|
||||
2. Fix broken dependency in `opencoder`
|
||||
|
||||
### Medium Priority (Warnings)
|
||||
1. Remove orphaned file or add to registry
|
||||
2. Add `workflow-orchestrator` to a profile or deprecate
|
||||
3. Update metadata.lastUpdated to 2025-11-19
|
||||
|
||||
### Low Priority (Improvements)
|
||||
1. Add more tags to components for better searchability
|
||||
2. Consider adding descriptions to all context files
|
||||
3. Document component categories in README
|
||||
|
||||
---
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Review and fix all ❌ errors
|
||||
2. Address ⚠️ warnings as needed
|
||||
3. Re-run validation to confirm fixes
|
||||
4. Update documentation if needed
|
||||
|
||||
---
|
||||
|
||||
**Validation Complete** ✓
|
||||
```
|
||||
|
||||
## Implementation Notes
|
||||
|
||||
The command should:
|
||||
- Use bash/python for file system operations
|
||||
- Parse JSON with proper error handling
|
||||
- Generate markdown report
|
||||
- Be non-destructive (read-only validation)
|
||||
- Provide actionable recommendations
|
||||
- Support verbose mode for detailed output
|
||||
|
||||
## Error Handling
|
||||
|
||||
- Gracefully handle missing files
|
||||
- Continue validation even if errors found
|
||||
- Collect all issues before reporting
|
||||
- Provide clear error messages with context
|
||||
|
||||
## Performance
|
||||
|
||||
- Should complete in < 30 seconds
|
||||
- Cache file reads where possible
|
||||
- Parallel validation where safe
|
||||
- Progress indicators for long operations
|
||||
Reference in New Issue
Block a user