Commit c0cd9d3
committed
feat(session): add bi-directional cursor-based pagination with Home/End navigation
Implements cursor-based pagination for message loading to handle long sessions without memory explosion with absolute navigation via Home/End keys.
API changes:
- Add 'before' cursor param: fetch messages older than cursor (newest first)
- Add 'after' cursor param: fetch messages newer than cursor (oldest first)
- Add 'oldest' param: start from oldest messages (for jumpToOldest)
- Link headers with rel="prev"/"next" for cursor discovery (RFC 5005)
TUI changes:
- loadOlder/loadNewer actions with sliding window eviction (500 msg limit)
- jumpToOldest (Home): fetches oldest page via ?oldest=true
- jumpToLatest (End): fetches newest page, preserves revert marker
- Detached mode: ignores SSE when viewing history to prevent gaps
Implementation:
- Binary.lowerBound for efficient cursor lookup
- parseLinkHeader utility for RFC 5988 parsing
- Message.stream() reverse option for ascending order
- Smart parts cleanup: only deletes parts for evicted messages
Tests:
- Unit tests for pagination logic and cursor handling
- API tests for before/after/oldest params and Link headers
Resolves: #65481 parent b3901ac commit c0cd9d3
File tree
13 files changed
+1342
-38
lines changed- packages
- opencode
- src
- cli/cmd/tui
- context
- routes/session
- server/routes
- session
- util
- test
- server
- session
- util
- sdk
- js/src/v2/gen
- util/src
13 files changed
+1342
-38
lines changedLarge diffs are not rendered by default.
Lines changed: 112 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
| |||
128 | 129 | | |
129 | 130 | | |
130 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
131 | 178 | | |
132 | 179 | | |
133 | 180 | | |
| |||
230 | 277 | | |
231 | 278 | | |
232 | 279 | | |
233 | | - | |
| 280 | + | |
234 | 281 | | |
235 | 282 | | |
236 | 283 | | |
| |||
268 | 315 | | |
269 | 316 | | |
270 | 317 | | |
271 | | - | |
| 318 | + | |
272 | 319 | | |
273 | 320 | | |
274 | 321 | | |
| |||
347 | 394 | | |
348 | 395 | | |
349 | 396 | | |
350 | | - | |
| 397 | + | |
351 | 398 | | |
352 | 399 | | |
353 | 400 | | |
| |||
370 | 417 | | |
371 | 418 | | |
372 | 419 | | |
373 | | - | |
| 420 | + | |
374 | 421 | | |
375 | 422 | | |
376 | 423 | | |
| |||
652 | 699 | | |
653 | 700 | | |
654 | 701 | | |
655 | | - | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
656 | 712 | | |
657 | 713 | | |
658 | 714 | | |
| |||
663 | 719 | | |
664 | 720 | | |
665 | 721 | | |
666 | | - | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
667 | 732 | | |
668 | 733 | | |
669 | 734 | | |
| |||
693 | 758 | | |
694 | 759 | | |
695 | 760 | | |
696 | | - | |
| 761 | + | |
697 | 762 | | |
698 | 763 | | |
699 | 764 | | |
| |||
963 | 1028 | | |
964 | 1029 | | |
965 | 1030 | | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
966 | 1047 | | |
967 | 1048 | | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
968 | 1063 | | |
969 | 1064 | | |
970 | 1065 | | |
| |||
1077 | 1172 | | |
1078 | 1173 | | |
1079 | 1174 | | |
| 1175 | + | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
| 1183 | + | |
| 1184 | + | |
1080 | 1185 | | |
1081 | 1186 | | |
1082 | 1187 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
570 | 571 | | |
571 | 572 | | |
572 | 573 | | |
573 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
574 | 578 | | |
575 | 579 | | |
576 | 580 | | |
577 | 581 | | |
578 | | - | |
579 | | - | |
580 | | - | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
581 | 650 | | |
582 | | - | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
583 | 665 | | |
584 | 666 | | |
585 | 667 | | |
| |||
0 commit comments