Skip to content

Commit 1841334

Browse files
committed
Plan mode: Build Fast & Build Max buttons!
1 parent 4358991 commit 1841334

4 files changed

Lines changed: 113 additions & 2 deletions

File tree

cli/src/chat.tsx

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useShallow } from 'zustand/react/shallow'
88

99
import { routeUserPrompt } from './commands/router'
1010
import { AgentModeToggle } from './components/agent-mode-toggle'
11+
import { BuildModeButtons } from './components/build-mode-buttons'
1112
import { LoginModal } from './components/login-modal'
1213
import {
1314
MultilineInput,
@@ -302,7 +303,10 @@ export const App = ({
302303
isChainInProgress,
303304
setIsChainInProgress,
304305
agentMode,
306+
setAgentMode,
305307
toggleAgentMode,
308+
hasReceivedPlanResponse,
309+
setHasReceivedPlanResponse,
306310
resetChatStore,
307311
} = useChatStore(
308312
useShallow((store) => ({
@@ -327,7 +331,10 @@ export const App = ({
327331
isChainInProgress: store.isChainInProgress,
328332
setIsChainInProgress: store.setIsChainInProgress,
329333
agentMode: store.agentMode,
334+
setAgentMode: store.setAgentMode,
330335
toggleAgentMode: store.toggleAgentMode,
336+
hasReceivedPlanResponse: store.hasReceivedPlanResponse,
337+
setHasReceivedPlanResponse: store.setHasReceivedPlanResponse,
331338
resetChatStore: store.reset,
332339
})),
333340
)
@@ -555,7 +562,7 @@ export const App = ({
555562

556563
const hasModifier = Boolean(key.ctrl || key.meta || key.alt || key.option)
557564

558-
function selectCurrent() {
565+
function selectCurrent(): boolean {
559566
const selected = slashMatches[slashSelectedIndex] ?? slashMatches[0]
560567
if (!selected) {
561568
return
@@ -574,6 +581,7 @@ export const App = ({
574581
helpers.setValue(newValue)
575582
helpers.setCursorPosition(before.length + replacement.length)
576583
setSlashSelectedIndex(0)
584+
return true
577585
}
578586

579587
if (key.name === 'down' && !hasModifier) {
@@ -640,7 +648,7 @@ export const App = ({
640648

641649
const hasModifier = Boolean(key.ctrl || key.meta || key.alt || key.option)
642650

643-
function selectCurrent() {
651+
function selectCurrent(): boolean {
644652
const selected = agentMatches[agentSelectedIndex] ?? agentMatches[0]
645653
if (!selected) {
646654
return
@@ -660,6 +668,7 @@ export const App = ({
660668
helpers.setValue(newValue)
661669
helpers.setCursorPosition(before.length + replacement.length)
662670
setAgentSelectedIndex(0)
671+
return true
663672
}
664673

665674
if (key.name === 'down' && !hasModifier) {
@@ -806,6 +815,7 @@ export const App = ({
806815
scrollToLatest,
807816
availableWidth: separatorWidth,
808817
onTimerEvent: handleTimerEvent,
818+
setHasReceivedPlanResponse,
809819
})
810820

811821
sendMessageRef.current = sendMessage
@@ -872,6 +882,28 @@ export const App = ({
872882
],
873883
)
874884

885+
const handleBuildFast = useCallback(() => {
886+
setAgentMode('FAST')
887+
setInputValue('Build it!')
888+
setTimeout(() => {
889+
if (sendMessageRef.current) {
890+
sendMessageRef.current({ content: 'Build it!', agentMode: 'FAST' })
891+
}
892+
setInputValue('')
893+
}, 0)
894+
}, [setAgentMode, setInputValue])
895+
896+
const handleBuildMax = useCallback(() => {
897+
setAgentMode('MAX')
898+
setInputValue('Build it!')
899+
setTimeout(() => {
900+
if (sendMessageRef.current) {
901+
sendMessageRef.current({ content: 'Build it!', agentMode: 'MAX' })
902+
}
903+
setInputValue('')
904+
}, 0)
905+
}, [setAgentMode, setInputValue])
906+
875907
useKeyboardHandlers({
876908
isStreaming,
877909
isWaitingForResponse,
@@ -1154,6 +1186,13 @@ export const App = ({
11541186
</box>
11551187
)}
11561188
<Separator theme={theme} width={separatorWidth} />
1189+
{agentMode === 'PLAN' && hasReceivedPlanResponse && (
1190+
<BuildModeButtons
1191+
theme={theme}
1192+
onBuildFast={handleBuildFast}
1193+
onBuildMax={handleBuildMax}
1194+
/>
1195+
)}
11571196
{slashContext.active && slashSuggestionItems.length > 0 ? (
11581197
<SuggestionMenu
11591198
items={slashSuggestionItems}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type { ChatTheme } from '../types/theme-system'
2+
3+
export const BuildModeButtons = ({
4+
theme,
5+
onBuildFast,
6+
onBuildMax,
7+
}: {
8+
theme: ChatTheme
9+
onBuildFast: () => void
10+
onBuildMax: () => void
11+
}) => {
12+
return (
13+
<box
14+
style={{
15+
flexDirection: 'row',
16+
gap: 2,
17+
paddingTop: 1,
18+
paddingBottom: 1,
19+
paddingLeft: 1,
20+
}}
21+
>
22+
<box
23+
style={{
24+
flexDirection: 'row',
25+
alignItems: 'center',
26+
backgroundColor: '#0a6515',
27+
paddingLeft: 2,
28+
paddingRight: 2,
29+
}}
30+
onMouseDown={onBuildFast}
31+
>
32+
<text wrap={false}>
33+
<span fg="#ffffff">Build Fast</span>
34+
</text>
35+
</box>
36+
<box
37+
style={{
38+
flexDirection: 'row',
39+
alignItems: 'center',
40+
backgroundColor: '#ac1626',
41+
paddingLeft: 2,
42+
paddingRight: 2,
43+
}}
44+
onMouseDown={onBuildMax}
45+
>
46+
<text wrap={false}>
47+
<span fg="#ffffff">Build Max</span>
48+
</text>
49+
</box>
50+
</box>
51+
)
52+
}

cli/src/hooks/use-send-message.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ interface UseSendMessageOptions {
164164
scrollToLatest: () => void
165165
availableWidth?: number
166166
onTimerEvent?: (event: SendMessageTimerEvent) => void
167+
setHasReceivedPlanResponse: (value: boolean) => void
167168
}
168169

169170
export const useSendMessage = ({
@@ -189,6 +190,7 @@ export const useSendMessage = ({
189190
scrollToLatest,
190191
availableWidth = 80,
191192
onTimerEvent = () => {},
193+
setHasReceivedPlanResponse,
192194
}: UseSendMessageOptions): {
193195
sendMessage: SendMessageFn
194196
clearMessages: () => void
@@ -325,6 +327,10 @@ export const useSendMessage = ({
325327
const { content, agentMode, postUserMessage } = params
326328
const timestamp = formatTimestamp()
327329

330+
if (agentMode !== 'PLAN') {
331+
setHasReceivedPlanResponse(false)
332+
}
333+
328334
const timerController = createSendMessageTimerController({
329335
mainAgentTimer,
330336
onTimerEvent,
@@ -1373,6 +1379,10 @@ export const useSendMessage = ({
13731379
setIsWaitingForResponse(false)
13741380
const timerResult = timerController.stop('success')
13751381

1382+
if (agentMode === 'PLAN') {
1383+
setHasReceivedPlanResponse(true)
1384+
}
1385+
13761386
if ((result as any)?.credits !== undefined) {
13771387
actualCredits = (result as any).credits
13781388
}
@@ -1486,6 +1496,7 @@ export const useSendMessage = ({
14861496
mainAgentTimer,
14871497
scrollToLatest,
14881498
availableWidth,
1499+
setHasReceivedPlanResponse,
14891500
],
14901501
)
14911502

cli/src/state/chat-store.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type ChatStoreState = {
1717
slashSelectedIndex: number
1818
agentSelectedIndex: number
1919
agentMode: AgentMode
20+
hasReceivedPlanResponse: boolean
2021
}
2122

2223
type ChatStoreActions = {
@@ -42,6 +43,7 @@ type ChatStoreActions = {
4243
setAgentSelectedIndex: (value: number | ((prev: number) => number)) => void
4344
setAgentMode: (mode: AgentMode) => void
4445
toggleAgentMode: () => void
46+
setHasReceivedPlanResponse: (value: boolean) => void
4547
reset: () => void
4648
}
4749

@@ -61,6 +63,7 @@ const initialState: ChatStoreState = {
6163
slashSelectedIndex: 0,
6264
agentSelectedIndex: 0,
6365
agentMode: 'FAST',
66+
hasReceivedPlanResponse: false,
6467
}
6568

6669
export const useChatStore = create<ChatStore>()(
@@ -141,6 +144,11 @@ export const useChatStore = create<ChatStore>()(
141144
}
142145
}),
143146

147+
setHasReceivedPlanResponse: (value) =>
148+
set((state) => {
149+
state.hasReceivedPlanResponse = value
150+
}),
151+
144152
reset: () =>
145153
set((state) => {
146154
state.messages = initialState.messages.slice()
@@ -154,6 +162,7 @@ export const useChatStore = create<ChatStore>()(
154162
state.slashSelectedIndex = initialState.slashSelectedIndex
155163
state.agentSelectedIndex = initialState.agentSelectedIndex
156164
state.agentMode = initialState.agentMode
165+
state.hasReceivedPlanResponse = initialState.hasReceivedPlanResponse
157166
}),
158167
})),
159168
)

0 commit comments

Comments
 (0)