@fanchao8609/agent_brain_sync 1.15.2 → 1.15.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/store.js +11 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanchao8609/agent_brain_sync",
3
- "version": "1.15.2",
3
+ "version": "1.15.3",
4
4
  "description": "agent-brain-sync: 跨会话 AI 编码记忆 — hook 纯触发 + CLI/MCP 读写 .brain markdown 图谱, 防并发写保护。",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/store.js CHANGED
@@ -879,7 +879,17 @@ export async function cmdWrapup({ dir }) {
879
879
  export async function cmdTodoArchive({ dir, keepDays = 3, dryRun = false } = {}) {
880
880
  let root;
881
881
  try { root = await requireBrain(dir || process.cwd()); } catch { return '未找到 .brain/ 图谱。先在项目根运行: abs init'; }
882
- const days = Math.max(1, Number(keepDays) || 3);
882
+ // 坑(2026-10-05 实测):原写法 `Math.max(1, Number(keepDays) || 3)` 有两个问题 ——
883
+ // ① JS falsy 陷阱:`0 || 3` 得 3,于是 `--keep-days 0` 被当成"没传值",静默变成
884
+ // 保留 3 天(用户以为归档了全部,实际一条没动,且输出还理直气壮说"保留近 3 天")。
885
+ // ② `Math.max(1, ...)` 会静默把 0 抬成 1 —— 即使修好 ①,用户也不知道自己被改了。
886
+ // 改为:显式校验 + 明确报错。宁可让用户改参数,也不静默改写他的意图。
887
+ const rawDays = Number(keepDays);
888
+ if (!Number.isFinite(rawDays) || rawDays < 1 || !Number.isInteger(rawDays)) {
889
+ return `✗ --keep-days 需为 ≥1 的整数(收到 "${keepDays}")\n`
890
+ + ' 下限 1 天是为了不误删今天刚完成的记录;要清空 Done 请先确认后手动编辑 todo.md。';
891
+ }
892
+ const days = rawDays;
883
893
  const todoP = brainPath(root, 'todo.md');
884
894
  const raw = await fs.readFile(todoP, 'utf8').catch(() => '');
885
895
  if (!raw.trim()) return '(todo.md 为空)';