Commit a8942f7
authored
feat(agent): Add session resumption support (#335)
## Summary
Adds session resumption support to the agent command, allowing users to
continue work from where they left off.
## Changes
### New Features
- **`--session-id` flag**: Resume existing agent sessions by
conversation ID
- **Session lifecycle events**: Structured JSON status messages for
session events
- **Conversation loading**: Load and restore full conversation history
from database
- **Turn counter reset**: Full budget restored when resuming sessions
### Implementation Details
1. **`convertFromConversationEntry`**: Reverse conversion from
domain.ConversationEntry to ConversationMessage
2. **`loadExistingSession`**: Load conversation from persistent
repository and restore state
3. **`outputStatusMessage`**: Output structured JSON for session
lifecycle events
4. **Session ID preservation**: Maintain session ID for continued
persistence
### Documentation Updates
- Updated README.md with session resumption examples
- Enhanced commands-reference.md with detailed usage and JSON examples
- Added session resumption to feature list
### Testing
- Comprehensive unit tests for `convertFromConversationEntry`
- Tests cover all message types: user, assistant, tool, with images,
tool calls, and metadata
- Edge cases: internal messages, tool execution metadata, empty content
## Usage Examples
```bash
# List conversations to find session IDs
infer conversations list
# Resume an existing session
infer agent "continue fixing the authentication bug" --session-id abc-123-def
# Resume with additional files
infer agent "analyze these new error logs" --session-id abc-123 --files error.log
# Resume without saving (testing mode)
infer agent "try a different approach" --session-id abc-123 --no-save
```
## JSON Status Messages
```json
// Successful resume
{"type":"info","message":"Resumed agent session","session_id":"abc-123","message_count":15,"timestamp":"2025-12-11T..."}
// Failed resume (warning)
{"type":"warning","message":"Could not load session, starting fresh","session_id":"invalid","error":"failed to load conversation: not found","timestamp":"2025-12-11T..."}
// New session
{"type":"info","message":"Starting new agent session","session_id":"new-uuid","model":"openai/gpt-4","timestamp":"2025-12-11T..."}
```
## Benefits
- **Continuity**: Continue complex tasks across multiple sessions
- **Context preservation**: Maintain full conversation history
- **Efficiency**: Avoid repeating setup and context establishment
- **Debugging**: Easier to debug and iterate on complex problems
- **Integration**: Structured JSON output for automation and monitoring
## Technical Notes
- Uses existing persistent conversation repository infrastructure
- Maintains backward compatibility (no breaking changes)
- All existing tests pass
- Follows existing code patterns and conventions1 parent 95f71cd commit a8942f7
File tree
4 files changed
+482
-5
lines changed- cmd
- docs
4 files changed
+482
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| 205 | + | |
205 | 206 | | |
206 | 207 | | |
207 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
208 | 214 | | |
209 | 215 | | |
210 | | - | |
| 216 | + | |
211 | 217 | | |
212 | 218 | | |
213 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
27 | 32 | | |
| 33 | + | |
28 | 34 | | |
29 | 35 | | |
30 | 36 | | |
31 | 37 | | |
32 | 38 | | |
33 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
34 | 45 | | |
35 | 46 | | |
36 | 47 | | |
37 | 48 | | |
38 | 49 | | |
| 50 | + | |
39 | 51 | | |
40 | 52 | | |
41 | 53 | | |
42 | 54 | | |
43 | | - | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
| |||
75 | 87 | | |
76 | 88 | | |
77 | 89 | | |
78 | | - | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
134 | 146 | | |
135 | 147 | | |
136 | 148 | | |
137 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
138 | 176 | | |
139 | 177 | | |
140 | 178 | | |
| |||
505 | 543 | | |
506 | 544 | | |
507 | 545 | | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
508 | 575 | | |
509 | 576 | | |
510 | 577 | | |
| |||
519 | 586 | | |
520 | 587 | | |
521 | 588 | | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
522 | 622 | | |
523 | 623 | | |
524 | 624 | | |
| |||
544 | 644 | | |
545 | 645 | | |
546 | 646 | | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
547 | 668 | | |
548 | 669 | | |
549 | 670 | | |
| |||
590 | 711 | | |
591 | 712 | | |
592 | 713 | | |
| 714 | + | |
593 | 715 | | |
594 | 716 | | |
0 commit comments