Skip to content

Commit fa29abd

Browse files
committed
Support mode cli args
1 parent bd4e8be commit fa29abd

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

cli/src/app.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { openFileAtPath } from './utils/open-file'
2121

2222
import type { MultilineInputHandle } from './components/multiline-input'
2323
import type { AuthStatus } from './utils/status-indicator-state'
24+
import type { AgentMode } from './utils/constants'
2425
import type { FileTreeNode } from '@codebuff/common/util/file'
2526

2627
interface AppProps {
@@ -31,6 +32,7 @@ interface AppProps {
3132
fileTree: FileTreeNode[]
3233
continueChat: boolean
3334
continueChatId?: string
35+
initialMode?: AgentMode
3436
}
3537

3638
export const App = ({
@@ -41,6 +43,7 @@ export const App = ({
4143
fileTree,
4244
continueChat,
4345
continueChatId,
46+
initialMode,
4447
}: AppProps) => {
4548
const { contentMaxWidth, terminalWidth } = useTerminalDimensions()
4649
const theme = useTheme()
@@ -194,6 +197,7 @@ export const App = ({
194197
continueChat={continueChat}
195198
continueChatId={continueChatId}
196199
authStatus={authStatus}
200+
initialMode={initialMode}
197201
/>
198202
)
199203
}

cli/src/chat.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export const Chat = ({
9292
continueChat,
9393
continueChatId,
9494
authStatus,
95+
initialMode,
9596
}: {
9697
headerContent: React.ReactNode
9798
initialPrompt: string | null
@@ -104,6 +105,7 @@ export const Chat = ({
104105
continueChat: boolean
105106
continueChatId?: string
106107
authStatus: AuthStatus
108+
initialMode?: AgentMode
107109
}) => {
108110
const scrollRef = useRef<ScrollBoxRenderable | null>(null)
109111
const [hasOverflow, setHasOverflow] = useState(false)
@@ -229,6 +231,13 @@ export const Chat = ({
229231
const mainAgentTimer = useElapsedTime()
230232
const timerStartTime = mainAgentTimer.startTime
231233

234+
// Set initial mode from CLI flag on mount
235+
useEffect(() => {
236+
if (initialMode) {
237+
setAgentMode(initialMode)
238+
}
239+
}, [initialMode, setAgentMode])
240+
232241
// Sync refs with state
233242
useEffect(() => {
234243
isChainInProgressRef.current = isChainInProgress

cli/src/index.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { detectTerminalTheme } from './utils/terminal-color-detection'
2828
import { setOscDetectedTheme } from './utils/theme-system'
2929

3030
import type { FileTreeNode } from '@codebuff/common/util/file'
31+
import type { AgentMode } from './utils/constants'
3132

3233
const require = createRequire(import.meta.url)
3334

@@ -82,6 +83,7 @@ type ParsedArgs = {
8283
continue: boolean
8384
continueId?: string | null
8485
cwd?: string
86+
initialMode?: AgentMode
8587
}
8688

8789
function parseArgs(): ParsedArgs {
@@ -104,6 +106,9 @@ function parseArgs(): ParsedArgs {
104106
'--cwd <directory>',
105107
'Set the working directory (default: current directory)',
106108
)
109+
.option('--lite', 'Start in LITE mode')
110+
.option('--max', 'Start in MAX mode')
111+
.option('--plan', 'Start in PLAN mode')
107112
.helpOption('-h, --help', 'Show this help message')
108113
.argument('[prompt...]', 'Initial prompt to send to the agent')
109114
.allowExcessArguments(true)
@@ -114,6 +119,12 @@ function parseArgs(): ParsedArgs {
114119

115120
const continueFlag = options.continue
116121

122+
// Determine initial mode from flags (last flag wins if multiple specified)
123+
let initialMode: AgentMode | undefined
124+
if (options.lite) initialMode = 'LITE'
125+
if (options.max) initialMode = 'MAX'
126+
if (options.plan) initialMode = 'PLAN'
127+
117128
return {
118129
initialPrompt: args.length > 0 ? args.join(' ') : null,
119130
agent: options.agent,
@@ -124,6 +135,7 @@ function parseArgs(): ParsedArgs {
124135
? continueFlag.trim()
125136
: null,
126137
cwd: options.cwd,
138+
initialMode,
127139
}
128140
}
129141

@@ -149,6 +161,7 @@ async function main(): Promise<void> {
149161
continue: continueChat,
150162
continueId,
151163
cwd,
164+
initialMode,
152165
} = parseArgs()
153166

154167
await initializeApp({ cwd })
@@ -245,6 +258,7 @@ async function main(): Promise<void> {
245258
fileTree={fileTree}
246259
continueChat={continueChat}
247260
continueChatId={continueId ?? undefined}
261+
initialMode={initialMode}
248262
/>
249263
)
250264
}

0 commit comments

Comments
 (0)