@@ -9,14 +9,10 @@ import { validateAgents } from '@codebuff/sdk'
99import { render } from '@opentui/react'
1010import { QueryClient , QueryClientProvider } from '@tanstack/react-query'
1111import { Command } from 'commander'
12- import { enableMapSet } from 'immer'
1312import React from 'react'
1413
15- // Enable Map and Set support in Immer globally (once at app initialization)
16- enableMapSet ( )
17-
1814import { App } from './app'
19- import { initializeThemeStore } from './hooks/use-theme '
15+ import { initializeApp } from './init/init-app '
2016import { getProjectRoot } from './project-files'
2117import { getUserCredentials } from './utils/auth'
2218import { loadAgentDefinitions } from './utils/load-agent-definitions'
@@ -28,58 +24,11 @@ import type { FileTreeNode } from '@codebuff/common/util/file'
2824const require = createRequire ( import . meta. url )
2925
3026const INTERNAL_OSC_FLAG = '--internal-osc-detect'
31- const OSC_DEBUG_ENABLED = process . env . CODEBUFF_OSC_DEBUG === '1'
32-
33- function logOscDebug ( message : string , data ?: Record < string , unknown > ) {
34- if ( ! OSC_DEBUG_ENABLED ) return
35- const payload = data ? ` ${ JSON . stringify ( data ) } ` : ''
36- console . error ( `[osc:subprocess] ${ message } ${ payload } ` )
37- }
3827
3928function isOscDetectionRun ( ) : boolean {
4029 return process . argv . includes ( INTERNAL_OSC_FLAG )
4130}
4231
43- async function runOscDetectionSubprocess ( ) : Promise < void > {
44- // Set env vars to keep subprocess quiet
45- process . env . __INTERNAL_OSC_DETECT = '1'
46- process . env . CODEBUFF_GITHUB_ACTIONS = 'true'
47- if ( process . env . CODEBUFF_OSC_DEBUG === undefined ) {
48- process . env . CODEBUFF_OSC_DEBUG = '1'
49- }
50- logOscDebug ( 'Starting OSC detection flag run' )
51-
52- // Avoid importing logger or other modules that produce output
53- const { detectTerminalTheme, terminalSupportsOSC } = await import (
54- './utils/terminal-color-detection'
55- )
56-
57- const oscSupported = terminalSupportsOSC ( )
58- logOscDebug ( 'terminalSupportsOSC result' , { oscSupported } )
59-
60- if ( ! oscSupported ) {
61- logOscDebug ( 'Terminal does not support OSC queries, returning null theme' )
62- console . log ( JSON . stringify ( { theme : null } ) )
63- await new Promise ( ( resolve ) => setImmediate ( resolve ) )
64- process . exit ( 0 )
65- }
66-
67- try {
68- const theme = await detectTerminalTheme ( )
69- logOscDebug ( 'detectTerminalTheme resolved' , { theme } )
70- console . log ( JSON . stringify ( { theme } ) )
71- await new Promise ( ( resolve ) => setImmediate ( resolve ) )
72- } catch ( error ) {
73- logOscDebug ( 'detectTerminalTheme threw' , {
74- error : error instanceof Error ? error . message : String ( error ) ,
75- } )
76- console . log ( JSON . stringify ( { theme : null } ) )
77- await new Promise ( ( resolve ) => setImmediate ( resolve ) )
78- }
79-
80- process . exit ( 0 )
81- }
82-
8332function loadPackageVersion ( ) : string {
8433 if ( process . env . CODEBUFF_CLI_VERSION ) {
8534 return process . env . CODEBUFF_CLI_VERSION
@@ -97,8 +46,6 @@ function loadPackageVersion(): string {
9746 return 'dev'
9847}
9948
100- const VERSION = loadPackageVersion ( )
101-
10249function createQueryClient ( ) : QueryClient {
10350 return new QueryClient ( {
10451 defaultOptions : {
@@ -131,7 +78,7 @@ function parseArgs(): ParsedArgs {
13178 program
13279 . name ( 'codebuff' )
13380 . description ( 'Codebuff CLI - AI-powered coding assistant' )
134- . version ( VERSION , '-v, --version' , 'Print the CLI version' )
81+ . version ( loadPackageVersion ( ) , '-v, --version' , 'Print the CLI version' )
13582 . option (
13683 '--agent <agent-id>' ,
13784 'Specify which agent to use (e.g., "base", "ask", "file-picker")' ,
@@ -163,7 +110,7 @@ function parseArgs(): ParsedArgs {
163110 }
164111}
165112
166- async function bootstrapCli ( ) : Promise < void > {
113+ async function main ( ) : Promise < void > {
167114 const {
168115 initialPrompt,
169116 agent,
@@ -172,7 +119,7 @@ async function bootstrapCli(): Promise<void> {
172119 continueId,
173120 } = parseArgs ( )
174121
175- initializeThemeStore ( )
122+ await initializeApp ( { isOscDetectionRun : isOscDetectionRun ( ) } )
176123
177124 if ( clearLogs ) {
178125 clearLogFile ( )
@@ -236,7 +183,6 @@ async function bootstrapCli(): Promise<void> {
236183 } , [ ] )
237184
238185 return (
239- // Hi!
240186 < App
241187 initialPrompt = { initialPrompt }
242188 agentId = { agent }
@@ -262,13 +208,4 @@ async function bootstrapCli(): Promise<void> {
262208 )
263209}
264210
265- async function main ( ) : Promise < void > {
266- if ( isOscDetectionRun ( ) ) {
267- await runOscDetectionSubprocess ( )
268- return
269- }
270-
271- await bootstrapCli ( )
272- }
273-
274211void main ( )
0 commit comments