Repository navigation
feat(vscode): load older sessions on demand in history #14344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
83d276a
feat(vscode): load older sessions on demand in history
marius-kilocode e850fc6
fix(vscode): repair session paging stories and load dispatch
marius-kilocode 6b6c9c9
fix(vscode): harden session paging failures and load-more state
marius-kilocode 55b2fc5
fix(vscode): keep tabs on appended pages and surface deferred load er…
marius-kilocode f98d1f8
Merge remote-tracking branch 'origin/main' into implement-paged-sessi…
marius-kilocode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "kilo-code": patch | ||
| --- | ||
|
|
||
| Load older chats on demand in the session history with a "Load more" control instead of stopping at the 100 most recent. Paging works across the workspace and every worktree directory. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import type { KiloClient, Session } from "@kilocode/sdk/v2/client" | ||
| import { retry } from "../services/cli-backend/retry" | ||
|
|
||
| export const SESSION_PAGE_LIMIT = 50 | ||
|
|
||
| /** One page of sessions for a single directory plus the cursor for the next page. */ | ||
| export interface SessionPage { | ||
| sessions: Session[] | ||
| cursor?: number | ||
| } | ||
|
|
||
| /** Per-directory paging state shared between the initial load and "load more". */ | ||
| export interface SessionPageState { | ||
| dirs: Map<string, { cursor?: number; more: boolean }> | ||
| hasMore: boolean | ||
| } | ||
|
|
||
| export function createSessionPageState(): SessionPageState { | ||
| return { dirs: new Map(), hasMore: false } | ||
| } | ||
|
|
||
| /** | ||
| * Fetch one page of sessions for a directory. Uses the existing paged | ||
| * experimental endpoint so no shared upstream session API changes are needed. | ||
| * Older pages use the returned cursor, which is the `time_updated` of the | ||
| * oldest session in the page. | ||
| */ | ||
| export async function fetchSessionPage( | ||
| client: KiloClient, | ||
| input: { dir: string; cursor?: number; limit?: number }, | ||
| ): Promise<SessionPage> { | ||
| const limit = input.limit ?? SESSION_PAGE_LIMIT | ||
| const result = await retry(() => | ||
| client.experimental.session.list( | ||
| { directory: input.dir, roots: true, archived: true, limit, cursor: input.cursor }, | ||
| { throwOnError: true }, | ||
| ), | ||
| ) | ||
| const items = result.data ?? [] | ||
| // When a proxy strips x-next-cursor but the page is full, synthesize the | ||
| // cursor from the oldest item so "load more" keeps working. | ||
| const header = result.response.headers.get("x-next-cursor") | ||
| const parsed = header == null ? undefined : Number(header) | ||
|
marius-kilocode marked this conversation as resolved.
Resolved
|
||
| const cursor = | ||
| parsed != null && Number.isFinite(parsed) | ||
| ? parsed | ||
| : items.length >= limit && items.length > 0 | ||
| ? items[items.length - 1]!.time.updated | ||
|
marius-kilocode marked this conversation as resolved.
Resolved
|
||
| : undefined | ||
| return { sessions: items, cursor } | ||
| } | ||
|
|
||
| /** Merge session batches, drop duplicate ids, and sort newest first. */ | ||
| export function mergeSessions(batches: Session[][]): Session[] { | ||
| const seen = new Set<string>() | ||
| const merged: Session[] = [] | ||
| for (const batch of batches) { | ||
| for (const session of batch) { | ||
| if (seen.has(session.id)) continue | ||
| seen.add(session.id) | ||
| merged.push(session) | ||
| } | ||
| } | ||
| return merged.sort((a, b) => b.time.updated - a.time.updated) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.