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: tui /memory无法创建和编辑project/local memory
jingjinduobe4d3d85a47a
diff --git a/jiuwenswarm/agents/harness/common/memory_rpc.py b/jiuwenswarm/agents/harness/common/memory_rpc.pyindex 5d6c5cc5a1..0c65c70368 100644--- a/jiuwenswarm/agents/harness/common/memory_rpc.py+++ b/jiuwenswarm/agents/harness/common/memory_rpc.py@@ -52,10 +52,19 @@ def _get_allowed_dirs(workspace: str, project_dir: str | None = None) -> list[stdef _is_in_allowed_dirs(abs_path: str, workspace: str, project_dir: str | None = None) -> bool:- for allowed_dir in _get_allowed_dirs(workspace, project_dir):- if abs_path == allowed_dir or abs_path.startswith(allowed_dir + os.sep):- return True- return False+ # On Windows, path comparison should be case-insensitive+ if os.name == "nt":+ abs_path_lower = abs_path.lower()+ for allowed_dir in _get_allowed_dirs(workspace, project_dir):+ allowed_dir_lower = allowed_dir.lower()+ if abs_path_lower == allowed_dir_lower or abs_path_lower.startswith(allowed_dir_lower + os.sep):+ return True+ return False+ else:+ for allowed_dir in _get_allowed_dirs(workspace, project_dir):+ if abs_path == allowed_dir or abs_path.startswith(allowed_dir + os.sep):+ return True+ return Falsedef _validate_edit_path(raw_path: str, workspace: str, project_dir: str | None = None) -> tuple[bool, str]:@@ -79,10 +88,16 @@ def _validate_edit_path(raw_path: str, workspace: str, project_dir: str | None =if basename in ("JIUWENSWARM.md", "JIUWENSWARM.local.md"):parent = os.path.dirname(abs_path)workspace_norm = os.path.normpath(workspace)- if parent == workspace_norm:- return (True, abs_path)- if project_dir and parent == os.path.normpath(project_dir):- return (True, abs_path)+ if os.name == "nt":+ if parent.lower() == workspace_norm.lower():+ return (True, abs_path)+ if project_dir and parent.lower() == os.path.normpath(project_dir).lower():+ return (True, abs_path)+ else:+ if parent == workspace_norm:+ return (True, abs_path)+ if project_dir and parent == os.path.normpath(project_dir):+ return (True, abs_path)return (False, f"Path not in allowed memory directories: {raw_path}")@@ -107,17 +122,37 @@ def _relative_path(abs_path: str, workspace: str, project_dir: str | None = Noneabs_path_norm = os.path.normpath(abs_path)if project_dir:project_dir_norm = os.path.normpath(project_dir)- if abs_path_norm.startswith(project_dir_norm + os.sep) or abs_path_norm == project_dir_norm:+ # On Windows, use case-insensitive comparison+ if os.name == "nt":+ abs_lower = abs_path_norm.lower()+ proj_lower = project_dir_norm.lower()+ if abs_lower.startswith(proj_lower + os.sep) or abs_lower == proj_lower:+ try:+ return os.path.relpath(abs_path, project_dir)+ except ValueError:+ pass+ else:+ if abs_path_norm.startswith(project_dir_norm + os.sep) or abs_path_norm == project_dir_norm:+ try:+ return os.path.relpath(abs_path, project_dir)+ except ValueError:+ pass+ workspace_norm = os.path.normpath(workspace)+ # On Windows, use case-insensitive comparison+ if os.name == "nt":+ abs_lower = abs_path_norm.lower()+ ws_lower = workspace_norm.lower()+ if abs_lower.startswith(ws_lower + os.sep) or abs_lower == ws_lower:try:- return os.path.relpath(abs_path, project_dir)+ return os.path.relpath(abs_path, workspace)+ except ValueError:+ pass+ else:+ if abs_path_norm.startswith(workspace_norm + os.sep) or abs_path_norm == workspace_norm:+ try:+ return os.path.relpath(abs_path, workspace)except ValueError:pass- workspace_norm = os.path.normpath(workspace)- if abs_path_norm.startswith(workspace_norm + os.sep) or abs_path_norm == workspace_norm:- try:- return os.path.relpath(abs_path, workspace)- except ValueError:- passreturn abs_pathdiff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.tsindex 47a5d48132..8c3cf3ae94 100644--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts@@ -1,3 +1,4 @@+import { join } from "path";import { addError, addInfo, makeItem } from "../helpers.js";import { CommandKind, type SlashCommand } from "../types.js";import { getEditorInfo } from "../../utils/editor.js";@@ -236,12 +237,56 @@ async function editMemoryInteractive(});const files = payload.files ?? [];- if (files.length === 0) {+ // Get workspace and project directories+ const workspaceDir = ctx.getWorkspaceDir() || "";+ const projectDir = ctx.getCurrentProjectDir();++ // Check if project and local memory exist+ const hasProjectMemory = files.some(+ (f) => f.path.endsWith("JIUWENSWARM.md") && !f.path.endsWith("JIUWENSWARM.local.md"),+ );+ const hasLocalMemory = files.some((f) => f.path.endsWith("JIUWENSWARM.local.md"));++ // Add default options if not exist+ const projectMemoryPath = join(projectDir, "JIUWENSWARM.md");+ const localMemoryPath = join(projectDir, "JIUWENSWARM.local.md");++ const allFiles: MemoryFile[] = [+ ...files,+ ...(hasProjectMemory+ ? []+ : [+ {+ path: projectMemoryPath,+ relative_path: "JIUWENSWARM.md",+ kind: "project",+ exists: false,+ size: 0,+ mtime: 0,+ lines: 0,+ },+ ]),+ ...(hasLocalMemory+ ? []+ : [+ {+ path: localMemoryPath,+ relative_path: "JIUWENSWARM.local.md",+ kind: "local",+ exists: false,+ size: 0,+ mtime: 0,+ lines: 0,+ },+ ]),+ ];++ if (allFiles.length === 0) {ctx.addItem(addInfo(ctx.sessionId, "No memory files to edit.", "m"));return;}- const options = files.map((f) => ({+ const options = allFiles.map((f) => ({label: f.relative_path,description: `${f.kind} · ${f.lines} lines${f.exists ? "" : " (new)"}`,}));@@ -269,7 +314,7 @@ async function editMemoryInteractive(return;}- const selectedFile = files.find(+ const selectedFile = allFiles.find((f) => f.relative_path === selectedLabel || f.path === selectedLabel,);@@ -291,7 +336,12 @@ async function editMemoryByPath(path: string,): Promise<void> {try {- const payload = await ctx.request<MemoryEditResult>("memory.edit", { path });+ const trustedDirs = ctx.getTrustedDirs();+ const payload = await ctx.request<MemoryEditResult>("memory.edit", {+ path,+ trusted_dirs: trustedDirs.length > 0 ? trustedDirs : undefined,+ cwd: ctx.getWorkspaceDir(),+ });if (!payload.editable) {ctx.addItem(addError(ctx.sessionId, `Cannot edit: ${path} — path not in allowed memory directories.`));