feat(session): add ts_before and breakpoint params to Session.messages API#14666
feat(session): add ts_before and breakpoint params to Session.messages API#14666ryanwyler wants to merge 3 commits intoanomalyco:devfrom
Conversation
…s API Add optional parameters to Session.messages() for loading older messages: - ts_before: filter to messages created before this timestamp - breakpoint: stop at first compaction summary when true This is a foundational API enhancement that enables clients to implement pagination and history loading without breaking existing functionality.
Adds TUI integration for loading older messages in sessions with 100+ messages. Implementation: - loadConversationHistory(): Loads messages up to next compaction summary - loadFullSessionHistory(): Loads entire remaining session history UI Integration: - Displays 'Load more messages' when 100+ messages present - Two clickable options for conversation vs full history - Toast notifications show count of messages loaded - Uses synthetic message pattern for clean positioning Depends on the ts_before and breakpoint API parameters added in the previous commit.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PRs FoundPR #8535 - "bi-directional cursor-based pagination"
PR #10198 - "add offset parameter for message pagination"
PR #6138 - "add session_list_limit for session picker"
The current PR acknowledges these related efforts and makes a case for why its approach (timestamp-based with breakpoint support) complements rather than duplicates the others. |
|
Closing — PR was incorrectly created from gignit/opencode-orig. Re-opening from gignit/opencode with correct commits. |
Summary
Adds two optional parameters to
Session.messages()API for loading messages older than the initial 100-message window:ts_before: Unix timestamp - returns messages created before this pointbreakpoint: Boolean - when true, stops at the first compaction summaryProblem
Multiple open issues request the ability to access message history beyond the initial 100-message limit:
Current
Session.messages()only supports alimitparameter, which returns the N most recent messages. There is no way to retrieve older messages.Solution
This PR adds the foundational server-side API enhancement required by all proposed solutions. The implementation is minimal (8 lines of core logic) and non-breaking:
Core changes:
packages/opencode/src/session/index.ts- Add params toSession.messages()schema and iteration logicpackages/opencode/src/server/routes/session.ts- Expose params in HTTP APIWhy this approach:
Usage
Testing
Verified against sessions with 170+ messages and multiple compactions:
ts_beforecorrectly filters to messages older than timestampbreakpoint=truestops at first compaction partRelated PRs
PR #8535 - "bi-directional cursor-based pagination"
Status: Open | Additions: 1,228 lines | Approach: Cursor-based with RFC 5005 Link headers
ts_before,breakpointbefore,after,oldest+ Link headersbreakpoint)Why this PR should still be considered:
breakpointparameter enables "load to last context boundary" which is semantically meaningful for LLM conversations.Verdict on #8535: Not mutually exclusive. Timestamps serve "load everything before X" queries; cursors serve "give me the next/previous page" navigation.
Verdict on #6656: Superseded by #8535. Not relevant to this PR's approach.
Verdict on #6138: Complementary but insufficient. Users with 1000+ message sessions still can't access early history.
Recommendation: This PR should merge because:
breakpointparameter for compaction-aware loading isn't in any other PR