opencode
opencode copied to clipboard
feat: export local and view exported & project sessions in web UI
Draft PR: Session Export and Local Viewing
Looking For Feedback
[!Note] This is a draft PR looking for feedback on the implementation approach and user experience.
Current Draft Limitation:
- Need to run
opencode serve.- Need to run web ui dev server
bun --cwd packages/web dev.
- Can also build using astro node adapter and run with
bun- Web UI port is hardcoded
https://github.com/user-attachments/assets/24a0cdfd-1093-4c07-80b4-98539f207f81
Summary
This PR adds the ability to export chat sessions to local storage and view them through a local web interface. Users can now:
- Export active sessions to local JSON files stored in the config directory
- Access exported sessions via local URLs (e.g.,
http://localhost:4321/local/{sessionId}) - Browse and manage exported sessions through new API endpoints
Key Changes
Server
-
New API endpoints (
packages/opencode/src/server/server.ts):-
POST /session/:id/export- Export a session to local storage -
GET /session/export- List all exported sessions -
GET /session/:id/export- Retrieve specific exported session data
-
-
Session export functionality (
packages/opencode/src/session/index.ts):- Export sessions as JSON files to
~/.config/opencode/session-exports/ - Include session metadata, messages, and export timestamp
- Generate local URLs for web access
- Export sessions as JSON files to
TUI
-
New export command (
packages/tui/internal/commands/command.go):- Added
SessionExportCommandwith trigger "export"
- Added
-
Export functionality (
packages/tui/internal/tui/tui.go):- Export current session and copy local URL to clipboard
- Success/error toast notifications
- Generated client updates - Updated OpenAPI spec and Go client code
User Experience
- User runs
exportcommand in active session - Session gets exported to local JSON file
- Local URL (
http://localhost:4321/local/{sessionId}) copied to clipboard - User can access exported session via browser at that URL
Technical Details
- Export files stored in
~/.config/opencode/session-exports/{sessionId}.json - Local web server runs on port 4321
- Exported sessions include full conversation history and metadata
- Error handling for missing sessions and file operations