11/**
2- * Recap extension - summarize and roll back the session tree
2+ * Fold extension - summarize and roll back the session tree
33 *
44 * Commands:
5- * /recap - Summarize the conversation and navigate back to a clean starting point
5+ * /fold - Summarize the conversation and navigate back to a clean starting point
66 *
7- * Recap generates a summary of the current conversation branch, then navigates
8- * the session tree back to the beginning (or the last recap point), using the
7+ * Fold generates a summary of the current conversation branch, then navigates
8+ * the session tree back to the beginning (or the last fold point), using the
99 * generated summary as the branch summary.
1010 *
1111 * The editor is left empty for the user to type their next prompt.
1212 *
1313 * Usage:
14- * /recap
14+ * /fold
1515 */
1616
1717import { complete , type Message } from "@mariozechner/pi-ai" ;
1818import type { ExtensionAPI , SessionEntry } from "@mariozechner/pi-coding-agent" ;
1919import { convertToLlm , serializeConversation } from "@mariozechner/pi-coding-agent" ;
2020
21- const RECAP_SYSTEM_PROMPT = `You are a context summarization assistant. Given a conversation history, generate a concise summary that captures:
21+ const FOLD_SYSTEM_PROMPT = `You are a context summarization assistant. Given a conversation history, generate a concise summary that captures:
2222
23231. Relevant context from the conversation (decisions made, approaches taken, key findings)
24242. Any relevant files that were discussed or modified
@@ -40,22 +40,22 @@ We've been working on X. Key decisions:
4040[What's been accomplished and what remains]` ;
4141
4242export default function ( pi : ExtensionAPI ) {
43- let pendingRecapSummary : string | null = null ;
43+ let pendingFoldSummary : string | null = null ;
4444
45- // Intercept tree navigation to provide custom summary when recapping
45+ // Intercept tree navigation to provide custom summary when folding
4646 pi . on ( "session_before_tree" , async ( _event , _ctx ) => {
47- if ( pendingRecapSummary !== null ) {
48- const summary = pendingRecapSummary ;
49- pendingRecapSummary = null ;
47+ if ( pendingFoldSummary !== null ) {
48+ const summary = pendingFoldSummary ;
49+ pendingFoldSummary = null ;
5050 return { summary : { summary, details : { } } } ;
5151 }
5252 } ) ;
5353
54- pi . registerCommand ( "recap " , {
54+ pi . registerCommand ( "fold " , {
5555 description : "Summarize conversation and roll back to a clean starting point" ,
5656 handler : async ( _args , ctx ) => {
5757 if ( ! ctx . hasUI ) {
58- ctx . ui . notify ( "recap requires interactive mode" , "error" ) ;
58+ ctx . ui . notify ( "fold requires interactive mode" , "error" ) ;
5959 return ;
6060 }
6161
@@ -64,13 +64,13 @@ export default function (pi: ExtensionAPI) {
6464 return ;
6565 }
6666
67- // Find anchor: last recap marker or first entry
67+ // Find anchor: last fold marker or first entry
6868 const branch = ctx . sessionManager . getBranch ( ) ;
6969 let anchorId : string | undefined ;
7070
7171 for ( const entry of branch ) {
7272 const label = ctx . sessionManager . getLabel ( entry . id ) ;
73- if ( label === "recap " ) {
73+ if ( label === "fold " ) {
7474 anchorId = entry . id ;
7575 }
7676 }
@@ -81,7 +81,7 @@ export default function (pi: ExtensionAPI) {
8181 }
8282
8383 if ( ! anchorId ) {
84- ctx . ui . notify ( "No conversation to recap " , "error" ) ;
84+ ctx . ui . notify ( "No conversation to fold " , "error" ) ;
8585 return ;
8686 }
8787
@@ -93,16 +93,16 @@ export default function (pi: ExtensionAPI) {
9393 . map ( ( entry ) => entry . message ) ;
9494
9595 if ( messages . length === 0 ) {
96- ctx . ui . notify ( "No conversation to recap " , "error" ) ;
96+ ctx . ui . notify ( "No conversation to fold " , "error" ) ;
9797 return ;
9898 }
9999
100100 // Convert to LLM format and serialize
101101 const llmMessages = convertToLlm ( messages ) ;
102102 const conversationText = serializeConversation ( llmMessages ) ;
103103
104- // Generate the recap summary (non-blocking: editor stays active)
105- ctx . ui . setWidget ( "recap " , [ ctx . ui . theme . fg ( "accent" , "● " ) + ctx . ui . theme . fg ( "muted" , "Generating recap summary..." ) ] ) ;
104+ // Generate the fold summary (non-blocking: editor stays active)
105+ ctx . ui . setWidget ( "fold " , [ ctx . ui . theme . fg ( "accent" , "● " ) + ctx . ui . theme . fg ( "muted" , "Generating fold summary..." ) ] ) ;
106106
107107 let result : string | null = null ;
108108 try {
@@ -121,7 +121,7 @@ export default function (pi: ExtensionAPI) {
121121
122122 const response = await complete (
123123 ctx . model ! ,
124- { systemPrompt : RECAP_SYSTEM_PROMPT , messages : [ userMessage ] } ,
124+ { systemPrompt : FOLD_SYSTEM_PROMPT , messages : [ userMessage ] } ,
125125 { apiKey } ,
126126 ) ;
127127
@@ -134,33 +134,33 @@ export default function (pi: ExtensionAPI) {
134134 . join ( "\n" ) ;
135135 }
136136 } catch ( err ) {
137- console . error ( "Recap generation failed:" , err ) ;
137+ console . error ( "Fold generation failed:" , err ) ;
138138 result = null ;
139139 } finally {
140- ctx . ui . setWidget ( "recap " , undefined ) ;
140+ ctx . ui . setWidget ( "fold " , undefined ) ;
141141 }
142142
143143 if ( result === null ) {
144- ctx . ui . notify ( "Recap generation failed" , "error" ) ;
144+ ctx . ui . notify ( "Fold generation failed" , "error" ) ;
145145 return ;
146146 }
147147
148148 // Store summary for session_before_tree handler
149- pendingRecapSummary = result ;
149+ pendingFoldSummary = result ;
150150
151151 // Navigate tree back to anchor with custom summary
152152 const navResult = await ctx . navigateTree ( anchorId , {
153153 summarize : true ,
154- label : "recap " ,
154+ label : "fold " ,
155155 } ) ;
156156
157157 if ( navResult . cancelled ) {
158- pendingRecapSummary = null ;
158+ pendingFoldSummary = null ;
159159 ctx . ui . notify ( "Cancelled" , "info" ) ;
160160 return ;
161161 }
162162
163- ctx . ui . notify ( "Recap complete. Ready for next task." , "info" ) ;
163+ ctx . ui . notify ( "Fold complete. Ready for next task." , "info" ) ;
164164 } ,
165165 } ) ;
166166}
0 commit comments