@hfyjq/crannia 1.0.0 → 1.1.0

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 (221) hide show
  1. package/LICENSE +201 -201
  2. package/NOTICE +45 -45
  3. package/THIRD-PARTY-FRONTEND.md +5266 -5266
  4. package/THIRD-PARTY-PYTHON.md +162 -153
  5. package/THIRD-PARTY.md +316 -316
  6. package/apps/desktop/quotes.txt +56 -56
  7. package/bus/core.py +671 -671
  8. package/bus/loaders/channel_loader.py +64 -64
  9. package/bus/loaders/skill_md.py +676 -676
  10. package/bus/skill_state.py +124 -124
  11. package/channels/cli_channel/manifest.yaml +5 -5
  12. package/channels/dingtalk_channel/manifest.yaml +12 -12
  13. package/channels/feishu_channel/manifest.yaml +12 -12
  14. package/channels/qq_bot_channel/__init__.py +1 -1
  15. package/channels/qq_bot_channel/handler.py +881 -881
  16. package/channels/qq_bot_channel/manifest.yaml +4 -4
  17. package/channels/telegram_channel/__init__.py +1 -1
  18. package/channels/telegram_channel/handler.py +813 -813
  19. package/channels/telegram_channel/manifest.yaml +4 -4
  20. package/channels/telegram_channel/media.py +231 -231
  21. package/channels/textfmt.py +58 -58
  22. package/channels/wechat_channel/__init__.py +1 -1
  23. package/channels/wechat_channel/auth.py +23 -5
  24. package/channels/wechat_channel/manifest.yaml +5 -5
  25. package/channels/wechat_channel/media.py +178 -178
  26. package/config.yaml +2 -2
  27. package/core/activity.py +3 -0
  28. package/core/agent_loop.py +390 -55
  29. package/core/approval.py +17 -6
  30. package/core/artifacts.py +7 -0
  31. package/core/auto_review.py +23 -5
  32. package/core/channel_configs.py +34 -2
  33. package/core/channel_turns.py +759 -759
  34. package/core/child_approval.py +150 -0
  35. package/core/config_requirements.py +205 -0
  36. package/core/cron/runner.py +118 -6
  37. package/core/cron/store.py +14 -5
  38. package/core/cron/tools.py +17 -5
  39. package/core/endpoint.py +141 -0
  40. package/core/events.py +23 -0
  41. package/core/i18n.py +329 -329
  42. package/core/ice/store.py +191 -191
  43. package/core/inbound.py +193 -193
  44. package/core/jobs.py +19 -3
  45. package/core/last_good.py +150 -150
  46. package/core/llm_errors.py +227 -227
  47. package/core/llm_retry.py +230 -230
  48. package/core/memory/compressor.py +1214 -1214
  49. package/core/memory/manager.py +14 -0
  50. package/core/model_configs.py +80 -0
  51. package/core/pipeline/scheduler.py +2 -2
  52. package/core/pipeline/stages/agent_loop.py +24 -4
  53. package/core/pipeline/stages/pre_process.py +58 -7
  54. package/core/prompt_assembler.py +680 -680
  55. package/core/rg.py +255 -255
  56. package/core/security.py +1544 -1544
  57. package/core/settings_baseline.py +70 -1
  58. package/core/shell.py +5 -17
  59. package/core/skill_settings.py +7 -2
  60. package/core/state_registry.py +19 -0
  61. package/core/subagent.py +64 -3
  62. package/core/task_tool.py +1 -1
  63. package/core/tasks_notify.py +69 -4
  64. package/core/tiers.py +9 -3
  65. package/core/tool_outcome.py +108 -0
  66. package/core/update_tui.py +158 -0
  67. package/core/version.py +2 -2
  68. package/core/web_cache.py +152 -0
  69. package/crannia_tray.py +278 -278
  70. package/creators/models.json +4 -4
  71. package/data/settings.example.json +67 -0
  72. package/licenses/GPL-3.0.txt +619 -619
  73. package/licenses/LGPL-2.1.txt +502 -502
  74. package/licenses/LGPL-3.0.txt +165 -165
  75. package/licenses/MIT-chat-on-wechat.txt +18 -18
  76. package/licenses/MIT-deepseek-harness.txt +21 -21
  77. package/licenses/Molio-LICENSE.txt +44 -44
  78. package/locales/en.json +9 -4
  79. package/main.py +154 -154
  80. package/mcpx/manager.py +522 -522
  81. package/mcpx/servers/__init__.py +22 -22
  82. package/mcpx/servers/web_search.py +321 -33
  83. package/package.json +14 -9
  84. package/providers/anthropic/client.py +772 -772
  85. package/providers/cost_table.json +3779 -3779
  86. package/providers/deepseek/client.py +20 -20
  87. package/providers/deepseek/manifest.yaml +2 -2
  88. package/providers/factory.py +136 -136
  89. package/providers/lmstudio/client.py +2 -2
  90. package/providers/metadata.py +80 -80
  91. package/providers/model_capabilities.json +6665 -6665
  92. package/providers/moonshot/client.py +12 -12
  93. package/providers/ollama/client.py +2 -2
  94. package/providers/openai/client.py +13 -13
  95. package/providers/openrouter/client.py +2 -2
  96. package/providers/qwen/__init__.py +1 -1
  97. package/providers/qwen/client.py +2 -2
  98. package/providers/qwen/manifest.yaml +16 -16
  99. package/providers/rate_limiter.py +144 -144
  100. package/providers/siliconflow/client.py +2 -2
  101. package/providers/validation.py +171 -171
  102. package/providers/window_table.json +8909 -8909
  103. package/sbom.json +4413 -4296
  104. package/skills/entertainment/SKILL.md +35 -35
  105. package/skills/entertainment/__init__.py +1 -1
  106. package/skills/entertainment/handler.py +91 -91
  107. package/skills/entertainment/manifest.yaml +26 -26
  108. package/skills/file_parser/GUIDANCE.md +10 -10
  109. package/skills/file_parser/handler.py +177 -4
  110. package/skills/file_parser/manifest.yaml +22 -1
  111. package/skills/github/SKILL.md +32 -32
  112. package/skills/github/__init__.py +1 -1
  113. package/skills/github/manifest.yaml +5 -0
  114. package/skills/mail_parser/SKILL.md +68 -68
  115. package/skills/mail_parser/__init__.py +1 -1
  116. package/skills/mail_parser/handler.py +806 -806
  117. package/skills/mail_parser/manifest.yaml +5 -0
  118. package/skills/media_gen/GUIDANCE.md +19 -19
  119. package/skills/media_gen/SKILL.md +43 -43
  120. package/skills/media_gen/__init__.py +1 -1
  121. package/skills/media_gen/handler.py +430 -430
  122. package/skills/media_gen/manifest.yaml +93 -88
  123. package/skills/office_parser/cell_validation.py +127 -127
  124. package/skills/office_parser/excel_transform.py +936 -936
  125. package/skills/office_parser/layout_spec.py +243 -243
  126. package/skills/office_parser/pptx_export/console_encoding.py +27 -27
  127. package/skills/office_parser/pptx_export/resource_paths.py +88 -88
  128. package/skills/office_parser/pptx_export/svg_finalize/__init__.py +12 -12
  129. package/skills/office_parser/pptx_export/svg_finalize/align_embed_images.py +575 -575
  130. package/skills/office_parser/pptx_export/svg_finalize/crop_images.py +366 -366
  131. package/skills/office_parser/pptx_export/svg_finalize/embed_icons.py +498 -498
  132. package/skills/office_parser/pptx_export/svg_finalize/embed_images.py +288 -288
  133. package/skills/office_parser/pptx_export/svg_finalize/fix_image_aspect.py +388 -388
  134. package/skills/office_parser/pptx_export/svg_finalize/flatten_tspan.py +818 -818
  135. package/skills/office_parser/pptx_export/svg_finalize/svg_rect_to_path.py +345 -345
  136. package/skills/office_parser/pptx_export/svg_to_pptx/__init__.py +14 -14
  137. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/__init__.py +1 -1
  138. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/context.py +186 -186
  139. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/converter.py +781 -781
  140. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/elements.py +2490 -2490
  141. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/paths.py +429 -429
  142. package/skills/office_parser/pptx_export/svg_to_pptx/drawingml/styles.py +656 -656
  143. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/__init__.py +1 -1
  144. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/builder.py +1267 -1267
  145. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/dimensions.py +155 -155
  146. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/discovery.py +101 -101
  147. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/media.py +141 -141
  148. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/narration.py +236 -236
  149. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/notes.py +257 -257
  150. package/skills/office_parser/pptx_export/svg_to_pptx/pptx_package/slide_xml.py +136 -136
  151. package/skills/office_parser/pptx_export/svg_to_pptx/tspan_flattener.py +44 -44
  152. package/skills/office_parser/pptx_export/svg_to_pptx/use_expander.py +129 -129
  153. package/skills/office_parser/references/LICENSE-Office-Word-MCP-Server.txt +20 -20
  154. package/skills/office_parser/references/LICENSE-excel-mcp-server.txt +21 -21
  155. package/skills/office_parser/references/layout_library.md +816 -816
  156. package/skills/office_parser/references/ppt-master/LICENSE +21 -21
  157. package/skills/office_parser/references/ppt-master/references/executor-base.md +474 -474
  158. package/skills/office_parser/references/ppt-master/references/shared-standards.md +1002 -1002
  159. package/skills/office_parser/references/ppt-master/references/strategist.md +880 -880
  160. package/skills/office_parser/references/ppt-master/references/template-designer.md +402 -402
  161. package/skills/office_parser/references/ppt-master/references/visual-review.md +240 -240
  162. package/skills/office_parser/references/ppt-master/references/visual-styles/_index.md +106 -106
  163. package/skills/office_parser/references/ppt-master/references/visual-styles/blueprint.md +37 -37
  164. package/skills/office_parser/references/ppt-master/references/visual-styles/brutalist.md +38 -38
  165. package/skills/office_parser/references/ppt-master/references/visual-styles/chalkboard.md +36 -36
  166. package/skills/office_parser/references/ppt-master/references/visual-styles/dark-tech.md +37 -37
  167. package/skills/office_parser/references/ppt-master/references/visual-styles/data-journalism.md +36 -36
  168. package/skills/office_parser/references/ppt-master/references/visual-styles/editorial.md +38 -38
  169. package/skills/office_parser/references/ppt-master/references/visual-styles/glassmorphism.md +36 -36
  170. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-notes.md +37 -37
  171. package/skills/office_parser/references/ppt-master/references/visual-styles/ink-wash.md +36 -36
  172. package/skills/office_parser/references/ppt-master/references/visual-styles/memphis.md +37 -37
  173. package/skills/office_parser/references/ppt-master/references/visual-styles/paper-cut.md +36 -36
  174. package/skills/office_parser/references/ppt-master/references/visual-styles/photo-editorial.md +38 -38
  175. package/skills/office_parser/references/ppt-master/references/visual-styles/pixel-art.md +36 -36
  176. package/skills/office_parser/references/ppt-master/references/visual-styles/sketch-notes.md +36 -36
  177. package/skills/office_parser/references/ppt-master/references/visual-styles/soft-rounded.md +37 -37
  178. package/skills/office_parser/references/ppt-master/references/visual-styles/swiss-minimal.md +38 -38
  179. package/skills/office_parser/references/ppt-master/references/visual-styles/vintage-poster.md +36 -36
  180. package/skills/office_parser/references/ppt-master/references/visual-styles/zine.md +37 -37
  181. package/skills/office_parser/references/spec_lock.md +235 -235
  182. package/skills/office_parser/soffice.py +68 -68
  183. package/skills/office_parser/word_tools.py +2909 -2909
  184. package/tui/crannia.cmd +134 -0
  185. package/tui/crannia_tui/__init__.py +1 -0
  186. package/tui/crannia_tui/__main__.py +223 -0
  187. package/tui/crannia_tui/app.py +1318 -0
  188. package/tui/crannia_tui/app.tcss +153 -0
  189. package/tui/crannia_tui/approval.py +85 -0
  190. package/tui/crannia_tui/backend.py +279 -0
  191. package/tui/crannia_tui/channel.py +472 -0
  192. package/tui/crannia_tui/client.py +125 -0
  193. package/tui/crannia_tui/clipboard.py +62 -0
  194. package/tui/crannia_tui/commands.py +65 -0
  195. package/tui/crannia_tui/doctor.py +304 -0
  196. package/tui/crannia_tui/events.py +84 -0
  197. package/tui/crannia_tui/headless.py +152 -0
  198. package/tui/crannia_tui/i18n.py +164 -0
  199. package/tui/crannia_tui/locales/en.json +263 -0
  200. package/tui/crannia_tui/outcome.py +62 -0
  201. package/tui/crannia_tui/paths.py +181 -0
  202. package/tui/crannia_tui/probe.py +53 -0
  203. package/tui/crannia_tui/profile.py +169 -0
  204. package/tui/crannia_tui/render.py +209 -0
  205. package/tui/crannia_tui/settings.py +134 -0
  206. package/tui/crannia_tui/setup.py +380 -0
  207. package/tui/crannia_tui/term.py +116 -0
  208. package/tui/crannia_tui/ui.py +1236 -0
  209. package/tui/crannia_tui/update.py +389 -0
  210. package/vendor/ripgrep/COPYING.txt +3 -3
  211. package/vendor/ripgrep/LICENSE-MIT.txt +21 -21
  212. package/vendor/ripgrep/NOTICE-vscode-ripgrep.txt +13 -13
  213. package/vendor/ripgrep/README.md +51 -51
  214. package/vendor/ripgrep/UNLICENSE.txt +24 -24
  215. package/vendor/ripgrep/package-source.json +19 -19
  216. package/web/__main__.py +15 -0
  217. package/web/server.py +168 -19
  218. package/web/static/img/channel-telegram.svg +1 -1
  219. package/web/static/img/channel-wechat.svg +1 -1
  220. package/web/templates/logs.html +49 -49
  221. package/web/templates/models.html +46 -46
package/core/approval.py CHANGED
@@ -813,7 +813,8 @@ def build_payload(kind: str, ask_index: int = 1, *,
813
813
  body: str = "", stage: str = "",
814
814
  request_id: str = "", file_list: str = "",
815
815
  rule: str = "", options=None, multi: bool = False,
816
- title: str = "", ask_question: str = "") -> dict:
816
+ title: str = "", ask_question: str = "",
817
+ requester: str = "") -> dict:
817
818
  """浮窗的渲染源。纯函数:同样的入参出同样的 dict。
818
819
 
819
820
  这里不拼字符串 —— 那是 :func:`render_prompt` 给文本通道的事。
@@ -823,8 +824,8 @@ def build_payload(kind: str, ask_index: int = 1, *,
823
824
  n = max(1, int(ask_index or 1))
824
825
  opts = options_for(kind, n, rule=rule, options=options)
825
826
  q = substate_question(kind, stage)
826
- if kind == "delete" and not body:
827
- body = render_delete_body(file_list)
827
+ if kind in ("delete", "delete_bulk") and not body:
828
+ body = render_delete_body(file_list, kind=kind)
828
829
  # 中间态不给选项:那一步用户该做的是"说一句话",不是"选一项"。
829
830
  # 给了也是死数据(前端在 `expect === 'text'` 时根本不渲染选项),
830
831
  # 而"载荷里有一份谁也不读的选项表"正是本模块要消灭的那种副本。
@@ -833,11 +834,17 @@ def build_payload(kind: str, ask_index: int = 1, *,
833
834
  #: 动态表那一路把每项的说明也带上(浮窗要显示第二行)。
834
835
  _desc = {str(r.get("key")): str(r.get("description") or "")
835
836
  for r in (options or ()) if isinstance(r, dict)}
837
+ _body = tr(body or _DEFAULT_BODY.get(kind, ""))
838
+ if requester:
839
+ # 谁在申请要写在正文最前面 —— 用户在批一个他自己没有发起过的动作。
840
+ _body = tr("来自子代理的请求,") + _body
836
841
  return {
837
842
  "request_id": request_id or new_request_id(kind),
838
843
  "kind": kind,
839
844
  "ask_index": n,
840
- "body": tr(body or _DEFAULT_BODY.get(kind, "")),
845
+ "body": _body,
846
+ #: 空 = 父代理自己发的;非空 = 子代理名(面板据此标注来源)。
847
+ "requester": str(requester or ""),
841
848
  #: 提问面板:允许多选(浮窗据此把单选改成多选)。
842
849
  "multi": bool(multi),
843
850
  # 选项按表里的顺序(升级项永远最后)
@@ -924,9 +931,13 @@ def compact_file_list(lines, *, total_note: str = "",
924
931
  return f"{head}\n {more}{total_note}"
925
932
 
926
933
 
927
- def render_delete_body(file_list: str) -> str:
934
+ def render_delete_body(file_list: str, kind: str = "delete") -> str:
928
935
  """删除那条的开场白 —— 带文件列表。
929
936
 
937
+ *kind* 决定抬头:`delete` 是"想删除以下文件",`delete_bulk` 要顺带说清
938
+ 这次为什么还要问(数量超过阈值)。抬头与列表必须由同一处拼出来 ——
939
+ 同一份授权在两条通道上长得不一样,是这一族反复踩过的坑。
940
+
930
941
  单独一个函数是因为列表也是提示语的一部分:内容无界会把按钮顶出视口,
931
942
  而判据是"被审批的文本就是被同意的文本,藏掉尾巴等于让用户同意他读不到
932
943
  的东西"。截断策略因此属于渲染层,并且要显式标注省略了多少
@@ -936,7 +947,7 @@ def render_delete_body(file_list: str) -> str:
936
947
  换行,而排版是空一行再接选项(`...{file_list}\\n\\n1. 同意`)。
937
948
  补上它才能保持这个逐字形状(有断言钉着)。
938
949
  """
939
- head = tr("Crannia 想删除以下文件:")
950
+ head = tr(_DEFAULT_BODY.get(kind) or _DEFAULT_BODY["delete"])
940
951
  return f"{head}\n{file_list}\n"
941
952
 
942
953
 
package/core/artifacts.py CHANGED
@@ -183,6 +183,13 @@ def sniff(data: bytes) -> Optional[str]:
183
183
  return _sniff_av(data)
184
184
 
185
185
 
186
+ def ext_for_mime(mime: str) -> str:
187
+ """mime -> 扩展名(不带点);认不出回空串。
188
+
189
+ 唯一来源是 `_EXT_BY_MIME` —— 别在别处再写一张。"""
190
+ return _EXT_BY_MIME.get(str(mime or "").strip().lower(), "").lstrip(".")
191
+
192
+
186
193
  def kind_of(mime: str) -> str:
187
194
  """mime -> `image` / `audio` / `video` / `""`(认不出)。"""
188
195
  if not mime:
@@ -208,14 +208,32 @@ def outcome_of_tool_result(content) -> Optional[str]:
208
208
  # 头从 `core.approval` 取(全仓只有那一处拼得出来)。
209
209
  # 只有 `rejected` 算数:`cancelled`/`unavailable`/`recused` 都不是"被拒绝"
210
210
  # (见 `APPROVAL_OUTCOMES` 那四条各自的语义)。
211
- from core.approval import APPROVAL_HEAD
212
- if body.startswith(APPROVAL_HEAD):
213
- token = body[len(APPROVAL_HEAD):].strip().split("(", 1)[0].strip()
214
- if token == "rejected":
215
- return OUTCOME_REJECTED_BY_USER
211
+ if settlement_outcome_of(text) == "rejected":
212
+ return OUTCOME_REJECTED_BY_USER
216
213
  return None
217
214
 
218
215
 
216
+ def settlement_outcome_of(content) -> str:
217
+ """回执是"结算过的审批"就返回它的语义 token;不是就回空串。
218
+
219
+ 头由 `core.approval.outcome_line` 拼(全仓唯一一处),形状是
220
+ `APPROVAL_HEAD` + `<token>(<白话>)—— <路线>`,外面可能套一层信封或隔离包裹。
221
+
222
+ 与 `outcome_of_tool_result` 分工:那个是审计口径(只认"用户拒绝"),
223
+ 这一个给事件用 —— 四种语义都要,客户端才能分得开"未采纳 / 未执行 / 被拒绝"。
224
+ """
225
+ from core.approval import APPROVAL_HEAD, APPROVAL_OUTCOMES
226
+
227
+ text = content_text(content)
228
+ if not isinstance(text, str) or not text.strip():
229
+ return ""
230
+ body = _strip_wrappers(text)
231
+ if not body.startswith(APPROVAL_HEAD):
232
+ return ""
233
+ token = body[len(APPROVAL_HEAD):].strip().split("(", 1)[0].strip()
234
+ return token if token in APPROVAL_OUTCOMES else ""
235
+
236
+
219
237
  # 一、声明层(复用已有的声明形状,不新建机制)
220
238
 
221
239
  #: 声明值:这个工具没有与分类器相关的输入,第 ④ 层跳过。
@@ -44,7 +44,7 @@ __all__ = [
44
44
  "ChannelConfigError", "PLATFORMS", "MAX_PER_PLATFORM", "MAX_NAME",
45
45
  "entries_for", "entry_of", "default_id", "credentials_for",
46
46
  "create", "update", "delete", "set_default", "seed_from_legacy",
47
- "masked_fields", "load",
47
+ "masked_fields", "load", "notice_for",
48
48
  ]
49
49
 
50
50
  #: 每种平台的字段表。`secret` 里的那几格界面不打码回显、日志里也不打印。
@@ -56,6 +56,22 @@ PLATFORMS: dict[str, dict] = {
56
56
  "qq_bot": {"fields": ("app_id", "app_secret"), "secret": ("app_secret",)},
57
57
  }
58
58
 
59
+ #: 接入警告的文案。住在这里而不是界面里 —— 命令行与 TUI 都没有那份界面表,
60
+ #: 而"接群聊有隐私风险"这件事与用哪个前端无关。
61
+ NOTICES: dict[str, str] = {
62
+ "group_unfinished":
63
+ "当前通道的群聊模式还没做完:群里的内容会进模型,也会被群里的人看到,"
64
+ "请先不要接入群聊使用。",
65
+ }
66
+
67
+ #: 哪个平台挂哪条警告。微信走扫码、CLI 不需要配置,两者都不挂。
68
+ PLATFORM_NOTICE: dict[str, str] = {
69
+ "feishu": "group_unfinished",
70
+ "dingtalk": "group_unfinished",
71
+ "telegram": "group_unfinished",
72
+ "qq_bot": "group_unfinished",
73
+ }
74
+
59
75
  #: 每种平台最多几条。超了拒,不静默丢。
60
76
  MAX_PER_PLATFORM = 10
61
77
  #: 条目名的长度上限。截断改的是用户起的名,所以超了是拒。
@@ -138,6 +154,17 @@ def _platform(data: dict, name: str) -> dict:
138
154
  return p
139
155
 
140
156
 
157
+ def notice_for(platform: str) -> dict:
158
+ """这个平台的接入警告:`{"key": ..., "text": ...}`;没有就空 dict。
159
+
160
+ 前端照 `text` 显示、照 `key` 做本地化,两样都不在该前端里另写一份。
161
+ """
162
+ key = PLATFORM_NOTICE.get(platform, "")
163
+ if not key:
164
+ return {}
165
+ return {"key": key, "text": NOTICES.get(key, "")}
166
+
167
+
141
168
  def masked_fields(platform: str, fields: dict) -> dict:
142
169
  """按字段表打码。密钥一律八颗点,其余留头尾各四位。"""
143
170
  spec = PLATFORMS.get(platform) or {}
@@ -171,6 +198,8 @@ def entries_for(platform: str) -> list[dict]:
171
198
  "is_default": cid == p.get("default"),
172
199
  "fields": masked_fields(platform, creds.get(cid) or {}),
173
200
  "created_at": entry.get("created_at") or 0,
201
+ # 账本里没写过的(老条目)按平台现推,免得列表少一个标记。
202
+ "notice": str(entry.get("notice") or PLATFORM_NOTICE.get(platform, "")),
174
203
  })
175
204
  rows.sort(key=lambda r: (not r["is_default"], r["created_at"], r["name"]))
176
205
  return rows
@@ -244,7 +273,8 @@ def create(platform: str, name: str, fields: dict) -> dict:
244
273
 
245
274
  cid = new_id()
246
275
  now = int(time.time())
247
- p["entries"][cid] = {"name": name, "created_at": now, "updated_at": now}
276
+ p["entries"][cid] = {"name": name, "created_at": now, "updated_at": now,
277
+ "notice": PLATFORM_NOTICE.get(platform, "")}
248
278
  if not p.get("default"):
249
279
  p["default"] = cid
250
280
  creds = _read(_CREDS)
@@ -287,6 +317,8 @@ def update(cid: str, *, name: str | None = None, fields: dict | None = None) ->
287
317
  _write(_CREDS, creds)
288
318
 
289
319
  p["entries"][cid]["updated_at"] = int(time.time())
320
+ # 老条目在这里补上标记(写一次就够,读侧还有一层兜底)。
321
+ p["entries"][cid]["notice"] = PLATFORM_NOTICE.get(platform, "")
290
322
  _write(_LEDGER, data)
291
323
  return {"id": cid, "platform": platform, "name": p["entries"][cid]["name"]}
292
324