generated from nhcarrigan/template
feat: naomi did too much at once (#53)
- feat: add slash commands - feat: toggle window always on top - fix: save settings button closes settings panel - feat: input history (both text and commands) - feat: add keyboard shortcuts - feat: add confirmation modal when closing connected tabs - fix: better text colours in light mode - fix: handle multiple tabs requesting permission Closes #6 Closes #13 Closes #21 Closes #28 Reviewed-on: #53 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #53.
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
import { get } from "svelte/store";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { claudeStore } from "$lib/stores/claude";
|
||||
import { characterState } from "$lib/stores/character";
|
||||
import { setSkipNextGreeting } from "$lib/tauri";
|
||||
|
||||
export interface SlashCommand {
|
||||
name: string;
|
||||
description: string;
|
||||
usage: string;
|
||||
execute: (args: string) => Promise<void> | void;
|
||||
}
|
||||
|
||||
async function startNewConversation(): Promise<void> {
|
||||
const conversationId = get(claudeStore.activeConversationId);
|
||||
if (!conversationId) {
|
||||
claudeStore.addLine("error", "No active conversation");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const workingDir = await invoke<string>("get_working_directory", {
|
||||
conversationId,
|
||||
});
|
||||
|
||||
claudeStore.addLine("system", "Starting new conversation...");
|
||||
characterState.setState("thinking");
|
||||
|
||||
await invoke("interrupt_claude", { conversationId });
|
||||
|
||||
claudeStore.clearTerminal();
|
||||
|
||||
setSkipNextGreeting(true);
|
||||
|
||||
await invoke("start_claude", {
|
||||
conversationId,
|
||||
options: {
|
||||
working_dir: workingDir,
|
||||
},
|
||||
});
|
||||
|
||||
claudeStore.addLine("system", "New conversation started!");
|
||||
characterState.setState("idle");
|
||||
} catch (error) {
|
||||
claudeStore.addLine("error", `Failed to start new conversation: ${error}`);
|
||||
characterState.setTemporaryState("error", 3000);
|
||||
}
|
||||
}
|
||||
|
||||
export const slashCommands: SlashCommand[] = [
|
||||
{
|
||||
name: "clear",
|
||||
description: "Clear the terminal display (keeps conversation context)",
|
||||
usage: "/clear",
|
||||
execute: () => {
|
||||
claudeStore.clearTerminal();
|
||||
claudeStore.addLine("system", "Terminal cleared");
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "new",
|
||||
description: "Start a fresh conversation (resets context)",
|
||||
usage: "/new",
|
||||
execute: startNewConversation,
|
||||
},
|
||||
{
|
||||
name: "help",
|
||||
description: "Show available slash commands",
|
||||
usage: "/help",
|
||||
execute: () => {
|
||||
const helpText = slashCommands
|
||||
.map((cmd) => ` ${cmd.usage.padEnd(12)} - ${cmd.description}`)
|
||||
.join("\n");
|
||||
claudeStore.addLine("system", `Available commands:\n${helpText}`);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "summarise",
|
||||
description: "Get a summary of the entire conversation",
|
||||
usage: "/summarise",
|
||||
execute: async () => {
|
||||
const conversationId = get(claudeStore.activeConversationId);
|
||||
if (!conversationId) {
|
||||
claudeStore.addLine("error", "No active conversation");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
claudeStore.addLine("system", "Requesting conversation summary...");
|
||||
await invoke("send_prompt", {
|
||||
conversationId,
|
||||
message:
|
||||
"Please provide a comprehensive summary of our entire conversation so far, including the key topics we've discussed, decisions made, and any important context.",
|
||||
});
|
||||
} catch (error) {
|
||||
claudeStore.addLine("error", `Failed to request summary: ${error}`);
|
||||
}
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export function parseSlashCommand(input: string): {
|
||||
command: SlashCommand | null;
|
||||
args: string;
|
||||
} {
|
||||
const trimmed = input.trim();
|
||||
|
||||
if (!trimmed.startsWith("/")) {
|
||||
return { command: null, args: "" };
|
||||
}
|
||||
|
||||
const parts = trimmed.slice(1).split(/\s+/);
|
||||
const commandName = parts[0]?.toLowerCase();
|
||||
const args = parts.slice(1).join(" ");
|
||||
|
||||
const command = slashCommands.find((cmd) => cmd.name.toLowerCase() === commandName);
|
||||
|
||||
return { command: command || null, args };
|
||||
}
|
||||
|
||||
export function getMatchingCommands(input: string): SlashCommand[] {
|
||||
const trimmed = input.trim();
|
||||
|
||||
if (!trimmed.startsWith("/")) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const partial = trimmed.slice(1).toLowerCase();
|
||||
|
||||
if (partial === "") {
|
||||
return slashCommands;
|
||||
}
|
||||
|
||||
return slashCommands.filter((cmd) => cmd.name.toLowerCase().startsWith(partial));
|
||||
}
|
||||
|
||||
export function isSlashCommand(input: string): boolean {
|
||||
return input.trim().startsWith("/");
|
||||
}
|
||||
Reference in New Issue
Block a user