Skip to content

Commit c221a8a

Browse files
rysweetUbuntuclaude
authored
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

9 files changed

+3654
-336
lines changed

.claude/commands/amplihack/transcripts.md

Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,80 @@ Shows the original request and requirements for a session.
4949

5050
- `session_id`: Target session (default: current)
5151

52+
## What To Do
53+
54+
When this command is invoked, use the `transcript_manager` tool to handle the request:
55+
56+
### List Sessions (No Args or "list")
57+
58+
```python
59+
from transcript_manager import TranscriptManager, list_transcripts, get_transcript_summary
60+
61+
# List all available sessions
62+
sessions = list_transcripts()
63+
64+
# Display formatted list with summaries
65+
manager = TranscriptManager()
66+
for i, session_id in enumerate(sessions[:10], 1): # Show latest 10
67+
summary = get_transcript_summary(session_id)
68+
print(manager.format_summary_display(summary, i))
69+
```
70+
71+
### Restore Latest Session ("latest")
72+
73+
```python
74+
from transcript_manager import list_transcripts, restore_transcript, TranscriptManager
75+
76+
sessions = list_transcripts()
77+
if sessions:
78+
context = restore_transcript(sessions[0])
79+
manager = TranscriptManager()
80+
print(manager.format_context_display(context))
81+
```
82+
83+
### Restore Specific Session (<session_id>)
84+
85+
```python
86+
from transcript_manager import restore_transcript, TranscriptManager
87+
88+
context = restore_transcript(session_id)
89+
manager = TranscriptManager()
90+
print(manager.format_context_display(context))
91+
# Display:
92+
# - Original user request
93+
# - Conversation summary
94+
# - Full transcript location
95+
# - Compaction events (if any)
96+
```
97+
98+
### Save Checkpoint ("save")
99+
100+
```python
101+
from transcript_manager import save_checkpoint, TranscriptManager
102+
from datetime import datetime
103+
104+
session_id = save_checkpoint()
105+
manager = TranscriptManager()
106+
checkpoint_count = manager.get_checkpoint_count(session_id)
107+
108+
# Display success message with:
109+
# - Session ID
110+
# - Checkpoint location
111+
# - Checkpoint number
112+
# - Timestamp
113+
print(f"✅ Session checkpoint created!")
114+
print(f"📄 Session ID: {session_id}")
115+
print(f"🔖 Checkpoint #{checkpoint_count}")
116+
print(f"⏰ Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
117+
```
118+
52119
## Implementation
53120

54-
The actual implementation is in `/Users/ryan/src/hackathon/MicrosoftHackathon2025-AgenticCoding/.claude/commands/transcripts.py`
121+
All transcript functionality is provided by the `transcript_manager` tool:
122+
123+
**Tool**: `.claude/tools/amplihack/transcript_manager.py`
124+
125+
This command provides instructions on how to use the tool. No Python code is executed directly by this command - Claude interprets the instructions and calls the tool.
55126

56127
## Examples
57128

@@ -130,4 +201,19 @@ Found 2 matches across sessions
130201
4. **Searchable History**: Find past decisions and implementations
131202
5. **Compaction Safe**: Automatic export before context loss
132203

133-
This command provides amplihack-style transcript management, ensuring that conversation context and original requirements are never lost, even during context compaction events.
204+
## Philosophy Alignment
205+
206+
- **Ruthless Simplicity**: Command is markdown instructions only, no Python code
207+
- **Separation of Concerns**: Command provides instructions, tool implements business logic
208+
- **Zero-BS**: All tool functions work completely, no stubs or placeholders
209+
- **Brick Philosophy**: transcript_manager.py is a self-contained, regeneratable brick
210+
211+
## Resources
212+
213+
- **Tool**: `.claude/tools/amplihack/transcript_manager.py` (business logic)
214+
- **Command**: `.claude/commands/amplihack/transcripts.md` (instructions only)
215+
- **PreCompact Hook**: `.claude/tools/amplihack/hooks/pre_compact.py` (automatic export)
216+
217+
This command provides amplihack-style transcript management through a clean, reusable tool. The tool can be called from commands, skills, and hooks. It ensures that conversation context and original requirements are never lost, even during context compaction events.
218+
219+
**Key Takeaway**: Business logic lives in `transcript_manager.py`, this command just tells you how to use it.

0 commit comments

Comments
 (0)