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(tui): 统一 /memory 显示路径盘符为大写

openJiuwen-bota0d34e34cd58
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory-path-utils.ts b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory-path-utils.ts
index 0f80bebdd9..dfb22d66d8 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory-path-utils.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory-path-utils.ts
@@ -5,6 +5,27 @@ import { dirname, join, parse, relative } from "node:path";
// ---------------------------------------------------------------------------
// Path display utilities (aligned with Claude Code's getDisplayPath)
// ---------------------------------------------------------------------------
+
+/**
+ * 格式化 /memory 中展示的路径,不修改实际用于文件操作的原始路径。
+ *
+ * Windows 路径可能分别来自 Node 前端和 Python 后端,盘符大小写不一致。
+ * 此处只将展示盘符转为大写,路径分隔符、目录名和文件名均保持不变。
+ */
+export function formatMemoryPathForDisplay(filePath: string): string {
+ // Windows 命名空间路径:\\?\d:\repo -> \\?\D:\repo
+ const namespacedPath = filePath.replace(
+ /^((?:\\\\\?\\|\/\/\?\/))([A-Za-z]):(?=[\\/]|$)/,
+ (_match, prefix: string, drive: string) => `${prefix}${drive.toUpperCase()}:`,
+ );
+
+ // 普通 Windows 路径:d:\repo -> D:\repo
+ return namespacedPath.replace(
+ /^([A-Za-z]):(?=[\\/]|$)/,
+ (_match, drive: string) => `${drive.toUpperCase()}:`,
+ );
+}
+
//
// 统一的路径展示工具:从 memory.ts 的 getDisplayPath 与 app-screen.ts 的
// mvDisplayPath 合并而来。二者原本各有侧重——
@@ -47,10 +68,10 @@ export function getDisplayPath(
projectDir: string,
gitRoot?: string | null,
): string {
- const fileSlashes = filePath.replace(/\\/g, "/");
+ const fileSlashes = formatMemoryPathForDisplay(filePath).replace(/\\/g, "/");
const fileNorm = process.platform === "win32" ? fileSlashes.toLowerCase() : fileSlashes;
const homeDir = homedir();
- const homeDirSlashes = homeDir.replace(/\\/g, "/");
+ const homeDirSlashes = formatMemoryPathForDisplay(homeDir).replace(/\\/g, "/");
const homeDirNorm = process.platform === "win32" ? homeDirSlashes.toLowerCase() : homeDirSlashes;
// Collect all valid candidate paths, then pick the shortest
@@ -66,9 +87,9 @@ export function getDisplayPath(
// 的 projectDir 相对路径(必带 ../ 前缀)。
const fileInsideProject = isAncestorOrSelfDir(projectDir, filePath);
if (resolvedGitRoot && fileInsideProject) {
- const gitRootSlashes = resolvedGitRoot.replace(/\\/g, "/");
+ const gitRootSlashes = formatMemoryPathForDisplay(resolvedGitRoot).replace(/\\/g, "/");
const gitRootNorm = process.platform === "win32" ? gitRootSlashes.toLowerCase() : gitRootSlashes;
- const projectDirSlashes = projectDir.replace(/\\/g, "/");
+ const projectDirSlashes = formatMemoryPathForDisplay(projectDir).replace(/\\/g, "/");
const projectDirNorm = process.platform === "win32" ? projectDirSlashes.toLowerCase() : projectDirSlashes;
// Only use git root as base if projectDir is inside the git repo
if (projectDirNorm.startsWith(gitRootNorm + "/") || projectDirNorm === gitRootNorm) {
@@ -83,7 +104,7 @@ export function getDisplayPath(
// Candidate 2: relative from projectDir (skip cross-drive & "../" paths)
// 允许空字符串(file === projectDir → 显示 ".");跳过 ../ 前缀(不友好)。
- const projectDirSlashes = projectDir.replace(/\\/g, "/");
+ const projectDirSlashes = formatMemoryPathForDisplay(projectDir).replace(/\\/g, "/");
const projectDirNorm = process.platform === "win32" ? projectDirSlashes.toLowerCase() : projectDirSlashes;
const relFromProj = relative(projectDirNorm, fileNorm);
if (!relFromProj.startsWith("/") && !/^[A-Za-z]:/.test(relFromProj) && !relFromProj.startsWith("..")) {
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 73b11b8004..ef56d0479a 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/memory.ts
@@ -4,7 +4,12 @@ import { dirname, join, parse, relative } from "node:path";
import { addError, addInfo, makeItem } from "../helpers.js";
import { CommandKind, type SlashCommand } from "../types.js";
import { getEditorInfo } from "../../utils/editor.js";
-import { getDisplayPath, findGitRoot, isAncestorOrSelfDir } from "./memory-path-utils.js";
+import {
+ findGitRoot,
+ formatMemoryPathForDisplay,
+ getDisplayPath,
+ isAncestorOrSelfDir,
+} from "./memory-path-utils.js";
export interface MemoryFile {
path: string;
@@ -610,7 +615,7 @@ async function showMemoryStatus(
if (payload.project_memory.project_dir) {
items.push({
label: "Project Dir",
- value: payload.project_memory.project_dir,
+ value: formatMemoryPathForDisplay(payload.project_memory.project_dir),
});
}
}
@@ -628,7 +633,7 @@ async function showMemoryStatus(
if (payload.coding_memory.dir) {
items.push({
label: "Coding Memory Dir",
- value: payload.coding_memory.dir,
+ value: formatMemoryPathForDisplay(payload.coding_memory.dir),
});
}
}
@@ -646,7 +651,7 @@ async function showMemoryStatus(
if (payload.auto_memory.dir) {
items.push({
label: "Auto Memory Dir",
- value: payload.auto_memory.dir,
+ value: formatMemoryPathForDisplay(payload.auto_memory.dir),
});
}
}
@@ -847,7 +852,10 @@ async function openMemoryDir(
{
header: "Memory open",
question: "Select a directory to open:",
- options: options.map((o) => ({ label: o.label, description: o.value })),
+ options: options.map((o) => ({
+ label: o.label,
+ description: formatMemoryPathForDisplay(o.value),
+ })),
},
],
"local_command_memory_open",
@@ -867,23 +875,24 @@ async function openMemoryDir(
// 优先调系统文件管理器打开;不支持时(无 GUI 或未注入回调)显示可复制路径提示
const opened = ctx.openFolder?.(selectedValue);
+ const displayValue = formatMemoryPathForDisplay(selectedValue);
if (opened) {
- ctx.addItem(addInfo(ctx.sessionId, `Opened memory folder: ${selectedValue}`, "m"));
+ ctx.addItem(addInfo(ctx.sessionId, `Opened memory folder: ${displayValue}`, "m"));
} else {
// 无 GUI explorer(如无头 Linux 服务器)或未注入 openFolder 回调:
// 显示可复制路径 + 平台命令,避免误导用户以为文件夹已打开。
let cmd: string;
if (process.platform === "win32") {
- cmd = `explorer "${selectedValue}"`;
+ cmd = `explorer "${displayValue}"`;
} else if (process.platform === "darwin") {
- cmd = `open "${selectedValue}"`;
+ cmd = `open "${displayValue}"`;
} else {
- cmd = `xdg-open "${selectedValue}"`;
+ cmd = `xdg-open "${displayValue}"`;
}
ctx.addItem(
addInfo(
ctx.sessionId,
- `No GUI explorer detected. Path: ${selectedValue}\nOpen with: ${cmd}`,
+ `No GUI explorer detected. Path: ${displayValue}\nOpen with: ${cmd}`,
"i",
),
);
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts b/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
index 1bad71b2d6..793d23fc05 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/memory-view.ts
@@ -9,7 +9,10 @@ import { addInfo } from "../core/commands/helpers.js";
import type { CliPiAppState } from "../app-state.js";
import { openFileInEditor as openInExternalEditor, openFolderInExplorer, getEditorInfo } from "../core/utils/editor.js";
import { collectOrderedMemoryFiles, type MemoryFile } from "../core/commands/builtins/memory.js";
-import { getDisplayPath } from "../core/commands/builtins/memory-path-utils.js";
+import {
+ formatMemoryPathForDisplay,
+ getDisplayPath,
+} from "../core/commands/builtins/memory-path-utils.js";
import { palette, selectListTheme } from "./theme.js";
import { padToWidth } from "./rendering/text.js";
import { resolveAction } from "../core/keybindings/resolver.js";
@@ -338,7 +341,7 @@ export class MemoryViewController {
const projectDir = this.state.projectDir ?? "";
const gitRoot = this.state.gitRoot ?? null;
const displayPath = this.showFullPath
- ? this.lastOpenedPath.replace(/\\/g, "/")
+ ? formatMemoryPathForDisplay(this.lastOpenedPath).replace(/\\/g, "/")
: getDisplayPath(this.lastOpenedPath, projectDir, gitRoot);
// 保留原有 "Opened:" / "No GUI explorer detected. ..." 前缀,只替换显示路径
if (this.statusMessage?.startsWith("Opened: ")) {
@@ -400,7 +403,9 @@ export class MemoryViewController {
private buildEditItems(files: MVFile[], projectDir: string, gitRoot: string | null): SelectItem[] {
return files.map((f) => {
const label = this.fileLabel(f);
- const dp = this.showFullPath ? f.path.replace(/\\/g, "/") : getDisplayPath(f.path, projectDir, gitRoot);
+ const dp = this.showFullPath
+ ? formatMemoryPathForDisplay(f.path).replace(/\\/g, "/")
+ : getDisplayPath(f.path, projectDir, gitRoot);
const isGitTracked = gitRoot && f.kind !== "local" && f.kind !== "user";
const desc = label === dp ? undefined : isGitTracked ? `Checked in at ${dp}` : `Saved in ${dp}`;
return { value: f.path, label, description: desc };
@@ -446,7 +451,9 @@ export class MemoryViewController {
const cat = this.modeCategory(mode);
const projectDir = this.state?.projectDir ?? "";
const gitRoot = this.state?.gitRoot ?? null;
- const fmt = (p: string) => (this.showFullPath ? p : getDisplayPath(p, projectDir, gitRoot));
+ const fmt = (p: string) => (
+ this.showFullPath ? formatMemoryPathForDisplay(p) : getDisplayPath(p, projectDir, gitRoot)
+ );
const items: SelectItem[] = [];
if (cat === "agent") items.push({ value: openP.memory_dir, label: "Memory Dir", description: fmt(openP.memory_dir) });
if (cat === "code" && openP.coding_memory_dir) items.push({ value: openP.coding_memory_dir, label: "Coding Memory Dir", description: fmt(openP.coding_memory_dir) });
@@ -512,7 +519,7 @@ export class MemoryViewController {
const projectDir = this.state?.projectDir ?? "";
const gitRoot = this.state?.gitRoot ?? null;
const displayPath = this.showFullPath
- ? item.value.replace(/\\/g, "/")
+ ? formatMemoryPathForDisplay(item.value).replace(/\\/g, "/")
: getDisplayPath(item.value, projectDir, gitRoot);
if (opened) {
this.statusMessage = `Opened: ${displayPath}`;
@@ -577,7 +584,7 @@ export class MemoryViewController {
}
private fileLabel(f: MVFile): string {
- const p = f.path.replace(/\\/g, "/");
+ const p = formatMemoryPathForDisplay(f.path).replace(/\\/g, "/");
if (f.kind === "user") return "User memory";
if (f.kind === "local") return "Local memory";
if (f.kind === "project" && p.endsWith("JIUWENSWARM.md") && !p.endsWith("JIUWENSWARM.local.md")) return "Project memory";