Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 30 additions & 64 deletions skills/context-optimize/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,51 @@
---
description: Context Optimization - Orchestrate RPI workflow TODO generation with interactive scoping
name: context-optimize
description: "Audit .claude/ directory structure, detect redundant files, and generate an RPI workflow TODO plan for context engineering improvements. Use when optimizing AI context files, cleaning up stale documentation, or planning context system enhancements."
---

# Context Engineering: Optimization Orchestrator
# Context Optimization Orchestrator

When invoked, orchestrate context engineering optimization with interactive scoping:
Audits the `.claude/` context engineering system and generates a prioritized TODO plan spanning research, plan, and implement phases.

## Process
## Workflow

1. **Interactive Scoping (if no --auto flag)**
- Ask up to 4 multiple choice questions to define scope
- Questions cover: optimization focus, codebase areas, enhancement types, priority order
- Skip questions if --scope or --auto flag provided
1. **Scope the optimization** β€” ask up to 4 multiple-choice questions (skip with `--auto` or `--scope`):
- Optimization focus (full system, docs, cleanup, or enhancements)
- Codebase coverage area (core logic, API, database, or all)
- Enhancement preference (agents, commands, docs, or cross-refs)
- TODO priority order (quick wins, high impact, grouped, or dependency-first)

2. **Context System Audit**
- Analyze `.claude/` directory structure
2. **Audit the context system:**
- Verify `.claude/` directory structure and index completeness
- Check workflow file coverage and accuracy
- Verify index file completeness
- Identify orphaned or outdated files
- Detect orphaned, duplicate, or outdated files
- Assess agent and command coverage gaps

3. **Generate RPI TODO List**
- Create actionable TODO with research, plan, implement phases
- Save to `.claude/plans/active/context-optimization_plan.md`
- Include specific commands for each task
3. **Generate the TODO plan** β€” save actionable items to `.claude/plans/active/context-optimization_plan.md` with specific commands per task.

4. **Redundant File Detection**
- Find files not referenced by any index
- Identify duplicate or overlapping content
- Flag outdated files with stale line references
- Report empty placeholder files
4. **Recommend enhancements** β€” suggest new agents, workflow commands, or documentation based on codebase patterns.

5. **Enhancement Recommendations**
- Suggest new specialized agents based on codebase patterns
- Recommend workflow commands for common tasks
- Identify undocumented workflows needing documentation

## Scoping Questions (Max 4)

**Q1: Optimization Focus**
- A) Functionalize the entire context engineering system
- B) Update outdated documentation and line references
- C) Identify and remove redundant context files
- D) Discover enhancement opportunities (new agents/commands)

**Q2: Codebase Coverage**
- A) Core business logic
- B) API/External integrations
- C) Database/Data layer
- D) All areas equally

**Q3: Enhancement Preferences**
- A) New specialized agents for specific domains
- B) New workflow commands for common tasks
- C) Improved documentation structure
- D) Better cross-referencing and navigation

**Q4: TODO Priority Order**
- A) Quick wins first (< 30 min each)
- B) High impact first (regardless of effort)
- C) By workflow area (grouped logically)
- D) By dependency order (foundational first)
## Arguments

## Context Budget
- Target: 20% of 200k tokens (40k)
- Output: TODO checklist + recommendations
| Flag | Effect |
|------|--------|
| `--auto` | Use intelligent defaults, skip scoping questions |
| `--scope documentation` | Focus on docs only |
| `--scope agents` | Focus on agent coverage gaps |
| `--scope workflows` | Focus on workflow coverage |
| `--scope cleanup` | Focus on redundant file removal |

## Output
- TODO checklist saved to `.claude/plans/active/context-optimization_plan.md`
- Audit findings in `.claude/research/active/context-audit_research.md`

## Arguments
- `$ARGUMENTS` can include:
- `--auto` - Use intelligent defaults, skip questions
- `--scope documentation` - Focus on docs only
- `--scope agents` - Focus on agent gaps
- `--scope workflows` - Focus on workflow coverage
- `--scope cleanup` - Focus on redundant file removal
| Artifact | Path |
|----------|------|
| TODO checklist | `.claude/plans/active/context-optimization_plan.md` |
| Audit findings | `.claude/research/active/context-audit_research.md` |

## Next Steps
After completion, execute the generated TODO list:

Execute the generated TODO list in RPI order:

1. `/rpi-research [first-research-task]`
2. `/rpi-plan [first-plan-task]`
3. `/rpi-implement [first-impl-task]`
Expand Down
163 changes: 41 additions & 122 deletions skills/implement/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,150 +1,69 @@
---
description: RPI Implement Phase - Execute chunk-based todolists with atomic changes and continuous testing
name: implement
description: "Execute an approved RPI implementation plan by processing chunk-based todolists with atomic changes, per-todo testing, and automatic context resets. Use when implementing a planned feature after the plan phase is complete and approved."
---

# Context Engineering: Implement Phase (Enhanced)
# RPI Implement Phase

When invoked, execute the approved implementation plan chunk by chunk:

## Key Innovation: Inter-Phase Awareness

This implement phase **KNOWS**:
- RPI-Plan structured chunks for atomic implementation
- Each CHUNK-Pn contains a complete, ordered todolist
- Chunk dependencies dictate execution order
- Marking chunks complete updates both plan AND research documents
- Context reset is needed after every 3 chunks or 35% utilization
Executes an approved chunk-based implementation plan from `.claude/plans/active/[feature]_plan.md`, processing each chunk's todolist atomically with continuous testing.

## Prerequisites
- Approved plan at `.claude/plans/active/[feature]_plan.md`
- Plan contains chunk manifest with chunk-todolists

- Approved plan at `.claude/plans/active/[feature]_plan.md` with chunk manifest
- If not found, run `/context-eng:plan $ARGUMENTS` first

## Golden Rules
## Core Rules

```
ONE CHUNK β†’ COMPLETE TODOLIST β†’ MARK DONE β†’ NEXT CHUNK
ONE TODO β†’ ONE CHANGE β†’ ONE TEST β†’ ONE COMMIT
```
- **One chunk at a time** β€” complete its full todolist before moving on
- **One todo = one change + one test + one commit** β€” keep changes atomic
- **Context reset** every 3 chunks or at 35% utilization

## Chunk-Based Implementation Loop
## Workflow

```
FOR each CHUNK-Pn in dependency_order:
IF dependencies_complete:
1. Load CHUNK-Pn todolist

FOR each TODO in todolist:
a. Make atomic change
b. Run todo-specific test
c. If PASS: commit, mark TODO βœ…
d. If FAIL: STOP, investigate, fix
END TODO LOOP

2. Update chunk documentation
3. Mark CHUNK-Pn as IMPLEMENTED
4. Update research CHUNK-Rn to IMPLEMENTED

IF chunks_processed % 3 == 0 OR context > 35%:
Context reset (save progress, reload plan)
END IF

5. Proceed to next ready chunk
END IF
END CHUNK LOOP
```
1. **Load the plan** β€” read the plan document, extract chunk manifest and dependency graph, verify APPROVED status.

## Process

1. **Load Plan Document**
- Read `.claude/plans/active/[feature]_plan.md`
- Extract chunk manifest and dependency graph
- Verify plan status is APPROVED

2. **Determine Execution Order**
Based on chunk dependency graph:
- Independent chunks first (parallel capable)
- Dependent chunks in order
- Final chunks (e.g., test additions)

3. **For Each Chunk (in dependency order):**

a. **Check dependencies complete**

b. **Execute each todo atomically:**
- Make single change
- Run specified test
- If pass: commit with message
- If fail: STOP, investigate, fix

c. **After all todos complete:**
- Mark CHUNK-Pn as IMPLEMENTED
- Update CHUNK-Rn in research to IMPLEMENTED
- Commit chunk documentation updates

d. **Context management:**
- After every 3 chunks: reload plan
- If >35% utilization: save, compact, continue

4. **Run Full Test Suite**
After all chunks complete

5. **Documentation Updates (MANDATORY)**
- Check `CODE_TO_WORKFLOW_MAP.md` for affected workflows
- Update workflow files with new line numbers
- Update function signatures if changed

6. **Context Reset (Every 3 Chunks)**
- Update chunk progress in plan
- Re-read plan document
- Verify scope alignment
- Compact if >35% utilization

7. **Finalize**
- Move plan to `.claude/plans/completed/`
- Move research to `.claude/research/completed/`
- Run `/context-eng:validate` to verify

## Chunk Status Updates

### Update Plan Document
```markdown
| Chunk | Status | Todos Done | Commit | Research Updated |
|-------|--------|------------|--------|------------------|
| P1 | βœ… IMPLEMENTED | 4/4 | abc123 | βœ… R1 |
| P2 | ▢️ IMPLEMENTING | 2/5 | - | - |
```
2. **Determine execution order** β€” independent chunks first (parallelizable), then dependent chunks in graph order.

### Update Research Document
Mark each CHUNK-Rn status:
- FOUND β†’ COMPLETE β†’ PLANNED β†’ **IMPLEMENTED**
3. **For each chunk (in dependency order):**
- Verify dependencies are complete
- Execute each todo atomically: make change, run test, commit on pass, stop on fail
- Mark CHUNK-Pn as IMPLEMENTED and update research CHUNK-Rn status
- Reset context after every 3 chunks or if >35% utilization

4. **Run full test suite** after all chunks complete.

5. **Update documentation** β€” check `CODE_TO_WORKFLOW_MAP.md`, update line numbers and function signatures.

6. **Finalize** β€” move plan to `.claude/plans/completed/`, research to `.claude/research/completed/`, run `/context-eng:validate`.

## Error Handling

| Error Type | Response |
|------------|----------|
| Syntax Error | STOP. Fix immediately in same todo. |
| Import Error | Check file paths, verify imports. |
| Test Failure | Do NOT add more code. Investigate first. |
| 3+ Failures in chunk | Mark chunk BLOCKED, try next independent chunk. |
| 3+ Chunks blocked | STOP. Start new session. |
| Syntax error | Stop and fix immediately in same todo |
| Import error | Check file paths and verify imports |
| Test failure | Investigate root cause β€” do not add more code |
| 3+ failures in chunk | Mark chunk BLOCKED, try next independent chunk |
| 3+ chunks blocked | Stop and start a new session |

## Commit Format

Per-todo:
```
# Per todo
feat(chunk-Pn): Todo N - description
Implements: [feature] chunk N
```

Per-chunk completion:
```
# Per chunk completion
feat(chunk-Pn): Complete chunk - [domain]
Completes: CHUNK-Pn, Updates: CHUNK-Rn
```

## Context Budget
- Plan: 15k tokens
- Active code (per chunk): ~10k tokens
- Test results (per chunk): ~5k tokens
- Max active (3 chunks): ~45k tokens (22.5%)
## Chunk Status Tracking

Track progress in the plan document:

```markdown
| Chunk | Status | Todos Done | Commit | Research Updated |
|-------|--------|------------|--------|------------------|
| P1 | IMPLEMENTED | 4/4 | abc123 | R1 |
| P2 | IMPLEMENTING | 2/5 | - | - |
```
Loading