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:/memory edit命令可以在记忆目录下,随便创建文件。功能冗余

openJiuwen-botd3047e1db8d2
diff --git a/jiuwenswarm/agents/harness/common/memory_rpc.py b/jiuwenswarm/agents/harness/common/memory_rpc.py
index e3e7434cb2..b9ea72e405 100644
--- a/jiuwenswarm/agents/harness/common/memory_rpc.py
+++ b/jiuwenswarm/agents/harness/common/memory_rpc.py
@@ -303,19 +303,24 @@ async def handle_memory_edit(
content_preview = ""
kind = _classify_memory_file(resolved, workspace)
- if exists:
- try:
- text = Path(resolved).read_text(encoding="utf-8", errors="replace")
- lines = text.splitlines()[:20]
- content_preview = "\n".join(lines)
- if len(text.splitlines()) > 20:
- content_preview += "\n... (truncated)"
- except OSError:
- pass
- else:
- parent = Path(resolved).parent
- parent.mkdir(parents=True, exist_ok=True)
- Path(resolved).touch()
+ if not exists:
+ return {
+ "path": resolved,
+ "exists": False,
+ "content_preview": "",
+ "kind": kind,
+ "editable": False,
+ "reason": "memory file does not exist",
+ }
+
+ try:
+ text = Path(resolved).read_text(encoding="utf-8", errors="replace")
+ lines = text.splitlines()[:20]
+ content_preview = "\n".join(lines)
+ if len(text.splitlines()) > 20:
+ content_preview += "\n... (truncated)"
+ except OSError:
+ pass
return {
"path": resolved,
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts
index 7245b558a3..73b11b8004 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts
@@ -1,4 +1,4 @@
-import { existsSync, mkdirSync, readdirSync, statSync, readFileSync, writeFileSync } from "node:fs";
+import { existsSync, readdirSync, statSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { dirname, join, parse, relative } from "node:path";
import { addError, addInfo, makeItem } from "../helpers.js";
@@ -467,10 +467,9 @@ async function editMemoryByPath(
if (isAncestorMemFile) {
const displayPath = getDisplayPath(path, projectDir);
- // 文件不存在则先创建(与后端 handle_memory_edit 的 touch 行为对齐)
if (!existsSync(path)) {
- mkdirSync(dirname(path), { recursive: true });
- writeFileSync(path, "");
+ ctx.addItem(addError(ctx.sessionId, `Cannot edit: ${path} — memory file does not exist.`));
+ return;
}
if (ctx.openInEditor) {
const { source, value } = getEditorInfo();
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts b/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
index d1f0c63c7c..1bad71b2d6 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
@@ -3,8 +3,7 @@
// 管理 /memory 的四个页签(edit/status/toggle/open)的交互、渲染和状态。
// app-screen.ts 通过持有 MemoryViewController 实例并委托调用其方法来使用。
-import * as fs from "node:fs";
-import * as path from "node:path";
+import { existsSync } from "node:fs";
import { type TUI, type SelectItem, SelectList } from "@mariozechner/pi-tui";
import { addInfo } from "../core/commands/helpers.js";
import type { CliPiAppState } from "../app-state.js";
@@ -459,13 +458,10 @@ export class MemoryViewController {
private async handleSelect(tab: MemoryViewTab, item: SelectItem, mode: string, _projectDir: string): Promise<void> {
if (tab === "edit" && item.value && item.value !== "__display__") {
const filePath = item.value;
- if (!fs.existsSync(filePath)) {
- try {
- fs.mkdirSync(path.dirname(filePath), { recursive: true });
- fs.writeFileSync(filePath, "", "utf-8");
- } catch {
- // 创建失败仍尝试打开,让编辑器报错
- }
+ if (!existsSync(filePath)) {
+ this.statusMessage = "Cannot edit: memory file does not exist.";
+ this.tui.requestRender();
+ return;
}
// 打开编辑器前先冻结列表(进入不可操作态)。编辑器关闭后由 onExit 退出列表
// 并提示编辑成功(含编辑器来源与环境变量切换提示),与 CC memory.tsx 行为一致: