@@ -20,7 +20,6 @@ import {
2020 formatAskUserQuestionAnswers ,
2121} from "../core/ask-user-question" ;
2222import { PermissionPrompt , type PermissionPromptResult } from "./PermissionPrompt" ;
23- import { PlanImplementationPrompt , extractProposedPlan , getImplementationPrompt } from "./PlanImplementationPrompt" ;
2423import { buildExitSummaryText , buildResumeHintText } from "../exit-summary" ;
2524import { RawMode , useRawModeContext } from "../contexts" ;
2625import { renderMessageToStdout } from "../components/MessageView/utils" ;
@@ -134,8 +133,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
134133 const [ nowTick , setNowTick ] = useState ( 0 ) ;
135134 const [ mcpStatuses , setMcpStatuses ] = useState < ReturnType < typeof sessionManager . getMcpStatus > > ( [ ] ) ;
136135 const [ showProcessStdout , setShowProcessStdout ] = useState ( false ) ;
137- const [ planMode , setPlanMode ] = useState ( false ) ;
138- const [ pendingPlanImplementation , setPendingPlanImplementation ] = useState < string | null > ( null ) ;
139136
140137 rawModeRef . current = mode ;
141138 messagesRef . current = messages ;
@@ -256,8 +253,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
256253 setActiveStatus ( null ) ;
257254 setActiveAskPermissions ( undefined ) ;
258255 setPendingPermissionReply ( null ) ;
259- setPlanMode ( false ) ;
260- setPendingPlanImplementation ( null ) ;
261256 setDismissedQuestionIds ( new Set ( ) ) ;
262257 await resetStaticView ( [ ] ) ;
263258 await refreshSkills ( ) ;
@@ -366,6 +361,55 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
366361 navigateToSubView ( "mcp-status" ) ;
367362 return ;
368363 }
364+ if ( submission . command === "compact" ) {
365+ const activeSessionId = sessionManager . getActiveSessionId ( ) ;
366+ if ( ! activeSessionId ) {
367+ setErrorLine ( "No active session to compact." ) ;
368+ return ;
369+ }
370+ setBusy ( true ) ;
371+ sessionManager . addSessionSystemMessage (
372+ activeSessionId ,
373+ "Compacting conversation context to reduce token usage..." ,
374+ true ,
375+ { asThinking : true }
376+ ) ;
377+ sessionManager . compactSession ( activeSessionId ) . then ( ( ) => {
378+ setBusy ( false ) ;
379+ refreshSessionsList ( ) ;
380+ } ) . catch ( ( err ) => {
381+ setBusy ( false ) ;
382+ setErrorLine ( `Compact failed: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
383+ } ) ;
384+ return ;
385+ }
386+ if ( submission . command === "context" ) {
387+ const sessionInfo = getSessionInfo ( ) ;
388+ if ( ! sessionInfo || ! sessionInfo . activeSessionId ) {
389+ setErrorLine ( "No active session." ) ;
390+ return ;
391+ }
392+ const pct = sessionInfo . maxContextTokens > 0
393+ ? Math . round ( ( sessionInfo . activeTokens / sessionInfo . maxContextTokens ) * 100 )
394+ : 0 ;
395+ const summary = [
396+ `Model: ${ sessionInfo . model } ` ,
397+ `Messages: ${ sessionInfo . messageCount } ` ,
398+ `API requests: ${ sessionInfo . requestCount } ` ,
399+ `Active tokens: ${ sessionInfo . activeTokens . toLocaleString ( ) } / ${ sessionInfo . maxContextTokens . toLocaleString ( ) } (${ pct } %)` ,
400+ `Total tokens used: ${ sessionInfo . totalTokens . toLocaleString ( ) } ` ,
401+ ] ;
402+ if ( Object . keys ( sessionInfo . toolUsage ) . length > 0 ) {
403+ const tools = Object . entries ( sessionInfo . toolUsage )
404+ . sort ( ( [ , a ] , [ , b ] ) => b - a )
405+ . slice ( 0 , 5 )
406+ . map ( ( [ name , count ] ) => ` ${ name } : ${ count } x` )
407+ . join ( "\n" ) ;
408+ summary . push ( `\nTop tools:\n${ tools } ` ) ;
409+ }
410+ sessionManager . addSessionSystemMessage ( sessionInfo . activeSessionId , summary . join ( "\n" ) , true , { asThinking : true } ) ;
411+ return ;
412+ }
369413
370414 const prompt : UserPromptContent = {
371415 text : submission . text ,
@@ -374,7 +418,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
374418 submission . selectedSkills && submission . selectedSkills . length > 0 ? submission . selectedSkills : undefined ,
375419 permissions : submission . permissions ,
376420 alwaysAllows : submission . alwaysAllows ,
377- planMode : submission . planMode ?? planMode ,
378421 } ;
379422 const activeSessionId = sessionManager . getActiveSessionId ( ) ;
380423 const permissionReply =
@@ -410,12 +453,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
410453 }
411454 await refreshSkills ( ) ;
412455 refreshSessionsList ( ) ;
413- const completedSession = sessionManager . getSession ( sessionManager . getActiveSessionId ( ) ?? "" ) ;
414- const proposedPlan =
415- prompt . planMode && completedSession ?. status === "completed"
416- ? extractProposedPlan ( completedSession . assistantReply )
417- : null ;
418- setPendingPlanImplementation ( proposedPlan ) ;
419456 } catch ( error ) {
420457 const message = error instanceof Error ? error . message : String ( error ) ;
421458 setErrorLine ( message ) ;
@@ -437,7 +474,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
437474 refreshSessionsList ,
438475 navigateToSubView ,
439476 resetToWelcome ,
440- planMode ,
441477 ]
442478 ) ;
443479
@@ -509,25 +545,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
509545 [ handlePrompt ]
510546 ) ;
511547
512- const handlePlanImplementationChoice = useCallback (
513- ( choice : "implement" | "stay" | "default" ) => {
514- const proposedPlan = pendingPlanImplementation ;
515- setPendingPlanImplementation ( null ) ;
516- if ( choice === "stay" ) {
517- return ;
518- }
519- setPlanMode ( false ) ;
520- if ( choice === "implement" && proposedPlan ) {
521- handleSubmit ( {
522- text : getImplementationPrompt ( proposedPlan ) ,
523- imageUrls : [ ] ,
524- planMode : false ,
525- } ) ;
526- }
527- } ,
528- [ handleSubmit , pendingPlanImplementation ]
529- ) ;
530-
531548 const handleExitShortcut = useCallback ( ( ) => {
532549 handleExit ( { showCommand : false , showSummary : false } ) ;
533550 } , [ handleExit ] ) ;
@@ -549,8 +566,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
549566 setRunningProcesses ( session ?. processes ?? null ) ;
550567 setActiveStatus ( session ?. status ?? null ) ;
551568 setActiveAskPermissions ( session ?. askPermissions ) ;
552- setPlanMode ( session ?. planMode === true ) ;
553- setPendingPlanImplementation ( null ) ;
554569 if ( pendingPermissionReply && pendingPermissionReply . sessionId !== sessionId ) {
555570 setPendingPermissionReply ( null ) ;
556571 }
@@ -999,8 +1014,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
9991014 onSubmit = { handlePermissionResult }
10001015 onCancel = { handlePermissionCancel }
10011016 />
1002- ) : pendingPlanImplementation && ! busy ? (
1003- < PlanImplementationPrompt onSelect = { handlePlanImplementationChoice } />
10041017 ) : isExiting ? null : (
10051018 < PromptInput
10061019 projectRoot = { projectRoot }
@@ -1022,8 +1035,6 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
10221035 placeholder = "Type your message..."
10231036 statusLineSegments = { statusLineSegments }
10241037 statusLineSeparator = { resolvedSettings . statusline . separator }
1025- planMode = { planMode }
1026- onPlanModeChange = { setPlanMode }
10271038 />
10281039 ) }
10291040 </ Box >
0 commit comments