Skip to content

Commit 4a85ab2

Browse files
committed
refactor(cli): Remove debug logger statements
Clean up debug logging in hooks: - Remove mock mode and streaming logs from use-send-message - Remove theme change event logs from use-system-theme-detector - Add project-files.ts for logger utilities These logs were used for development debugging and are no longer needed.
1 parent 53022f9 commit 4a85ab2

File tree

3 files changed

+47
-67
lines changed

3 files changed

+47
-67
lines changed

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

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import type { ChatMessage, ContentBlock } from '../chat'
1010
import type { AgentDefinition, ToolName } from '@codebuff/sdk'
1111
import type { SetStateAction } from 'react'
1212

13-
const completionMessages = [
14-
'All changes have been applied successfully.',
15-
'Implementation complete. Ready for your next request.',
16-
'Done! All requested modifications are in place.',
17-
'Changes completed and verified.',
18-
'Finished! Everything is working as expected.',
19-
'All tasks completed successfully.',
20-
'Implementation finished. All systems go!',
21-
'Done! All updates have been applied.',
22-
]
23-
2413
const hiddenToolNames = new Set<ToolName | 'spawn_agent_inline'>([
2514
'spawn_agent_inline',
2615
'end_turn',
@@ -279,56 +268,7 @@ export const useSendMessage = ({
279268
const client = getCodebuffClient()
280269

281270
if (!client) {
282-
logger.info({}, 'No API client available, using mock mode')
283-
const aiMessageId = `ai-${Date.now()}-${Math.random().toString(16).slice(2)}`
284-
const aiMessage: ChatMessage = {
285-
id: aiMessageId,
286-
variant: 'ai',
287-
content: '',
288-
timestamp: formatTimestamp(),
289-
}
290-
291-
applyMessageUpdate((prev) => [...prev, aiMessage])
292-
293-
const fullResponse = `I've reviewed your message. Let me help with that.\n\n## Analysis\n\nBased on your request, here are the key points:\n\n1. **Architecture**: The current structure is well-organized\n2. **Performance**: Consider adding memoization for expensive calculations\n3. **Testing**: Add unit tests using \`bun:test\`\n\n### Code Example\n\n\`\`\`typescript\n// Add this optimization\nconst memoized = useMemo(() => {\n return expensiveCalculation(data)\n}, [data])\n\`\`\`\n\nThis approach will improve _performance_ while maintaining **code clarity**.`
294-
295-
const tokens = fullResponse.split(/(\s+)/)
296-
let index = 0
297-
const interval = setInterval(() => {
298-
if (index >= tokens.length) {
299-
clearInterval(interval)
300-
stopStreaming()
301-
302-
const completionMessageId = `ai-${Date.now()}-${Math.random().toString(16).slice(2)}`
303-
const completionMessage: ChatMessage = {
304-
id: completionMessageId,
305-
variant: 'ai',
306-
content:
307-
completionMessages[
308-
Math.floor(Math.random() * completionMessages.length)
309-
],
310-
timestamp: formatTimestamp(),
311-
isCompletion: true,
312-
credits: Math.floor(Math.random() * (230 - 18 + 1)) + 18,
313-
}
314-
applyMessageUpdate((prev) => [...prev, completionMessage])
315-
return
316-
}
317-
318-
const nextChunk = tokens[index]
319-
index++
320-
321-
queueMessageUpdate((prev) =>
322-
prev.map((msg) =>
323-
msg.id === aiMessageId
324-
? { ...msg, content: msg.content + nextChunk }
325-
: msg,
326-
),
327-
)
328-
}, 28)
329-
330-
logger.info({}, 'Starting mock response streaming')
331-
startStreaming()
271+
logger.error({}, 'No Codebuff client available. Please ensure you are authenticated.')
332272
return
333273
}
334274

@@ -540,7 +480,7 @@ export const useSendMessage = ({
540480
)
541481
}
542482

543-
logger.info('Initiating SDK client.run()')
483+
544484
setIsWaitingForResponse(true)
545485
applyMessageUpdate((prev) => [...prev, aiMessage])
546486
setIsStreaming(true)

cli/src/hooks/use-system-theme-detector.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,9 @@ export const useSystemThemeDetector = (): ThemeName => {
3030
const currentTheme = detectSystemTheme()
3131

3232
if (currentTheme !== lastThemeRef.current) {
33-
logger.info(
34-
{},
35-
`[theme] theme changed ${lastThemeRef.current} -> ${currentTheme}`,
36-
)
33+
3734
} else {
38-
logger.info({}, '[theme] theme change event with no delta')
35+
3936
}
4037

4138
// Only update state if theme actually changed

cli/src/project-files.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { mkdirSync } from 'fs'
2+
import path from 'path'
3+
4+
import { findGitRoot } from './utils/git'
5+
6+
let projectRoot: string | undefined
7+
let currentChatId: string | undefined
8+
9+
function ensureChatDirectory(dir: string) {
10+
mkdirSync(dir, { recursive: true })
11+
}
12+
13+
export function setProjectRoot(dir: string) {
14+
projectRoot = dir
15+
return projectRoot
16+
}
17+
18+
export function getProjectRoot() {
19+
if (!projectRoot) {
20+
projectRoot = findGitRoot()
21+
}
22+
return projectRoot
23+
}
24+
25+
export function getCurrentChatId() {
26+
if (!currentChatId) {
27+
currentChatId = new Date().toISOString().replace(/:/g, '-')
28+
}
29+
return currentChatId
30+
}
31+
32+
export function startNewChat() {
33+
currentChatId = new Date().toISOString().replace(/:/g, '-')
34+
return currentChatId
35+
}
36+
37+
export function getCurrentChatDir() {
38+
const root = getProjectRoot() || process.cwd()
39+
const chatId = getCurrentChatId()
40+
const dir = path.join(root, 'debug', 'chats', chatId)
41+
ensureChatDirectory(dir)
42+
return dir
43+
}

0 commit comments

Comments
 (0)