Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(mode): add switch.ts

douran839892b70a5e
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/switch.ts b/jiuwenclaw/cli/src/core/commands/builtins/switch.ts
index 5eda37d5d9..308d74f2dd 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/switch.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/switch.ts
@@ -1,28 +1,57 @@
import { makeItem } from "../helpers.js";
import { CommandKind, type SlashCommand } from "../types.js";
+type ClientMode = "agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team";
+type SwitchArg = "plan" | "fast" | "normal";
+
+const AGENT_MODES = new Set<ClientMode>(["agent.plan", "agent.fast"]);
+const CODE_MODES = new Set<ClientMode>(["code.plan", "code.normal"]);
+
+function resolveRequestedMode(currentMode: ClientMode, switchArg: SwitchArg): string | null {
+ if (switchArg === "plan") {
+ if (AGENT_MODES.has(currentMode)) return "agent.plan";
+ if (CODE_MODES.has(currentMode)) return "code.plan";
+ return null;
+ }
+ if (switchArg === "fast") {
+ return AGENT_MODES.has(currentMode) ? "agent.fast" : null;
+ }
+ if (switchArg === "normal") {
+ return CODE_MODES.has(currentMode) ? "code.normal" : null;
+ }
+ return null;
+}
+
export function createSwitchCommand(): SlashCommand {
return {
name: "switch",
- description: "Switch to an existing session",
- usage: "/switch <session_id>",
- example: "/switch my-session",
+ description: "Switch sub-mode in current mode family",
+ usage: "/switch <plan|fast|normal>",
+ example: "/switch fast",
kind: CommandKind.BUILT_IN,
takesArgs: true,
+ completion: async () => ["plan", "fast", "normal"],
action: async (ctx, args) => {
- if (ctx.isProcessing) {
- ctx.addItem(makeItem(ctx.sessionId, "error", "session is busy"));
+ const switchArg = args.trim() as SwitchArg;
+ if (switchArg !== "plan" && switchArg !== "fast" && switchArg !== "normal") {
+ ctx.addItem(makeItem(ctx.sessionId, "error", "usage: /switch <plan|fast|normal>"));
return;
}
- const targetId = args.trim();
- if (!targetId) {
- ctx.addItem(makeItem(ctx.sessionId, "error", "usage: /switch <session_id>"));
+
+ const requestedMode = resolveRequestedMode(ctx.mode, switchArg);
+ if (!requestedMode) {
+ ctx.addItem(makeItem(ctx.sessionId, "error", "illegal command"));
return;
}
- ctx.updateSession(targetId);
- ctx.clearEntries();
- ctx.addItem(makeItem(targetId, "info", `Switched to session ${targetId}`, "i"));
- await ctx.restoreHistory(targetId);
+
+ try {
+ await ctx.request("mode.set", { mode: requestedMode });
+ } catch {
+ // Some backends still accept mode only on chat.send.
+ }
+
+ ctx.setMode(requestedMode as ClientMode);
+ ctx.addItem(makeItem(ctx.sessionId, "info", `Mode switched to ${requestedMode}`, "s"));
},
};
}