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

feat(code): /plan code mode适配

douran20a51b843e77
diff --git a/jiuwenclaw/agentserver/agent_ws_server.py b/jiuwenclaw/agentserver/agent_ws_server.py
index b87870b5e7..144a24898f 100644
--- a/jiuwenclaw/agentserver/agent_ws_server.py
+++ b/jiuwenclaw/agentserver/agent_ws_server.py
@@ -428,6 +428,11 @@ class AgentWebSocketServer:
mode = request.params.get("mode", "agent.plan").split(".")[0]
agent = await self._agent_manager.get_agent(channel_id=channel_id, mode=mode)
+ if mode == "code":
+ sub_mode = request.params.get("mode", "agent.plan").split(".")[1]
+ from openjiuwen.core.single_agent import create_agent_session
+ session = create_agent_session(session_id=request.session_id)
+ agent.get_instance().switch_mode(session=session, mode=sub_mode)
if agent is None:
raise ValueError("Failed to get agent")
@@ -451,6 +456,12 @@ class AgentWebSocketServer:
if agent is None:
raise ValueError("Failed to get agent")
+ if mode == "code":
+ sub_mode = request.params.get("mode", "agent.plan").split(".")[1]
+ from openjiuwen.core.single_agent import create_agent_session
+ session = create_agent_session(session_id=request.session_id)
+ agent.get_instance().switch_mode(session=session, mode=sub_mode)
+
chunk_count = 0
# 心跳控制:当有真实 chunk 发送时重置,空闲时发送心跳
heartbeat_event = asyncio.Event()
diff --git a/jiuwenclaw/agentserver/interface.py b/jiuwenclaw/agentserver/interface.py
index b59b89f786..a4682b76e2 100644
--- a/jiuwenclaw/agentserver/interface.py
+++ b/jiuwenclaw/agentserver/interface.py
@@ -709,6 +709,11 @@ class JiuWenClaw:
is_complete=True,
)
+ # ---------- 实例获取 ----------
+
+ def get_instance(self):
+ return self._adapter._instance
+
# ---------- 资源清理 ----------
async def cleanup(self) -> None:
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/mode.ts b/jiuwenclaw/cli/src/core/commands/builtins/mode.ts
index 0592ee5b37..7831960739 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/mode.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/mode.ts
@@ -2,13 +2,21 @@ import { makeItem } from "../helpers.js";
import { CommandKind, type SlashCommand } from "../types.js";
export function createModeCommand(): SlashCommand {
- const directModes = ["agent.plan", "agent.fast", "code.plan", "code.normal", "team"] as const;
+ const directModes = [
+ "agent",
+ "code",
+ "agent.plan",
+ "agent.fast",
+ "code.plan",
+ "code.normal",
+ "team",
+ ] as const;
const modeAlias: Record<
string,
"agent.plan" | "agent.fast" | "code.plan" | "code.normal" | "team"
> = {
plan: "agent.plan",
- agent: "agent.fast",
+ agent: "agent.plan",
code: "code.normal",
"agent.plan": "agent.plan",
"agent.fast": "agent.fast",
@@ -20,8 +28,8 @@ export function createModeCommand(): SlashCommand {
return {
name: "mode",
description: "Switch chat mode",
- usage: "/mode <agent.plan|agent.fast|code.plan|code.normal|team>",
- example: "/mode agent.plan",
+ usage: "/mode <agent|code|agent.plan|agent.fast|code.plan|code.normal|team>",
+ example: "/mode agent",
kind: CommandKind.BUILT_IN,
takesArgs: true,
completion: async () => [...directModes],
@@ -33,13 +41,13 @@ export function createModeCommand(): SlashCommand {
makeItem(
ctx.sessionId,
"error",
- "usage: /mode <agent.plan|agent.fast|code.plan|code.normal|team>",
+ "usage: /mode <agent|code|agent.plan|agent.fast|code.plan|code.normal|team>",
),
);
return;
}
try {
- await ctx.request("mode.set", { mode: requestedMode });
+ await ctx.request("mode.set", { mode: nextMode });
} catch {
// Some backends still accept mode only on chat.send.
}
diff --git a/jiuwenclaw/cli/src/core/commands/builtins/plan.ts b/jiuwenclaw/cli/src/core/commands/builtins/plan.ts
index 4933623652..56511b6039 100644
--- a/jiuwenclaw/cli/src/core/commands/builtins/plan.ts
+++ b/jiuwenclaw/cli/src/core/commands/builtins/plan.ts
@@ -1,18 +1,35 @@
import { addInfo } from "../helpers.js";
-import { CommandKind, type SlashCommand } from "../types.js";
+import { CommandKind, type CommandContext, type SlashCommand } from "../types.js";
+
+function planSubMode(ctx: CommandContext): "agent.plan" | "code.plan" {
+ if (ctx.mode === "code.plan" || ctx.mode === "code.normal") return "code.plan";
+ return "agent.plan";
+}
export function createPlanCommand(): SlashCommand {
return {
name: "plan",
- description: "Enable plan mode or view the current session plan",
+ description: "Switch to plan sub-mode for the current mode family, or send a planning request",
usage: "/plan [open|<description>]",
example: "/plan outline the migration steps",
kind: CommandKind.BUILT_IN,
takesArgs: true,
action: (ctx, args) => {
+ if (ctx.mode === "team") {
+ ctx.addItem(
+ addInfo(
+ ctx.sessionId,
+ "/plan does not apply in team mode; switch mode first (e.g. /mode agent).",
+ "p",
+ ),
+ );
+ return;
+ }
+
const value = args.trim();
- if (ctx.mode !== "agent.plan") {
- ctx.setMode("agent.plan");
+ const target = planSubMode(ctx);
+ if (ctx.mode !== target) {
+ ctx.setMode(target);
}
if (!value) {
@@ -31,7 +48,7 @@ export function createPlanCommand(): SlashCommand {
return;
}
- const requestId = ctx.sendMessage(value, "agent.plan");
+ const requestId = ctx.sendMessage(value, target);
if (!requestId) {
ctx.addItem(
addInfo(ctx.sessionId, "offline: waiting for reconnect before sending plan request", "p"),