3.0 KiB
3.0 KiB
Tasks: Add Workspace Context Injection
1. Dependencies
- 1.1 No new dependencies required (use direct
fetch()calls)
2. Types and Settings
- 2.1 Add
injectWorkspaceContext: booleantoOpenCodeSettingsinterface (default:true) - 2.2 Add
maxNotesInContext: numbertoOpenCodeSettingsinterface (default:20) - 2.3 Add
maxSelectionLength: numbertoOpenCodeSettingsinterface (default:2000) - 2.4 Update
DEFAULT_SETTINGSwith new values
3. OpenCode Client Module
- 3.1 Create
src/OpenCodeClient.tswith a small HTTP wrapper - 3.2 Implement
createSession()and session URL helpers - 3.3 Implement
updateContext()using update-part or ignore+reinject (no revert) - 3.4 Track last injected context message/part IDs for the tracked session
- 3.5 Add error handling for API failures (silent catch, log to console)
4. Workspace Context Module
- 4.1 Create
src/WorkspaceContext.tsfor collecting workspace context - 4.2 Implement
getOpenNotePaths()usinggetLeavesOfType("markdown") - 4.3 Implement
getSelectedText()to get current editor selection with source file - 4.4 Implement
formatContext()to generate the combined context string - 4.5 Add deduplication for files open in multiple panes
- 4.6 Add truncation for selections exceeding
maxSelectionLength
5. Main Plugin Integration
- 5.1 Import
OpenCodeClientandWorkspaceContextin main.ts - 5.2 Initialize
WorkspaceContextinonload() - 5.3 Create
updateOpenCodeContext()method triggered on OpenCode view focus - 5.4 Register
active-leaf-changeevent listener to detect OpenCode view focus (conditional on setting) - 5.5 Create an OpenCode session on first view open and store the iframe URL (in-memory)
- 5.6 Before injecting, resolve
sessionIDby parsing the current iframe URL (if no session route, no-op) - 5.7 Add server running check before attempting context updates
- 5.8 Trigger initial context injection when server reaches running state and a session exists
6. Settings UI
- 6.1 Add toggle for "Inject workspace context" in SettingsTab
- 6.2 Add slider for "Max notes in context" (1-50 range)
- 6.3 Add slider or input for "Max selection length" (500-5000 range)
- 6.4 Add descriptive text explaining the feature includes open notes and selected text
7. Testing
- 7.1 Manual test: Open multiple notes, verify context appears in OpenCode
- 7.2 Manual test: Select text, verify selection appears in context with source file
- 7.3 Manual test: Change open notes while OpenCode is not focused, then focus OpenCode and verify context refreshes
- 7.4 Manual test: Clear selection, verify selection section is removed
- 7.5 Manual test: Disable setting, verify no context injection
- 7.6 Manual test: Server not running, verify no errors thrown
- 7.7 Manual test: Large selection, verify truncation works
- 7.8 Build and verify no TypeScript errors