Commit c221a8a
refactor: Extract context management to reusable tools + Simplify profile API (#1587)
* refactor: Simplify profile API - Remove URI scheme for built-in profiles
Fixes #1575
## Changes
Simplified the profile API so built-in profiles can be referenced by simple
names instead of requiring URI schemes. Reduces unnecessary complexity while
maintaining full backward compatibility.
### API Simplification
**Before** (Complex):
```python
loader.load("amplihack://profiles/coding") # Built-in
loader.load("file:///path/to/custom.yaml") # Custom
```
**After** (Simple):
```python
loader.load("coding") # Built-in - just the name!
loader.load("file:///path/to/custom.yaml") # Custom - unchanged
loader.load("amplihack://profiles/coding") # Still works (backward compat)
```
### Implementation Details
**loader.py** (~5 lines):
- Added simple scheme detection: if no "://" present, treat as built-in name
- Reuses existing _load_builtin() method for both paths
- Maintains backward compatibility for amplihack:// URIs
**config.py** (~4 lines):
- Changed default from "amplihack://profiles/all" to "all"
- Updated docstrings and examples
**cli.py** (~8 lines):
- Changed list_profiles() to display simple names instead of amplihack:// URIs
- Added proper try/except for optional rich dependency
- More user-friendly output
**README.md** (~20 lines):
- Added section showing both syntaxes with clear preference for simple names
- Documented backward compatibility
- Updated all examples to prefer simple syntax
**test_simple_names.py** (NEW):
- 6 comprehensive test cases for simple name API
- Tests backward compatibility
- Tests edge cases
### Testing
✅ Simple names work: load("coding"), load("all"), load("research")
✅ Backward compat: load("amplihack://profiles/coding") still works
✅ File scheme unchanged: load("file:///path") unchanged
✅ Edge cases: load("all.yaml") works correctly
✅ All manual tests passed
### Philosophy Alignment
**Ruthless Simplicity**: Removes unnecessary amplihack:// scheme complexity
through a 5-line string check, while maintaining backward compatibility.
**Modular Design**: Changes localized to logical boundaries, no coupling.
**Zero-BS**: All code works, no stubs or placeholders.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: Extract context management to reusable tools following best practices
Refactored context management system to follow Claude Code skill best practices
and the brick philosophy. Separated business logic from presentation layer into
reusable, self-contained tools.
Key Changes:
- Created context_manager.py (900+ lines) - Consolidates token monitoring, context
extraction, snapshot creation, and rehydration
- Created transcript_manager.py (577 lines) - Consolidates transcript operations
- Created tool_registry.py (333 lines) - Extensible hook registration system
- Created context_automation_hook.py (190 lines) - Bridge between hooks and tools
- Refactored post_tool_use.py - Uses registry pattern instead of inline logic
- Reduced SKILL.md from 513→395 lines, instructions only (< 500 ✓)
- Converted transcripts.py to transcripts.md (markdown instructions)
Benefits:
- Clean separation of concerns (tools/ vs skills/ vs commands/)
- Extensible hook system (easy to add new tool hooks)
- Follows Claude Code best practices (< 500 line skills, instructions-only)
- Self-contained, regeneratable modules (brick philosophy)
- Zero-BS implementation (all functions work completely)
Architecture:
- Business logic in .claude/tools/amplihack/ (reusable bricks)
- Skills/commands are instruction-only markdown
- Hook system supports multiple tools via registry pattern
- See .claude/docs/context-management-refactoring-architecture.md
Code Review: 87/100 (reviewer agent)
- Fixed bare exception handling with specific types
- Fixed type hint errors (any → Any)
- Fixed unused variable warnings from ruff
- All manual tests pass via CLI interfaces
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Ubuntu <azureuser@amplihack2.yb0a3bvkdghunmsjr4s3fnfhra.phxx.internal.cloudapp.net>
Co-authored-by: Claude <noreply@anthropic.com>1 parent b961d83 commit c221a8a
File tree
9 files changed
+3654
-336
lines changed- .claude
- commands/amplihack
- docs
- skills/context_management
- tools/amplihack
- hooks
9 files changed
+3654
-336
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
52 | 119 | | |
53 | 120 | | |
54 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
55 | 126 | | |
56 | 127 | | |
57 | 128 | | |
| |||
130 | 201 | | |
131 | 202 | | |
132 | 203 | | |
133 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
0 commit comments