Peter Parker a7ee3994b4
feat: session digest โ€” auto-summary on session completion (#52)
* docs: add Session Digest design spec and implementation plan

- Auto-generate session summaries when sessions complete (using autoName pattern)
- DigestStore with JSON persistence, query with filters, retention cleanup
- Rich notifications replacing generic "Session completed" message
- /digest command with limit and agent filter
- GET /api/digests endpoint for UI dashboard
- 7 TDD tasks covering store, generation, bridge wiring, command, API

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: rewrite session digest โ†’ on-demand /summary per review feedback

Major design changes:
- Remove auto-digest on session end (context pollution, cost, edge cases)
- Replace with user-initiated /summary command in session topics
- Remove DigestStore/persistence (summary is just a message, no store needed)
- Remove GET /api/digests (replaced with POST /sessions/:id/summary)
- Remove config changes (no DigestSchema needed)
- Add [๐Ÿ“‹ Summary] inline button in completion notifications
- Add promptCount to Session for stats in notifications
- Works mid-session (progress check) not just at end

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: implement on-demand /summary command for session topics

- Add Session.generateSummary() with pause/capture/resume pattern + 15s timeout
- Add Session.promptCount tracking (incremented in processPrompt, skips warmup)
- Add OpenACPCore.summarizeSession() with validation
- Add /summary command in Telegram session topics
- Add [๐Ÿ“‹ Summary] inline button in session completion notifications
- Add sm: callback prefix for summary button handler
- Add POST /api/sessions/:id/summary endpoint
- Add formatSummary() helper in formatting.ts
- Enhance session_end notification with duration + prompt count stats
- 13 tests covering generateSummary, command, callback, formatting

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix(archive): allow archiving initializing sessions + better error handling

Bug fixes reported by tester:
1. Allow /archive for sessions that haven't been chatted in yet
   (status=initializing) โ€” only reject finished/cancelled/error
2. Add topicId validation โ€” return null if threadId is NaN/0
3. Add try/catch around deleteForumTopic with clear error message
   about bot admin permissions
4. Update core.archiveSession to match โ€” allow initializing + active

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address code review feedback on /summary implementation

1. Fix timer leak in generateSummary() โ€” clearTimeout in finally block
2. Remove unnecessary block scope in session-bridge session_end handler
3. Fix promptCount: single if/else instead of duplicated condition
4. Fix handleSummaryCallback: answer callback once (with message for
   ended sessions, plain ack for active)
5. Improve ended session message: "Use /summary while session is active"
6. Revert archive initializing change โ€” belongs in separate PR

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: support /summary for ended sessions via agent respawn

1. Implement respawn for ended sessions: resume agent with conversation
   history via agentSessionId, generate summary, destroy temp agent
2. Remove status !== "active" guard from handleSummary โ€” let core decide
3. Update handleSummaryCallback to find threadId from stored record
4. Update spec to document respawn architecture
5. Fix promptCount: already correct (after warmup guard)
6. No archive changes in this PR (reverted to match upstream)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: address round 4 review โ€” static import, session cleanup, type safety, docs

1. Replace dynamic import("./agent-registry.js") with static import
   (already imported at top of file)
2. Fix tempSession cleanup: destroy Session (not just AgentInstance)
   in finally block to prevent listener leaks
3. Remove unsafe type assertion on record.platform โ€” use (as any)?.topicId
4. Update plan/spec docs to document respawn architecture for ended sessions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: peter <peter@lab3.asia>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:26:25 +07:00
..