mirror of
https://github.com/wu736139669/hapi.git
synced 2026-08-05 06:24:37 +00:00
fix(cli): preserve invoked cwd for local launcher (#299)
This commit is contained in:
@@ -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
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user