codebee 0.1.68 → 0.1.70

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 (133) hide show
  1. package/CHANGELOG.md +580 -543
  2. package/LICENSE +21 -21
  3. package/README.md +11 -0
  4. package/app/browser-final-1440.png +0 -0
  5. package/app/browser-final-390.png +0 -0
  6. package/app/browser-google-fallback.png +0 -0
  7. package/app/browser-google-test.png +0 -0
  8. package/app/browser-workbench-1440.png +0 -0
  9. package/app/browser-workbench-390.png +0 -0
  10. package/app/browser-workspace-google.png +0 -0
  11. package/app/browser-workspace-smoke.png +0 -0
  12. package/app/browser-workspace.png +0 -0
  13. package/app/core/acceptance.py +100 -100
  14. package/app/core/aiflavor.py +197 -197
  15. package/app/core/artifacts.py +148 -148
  16. package/app/core/assets.py +110 -110
  17. package/app/core/attachments.py +623 -623
  18. package/app/core/audit.py +30 -0
  19. package/app/core/automation.py +853 -758
  20. package/app/core/backup.py +470 -470
  21. package/app/core/beekeeper.py +183 -183
  22. package/app/core/benchstore.py +95 -0
  23. package/app/core/board.py +209 -209
  24. package/app/core/bookmeta.py +935 -930
  25. package/app/core/bookmeta_catalog.py +180 -180
  26. package/app/core/branching.py +137 -137
  27. package/app/core/builtin_agent.py +1673 -1234
  28. package/app/core/capability.py +144 -144
  29. package/app/core/catalog.py +7 -1
  30. package/app/core/chaptersafe.py +32 -32
  31. package/app/core/cleanup.py +303 -303
  32. package/app/core/compaction.py +201 -201
  33. package/app/core/covergen.py +356 -356
  34. package/app/core/defectretro.py +43 -43
  35. package/app/core/diagnostics.py +114 -114
  36. package/app/core/dispatch.py +190 -173
  37. package/app/core/dispatch_log.py +128 -128
  38. package/app/core/env_scrub.py +85 -85
  39. package/app/core/error_codes.py +33 -24
  40. package/app/core/errorlog.py +137 -137
  41. package/app/core/evalbench.py +720 -0
  42. package/app/core/evaluation.py +174 -174
  43. package/app/core/failure_notify.py +290 -290
  44. package/app/core/flows.py +228 -3
  45. package/app/core/goal_service.py +167 -167
  46. package/app/core/health.py +374 -374
  47. package/app/core/history.py +38 -38
  48. package/app/core/hooks.py +162 -162
  49. package/app/core/jobs.py +51 -30
  50. package/app/core/manager.py +2143 -2122
  51. package/app/core/market.py +362 -362
  52. package/app/core/market_remote.py +10 -0
  53. package/app/core/mcp_client.py +287 -0
  54. package/app/core/mocks.py +64 -64
  55. package/app/core/modelhub.py +193 -10
  56. package/app/core/notify.py +201 -106
  57. package/app/core/novel_quality.py +189 -0
  58. package/app/core/operations.py +228 -228
  59. package/app/core/paihang.py +138 -138
  60. package/app/core/paths.py +6 -2
  61. package/app/core/pipeline.py +426 -28
  62. package/app/core/planner.py +243 -22
  63. package/app/core/plugins.py +525 -0
  64. package/app/core/portguard.py +111 -111
  65. package/app/core/preview.py +293 -293
  66. package/app/core/publish/__init__.py +7 -7
  67. package/app/core/publish/auto.py +367 -367
  68. package/app/core/publish/browser.py +655 -539
  69. package/app/core/publish/fanqie.py +165 -159
  70. package/app/core/publish/flow.py +589 -440
  71. package/app/core/publish/flows-fanqie-calibrated.json +336 -332
  72. package/app/core/publish/ledger.py +229 -203
  73. package/app/core/publish/manager.py +824 -692
  74. package/app/core/publish/qimao.py +146 -141
  75. package/app/core/publish/ws.py +139 -139
  76. package/app/core/redact.py +38 -38
  77. package/app/core/remotesync.py +121 -0
  78. package/app/core/repeat_guard.py +129 -129
  79. package/app/core/router.py +398 -398
  80. package/app/core/runner.py +2142 -2067
  81. package/app/core/selfupdate.py +384 -384
  82. package/app/core/session_log.py +161 -161
  83. package/app/core/sessions.py +312 -312
  84. package/app/core/settings.py +186 -149
  85. package/app/core/settings_schema.py +270 -262
  86. package/app/core/share_page.py +114 -114
  87. package/app/core/skill_scan.py +122 -122
  88. package/app/core/skillpacks/fanqie-novel.md +80 -80
  89. package/app/core/skillpacks/market/character-bible.md +66 -66
  90. package/app/core/skillpacks/market/code-risk-checklist.md +58 -58
  91. package/app/core/skillpacks/market/git-workflow.md +57 -57
  92. package/app/core/skillpacks/market/release-notes.md +72 -72
  93. package/app/core/skillpacks/market/weekly-report.md +71 -71
  94. package/app/core/skillpacks/market/worldview-consistency.md +70 -70
  95. package/app/core/step_runner.py +132 -132
  96. package/app/core/store.py +104 -82
  97. package/app/core/task_compile.py +199 -199
  98. package/app/core/telemetry.py +292 -292
  99. package/app/core/tlsctx.py +64 -64
  100. package/app/core/token_meter.py +147 -147
  101. package/app/core/tracing.py +144 -144
  102. package/app/core/upstream.py +41 -41
  103. package/app/core/usage.py +1035 -862
  104. package/app/core/volumes.py +389 -389
  105. package/app/core/wxdigest.py +858 -858
  106. package/app/core/zentao.py +2614 -2465
  107. package/app/current-browser.png +0 -0
  108. package/app/main.py +3245 -2981
  109. package/app/mcp_server.py +175 -0
  110. package/app/pet.py +82 -21
  111. package/app/pick_dialog.py +110 -110
  112. package/app/plugins/code-review-helper/.codex-plugin/plugin.json +18 -0
  113. package/app/plugins/code-review-helper/skills/review.md +16 -0
  114. package/app/ui/app.js +15706 -14399
  115. package/app/ui/artdiff.js +74 -74
  116. package/app/ui/board.html +162 -162
  117. package/app/ui/board.js +305 -305
  118. package/app/ui/i18n.js +3012 -2770
  119. package/app/ui/icons/bee.svg +79 -79
  120. package/app/ui/index.html +277 -13
  121. package/app/ui/manifest.json +16 -16
  122. package/app/ui/qrcode.js +2297 -2297
  123. package/app/ui/style.css +802 -16
  124. package/bin/tutti.js +147 -147
  125. package/package.json +47 -46
  126. package/tools/wx_reader.py +261 -261
  127. package/app/.playwright-cli/console-2026-09-23T08-26-03-635Z.log +0 -88
  128. package/app/.playwright-cli/page-2026-09-23T08-26-03-845Z.yml +0 -126
  129. package/app/.playwright-cli/page-2026-09-23T08-29-44-203Z.png +0 -0
  130. package/app/.playwright-cli/page-2026-09-23T08-35-42-046Z.yml +0 -210
  131. package/app/.playwright-cli/page-2026-09-23T08-36-52-858Z.png +0 -0
  132. package/app/.playwright-cli/page-2026-09-23T08-37-33-938Z.png +0 -0
  133. package/app/.playwright-cli/run-detail-after.png +0 -0
@@ -1,149 +1,186 @@
1
- # -*- coding: utf-8 -*-
2
- """运行设置(data/settings.json):并发 worker 数 + 默认保存路径。"""
3
- from __future__ import annotations
4
-
5
- import json
6
- import threading
7
- from pathlib import Path
8
-
9
- from . import paths
10
-
11
- _LOCK = threading.RLock()
12
- _FILE = paths.DATA_DIR / "settings.json"
13
-
14
- # default_workdir 为空表示未自定义,用 builtin_workdir() 回落;
15
- # telemetry_errors:匿名错误回传开关(默认开;关掉后版本 ping/错误上传/诊断包遥测部分全部停发,
16
- # 「导出诊断包」是用户手动操作不受此开关限制)
17
- # publish_daily_cap / publish_fail_streak:自动发布护栏——每任务每平台每日
18
- # 成功发章上限、平台连续失败几次后暂停自动发布(publish/auto.py 读取)
19
- # pet_enabled / pet_mode:桌面蜜蜂(app/pet.py)开关与显示模式。关闭后看护线程
20
- # 不再拉起、在岗蜜蜂轮询到 false 自行退出;mode=always 常驻,tasks_only 仅任务
21
- # 运行时出现(空闲 90s 隐身)。
22
- # cleanup_enabled / cleanup_retention_days:每日垃圾清理(core/cleanup.py)——
23
- # 运行过程日志/发布截图/bak 残留等超期自动清理;retention 为保留天数。
24
- DEFAULTS = {"max_concurrent_jobs": 12, "default_workdir": "", "hooks_token": "",
25
- "telemetry_errors": True, "publish_daily_cap": 10,
26
- "publish_fail_streak": 3, "notify_webhook": "", "notify_base_url": "",
27
- "pet_enabled": True, "pet_mode": "always", "pet_skin": "plush",
28
- "cleanup_enabled": True, "cleanup_retention_days": 14,
29
- # claude_config_sync:打开/运行前防线是否直写 ~/.claude/settings.json。
30
- # 关闭后交互 claude 配置归用户手动管理(cc-switch 等),编排步骤经
31
- # runner 一次性 --settings 注入绑定链,路由不受影响(manager 读取)
32
- "claude_config_sync": True}
33
- # 桌宠形象白名单(与 app/pet.py 的 SKINS 对齐;这里不 import pet 模块,避免
34
- # core 反向依赖 app 根目录脚本)
35
- PET_SKINS = ("plush", "robot")
36
- # 并发保护上限 24:编排任务有空位即直接启动,满载回滚 queued 排队自动补跑,
37
- # 不秒判失败;同任务单飞守卫在 jobs 层。该上限保护的是本机资源(CLI 子进程
38
- # 数),与各 API 厂商的限流无关;direct 对话走 jobs 轻量池不占此额度。
39
- MIN_WORKERS, MAX_WORKERS = 1, 24
40
-
41
-
42
- def builtin_workdir():
43
- """内置默认保存路径:<data 目录同级>/workspace。"""
44
- return str(paths.DATA_DIR.parent / "workspace")
45
-
46
-
47
- def default_workdir():
48
- """当前生效的默认保存路径(自定义优先,回落内置值)。"""
49
- raw = str(load().get("default_workdir") or "").strip()
50
- return raw if raw else builtin_workdir()
51
-
52
-
53
- def _norm_workdir(v):
54
- """展开 ~ 并转绝对路径;空值合法(回落内置)。返回 (标准化串, 错误)。"""
55
- v = str(v or "").strip()
56
- if not v:
57
- return "", None
58
- if v.startswith("~"):
59
- v = str(Path(v).expanduser())
60
- p = Path(v)
61
- if not p.is_absolute():
62
- return "", "默认保存路径必须是绝对路径"
63
- return str(p), None
64
-
65
-
66
- def load():
67
- with _LOCK:
68
- try:
69
- data = json.loads(_FILE.read_text(encoding="utf-8"))
70
- except Exception:
71
- data = {}
72
- out = dict(DEFAULTS)
73
- if isinstance(data, dict):
74
- out.update({k: v for k, v in data.items() if k in DEFAULTS})
75
- try:
76
- out["max_concurrent_jobs"] = max(MIN_WORKERS, min(MAX_WORKERS, int(out["max_concurrent_jobs"])))
77
- except Exception:
78
- out["max_concurrent_jobs"] = DEFAULTS["max_concurrent_jobs"]
79
- wd, _ = _norm_workdir(out.get("default_workdir"))
80
- out["default_workdir"] = wd
81
- out["default_workdir_effective"] = wd if wd else builtin_workdir()
82
- return out
83
-
84
-
85
- def save(patch):
86
- """合并保存。返回 (view, 错误)。"""
87
- if not isinstance(patch, dict):
88
- return load(), "payload 必须是对象"
89
- with _LOCK:
90
- cur = load()
91
- if "max_concurrent_jobs" in patch:
92
- try:
93
- cur["max_concurrent_jobs"] = int(patch["max_concurrent_jobs"])
94
- except Exception:
95
- return cur, "max_concurrent_jobs 必须是整数"
96
- if not MIN_WORKERS <= cur["max_concurrent_jobs"] <= MAX_WORKERS:
97
- return cur, "max_concurrent_jobs 取值 %d-%d" % (MIN_WORKERS, MAX_WORKERS)
98
- if "default_workdir" in patch:
99
- wd, err = _norm_workdir(patch.get("default_workdir"))
100
- if err:
101
- return cur, err
102
- cur["default_workdir"] = wd
103
- if "hooks_token" in patch:
104
- cur["hooks_token"] = str(patch.get("hooks_token") or "").strip()[:128]
105
- if "telemetry_errors" in patch:
106
- cur["telemetry_errors"] = bool(patch.get("telemetry_errors"))
107
- if "publish_daily_cap" in patch:
108
- try:
109
- cur["publish_daily_cap"] = max(1, min(50, int(patch.get("publish_daily_cap"))))
110
- except (TypeError, ValueError):
111
- return cur, "publish_daily_cap 必须是 1-50 的整数"
112
- if "publish_fail_streak" in patch:
113
- try:
114
- cur["publish_fail_streak"] = max(1, min(10, int(patch.get("publish_fail_streak"))))
115
- except (TypeError, ValueError):
116
- return cur, "publish_fail_streak 必须是 1-10 的整数"
117
- if "notify_webhook" in patch:
118
- cur["notify_webhook"] = str(patch.get("notify_webhook") or "").strip()[:300]
119
- if "notify_base_url" in patch:
120
- cur["notify_base_url"] = str(patch.get("notify_base_url") or "").strip()[:200]
121
- if "pet_enabled" in patch:
122
- cur["pet_enabled"] = bool(patch.get("pet_enabled"))
123
- if "pet_mode" in patch:
124
- pm = str(patch.get("pet_mode") or "").strip()
125
- if pm not in ("always", "tasks_only"):
126
- return cur, "pet_mode 只能是 always 或 tasks_only"
127
- cur["pet_mode"] = pm
128
- if "pet_skin" in patch:
129
- ps = str(patch.get("pet_skin") or "").strip()
130
- if ps not in PET_SKINS:
131
- return cur, "pet_skin 只能是 %s 之一" % "/".join(PET_SKINS)
132
- cur["pet_skin"] = ps
133
- if "cleanup_enabled" in patch:
134
- cur["cleanup_enabled"] = bool(patch.get("cleanup_enabled"))
135
- if "claude_config_sync" in patch:
136
- cur["claude_config_sync"] = bool(patch.get("claude_config_sync"))
137
- if "cleanup_retention_days" in patch:
138
- try:
139
- cur["cleanup_retention_days"] = int(patch.get("cleanup_retention_days"))
140
- except (TypeError, ValueError):
141
- return cur, "cleanup_retention_days 必须是整数"
142
- if not 1 <= cur["cleanup_retention_days"] <= 365:
143
- return cur, "cleanup_retention_days 取值 1-365"
144
- _FILE.parent.mkdir(parents=True, exist_ok=True)
145
- tmp = _FILE.with_suffix(".tmp")
146
- tmp.write_text(json.dumps(cur, ensure_ascii=False, indent=2), encoding="utf-8")
147
- tmp.replace(_FILE)
148
- cur["default_workdir_effective"] = cur["default_workdir"] if cur["default_workdir"] else builtin_workdir()
149
- return cur, None
1
+ # -*- coding: utf-8 -*-
2
+ """运行设置(data/settings.json):并发 worker 数 + 默认保存路径。"""
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import threading
7
+ from pathlib import Path
8
+
9
+ from . import paths
10
+
11
+ _LOCK = threading.RLock()
12
+ _FILE = paths.DATA_DIR / "settings.json"
13
+
14
+ # default_workdir 为空表示未自定义,用 builtin_workdir() 回落;
15
+ # telemetry_errors:匿名错误回传开关(默认开;关掉后版本 ping/错误上传/诊断包遥测部分全部停发,
16
+ # 「导出诊断包」是用户手动操作不受此开关限制)
17
+ # publish_daily_cap / publish_fail_streak:自动发布护栏——每任务每平台每日
18
+ # 成功发章上限、平台连续失败几次后暂停自动发布(publish/auto.py 读取)
19
+ # pet_enabled / pet_mode:桌面蜜蜂(app/pet.py)开关与显示模式。关闭后看护线程
20
+ # 不再拉起、在岗蜜蜂轮询到 false 自行退出;mode=always 常驻,tasks_only 仅任务
21
+ # 运行时出现(空闲 90s 隐身)。
22
+ # cleanup_enabled / cleanup_retention_days:每日垃圾清理(core/cleanup.py)——
23
+ # 运行过程日志/发布截图/bak 残留等超期自动清理;retention 为保留天数。
24
+ # 个人推送通道(core/notify.py 读取):Bark(iOS)/ ntfy(自托管友好)/
25
+ # Server酱(微信)/ Telegram Bot。密钥只存本机 settings.json,不出网(推送
26
+ # 时才带着发给对应服务)。bark_server 留空回落官方 api.day.app。
27
+ DEFAULTS = {"max_concurrent_jobs": 12, "default_workdir": "", "hooks_token": "",
28
+ "telemetry_errors": True, "publish_daily_cap": 10,
29
+ "publish_fail_streak": 3, "notify_webhook": "", "notify_base_url": "",
30
+ "notify_bark_server": "", "notify_bark_key": "",
31
+ "notify_ntfy_topic": "", "notify_serverchan_key": "",
32
+ "notify_telegram_token": "", "notify_telegram_chat_id": "",
33
+ # 评测台定时回归(evalbench.fire_due,automation tick 调用):
34
+ # enabled=False 关;days 间隔天数控节流;mcp_servers=内置智能体的
35
+ # MCP 服务器清单(JSON 数组字符串,stdio 形态)
36
+ "bench_auto_enabled": False, "bench_auto_days": 7,
37
+ "mcp_servers": "",
38
+ # 备份远程通道(remotesync):导出成功后自动 PUT 到 WebDAV/S3 兼容
39
+ # 端点(Basic auth);密钥只存本机
40
+ "backup_remote_enabled": False, "backup_remote_url": "",
41
+ "backup_remote_user": "", "backup_remote_pass": "",
42
+ "pet_enabled": True, "pet_mode": "always", "pet_skin": "plush",
43
+ "cleanup_enabled": True, "cleanup_retention_days": 14,
44
+ # claude_config_sync:打开/运行前防线是否直写 ~/.claude/settings.json。
45
+ # 关闭后交互 claude 配置归用户手动管理(cc-switch 等),编排步骤经
46
+ # runner 一次性 --settings 注入绑定链,路由不受影响(manager 读取)
47
+ "claude_config_sync": True}
48
+ # 桌宠形象白名单(与 app/pet.py 的 SKINS 对齐;这里不 import pet 模块,避免
49
+ # core 反向依赖 app 根目录脚本)
50
+ PET_SKINS = ("plush", "robot")
51
+ # 并发保护上限 24:编排任务有空位即直接启动,满载回滚 queued 排队自动补跑,
52
+ # 不秒判失败;同任务单飞守卫在 jobs 层。该上限保护的是本机资源(CLI 子进程
53
+ # 数),与各 API 厂商的限流无关;direct 对话走 jobs 轻量池不占此额度。
54
+ MIN_WORKERS, MAX_WORKERS = 1, 24
55
+
56
+
57
+ def builtin_workdir():
58
+ """内置默认保存路径:数据目录内的 workspace/(CodeBee 自己的地盘,
59
+ 启动 ensure_dirs 即创建;老版本落在数据目录同级——Windows 上是
60
+ AppData\\Roaming\\workspace,平时不存在点开即报错,已废弃)。"""
61
+ return str(paths.DATA_DIR / "workspace")
62
+
63
+
64
+ def default_workdir():
65
+ """当前生效的默认保存路径(自定义优先,回落内置值)。"""
66
+ raw = str(load().get("default_workdir") or "").strip()
67
+ return raw if raw else builtin_workdir()
68
+
69
+
70
+ def _norm_workdir(v):
71
+ """展开 ~ 并转绝对路径;空值合法(回落内置)。返回 (标准化串, 错误)。"""
72
+ v = str(v or "").strip()
73
+ if not v:
74
+ return "", None
75
+ if v.startswith("~"):
76
+ v = str(Path(v).expanduser())
77
+ p = Path(v)
78
+ if not p.is_absolute():
79
+ return "", "默认保存路径必须是绝对路径"
80
+ return str(p), None
81
+
82
+
83
+ def load():
84
+ with _LOCK:
85
+ try:
86
+ data = json.loads(_FILE.read_text(encoding="utf-8"))
87
+ except Exception:
88
+ data = {}
89
+ out = dict(DEFAULTS)
90
+ if isinstance(data, dict):
91
+ out.update({k: v for k, v in data.items() if k in DEFAULTS})
92
+ try:
93
+ out["max_concurrent_jobs"] = max(MIN_WORKERS, min(MAX_WORKERS, int(out["max_concurrent_jobs"])))
94
+ except Exception:
95
+ out["max_concurrent_jobs"] = DEFAULTS["max_concurrent_jobs"]
96
+ wd, _ = _norm_workdir(out.get("default_workdir"))
97
+ out["default_workdir"] = wd
98
+ out["default_workdir_effective"] = wd if wd else builtin_workdir()
99
+ return out
100
+
101
+
102
+ def save(patch):
103
+ """合并保存。返回 (view, 错误)。"""
104
+ if not isinstance(patch, dict):
105
+ return load(), "payload 必须是对象"
106
+ with _LOCK:
107
+ cur = load()
108
+ if "max_concurrent_jobs" in patch:
109
+ try:
110
+ cur["max_concurrent_jobs"] = int(patch["max_concurrent_jobs"])
111
+ except Exception:
112
+ return cur, "max_concurrent_jobs 必须是整数"
113
+ if not MIN_WORKERS <= cur["max_concurrent_jobs"] <= MAX_WORKERS:
114
+ return cur, "max_concurrent_jobs 取值 %d-%d" % (MIN_WORKERS, MAX_WORKERS)
115
+ if "default_workdir" in patch:
116
+ wd, err = _norm_workdir(patch.get("default_workdir"))
117
+ if err:
118
+ return cur, err
119
+ cur["default_workdir"] = wd
120
+ if "hooks_token" in patch:
121
+ cur["hooks_token"] = str(patch.get("hooks_token") or "").strip()[:128]
122
+ if "telemetry_errors" in patch:
123
+ cur["telemetry_errors"] = bool(patch.get("telemetry_errors"))
124
+ if "publish_daily_cap" in patch:
125
+ try:
126
+ cur["publish_daily_cap"] = max(1, min(50, int(patch.get("publish_daily_cap"))))
127
+ except (TypeError, ValueError):
128
+ return cur, "publish_daily_cap 必须是 1-50 的整数"
129
+ if "publish_fail_streak" in patch:
130
+ try:
131
+ cur["publish_fail_streak"] = max(1, min(10, int(patch.get("publish_fail_streak"))))
132
+ except (TypeError, ValueError):
133
+ return cur, "publish_fail_streak 必须是 1-10 的整数"
134
+ if "notify_webhook" in patch:
135
+ cur["notify_webhook"] = str(patch.get("notify_webhook") or "").strip()[:300]
136
+ if "notify_base_url" in patch:
137
+ cur["notify_base_url"] = str(patch.get("notify_base_url") or "").strip()[:200]
138
+ for _nk, _nmax in (("notify_bark_server", 200), ("notify_bark_key", 128),
139
+ ("notify_ntfy_topic", 200), ("notify_serverchan_key", 128),
140
+ ("notify_telegram_token", 128), ("notify_telegram_chat_id", 64)):
141
+ if _nk in patch:
142
+ cur[_nk] = str(patch.get(_nk) or "").strip()[:_nmax]
143
+ if "bench_auto_enabled" in patch:
144
+ cur["bench_auto_enabled"] = bool(patch.get("bench_auto_enabled"))
145
+ if "bench_auto_days" in patch:
146
+ try:
147
+ cur["bench_auto_days"] = max(1, min(90, int(patch.get("bench_auto_days"))))
148
+ except (TypeError, ValueError):
149
+ return cur, "bench_auto_days 必须是 1-90 的整数"
150
+ if "mcp_servers" in patch:
151
+ cur["mcp_servers"] = str(patch.get("mcp_servers") or "").strip()[:4000]
152
+ if "backup_remote_enabled" in patch:
153
+ cur["backup_remote_enabled"] = bool(patch.get("backup_remote_enabled"))
154
+ for _rk, _rmax in (("backup_remote_url", 300), ("backup_remote_user", 128),
155
+ ("backup_remote_pass", 128)):
156
+ if _rk in patch:
157
+ cur[_rk] = str(patch.get(_rk) or "").strip()[:_rmax]
158
+ if "pet_enabled" in patch:
159
+ cur["pet_enabled"] = bool(patch.get("pet_enabled"))
160
+ if "pet_mode" in patch:
161
+ pm = str(patch.get("pet_mode") or "").strip()
162
+ if pm not in ("always", "tasks_only"):
163
+ return cur, "pet_mode 只能是 always 或 tasks_only"
164
+ cur["pet_mode"] = pm
165
+ if "pet_skin" in patch:
166
+ ps = str(patch.get("pet_skin") or "").strip()
167
+ if ps not in PET_SKINS:
168
+ return cur, "pet_skin 只能是 %s 之一" % "/".join(PET_SKINS)
169
+ cur["pet_skin"] = ps
170
+ if "cleanup_enabled" in patch:
171
+ cur["cleanup_enabled"] = bool(patch.get("cleanup_enabled"))
172
+ if "claude_config_sync" in patch:
173
+ cur["claude_config_sync"] = bool(patch.get("claude_config_sync"))
174
+ if "cleanup_retention_days" in patch:
175
+ try:
176
+ cur["cleanup_retention_days"] = int(patch.get("cleanup_retention_days"))
177
+ except (TypeError, ValueError):
178
+ return cur, "cleanup_retention_days 必须是整数"
179
+ if not 1 <= cur["cleanup_retention_days"] <= 365:
180
+ return cur, "cleanup_retention_days 取值 1-365"
181
+ _FILE.parent.mkdir(parents=True, exist_ok=True)
182
+ tmp = _FILE.with_suffix(".tmp")
183
+ tmp.write_text(json.dumps(cur, ensure_ascii=False, indent=2), encoding="utf-8")
184
+ tmp.replace(_FILE)
185
+ cur["default_workdir_effective"] = cur["default_workdir"] if cur["default_workdir"] else builtin_workdir()
186
+ return cur, None