fix(gitea): 同步會漏掉子資料夾與非 ASCII 檔名的檔案

兩個各自獨立、但都是「檔案在本機有、在存取庫沒有/拉不回來」的靜默失真:

1. `listAreaFiles` 只收資料夾第一層的 `entry.isFile()`,所以
   `mindmap/threads/archive/`(睡眠時把太久沒動的思維導圖收進去的地方)
   從來沒有被同步過。改成遞迴。

2. `git ls-files` / `status --porcelain` / `diff --name-only` 預設會把
   非 ASCII 路徑引號跳脫成 `"Memory-\350\267\250…"`。長期記憶的檔名正好是中文的,
   於是這些檔名跟工作副本比對不上:pull 時被當成「clone 裡沒有的東西」整批略過
   (拉回一個沒有長期記憶的人格),本機刪掉的也不會從遠端消失。
   一律改用 `-z`,並把三處解析收斂成 `diffPaths()` / `statusPaths()`。
   順便修掉 porcelain 第一筆因為整體 trim 而少一個字元的解析錯誤。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-31 09:32:49 +00:00
co-authored by Claude Opus 5
parent 9e7a9cf8e2
commit b937c9ad7a
2 changed files with 51 additions and 23 deletions
+8
View File
@@ -864,6 +864,14 @@ check("高頻資料在檔案區、低頻資料在 Wiki 區",
covered("journal/2026-01.jsonl")[0] === "files" && covered("state/said.jsonl")[0] === "files" &&
covered("IDENTITY.md")[0] === "wiki" && covered("memory/long-term/x.md")[0] === "wiki" &&
covered("relations/graph.json")[0] === "wiki");
// 分區的路徑有好幾個是資料夾,而資料夾裡還有資料夾:`mindmap/threads/archive/`
// (睡眠時把太久沒動的思維導圖收進去)只看第一層的話整個不會被同步。
check("同步範圍會遞迴進子資料夾(mindmap/threads/archive 以前整個漏掉)", (() => {
const dir = path.join(pl.personaDir("alpha"), "mindmap", "threads", "archive");
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(path.join(dir, "old-thread.mmd"), "%% 收起來的舊思維導圖\nflowchart TD\n");
return gt.listAreaFiles(pl.personaDir("alpha"), "files").includes("mindmap/threads/archive/old-thread.mmd");
})(), gt.listAreaFiles(pl.personaDir("alpha"), "files").join(", "));
check("沒設定 Gitea 時同步只是略過,不會爆炸", (() => {
const res = cli(["sync", "status", "--session", S_CODE]);
const push = cli(["sync", "push", "--session", S_CODE], { expectOk: false });