refactor(wechat_kf): persist sync_msg cursor under $HOME

Move the sync_msg cursor file from the project-local tmp/ dir to ~/.wechat_kf_cursors.json so it survives tmp/ cleanups and cwd changes across restarts. Aligns with the weixin channel's credentials file convention.

- add wechat_kf_cursor_path config (default ~/.wechat_kf_cursors.json)
- expand ~ via os.path.expanduser in the channel init
- chmod the cursor file to 0o600 after each flush (no-op on Windows)
This commit is contained in:
6vision
2026-05-28 14:33:45 +08:00
parent 877b848370
commit 37661daf40
3 changed files with 12 additions and 3 deletions

View File

@@ -48,6 +48,12 @@ class CursorStore:
with open(tmp_path, "w", encoding="utf-8") as f:
json.dump(self._data, f, ensure_ascii=False)
os.replace(tmp_path, self._file_path)
# Tighten permissions: cursor file lives in $HOME, restrict to owner.
# No-op on Windows.
try:
os.chmod(self._file_path, 0o600)
except Exception:
pass
except Exception as e:
logger.warning(f"[wechat_kf] failed to flush cursor file {self._file_path}: {e}")
try: