session-sync 修存量 worktree 洗白:INSERT OR IGNORE 洗不掉 WSL 已存在 project 行

- 新增 FIX_WORKTREE_SRC:每次同步无条件把 WSL project 表存量 C:/Users/ypshidifu
  与 C://Users//ypshidifu 前缀 worktree UPDATE 成 /root(幂等)
- 修 WSL 侧 Session location unavailable(截图实锤:推送侧转换只对新插入行生效,
  存量行永远不更新且无 missing/stale 时 import 根本不执行)
This commit is contained in:
ypshidifu
2026-10-20 23:13:30 +08:00
parent 6b65ec50e7
commit 546fc07779
+45
View File
@@ -173,6 +173,39 @@ except Exception as e:
open("/root/.oc_sync_result.json", "w", encoding="utf-8").write(json.dumps(res)) open("/root/.oc_sync_result.json", "w", encoding="utf-8").write(json.dumps(res))
''' '''
# ★ 存量 worktree 洗白(2026-10-20 截图实锤「Session location unavailable / C:/Users/ypshidifu」):
# IMPORT 用 INSERT OR IGNORE —— WSL 已存在的 project 行永远不会被 UPDATE,
# 推送侧的路径转换只对「新插入」的行生效,存量 Win 路径洗不掉。
# 此脚本每次同步无条件跑(幂等 UPDATE,开销可忽略),把 WSL project 表里
# 所有 C:/Users/ypshidifu 或 C:\Users\ypshidifu 前缀的 worktree 洗成 /root。
FIX_WORKTREE_SRC = r'''
import sqlite3
BK = chr(92)
PRE_SL = "C:/Users/ypshidifu"
PRE_BK = "C:" + BK + "Users" + BK + "ypshidifu"
res = {"fixed": 0, "err": None}
try:
con = sqlite3.connect("/root/.local/share/opencode/opencode.db")
cur = con.cursor()
rows = cur.execute("select id, worktree from project").fetchall()
for pid, wt in rows:
if not wt or not isinstance(wt, str):
continue
if wt.startswith(PRE_SL):
cur.execute("update project set worktree=? where id=?",
("/root" + wt[len(PRE_SL):], pid))
res["fixed"] += 1
elif wt.startswith(PRE_BK):
cur.execute("update project set worktree=? where id=?",
("/root" + wt[len(PRE_BK):], pid))
res["fixed"] += 1
con.commit()
con.close()
except Exception as e:
res["err"] = str(e)
open("/root/.oc_fix_wt_result.json", "w", encoding="utf-8").write(json.dumps(res))
'''
def main(): def main():
t0 = time.time() t0 = time.time()
@@ -206,6 +239,18 @@ def main():
wsl_sessions = probe.get("sessions") or {} wsl_sessions = probe.get("sessions") or {}
wsl_sessions_v2 = probe.get("sessions_v2") or {} wsl_sessions_v2 = probe.get("sessions_v2") or {}
wsl_msgs = probe.get("msgs") or {} wsl_msgs = probe.get("msgs") or {}
# ★ 存量 worktree 洗白:每次无条件跑(幂等,修 INSERT OR IGNORE 洗不掉存量行的洞)
try:
rc_fw, _ = wsl_py(FIX_WORKTREE_SRC, timeout=60)
if rc_fw == 0:
fw = json.loads(wsl_cat("/root/.oc_fix_wt_result.json"))
if fw.get("fixed"):
log("worktree fixed: %d rows -> /root" % fw["fixed"])
if fw.get("err"):
log("worktree fix err: " + str(fw["err"]))
except Exception as e:
log("worktree fix exception: " + str(e))
# WSL 侧合并双表(id -> 最新 time_updated) # WSL 侧合并双表(id -> 最新 time_updated)
wsl_all = dict(wsl_sessions) wsl_all = dict(wsl_sessions)
for k, v in (wsl_sessions_v2 or {}).items(): for k, v in (wsl_sessions_v2 or {}).items():