fix(cli): preserve invoked cwd for local launcher (#299)

This commit is contained in:
ROOOO
2026-03-17 22:55:23 +08:00
committed by GitHub
parent 1691100328
commit caa76826f4
16 changed files with 127 additions and 16 deletions
+4 -2
View File
@@ -11,6 +11,7 @@ import { getHappyCliCommand } from '@/utils/spawnHappyCLI';
import { registerKillSessionHandler } from '@/claude/registerKillSessionHandler';
import { bootstrapSession } from '@/agent/sessionFactory';
import { formatMessageWithAttachments } from '@/utils/attachmentFormatter';
import { getInvokedCwd } from '@/utils/invokedCwd';
function emitReadyIfIdle(props: {
queueSize: () => number;
@@ -28,13 +29,14 @@ export async function runAgentSession(opts: {
agentType: string;
startedBy?: 'runner' | 'terminal';
}): Promise<void> {
const workingDirectory = getInvokedCwd();
const initialState: AgentState = {
controlledByUser: false
};
const { session } = await bootstrapSession({
flavor: opts.agentType,
startedBy: opts.startedBy ?? 'terminal',
workingDirectory: process.cwd(),
workingDirectory,
agentState: initialState
});
@@ -67,7 +69,7 @@ export async function runAgentSession(opts: {
];
const agentSessionId = await backend.newSession({
cwd: process.cwd(),
cwd: workingDirectory,
mcpServers
});
+2 -1
View File
@@ -10,6 +10,7 @@ import { readSettings } from '@/persistence'
import { configuration } from '@/configuration'
import { logger } from '@/ui/logger'
import { runtimePath } from '@/projectPath'
import { getInvokedCwd } from '@/utils/invokedCwd'
import { readWorktreeEnv } from '@/utils/worktreeEnv'
import packageJson from '../../package.json'
@@ -105,7 +106,7 @@ async function reportSessionStarted(sessionId: string, metadata: Metadata): Prom
}
export async function bootstrapSession(options: SessionBootstrapOptions): Promise<SessionBootstrapResult> {
const workingDirectory = options.workingDirectory ?? process.cwd()
const workingDirectory = options.workingDirectory ?? getInvokedCwd()
const startedBy = options.startedBy ?? 'terminal'
const sessionTag = options.tag ?? randomUUID()
const agentState = options.agentState === undefined ? {} : options.agentState