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): exclude untracked files from /diff and update empty state

haowenzhong1fb5eee8d14be
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index 905c0c9240..92648a365e 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -460,13 +460,13 @@ export function buildDiffViewerSources(payload: Record<string, unknown>): DiffSo
sources.push({
label: "Current",
- title: "Diff (git diff HEAD)",
+ title: "Uncommitted changes (git diff HEAD)",
subtitle: formatDiffStats(currentStats),
stats: currentStats,
files: currentFiles,
emptyMessage: currentStats.filesChanged > 0 && currentFiles.length === 0
? "Too many files to display details"
- : "Working tree is clean",
+ : "No changes yet",
});
for (const turn of turns) {
@@ -2000,9 +2000,7 @@ export class AppScreen implements Component, Focusable {
}
const sourceHint = this.diffViewerState.sources.length > 1 ? "←/→ source · " : "";
- const hintText = source.files.length > 0
- ? ` ${sourceHint}↑/↓ to select · Enter to view · Esc to close`
- : ` ${sourceHint}Esc to close`;
+ const hintText = ` ${sourceHint}↑/↓ to select · Enter to view · Esc to close`;
lines.push(padToWidth(palette.text.dim(hintText), safeWidth));
return lines;
diff --git a/jiuwenswarm/server/utils/diff_service.py b/jiuwenswarm/server/utils/diff_service.py
index e0dd0ad82d..e5d638b29a 100644
--- a/jiuwenswarm/server/utils/diff_service.py
+++ b/jiuwenswarm/server/utils/diff_service.py
@@ -893,11 +893,7 @@ class DiffService:
return files
def get_git_diff(self, project_dir: str | None) -> dict[str, Any] | None:
- """获取工作区相对于 HEAD 的 git diff.
-
- 包含两类改动:
- 1. 已跟踪文件的修改(git diff HEAD)
- 2. 未跟踪的新文件(git ls-files --others --exclude-standard)
+ """获取工作区相对于 HEAD 的 git diff(仅已跟踪文件的修改).
Args:
project_dir: 项目目录路径.
@@ -908,7 +904,7 @@ class DiffService:
"files": { file_path: { "filePath": str, "hunks": [...],
"isNewFile": bool, "linesAdded": int, "linesRemoved": int } }
}
- 如果不是 git 仓库或没有任何改动(含未跟踪文件),返回 None.
+ 如果不是 git 仓库或没有任何改动,返回 None.
"""
if not project_dir:
return None
@@ -977,18 +973,6 @@ class DiffService:
"lastEditTime": None,
}
- # 2. 未跟踪的新文件: 仅填充剩余名额,避免无限加载
- remaining_slots = max(0, MAX_FILES - len(files))
- untracked = self._get_untracked_files(repo_dir, max_files=remaining_slots)
- for abs_path, file_info in untracked.items():
- if abs_path not in files: # 避免重复(理论上不会)
- file_info.setdefault("isBinary", False)
- file_info.setdefault("isLargeFile", False)
- file_info.setdefault("isTruncated", False)
- files[abs_path] = file_info
- total_files_changed += 1
- total_added += file_info["linesAdded"]
-
if not files:
return None
diff --git a/tests/unit_tests/server/test_diff_service.py b/tests/unit_tests/server/test_diff_service.py
index 155ccc54e9..a411f56c38 100644
--- a/tests/unit_tests/server/test_diff_service.py
+++ b/tests/unit_tests/server/test_diff_service.py
@@ -8,7 +8,7 @@ def _git(repo: Path, *args: str) -> None:
subprocess.run(["git", *args], cwd=repo, check=True, capture_output=True, text=True)
-def test_git_diff_from_subdir_includes_repo_root_untracked_files(tmp_path):
+def test_git_diff_from_subdir_excludes_untracked_files(tmp_path):
repo = tmp_path / "repo"
repo.mkdir()
_git(repo, "init")
@@ -30,11 +30,8 @@ def test_git_diff_from_subdir_includes_repo_root_untracked_files(tmp_path):
assert diff is not None
assert str(tracked) in diff["files"]
- assert str(untracked) in diff["files"]
- assert diff["files"][str(untracked)]["isUntracked"] is True
- assert diff["files"][str(untracked)]["linesAdded"] == 0
- assert diff["files"][str(untracked)]["hunks"] == []
- assert diff["stats"]["filesChanged"] == 2
+ assert str(untracked) not in diff["files"]
+ assert diff["stats"]["filesChanged"] == 1
assert diff["stats"]["linesAdded"] == 1
assert diff["stats"]["linesRemoved"] == 1