pi BranchSummary 会话树导航机制解析
AI 总结
一篇技术笔记分析了 pi 的 BranchSummary 和 /tree 命令,指出它们会在 SessionTree 中导航到其他节点并留在同一会话文件中,而不是切换 Git 分支。笔记称,用户可以选择大多数条目,甚至返回到某次具体工具调用之后,并选择不摘要、标准摘要或使用自定义提示词摘要。文章将其与 Claude Code 的 /rewind 作比较,指出后者以用户查询检查点为基础,可同时恢复对话和代码状态。笔记还梳理了被放弃路径上的条目如何被收集以供摘要,以及 BranchSummaryEntry 如何被追加。
深度见解
该分析厘清了 BranchSummary 是一种用于返回早期对话状态的会话上下文导航机制,并区分了 pi 的条目级选择与可选摘要机制,以及可恢复代码状态的 Claude Code 检查点机制。
看到 BranchSummary 或者pi中对应的命令 /tree,总让人联想到git worktree,或者在git上切换分支之后摘要的感觉。但是实际上和git没有一毛钱关系。
看了一眼方法签名, 好吧原来是在 SessionTree 上面切换node。
// =========================================================================
// Tree Navigation
// =========================================================================
/**
* Navigate to a different node in the session tree.
* Unlike fork() which creates a new session file, this stays in the same file.
*
* @param targetId The entry ID to navigate to
* @param options.summarize Whether user wants to summarize abandoned branch
* @param options.customInstructions Custom instructions for summarizer
* @param options.replaceInstructions If true, customInstructions replaces the default prompt
* @param options.label Label to attach to the branch summary entry
* @returns Result with editorText (if user message) and cancelled status
*/
async navigateTree(
targetId: string,
options: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string } = {},
): Promise<{ editorText?: string; cancelled: boolean; aborted?: boolean; summaryEntry?: BranchSummaryEntry }>