chore: install openagent opencode

Signed-off-by: Dmytro Stanchiev <git@dmytros.dev>
This commit is contained in:
2026-04-07 11:31:26 -04:00
parent b4c03ff25e
commit c2263602c4
204 changed files with 38010 additions and 0 deletions

View File

@@ -0,0 +1,275 @@
<!-- Context: core/error | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Error Operation
**Purpose**: Add recurring errors to knowledge base with deduplication
**Last Updated**: 2026-01-06
---
## When to Use
- Encountered same error multiple times
- Want to document solution for team
- Building error knowledge base
- Preventing repeated debugging
---
## 6-Stage Workflow
### Stage 1: Search Existing
**Action**: Search for similar/related errors
**Process**:
1. Search error message across all errors/ files
2. Find similar errors (fuzzy matching)
3. Find related errors (same category)
**Format**:
```
Searching for: "Cannot read property 'map' of undefined"
Found 1 similar error:
📄 development/errors/react-errors.md (Line 45)
## Error: Cannot read property 'X' of undefined
Covers: General undefined property access
Frequency: common
Found 2 related errors:
📄 development/errors/react-errors.md
## Error: Cannot read property 'length' of undefined
## Error: Undefined is not an object
```
---
### Stage 2: Check Duplication (APPROVAL REQUIRED)
**Action**: Present deduplication options
**Format**:
```
Options:
[A] Add as new error to react-errors.md
(Specific case: 'map' on undefined array)
[B] Update existing 'Cannot read property X' error
(Add 'map' as common example)
[C] Skip (already covered sufficiently)
Which framework/category?
[1] React (react-errors.md)
[2] JavaScript (js-errors.md)
[3] General (common-errors.md)
[4] Create new: ___
Select option + category (e.g., 'B 1'):
```
**Validation**: MUST wait for user input
---
### Stage 3: Preview (APPROVAL REQUIRED)
**Action**: Show full error entry before adding
**Format**:
```
Would update development/errors/react-errors.md:
Current (Line 45):
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Error: Cannot read property 'X' of undefined
**Symptom**:
```
TypeError: Cannot read property 'X' of undefined
```
**Cause**: Attempting to access property on undefined/null object.
**Solution**:
1. Add null check
2. Use optional chaining (?.)
3. Provide default value
**Code**:
```jsx
// ❌ Before
const value = obj.property
// ✅ After
const value = obj?.property ?? 'default'
```
**Prevention**: Always validate data exists
**Frequency**: common
**Reference**: [Link]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Proposed update:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
## Error: Cannot read property 'X' of undefined
**Symptom**:
```
TypeError: Cannot read property 'X' of undefined
TypeError: Cannot read property 'map' of undefined ← NEW
TypeError: Cannot read property 'length' of undefined ← NEW
```
**Cause**: Attempting to access property on undefined/null object.
Common with array methods (map, filter) when data hasn't loaded. ← NEW
**Solution**:
1. Add null check
2. Use optional chaining (?.)
3. Provide default value (especially for arrays) ← UPDATED
**Code**:
```jsx
// ❌ Before
const value = obj.property
const items = data.map(item => item.name) NEW
// ✅ After
const value = obj?.property ?? 'default'
const items = (data || []).map(item => item.name) NEW
```
**Prevention**: Always validate data exists. For arrays, provide empty array default. ← UPDATED
**Frequency**: common
**Reference**: [Link]
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
File size: 98 lines → 105 lines (under 150 limit ✓)
Approve? (yes/no/edit):
```
**Edit mode**: Allow modification before adding
**Validation**: MUST get approval before proceeding
---
### Stage 4: Add/Update
**Action**: Add or update error entry
**Process**:
1. Add/update error in target file
2. Follow error template format
3. Maintain file size <150 lines
4. Update "Last Updated" date
**Template Format**:
```markdown
## Error: {Name}
**Symptom**: [Error message]
**Cause**: [Why - 1-2 sentences]
**Solution**: [Steps]
**Code**: [Before/After example]
**Prevention**: [How to avoid]
**Frequency**: common/occasional/rare
**Reference**: [Link]
```
---
### Stage 5: Update Navigation
**Action**: Update README.md and add cross-references
**Process**:
1. Update README.md if new file created
2. Add cross-references to related errors
3. Link from related concepts/examples
---
### Stage 6: Report
**Action**: Show results
**Format**:
```
✅ Added error to {category}/errors/{file}.md
🔗 Cross-referenced with X related errors
📊 Updated README.md (if needed)
Changes:
- Updated existing error entry
- Added 'map' and 'length' examples
- File size: 105 lines (under 150 limit)
```
---
## Deduplication Strategy
### Similar Errors
Same root cause, different manifestations
**Update existing** to include new examples
### Related Errors
Different causes, same category
**Cross-reference** between errors
### Duplicate Errors
Exact same error already documented
**Skip** (already covered)
### New Errors
Unique error not yet documented
**Add as new** error entry
---
## Error Grouping
Group errors by framework/topic in single file:
- `react-errors.md` - All React errors
- `nextjs-errors.md` - All Next.js errors
- `auth-errors.md` - All authentication errors
**Don't create**: One file per error (too granular)
---
## Examples
### Add New Error
```bash
/context error for "hooks can only be called inside components"
```
### Add Common Error
```bash
/context error for "Cannot read property 'map' of undefined"
```
### Add Framework Error
```bash
/context error for "Hydration failed in Next.js"
```
---
## Success Criteria
- [ ] Searched for similar errors?
- [ ] Deduplication options presented?
- [ ] Preview shown?
- [ ] User approved?
- [ ] Error follows template format?
- [ ] File size <150 lines?
- [ ] Cross-references added?
- [ ] README.md updated (if new file)?
---
## Related
- standards/templates.md - Error template format
- guides/workflows.md - Interactive examples

View File

@@ -0,0 +1,202 @@
<!-- Context: core/extract | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Extract Operation
**Purpose**: Extract context from docs, code, or URLs into organized context files
**Last Updated**: 2026-01-06
---
## When to Use
- Extracting from documentation (React docs, API docs, etc.)
- Extracting from codebase (patterns, conventions)
- Extracting from URLs (blog posts, guides)
- Creating initial context for new topics
---
## 7-Stage Workflow
### Stage 1: Read Source
```
/context extract from https://react.dev/hooks
Agent: "Reading source (8,500 lines)...
Analyzing content for extractable items..."
```
**Action**: Read and analyze source material
---
### Stage 2: Analyze & Categorize
**Action**: Extract and categorize content by function
**Categorization**:
- Design decisions → `concepts/`
- Working code → `examples/`
- Step-by-step workflows → `guides/`
- Reference data (commands, paths) → `lookup/`
- Errors/gotchas → `errors/`
**Output**: List of extractable items with previews
---
### Stage 3: Select Category (APPROVAL REQUIRED)
**Action**: User chooses target category and items
**Format**:
```
Found 12 extractable items from {source}:
Concepts (8):
✓ [A] useState - State management hook
✓ [B] useEffect - Side effects hook
... (6 more)
Errors (4):
✓ [I] Hooks called conditionally
✓ [J] Hooks in loops
... (2 more)
Which category?
[1] development/
[2] core/
[3] Create new category: ___
Select items (A B I or 'all') + category (1/2/3):
```
**Validation**: MUST wait for user input before proceeding
---
### Stage 4: Preview (APPROVAL REQUIRED)
**Action**: Show what will be created, check for conflicts
**Format**:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Extraction Plan: development/
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
CREATE (new files):
concepts/use-state.md (45 lines)
concepts/use-effect.md (52 lines)
concepts/use-context.md (38 lines)
... (6 more)
guides/custom-hooks.md (87 lines)
guides/debugging-hooks.md (65 lines)
ADD TO (existing files):
errors/react-hooks-errors.md (98 → 124 lines)
+ 4 new error entries
⚠️ CONFLICT (file already exists):
concepts/use-memo.md already exists (42 lines)
Options:
[A] Skip — keep existing file
[B] Overwrite — replace with extracted version
[C] Merge — add new content to existing file (42 → 58 lines)
Choose [A/B/C]: _
NAVIGATION UPDATE:
development/navigation.md
+ 9 new entries in Concepts table
+ 2 new entries in Guides table
+ 1 updated entry in Errors table
Total: 12 files, ~650 lines
Preview content? (type filename, 'all' for batch, or 'skip')
Approve? [y/n/edit]: _
```
**If user types 'all'**: Show first 10 lines of each file in sequence
**If user types filename**: Show full content of that file
**If user types 'skip'**: Proceed to approval
**Validation**: MUST get approval before proceeding
---
### Stage 5: Create
**Action**: Create files in function folders
**Process**:
1. Apply MVI format (1-3 sentences, 3-5 key points, minimal example)
2. Create files in correct function folders
3. Ensure all files <200 lines
4. Add cross-references
**Enforcement**: `@critical_rules.mvi_strict` + `@critical_rules.function_structure`
---
### Stage 6: Update Navigation (preview included in Stage 4)
**Action**: Update navigation.md and add cross-references
**Process**:
1. Update category navigation.md with new files (as previewed in Stage 4)
2. Add priority levels (critical/high/medium/low)
3. Add cross-references between related files
4. Update "Last Updated" dates
---
### Stage 7: Report
**Action**: Show comprehensive results
**Format**:
```
✅ Extracted X items into {category}
📄 Created Y files
📊 Updated {category}/README.md
Files created:
- {category}/concepts/ (N files)
- {category}/examples/ (N files)
- {category}/errors/ (N files)
```
---
## Examples
### Extract from URL
```bash
/context extract from https://react.dev/hooks
```
### Extract from Local Docs
```bash
/context extract from docs/api.md
/context extract from docs/architecture/
```
### Extract from Code
```bash
/context extract from src/utils/
```
---
## Success Criteria
- [ ] All files <200 lines?
- [ ] MVI format applied (1-3 sentences, 3-5 points, example, reference)?
- [ ] Files in correct function folders?
- [ ] README.md updated?
- [ ] Cross-references added?
- [ ] User approved before creation?
---
## Related
- standards/mvi.md - What to extract
- guides/compact.md - How to minimize
- guides/workflows.md - Interactive examples

View File

@@ -0,0 +1,342 @@
<!-- Context: core/harvest | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Context Harvest Operation
**Purpose**: Extract knowledge from AI summaries → permanent context, then clean workspace
**Last Updated**: 2026-01-06
---
## Core Problem
AI agents create summary files (OVERVIEW.md, SESSION-*.md, SUMMARY.md) that contain valuable knowledge but clutter the workspace. These files "plague" the codebase.
**Solution**: Harvest the knowledge → permanent context, then delete the summaries.
---
## Auto-Detection Patterns
<rule id="summary_patterns" enforcement="strict">
Harvest automatically detects these patterns:
Filename patterns:
- *OVERVIEW.md
- *SUMMARY.md
- SESSION-*.md
- CONTEXT-*.md
- *NOTES.md
Location patterns:
- Files in .tmp/ directory
- Files with "Summary", "Overview", "Session" in title
- Files >2KB in root directory (likely summaries)
</rule>
---
## 6-Stage Workflow
<workflow id="harvest" enforce="@critical_rules">
### Stage 1: Scan
**Action**: Find all summary files in workspace
**Process**:
1. Search for auto-detection patterns
2. Check .tmp/ directory
3. List files with sizes
4. Sort by modification date (newest first)
**Output**: List of candidate files
**Example**:
```
Found 3 summary documents:
1. CONTEXT-SYSTEM-OVERVIEW.md (4.2 KB, modified 1 hour ago)
2. SESSION-auth-work.md (1.8 KB, modified today)
3. .tmp/IMPLEMENTATION-NOTES.md (800 bytes, modified today)
```
---
### Stage 2: Analyze
**Action**: Categorize content by function
**Mapping Rules**:
| Content Type | Target Folder | How to Identify |
|--------------|---------------|-----------------|
| Design decisions | `concepts/` | "We decided to...", "Architecture", "Pattern" |
| Solutions/patterns | `examples/` | Code snippets, "Here's how we..." |
| Workflows | `guides/` | Numbered steps, "How to...", "Setup" |
| Errors encountered | `errors/` | Error messages, "Fixed issue", "Gotcha" |
| Reference data | `lookup/` | Tables, lists, paths, commands |
**Process**:
1. Read each file
2. Identify valuable sections (skip planning/conversation)
3. Categorize by function
4. Determine target file path
5. Generate preview (first 60 chars)
**Output**: Categorized items with letter IDs
---
### Stage 3: Approve (CRITICAL)
**Action**: Present approval UI with letter-based selection
<rule id="approval_gate" enforcement="strict">
ALWAYS show approval UI before extracting/deleting.
NEVER auto-harvest without user confirmation.
</rule>
**Format**:
```
### CONTEXT-SYSTEM-OVERVIEW.md (4.2 KB)
✓ [A] Design: Function-based context organization
→ Would add to: core/concepts/context-organization.md
Preview: "Organize by function (concepts/, examples/...)..."
✓ [B] Pattern: Minimal Viable Information
→ Would add to: core/concepts/mvi-principle.md
Preview: "Extract core only (1-3 sentences), 3-5 key points..."
✓ [C] Workflow: Harvesting summary documents
→ Would create: core/guides/harvesting.md
Preview: "Scan for summaries → Extract → Approve → Delete"
✗ [D] Skip: Planning discussion notes (temporary knowledge)
---
### SESSION-auth-work.md (1.8 KB)
✓ [E] Error: JWT token expiration not handled
→ Would add to: development/errors/auth-errors.md
Preview: "Symptom: 401 after 1 hour. Cause: No refresh flow..."
✓ [F] Example: JWT refresh token implementation
→ Would create: development/examples/jwt-refresh.md
Preview: "Store refresh token → Check expiry → Request new..."
---
### .tmp/IMPLEMENTATION-NOTES.md (800 bytes)
✗ [G] Skip: Duplicate info (already in development/concepts/api-design.md)
---
**Quick options**:
- Type 'A B C E F' - Approve specific items
- Type 'all' - Approve all ✓ items (A B C E F)
- Type 'none' - Skip harvesting, delete files anyway
- Type 'cancel' - Keep files, don't harvest
```
**Validation**:
- MUST wait for user input
- MUST not proceed without approval
- If user types 'cancel', stop immediately
**Output**: List of approved items
---
### Stage 4: Extract
**Action**: Extract and minimize approved items
<rule id="extraction" enforce="@mvi_principle">
Apply MVI to all extracted content:
- Core concept: 1-3 sentences
- Key points: 3-5 bullets
- Minimal example: <10 lines
- Reference link: to original source
- Files: <200 lines each
</rule>
**Process**:
1. For each approved item:
- Extract core content
- Apply MVI minimization (see compact.md)
- Generate preview of final content
2. Show extraction preview (APPROVAL REQUIRED):
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Extraction Preview
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
[A] → core/concepts/context-organization.md (CREATE, 45 lines)
┌─────────────────────────────────────────────────────────┐
│ # Concept: Context Organization │
│ │
│ **Purpose**: Function-based knowledge organization │
│ │
│ ## Core Concept │
│ Organize context by function: concepts/, examples/... │
│ ... │
└─────────────────────────────────────────────────────────┘
[E] → development/errors/auth-errors.md (ADD to existing, 98 → 112 lines)
┌─────────────────────────────────────────────────────────┐
│ + ## Error: JWT Token Expiration Not Handled │
│ + │
│ + **Symptom**: 401 after 1 hour │
│ + **Cause**: No refresh token flow │
│ + ... │
└─────────────────────────────────────────────────────────┘
... ({remaining_count} more items)
Show all? [y/n] | Approve extraction? [y/n/edit]: _
```
3. On approval:
- Write files to disk
- Add cross-references
- Update navigation.md maps
**Output**: List of created/updated files
---
### Stage 5: Cleanup (APPROVAL REQUIRED)
**Action**: Archive or delete source summary files
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Cleanup: Source Files
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Successfully harvested from:
CONTEXT-SYSTEM-OVERVIEW.md (4.2 KB)
SESSION-auth-work.md (1.8 KB)
Skipped (no valuable content):
.tmp/IMPLEMENTATION-NOTES.md (800 bytes)
How should we handle these source files?
1. Archive (safe) — move to .tmp/archive/harvested/{date}/
→ Can restore later if needed
2. Delete — permanently remove harvested files
→ Frees disk space, no undo
3. Keep — leave source files in place
→ No cleanup, files remain where they are
Choose [1/2/3] (default: 1): _
```
<rule id="cleanup_safety" enforcement="strict">
ONLY cleanup files that had content successfully harvested.
If extraction failed, keep the original file.
</rule>
**Output**: Cleanup report
---
### Stage 6: Report
**Action**: Show comprehensive results summary
**Format**:
```
✅ Harvested 5 items into permanent context:
- Added to core/concepts/context-organization.md
- Added to core/concepts/mvi-principle.md
- Created core/guides/harvesting.md
- Added to development/errors/auth-errors.md
- Created development/examples/jwt-refresh.md
🗑️ Cleaned up workspace:
- Archived: CONTEXT-SYSTEM-OVERVIEW.md → .tmp/archive/harvested/2026-01-06/
- Archived: SESSION-auth-work.md → .tmp/archive/harvested/2026-01-06/
- Deleted: .tmp/IMPLEMENTATION-NOTES.md (no valuable content)
📊 Updated navigation maps:
- .opencode/context/core/navigation.md
- .opencode/context/development/navigation.md
💾 Disk space freed: 6.8 KB
```
</workflow>
---
## Usage Examples
### Scan entire workspace
```bash
/context harvest
```
### Scan specific directory
```bash
/context harvest .tmp/
/context harvest docs/sessions/
```
### Harvest specific file
```bash
/context harvest OVERVIEW.md
/context harvest SESSION-2026-01-06.md
```
---
## Smart Content Detection
### ✅ Extract (Valuable Knowledge)
- Design decisions ("We chose X because...")
- Patterns that worked ("This pattern solved...")
- Errors encountered + solutions
- API changes ("Updated from v1 to v2...")
- Performance findings ("Optimization reduced...")
- Core concepts explained
### ❌ Skip (Temporary/Noise)
- Planning discussion ("Should we...?", "Maybe try...")
- Conversational notes ("I think...", "We talked about...")
- Duplicate info (already in context)
- TODO lists (move to task system instead)
- Timestamps and session metadata
---
## Safety Features
1. **Approval gate** - Never auto-delete without confirmation
2. **Archive by default** - Move to .tmp/archive/, not permanent delete
3. **Validation** - Check file sizes, structure before committing
4. **Rollback** - Can restore from archive if needed
5. **Dry run** - Show what would happen before doing it
---
## Success Criteria
After harvest operation:
- [ ] Valuable knowledge extracted to permanent context?
- [ ] All extracted files <200 lines?
- [ ] Files in correct function folders?
- [ ] navigation.md navigation updated?
- [ ] Summary files archived/deleted?
- [ ] Workspace cleaner than before?
- [ ] No knowledge lost?
---
## Related
- compact.md - How to minimize extracted content
- mvi-principle.md - What to extract
- structure.md - Where files go
- creation.md - File creation rules

View File

@@ -0,0 +1,223 @@
<!-- Context: core/migrate | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Context Migrate Operation
**Purpose**: Copy context files from global (`~/.config/opencode/context/`) to local (`.opencode/context/`) so they're project-specific and git-committed.
**Last Updated**: 2026-02-06
---
## Core Problem
Users who installed OAC globally have project-intelligence files at `~/.config/opencode/context/project-intelligence/`. These files are project-specific patterns but aren't committed to git or shared with the team.
**Solution**: Migrate project-intelligence from global → local, so patterns are version-controlled and team-shared.
---
## 4-Stage Workflow
<workflow id="migrate" enforce="@critical_rules">
### Stage 1: Detect Sources
Scan for context files in the global config directory:
```
Scanning global context...
Global location: ~/.config/opencode/context/
Found:
project-intelligence/
technical-domain.md (1.2 KB, Version: 1.3)
navigation.md (800 bytes, Version: 1.0)
business-domain.md (1.5 KB, Version: 1.1)
Local location: .opencode/context/
Status: No local project-intelligence/ found
```
**If no global context found:**
```
No global context found at ~/.config/opencode/context/
Nothing to migrate. Use /add-context to create project intelligence.
```
→ Exit
**If no global project-intelligence found (but other global context exists):**
```
Global context found at ~/.config/opencode/context/ but no project-intelligence/ directory.
Only project-intelligence files are migrated (project-specific patterns).
Core standards stay in global (they're universal, not project-specific).
Nothing to migrate. Use /add-context to create project intelligence.
```
→ Exit
---
### Stage 2: Check for Conflicts
If local `.opencode/context/project-intelligence/` already exists:
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Conflict: Local project-intelligence already exists
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Global files: Local files:
technical-domain.md technical-domain.md
Version: 1.3, Updated: 2026-01-15 Version: 1.0, Updated: 2026-02-01
navigation.md navigation.md
Version: 1.0, Updated: 2026-01-10 Version: 1.0, Updated: 2026-02-01
business-domain.md (not present locally)
Version: 1.1, Updated: 2026-01-12
Options:
1. Skip existing — only copy files that don't exist locally
→ Will copy: business-domain.md
→ Will skip: technical-domain.md, navigation.md (local kept)
2. Overwrite all — replace local with global versions
→ Will overwrite: technical-domain.md, navigation.md
→ Will copy: business-domain.md
→ Local backup created first
3. Cancel
Choose [1/2/3]: _
```
**If user chooses 2 (Overwrite), show content diff first:**
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Diff: technical-domain.md
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Local (current): Global (incoming):
Version: 1.0 Version: 1.3
Tech Stack: Next.js 14 Tech Stack: Next.js 15 ← different
API: basic validation API: Zod validation ← different
Component: same Component: same
Naming: same Naming: same
Show full diff? [y/n]: _
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Backup local files to .tmp/backup/migrate-{timestamp}/ before overwriting?
[y/n] (default: y): _
```
If no conflicts → proceed directly to Stage 3.
---
### Stage 3: Approval & Copy
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Migration Plan
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Will copy from: ~/.config/opencode/context/project-intelligence/
Will copy to: .opencode/context/project-intelligence/
Files to copy:
✓ technical-domain.md (1.2 KB)
✓ navigation.md (800 bytes)
✓ business-domain.md (1.5 KB)
After migration:
→ Local files committed to git = team gets your patterns
→ Agents load local (overrides global)
→ Global files remain as fallback for other projects
Proceed? [y/n]: _
```
**Actions on approval:**
1. Create `.opencode/context/project-intelligence/` if it doesn't exist
2. Copy each file from global → local
3. Validate copied files (frontmatter, MVI compliance)
---
### Stage 4: Cleanup & Confirmation
```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Migration Complete
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Copied 3 files to .opencode/context/project-intelligence/
✓ technical-domain.md
✓ navigation.md
✓ business-domain.md
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Clean up global project-intelligence?
The global files are no longer needed for THIS project (local takes priority).
Keeping them means they still apply as fallback to other projects.
1. Keep global files (safe default)
2. Remove global project-intelligence/ (only affects this user)
Choose [1/2] (default: 1): _
```
**If user chooses 2 (Remove):**
- Delete `~/.config/opencode/context/project-intelligence/` only
- Do NOT touch `~/.config/opencode/context/core/` or any other global context
</workflow>
---
## What Gets Migrated
| Migrated (project-specific) | NOT Migrated (universal) |
|---|---|
| `project-intelligence/` | `core/standards/` |
| `project-intelligence/technical-domain.md` | `core/context-system/` |
| `project-intelligence/business-domain.md` | `core/workflows/` |
| `project-intelligence/navigation.md` | `core/guides/` |
| `project-intelligence/decisions-log.md` | Any other `core/` files |
| `project-intelligence/living-notes.md` | |
**Rationale**: Project intelligence is project-specific (YOUR tech stack, YOUR patterns). Core standards are universal (code quality, documentation standards) and should stay global.
---
## Error Handling
**Permission denied:**
```
Error: Cannot write to .opencode/context/project-intelligence/
Check directory permissions and try again.
```
**Global path not found:**
```
No global OpenCode config found at ~/.config/opencode/
If you installed to a custom location, set OPENCODE_INSTALL_DIR:
export OPENCODE_INSTALL_DIR=/your/custom/path
/context migrate
```
---
## Related
- `/add-context` — Create new project intelligence (interactive wizard)
- `/context harvest` — Extract knowledge from summaries
- Context path resolution: `.opencode/context/core/system/context-paths.md`

View File

@@ -0,0 +1,224 @@
<!-- Context: core/organize | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Organize Operation
**Purpose**: Restructure flat context files into function-based folder structure
**Last Updated**: 2026-01-06
---
## When to Use
- Migrating from flat structure to function-based
- Cleaning up disorganized context directories
- Splitting ambiguous files into proper categories
- Resolving duplicate/conflicting files
---
## 8-Stage Workflow
### Stage 1: Scan
**Action**: Scan category for all files and detect structure
**Output**: List of files with current structure type (flat vs organized)
---
### Stage 2: Categorize
**Action**: Categorize each file by function
**Categorization Rules**:
- Explains concept? → `concepts/`
- Shows working code? → `examples/`
- Step-by-step instructions? → `guides/`
- Reference data (tables, commands)? → `lookup/`
- Errors/issues? → `errors/`
**Output**: Categorization plan with flagged ambiguous files
---
### Stage 3: Resolve Conflicts (APPROVAL REQUIRED)
**Action**: Present categorization plan and handle conflicts
**Format**:
```
Organizing {category}/ (23 files, flat structure)
Clear categorization (18 files):
concepts/ (8):
✓ authentication.md → concepts/authentication.md
examples/ (5):
✓ jwt-example.md → examples/jwt-example.md
Ambiguous files (5 - need your input):
[?] api-design.md (contains concepts AND steps)
→ [A] Split: concepts/api-design.md + guides/api-design-guide.md
→ [B] Keep as concepts/api-design.md
→ [C] Keep as guides/api-design.md
Conflicts (2):
[!] authentication.md → concepts/auth.md
Target already exists (120 lines)
→ [J] Merge into existing
→ [K] Rename to concepts/authentication-v2.md
→ [L] Skip (keep flat)
Select resolutions (A J or 'auto'):
```
**Validation**: MUST wait for user input
---
### Stage 4: Preview (APPROVAL REQUIRED)
**Action**: Show preview of all changes
**Format**:
```
Preview changes:
CREATE directories:
{category}/concepts/
{category}/examples/
{category}/guides/
{category}/lookup/
{category}/errors/
MOVE files (18):
authentication.md → concepts/authentication.md
... (17 more)
SPLIT files (3):
api-design.md → concepts/api-design.md + guides/api-design-guide.md
MERGE files (2):
authentication.md → concepts/auth.md (merge content)
UPDATE:
{category}/README.md
Fix 47 internal references
Dry-run? (yes/no/show-diff):
```
**Dry-run**: Simulates changes without executing
**Validation**: MUST get approval before proceeding
---
### Stage 5: Backup
**Action**: Create backup before making changes
**Location**: `.tmp/backup/organize-{category}-{timestamp}/`
**Purpose**: Enable rollback if needed
---
### Stage 6: Execute
**Action**: Perform the reorganization
**Process**:
1. Create function folders
2. Move files to correct locations
3. Split ambiguous files if requested
4. Merge conflicts if requested
---
### Stage 7: Update
**Action**: Update navigation and fix references
**Process**:
1. Update README.md with navigation tables
2. Fix all internal references to moved files
3. Validate all links work
4. Update "Last Updated" dates
---
### Stage 8: Report
**Action**: Show comprehensive results
**Format**:
```
✅ Organized X files into function folders
📁 Created Y new folders
🔀 Split Z ambiguous files
🔗 Fixed N references
💾 Backup: .tmp/backup/organize-{category}-{timestamp}/
Rollback available if needed.
```
---
## Conflict Resolution
### Ambiguous Files
File fits multiple categories (e.g., has concepts AND steps)
**Options**:
- Split into multiple files (recommended)
- Keep in primary category
- User decides which is primary
### Duplicate Targets
Target file already exists
**Options**:
- Merge content into existing file
- Rename to avoid conflict (e.g., -v2)
- Skip (keep in flat structure)
### Auto-Resolution
Agent suggests best option based on:
- File size
- Content analysis
- Existing structure
---
## Examples
### Organize Flat Directory
```bash
/context organize development/
```
### Dry-Run First
```bash
/context organize development/ --dry-run
```
### Organize Multiple
```bash
/context organize development/
/context organize core/
```
---
## Success Criteria
- [ ] All files in function folders (not flat)?
- [ ] Ambiguous files resolved?
- [ ] Conflicts handled?
- [ ] README.md created/updated?
- [ ] All references fixed?
- [ ] Backup created?
- [ ] User approved changes?
---
## Related
- standards/structure.md - Folder organization rules
- guides/workflows.md - Interactive examples

View File

@@ -0,0 +1,237 @@
<!-- Context: core/update | Priority: medium | Version: 1.0 | Updated: 2026-02-15 -->
# Update Operation
**Purpose**: Update context when APIs, frameworks, or contracts change
**Last Updated**: 2026-01-06
---
## When to Use
- Framework version updates (Next.js 14 → 15)
- API changes (breaking changes, deprecations)
- New features added to existing topics
- Migration guides needed
---
## 8-Stage Workflow
### Stage 1: Identify Changes (APPROVAL REQUIRED)
**Action**: User describes what changed
**Format**:
```
What changed in {topic}?
[A] API changes
[B] Deprecations
[C] New features
[D] Breaking changes
[E] Other (describe)
Select all that apply (A B C D or describe):
```
**Follow-up**: Get specific details for each selected type
**Validation**: MUST get user input before proceeding
---
### Stage 2: Find Affected Files
**Action**: Search for files referencing the topic
**Process**:
1. Grep for topic references across all context
2. Count references per file
3. Show impact analysis
**Format**:
```
Found 5 files referencing {topic}:
📄 concepts/routing.md (3 references, 145 lines)
📄 examples/app-router-example.md (7 references, 78 lines)
📄 guides/setting-up-nextjs.md (2 references, 132 lines)
📄 errors/nextjs-errors.md (1 reference, 98 lines)
📄 lookup/nextjs-commands.md (4 references, 54 lines)
Total impact: 17 references across 5 files
```
---
### Stage 3: Preview Changes (APPROVAL REQUIRED)
**Action**: Show line-by-line diff for each file
**Format**:
```
Proposed updates:
━━━ concepts/routing.md ━━━
Line 15:
- App router is optional (use pages/ or app/)
+ App router is now default in Next.js 15 (pages/ still supported)
Line 42:
+ ## Metadata API (New in v15)
+ Next.js 15 introduces new metadata API...
━━━ examples/app-router-example.md ━━━
Line 8:
- // Optional: use app router
+ // Default in Next.js 15+
Preview next file? (yes/no/show-all)
Approve changes? (yes/no/edit):
```
**Edit mode**: Line-by-line approval for each change
**Validation**: MUST get approval before proceeding
---
### Stage 4: Backup
**Action**: Create backup before updating
**Location**: `.tmp/backup/update-{topic}-{timestamp}/`
**Purpose**: Enable rollback if updates cause issues
---
### Stage 5: Update Files
**Action**: Apply approved changes
**Process**:
1. Update concepts, examples, guides, lookups
2. Maintain MVI format (<200 lines)
3. Update "Last Updated" dates
4. Preserve file structure
**Enforcement**: `@critical_rules.mvi_strict`
---
### Stage 6: Add Migration Notes
**Action**: Add migration guide to errors/
**Format**:
```markdown
## Migration: {Old Version} → {New Version}
**Breaking Changes**:
- Change 1
- Change 2
**Migration Steps**:
1. Step 1
2. Step 2
**Reference**: [Link to changelog]
```
**Location**: `{category}/errors/{topic}-errors.md`
---
### Stage 7: Validate
**Action**: Check all references and links
**Checks**:
- All internal references still work
- No broken links
- All files still <200 lines
- MVI format maintained
---
### Stage 8: Report
**Action**: Show comprehensive results
**Format**:
```
✅ Updated X files
📝 Modified Y references
🔄 Added migration notes to errors/
💾 Backup: .tmp/backup/update-{topic}-{timestamp}/
Summary of changes:
- concepts/routing.md: 2 updates (145 → 162 lines)
- examples/app-router-example.md: 4 updates (78 → 89 lines)
- guides/setting-up-nextjs.md: 1 update (132 → 133 lines)
All files still under 200 line limit ✓
Rollback available if needed.
```
---
## Change Types
### API Changes
- Method signatures changed
- Parameters added/removed
- Return types changed
### Deprecations
- Features marked deprecated
- Replacement APIs available
- Timeline for removal
### New Features
- New capabilities added
- New APIs introduced
- New patterns available
### Breaking Changes
- Incompatible changes
- Migration required
- Old code won't work
---
## Examples
### Framework Update
```bash
/context update for Next.js 15
/context update for React 19
```
### API Changes
```bash
/context update for Stripe API v2024
/context update for OpenAI API breaking changes
```
### Library Update
```bash
/context update for Tailwind CSS v4
```
---
## Success Criteria
- [ ] User described changes?
- [ ] All affected files found?
- [ ] Diff preview shown?
- [ ] User approved changes?
- [ ] Backup created?
- [ ] Migration notes added?
- [ ] All references validated?
- [ ] All files still <200 lines?
---
## Related
- guides/workflows.md - Interactive diff examples
- standards/mvi.md - Maintain MVI format
- operations/error.md - Adding migration notes