mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-17 13:13:35 +08:00
fix: default to user home dir when no workDir selected on new session
Previously, creating a new session without selecting a project directory defaulted to process.cwd(), which in the desktop app resolves to the app installation path. Now it defaults to os.homedir(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6aedd6eb53
commit
90b5772fb4
@ -30,8 +30,8 @@ export const sessionsApi = {
|
||||
return api.get<MessagesResponse>(`/api/sessions/${sessionId}/messages`)
|
||||
},
|
||||
|
||||
create(workDir: string) {
|
||||
return api.post<CreateSessionResponse>('/api/sessions', { workDir })
|
||||
create(workDir?: string) {
|
||||
return api.post<CreateSessionResponse>('/api/sessions', workDir ? { workDir } : {})
|
||||
},
|
||||
|
||||
delete(sessionId: string) {
|
||||
|
||||
@ -48,7 +48,7 @@ export const useSessionStore = create<SessionStore>((set, get) => ({
|
||||
},
|
||||
|
||||
createSession: async (workDir?: string) => {
|
||||
const { sessionId: id } = await sessionsApi.create(workDir ?? '.')
|
||||
const { sessionId: id } = await sessionsApi.create(workDir || undefined)
|
||||
// Refresh session list
|
||||
await get().fetchSessions()
|
||||
set({ activeSessionId: id })
|
||||
|
||||
@ -154,8 +154,8 @@ async function createSession(req: Request): Promise<Response> {
|
||||
throw ApiError.badRequest('Invalid JSON body')
|
||||
}
|
||||
|
||||
if (!body.workDir || typeof body.workDir !== 'string') {
|
||||
throw ApiError.badRequest('workDir (string) is required in request body')
|
||||
if (body.workDir && typeof body.workDir !== 'string') {
|
||||
throw ApiError.badRequest('workDir must be a string')
|
||||
}
|
||||
|
||||
const result = await sessionService.createSession(body.workDir)
|
||||
|
||||
@ -470,13 +470,12 @@ export class SessionService {
|
||||
/**
|
||||
* Create a new session file for the given working directory.
|
||||
*/
|
||||
async createSession(workDir: string): Promise<{ sessionId: string }> {
|
||||
if (!workDir) {
|
||||
throw ApiError.badRequest('workDir is required')
|
||||
}
|
||||
async createSession(workDir?: string): Promise<{ sessionId: string }> {
|
||||
// Default to user home directory when no workDir specified
|
||||
const resolvedWorkDir = workDir || os.homedir()
|
||||
|
||||
// Resolve to absolute path
|
||||
const absWorkDir = path.resolve(workDir)
|
||||
const absWorkDir = path.resolve(resolvedWorkDir)
|
||||
let stat
|
||||
try {
|
||||
stat = await fs.stat(absWorkDir)
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
|
||||
import type { ServerWebSocket } from 'bun'
|
||||
import type { ClientMessage, ServerMessage } from './events.js'
|
||||
import * as os from 'node:os'
|
||||
import {
|
||||
ConversationStartupError,
|
||||
conversationService,
|
||||
@ -152,7 +153,7 @@ async function handleUserMessage(
|
||||
message: Extract<ClientMessage, { type: 'user_message' }>
|
||||
) {
|
||||
const { sessionId } = ws.data
|
||||
let workDir = process.cwd()
|
||||
let workDir = os.homedir()
|
||||
|
||||
// Send thinking status
|
||||
sendMessage(ws, { type: 'status', state: 'thinking', verb: 'Thinking' })
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user