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(diff): file info display for /diff command

ldstyle8a101304c819e
diff --git a/jiuwenswarm/channels/tui/frontend/src/core/types.ts b/jiuwenswarm/channels/tui/frontend/src/core/types.ts
index d32f6825ff..9a67fa2e13 100644
--- a/jiuwenswarm/channels/tui/frontend/src/core/types.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/core/types.ts
@@ -144,6 +144,10 @@ export interface FileDiff {
filePath: string;
hunks: Hunk[];
isNewFile: boolean;
+ isBinary?: boolean;
+ isLargeFile?: boolean;
+ isTruncated?: boolean;
+ isUntracked?: boolean;
linesAdded: number;
linesRemoved: number;
lastEditTime?: string;
@@ -165,6 +169,10 @@ export interface GitDiffFile {
filePath: string;
hunks: Hunk[];
isNewFile: boolean;
+ isBinary?: boolean;
+ isLargeFile?: boolean;
+ isTruncated?: boolean;
+ isUntracked?: boolean;
linesAdded: number;
linesRemoved: number;
lastEditTime: string | null;
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
index 6a9e5db032..9f2af538a5 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/app-screen.ts
@@ -364,6 +364,9 @@ interface DiffFileEntry {
linesRemoved: number;
isNewFile: boolean;
isUntracked: boolean;
+ isBinary: boolean;
+ isLargeFile: boolean;
+ isTruncated: boolean;
hunks: Hunk[];
source: "working" | string;
}
@@ -1487,7 +1490,10 @@ export class AppScreen implements Component, Focusable {
linesAdded: f.linesAdded,
linesRemoved: f.linesRemoved,
isNewFile: f.isNewFile,
- isUntracked: f.isNewFile,
+ isUntracked: f.isUntracked ?? f.isNewFile,
+ isBinary: f.isBinary ?? false,
+ isLargeFile: f.isLargeFile ?? false,
+ isTruncated: f.isTruncated ?? false,
hunks: f.hunks || [],
source: "working",
});
@@ -1501,7 +1507,10 @@ export class AppScreen implements Component, Focusable {
linesAdded: f.linesAdded,
linesRemoved: f.linesRemoved,
isNewFile: f.isNewFile,
- isUntracked: false,
+ isUntracked: f.isUntracked ?? false,
+ isBinary: f.isBinary ?? false,
+ isLargeFile: f.isLargeFile ?? false,
+ isTruncated: f.isTruncated ?? false,
hunks: f.hunks || [],
source: `Turn ${turn.turnIndex}`,
});
@@ -1510,8 +1519,13 @@ export class AppScreen implements Component, Focusable {
const totalAdded = files.reduce((s, f) => s + f.linesAdded, 0);
const totalRemoved = files.reduce((s, f) => s + f.linesRemoved, 0);
- const title = `Diff`;
- const subtitle = `${files.length} files changed +${totalAdded} -${totalRemoved}`;
+ const workingCount = gitDiff ? Object.keys(gitDiff.files).length : 0;
+ const turnCount = turns.length;
+ const title = `Diff (git diff HEAD)`;
+ const parts: string[] = [`${files.length} files changed +${totalAdded} -${totalRemoved}`];
+ if (workingCount > 0) parts.push(`working:${workingCount}`);
+ if (turnCount > 0) parts.push(`turns:${turnCount}`);
+ const subtitle = parts.join(" · ");
this.diffViewerState = {
viewMode: "list",
@@ -1662,18 +1676,56 @@ export class AppScreen implements Component, Focusable {
private _renderDiffDetailLines(file: DiffFileEntry, width: number): string[] {
const lines: string[] = [];
const displayPath = this._toRelativePath(file.filePath);
- const label = file.isUntracked ? "(untracked)" : file.isNewFile ? "(new)" : "";
+ const label = file.isUntracked
+ ? palette.text.dim("(untracked)")
+ : file.isNewFile
+ ? palette.text.dim("(new)")
+ : "";
- lines.push(`│ ${displayPath} ${label} +${file.linesAdded} -${file.linesRemoved}`);
+ const added = palette.status.success(`+${file.linesAdded}`);
+ const removed = palette.status.error(`-${file.linesRemoved}`);
+ lines.push(`│ ${displayPath} ${label} ${added} ${removed}`);
lines.push(`│ ${"─".repeat(Math.max(0, width - 4))}`);
+ if (file.isUntracked) {
+ lines.push(palette.text.dim("│ New file not yet staged."));
+ lines.push(palette.text.dim(`│ Run \`git add ${displayPath}\` to see line counts.`));
+ return lines;
+ }
+
+ if (file.isBinary) {
+ lines.push(palette.text.dim("│ Binary file - cannot display diff"));
+ return lines;
+ }
+
+ if (file.isLargeFile) {
+ lines.push(palette.text.dim("│ Large file - diff exceeds 1 MB limit"));
+ return lines;
+ }
+
for (const hunk of file.hunks) {
- lines.push(`│ @@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`);
+ lines.push(
+ palette.text.dim(
+ `│ @@ -${hunk.oldStart},${hunk.oldLines} +${hunk.newStart},${hunk.newLines} @@`,
+ ),
+ );
for (const line of hunk.lines) {
const display = `│ ${line}`;
- lines.push(truncateToWidth(display, width, ""));
+ let styled: string;
+ if (line.startsWith("+")) {
+ styled = palette.diff.add(display);
+ } else if (line.startsWith("-")) {
+ styled = palette.diff.remove(display);
+ } else {
+ styled = palette.diff.context(display);
+ }
+ lines.push(truncateToWidth(styled, width, ""));
}
}
+
+ if (file.isTruncated) {
+ lines.push(palette.text.dim("│ … diff truncated (exceeded 400 line limit)"));
+ }
return lines;
}
@@ -1692,6 +1744,10 @@ export class AppScreen implements Component, Focusable {
if (this.diffViewerState.viewMode === "list") {
const availableHeight = Math.max(1, this.tui.terminal.rows - 5);
+ if (this.diffViewerState.files.length === 0) {
+ lines.push(padToWidth(palette.text.dim(" No file changes in this session"), safeWidth));
+ }
+
for (let i = this.diffViewerState.scrollOffset; i < this.diffViewerState.files.length; i++) {
const file = this.diffViewerState.files[i]!;
const isSelected = i === this.diffViewerState.selectedIndex;
@@ -1700,11 +1756,42 @@ export class AppScreen implements Component, Focusable {
const displayPath = relativePath.length > safeWidth - 16
? relativePath.slice(0, safeWidth - 19) + "..."
: relativePath;
- const label = file.isUntracked ? "untracked" : file.source;
- const stats = `+${file.linesAdded} -${file.linesRemoved}`;
+
+ // 构建右侧状态标签(对齐 Claude Code FileStats):
+ // - untracked → "untracked"
+ // - binary → "Binary file"
+ // - large file → "Large file modified"
+ // - normal/truncated → +N -N [ (truncated)]
+ let statsLabel: string;
+ let statsStyled: string;
+ if (file.isUntracked) {
+ statsLabel = "untracked";
+ statsStyled = palette.text.dim("untracked");
+ } else if (file.isBinary) {
+ statsLabel = "Binary file";
+ statsStyled = palette.text.dim("Binary file");
+ } else if (file.isLargeFile) {
+ statsLabel = "Large file modified";
+ statsStyled = palette.text.dim("Large file modified");
+ } else {
+ const addPart = palette.status.success(`+${file.linesAdded}`);
+ const removePart = palette.status.error(`-${file.linesRemoved}`);
+ statsLabel = `+${file.linesAdded} -${file.linesRemoved}`;
+ statsStyled = `${addPart} ${removePart}`;
+ if (file.isTruncated) {
+ statsLabel += " (truncated)";
+ statsStyled += palette.text.dim(" (truncated)");
+ }
+ }
+
+ const sourceLabel = file.isUntracked
+ ? "untracked"
+ : file.isNewFile
+ ? "(new)"
+ : file.source;
const line = `${pointer}${displayPath}`;
- const padded = padToWidth(line, safeWidth - stats.length - label.length - 3);
- const fullLine = `${padded}${label} ${stats}`;
+ const padded = padToWidth(line, safeWidth - statsLabel.length - sourceLabel.length - 3);
+ const fullLine = `${padded}${palette.text.dim(sourceLabel)} ${statsStyled}`;
if (isSelected) {
lines.push(palette.text.accent(fullLine));
} else {
diff --git a/jiuwenswarm/channels/tui/frontend/src/ui/components/messages/diff-component.ts b/jiuwenswarm/channels/tui/frontend/src/ui/components/messages/diff-component.ts
index d002f5445a..d82ac99694 100644
--- a/jiuwenswarm/channels/tui/frontend/src/ui/components/messages/diff-component.ts
+++ b/jiuwenswarm/channels/tui/frontend/src/ui/components/messages/diff-component.ts
@@ -39,7 +39,7 @@ export class DiffComponent implements Component {
const trackedFiles: GitDiffFile[] = [];
const untrackedFiles: GitDiffFile[] = [];
for (const f of Object.values(gitDiff!.files)) {
- (f.isNewFile ? untrackedFiles : trackedFiles).push(f);
+ (f.isUntracked ? untrackedFiles : trackedFiles).push(f);
}
lines.push(...renderWrappedText(innerWidth,
@@ -53,7 +53,7 @@ export class DiffComponent implements Component {
// Untracked
for (const f of untrackedFiles) {
- lines.push(...this._renderCompactFile(f, innerWidth, "(untracked)"));
+ lines.push(...this._renderCompactFile(f, innerWidth));
}
// separator before turns
@@ -91,16 +91,35 @@ export class DiffComponent implements Component {
private _renderCompactFile(
fileDiff: FileDiff | GitDiffFile,
width: number,
- tag?: string,
): string[] {
const fileName = fileDiff.filePath.split(/[/\\]/).pop() || fileDiff.filePath;
- const label = tag || (fileDiff.isNewFile ? "(new)" : "");
- const added = palette.status.success(`+${fileDiff.linesAdded}`);
- const removed = palette.status.error(`-${fileDiff.linesRemoved}`);
+
+ // 构建右侧状态信息:
+ // - untracked → "untracked"
+ // - binary → "Binary file"
+ // - large file → "Large file modified"
+ // - normal/truncated → +N -N [ (truncated)]
+ let statsText: string;
+ if (fileDiff.isUntracked) {
+ statsText = palette.text.dim("untracked");
+ } else if (fileDiff.isBinary) {
+ statsText = palette.text.dim("Binary file");
+ } else if (fileDiff.isLargeFile) {
+ statsText = palette.text.dim("Large file modified");
+ } else {
+ const added = palette.status.success(`+${fileDiff.linesAdded}`);
+ const removed = palette.status.error(`-${fileDiff.linesRemoved}`);
+ statsText = `${added} ${removed}`;
+ if (fileDiff.isTruncated) {
+ statsText += palette.text.dim(" (truncated)");
+ }
+ }
+
+ const label = fileDiff.isNewFile && !fileDiff.isUntracked ? palette.text.dim("(new) ") : "";
const lines: string[] = [];
lines.push(...renderWrappedText(width,
- `│ ${fileName} ${label} ${added} ${removed}`,
+ `│ ${fileName} ${label} ${statsText}`,
palette.text.assistant));
return lines;
}
diff --git a/jiuwenswarm/server/utils/diff_service.py b/jiuwenswarm/server/utils/diff_service.py
index 1eb2528a34..7e1bb2a363 100644
--- a/jiuwenswarm/server/utils/diff_service.py
+++ b/jiuwenswarm/server/utils/diff_service.py
@@ -18,6 +18,12 @@ from jiuwenswarm.server.runtime.session.session_history import load_history_reco
logger = logging.getLogger(__name__)
+MAX_FILES = 50
+MAX_DIFF_SIZE_BYTES = 1_000_000
+MAX_LINES_PER_FILE = 400
+MAX_FILES_FOR_DETAILS = 500
+
+
class DiffService:
"""提供 turn-based diff 查询服务."""
@@ -88,18 +94,24 @@ class DiffService:
"filePath": file_path,
"hunks": [],
"isNewFile": False,
+ "isBinary": False,
+ "isLargeFile": False,
+ "isTruncated": False,
+ "isUntracked": False,
"linesAdded": 0,
"linesRemoved": 0,
"lastEditTime": None,
}
for op in edit_info["operations"]:
- hunks = self._compute_hunks(
+ hunks, truncated = self._compute_hunks(
op["old_content"],
op["new_content"],
)
turn["files"][file_path]["hunks"].extend(hunks)
turn["files"][file_path]["lastEditTime"] = op["timestamp"]
+ if truncated:
+ turn["files"][file_path]["isTruncated"] = True
if op["action"] == "write" and op["old_content"] is None:
turn["files"][file_path]["isNewFile"] = True
@@ -326,58 +338,80 @@ class DiffService:
def _compute_hunks(
old_content: str | None,
new_content: str | None,
- ) -> list[dict[str, Any]]:
- """计算结构化 diff hunks."""
+ max_lines: int = MAX_LINES_PER_FILE,
+ ) -> tuple[list[dict[str, Any]], bool]:
+ """计算结构化 diff hunks.
+
+ Returns:
+ (hunks, truncated): hunks 列表和是否被截断的标志。
+ """
# 处理删除文件的情况:new_content 为 None
if new_content is None:
if old_content is None:
- return []
+ return [], False
# 文件被删除:显示所有行被移除
lines = old_content.splitlines()
+ truncated = len(lines) > max_lines
+ if truncated:
+ lines = lines[:max_lines]
return [{
"oldStart": 1,
"oldLines": len(lines),
"newStart": 0,
"newLines": 0,
"lines": [f"-{line}" for line in lines],
- }]
+ }], truncated
# 处理新建文件的情况:old_content 为 None
if old_content is None:
lines = new_content.splitlines()
+ truncated = len(lines) > max_lines
+ if truncated:
+ lines = lines[:max_lines]
return [{
"oldStart": 0,
"oldLines": 0,
"newStart": 1,
"newLines": len(lines),
"lines": [f"+{line}" for line in lines],
- }]
+ }], truncated
old_lines = old_content.splitlines(keepends=True)
new_lines = new_content.splitlines(keepends=True)
if not old_lines and not new_lines:
- return []
+ return [], False
matcher = difflib.SequenceMatcher(None, old_lines, new_lines)
hunks: list[dict[str, Any]] = []
+ total_lines = 0
+ truncated = False
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
if tag == "equal":
continue
+ if total_lines >= max_lines:
+ truncated = True
+ break
+
old_start = i1 + 1
old_count = i2 - i1
new_start = j1 + 1
new_count = j2 - j1
lines: list[str] = []
+ remaining = max_lines - total_lines
- for k in range(i1, i2):
+ for k in range(i1, min(i2, i1 + remaining)):
lines.append(f"-{old_lines[k].rstrip()}")
+ total_lines += 1
- for k in range(j1, j2):
+ for k in range(j1, min(j2, j1 + max(0, remaining - (i2 - i1)))):
+ if total_lines >= max_lines:
+ break
lines.append(f"+{new_lines[k].rstrip()}")
+ total_lines += 1
hunks.append({
"oldStart": old_start,
@@ -387,7 +421,7 @@ class DiffService:
"lines": lines,
})
- return hunks
+ return hunks, truncated
@staticmethod
def _run_git_command(project_dir: str, args: list[str]) -> str | None:
@@ -425,6 +459,39 @@ class DiffService:
except Exception:
return False
+ @staticmethod
+ def _is_in_transient_git_state(project_dir: str) -> bool:
+ """检测是否处于 merge/rebase/cherry-pick/revert 等瞬态 git 状态.
+
+ 这些状态下工作区包含 incoming 改动(非用户意图编辑),
+ 应跳过 diff 计算以避免显示误导性内容。
+ """
+ import subprocess
+
+ try:
+ result = subprocess.run(
+ ["git", "rev-parse", "--git-dir"],
+ cwd=project_dir,
+ capture_output=True,
+ text=True,
+ timeout=5,
+ )
+ if result.returncode != 0:
+ return False
+ git_dir = Path(result.stdout.strip())
+ if not git_dir.is_absolute():
+ git_dir = Path(project_dir) / git_dir
+ except Exception:
+ return False
+
+ transient_files = [
+ "MERGE_HEAD",
+ "REBASE_HEAD",
+ "CHERRY_PICK_HEAD",
+ "REVERT_HEAD",
+ ]
+ return any((git_dir / name).exists() for name in transient_files)
+
@staticmethod
def _parse_git_numstat(output: str) -> dict[str, dict[str, int | bool]]:
"""解析 git diff --numstat 输出为 per-file 统计.
@@ -452,6 +519,27 @@ class DiffService:
}
return result
+ @staticmethod
+ def _parse_shortstat(output: str) -> dict[str, int] | None:
+ """解析 git diff --shortstat 输出.
+
+ 格式: " N files changed, N insertions(+), N deletions(-)"
+ 用于在加载完整 diff 前快速探测规模。
+ """
+ import re
+
+ match = re.match(
+ r"(\d+)\s+files?\s+changed(?:,\s+(\d+)\s+insertions?\(\+\))?(?:,\s+(\d+)\s+deletions?\(-\))?",
+ output.strip(),
+ )
+ if not match:
+ return None
+ return {
+ "filesChanged": int(match.group(1) or "0"),
+ "linesAdded": int(match.group(2) or "0"),
+ "linesRemoved": int(match.group(3) or "0"),
+ }
+
@staticmethod
def _parse_git_diff_hunks(output: str) -> dict[str, list[dict[str, Any]]]:
"""解析 git diff 输出为按文件分组的 hunk 列表.
@@ -468,6 +556,8 @@ class DiffService:
files: dict[str, list[dict[str, Any]]] = {}
current_file: str | None = None
current_hunk: dict[str, Any] | None = None
+ line_counts: dict[str, int] = {}
+ truncated: set[str] = set()
# 匹配 diff 头部: diff --git a/path b/path, --- a/path, +++ b/path
# 对于删除文件,+++ b/ 行是 +++ /dev/null 不会匹配,需要回退到 --- a/ 行
@@ -485,6 +575,7 @@ class DiffService:
current_file = file_match.group(1)
if current_file not in files:
files[current_file] = []
+ line_counts[current_file] = 0
current_hunk = None
continue
@@ -497,6 +588,7 @@ class DiffService:
current_file = path
if current_file not in files:
files[current_file] = []
+ line_counts[current_file] = 0
current_hunk = None
continue
@@ -526,12 +618,50 @@ class DiffService:
# 收集 hunk 行(+, -, 空格前缀的上下文行)
if line.startswith("+") or line.startswith("-") or line.startswith(" "):
+ if line_counts[current_file] >= MAX_LINES_PER_FILE:
+ truncated.add(current_file)
+ continue
current_hunk["lines"].append(line)
+ line_counts[current_file] += 1
- return files
+ return files, truncated
+
+ @staticmethod
+ def _split_large_file_diffs(
+ output: str,
+ ) -> tuple[str, set[str]]:
+ """将 git diff 输出按文件切分,跳过超过 MAX_DIFF_SIZE_BYTES 的文件块.
+
+ 返回 (过滤后的 diff 输出, 被跳过的大文件路径集合)。
+ 被跳过的文件不参与 hunk 解析,但 numstat 统计仍会保留。
+ """
+ import re
+
+ if not output:
+ return "", set()
+ # 以 "diff --git " 为分隔切分(首段通常为空)
+ chunks = output.split("diff --git ")
+ kept: list[str] = []
+ large_files: set[str] = set()
+ for chunk in chunks:
+ if not chunk:
+ continue
+ full = "diff --git " + chunk
+ if len(full.encode("utf-8", errors="replace")) > MAX_DIFF_SIZE_BYTES:
+ # 提取文件路径用于标记
+ m = re.search(r"^\+\+\+ b/(.+)$", full, re.MULTILINE)
+ if m:
+ large_files.add(m.group(1))
+ else:
+ m2 = re.search(r"^--- a/(.+)$", full, re.MULTILINE)
+ if m2 and m2.group(1) != "/dev/null":
+ large_files.add(m2.group(1))
+ continue
+ kept.append(full)
+ return "".join(kept), large_files
def _get_untracked_files(
- self, project_dir: str
+ self, project_dir: str, max_files: int = MAX_FILES
) -> dict[str, dict[str, Any]]:
"""获取未跟踪文件列表并生成合成 diff(全部为新增行)."""
output = self._run_git_command(
@@ -543,6 +673,8 @@ class DiffService:
files: dict[str, dict[str, Any]] = {}
for rel_path in output.strip().splitlines():
+ if len(files) >= max_files:
+ break
rel_path = rel_path.strip()
if not rel_path:
continue
@@ -555,6 +687,9 @@ class DiffService:
if content is not None:
lines = content.splitlines()
+ is_truncated = len(lines) > MAX_LINES_PER_FILE
+ if is_truncated:
+ lines = lines[:MAX_LINES_PER_FILE]
hunks = [{
"oldStart": 0,
"oldLines": 0,
@@ -566,11 +701,16 @@ class DiffService:
else:
hunks = []
lines_added = 0
+ is_truncated = False
files[abs_path] = {
"filePath": abs_path,
"hunks": hunks,
"isNewFile": True,
+ "isBinary": content is None,
+ "isLargeFile": False,
+ "isTruncated": is_truncated,
+ "isUntracked": True,
"linesAdded": lines_added,
"linesRemoved": 0,
"lastEditTime": None,
@@ -600,25 +740,48 @@ class DiffService:
return None
if not self._is_git_repo(project_dir):
return None
+ if self._is_in_transient_git_state(project_dir):
+ return None
files: dict[str, dict[str, Any]] = {}
total_added = 0
total_removed = 0
# 1. 已跟踪文件的改动: git diff HEAD
+ # 先用 --shortstat 快速探测规模,避免对超大 diff 加载完整内容
shortstat = self._run_git_command(project_dir, ["diff", "HEAD", "--shortstat"])
has_tracked_changes = shortstat and shortstat.strip() != ""
+ # 解析 shortstat 取得准确的文件/行数总计
+ shortstat_stats = self._parse_shortstat(shortstat) if has_tracked_changes else None
+ if shortstat_stats and shortstat_stats["filesChanged"] > MAX_FILES_FOR_DETAILS:
+ # 文件数过多,仅返回统计以避免加载数百 MB 内容
+ return {
+ "stats": {
+ "filesChanged": shortstat_stats["filesChanged"],
+ "linesAdded": shortstat_stats["linesAdded"],
+ "linesRemoved": shortstat_stats["linesRemoved"],
+ },
+ "files": {},
+ }
+
if has_tracked_changes:
numstat_output = self._run_git_command(project_dir, ["diff", "HEAD", "--numstat"])
diff_output = self._run_git_command(project_dir, ["diff", "HEAD"])
if numstat_output and diff_output:
per_file_stats = self._parse_git_numstat(numstat_output)
- all_hunks = self._parse_git_diff_hunks(diff_output)
+ filtered_output, large_files = self._split_large_file_diffs(diff_output)
+ all_hunks, truncated_files = self._parse_git_diff_hunks(filtered_output)
- for rel_path, stats in per_file_stats.items():
+ for rel_path, stats in list(per_file_stats.items())[:MAX_FILES]:
abs_path = str(Path(project_dir) / rel_path)
- hunks = all_hunks.get(rel_path, [])
+ is_binary = bool(stats.get("isBinary", False))
+ is_large = rel_path in large_files
+ is_truncated = rel_path in truncated_files
+ if is_binary or is_large:
+ hunks = []
+ else:
+ hunks = all_hunks.get(rel_path, [])
lines_added = stats["added"]
lines_removed = stats["removed"]
total_added += lines_added
@@ -628,15 +791,23 @@ class DiffService:
"filePath": abs_path,
"hunks": hunks,
"isNewFile": False,
+ "isBinary": is_binary,
+ "isLargeFile": is_large,
+ "isTruncated": is_truncated,
+ "isUntracked": False,
"linesAdded": lines_added,
"linesRemoved": lines_removed,
"lastEditTime": None,
}
- # 2. 未跟踪的新文件: git ls-files --others --exclude-standard
- untracked = self._get_untracked_files(project_dir)
+ # 2. 未跟踪的新文件: 仅填充剩余名额,避免无限加载
+ remaining_slots = max(0, MAX_FILES - len(files))
+ untracked = self._get_untracked_files(project_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_added += file_info["linesAdded"]