Conversation
Press f on any user turn in the chat buffer to fork the conversation from that point. Uses the get_tree RPC to map visible buffer position to entry ID, handling compaction (compacted-away turns aren't rendered, so the last-N visible headings are aligned to the active branch). Also fixes chat navigation (n/p): the old pattern searched for the never-present "You:" instead of setext headings, and now recenters the heading to the top of the window. Changes: - Setext heading detection: regex + underline predicate, shared across navigation and fork-at-point - Turn detection: collect headings, map point to 0-based turn index - Tree helpers: flatten-tree (hash index) and active-branch-user-ids (leaf-to-root walk) - execute-fork: extracted shared fork logic (RPC + state refresh + history reload + input prefill), used by both fork-at-point and the menu fork selector - resolve-fork-entry: tree-to-entryId mapping, independently testable - build-tree test helper: flat specs replace deeply nested tree construction in tests 49 new tests covering heading detection, navigation, turn indexing, tree walk scenarios, and fork-at-point integration.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Press
fon any user turn in the chat buffer to fork the conversation from that point. Confirms with a preview, then creates a new session branching from that message.Also fixes
n/pnavigation — the old pattern searched for the never-presentYou:instead of setext headings — and recenters the heading to the top of the window.How it works
get_treeRPC)y-or-n-p, then fork via the existingforkRPCUpstream enhancements that would simplify this
The main complexity here is mapping a buffer position to an entry ID. We render user turns from
get_messages, but forking requires an entry ID fromget_tree— two different RPCs with no shared identifiers. This forces us to:Two possible upstream improvements:
Include
entryIdinget_messagesresponses. If each message carried its entry ID, fork-at-point would be a single lookup — no tree walk, no alignment heuristic.A
fork_at_indexRPC that accepts a 0-based user turn index (from the active branch) instead of an entry ID. The server already knows the active branch and could resolve the index internally.Either would eliminate
flatten-tree,active-branch-user-ids,resolve-fork-entry, and the last-N alignment logic (~50 lines of production code and ~20 tests).