Tool to send cross-session opencode messages, including as request-response pattern
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

sketch of tools

rektide 42ecbdb5

+706
+11
README.md
··· 1 + # opencode-call-response 2 + 3 + > Tool to send cross-session opencode messages, including as request-response pattern 4 + 5 + # Tools 6 + 7 + | tool | description | params=[default] | 8 + | ---------- | ----------------------------------- | --------------------------------------------------- | 9 + | `list` | list all sessions | `dir=[pwd]` constraint | 10 + | `call` | send a request or message | `session=[new]`, `elaborate=[true]`, `fork=[false]` | 11 + | `response` | multitool for queues responses, get | `get=[top]`, `list=[false]` |
+673
doc/discovery/opencode-sessions.md
··· 1 + # Session Architecture in OpenCode 2 + 3 + ## Overview 4 + 5 + Sessions in OpenCode represent the core unit of conversation state between users and AI assistants. Each session encapsulates the entire interaction history, including messages, tool executions, file changes, permissions, and metadata. Sessions are persistently stored and can be restored, forked, shared, and managed through various interfaces. 6 + 7 + ## Session Storage 8 + 9 + ### Physical Storage Location 10 + 11 + Sessions are stored in the OpenCode data directory using a structured JSON-based storage system: 12 + 13 + ``` 14 + ~/.local/share/opencode/storage/ 15 + ├── session/ 16 + │ └── {projectID}/ 17 + │ └── {sessionID}.json # Session metadata 18 + ├── message/ 19 + │ └── {sessionID}/ 20 + │ └── {messageID}.json # Message metadata 21 + ├── part/ 22 + │ └── {messageID}/ 23 + │ └── {partID}.json # Message parts (text, tool calls, etc.) 24 + ├── session_diff/ 25 + │ └── {sessionID}.json # File changes/diffs 26 + └── share/ 27 + └── {sessionID}.json # Share information 28 + ``` 29 + 30 + The data directory location follows XDG Base Directory specifications: 31 + 32 + - Linux/macOS: `~/.local/share/opencode/storage/` 33 + - Can be overridden via `OPENCODE_TEST_HOME` environment variable for testing 34 + 35 + ### Project Association 36 + 37 + Sessions are grouped by project ID, which is derived from the Git repository's root commit: 38 + 39 + - Git projects: Project ID is the hash of the first commit (`git rev-list --max-parents=0 --all`) 40 + - Non-Git projects: Project ID is `"global"` 41 + 42 + This allows sessions to be scoped to specific codebases and worktrees. 43 + 44 + ### Session Identifier Format 45 + 46 + Session IDs use a monotonic identifier format with the prefix `ses_`: 47 + 48 + ``` 49 + {prefix}_{timestamp_base62}{random} 50 + ``` 51 + 52 + - **Prefix**: `ses_` (identifies as session) 53 + - **Timestamp**: 6 bytes of base62-encoded timestamp with counter 54 + - **Random**: 14 bytes of random base62 characters 55 + 56 + Example: `ses_01h8k7m5n2p3q4r5s6t7u8v9w0x1y2z3` 57 + 58 + The timestamp allows sorting by creation time, while the random component ensures uniqueness. IDs can be generated in ascending (newest last) or descending (newest first) order. 59 + 60 + ### Session Data Structure 61 + 62 + Each session file (`{sessionID}.json`) contains: 63 + 64 + ```typescript 65 + { 66 + id: string // Unique session identifier 67 + slug: string // URL-friendly slug for sharing 68 + projectID: string // Associated project ID 69 + directory: string // Working directory path 70 + parentID: string? // Parent session ID (for forks) 71 + title: string // Session title 72 + version: string // OpenCode version that created the session 73 + time: { 74 + created: number // Creation timestamp (ms) 75 + updated: number // Last update timestamp (ms) 76 + compacting: number? // Last compaction timestamp 77 + archived: number? // Archive timestamp 78 + } 79 + summary?: { 80 + additions: number // Total lines added 81 + deletions: number // Total lines deleted 82 + files: number // Number of files modified 83 + diffs?: FileDiff[] // Detailed file changes 84 + } 85 + share?: { 86 + url: string // Shareable URL 87 + } 88 + permission?: PermissionRuleset[] // Permission rules for this session 89 + revert?: { 90 + messageID: string // Message being reverted 91 + partID: string? // Specific part being reverted 92 + snapshot: string? // Git snapshot hash 93 + diff: string? // Diff content 94 + } 95 + } 96 + ``` 97 + 98 + ### Message and Part Storage 99 + 100 + Messages are stored separately from session metadata: 101 + 102 + **Message Structure** (`message/{sessionID}/{messageID}.json`): 103 + 104 + ```typescript 105 + { 106 + id: string // Message ID (msg_ prefix) 107 + sessionID: string // Parent session ID 108 + role: "user" | "assistant" | "system" 109 + parentID: string? // Parent message ID 110 + agent?: string // Agent that processed this 111 + model?: string // Model used 112 + time: { 113 + created: number // Creation timestamp 114 + } 115 + error?: Error // Error if processing failed 116 + cost?: number // Token cost 117 + tokens?: { 118 + input: number 119 + output: number 120 + reasoning: number 121 + cache: { 122 + read: number 123 + write: number 124 + } 125 + } 126 + } 127 + ``` 128 + 129 + **Part Structure** (`part/{messageID}/{partID}.json`): 130 + 131 + ```typescript 132 + { 133 + id: string // Part ID (prt_ prefix) 134 + messageID: string // Parent message ID 135 + sessionID: string // Parent session ID 136 + type: "text" | "tool" | "file" | "agent" | "subtask" | "reasoning" 137 + // Type-specific fields... 138 + time: { 139 + start: number 140 + end?: number 141 + } 142 + } 143 + ``` 144 + 145 + This separation allows efficient streaming of message parts during AI processing without reloading the entire session. 146 + 147 + ## Session List Implementation 148 + 149 + ### CLI Command: `opencode session list` 150 + 151 + The `opencode session list` command is implemented in `packages/opencode/src/cli/cmd/session.ts`: 152 + 153 + **Location**: [`packages/opencode/src/cli/cmd/session.ts:45-136`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/cli/cmd/session.ts#L45) 154 + 155 + **Key Features**: 156 + 157 + 1. **Bootstrap Loading**: Uses `bootstrap()` to initialize project context from current working directory 158 + 2. **Session Enumeration**: Iterates through `Session.list()` to load all sessions 159 + 3. **Root Filtering**: Excludes child sessions (those with `parentID`) by default 160 + 4. **Sorting**: Sorts by `time.updated` in descending order (newest first) 161 + 5. **Limiting**: Supports `--max-count` flag to limit output 162 + 6. **Pagination**: Automatically uses `less` pager when outputting to TTY 163 + 7. **Format Options**: Supports table (default) and JSON formats 164 + 165 + **Code Flow**: 166 + 167 + ```typescript 168 + for await (const session of Session.list()) { 169 + if (!session.parentID) { 170 + sessions.push(session) 171 + } 172 + } 173 + sessions.sort((a, b) => b.time.updated - a.time.updated) 174 + ``` 175 + 176 + **Table Format Output**: 177 + 178 + ``` 179 + Session ID Title Updated 180 + ────────────────────────────────────────────────────────────────────────── 181 + ses_01h8k7m... New session - 2025-01-15... Today at 2:30 PM 182 + ses_01h8j9k... Add authentication API Yesterday 183 + ses_01h8i8j... Fix memory leak in worker 2 days ago 184 + ``` 185 + 186 + **JSON Format Output**: 187 + 188 + ```json 189 + [ 190 + { 191 + "id": "ses_01h8k7m...", 192 + "title": "New session - 2025-01-15T14:30:00.000Z", 193 + "updated": 1736963400000, 194 + "created": 1736963400000, 195 + "projectId": "a1b2c3d4...", 196 + "directory": "/home/user/project" 197 + } 198 + ] 199 + ``` 200 + 201 + ### Server API Endpoint 202 + 203 + The HTTP API provides equivalent functionality via `GET /api/session`: 204 + 205 + **Location**: [`packages/opencode/src/server/routes/session.ts:24-67`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L24) 206 + 207 + **Query Parameters**: 208 + 209 + - `directory`: Filter sessions by project directory 210 + - `roots`: Only return root sessions (no parentID) 211 + - `start`: Filter sessions updated on or after timestamp 212 + - `search`: Filter sessions by title (case-insensitive) 213 + - `limit`: Maximum number of sessions to return 214 + 215 + **Example Request**: 216 + 217 + ```bash 218 + curl "http://localhost:5173/api/session?roots=true&limit=10" 219 + ``` 220 + 221 + ## Session Write Operations 222 + 223 + OpenCode writes to sessions through multiple pathways depending on the operation type: 224 + 225 + ### 1. Session Creation 226 + 227 + **Method**: `Session.create()` 228 + **Location**: [`packages/opencode/src/session/index.ts:140-247`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/index.ts#L140) 229 + 230 + **Process**: 231 + 232 + 1. Generate unique session ID using `Identifier.descending("session")` 233 + 2. Create session metadata with defaults: 234 + - Default title: "New session - {timestamp}" or "Child session - {timestamp}" 235 + - Project ID from current instance 236 + - Directory from instance context 237 + 3. Write to storage: `Storage.write(["session", projectID, sessionID], sessionInfo)` 238 + 4. Publish `session.created` event via Bus 239 + 5. Auto-share if configured 240 + 6. Publish `session.updated` event 241 + 242 + **Code**: 243 + 244 + ```typescript 245 + const result = { 246 + id: Identifier.descending("session"), 247 + slug: Slug.create(), 248 + version: Installation.VERSION, 249 + projectID: Instance.project.id, 250 + directory: input.directory, 251 + parentID: input.parentID, 252 + title: input.title ?? createDefaultTitle(!!input.parentID), 253 + time: { 254 + created: Date.now(), 255 + updated: Date.now(), 256 + }, 257 + } 258 + await Storage.write(["session", Instance.project.id, result.id], result) 259 + ``` 260 + 261 + ### 2. Message Addition 262 + 263 + **Method**: `SessionPrompt.prompt()` 264 + **Location**: [`packages/opencode/src/session/prompt.ts:152-181`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/prompt.ts#L152) 265 + 266 + **Process**: 267 + 268 + 1. Create user message with provided parts (text, files, etc.) 269 + 2. Touch session to update timestamp 270 + 3. Start message processing loop 271 + 4. Stream AI response into assistant message parts 272 + 5. Each part is written immediately via `Session.updatePart()` 273 + 6. Publish events for each part update 274 + 275 + **Flow**: 276 + 277 + ```typescript 278 + const message = await createUserMessage(input) 279 + await Session.touch(input.sessionID) 280 + return loop(input.sessionID) 281 + ``` 282 + 283 + ### 3. Part Streaming (During AI Processing) 284 + 285 + **Method**: `Session.updatePart()` 286 + **Location**: [`packages/opencode/src/session/index.ts:428-437`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/index.ts#L428) 287 + 288 + **Process**: 289 + 290 + 1. Write part to storage: `Storage.write(["part", messageID, partID], part)` 291 + 2. Publish `part.updated` event via Bus 292 + 3. Support delta updates for text/reasoning parts (append instead of rewrite) 293 + 294 + **Use Cases**: 295 + 296 + - Text streaming: User prompts are built incrementally 297 + - Reasoning: AI thinking process streams in real-time 298 + - Tool execution: Tool inputs, outputs, and status updates 299 + - File attachments: File metadata and content 300 + 301 + ### 4. Session Updates 302 + 303 + **Method**: `Session.update()` 304 + **Location**: [`packages/opencode/src/session/index.ts:297-309`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/index.ts#L297) 305 + 306 + **Process**: 307 + 308 + 1. Read existing session from storage 309 + 2. Apply editor function to modify fields 310 + 3. Auto-update `time.updated` timestamp unless `{ touch: false }` option 311 + 4. Write back to storage 312 + 5. Publish `session.updated` event 313 + 314 + **Common Updates**: 315 + 316 + - Title changes 317 + - Permission modifications 318 + - Archive/unarchive 319 + - Share URL updates 320 + - Revert state changes 321 + 322 + ### 5. Session Compaction 323 + 324 + **Method**: `SessionCompaction.create()` 325 + **Location**: [`packages/opencode/src/session/compaction.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/compaction.ts) 326 + 327 + **Process**: 328 + 329 + 1. Create a summary message containing key information 330 + 2. Remove older messages that are summarized 331 + 3. Update session metadata with `time.compacting` timestamp 332 + 4. Generate diffs for summarized messages 333 + 5. Store diffs in `session_diff/{sessionID}.json` 334 + 335 + **Purpose**: Reduce token usage by condensing long conversation histories while preserving important context. 336 + 337 + ### 6. Session Forking 338 + 339 + **Method**: `Session.fork()` 340 + **Location**: [`packages/opencode/src/session/index.ts:158-198`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/index.ts#L158) 341 + 342 + **Process**: 343 + 344 + 1. Load original session 345 + 2. Create new session with derived title: "{original_title} (fork #N)" 346 + 3. Copy messages up to specified message ID (or all) 347 + 4. Remap message IDs using `Identifier.ascending("message")` 348 + 5. Copy all message parts with new IDs 349 + 6. Maintain parent-child relationship 350 + 351 + **Use Case**: Experiment with different approaches without losing original work. 352 + 353 + ### 7. Session Revert 354 + 355 + **Method**: `SessionRevert.revert()` 356 + **Location**: [`packages/opencode/src/session/revert.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/revert.ts) 357 + 358 + **Process**: 359 + 360 + 1. Create git snapshot of current state 361 + 2. Mark message as reverted in session metadata 362 + 3. Restore files from git snapshot 363 + 4. Store revert info in session 364 + 5. Messages are not deleted, just marked as reverted 365 + 366 + **Support**: `SessionRevert.unrevert()` restores previously reverted messages. 367 + 368 + ## Session Restoration and Switching 369 + 370 + ### HTTP API Session Selection 371 + 372 + The web interface switches sessions by calling session endpoints: 373 + 374 + **Get Session**: `GET /api/session/{sessionID}` 375 + **Location**: [`packages/opencode/src/server/routes/session.ts:93-123`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L93) 376 + 377 + **Load Messages**: `GET /api/session/{sessionID}/message` 378 + **Location**: [`packages/opencode/src/server/routes/session.ts:547-584`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L547) 379 + 380 + **Process**: 381 + 382 + 1. Frontend requests session metadata and messages 383 + 2. Backend loads from storage using `Session.get(sessionID)` and `Session.messages({ sessionID })` 384 + 3. Messages are returned with all parts 385 + 4. Frontend renders conversation history 386 + 387 + ### CLI Session Switching 388 + 389 + The CLI doesn't have explicit session switching - instead, operations are performed on a per-project basis. The `opencode session list` command shows all sessions for the current project. 390 + 391 + ### ACP Session Management 392 + 393 + The ACP (Agent Client Protocol) agent maintains its own session state: 394 + 395 + **Manager**: `ACPSessionManager` 396 + **Location**: [`packages/opencode/src/acp/session.ts:8-117`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/acp/session.ts#L8) 397 + 398 + **In-Memory State**: 399 + 400 + ```typescript 401 + { 402 + id: string 403 + cwd: string 404 + mcpServers: McpServer[] 405 + createdAt: Date 406 + model?: ModelInfo 407 + variant?: string 408 + modeId?: string 409 + } 410 + ``` 411 + 412 + **Operations**: 413 + 414 + - `create()`: Creates new session via SDK and stores in memory 415 + - `load()`: Loads existing session from SDK and stores in memory 416 + - `get()`: Retrieves in-memory session state 417 + - `setModel()`, `setVariant()`, `setMode()`: Update session properties 418 + 419 + **Persistence**: ACP sessions are persisted via the OpenCode SDK to the same storage backend. 420 + 421 + ### Instance Context Management 422 + 423 + Sessions are tied to project instances: 424 + 425 + **Location**: [`packages/opencode/src/project/instance.ts:22-44`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/project/instance.ts#L22) 426 + 427 + **Context Scope**: 428 + 429 + - Each directory/project has its own instance context 430 + - Sessions are loaded within their project's instance 431 + - Session operations automatically use the correct project context 432 + 433 + **Cache**: 434 + 435 + - Instances are cached by directory path 436 + - Re-opening a session reuses the cached instance 437 + - `Instance.dispose()` cleans up instance state 438 + 439 + ## Session Status Tracking 440 + 441 + OpenCode tracks session processing status in-memory: 442 + 443 + **Status Types**: [`packages/opencode/src/session/status.ts:7-25`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/status.ts#L7) 444 + 445 + - **idle**: Session is not actively processing 446 + - **busy**: Session is currently processing a prompt 447 + - **retry**: Session encountered an error and is retrying 448 + 449 + **Status Updates**: 450 + 451 + - Set to "busy" when AI processing starts 452 + - Set to "idle" when processing completes 453 + - Set to "retry" with error info on failure 454 + 455 + **Events**: Status changes are published via Bus events (`session.status`, `session.idle`). 456 + 457 + ## Session Events 458 + 459 + OpenCode publishes events for session lifecycle changes: 460 + 461 + **Event Types**: 462 + 463 + - `session.created`: New session created 464 + - `session.updated`: Session metadata updated 465 + - `session.deleted`: Session deleted 466 + - `session.diff`: File changes computed 467 + - `session.error`: Processing error occurred 468 + - `session.status`: Status changed (busy/idle/retry) 469 + 470 + **Bus Integration**: 471 + 472 + ```typescript 473 + Bus.subscribe(Session.Event.Created, (event) => { 474 + console.log("New session:", event.properties.info.id) 475 + }) 476 + ``` 477 + 478 + ## Session Lifecycle 479 + 480 + ``` 481 + 1. Creation 482 + ├─ Generate ID 483 + ├─ Create metadata 484 + ├─ Write to storage 485 + ├─ Publish events 486 + └─ Auto-share (if configured) 487 + 488 + 2. Active Use 489 + ├─ Add messages (user + assistant) 490 + ├─ Stream message parts 491 + ├─ Execute tools 492 + ├─ Track file changes (snapshots) 493 + └─ Update status (busy/idle) 494 + 495 + 3. Optional Operations 496 + ├─ Fork (create copy at message point) 497 + ├─ Revert (undo to previous state) 498 + ├─ Compaction (summarize long history) 499 + ├─ Share (create shareable link) 500 + └─ Archive (mark as archived) 501 + 502 + 4. Deletion 503 + ├─ Recursively delete children 504 + ├─ Delete all messages and parts 505 + ├─ Remove share 506 + ├─ Delete session metadata 507 + └─ Publish events 508 + ``` 509 + 510 + ## Storage Implementation Details 511 + 512 + ### Locking 513 + 514 + Storage operations use file-based locking to prevent concurrent writes: 515 + 516 + ```typescript 517 + using _ = await Lock.write(target) 518 + await Bun.write(target, JSON.stringify(content, null, 2)) 519 + ``` 520 + 521 + Locks are acquired at file granularity to allow concurrent access to different sessions. 522 + 523 + ### Migrations 524 + 525 + Storage includes migration support for schema changes: 526 + 527 + **Location**: [`packages/opencode/src/storage/storage.ts:24-142`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/storage/storage.ts#L24) 528 + 529 + Migration version is stored in `storage/migration` file and migrations run sequentially on startup. 530 + 531 + ### Error Handling 532 + 533 + Storage operations throw `NotFoundError` for missing resources: 534 + 535 + ```typescript 536 + try { 537 + const session = await Session.get(sessionID) 538 + } catch (e) { 539 + if (e instanceof Storage.NotFoundError) { 540 + // Session doesn't exist 541 + } 542 + } 543 + ``` 544 + 545 + ## Performance Considerations 546 + 547 + ### Streaming 548 + 549 + Message parts are written incrementally during AI processing to: 550 + 551 + - Reduce memory usage 552 + - Enable real-time UI updates 553 + - Avoid blocking on large tool outputs 554 + 555 + ### Lazy Loading 556 + 557 + Session messages are loaded on-demand via `Session.messages()` to avoid loading entire conversation history when only metadata is needed. 558 + 559 + ### Compaction 560 + 561 + Long sessions can be compacted to: 562 + 563 + - Reduce token usage 564 + - Improve performance 565 + - Maintain conversation context 566 + 567 + Compaction is triggered automatically when sessions exceed certain thresholds (configurable). 568 + 569 + ## Integration with Other Systems 570 + 571 + ### Project System 572 + 573 + Sessions are scoped to projects, which are identified by: 574 + 575 + - Git root commit (for Git projects) 576 + - "global" (for non-Git projects) 577 + 578 + This allows sessions to be associated with specific codebases. 579 + 580 + ### Snapshot System 581 + 582 + File changes are tracked using git-based snapshots: 583 + 584 + - Each message can create a snapshot 585 + - Diffs are computed between snapshots 586 + - Reverts restore files to previous snapshots 587 + 588 + ### Bus System 589 + 590 + All session changes are published as events: 591 + 592 + - Enables real-time UI updates 593 + - Supports plugins that react to session changes 594 + - Provides audit trail 595 + 596 + ### MCP Integration 597 + 598 + MCP servers are managed at the session level: 599 + 600 + - Each session can have different MCP servers 601 + - MCP state is scoped to session context 602 + 603 + ### Permission System 604 + 605 + Sessions have their own permission rulesets: 606 + 607 + - Control which tools can be used 608 + - Apply to all operations within the session 609 + - Can be updated dynamically 610 + 611 + ## Session API Endpoints 612 + 613 + ### Session Management 614 + 615 + | Method | Endpoint | Description | Location | 616 + | ------ | ---------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------- | 617 + | GET | `/api/session` | List sessions | [`session.ts:24-67`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L24) | 618 + | POST | `/api/session` | Create session | [`session.ts:186-209`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L186) | 619 + | GET | `/api/session/:sessionID` | Get session | [`session.ts:93-123`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L93) | 620 + | PATCH | `/api/session/:sessionID` | Update session | [`session.ts:240-292`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L240) | 621 + | DELETE | `/api/session/:sessionID` | Delete session | [`session.ts:210-239`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L210) | 622 + | GET | `/api/session/:sessionID/children` | Get child sessions | [`session.ts:125-154`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L125) | 623 + | GET | `/api/session/status` | Get all session statuses | [`session.ts:70-91`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L70) | 624 + 625 + ### Message Operations 626 + 627 + | Method | Endpoint | Description | Location | 628 + | ------ | --------------------------------------------------------- | --------------------- | --------------------------------------------------------------------------------------------------------------------------- | 629 + | GET | `/api/session/:sessionID/message` | Get messages | [`session.ts:547-584`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L547) | 630 + | GET | `/api/session/:sessionID/message/:messageID` | Get single message | [`session.ts:586-623`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L586) | 631 + | POST | `/api/session/:sessionID/message` | Send message (stream) | [`session.ts:698-737`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L698) | 632 + | POST | `/api/session/:sessionID/prompt_async` | Send async message | [`session.ts:739-768`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L739) | 633 + | DELETE | `/api/session/:sessionID/message/:messageID/part/:partID` | Delete part | [`session.ts:624-658`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L624) | 634 + | PATCH | `/api/session/:sessionID/message/:messageID/part/:partID` | Update part | [`session.ts:660-696`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L660) | 635 + 636 + ### Session Actions 637 + 638 + | Method | Endpoint | Description | Location | 639 + | ------ | ----------------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------- | 640 + | POST | `/api/session/:sessionID/fork` | Fork session | [`session.ts:327-356`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L327) | 641 + | POST | `/api/session/:sessionID/init` | Initialize session | [`session.ts:294-325`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L294) | 642 + | POST | `/api/session/:sessionID/abort` | Abort active session | [`session.ts:358-385`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L358) | 643 + | POST | `/api/session/:sessionID/share` | Create share link | [`session.ts:387-416`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L387) | 644 + | DELETE | `/api/session/:sessionID/share` | Remove share link | [`session.ts:457-486`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L457) | 645 + | POST | `/api/session/:sessionID/summarize` | Compact session | [`session.ts:488-545`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L488) | 646 + | POST | `/api/session/:sessionID/revert` | Revert message | [`session.ts:839-872`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L839) | 647 + | POST | `/api/session/:sessionID/unrevert` | Restore reverted | [`session.ts:874-902`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L874) | 648 + 649 + ### Other Operations 650 + 651 + | Method | Endpoint | Description | Location | 652 + | ------ | --------------------------------- | ----------------- | --------------------------------------------------------------------------------------------------------------------------- | 653 + | POST | `/api/session/:sessionID/command` | Send command | [`session.ts:770-805`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L770) | 654 + | POST | `/api/session/:sessionID/shell` | Run shell command | [`session.ts:807-837`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L807) | 655 + | GET | `/api/session/:sessionID/todo` | Get session todos | [`session.ts:156-184`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L156) | 656 + | GET | `/api/session/:sessionID/diff` | Get message diff | [`session.ts:418-455`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts#L418) | 657 + 658 + ## Key Files Reference 659 + 660 + | File | Purpose | 661 + | -------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | 662 + | [`packages/opencode/src/session/index.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/index.ts) | Core session operations (CRUD, messages) | 663 + | [`packages/opencode/src/session/prompt.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/prompt.ts) | Message processing and AI interaction | 664 + | [`packages/opencode/src/session/processor.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/processor.ts) | Message part streaming and tool execution | 665 + | [`packages/opencode/src/session/message-v2.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/message-v2.ts) | Message and part types | 666 + | [`packages/opencode/src/session/status.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/status.ts) | Session status tracking | 667 + | [`packages/opencode/src/session/compaction.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/compaction.ts) | Session compaction logic | 668 + | [`packages/opencode/src/session/revert.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/session/revert.ts) | Revert functionality | 669 + | [`packages/opencode/src/storage/storage.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/storage/storage.ts) | Storage abstraction layer | 670 + | [`packages/opencode/src/project/instance.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/project/instance.ts) | Project instance context | 671 + | [`packages/opencode/src/cli/cmd/session.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/cli/cmd/session.ts) | CLI session commands | 672 + | [`packages/opencode/src/server/routes/session.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/server/routes/session.ts) | HTTP API routes | 673 + | [`packages/opencode/src/acp/session.ts`](https://github.com/anomalyco/opencode/blob/main/packages/opencode/src/acp/session.ts) | ACP session management |
opencode-call-response.ts

This is a binary file and will not be displayed.

+22
package.json
··· 1 + { 2 + "name": "opencode-call-response", 3 + "version": "1.0.0", 4 + "description": "", 5 + "main": "index.js", 6 + "scripts": { 7 + "test": "echo \"Error: no test specified\" && exit 1" 8 + }, 9 + "repository": { 10 + "type": "git", 11 + "url": "git+https://github.com/rektide/opencode-call-response.git" 12 + }, 13 + "keywords": [], 14 + "author": "rektide de la faye", 15 + "license": "MIT", 16 + "type": "module", 17 + "bugs": { 18 + "url": "https://github.com/rektide/opencode-call-response/issues" 19 + }, 20 + "homepage": "https://github.com/rektide/opencode-call-response#readme", 21 + "module": "opencode-call-response.js" 22 + }