generated from nhcarrigan/template
feat: add /cd command to change working directory
This commit is contained in:
@@ -11,6 +11,71 @@ export interface SlashCommand {
|
||||
execute: (args: string) => Promise<void> | void;
|
||||
}
|
||||
|
||||
async function changeDirectory(path: string): Promise<void> {
|
||||
const conversationId = get(claudeStore.activeConversationId);
|
||||
if (!conversationId) {
|
||||
claudeStore.addLine("error", "No active conversation");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!path.trim()) {
|
||||
const currentDir = get(claudeStore.currentWorkingDirectory);
|
||||
claudeStore.addLine("system", `Current directory: ${currentDir}`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
characterState.setState("thinking");
|
||||
claudeStore.addLine("system", `Changing directory to: ${path}`);
|
||||
|
||||
const currentDir = get(claudeStore.currentWorkingDirectory);
|
||||
const validatedPath = await invoke<string>("validate_directory", { path, currentDir });
|
||||
|
||||
// Capture conversation history before disconnecting
|
||||
const conversationHistory = claudeStore.getConversationHistory();
|
||||
|
||||
await invoke("stop_claude", { conversationId });
|
||||
|
||||
// Wait for clean shutdown
|
||||
await new Promise((resolve) => setTimeout(resolve, 500));
|
||||
|
||||
claudeStore.setWorkingDirectory(validatedPath);
|
||||
|
||||
setSkipNextGreeting(true);
|
||||
|
||||
await invoke("start_claude", {
|
||||
conversationId,
|
||||
options: {
|
||||
working_dir: validatedPath,
|
||||
},
|
||||
});
|
||||
|
||||
// Wait for connection to establish
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
|
||||
// Restore context if there was conversation history
|
||||
if (conversationHistory) {
|
||||
const contextMessage = `[CONTEXT RESTORATION]
|
||||
I just changed the working directory from ${currentDir} to ${validatedPath}. Here's our conversation so far:
|
||||
|
||||
${conversationHistory}
|
||||
|
||||
Please continue where we left off. You are now operating in the new directory.`;
|
||||
|
||||
await invoke("send_prompt", {
|
||||
conversationId,
|
||||
message: contextMessage,
|
||||
});
|
||||
}
|
||||
|
||||
claudeStore.addLine("system", `Changed directory to: ${validatedPath}`);
|
||||
characterState.setState("idle");
|
||||
} catch (error) {
|
||||
claudeStore.addLine("error", `Failed to change directory: ${error}`);
|
||||
characterState.setTemporaryState("error", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
async function startNewConversation(): Promise<void> {
|
||||
const conversationId = get(claudeStore.activeConversationId);
|
||||
if (!conversationId) {
|
||||
@@ -48,6 +113,12 @@ async function startNewConversation(): Promise<void> {
|
||||
}
|
||||
|
||||
export const slashCommands: SlashCommand[] = [
|
||||
{
|
||||
name: "cd",
|
||||
description: "Change the working directory",
|
||||
usage: "/cd <path>",
|
||||
execute: changeDirectory,
|
||||
},
|
||||
{
|
||||
name: "clear",
|
||||
description: "Clear the terminal display (keeps conversation context)",
|
||||
|
||||
Reference in New Issue
Block a user